int main(int argc, char **argv) { int i, c, act = ACT_FDISK; int colormode = UL_COLORMODE_AUTO; struct fdisk_context *cxt; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); fdisk_init_debug(0); cxt = fdisk_new_context(); if (!cxt) err(EXIT_FAILURE, _("failed to allocate libfdisk context")); fdisk_context_set_ask(cxt, ask_callback, NULL); while ((c = getopt(argc, argv, "b:c::C:hH:lL::sS:t:u::vV")) != -1) { switch (c) { case 'b': { size_t sz = strtou32_or_err(optarg, _("invalid sector size argument")); if (sz != 512 && sz != 1024 && sz != 2048 && sz != 4096) usage(stderr); fdisk_save_user_sector_size(cxt, sz, sz); break; } case 'C': fdisk_save_user_geometry(cxt, strtou32_or_err(optarg, _("invalid cylinders argument")), 0, 0); break; case 'c': if (optarg) { /* this setting is independent on the current * actively used label */ struct fdisk_label *lb = fdisk_context_get_label(cxt, "dos"); if (!lb) err(EXIT_FAILURE, _("not found DOS label driver")); if (strcmp(optarg, "=dos") == 0) fdisk_dos_enable_compatible(lb, TRUE); else if (strcmp(optarg, "=nondos") == 0) fdisk_dos_enable_compatible(lb, FALSE); else usage(stderr); } /* use default if no optarg specified */ break; case 'H': fdisk_save_user_geometry(cxt, 0, strtou32_or_err(optarg, _("invalid heads argument")), 0); break; case 'S': fdisk_save_user_geometry(cxt, 0, 0, strtou32_or_err(optarg, _("invalid sectors argument"))); break; case 'l': act = ACT_LIST; break; case 'L': if (optarg) colormode = colormode_or_err(optarg, _("unsupported color mode")); break; case 's': act = ACT_SHOWSIZE; break; case 't': { struct fdisk_label *lb = NULL; while (fdisk_context_next_label(cxt, &lb) == 0) fdisk_label_set_disabled(lb, 1); lb = fdisk_context_get_label(cxt, optarg); if (!lb) errx(EXIT_FAILURE, _("unsupported disklabel: %s"), optarg); fdisk_label_set_disabled(lb, 0); } case 'u': if (optarg && *optarg == '=') optarg++; if (fdisk_context_set_unit(cxt, optarg) != 0) usage(stderr); break; case 'V': case 'v': printf(UTIL_LINUX_VERSION); return EXIT_SUCCESS; case 'h': usage(stdout); default: usage(stderr); } } if (argc-optind != 1 && fdisk_has_user_device_properties(cxt)) warnx(_("The device properties (sector size and geometry) should" " be used with one specified device only.")); colors_init(colormode); switch (act) { case ACT_LIST: fdisk_context_enable_listonly(cxt, 1); if (argc > optind) { int k; for (k = optind; k < argc; k++) print_device_pt(cxt, argv[k]); } else print_all_devices_pt(cxt); break; case ACT_SHOWSIZE: /* deprecated */ if (argc - optind <= 0) usage(stderr); for (i = optind; i < argc; i++) { if (argc - optind == 1) printf("%llu\n", get_dev_blocks(argv[i])); else printf("%s: %llu\n", argv[i], get_dev_blocks(argv[i])); } break; case ACT_FDISK: if (argc-optind != 1) usage(stderr); /* Here starts interactive mode, use fdisk_{warn,info,..} functions */ color_enable(UL_COLOR_GREEN); fdisk_info(cxt, _("Welcome to fdisk (%s)."), PACKAGE_STRING); color_disable(); fdisk_info(cxt, _("Changes will remain in memory only, until you decide to write them.\n" "Be careful before using the write command.\n")); if (fdisk_context_assign_device(cxt, argv[optind], 0) != 0) err(EXIT_FAILURE, _("cannot open %s"), argv[optind]); fflush(stdout); if (!fdisk_dev_has_disklabel(cxt)) { fdisk_info(cxt, _("Device does not contain a recognized partition table.")); fdisk_create_disklabel(cxt, NULL); } else if (fdisk_is_disklabel(cxt, GPT) && fdisk_gpt_is_hybrid(cxt)) fdisk_warnx(cxt, _( "The hybrid GPT detected. You have to sync " "the hybrid MBR manually (expert command 'M').")); while (1) process_fdisk_menu(&cxt); } fdisk_free_context(cxt); return EXIT_SUCCESS; }
/** * Program entry point * * @param argc Number of argv elements * @param argv Program name and arguments * @param envp Program environment * @return <i>0</i> Success * @return <br><i>254</i> Initialization failed */ int main(int argc, char **argv, char **envp) { bk_s B = NULL; /* Baka general structure */ BK_ENTRY_MAIN(B, __FUNCTION__, __FILE__, "SIMPLE"); int c; int getopterr = 0; int debug_level = 0; char i18n_localepath[_POSIX_PATH_MAX]; char *i18n_locale; struct program_config Pconfig, *pc = NULL; poptContext optCon = NULL; struct poptOption optionsTable[] = { {"debug", 'd', POPT_ARG_NONE, NULL, 'd', N_("Turn on debugging"), NULL }, {"verbose", 'v', POPT_ARG_NONE, NULL, 'v', N_("Turn on verbose message"), NULL }, {"no-seatbelts", 0, POPT_ARG_NONE, NULL, 0x1000, N_("Sealtbelts off & speed up"), NULL }, {"seatbelts", 0, POPT_ARG_NONE, NULL, 0x1001, N_("Enable function tracing"), NULL }, {"profiling", 0, POPT_ARG_STRING, NULL, 0x1002, N_("Enable and write profiling data"), N_("filename") }, POPT_AUTOHELP POPT_TABLEEND }; if (!(B=bk_general_init(argc, &argv, &envp, BK_ENV_GWD(NULL, "BK_ENV_CONF_APP", BK_APP_CONF), NULL, ERRORQUEUE_DEPTH, LOG_LOCAL0, 0))) { fprintf(stderr,"Could not perform basic initialization\n"); exit(254); } bk_fun_reentry(B); // Enable error output bk_error_config(B, BK_GENERAL_ERROR(B), ERRORQUEUE_DEPTH, stderr, BK_ERR_ERR, BK_ERR_ERR, BK_ERROR_CONFIG_FH | BK_ERROR_CONFIG_SYSLOGTHRESHOLD | BK_ERROR_CONFIG_HILO_PIVOT); // i18n stuff setlocale(LC_ALL, ""); if (!(i18n_locale = BK_GWD(B, STD_LOCALEDIR_KEY, NULL))) { i18n_locale = i18n_localepath; snprintf(i18n_localepath, sizeof(i18n_localepath), "%s/%s", BK_ENV_GWD(B, STD_LOCALEDIR_ENV,STD_LOCALEDIR_DEF), STD_LOCALEDIR_SUB); } bindtextdomain(BK_GENERAL_PROGRAM(B), i18n_locale); textdomain(BK_GENERAL_PROGRAM(B)); for (c = 0; optionsTable[c].longName || optionsTable[c].shortName; c++) { if (optionsTable[c].descrip) (*((char **)&(optionsTable[c].descrip)))=_(optionsTable[c].descrip); if (optionsTable[c].argDescrip) (*((char **)&(optionsTable[c].argDescrip)))=_(optionsTable[c].argDescrip); } pc = &Pconfig; memset(pc, 0, sizeof(*pc)); if (!(optCon = poptGetContext(NULL, argc, (const char **)argv, optionsTable, 0))) { bk_error_printf(B, BK_ERR_ERR, "Could not initialize options processing\n"); bk_exit(B, 254); } while ((c = poptGetNextOpt(optCon)) >= 0) { switch (c) { case 'd': // debug if (!debug_level) { // Set up debugging, from config file bk_general_debug_config(B, stderr, BK_ERR_NONE, 0); bk_debug_printf(B, "Debugging on\n"); debug_level++; } else if (debug_level == 1) { /* * Enable output of error and higher error logs (this can be * annoying so require -dd) */ bk_error_config(B, BK_GENERAL_ERROR(B), 0, stderr, BK_ERR_NONE, BK_ERR_ERR, BK_ERROR_CONFIG_FH | BK_ERROR_CONFIG_HILO_PIVOT | BK_ERROR_CONFIG_SYSLOGTHRESHOLD); bk_debug_printf(B, "Extra debugging on\n"); debug_level++; } else if (debug_level == 2) { /* * Enable output of all levels of bk_error logs (this can be * very annoying so require -ddd) */ bk_error_config(B, BK_GENERAL_ERROR(B), 0, stderr, BK_ERR_NONE, BK_ERR_DEBUG, BK_ERROR_CONFIG_FH | BK_ERROR_CONFIG_HILO_PIVOT | BK_ERROR_CONFIG_SYSLOGTHRESHOLD); bk_debug_printf(B, "Super-extra debugging on\n"); debug_level++; } break; case 'v': // verbose BK_FLAG_SET(pc->pc_flags, PC_VERBOSE); bk_error_config(B, BK_GENERAL_ERROR(B), ERRORQUEUE_DEPTH, stderr, BK_ERR_NONE, BK_ERR_ERR, 0); break; case 0x1000: // no-seatbelts BK_FLAG_CLEAR(BK_GENERAL_FLAGS(B), BK_BGFLAGS_FUNON); break; case 0x1001: // seatbelts BK_FLAG_SET(BK_GENERAL_FLAGS(B), BK_BGFLAGS_FUNON); break; case 0x1002: // profiling bk_general_funstat_init(B, (char *)poptGetOptArg(optCon), 0); break; default: getopterr++; break; } } /* * Reprocess so that argc and argv contain the remaining command * line arguments (note argv[0] is an argument, not the program * name). argc remains the number of elements in the argv array. */ argv = (char **)poptGetArgs(optCon); argc = 0; if (argv) for (; argv[argc]; argc++) ; // Void if (c < -1 || getopterr) { if (c < -1) { fprintf(stderr, "%s\n", poptStrerror(c)); } poptPrintUsage(optCon, stderr, 0); bk_exit(B, 254); } progrun(B, pc); poptFreeContext(optCon); bk_exit(B, 0); return(255); // Stupid INSIGHT stuff. }
int main(int argc, char *argv[]) { /* Workaround Qt platform integration plugin not advertising itself as having the following capabilities: - QPlatformIntegration::ThreadedOpenGL - QPlatformIntegration::BufferQueueingOpenGL */ setenv("QML_FORCE_THREADED_RENDERER", "1", 1); setenv("QML_FIXED_ANIMATION_STEP", "1", 1); // ignore favorites in unity-scopes-shell plugin setenv("UNITY_SCOPES_NO_FAVORITES", "1", 1); QGuiApplication::setApplicationName("Unity Scope Tool"); QGuiApplication *application; application = new QGuiApplication(argc, argv); QCommandLineParser parser; parser.setApplicationDescription("Unity Scope Tool\n\n" "This tool allows development and testing of scopes. Running it without\n" "any arguments will open a session to all scopes available on the system.\n" "Otherwise passing a path to a scope config file will open a session with\n" "only that scope (assuming that the binary implementing the scope can be\n" "found in the same directory as the config file)."); QCommandLineOption helpOption = parser.addHelpOption(); parser.addPositionalArgument("scopes", "Paths to scope config files to spawn, optionally.", "[scopes...]"); QCommandLineOption includeSystemScopes("include-system-scopes", "Initialize the registry with scopes installed on this system"); QCommandLineOption includeServerScopes("include-server-scopes", "Initialize the registry with scopes on the default server"); parser.addOption(includeServerScopes); parser.addOption(includeSystemScopes); parser.parse(application->arguments()); if (parser.isSet(helpOption)) { parser.showHelp(); } QStringList extraScopes = parser.positionalArguments(); QScopedPointer<RegistryTracker> tracker; if (!extraScopes.isEmpty()) { bool systemScopes = parser.isSet(includeSystemScopes); bool serverScopes = parser.isSet(includeServerScopes); tracker.reset(new RegistryTracker(extraScopes, systemScopes, serverScopes)); } bindtextdomain("unity8", translationDirectory().toUtf8().data()); textdomain("unity8"); QQuickView* view = new QQuickView(); view->setResizeMode(QQuickView::SizeRootObjectToView); view->setTitle(QGuiApplication::applicationName()); view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory())); QUrl source(::qmlDirectory() + "/ScopeTool.qml"); prependImportPaths(view->engine(), ::overrideImportPaths()); prependImportPaths(view->engine(), ::nonMirImportPaths()); appendImportPaths(view->engine(), ::fallbackImportPaths()); view->setSource(source); view->show(); UnixSignalHandler signal_handler([]{ QGuiApplication::exit(0); }); signal_handler.setupUnixSignalHandlers(); int result = application->exec(); delete view; delete application; return result; }
int main (int argc, char *argv[]) { gboolean gui_possible; int c; int option_index; char **cmdline = NULL; int cmdline_source = 0; struct config *config = new_config (); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEBASEDIR); textdomain (PACKAGE); #if ! GLIB_CHECK_VERSION(2,32,0) /* In glib2 < 2.32 you had to call g_thread_init(). In later glib2 * that is not required and should not be called. */ if (glib_check_version (2, 32, 0) != NULL) /* This checks < 2.32 */ g_thread_init (NULL); #endif gdk_threads_init (); gdk_threads_enter (); gui_possible = gtk_init_check (&argc, &argv); for (;;) { c = getopt_long (argc, argv, options, long_options, &option_index); if (c == -1) break; switch (c) { case 0: /* options which are long only */ if (STREQ (long_options[option_index].name, "long-options")) { display_long_options (long_options); } else if (STREQ (long_options[option_index].name, "short-options")) { display_short_options (options); } else if (STREQ (long_options[option_index].name, "cmdline")) { cmdline = parse_cmdline_string (optarg); cmdline_source = CMDLINE_SOURCE_COMMAND_LINE; } else { fprintf (stderr, _("%s: unknown long option: %s (%d)\n"), guestfs_int_program_name, long_options[option_index].name, option_index); exit (EXIT_FAILURE); } break; case 'v': config->verbose = 1; break; case 'V': printf ("%s %s%s\n", guestfs_int_program_name, PACKAGE_VERSION, PACKAGE_VERSION_EXTRA); exit (EXIT_SUCCESS); case HELP_OPTION: usage (EXIT_SUCCESS); default: usage (EXIT_FAILURE); } } if (optind != argc) { fprintf (stderr, _("%s: unused arguments on the command line\n"), guestfs_int_program_name); usage (EXIT_FAILURE); } set_config_defaults (config); /* If /proc/cmdline exists and contains "p2v.server=" then we enable * non-interactive configuration. * If /proc/cmdline contains p2v.debug then we enable verbose mode * even for interactive configuration. */ if (cmdline == NULL) { cmdline = parse_proc_cmdline (); if (cmdline == NULL) goto gui; cmdline_source = CMDLINE_SOURCE_PROC_CMDLINE; } if (get_cmdline_key (cmdline, "p2v.debug") != NULL) config->verbose = 1; if (get_cmdline_key (cmdline, "p2v.server") != NULL) kernel_configuration (config, cmdline, cmdline_source); else { gui: if (!gui_possible) { fprintf (stderr, _("%s: gtk_init_check returned false, indicating that\n" "a GUI is not possible on this host. Check X11, $DISPLAY etc.\n"), guestfs_int_program_name); exit (EXIT_FAILURE); } gui_application (config); } guestfs_int_free_string_list (cmdline); exit (EXIT_SUCCESS); }
int main(int argc, char **argv) { int optind; char **playlist_array; int items; struct stat stat_buf; int i; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); ao_initialize(); stat_format = stat_format_create(); options_init(&options); file_options_init(file_opts); parse_std_configs(file_opts); options.playlist = playlist_create(); optind = parse_cmdline_options(argc, argv, &options, file_opts); audio_play_arg.devices = options.devices; audio_play_arg.stat_format = stat_format; /* Add remaining arguments to playlist */ for (i = optind; i < argc; i++) { if (stat(argv[i], &stat_buf) == 0) { if (S_ISDIR(stat_buf.st_mode)) { if (playlist_append_directory(options.playlist, argv[i]) == 0) fprintf(stderr, _("WARNING: Could not read directory %s.\n"), argv[i]); } else { playlist_append_file(options.playlist, argv[i]); } } else /* If we can't stat it, it might be a non-disk source */ playlist_append_file(options.playlist, argv[i]); } /* Do we have anything left to play? */ if (playlist_length(options.playlist) == 0) { cmdline_usage(); exit(1); } else { playlist_array = playlist_to_array(options.playlist, &items); playlist_destroy(options.playlist); options.playlist = NULL; } /* Don't use status_message until after this point! */ status_init(options.verbosity); print_audio_devices_info(options.devices); /* Setup buffer */ if (options.buffer_size > 0) { /* Keep sample size alignment for surround sound with up to 10 channels */ options.buffer_size = (options.buffer_size + PRIMAGIC - 1) / PRIMAGIC * PRIMAGIC; audio_buffer = buffer_create(options.buffer_size, options.buffer_size * options.prebuffer / 100, audio_play_callback, &audio_play_arg, AUDIO_CHUNK_SIZE); if (audio_buffer == NULL) { status_error(_("Error: Could not create audio buffer.\n")); exit(1); } } else audio_buffer = NULL; /* Setup signal handlers and callbacks */ signal (SIGINT, signal_handler); signal (SIGTSTP, signal_handler); signal (SIGCONT, signal_handler); signal (SIGTERM, signal_handler); if (options.remote) { /* run the mainloop for the remote interface */ remote_mainloop(); } else { do { /* Shuffle playlist */ if (options.shuffle) { int i; srandom(time(NULL)); for (i = 0; i < items; i++) { int j = i + random() % (items - i); char *temp = playlist_array[i]; playlist_array[i] = playlist_array[j]; playlist_array[j] = temp; } } /* Play the files/streams */ i = 0; while (i < items && !sig_request.exit) { play(playlist_array[i]); i++; } } while (options.repeat); } playlist_array_destroy(playlist_array, items); status_deinit(); if (audio_buffer != NULL) { buffer_destroy (audio_buffer); audio_buffer = NULL; } ao_onexit (options.devices); exit (exit_status); }
int main(int argc, char *argv[]) { int status = 0; int print = 0; char *mapName = NULL; char *saveName = NULL; char *dirName = NULL; char opt; int count; setlocale(LC_ALL, getenv(ENV_LANG)); textdomain("keymap"); // Graphics enabled? graphics = graphicsAreEnabled(); // Check options while (strchr("psT:?", (opt = getopt(argc, argv, "ps:T")))) { switch (opt) { case 'p': // Just print out the map, if we're in text mode print = 1; break; case 's': // Save the map to a file if (!optarg) { fprintf(stderr, "%s", _("Missing filename argument for -s " "option\n")); usage(argv[0]); return (status = ERR_NULLPARAMETER); } saveName = optarg; break; case 'T': // Force text mode graphics = 0; break; case ':': fprintf(stderr, _("Missing parameter for %s option\n"), argv[optind - 1]); usage(argv[0]); return (status = ERR_NULLPARAMETER); default: fprintf(stderr, _("Unknown option '%c'\n"), optopt); usage(argv[0]); return (status = ERR_INVALID); } } cwd = malloc(MAX_PATH_LENGTH); selectedMap = malloc(sizeof(keyMap)); if (!cwd || !selectedMap) { status = ERR_MEMORY; goto out; } strncpy(cwd, PATH_SYSTEM_KEYMAPS, MAX_PATH_LENGTH); // Get the current map status = keyboardGetMap(selectedMap); if (status < 0) goto out; strncpy(currentName, selectedMap->name, KEYMAP_NAMELEN); mapName = selectedMap->name; // Did the user supply either a map name or a key map file name? if ((argc > 1) && (optind < argc)) { // Is it a file name? status = fileFind(argv[optind], NULL); if (status >= 0) { status = readMap(argv[optind], selectedMap); if (status < 0) goto out; mapName = selectedMap->name; dirName = dirname(argv[optind]); if (dirName) { strncpy(cwd, dirName, MAX_PATH_LENGTH); free(dirName); } } else { // Assume we've been given a map name. mapName = argv[optind]; } if (!graphics && !saveName && !print) { // The user wants to set the current keyboard map to the supplied // name. status = setMap(mapName); goto out; } // Load the supplied map name status = loadMap(mapName); if (status < 0) goto out; } keyArray = malloc(KEYBOARD_SCAN_CODES * sizeof(scanKey)); if (!keyArray) { status = ERR_MEMORY; goto out; } // Make the initial key array based on the current map. makeKeyArray(selectedMap); if (saveName) { // The user wants to save the current keyboard map to the supplied // file name. status = saveMap(saveName); goto out; } status = getMapNameParams(); if (status < 0) goto out; if (graphics) { // Make our window constructWindow(); // Run the GUI windowGuiRun(); // ...and when we come back... windowDestroy(window); } else { if (print) { // Print out the whole keyboard for the selected map printKeyboard(); } else { // Just print the list of map names printf("\n"); for (count = 0; count < numMapNames; count ++) printf("%s%s\n", mapListParams[count].text, (!strcmp(mapListParams[count].text, selectedMap->name)? _(" (current)") : "")); } } status = 0; out: if (cwd) free(cwd); if (selectedMap) free(selectedMap); if (mapListParams) free(mapListParams); if (keyArray) free(keyArray); return (status); }
int main(int argc, char **argv) { int c; int fd; int mode = 0; int dig = 0; loff_t length = -2LL; loff_t offset = 0; static const struct option longopts[] = { { "help", 0, 0, 'h' }, { "version", 0, 0, 'V' }, { "keep-size", 0, 0, 'n' }, { "punch-hole", 0, 0, 'p' }, { "collapse-range", 0, 0, 'c' }, { "dig-holes", 0, 0, 'd' }, { "zero-range", 0, 0, 'z' }, { "offset", 1, 0, 'o' }, { "length", 1, 0, 'l' }, { "verbose", 0, 0, 'v' }, { NULL, 0, 0, 0 } }; static const ul_excl_t excl[] = { /* rows and cols in in ASCII order */ { 'c', 'd', 'p', 'z' }, { 'c', 'n' }, { 0 } }; int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); while ((c = getopt_long(argc, argv, "hvVncpdzl:o:", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); switch(c) { case 'h': usage(stdout); break; case 'c': mode |= FALLOC_FL_COLLAPSE_RANGE; break; case 'd': dig = 1; break; case 'l': length = cvtnum(optarg); break; case 'n': mode |= FALLOC_FL_KEEP_SIZE; break; case 'o': offset = cvtnum(optarg); break; case 'p': mode |= FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE; break; case 'z': mode |= FALLOC_FL_ZERO_RANGE; break; case 'v': verbose++; break; case 'V': printf(UTIL_LINUX_VERSION); return EXIT_SUCCESS; default: usage(stderr); break; } } if (optind == argc) errx(EXIT_FAILURE, _("no filename specified")); filename = argv[optind++]; if (optind != argc) errx(EXIT_FAILURE, _("unexpected number of arguments")); if (dig) { /* for --dig-holes the default is analyze all file */ if (length == -2LL) length = 0; if (length < 0) errx(EXIT_FAILURE, _("invalid length value specified")); } else { /* it's safer to require the range specification (--length --offset) */ if (length == -2LL) errx(EXIT_FAILURE, _("no length argument specified")); if (length <= 0) errx(EXIT_FAILURE, _("invalid length value specified")); } if (offset < 0) errx(EXIT_FAILURE, _("invalid offset value specified")); /* O_CREAT makes sense only for the default fallocate(2) behavior * when mode is no specified and new space is allocated */ fd = open(filename, O_RDWR | (!dig && !mode ? O_CREAT : 0), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (fd < 0) err(EXIT_FAILURE, _("cannot open %s"), filename); if (dig) dig_holes(fd, offset, length); else xfallocate(fd, mode, offset, length); if (close_fd(fd) != 0) err(EXIT_FAILURE, _("write failed: %s"), filename); return EXIT_SUCCESS; }
int main (gint argc, gchar *argv[]) { TrackerConfig *config; TrackerMiner *miner_files; TrackerMinerFilesIndex *miner_files_index; GOptionContext *context; GError *error = NULL; gchar *log_filename = NULL; gboolean do_mtime_checking; gboolean do_crawling; gboolean force_mtime_checking = FALSE; gboolean store_available; main_loop = NULL; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Set timezone info */ tzset (); /* Translators: this messagge will apper immediately after the * usage string - Usage: COMMAND <THIS_MESSAGE> */ context = g_option_context_new (_("- start the tracker indexer")); g_option_context_add_main_entries (context, entries, NULL); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (error) { g_printerr ("%s\n", error->message); g_error_free (error); return EXIT_FAILURE; } if (version) { g_print ("\n" ABOUT "\n" LICENSE "\n"); return EXIT_SUCCESS; } if (eligible) { check_eligible (); return EXIT_SUCCESS; } /* Initialize logging */ config = tracker_config_new (); if (verbosity > -1) { tracker_config_set_verbosity (config, verbosity); } if (initial_sleep > -1) { tracker_config_set_initial_sleep (config, initial_sleep); } tracker_log_init (tracker_config_get_verbosity (config), &log_filename); if (log_filename) { g_message ("Using log file:'%s'", log_filename); g_free (log_filename); } sanity_check_option_values (config); /* This makes sure we don't steal all the system's resources */ initialize_priority_and_scheduling (tracker_config_get_sched_idle (config), tracker_db_manager_get_first_index_done () == FALSE); main_loop = g_main_loop_new (NULL, FALSE); g_message ("Checking if we're running as a daemon:"); g_message (" %s %s", no_daemon ? "No" : "Yes", no_daemon ? "(forced by command line)" : ""); /* Create new TrackerMinerFiles object */ miner_files = tracker_miner_files_new (config, &error); if (!miner_files) { g_critical ("Couldn't create new Files miner: '%s'", error ? error->message : "unknown error"); g_object_unref (config); tracker_log_shutdown (); return EXIT_FAILURE; } tracker_writeback_init (TRACKER_MINER_FILES (miner_files), config, &error); if (error) { g_critical ("Couldn't create writeback handling: '%s'", error ? error->message : "unknown error"); g_object_unref (config); g_object_unref (miner_files); tracker_log_shutdown (); g_array_free (disable_options, TRUE); return EXIT_FAILURE; } /* Create new TrackerMinerFilesIndex object */ miner_files_index = tracker_miner_files_index_new (TRACKER_MINER_FILES (miner_files)); if (!miner_files_index) { g_object_unref (miner_files); tracker_writeback_shutdown (); g_object_unref (config); tracker_log_shutdown (); return EXIT_FAILURE; } /* Check if we should crawl and if we should force mtime * checking based on the config. */ do_crawling = should_crawl (config, &force_mtime_checking); /* Get the last shutdown state to see if we need to perform a * full mtime check against the db or not. * * Set to TRUE here in case we crash and miss file system * events. */ g_message ("Checking whether to force mtime checking during crawling (based on last clean shutdown):"); /* Override the shutdown state decision based on the config */ if (force_mtime_checking) { do_mtime_checking = TRUE; } else { do_mtime_checking = tracker_db_manager_get_need_mtime_check (); } g_message (" %s %s", do_mtime_checking ? "Yes" : "No", force_mtime_checking ? "(forced from config)" : ""); /* Set the need for an mtime check to TRUE so we check in the * event of a crash, this is changed back on shutdown if * everything appears to be fine. */ tracker_db_manager_set_need_mtime_check (TRUE); /* Configure files miner */ tracker_miner_fs_set_initial_crawling (TRACKER_MINER_FS (miner_files), do_crawling); tracker_miner_fs_set_mtime_checking (TRACKER_MINER_FS (miner_files), do_mtime_checking); g_signal_connect (miner_files, "finished", G_CALLBACK (miner_finished_cb), NULL); miners = g_slist_prepend (miners, miner_files); miner_handle_first (config, do_mtime_checking); initialize_signal_handler (); /* Go, go, go! */ g_main_loop_run (main_loop); g_message ("Shutdown started"); store_available = store_is_available (); if (miners_timeout_id == 0 && !miner_needs_check (miner_files, store_available)) { tracker_db_manager_set_need_mtime_check (FALSE); } g_main_loop_unref (main_loop); g_object_unref (config); g_object_unref (miner_files_index); g_slist_foreach (miners, (GFunc) finalize_miner, NULL); g_slist_free (miners); tracker_writeback_shutdown (); tracker_log_shutdown (); g_print ("\nOK\n\n"); return EXIT_SUCCESS; }
int main(int argc, char **argv) { int ch; struct iovec iov; struct utmp *utmpptr; char *p; char line[sizeof(utmpptr->ut_line) + 1]; int print_banner = TRUE; char *mbuf, *fname = NULL; size_t mbufsize; unsigned timeout = WRITE_TIME_OUT; char **mvec = NULL; int mvecsz = 0; static const struct option longopts[] = { { "nobanner", no_argument, 0, 'n' }, { "timeout", required_argument, 0, 't' }, { "version", no_argument, 0, 'V' }, { "help", no_argument, 0, 'h' }, { NULL, 0, 0, 0 } }; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); while ((ch = getopt_long(argc, argv, "nt:Vh", longopts, NULL)) != -1) { switch (ch) { case 'n': if (geteuid() == 0) print_banner = FALSE; else warnx(_("--nobanner is available only for root")); break; case 't': timeout = strtou32_or_err(optarg, _("invalid timeout argument")); if (timeout < 1) errx(EXIT_FAILURE, _("invalid timeout argument: %s"), optarg); break; case 'V': printf(UTIL_LINUX_VERSION); exit(EXIT_SUCCESS); case 'h': usage(stdout); default: usage(stderr); } } argc -= optind; argv += optind; if (argc == 1 && access(argv[0], F_OK) == 0) fname = argv[0]; else if (argc >= 1) { mvec = argv; mvecsz = argc; } mbuf = makemsg(fname, mvec, mvecsz, &mbufsize, print_banner); iov.iov_base = mbuf; iov.iov_len = mbufsize; while((utmpptr = getutent())) { if (!utmpptr->ut_user[0]) continue; #ifdef USER_PROCESS if (utmpptr->ut_type != USER_PROCESS) continue; #endif /* Joey Hess reports that use-sessreg in /etc/X11/wdm/ produces ut_line entries like :0, and a write to /dev/:0 fails. */ if (utmpptr->ut_line[0] == ':') continue; xstrncpy(line, utmpptr->ut_line, sizeof(utmpptr->ut_line)); if ((p = ttymsg(&iov, 1, line, timeout)) != NULL) warnx("%s", p); } endutent(); free(mbuf); exit(EXIT_SUCCESS); }
int main (int argc, char **argv) { gboolean arg_version = FALSE; gboolean arg_display_properties = FALSE; gboolean arg_display_about = FALSE; gboolean arg_consider_new_mail_as_read = FALSE; gboolean arg_update = FALSE; gboolean arg_print_summary = FALSE; gboolean arg_unset_obsolete_configuration = FALSE; gboolean arg_quit = FALSE; const GOptionEntry options[] = { { "version", 'v', 0, G_OPTION_ARG_NONE, &arg_version, N_("Show version information"), NULL }, { "enable-info", 'i', 0, G_OPTION_ARG_NONE, &arg_enable_info, N_("Enable informational output"), NULL }, { "display-properties", 'p', 0, G_OPTION_ARG_NONE, &arg_display_properties, N_("Display the properties dialog"), NULL }, { "display-about", 'a', 0, G_OPTION_ARG_NONE, &arg_display_about, N_("Display the about dialog"), NULL }, { "consider-new-mail-as-read", 'r', 0, G_OPTION_ARG_NONE, &arg_consider_new_mail_as_read, N_("Consider new mail as read"), NULL }, { "update", 'u', 0, G_OPTION_ARG_NONE, &arg_update, N_("Update the mail status"), NULL }, { "print-summary", 's', 0, G_OPTION_ARG_NONE, &arg_print_summary, N_("Print a XML mail summary"), NULL }, { "unset-obsolete-configuration", '\0', 0, G_OPTION_ARG_NONE, &arg_unset_obsolete_configuration, N_("Unset obsolete GConf configuration"), NULL }, { "quit", 'q', 0, G_OPTION_ARG_NONE, &arg_quit, N_("Quit Mail Notification"), NULL }, { NULL } }; GOptionContext *option_context; DBusGConnection *bus; DBusGProxy *bus_proxy; g_log_set_fatal_mask(NULL, G_LOG_LEVEL_CRITICAL); g_log_set_handler(NULL, G_LOG_LEVEL_INFO, info_log_cb, NULL); #ifdef ENABLE_NLS bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); #endif g_set_application_name(_("Mail Notification")); g_thread_init(NULL); if (! g_thread_supported()) /* * We cannot use mn_fatal_error_dialog() because gtk_init() has * not been called yet. */ g_critical(_("multi-threading is not available")); gdk_threads_init(); GDK_THREADS_ENTER(); option_context = g_option_context_new(NULL); g_option_context_add_main_entries(option_context, options, GETTEXT_PACKAGE); gnome_program_init(PACKAGE, VERSION, LIBGNOME_MODULE, argc, argv, GNOME_PARAM_HUMAN_READABLE_NAME, _("Mail Notification"), GNOME_PROGRAM_STANDARD_PROPERTIES, GNOME_PARAM_GOPTION_CONTEXT, option_context, NULL); gtk_init(&argc, &argv); if (arg_version) { print_version(); goto end; } if (arg_unset_obsolete_configuration) { mn_conf_unset_obsolete(); goto end; } ensure_icon_path(); gtk_window_set_default_icon_name("mail-notification"); mn_stock_init(); bus = connect_to_session_bus(); bus_proxy = get_bus_proxy(bus); if (mn_server_start(bus, bus_proxy)) /* not already running */ { if (arg_quit) g_message(_("Mail Notification is not running")); else { mn_mailbox_init_types(); #if WITH_MBOX || WITH_MOZILLA || WITH_MH || WITH_MAILDIR || WITH_SYLPHEED mn_vfs_mailbox_init_types(); #endif /* mn-client-session uses sockets, we don't want to die on SIGPIPE */ signal(SIGPIPE, SIG_IGN); if (! gnome_vfs_init()) mn_show_fatal_error_dialog(NULL, _("Unable to initialize the GnomeVFS library.")); #if !GTK_CHECK_VERSION(3,0,0) gnome_authentication_manager_init(); #endif /* must be called before init_gmime() */ mn_conf_init(); #if WITH_GMIME init_gmime(); #endif if (! notify_init(_("Mail Notification"))) mn_show_error_dialog(NULL, _("An initialization error has occurred in Mail Notification"), _("Unable to initialize the notification library. Message popups will not be displayed.")); /* * Work around * http://bugzilla.gnome.org/show_bug.cgi?id=64764: * initialize the classes we will be using concurrently * before any thread is created. */ init_classes(); mn_shell_new(bus, bus_proxy); /* also display the properties dialog if there are no mailboxes */ if (! mn_shell->mailboxes->list) arg_display_properties = TRUE; if (arg_display_properties) mn_shell_show_properties_dialog(mn_shell, 0); if (arg_display_about) mn_shell_show_about_dialog(mn_shell, 0); if (arg_consider_new_mail_as_read) report_option_ignored("--consider-new-mail-as-read"); if (arg_update) report_option_ignored("--update"); if (arg_print_summary) report_option_ignored("--print-summary"); /* in case no window has been displayed */ gdk_notify_startup_complete(); gtk_main(); } } else /* already running */ { DBusGProxy *proxy; GError *err = NULL; proxy = dbus_g_proxy_new_for_name(bus, MN_SERVER_SERVICE, MN_SERVER_PATH, MN_SERVER_INTERFACE); if (arg_quit) { g_message(_("quitting Mail Notification")); CALL_SERVER(org_gnome_MailNotification_quit(proxy, &err)); } else { /* also display the properties dialog if there are no mailboxes */ if (! arg_display_properties) { gboolean has; CALL_SERVER(org_gnome_MailNotification_has_mailboxes(proxy, &has, &err)); arg_display_properties = ! has; } if (arg_display_properties) CALL_SERVER(org_gnome_MailNotification_display_properties(proxy, &err)); if (arg_display_about) CALL_SERVER(org_gnome_MailNotification_display_about(proxy, &err)); if (arg_consider_new_mail_as_read) { g_message(_("considering new mail as read")); CALL_SERVER(org_gnome_MailNotification_consider_new_mail_as_read(proxy, &err)); } if (arg_update) { g_message(_("updating the mail status")); CALL_SERVER(org_gnome_MailNotification_update(proxy, &err)); } if (arg_print_summary) { char *summary; CALL_SERVER(org_gnome_MailNotification_get_summary(proxy, &summary, &err)); g_print("%s", summary); g_free(summary); } if (! (arg_display_properties || arg_display_about || arg_consider_new_mail_as_read || arg_update || arg_print_summary)) g_message(_("Mail Notification is already running")); } /* * Do not unref the proxy, since it might break when the * DBusGProxy memory management issue is fixed * (https://bugs.freedesktop.org/show_bug.cgi?id=14030). */ /* no window has been displayed by this process */ gdk_notify_startup_complete(); } end: GDK_THREADS_LEAVE(); return 0; }
int main (int argc, char *argv[]) { struct sigaction sig_callback; g_thread_init (NULL); gdk_threads_init (); gtk_init (&argc, &argv); bindtextdomain (GETTEXT_PACKAGE, SNES9XLOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); memset (&Settings, 0, sizeof (Settings)); /* Allow original config file for backend settings */ S9xLoadConfigFiles (argv, argc); /* Perform our config here */ gui_config = new Snes9xConfig (); S9xInitInputDevices (); gui_config->load_config_file (); char *rom_filename = S9xParseArgs (argv, argc); S9xReportControllers (); if (!Memory.Init () || !S9xInitAPU ()) exit (3); g_set_application_name ("Snes9x"); top_level = new Snes9xWindow (gui_config); /* If we're going to fullscreen, do it before showing window to avoid flicker. */ if ((gui_config->full_screen_on_open && rom_filename) || (gui_config->fullscreen)) gtk_window_fullscreen (top_level->get_window ()); top_level->show (); S9xInitDisplay (argc, argv); Memory.PostRomInitFunc = S9xPostRomInit; S9xPortSoundInit (); gui_config->reconfigure (); top_level->update_accels (); Settings.Paused = TRUE; syncing = 0; idle_func_id = g_idle_add_full (IDLE_FUNC_PRIORITY, S9xIdleFunc, NULL, NULL); g_timeout_add (10000, S9xScreenSaverCheckFunc, NULL); S9xNoROMLoaded (); if (rom_filename) { if (S9xOpenROM (rom_filename) && gui_config->full_screen_on_open) gtk_window_unfullscreen (top_level->get_window()); } memset (&sig_callback, 0, sizeof (struct sigaction)); sig_callback.sa_handler = S9xTerm; sigaction (15 /* SIGTERM */, &sig_callback, NULL); sigaction (3 /* SIGQUIT */, &sig_callback, NULL); sigaction (2 /* SIGINT */, &sig_callback, NULL); if (gui_config->fullscreen) { gui_config->fullscreen = 0; needs_fullscreening = 1; } #ifdef USE_JOYSTICK gui_config->flush_joysticks (); #endif gtk_window_present (top_level->get_window ()); gtk_main (); return 0; }
/** * main: **/ int main (int argc, char *argv[]) { AsAppValidateFlags validate_flags = 0; gboolean nonet = FALSE; gboolean relax = FALSE; gboolean ret; gboolean strict = FALSE; gboolean verbose = FALSE; gboolean version = FALSE; gchar *filename = NULL; gchar *output_format = NULL; GError *error = NULL; gint i; gint retval = EXIT_CODE_SUCCESS; gint retval_tmp; GOptionContext *context; const GOptionEntry options[] = { { "relax", 'r', 0, G_OPTION_ARG_NONE, &relax, /* TRANSLATORS: this is the --relax argument */ _("Be less strict when checking files"), NULL }, { "strict", 's', 0, G_OPTION_ARG_NONE, &strict, /* TRANSLATORS: this is the --relax argument */ _("Be more strict when checking files"), NULL }, { "nonet", '\0', 0, G_OPTION_ARG_NONE, &nonet, /* TRANSLATORS: this is the --nonet argument */ _("Do not use network access"), NULL }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, /* TRANSLATORS: this is the --verbose argument */ _("Show extra debugging information"), NULL }, { "version", '\0', 0, G_OPTION_ARG_NONE, &version, /* TRANSLATORS: this is the --version argument */ _("Show the version number and then quit"), NULL }, { "filename", '\0', 0, G_OPTION_ARG_STRING, &filename, /* TRANSLATORS: this is the --filename argument */ _("The source filename when using a temporary file"), NULL }, { "output-format", '\0', 0, G_OPTION_ARG_STRING, &output_format, /* TRANSLATORS: this is the --output-format argument */ _("The output format [text|html|xml]"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #if !GLIB_CHECK_VERSION(2,36,0) g_type_init (); #endif context = g_option_context_new ("AppData Validation Program"); g_option_context_add_main_entries (context, options, NULL); ret = g_option_context_parse (context, &argc, &argv, &error); if (!ret) { /* TRANSLATORS: this is where the user used unknown command * line switches -- the exact error follows */ g_print ("%s %s\n", _("Failed to parse command line:"), error->message); g_error_free (error); goto out; } /* big fat warning */ g_print ("THIS TOOL IS *DEPRECATED* AND WILL BE REMOVED SOON.\n"); g_print ("Please use 'apstream-util validate' in appstream-glib.\n\n"); /* just show the version */ if (version) { g_print ("%s\n", PACKAGE_VERSION); goto out; } /* verbose? */ if (verbose) { g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL); g_log_set_handler ("AppDataTools", G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_WARNING, appdata_validate_log_handler_cb, NULL); } else { /* hide all debugging */ g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL); g_log_set_handler ("AppDataTools", G_LOG_LEVEL_DEBUG, appdata_validate_log_ignore_cb, NULL); } if (argc < 2) { retval = EXIT_CODE_USAGE; /* TRANSLATORS: this is explaining how to use the tool */ g_print ("%s %s %s\n", _("Usage:"), argv[0], _("<file>")); goto out; } /* make more strict or relaxed */ if (strict) validate_flags |= AS_APP_VALIDATE_FLAG_STRICT; else if (relax) validate_flags |= AS_APP_VALIDATE_FLAG_RELAX; /* the user has forced no network mode */ if (nonet) validate_flags |= AS_APP_VALIDATE_FLAG_NO_NETWORK; /* validate each file */ for (i = 1; i < argc; i++) { retval_tmp = appdata_validate_and_show_results (filename, argv[i], output_format, validate_flags); if (retval_tmp != EXIT_CODE_SUCCESS) retval = retval_tmp; } out: g_free (filename); g_free (output_format); g_option_context_free (context); return retval; }
int main(int argc, char **argv) { int tty_fd; struct termios ts; int speed = 0, bits = '-', parity = '-', stop = '-'; int set_iflag = 0, clr_iflag = 0; int ldisc; int optc; char *dev; int intropause = 1; char *introparm = NULL; static const struct option opttbl[] = { {"speed", required_argument, NULL, 's'}, {"sevenbits", no_argument, NULL, '7'}, {"eightbits", no_argument, NULL, '8'}, {"noparity", no_argument, NULL, 'n'}, {"evenparity", no_argument, NULL, 'e'}, {"oddparity", no_argument, NULL, 'o'}, {"onestopbit", no_argument, NULL, '1'}, {"twostopbits", no_argument, NULL, '2'}, {"iflag", required_argument, NULL, 'i'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, {"debug", no_argument, NULL, 'd'}, {"intro-command", no_argument, NULL, 'c'}, {"pause", no_argument, NULL, 'p'}, {NULL, 0, NULL, 0} }; signal(SIGKILL, handler); signal(SIGINT, handler); setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); /* parse options */ if (argc == 0) usage(EXIT_SUCCESS); while ((optc = getopt_long(argc, argv, "dhV78neo12s:i:c:p:", opttbl, NULL)) >= 0) { switch (optc) { case 'd': debug = 1; break; case '1': case '2': stop = optc; break; case '7': case '8': bits = optc; break; case 'n': case 'e': case 'o': parity = optc; break; case 's': speed = strtos32_or_err(optarg, _("invalid speed argument")); break; case 'p': intropause = strtou32_or_err(optarg, _("invalid pause argument")); if (intropause > 10) errx(EXIT_FAILURE, "invalid pause: %s", optarg); break; case 'c': introparm = optarg; break; case 'i': parse_iflag(optarg, &set_iflag, &clr_iflag); break; case 'V': printf(UTIL_LINUX_VERSION); return EXIT_SUCCESS; case 'h': usage(EXIT_SUCCESS); default: errtryhelp(EXIT_FAILURE); } } if (argc - optind != 2) usage(EXIT_FAILURE); /* parse line discipline specification */ ldisc = lookup_table(ld_discs, argv[optind]); if (ldisc < 0) ldisc = strtos32_or_err(argv[optind], _("invalid line discipline argument")); /* ldisc specific option settings */ if (ldisc == N_GIGASET_M101) { /* device specific defaults for line speed and data format */ if (speed == 0) speed = 115200; if (bits == '-') bits = '8'; if (parity == '-') parity = 'n'; if (stop == '-') stop = '1'; } /* open device */ dev = argv[optind + 1]; if ((tty_fd = open(dev, O_RDWR | O_NOCTTY)) < 0) err(EXIT_FAILURE, _("cannot open %s"), dev); if (!isatty(tty_fd)) errx(EXIT_FAILURE, _("%s is not a serial line"), dev); dbg("opened %s", dev); /* set line speed and format */ if (tcgetattr(tty_fd, &ts) < 0) err(EXIT_FAILURE, _("cannot get terminal attributes for %s"), dev); cfmakeraw(&ts); if (speed && my_cfsetspeed(&ts, speed) < 0) errx(EXIT_FAILURE, _("speed %d unsupported"), speed); switch (stop) { case '1': ts.c_cflag &= ~CSTOPB; break; case '2': ts.c_cflag |= CSTOPB; break; case '-': break; default: abort(); } switch (bits) { case '7': ts.c_cflag = (ts.c_cflag & ~CSIZE) | CS7; break; case '8': ts.c_cflag = (ts.c_cflag & ~CSIZE) | CS8; break; case '-': break; default: abort(); } switch (parity) { case 'n': ts.c_cflag &= ~(PARENB | PARODD); break; case 'e': ts.c_cflag |= PARENB; ts.c_cflag &= ~PARODD; break; case 'o': ts.c_cflag |= (PARENB | PARODD); break; case '-': break; default: abort(); } ts.c_cflag |= CREAD; /* just to be on the safe side */ ts.c_iflag |= set_iflag; ts.c_iflag &= ~clr_iflag; if (tcsetattr(tty_fd, TCSAFLUSH, &ts) < 0) err(EXIT_FAILURE, _("cannot set terminal attributes for %s"), dev); dbg("set to raw %d %c%c%c: cflag=0x%x", speed, bits, parity, stop, ts.c_cflag); if (introparm && *introparm) { dbg("intro command is '%s'", introparm); if (write_all(tty_fd, introparm, strlen(introparm)) != 0) err(EXIT_FAILURE, _("cannot write intro command to %s"), dev); if (intropause) { dbg("waiting for %d seconds", intropause); sleep(intropause); } } /* Attach the line discipline. */ if (ioctl(tty_fd, TIOCSETD, &ldisc) < 0) err(EXIT_FAILURE, _("cannot set line discipline")); dbg("line discipline set to %d", ldisc); /* ldisc specific post-attach actions */ if (ldisc == N_GSM0710) gsm0710_set_conf(tty_fd); /* Go into background if not in debug mode. */ if (!debug && daemon(0, 0) < 0) err(EXIT_FAILURE, _("cannot daemonize")); /* Sleep to keep the line discipline active. */ pause(); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { /* I18n */ setlocale(LC_ALL, ""); #if ENABLE_NLS bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #endif abrt_init(argv); const char *program_usage_string = _( "& [-v -i -n INCREMENT] -e|--event EVENT DIR..." ); char *event_name = NULL; int interactive = 0; /* must be _int_, OPT_BOOL expects that! */ int nice_incr = 0; struct options program_options[] = { OPT__VERBOSE(&g_verbose), OPT_STRING('e', "event" , &event_name, "EVENT", _("Run EVENT on DIR")), OPT_BOOL('i', "interactive" , &interactive, _("Communicate directly to the user")), OPT_INTEGER('n', "nice" , &nice_incr, _("Increment the nice value by INCREMENT")), OPT_END() }; parse_opts(argc, argv, program_options, program_usage_string); argv += optind; if (!*argv || !event_name) show_usage_and_die(program_usage_string, program_options); load_abrt_conf(); const char *const opt_env_nice = getenv("ABRT_EVENT_NICE"); if (opt_env_nice != NULL && opt_env_nice[0] != '\0') { log_debug("Using ABRT_EVENT_NICE=%s to increment the nice value", opt_env_nice); nice_incr = xatoi(opt_env_nice); } if (nice_incr != 0) { log_debug("Incrementing the nice value by %d", nice_incr); const int ret = nice(nice_incr); if (ret == -1) perror_msg_and_die("Failed to increment the nice value"); } bool post_create = (strcmp(event_name, "post-create") == 0); char *dump_dir_name = NULL; while (*argv) { dump_dir_name = xstrdup(*argv++); int i = strlen(dump_dir_name); while (--i >= 0) if (dump_dir_name[i] != '/') break; dump_dir_name[++i] = '\0'; struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ DD_OPEN_READONLY); if (!dd) return 1; uid = dd_load_text_ext(dd, FILENAME_UID, DD_FAIL_QUIETLY_ENOENT); dd_close(dd); struct run_event_state *run_state = new_run_event_state(); if (!interactive) make_run_event_state_forwarding(run_state); run_state->logging_callback = do_log; if (post_create) run_state->post_run_callback = is_crash_a_dup; int r = run_event_on_dir_name(run_state, dump_dir_name, event_name); const bool no_action_for_event = (r == 0 && run_state->children_count == 0); free_run_event_state(run_state); /* Needed only if is_crash_a_dup() was called, but harmless * even if it wasn't: */ dup_uuid_fini(); dup_corebt_fini(); if (no_action_for_event) error_msg_and_die("No actions are found for event '%s'", event_name); //TODO: consider this case: // new dump is created, post-create detects that it is a dup, // but then load_crash_info(dup_name) *FAILS*. // In this case, we later delete damaged dup_name (right?) // but new dump never gets its FILENAME_COUNT set! /* Is crash a dup? (In this case, is_crash_a_dup() should have * aborted "post-create" event processing as soon as it saw uuid * and determined that there is another crash with same uuid. * In this case it sets crash_dump_dup_name) */ if (crash_dump_dup_name) error_msg_and_die("DUP_OF_DIR: %s", crash_dump_dup_name); /* Was there error on one of processing steps in run_event? */ if (r != 0) return r; /* yes */ free(dump_dir_name); dump_dir_name = NULL; } /* exit 0 means, that there is no duplicate of dump-dir */ return 0; }
int main(int argc, char **argv) { int permission = 0644; int opt; size_t size = 0; int nsems = 0; int ask_shm = 0, ask_msg = 0, ask_sem = 0; static const struct option longopts[] = { {"shmem", required_argument, NULL, 'M'}, {"semaphore", required_argument, NULL, 'S'}, {"queue", no_argument, NULL, 'Q'}, {"mode", required_argument, NULL, 'p'}, {"version", no_argument, NULL, 'V'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0} }; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); while((opt = getopt_long(argc, argv, "hM:QS:p:Vh", longopts, NULL)) != -1) { switch(opt) { case 'M': size = strtou64_or_err(optarg, _("failed to parse size")); ask_shm = 1; break; case 'Q': ask_msg = 1; break; case 'S': nsems = strtos32_or_err(optarg, _("failed to parse elements")); ask_sem = 1; break; case 'p': permission = strtoul(optarg, NULL, 8); break; case 'h': usage(stdout); break; case 'V': printf(UTIL_LINUX_VERSION); return EXIT_SUCCESS; default: ask_shm = ask_msg = ask_sem = 0; break; } } if(!ask_shm && !ask_msg && !ask_sem) usage(stderr); if (ask_shm) { int shmid; if (-1 == (shmid = create_shm(size, permission))) err(EXIT_FAILURE, _("create share memory failed")); else printf(_("Shared memory id: %d\n"), shmid); } if (ask_msg) { int msgid; if (-1 == (msgid = create_msg(permission))) err(EXIT_FAILURE, _("create message queue failed")); else printf(_("Message queue id: %d\n"), msgid); } if (ask_sem) { int semid; if (-1 == (semid = create_sem(nsems, permission))) err(EXIT_FAILURE, _("create semaphore failed")); else printf(_("Semaphore id: %d\n"), semid); } return EXIT_SUCCESS; }
int main(int argc, char **argv) { char *path; int c, fd, verbose = 0, secure = 0, secsize; uint64_t end, blksize, step, range[2], stats[2]; struct stat sb; struct timeval now, last; static const struct option longopts[] = { { "help", 0, 0, 'h' }, { "version", 0, 0, 'V' }, { "offset", 1, 0, 'o' }, { "length", 1, 0, 'l' }, { "step", 1, 0, 'p' }, { "secure", 0, 0, 's' }, { "verbose", 0, 0, 'v' }, { NULL, 0, 0, 0 } }; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); range[0] = 0; range[1] = ULLONG_MAX; step = 0; while ((c = getopt_long(argc, argv, "hVsvo:l:p:", longopts, NULL)) != -1) { switch(c) { case 'h': usage(stdout); break; case 'V': printf(UTIL_LINUX_VERSION); return EXIT_SUCCESS; case 'l': range[1] = strtosize_or_err(optarg, _("failed to parse length")); break; case 'o': range[0] = strtosize_or_err(optarg, _("failed to parse offset")); break; case 'p': step = strtosize_or_err(optarg, _("failed to parse step")); break; case 's': secure = 1; break; case 'v': verbose = 1; break; default: usage(stderr); break; } } if (optind == argc) errx(EXIT_FAILURE, _("no device specified")); path = argv[optind++]; if (optind != argc) { warnx(_("unexpected number of arguments")); usage(stderr); } fd = open(path, O_WRONLY); if (fd < 0) err(EXIT_FAILURE, _("cannot open %s"), path); if (fstat(fd, &sb) == -1) err(EXIT_FAILURE, _("stat of %s failed"), path); if (!S_ISBLK(sb.st_mode)) errx(EXIT_FAILURE, _("%s: not a block device"), path); if (ioctl(fd, BLKGETSIZE64, &blksize)) err(EXIT_FAILURE, _("%s: BLKGETSIZE64 ioctl failed"), path); if (ioctl(fd, BLKSSZGET, &secsize)) err(EXIT_FAILURE, _("%s: BLKSSZGET ioctl failed"), path); /* check offset alignment to the sector size */ if (range[0] % secsize) errx(EXIT_FAILURE, _("%s: offset %" PRIu64 " is not aligned " "to sector size %i"), path, range[0], secsize); /* is the range end behind the end of the device ?*/ if (range[0] > blksize) errx(EXIT_FAILURE, _("%s: offset is greater than device size"), path); end = range[0] + range[1]; if (end < range[0] || end > blksize) end = blksize; range[1] = (step > 0) ? step : end - range[0]; /* check length alignment to the sector size */ if (range[1] % secsize) errx(EXIT_FAILURE, _("%s: length %" PRIu64 " is not aligned " "to sector size %i"), path, range[1], secsize); stats[0] = range[0], stats[1] = 0; gettime_monotonic(&last); for (range[0] = range[0]; range[0] < end; range[0] += range[1]) { if (range[0] + range[1] > end) range[1] = end - range[0]; if (secure) { if (ioctl(fd, BLKSECDISCARD, &range)) err(EXIT_FAILURE, _("%s: BLKSECDISCARD ioctl failed"), path); } else { if (ioctl(fd, BLKDISCARD, &range)) err(EXIT_FAILURE, _("%s: BLKDISCARD ioctl failed"), path); } /* reporting progress */ if (verbose && step) { gettime_monotonic(&now); if (last.tv_sec < now.tv_sec) { print_stats(path, stats); stats[0] = range[0], stats[1] = 0; last = now; } } stats[1] += range[1]; } if (verbose) print_stats(path, stats); close(fd); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) try { setlocale(LC_ALL, ""); #if ENABLE_NLS bindtextdomain("sdcv", //"./locale"//< for testing GETTEXT_TRANSLATIONS_PATH //< should be ); textdomain("sdcv"); #endif gboolean show_version = FALSE; gboolean show_list_dicts = FALSE; glib::StrArr use_dict_list; gboolean non_interactive = FALSE; gboolean utf8_output = FALSE; gboolean utf8_input = FALSE; glib::CharStr opt_data_dir; gboolean colorize = FALSE; const GOptionEntry entries[] = { { "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, _("display version information and exit"), nullptr }, { "list-dicts", 'l', 0, G_OPTION_ARG_NONE, &show_list_dicts, _("display list of available dictionaries and exit"), nullptr }, { "use-dict", 'u', 0, G_OPTION_ARG_STRING_ARRAY, get_addr(use_dict_list), _("for search use only dictionary with this bookname"), _("bookname") }, { "non-interactive", 'n', 0, G_OPTION_ARG_NONE, &non_interactive, _("for use in scripts"), nullptr }, { "utf8-output", '0', 0, G_OPTION_ARG_NONE, &utf8_output, _("output must be in utf8"), nullptr }, { "utf8-input", '1', 0, G_OPTION_ARG_NONE, &utf8_input, _("input of sdcv in utf8"), nullptr }, { "data-dir", '2', 0, G_OPTION_ARG_STRING, get_addr(opt_data_dir), _("use this directory as path to stardict data directory"), _("path/to/dir") }, { "color", 'c', 0, G_OPTION_ARG_NONE, &colorize, _("colorize the output"), nullptr }, { nullptr }, }; glib::Error error; GOptionContext *context = g_option_context_new(_(" words")); g_option_context_set_help_enabled(context, TRUE); g_option_context_add_main_entries(context, entries, nullptr); const gboolean parse_res = g_option_context_parse(context, &argc, &argv, get_addr(error)); g_option_context_free(context); if (!parse_res) { fprintf(stderr, _("Invalid command line arguments: %s\n"), error->message); return EXIT_FAILURE; } if (show_version) { printf(_("Console version of Stardict, version %s\n"), gVersion); return EXIT_SUCCESS; } const gchar *stardict_data_dir = g_getenv("STARDICT_DATA_DIR"); std::string data_dir; if (!opt_data_dir) { if (stardict_data_dir) data_dir = stardict_data_dir; else data_dir = "/usr/share/stardict/dic"; } else { data_dir = get_impl(opt_data_dir); } const char *homedir = g_getenv("HOME"); if (!homedir) homedir = g_get_home_dir(); const std::list<std::string> dicts_dir_list = { std::string(homedir) + G_DIR_SEPARATOR + ".stardict" + G_DIR_SEPARATOR + "dic", data_dir }; if (show_list_dicts) { printf(_("Dictionary's name Word count\n")); std::list<std::string> order_list, disable_list; for_each_file(dicts_dir_list, ".ifo", order_list, disable_list, [](const std::string &filename, bool) -> void { DictInfo dict_info; if (dict_info.load_from_ifo_file(filename, false)) { const std::string bookname = utf8_to_locale_ign_err(dict_info.bookname); printf("%s %d\n", bookname.c_str(), dict_info.wordcount); } }); return EXIT_SUCCESS; } std::list<std::string> disable_list; if (use_dict_list) { std::list<std::string> empty_list; for_each_file(dicts_dir_list, ".ifo", empty_list, empty_list, [&disable_list, &use_dict_list](const std::string &filename, bool) -> void { DictInfo dict_info; const bool load_ok = dict_info.load_from_ifo_file(filename, false); if (!load_ok) return; for (gchar **p = get_impl(use_dict_list); *p != nullptr; ++p) if (strcmp(*p, dict_info.bookname.c_str()) == 0) return; disable_list.push_back(dict_info.ifo_file_name); }); } const std::string conf_dir = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".stardict"; if (g_mkdir(conf_dir.c_str(), S_IRWXU) == -1 && errno != EEXIST) fprintf(stderr, _("g_mkdir failed: %s\n"), strerror(errno)); Library lib(utf8_input, utf8_output, colorize); std::list<std::string> empty_list; lib.load(dicts_dir_list, empty_list, disable_list); std::unique_ptr<IReadLine> io(create_readline_object()); if (optind < argc) { for (int i = optind; i < argc; ++i) if (!lib.process_phrase(argv[i], *io, non_interactive)) return EXIT_FAILURE; } else if (!non_interactive) { std::string phrase; while (io->read(_("Enter word or phrase: "), phrase)) { if (!lib.process_phrase(phrase.c_str(), *io)) return EXIT_FAILURE; phrase.clear(); } putchar('\n'); } else { fprintf(stderr, _("There are no words/phrases to translate.\n")); } return EXIT_SUCCESS; } catch (const std::exception &ex) { fprintf(stderr, "Internal error: %s\n", ex.what()); exit(EXIT_FAILURE); }
int main( int argc, char ** argv) { char *line = NULL; char *qdisk = NULL; char *qamdevice = NULL; char *optstr = NULL; char *err_extra = NULL; char *s, *fp; int ch; dle_t *dle = NULL; int level; GSList *errlist; level_t *alevel; if (argc > 1 && argv && argv[1] && g_str_equal(argv[1], "--version")) { printf("selfcheck-%s\n", VERSION); return (0); } /* initialize */ /* * Configure program for internationalization: * 1) Only set the message locale for now. * 2) Set textdomain for all amanda related programs to "amanda" * We don't want to be forced to support dozens of message catalogs. */ setlocale(LC_MESSAGES, "C"); textdomain("amanda"); safe_fd(-1, 0); openbsd_fd_inform(); safe_cd(); set_pname("selfcheck"); /* Don't die when child closes pipe */ signal(SIGPIPE, SIG_IGN); add_amanda_log_handler(amanda_log_stderr); add_amanda_log_handler(amanda_log_syslog); dbopen(DBG_SUBDIR_CLIENT); startclock(); dbprintf(_("version %s\n"), VERSION); g_printf("OK version %s\n", VERSION); print_platform(); if(argc > 2 && g_str_equal(argv[1], "amandad")) { amandad_auth = g_strdup(argv[2]); } config_init(CONFIG_INIT_CLIENT, NULL); /* (check for config errors comes later) */ check_running_as(RUNNING_AS_CLIENT_LOGIN); our_features = am_init_feature_set(); our_feature_string = am_feature_to_string(our_features); /* handle all service requests */ /*@[email protected]*/ for(; (line = agets(stdin)) != NULL; free(line)) { /*@[email protected]*/ if (line[0] == '\0') continue; if(strncmp_const(line, "OPTIONS ") == 0) { if (g_options) { g_printf(_("ERROR [Multiple OPTIONS line in selfcheck input]\n")); error(_("Multiple OPTIONS line in selfcheck input\n")); /*NOTREACHED*/ } g_options = parse_g_options(line+8, 1); if(!g_options->hostname) { g_options->hostname = g_malloc(MAX_HOSTNAME_LENGTH+1); gethostname(g_options->hostname, MAX_HOSTNAME_LENGTH); g_options->hostname[MAX_HOSTNAME_LENGTH] = '\0'; } g_printf("OPTIONS "); if(am_has_feature(g_options->features, fe_rep_options_features)) { g_printf("features=%s;", our_feature_string); } if(am_has_feature(g_options->features, fe_rep_options_hostname)) { g_printf("hostname=%s;", g_options->hostname); } g_printf("\n"); fflush(stdout); if (g_options->config) { /* overlay this configuration on the existing (nameless) configuration */ config_init(CONFIG_INIT_CLIENT | CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_OVERLAY, g_options->config); dbrename(get_config_name(), DBG_SUBDIR_CLIENT); } /* check for any config errors now */ if (config_errors(&errlist) >= CFGERR_ERRORS) { char *errstr = config_errors_to_error_string(errlist); g_printf("%s\n", errstr); amfree(errstr); amfree(line); dbclose(); return 1; } if (am_has_feature(g_options->features, fe_req_xml)) { break; } continue; } dle = alloc_dle(); s = line; ch = *s++; skip_whitespace(s, ch); /* find program name */ if (ch == '\0') { goto err; /* no program */ } dle->program = s - 1; skip_non_whitespace(s, ch); s[-1] = '\0'; /* terminate the program name */ dle->program_is_application_api = 0; if(g_str_equal(dle->program, "APPLICATION")) { dle->program_is_application_api = 1; skip_whitespace(s, ch); /* find dumper name */ if (ch == '\0') { goto err; /* no program */ } dle->program = s - 1; skip_non_whitespace(s, ch); s[-1] = '\0'; /* terminate the program name */ } if(strncmp_const(dle->program, "CALCSIZE") == 0) { skip_whitespace(s, ch); /* find program name */ if (ch == '\0') { goto err; /* no program */ } dle->program = s - 1; skip_non_whitespace(s, ch); s[-1] = '\0'; dle->estimatelist = g_slist_append(dle->estimatelist, GINT_TO_POINTER(ES_CALCSIZE)); } else { dle->estimatelist = g_slist_append(dle->estimatelist, GINT_TO_POINTER(ES_CLIENT)); } skip_whitespace(s, ch); /* find disk name */ if (ch == '\0') { goto err; /* no disk */ } qdisk = s - 1; skip_quoted_string(s, ch); s[-1] = '\0'; /* terminate the disk name */ dle->disk = unquote_string(qdisk); skip_whitespace(s, ch); /* find the device or level */ if (ch == '\0') { goto err; /* no device or level */ } if(!isdigit((int)s[-1])) { fp = s - 1; skip_quoted_string(s, ch); s[-1] = '\0'; /* terminate the device */ qamdevice = g_strdup(fp); dle->device = unquote_string(qamdevice); skip_whitespace(s, ch); /* find level number */ } else { dle->device = g_strdup(dle->disk); qamdevice = g_strdup(qdisk); } amfree(qamdevice); /* find level number */ if (ch == '\0' || sscanf(s - 1, "%d", &level) != 1) { goto err; /* bad level */ } alevel = g_new0(level_t, 1); alevel->level = level; dle->levellist = g_slist_append(dle->levellist, alevel); skip_integer(s, ch); skip_whitespace(s, ch); if (ch && strncmp_const_skip(s - 1, "OPTIONS ", s, ch) == 0) { skip_whitespace(s, ch); /* find the option string */ if(ch == '\0') { goto err; /* bad options string */ } optstr = s - 1; skip_quoted_string(s, ch); s[-1] = '\0'; /* terminate the options */ parse_options(optstr, dle, g_options->features, 1); /*@[email protected]*/ check_options(dle); check_disk(dle); /*@[email protected]*/ } else if (ch == '\0') { /* check all since no option */ need_samba=1; need_rundump=1; need_dump=1; need_restore=1; need_vdump=1; need_vrestore=1; need_xfsdump=1; need_xfsrestore=1; need_vxdump=1; need_vxrestore=1; need_runtar=1; need_gnutar=1; need_compress_path=1; need_calcsize=1; need_global_check=1; /*@[email protected]*/ check_disk(dle); /*@[email protected]*/ } else { goto err; /* bad syntax */ } free_dle(dle); dle = NULL; } if (g_options == NULL) { g_printf(_("ERROR [Missing OPTIONS line in selfcheck input]\n")); error(_("Missing OPTIONS line in selfcheck input\n")); /*NOTREACHED*/ } if (am_has_feature(g_options->features, fe_req_xml)) { char *errmsg = NULL; dle_t *dles, *dle, *dle_next; dles = amxml_parse_node_FILE(stdin, &errmsg); if (errmsg) { err_extra = errmsg; goto err; } if (merge_dles_properties(dles, 1) == 0) { goto checkoverall; } for (dle = dles; dle != NULL; dle = dle->next) { run_client_scripts(EXECUTE_ON_PRE_HOST_AMCHECK, g_options, dle, stdout); } for (dle = dles; dle != NULL; dle = dle->next) { check_options(dle); run_client_scripts(EXECUTE_ON_PRE_DLE_AMCHECK, g_options, dle, stdout); check_disk(dle); run_client_scripts(EXECUTE_ON_POST_DLE_AMCHECK, g_options, dle, stdout); } for (dle = dles; dle != NULL; dle = dle->next) { run_client_scripts(EXECUTE_ON_POST_HOST_AMCHECK, g_options, dle, stdout); } for (dle = dles; dle != NULL; dle = dle_next) { dle_next = dle->next; free_dle(dle); } } checkoverall: check_overall(); amfree(line); amfree(our_feature_string); am_release_feature_set(our_features); our_features = NULL; free_g_options(g_options); dbclose(); return 0; err: if (err_extra) { g_printf(_("ERROR [FORMAT ERROR IN REQUEST PACKET %s]\n"), err_extra); dbprintf(_("REQ packet is bogus: %s\n"), err_extra); } else { g_printf(_("ERROR [FORMAT ERROR IN REQUEST PACKET]\n")); dbprintf(_("REQ packet is bogus\n")); } amfree(err_extra); amfree(line); if (dle) free_dle(dle); dbclose(); return 1; }
int main(int argc, char **argv) { struct tm *local_time; time_t now; int ch, day, month, year, yflag; char *progname, *p; int num_months = NUM_MONTHS; progname = argv[0]; if ((p = strrchr(progname, '/')) != NULL) progname = p+1; __progname = progname; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW) || defined(HAVE_LIBTERMCAP) if ((term = getenv("TERM"))) { int ret; my_setupterm(term, 1, &ret); if (ret > 0) { Senter = my_tgetstr("so","smso"); Sexit = my_tgetstr("se","rmso"); Slen = strlen(Senter) + strlen(Sexit); } } #endif /* * The traditional Unix cal utility starts the week at Sunday, * while ISO 8601 starts at Monday. We read the start day from * the locale database, which can be overridden with the * -s (Sunday) or -m (Monday) options. */ #if HAVE_DECL__NL_TIME_WEEK_1STDAY /* * You need to use 2 locale variables to get the first day of the week. * This is needed to support first_weekday=2 and first_workday=1 for * the rare case where working days span across 2 weeks. * This shell script shows the combinations and calculations involved: for LANG in en_US ru_RU fr_FR csb_PL POSIX; do printf "%s:\t%s + %s -1 = " $LANG $(locale week-1stday first_weekday) date -d"$(locale week-1stday) +$(($(locale first_weekday)-1))day" +%w done en_US: 19971130 + 1 -1 = 0 #0 = sunday ru_RU: 19971130 + 2 -1 = 1 fr_FR: 19971201 + 1 -1 = 1 csb_PL: 19971201 + 2 -1 = 2 POSIX: 19971201 + 7 -1 = 0 */ { int wfd; union { unsigned int word; char *string; } val; val.string = nl_langinfo(_NL_TIME_WEEK_1STDAY); wfd = val.word; wfd = day_in_week(wfd % 100, (wfd / 100) % 100, wfd / (100 * 100)); weekstart = (wfd + *nl_langinfo(_NL_TIME_FIRST_WEEKDAY) - 1) % 7; } #endif yflag = 0; while ((ch = getopt(argc, argv, "13mjsyV")) != -1) switch(ch) { case '1': num_months = 1; /* default */ break; case '3': num_months = 3; break; case 's': weekstart = 0; /* default */ break; case 'm': weekstart = 1; break; case 'j': julian = 1; break; case 'y': yflag = 1; break; case 'V': printf(_("%s from %s\n"), progname, PACKAGE_STRING); return 0; case '?': default: usage(); } argc -= optind; argv += optind; time(&now); local_time = localtime(&now); day = month = year = 0; switch(argc) { case 3: if ((day = atoi(*argv++)) < 1 || day > 31) errx(1, _("illegal day value: use 1-%d"), 31); /* FALLTHROUGH */ case 2: if ((month = atoi(*argv++)) < 1 || month > 12) errx(1, _("illegal month value: use 1-12")); /* FALLTHROUGH */ case 1: if ((year = atoi(*argv)) < 1 || year > 9999) errx(1, _("illegal year value: use 1-9999")); if (day) { int dm = days_in_month[leap_year(year)][month]; if (day > dm) errx(1, _("illegal day value: use 1-%d"), dm); day = day_in_year(day, month, year); } else if ((local_time->tm_year + 1900) == year) { day = local_time->tm_yday + 1; } if (!month) yflag=1; break; case 0: day = local_time->tm_yday + 1; year = local_time->tm_year + 1900; month = local_time->tm_mon + 1; break; default: usage(); } headers_init(); if (!isatty(1)) day = 0; /* don't highlight */ if (yflag && julian) j_yearly(day, year); else if (yflag) yearly(day, year); else if (num_months == 1) monthly(day, month, year); else if (num_months == 3) monthly3(day, month, year); exit(0); }
bool gtkgui_init(int argc, char *argv[], Stream_mixer *mix) { GtkWidget *bbox = NULL; bool isx = false; /* FIXME: bisogan mettere l'enable_nls*/ /* i18n */ setlocale(LC_ALL, ""); bindtextdomain("muse", LOCALEDIR); bind_textdomain_codeset("muse", "UTF-8"); textdomain("muse"); /* initialization */ state = true; mixer = mix; list_init(&listachan); list_init(&lamelist); list_init(&ogglist); iceprof = lameprof = vorbisprof = NULL; if(!profile_init()) error(_("profile initialization error")); profile_ice_load(); /* profile_lame_load and profile_vorbis_load are into encoder.cpp */ pathfile = NULL; /* signal to glib we're going to use threads */ g_thread_init(NULL); isx = gtk_init_check(&argc,&argv); if(!isx) return false; isx = mixer->set_lineout(true); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), _("MuSE-cvs Gtk+2")); gtk_window_set_resizable(GTK_WINDOW(window), FALSE); gtk_container_set_border_width(GTK_CONTAINER(window), 12); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gcb_exit), NULL); /* FIXME: gtk2 remove ? */ gtk_widget_realize(window); vbox=gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(window), vbox); fix = gtk_fixed_new(); gtk_box_pack_start(GTK_BOX(vbox), fix, FALSE, FALSE, 0); bbox = createbbox(bbox); gtk_fixed_put(GTK_FIXED(fix), bbox, 0, 0); if(isx) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(speakout), TRUE); pack_new(); createch(); putstatusbar(); /*let's show window */ gtk_widget_show_all(window); gtk_widget_hide(pack1.hscale); gtk_widget_hide(pack2.hscale); gtk_widget_hide(pack3.hscale); return true; }
int main(int argc, char *argv[]) { int c; char *raw_name; char *block_name; int retval; int block_major, block_minor; int i, rc; struct stat statbuf; static const struct option longopts[] = { {"query", no_argument, 0, 'q'}, {"all", no_argument, 0, 'a'}, {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, {NULL, no_argument, 0, '0'}, }; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); while ((c = getopt_long(argc, argv, "qaVh", longopts, NULL)) != -1) switch (c) { case 'q': do_query = 1; break; case 'a': do_query_all = 1; break; case 'V': printf(UTIL_LINUX_VERSION); return EXIT_SUCCESS; case 'h': usage(EXIT_SUCCESS); default: usage(EXIT_FAILURE); } /* * Check for, and open, the master raw device, /dev/raw */ open_raw_ctl(); if (do_query_all) { if (optind < argc) usage(EXIT_FAILURE); for (i = 1; i < RAW_NR_MINORS; i++) query(i, NULL, 1); exit(EXIT_SUCCESS); } /* * It's a bind or a single query. Either way we need a raw device. */ if (optind >= argc) usage(EXIT_FAILURE); raw_name = argv[optind++]; /* * try to check the device name before stat(), because on systems with * udev the raw0 causes a create udev event for char 162/0, which * causes udev to *remove* /dev/rawctl */ rc = sscanf(raw_name, _PATH_RAWDEVDIR "raw%d", &raw_minor); if (rc != 1) usage(EXIT_FAILURE); if (raw_minor == 0) errx(EXIT_RAW_ACCESS, _("Device '%s' is the control raw device " "(use raw<N> where <N> is greater than zero)"), raw_name); if (do_query) return query(raw_minor, raw_name, 0); /* * It's not a query, so we still have some parsing to do. Have we been * given a block device filename or a major/minor pair? */ switch (argc - optind) { case 1: block_name = argv[optind]; retval = stat(block_name, &statbuf); if (retval) err(EXIT_RAW_ACCESS, _("Cannot locate block device '%s'"), block_name); if (!S_ISBLK(statbuf.st_mode)) errx(EXIT_RAW_ACCESS, _("Device '%s' is not a block device"), block_name); block_major = major(statbuf.st_rdev); block_minor = minor(statbuf.st_rdev); break; case 2: block_major = strtol_octal_or_err(argv[optind], _("failed to parse argument")); block_minor = strtol_octal_or_err(argv[optind + 1], _("failed to parse argument")); break; default: usage(EXIT_FAILURE); } return bind(raw_minor, block_major, block_minor); }
int main (int argc, char *argv[]) { GOptionContext *optcontext; GOptionEntry options[] = { { NULL } }; #ifdef ENABLE_DEBUG TpDebugSender *debug_sender; #endif GError *error = NULL; EmpathyChatManager *chat_mgr; EmpathyIdle *idle; gint retval; /* Init */ g_thread_init (NULL); optcontext = g_option_context_new (N_("- Empathy Chat Client")); g_option_context_add_group (optcontext, gtk_get_option_group (TRUE)); g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE); if (!g_option_context_parse (optcontext, &argc, &argv, &error)) { g_print ("%s\nRun '%s --help' to see a full list of available command " "line options.\n", error->message, argv[0]); g_warning ("Error in empathy-av init: %s", error->message); return EXIT_FAILURE; } g_option_context_free (optcontext); empathy_gtk_init (); gtk_window_set_default_icon_name ("empathy"); textdomain (GETTEXT_PACKAGE); app = gtk_application_new (EMPATHY_CHAT_DBUS_NAME, G_APPLICATION_IS_SERVICE); g_signal_connect (app, "activate", G_CALLBACK (activate_cb), NULL); #ifdef ENABLE_DEBUG /* Set up debug sender */ debug_sender = tp_debug_sender_dup (); g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN); #endif /* Setting up Idle */ idle = empathy_idle_dup_singleton (); chat_mgr = empathy_chat_manager_dup_singleton (); g_signal_connect (chat_mgr, "handled-chats-changed", G_CALLBACK (handled_chats_changed_cb), GUINT_TO_POINTER (1)); if (g_getenv ("EMPATHY_PERSIST") != NULL) { DEBUG ("Disable timer"); use_timer = FALSE; } /* the inactivity timeout can only be set while the application is held */ g_application_hold (G_APPLICATION (app)); g_application_set_inactivity_timeout (G_APPLICATION (app), TIMEOUT * 1000); g_application_release (G_APPLICATION (app)); DEBUG ("Waiting for text channels to handle"); retval = g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app); g_object_unref (idle); g_object_unref (chat_mgr); #ifdef ENABLE_DEBUG g_object_unref (debug_sender); #endif return retval; }
void init_locales(std::string locale) { translation_c::initialize_available_translations(); if (debugging_requested("locale")) mxinfo(boost::format("[init_locales start: locale %1%]\n") % locale); std::string locale_dir; std::string default_locale = translation_c::get_default_ui_locale(); if (-1 == translation_c::look_up_translation(locale)) { if (debugging_requested("locale")) mxinfo(boost::format("[init_locales lookup failed; clearing locale]\n")); locale = ""; } if (locale.empty()) { locale = default_locale; if (debugging_requested("locale")) mxinfo(boost::format("[init_locales setting to default locale %1%]\n") % locale); } # if defined(SYS_WINDOWS) set_environment_variable("LANGUAGE", ""); if (!locale.empty()) { // The Windows system headers define LC_MESSAGES but // Windows itself doesn't know it and treats "set_locale(LC_MESSAGES, ...)" // as an error. gettext uses the LANG and LC_MESSAGE environment variables instead. // Windows knows two environments: the system environment that's // modified by SetEnvironmentVariable() and the C library's cache // of said environment which is modified via _putenv(). set_environment_variable("LANG", locale); set_environment_variable("LC_MESSAGES", locale); translation_c::set_active_translation(locale); // Boost's path class uses wide chars on Windows for path // names. Tell that all narrow strings are encoded in UTF-8. std::locale utf8_locale(std::locale(), new mtx::utf8_codecvt_facet); std::locale::global(utf8_locale); boost::filesystem::path::imbue(utf8_locale); } locale_dir = get_installation_path() + "\\locale"; # else // SYS_WINDOWS std::string chosen_locale; try { locale_string_c loc_default(default_locale); std::string loc_req_with_default_codeset(locale_string_c(locale).set_codeset_and_modifier(loc_default).str()); if (setlocale(LC_MESSAGES, loc_req_with_default_codeset.c_str()) != NULL) chosen_locale = loc_req_with_default_codeset; else if (setlocale(LC_MESSAGES, locale.c_str()) != NULL) chosen_locale = locale; else { std::string loc_req_with_utf8 = locale_string_c(locale).set_codeset_and_modifier(locale_string_c("dummy.UTF-8")).str(); if (setlocale(LC_MESSAGES, loc_req_with_utf8.c_str()) != NULL) chosen_locale = loc_req_with_utf8; } } catch (mtx::locale_string_format_x &error) { if (debugging_requested("locale")) mxinfo(boost::format("[init_locales format error in %1%]\n") % error.error()); } if (debugging_requested("locale")) mxinfo(boost::format("[init_locales chosen locale %1%]\n") % chosen_locale); // Hard fallback to "C" locale if no suitable locale was // selected. This can happen if the system has no locales for // "en_US" or "en_US.UTF-8" compiled. if (chosen_locale.empty() && (setlocale(LC_MESSAGES, "C") != NULL)) chosen_locale = "C"; if (chosen_locale.empty()) mxerror(Y("The locale could not be set properly. Check the LANG, LC_ALL and LC_MESSAGES environment variables.\n")); std::locale utf8_locale(std::locale(), new mtx::utf8_codecvt_facet); std::locale::global(utf8_locale); translation_c::set_active_translation(chosen_locale); locale_dir = MTX_LOCALE_DIR; # endif // SYS_WINDOWS # if defined(SYS_APPLE) int result = setenv("LC_MESSAGES", chosen_locale.c_str(), 1); if (debugging_requested("locale")) mxinfo(boost::format("[init_locales setenv() return code: %1%]\n") % result); # endif bindtextdomain("mkvtoolnix", locale_dir.c_str()); textdomain("mkvtoolnix"); bind_textdomain_codeset("mkvtoolnix", "UTF-8"); }
int main (int argc, char **argv) { const struct group *gr; struct group grent; const struct sgrp *sg; struct sgrp sgent; Prog = Basename (argv[0]); (void) setlocale (LC_ALL, ""); (void) bindtextdomain (PACKAGE, LOCALEDIR); (void) textdomain (PACKAGE); process_root_flag ("-R", argc, argv); OPENLOG ("grpconv"); process_flags (argc, argv); if (gr_lock () == 0) { fprintf (stderr, _("%s: cannot lock %s; try again later.\n"), Prog, gr_dbname ()); fail_exit (5); } gr_locked = true; if (gr_open (O_CREAT | O_RDWR) == 0) { fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); fail_exit (1); } if (sgr_lock () == 0) { fprintf (stderr, _("%s: cannot lock %s; try again later.\n"), Prog, sgr_dbname ()); fail_exit (5); } sgr_locked = true; if (sgr_open (O_CREAT | O_RDWR) == 0) { fprintf (stderr, _("%s: cannot open %s\n"), Prog, sgr_dbname ()); fail_exit (1); } /* * Remove /etc/gshadow entries for groups not in /etc/group. */ (void) sgr_rewind (); while ((sg = sgr_next ()) != NULL) { if (gr_locate (sg->sg_name) != NULL) { continue; } if (sgr_remove (sg->sg_name) == 0) { /* * This shouldn't happen (the entry exists) but... */ fprintf (stderr, _("%s: cannot remove entry '%s' from %s\n"), Prog, sg->sg_name, sgr_dbname ()); fail_exit (3); } (void) sgr_rewind (); } /* * Update shadow group passwords if non-shadow password is not "x". * Add any missing shadow group entries. */ (void) gr_rewind (); while ((gr = gr_next ()) != NULL) { sg = sgr_locate (gr->gr_name); if (NULL != sg) { /* update existing shadow group entry */ sgent = *sg; if (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0) sgent.sg_passwd = gr->gr_passwd; } else { static char *empty = 0; /* add new shadow group entry */ memset (&sgent, 0, sizeof sgent); sgent.sg_name = gr->gr_name; sgent.sg_passwd = gr->gr_passwd; sgent.sg_adm = ∅ } /* * XXX - sg_mem is redundant, it is currently always a copy * of gr_mem. Very few programs actually use sg_mem, and all * of them are in the shadow suite. Maybe this field could * be used for something else? Any suggestions? */ sgent.sg_mem = gr->gr_mem; if (sgr_update (&sgent) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, sgr_dbname (), sgent.sg_name); fail_exit (3); } /* remove password from /etc/group */ grent = *gr; grent.gr_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */ if (gr_update (&grent) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, gr_dbname (), grent.gr_name); fail_exit (3); } } if (sgr_close () == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ()); SYSLOG ((LOG_ERR, "failure while writing changes to %s", sgr_dbname ())); fail_exit (3); } if (gr_close () == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ()); SYSLOG ((LOG_ERR, "failure while writing changes to %s", gr_dbname ())); fail_exit (3); } if (sgr_unlock () == 0) { fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ())); /* continue */ } if (gr_unlock () == 0) { fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ())); /* continue */ } nscd_flush_cache ("group"); sssd_flush_cache (SSSD_DB_GROUP); return 0; }
int main (int argc, char **argv) { GstPlay *play; GPtrArray *playlist; gboolean print_version = FALSE; gboolean gapless = FALSE; gchar **filenames = NULL; gchar *audio_sink = NULL; gchar *video_sink = NULL; gchar **uris; guint num, i; GError *err = NULL; GOptionContext *ctx; GOptionEntry options[] = { {"version", 0, 0, G_OPTION_ARG_NONE, &print_version, N_("Print version information and exit"), NULL}, {"videosink", 0, 0, G_OPTION_ARG_STRING, &video_sink, N_("Video sink to use (default is autovideosink)"), NULL}, {"audiosink", 0, 0, G_OPTION_ARG_STRING, &audio_sink, N_("Audio sink to use (default is autoaudiosink)"), NULL}, {"gapless", 0, 0, G_OPTION_ARG_NONE, &gapless, N_("Enable gapless playback"), NULL}, {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL}, {NULL} }; #ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif g_set_prgname ("gst-play-" GST_API_VERSION); ctx = g_option_context_new ("FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ..."); g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE); g_option_context_add_group (ctx, gst_init_get_option_group ()); if (!g_option_context_parse (ctx, &argc, &argv, &err)) { g_print ("Error initializing: %s\n", GST_STR_NULL (err->message)); return 1; } g_option_context_free (ctx); GST_DEBUG_CATEGORY_INIT (play_debug, "play", 0, "gst-play"); if (print_version) { gchar *version_str; version_str = gst_version_string (); g_print ("%s version %s\n", g_get_prgname (), PACKAGE_VERSION); g_print ("%s\n", version_str); g_print ("%s\n", GST_PACKAGE_ORIGIN); g_free (version_str); return 0; } if (filenames == NULL || *filenames == NULL) { g_printerr (_("Usage: %s FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ..."), "gst-play-" GST_API_VERSION); g_printerr ("\n\n"), g_printerr ("%s\n\n", _("You must provide at least one filename or URI to play.")); return 1; } playlist = g_ptr_array_new (); /* fill playlist */ num = g_strv_length (filenames); for (i = 0; i < num; ++i) { GST_LOG ("command line argument: %s", filenames[i]); add_to_playlist (playlist, filenames[i]); } g_strfreev (filenames); g_ptr_array_add (playlist, NULL); /* play */ uris = (gchar **) g_ptr_array_free (playlist, FALSE); play = play_new (uris, audio_sink, video_sink, gapless); do_play (play); /* clean up */ play_free (play); return 0; }
int main (int argc, char **argv) { register int c; int errflg; int function; u_short portnum; static const struct option long_options[] = { { "help", no_argument, NULL, 'H' }, { "version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0 } }; setlocale (LC_ALL, ""); textdomain (_libc_intl_domainname); function = NONE; portnum = 0; errflg = 0; while ((c = getopt_long (argc, argv, "ptubdn:", long_options, NULL)) != -1) { switch (c) { case 'p': if (function != NONE) errflg = 1; else function = PMAPDUMP; break; case 't': if (function != NONE) errflg = 1; else function = TCPPING; break; case 'u': if (function != NONE) errflg = 1; else function = UDPPING; break; case 'b': if (function != NONE) errflg = 1; else function = BRDCST; break; case 'n': portnum = (u_short) atoi (optarg); /* hope we don't get bogus # */ break; case 'd': if (function != NONE) errflg = 1; else function = DELETES; break; case 'H': usage (stdout); return 0; case 'V': print_version (); return 0; case '?': errflg = 1; } } if (errflg || function == NONE) { usage (stderr); return 1; } switch (function) { case PMAPDUMP: if (portnum != 0) { usage (stderr); return 1; } pmapdump (argc - optind, argv + optind); break; case UDPPING: udpping (portnum, argc - optind, argv + optind); break; case TCPPING: tcpping (portnum, argc - optind, argv + optind); break; case BRDCST: if (portnum != 0) { usage (stderr); return 1; } brdcst (argc - optind, argv + optind); break; case DELETES: deletereg (argc - optind, argv + optind); break; } return 0; }
int main(int argc, char *argv[]) { int status = 0, c; size_t i; static const struct option long_opts[] = { { "all", 0, 0, 'a' }, { "help", 0, 0, 'h' }, { "verbose", 0, 0, 'v' }, { "version", 0, 0, 'V' }, { NULL, 0, 0, 0 } }; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); atexit(close_stdout); while ((c = getopt_long(argc, argv, "ahvVL:U:", long_opts, NULL)) != -1) { switch (c) { case 'a': /* all */ ++all; break; case 'h': /* help */ usage(stdout); break; case 'v': /* be chatty */ ++verbose; break; case 'V': /* version */ printf(UTIL_LINUX_VERSION); return EXIT_SUCCESS; case 'L': add_label(optarg); break; case 'U': add_uuid(optarg); break; default: errtryhelp(EXIT_FAILURE); } } argv += optind; if (!all && !numof_labels() && !numof_uuids() && *argv == NULL) usage(stderr); mnt_init_debug(0); mntcache = mnt_new_cache(); for (i = 0; i < numof_labels(); i++) status |= swapoff_by("LABEL", get_label(i), !QUIET); for (i = 0; i < numof_uuids(); i++) status |= swapoff_by("UUID", get_uuid(i), !QUIET); while (*argv != NULL) status |= do_swapoff(*argv++, !QUIET, !CANONIC); if (all) status |= swapoff_all(); free_tables(); mnt_unref_cache(mntcache); return status; }
int main (int argc, char **argv) { /* normaly should be int result = STATE_UNKNOWN; */ int status = STATE_UNKNOWN; int result = 0; char *fping_prog = NULL; char *server = NULL; char *command_line = NULL; char *input_buffer = NULL; char *option_string = ""; input_buffer = malloc (MAX_INPUT_BUFFER); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); /* Parse extra opts if any */ argv=np_extra_opts (&argc, argv, progname); if (process_arguments (argc, argv) == ERROR) usage4 (_("Could not parse arguments")); server = strscpy (server, server_name); /* compose the command */ if (target_timeout) xasprintf(&option_string, "%s-t %d ", option_string, target_timeout); if (packet_interval) xasprintf(&option_string, "%s-p %d ", option_string, packet_interval); if (sourceip) xasprintf(&option_string, "%s-S %s ", option_string, sourceip); if (sourceif) xasprintf(&option_string, "%s-I %s ", option_string, sourceif); #ifdef PATH_TO_FPING6 if (address_family != AF_INET && is_inet6_addr(server)) fping_prog = strdup(PATH_TO_FPING6); else fping_prog = strdup(PATH_TO_FPING); #else fping_prog = strdup(PATH_TO_FPING); #endif xasprintf (&command_line, "%s %s-b %d -c %d %s", fping_prog, option_string, packet_size, packet_count, server); if (verbose) printf ("%s\n", command_line); /* run the command */ child_process = spopen (command_line); if (child_process == NULL) { printf (_("Could not open pipe: %s\n"), command_line); return STATE_UNKNOWN; } child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); if (child_stderr == NULL) { printf (_("Could not open stderr for %s\n"), command_line); } while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { if (verbose) printf ("%s", input_buffer); status = max_state (status, textscan (input_buffer)); } /* If we get anything on STDERR, at least set warning */ while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { status = max_state (status, STATE_WARNING); if (verbose) printf ("%s", input_buffer); status = max_state (status, textscan (input_buffer)); } (void) fclose (child_stderr); /* close the pipe */ if (result = spclose (child_process)) /* need to use max_state not max */ status = max_state (status, STATE_WARNING); if (result > 1 ) { status = max_state (status, STATE_UNKNOWN); if (result == 2) { die (STATE_UNKNOWN, _("FPING UNKNOWN - IP address not found\n")); } if (result == 3) { die (STATE_UNKNOWN, _("FPING UNKNOWN - invalid commandline argument\n")); } if (result == 4) { die (STATE_UNKNOWN, _("FPING UNKNOWN - failed system call\n")); } } printf ("FPING %s - %s\n", state_text (status), server_name); return status; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { if (set_applet_wd() < 0) return -1; #ifdef SEAF_LANG_CHINESE char *seafile_locale_dir = g_build_filename (seafile_bin_dir, "i18n", NULL); /* init i18n */ setlocale (LC_ALL, "zh_CN"); bindtextdomain(GETTEXT_PACKAGE, seafile_locale_dir); bind_textdomain_codeset(GETTEXT_PACKAGE, "GBK"); textdomain(GETTEXT_PACKAGE); #endif if (count_process("seafile-applet") > 1) { MessageBox(NULL, _("Seafile is already running"), "Seafile", MB_OK); exit(1); } int argc; char **argv; char cmdbuf[1024]; GError *err = NULL; WSADATA wsadata; WSAStartup(0x0101, &wsadata); UNREFERENCED_PARAMETER(hPrevInstance); snprintf(cmdbuf, sizeof(cmdbuf), "seafile-applet.exe %s", lpCmdLine); char *xxx = _("Seafile Initialization"); char tmp[128]; snprintf(tmp, sizeof(tmp), "%s", xxx); if (!g_shell_parse_argv (cmdbuf, &argc, &argv, &err)) { if (err) applet_warning ("parse arguments failed %s\n", err->message); applet_exit(1); } g_type_init(); applet = g_new0 (SeafileApplet, 1); seafile_applet_init (hInstance); seafile_applet_start (argc, argv); MSG msg; HACCEL hAccelTable; memset(&msg, 0, sizeof(msg)); hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_STARTINTRAY)); while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int) msg.wParam; }
/* main() {{{ */ int main(int argc, char *argv[]) { P_DBF *p_dbf; FILE *output = NULL; int record_length, i; const char *filename, *export_filename = NULL; headerMethod writeHeader = NULL; footerMethod writeFooter = NULL; lineMethod writeLine = printDBF; int outputmode = -1; /* Index of option in struct options */ unsigned char *record; unsigned int dataset_deleted; #ifdef ENABLE_NLS setlocale (LC_ALL, ""); setlocale (LC_NUMERIC, "C"); bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); textdomain (GETTEXT_PACKAGE); #endif if (argc < 2) { usage(PACKAGE_NAME); /* Does not return */ exit(1); } /* Check if someone needs help */ for(i=1; i < argc; i++) if(strcmp(argv[i],"-h")==0 || strcmp(argv[i],"--help")==0 || strcmp(argv[i],"/?")==0) usage(PACKAGE_NAME); /* Does not return */ /* Check if someone wants only version output */ for(i=1; i < argc; i++) { if( strcmp(argv[i],"-v")==0 || strcmp(argv[i],"--version")==0 ) { banner(); exit(1); } } /* fill filename with last argument * Test if last argument is an option or a possible valid filename */ filename = argv[--argc]; if (filename[0] == '-' && filename[1] != '\0') { fprintf(stderr, _("No input file specified. Please make sure that the last argument is a valid dBASE file.")); fprintf(stderr, "\n"); exit(1); } /* Open the input dBASE file */ if(NULL == (p_dbf = dbf_Open(filename))) { fprintf(stderr, _("Could not open dBASE file '%s'."), filename); fprintf(stderr, "\n"); exit(1); } /* Check for calling name of the programm */ if(!strcmp(argv[0], "dbfinfo")) { struct options *option = options; int optionindex; optionindex = 0; while (option->id && strcmp("--view-info", option->id)) { option++; optionindex++; } if (option->id != NULL) { writeHeader = option->writeHeader; writeFooter = option->writeFooter; writeLine = option->writeLine; outputmode = optionindex; } else { fprintf(stderr, _("Could not find predefined option when calling '%s'"), argv[0]); fprintf(stderr, "\n"); } } /* Scan through arguments looking for options */ for(i=1; i < argc; i++) { struct options *option = options; int optionindex; if (argv[i][0] != '-' && argv[i][1] != '-') goto badarg; optionindex = 0; while (option->id && strcmp(argv[i], option->id)) { option++; optionindex++; } if (option->id == NULL) { badarg: fprintf(stderr, _("Unrecognized option ``%s''. Try ``--help'' for a list of options."), argv[i]); fprintf(stderr, "\n"); exit(1); } if(option->class == ARG_CLASS_OUTPUT && outputmode >= 0) { fprintf(stderr, _("Output mode cannot be set twice. Has been set with '%s' already. Discarding option '%s'."), options[outputmode].id, option->id); fprintf(stderr, "\n"); /* Consume the next parametere containing the output file */ if((option->argument == ARG_OUTPUT) && (i < argc)) i++; } else { if(option->class == ARG_CLASS_OUTPUT) outputmode = optionindex; switch (option->argument) { case ARG_OUTPUT: if (export_filename) { fprintf(stderr, _("Output file name was already specified as ``%s''. Try the --help for a list of options."), export_filename); fprintf(stderr, "\n"); exit(1); } export_filename = argv[++i]; /* Fail safe routine to keep sure that the original file can * never be overwritten */ if ( strcmp(export_filename, filename) == 0 ) { fprintf(stderr, _("Input file name is equal to output file name. Please choose a different output file name.")); fprintf(stderr, "\n"); exit(1); } /* FALLTHROUGH */ case ARG_NONE: writeHeader = option->writeHeader; writeFooter = option->writeFooter; writeLine = option->writeLine; break; case ARG_OPTION: i++; /* FALLTHROUGH */ case ARG_BOOLEAN: /* There can be many -- call them all: */ if (option->writeHeader && option->writeHeader(NULL, p_dbf, filename, argv[i])) exit (1); break; default: assert(!"Unknown type of option argument"); } } }