Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept --version to show short version info, and --help for usage. #45

Merged
merged 1 commit into from
Oct 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions lslmini.cc
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,9 @@ void usage(char *name) {
#ifdef COMPILE_ENABLED
printf("\t-c\t\tFlag: Compile (default off)\n");
#endif /* COMPILE_ENABLED */
printf("\t-V\t\tPrint version and exit.\n");
printf("\t-V\t\tPrint long version info and exit.\n");
printf("\t--version\tPrint short version info and exit.\n");
printf("\t--help\t\tPrint this help text and exit.\n");
printf("\n");
printf("Options that are flags can have a - sign at the end to disable them\n");
printf("(e.g. -m- to disable Mono and enable LSO)\n");
Expand Down Expand Up @@ -887,6 +889,10 @@ void version() {
fprintf(stderr, "VS 2015 by: Xenhat @ https://github.com/Ociidii-Works/lslint\n");
}

void short_version() {
fprintf(stderr, "lslint %s\n", VERSION);
}

int yylex_init( void ** );
void yyset_in( FILE *, void *);
int yylex_destroy( void *) ;
Expand All @@ -903,6 +909,21 @@ int main(int argc, char **argv) {
bool compile = true;
#endif

// HACK: Parse long options before anything else.
for ( i = 1; i < argc; ++i ) {
if (argv[i][0] == '-' && argv[i][1] == '-') {
char *optiontext = argv[i] + 2;
if ( !strcmp(optiontext, "version") ) {
short_version();
return 0;
}
if ( !strcmp(optiontext, "help") ) {
usage(argv[0]);
return 0;
}
}
}

for ( i = 1; i < argc; ++i ) {
if ( argv[i][0] == '-' ) {
for ( j = 1 ; argv[i][j]; ++j ) {
Expand Down Expand Up @@ -966,7 +987,7 @@ int main(int argc, char **argv) {
} else compile = true;
break;
#endif /* COMPILE_ENABLED */
default: usage(argv[0]); exit(1);
default: usage(argv[0]); return 1;
}
}
} else {
Expand Down