static int param_history(t_history **history, char **cmd) { ptr_f_built_history func[6]; char **args; int i; create_ptr_built_history(func); args = create_args_history(); i = 0; if (cmd[1]) while (func[i] && strncmp(args[i], cmd[1], strlen(args[i]))) i++; if (func[i] == NULL) { if (cmd[1] && cmd[1][0] == '-' && cmd[1][1] == '\0') show_history(*history, NULL); else fprintf(stderr, "Usage: history [-chrST] [#number of events].\n"); return (EXIT_FAILURE); } else if (!func[i](&cmd[1], history)) return (EXIT_SUCCESS); else return (EXIT_FAILURE); return (EXIT_FAILURE); }
int check_history(t_global *global, char **cmd) { if (!cmd[1]) show_history(global->hist, NULL); else if (cmd[1] && !put_error(cmd[1], 0) && !cmd[2]) show_history(global->hist, cmd[1]); else if (cmd[1] && cmd[2] && cmd[3]) { fprintf(stderr, "%s: Too many arguments.\n", cmd[0]); return (EXIT_FAILURE); } else if (cmd[1] || (cmd[1] && cmd[2])) { if (param_history(&global->hist, cmd)) return (EXIT_FAILURE); } return (EXIT_SUCCESS); }
void SimuSchedule(void) { printf("begin SimuSchedule"); while(1) { //检查当前是否是时间窗口 if(is_time_window()) { clear_proc_belong_cpu(); } //更新所有进程的实时优先级和状态 refresh_all_proc(); //为所有进程排序,优先级数值小的靠前 sort_for_all_proc(); __show_runqueue(); //恢复所有core的curr refresh_all_core(); //更新所有core的当前优先级 update_prio_all_core(); //为所有core排序,优先级数值大的靠前 sort_for_all_core(); __show_core_list(); while(is_core_free() && is_proc_need_dispatch()) { //从优先级数值最低的一个进程选择核 Task_Struct* pTask_Struct_temp = select_first_no_dispatch_proc(); //考虑过的进程,将be_dispatch置位 dispatch_proc(pTask_Struct_temp); } //检查整个runqueue是否还有进程需要运行 if(is_runqueue_over()) { printf("all proc run over\n"); break; } __show_dispatch_result(); //process_manager的curr_timestamp向前推进一个 scheduler_tick(); } show_history(); }
bool console_module::call_method(int id, base_stream &out, const std::vector<std::string> &args) { switch (id) { case console_method_allow_access: return allow_addr(args); case console_method_deny_access: return deny_addr(args); case console_method_allow_local_access: return allow_local(args); case console_method_attach_log: return attach_log(out, args); case console_method_show_history: if (!args.empty()) return false; return show_history(out); } return node::call_method(id, out, args); }
int show_prompthistory_menu(FileView *view) { return show_history(view, PROMPTHISTORY, &cfg.prompt_hist, "Prompt History"); }
int show_bsearchhistory_menu(FileView *view) { return show_history(view, BSEARCHHISTORY, &cfg.search_hist, "Search History"); }
int show_cmdhistory_menu(FileView *view) { return show_history(view, CMDHISTORY, &cfg.cmd_hist, "Command Line History"); }
//=============== SEQUENTIAL ==================== int main(int argc, char ** argv) { int i, j; //genrate one round of league game oneround[10]; game odds_history[R][M]; round_generate(league,oneround); init_odds(oneround); // test_round_generate(league,oneround); // all of the player gamester players[N]; // money in the pool stack total_stack[10]; // money should pay stack total_payoff[10]; // ----------- DEBUGGING -------------- // init_gamester(players, oneround); // init_stack(total_stack); // init_stack(total_payoff); // // bet_iterate(players, oneround, total_stack, total_stack); // test_round_generate(league, oneround); // show_gamester(players, N); // // show_stack(total_payoff); // show_stack(total_stack); // ------------------------------------ clock_t start = clock(); // the odds updates R times for (i = 0; i < R; ++i) { // every time there are new gamblers init_gamester(players, oneround); // for N gambler for (j = 0; j<N; ++j) { // every gambler bet bet_iterate(players + j, oneround, odds_history, i, total_stack, total_payoff); } // for M games for (j = 0; j<M; ++j) { // the gambler maker updates the odds update_odds(oneround+j, total_stack+j, total_payoff+j, 0.1); } // copy the current odds into history record copy_odds(oneround, odds_history[i]); } double duration = (clock() - start) / CLOCKS_PER_SEC; printf("%f\n", duration); // test_round_generate(league,oneround); show_history(odds_history); //=============== SEQUENTIAL ==================== // -------------- DEBUGGING ------------------- // show_gamester(players, N); // show_stack(total_stack); // show_stack(total_payoff); // -------------------------------------------- return 0; }
gint main (gint argc, gchar *argv[]) { G_PASTE_INIT_GETTEXT (); if (argc > 1) { if (is_help (argv[1])) { show_help (argv[0]); return EXIT_SUCCESS; } else if (is_version (argv[1])) { show_version (); return EXIT_SUCCESS; } } int status = EXIT_SUCCESS; G_PASTE_CLEANUP_ERROR_FREE GError *error = NULL; G_PASTE_CLEANUP_UNREF GPasteClient *client = g_paste_client_new_sync (&error); if (!client) failure_exit (error); if (!isatty (fileno (stdin))) { /* We are being piped */ G_PASTE_CLEANUP_STRING_FREE GString *data = g_string_new (""); gchar c; while ((c = fgetc (stdin)) != EOF) data = g_string_append_c (data, c); data->str[data->len - 1] = '\0'; g_paste_client_add_sync (client, data->str, &error); } else { const gchar *arg1, *arg2; switch (argc) { case 1: show_history (client, FALSE, FALSE, &error); break; case 2: arg1 = argv[1]; if (!g_strcmp0 (arg1, "start") || !g_strcmp0 (arg1, "d") || !g_strcmp0 (arg1, "daemon")) { g_paste_client_track_sync (client, TRUE, &error); } else if (!g_strcmp0 (arg1, "stop") || !g_strcmp0 (arg1, "q") || !g_strcmp0 (arg1, "quit")) { g_paste_client_track_sync (client, FALSE, &error); } else if (!g_strcmp0 (arg1, "e") || !g_strcmp0 (arg1, "empty")) { g_paste_client_empty_sync (client, &error); } #if G_PASTE_CONFIG_ENABLE_APPLET else if (!g_strcmp0 (arg1, "applet")) { g_spawn_command_line_async (PKGLIBEXECDIR "/gpaste-applet", &error); if (error) { g_critical ("%s: %s", _("Couldn't spawn gpaste-applet.\n"), error->message); g_clear_error (&error); status = EXIT_FAILURE; } } #endif else if (!g_strcmp0 (arg1, "s") || !g_strcmp0 (arg1, "settings") || !g_strcmp0 (arg1, "p") || !g_strcmp0 (arg1, "preferences")) { execl (PKGLIBEXECDIR "/gpaste-settings", "GPaste-Settings", NULL); } else if (!g_strcmp0 (arg1, "dr") || !g_strcmp0 (arg1, "daemon-reexec")) { g_paste_client_reexecute_sync (client, &error); if (error && error->code == G_DBUS_ERROR_NO_REPLY) { printf (_("Successfully reexecuted the daemon\n")); return EXIT_SUCCESS; } } else if (!g_strcmp0 (arg1, "h") || !g_strcmp0 (arg1, "history")) { show_history (client, FALSE, FALSE, &error); } else if (!g_strcmp0 (arg1, "hs") || !g_strcmp0 (arg1, "history-size")) { guint32 size = g_paste_client_get_history_size_sync (client, &error); if (!error) printf ("%u\n", size); } else if (!g_strcmp0 (arg1, "rh") || !g_strcmp0 (arg1, "raw-history")) { show_history (client, TRUE, FALSE, &error); } else if (!g_strcmp0 (arg1, "zh") || !g_strcmp0 (arg1, "zero-history")) { show_history (client, FALSE, TRUE, &error); } else if (!g_strcmp0 (arg1, "lh") || !g_strcmp0 (arg1, "list-histories")) { G_PASTE_CLEANUP_STRFREEV GStrv histories = g_paste_client_list_histories_sync (client, &error); if (!error) { for (GStrv h = histories; *h; ++h) printf ("%s\n", *h); } } else if (!g_strcmp0 (argv[1], "about")) { g_paste_client_about_sync (client, &error); } else { show_help (argv[0]); status = EXIT_FAILURE; } break; case 3: arg1 = argv[1]; arg2 = argv[2]; if (!g_strcmp0 (arg1, "bh")|| !g_strcmp0 (arg1, "backup-history")) { g_paste_client_backup_history_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "sh") || !g_strcmp0 (arg1, "switch-history")) { g_paste_client_switch_history_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "dh") || !g_strcmp0 (arg1, "delete-history")) { g_paste_client_delete_history_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "a") || !g_strcmp0 (arg1, "add")) { g_paste_client_add_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "g")|| !g_strcmp0 (arg1, "get")) { printf ("%s", g_paste_client_get_element_sync (client, g_ascii_strtoull (arg2, NULL, 0), &error)); } else if (!g_strcmp0 (arg1, "s") || !g_strcmp0 (arg1, "set") || !g_strcmp0 (arg1, "select")) { g_paste_client_select_sync (client, g_ascii_strtoull (arg2, NULL, 0), &error); } else if (!g_strcmp0 (arg1, "d") || !g_strcmp0 (arg1, "delete")) { g_paste_client_delete_sync (client, g_ascii_strtoull (arg2, NULL, 0), &error); } else if (!g_strcmp0 (arg1, "f") || !g_strcmp0 (arg1, "file")) { g_paste_client_add_file_sync (client, arg2, &error); } else { show_help (argv[0]); status = EXIT_FAILURE; } break; default: show_help (argv[0]); status = EXIT_FAILURE; break; } } if (error) failure_exit (error); return status; }
int main(int argc, char *argv[]) { int ret; int num_pkts; char *dev = NULL; char errbuf[PCAP_ERRBUF_SIZE]; pcap_t *dev_handle; const u_char *packet; struct pcap_pkthdr hdr; struct ether_header *eptr; #ifdef WITH_HISTORY conn = connect_to_database(LOCALHOST, DATABASE, USER, PW); #endif char *ival = NULL; int iflag = 0; int c; opterr = 0; while ((c = getopt(argc, argv, "i:csh")) != -1) { switch (c) { /* select interface */ case 'i': ival = optarg; iflag = 1; break; /* clear history table */ case 'c': #ifdef WITH_HISTORY clear_history(conn); exit_nicely("History cleared"); #else exit_nicely("History database not in use."); #endif /* show history */ case 's': #ifdef WITH_HISTORY show_history(conn); exit_nicely(NULL); #else exit_nicely("History database not in use."); #endif /* print help */ case 'h': fprintf(stdout, "netSnarf Help:\n\tsnarf [OPTION]" "\nOPTIONS\n" "\t-c " "clear history records (requires database module)\n" "\t-h " "help, prints cli options\n" "\t-i <interface> " "selects network interface to use for sniffing\n" "\t-s " "show history records (requires database module)\n"); exit_nicely(""); case '?': if (optopt == 'i') { fprintf(stderr, "Option -%c requires an argurment.\n", optopt); } else if (isprint(optopt)) { fprintf(stderr, "Unknown option '-%c'.\n", optopt); } else { fprintf(stderr, "Unknown option character '\\x%x'.\n", optopt); } return 1; default: fprintf(stdout, "Starting packet sniffer\n"); } } /* Select device: wlan if developing, else lookup or supply via cli */ if (iflag) dev = ival; else { #ifdef WLAN dev = "wlan0"; #else dev = pcap_lookupdev(errbuf); #endif } if (dev == NULL) error_nicely(errbuf, __LINE__); /* Get basic information on capture interface/device */ device_info(dev, errbuf); dev_handle = pcap_open_live(dev, BUFSIZ, 0, -1, errbuf); if (!dev_handle) error_nicely(errbuf, __LINE__); /* primary packet handling engine */ pcap_loop(dev_handle, num_pkts, handle_packet, NULL); if (conn) mysql_close(conn); return 0; }
const std::string &string_input_popup::query_string( const bool loop, const bool draw_only ) { if( !w ) { create_window(); } if( !ctxt ) { create_context(); } utf8_wrapper ret( _text ); utf8_wrapper edit( ctxt->get_edittext() ); if( _position == -1 ) { _position = ret.length(); } const int scrmax = _endx - _startx; // in output (console) cells, not characters of the string! int shift = 0; bool redraw = true; int ch = 0; do { if( _position < 0 ) { _position = 0; } const size_t left_shift = ret.substr( 0, _position ).display_width(); if( ( int )left_shift < shift ) { shift = 0; } else if( _position < ( int )ret.length() && ( int )left_shift + 1 >= shift + scrmax ) { // if the cursor is inside the input string, keep one cell right of // the cursor visible, because the cursor might be on a multi-cell // character. shift = left_shift - scrmax + 2; } else if( _position == ( int )ret.length() && ( int )left_shift >= shift + scrmax ) { // cursor is behind the end of the input string, keep the // trailing '_' visible (always a single cell character) shift = left_shift - scrmax + 1; } else if( shift < 0 ) { shift = 0; } const size_t xleft_shift = ret.substr_display( 0, shift ).display_width(); if( ( int )xleft_shift != shift ) { // This prevents a multi-cell character from been split, which is not possible // instead scroll a cell further to make that character disappear completely shift++; } if( redraw ) { redraw = false; draw( ret, edit, shift ); wrefresh( w ); } wrefresh( w ); if( draw_only ) { return _text; } const std::string action = ctxt->handle_input(); const input_event ev = ctxt->get_raw_input(); ch = ev.type == CATA_INPUT_KEYBOARD ? ev.get_first_input() : 0; if( callbacks[ch] ) { if( callbacks[ch]() ) { continue; } } // This class only registers the ANY_INPUT action by default. If the // client provides their own input_context with registered actions // besides ANY_INPUT, ignore those so that the client may handle them. if( action != "ANY_INPUT" ) { continue; } if( ch == KEY_ESCAPE ) { _text.clear(); _canceled = true; return _text; } else if( ch == '\n' ) { add_to_history( ret.str() ); _text = ret.str(); return _text; } else if( ch == KEY_UP ) { show_history( ret ); redraw = true; } else if( ch == KEY_DOWN || ch == KEY_NPAGE || ch == KEY_PPAGE || ch == KEY_BTAB || ch == 9 ) { /* absolutely nothing */ } else if( ch == KEY_RIGHT ) { if( _position + 1 <= ( int )ret.size() ) { _position++; } redraw = true; } else if( ch == KEY_LEFT ) { if( _position > 0 ) { _position--; } redraw = true; } else if( ch == 0x15 ) { // ctrl-u: delete all the things _position = 0; ret.erase( 0 ); redraw = true; // Move the cursor back and re-draw it } else if( ch == KEY_BACKSPACE ) { // but silently drop input if we're at 0, instead of adding '^' if( _position > 0 && _position <= ( int )ret.size() ) { //TODO: it is safe now since you only input ASCII chars _position--; ret.erase( _position, 1 ); redraw = true; } } else if( ch == KEY_HOME ) { _position = 0; redraw = true; } else if( ch == KEY_END ) { _position = ret.size(); redraw = true; } else if( ch == KEY_DC ) { if( _position < ( int )ret.size() ) { ret.erase( _position, 1 ); redraw = true; } } else if( ch == KEY_F( 2 ) ) { std::string tmp = get_input_string_from_file(); int tmplen = utf8_width( tmp ); if( tmplen > 0 && ( tmplen + utf8_width( ret.c_str() ) <= _max_length || _max_length == 0 ) ) { ret.append( tmp ); } } else if( !ev.text.empty() && _only_digits && !( isdigit( ev.text[0] ) || ev.text[0] == '-' ) ) { // ignore non-digit (and '-' is a digit as well) } else if( _max_length > 0 && ( int )ret.length() >= _max_length ) { // no further input possible, ignore key } else if( !ev.text.empty() ) { const utf8_wrapper t( ev.text ); ret.insert( _position, t ); _position += t.length(); edit.erase( 0 ); ctxt->set_edittext( edit.c_str() ); redraw = true; } else if( ev.edit_refresh ) { const utf8_wrapper t( ev.edit ); edit.erase( 0 ); edit.insert( 0, t ); ctxt->set_edittext( edit.c_str() ); redraw = true; } else if( ev.edit.empty() ) { edit.erase( 0 ); ctxt->set_edittext( edit.c_str() ); redraw = true; } } while( loop == true ); _text = ret.str(); return _text; }
int main() { int bg; char *args[ARGS_SIZE]; int cnt; char new_dir[MAX_PATH + 1]; // new_dir[0] = '\0'; char buf[MAX_PATH + 1]; memcpy(curdir, getcwd(buf, MAX_PATH + 1), MAX_PATH + 1); signal(SIGCHLD, handle_child_death); // free(shell_command_history); shell_command_history = (struct history_item **) malloc(HISTORY_SIZE*sizeof(struct history_item *)); for(int i = 0; i < HISTORY_SIZE; i++) { shell_command_history[i] = (struct history_item *) malloc(sizeof(struct history_item)); } while(1) { bg = 0; cnt = getcmd("\n>> ", args, &bg); args[cnt] = NULL; /* for (int i = 0; i < cnt; i++) printf("\nArg[%d] = %s", i, args[i]); */ printf("\n"); int history_element_to_execute; if ( (history_element_to_execute = atoi(args[0])) > 0) { printf("history_element_to_execute: %d\n", history_element_to_execute); memcpy(args, shell_command_history[history_element_to_execute-1], ARGS_SIZE); } save_to_history(args); if (strcmp(args[0],"history") == 0) { if (args[1] != NULL) { printf("history does not require any arguments.\n"); exit(-1); } show_history(); continue; } if (strcmp(args[0], "cd") == 0) { new_dir[0] = '\0'; strcat(new_dir, curdir); printf("%s\n", new_dir); if (args[1][0] == '/') { new_dir[0] = '\0'; } char slash[] = {'/', '\0'}; strcat(new_dir, slash); strcat(new_dir, args[1]); strcat(new_dir, slash); curdir[0] = '\0'; strcat(curdir, new_dir); chdir(new_dir); continue; } if (strcmp(args[0], "pwd") == 0) { char* cwd; cwd = getcwd(buf, MAX_PATH + 1); printf("%s", cwd); continue; } if (strcmp(args[0], "exit") == 0) { exit(0); } if (strcmp(args[0], "jobs") == 0) { print_jobs(); continue; } if (strcmp(args[0], "fg") == 0) { // waitpid(); int pos = strtol(args[1], NULL, 10); struct job * selected_job = get_job_at_pos(pos); if (selected_job == NULL) { printf("There was an issue. The selected job, %d, has not been found.\n", pos); continue; } int status = 0; waitpid(selected_job->pid, &status, 0); continue; } // char * file = malloc(sizeof); int child_pid = 0; if((child_pid = fork()) == 0) { int output_filename_index = cnt - 1; if (bg) { output_filename_index--; } if (output_filename_index < 1) { output_filename_index = 1; } printf("cnt: %d.\n", cnt); char* output_filename = malloc((MAX_PATH+1)*sizeof(char)); if (strcmp(args[output_filename_index - 1], ">") == 0) { char* arg = args[output_filename_index]; memcpy(output_filename, arg, strlen(arg)+1); printf("%s\n", output_filename); close(1); open(output_filename, O_WRONLY | O_CREAT, 0666); // int fd[2] = {0,1}; // pipe(fd); args[output_filename_index - 1] = NULL; } int result = execvp(args[0], args); if (result < 0) { printf("We got the errno %d", errno); } } else { // continue execution } if (bg) { // printf("\nBackground enabled..\n"); int inserted_job_pos = insert_job(child_pid, args); printf("Created job with pid: %d, at pos: %d", child_pid, inserted_job_pos); } else { // printf("\nBackground not enabled \n"); int status = 0; waitpid(child_pid, &status, 0); } printf("\n\n"); } }
/** * \brief Main function for the snowfocus program */ int main(int argc, char *argv[]) { snowstar::CommunicatorSingleton cs(argc, argv); std::string instrumentname; int steps = 10; double exposuretime = 1.0; double temperature = std::numeric_limits<double>::quiet_NaN(); std::string binning; std::string frame; std::string filtername; astro::focusing::Focusing::method_type method = astro::focusing::Focusing::FWHM; int c; int longindex; while (EOF != (c = getopt_long(argc, argv, "b:c:de:f:hi:m:r:t:", longopts, &longindex))) switch (c) { case 'b': binning = optarg; break; case 'c': astro::config::Configuration::set_default(optarg); break; case 'd': debuglevel = LOG_DEBUG; break; case 'e': exposuretime = std::stod(optarg); break; case 'f': filtername = optarg; break; case 'h': usage(argv[0]); return EXIT_SUCCESS; case 'i': instrumentname = optarg; break; case 'm': method = astro::focusing::Focusing::string2method(optarg); break; case 'r': frame = optarg; break; case 's': steps = std::stoi(optarg); break; case 't': temperature = std::stod(optarg); break; } // the next argument is the command if (argc <= optind) { throw std::runtime_error("not enough arguments"); } std::string command = argv[optind++]; debug(LOG_DEBUG, DEBUG_LOG, 0, "command: %s", command.c_str()); if (command == "help") { usage(argv[0]); return EXIT_SUCCESS; } // get the configuration ConfigurationPtr config = Configuration::get(); // check whether we have an instrument if (0 == instrumentname.size()) { throw std::runtime_error("instrument name not set"); } RemoteInstrument instrument(config->database(), instrumentname); // get the device names CcdPrx ccdprx = instrument.ccd_proxy(); std::string ccdname = ccdprx->getName(); FocuserPrx focuserprx = instrument.focuser_proxy(); std::string focusername = focuserprx->getName(); debug(LOG_DEBUG, DEBUG_LOG, 0, "ccd: %s focuser: %s", ccdname.c_str(), focusername.c_str()); // first get a connection to the server Ice::CommunicatorPtr ic = CommunicatorSingleton::get(); astro::ServerName servername = instrument.servername(astro::DeviceName::Ccd); Ice::ObjectPrx base = ic->stringToProxy( servername.connect("FocusingFactory")); FocusingFactoryPrx focusingfactory = FocusingFactoryPrx::checkedCast(base); // get the focusing interface FocusingPrx focusing = focusingfactory->get(ccdname, focusername); debug(LOG_DEBUG, DEBUG_LOG, 0, "got a focusing proxy"); // creating a callback Ice::ObjectPtr callback = new FocusCallbackI(); CallbackAdapter adapter(ic); Ice::Identity ident = adapter.add(callback); focusing->ice_getConnection()->setAdapter(adapter.adapter()); // handle the simple commands if (command == "status") { std::cout << "status: "; std::cout << focusingstate2string(focusing->status()); std::cout << std::endl; return EXIT_SUCCESS; } if (command == "history") { show_history(focusing->history()); return EXIT_SUCCESS; } if (command == "monitor") { std::cout << "current status: "; std::cout << focusingstate2string(focusing->status()); std::cout << std::endl; focusing->registerCallback(ident); signal(SIGINT, handler); while (!signal_received) { sleep(1); } focusing->unregisterCallback(ident); return EXIT_SUCCESS; } if (command == "cancel") { focusing->cancel(); std::cout << "cancel command sent" << std::endl; return EXIT_SUCCESS; } // throw exception for unknown commands if (command != "start") { throw std::runtime_error("unknown command"); } // make sure temperature is set CoolerPrx cooler; if (instrument.has(DeviceName::Cooler)) { cooler = instrument.cooler_proxy(); } CoolerTask coolertask(cooler, temperature); coolertask.wait(); // next two arguments are the interval boundaries if ((argc - optind) < 2) { throw std::runtime_error("missing intervale arguments"); } int min = std::stoi(argv[optind++]); int max = std::stoi(argv[optind++]); debug(LOG_DEBUG, DEBUG_LOG, 0, "interval [%d,%d]", min, max); if (min >= max) { throw std::runtime_error("not an interval"); } // ensure that focuser is ready FocusState state = focusing->status(); debug(LOG_DEBUG, DEBUG_LOG, 0, "current state = %d", state); if ((state == FocusMOVING) && (state == FocusMEASURING)) { throw std::runtime_error("already focusing"); } // set up the exposure CcdTask ccdtask(ccdprx); ccdtask.frame(frame); ccdtask.binning(binning); ccdtask.exposuretime(exposuretime); // set up the focusing focusing->setSteps(steps); focusing->setMethod(convert(method)); // start the focusing process debug(LOG_DEBUG, DEBUG_LOG, 0, "starting between %d and %d", min, max); focusing->start(min, max); debug(LOG_DEBUG, DEBUG_LOG, 0, "focusing started, status: %d", focusing->status()); // wait for the process to complete bool completed = false; signal(SIGINT, handler); do { sleep(1); switch (focusing->status()) { case FocusIDLE: case FocusMOVING: case FocusMEASURING: break; case FocusFOCUSED: case FocusFAILED: completed = true; break; } } while ((!completed) && (!signal_received)); if (completed) { std::cout << "final focus position: " << focuserprx->current(); std::cout << std::endl; // display the history show_history(focusing->history()); } else { std::cout << "focusing incomplete" << std::endl; return EXIT_FAILURE; } return EXIT_SUCCESS; }
gint main (gint argc, gchar *argv[]) { G_PASTE_INIT_GETTEXT (); if (argc > 1) { if (is_help (argv[1])) { show_help (argv[0]); return EXIT_SUCCESS; } else if (is_version (argv[1])) { show_version (); return EXIT_SUCCESS; } } int status = EXIT_SUCCESS; G_PASTE_CLEANUP_ERROR_FREE GError *error = NULL; G_PASTE_CLEANUP_UNREF GPasteClient *client = g_paste_client_new_sync (&error); if (!client) failure_exit (error); if (!isatty (fileno (stdin)) && argc == 1) { /* We are being piped */ G_PASTE_CLEANUP_STRING_FREE GString *data = g_string_new (""); gchar c; while ((c = fgetc (stdin)) != EOF) data = g_string_append_c (data, c); data->str[data->len - 1] = '\0'; g_paste_client_add_sync (client, data->str, &error); } else { const gchar *arg1, *arg2, *arg3; switch (argc) { case 1: show_history (client, FALSE, FALSE, &error); break; case 2: arg1 = argv[1]; if (!g_strcmp0 (arg1, "about")) g_paste_client_about_sync (client, &error); else if (!g_strcmp0 (arg1, "dr") || !g_strcmp0 (arg1, "daemon-reexec")) { g_paste_client_reexecute_sync (client, &error); if (error && error->code == G_DBUS_ERROR_NO_REPLY) { printf (_("Successfully reexecuted the daemon\n")); return EXIT_SUCCESS; } } else if (!g_strcmp0 (arg1, "dv") || !g_strcmp0 (arg1, "daemon-version")) { G_PASTE_CLEANUP_FREE gchar *v = g_paste_client_get_version (client); printf ("%s\n", v); } else if (!g_strcmp0 (arg1, "e") || !g_strcmp0 (arg1, "empty")) { g_paste_client_empty_sync (client, &error); } else if (!g_strcmp0 (arg1, "h") || !g_strcmp0 (arg1, "history")) { show_history (client, FALSE, FALSE, &error); } else if (!g_strcmp0 (arg1, "hs") || !g_strcmp0 (arg1, "history-size")) { guint32 size = g_paste_client_get_history_size_sync (client, &error); if (!error) printf ("%u\n", size); } else if (!g_strcmp0 (arg1, "lh") || !g_strcmp0 (arg1, "list-histories")) { G_PASTE_CLEANUP_STRFREEV GStrv histories = g_paste_client_list_histories_sync (client, &error); if (!error) { for (GStrv h = histories; *h; ++h) printf ("%s\n", *h); } } else if (!g_strcmp0 (arg1, "rh") || !g_strcmp0 (arg1, "raw-history")) { show_history (client, TRUE, FALSE, &error); } else if (!g_strcmp0 (arg1, "s") || !g_strcmp0 (arg1, "settings") || !g_strcmp0 (arg1, "p") || !g_strcmp0 (arg1, "preferences")) { status = spawn ("Settings", &error); } else if (!g_strcmp0 (arg1, "start") || !g_strcmp0 (arg1, "d") || !g_strcmp0 (arg1, "daemon")) { g_paste_client_track_sync (client, TRUE, &error); } else if (!g_strcmp0 (arg1, "stop") || !g_strcmp0 (arg1, "q") || !g_strcmp0 (arg1, "quit")) { g_paste_client_track_sync (client, FALSE, &error); } else if (!g_strcmp0 (arg1, "zh") || !g_strcmp0 (arg1, "zero-history")) { show_history (client, FALSE, TRUE, &error); } #if G_PASTE_CONFIG_ENABLE_APPLET else if (!g_strcmp0 (arg1, "applet")) { status = spawn ("Applet", &error); } #endif #if G_PASTE_CONFIG_ENABLE_UNITY else if (!g_strcmp0 (arg1, "app-indicator")) { status = spawn ("AppIndicator", &error); } #endif else { show_help (argv[0]); status = EXIT_FAILURE; } break; case 3: arg1 = argv[1]; arg2 = argv[2]; if (!g_strcmp0 (arg1, "a") || !g_strcmp0 (arg1, "add")) { g_paste_client_add_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "bh") || !g_strcmp0 (arg1, "backup-history")) { g_paste_client_backup_history_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "d") || !g_strcmp0 (arg1, "del") || !g_strcmp0 (arg1, "delete") || !g_strcmp0 (arg1, "rm") || !g_strcmp0 (arg1, "remove")) { g_paste_client_delete_sync (client, _strtoull (arg2), &error); } else if (!g_strcmp0 (arg1, "dp") || !g_strcmp0 (arg1, "delete-password")) { g_paste_client_delete_password_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "dh") || !g_strcmp0 (arg1, "delete-history")) { g_paste_client_delete_history_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "f") || !g_strcmp0 (arg1, "file")) { g_paste_client_add_file_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "g") || !g_strcmp0 (arg1, "get")) { printf ("%s", g_paste_client_get_element_sync (client, _strtoull (arg2), &error)); } else if (!g_strcmp0 (arg1, "gr") || !g_strcmp0 (arg1, "get-raw")) { printf ("%s", g_paste_client_get_raw_element_sync (client, _strtoull (arg2), &error)); } else if (!g_strcmp0 (arg1, "s") || !g_strcmp0 (arg1, "set") || !g_strcmp0 (arg1, "select")) { g_paste_client_select_sync (client, _strtoull (arg2), &error); } else if (!g_strcmp0 (arg1, "sh") || !g_strcmp0 (arg1, "switch-history")) { g_paste_client_switch_history_sync (client, arg2, &error); } else { show_help (argv[0]); status = EXIT_FAILURE; } break; case 4: arg1 = argv[1]; arg2 = argv[2]; arg3 = argv[3]; if (!g_strcmp0 (arg1, "ap") || !g_strcmp0 (arg1, "add-password")) { g_paste_client_add_password_sync (client, arg2, arg3, &error); } else if (!g_strcmp0 (arg1, "rp") || !g_strcmp0 (arg1, "rename-password")) { g_paste_client_rename_password_sync (client, arg2, arg3, &error); } else if (!g_strcmp0 (arg1, "sp") || !g_strcmp0 (arg1, "set-password")) { g_paste_client_set_password_sync (client, _strtoull (arg2), arg3, &error); } else { show_help (argv[0]); status = EXIT_FAILURE; } break; default: show_help (argv[0]); status = EXIT_FAILURE; break; } } if (error) failure_exit (error); return status; }
int show_filterhistory_menu(FileView *view) { return show_history(view, FILTERHISTORY, &cfg.filter_hist, "Filter History"); }
int main(int argc, char **argv) { int flag; int rc = 0; int quiet = 0; int verbose = 0; int argerr = 0; int timeout = 120; int option_index = 0; int fence_level = 0; int no_connect = 0; int tolerance = 0; int as_nodeid = FALSE; char *name = NULL; char *value = NULL; char *target = NULL; char *lists = NULL; const char *agent = NULL; const char *device = NULL; const char *longname = NULL; char action = 0; stonith_t *st = NULL; stonith_key_value_t *params = NULL; stonith_key_value_t *devices = NULL; stonith_key_value_t *dIter = NULL; crm_log_cli_init("stonith_admin"); crm_set_options(NULL, "mode [options]", long_options, "Provides access to the stonith-ng API.\n" "\nAllows the administrator to add/remove/list devices, check device and host status and fence hosts\n"); async_fence_data.name = strdup(crm_system_name); while (1) { flag = crm_get_option_long(argc, argv, &option_index, &longname); if (flag == -1) break; switch (flag) { case 'V': verbose = 1; crm_bump_log_level(argc, argv); break; case '$': case '?': crm_help(flag, EX_OK); break; case 'I': no_connect = 1; /* fall through */ case 'L': action = flag; break; case 'q': quiet = 1; break; case 'Q': case 'R': case 'D': case 's': action = flag; device = optarg; break; case 'T': free(async_fence_data.name); async_fence_data.name = crm_strdup_printf("%s.%s", crm_system_name, optarg); break; case 'a': agent = optarg; break; case 'l': target = optarg; action = 'L'; break; case 'M': no_connect = 1; action = flag; break; case 't': timeout = crm_atoi(optarg, NULL); break; case 'B': case 'F': case 'U': /* using mainloop here */ no_connect = 1; /* fall through */ case 'C': /* Always log the input arguments */ crm_log_args(argc, argv); target = optarg; action = flag; break; case 'n': as_nodeid = TRUE; break; case 'h': case 'H': case 'r': case 'd': target = optarg; action = flag; break; case 'i': fence_level = crm_atoi(optarg, NULL); break; case 'v': devices = stonith_key_value_add(devices, NULL, optarg); break; case 'o': crm_info("Scanning: -o %s", optarg); rc = sscanf(optarg, "%m[^=]=%m[^=]", &name, &value); if (rc != 2) { crm_err("Invalid option: -o %s", optarg); ++argerr; } else { crm_info("Got: '%s'='%s'", name, value); params = stonith_key_value_add(params, name, value); } free(value); value = NULL; free(name); name = NULL; break; case 'e': { char *key = crm_concat("OCF_RESKEY", optarg, '_'); const char *env = getenv(key); if (env == NULL) { crm_err("Invalid option: -e %s", optarg); ++argerr; } else { crm_info("Got: '%s'='%s'", optarg, env); params = stonith_key_value_add(params, optarg, env); } } break; case 0: if (safe_str_eq("tolerance", longname)) { tolerance = crm_get_msec(optarg) / 1000; /* Send in seconds */ } break; default: ++argerr; break; } } if (optind > argc) { ++argerr; } if (argerr) { crm_help('?', EX_USAGE); } crm_debug("Create"); st = stonith_api_new(); crm_debug("Created"); if (!no_connect) { crm_debug("Connecting as %s", async_fence_data.name); rc = st->cmds->connect(st, async_fence_data.name, NULL); crm_debug("Connect: %d", rc); if (rc < 0) { goto done; } } switch (action) { case 'I': rc = st->cmds->list_agents(st, st_opt_sync_call, NULL, &devices, timeout); for (dIter = devices; dIter; dIter = dIter->next) { fprintf(stdout, " %s\n", dIter->value); } if (rc == 0) { fprintf(stderr, "No devices found\n"); } else if (rc > 0) { fprintf(stderr, "%d devices found\n", rc); rc = 0; } stonith_key_value_freeall(devices, 1, 1); break; case 'L': rc = st->cmds->query(st, st_opts, target, &devices, timeout); for (dIter = devices; dIter; dIter = dIter->next) { fprintf(stdout, " %s\n", dIter->value); } if (rc == 0) { fprintf(stderr, "No devices found\n"); } else if (rc > 0) { fprintf(stderr, "%d devices found\n", rc); rc = 0; } stonith_key_value_freeall(devices, 1, 1); break; case 'Q': rc = st->cmds->monitor(st, st_opts, device, timeout); if (rc < 0) { rc = st->cmds->list(st, st_opts, device, NULL, timeout); } break; case 's': rc = st->cmds->list(st, st_opts, device, &lists, timeout); if (rc == 0) { if (lists) { char *source = lists, *dest = lists; while (*dest) { if ((*dest == '\\') && (*(dest+1) == 'n')) { *source = '\n'; dest++; dest++; source++; } else if ((*dest == ',') || (*dest == ';')) { dest++; } else { *source = *dest; dest++; source++; } if (!(*dest)) { *source = 0; } } fprintf(stdout, "%s", lists); free(lists); } } else { fprintf(stderr, "List command returned error. rc : %d\n", rc); } break; case 'R': rc = st->cmds->register_device(st, st_opts, device, "stonith-ng", agent, params); break; case 'D': rc = st->cmds->remove_device(st, st_opts, device); break; case 'd': case 'r': rc = handle_level(st, target, fence_level, devices, action == 'r'); break; case 'M': if (agent == NULL) { printf("Please specify an agent to query using -a,--agent [value]\n"); return -1; } else { char *buffer = NULL; rc = st->cmds->metadata(st, st_opt_sync_call, agent, NULL, &buffer, timeout); if (rc == pcmk_ok) { printf("%s\n", buffer); } free(buffer); } break; case 'C': rc = st->cmds->confirm(st, st_opts, target); break; case 'B': rc = mainloop_fencing(st, target, "reboot", timeout, tolerance); break; case 'F': rc = mainloop_fencing(st, target, "off", timeout, tolerance); break; case 'U': rc = mainloop_fencing(st, target, "on", timeout, tolerance); break; case 'h': { time_t when = 0; if(as_nodeid) { uint32_t nodeid = atol(target); when = stonith_api_time(nodeid, NULL, FALSE); } else { when = stonith_api_time(0, target, FALSE); } if(when) { printf("Node %s last kicked at: %s\n", target, ctime(&when)); } else { printf("Node %s has never been kicked\n", target); } } break; case 'H': rc = show_history(st, target, timeout, quiet, verbose); break; } done: free(async_fence_data.name); crm_info("Command returned: %s (%d)", pcmk_strerror(rc), rc); if (rc < 0) { printf("Command failed: %s\n", pcmk_strerror(rc)); } stonith_key_value_freeall(params, 1, 1); st->cmds->disconnect(st); crm_debug("Disconnect: %d", rc); crm_debug("Destroy"); stonith_api_delete(st); return rc; }
/** @brief Yes we need a main function **/ int main(void) { int result = OK; /* get the variables passed to us */ process_cgivars(); /* reset internal CGI variables */ reset_cgi_vars(); /* read the CGI configuration file */ result = read_cgi_config_file(get_cgi_config_location()); if (result == ERROR) { document_header(CGI_ID, FALSE, "Error"); print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE, FALSE); document_footer(CGI_ID); return ERROR; } /* read the main configuration file */ result = read_main_config_file(main_config_file); if (result == ERROR) { document_header(CGI_ID, FALSE, "Error"); print_error(main_config_file, ERROR_CGI_MAIN_CFG, FALSE); document_footer(CGI_ID); return ERROR; } /* read all object configuration data */ result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA); if (result == ERROR) { document_header(CGI_ID, FALSE, "Error"); print_error(NULL, ERROR_CGI_OBJECT_DATA, FALSE); document_footer(CGI_ID); return ERROR; } /* overwrite config value with amount we got via GET */ result_limit = (get_result_limit != -1) ? get_result_limit : result_limit; document_header(CGI_ID, TRUE, "History"); /* get authentication information */ get_authentication_information(¤t_authdata); /* calculate timestamps for reading logs */ convert_timeperiod_to_times(TIMEPERIOD_SINGLE_DAY, &ts_start, &ts_end); if (display_header == TRUE) { /* begin top table */ printf("<table border=0 width=100%%>\n"); printf("<tr>\n"); /* left column of the first row */ printf("<td align=left valign=top width=33%%>\n"); if (display_type == DISPLAY_HOSTS) display_info_table("Host Alert History", ¤t_authdata, daemon_check); else if (display_type == DISPLAY_SERVICES) display_info_table("Service Alert History", ¤t_authdata, daemon_check); else if (display_type == DISPLAY_HOSTGROUPS) display_info_table("Host Group Alert History", ¤t_authdata, daemon_check); else if (display_type == DISPLAY_SERVICEGROUPS) display_info_table("Service Group Alert History", ¤t_authdata, daemon_check); else display_info_table("Alert History", ¤t_authdata, daemon_check); printf("<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 CLASS='linkBox'>\n"); printf("<TR><TD CLASS='linkBox'>\n"); if (display_type == DISPLAY_HOSTS) { printf("<a href='%s?host=%s'>View <b>Service Status Detail</b> For <b>%s</b></a><br>\n", STATUS_CGI, (show_all_hosts == TRUE) ? "all" : url_encode(host_name), (show_all_hosts == TRUE) ? "All Hosts" : "This Host"); printf("<a href='%s?host=%s'>View <b>Notifications</b> For <b>%s</b></a><br>\n", NOTIFICATIONS_CGI, (show_all_hosts == TRUE) ? "all" : url_encode(host_name), (show_all_hosts == TRUE) ? "All Hosts" : "This Host"); printf("<a href='%s?type=%d&host=%s'>View <b>Information</b> For <b>This Host</b></a><br>\n", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(host_name)); #ifdef USE_TRENDS if (show_all_hosts == FALSE) printf("<a href='%s?host=%s'>View <b>Trends</b> For <b>This Host</b></a>\n", TRENDS_CGI, url_encode(host_name)); #endif } else if (display_type == DISPLAY_SERVICES) { printf("<a href='%s?host=%s&service=%s'>View <b>Notifications</b> For <b>This Service</b></a><br>\n", NOTIFICATIONS_CGI, url_encode(host_name), url_encode(service_desc)); printf("<a href='%s?type=%d&host=%s&service=%s'>View <b>Information</b> For <b>This Service</b></a><br>\n", EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(host_name), url_encode(service_desc)); #ifdef USE_TRENDS printf("<a href='%s?host=%s&service=%s'>View <b>Trends</b> For <b>This Service</b></a><br>\n", TRENDS_CGI, url_encode(host_name), url_encode(service_desc)); #endif printf("<a href='%s?host=%s'>View <b>Alert History</b> For <b>This Host</b></a>\n", HISTORY_CGI, url_encode(host_name)); } else if (display_type == DISPLAY_HOSTGROUPS) { printf("<a href='%s?hostgroup=%s&style=hostdetail'>View <b>Host Status Detail</b> For <b>This Hostgroup</b></a><br>\n", STATUS_CGI, url_encode(hostgroup_name)); printf("<a href='%s?hostgroup=%s&style=detail'>View <b>Service Status Detail</b> For <b>This Hostgroup</b></a><br>\n", STATUS_CGI, url_encode(hostgroup_name)); printf("<a href='%s?hostgroup=%s'>View <b>Notifications</b> For <b>This Hostgroup</b></a>\n", NOTIFICATIONS_CGI, url_encode(hostgroup_name)); } else if (display_type == DISPLAY_SERVICEGROUPS) { printf("<a href='%s?servicegroup=%s&style=hostdetail'>View <b>Host Status Detail</b> For <b>This Servicegroup</b></a><br>\n", STATUS_CGI, url_encode(servicegroup_name)); printf("<a href='%s?servicegroup=%s&style=detail'>View <b>Service Status Detail</b> For <b>This Servicegroup</b></a><br>\n", STATUS_CGI, url_encode(servicegroup_name)); printf("<a href='%s?servicegroup=%s'>View <b>Notifications</b> For <b>This Servicegroup</b></a>\n", NOTIFICATIONS_CGI, url_encode(servicegroup_name)); } printf("</TD></TR>\n"); printf("</TABLE>\n"); printf("</td>\n"); /* middle column of top row */ printf("<td align=center valign=top width=33%%>\n"); printf("<DIV ALIGN=CENTER CLASS='dataTitle'>\n"); if (display_type == DISPLAY_SERVICES) printf("Service '%s' On Host '%s'", html_encode(service_desc, TRUE), html_encode(host_name, TRUE)); else if (display_type == DISPLAY_HOSTS) { if (show_all_hosts == TRUE) printf("All Hosts and Services"); else printf("Host '%s'", html_encode(host_name, TRUE)); } else if (display_type == DISPLAY_HOSTGROUPS) printf("Host Group '%s'", html_encode(hostgroup_name, TRUE)); else if (display_type == DISPLAY_SERVICEGROUPS) printf("Service Group '%s'", html_encode(servicegroup_name, TRUE)); printf("</DIV>\n"); printf("<BR />\n"); display_nav_table(ts_start, ts_end); printf("</td>\n"); /* right hand column of top row */ printf("<td align=right valign=top width=33%%>\n"); printf("<form method=\"GET\" action=\"%s\">\n", HISTORY_CGI); printf("<input type='hidden' name='ts_start' value='%lu'>\n", ts_start); printf("<input type='hidden' name='ts_end' value='%lu'>\n", ts_end); printf("<input type='hidden' name='limit' value='%d'>\n", result_limit); if (display_type == DISPLAY_HOSTGROUPS) printf("<input type='hidden' name='hostgroup' value='%s'>\n", escape_string(hostgroup_name)); else if (display_type == DISPLAY_SERVICEGROUPS) printf("<input type='hidden' name='servicegroup' value='%s'>\n", escape_string(servicegroup_name)); else { printf("<input type='hidden' name='host' value='%s'>\n", (show_all_hosts == TRUE) ? "all" : escape_string(host_name)); if (display_type == DISPLAY_SERVICES) printf("<input type='hidden' name='service' value='%s'>\n", escape_string(service_desc)); } printf("<table border=0 CLASS='optBox'>\n"); printf("<tr>\n"); printf("<td align=left CLASS='optBoxItem'>State type options:</td>\n"); printf("</tr>\n"); printf("<tr>\n"); printf("<td align=left CLASS='optBoxItem'><select name='statetype'>\n"); printf("<option value=%d %s>All state types</option>\n", STATE_ALL, (state_options == STATE_ALL) ? "selected" : ""); printf("<option value=%d %s>Soft states</option>\n", STATE_SOFT, (state_options == STATE_SOFT) ? "selected" : ""); printf("<option value=%d %s>Hard states</option>\n", STATE_HARD, (state_options == STATE_HARD) ? "selected" : ""); printf("</select></td>\n"); printf("</tr>\n"); printf("<tr>\n"); printf("<td align=left CLASS='optBoxItem'>History detail level for "); if (display_type == DISPLAY_HOSTGROUPS || display_type == DISPLAY_SERVICEGROUPS) printf("this %sgroup", (display_type == DISPLAY_HOSTGROUPS) ? "host" : "service"); else if (display_type == DISPLAY_HOSTS) printf("%s host%s", (show_all_hosts == TRUE) ? "all" : "this", (show_all_hosts == TRUE) ? "s" : ""); else printf("service"); printf(":</td>\n"); printf("</tr>\n"); printf("<tr>\n"); printf("<td align=left CLASS='optBoxItem'><select name='type'>\n"); if (display_type == DISPLAY_HOSTS || display_type == DISPLAY_HOSTGROUPS) printf("<option value=%d %s>All alerts</option>\n", HISTORY_ALL, (history_options == HISTORY_ALL) ? "selected" : ""); printf("<option value=%d %s>All service alerts</option>\n", HISTORY_SERVICE_ALL, (history_options == HISTORY_SERVICE_ALL) ? "selected" : ""); if (display_type == DISPLAY_HOSTS || display_type == DISPLAY_HOSTGROUPS) printf("<option value=%d %s>All host alerts</option>\n", HISTORY_HOST_ALL, (history_options == HISTORY_HOST_ALL) ? "selected" : ""); printf("<option value=%d %s>Service warning</option>\n", HISTORY_SERVICE_WARNING, (history_options == HISTORY_SERVICE_WARNING) ? "selected" : ""); printf("<option value=%d %s>Service unknown</option>\n", HISTORY_SERVICE_UNKNOWN, (history_options == HISTORY_SERVICE_UNKNOWN) ? "selected" : ""); printf("<option value=%d %s>Service critical</option>\n", HISTORY_SERVICE_CRITICAL, (history_options == HISTORY_SERVICE_CRITICAL) ? "selected" : ""); printf("<option value=%d %s>Service recovery</option>\n", HISTORY_SERVICE_RECOVERY, (history_options == HISTORY_SERVICE_RECOVERY) ? "selected" : ""); if (display_type == DISPLAY_HOSTS || display_type == DISPLAY_HOSTGROUPS) { printf("<option value=%d %s>Host down</option>\n", HISTORY_HOST_DOWN, (history_options == HISTORY_HOST_DOWN) ? "selected" : ""); printf("<option value=%d %s>Host unreachable</option>\n", HISTORY_HOST_UNREACHABLE, (history_options == HISTORY_HOST_UNREACHABLE) ? "selected" : ""); printf("<option value=%d %s>Host recovery</option>\n", HISTORY_HOST_RECOVERY, (history_options == HISTORY_HOST_RECOVERY) ? "selected" : ""); } printf("</select></td>\n"); printf("</tr>\n"); printf("<tr>\n"); printf("<td align=left valign=bottom CLASS='optBoxItem'><input type='checkbox' name='noflapping' %s> Hide Flapping Alerts</td>", (display_flapping_alerts == FALSE) ? "checked" : ""); printf("</tr>\n"); printf("<tr>\n"); printf("<td align=left valign=bottom CLASS='optBoxItem'><input type='checkbox' name='nodowntime' %s> Hide Downtime Alerts</td>", (display_downtime_alerts == FALSE) ? "checked" : ""); printf("</tr>\n"); printf("<tr>\n"); printf("<td align=left valign=bottom CLASS='optBoxItem'><input type='checkbox' name='nosystem' %s> Hide Process Messages</td>", (display_system_messages == FALSE) ? "checked" : ""); printf("</tr>\n"); printf("<tr>\n"); printf("<td align=left valign=bottom CLASS='optBoxItem'><input type='checkbox' name='order' value='old2new' %s> Older Entries First</td>", (reverse == TRUE) ? "checked" : ""); printf("</tr>\n"); printf("<tr>\n"); printf("<td align=left CLASS='optBoxItem'><input type='submit' value='Update'></td>\n"); printf("</tr>\n"); printf("</table>\n"); printf("</form>\n"); printf("</td>\n"); /* end of top table */ printf("</tr>\n"); printf("</table>\n"); } /* display history */ show_history(); document_footer(CGI_ID); /* free allocated memory */ free_memory(); return OK; }
gint main (gint argc, gchar *argv[]) { G_PASTE_INIT_GETTEXT (); g_set_prgname (argv[0]); struct option long_options[] = { { "decoration", required_argument, NULL, 'd' }, { "help", no_argument, NULL, 'h' }, { "oneline", no_argument, NULL, 'o' }, { "raw" , no_argument, NULL, 'r' }, { "separator" , required_argument, NULL, 's' }, { "version", no_argument, NULL, 'v' }, { "zero", no_argument, NULL, 'z' }, { NULL, no_argument, NULL, '\0' } }; gboolean help = FALSE, version = FALSE; gboolean oneline = FALSE, raw = FALSE, zero = FALSE; const gchar *decoration = NULL, *separator = NULL; gint c; while ((c = getopt_long(argc, argv, "d:hors:vz", long_options, NULL)) != -1) { switch (c) { case 'd': decoration = optarg; break; case 'h': help = TRUE; break; case 'o': oneline = TRUE; break; case 'r': raw = TRUE; break; case 's': separator = optarg; break; case 'v': version = TRUE; break; case 'z': zero = TRUE; break; default: return EXIT_FAILURE; } } argv += optind; argc -= optind; if (help || (argc > 0 && !g_strcmp0 (argv[0], "help"))) { show_help (); return EXIT_SUCCESS; } else if (version || (argc > 0 && is_version (argv[0]))) { show_version (); return EXIT_SUCCESS; } int status = EXIT_SUCCESS; g_autoptr (GError) error = NULL; g_autoptr (GPasteClient) client = g_paste_client_new_sync (&error); if (!client) failure_exit (error); gboolean was_valid_pipe = FALSE; if (!isatty (fileno (stdin))) { /* We are being piped */ G_PASTE_CLEANUP_STRING_FREE GString *data = g_string_new (NULL); while ((c = fgetc (stdin)) != EOF) data = g_string_append_c (data, (guchar)c); data->str[data->len - 1] = '\0'; if (!argc) { g_paste_client_add_sync (client, data->str, &error); was_valid_pipe = TRUE; } else if (argc == 2) { const gchar *arg1 = argv[0]; const gchar *arg2 = argv[1]; if (!g_strcmp0 (arg1, "ap") || !g_strcmp0 (arg1, "add-password")) { g_paste_client_add_password_sync (client, arg2, data->str, &error); was_valid_pipe = TRUE; } } } if (was_valid_pipe) {} else if (argc > 0 && (!g_strcmp0 (argv[0], "merge") || !g_strcmp0 (argv[0], "m"))) { --argc; ++argv; guint32 *indexes = alloca (argc * sizeof (guint32)); for (gint i = 0; i < argc; ++i) indexes[i] = _strtoull (argv[i]); g_paste_client_merge_sync (client, decoration, separator, indexes, argc, &error); } else { const gchar *arg1, *arg2, *arg3; switch (argc) { case 0: show_history (client, oneline, raw, zero, &error); break; case 1: arg1 = argv[0]; if (!g_strcmp0 (arg1, "about")) g_paste_client_about_sync (client, &error); else if (!g_strcmp0 (arg1, "dr") || !g_strcmp0 (arg1, "daemon-reexec")) { g_paste_client_reexecute_sync (client, &error); if (error && error->code == G_DBUS_ERROR_NO_REPLY) { printf (_("Successfully reexecuted the daemon\n")); return EXIT_SUCCESS; } } else if (!g_strcmp0 (arg1, "dv") || !g_strcmp0 (arg1, "daemon-version")) { g_autofree gchar *v = g_paste_client_get_version (client); printf ("%s\n", v); } else if (!g_strcmp0 (arg1, "e") || !g_strcmp0 (arg1, "empty")) { g_paste_client_empty_sync (client, &error); } else if (!g_strcmp0 (arg1, "h") || !g_strcmp0 (arg1, "history")) { show_history (client, oneline, raw, zero, &error); } else if (!g_strcmp0 (arg1, "hs") || !g_strcmp0 (arg1, "history-size")) { guint32 size = g_paste_client_get_history_size_sync (client, &error); if (!error) printf ("%u\n", size); } else if (!g_strcmp0 (arg1, "lh") || !g_strcmp0 (arg1, "list-histories")) { g_auto (GStrv) histories = g_paste_client_list_histories_sync (client, &error); if (!error) { for (GStrv h = histories; *h; ++h) printf ("%s\n", *h); } } else if (!g_strcmp0 (arg1, "settings") || !g_strcmp0 (arg1, "p") || !g_strcmp0 (arg1, "preferences")) { if (!g_paste_util_activate_ui_sync ("prefs", NULL, &error)) { g_critical ("%s Ui: %s", _("Couldn't spawn"), error->message); return EXIT_FAILURE; } } else if (!g_strcmp0 (arg1, "show-history")) { g_paste_client_show_history_sync (client, &error); } else if (!g_strcmp0 (arg1, "start") || !g_strcmp0 (arg1, "d") || !g_strcmp0 (arg1, "daemon")) { g_paste_client_track_sync (client, TRUE, &error); } else if (!g_strcmp0 (arg1, "stop") || !g_strcmp0 (arg1, "q") || !g_strcmp0 (arg1, "quit")) { g_paste_client_track_sync (client, FALSE, &error); } else if (!g_strcmp0 (arg1, "ui")) { status = spawn ("Ui"); } else if (g_paste_util_has_applet () && !g_strcmp0 (arg1, "applet")) { status = spawn ("Applet"); } else if (g_paste_util_has_unity () && !g_strcmp0 (arg1, "app-indicator")) { status = spawn ("AppIndicator"); } else { show_help (); status = EXIT_FAILURE; } break; case 2: arg1 = argv[0]; arg2 = argv[1]; if (!g_strcmp0 (arg1, "a") || !g_strcmp0 (arg1, "add")) { g_paste_client_add_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "bh") || !g_strcmp0 (arg1, "backup-history")) { g_paste_client_backup_history_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "d") || !g_strcmp0 (arg1, "del") || !g_strcmp0 (arg1, "delete") || !g_strcmp0 (arg1, "rm") || !g_strcmp0 (arg1, "remove")) { g_paste_client_delete_sync (client, _strtoull (arg2), &error); } else if (!g_strcmp0 (arg1, "dp") || !g_strcmp0 (arg1, "delete-password")) { g_paste_client_delete_password_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "dh") || !g_strcmp0 (arg1, "delete-history")) { g_paste_client_delete_history_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "f") || !g_strcmp0 (arg1, "file")) { g_paste_client_add_file_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "g") || !g_strcmp0 (arg1, "get")) { const gchar *value = (!raw) ? g_paste_client_get_element_sync (client, _strtoull (arg2), &error) : g_paste_client_get_raw_element_sync (client, _strtoull (arg2), &error); if (!error) printf ("%s", value); } else if (!g_strcmp0 (arg1, "search")) { gsize hits; g_autofree guint32 *results = g_paste_client_search_sync (client, arg2, &hits, &error); if (!error) { if (hits > 0) { for (gsize i = 0; i < hits; ++i) { guint32 index = results[i]; gchar *line = g_paste_client_get_element_sync (client, index, &error); if (error) break; print_history_line (line, index, oneline, raw, zero); } } } } else if (!g_strcmp0 (arg1, "s") || !g_strcmp0 (arg1, "set") || !g_strcmp0 (arg1, "select")) { g_paste_client_select_sync (client, _strtoull (arg2), &error); } else if (!g_strcmp0 (arg1, "sh") || !g_strcmp0 (arg1, "switch-history")) { g_paste_client_switch_history_sync (client, arg2, &error); } else if (!g_strcmp0 (arg1, "u") || !g_strcmp0 (arg1, "upload")) { g_paste_client_upload_sync (client, _strtoull (arg2), &error); } else { show_help (); status = EXIT_FAILURE; } break; case 3: arg1 = argv[0]; arg2 = argv[1]; arg3 = argv[2]; if (!g_strcmp0 (arg1, "ap") || !g_strcmp0 (arg1, "add-password")) { g_paste_client_add_password_sync (client, arg2, arg3, &error); } else if (!g_strcmp0 (arg1, "rp") || !g_strcmp0 (arg1, "rename-password")) { g_paste_client_rename_password_sync (client, arg2, arg3, &error); } else if (!g_strcmp0 (arg1, "sp") || !g_strcmp0 (arg1, "set-password")) { g_paste_client_set_password_sync (client, _strtoull (arg2), arg3, &error); } else { show_help (); status = EXIT_FAILURE; } break; default: show_help (); status = EXIT_FAILURE; break; } } if (error) failure_exit (error); return status; }
int main (int argc, char *argv[]) { bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); int status = EXIT_SUCCESS; g_type_init (); GPasteClient *client = g_paste_client_new (); GError *error = NULL; const gchar *arg1, *arg2; if (!client) { if (argc == 2 && is_help (argv[1])) { show_help (argv[0]); return EXIT_SUCCESS; } failure_exit (); } if (!isatty (fileno (stdin))) { /* We are being piped */ GString *data = g_string_new (""); gchar c; while ((c = fgetc (stdin)) != EOF) data = g_string_append_c (data, c); data->str[data->len - 1] = '\0'; g_paste_client_add (client, data->str, &error); g_string_free (data, TRUE); } else { switch (argc) { case 1: show_history (client, FALSE, FALSE, &error); break; case 2: arg1 = argv[1]; if (is_help (arg1)) { show_help (argv[0]); } else if (g_strcmp0 (arg1, "start") == 0 || g_strcmp0 (arg1, "d") == 0 || g_strcmp0 (arg1, "daemon") == 0) { g_paste_client_track (client, TRUE, &error); } else if (g_strcmp0 (arg1, "stop") == 0 || g_strcmp0 (arg1, "q") == 0 || g_strcmp0 (arg1, "quit") == 0) { g_paste_client_track (client, FALSE, &error); } else if (g_strcmp0 (arg1, "e") == 0 || g_strcmp0 (arg1, "empty") == 0) { g_paste_client_empty (client, &error); } else if (g_strcmp0 (arg1, "v") == 0 || g_strcmp0 (arg1, "version") == 0 || g_strcmp0 (arg1, "-v") == 0 || g_strcmp0 (arg1, "--version") == 0) { printf ("%s\n", PACKAGE_STRING); } #ifdef ENABLE_APPLET else if (g_strcmp0 (arg1, "applet") == 0) { g_spawn_command_line_async (PKGLIBEXECDIR "/gpaste-applet", &error); if (error) { fprintf (stderr, _("Couldn't spawn gpaste-applet.\n")); g_clear_error (&error); status = EXIT_FAILURE; } } #endif else if (g_strcmp0 (arg1, "s") == 0 || g_strcmp0 (arg1, "settings") == 0 || g_strcmp0 (arg1, "p") == 0 || g_strcmp0 (arg1, "preferences") == 0) { execl (PKGLIBEXECDIR "/gpaste-settings", "GPaste-Settings", NULL); } else if (g_strcmp0 (arg1, "dr") == 0 || g_strcmp0 (arg1, "daemon-reexec") == 0) { g_paste_client_reexecute (client, &error); if (error && error->code == G_DBUS_ERROR_NO_REPLY) { printf (_("Successfully reexecuted the daemon\n")); } } else if (g_strcmp0 (arg1, "h") == 0 || g_strcmp0 (arg1, "history") == 0) { show_history (client, FALSE, FALSE, &error); } else if (g_strcmp0 (arg1, "rh") == 0 || g_strcmp0 (arg1, "raw-history") == 0) { show_history (client, TRUE, FALSE, &error); } else if (g_strcmp0 (arg1, "zh") == 0 || g_strcmp0 (arg1, "zero-history") == 0) { show_history (client, FALSE, TRUE, &error); } else if (g_strcmp0 (arg1, "lh") == 0 || g_strcmp0 (arg1, "list-histories") == 0) { gchar **histories = g_paste_client_list_histories (client, &error); if (!error) { for (gchar **h = histories; *h; ++h) printf ("%s\n", *h); g_strfreev (histories); } } else { show_help (argv[0]); status = EXIT_FAILURE; } break; case 3: arg1 = argv[1]; arg2 = argv[2]; if (g_strcmp0 (arg1, "bh") == 0|| g_strcmp0 (arg1, "backup-history") == 0) { g_paste_client_backup_history (client, arg2, &error); } else if (g_strcmp0 (arg1, "sh") == 0 || g_strcmp0 (arg1, "switch-history") == 0) { g_paste_client_switch_history (client, arg2, &error); } else if (g_strcmp0 (arg1, "dh") == 0 || g_strcmp0 (arg1, "delete-history") == 0) { g_paste_client_delete_history (client, arg2, &error); } else if (g_strcmp0 (arg1, "a") == 0 || g_strcmp0 (arg1, "add") == 0) { g_paste_client_add (client, arg2, &error); } else if (g_strcmp0 (arg1, "g") == 0|| g_strcmp0 (arg1, "get") == 0) { printf ("%s", g_paste_client_get_element (client, g_ascii_strtoull (arg2, NULL, 0), &error)); } else if (g_strcmp0 (arg1, "s") == 0 || g_strcmp0 (arg1, "set") == 0 || g_strcmp0 (arg1, "select") == 0) { g_paste_client_select (client, g_ascii_strtoull (arg2, NULL, 0), &error); } else if (g_strcmp0 (arg1, "d") == 0 || g_strcmp0 (arg1, "delete") == 0) { g_paste_client_delete (client, g_ascii_strtoull (arg2, NULL, 0), &error); } else if (g_strcmp0 (arg1, "f") == 0 || g_strcmp0 (arg1, "file") == 0) { gchar *content = NULL; if (g_file_get_contents (arg2, &content, NULL, /* length */ &error)) { g_paste_client_add (client, content, &error); g_free (content); } else { fprintf (stderr, _("Could not read file: %s\n"), arg2); g_clear_error (&error); status = EXIT_FAILURE; } } else { show_help (argv[0]); status = EXIT_FAILURE; } break; default: show_help (argv[0]); status = EXIT_FAILURE; break; } } if (error) { g_error_free (error); failure_exit (); } g_object_unref (client); return status; }
/** * \brief Main function for the snowfocus program */ int main(int argc, char *argv[]) { debug_set_ident("snowfocus"); snowstar::CommunicatorSingleton cs(argc, argv); Ice::CommunicatorPtr ic = cs.get(); bool remote = false; int steps = 10; double exposuretime = 1.0; double temperature = std::numeric_limits<double>::quiet_NaN(); std::string binning; std::string frame; std::string filtername; astro::focusing::Focusing::method_type method = astro::focusing::Focusing::BRENNER; int c; int longindex; while (EOF != (c = getopt_long(argc, argv, "b:c:de:f:hi:m:r:Rt:", longopts, &longindex))) switch (c) { case 'b': binning = optarg; break; case 'c': astro::config::Configuration::set_default(optarg); break; case 'd': debuglevel = LOG_DEBUG; break; case 'e': exposuretime = std::stod(optarg); break; case 'f': filtername = optarg; break; case 'h': usage(argv[0]); return EXIT_SUCCESS; case 'm': method = astro::focusing::Focusing::string2method(optarg); break; case 'r': frame = optarg; break; case 'R': remote = true; break; case 's': steps = std::stoi(optarg); break; case 't': temperature = std::stod(optarg); break; default: throw std::runtime_error("unknown option"); } // the next argument is the command if (argc <= optind) { short_usage(argv[0]); throw std::runtime_error("missing service argument"); } std::string argument(argv[optind++]); if ("help" == argument) { usage(argv[0]); return EXIT_SUCCESS; } astro::ServerName servername(argument); if (argc <= optind) { short_usage(argv[0]); throw std::runtime_error("missing instrument name argument"); } // make sure the server offers instruments and guiding if (!remote) { astro::discover::ServiceDiscoveryPtr sd = astro::discover::ServiceDiscovery::get(); sd->start(); astro::discover::ServiceObject so = sd->find(sd->waitfor(argument)); if (!so.has(astro::discover::ServiceSubset::INSTRUMENTS)) { std::cerr << "service '" << argument; std::cerr << "' does not offer focusing service"; std::cerr << std::endl; return EXIT_FAILURE; } if (!so.has(astro::discover::ServiceSubset::FOCUSING)) { std::cerr << "service '" << argument; std::cerr << "' does not offer focusing service"; std::cerr << std::endl; return EXIT_FAILURE; } } std::string instrumentname(argv[optind++]); if (argc <= optind) { short_usage(argv[0]); throw std::runtime_error("missing command argument"); } std::string command = argv[optind++]; debug(LOG_DEBUG, DEBUG_LOG, 0, "command: %s", command.c_str()); // get a proxy for the instruments Ice::ObjectPrx base = ic->stringToProxy( servername.connect("Instruments")); InstrumentsPrx instruments = InstrumentsPrx::checkedCast(base); // get the configuration astro::config::ConfigurationPtr config = astro::config::Configuration::get(); // check whether we have an instrument if (0 == instrumentname.size()) { throw std::runtime_error("instrument name not set"); } RemoteInstrument instrument(instruments, instrumentname); // make sure the server names for focuser and ccd are identical astro::ServerName targetserver = instrument.servername(InstrumentCCD); if (targetserver != instrument.servername(InstrumentFocuser)) { throw std::runtime_error("ccd and focuser are on different " "servers"); } // get the device names CcdPrx ccdprx = instrument.ccd(); std::string ccdname = ccdprx->getName(); FocuserPrx focuserprx = instrument.focuser(); std::string focusername = focuserprx->getName(); debug(LOG_DEBUG, DEBUG_LOG, 0, "ccd: %s focuser: %s", ccdname.c_str(), focusername.c_str()); // first get a connection to the server Ice::ObjectPrx fbase = ic->stringToProxy( targetserver.connect("FocusingFactory")); FocusingFactoryPrx focusingfactory = FocusingFactoryPrx::checkedCast(fbase); // get the focusing interface FocusingPrx focusing = focusingfactory->get(ccdname, focusername); debug(LOG_DEBUG, DEBUG_LOG, 0, "got a focusing proxy"); // creating a callback Ice::ObjectPtr callback = new FocusCallbackI(); CallbackAdapter adapter(ic); Ice::Identity ident = adapter.add(callback); focusing->ice_getConnection()->setAdapter(adapter.adapter()); debug(LOG_DEBUG, DEBUG_LOG, 0, "callback installed"); // handle the simple commands if (command == "help") { short_usage(argv[0]); return EXIT_SUCCESS; } if (command == "status") { std::cout << "status: "; FocusState state = focusing->status(); std::cout << focusingstate2string(state); switch (state) { case FocusFOCUSED: std::cout << " "; std::cout << focusing->getFocuser()->current(); break; default: break; } std::cout << std::endl; return EXIT_SUCCESS; } if (command == "history") { show_history(focusing->history()); return EXIT_SUCCESS; } if (command == "monitor") { std::cout << "current status: "; std::cout << focusingstate2string(focusing->status()); std::cout << std::endl; focusing->registerCallback(ident); signal(SIGINT, handler); while (!signal_received) { sleep(1); } focusing->unregisterCallback(ident); return EXIT_SUCCESS; } if (command == "cancel") { focusing->cancel(); std::cout << "cancel command sent" << std::endl; return EXIT_SUCCESS; } if (command == "repository") { if (optind < argc) { std::string reponame(argv[optind]); focusing->setRepositoryName(reponame); } else { std::string reponame = focusing->getRepositoryName(); if (reponame.size() > 0) { std::cout << "repository: " << reponame; std::cout << std::endl; } else { std::cout << "repository not set" << std::endl; } } return EXIT_SUCCESS; } // throw exception for unknown commands if (command != "start") { short_usage(argv[0]); throw std::runtime_error("unknown command"); } debug(LOG_DEBUG, DEBUG_LOG, 0, "executing start command"); // make sure temperature is set CoolerTask coolertask(instrument, temperature); coolertask.stop_on_exit(true); coolertask.wait(); // next two arguments are the interval boundaries if ((argc - optind) < 2) { short_usage(argv[0]); throw std::runtime_error("missing interval arguments"); } int min = std::stoi(argv[optind++]); int max = std::stoi(argv[optind++]); debug(LOG_DEBUG, DEBUG_LOG, 0, "interval [%d,%d]", min, max); if (min >= max) { short_usage(argv[0]); throw std::runtime_error("not an interval"); } debug(LOG_DEBUG, DEBUG_LOG, 0, "focusing in interval [%d,%d]", min, max); // ensure that focuser is ready FocusState state = focusing->status(); debug(LOG_DEBUG, DEBUG_LOG, 0, "current state = %d", state); if ((state == FocusMOVING) && (state == FocusMEASURING)) { short_usage(argv[0]); throw std::runtime_error("already focusing"); } debug(LOG_DEBUG, DEBUG_LOG, 0, "focuser available"); // set up the exposure astro::camera::Exposure exposure; exposure.purpose(astro::camera::Exposure::focus); exposure.exposuretime(exposuretime); if (binning.size() > 0) { exposure.mode(astro::image::Binning(binning)); } exposure.shutter(astro::camera::Shutter::OPEN); if (frame.size() > 0) { exposure.frame(astro::image::ImageRectangle(frame)); } // set up the focusing focusing->setSteps(steps); focusing->setMethod(convert(method)); focusing->setExposure(convert(exposure)); debug(LOG_DEBUG, DEBUG_LOG, 0, "focusing set up %d steps, method %s", steps, astro::focusing::Focusing::method2string(method).c_str()); // start the focusing process debug(LOG_DEBUG, DEBUG_LOG, 0, "starting between %d and %d", min, max); focusing->start(min, max); debug(LOG_DEBUG, DEBUG_LOG, 0, "focusing started, status: %d", focusing->status()); // wait for the process to complete bool completed = false; signal(SIGINT, handler); do { sleep(1); switch (focusing->status()) { case FocusIDLE: case FocusMOVING: case FocusMEASURING: break; case FocusFOCUSED: case FocusFAILED: completed = true; break; } } while ((!completed) && (!signal_received)); if (completed) { std::cout << "final focus position: " << focuserprx->current(); std::cout << std::endl; // display the history show_history(focusing->history()); } else { std::cout << "focusing incomplete" << std::endl; return EXIT_FAILURE; } return EXIT_SUCCESS; }