@@ -34,14 +34,15 @@ int qdl_write(struct qdl_device *qdl, const void *buf, size_t len)
3434 return write (qdl -> fd , buf , len );
3535}
3636
37- static void print_usage (void )
37+ static void print_usage (FILE * out )
3838{
3939 extern const char * __progname ;
4040
41- fprintf (stderr ,
41+ fprintf (out ,
4242 "%s -p <sahara dev_node> -s <id:file path> ...\n" ,
4343 __progname );
44- fprintf (stderr ,
44+ fprintf (out ,
45+ " -h --help Print this usage info\n"
4546 " -p --port Sahara device node to use\n"
4647 " -s <id:file path> --sahara <id:file path> Sahara protocol file mapping\n"
4748 "\n"
@@ -62,13 +63,14 @@ int main(int argc, char **argv)
6263
6364 static struct option options [] = {
6465 {"debug" , no_argument , 0 , 'd' },
66+ {"help" , no_argument , 0 , 'h' },
6567 {"version" , no_argument , 0 , 'v' },
6668 {"port" , required_argument , 0 , 'p' },
6769 {"sahara" , required_argument , 0 , 's' },
6870 {0 , 0 , 0 , 0 }
6971 };
7072
71- while ((opt = getopt_long (argc , argv , "dvp:s:" , options , NULL )) != -1 ) {
73+ while ((opt = getopt_long (argc , argv , "dvp:s:h " , options , NULL )) != -1 ) {
7274 switch (opt ) {
7375 case 'd' :
7476 qdl_debug = true;
@@ -84,7 +86,7 @@ int main(int argc, char **argv)
8486 found_mapping = true;
8587 file_id = strtol (optarg , NULL , 10 );
8688 if (file_id < 0 ) {
87- print_usage ();
89+ print_usage (stderr );
8890 return 1 ;
8991 }
9092 if (file_id >= MAPPING_SZ ) {
@@ -96,21 +98,24 @@ int main(int argc, char **argv)
9698 }
9799 colon = strchr (optarg , ':' );
98100 if (!colon ) {
99- print_usage ();
101+ print_usage (stderr );
100102 return 1 ;
101103 }
102104 qdl .mappings [file_id ] = & optarg [colon - optarg + 1 ];
103105 printf ("Created mapping ID:%ld File:%s\n" , file_id , qdl .mappings [file_id ]);
104106 break ;
107+ case 'h' :
108+ print_usage (stdout );
109+ return 0 ;
105110 default :
106- print_usage ();
111+ print_usage (stderr );
107112 return 1 ;
108113 }
109114 }
110115
111116 // -p and -s is required
112117 if (!dev_node || !found_mapping ) {
113- print_usage ();
118+ print_usage (stderr );
114119 return 1 ;
115120 }
116121
0 commit comments