static int import_callback(const char *path, void *data) { /* initialize watchfile data */ watchfile_list_data = data; vector_init(&watchfile_entries, sizeof(struct watchfile_entry)); /* parse lines */ const char *err_str = NULL; FILE *f = fopen(path, "r"); char *line = malloc(1024); if (f) { while (1) { if (fgets(line, 1024, f)) { if (strchr(line, '\n') || feof(f)) { if (!parse_line(line, &err_str)) break; } else { err_str = "line overflow"; break; } } else { if (!feof(f)) err_str = strerror(ferror(f)); break; } } } else err_str = strerror(errno); if (f) fclose(f); if (line) free(line); /* show error message or view file */ struct menu *menu_top = menu_get_top(watchfile_list_data->imenu); if (err_str) { watchfile_destroy(); menu_prompt(menu_top, err_str, "return\0", 0, NULL, NULL); } else { menu_return(menu_top); watchfile_view(menu_top); } return 1; }
static int entry_activate_proc(struct menu_item *item) { int row = (int)item->data; struct watchfile_entry *entry = vector_at(&watchfile_entries, watchfile_scroll + row); entry->anim_state = 1; uint32_t address; enum adex_error e = adex_eval(&entry->adex, &address); if (!e && (address < 0x80000000 || address >= 0x80800000 || address % watch_type_size[entry->type] != 0)) { e = ADEX_ERROR_ADDRESS; } if (e) { struct menu *menu_top = menu_get_top(watchfile_list_data->imenu); menu_prompt(menu_top, adex_error_name[e], "return\0", 0, NULL, NULL); } else { add_member(watchfile_list_data, address, entry->type, watchfile_list_data->members.size, 1, 0, 0, 0); } return 1; }
void process_commands(std::string preface) { for (;;) try { std::string command = menu_prompt(preface); if (command == "e") { std::string e = ics::prompt_string(preface+" Enter element to add"); std::cout << preface+" enqueue = " << q.enqueue(e) << std::endl; } else if (command == "E") { PriorityQueueType q2(prompt_queue(preface)); std::cout << " dequeue = " << q.enqueue_all(q2) << std::endl;; } else if (command == "d") std::cout << preface+" dequeue = " << q.dequeue() << std::endl; else if (command == "x") q.clear(); else if (command == "=") { PriorityQueueType q2(prompt_queue(preface)); q = q2; std::cout << " s now = " << q << std::endl; } else if (command == "m") std::cout << preface+" empty = " << q.empty(); else if (command == "s") std::cout << preface+" size = " << q.size() << std::endl; else if (command == "p") { std::cout << preface+" peek = " << q.peek() << std::endl; } else if (command == "<") std::cout << preface+" << = " << q << std::endl; else if (command == "r") { std::cout << preface+" q == q = " << (q == q) << std::endl; std::cout << preface+" q != q = " << (q != q) << std::endl; PriorityQueueType q2(prompt_queue(preface)); std::cout << preface+" q = " << q << " ?? q2 = " << q2 << std::endl; std::cout << preface+" q == q2 = " << (q == q2) << std::endl; std::cout << preface+" q != q2 = " << (q != q2) << std::endl; } else if (command == "lf") { std::ifstream in_queue; ics::safe_open(in_queue,preface+" Enter file name to read", "loadpq.txt"); std::string e; while (getline(in_queue,e)) q.enqueue(e); in_queue.close(); } else if (command == "l{") { q = PriorityQueueType({"c","b","d","e","a"}); } else if (command == "it") process_iterator_commands(q, "it: "+preface); else if (command == "q") break; else std::cout << preface+"\""+command+"\" is unknown command" << std::endl; } catch (ics::IcsError& e) { std::cout << preface+" " << e.what() << std::endl; } };
void process_commands(std::string preface) { for (;;) try { std::string command = menu_prompt(preface); if (command == "v") { std::string e = ics::prompt_string(preface+" Enter element to add"); std::cout << preface+" push = " << s.push(e) << std::endl; } else if (command == "V") { StackType s2(prompt_stack(preface)); std::cout << " push_all = " << s.push_all(s2) << std::endl;; } else if (command == "^") std::cout << preface+" pop = " << s.pop() << std::endl; else if (command == "x") s.clear(); else if (command == "=") { StackType s2(prompt_stack(preface)); s = s2; std::cout << " s now = " << s << std::endl; } else if (command == "m") std::cout << preface+" empty = " << s.empty(); else if (command == "s") std::cout << preface+" size = " << s.size() << std::endl; else if (command == "p") { std::cout << preface+" peek = " << s.peek() << std::endl; } else if (command == "<") std::cout << preface+" << = " << s << std::endl; else if (command == "r") { std::cout << preface+" s == s = " << (s == s) << std::endl; std::cout << preface+" s != s = " << (s != s) << std::endl; StackType s2(prompt_stack(preface)); std::cout << preface+" s = " << s << " ?? s2 = " << s2 << std::endl; std::cout << preface+" s == s2 = " << (s == s2) << std::endl; std::cout << preface+" s != s2 = " << (s != s2) << std::endl; } else if (command == "lf") { std::ifstream in_stack; ics::safe_open(in_stack,preface+" Enter file name to read", "loadstack.txt"); std::string e; while (getline(in_stack,e)) s.push(e); in_stack.close(); } else if (command == "l{") s = StackType{"c","b","d","e","a"}; else if (command == "it") process_iterator_commands(s, "it: "+preface); else if (command == "q") break; else std::cout << preface+"\""+command+"\" is unknown command" << std::endl; } catch (ics::IcsError& e) { std::cout << preface+" " << e.what() << std::endl; } };
int gen_setup() { extern char *v_yes[]; WINDOW *g_win, *newwin(); int i, num, ret_code; char c, *ans, *str_prompt(), *menu_prompt(), chr_prompt(); char *str_rep(); void line_set(); static char *v_abort[3] = {"KEEP", "DELETE", NULL}; g_win = newwin(23, 80, 0, 0); horizontal(g_win, 0, 0, 32); mvwattrstr(g_win, 0, 33, A_BOLD, "General Setup"); horizontal(g_win, 0, 47, 32); mvwprintw(g_win, 3, 22, "1) Default log file ....... %s", param->logfile); mvwprintw(g_win, 4, 22, "2) Screen dump file ....... %s", param->dumpfile); mvwprintw(g_win, 6, 22, "3) Strip high bit ........ %s", param->strip); mvwprintw(g_win, 8, 22, "4) Pause character ........ %c", param->pause_char); mvwprintw(g_win, 9, 22, "5) CR character ........... %c", param->cr_char); mvwprintw(g_win, 10, 22, "6) CTRL character ......... %c", param->ctrl_char); mvwprintw(g_win, 11, 22, "7) ESC character .......... %c", param->esc_char); mvwprintw(g_win, 12, 22, "8) Break character ........ %c", param->brk_char); mvwprintw(g_win, 14, 22, "9) Aborted downloads ...... %s", param->abort); mvwprintw(g_win, 16, 21, "10) Connect delay (sec) .... %d", param->c_delay); mvwprintw(g_win, 17, 21, "11) Redial delay (sec) ..... %d", param->r_delay); horizontal(g_win, 19, 0, 80); mvwattrstr(g_win, 20, 0, A_BOLD, "OPTION ==> "); mvwaddstr(g_win, 20, 58, "Press <ESC> to return"); wmove(g_win, 20, 12); touchwin(g_win); wrefresh(g_win); /* get the option number */ ret_code = 0; while ((i = get_num(g_win, 2)) != -1) { switch (i) { case 1: if ((ans = str_prompt(g_win, 3, 50, "Default log file", "")) != NULL) { param->logfile = str_rep(param->logfile, ans); ret_code++; } break; case 2: if ((ans = str_prompt(g_win, 4, 50, "Default screen dump file", "")) != NULL) { param->dumpfile = str_rep(param->dumpfile, ans); ret_code++; } break; case 3: if ((ans = menu_prompt(g_win, 6, 50, "Strip high bit?", v_yes)) != NULL) { param->strip = str_rep(param->strip, ans); line_set(); ret_code++; } break; case 4: if ((c = chr_prompt(g_win, 8, 50, "Pause character", "1 second")) != '\0') { param->pause_char = c; ret_code++; } break; case 5: if ((c = chr_prompt(g_win, 9, 50, "CR character", "(carriage return)")) != '\0') { param->cr_char = c; ret_code++; } break; case 6: if ((c = chr_prompt(g_win, 10, 50, "CTRL character", "(control)")) != '\0') { param->ctrl_char = c; ret_code++; } break; case 7: if ((c = chr_prompt(g_win, 11, 50, "ESC character", "(escape)")) != '\0') { param->esc_char = c; ret_code++; } break; case 8: if ((c = chr_prompt(g_win, 12, 50, "Break character", "")) != '\0') { param->brk_char = c; ret_code++; } case 9: if ((ans = menu_prompt(g_win, 14, 50, "Aborted downloads", v_abort)) != NULL) { param->abort = str_rep(param->abort, ans); ret_code++; } break; case 10: if ((num = num_prompt(g_win, 16, 50, "Connect delay time", "(in seconds)")) != -1) { if (num > MAX_CDELAY || num < MIN_CDELAY) { beep(); /* some reasonable range of values */ if (num < MIN_CDELAY) num = MIN_CDELAY; else num = MAX_CDELAY; mvwaddstr(g_win, 16, 50, " "); wrefresh(g_win); mvwattrnum(g_win, 16, 50, A_BOLD, num); wrefresh(g_win); } param->c_delay = num; ret_code++; } break; case 11: if ((num = num_prompt(g_win, 17, 50, "Redial delay time", "(in seconds)")) != -1) { if (num > MAX_PAUSE || num < MIN_PAUSE) { beep(); /* some reasonable range */ if (num < MIN_PAUSE) num = MIN_PAUSE; else num = MAX_PAUSE; mvwaddstr(g_win, 17, 50, " "); wrefresh(g_win); mvwattrnum(g_win, 17, 50, A_BOLD, num); wrefresh(g_win); } param->r_delay = num; ret_code++; } break; default: beep(); } mvwaddstr(g_win, 20, 12, " "); clear_line(g_win, 21, 0, FALSE); clear_line(g_win, 22, 0, FALSE); wmove(g_win, 20, 12); wrefresh(g_win); } delwin(g_win); return(ret_code); }
int modem_setup() { WINDOW *mo_win, *newwin(); int i, j, ret_code, mod_prompt(); char *ans, *str_rep(), *str_prompt(), *menu_prompt(); void disp_modem(); extern char *v_yn[]; /* the current modem */ j = 0; if (modem->m_cur != -1) j = modem->m_cur; mo_win = newwin(23, 80, 0, 0); horizontal(mo_win, 0, 0, 33); mvwattrstr(mo_win, 0, 34, A_BOLD, "Modem Setup"); horizontal(mo_win, 0, 46, 34); /* display the current settings */ disp_modem(mo_win, j); horizontal(mo_win, 19, 0, 80); mvwattrstr(mo_win, 20, 0, A_BOLD, "OPTION ==> "); mvwaddstr(mo_win, 20, 58, "Press <ESC> to return"); wmove(mo_win, 20, 12); touchwin(mo_win); wrefresh(mo_win); /* get the option number */ ret_code = 0; while ((i = get_num(mo_win, 2)) != -1) { switch (i) { case 1: j = mod_prompt(mo_win); break; case 2: if ((ans = str_prompt(mo_win, 3, 39, "Modem init string", "sent to the modem once")) != NULL) { modem->init[j] = str_rep(modem->init[j], ans); ret_code++; } break; case 3: if ((ans = str_prompt(mo_win, 4, 39, "Dialing command", "")) != NULL) { modem->dial[j] = str_rep(modem->dial[j], ans); ret_code++; } break; case 4: if ((ans = str_prompt(mo_win, 5, 39, "Dialing cmd suffix", "typically the <CR> character")) != NULL) { modem->suffix[j] = str_rep(modem->suffix[j], ans); ret_code++; } break; case 5: if ((ans = str_prompt(mo_win, 6, 39, "Hang up string", "")) != NULL) { modem->hang_up[j] = str_rep(modem->hang_up[j], ans); ret_code++; } break; case 6: if ((ans = menu_prompt(mo_win, 7, 39, "Auto Baud detect", v_yn)) != NULL) { modem->auto_baud[j] = *ans; ret_code++; } break; case 7: if ((ans = str_prompt(mo_win, 8, 39, "300 baud connect string", "")) != NULL) { modem->con_3[j] = str_rep(modem->con_3[j], ans); ret_code++; } break; case 8: if ((ans = str_prompt(mo_win, 9, 39, "1200 baud connect string", "")) != NULL) { modem->con_12[j] = str_rep(modem->con_12[j], ans); ret_code++; } break; case 9: if ((ans = str_prompt(mo_win, 10, 39, "2400 baud connect string", "")) != NULL) { modem->con_24[j] = str_rep(modem->con_24[j], ans); ret_code++; } break; case 10: if ((ans = str_prompt(mo_win, 11, 39, "4800 baud connect string", "")) != NULL) { modem->con_48[j] = str_rep(modem->con_48[j], ans); ret_code++; } break; case 11: if ((ans = str_prompt(mo_win, 12, 39, "9600 baud connect string", "")) != NULL) { modem->con_96[j] = str_rep(modem->con_96[j], ans); ret_code++; } break; case 12: if ((ans = str_prompt(mo_win, 13, 39, "19200 baud connect string", "")) != NULL) { modem->con_192[j] = str_rep(modem->con_192[j], ans); ret_code++; } break; case 13: if ((ans = str_prompt(mo_win, 14, 39, "No connect string 1", "")) != NULL) { modem->no_con1[j] = str_rep(modem->no_con1[j], ans); ret_code++; } break; case 14: if ((ans = str_prompt(mo_win, 15, 39, "No connect string 2", "")) != NULL) { modem->no_con2[j] = str_rep(modem->no_con2[j], ans); ret_code++; } break; case 15: if ((ans = str_prompt(mo_win, 16, 39, "No connect string 3", "")) != NULL) { modem->no_con3[j] = str_rep(modem->no_con3[j], ans); ret_code++; } break; case 16: if ((ans = str_prompt(mo_win, 17, 39, "No connect string 4", "")) != NULL) { modem->no_con4[j] = str_rep(modem->no_con4[j], ans); ret_code++; } break; default: beep(); } /* clear the previous prompts */ mvwaddstr(mo_win, 20, 12, " "); clear_line(mo_win, 21, 0, FALSE); clear_line(mo_win, 22, 0, FALSE); wmove(mo_win, 20, 12); wrefresh(mo_win); } delwin(mo_win); return(ret_code); }
void process_commands(std::string preface) { for (;;) try { std::string command = menu_prompt(preface); if (command == "an") { std::string n = ics::prompt_string(" Enter node name"); g.add_node(n); } else if (command == "ae") { std::string o = ics::prompt_string(" Enter origin node name"); std::string d = ics::prompt_string(" Enter destination node name"); int v = ics::prompt_int (" Enter value for this edge "); g.add_edge(o,d,v); } else if (command == "rn") { std::string n = ics::prompt_string(" Enter node name"); g.remove_node(n); } else if (command == "re") { std::string o = ics::prompt_string(" Enter origin node name"); std::string d = ics::prompt_string(" Enter destination node name"); g.remove_edge(o,d); } else if (command == "x") g.clear(); else if (command == "=") { ics::HashGraph<int> g2(ics::prompt_graph()); g = g2; } else if (command == "m") std::cout << " empty() = " << g.empty() << std::endl; else if (command == "#n") std::cout << " node_count() = " << g.node_count() << std::endl; else if (command == "#e") std::cout << " edge_count() = " << g.edge_count() << std::endl; else if (command == "n") { std::string n = ics::prompt_string(" Enter node name"); std::cout << " has_node(...) = " << g.has_node(n) << std::endl; } else if (command == "e") { std::string o = ics::prompt_string(" Enter origin node name"); std::string d = ics::prompt_string(" Enter destination node name"); std::cout << " has_edge(...) = " << g.has_edge(o,d) << std::endl; } else if (command == "v") { std::string o = ics::prompt_string(" Enter origin node name"); std::string d = ics::prompt_string(" Enter destination node name"); std::cout << " edge_value(...) = " << g.edge_value(o,d) << std::endl; } else if (command == "i") { std::string n = ics::prompt_string(" Enter node name"); std::cout << " in_degree(...) = " << g.in_degree(n) << std::endl; } else if (command == "o") { std::string n = ics::prompt_string(" Enter node name"); std::cout << " out_degree(...) = " << g.out_degree(n) << std::endl; } else if (command == "d") { std::string n = ics::prompt_string(" Enter node name"); std::cout << " degree(...) = " << g.degree(n) << std::endl; } else if (command == "<") std::cout << preface+" << = " << g << std::endl; else if (command == "r") { std::cout << " g == g = " << (g == g) << std::endl; std::cout << " g != g = " << (g != g) << std::endl; ics::HashGraph<int> g2(ics::prompt_graph()); std::cout << " g == g2 = " << (g == g2) << std::endl; std::cout << " g != g2 = " << (g != g2) << std::endl; } else if (command == "l") { std::string separator = prompt_string(" Enter separator used in file"); std::ifstream in_file; ics::safe_open(in_file," Enter file name to read graph from","graph.txt"); g.load(in_file,separator); } else if (command == "s") { std::string separator = prompt_string(" Enter separator to use in file"); std::ofstream out_file; out_file.open(ics::prompt_string(" Enter file name to store graph in").c_str()); if (out_file.fail()) std::cout << " Illegal file name" << std :: endl; else g.store(out_file,separator); } else if (command == "q") break; else std::cout << preface+"\""+command+"\" is unknown command" << std::endl; } catch (ics::IcsError& e) { std::cout << preface+" " << e.what() << std::endl; } }
void process_commands(std::string preface) { for (;;) try { std::string command = menu_prompt(preface); if (command == "i") { std::string e = ics::prompt_string(preface+" Enter element to add"); std::cout << preface+" insert = " << s.insert(e) << std::endl; } else if (command == "I") { SetType s2(prompt_set(preface)); std::cout << " insert = " << s.insert(s2.abegin(),s2.aend()) << std::endl;; } else if (command == "e") { std::string e = ics::prompt_string(preface+" Enter element to erase"); std::cout << preface+" erase = " << s.erase(e) << std::endl; } else if (command == "E") { SetType s2(prompt_set(preface)); std::cout << " erase = " << s.erase(s2.abegin(),s2.aend()) << std::endl;; } else if (command == "x") s.clear(); else if (command == "R") { SetType s2(prompt_set(preface)); std::cout << " retain = " << s.retain(s2.abegin(),s2.aend()) << std::endl; } else if (command == "=") { SetType s2(prompt_set(preface)); s = s2; std::cout << " s now = " << s << std::endl; } else if (command == "m") std::cout << preface+" empty = " << s.empty(); else if (command == "s") std::cout << preface+" size = " << s.size() << std::endl; else if (command == "c") { std::string e = ics::prompt_string(preface+" Enter element to erase"); std::cout << preface+" contains = " << s.contains(e) << std::endl; } else if (command == "C") { SetType s2(prompt_set(preface)); std::cout << " contains = " << s.contains(s2.abegin(),s2.aend()) << std::endl; } else if (command == "<") std::cout << preface+" << = " << s.str() << std::endl; else if (command == "r") { std::cout << preface+" s == s = " << (s == s) << std::endl; std::cout << preface+" s != s = " << (s != s) << std::endl; std::cout << preface+" s <= s = " << (s <= s) << std::endl; std::cout << preface+" s < s = " << (s < s) << std::endl; std::cout << preface+" s > s = " << (s > s) << std::endl; std::cout << preface+" s >= s = " << (s >= s) << std::endl; SetType s2(prompt_set(preface)); std::cout << preface+" s = " << s << " ?? s2 = " << s2 << std::endl; std::cout << preface+" s == s2 = " << (s == s2) << std::endl; std::cout << preface+" s != s2 = " << (s != s2) << std::endl; std::cout << preface+" s <= s2 = " << (s <= s2) << std::endl; std::cout << preface+" s < s2 = " << (s < s2) << std::endl; std::cout << preface+" s > s2 = " << (s > s2) << std::endl; std::cout << preface+" s >= s2 = " << (s >= s2) << std::endl; } else if (command == "l") { std::ifstream in_set; ics::safe_open(in_set,preface+" Enter file name to read", "load.txt"); std::string e; while (getline(in_set,e)) s.insert(e); in_set.close(); } else if (command == "it") process_iterator_commands(s, "it: "+preface); else if (command == "q") break; else std::cout << preface+"\""+command+"\" is unknown command" << std::endl; } catch (ics::IcsError& e) { std::cout << preface+" " << e.what() << std::endl; } };