Skip to content

Commit

Permalink
Merge pull request #45 from Sei-Lisa/sei-add-version-option
Browse files Browse the repository at this point in the history
Accept --version to show short version info, and --help for usage.
  • Loading branch information
Makopo authored Oct 6, 2017
2 parents 6b4fcdc + b9a7eb0 commit c403d75
Showing 1 changed file with 23 additions and 2 deletions.
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

0 comments on commit c403d75

Please sign in to comment.