func_t *func_set_script(func_t *f) { strings *a=NULL,*b=NULL,*vlist=NULL; func_t *g=NULL; if(func_is_strings(f) && func_strings_size(f)==1){ if(str_match(func_strings_at(f,0),"=",BLK0,BLK1)){ a=strings_split(func_strings_at(f,0),"=",BLK0,BLK1,SPC); if(strings_size(a)==2 && str_match(strings_at(a,0),"^%A%I*$",BLK0,BLK1)){ g=func_set(func_def(strings_at(a,0),func_script(strings_at(a,1)),0,FUNC_NOLIMIT)); }else if(strings_size(a)==2 && str_match(strings_at(a,0),"^%A%I*(%m*)$",BLK0,BLK1)){ b=strings_split_mask(strings_at(a,0),BLK0,BLK1,SPC); if(strings_size(b)==1){ g=func_set(func_def(strings_at(b,0),func_script(strings_at(a,1)),0,0)); }else if(strings_size(b)>1){ vlist=strings_split(strings_at(b,1),",",BLK0,BLK1,SPC); func_scope_begin(func_strings_strings(vlist)); g=func_set(func_def(strings_at(b,0),func_eval(func_script(strings_at(a,1))),strings_size(vlist),strings_size(vlist))); func_scope_end(); } } } } if(g==NULL){ g=f; }else{ f=func_del(f); } a=strings_del(a); b=strings_del(b); vlist=strings_del(vlist); return g; }
static void test_match() { if (str_match("hello", "world", '\0')) fail(); if (!str_match("hello", "hello", '\0')) fail(); if (!str_match("localhost:12345", "localhost:54321", ':')) fail(); }
/* * should_patch_object * Decides whether a particular loaded object should should be targeted for * hotpatching. * Always skipped: [vdso], and the syscall_intercept library itself. * Besides these two, if patch_all_objs is true, everything object is * a target. When patch_all_objs is false, only libraries that are parts of * the glibc implementation are targeted, i.e.: libc and libpthread. */ static bool should_patch_object(uintptr_t addr, const char *path) { static uintptr_t self_addr; if (self_addr == 0) { extern unsigned char intercept_asm_wrapper_tmpl[]; Dl_info self; if (!dladdr((void *)&intercept_asm_wrapper_tmpl, &self)) xabort("self dladdr failure"); self_addr = (uintptr_t)self.dli_fbase; } static const char libc[] = "libc"; static const char pthr[] = "libpthread"; static const char caps[] = "libcapstone"; if (is_vdso(addr, path)) { debug_dump(" - skipping: is_vdso\n"); return false; } const char *name = get_lib_short_name(path); size_t len = strcspn(name, "-."); if (len == 0) return false; if (addr == self_addr) { debug_dump(" - skipping: matches self\n"); return false; } if (str_match(name, len, caps)) { debug_dump(" - skipping: matches capstone\n"); return false; } if (str_match(name, len, libc)) { debug_dump(" - libc found\n"); libc_found = true; return true; } if (patch_all_objs) return true; if (str_match(name, len, pthr)) { debug_dump(" - libpthread found\n"); return true; } debug_dump(" - skipping, patch_all_objs == false\n"); return false; }
struct lcmd_tab * lcmd_lookup(const char *name) { struct lcmd_tab *p; for (p = lcmd_tab; p->lc_name != 0; p++) if (str_match(name, p->lc_name, p->lc_minlen)) return p; return 0; }
void WpaGui::processMsg(char *msg) { char *pos = msg, *pos2; int priority = 2; if (*pos == '<') { /* skip priority */ pos++; priority = atoi(pos); pos = strchr(pos, '>'); if (pos) pos++; else pos = msg; } WpaMsg wm(pos, priority); if (eh) eh->addEvent(wm); msgs.append(wm); while (msgs.count() > 100) msgs.pop_front(); /* Update last message with truncated version of the event */ if (strncmp(pos, "CTRL-", 5) == 0) { pos2 = strchr(pos, str_match(pos, WPA_CTRL_REQ) ? ':' : ' '); if (pos2) pos2++; else pos2 = pos; } else pos2 = pos; QString lastmsg = pos2; lastmsg.truncate(40); textLastMessage->setText(lastmsg); pingsToStatusUpdate = 0; networkMayHaveChanged = true; if (str_match(pos, WPA_CTRL_REQ)) processCtrlReq(pos + strlen(WPA_CTRL_REQ)); }
func_t *func_null_script(func_t *f) { func_t *g=NULL; if(func_is_strings(f) && func_strings_size(f)==1 && str_match(func_strings_at(f,0),"^NULL$",BLK0,BLK1)) { g=NULL; f=func_del(f); } else { g=f; } return g; }
SEXP simplify_names(const SEXP x) { if (TYPEOF(x)!=STRSXP) error("simplify: argument type error"); int len = length(x); int lenf=0, lenb=0; if (len>1) { char front[MAX_FLD], back[MAX_FLD]; strncpy(front, CHAR(STRING_ELT(x, 0)), MAX_FLD-1); strncpy(back, front, MAX_FLD-1); lenf = lenb = strlen(front); char *end_back = back + lenb; /* pointer to terminating 0 */ char *start_back = back; for (int i=1; i<len; i++) { const char *xi = CHAR(STRING_ELT(x, i)); if (lenf) { lenf = str_match(front, xi, 1); front[lenf] = (char) 0; } if (lenb) { lenb = str_match(start_back, xi, 0); start_back = end_back - lenb ; } } } SEXP Result; PROTECT(Result = allocVector(STRSXP, len)); char id[MAX_FLD]; for (int i=0; i<len; i++) { const char *xi = CHAR(STRING_ELT(x, i)); int lenx = strlen(xi); int ncp = lenx - lenf - lenb; if (ncp>=MAX_FLD) error("simplify: id length overflow"); strncpy(id, xi+lenf, ncp); *(id+ncp) = (char) 0; SET_STRING_ELT(Result, i, mkChar(id)); } UNPROTECT(1); return Result; }
bot_t *dumbgames_help(dlist_t * dlist_node, bot_t * bot) { debug(bot, "dumbgames_help: Entered\n"); if (!bot) return NULL; if (str_match(bot->trig_called, STR_MATCH_STRCASECMP, 0, "^dice", NULL)) { bot->dl_module_help = "^dice ::: rolls two random dice"; } else if (str_match (bot->trig_called, STR_MATCH_STRCASECMP, 0, "^roulette", NULL)) { bot->dl_module_help = "^roulette(numtriggerpulls) ::: pulls the \"trigger\" numtriggerpulls times and hopefully doesn't return a BANG!"; } else { bot->dl_module_help = "^dumbgames ::: ^dice || ^roulette(numtriggerpulls)"; } return NULL; }
static void wpa_cli_action_process(const char *msg) { const char *pos; pos = msg; if (*pos == '<') { /* skip priority */ pos = strchr(pos, '>'); if (pos) pos++; else pos = msg; } if (str_match(pos, WPA_EVENT_CONNECTED)) { wpa_cli_exec(action_file, ctrl_ifname, "CONNECTED"); } else if (str_match(pos, WPA_EVENT_DISCONNECTED)) { wpa_cli_exec(action_file, ctrl_ifname, "DISCONNECTED"); } else if (str_match(pos, WPA_EVENT_TERMINATING)) { printf("wpa_supplicant is terminating - stop monitoring\n"); wpa_cli_quit = 1; } }
func_t *func_def_script(func_t *f) { int i; strings *a=NULL,*b=NULL; func_t *g=NULL; if(func_is_strings(f) && func_strings_size(f)==1){ if(str_match(func_strings_at(f,0),"^%A%I*$",BLK0,BLK1)){ // f g=func_scope_find(0,func_strings_at(f,0)); if(func_is_def(g) && func_def_name(g)!=NULL){ g=func_new(func_def_name(g)); if(func_find_amin(g)>0){ g=func_del(g); } }else{ g=NULL; } }else if(str_match(func_strings_at(f,0),"^%A%I*(%m+)$",BLK0,BLK1)){ // f(.....) a=strings_split_mask(func_strings_at(f,0),BLK0,BLK1,SPC); if(strings_size(a)==2){ g=func_scope_find(0,strings_at(a,0)); b=strings_split(strings_at(a,1),",",BLK0,BLK1,SPC); if(func_is_def(g) && func_def_name(g)!=NULL){ g=func_new(func_def_name(g)); if(func_find_amin(g)<=strings_size(b) && (strings_size(b)<=func_find_amax(g) || func_find_amax(g)==FUNC_NOLIMIT)){ func_a_resize(g,strings_size(b)); for(i=0; i<strings_size(b); i++){ func_aset(g,i,func_script(strings_at(b,i))); } }else{ g=func_del(g); } }else{ g=NULL; } } } } if(g==NULL){ g=f; }else{ f=func_del(f); } a=strings_del(a); b=strings_del(b); return g; }
/** * @brief Returns, if found, the node whose comment tag matches the beginning of @p str. * * @param str String that may be the start of a comment. * @return The matching HLNode* if found, NULL otherwise. */ const HLNode *HLIndex::seek_comment(const char *str) const { HLNode **n = m_comments; int len; while (n < m_last_comment) { const char *c = (*n)->tag(); if ((len=str_match(str, c, false))) return const_cast<const HLNode*>(*n); else ++n; } return nullptr; }
/* Called when data is received from a client. If the server checks * for quit commands, the user's 'data_in_cb' will be called after * checking for a quit command. * * Parameters: * client: The handle to the client. The client's data will contain * the callback package for the client. * nread: The number of bytes read from the client. If this is a negative * number, it signifies an error occurred. If this happens, the * client will be closed and the 'data_in_cb' will not be called. * buf: The 'uv_buf_t' struct that holds the input buffer. */ static void client_data_in_cb(uv_stream_t* client, ssize_t nread, const uv_buf_t* buf) { uscb_package* package = (uscb_package*)client->data; UvTcpServer* server = (UvTcpServer*)package->server; /* Error occurred, we need to close the client. */ if(nread < 0) { ArrayList_remove_tsafe(server->client_list, client); goto f_return; } /* Check if a quit command was received. */ if(server->handle_quit_command && str_match(buf->base, nread, (server->quit_command)?server->quit_command:DEFAULT_QUIT_COMMAND, 0) == 0) { if(server->qc_cb) { uscb_rval rval = server->qc_cb(server, client); if(rval & USCB_CLIENT_CLOSE) ArrayList_remove_tsafe(server->client_list, client); if(rval & USCB_CONTINUE) goto f_return; } UvTcpServer_stop(server); } /* Call the user's data_in_cb. */ else if(server->data_in_cb) { uscb_rval r_val; r_val = server->data_in_cb(server, client, buf->base, nread, package->data); if((r_val & USCB_CLIENT_CLOSE) || (r_val & USCB_SERVER_SHUTDOWN)) { ArrayList_remove_tsafe(server->client_list, client); if(r_val & USCB_SERVER_SHUTDOWN) UvTcpServer_stop(server); goto f_return; } } f_return: /* Need to unreserve the memory block. */ if(package) MemPool_unreserve_block(&package->mem_block); }
bot_t *attrib_help(dlist_t * dlist_node, bot_t * bot) { debug(bot, "attrib_help: Entered\n"); if (!bot) return NULL; if (str_match (bot->trig_called, STR_MATCH_STRCASECMP, 0, "^multi", NULL)) { bot->dl_module_help = "^multi ::: allows result data to be displayed on multiple lines"; } else { bot->dl_module_help = "^attrib ::: ^bold || ^underline || ^multi"; } return NULL; }
void WpaGui::processMsg(char *msg) { printf("======== WpaGui::processMsg Function. ========\n"); char *pos = msg, *pos2; int priority = 2; if (*pos == '<') { /* skip priority */ pos++; priority = atoi(pos); pos = strchr(pos, '>'); if (pos) pos++; else pos = msg; } // WpaMsg wm(pos, priority); // if (eh) // eh->addEvent(wm); // msgs.append(wm); // while (msgs.count() > 100) // msgs.pop_front(); /* Update last message with truncated version of the event */ if (strncmp(pos, "CTRL-", 5) == 0) { pos2 = strchr(pos, str_match(pos, WPA_CTRL_REQ) ? ':' : ' '); //include in file wpa_ctrl.h if (pos2) pos2++; else pos2 = pos; } else pos2 = pos; printf("======== In processMsg, pos2:%s\n",pos2); QString lastmsg = pos2; lastmsg.truncate(40); ui->textLastMessage->setText(lastmsg); pingsToStatusUpdate = 0; networkMayHaveChanged = true; // if (str_match(pos, WPA_CTRL_REQ)) // processCtrlReq(pos + strlen(WPA_CTRL_REQ)); }
//int main (int argc, char const* argv[]) int main(int argc, char* argv[]) { srand(time(NULL)); opt_preview=5; opt[OPT_HOLD]=1; opt[OPT_NUDGE]=1; opt[OPT_EASYSPIN]=1; opt[OPT_SHADOW]=1; opt[OPT_SLIDE]=1; opt[OPT_ALTHOLD]=0; opt[OPT_GHOST]=0; opt[OPT_DARK]=0; opt[OPT_FLASHLIGHT]=0; opt[OPT_THUNDER]=0; opt[OPT_FLARE]=0; opt[OPT_TRAINING]=0; opt[OPT_BAG]=0; if (argc>1) {if (str_match((char*)argv[1],(char*)"reset-cfg")) generate_config(1);} else generate_config(0); game_init(); #ifdef caanoo SDL_ShowCursor(0); #elif dingux SDL_ShowCursor(0); #else SDL_ShowCursor(1); #endif //if (main_menu(0)==0) {clearSDL(); return 0;} main_menu(0); clearSDL(); #ifdef caanoo chdir("/usr/gp2x"); execl("/usr/gp2x/gp2xmenu", "/usr/gp2x/gp2xmenu", NULL); #endif return 0; }
func_t *func_bracket_script(func_t *f) { strings *a=NULL; func_t *g=NULL; if(func_is_strings(f) && func_strings_size(f)==1) { if(str_match(func_strings_at(f,0),"^(%m+)$",BLK0,BLK1)) { a=strings_split_mask(func_strings_at(f,0),BLK0,BLK1,SPC); if(strings_size(a)==1) { g=func_script(strings_at(a,0)); } } } if(g==NULL) { g=f; } else { f=func_del(f); } a=strings_del(a); return g; }
const HLNode* HLIndex::seek_word(const char *str) const { HLNode **n = m_entries; int len; while (n < m_last_entry) { const char *c = (*n)->tag(); if (strncmp(str, "background-attachment", 21)==0) if ((*n)->is_equal("background")) len = 1; if ((len=str_match(str, c, true))) return const_cast<const HLNode*>(*n); else ++n; } return nullptr; }
func_t *func_add_script(func_t *f) { int i; strings *a=NULL; func_t *g=NULL; if(func_is_strings(f) && func_strings_size(f)==1){ if(str_match(func_strings_at(f,0),"%+",BLK0,BLK1)){ a=strings_split(func_strings_at(f,0),"+",BLK0,BLK1,SPC); if(strings_size(a)>0){ g=func_add_new(strings_size(a)); for(i=0; i<func_asize(g); i++){ func_aset(g,i,func_script(strings_at(a,i))); } g=func_add_eval(g); } } } if(g==NULL){ g=f; }else{ f=func_del(f); } a=strings_del(a); return g; }
char * string_replace (char *input, char *match, char *with, char *output, size_t max_out) { size_t i_l = strlen (input), w_l = strlen (with), m_l = strlen (match); size_t m_off = str_match (input, match); if ((int) m_off < 0) { return output; } bzero (output, max_out); strncpy (output, input, m_off); strncpy (&output[m_off], with, w_l); strncpy (&output[m_off + w_l], &input[m_off + m_l], i_l - m_off - m_l); return output; }
void WpaGui::saveConfig() { char buf[10]; size_t len; len = sizeof(buf) - 1; ctrlRequest("SAVE_CONFIG", buf, &len); buf[len] = '\0'; if (str_match(buf, "FAIL")) QMessageBox::warning( this, tr("Failed to save configuration"), tr("The configuration could not be saved.\n" "\n" "The update_config=1 configuration option\n" "must be used for configuration saving to\n" "be permitted.\n")); else QMessageBox::information( this, tr("Saved configuration"), tr("The current configuration was saved." "\n")); }
tree_cell* nasl_match(lex_ctxt* lexic) { char *pattern = get_str_local_var_by_name(lexic, "pattern"); char *string = get_str_local_var_by_name(lexic, "string"); int icase = get_int_local_var_by_name(lexic, "icase", 0); tree_cell *retc; if (pattern == NULL) { nasl_perror(lexic, "nasl_match: parameter 'pattern' missing\n"); pattern = ""; } if (string == NULL) { nasl_perror(lexic, "nasl_match: parameter 'string' missing\n"); string = ""; } retc = alloc_tree_cell(0, NULL); retc->type = CONST_INT; retc->x.i_val = str_match(string, pattern, icase); return retc; }
t_data *get_obj_and_light(int fd, t_data *data) { char *line; int end; end = 0; line = NULL; while (end == 0) { line = get_next_line(fd); if (line == NULL || str_match(line, "#EOF") == 1) end = 1; else { if (my_strncmp(line, "LIGHT", my_strlen("LIGHT")) == 0) data->light = get_light(line, data->light); else data->obj = get_obj(line, data->obj); } if (line != NULL) free(line); } return (data); }
int WpaGui::getNetworkDisabled(const QString &sel) { QString cmd(sel); char reply[10]; size_t reply_len = sizeof(reply) - 1; int pos = cmd.indexOf(':'); if (pos < 0) { printf("Invalid getNetworkDisabled '%s'\n", cmd.toAscii().constData()); return -1; } cmd.truncate(pos); cmd.prepend("GET_NETWORK "); cmd.append(" disabled"); if (ctrlRequest(cmd.toAscii().constData(), reply, &reply_len) >= 0 && reply_len >= 1) { reply[reply_len] = '\0'; if (!str_match(reply, "FAIL")) return atoi(reply); } return -1; }
static void wpatalk_action_process(const char *msg) { const char *pos; char *copy = NULL, *id, *pos2; pos = msg; if (*pos == '<') { /* skip priority */ pos = os_strchr(pos, '>'); if (pos) pos++; else pos = msg; } if (str_match(pos, WPA_EVENT_CONNECTED)) { int new_id = -1; os_unsetenv("WPA_ID"); os_unsetenv("WPA_ID_STR"); os_unsetenv("WPA_CTRL_DIR"); pos = os_strstr(pos, "[id="); if (pos) copy = os_strdup(pos + 4); if (copy) { pos2 = id = copy; while (*pos2 && *pos2 != ' ') pos2++; *pos2++ = '\0'; new_id = atoi(id); os_setenv("WPA_ID", id, 1); while (*pos2 && *pos2 != '=') pos2++; if (*pos2 == '=') pos2++; id = pos2; while (*pos2 && *pos2 != ']') pos2++; *pos2 = '\0'; os_setenv("WPA_ID_STR", id, 1); os_free(copy); } os_setenv("WPA_CTRL_DIR", ctrl_iface_dir, 1); if (!wpatalk_connected || new_id != wpatalk_last_id) { wpatalk_connected = 1; wpatalk_last_id = new_id; } return; } if (str_match(pos, WPA_EVENT_DISCONNECTED)) { if (wpatalk_connected) { wpatalk_connected = 0; } return; } if (str_match(pos, WPA_EVENT_TERMINATING)) { wpatalk_error("daemon is terminating"); os_sleep(2,0); wpatalk_reconnect(); return; } /* WPS-related messages. * All WPS "jobs" send CTRL-REQ-WPS_JOB_DONE when done. * They first send CTRL-REQ-EAP-WPS-SUCCESS if successful. */ if (str_match(pos, "CTRL-REQ-EAP-WPS-SUCCESS")) { if (wpatalk_wps_pending) { wpatalk_wps_finish(1, pos); } return; } if (str_match(pos, "CTRL-REQ-WPS-JOB-DONE")) { /* If we didn't stop due to success, must be failure */ if (wpatalk_wps_pending) { wpatalk_wps_finish(0, pos); } return; } }
tree_cell * get_kb_list(lex_ctxt * lexic) { struct arglist * script_infos = lexic->script_infos; struct arglist * kb = arg_get_value(script_infos, "key"); /* gruik gruik */ char * kb_mask = get_str_var_by_num(lexic, 0); tree_cell * retc; int num_elems = 0; nasl_array * a; if(kb_mask == NULL) { nasl_perror(lexic, "get_kb_list() usage : get_kb_list(<NameOfItem>)\n"); return NULL; } if(kb == NULL) { return NULL; } retc = alloc_tree_cell(0,NULL); retc->type = DYN_ARRAY; retc->x.ref_val = a = emalloc(sizeof(nasl_array)); while(kb->next != NULL) { anon_nasl_var v; bzero(&v, sizeof(v)); if(str_match(kb->name, kb_mask, 1) != 0) { if(kb->type == ARG_INT) { v.var_type = VAR2_INT; v.v.v_int = (int)kb->value; add_var_to_array(a, kb->name, &v); num_elems ++; } else if(kb->type == ARG_STRING) { v.var_type = VAR2_DATA; v.v.v_str.s_val = kb->value; v.v.v_str.s_siz = strlen(kb->value); add_var_to_array(a, kb->name, &v); num_elems ++; } else if(kb->type == ARG_ARGLIST) { struct arglist * tmp = kb->value; if( tmp != NULL ) while (tmp->next != NULL ) { v.var_type = VAR2_DATA; v.v.v_str.s_val = tmp->value; v.v.v_str.s_siz = strlen(tmp->value); add_var_to_array(a, kb->name, &v); num_elems ++; tmp = tmp->next; } } } kb = kb->next; } if(num_elems == 0) { deref_cell(retc); return NULL; } return retc; }
void radc_compiler::compile(int options) { if (_cache_program != -1) { varlist = programs[_cache_program].value->varlist; statements = programs[_cache_program].value->statements; return ; } char * str = buffer.c_ptr(); int line = 1; int depth = 0; _options = options; while (*str && !is_error()) { str = str_skip(str, ' '); if (*str == '#') // comment { while (*str && *str != '\n') ++str; if (*str == '\n') ++str; continue; } char * line_str = str; int line_length = 0; while (*str && *str != '\n') { ++str; ++line_length; } if (*str == '\n') { *str = 0; ++str; } str_trim(line_str, line_length); if (*line_str) { const char * matched_str = NULL; radc_stat * stat = NULL; bool insert_empty = false; do { matched_str = str_match(line_str, "function"); if (matched_str && (*matched_str == ' ' || *matched_str == '\0')) { matched_str = str_skip(matched_str, ' '); matched_str = str_match(matched_str, "main"); if (matched_str) { stat = new rstat_entry; stat->str = str_skip(matched_str, ' '); } else { set_error("Error: [%d] - main.", line); } depth += 1; break; } matched_str = str_match(line_str, "if"); if (matched_str && (*matched_str == ' ' || *matched_str == '\0')) { stat = new rstat_if; stat->str = str_skip(matched_str, ' '); insert_empty = true; depth += 1; break; } matched_str = str_match(line_str, "else"); if (matched_str && (*matched_str == ' ' || *matched_str == '\0')) { matched_str = str_skip(matched_str, ' '); const char * matched_str2 = str_match(matched_str, "if"); if (matched_str2 && (*matched_str2 == ' ' || *matched_str2 == '\0')) { stat = new rstat_elseif; stat->str = str_skip(matched_str2, ' '); insert_empty = true; } else { stat = new rstat_else; stat->str = str_skip(matched_str, ' '); insert_empty = true; } break; } matched_str = str_match(line_str, "end"); if (matched_str && (*matched_str == ' ' || *matched_str == '\0')) { stat = new rstat_end; stat->str = str_skip(matched_str, ' '); depth -= 1; break; } matched_str = str_match(line_str, "while"); if (matched_str && (*matched_str == ' ' || *matched_str == '\0')) { stat = new rstat_while; stat->str = str_skip(matched_str, ' '); insert_empty = true; depth += 1; break; } matched_str = str_match(line_str, "return"); if (matched_str && (*matched_str == ' ' || *matched_str == '\0')) { stat = new rstat_return; stat->str = str_skip(matched_str, ' '); break; } stat = new rstat_exp; stat->str = str_skip(line_str, ' '); } while (0); if (stat != NULL) { stat->line = line; statements.PushBack(stat); if (insert_empty) { statements.PushBack(new rstat_empty); } } } ++line; } if (!is_error() && depth != 0) { set_error("Error: end don't macthed."); } // if Ìøת for (int i = 0; i < statements.Size(); ++i) { if (TYPE_OF(rstat_if, statements[i]) || TYPE_OF(rstat_elseif, statements[i]) || TYPE_OF(rstat_else, statements[i])) { int in_if = 0, end_if = 0; for (int j = i + 1; j < statements.Size(); ++j) { if (TYPE_OF(rstat_elseif, statements[j]) || TYPE_OF(rstat_else, statements[j]) || TYPE_OF(rstat_end, statements[j])) { if (in_if == 0) { end_if = j - 1; statements[i]->jump = j; break; } } if (TYPE_OF(rstat_if, statements[j]) || TYPE_OF(rstat_while, statements[j])) { in_if += 1; } if (TYPE_OF(rstat_end, statements[j])) { in_if -= 1; } } d_assert (end_if > i); in_if = 0; for (int j = end_if + 1; j < statements.Size(); ++j) { if (TYPE_OF(rstat_end, statements[j])) { if (in_if == 0) { statements[end_if]->jump = j; break; } } if (TYPE_OF(rstat_if, statements[j]) || TYPE_OF(rstat_while, statements[j])) { in_if += 1; } if (TYPE_OF(rstat_end, statements[j])) { in_if -= 1; } } } } // while Ìøת for (int i = 0; i < statements.Size(); ++i) { if (TYPE_OF(rstat_while, statements[i])) { int in_while = 0, end_while = 0; for (int j = i + 1; j < statements.Size(); ++j) { if (TYPE_OF(rstat_end, statements[j])) { if (in_while == 0) { end_while = j - 1; statements[i]->jump = j; break; } } if (TYPE_OF(rstat_if, statements[j]) || TYPE_OF(rstat_while, statements[j])) { in_while += 1; } if (TYPE_OF(rstat_end, statements[j])) { in_while -= 1; } } d_assert (end_while > i); statements[end_while]->jump = i; } } for (int i = 0; i < statements.Size(); ++i) { statements[i]->build(); } }
unsigned char easyUtils::str_match (const char *search, const std::string &subject) { std::string str_search (search); return str_match (str_search, subject); }
//遍历dir_1下的所有文件,在dir_2中寻找匹配的ISD void compare_find_match(string dir_1,string dir_2){ u32 success_num=0; string fileSuffix="*.txt"; string fileDir=dir_1+fileSuffix; struct _finddata_t file; long longf; if((longf = _findfirst(fileDir.c_str(),&file))==-1L){ cout<<"文件没有找到!\n"<<endl; }else{ //循环查找所有后缀为.txt的文件 string fileName=file.name; cout<<"proceed:"<<fileName<<endl; //解析出KSD string::size_type pos=fileName.find("."); string curr_KSD=fileName.substr(0,pos); //do something读取当前的ISD string tableName=dir_1+fileName; ifstream infile; infile.open(tableName.c_str()); if(infile){ char val[2048]; while(infile.getline(val,sizeof(val))){ string str(val); string curr_ISD=str; //在dir_2中寻找匹配项 string match_TB=dir_2+fileName; ifstream infile_match; infile_match.open(match_TB.c_str()); if(infile_match){ char val_match[2048]; while(infile_match.getline(val_match,sizeof(val_match))){ string str_match(val_match); string::size_type pos=str_match.find(" "); string ISD=str_match.substr(0,pos); if(curr_ISD.compare(ISD)==0){ cout<<"Success!"<<endl; success_num++; } } } infile_match.close(); } } infile.close(); while(_findnext(longf,&file)==0){ fileName=file.name; cout<<"proceed:"<<fileName<<endl; curr_KSD=fileName.substr(0,pos); //do something tableName=dir_1+fileName; ifstream infile; infile.open(tableName.c_str()); if(infile){ char val[2048]; while(infile.getline(val,sizeof(val))){ string str(val); string curr_ISD=str; //在dir_2中寻找匹配项 string match_TB=dir_2+fileName; ifstream infile_match; infile_match.open(match_TB.c_str()); if(infile_match){ char val_match[2048]; while(infile_match.getline(val_match,sizeof(val_match))){ string str_match(val_match); string::size_type pos=str_match.find(" "); string ISD=str_match.substr(0,pos); if(curr_ISD.compare(ISD)==0){ cout<<"Success!"<<endl; success_num++; } } } infile_match.close(); } } infile.close(); } } _findclose(longf); cout<<"Success num:"<<success_num<<endl; }
void mu_getlst(char *name, int4 size) { char *c1, *c2, *c3, *c4, rbuff[MAX_FN_LEN + 1], fbuff[MAX_FN_LEN + 1]; unsigned short rlen, flen, i; gd_region *reg; tp_region *list; boolean_t matched; error_def(ERR_MUNODBNAME); error_def(ERR_MUBCKNODIR); error_def(ERR_MUNOACTION); error_def(ERR_TEXT); mu_star_specified = FALSE; assert(size > 0); rlen = sizeof(rbuff); flen = sizeof(fbuff); if (!cli_get_str(name, rbuff, &rlen)) mupip_exit(ERR_MUNODBNAME); if (in_backup && ((!cli_get_str("SAVE_DIR", fbuff, &flen)) || (0 == flen))) mupip_exit(ERR_MUBCKNODIR); is_directory = FALSE; for (c1 = c2 = rbuff, c3 = c4 = fbuff;;) { for (; *c2 && (*c2 != ','); c2++) /* locate a reg spec */ ; if (c2 - c1 > MAX_RN_LEN) { error_mupip = TRUE; util_out_print("!UL exceeds maximum REGION name length of !UL characters.", TRUE, c2 - c1, MAX_RN_LEN); } else { /* handle the reg spec here */ if ('*' == *c1 && (1 == c2 - c1)) mu_star_specified = TRUE; matched = FALSE; for (i = 0, reg = gd_header->regions; i < gd_header->n_regions; i++, reg++) { if (TRUE == str_match((char *)reg->rname, reg->rname_len, c1, c2 - c1)) { matched = TRUE; if (NULL == (list = insert_region(reg, &(grlist), NULL, size))) { error_mupip = TRUE; rts_error(VARLSTCNT(4) ERR_TEXT, 2, RTS_ERROR_STRING("Region not found")); continue; } if ((FALSE == in_backup) || (0 != ((backup_reg_list *)list)->backup_file.len)) continue; if (TRUE == is_directory) { assert(NULL != grlist->fPtr); mubexpfilnam(directory.addr, directory.len, (backup_reg_list *)list); } else { for (; *c4 && (*c4 != ','); c4++) /* locate a file spec */ ; if (FALSE == mubgetfil((backup_reg_list *)list, c3, c4 - c3)) break; if (*c4) c3 = ++c4; else if (FALSE == is_directory) break; } } } if (!matched) { util_out_print("REGION !AD not found", TRUE, c2 - c1, c1); mupip_exit(ERR_MUNOACTION); } } if (!*c2) break; else c1 = ++c2; } return; }
static void wpa_cli_action_process(const char *msg) { const char *pos; char *copy = NULL, *id, *pos2; pos = msg; if (*pos == '<') { /* skip priority */ pos = os_strchr(pos, '>'); if (pos) pos++; else pos = msg; } if (str_match(pos, WPA_EVENT_CONNECTED)) { int new_id = -1; os_unsetenv("WPA_ID"); os_unsetenv("WPA_ID_STR"); os_unsetenv("WPA_CTRL_DIR"); pos = os_strstr(pos, "[id="); if (pos) copy = os_strdup(pos + 4); if (copy) { pos2 = id = copy; while (*pos2 && *pos2 != ' ') pos2++; *pos2++ = '\0'; new_id = atoi(id); os_setenv("WPA_ID", id, 1); while (*pos2 && *pos2 != '=') pos2++; if (*pos2 == '=') pos2++; id = pos2; while (*pos2 && *pos2 != ']') pos2++; *pos2 = '\0'; os_setenv("WPA_ID_STR", id, 1); os_free(copy); } os_setenv("WPA_CTRL_DIR", ctrl_iface_dir, 1); if (!wpa_cli_connected || new_id != wpa_cli_last_id) { wpa_cli_connected = 1; wpa_cli_last_id = new_id; wpa_cli_exec(action_file, ctrl_ifname, "CONNECTED"); } } else if (str_match(pos, WPA_EVENT_DISCONNECTED)) { if (wpa_cli_connected) { wpa_cli_connected = 0; wpa_cli_exec(action_file, ctrl_ifname, "DISCONNECTED"); } } else if (str_match(pos, WPA_EVENT_TERMINATING)) { printf("wpa_supplicant is terminating - stop monitoring\n"); wpa_cli_quit = 1; } }