@@ -292,6 +292,11 @@ static const struct option options[] = {
292292};
293293
294294static const char * options_descriptions [] = {
295+ "-d [device] [attr] [value]\n"
296+ "\t\t\t\t-c [device] [channel] [attr] [value]\n"
297+ "\t\t\t\t-B [device] [attr] [value]\n"
298+ "\t\t\t\t-D [device] [attr] [value]\n"
299+ "\t\t\t\t-C [attr]" ,
295300 /* help */
296301 "Show this help and quit." ,
297302 "Ignore case distinctions." ,
@@ -312,34 +317,6 @@ static const char *options_descriptions[] = {
312317 "Read/Write debug attributes." ,
313318};
314319
315- static void usage (void )
316- {
317- unsigned int i , j = 0 , k ;
318-
319- printf ("Usage:\n\t" MY_NAME " [OPTION]...\t-d [device] [attr] [value]\n"
320- "\t\t\t\t-c [device] [channel] [attr] [value]\n"
321- "\t\t\t\t-B [device] [attr] [value]\n"
322- "\t\t\t\t-D [device] [attr] [value]\n"
323- "\t\t\t\t-C [attr]\nOptions:\n" );
324- for (i = 0 ; options [i ].name ; i ++ ) {
325- k = strlen (options [i ].name );
326- if (k > j )
327- j = k ;
328- }
329- j ++ ;
330- for (i = 0 ; options [i ].name ; i ++ ) {
331- printf ("\t-%c, --%s%*c: %s\n" ,
332- options [i ].val , options [i ].name ,
333- j - (int )strlen (options [i ].name ), ' ' ,
334- options_descriptions [i ]);
335- /* when printing out the help, add some subtitles, to help visually */
336- if (i == 3 )
337- printf ("Optional qualifiers:\n" );
338- if (i == 8 )
339- printf ("Attribute types:\n" );
340- }
341- }
342-
343320int main (int argc , char * * argv )
344321{
345322 struct iio_context * ctx ;
@@ -359,7 +336,7 @@ int main(int argc, char **argv)
359336 switch (c ) {
360337 /* help */
361338 case 'h' :
362- usage ();
339+ usage (MY_NAME , options , options_descriptions );
363340 return EXIT_SUCCESS ;
364341 /* context connection */
365342 case 'a' :
@@ -429,7 +406,7 @@ int main(int argc, char **argv)
429406
430407 if (!(search_device + search_channel + search_context + search_debug + search_buffer )) {
431408 if (argc == 1 ) {
432- usage ();
409+ usage (MY_NAME , options , options_descriptions );
433410 return EXIT_SUCCESS ;
434411 }
435412 fprintf (stderr , "must specify one of -d, -c, -C, -B or -D.\n" );
0 commit comments