bool parse_mask( const char **string, unsigned int fa_entry_count, struct filter_mask *mask) { memset(mask->mask, 0, sizeof(mask->mask)); if (read_char(string, 'R')) return parse_raw_mask(string, fa_entry_count, mask); else { bool ok = true; do { unsigned int id; ok = parse_id(string, fa_entry_count, &id); if (ok) { unsigned int end_id = id; if (read_char(string, '-')) ok = parse_id(string, fa_entry_count, &end_id) && TEST_OK_(id <= end_id, "Range %d-%d is empty", id, end_id); for (unsigned int i = id; ok && i <= end_id; i ++) set_mask_bit(mask, i); } } while (ok && read_char(string, ',')); return ok; } }
int main(int argc, char *argv[]) { idtype_t idtype; id_t id; int ch, flags; bool descend, inherit, idset; idtype = P_PID; id = getpid(); flags = PPROT_SET; descend = inherit = idset = false; while ((ch = getopt(argc, argv, "cdig:p:")) != -1) switch (ch) { case 'c': flags = PPROT_CLEAR; break; case 'd': descend = true; break; case 'i': inherit = true; break; case 'g': idtype = P_PGID; id = parse_id(optarg); idset = true; break; case 'p': idtype = P_PID; id = parse_id(optarg); idset = true; break; } argc -= optind; argv += optind; if ((idset && argc != 0) || (!idset && (argc == 0 || descend))) usage(); if (descend) flags |= PPROT_DESCEND; if (inherit) flags |= PPROT_INHERIT; if (procctl(idtype, id, PROC_SPROTECT, &flags) == -1) err(1, "procctl"); if (argc != 0) { errno = 0; execvp(*argv, argv); err(errno == ENOENT ? 127 : 126, "%s", *argv); } return (0); }
/* * Evaluate a string as Duktape code in the selected heap. * Usage: eval token code * Return value: the result of the evaluation coerced to string. * Side effects: may change the Duktape interpreter heap. */ static int Eval_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { duk_context *ctx; duk_int_t duk_result; const char *js_code; if (objc != 3) { Tcl_WrongNumArgs(interp, 1, objv, USAGE_EVAL); return TCL_ERROR; } ctx = parse_id(cdata, interp, objv[1], 0); if (ctx == NULL) { return TCL_ERROR; } js_code = Tcl_GetString(objv[2]); duk_result = duk_peval_string(ctx, js_code); Tcl_SetObjResult(interp, Tcl_NewStringObj( duk_safe_to_string(ctx, -1), -1)); duk_pop(ctx); if (duk_result == 0) { return TCL_OK; } else { return TCL_ERROR; } }
Status EpdParser::parse(const string& epd, EpdPosition* const position) const { int fen_end_position; const Status& status = FenParser::parse(epd, &(position->board), &fen_end_position); if (!status.ok()) { return status; } unsigned int it = fen_end_position; while (it < epd.size()) { while (it < epd.size() && epd[it] == c_space) { ++it; } if (it >= epd.size()) { break; } // TODO semicolons in strings const unsigned long end = epd.find(c_semicolon, it); const unsigned long command_length = (end == string::npos ? epd.size(): end) - it; assert(command_length > 0); // If we don't find a semicolon, the command goes to the end. const string& command = epd.substr(it, command_length); if (epd.find(c_id, it) == it) { parse_id(command.substr(c_id.size() + 1), position); } else if (epd.find(c_bm, it) == it) { parse_bm(command.substr(c_bm.size() + 1), position); } else if (epd.find(c_am, it) == it) { parse_am(command.substr(c_am.size() + 1), position); } it += command_length + 1; } return Status::valid(); }
static int do_command(char *str) { int action, id; char action_str[10+1] = {0}, id_str[64+1] = {0}; if (0 == strncasecmp(str, "HELP", strlen(str))) { print_help(stdout); return 0; } if (2 != sscanf(str, " %10s %64s", action_str, id_str)) return -1; if (0 == strncasecmp(action_str, "TARGET", strlen(action_str))) return parse_target(id_str); action = parse_action(action_str); id = parse_id(id_str); if (action == BAD_ACTION || id == BAD_ID) return -1; if (id == AMBIGUOUS_ID) { fprintf(stdout, "id %s is too ambiguous\n", id_str); return 0; } fprintf(stdout, "sending: %s %s\n", action_string[action], idtab[id].name); idtab[id].func(action, id, str); return 0; }
void console_history(char *out_buffer, int buffer_len, char *args) { char *tok; net_id_t id; int j; tok = strtok(args, " \n"); if (tok == NULL) { return; } parse_id(id, tok); int routing_entry = lnp_routing_entry_lock(id); if (routing_entry == NULL_SLOT) { console_printf(out_buffer, buffer_len, "no routing entry.\n"); return; } history_entry_t *entry = &routing_table[routing_entry].history; if (entry->begin == entry->end) { console_printf(out_buffer, buffer_len, "[*EMPTY*]\n"); } else { console_printf(out_buffer, buffer_len, "sessions: "); for (j=entry->begin; j!=entry->end; j=(j+1)%HISTORY_SIZE) { console_printf(out_buffer, buffer_len, "[%2d]", entry->history[j]); } console_printf(out_buffer, buffer_len, "[*END*]\n"); } lnp_routing_entry_unlock(routing_entry); }
void console_print_keys(char *out_buffer, int buffer_len, char *args) { char *tok; net_id_t id; int store_index; tok = strtok(args, " \n"); if (tok == NULL) { return; } parse_id(id, tok); int routing_entry = lnp_routing_entry_lock(id); if (routing_entry == NULL_SLOT) { console_printf(out_buffer, buffer_len, "no routing entry.\n"); return; } store_index = routing_table[routing_entry].store_index; if (store_index == NULL_SLOT) { console_printf(out_buffer, buffer_len, "no keys.\n"); return; } lnp_key_entry_t *entry = &lnp_key_store[store_index]; if (entry->handshake_state == LNP_HANDSHAKE_CONNECTED) { console_printf(out_buffer, buffer_len, " cipher_in_key:"); console_dump(out_buffer, buffer_len, entry->cipher_in_key, entry->cipher->key_length); console_printf(out_buffer, buffer_len, " cipher_out_key:"); console_dump(out_buffer, buffer_len, entry->cipher_out_key, entry->cipher->key_length); console_printf(out_buffer, buffer_len, " cipher_in_iv:"); console_dump(out_buffer, buffer_len, entry->cipher_in_iv, entry->cipher->iv_length); console_printf(out_buffer, buffer_len, " cipher_out_iv:"); console_dump(out_buffer, buffer_len, entry->cipher_out_iv, entry->cipher->iv_length); console_printf(out_buffer, buffer_len, " mac_in_key:"); console_dump(out_buffer, buffer_len, entry->mac_in_key, entry->mac->key_length); console_printf(out_buffer, buffer_len, " mac_out_key:"); console_dump(out_buffer, buffer_len, entry->mac_out_key, entry->mac->key_length); } else { console_printf(out_buffer, buffer_len, "session not established yet\n"); } lnp_routing_entry_unlock(routing_entry); }
int main( int argc, char *argv[] ) { DFBResult ret; int i; IDirectFB *dfb; DFBInputDeviceID device_id = 0; /* Initialize DirectFB. */ ret = DirectFBInit( &argc, &argv ); if (ret) { D_DERROR( ret, "DFBTest/Input: DirectFBInit() failed!\n" ); return ret; } /* Parse arguments. */ for (i=1; i<argc; i++) { const char *arg = argv[i]; if (strcmp( arg, "-h" ) == 0 || strcmp (arg, "--help") == 0) return print_usage( argv[0] ); else if (strcmp (arg, "-v") == 0 || strcmp (arg, "--version") == 0) { fprintf (stderr, "dfbtest_input version %s\n", DIRECTFB_VERSION); return false; } else if (strcmp (arg, "-d") == 0 || strcmp (arg, "--device") == 0) { if (++i == argc) { print_usage (argv[0]); return false; } if (!parse_id( argv[i], &device_id )) return false; } else return print_usage( argv[0] ); } /* Create super interface. */ ret = DirectFBCreate( &dfb ); if (ret) { D_DERROR( ret, "DFBTest/Input: DirectFBCreate() failed!\n" ); return ret; } Test_Sensitivity( dfb, device_id ); /* Shutdown DirectFB. */ ret = dfb->Release( dfb ); if (ret) { D_DERROR( ret, "DFBTest/Input: IDirectFB::Release() failed!\n" ); return ret; } return 0; }
int pp_ifndef(char *p) { parse_id(p, m_id_buf); if (get_symbol_index(m_id_buf) < 0) { return XPP_OUTP; } else { return XPP_SKIP; } }
static int parse_entry(const char **ep, struct authlist_entry *entry) { if (istag(ep, tag_everybody)) entry->kind = AUTHLIST_KIND_EVERYBODY; else if (istag(ep, tag_nobody)) entry->kind = AUTHLIST_KIND_NOBODY; else if (istag_col(ep, tag_uid)) return parse_id(ep, entry, AUTHLIST_KIND_UID); else if (istag_col(ep, tag_nouid)) return parse_id(ep, entry, AUTHLIST_KIND_NOUID); else if (istag_col(ep, tag_gid)) return parse_id(ep, entry, AUTHLIST_KIND_GID); else if (istag_col(ep, tag_nogid)) return parse_id(ep, entry, AUTHLIST_KIND_NOGID); else return -EINVAL; return 0; }
void pp_undef(char *p) { int si; p = parse_id(p, m_id_buf); si = get_symbol_index(m_id_buf); if (si >= 0) { strcpy(m_symbol[si].id, XPP_UNDEFINED); m_symbol[si].val[0] = 0; // empty str } }
static int parse_def(struct peg_grammar_parser *pgp, struct peg_cursor *pc, int *idp) { struct peg_grammar *peg = pgp->peg; struct peg_cursor npc = *pc; int id = -1; int expr = -1; int def = -1; struct peg_node *pn; int rv; rv = parse_id(pgp, &npc, &id); if ( rv <= 0 ) return rv; if ( NODE(peg, id)->pi_def >= 0 ) { pgp->err = PEG_ERR_DUP_DEF; pgp->eloc = *pc; return -1; } if ( !string_match(pgp, "<-", &npc) ) { peg_node_free(peg, id); return 0; } if ( (rv = parse_expr(pgp, &npc, &expr)) <= 0 ) { if ( rv == 0 ) pgp->err = PEG_ERR_BAD_DEF; pgp->eloc = npc; peg_node_free(peg, id); return -1; } def = peg_node_new(peg, PEG_DEFINITION, pc->line); if ( def < 0 ) { peg_node_free(peg, id); peg_node_free(peg, expr); pgp->err = PEG_ERR_NOMEM; return -1; } pn = NODE(peg, def); pn->pd_id = id; pn->pd_expr = expr; pn = NODE(peg, id); pn->pi_def = def; *pc = npc; if ( idp != NULL ) *idp = id; return 1; }
void pp_include(char *p) { parse_id(p, m_path_buf); if (append_to_output(m_path_buf)) { if (m_option.verbose) { printf("%s (included)\n", m_path_buf); } } else if (m_option.verbose) { printf("%s (include failed)\n", m_path_buf); } }
struct single *parse_io() { token t; int current = current_token, error = 0; struct single *s; s = malloc(sizeof (struct single)); t = get_token(); if (t.type == T_VISIBLE) { if ((t = get_token()).type == T_STRING) { s->type = I_VISIBLE_STRING; s->data.string = t.data; } else { unget_token(); s->type = I_VISIBLE; s->data.e = parse_expr(); if (s->data.e == NULL) { error = 1; parse_error("I can only visible strings and epressions"); } } } else if (t.type == T_GIMMEH) { s->type = I_GIMMEH; s->data.id = parse_id(); if (s->data.id == NULL) { error = 1; } } else error = 1; if (error == 1) { free(s); current_token = current; return NULL; } return s; }
struct vardecl *parse_decl() { int current = current_token; token t1, t2; struct vardecl *d; t1 = get_token(); t2 = get_token(); if (t1.type != T_I || t2.type != T_HAS) { current_token = current; return NULL; } d = malloc(sizeof(struct vardecl)); if (d == NULL) { perror("No memory"); return NULL; } d->id = parse_id(); if (d->id == NULL) { free(d); parse_error("expected id"); return NULL; } if (get_token().type != T_ITZ) { unget_token(); d->number = NULL; return d; } d->number = parse_number(); if (d->number == NULL) { free(d); parse_error("expected number"); return NULL; } return d; }
static void handler_cfg_data_frequency_lcm(const lcm_recv_buf_t *rbuf, const char *channel, const cfg_data_frequency_t *msg, void *user) { uint8_t id = parse_id(channel); verbose_printf("Received msg on lcm channel %s with id %d\n", channel, id); uint32_t maxlen = __cfg_data_frequency_t_encoded_array_size(msg, 1); uint8_t *buf = (uint8_t *) malloc(sizeof(uint8_t) * maxlen); uint32_t len = __cfg_data_frequency_t_encode_array(buf, 0, maxlen, msg, 1); if(usb) comms_publish_id( usb_comms, id, CHANNEL_CFG_DATA_FREQUENCY, buf, 0, len); if(xbee) comms_publish_id(xbee_comms, id, CHANNEL_CFG_DATA_FREQUENCY, buf, 0, len); if(loopback_mode) handler_cfg_data_frequency(NULL, id, CHANNEL_CFG_DATA_FREQUENCY, buf, len); free(buf); }
static void parse_id_range(const char *portstring, uint16_t *id) { char *buffer; char *cp; buffer = strdup(portstring); if ((cp = strchr(buffer, ':')) == NULL) id[0] = id[1] = parse_id(buffer); else { *cp = '\0'; cp++; id[0] = buffer[0] ? parse_id(buffer) : 0; if (ebt_errormsg[0] != '\0') return; id[1] = cp[0] ? parse_id(cp) : 0xFFFF; if (ebt_errormsg[0] != '\0') return; if (id[0] > id[1]) ebt_print_error("Invalid VlanID range (min > max)"); } free(buffer); }
void console_connect(char *out_buffer, int buffer_len, char *args) { char *tok; net_id_t id; tok = strtok(args, " \n"); if (tok == NULL) { return; } parse_id(id, tok); if (lnp_connect(id) == NET_OK) { console_printf(out_buffer, buffer_len, "Connected.\n"); } else { console_printf(out_buffer, buffer_len, "Error connecting.\n"); } }
struct single *parse_assign() { struct single *s; if (get_token().type != T_LOL) { unget_token() ; return NULL; } s = malloc(sizeof(struct single)); if (s == NULL) { perror("No memory"); return NULL; } s->type = I_ASSIGN; s->data.assign.id = parse_id(); if (s->data.assign.id == NULL) { parse_error("expected id"); free(s); return NULL; } if (get_token().type != T_IZ) { parse_error("expected `IZ`"); free(s); return NULL; } s->data.assign.e = parse_expr(); if (s->data.assign.e == NULL) { parse_error("expected expression"); free(s); return NULL; } return s; }
/* * Destroy a Duktape interpreter heap. * Return value: nothing. * Side effects: destroys a Duktape interpreter heap. */ static int Close_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { duk_context *ctx; if (objc != 2) { Tcl_WrongNumArgs(interp, 1, objv, USAGE_CLOSE); return TCL_ERROR; } ctx = parse_id(cdata, interp, objv[1], 1); if (ctx == NULL) { return TCL_ERROR; } duk_destroy_heap(ctx); return TCL_OK; }
static int parse_id_and_not_arrow(struct peg_grammar_parser *pgp, struct peg_cursor *pc, int *idp) { int rv; struct peg_cursor npc1 = *pc; struct peg_cursor npc2; int id; rv = parse_id(pgp, &npc1, &id); if ( rv <= 0 ) return rv; npc2 = npc1; if ( string_match(pgp, "<-", &npc2) ) { peg_node_free(pgp->peg, id); return 0; } *pc = npc1; *idp = id; return 1; }
void console_write(char *out_buffer, int buffer_len, char *args) { char *tok; u_char *msg; net_id_t id; tok = strtok(args, " \n"); if (tok == NULL) { return; } parse_id(id, tok); tok = strtok(NULL, " \n"); if (tok == NULL) { return; } msg = (u_char*)tok; lnp_write(id, msg, strlen(tok)+1, LNP_PROTOCOL_UNRELIABLE); console_printf(out_buffer, buffer_len, "Message sent.\n"); }
void pp_define(char *p, bool ww) { int i, si; p = parse_id(p, m_id_buf); si = get_symbol_index(m_id_buf); if (si < 0) { si = m_symbol_len; // not defined so add it strcpy(m_symbol[si].id, m_id_buf); m_symbol[si].val[0] = 0; // default val is empty str ++m_symbol_len; } // else if defined change its value if (!is_line_end(*p)) { skip_white_space(&p); i = 0; while (!is_line_end(*p)) { // get pp value, to end of line m_symbol[si].val[i++] = *p++; } m_symbol[si].val[i] = 0; // terminate string } m_symbol[si].ww = ww; // to use whole-word search or not }
/****** router *********************************************************************/ static inline void print_router(ccir_router_t *r) { uint32_t i = 0, lo = 0, hi = 0; debug(RDB_TOPO, " router 0x%x count %u instance 0x%"PRIx64, r->id, r->count, r->instance); if (r->count) debug(RDB_TOPO, " %u subnets:", r->count); for (i = 0; i < r->count; i++) debug(RDB_TOPO, " subnet 0x%x", r->subnets[i]); if (r->pair_count) { debug(RDB_TOPO, " %u pairs:", r->pair_count); for (i = 0; i < r->pair_count; i++) { parse_id(r->pairs[i], &lo, &hi); debug(RDB_TOPO, " pair 0x%x_%x", lo, hi); } } return; }
static int read_repo_config_option(char *name, size_t namelen, char *value, size_t valuelen, void *data) { if (!strcmp(name, "i18n.commitencoding")) set_encoding(&default_encoding, value, FALSE); else if (!strcmp(name, "gui.encoding")) set_encoding(&default_encoding, value, TRUE); else if (!strcmp(name, "core.editor")) string_ncopy(opt_editor, value, valuelen); else if (!strcmp(name, "core.worktree")) set_work_tree(value); else if (!strcmp(name, "core.abbrev")) parse_id(&opt_id_width, value); else if (!prefixcmp(name, "tig.color.")) set_repo_config_option(name + 10, value, option_color_command); else if (!prefixcmp(name, "tig.bind.")) set_repo_config_option(name + 9, value, option_bind_command); else if (!prefixcmp(name, "tig.")) set_repo_config_option(name + 4, value, option_set_command); else if (!prefixcmp(name, "color.")) set_git_color_option(name + STRING_SIZE("color."), value); else if (*repo.head && !prefixcmp(name, "branch.") && !strncmp(name + 7, repo.head, strlen(repo.head))) set_remote_branch(name + 7 + strlen(repo.head), value, valuelen); return OK; }
// Format: // DEL <id> int op_del(char **cursor, uint16_t *line_remaining) { int ret = SUCCESS; uint8_t id = 0; size_t i = 0; // Get ID to DEL. if (SUCCESS != (ret = parse_id(cursor, line_remaining, &id))) { #ifdef DEBUG fprintf(stderr, "[E] op_del | non-SUCCESS from op_del()\n"); #endif goto bail; } for (i=0; i<NUM_OBJS; i++) { if (NULL != ns.obj[i] && id == ns.obj[i]->id) { #ifdef DEBUG fprintf(stderr, "[D] object_del | deleting %03d\n", id); #endif if (SUCCESS != (ret = deallocate(ns.obj[i], SZ_PAGE))) { #ifdef DEBUG fprintf(stderr, "[E] op_del | failed to deallocate backing memory for ID %03d\n", id); #endif } ns.obj[i] = NULL; goto bail; } } #ifdef DEBUG fprintf(stderr, "[D] op_del | attempted to DEL non-existant object %03d\n", id); #endif bail: return ret; }
int main (int argc, char* argv[]) { uint64_t id; string name; string id_preparse; int fd; //Timer variables timer_t tid; sigevent sevp; itimerspec its; //Setup the SigEvent to trigger SIGUSR1 signal sevp.sigev_notify = SIGEV_SIGNAL; sevp.sigev_signo = SIGUSR1; //Set the Timer to trigger ~every minute its.it_interval.tv_sec = 60; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = 60; its.it_value.tv_nsec = 0; //setup signal handler signal(SIGINT, sig_handler); signal(SIGHUP, sig_handler); signal(SIGUSR1, timer_handler); //Create and set the save timer timer_create(CLOCK_REALTIME, &sevp, &tid); timer_settime(tid, 0, &its, NULL); if(argc < 2) { cout << "must input filename of database!" << endl; exit(1); } fd = open(argv[1], O_RDONLY); if(fd < 0) { string tmp; cout << "file \'" << argv[1] << "\' does not exist, do you want to create it? > "; getline(cin, tmp); if(tmp[0] != 'y') exit(1); } else { close(fd); } db = Student_db(argv[1], "password"); db.Load_records(); while(1) { cout << "Please swipe card" << endl; //get id number from the card reader id = parse_id(reader.Read_raw().c_str()); if (id != 0) { //check if id already is known if(!db.Lookup_name(id, name)) //if not, prompt for a name and add to database { cout << "Card not recognized, you must be new!" << endl; string tmp; while(1) { cout << "Please enter your name (first last) > "; getline(cin, name); //Loop over the name and send specific characters to upper for (auto i = name.begin(); i < name.end(); ++i) { if (i == name.begin()) *i = toupper(*i); if (*(i-1) == ' ') *i = toupper(*i); if (*(i-1) == '-') *i = toupper(*i); } if (cin.eof()) //Someone typed CTRL-D ! { cin.clear(); //Clear the Error bits cin.ignore(); //Clear out the input buffer continue; //Restart the loop } cout << "You entered \"" << name << "\", is this correct (y/n)? > "; getline(cin, tmp); if (cin.eof()) //Someone typed CTRL-D ! { cin.clear(); //Clear the Error bits cin.ignore(); //Clear out the input buffer continue; //Restart the loop } if(tmp[0] == 'y') break; } db.Add(id, name); } cout << "Welcome " << name << "! You have been logged in." << endl << endl; db.Login(id); //login the user } else { cout << "Error. Please try again." << endl; } } return 0; }
/* Wants: name = value */ static enum status_code option_set_command(int argc, const char *argv[]) { if (argc < 3) return ERROR_WRONG_NUMBER_OF_ARGUMENTS; if (strcmp(argv[1], "=")) return ERROR_NO_VALUE_ASSIGNED; if (!strcmp(argv[0], "blame-options")) return parse_args(&opt_blame_options, argv + 2); if (!strcmp(argv[0], "diff-options")) return parse_args(&opt_diff_options, argv + 2); if (argc != 3) return ERROR_WRONG_NUMBER_OF_ARGUMENTS; if (!strcmp(argv[0], "show-author")) return parse_enum(&opt_show_author, argv[2], author_map); if (!strcmp(argv[0], "show-date")) return parse_enum(&opt_show_date, argv[2], date_map); if (!strcmp(argv[0], "show-rev-graph")) return parse_bool(&opt_show_rev_graph, argv[2]); if (!strcmp(argv[0], "show-refs")) return parse_bool(&opt_show_refs, argv[2]); if (!strcmp(argv[0], "show-changes")) return parse_bool(&opt_show_changes, argv[2]); if (!strcmp(argv[0], "show-notes")) { bool matched = FALSE; enum status_code res = parse_bool_matched(&opt_show_notes, argv[2], &matched); if (res == SUCCESS && matched) { update_notes_arg(); return res; } opt_show_notes = TRUE; strcpy(opt_notes_arg, "--show-notes="); res = parse_string(opt_notes_arg + 8, argv[2], sizeof(opt_notes_arg) - 8); if (res == SUCCESS && opt_notes_arg[8] == '\0') opt_notes_arg[7] = '\0'; return res; } if (!strcmp(argv[0], "show-line-numbers")) return parse_bool(&opt_show_line_numbers, argv[2]); if (!strcmp(argv[0], "line-graphics")) return parse_enum(&opt_line_graphics, argv[2], graphic_map); if (!strcmp(argv[0], "line-number-interval")) return parse_int(&opt_line_number_interval, argv[2], 1, 1024); if (!strcmp(argv[0], "author-width")) return parse_int(&opt_author_width, argv[2], 0, 1024); if (!strcmp(argv[0], "filename-width")) return parse_int(&opt_show_filename_width, argv[2], 0, 1024); if (!strcmp(argv[0], "show-filename")) return parse_enum(&opt_show_filename, argv[2], filename_map); if (!strcmp(argv[0], "show-file-size")) return parse_enum(&opt_show_file_size, argv[2], file_size_map); if (!strcmp(argv[0], "horizontal-scroll")) return parse_step(&opt_horizontal_scroll, argv[2]); if (!strcmp(argv[0], "split-view-height")) return parse_step(&opt_split_view_height, argv[2]); if (!strcmp(argv[0], "vertical-split")) return parse_enum(&opt_vertical_split, argv[2], vertical_split_map); if (!strcmp(argv[0], "tab-size")) return parse_int(&opt_tab_size, argv[2], 1, 1024); if (!strcmp(argv[0], "diff-context") && !*opt_diff_context_arg) { enum status_code code = parse_int(&opt_diff_context, argv[2], 0, 999999); if (code == SUCCESS) update_diff_context_arg(opt_diff_context); return code; } if (!strcmp(argv[0], "ignore-space") && !*opt_ignore_space_arg) { enum status_code code = parse_enum(&opt_ignore_space, argv[2], ignore_space_map); if (code == SUCCESS) update_ignore_space_arg(); return code; } if (!strcmp(argv[0], "commit-order") && !*opt_commit_order_arg) { enum status_code code = parse_enum(&opt_commit_order, argv[2], commit_order_map); if (code == SUCCESS) update_commit_order_arg(); return code; } if (!strcmp(argv[0], "status-untracked-dirs")) return parse_bool(&opt_status_untracked_dirs, argv[2]); if (!strcmp(argv[0], "read-git-colors")) return parse_bool(&opt_read_git_colors, argv[2]); if (!strcmp(argv[0], "ignore-case")) return parse_bool(&opt_ignore_case, argv[2]); if (!strcmp(argv[0], "focus-child")) return parse_bool(&opt_focus_child, argv[2]); if (!strcmp(argv[0], "wrap-lines")) return parse_bool(&opt_wrap_lines, argv[2]); if (!strcmp(argv[0], "show-id")) return parse_bool(&opt_show_id, argv[2]); if (!strcmp(argv[0], "id-width")) return parse_id(&opt_id_width, argv[2]); if (!strcmp(argv[0], "title-overflow")) { bool enabled = FALSE; bool matched; enum status_code code; /* * "title-overflow" is considered a boolint. * We try to parse it as a boolean (and set the value to 50 if true), * otherwise we parse it as an integer and use the given value. */ code = parse_bool_matched(&enabled, argv[2], &matched); if (code == SUCCESS && matched) { if (enabled) opt_title_overflow = 50; } else { code = parse_int(&opt_title_overflow, argv[2], 2, 1024); if (code != SUCCESS) opt_title_overflow = 50; } return code; } if (!strcmp(argv[0], "editor-line-number")) return parse_bool(&opt_editor_line_number, argv[2]); if (!strcmp(argv[0], "mouse")) return parse_bool(&opt_mouse, argv[2]); if (!strcmp(argv[0], "mouse-scroll")) return parse_int(&opt_mouse_scroll, argv[2], 0, 1024); return ERROR_UNKNOWN_VARIABLE_NAME; }
void read_tstset(const path_set_type& files, hypergraph_set_type& graphs) { const int mpi_rank = MPI::COMM_WORLD.Get_rank(); const int mpi_size = MPI::COMM_WORLD.Get_size(); std::string line; path_set_type::const_iterator titer_end = tstset_files.end(); for (path_set_type::const_iterator titer = tstset_files.begin(); titer != titer_end; ++ titer) { if (debug) std::cerr << "file: " << *titer << std::endl; if (boost::filesystem::is_directory(*titer)) { size_t id; hypergraph_type hypergraph; for (size_t i = mpi_rank; /**/; i += mpi_size) { const path_type path = (*titer) / (utils::lexical_cast<std::string>(i) + ".gz"); if (! boost::filesystem::exists(path)) break; utils::compress_istream is(path, 1024 * 1024); if (! utils::getline(is, line)) throw std::runtime_error("no line in file-no: " + utils::lexical_cast<std::string>(i)); std::string::const_iterator iter = line.begin(); std::string::const_iterator end = line.end(); if (! parse_id(id, iter, end)) throw std::runtime_error("invalid id input: " + path.string()); if (id != i) throw std::runtime_error("id mismatch: " + path.string()); if (static_cast<int>(id % mpi_size) != mpi_rank) throw std::runtime_error("difference it?"); if (! hypergraph.assign(iter, end)) throw std::runtime_error("invalid graph format" + path.string()); if (iter != end) throw std::runtime_error("invalid id ||| graph format" + path.string()); if (graphs[id].is_valid()) graphs[id].unite(hypergraph); else graphs[id].swap(hypergraph); } } else { const path_type& path = *titer; utils::compress_istream is(path, 1024 * 1024); size_t id; hypergraph_type hypergraph; while (utils::getline(is, line)) { std::string::const_iterator iter = line.begin(); std::string::const_iterator end = line.end(); if (! parse_id(id, iter, end)) throw std::runtime_error("invalid id input: " + path.string()); if (id >= graphs.size()) throw std::runtime_error("tstset size exceeds refset size?" + utils::lexical_cast<std::string>(id) + ": " + titer->string()); if (static_cast<int>(id % mpi_size) != mpi_rank) continue; if (! hypergraph.assign(iter, end)) throw std::runtime_error("invalid graph format" + path.string()); if (iter != end) throw std::runtime_error("invalid id ||| graph format" + path.string()); if (graphs[id].is_valid()) graphs[id].unite(hypergraph); else graphs[id].swap(hypergraph); } } } }
static pxd_client_t * do_open ( pxd_open_t * open, char * user_id, char * device_id, int is_incoming ) { pxd_client_t * client; pxd_client_t * rejected; pxd_error_t error; char * bytes; int tries; open->credentials->id->user_id = parse_id(user_id ); open->credentials->id->device_id = parse_id(device_id); open->callback = is_incoming ? &pxd_server_callbacks : &pxd_client_callbacks; open->is_incoming = is_incoming; make_pxd_blob(open); client = pxd_open(open, &error); if (error.error != 0) { error("pxd_open failed: %s\n", error.message); exit(1); } bytes = (char *) open->credentials->opaque; if (is_incoming) { bytes[open->credentials->opaque_length - 1]++; } else { bytes[0]++; } test_pxd_rejection = true; rejections = 0; rejected = pxd_open(open, &error); if (error.error != 0) { error("pxd_open failed for the reject test: %s\n", error.message); exit(1); } tries = 0; while (rejections == 0 && tries++ < 10) { sleep(1); } if (rejections == 0) { error("I did not receive a reject-credentials callback.\n"); exit(1); } pxd_close(&rejected, true, &error); test_pxd_rejection = false; return client; }