static int next_token (void) { int result; lastpos = p; switch (*p) { case '\0': result = END; break; case ':': case ',': case '-': case ';': result = *p; p++; break; case 'b': case 'B': result = match_word ("big_endian", BIG); break; case 'l': case 'L': result = match_word ("little_endian", LITTLE); break; case 'n': case 'N': result = match_word ("native", NATIVE); break; case 's': case 'S': result = match_word ("swap", SWAP); break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': result = match_integer (); break; default: result = ILLEGAL; break; } return result; }
void insert(int id) { static int space_min = 0; Entry * word = &lexicon[id]; for (;;) { int p,i; match_word(dat, word->key, &p, &i, 0); if (p == word->length) return; get_words_with_prefix(word->key, p); int delta; delta = space_min - words_set_char[0]; for (; delta < DATRIE_SIZE; delta ++) if (words_space_available(delta)) break; if (delta == DATRIE_SIZE) { fprintf(stderr,"DATRIE_SIZE Not Enough!\n"); exit(1); } insert_words(delta, i, p); dat[i].base = delta; while (!unused(space_min)) space_min++; } }
int match_disk(const char *glob, const char *disk) { char *glob2 = NULL, *disk2 = NULL; const char *g = glob, *d = disk; int result; /* * Check whether our disk potentially refers to a Windows share (the first * two characters are '\' and there is no / in the word at all): if yes, * build Unix paths instead and pass those as arguments to match_word() */ gboolean windows_share = !(strncmp(disk, "\\\\", 2) || strchr(disk, '/')); if (*glob == '=') { return strcmp(glob+1, disk) == 0; } if (windows_share) { glob2 = convert_winglob_to_unix(glob); disk2 = convert_unc_to_unix(disk); g = (const char *) glob2; d = (const char *) disk2; } result = match_word(g, d, '/'); /* * We can g_free(NULL), so this is "safe" */ g_free(glob2); g_free(disk2); return result; }
void scan_file(char * filename, int * tokens) { FILE * fd = fopen(filename, "r"); while(!feof(fd)) { char word[80]; fgets(word, 80, fd); if(match_word(word, tokens)) printf("%s", word); } fclose(fd); }
// Returns whether any of the words in in_files is matched in any of the files // in out_files bool compare_file_arrays(FileArray* in_files, FileArray* out_files) { int i, j; for (i = 0; i < in_files->pos; i++) for (j = 0; j < out_files->pos; j++) if (match_word(in_files->files[i], out_files->files[j])) return true; return false; }
/** * translate chinese sentence into pinyin * @param raw raw string * @return pinyin string */ char* pinyin_translate(char* raw, PinTable * dict){ int max_cut_len = MAX_CUT_LEN; int length = strlen(raw); int idx = 0; int chr_idx = 0; int flag_idx = 0; int back = 0; wchar_t* buffer = 0; wchar_t* wraw = 0; int wlen = 0; wraw = (wchar_t*)malloc(sizeof(wchar_t) * length); memset(wraw, 0, sizeof(wchar_t) * length); wlen = mbstowcs(wraw, raw, length); buffer = (wchar_t*)malloc((max_cut_len + 1) * sizeof(wchar_t)); memset(buffer, 0, (max_cut_len + 1) * sizeof(wchar_t)); result_buffer = (char*)malloc(1); memset(result_buffer, 0, 1); for(idx = 0; idx < wlen; idx++){ flag_idx = idx % max_cut_len; chr_idx = wlen - 1 - idx; buffer[max_cut_len - 1 - flag_idx] = wraw[chr_idx]; // get the fragment string if (flag_idx == max_cut_len - 1 || idx == wlen - 1){ wchar_t* tmp_buffer = 0; tmp_buffer = buffer_shift(buffer, max_cut_len); back = match_word(tmp_buffer, dict); idx = idx - back; if (idx == wlen - 1){ // } memset(buffer, 0, (max_cut_len + 1) * sizeof(wchar_t)); } } free(buffer); buffer = 0; free(wraw); wraw = 0; result_buffer[strlen(result_buffer)] = 0; return result_buffer; }
int main(){ //dir_content dir; //int j; //char *name = "E:\\Programing\\C"; //dir = scan_dir(name); //for (j = 0 ; j < dir.count ; j++){ // scan_dir(dir.dp_N[j]); //} char *location = "E:\\Programing\\C\\Experiment\\Marshall\\Marshall"; char *word = "Line"; match_word(word,location); }
int match_host(const char *glob, const char *host) { char *lglob, *lhost; int ret; lglob = g_ascii_strdown(glob, -1); lhost = g_ascii_strdown(host, -1); ret = match_word(lglob, lhost, '.'); g_free(lglob); g_free(lhost); return ret; }
int match_host(const char *glob, const char *host) { char *lglob, *lhost; int ret; if (*glob == '=') { return strcmp(glob+1, host) == 0; } lglob = g_ascii_strdown(glob, -1); lhost = g_ascii_strdown(host, -1); ret = match_word(lglob, lhost, '.'); g_free(lglob); g_free(lhost); return ret; }
int kmp(char *s, char *t) { int *next; int i = 0, j, cond; next = get_next_word(t); while(1) { cond = match_word(s, t, i); if(cond == -1) return i; else if(cond == -2) break; else i += (cond - next[cond]); } return -1; }
// Grammar match bool match_prototype(TokenState& state, Prototype *ptr_prototype) { Type ret_type; if (! match_type(state, &ret_type)) { state.error_msg += "Expected return type for prototype.\n"; return false; } simple::string fun_name; if (!match_ident_name(state, &fun_name)) { state.error_msg += "Expected function name.\n"; return false; } if (!match_word(state, "(")) { state.error_msg += "Missed ( after function name.\n"; return false; } ArgumentsList argument_list; if (!match_arguments_list(state, &argument_list)) return false; // Skip ; simple::string token; if (state.peek_token(&token) && token == ";") state.skip(); if (state.peek_token(&token)) { state.error_msg.snprintf("There are some words(\"%s\") following prototype.", 256, token.c_str()); return false; } ptr_prototype->fun_name = simple::move(fun_name); ptr_prototype->ret_type = simple::move(ret_type); ptr_prototype->arguments_list = simple::move(argument_list); return true; }
// Grammar match: arguments_list = type argument [= const_value] [,arguments_list] bool match_arguments_list(TokenState& state, ArgumentsList *ptr_arguments) { ArgumentsList argument_list; simple::string token; while (state.peek_token(&token) && token != ")") { if (token == "...") { // Matched ... state.skip(); argument_list.is_va_arg = true; break; } // Get next argument Argument argument; if (!match_argument(state, &argument)) return false; argument_list.args.push_back(simple::move(argument)); if (state.peek_token(&token) && token == ",") { // Continue to match state.skip(); continue; } } if (!match_word(state, ")")) { state.error_msg += "Missed ) for prototype.\n"; return false; } *ptr_arguments = simple::move(argument_list); return true; }
/* * Extracts given chains from a policy file. */ static int openpam_read_chain(pam_handle_t *pamh, const char *service, pam_facility_t facility, const char *filename, openpam_style_t style) { pam_chain_t *this, **next; const char *p, *q; int count, i, lineno, ret; pam_facility_t fclt; pam_control_t ctlf; char *line, *name; FILE *f; if ((f = fopen(filename, "r")) == NULL) { openpam_log(errno == ENOENT ? PAM_LOG_LIBDEBUG : PAM_LOG_NOTICE, "%s: %m", filename); return (0); } this = NULL; count = lineno = 0; while ((line = openpam_readline(f, &lineno, NULL)) != NULL) { p = line; /* match service name */ if (style == pam_conf_style) { if (!match_word(p, service)) { FREE(line); continue; } p = next_word(p); } /* match facility name */ for (fclt = 0; fclt < PAM_NUM_FACILITIES; ++fclt) if (match_word(p, _pam_facility_name[fclt])) break; if (fclt == PAM_NUM_FACILITIES) { openpam_log(PAM_LOG_NOTICE, "%s(%d): invalid facility '%.*s' (ignored)", filename, lineno, wordlen(p), p); goto fail; } if (facility != fclt && facility != PAM_FACILITY_ANY) { FREE(line); continue; } p = next_word(p); /* include other chain */ if (match_word(p, "include")) { p = next_word(p); if (*next_word(p) != '\0') openpam_log(PAM_LOG_NOTICE, "%s(%d): garbage at end of 'include' line", filename, lineno); if ((name = dup_word(p)) == NULL) goto syserr; ret = openpam_load_chain(pamh, name, fclt); FREE(name); if (ret < 0) goto fail; count += ret; FREE(line); continue; } /* allocate new entry */ if ((this = calloc(1, sizeof *this)) == NULL) goto syserr; /* control flag */ for (ctlf = 0; ctlf < PAM_NUM_CONTROL_FLAGS; ++ctlf) if (match_word(p, _pam_control_flag_name[ctlf])) break; if (ctlf == PAM_NUM_CONTROL_FLAGS) { openpam_log(PAM_LOG_ERROR, "%s(%d): invalid control flag '%.*s'", filename, lineno, wordlen(p), p); goto fail; } this->flag = ctlf; /* module name */ p = next_word(p); if (*p == '\0') { openpam_log(PAM_LOG_ERROR, "%s(%d): missing module name", filename, lineno); goto fail; } if ((name = dup_word(p)) == NULL) goto syserr; this->module = openpam_load_module(name); FREE(name); if (this->module == NULL) goto fail; /* module options */ p = q = next_word(p); while (*q != '\0') { ++this->optc; q = next_word(q); } this->optv = calloc(this->optc + 1, sizeof(char *)); if (this->optv == NULL) goto syserr; for (i = 0; i < this->optc; ++i) { if ((this->optv[i] = dup_word(p)) == NULL) goto syserr; p = next_word(p); } /* hook it up */ for (next = &pamh->chains[fclt]; *next != NULL; next = &(*next)->next) /* nothing */ ; *next = this; this = NULL; ++count; /* next please... */ FREE(line); } if (!feof(f)) goto syserr; fclose(f); return (count); syserr: openpam_log(PAM_LOG_ERROR, "%s: %m", filename); fail: FREE(this); FREE(line); fclose(f); return (-1); }
struct pipe_screen * ddebug_screen_create(struct pipe_screen *screen) { struct dd_screen *dscreen; const char *option; bool flush = false; bool verbose = false; bool transfers = false; unsigned timeout = 1000; unsigned apitrace_dump_call = 0; enum dd_dump_mode mode = DD_DUMP_ONLY_HANGS; option = debug_get_option("GALLIUM_DDEBUG", NULL); if (!option) return screen; if (!strcmp(option, "help")) { puts("Gallium driver debugger"); puts(""); puts("Usage:"); puts(""); puts(" GALLIUM_DDEBUG=\"[<timeout in ms>] [(always|apitrace <call#)] [flush] [transfers] [verbose]\""); puts(" GALLIUM_DDEBUG_SKIP=[count]"); puts(""); puts("Dump context and driver information of draw calls into"); puts("$HOME/"DD_DIR"/. By default, watch for GPU hangs and only dump information"); puts("about draw calls related to the hang."); puts(""); puts("<timeout in ms>"); puts(" Change the default timeout for GPU hang detection (default=1000ms)."); puts(" Setting this to 0 will disable GPU hang detection entirely."); puts(""); puts("always"); puts(" Dump information about all draw calls."); puts(""); puts("transfers"); puts(" Also dump and do hang detection on transfers."); puts(""); puts("apitrace <call#>"); puts(" Dump information about the draw call corresponding to the given"); puts(" apitrace call number and exit."); puts(""); puts("flush"); puts(" Flush after every draw call."); puts(""); puts("verbose"); puts(" Write additional information to stderr."); puts(""); puts("GALLIUM_DDEBUG_SKIP=count"); puts(" Skip dumping on the first count draw calls (only relevant with 'always')."); puts(""); exit(0); } for (;;) { skip_space(&option); if (!*option) break; if (match_word(&option, "always")) { if (mode == DD_DUMP_APITRACE_CALL) { printf("ddebug: both 'always' and 'apitrace' specified\n"); exit(1); } mode = DD_DUMP_ALL_CALLS; } else if (match_word(&option, "flush")) { flush = true; } else if (match_word(&option, "transfers")) { transfers = true; } else if (match_word(&option, "verbose")) { verbose = true; } else if (match_word(&option, "apitrace")) { if (mode != DD_DUMP_ONLY_HANGS) { printf("ddebug: 'apitrace' can only appear once and not mixed with 'always'\n"); exit(1); } if (!match_uint(&option, &apitrace_dump_call)) { printf("ddebug: expected call number after 'apitrace'\n"); exit(1); } mode = DD_DUMP_APITRACE_CALL; } else if (match_uint(&option, &timeout)) { /* no-op */ } else { printf("ddebug: bad options: %s\n", option); exit(1); } } dscreen = CALLOC_STRUCT(dd_screen); if (!dscreen) return NULL; #define SCR_INIT(_member) \ dscreen->base._member = screen->_member ? dd_screen_##_member : NULL dscreen->base.destroy = dd_screen_destroy; dscreen->base.get_name = dd_screen_get_name; dscreen->base.get_vendor = dd_screen_get_vendor; dscreen->base.get_device_vendor = dd_screen_get_device_vendor; SCR_INIT(get_disk_shader_cache); dscreen->base.get_param = dd_screen_get_param; dscreen->base.get_paramf = dd_screen_get_paramf; dscreen->base.get_compute_param = dd_screen_get_compute_param; dscreen->base.get_shader_param = dd_screen_get_shader_param; dscreen->base.query_memory_info = dd_screen_query_memory_info; /* get_video_param */ /* get_compute_param */ SCR_INIT(get_timestamp); dscreen->base.context_create = dd_screen_context_create; dscreen->base.is_format_supported = dd_screen_is_format_supported; /* is_video_format_supported */ SCR_INIT(can_create_resource); dscreen->base.resource_create = dd_screen_resource_create; dscreen->base.resource_from_handle = dd_screen_resource_from_handle; SCR_INIT(resource_from_memobj); SCR_INIT(resource_from_user_memory); SCR_INIT(check_resource_capability); dscreen->base.resource_get_handle = dd_screen_resource_get_handle; SCR_INIT(resource_changed); dscreen->base.resource_destroy = dd_screen_resource_destroy; SCR_INIT(flush_frontbuffer); SCR_INIT(fence_reference); SCR_INIT(fence_finish); SCR_INIT(memobj_create_from_handle); SCR_INIT(memobj_destroy); SCR_INIT(get_driver_query_info); SCR_INIT(get_driver_query_group_info); SCR_INIT(get_compiler_options); SCR_INIT(get_driver_uuid); SCR_INIT(get_device_uuid); #undef SCR_INIT dscreen->screen = screen; dscreen->timeout_ms = timeout; dscreen->dump_mode = mode; dscreen->flush_always = flush; dscreen->transfers = transfers; dscreen->verbose = verbose; dscreen->apitrace_dump_call = apitrace_dump_call; switch (dscreen->dump_mode) { case DD_DUMP_ALL_CALLS: fprintf(stderr, "Gallium debugger active. Logging all calls.\n"); break; case DD_DUMP_APITRACE_CALL: fprintf(stderr, "Gallium debugger active. Going to dump an apitrace call.\n"); break; default: fprintf(stderr, "Gallium debugger active.\n"); break; } if (dscreen->timeout_ms > 0) fprintf(stderr, "Hang detection timeout is %ums.\n", dscreen->timeout_ms); else fprintf(stderr, "Hang detection is disabled.\n"); dscreen->skip_count = debug_get_num_option("GALLIUM_DDEBUG_SKIP", 0); if (dscreen->skip_count > 0) { fprintf(stderr, "Gallium debugger skipping the first %u draw calls.\n", dscreen->skip_count); } return &dscreen->base; }
static double parse_simple_number(MVMThreadContext *tc, MVMCodepointIter *ci, MVMCodepoint *cp, MVMString *s) { double sign; /* Handle NaN here, to make later parsing simpler */ if (match_word(tc, ci, cp, "NaN", s)) { return MVM_num_nan(tc); } sign = parse_sign(tc, ci, cp); if (match_word(tc, ci, cp, "Inf", s)) { return sign * MVM_num_posinf(tc); } else if (*cp == ':') { int radix; double body; get_cp(tc, ci, cp); radix = (int) parse_int_frac_exp(tc, ci, cp, s, 10, 0); if (*cp == '<') { get_cp(tc, ci, cp); body = parse_int_frac_exp(tc, ci, cp, s, radix, 0); if (*cp == '>') { /* > */ get_cp(tc, ci, cp); return sign * body; } parse_error(tc, s, "malformed ':radix<>' style radix number, expecting '>' after the body"); } else if (*cp == 171) { /* « */ get_cp(tc, ci, cp); body = parse_int_frac_exp(tc, ci, cp, s, radix, 0); if (*cp == 187) { /* » */ get_cp(tc, ci, cp); return sign * body; } parse_error(tc, s, "malformed ':radix«»' style radix number, expecting '>' after the body"); } else if (*cp == '[') { double result = 0; get_cp(tc, ci, cp); while (*cp != ']' && MVM_string_ci_has_more(tc, ci)) { double digit = parse_decimal_integer(tc, ci, cp, s); result = result * radix + digit; if (*cp == ',') { get_cp(tc, ci, cp); } } if (*cp == ']') { get_cp(tc, ci, cp); return sign * result; } parse_error(tc, s, "malformed ':radix[]' style radix number, expecting ']' after the body"); } parse_error(tc, s, "malformed ':radix' style number. Expected <, [ or « after ':radix'"); } else if (*cp == '0') { int radix = 0; get_cp(tc, ci, cp); switch (*cp) { case 'b': radix = 2; break; case 'o': radix = 8; break; case 'd': radix = 10; break; case 'x': radix = 16; break; } if (radix) { get_cp(tc, ci, cp); if (*cp == '_') get_cp(tc, ci, cp); return sign * parse_int_frac_exp(tc, ci, cp, s, radix, 1); } return sign * parse_int_frac_exp(tc, ci, cp, s, 10, 1); } else { return sign * parse_int_frac_exp(tc, ci, cp, s, 10, 0); } }
static int parse_color(struct color *out, const char *name, int len) { /* Positions in array must match ANSI color codes */ static const char * const color_names[] = { "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white" }; char *end; int i; long val; /* First try the special word "normal"... */ if (match_word(name, len, "normal")) { out->type = COLOR_NORMAL; return 0; } /* Try a 24-bit RGB value */ if (len == 7 && name[0] == '#') { if (!get_hex_color(name + 1, &out->red) && !get_hex_color(name + 3, &out->green) && !get_hex_color(name + 5, &out->blue)) { out->type = COLOR_RGB; return 0; } } /* Then pick from our human-readable color names... */ for (i = 0; i < ARRAY_SIZE(color_names); i++) { if (match_word(name, len, color_names[i])) { out->type = COLOR_ANSI; out->value = i; return 0; } } /* And finally try a literal 256-color-mode number */ val = strtol(name, &end, 10); if (end - name == len) { /* * Allow "-1" as an alias for "normal", but other negative * numbers are bogus. */ if (val < -1) ; /* fall through to error */ else if (val < 0) { out->type = COLOR_NORMAL; return 0; /* Rewrite low numbers as more-portable standard colors. */ } else if (val < 8) { out->type = COLOR_ANSI; out->value = val; return 0; } else if (val < 256) { out->type = COLOR_256; out->value = val; return 0; } } return -1; }