static really_inline char shengHasAccept(const struct sheng *sh, const struct sstate_aux *aux, ReportID report) { assert(sh && aux); const struct report_list *rl = get_rl(sh, aux); assert(ISALIGNED_N(rl, 4)); DEBUG_PRINTF("report list has %u entries\n", rl->count); for (u32 i = 0; i < rl->count; i++) { if (rl->report[i] == report) { DEBUG_PRINTF("reporting %u\n", rl->report[i]); return 1; } } return 0; }
static really_inline char fireReports(const struct sheng *sh, NfaCallback cb, void *ctxt, const u8 state, u64a loc, u8 *const cached_accept_state, ReportID *const cached_accept_id, char eod) { DEBUG_PRINTF("reporting matches @ %llu\n", loc); if (!eod && state == *cached_accept_state) { DEBUG_PRINTF("reporting %u\n", *cached_accept_id); if (cb(0, loc, *cached_accept_id, ctxt) == MO_HALT_MATCHING) { return MO_HALT_MATCHING; /* termination requested */ } return MO_CONTINUE_MATCHING; /* continue execution */ } const struct sstate_aux *aux = get_aux(sh, state); const struct report_list *rl = eod ? get_eod_rl(sh, aux) : get_rl(sh, aux); assert(ISALIGNED(rl)); DEBUG_PRINTF("report list has %u entries\n", rl->count); u32 count = rl->count; if (!eod && count == 1) { *cached_accept_state = state; *cached_accept_id = rl->report[0]; DEBUG_PRINTF("reporting %u\n", rl->report[0]); if (cb(0, loc, rl->report[0], ctxt) == MO_HALT_MATCHING) { return MO_HALT_MATCHING; /* termination requested */ } return MO_CONTINUE_MATCHING; /* continue execution */ } for (u32 i = 0; i < count; i++) { DEBUG_PRINTF("reporting %u\n", rl->report[i]); if (cb(0, loc, rl->report[i], ctxt) == MO_HALT_MATCHING) { return MO_HALT_MATCHING; /* termination requested */ } } return MO_CONTINUE_MATCHING; /* continue execution */ }
void eval(struct var_struct * p, char * s, int l, int r) { int i,j,n; char op[9]=";, +-*/^E"; char buf[1000]; while(s[l]==' '&&l<=r) l++; while(s[r]==' '&&l<=r) r--; makesure(l<=r,11); while((s[l]=='('&&s[r]==')'&&get_rl(s,r,l)==l)|| (s[l]=='['&&s[r]==']'&&get_rl3(s,r,l)==l)) { l++; r--; while(s[l]==' '&&l<=r) l++; while(s[r]==' '&&l<=r) r--; } if(check_var_name(s+l, r-l+1)||(s[l]=='%'&&check_var_name(s+l+1, r-l))) { strncpy(buf, s+l, 1000); buf[r-l+1]=0; i=get_var(buf); copy_var(vars+i, p); return; } if(check_var_double(s+l, r-l+1)) { double f; strncpy(buf, s+l, 1000); buf[r-l+1]=0; f = atof(buf); set_var(p, f); return; } if(check_var_array(s+l, r-l+1)) { double f1,f2,f3; strncpy(buf, s+l, 1000); buf[r-l+1]=0; i=check_var_array(s+l,r-l+1); if(buf[0]==':'&&!buf[1]) { p->p=0; return; } else if(i==1) { sscanf(buf, "%lf:%lf", &f1, &f2); if(f1<f2) f3=1; else f3=-1; } else { sscanf(buf, "%lf:%lf:%lf", &f1, &f2, &f3); if(fabs(f3)<MINIMUM) { calcerr=17; return; } if((f2-f1)/f3<0) f3=-f3; } if(f3>0) makesize(p, 1, (int)((f2-f1+MINIMUM)/f3)+1); else makesize(p, 1, (int)((f2-f1-MINIMUM)/f3)+1); makesure(1,0); i=0; do{ p->p[0][i]=f1; f1+=f3; i++; if(i>p->width) break; }while((f1-MINIMUM<=f2&&f3>0)||(f1+MINIMUM>=f2&&f3<0)); return; } i=l; while(isalpha(s[i])&&i<=r) i++; if(i>l&&s[i]=='('&&s[r]==')'&&get_rl(s,r,l)==i) { struct var_struct u,v; u.p=0; v.p=0; strncpy(buf, s+l, 1000); buf[i-l]=0; j=0; while(funcname[j][0]) { if(!strncasecmp(funcname[j],buf,10)) break; j++; } if(funcname[j][0]) { eval(&u, s, i+1, r-1); makesure(1,0); take_func(p, &u, j); del(&u); } else { int k; char* kk; j=get_var(buf); strncpy(buf, s+i+1, 1000); buf[r-1-i]=0; kk=strchr(buf, ','); if(!kk) { calcerr=18; return; } k=kk-buf; eval(&u, buf, 0, k-1); makesure(1,0); eval(&v, buf, k+1, strlen(buf)-1); makesure(1,0); selmatrix(vars+j, &u, &v, p); del(&u); del(&v); } return ; } for(j=0;j<9;j++) { n=r; do{ if(toupper(s[n])==op[j]) { struct var_struct m1,m2,m3; m1.p=0; m2.p=0; m3.p=0; if(n>l&&s[n-1]=='.'&&(j==4||j==5||j==6)) eval(&m1,s,l,n-2); else eval(&m1,s,l,n-1); makesure(1,0); eval(&m2,s,n+1,r); makesure(1,0); switch(j) { case 0: link_h(&m1, &m2, p); break; case 1: case 2: link_w(&m1, &m2, p); break; case 3: add_var(&m1, &m2, p); break; case 4: sub_var(&m1, &m2, p); break; case 5: if(n>l&&s[n-1]=='.') domatrix(&m1,&m2,p,4); else mul_var(&m1, &m2, p); break; case 6: if(n>l&&s[n-1]=='.') domatrix(&m1,&m2,p,5); else { inverse(&m3, &m2); mul_var(&m1, &m3, p); del(&m3); } break; case 7: if(n>l&&s[n-1]=='.') domatrix(&m1,&m2,p,6); else { makesure(is_single_var(&m1)&&is_single_var(&m2),12); makesure((**(m1.p))>0,7); set_var(p, exp(log(**(m1.p))*(**(m2.p)))); } break; case 8: makesure(is_single_var(&m1)&&is_single_var(&m2),12); set_var(p, exp(log(10)*(**(m2.p)))*(**m1.p)); break; } del(&m1); del(&m2); return; } if(s[n]==')') n=get_rl(s,n,l); if(s[n]==']') n=get_rl3(s,n,l); n--; }while(n>=l); } if(s[r]=='\'') { struct var_struct m; m.p = 0; eval(&m, s, l, r-1); makesure(1,0); reverse(&m,p); del(&m); return; } calcerr=18; }
static int mv_pcib_ofw_bus_attach(device_t dev) { struct mv_pcib_ctrl_devinfo *di; struct mv_pcib_ctrl_softc *sc; device_t child; phandle_t parent, node; get_rl_t get_rl; parent = ofw_bus_get_node(dev); sc = device_get_softc(dev); if (parent > 0) { sc->addr_cells = 1; if (OF_getencprop(parent, "#address-cells", &(sc->addr_cells), sizeof(sc->addr_cells)) <= 0) return(ENXIO); sc->size_cells = 1; if (OF_getencprop(parent, "#size-cells", &(sc->size_cells), sizeof(sc->size_cells)) <= 0) return(ENXIO); for (node = OF_child(parent); node > 0; node = OF_peer(node)) { di = malloc(sizeof(*di), M_PCIB_CTRL, M_WAITOK | M_ZERO); if (ofw_bus_gen_setup_devinfo(&di->di_dinfo, node)) { if (bootverbose) { device_printf(dev, "Could not set up devinfo for PCI\n"); } free(di, M_PCIB_CTRL); continue; } child = device_add_child(dev, NULL, -1); if (child == NULL) { if (bootverbose) { device_printf(dev, "Could not add child: %s\n", di->di_dinfo.obd_name); } ofw_bus_gen_destroy_devinfo(&di->di_dinfo); free(di, M_PCIB_CTRL); continue; } resource_list_init(&di->di_rl); get_rl = (get_rl_t) ofw_bus_search_compatible(dev, mv_pcib_ctrl_compat)->ocd_data; if (get_rl != NULL) get_rl(child, node, sc->addr_cells, sc->size_cells, &di->di_rl); device_set_ivars(child, di); } } if (mv_pcib_ctrl_fill_ranges(parent, sc) < 0) { device_printf(dev, "could not get ranges\n"); return (ENXIO); } return (0); }
static void feval(struct fvar_struct * p, char * s, int l, int r) { int i,j,n; char op[14][4]={"||","&&","==","!=",">=","<=",">","<","+","-","*","/","%","<<"}; char op2[14][10]={"或","且","是","不是","大等于","小等于","大于","小于","加","减","乘","除","模", "包含"}; char buf[1000]; while(s[l]==' '&&l<=r) l++; while(s[r]==' '&&l<=r) r--; fmakesure(l<=r,11); while(s[l]=='('&&s[r]==')'&&get_rl(s,r,l)==l) { l++; r--; while(s[l]==' '&&l<=r) l++; while(s[r]==' '&&l<=r) r--; } if(fcheck_var_name(s+l, r-l+1)) { strncpy(buf, s+l, 1000); buf[r-l+1]=0; if(fexist_var(buf)!=-1) { i=fget_var(buf); p->num = fvars[i].num; p->s = fvars[i].s; p->p = fvars[i].p; return; } } if(check_var_int(s+l, r-l+1)) { int f; strncpy(buf, s+l, 1000); buf[r-l+1]=0; f = atoi(buf); set_vard(p, f); return; } if((s[l]=='\''||s[l]=='"')&&(s[r]=='\''||s[r]=='"')&&get_rl2(s,r,l)==l) { fmakesure(r-l+libptr<libs+LIBLEN,4); strncpy(libptr, s+l+1, r-l-1); libptr[r-l-1]=0; p->num=false; p->p=libptr; libptr+=r-l; return; } i=l; while(isalpha(s[i])&&i<=r) i++; if(i>l&&s[i]=='('&&s[r]==')'&&get_rl(s,r,l)==i) { struct fvar_struct u,v,w; u.p=0; v.p=0; w.p=0; strncpy(buf, s+l, 1000); buf[i-l]=0; if(!strcmp("sub",buf)) { int j=strchr(s+i+1, ',')-s; char * res; fmakesure(strchr(s+i+1, ',')!=NULL, 2); fmakesure(strchr(s+i+1, ',')<=s+r, 2); feval(&u, s, i+1, j-1); fmakesure(!u.num&&u.p, 2); feval(&v, s, j+1, r-1); fmakesure(!v.num&&v.p, 2); p->num=true; res = bm_strcasestr(v.p, u.p); if(res==NULL) p->s=0; else p->s=res-v.p+1; return; } else if(!strcmp("len",buf)){ feval(&u, s, i+1, r-1); fmakesure(!u.num&&u.p, 3); p->num=true; p->s = strlen(u.p); return; } else if(!strcmp("date",buf)){ int j=strchr(s+i+1, ',')-s, k; struct tm t; fmakesure(strchr(s+i+1, ',')!=NULL, 4); fmakesure(strchr(s+i+1, ',')<=s+r, 4); fmakesure(strchr(s+j+1, ',')!=NULL, 4); fmakesure(strchr(s+j+1, ',')<=s+r, 4); k=strchr(s+j+1, ',')-s; feval(&u, s, i+1, j-1); fmakesure(u.num, 4); feval(&v, s, j+1, k-1); fmakesure(v.num, 4); feval(&w, s, k+1, r-1); fmakesure(w.num, 4); p->num=true; t.tm_sec=0; t.tm_min=0; t.tm_hour=0; t.tm_mday=w.s; t.tm_mon=v.s-1; t.tm_year=u.s-1900; p->s = mktime(&t); return; } else if(!strcmp("today",buf)){ struct tm t; time_t tt; p->num=true; tt=time(0); gmtime_r(&tt, &t); t.tm_sec=0; t.tm_min=0; t.tm_hour=0; p->s = mktime(&t); return; } else if(!strcmp("time",buf)){ int j=strchr(s+i+1, ',')-s, k; fmakesure(strchr(s+i+1, ',')!=NULL, 4); fmakesure(strchr(s+i+1, ',')<=s+r, 4); fmakesure(strchr(s+j+1, ',')!=NULL, 4); fmakesure(strchr(s+j+1, ',')<=s+r, 4); k=strchr(s+j+1, ',')-s; feval(&u, s, i+1, j-1); fmakesure(u.num, 4); feval(&v, s, j+1, k-1); fmakesure(v.num, 4); feval(&w, s, k+1, r-1); fmakesure(w.num, 4); p->num=true; p->s = (u.s*60+v.s)*60+w.s; return; } ferr=18; return ; } for(j=0;j<14;j++) { n=r; do{ if((n+strlen(op[j])<=r&&!strncmp(s+n, op[j], strlen(op[j]))) ||(n+strlen(op2[j])<=r&&!strncmp(s+n, op2[j], strlen(op2[j])))) { struct fvar_struct m1,m2,m3; char * res; m1.p=0; m2.p=0; m3.p=0; feval(&m1,s,l,n-1); if(j==2||j==3) {fmakesure(m1.num||(!m1.num&&m1.p),1);} else if(j==13) {fmakesure(!m1.num,1);} else {fmakesure(m1.num,1);} if(!strncmp(s+n, op[j], strlen(op[j]))) feval(&m2,s,n+strlen(op[j]),r); else feval(&m2,s,n+strlen(op2[j]),r); if(j==2||j==3) {fmakesure((m1.num&&m2.num)||(!m1.num&&!m2.num&&m2.p),1);} else if(j==13) {fmakesure(!m2.num,1);} else {fmakesure(m2.num,1);} p->num=true; switch(j) { case 0: p->s=m1.s||m2.s; break; case 1: p->s=m1.s&&m2.s; break; case 2: if(m1.num) p->s=m1.s==m2.s; else p->s=!strcasecmp(m1.p,m2.p); break; case 3: if(m1.num) p->s=m1.s!=m2.s; else p->s=strcasecmp(m1.p,m2.p); break; case 4: p->s=m1.s>=m2.s; break; case 5: p->s=m1.s<=m2.s; break; case 6: p->s=m1.s>m2.s; break; case 7: p->s=m1.s<m2.s; break; case 8: p->s=m1.s+m2.s; break; case 9: p->s=m1.s-m2.s; break; case 10: p->s=m1.s*m2.s; break; case 11: fmakesure(m2.s!=0, 6); p->s=m1.s/m2.s; break; case 12: fmakesure(m2.s!=0, 6); p->s=m1.s%m2.s; break; case 13: res = bm_strcasestr(m1.p, m2.p); if(res==NULL) p->s=0; else p->s=res-m1.p+1; break; } return; } if(s[n]==')') n=get_rl(s,n,l); if(s[n]=='\'') {n--;while(n>=l&&s[n]!='\'') n--;} if(s[n]=='"') {n--;while(n>=l&&s[n]!='"') n--;} n--; }while(n>=l); } if (r-l>=6&&!strncmp("的长度", s+r-5, 6)) { struct fvar_struct u; u.p = 0; feval(&u, s, l, r-6); fmakesure(!u.num&&u.p, 3); p->num=true; p->s = strlen(u.p); return; } if(s[l]=='!') { struct fvar_struct m; m.p = 0; feval(&m, s, l+1, r); fmakesure(m.num,1); p->num=true; p->s=!m.s; return; } if(!strncmp(s+l,"没有",4)) { struct fvar_struct m; m.p = 0; feval(&m, s, l+4, r); fmakesure(m.num,1); p->num=true; p->s=!m.s; return; } fmakesure(r-l+2+libptr<libs+LIBLEN,4); strncpy(libptr, s+l, r-l+1); libptr[r-l+1]=0; p->num=false; p->p=libptr; libptr+=r-l+2; }