📄 getopt.c
字号:
/* keyboard emulator project Copyright (C) 1998-2003 Reznic Valery <valery_reznic@users.sourceforge.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ #include <getopt.h> struct option long_options[] = { {"ascii" , required_argument, 0, 'a'}, {"background" , no_argument, 0, 'b'}, {"delay" , required_argument, 0, 'd'}, {"input" , required_argument, 0, 'i'}, {"key" , required_argument, 0, 'k'}, {"list" , no_argument, 0, 'l'}, {"output" , required_argument, 0, 'o'}, {"text" , required_argument, 0, 't'}, {"press" , required_argument, 0, 'p'}, {"release" , required_argument, 0, 'r'}, {"sleep" , required_argument, 0, 's'}, {"help" , no_argument, 0, 'h'}, {"version" , no_argument, 0, 'v'}, {0 , 0, 0, 0} }; int result; int option_index = 0; while( 1 ) { result = getopt_long( argc, argv, "-a:bd:i:k:lo:t:p:r:s:hv", long_options, &option_index ); if (result == EOF) break; switch (result) { case 'h': usage(); exit (0); case 'v': printf("%s version %s\n", pgm_name, VERSION ); exit(0); case 'l': key_name_list(); exit(0); case 'o': device = optarg; break; case 'b': need_fork = 1; break; case 'i': operations[op_number].type = type_file; operations[op_number].op.filename = optarg; operations[op_number].delay = delay; op_number++; break; case 'a': case 't': case 1 : operations[op_number].type = type_ascii; operations[op_number].op.filename = optarg; operations[op_number].delay = delay; op_number++; break; case 'k': case 'p': case 'r': switch(result) { case 'k': operations[op_number].type = type_key; break; case 'p': operations[op_number].type = type_key_press; break; case 'r': operations[op_number].type = type_key_release; break; default: fprintf(stderr, "%s: internal error: result='%c (%d)'\n", pgm_name, result, result ); exit(1); } operations[op_number].op.key_code = kbde_case_name_to_key(optarg); if (operations[op_number].op.key_code == 0) { fprintf( stderr, "%s: Unrecognized key name '%s', try `%s -l'\n", argv[0], optarg, pgm_name ); exit(1); } operations[op_number].delay = delay; op_number++; break; case 'd': delay = atol(optarg) * MILLI_TO_MICRO; if (delay < 0) delay = 0; break; case 's': operations[op_number].type = type_sleep; operations[op_number].op.sleep = atol(optarg) * MILLI_TO_MICRO; if (operations[op_number].op.sleep < 0) { operations[op_number].op.sleep = 0; } operations[op_number].delay = 0; op_number++; break; case ':': case '?': fprintf(stderr, "Try `%s --help' for more information.\n", pgm_name); exit(1); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -