static void del_command(client_t *c, int ntoken, char **tokens) { char command[1024]; int i; if (c->registered) { print(c, "You need to unregister first to modify commands."); return; } if (concat_tokens(command, sizeof(command), ntoken, tokens) == NULL) { print(c, "Command too long."); return; } for (i = 0; i < c->ncommand; i++) { if (!strcmp(c->commands[i], command)) { if (i < c->ncommand - 1) memmove(c->commands + i + 1, c->commands + i, (c->ncommand - 1 - i) * sizeof(*c->commands)); c->ncommand--; mrp_realloc(c->commands, sizeof(*c->commands) * c->ncommand); print(c, "Command '%s' deleted.", command); } } }
static void add_command(client_t *c, int ntoken, char **tokens) { char command[1024]; size_t osize, nsize; if (c->registered) { print(c, "You need to unregister first to modify commands."); return; } if (concat_tokens(command, sizeof(command), ntoken, tokens) == NULL) { print(c, "Command too long."); return; } osize = sizeof(*c->commands) * c->ncommand; nsize = sizeof(*c->commands) * (c->ncommand + 1); if (!mrp_reallocz(c->commands, osize, nsize)) { print(c, "Failed to add new command."); return; } c->commands[c->ncommand] = mrp_strdup(command); if (c->commands[c->ncommand] != NULL) { c->ncommand++; print(c, "Command '%s' added to command set.", command); } else print(c, "Failed to register new command."); }
void read_final_ops_file(char *name, FILE *f, struct ops_list *ops, int num_ops, int sp_mode, struct n_pair *contigs, int num_contigs) { char buf[1000]; bool is_in = false; char temp_name[LEN_NAME]; int count = 0; int i = 0; int len = 0; int *len_sum; if( num_contigs > 0 ) { len_sum = (int *) ckalloc(sizeof(int) * num_contigs); // cal_length_sum(len_sum, contigs, num_contigs); for( i = 0; i < num_contigs; i++ ) { len_sum[i] = contigs[i].len; } } fseek(f, 0, SEEK_SET); while((is_in == false) && (fgets(buf, 500, f))) { if( buf[0] == '#' ) { i = 2; len = strlen(buf); while( (i < len) && (buf[i] != '\0') && (buf[i] != '\n') ) { i = concat_tokens(buf, i, temp_name); if( strcmp(temp_name, name) == 0 ) { is_in = true; } } } else { if( is_in == false ) { count = add_one_ops(ops, count, buf, contigs, num_contigs, len_sum, sp_mode); } if( count > num_ops ) { fatalf("counting events mismatches: %d in %s\n", num_ops, name); } } } if( num_contigs > 0 ) free(len_sum); }
int count_final_ops(char *name, FILE *f, int sp_mode) { char buf[1000]; bool is_in = false; char temp_name[LEN_NAME]; int count = 0; int res = 0; int mode = -1; int i = 0; int len = 0; fseek(f, 0, SEEK_SET); while((is_in == false) && (fgets(buf, 500, f))) { if( buf[0] == '#' ) { i = 2; len = strlen(buf); while( (i < len) && (buf[i] != '\0') && (buf[i] != '\n') ) { i = concat_tokens(buf, i, temp_name); if( strcmp(temp_name, name) == 0 ) { is_in = true; } } } else { if( is_in == false ) { sscanf(buf, "%*s %*s %*s %*s %*s %*s %*s %d %*s", &mode); if( mode == sp_mode ) { count++; } } } } res = count; return(res); }
static void do_extension_pdf(int immediate) { int i; if(scan_keyword("literal")){ new_whatsit(pdf_literal_node); if(scan_keyword("direct")) set_pdf_literal_mode(tail,direct_always); else if(scan_keyword("page")) set_pdf_literal_mode(tail,direct_page); else set_pdf_literal_mode(tail,set_origin); scan_toks(false,true); set_pdf_literal_type(tail,normal); set_pdf_literal_data(tail,def_ref); }else if(scan_keyword("dest")){ scan_pdfdest(static_pdf); }else if(scan_keyword("annot")){ scan_annot(static_pdf); }else if(scan_keyword("save")){ new_whatsit(pdf_save_node); }else if(scan_keyword("restore")){ new_whatsit(pdf_restore_node); }else if(scan_keyword("setmatrix")){ new_whatsit(pdf_setmatrix_node); scan_toks(false,true); set_pdf_setmatrix_data(tail,def_ref); }else if(scan_keyword("obj")){ scan_obj(static_pdf); if(immediate){ if(obj_data_ptr(static_pdf,pdf_last_obj)==0) normal_error("pdf backend","\\pdfextension obj 'reserveobjnum' cannot be used with \\immediate"); pdf_write_obj(static_pdf,pdf_last_obj); } }else if(scan_keyword("refobj")){ scan_refobj(static_pdf); }else if(scan_keyword("colorstack")){ scan_int(); if(cur_val>=colorstackused()){ print_err("Unknown color stack number "); print_int(cur_val); help3 ("Allocate and initialize a color stack with \\pdfextension colorstackinit.", "I'll use default color stack 0 here.", "Proceed, with fingers crossed."); error(); cur_val= 0; } if(cur_val<0){ print_err("Invalid negative color stack number"); help2("I'll use default color stack 0 here.", "Proceed, with fingers crossed."); error(); cur_val= 0; } if(scan_keyword("set")) i= colorstack_set; else if(scan_keyword("push")) i= colorstack_push; else if(scan_keyword("pop")) i= colorstack_pop; else if(scan_keyword("current")) i= colorstack_current; else i= -1; if(i>=0){ new_whatsit(pdf_colorstack_node); set_pdf_colorstack_stack(tail,cur_val); set_pdf_colorstack_cmd(tail,i); set_pdf_colorstack_data(tail,null); if(i<=colorstack_data){ scan_toks(false,true); set_pdf_colorstack_data(tail,def_ref); } }else{ print_err("Color stack action is missing"); help3("The expected actions for \\pdfextension colorstack:", " set, push, pop, current", "I'll ignore the color stack command."); error(); } }else if(scan_keyword("startlink")){ scan_startlink(static_pdf); }else if(scan_keyword("endlink")){ if(abs(mode)==vmode) normal_error("pdf backend","\\pdfextension endlink cannot be used in vertical mode"); new_whatsit(pdf_end_link_node); }else if(scan_keyword("startthread")){ new_annot_whatsit(pdf_start_thread_node); scan_thread_id(); }else if(scan_keyword("endthread")){ new_whatsit(pdf_end_thread_node); }else if(scan_keyword("thread")){ new_annot_whatsit(pdf_thread_node); scan_thread_id(); }else if(scan_keyword("outline")){ scan_pdfoutline(static_pdf); }else if(scan_keyword("glyphtounicode")){ glyph_to_unicode(); }else if(scan_keyword("catalog")){ scan_pdfcatalog(static_pdf); }else if(scan_keyword("fontattr")){ scan_font_ident(); i= cur_val; if(i==null_font) normal_error("pdf backend","invalid font identifier"); scan_toks(false,true); set_pdf_font_attr(i,tokens_to_string(def_ref)); if(str_length(pdf_font_attr(i))==0){ flush_str((str_ptr-1)); set_pdf_font_attr(i,0); } }else if(scan_keyword("mapfile")){ scan_toks(false,true); pdfmapfile(def_ref); delete_token_ref(def_ref); }else if(scan_keyword("mapline")){ scan_toks(false,true); pdfmapline(def_ref); delete_token_ref(def_ref); }else if(scan_keyword("includechars")){ pdf_include_chars(static_pdf); }else if(scan_keyword("info")){ scan_toks(false,true); pdf_info_toks= concat_tokens(pdf_info_toks,def_ref); }else if(scan_keyword("names")){ scan_toks(false,true); pdf_names_toks= concat_tokens(pdf_names_toks,def_ref); }else if(scan_keyword("trailer")){ scan_toks(false,true); pdf_trailer_toks= concat_tokens(pdf_trailer_toks,def_ref); }else{ tex_error("unexpected use of \\pdfextension",null); } }
/* * Creates new table * * ipfw table NAME create [ type { addr | iface | number | flow } ] * [ algo algoname ] */ static void table_create(ipfw_obj_header *oh, int ac, char *av[]) { ipfw_xtable_info xi; int error, tcmd, val; uint32_t fset, fclear; char *e, *p; char tbuf[128]; memset(&xi, 0, sizeof(xi)); while (ac > 0) { tcmd = get_token(tablenewcmds, *av, "option"); ac--; av++; switch (tcmd) { case TOK_LIMIT: NEED1("limit value required"); xi.limit = strtol(*av, NULL, 10); ac--; av++; break; case TOK_TYPE: NEED1("table type required"); /* Type may have suboptions after ':' */ if ((p = strchr(*av, ':')) != NULL) *p++ = '\0'; val = match_token(tabletypes, *av); if (val == -1) { concat_tokens(tbuf, sizeof(tbuf), tabletypes, ", "); errx(EX_USAGE, "Unknown tabletype: %s. Supported: %s", *av, tbuf); } xi.type = val; if (p != NULL) { error = table_parse_type(val, p, &xi.tflags); if (error != 0) errx(EX_USAGE, "Unsupported suboptions: %s", p); } ac--; av++; break; case TOK_VALTYPE: NEED1("table value type required"); fset = fclear = 0; val = fill_flags(tablevaltypes, *av, &e, &fset, &fclear); if (val != -1) { xi.vmask = fset; ac--; av++; break; } concat_tokens(tbuf, sizeof(tbuf), tablevaltypes, ", "); errx(EX_USAGE, "Unknown value type: %s. Supported: %s", e, tbuf); break; case TOK_ALGO: NEED1("table algorithm name required"); if (strlen(*av) > sizeof(xi.algoname)) errx(EX_USAGE, "algorithm name too long"); strlcpy(xi.algoname, *av, sizeof(xi.algoname)); ac--; av++; break; case TOK_LOCK: xi.flags |= IPFW_TGFLAGS_LOCKED; break; } } /* Set some defaults to preserve compatibility. */ if (xi.algoname[0] == '\0' && xi.type == 0) xi.type = IPFW_TABLE_ADDR; if (xi.vmask == 0) xi.vmask = IPFW_VTYPE_LEGACY; if ((error = table_do_create(oh, &xi)) != 0) err(EX_OSERR, "Table creation failed"); }