3838
3939#include <errno.h>
4040#include <stdio.h>
41- #include <getopt.h>
4241
4342#include <string.h>
4443
45- #ifndef VERSION
46- #define VERSION "unknown"
47- #endif
48-
4944struct tool_def {
5045 char name [16 ];
5146 void * ptr ;
@@ -86,10 +81,7 @@ static const struct tool_def tool_list[] = {
8681};
8782
8883static void show_help () {
89- puts ("Usage: ydotool [OPTION] <cmd> <args>\n"
90- "Options:\n"
91- " -h, --help Display this help and exit\n"
92- " -V, --version Show version information\n"
84+ puts ("Usage: ydotool <cmd> <args>\n"
9385 "Available commands:" );
9486
9587 int tool_count = sizeof (tool_list ) / sizeof (struct tool_def );
@@ -101,11 +93,6 @@ static void show_help() {
10193 puts ("Use environment variable YDOTOOL_SOCKET to specify daemon socket." );
10294}
10395
104- static void show_version () {
105- puts ("ydotool version(or hash): " );
106- puts (VERSION );
107- }
108-
10996void uinput_emit (uint16_t type , uint16_t code , int32_t val , bool syn_report ) {
11097 struct input_event ie = {
11198 .type = type ,
@@ -125,29 +112,9 @@ void uinput_emit(uint16_t type, uint16_t code, int32_t val, bool syn_report) {
125112}
126113
127114int main (int argc , char * * argv ) {
128-
129- static struct option long_options [] = {
130- {"help" , no_argument , 0 , 'h' },
131- {"version" , no_argument , 0 , 'V' },
132- };
133-
134- int opt = getopt_long (argc , argv , "hV" , long_options , NULL );
135- if (opt != -1 )
136- {
137- switch (opt ) {
138- case 'h' :
139- show_help ();
140- exit (0 );
141-
142- case 'V' :
143- show_version ();
144- exit (0 );
145-
146- default :
147- puts ("Not a valid option\n" );
148- show_help ();
149- exit (1 );
150- }
115+ if (argc < 2 || strncmp (argv [1 ], "-h" , 2 ) == 0 || strncmp (argv [1 ], "--h" , 3 ) == 0 || strcmp (argv [1 ], "help" ) == 0 ) {
116+ show_help ();
117+ return 0 ;
151118 }
152119
153120 int (* tool_main )(int argc , char * * argv ) = NULL ;
@@ -162,7 +129,7 @@ int main(int argc, char **argv) {
162129
163130 if (!tool_main ) {
164131 printf ("ydotool: Unknown command: %s\n"
165- "Run 'ydotool -- help' if you want a command list\n" , argv [1 ]);
132+ "Run 'ydotool help' if you want a command list\n" , argv [1 ]);
166133 return 1 ;
167134 }
168135
0 commit comments