result_t Redis::_single(std::string key, v8::Local<v8::Function> func, int32_t cmd) { std::string key1 = s_cmd[cmd][1] + key; m_subMode = 1; if (!((cmd & 1) ? unregsub(key1, func) : regsub(key1, func))) return 0; Variant v; return doCommand(s_cmd[cmd][0], key, v); }
main(int ac, char **av) { Resub rs[10]; char dst[128]; int n; struct x *tp; for(tp = t; tp->re; tp++) tp->p = regcomp(tp->re); for(tp = t; tp->re; tp++){ print("%s VIA %s", av[1], tp->re); memset(rs, 0, sizeof rs); if(regexec(tp->p, av[1], rs, 10)){ regsub(tp->s, dst, sizeof dst, rs, 10); print(" sub %s -> %s", tp->s, dst); } print("\n"); } exit(0); }
static void try_func( char** fields) { regexp *r; char dbuf[BUFSIZ]; errseen = NULL; r = regcomp(fields[0]); if (r == NULL) { if (*fields[2] != 'c') complain("regcomp failure in `%s'", fields[0]); return; } if (*fields[2] == 'c') { complain("unexpected regcomp success in `%s'", fields[0]); free((char *)r); return; } if (!regexec(r, fields[1])) { if (*fields[2] != 'n') complain("regexec failure in `%s'", ""); free((char *)r); return; } if (*fields[2] == 'n') { complain("unexpected regexec success", ""); free((char *)r); return; } errseen = NULL; regsub(r, fields[3], dbuf); if (errseen != NULL) { complain("regsub complaint", ""); free((char *)r); return; } if (strcmp(dbuf, fields[4]) != 0) complain("regsub result `%s' wrong", dbuf); free((char *)r); }
/* ARGSUSED */ main( int argc, char *argv[]) { regexp *r; int i; set_regerror_func( try_regerror); #ifdef ERRAVAIL progname = mkprogname(argv[0]); #endif if (argc == 1) { multiple(); exit(status); } r = regcomp(argv[1]); if (r == NULL) error("regcomp failure", ""); #ifdef DEBUG regdump(r); if (argc > 4) regnarrate++; #endif if (argc > 2) { i = regexec(r, argv[2]); printf("%d", i); for (i = 1; i < NSUBEXP; i++) if (r->startp[i] != NULL && r->endp[i] != NULL) printf(" \\%d", i); printf("\n"); } if (argc > 3) { regsub(r, argv[3], buf); printf("%s\n", buf); } exit(status); }
/* This is the worker routing for the threads that process the * substitution of the nucleic acid codes with their meanings. These * threads are not in a thread pool because the work can be divided * exactly into one thread per cpu. So the parent just starts each * thread and waits for them all to finish. * * Each worker gets a range of characters from the main input string * and is responsible for calling regsub() once for each nucleic acid * code. Thus, if there are 11 nucleic acid codes, each thread calls * regsub() 11 times but the scope of the regsub() call is limited to * just the range of characters it has been assigned. */ static void* process_nacodes_worker(nacodes_worker_data_t data) { char* s_in = NULL; char* s_out = NULL; struct nucleic_acid_code* nacode = NULL; /* Get the character range as a C-style string. */ s_in = Tcl_GetString(data->range); /* Iterate over the nucleic acid codes. */ for (nacode = nacodes ; nacode->code ; ++nacode) { /* Perform the substitution. */ s_out = regsub(nacode->code, s_in, nacode->meaning, NULL); /* Free s_in on all but the first pass because s_in * belongs to Tcl on the first pass. */ if (nacode != nacodes) { g_free(s_in); s_in = NULL; } /* If this is the last pass, save the result and clean up. */ if ((nacode + 1)->code == NULL) { Tcl_SetStringObj(data->range, s_out, strlen(s_out)); g_free(s_out); s_out = NULL; } else { /* Otherwise, prepare for the next iteration. */ s_in = s_out; s_out = NULL; } } return NULL; }
result_t Redis::_map(v8::Local<v8::Object> &map, int32_t cmd) { m_subMode = 1; Isolate* isolate = holder(); v8::Local<v8::Array> channels = map->GetPropertyNames(); int32_t sz = channels->Length(); int32_t i; v8::Local<v8::Array> subs = v8::Array::New(isolate->m_isolate); int32_t count = 0; for (i = 0; i < sz; i ++) { v8::Local<v8::Value> channel = channels->Get(i); std::string s; GetArgumentValue(channel, s); s = s_cmd[cmd][1] + s; v8::Local<v8::Value> value = map->Get(channel); if (!value->IsFunction()) return CHECK_ERROR(CALL_E_TYPEMISMATCH); v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(value); if ((cmd & 1) ? unregsub(s, func) : regsub(s, func)) subs->Set(count ++, channel); } if (!count) return 0; Variant v; return doCommand(s_cmd[cmd][0], subs, v); }
int main(int argc, char* argv[]) { int rv = 0; int cpu_count = 0; int init_length = 0; int code_length = 0; int seq_length = 0; char* s_cstr = NULL; Tcl_Interp *tcl = NULL; Tcl_Obj* s = NULL; /* Initialize Tcl. */ Tcl_FindExecutable(argv[0]); tcl = Tcl_CreateInterp(); Tcl_Preserve((ClientData)tcl); /* Count the number of cpus. If the cpu count could not be * determined, assume 4 cpus. */ cpu_count = get_cpu_count(); if (!cpu_count) { cpu_count = 4; } /* Allocate s. */ s = Tcl_NewStringObj("", 0); Tcl_IncrRefCount(s); /* Load stdin into s. */ load_file(stdin, s); /* Get the length of s. */ init_length = Tcl_GetCharLength(s); /* Strip off section headers and EOLs from s. This is a little * messy because we have to go from Tcl-string to C-string and * back to Tcl-string. */ s_cstr = regsub("(>.*)|\n", Tcl_GetString(s), "", NULL); Tcl_SetStringObj(s, s_cstr, strlen(s_cstr)); g_free(s_cstr); s_cstr = NULL; /* Get the length of s. */ code_length = Tcl_GetCharLength(s); /* Process the variants by counting them and printing the results. */ process_variants(cpu_count, s); /* Substitute nucleic acid codes in s with their meanings. */ process_nacodes(cpu_count, s); /* Get the length of s. */ seq_length = Tcl_GetCharLength(s); /* Print the lengths. */ printf("\n%d\n%d\n%d\n", init_length, code_length, seq_length); /* Clean up. */ Tcl_DecrRefCount(s); /* Finalize Tcl. */ Tcl_Release((ClientData)tcl); Tcl_Exit(rv); /* Not reached. */ return rv; }
static void multiple() { char rbuf[BUFSIZ]; char *field[5]; char *scan; int i; regexp *r; errreport = 1; lineno = 0; while (fgets(rbuf, sizeof(rbuf), stdin) != NULL) { rbuf[strlen(rbuf)-1] = '\0'; /* Dispense with \n. */ lineno++; scan = rbuf; for (i = 0; i < 5; i++) { field[i] = scan; if (field[i] == NULL) { complain("bad testfile format", ""); exit(1); } scan = strchr(scan, '\t'); if (scan != NULL) *scan++ = '\0'; } try_func(field); } /* And finish up with some internal testing... */ lineno = 9990; errseen = NULL; if (regcomp((char *)NULL) != NULL || errseen == NULL) complain("regcomp(NULL) doesn't complain", ""); lineno = 9991; errseen = NULL; if (regexec((regexp *)NULL, "foo") || errseen == NULL) complain("regexec(NULL, ...) doesn't complain", ""); lineno = 9992; r = regcomp("foo"); if (r == NULL) { complain("regcomp(\"foo\") fails", ""); return; } lineno = 9993; errseen = NULL; if (regexec(r, (char *)NULL) || errseen == NULL) complain("regexec(..., NULL) doesn't complain", ""); lineno = 9994; errseen = NULL; regsub((regexp *)NULL, "foo", rbuf); if (errseen == NULL) complain("regsub(NULL, ..., ...) doesn't complain", ""); lineno = 9995; errseen = NULL; regsub(r, (char *)NULL, rbuf); if (errseen == NULL) complain("regsub(..., NULL, ...) doesn't complain", ""); lineno = 9996; errseen = NULL; regsub(r, "foo", (char *)NULL); if (errseen == NULL) complain("regsub(..., ..., NULL) doesn't complain", ""); lineno = 9997; errseen = NULL; if (regexec(&badregexp, "foo") || errseen == NULL) complain("regexec(nonsense, ...) doesn't complain", ""); lineno = 9998; errseen = NULL; regsub(&badregexp, "foo", rbuf); if (errseen == NULL) complain("regsub(nonsense, ..., ...) doesn't complain", ""); }
O mods(O a,O b){ L z;S s;C d[BZ];Reprog*p;Resub rs[10];O r,os=pop(top(rst));if(os->t!=TS)TE;s=os->s.s;p=regcomp(a->s.s);if(!p)ex("bad regex");memset(rs,0,sizeof(rs)); for(r=newos("",0);s<os->s.s+os->s.z&®exec(p,s,rs,10);s=rs[0].e.ep,memset(rs,0,sizeof(rs))){if(rs[0].s.sp>s){z=rs[0].s.sp-s;r->s.s=rlc(r->s.s,r->s.z+z);memcpy(r->s.s+r->s.z,s,z);r->s.z+=z;}if(b->s.z==0)continue;regsub(b->s.s,d,BZ,rs,sizeof(rs));z=strlen(d);r->s.s=rlc(r->s.s,r->s.z+z);memcpy(r->s.s+r->s.z,d,z);r->s.z+=z;} if(s<os->s.s+os->s.z){z=os->s.s+os->s.z-s;r->s.s=rlc(r->s.s,r->s.z+z);memcpy(r->s.s+r->s.z,s,z);r->s.z+=z;}r->s.s=rlc(r->s.s,r->s.z+1);r->s.s[r->s.z]=0;dlo(os);DL(p);R r; }
static Node * applyrules(char *target, char *cnt) { Symtab *sym; Node *node; Rule *r; Arc head, *a = &head; Word *w; char stem[NAMEBLOCK], buf[NAMEBLOCK]; Resub rmatch[NREGEXP]; /* print("applyrules(%lux='%s')\n", target, target); */ sym = symlook(target, S_NODE, 0); if(sym) return sym->u.ptr; target = strdup(target); node = newnode(target); head.n = 0; head.next = 0; sym = symlook(target, S_TARGET, 0); memset((char*)rmatch, 0, sizeof(rmatch)); for(r = sym? sym->u.ptr:0; r; r = r->chain){ if(r->attr&META) continue; if(strcmp(target, r->target)) continue; if((!r->recipe || !*r->recipe) && (!r->tail || !r->tail->s || !*r->tail->s)) continue; /* no effect; ignore */ if(cnt[r->rule] >= nreps) continue; cnt[r->rule]++; node->flags |= PROBABLE; /* if(r->attr&VIR) * node->flags |= VIRTUAL; * if(r->attr&NOREC) * node->flags |= NORECIPE; * if(r->attr&DEL) * node->flags |= DELETE; */ if(!r->tail || !r->tail->s || !*r->tail->s) { a->next = newarc((Node *)0, r, "", rmatch); a = a->next; } else for(w = r->tail; w; w = w->next){ a->next = newarc(applyrules(w->s, cnt), r, "", rmatch); a = a->next; } cnt[r->rule]--; head.n = node; } for(r = metarules; r; r = r->next){ if((!r->recipe || !*r->recipe) && (!r->tail || !r->tail->s || !*r->tail->s)) continue; /* no effect; ignore */ if ((r->attr&NOVIRT) && a != &head && (a->r->attr&VIR)) continue; if(r->attr®EXP){ stem[0] = 0; patrule = r; memset((char*)rmatch, 0, sizeof(rmatch)); if(regexec(r->pat, node->name, rmatch, NREGEXP) == 0) continue; } else { if(!match(node->name, r->target, stem, r->shellt)) continue; } if(cnt[r->rule] >= nreps) continue; cnt[r->rule]++; /* if(r->attr&VIR) * node->flags |= VIRTUAL; * if(r->attr&NOREC) * node->flags |= NORECIPE; * if(r->attr&DEL) * node->flags |= DELETE; */ if(!r->tail || !r->tail->s || !*r->tail->s) { a->next = newarc((Node *)0, r, stem, rmatch); a = a->next; } else for(w = r->tail; w; w = w->next){ if(r->attr®EXP) regsub(w->s, buf, sizeof buf, rmatch, NREGEXP); else subst(stem, w->s, buf); a->next = newarc(applyrules(buf, cnt), r, stem, rmatch); a = a->next; } cnt[r->rule]--; } a->next = node->prereqs; node->prereqs = head.next; return(node); }