int main (int argc, char **argv) { long int id; initialize_main (&argc, &argv); program_name = argv[0]; setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); atexit (close_stdout); parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION, usage, AUTHORS, (char const *) NULL); if (argc > 1) { error (0, 0, _("too many arguments")); usage (EXIT_FAILURE); } id = gethostid (); printf ("%lx\n", id); exit (EXIT_SUCCESS); }
int main (int argc, char **argv) { initialize_main (&argc, &argv); set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); atexit (close_stdout); parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "", NULL, NULL) != -1) usage (EXIT_FAILURE); if (argc < optind + 1) { error (0, 0, _("missing operand")); usage (EXIT_FAILURE); } if (optind + 1 < argc) { error (0, 0, _("extra operand %s"), quote (argv[optind + 1])); usage (EXIT_FAILURE); } if (unlink (argv[optind]) != 0) error (EXIT_FAILURE, errno, _("cannot unlink %s"), quote (argv[optind])); exit (EXIT_SUCCESS); }
int main (int argc, char **argv) { char limit[1 + MAX (INT_BUFSIZE_BOUND (intmax_t), INT_BUFSIZE_BOUND (uintmax_t))]; initialize_main (&argc, &argv); set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); initialize_exit_failure (EXIT_FAILURE); atexit (close_stdout); parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, usage, AUTHORS, (char const *) NULL); #define print_int(TYPE) \ sprintf (limit + 1, "%"PRIuMAX, (uintmax_t) TYPE##_MAX); \ printf (#TYPE"_MAX=%s\n", limit + 1); \ printf (#TYPE"_OFLOW=%s\n", decimal_absval_add_one (limit)); \ if (TYPE##_MIN) \ { \ sprintf (limit + 1, "%"PRIdMAX, (intmax_t) TYPE##_MIN); \ printf (#TYPE"_MIN=%s\n", limit + 1); \ printf (#TYPE"_UFLOW=%s\n", decimal_absval_add_one (limit)); \ } #define print_float(TYPE) \ printf (#TYPE"_MIN=%Le\n", (long double)TYPE##_MIN); \ printf (#TYPE"_MAX=%Le\n", (long double)TYPE##_MAX); /* Variable sized ints */ print_int (CHAR); print_int (SCHAR); print_int (UCHAR); print_int (SHRT); print_int (INT); print_int (UINT); print_int (LONG); print_int (ULONG); print_int (SIZE); print_int (SSIZE); print_int (TIME_T); print_int (UID_T); print_int (GID_T); print_int (PID_T); print_int (OFF_T); print_int (INTMAX); print_int (UINTMAX); /* Variable sized floats */ print_float (FLT); print_float (DBL); print_float (LDBL); }
int main (int argc, char **argv) { int i; double seconds = 0.0; bool ok = true; initialize_main (&argc, &argv); set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); atexit (close_stdout); parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "", NULL, NULL) != -1) usage (EXIT_FAILURE); if (argc == 1) { error (0, 0, _("missing operand")); usage (EXIT_FAILURE); } for (i = optind; i < argc; i++) { double s; const char *p; if (! xstrtod (argv[i], &p, &s, c_strtod) /* Nonnegative interval. */ || ! (0 <= s) /* No extra chars after the number and an optional s,m,h,d char. */ || (*p && *(p+1)) /* Check any suffix char and update S based on the suffix. */ || ! apply_suffix (&s, *p)) { error (0, 0, _("invalid time interval %s"), quote (argv[i])); ok = false; } seconds += s; } if (!ok) usage (EXIT_FAILURE); if (xnanosleep (seconds)) error (EXIT_FAILURE, errno, _("cannot read realtime clock")); return EXIT_SUCCESS; }
CHECK_TYPE GLOBAL(PROGRAM_NAME_LOC) { char *hostname; initialize_main (&argc, &argv); set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); atexit (close_stdout); parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "", NULL, NULL) != -1) usage (EXIT_FAILURE); if (argc == optind + 1) { #ifdef HAVE_SETHOSTNAME /* Set hostname to operand. */ char const *name = argv[optind]; if (sethostname (name, strlen (name)) != 0) error (EXIT_FAILURE, errno, _("cannot set name to %s"), quote (name)); #else error (EXIT_FAILURE, 0, _("cannot set hostname; this system lacks the functionality")); #endif } if (argc <= optind) { hostname = xgethostname (); if (hostname == NULL) error (EXIT_FAILURE, errno, _("cannot determine hostname")); printf ("%s\n", hostname); } if (optind + 1 < argc) { error (0, 0, _("extra operand %s"), quote (argv[optind + 1])); usage (EXIT_FAILURE); } exit (EXIT_SUCCESS); return 0; }
CHECK_TYPE GLOBAL(PROGRAM_NAME_LOC) { initialize_main (&argc, &argv); set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); atexit (close_stdout); parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "", NULL, NULL) != -1) usage (EXIT_FAILURE); if (argc < optind + 1) { error (0, 0, _("missing operand")); usage (EXIT_FAILURE); return 0; } if (optind + 1 < argc) { error (0, 0, _("extra operand %s"), quote (argv[optind + 1])); usage (EXIT_FAILURE); return 0; } // pmr: Annotation. We know all the pertinenet facts about optind at this point, // but we don't know that unlink doesn't modify optind, so we fold it. int pmr_optind = optind; if (unlink (argv[optind]) != 0) error (EXIT_FAILURE, errno, _("cannot unlink %s"), quote (argv[pmr_optind])); exit (EXIT_SUCCESS); return 0; }
int main(int argc, char *argv[]) { /* Uncomment to debug and attach */ #if 0 int c; read(0, &c, 1); #endif parse_long_options(&argc, &argv); current_line = ibuf_init(); cgdbrc_init(); if (create_and_init_pair() == -1) { fprintf(stderr, "%s:%d Unable to create PTY pair", __FILE__, __LINE__); exit(-1); } /* First create tgdb, because it has the error log */ if (start_gdb(argc, argv) == -1) { fprintf(stderr, "%s:%d Unable to invoke GDB", __FILE__, __LINE__); exit(-1); } /* From here on, the logger is initialized */ /* Create the home directory */ if (init_home_dir() == -1) { logger_write_pos(logger, __FILE__, __LINE__, "Unable to create home dir ~/.cgdb"); cleanup(); exit(-1); } if (init_readline() == -1) { logger_write_pos(logger, __FILE__, __LINE__, "Unable to init readline"); cleanup(); exit(-1); } if (tty_cbreak(STDIN_FILENO, &term_attributes) == -1) { logger_write_pos(logger, __FILE__, __LINE__, "tty_cbreak error"); cleanup(); exit(-1); } if (init_kui() == -1) { logger_write_pos(logger, __FILE__, __LINE__, "init_kui error"); cleanup(); exit(-1); } /* Initialize the display */ switch (if_init()) { case 1: logger_write_pos(logger, __FILE__, __LINE__, "Unable to initialize the curses library"); cleanup(); exit(-1); case 2: logger_write_pos(logger, __FILE__, __LINE__, "Unable to handle signal: SIGWINCH"); cleanup(); exit(-1); case 3: logger_write_pos(logger, __FILE__, __LINE__, "Unable to setup highlighting groups"); cleanup(); exit(-1); case 4: logger_write_pos(logger, __FILE__, __LINE__, "New GDB window failed -- out of memory?"); cleanup(); exit(-1); } /* Initialize the pipe that is used for resize */ if (init_resize_pipe() == -1) { logger_write_pos(logger, __FILE__, __LINE__, "init_resize_pipe error"); cleanup(); exit(-1); } { char config_file[FSUTIL_PATH_MAX]; FILE *config; fs_util_get_path(cgdb_home_dir, "cgdbrc", config_file); config = fopen(config_file, "r"); if (config) { command_parse_file(config); fclose(config); } } /* Enter main loop */ main_loop(); /* Shut down curses and exit */ cleanup(); return 0; }
/* * getopt_internal -- * Parse argc/argv argument vector. Called by user level routines. */ static int getopt_internal(int nargc, char * const *nargv, const char *options, const struct option *long_options, int *idx, int flags) { char *oli; /* option letter list index */ int optchar, short_too; static int posixly_correct = -1; if (options == NULL) return (-1); /* * Disable GNU extensions if POSIXLY_CORRECT is set or options * string begins with a '+'. */ if (posixly_correct == -1) posixly_correct = (getenv("POSIXLY_CORRECT") != NULL); if (posixly_correct || *options == '+') flags &= ~FLAG_PERMUTE; else if (*options == '-') flags |= FLAG_ALLARGS; if (*options == '+' || *options == '-') options++; /* * XXX Some GNU programs (like cvs) set optind to 0 instead of * XXX using optreset. Work around this braindamage. */ if (optind == 0) optind = optreset = 1; optarg = NULL; if (optreset) nonopt_start = nonopt_end = -1; start: if (optreset || !*place) { /* update scanning pointer */ optreset = 0; if (optind >= nargc) { /* end of argument vector */ place = EMSG; if (nonopt_end != -1) { /* do permutation, if we have to */ permute_args(nonopt_start, nonopt_end, optind, nargv); optind -= nonopt_end - nonopt_start; } else if (nonopt_start != -1) { /* * If we skipped non-options, set optind * to the first of them. */ optind = nonopt_start; } nonopt_start = nonopt_end = -1; return (-1); } if (*(place = nargv[optind]) != '-' || (place[1] == '\0' && strchr(options, '-') == NULL)) { place = EMSG; /* found non-option */ if (flags & FLAG_ALLARGS) { /* * GNU extension: * return non-option as argument to option 1 */ optarg = nargv[optind++]; return (INORDER); } if (!(flags & FLAG_PERMUTE)) { /* * If no permutation wanted, stop parsing * at first non-option. */ return (-1); } /* do permutation */ if (nonopt_start == -1) nonopt_start = optind; else if (nonopt_end != -1) { permute_args(nonopt_start, nonopt_end, optind, nargv); nonopt_start = optind - (nonopt_end - nonopt_start); nonopt_end = -1; } optind++; /* process next argument */ goto start; } if (nonopt_start != -1 && nonopt_end == -1) nonopt_end = optind; /* * If we have "-" do nothing, if "--" we are done. */ if (place[1] != '\0' && *++place == '-' && place[1] == '\0') { optind++; place = EMSG; /* * We found an option (--), so if we skipped * non-options, we have to permute. */ if (nonopt_end != -1) { permute_args(nonopt_start, nonopt_end, optind, nargv); optind -= nonopt_end - nonopt_start; } nonopt_start = nonopt_end = -1; return (-1); } } /* * Check long options if: * 1) we were passed some * 2) the arg is not just "-" * 3) either the arg starts with -- we are getopt_long_only() */ if (long_options != NULL && place != nargv[optind] && (*place == '-' || (flags & FLAG_LONGONLY))) { short_too = 0; if (*place == '-') place++; /* --foo long option */ else if (*place != ':' && strchr(options, *place) != NULL) short_too = 1; /* could be short option too */ optchar = parse_long_options(nargv, options, long_options, idx, short_too); if (optchar != -1) { place = EMSG; return (optchar); } } if ((optchar = (int)*place++) == (int)':' || (optchar == (int)'-' && *place != '\0') || (oli = strchr(options, optchar)) == NULL) { /* * If the user specified "-" and '-' isn't listed in * options, return -1 (non-option) as per POSIX. * Otherwise, it is an unknown option character (or ':'). */ if (optchar == (int)'-' && *place == '\0') return (-1); if (!*place) ++optind; if (PRINT_ERROR) fprintf(stderr, illoptchar, optchar); optopt = optchar; return (BADCH); } if (long_options != NULL && optchar == 'W' && oli[1] == ';') { /* -W long-option */ if (*place) /* no space */ /* NOTHING */; else if (++optind >= nargc) { /* no arg */ place = EMSG; if (PRINT_ERROR) fprintf(stderr, recargchar, optchar); optopt = optchar; return (BADARG); } else /* white space */ place = nargv[optind]; optchar = parse_long_options(nargv, options, long_options, idx, 0); place = EMSG; return (optchar); } if (*++oli != ':') { /* doesn't take argument */ if (!*place) ++optind; } else { /* takes (optional) argument */ optarg = NULL; if (*place) /* no white space */ optarg = place; else if (oli[1] != ':') { /* arg not optional */ if (++optind >= nargc) { /* no arg */ place = EMSG; if (PRINT_ERROR) fprintf(stderr, recargchar, optchar); optopt = optchar; return (BADARG); } else optarg = nargv[optind]; } place = EMSG; ++optind; } /* dump back option letter */ return (optchar); }