int ipcs_main(int argc UNUSED_PARAM, char **argv) { int id = 0; unsigned flags = 0; unsigned opt; char *opt_i; #define flag_print (1<<0) #define flag_msg (1<<1) #define flag_sem (1<<2) #define flag_shm (1<<3) opt = getopt32(argv, "i:aqsmtcplu", &opt_i); if (opt & 0x1) { // -i id = xatoi(opt_i); flags |= flag_print; } if (opt & 0x2) flags |= flag_msg | flag_sem | flag_shm; // -a if (opt & 0x4) flags |= flag_msg; // -q if (opt & 0x8) flags |= flag_sem; // -s if (opt & 0x10) flags |= flag_shm; // -m if (opt & 0x20) format = TIME; // -t if (opt & 0x40) format = CREATOR; // -c if (opt & 0x80) format = PID; // -p if (opt & 0x100) format = LIMITS; // -l if (opt & 0x200) format = STATUS; // -u if (flags & flag_print) { if (flags & flag_shm) { print_shm(id); fflush_stdout_and_exit(EXIT_SUCCESS); } if (flags & flag_sem) { print_sem(id); fflush_stdout_and_exit(EXIT_SUCCESS); } if (flags & flag_msg) { print_msg(id); fflush_stdout_and_exit(EXIT_SUCCESS); } bb_show_usage(); } if (!(flags & (flag_shm | flag_msg | flag_sem))) flags |= flag_msg | flag_shm | flag_sem; bb_putchar('\n'); if (flags & flag_shm) { do_shm(); bb_putchar('\n'); } if (flags & flag_sem) { do_sem(); bb_putchar('\n'); } if (flags & flag_msg) { do_msg(); bb_putchar('\n'); } fflush_stdout_and_exit(EXIT_SUCCESS); }
int ipcs_main(int argc UNUSED_PARAM, char **argv) { int format = 0; unsigned opt; char *opt_i; opt = getopt32(argv, "i:aqsmtcplu", &opt_i); #define flag_msg (1<<2) #define flag_sem (1<<3) #define flag_shm (1<<4) if (opt & (1<<5)) format = TIME; // -t if (opt & (1<<6)) format = CREATOR; // -c if (opt & (1<<7)) format = PID; // -p if (opt & (1<<8)) format = LIMITS; // -l if (opt & (1<<9)) format = STATUS; // -u if (opt & (1<<0)) { // -i int id; id = xatoi(opt_i); if (opt & flag_shm) { print_shm(id); fflush_stdout_and_exit(EXIT_SUCCESS); } if (opt & flag_sem) { print_sem(id); fflush_stdout_and_exit(EXIT_SUCCESS); } if (opt & flag_msg) { print_msg(id); fflush_stdout_and_exit(EXIT_SUCCESS); } bb_show_usage(); } if ((opt & (1<<1)) // -a || !(opt & (flag_msg | flag_sem | flag_shm)) // none of -q,-s,-m == all ) { opt |= flag_msg | flag_sem | flag_shm; } bb_putchar('\n'); if (opt & flag_msg) { do_msg(format); bb_putchar('\n'); } if (opt & flag_shm) { do_shm(format); bb_putchar('\n'); } if (opt & flag_sem) { do_sem(format); bb_putchar('\n'); } fflush_stdout_and_exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { int option_index = 0; while (1) { int c = getopt_long(argc, argv, "ah", lopts, &option_index); if (c == -1) break; switch (c) { case 0: break; case 'a': mode = PRINT_AST; break; case 's': mode = PRINT_SSA; break; case 'm': mode = PRINT_SEM; break; case 'h': print_help(); return 0; default: print_help(); return 0; } } if (optind == argc - 1) { fname = argv[argc - 1]; yyin = fopen(fname, "r"); if (!yyin) { fprintf(stderr, "Error while opening file.\n"); return 1; } } else if (optind == argc) { fname = NULL; yyin = stdin; } else { fprintf(stderr, "Only one source file is exepected.\n"); return 1; } switch (mode) { case PRINT_AST: print_ast(); break; case PRINT_SEM: print_sem(); break; case PRINT_SSA: print_ssa(); break; case PRINT_HELP: print_help(); break; case COMPILE: compile(); break; } return 0; }
int main (int argc, char **argv) { int opt, msg = 0, shm = 0, sem = 0, id = 0, specific = 0; char format = NOTSPECIFIED; int unit = IPC_UNIT_DEFAULT; static const struct option longopts[] = { {"id", required_argument, NULL, 'i'}, {"queues", no_argument, NULL, 'q'}, {"shmems", no_argument, NULL, 'm'}, {"semaphores", no_argument, NULL, 's'}, {"all", no_argument, NULL, 'a'}, {"time", no_argument, NULL, 't'}, {"pid", no_argument, NULL, 'p'}, {"creator", no_argument, NULL, 'c'}, {"limits", no_argument, NULL, 'l'}, {"summary", no_argument, NULL, 'u'}, {"human", no_argument, NULL, OPT_HUMAN}, {"bytes", no_argument, NULL, 'b'}, {"version", no_argument, NULL, 'V'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0} }; char options[] = "i:qmsatpclubVh"; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); while ((opt = getopt_long(argc, argv, options, longopts, NULL)) != -1) { switch (opt) { case 'i': id = atoi (optarg); specific = 1; break; case 'a': msg = shm = sem = 1; break; case 'q': msg = 1; break; case 'm': shm = 1; break; case 's': sem = 1; break; case 't': format = TIME; break; case 'c': format = CREATOR; break; case 'p': format = PID; break; case 'l': format = LIMITS; break; case 'u': format = STATUS; break; case OPT_HUMAN: unit = IPC_UNIT_HUMAN; break; case 'b': unit = IPC_UNIT_BYTES; break; case 'h': usage(stdout); case 'V': printf(UTIL_LINUX_VERSION); return EXIT_SUCCESS; default: usage(stderr); } } if (specific && (msg + shm + sem != 1)) errx (EXIT_FAILURE, _("when using an ID, a single resource must be specified")); if (specific) { if (msg) print_msg (id, unit); if (shm) print_shm (id, unit); if (sem) print_sem (id); } else { if (!msg && !shm && !sem) msg = shm = sem = 1; printf ("\n"); if (msg) { do_msg (format, unit); printf ("\n"); } if (shm) { do_shm (format, unit); printf ("\n"); } if (sem) { do_sem (format); printf ("\n"); } } return EXIT_SUCCESS; }