@@ -43,13 +43,11 @@ static struct option long_options[] = {
4343 {"update" , no_argument , & update_flag , 1 },
4444 {"clear-cache" , no_argument , & clear_flag , 1 },
4545 {"platform" , required_argument , 0 , 'p' },
46- {"linux" , no_argument , 0 , 'p' },
47- {"osx" , no_argument , 0 , 'p' },
48- {"sunos" , no_argument , 0 , 'p' },
49- {"list" , no_argument , & list_flag , 'l' },
46+ {"list" , no_argument , & list_flag , 1 },
5047 {"render" , required_argument , 0 , 'r' },
51- {"color" , no_argument , & color_flag , 'C' },
52- {0 , 0 , 0 , 0 }};
48+ {"color" , no_argument , & color_flag , 1 },
49+ { 0 }
50+ };
5351
5452int main (int argc , char * * argv ) {
5553 int c ;
@@ -70,7 +68,7 @@ int main(int argc, char **argv) {
7068
7169 while (1 ) {
7270 option_index = 0 ;
73- c = getopt_long_only (argc , argv , "vp:r :C" , long_options , & option_index );
71+ c = getopt_long (argc , argv , "hvVucp:lr :C" , long_options , & option_index );
7472
7573 /* reached the end, bail out */
7674 if (c == -1 ) {
@@ -91,20 +89,10 @@ int main(int argc, char **argv) {
9189 return EXIT_FAILURE ;
9290 break ;
9391
94- case 'p' : {
95- const char * platform_name = long_options [option_index ].name ;
96- if (strcmp (platform_name , "platform" ) == 0 ) {
97- size_t len = strlen (optarg );
98- if (len > STRBUFSIZ )
99- exit (EXIT_FAILURE );
100-
101- memcpy (pbuf , optarg , len );
102- pbuf [len ] = '\0' ;
103- } else {
104- memcpy (pbuf , platform_name , strlen (platform_name ));
105- }
92+ case 'p' :
93+ memcpy (pbuf , optarg , strlen (optarg ));
10694 platform_flag = 1 ;
107- } break ;
95+ break ;
10896
10997 case 'r' : {
11098 size_t len = strlen (optarg );
@@ -120,6 +108,26 @@ int main(int argc, char **argv) {
120108 color_flag = 1 ;
121109 break ;
122110
111+ case 'h' :
112+ help_flag = 1 ;
113+ break ;
114+
115+ case 'l' :
116+ list_flag = 1 ;
117+ break ;
118+
119+ case 'V' :
120+ verbose_flag = 1 ;
121+ break ;
122+
123+ case 'u' :
124+ update_flag = 1 ;
125+ break ;
126+
127+ case 'c' :
128+ clear_flag = 1 ;
129+ break ;
130+
123131 default :
124132 abort ();
125133 }
@@ -216,24 +224,21 @@ void print_version(char const *arg) {
216224}
217225
218226void print_usage (char const * arg ){
219- char const * out = "usage: %s [--verbose] [ OPTION]... [ PAGE] \n\n" ;
227+ char const * out = "usage: %s [OPTION]... PAGE\n\n" ;
220228
221229 /* *INDENT-OFF* */
222230 fprintf (stdout , out , arg );
223231 fprintf (stdout , "available commands:\n" );
224- fprintf (stdout , " %-23s %s\n" , "-C, --color" , "force color display" );
225232 fprintf (stdout , " %-23s %s\n" , "-h, --help" , "print this help and exit" );
233+ fprintf (stdout , " %-23s %s\n" , "-C, --color" , "force color display" );
226234 fprintf (stdout , " %-23s %s\n" , "-p, --platform=PLATFORM" ,
227235 "select platform, supported are linux / osx / sunos / windows / common" );
228236 fprintf (stdout , " %-23s %s\n" , "-r, --render=PATH" ,
229237 "render a local page for testing purposes" );
230238 fprintf (stdout , " %-23s %s\n" , "-u, --update" , "update local database" );
231239 fprintf (stdout , " %-23s %s\n" , "-v, --version" , "print version and exit" );
232- fprintf (stdout , " %-23s %s\n" , "--clear-cache" , "clear local database" );
233- fprintf (stdout , " %-23s %s\n" , "--verbose" , "display verbose output (when used with --clear-cache or --update)" );
234- fprintf (stdout , " %-23s %s\n" , "--list" , "list all entries in the local database" );
235- fprintf (stdout , " %-23s %s\n" , "--linux" , "show command page for Linux" );
236- fprintf (stdout , " %-23s %s\n" , "--osx" , "show command page for OSX" );
237- fprintf (stdout , " %-23s %s\n" , "--sunos" , "show command page for SunOS" );
240+ fprintf (stdout , " %-23s %s\n" , "-c, --clear-cache" , "clear local database" );
241+ fprintf (stdout , " %-23s %s\n" , "-V, --verbose" , "display verbose output (when used with -c or -u)" );
242+ fprintf (stdout , " %-23s %s\n" , "-l, --list" , "list all entries in the local database" );
238243 /* *INDENT-ON* */
239244}
0 commit comments