Tree consttree(unsigned n, Type ty) { if (isarray(ty)) ty = atop(ty); else assert(isint(ty)); return cnsttree(ty, (unsigned long)n); }
BOOLEAN isarithmetic(TYPE *tp) { tp = basetype(tp); return isint(tp) || isfloat(tp) || iscomplex(tp) || isimaginary(tp); }
Tree call(Tree f, Type fty, Coordinate src) { int n = 0; Tree args = NULL, r = NULL, e; Type *proto, rty = unqual(freturn(fty)); Symbol t3 = NULL; if (fty->u.f.oldstyle) proto = NULL; else proto = fty->u.f.proto; if (hascall(f)) r = f; if (isstruct(rty)) { t3 = temporary(AUTO, unqual(rty)); if (rty->size == 0) error("illegal use of incomplete type `%t'\n", rty); } if (t != ')') for (;;) { Tree q = pointer(expr1(0)); if (proto && *proto && *proto != voidtype) { Type aty; q = value(q); aty = assign(*proto, q); if (aty) q = cast(q, aty); else error("type error in argument %d to %s; found `%t' expected `%t'\n", n + 1, funcname(f), q->type, *proto); if ((isint(q->type) || isenum(q->type)) && q->type->size != inttype->size) q = cast(q, promote(q->type)); ++proto; } else { if (!fty->u.f.oldstyle && *proto == NULL) error("too many arguments to %s\n", funcname(f)); q = value(q); if (isarray(q->type) || q->type->size == 0) error("type error in argument %d to %s; `%t' is illegal\n", n + 1, funcname(f), q->type); else q = cast(q, promote(q->type)); } if (!IR->wants_argb && isstruct(q->type)) if (iscallb(q)) q = addrof(q); else { Symbol t1 = temporary(AUTO, unqual(q->type)); q = asgn(t1, q); q = tree(RIGHT, ptr(t1->type), root(q), lvalue(idtree(t1))); } if (q->type->size == 0) q->type = inttype; if (hascall(q)) r = r ? tree(RIGHT, voidtype, r, q) : q; args = tree(mkop(ARG, q->type), q->type, q, args); n++; if (Aflag >= 2 && n == 32) warning("more than 31 arguments in a call to %s\n", funcname(f)); if (t != ',') break; t = gettok(); } expect(')'); if (proto && *proto && *proto != voidtype) error("insufficient number of arguments to %s\n", funcname(f)); if (r) args = tree(RIGHT, voidtype, r, args); e = calltree(f, rty, args, t3); if (events.calls) apply(events.calls, &src, &e); return e; }
void statement(int loop, Swtch swp, int lev) { float ref = refinc; if (Aflag >= 2 && lev == 15) warning("more than 15 levels of nested statements\n"); switch (t) { case IF: ifstmt(genlabel(2), loop, swp, lev + 1); break; case WHILE: whilestmt(genlabel(3), swp, lev + 1); break; case DO: dostmt(genlabel(3), swp, lev + 1); expect(';'); break; case FOR: forstmt(genlabel(4), swp, lev + 1); break; case BREAK: walk(NULL, 0, 0); definept(NULL); if (swp && swp->lab > loop) branch(swp->lab + 1); else if (loop) branch(loop + 2); else error("illegal break statement\n"); t = gettok(); expect(';'); break; case CONTINUE: walk(NULL, 0, 0); definept(NULL); if (loop) branch(loop + 1); else error("illegal continue statement\n"); t = gettok(); expect(';'); break; case SWITCH: swstmt(loop, genlabel(2), lev + 1); break; case CASE: { int lab = genlabel(1); if (swp == NULL) error("illegal case label\n"); definelab(lab); while (t == CASE) { static char stop[] = { IF, ID, 0 }; Tree p; t = gettok(); p = constexpr(0); if (generic(p->op) == CNST && isint(p->type)) { if (swp) { needconst++; p = cast(p, swp->sym->type); if (p->type->op == UNSIGNED) p->u.v.i = extend(p->u.v.u, p->type); needconst--; caselabel(swp, p->u.v.i, lab); } } else error("case label must be a constant integer expression\n"); test(':', stop); } statement(loop, swp, lev); } break; case DEFAULT: if (swp == NULL) error("illegal default label\n"); else if (swp->deflab) error("extra default label\n"); else { swp->deflab = findlabel(swp->lab); definelab(swp->deflab->u.l.label); } t = gettok(); expect(':'); statement(loop, swp, lev); break; case RETURN: { Type rty = freturn(cfunc->type); t = gettok(); definept(NULL); if (t != ';') if (rty == voidtype) { error("extraneous return value\n"); expr(0); retcode(NULL); } else retcode(expr(0)); else { if (rty != voidtype) { warning("missing return value\n"); retcode(cnsttree(inttype, 0L)); } else retcode(NULL); } branch(cfunc->u.f.label); } expect(';'); break; case '{': compound(loop, swp, lev + 1); break; case ';': definept(NULL); t = gettok(); break; case GOTO: walk(NULL, 0, 0); definept(NULL); t = gettok(); if (t == ID) { Symbol p = lookup(token, stmtlabs); if (p == NULL) { p = install(token, &stmtlabs, 0, FUNC); p->scope = LABELS; p->u.l.label = genlabel(1); p->src = src; } use(p, src); branch(p->u.l.label); t = gettok(); } else error("missing label in goto\n"); expect(';'); break; case ID: if (getchr() == ':') { stmtlabel(); statement(loop, swp, lev); break; } default: definept(NULL); if (kind[t] != ID) { error("unrecognized statement\n"); t = gettok(); } else { Tree e = expr0(0); listnodes(e, 0, 0); if (nodecount == 0 || nodecount > 200) walk(NULL, 0, 0); else if (glevel) walk(NULL, 0, 0); deallocate(STMT); } expect(';'); break; } if (kind[t] != IF && kind[t] != ID && t != '}' && t != EOI) { static char stop[] = { IF, ID, '}', 0 }; error("illegal statement termination\n"); skipto(0, stop); } refinc = ref; }
cmd_result_t iprocwrite_cmd(int unit, args_t *args) { cmd_result_t rv = CMD_OK; parse_table_t pt; char *c, *filename = NULL; int ce = 0; uint32 addr = 0; #ifndef NO_FILEIO #ifndef NO_CTRL_C jmp_buf ctrl_c; #endif FILE * volatile fp = NULL; #endif if (ARG_CNT(args) < 1) { return(CMD_USAGE); } parse_table_init(unit, &pt); parse_table_add(&pt, "ChangeEndian", PQ_DFL|PQ_BOOL, 0, &ce, NULL); if (parse_arg_eq(args, &pt) < 0) { printk("%s: Error: Unknown option: %s\n", ARG_CMD(args), ARG_CUR(args)); parse_arg_eq_done(&pt); return(CMD_USAGE); } c = ARG_GET(args); if (!isint(c)) { printk("%s: Error: Address not specified\n", ARG_CMD(args)); return(CMD_USAGE); } addr = parse_address(c); if (ARG_CNT(args) <= 0) { printk("%s: Error: Data / Filename not specified\n", ARG_CMD(args)); return(CMD_USAGE); } c = ARG_GET(args); if (!isint(c)) { filename = c; } if (filename == NULL) { ARG_PREV(args); rv = _iproc_write_from_args(unit, ce, addr, args); } else { #ifdef NO_FILEIO printk("no filesystem\n"); #else /* Read from file */ #ifndef NO_CTRL_C if (!setjmp(ctrl_c)) { sh_push_ctrl_c(&ctrl_c); #endif fp = sal_fopen(filename, "r"); if (!fp) { printk("%s: Error: Unable to open file: %s\n", ARG_CMD(args), filename); rv = CMD_FAIL; #ifndef NO_CTRL_C sh_pop_ctrl_c(); #endif return(rv); } else { rv = _iproc_write_from_bin_file(unit, ce, addr, fp); sal_fclose((FILE *)fp); fp = NULL; } #ifndef NO_CTRL_C } else if (fp) { sal_fclose((FILE *)fp); fp = NULL; rv = CMD_INTR; } sh_pop_ctrl_c(); #endif #endif } return(rv); }
int main(int argc,char *argv[]) { FILE *in,*out; char *infile=NULL,*outfile=NULL,*tmpfile=NULL,*copt,*ptr,*gsexec,buf[21]; char command[MAX_IN],ch[MAX_IN],*BBname,*device,ropt[20],*gsopt; double bbllx,bblly,bburx,bbury,xoffset,yoffset,enlarge; int width,height,res,xpix,ypix; int i,count,status,BBCorrected,did_CR,debug,compress,usegs,wait, BBhires,BBexact,found,depth,filter,ngsopt; int doseps; unsigned long dosepsbegin, dosepsend, pos; unsigned int c; fpos_t fpos; #if defined (__EMX__) _wildcard (&argc, &argv); #endif /* default parameter */ status=0; BBCorrected=0; BBhires=0; BBexact=0; debug=0; compress=1; usegs=1; gsexec=GSEXEC; wait=0; filter=0; enlarge=0.; res=600; device="pdfwrite"; xpix=0; ypix=0; ngsopt=100; gsopt=malloc(ngsopt); gsopt[0]='\0'; /****************************************************************** Process command line options ******************************************************************/ for(i=1;i<argc;i++){ /* printf("i=%d arg=>>%s<<\n",i,argv[i]); */ if(!strcmp(argv[i],"--help") || !strcmp(argv[i],"-h")){ usage(); status=0; goto EXIT; } if(!strcmp(argv[i],"--debug") || !strcmp(argv[i],"-d")){ debug=1; continue; } if(!strcmp(argv[i],"--nodebug")){ debug=0; continue; } if(!strcmp(argv[i],"--compress") || !strcmp(argv[i],"-c")){ compress=1; continue; } if(!strcmp(argv[i],"--nocompress")){ compress=0; continue; } if(!strcmp(argv[i],"--nogs")){ usegs=0; continue; } if(!strcmp(argv[i],"--gs")){ usegs=1; continue; } if(!strcmp(argv[i],"--wait") || !strcmp(argv[i],"-w")){ wait=1; continue; } if(!strcmp(argv[i],"--nowait")){ wait=0; continue; } if(!strcmp(argv[i],"--filter")){ filter=1; continue; } if(!strcmp(argv[i],"--nofilter")){ filter=0; continue; } if(!strcmp(argv[i],"--hires")){ BBhires=1; continue; } if(!strcmp(argv[i],"--nohires")){ BBhires=0; continue; } if(!strcmp(argv[i],"--exact")){ BBexact=1; continue; } if(!strcmp(argv[i],"--noexact")){ BBexact=0; continue; } if(!strncmp(argv[i],"--outfile=",strlen("--outfile="))){ outfile=malloc(strlen(argv[i])-strlen("--outfile=")+1); strcpy(outfile, argv[i]+strlen("--outfile=")); continue; } if(!strncmp(argv[i],"--tmpfile=",strlen("--tmpfile="))){ tmpfile=malloc(strlen(argv[i])-strlen("--tmpfile=")+1); strcpy(tmpfile, argv[i]+strlen("--tmpfile=")); continue; } if(!strncmp(argv[i],"-r",strlen("-r"))){ sscanf(argv[i]+strlen("-r"),"%d",&res); continue; } if(!strncmp(argv[i],"--width=",strlen("--width="))){ sscanf(argv[i]+strlen("--width="),"%d",&xpix); continue; } if(!strncmp(argv[i],"--height=",strlen("--height="))){ sscanf(argv[i]+strlen("--height="),"%d",&ypix); continue; } if(!strncmp(argv[i],"--gsopt=",strlen("--gsopt="))){ char *opt=argv[i]+strlen("--gsopt="); if(strlen(gsopt)+strlen(opt)+2 < ngsopt){ ngsopt+=100; gsopt=realloc(gsopt,ngsopt); } strcat(gsopt," "); strcat(gsopt,opt); continue; } if(!strncmp(argv[i],"-sDEVICE=",strlen("-sDEVICE="))){ device=argv[i]+strlen("-sDEVICE="); continue; } if(!strcmp(argv[i],"-o") && i+1<argc){ outfile=malloc(strlen(argv[i+1])+1); strcpy(outfile, argv[i+1]); i++; continue; } if(!strncmp(argv[i],"--gsexec=",strlen("--gsexec="))){ gsexec=argv[i]+strlen("--gsexec="); continue; } if(argv[i][0]!='-'){ if(infile) printf("\nCan process only one input file\n"); else infile=argv[i]; continue; } if(!strncmp(argv[i],"--enlarge=",strlen("--enlarge="))){ sscanf(argv[i]+strlen("--enlarge="),"%lf",&enlarge); continue; } usage(); fprintf(stderr,"\nunknown option >>%s<<\n",argv[i]); status=1; goto EXIT; } /****************************************************************** check arguments and files ******************************************************************/ if(filter) debug=0; if(filter) wait =0; if(BBexact && BBhires){ fprintf(stderr,"\nOptions --hires and --exact cannot be used together\n"); status=1; goto EXIT; } if (BBexact) BBname="%%ExactBoundingBox:"; else if(BBhires) BBname="%%HiresBoundingBox:"; else BBname="%%BoundingBox:"; if(!filter) { if(!infile) { usage(); fprintf(stderr,"no input file specified!\n"); status=1; goto EXIT; } if((in=fopen(infile,"rb")) == NULL) { usage(); fprintf(stderr,"%s: File not found!\n",infile); status=1; goto EXIT; } fclose(in); }else{ if(infile) { fprintf(stderr,"Input file cannot be used with filter option!\n"); status=1; goto EXIT; } infile="epstopdf"; /* dummy input filename to generate tmp-filename */ } /* find a temporary filename that does not exist yet */ if(usegs && !tmpfile){ tmpfile=malloc(strlen(infile)+9); count=0; do{ if(count>99) { fprintf(stderr,"No temporary file available! Try deleting *.tmp.\n\n"); status=1; goto EXIT; } sprintf(tmpfile,"%s.%d.tmp",infile,count); if(debug) printf("checking temporary filename >>%s<<\n",tmpfile); out=fopen(tmpfile,"rb"); if(out) fclose(out); count++; }while(out); } if(!filter){ if(!outfile){ outfile=malloc(strlen(infile)+6); strcpy(outfile,infile); ptr=outfile; while(strpbrk(ptr,"\\/")) ptr=strpbrk(ptr,"\\/")+1; ptr=strrchr(ptr,'.'); if(ptr) *ptr='\0'; if(usegs) strcat(outfile,".pdf"); else strcat(outfile,"2.eps"); } }else{ if(outfile) { fprintf(stderr,"Output file cannot be used with filter option!\n"); status=1; goto EXIT; } outfile=malloc(2); strcpy(outfile,"-"); } if(!filter) printf("Converting %s to %s ..... ",infile,outfile); /****************************************************************** put the pagesize from the bounding box into the eps file ******************************************************************/ if(debug) printf("\nAdding correct pagesize to EPS ... searching for %s ...\n",BBname); if (!filter) in = fopen(infile, "rb"); else { in = stdin; setmode(fileno(stdin), O_BINARY); } if (usegs) out = fopen(tmpfile,"wb"); else if(!filter) out = fopen(outfile,"wb"); else { out = stdout; setmode(fileno(stdout), O_BINARY); } if(!in || !out){ fprintf(stderr,"cannot open files\n"); status=1; goto EXIT; } depth=0; doseps = dosepsbegin = dosepsend = 0; c = getc(in); if (c == 'E'+0x80) { if ((getc(in)=='P'+0x80) && (getc(in)=='S'+0x80) && (getc(in)=='F'+0x80)) { doseps = 1; dosepsbegin = getc(in) ; dosepsbegin += getc(in) * 256L ; dosepsbegin += getc(in) * 65536L ; dosepsbegin += getc(in) * 256L * 65536 ; dosepsend = getc(in) ; dosepsend += getc(in) * 256L ; dosepsend += getc(in) * 65536L ; dosepsend += getc(in) * 256L * 65536 ; fseek(in, dosepsbegin, 0); c = getc(in); dosepsend-- ; } } rewind(in); if (doseps) fseek(in, dosepsbegin, SEEK_SET); pos = dosepsbegin; while (fgets(ch,MAX_IN,in)) { if (doseps && ftell(in) > dosepsend + dosepsbegin) { ch[dosepsend + dosepsbegin - pos ] = '\0'; fputs(ch, out); fputc('\n', out); break; } pos = ftell(in); if(!strncmp(ch,BEGINDOC,strlen(BEGINDOC))) depth++; /* count included documents */ if(!strncmp(ch,ENDDOC, strlen(ENDDOC) )) depth--; if(!strncmp(ch,BBname, strlen(BBname)) && depth==0) { /* look for BB comment in main doc only */ sscanf(ch,"%*s %20s",buf); if(!strcmp(buf,"(atend)")){ /* BB is atended */ if(filter){ fprintf(stderr,"Cannot look for BoundingBox in the trailer " "with option --filter\n"); if(usegs) remove(tmpfile); status=1; goto EXIT; } if(debug) printf("\n (atend)! ...\n"); fgetpos(in, &fpos); /* store file position */ found=0; while (fgets(ch,MAX_IN,in)){ if(!strncmp(ch,BEGINDOC,strlen(BEGINDOC))) depth++; /* count included documents */ if(!strncmp(ch,ENDDOC, strlen(ENDDOC) )) depth--; if(!strncmp(ch,BBname,strlen(BBname)) && depth==0) { /* look for bounding box in main doc only */ found=1; fsetpos(in, &fpos); /* rewind to (atend) comment */ break; } } if(!found){ fprintf(stderr,"atended %s not found\n",BBname); if(usegs && !debug) remove(tmpfile); if(!usegs && !debug) remove(outfile); status=1; goto EXIT; } } /* No Idea what ExactBoundingBox means. Hope it also works with this code */ /* I thought Postscript says that the bounding box should be integer. However, some applications (like Corel Draw) use floats and gs has no problem with it. So I use floats for translate that will result in a more exact box. Since gs seems not to be able to use floats in setpagedevice, these values are converted to integer */ if(!BBCorrected){ /* write Bounding box one time only! */ if(sscanf(ch,"%*s %lf %lf %lf %lf",&bbllx,&bblly,&bburx,&bbury)!=4){ fprintf(stderr,"incorrect %s \n",BBname); if(usegs && !debug) remove(tmpfile); status=1; goto EXIT; } if(debug) printf("BoundingBox: %f %f %f %f\n",bbllx,bblly,bburx,bbury); bblly -= enlarge; bbllx -= enlarge; bbury += enlarge; bburx += enlarge; width = ceil(bburx-bbllx); /* make papersize integer and enlarge it a little bit */ height = ceil(bbury-bblly); xoffset =-bbllx; yoffset =-bblly; fprintf(out,"%s %d %d %d %d\n",BBname,0,0,width,height); fprintf(out,"<< /PageSize [%d %d] >> setpagedevice \n",width,height); if(isint(xoffset) && isint(yoffset)) fprintf(out,"gsave %d %d translate\n",round(xoffset),round(yoffset)); else fprintf(out,"gsave %f %f translate\n",xoffset,yoffset); if(!filter) printf(" (%dx%d mm) ... ",(int)(25.4/72.*width),(int)(25.4/72.*height)); did_CR=1; BBCorrected=1; } }else{ fputs(ch,out); if(strpbrk(ch, "\n")) did_CR=1; else did_CR=0; } } if(BBCorrected){ if(!did_CR) fprintf(out,"\ngrestore\n"); else fprintf(out, "grestore\n"); } if(in !=stdin ) fclose(in); if(out!=stdout) fclose(out); if(width && height){ if (xpix) res=(72*xpix)/width; else if (ypix) res=(72*ypix)/height; } /****************************************************************** do the conversion eps->pdf using gs ******************************************************************/ if(usegs){ #ifdef FPTEX char stemp[512]; char *gs_argv[] = { NULL, /* 0 gsexec */ "-q", "-dNOPAUSE", "-dBATCH", NULL, /* 4 copt */ NULL, /* 5 device */ NULL, /* 6 ropt */ NULL, /* 7 gsopt */ NULL, /* 8 outfile */ /* "-", "-c", "quit", "-f", */ NULL /* 9 tmpfile */, NULL }; int gs_argc = sizeof(gs_argv)/sizeof(gs_argv[0]); gs_argv[0] = gsexec; if(compress) gs_argv[4]="-dUseFlateCompression=true"; else gs_argv[4]="-dUseFlateCompression=false"; if(res) sprintf(ropt,"-r%d",res); else ropt[0]='\0'; if(res && debug) printf(" (%d dpi) ... ",res); sprintf(stemp, "-sDEVICE=%s", device); gs_argv[5] = xstrdup(stemp); gs_argv[6] = ropt; if (gsopt && *gsopt) { gs_argv[7] = gsopt; sprintf(stemp, "-sOutputFile=%s", outfile); gs_argv[8] = xstrdup(stemp); sprintf(stemp, "%s", tmpfile); gs_argv[9] = xstrdup(stemp); } else { sprintf(stemp, "-sOutputFile=%s", outfile); gs_argv[7] = xstrdup(stemp); sprintf(stemp, "%s", tmpfile); gs_argv[8] = xstrdup(stemp); gs_argc--; } if(debug) { int i; printf("running ghostscript ...\n"); for (i = 0; i < gs_argc - 1; i++) fprintf(stderr, "gs_argv[%d] = %s\n", i, gs_argv[i]); } if (gs_locate() == NULL) { fprintf(stderr, "\nCan't locate Ghostscript ! Exiting ...\n"); return EXIT_FAILURE; } if (!gs_dll_initialize()) { fprintf(stderr, "Can't initialize ghostscript, exiting ...\n"); return EXIT_FAILURE; } if ((status = (*pgsdll_init)(gsdll_callback, NULL, gs_argc - 1, gs_argv)) == 0) { /* Should not happen : gs should quit right after being initialized. */ /* fprintf(stderr, "gs exited quickly.\n"); */ (*pgsdll_exit)(); } if (status != 0 && status != GSDLL_INIT_QUIT) fprintf(stderr, "gsdll_init returned %d\n", status); gs_dll_release(); free(gs_argv[5]); #if 1 if(!debug) remove(tmpfile); else printf("keeping temporary file >>%s<<\n",tmpfile); #else remove(tmpfile); #endif #else if(compress) copt="-dUseFlateCompression=true"; else copt="-dUseFlateCompression=false"; if(res) sprintf(ropt,"-r%d",res); else ropt[0]='\0'; if(res && debug) printf(" (%d dpi) ... ",res); sprintf(command,"%s -q -dNOPAUSE -dBATCH %s -sDEVICE=%s %s %s" " \"-sOutputFile=%s\" -c save pop -f \"%s\"", gsexec,copt,device,ropt,gsopt,outfile,tmpfile); if(debug) printf("running ghostscript ...\n"); if(debug) puts(command); status=system(command); if(!debug) remove(tmpfile); else printf("keeping temporary file >>%s<<\n",tmpfile); #endif /* ! FPTEX */ } if(!filter) printf("Done\n"); EXIT: free(outfile); free(tmpfile); free(gsopt); if(wait){ printf("\n<Press a key> "); getchar(); printf("\n"); } return status; }
cmd_result_t cmd_knet_ctrl(int unit, args_t *args) { parse_table_t pt; char *subcmd; int rv; int idx, pdx, count; int if_id; int if_type; int if_vlan; int if_port; int if_addtag; int if_rcpu; char *if_name; int pf_id; int pf_prio; int pf_dest_type; int pf_dest_id; int pf_striptag; int pf_mirror; int pf_mirror_id; int pf_vlan; int pf_ingport; int pf_src_modport; int pf_src_modid; int pf_reason; int pf_fp_rule; char *pf_desc; uint32 pkt_offset; int pkt_data[8]; bcm_knet_netif_t netif; bcm_knet_filter_t filter; int pf_dest_proto; int pf_mirror_proto; if ((subcmd = ARG_GET(args)) == NULL) { cli_out("Requires string argument\n"); return CMD_USAGE; } if (sal_strcasecmp(subcmd, "netif") == 0) { if ((subcmd = ARG_GET(args)) == NULL) { cli_out("Requires additional string argument\n"); return CMD_USAGE; } if (sal_strcasecmp(subcmd, "create") == 0) { if_type = BCM_KNET_NETIF_T_TX_CPU_INGRESS; if_vlan = 1; if_port = -1; if_addtag = 0; if_rcpu = 0; if_name = NULL; parse_table_init(unit, &pt); parse_table_add(&pt, "Type", PQ_DFL|PQ_MULTI, 0, &if_type, netif_type); parse_table_add(&pt, "Vlan", PQ_DFL|PQ_INT, 0, &if_vlan, 0); parse_table_add(&pt, "Port", PQ_DFL|PQ_PORT, 0, &if_port, 0); parse_table_add(&pt, "AddTag", PQ_DFL|PQ_BOOL, 0, &if_addtag, 0); parse_table_add(&pt, "RCPU", PQ_DFL|PQ_BOOL, 0, &if_rcpu, 0); parse_table_add(&pt, "IFName", PQ_DFL|PQ_STRING, 0, &if_name, 0); if (parse_arg_eq(args, &pt) < 0) { parse_arg_eq_done(&pt); return CMD_USAGE; } bcm_knet_netif_t_init(&netif); if (if_name) { sal_strncpy(netif.name, if_name, sizeof(netif.name) - 1); } parse_arg_eq_done(&pt); /* Force port mode if port was specified */ if (if_port >= 0) { if_type = BCM_KNET_NETIF_T_TX_LOCAL_PORT; } /* Force meta mode if RCPU was specified */ if (if_rcpu) { if_type = BCM_KNET_NETIF_T_TX_META_DATA; } netif.type = if_type; netif.vlan = if_vlan; if (if_port >= 0) { netif.port = if_port; } if (if_addtag) { netif.flags |= BCM_KNET_NETIF_F_ADD_TAG; } if (if_rcpu) { netif.flags |= BCM_KNET_NETIF_F_RCPU_ENCAP; } if ((rv = bcm_knet_netif_create(unit, &netif)) < 0) { cli_out("Error creating network interface: %s\n", bcm_errmsg(rv)); return CMD_FAIL; } _show_netif(unit, &netif); } else if (sal_strcasecmp(subcmd, "destroy") == 0) { if (!ARG_CNT(args) || !isint(ARG_CUR(args))) { return(CMD_USAGE); } if_id = parse_integer(ARG_GET(args)); if ((rv = bcm_knet_netif_destroy(unit, if_id)) < 0) { cli_out("Error destroying network interface: %s\n", bcm_errmsg(rv)); return CMD_FAIL; } } else if (sal_strcasecmp(subcmd, "show") == 0) { count = 0; if (bcm_knet_netif_traverse(unit, _trav_netif, &count) < 0) { return CMD_FAIL; } if (count == 0) { cli_out("<no network interfaces>\n"); } } else { cli_out("Subcommand not found: %s\n", subcmd); return CMD_USAGE; } } else if (sal_strcasecmp(subcmd, "filter") == 0) { if ((subcmd = ARG_GET(args)) == NULL) { cli_out("Requires string argument\n"); return CMD_USAGE; } if (sal_strcasecmp(subcmd, "create") == 0) { pf_dest_type = -1; pf_dest_id = -1; pf_mirror = 0; pf_mirror_id = 0; pf_vlan = -1; pf_ingport = -1; pf_src_modport = -1; pf_src_modid = -1; pf_reason = -1; pf_fp_rule = -1; pkt_offset = 0; for (idx = 0; idx < COUNTOF(pkt_data); idx++) { pkt_data[idx] = -1; } pf_desc = NULL; pf_prio = 0; pf_striptag = 1; pf_dest_proto = 0; pf_mirror_proto = 0; parse_table_init(unit, &pt); parse_table_add(&pt, "DestType", PQ_DFL|PQ_MULTI, 0, &pf_dest_type, filter_dest_type); parse_table_add(&pt, "DestID", PQ_DFL|PQ_INT, 0, &pf_dest_id, 0); parse_table_add(&pt, "PRIOrity", PQ_DFL|PQ_INT, 0, &pf_prio, 0); parse_table_add(&pt, "DESCription", PQ_DFL|PQ_STRING, 0, &pf_desc, 0); parse_table_add(&pt, "StripTag", PQ_DFL|PQ_BOOL, 0, &pf_striptag, 0); parse_table_add(&pt, "Mirror", PQ_DFL|PQ_BOOL, 0, &pf_mirror, 0); parse_table_add(&pt, "MirrorID", PQ_DFL|PQ_INT, 0, &pf_mirror_id, 0); parse_table_add(&pt, "Vlan", PQ_DFL|PQ_INT, 0, &pf_vlan, 0); parse_table_add(&pt, "IngPort", PQ_DFL|PQ_PORT, 0, &pf_ingport, 0); parse_table_add(&pt, "SrcPort", PQ_DFL|PQ_INT, 0, &pf_src_modport, 0); parse_table_add(&pt, "SrcModid", PQ_DFL|PQ_INT, 0, &pf_src_modid, 0); parse_table_add(&pt, "Reason", PQ_DFL|PQ_MULTI, 0, &pf_reason, reason_str); parse_table_add(&pt, "FPRule", PQ_DFL|PQ_INT, 0, &pf_fp_rule, 0); parse_table_add(&pt, "PktOffset", PQ_DFL|PQ_HEX, 0, &pkt_offset, 0); parse_table_add(&pt, "PktByte0", PQ_DFL|PQ_INT, 0, &pkt_data[0], 0); parse_table_add(&pt, "PktByte1", PQ_DFL|PQ_INT, 0, &pkt_data[1], 0); parse_table_add(&pt, "PktByte2", PQ_DFL|PQ_INT, 0, &pkt_data[2], 0); parse_table_add(&pt, "PktByte3", PQ_DFL|PQ_INT, 0, &pkt_data[3], 0); parse_table_add(&pt, "PktByte4", PQ_DFL|PQ_INT, 0, &pkt_data[4], 0); parse_table_add(&pt, "PktByte5", PQ_DFL|PQ_INT, 0, &pkt_data[5], 0); parse_table_add(&pt, "PktByte6", PQ_DFL|PQ_INT, 0, &pkt_data[6], 0); parse_table_add(&pt, "PktByte7", PQ_DFL|PQ_INT, 0, &pkt_data[7], 0); parse_table_add(&pt, "DestProto", PQ_DFL|PQ_INT, 0, &pf_dest_proto, 0); parse_table_add(&pt, "MirrorProto", PQ_DFL|PQ_INT, 0, &pf_mirror_proto, 0); if (parse_arg_eq(args, &pt) < 0) { parse_arg_eq_done(&pt); return CMD_USAGE; } bcm_knet_filter_t_init(&filter); filter.type = BCM_KNET_FILTER_T_RX_PKT; if (pf_desc) { sal_strncpy(filter.desc, pf_desc, sizeof(filter.desc) - 1); } parse_arg_eq_done(&pt); if (pf_dest_type < 0) { cli_out("Missing destination\n"); return CMD_USAGE; } filter.priority = pf_prio; filter.dest_type = pf_dest_type; filter.dest_id = pf_dest_id; filter.dest_proto = pf_dest_proto; /* * Specifying a mirror ID implies mirroring to another * netif. Enabling mirroring while leaving mirror ID at * zero implies mirroring to the Rx API. */ if (pf_mirror_id) { pf_mirror = 1; } if (pf_dest_type == BCM_KNET_DEST_T_NETIF && pf_mirror) { filter.mirror_type = BCM_KNET_DEST_T_BCM_RX_API; if (pf_mirror_id) { filter.mirror_type = BCM_KNET_DEST_T_NETIF; filter.mirror_id = pf_mirror_id; filter.mirror_proto = pf_mirror_proto; } } if (pf_striptag) { filter.flags |= BCM_KNET_FILTER_F_STRIP_TAG; } if (pf_vlan >= 0) { filter.m_vlan = pf_vlan; filter.match_flags |= BCM_KNET_FILTER_M_VLAN; } if (pf_ingport >= 0) { filter.m_ingport = pf_ingport; filter.match_flags |= BCM_KNET_FILTER_M_INGPORT; } if (pf_src_modport >= 0) { filter.m_src_modport = pf_src_modport; filter.match_flags |= BCM_KNET_FILTER_M_SRC_MODPORT; } if (pf_src_modid >= 0) { filter.m_src_modid = pf_src_modid; filter.match_flags |= BCM_KNET_FILTER_M_SRC_MODID; } if (pf_reason >= 0) { BCM_RX_REASON_SET(filter.m_reason, pf_reason); filter.match_flags |= BCM_KNET_FILTER_M_REASON; } if (pf_fp_rule >= 0) { filter.m_fp_rule = pf_fp_rule; filter.match_flags |= BCM_KNET_FILTER_M_FP_RULE; } for (idx = 0; idx < COUNTOF(pkt_data); idx++) { pdx = pkt_offset + idx; if (pdx >= sizeof(filter.m_raw_data)) { cli_out("PktOffset too large - max is %d\n", (int)sizeof(filter.m_raw_data) - COUNTOF(pkt_data)); return CMD_USAGE; } if (pkt_data[idx] >= 0) { filter.raw_size = pdx + 1; filter.match_flags |= BCM_KNET_FILTER_M_RAW; filter.m_raw_data[pdx] = (uint8)pkt_data[idx]; filter.m_raw_mask[pdx] = 0xff; } } if ((rv = bcm_knet_filter_create(unit, &filter)) < 0) { cli_out("Error creating packet filter: %s\n", bcm_errmsg(rv)); return CMD_FAIL; } _show_filter(unit, &filter); } else if (sal_strcasecmp(subcmd, "destroy") == 0) { if (!ARG_CNT(args) || !isint(ARG_CUR(args))) { return(CMD_USAGE); } pf_id = parse_integer(ARG_GET(args)); if ((rv = bcm_knet_filter_destroy(unit, pf_id)) < 0) { cli_out("Error destroying packet filter: %s\n", bcm_errmsg(rv)); return CMD_FAIL; } } else if (sal_strcasecmp(subcmd, "show") == 0) { count = 0; if (bcm_knet_filter_traverse(unit, _trav_filter, &count) < 0) { return CMD_FAIL; } if (count == 0) { cli_out("<no filters>\n"); } } else { cli_out("Subcommand not found: %s\n", subcmd); return CMD_USAGE; } } else { cli_out("Subcommand not found: %s\n", subcmd); return CMD_USAGE; } return CMD_OK; }
char* search(char* database, char* inparams[], char* invalues[], int incount, int* hformat) { int i,rcount,gcount,itmp; wg_int type=0; char* fields[MAXPARAMS]; char* values[MAXPARAMS]; char* compares[MAXPARAMS]; char* types[MAXPARAMS]; int fcount=0, vcount=0, ccount=0, tcount=0; int from=0; int count=MAXCOUNT; void* db=NULL; // actual database pointer void* rec; char* res; int res_size=INITIAL_MALLOC; wg_query *wgquery; // query datastructure built later wg_query_arg wgargs[MAXPARAMS]; wg_int lock_id=0; // non-0 iff lock set int nosearch=0; // 1 iff no search parameters given, use scan int maxdepth=MAX_DEPTH_DEFAULT; // rec depth limit for printer int showid=0; // add record id as first extra elem: 0: no, 1: yes int format=1; // 0: csv, 1:json int escape=2; // string special chars escaping: 0: just ", 1: urlencode, 2: json, 3: csv char errbuf[200]; // used for building variable-content input param error strings only char* strbuffer; // main result string buffer start (malloced later) int strbufferlen; // main result string buffer length char* strbufferptr; // current output location ptr in the main result string buffer // -------check and parse cgi parameters, attach database ------------ // set params to defaults for(i=0;i<MAXPARAMS;i++) { fields[i]=NULL; values[i]=NULL; compares[i]=NULL; types[i]=NULL; } // find search parameters for(i=0;i<incount;i++) { if (strncmp(inparams[i],"field",MAXQUERYLEN)==0) { fields[fcount++]=invalues[i]; } else if (strncmp(inparams[i],"value",MAXQUERYLEN)==0) { values[vcount++]=invalues[i]; } else if (strncmp(inparams[i],"compare",MAXQUERYLEN)==0) { compares[ccount++]=invalues[i]; } else if (strncmp(inparams[i],"type",MAXQUERYLEN)==0) { types[tcount++]=invalues[i]; } else if (strncmp(inparams[i],"from",MAXQUERYLEN)==0) { from=atoi(invalues[i]); } else if (strncmp(inparams[i],"count",MAXQUERYLEN)==0) { count=atoi(invalues[i]); } else if (strncmp(inparams[i],"depth",MAXQUERYLEN)==0) { maxdepth=atoi(invalues[i]); } else if (strncmp(inparams[i],"showid",MAXQUERYLEN)==0) { if (strncmp(invalues[i],"yes",MAXQUERYLEN)==0) showid=1; else if (strncmp(invalues[i],"no",MAXQUERYLEN)==0) showid=0; else { snprintf(errbuf,100,UNKNOWN_PARAM_VALUE_ERR,invalues[i],inparams[i]); errhalt(errbuf); } } else if (strncmp(inparams[i],"format",MAXQUERYLEN)==0) { if (strncmp(invalues[i],"csv",MAXQUERYLEN)==0) format=0; else if (strncmp(invalues[i],"json",MAXQUERYLEN)==0) format=1; else { snprintf(errbuf,100,UNKNOWN_PARAM_VALUE_ERR,invalues[i],inparams[i]); errhalt(errbuf); } } else if (strncmp(inparams[i],"escape",MAXQUERYLEN)==0) { if (strncmp(invalues[i],"no",MAXQUERYLEN)==0) escape=0; else if (strncmp(invalues[i],"url",MAXQUERYLEN)==0) escape=1; else if (strncmp(invalues[i],"json",MAXQUERYLEN)==0) escape=2; else { snprintf(errbuf,100,UNKNOWN_PARAM_VALUE_ERR,invalues[i],inparams[i]); errhalt(errbuf); } } else if (strncmp(inparams[i],"db",MAXQUERYLEN)==0) { // correct parameter, no action here } else if (strncmp(inparams[i],"op",MAXQUERYLEN)==0) { // correct parameter, no action here } else { // incorrect/unrecognized parameter snprintf(errbuf,100,UNKNOWN_PARAM_ERR,inparams[i]); errhalt(errbuf); } } // all parameters and values were understood if (format==0) { // csv maxdepth=0; // record structure not printed for csv escape=3; // only " replaced with "" *hformat=0; // store to caller for content-type header global_format=0; // for error handler only } // check search parameters if (!fcount) { if (vcount || ccount || tcount) errhalt(NO_FIELD_ERR); else nosearch=1; } // attach to database db = wg_attach_existing_database(database); global_db=db; if (!db) errhalt(DB_ATTACH_ERR); res=malloc(res_size); if (!res) { err_clear_detach_halt(db,0,MALLOC_ERR); } // database attached OK // create output string buffer (may be reallocated later) strbuffer=str_new(INITIAL_MALLOC); strbufferlen=INITIAL_MALLOC; strbufferptr=strbuffer; if (nosearch) { // ------- special case without real search: just output records --- gcount=0; rcount=0; lock_id = wg_start_read(db); // get read lock global_lock_id=lock_id; // only for handling errors if (!lock_id) err_clear_detach_halt(db,0,LOCK_ERR); str_guarantee_space(&strbuffer,&strbufferlen,&strbufferptr,MIN_STRLEN); if (format!=0) { // json snprintf(strbufferptr,MIN_STRLEN,"[\n"); strbufferptr+=2; } if (maxdepth>MAX_DEPTH_HARD) maxdepth=MAX_DEPTH_HARD; rec=wg_get_first_record(db); do { if (rcount>=from) { gcount++; if (gcount>count) break; str_guarantee_space(&strbuffer,&strbufferlen,&strbufferptr,MIN_STRLEN); if (gcount>1 && format!=0) { // json and not first row snprintf(strbufferptr,MIN_STRLEN,",\n"); strbufferptr+=2; } sprint_record(db,rec,&strbuffer,&strbufferlen,&strbufferptr,format,showid,0,maxdepth,escape); if (format==0) { // csv str_guarantee_space(&strbuffer,&strbufferlen,&strbufferptr,MIN_STRLEN); snprintf(strbufferptr,MIN_STRLEN,"\r\n"); strbufferptr+=2; } } rec=wg_get_next_record(db,rec); rcount++; } while(rec!=NULL); if (!wg_end_read(db, lock_id)) { // release read lock err_clear_detach_halt(db,lock_id,LOCK_RELEASE_ERR); } global_lock_id=0; // only for handling errors wg_detach_database(db); global_db=NULL; // only for handling errors str_guarantee_space(&strbuffer,&strbufferlen,&strbufferptr,MIN_STRLEN); if (format!=0) { // json snprintf(strbufferptr,MIN_STRLEN,"\n]"); strbufferptr+=3; } return strbuffer; } // ------------ normal search case: --------- // create a query list datastructure for(i=0;i<fcount;i++) { // field num if (!isint(fields[i])) err_clear_detach_halt(db,0,NO_FIELD_ERR); itmp=atoi(fields[i]); // column to compare wgargs[i].column = itmp; // comparison op: default equal wgargs[i].cond = encode_incomp(db,compares[i]); // valuetype: default guess from value later type=encode_intype(db,types[i]); // encode value to compare with wgargs[i].value = encode_invalue(db,values[i],type); } // make the query structure and read-lock the database before! lock_id = wg_start_read(db); // get read lock global_lock_id=lock_id; // only for handling errors if (!lock_id) err_clear_detach_halt(db,lock_id,LOCK_ERR); wgquery = wg_make_query(db, NULL, 0, wgargs, i); if (!wgquery) err_clear_detach_halt(db,lock_id,QUERY_ERR); // actually perform the query rcount=0; gcount=0; str_guarantee_space(&strbuffer,&strbufferlen,&strbufferptr,MIN_STRLEN); if (format!=0) { // json snprintf(strbufferptr,MIN_STRLEN,"[\n"); strbufferptr+=2; } if (maxdepth>MAX_DEPTH_HARD) maxdepth=MAX_DEPTH_HARD; while((rec = wg_fetch(db, wgquery))) { if (rcount>=from) { gcount++; str_guarantee_space(&strbuffer,&strbufferlen,&strbufferptr,MIN_STRLEN); if (gcount>1 && format!=0) { // json and not first row snprintf(strbufferptr,MIN_STRLEN,",\n"); strbufferptr+=2; } sprint_record(db,rec,&strbuffer,&strbufferlen,&strbufferptr,format,showid,0,maxdepth,escape); if (format==0) { // csv str_guarantee_space(&strbuffer,&strbufferlen,&strbufferptr,MIN_STRLEN); snprintf(strbufferptr,MIN_STRLEN,"\r\n"); strbufferptr+=2; } } rcount++; if (gcount>=count) break; } // free query datastructure, release lock, detach for(i=0;i<fcount;i++) wg_free_query_param(db, wgargs[i].value); wg_free_query(db,wgquery); if (!wg_end_read(db, lock_id)) { // release read lock err_clear_detach_halt(db,lock_id,LOCK_RELEASE_ERR); } global_lock_id=0; // only for handling errors wg_detach_database(db); global_db=NULL; // only for handling errors str_guarantee_space(&strbuffer,&strbufferlen,&strbufferptr,MIN_STRLEN); if (format!=0) { // json snprintf(strbufferptr,MIN_STRLEN,"\n]"); strbufferptr+=3; } return strbuffer; }
//function(..) module saved jan 1 2013 as part of prep for scrt integration static void function(Symbol f, Symbol caller[], Symbol callee[], int ncalls) { int i, saved, sizefsave, sizeisave, varargs; Symbol r, argregs[NUM_ARG_REGS]; usedmask[0] = usedmask[1] = 0; freemask[0] = freemask[1] = ~(unsigned)0; offset = maxoffset = maxargoffset = 0; for (i = 0; callee[i]; i++) //find last argument ; varargs = variadic(f->type) //see if variable arguments by type or by name of final argument || i > 0 && strcmp(callee[i-1]->name, "va_alist") == 0; for (i = 0; callee[i]; i++) { //for each argument Symbol p = callee[i]; Symbol q = caller[i]; assert(q); offset = roundup(offset, q->type->align); //calculate the offset from the caller's sp p->x.offset = q->x.offset = offset; p->x.name = q->x.name = stringd(offset); r = argreg(i, offset, optype(ttob(q->type)), q->type->size, optype(ttob(caller[0]->type))); if (i < NUM_ARG_REGS) argregs[i] = r; offset = roundup(offset + q->type->size, 2); //i dunno if (varargs) p->sclass = AUTO; //variable args are always auto? else if (r && ncalls == 0 && //I dunno !isstruct(q->type) && !p->addressed && !(isfloat(q->type) && r->x.regnode->set == IREG)) { p->sclass = q->sclass = REGISTER; askregvar(p, r); assert(p->x.regnode && p->x.regnode->vbl == p); q->x = p->x; q->type = p->type; } else if (askregvar(p, rmap(ttob(p->type))) && r != NULL && (isint(p->type) || p->type == q->type)) { assert(q->sclass != REGISTER); p->sclass = q->sclass = REGISTER; q->type = p->type; } } assert(!caller[i]); //done with arguments, their individual offsets and maxargoffset have been set offset = 0; gencode(caller, callee); if (ncalls) //prepare to save return address if necessary(i.e. we do calls of our own) usedmask[IREG] |= ((unsigned)1)<<REG_RETADDR; usedmask[IREG] &= INT_CALLEE_SAVE; //limit saving to those we're responsible for usedmask[FREG] &= 0xfff00000; maxargoffset = roundup(maxargoffset, usedmask[FREG] ? 8 : 2); if (ncalls && maxargoffset < NUM_ARG_REGS*2) maxargoffset = NUM_ARG_REGS*2; sizefsave = 4*bitcount(usedmask[FREG]); //space needed to save the float regs sizeisave = 2*bitcount(usedmask[IREG]); //space needed to save the int regs framesize = roundup(maxargoffset + sizefsave //space for outgoing arguments, space for saving floats, + sizeisave + maxoffset, 2); //space for saving ints, space for locals //segment(CODE); //printf("\talign 16\n"); printf("%s:\n", f->x.name); i = maxargoffset + sizefsave - framesize; //I dunno but it's -v and it's never used! if (framesize > 0) print("\talu2I sp,sp,%d,smi,smbi\n", framesize); saved = maxargoffset; /space needed for outgoing arguments
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[]) { double *x, *h, *yl, *yh, *Lf, *Lr; int m, n, mh, nh, h_col, h_row, lh, L, i, po2, j; double mtest, ntest; /* check for correct # of input variables */ if (nrhs>4){ mexErrMsgTxt("There are at most 4 input parameters allowed!"); return; } if (nrhs<3){ mexErrMsgTxt("There are at least 3 input parameters required!"); return; } yl = mxGetPr(prhs[0]); n = mxGetN(prhs[0]); m = mxGetM(prhs[0]); yh = mxGetPr(prhs[1]); nh = mxGetN(prhs[1]); mh = mxGetM(prhs[1]); h = mxGetPr(prhs[2]); h_col = mxGetN(prhs[2]); h_row = mxGetM(prhs[2]); if (h_col>h_row) lh = h_col; else lh = h_row; if (nrhs == 4){ L = (int) *mxGetPr(prhs[3]); if (L < 0) mexErrMsgTxt("The number of levels, L, must be a non-negative integer"); } else /* Estimate L */ { i=n;j=0; while (even(i)){ i=(i>>1); j++; } L=m;i=0; while (even(L)){ L=(L>>1); i++; } if(min(m,n) == 1) L = max(i,j); else L = min(i,j); if (L==0){ mexErrMsgTxt("Maximum number of levels is zero; no decomposition can be performed!"); return; } } /* check for consistency of rows and columns of yl, yh */ if (min(m,n) > 1){ if((m != mh) | (3*n*L != nh)){ mexErrMsgTxt("Dimensions of first two input matrices not consistent!"); return; } } else{ if((m != mh) | (n*L != nh)){ mexErrMsgTxt("Dimensions of first two input vectors not consistent!");{ return; } } } /* Check the ROW dimension of input */ if(m > 1){ mtest = (double) m/pow(2.0, (double) L); if (!isint(mtest)) mexErrMsgTxt("The matrix row dimension must be of size m*2^(L)"); } /* Check the COLUMN dimension of input */ if(n > 1){ ntest = (double) n/pow(2.0, (double) L); if (!isint(ntest)) mexErrMsgTxt("The matrix column dimension must be of size n*2^(L)"); } plhs[0] = mxCreateDoubleMatrix(m,n,mxREAL); x = mxGetPr(plhs[0]); plhs[1] = mxCreateDoubleMatrix(1,1,mxREAL); Lr = mxGetPr(plhs[1]); *Lr = L; MIRDWT(x, m, n, h, lh, L, yl, yh); }
static char* search(thread_data_p tdata, char* inparams[], char* invalues[], int incount, int opcode) { char* database=tdata->database; char *token=NULL; int i,j,x,itmp; wg_int type=0; char* fields[MAXPARAMS]; // search fields char* values[MAXPARAMS]; // search values char* compares[MAXPARAMS]; // search comparisons char* types[MAXPARAMS]; // search value types char* cids=NULL; wg_int ids[MAXIDS]; // select these ids only int fcount=0, vcount=0, ccount=0, tcount=0; // array el counters for above char* sfields[MAXPARAMS]; // set / selected fields char* svalues[MAXPARAMS]; // set field values char* stypes[MAXPARAMS]; // set field types int sfcount; // array el counters for above int from=0; unsigned long count,rcount,gcount,handlecount; void* db=NULL; // actual database pointer void *rec, *oldrec; char* res; wg_query *wgquery; // query datastructure built later wg_query_arg wgargs[MAXPARAMS]; wg_int lock_id=0; // non-0 iff lock set int searchtype=0; // 0: full scan, 1: record ids, 2: by fields char errbuf[ERRBUF_LEN]; // used for building variable-content input param error strings only // default max nr of rows shown/handled if (opcode==COUNT_CODE) count=LONG_MAX; else count=MAXCOUNT; // -------check and parse cgi parameters, attach database ------------ // set params to defaults for(i=0;i<MAXPARAMS;i++) { fields[i]=NULL; values[i]=NULL; compares[i]=NULL; types[i]=NULL; sfields[i]=NULL; svalues[i]=NULL; stypes[i]=NULL; } // set printing params to defaults tdata->format=1; // 1: json tdata->maxdepth=MAX_DEPTH_DEFAULT; // rec depth limit for printer tdata->showid=0; // add record id as first extra elem: 0: no, 1: yes tdata->strenc=2; // string special chars escaping: 0: just ", 1: urlencode, 2: json, 3: csv // find search parameters for(i=0;i<incount;i++) { if (strncmp(inparams[i],"recids",MAXQUERYLEN)==0) { cids=invalues[i]; x=0; // set ids to defaults for(j=0;j<MAXIDS;j++) ids[j]=0; // split csv int list to ids int array for(j=0;j<strlen(cids);j++) { if (atoi(cids+j) && atoi(cids+j)>0) ids[x++]=atoi(cids+j); if (x>=MAXIDS) break; for(;j<strlen(cids) && cids[j]!=','; j++) {}; } } else if (strncmp(inparams[i],"fld",MAXQUERYLEN)==0) { res=handle_fld_param(tdata,inparams[i],invalues[i], &sfields[sfcount],&svalues[sfcount],&stypes[sfcount],sfcount,errbuf); if (res!=NULL) return res; // return error string sfcount++; } else if (strncmp(inparams[i],"field",MAXQUERYLEN)==0) { fields[fcount++]=invalues[i]; } else if (strncmp(inparams[i],"value",MAXQUERYLEN)==0) { values[vcount++]=invalues[i]; } else if (strncmp(inparams[i],"compare",MAXQUERYLEN)==0) { compares[ccount++]=invalues[i]; } else if (strncmp(inparams[i],"type",MAXQUERYLEN)==0) { types[tcount++]=invalues[i]; } else if (strncmp(inparams[i],"from",MAXQUERYLEN)==0) { from=atoi(invalues[i]); } else if (strncmp(inparams[i],"count",MAXQUERYLEN)==0) { count=atoi(invalues[i]); } else { // handle generic parameters for all queries: at end of param check res=handle_generic_param(tdata,inparams[i],invalues[i],&token,errbuf); if (res!=NULL) return res; // return error string } } // authorization if (opcode==DELETE_CODE || opcode==UPDATE_CODE) { if (!authorize(WRITE_LEVEL,tdata,database,token)) return errhalt(NOT_AUTHORIZED_ERR,tdata); } else { if (!authorize(READ_LEVEL,tdata,database,token)) return errhalt(NOT_AUTHORIZED_ERR,tdata); } // all parameters and values were understood if (tdata->format==0) { // csv tdata->maxdepth=0; // record structure not printed for csv tdata->strenc=3; // only " replaced with "" } // check search parameters if (cids!=NULL) { // query by record ids if (fcount) return errhalt(RECIDS_COMBINED_ERR,tdata); searchtype=1; } else if (!fcount) { // no search fields given if (vcount || ccount || tcount) return errhalt(NO_FIELD_ERR,tdata); else searchtype=0; // scan everything } else { // search by fields searchtype=2; } // attach to database db=op_attach_database(tdata,database,READ_LEVEL); if (!db) return errhalt(DB_ATTACH_ERR,tdata); // database attached OK // create output string buffer (may be reallocated later) tdata->buf=str_new(INITIAL_MALLOC); if (tdata->buf==NULL) return errhalt(MALLOC_ERR,tdata); tdata->bufsize=INITIAL_MALLOC; tdata->bufptr=tdata->buf; // check printing depth if (tdata->maxdepth>MAX_DEPTH_HARD) tdata->maxdepth=MAX_DEPTH_HARD; // initial print if(!op_print_data_start(tdata,opcode==SEARCH_CODE)) return err_clear_detach_halt(MALLOC_ERR,tdata); // zero counters rcount=0; gcount=0; handlecount=0; // actual nr of records handled // get lock if (tdata->realthread && tdata->common->shutdown) return NULL; // for multithreading only lock_id = wg_start_read(db); // get read lock tdata->lock_id=lock_id; tdata->lock_type=READ_LOCK_TYPE; if (!lock_id) return err_clear_detach_halt(LOCK_ERR,tdata); // handle one of the cases if (searchtype==0) { // ------- full scan case --- rec=wg_get_first_record(db); while (rec!=NULL) { if (rcount>=from) { gcount++; if (gcount>count) break; if (opcode==COUNT_CODE) { handlecount++; } else if (opcode==SEARCH_CODE) { itmp=op_print_record(tdata,rec,gcount); if (!itmp) return err_clear_detach_halt(MALLOC_ERR,tdata); } else if (opcode==UPDATE_CODE) { itmp=op_update_record(tdata,db,rec,0,0); if (!itmp) handlecount++; } } oldrec=rec; rec=wg_get_next_record(db,rec); if (opcode==DELETE_CODE) { x=wg_get_record_len(db,oldrec); if (x>0) { itmp=op_delete_record(tdata,oldrec); if (!itmp) handlecount++; //else err_clear_detach_halt(DELETE_ERR,tdata); } } rcount++; } } else if (searchtype==1) { // ------------ search by record ids: ------------ for(j=0; ids[j]!=0 && j<MAXIDS; j++) { x=wg_get_encoded_type(db,ids[j]); if (x!=WG_RECORDTYPE) continue; rec=wg_decode_record(db,ids[j]); if (rec==NULL) continue; x=wg_get_record_len(db,rec); if (x<=0) continue; gcount++; if (gcount>count) break; if (opcode==COUNT_CODE) handlecount++; else if (opcode==SEARCH_CODE) { itmp=op_print_record(tdata,rec,gcount); if (!itmp) return err_clear_detach_halt(MALLOC_ERR,tdata); } else if (opcode==UPDATE_CODE) { itmp=op_update_record(tdata,db,rec,0,0); if (!itmp) handlecount++; } else if (opcode==DELETE_CODE) { // test that db is not null, otherwise we may corrupt the database oldrec=wg_get_first_record(db); if (oldrec!=NULL) { //wg_int objecthead=dbfetch((void*)db,(void*)rec); //printf("isfreeobject %d\n",isfreeobject((int)objecthead)); wg_print_record(db,rec); itmp=op_delete_record(tdata,rec); printf("deletion result %d\n",itmp); if (!itmp) handlecount++; //else return err_clear_detach_halt(DELETE_ERR,tdata); } } } } else if (searchtype==2) { // ------------by field search case: --------- // create a query list datastructure for(i=0;i<fcount;i++) { // field num if (!isint(fields[i])) return err_clear_detach_halt(NO_FIELD_ERR,tdata); itmp=atoi(fields[i]); if(itmp<0) return err_clear_detach_halt(NO_FIELD_ERR,tdata); // column to compare wgargs[i].column = itmp; // comparison op: default equal wgargs[i].cond = encode_incomp(db,compares[i]); if (wgargs[i].cond==BAD_WG_VALUE) return err_clear_detach_halt(COND_ERR,tdata); // valuetype: default guess from value later type=encode_intype(db,types[i]); if (type==BAD_WG_VALUE) return err_clear_detach_halt(INTYPE_ERR,tdata); // encode value to compare with wgargs[i].value = encode_invalue(db,values[i],type); if (wgargs[i].value==WG_ILLEGAL) return err_clear_detach_halt(INTYPE_ERR,tdata); } // make the query structure wgquery = wg_make_query(db, NULL, 0, wgargs, i); if (!wgquery) return err_clear_detach_halt(QUERY_ERR,tdata); // actually perform the query if (tdata->maxdepth>MAX_DEPTH_HARD) tdata->maxdepth=MAX_DEPTH_HARD; while((rec = wg_fetch(db, wgquery))) { if (rcount>=from) { gcount++; if (opcode==COUNT_CODE) handlecount++; else if (opcode==SEARCH_CODE) { itmp=op_print_record(tdata,rec,gcount); if (!itmp) return err_clear_detach_halt(MALLOC_ERR,tdata); } else if (opcode==UPDATE_CODE) { itmp=op_update_record(tdata,db,rec,0,0); if (!itmp) handlecount++; } else if (opcode==DELETE_CODE) { itmp=op_delete_record(tdata,rec); if (!itmp) handlecount++; //else return err_clear_detach_halt(DELETE_ERR,tdata); } } rcount++; if (gcount>=count) break; } // free query datastructure, for(i=0;i<fcount;i++) wg_free_query_param(db, wgargs[i].value); wg_free_query(db,wgquery); } // ----- cases handled ------ // print a single number for count and delete if (opcode==COUNT_CODE || opcode==DELETE_CODE) { if(!str_guarantee_space(tdata,MIN_STRLEN)) return err_clear_detach_halt(MALLOC_ERR,tdata); itmp=snprintf(tdata->bufptr,MIN_STRLEN,"%lu",handlecount); tdata->bufptr+=itmp; } // release locks and detach if (!wg_end_read(db, lock_id)) { // release read lock return err_clear_detach_halt(LOCK_RELEASE_ERR,tdata); } tdata->lock_id=0; op_detach_database(tdata,db); if(!op_print_data_end(tdata,opcode==SEARCH_CODE)) return err_clear_detach_halt(MALLOC_ERR,tdata); return tdata->buf; }
cmd_result_t cmd_if_config(int u, args_t *a) /* * Function: if_config * Purpose: Perform a variety of configuration functions on an interface. * Parameters: u - unit number to act on. * a - Parameters. * Returns: CMD_USAGE/CMD_FAIL/CMD_OK. */ { if_soc_t *ifs; int interface; cmd_result_t rv; if_soc_t newif; #if VX_VERSION == 66 || VX_VERSION == 68 char gw_cfg_str[32]; #endif /* * Just dump all of our information. */ if (0 == ARG_CNT(a)) { if_dump_table(u, -1, FALSE); return(CMD_OK); } /* Pick up interface number */ if (!isint(ARG_CUR(a))) { cli_out("%s: Invalid interface number: %s\n", ARG_CMD(a), ARG_CUR(a)); return(CMD_FAIL); } interface = parse_integer(ARG_GET(a)); if (interface >= MAX_INTERFACE) { cli_out("%s: ERROR: Interface # too high, only permitted %d\n", ARG_CMD(a), MAX_INTERFACE); return(CMD_FAIL); } /* If no parameters left now, display information on the port */ if (0 == ARG_CNT(a)) { if_dump_table(u, interface, TRUE); return(CMD_OK); } if (if_table[u] == NULL) { sal_memset(&newif, 0, sizeof(newif)); ifs = &newif; } else { ifs = &if_table[u][interface]; } ifs->ifs_net_name = SOC_END_NAME; ifs->ifs_net_interface = interface; /* Check for UP/DOWN */ if (sal_strcasecmp("up", _ARG_CUR(a)) == 0) { ARG_NEXT(a); /* Passed UP */ if (ifs->ifs_sal) { cli_out("%s: ERROR: Interface %d already running\n", ARG_CMD(a), interface); return(CMD_FAIL); } /* Parse the Parameters and try to configure the device */ if (CMD_OK != (rv = if_config_parse(u, ifs, a))) { return(rv); } if (ARG_CNT(a)) { return(CMD_USAGE); } ifs->ifs_sal = sal_if_config(ARG_CMD(a), u, ifs->ifs_net_name, ifs->ifs_net_interface, ifs->ifs_net_host, ifs->ifs_net_mac, ifs->ifs_net_vlan, ifs->ifs_net_ip, ifs->ifs_net_mask); if (ifs->ifs_sal == NULL) { return CMD_FAIL; } if (if_table[u] == NULL) { if_table[u] = sal_alloc(sizeof(*ifs) * MAX_INTERFACE, "if_table"); if (if_table[u] == NULL) { cli_out("%s: ERROR: cannot allocate interface table\n", ARG_CMD(a)); return CMD_FAIL; } sal_memset(if_table[u], 0, sizeof(*ifs) * MAX_INTERFACE); if_table[u][interface] = *ifs; } /* Add default gateway */ if (ifs->ifs_gateway != 0) { char gateway_str[SAL_IPADDR_STR_LEN]; format_ipaddr(gateway_str, ifs->ifs_gateway); #if VX_VERSION == 66 || VX_VERSION == 68 sprintf(gw_cfg_str, "add default %s", gateway_str); LOG_INFO(BSL_LS_APPL_END, (BSL_META_U(u, "Default gateway: %s\n"), gw_cfg_str)); if (ERROR == routec(gw_cfg_str)) { cli_out("Warning: Failed to add default route gatway = %s\n", gateway_str); } #else #ifdef VXWORKS_NETWORK_STACK_6_5 #ifdef VXWORKS_NETWORK_STACK_FIXME_SHOW #error VXWORKS_NETWORK_STACK_FIXME_SHOW #endif #else if (OK != routeAdd("0.0.0.0", gateway_str)) { cli_out("Warning: Failed to add default route gatway = %s\n", gateway_str); } #endif /* VXWORKS_NETWORK_STACK_6_5 */ #endif } return CMD_OK; } else if (sal_strcasecmp("down", _ARG_CUR(a)) == 0) { ARG_NEXT(a); #if VX_VERSION == 66 || VX_VERSION == 68 if (ifs->ifs_gateway != 0) { char gateway_str[SAL_IPADDR_STR_LEN]; format_ipaddr(gateway_str, ifs->ifs_gateway); sprintf(gw_cfg_str, "delete default %s", gateway_str); if (OK != routec(gw_cfg_str)) { cli_out("Warning: Failed to delete default route gatway = %s\n", gateway_str); } } #endif /* VX_VERSION == 66 || VX_VERSION == 68 */ if (!ifs->ifs_sal) { cli_out("%s: Interface %d not running\n", ARG_CMD(a), interface); return(CMD_FAIL); } if (sal_if_deconfig(ARG_CMD(a), ifs->ifs_sal, ifs->ifs_net_name, ifs->ifs_net_interface)) { ifs->ifs_sal = NULL; return CMD_FAIL; } ifs->ifs_sal = NULL; return CMD_OK; } cli_out("%s: ERROR: Invalid option %s: [up|down] expected\n", ARG_CMD(a), ARG_CUR(a)); return(CMD_USAGE); }
/**This reads each file that in.file actually contains, one by one, and stores them in a struct*/ PROCESS *readFiles() { if (lf) fprintf(logger,"Job has %d files\n",nfiles); PROCESS *processes = malloc(nfiles*sizeof(PROCESS)); if (files == NULL) { perror("Cannot allocate to processes"); exit(1); } FILE *fp; PROCESS *pp = processes; //Reading the files in one by one and storing to "processes" for(int fileCount = 0; fileCount < nfiles; fileCount++) { char **fparse = files + fileCount; if ((fp = fopen(*fparse,"r")) == NULL) { char error[BUFSIZ]; sprintf(error,"Cannot open %s",*files); fprintf(logger, "Fatal Error: %s\n", error); perror(error); exit(1); //Exit if reading file fails -- MAY NOT BE THE CASE! } else { //Parse the file line-by-line char line[BUFSIZ]; if (fgets(line,sizeof line,fp) == NULL) {//Read first line perror("Cannot process file"); exit(0); } else { trimLine(line); if (isint(line)) { pp->pname = calloc(sizeof(char),strlen(*fparse)+1); strcpy(pp->pname,*fparse); //file is valid and has a start time at the beginning pp->stime = strtol(line,NULL,10); //construct a new process and initialise its default values pp->nlines = pp->nifs = pp->runningTime = 0; pp->curLine = 1; //apparently causes a memory access error if not first set to NULL pp->iflines = (IFLINE*) NULL; pp->scheduledTimeSlots = (int*) NULL; pp->durationTimeSlots = (int*) NULL; pp->nTimeSlots = 0; pp->lines = (char**) NULL; } else { fprintf(stderr,"Start time missing from %s\n",*fparse); fprintf(logger, "Fatal Error: Start time missing from %s\n",*fparse); exit(1); } while (INFILE(fp)) { //Read rest of proc. if (fgets(line,sizeof line,fp) != NULL) { trimLine(line); ++(pp->nlines); pp->lines = (char**)realloc(pp->lines, pp->nlines * (sizeof(char*))); //explictly initialise pointer to NULL to avoid memory referential issues (pp->lines)[pp->nlines-1] = (char*) NULL; (pp->lines)[pp->nlines-1] = malloc((strlen(line) + 1) * sizeof(char)); strcpy((pp->lines)[pp->nlines-1], line); //check for existence of ifline if (findIfLine(pp,line,pp->nlines)) { IFLINE il = (pp->iflines)[pp->nifs - 1]; fprintf(logger,"If-Line found at line %d: "\ "if %c < %d goto %d\n",il.originline, il.ifvar,il.loopLimit,il.gotoline); } } } } pp->currtime = 0; pp->runningTime = findRunningTime(pp); if (lf) fprintf(logger,"Read file %s\n",*fparse); fparse++; pp++; } fclose(fp); } pp = processes; if (lf) for (int i = 0; i < nfiles; i++,pp++) fprintf(logger,"Process %s has starttime %d and %d if-lines\n", files[i],pp->stime,pp->nifs); return processes; }
cmd_result_t iprocread_cmd(int unit, args_t *args) { cmd_result_t rv = CMD_OK; parse_table_t pt; char *c, *filename = NULL; uint32 addr = 0; int ce = 0; int len=1; #ifndef NO_FILEIO #ifndef NO_CTRL_C jmp_buf ctrl_c; #endif FILE * volatile fp = NULL; #endif if (ARG_CNT(args) < 1) { return(CMD_USAGE); } parse_table_init(unit, &pt); parse_table_add(&pt, "ChangeEndian", PQ_DFL|PQ_BOOL, 0, &ce, NULL); if (parse_arg_eq(args, &pt) < 0) { printk("%s: Error: Unknown option: %s\n", ARG_CMD(args), ARG_CUR(args)); parse_arg_eq_done(&pt); return(CMD_USAGE); } c = ARG_GET(args); if (!isint(c)) { printk("%s: Error: Address not specified\n", ARG_CMD(args)); return(CMD_USAGE); } addr = parse_address(c); if (ARG_CNT(args) > 0) { c = ARG_GET(args); if (isint(c)) { len = parse_address(c); if (ARG_CNT(args) > 0) { filename = ARG_GET(args); } } else { filename = c; } } if (filename == NULL) { /* Just dump to screen */ rv = _iproc_dump(unit, ce, NULL, addr, len); } else { #ifdef NO_FILEIO printk("no filesystem\n"); #else /* Dump to file */ #ifndef NO_CTRL_C if (!setjmp(ctrl_c)) { sh_push_ctrl_c(&ctrl_c); #endif fp = sal_fopen(filename, "w"); if (!fp) { printk("%s: Error: Unable to open file: %s\n", ARG_CMD(args), filename); rv = CMD_FAIL; #ifndef NO_CTRL_C sh_pop_ctrl_c(); #endif return(rv); } else { soc_cm_debug(DK_VERBOSE, "Dump to file %s\n", filename); rv = _iproc_dump(unit, ce, fp, addr, len); sal_fclose((FILE *)fp); fp = NULL; } #ifndef NO_CTRL_C } else if (fp) { sal_fclose((FILE *)fp); fp = NULL; rv = CMD_INTR; } sh_pop_ctrl_c(); #endif sal_usleep(10000); #endif /* NO_FILEIO */ } return(rv); }
void Check64BitPortability::pointerassignment() { if (!_settings->isEnabled("portability")) return; const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase(); // Check return values const std::size_t functions = symbolDatabase->functionScopes.size(); for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; if (scope->function == 0 || !scope->function->hasBody) // We only look for functions with a body continue; bool retPointer = false; if (scope->function->token->strAt(-1) == "*") // Function returns a pointer retPointer = true; else if (Token::Match(scope->function->token->previous(), "int|long|DWORD")) // Function returns an integer ; else continue; for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { if (Token::Match(tok, "return %var%|%num% [;+]") && !Token::simpleMatch(tok, "return 0 ;")) { enum { NO, INT, PTR, PTRDIFF } type = NO; for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) { if ((type == NO || type == INT) && isaddr(tok2->variable())) type = PTR; else if (type == NO && (tok2->isNumber() || isint(tok2->variable()))) type = INT; else if (type == PTR && Token::Match(tok2, "- %var%") && isaddr(tok2->next()->variable())) type = PTRDIFF; else if (Token::Match(tok2, "%type% (")) { type = NO; break; } else if (tok2->str() == ";") break; } if (retPointer && (type == INT || type == PTRDIFF)) returnIntegerError(tok); else if (!retPointer && type == PTR) returnPointerError(tok); } } } // Check assignments for (std::size_t i = 0; i < functions; ++i) { const Scope * scope = symbolDatabase->functionScopes[i]; for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { if (Token::Match(tok, "[;{}] %var% = %var% [;+]")) { const Variable *var1(tok->next()->variable()); const Variable *var2(tok->tokAt(3)->variable()); if (isaddr(var1) && isint(var2) && tok->strAt(4) != "+") assignmentIntegerToAddressError(tok->next()); else if (isint(var1) && isaddr(var2) && !tok->tokAt(3)->isPointerCompare()) { // assigning address => warning // some trivial addition => warning if (Token::Match(tok->tokAt(4), "+ %any% !!;")) continue; assignmentAddressToIntegerError(tok->next()); } } } } }
cmd_result_t cmd_esw_rx_cfg(int unit, args_t *args) /* * Function: rx * Purpose: Perform simple RX test * Parameters: unit - unit number * args - arguments * Returns: CMD_XX */ { int chan; parse_table_t pt; bcm_cos_queue_t queue_max; /* This isn't configurable per unit yet. */ int cos_pps[BCM_RX_COS]; char cospps_str[BCM_RX_COS][20]; uint8 cos_pps_init = 0; int rv = BCM_E_NONE; int i; int system_pps = 0; if (!cos_pps_init) { for (i = 0; i < BCM_RX_COS; i++) { cos_pps[i] = 100; } cos_pps_init = 1; } if (!sh_check_attached(ARG_CMD(args), unit)) { return(CMD_FAIL); } if (BCM_FAILURE(bcm_rx_queue_max_get(unit, &queue_max))) { return (CMD_FAIL); } if (!ARG_CUR(args)) { int spps; /* Display current configuration */ printk("Current RX configuration:\n"); printk(" Pkt Size %d. Pkts/chain %d. All COS PPS %d. Burst %d\n", rx_cfg.pkt_size, rx_cfg.pkts_per_chain, rx_cfg.global_pps, rx_cfg.max_burst); for (chan = 0; chan < BCM_RX_CHANNELS; chan++) { printk(" Channel %d: Chains %d. PPS %d. COSBMP 0x%x.\n", chan, rx_cfg.chan_cfg[chan].chains, rx_cfg.chan_cfg[chan].rate_pps, rx_cfg.chan_cfg[chan].cos_bmp); } if ((rv = bcm_rx_cpu_rate_get(unit, &spps)) < 0) { printk("ERROR getting system rate limit: %s\n", bcm_errmsg(rv)); } else { printk(" System wide rate limit: %d\n", spps); } return CMD_OK; } if (isint(ARG_CUR(args))) { chan = parse_integer(ARG_GET(args)); if (chan < 0 || chan >= BCM_RX_CHANNELS) { printk("Error: Bad channel %d\n", chan); return CMD_FAIL; } } else { chan = -1; } parse_table_init(unit, &pt); /* SPPS must be first, or else adjust pt_entries index below */ parse_table_add(&pt, "SPPS", PQ_DFL|PQ_INT, 0, &system_pps, NULL); parse_table_add(&pt, "GPPS", PQ_DFL|PQ_INT, 0, &rx_cfg.global_pps, NULL); parse_table_add(&pt, "PKTSIZE", PQ_DFL|PQ_INT, 0, &rx_cfg.pkt_size, NULL); parse_table_add(&pt, "PPC", PQ_DFL|PQ_INT, 0, &rx_cfg.pkts_per_chain, NULL); parse_table_add(&pt, "BURST", PQ_DFL|PQ_INT, 0, &rx_cfg.max_burst, NULL); parse_table_add(&pt, "FREE", PQ_DFL|PQ_BOOL, 0, &free_buffers, NULL); if (queue_max >= BCM_RX_COS) { printk("Error: Too many queues %d > %d\n", queue_max, BCM_RX_COS); parse_arg_eq_done(&pt); return CMD_FAIL; } for (i = 0; i < queue_max; i++) { sal_sprintf(cospps_str[i], "COSPPS%d", i); parse_table_add(&pt, cospps_str[i], PQ_DFL|PQ_INT, 0, &cos_pps[i], NULL); } if (chan >= 0) { parse_table_add(&pt, "CHAINS", PQ_DFL|PQ_INT, 0, &rx_chan_cfg.chains, NULL); parse_table_add(&pt, "PPS", PQ_DFL|PQ_INT, 0, &rx_chan_cfg.rate_pps, NULL); parse_table_add(&pt, "COSBMP", PQ_DFL|PQ_HEX, 0, &rx_chan_cfg.cos_bmp, NULL); } /* Parse remaining arguments */ if (0 > parse_arg_eq(args, &pt)) { printk("%s: Error: Invalid option or malformed expression: %s\n", ARG_CMD(args), ARG_CUR(args)); parse_arg_eq_done(&pt); return(CMD_FAIL); } /* Check if SPPS was entered; if so do only that */ if (pt.pt_entries[0].pq_type & PQ_PARSED) { rv = bcm_rx_cpu_rate_set(unit, system_pps); parse_arg_eq_done(&pt); if (rv < 0) { printk("Warning: system rate set (to %d) returned %s\n", system_pps, bcm_errmsg(rv)); return CMD_FAIL; } return CMD_OK; } parse_arg_eq_done(&pt); for (i = 0; i < queue_max; i++) { rv = bcm_rx_cos_rate_set(unit, i, cos_pps[i]); if (rv < 0) { printk("Warning: cos rate set(%d to %d) returned %s\n", i, cos_pps[i], bcm_errmsg(rv)); } } if (chan >=0 ) { /* Copy external chan cfg to right place */ sal_memcpy(&rx_cfg.chan_cfg[chan], &rx_chan_cfg, sizeof(bcm_rx_chan_cfg_t)); } return CMD_OK; }
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[]) { double *x, *h, *y, *Lr; intptr_t m, n, h_col, h_row, lh, i, j, L; double mtest, ntest; /* check for correct # of input variables */ if (nrhs>3){ mexErrMsgTxt("There are at most 3 input parameters allowed!"); return; } if (nrhs<2){ mexErrMsgTxt("There are at least 2 input parameters required!"); return; } y = mxGetPr(prhs[0]); n = mxGetN(prhs[0]); m = mxGetM(prhs[0]); h = mxGetPr(prhs[1]); h_col = mxGetN(prhs[1]); h_row = mxGetM(prhs[1]); if (h_col>h_row) lh = h_col; else lh = h_row; if (nrhs == 3){ L = (intptr_t) *mxGetPr(prhs[2]); if (L < 0) mexErrMsgTxt("The number of levels, L, must be a non-negative integer"); } else /* Estimate L */ { i=n;j=0; while (even(i)){ i=(i>>1); j++; } L=m;i=0; while (even(L)){ L=(L>>1); i++; } if(min(m,n) == 1) L = max(i,j); else L = min(i,j); if (L==0){ mexErrMsgTxt("Maximum number of levels is zero; no decomposition can be performed!"); return; } } /* Check the ROW dimension of input */ if(m > 1){ mtest = (double) m/pow(2.0, (double) L); if (!isint(mtest)) mexErrMsgTxt("The matrix row dimension must be of size m*2^(L)"); } /* Check the COLUMN dimension of input */ if(n > 1){ ntest = (double) n/pow(2.0, (double) L); if (!isint(ntest)) mexErrMsgTxt("The matrix column dimension must be of size n*2^(L)"); } plhs[0] = mxCreateDoubleMatrix(m,n,mxREAL); x = mxGetPr(plhs[0]); if (nlhs > 1){ plhs[1] = mxCreateDoubleMatrix(1,1,mxREAL); Lr = mxGetPr(plhs[1]); *Lr = L; } MIDWT(x, m, n, h, lh, L, y); }
STATIC cmd_result_t robo_tx_parse(int u, args_t *a, xd_t *xd) /* * Function: txrx_parse * Purpose: Parse input parameters into a xd structure. * Parameters: u - unit #. * a - pointer to arguments * xd - pointer to xd structure to fill in. * Returns: 0 - success, -1 failed. */ { static char *crc_list[] = {"None", "Recompute", "Append", NULL}; parse_table_t pt; int min_len, tagged; char *xfile; #if defined(BCM_TB_SUPPORT) || defined(BCM_POLAR_SUPPORT) uint32 traffic_class = 0; #endif /* BCM_TB_SUPPORT || BCM_POLAR_SUPPORT */ /* First arg is count */ if (!ARG_CNT(a) || !isint(ARG_CUR(a))) { return(CMD_USAGE); } _XD_INIT(u, xd); xd->xd_tot_cnt = parse_integer(ARG_GET(a)); parse_table_init(u, &pt); /* Add XGS Ethernet/BCM5632/HIGIG Options */ if (xd->hdr_mode == ENCAP_IEEE) { /* Do nothing, already setup */ } parse_table_add(&pt, "PortBitMap", PQ_DFL|PQ_PBMP, 0, &xd->pkt_info.tx_pbmp, NULL); parse_table_add(&pt, "UntagBitMap", PQ_DFL|PQ_PBMP, 0, &xd->pkt_info.tx_upbmp, NULL); parse_table_add(&pt, "Filename", PQ_DFL|PQ_STRING,0, &xd->xd_file, NULL); parse_table_add(&pt, "Length", PQ_DFL|PQ_INT, 0, &xd->xd_pkt_len, NULL); parse_table_add(&pt, "VLantag", PQ_DFL|PQ_HEX, 0, &xd->xd_vlan, NULL); parse_table_add(&pt, "VlanPrio", PQ_DFL|PQ_INT, 0, &xd->xd_prio, NULL); parse_table_add(&pt, "Pattern", PQ_DFL|PQ_HEX, 0, &xd->xd_pat, NULL); parse_table_add(&pt, "PatternInc", PQ_DFL|PQ_INT, 0, &xd->xd_pat_inc, NULL); parse_table_add(&pt, "PerPortSrcMac",PQ_DFL|PQ_INT, 0, &xd->xd_ppsm, NULL); parse_table_add(&pt, "SourceMac", PQ_DFL|PQ_MAC, 0, &xd->xd_mac_src, NULL); parse_table_add(&pt, "SourceMacInc",PQ_DFL|PQ_INT, 0, &xd->xd_mac_src_inc,NULL); parse_table_add(&pt, "DestMac", PQ_DFL|PQ_MAC, 0, &xd->xd_mac_dst, NULL); parse_table_add(&pt, "DestMacInc", PQ_DFL|PQ_INT, 0, &xd->xd_mac_dst_inc,NULL); parse_table_add(&pt, "CRC", PQ_DFL|PQ_MULTI,0, &xd->xd_crc, crc_list); parse_table_add(&pt, "CallbackFunction",PQ_DFL|PQ_INT, 0, &xd->xd_cbk_enable, NULL); #if defined(BCM_TB_SUPPORT) || defined(BCM_POLAR_SUPPORT) parse_table_add(&pt, "TrafficClass", PQ_DFL|PQ_INT, 0, &traffic_class, NULL); #endif /* BCM_TB_SUPPORT || BCM_POLAR_SUPPORT */ #ifdef BCM_TB_SUPPORT parse_table_add(&pt, "McastGroupID", PQ_DFL|PQ_INT, 0, &xd->pkt_info.multicast_group, NULL); parse_table_add(&pt, "DropPrecedence", PQ_DFL|PQ_INT, 0, &xd->pkt_info.color, NULL); parse_table_add(&pt, "FlowID", PQ_DFL|PQ_INT, 0, &xd->pkt_info.flow_id, NULL); parse_table_add(&pt, "FilTeRs", PQ_DFL|PQ_HEX, 0, &xd->pkt_info.filter_enable, NULL); #endif /* BCM_TB_SUPPORT */ /* Parse remaining arguments */ if (0 > parse_arg_eq(a, &pt)) { cli_out("%s: Error: Invalid option or malformed expression: %s\n", ARG_CMD(a), ARG_CUR(a)); parse_arg_eq_done(&pt); return(CMD_FAIL); } if (xd->xd_file) { xfile = sal_strdup(xd->xd_file); } else { xfile = NULL; } parse_arg_eq_done(&pt); xd->xd_file = xfile; tagged = (xd->xd_vlan != 0); min_len = (tagged ? 68 : 64); if (!XD_FILE(xd) && xd->xd_pkt_len < min_len) { LOG_WARN(BSL_LS_APPL_COMMON, (BSL_META_U(u, "%s: Warning: Length %d too small for %s packet (min %d)\n"), ARG_CMD(a), xd->xd_pkt_len, tagged ? "tagged" : "untagged", min_len)); } #if defined(BCM_TB_SUPPORT) || defined(BCM_POLAR_SUPPORT) xd->pkt_info.prio_int = traffic_class; #endif /* BCM_TB_SUPPORT || BCM_POLAR_SUPPORT */ return(0); }
/* * Public */ SEXP do_mdwt(SEXP vntX, SEXP vntH, SEXP vntL) { SEXP vntOut; SEXP vntY; SEXP vntLr; double *x, *h, *y; int m, n, lh, L; #ifdef DEBUG_RWT REprintf("In do_mdwt(x, h, L)...\n"); #endif /* * Handle first parameter (numeric matrix) */ #ifdef DEBUG_RWT REprintf("\tfirst param 'x'\n"); #endif if (GetMatrixDimen(vntX, &m, &n) != 2) { error("'x' is not a two dimensional matrix"); /*NOTREACHED*/ } PROTECT(vntX = AS_NUMERIC(vntX)); x = NUMERIC_POINTER(vntX); #ifdef DEBUG_RWT REprintf("x[%d][%d] = 0x%p\n", m, n, x); #endif /* * Handle second parameter (numeric vector) */ #ifdef DEBUG_RWT REprintf("\tsecond param 'h'\n"); #endif PROTECT(vntH = AS_NUMERIC(vntH)); h = NUMERIC_POINTER(vntH); lh = GET_LENGTH(vntH); #ifdef DEBUG_RWT REprintf("h[%d] = 0x%p\n", GET_LENGTH(vntH), h); #endif /* * Handle third parameter (integer scalar) */ #ifdef DEBUG_RWT REprintf("\tthird param 'L'\n"); #endif { PROTECT(vntL = AS_INTEGER(vntL)); { int *piL = INTEGER_POINTER(vntL); L = piL[0]; } UNPROTECT(1); } #ifdef DEBUG_RWT REprintf("L = %d\n", L); #endif #ifdef DEBUG_RWT REprintf("\tcheck number of levels\n"); #endif if (L < 0) { error("The number of levels, L, must be a non-negative integer"); /*NOTREACHED*/ } #ifdef DEBUG_RWT REprintf("\tcheck dimen prereqs\n"); #endif /* Check the ROW dimension of input */ if (m > 1) { double mtest = (double) m / pow(2.0, (double) L); if (!isint(mtest)) { error("The matrix row dimension must be of size m*2^(L)"); /*NOTREACHED*/ } } /* Check the COLUMN dimension of input */ if (n > 1) { double ntest = (double) n / pow(2.0, (double) L); if (!isint(ntest)) { error("The matrix column dimension must be of size n*2^(L)"); /*NOTREACHED*/ } } #ifdef DEBUG_RWT REprintf("\tcreate value objects\n"); #endif /* Create y value object */ { #ifdef DEBUG_RWT REprintf("\tcreate 'y' value object\n"); #endif PROTECT(vntY = NEW_NUMERIC(n*m)); y = NUMERIC_POINTER(vntY); /* Add dimension attribute to value object */ #ifdef DEBUG_RWT REprintf("\tconvert 'y' value object to matrix\n"); #endif { SEXP vntDim; PROTECT(vntDim = NEW_INTEGER(2)); INTEGER(vntDim)[0] = m; INTEGER(vntDim)[1] = n; SET_DIM(vntY, vntDim); UNPROTECT(1); } } /* Create Lr value object */ { #ifdef DEBUG_RWT REprintf("\tcreating 'Lr' value object\n"); #endif PROTECT(vntLr = NEW_INTEGER(1)); INTEGER_POINTER(vntLr)[0] = L; } #ifdef DEBUG_RWT REprintf("\tcompute discrete wavelet transform\n"); #endif MDWT(x, m, n, h, lh, L, y); /* Unprotect params */ UNPROTECT(2); #ifdef DEBUG_RWT REprintf("\tcreate list output object\n"); #endif PROTECT(vntOut = NEW_LIST(2)); #ifdef DEBUG_RWT REprintf("\tassigning value objects to list\n"); #endif SET_VECTOR_ELT(vntOut, 0, vntY); SET_VECTOR_ELT(vntOut, 1, vntLr); /* Unprotect value objects */ UNPROTECT(2); { SEXP vntNames; #ifdef DEBUG_RWT REprintf("\tassigning names to value objects in list\n"); #endif PROTECT(vntNames = NEW_CHARACTER(2)); SET_STRING_ELT(vntNames, 0, CREATE_STRING_VECTOR("y")); SET_STRING_ELT(vntNames, 1, CREATE_STRING_VECTOR("L")); SET_NAMES(vntOut, vntNames); UNPROTECT(1); } /* Unprotect output object */ UNPROTECT(1); #ifdef DEBUG_RWT REprintf("\treturning output...\n"); #endif return vntOut; }
Cell unabstract(Cell t) { if (isint(t)) { if (t == mkint(0)) return COMB_I; else return pair(COMB_K, mkint(intof(t)-1)); } else if (ispair(t)) { Cell f, g; PUSH(cdr(t)); PUSH(unabstract(car(t))); g = PUSHED(1) = unabstract(PUSHED(1)); f = TOP; if (IS_K1(f)) { if (g == COMB_I) { /* S (K x) I => x */ f = cdr(f); } else if (IS_K1(g)) { /* S (K x) (K y) => K (x y) */ car(g) = cdr(f); /* x y */ cdr(f) = g; /* K (x y) */ } else if (IS_B2(g)) { /* S (K x) (B y z) => B* x y z */ car(f) = COMB_BS; /* B* x */ car(car(g)) = f; /* B* x y z */ f = g; } else { /* S (K x) y => B x y */ car(f) = COMB_B; /* B x */ f = pair(f, g); /* B x y */ } } else if (IS_K1(g)) { if (IS_B2(f)) { /* S (B x y) (K z) => C' x y z */ car(car(f)) = COMB_CP; car(g) = f; f = g; } else { /* S x (K y) => C x y */ f = cdr(g); SET(g, COMB_C, TOP); /* C x */ f = pair(g, f); /* C x y */ } } else if (IS_B2(f)) { /* S (B x y) z => S' x y z */ car(car(f)) = COMB_SP; /* S' x y */ f = pair(f, g); /* S' x y z */ } else { /* S x y */ f = pair(COMB_S, f); f = pair(f, PUSHED(1)); } DROP(2); return f; } else return pair(COMB_K, t); }
static Tree unary(void) { Tree p; switch (t) { case '*': t = gettok(); p = unary(); p = pointer(p); if (isptr(p->type) && (isfunc(p->type->type) || isarray(p->type->type))) p = retype(p, p->type->type); else { if (YYnull) p = nullcheck(p); p = rvalue(p); } break; case '&': t = gettok(); p = unary(); if (isarray(p->type) || isfunc(p->type)) p = retype(p, ptr(p->type)); else p = lvalue(p); if (isaddrop(p->op) && p->u.sym->sclass == REGISTER) error("invalid operand of unary &; `%s' is declared register\n", p->u.sym->name); else if (isaddrop(p->op)) p->u.sym->addressed = 1; break; case '+': t = gettok(); p = unary(); p = pointer(p); if (isarith(p->type)) p = cast(p, promote(p->type)); else typeerror(ADD, p, NULL); break; case '-': t = gettok(); p = unary(); p = pointer(p); if (isarith(p->type)) { Type ty = promote(p->type); p = cast(p, ty); if (isunsigned(ty)) { warning("unsigned operand of unary -\n"); p = simplify(ADD, ty, simplify(BCOM, ty, p, NULL), cnsttree(ty, 1UL)); } else p = simplify(NEG, ty, p, NULL); } else typeerror(SUB, p, NULL); break; case '~': t = gettok(); p = unary(); p = pointer(p); if (isint(p->type)) { Type ty = promote(p->type); p = simplify(BCOM, ty, cast(p, ty), NULL); } else typeerror(BCOM, p, NULL); break; case '!': t = gettok(); p = unary(); p = pointer(p); if (isscalar(p->type)) p = simplify(NOT, inttype, cond(p), NULL); else typeerror(NOT, p, NULL); break; case INCR: t = gettok(); p = unary(); p = incr(INCR, pointer(p), consttree(1, inttype)); break; case DECR: t = gettok(); p = unary(); p = incr(DECR, pointer(p), consttree(1, inttype)); break; case TYPECODE: case SIZEOF: { int op = t; Type ty; p = NULL; t = gettok(); if (t == '(') { t = gettok(); if (istypename(t, tsym)) { ty = typename(); expect(')'); } else { p = postfix(expr(')')); ty = p->type; } } else {
void eval(Cell root) { Cell *bottom = rd_stack.sp; PUSH(root); for (;;) { while (ispair(TOP)) PUSH(car(TOP)); if (TOP == COMB_I && APPLICABLE(1)) { /* I x -> x */ POP; TOP = cdr(TOP); } else if (TOP == COMB_S && APPLICABLE(3)) { /* S f g x -> f x (g x) */ Cell a = alloc(2); SET(a+0, ARG(1), ARG(3)); /* f x */ SET(a+1, ARG(2), ARG(3)); /* g x */ DROP(3); SET(TOP, a+0, a+1); /* f x (g x) */ } else if (TOP == COMB_K && APPLICABLE(2)) { /* K x y -> I x */ Cell x = ARG(1); DROP(2); SET(TOP, COMB_I, x); TOP = cdr(TOP); /* shortcut reduction of I */ } else if (TOP == COMB_B && APPLICABLE(3)) { /* B f g x -> f (g x) */ Cell f, gx; gx = pair(ARG(2), ARG(3)); f = ARG(1); DROP(3); SET(TOP, f, gx); } else if (TOP == COMB_C && APPLICABLE(3)) { /* C f g x -> f x g */ Cell fx, g; fx = pair(ARG(1), ARG(3)); g = ARG(2); DROP(3); SET(TOP, fx, g); } else if (TOP == COMB_SP && APPLICABLE(4)) { /* SP c f g x -> c (f x) (g x) */ Cell a = alloc(3); SET(a+0, ARG(2), ARG(4)); /* f x */ SET(a+1, ARG(3), ARG(4)); /* g x */ SET(a+2, ARG(1), a+0); /* c (f x) */ DROP(4); SET(TOP, a+2, a+1); /* c (f x) (g x) */ } else if (TOP == COMB_BS && APPLICABLE(4)) { /* BS c f g x -> c (f (g x)) */ Cell a, c; a = alloc(2); SET(a+0, ARG(3), ARG(4)); /* g x */ SET(a+1, ARG(2), a+0); /* f (g x) */ c = ARG(1); DROP(4); SET(TOP, c, a+1); /* c (f (g x)) */ } else if (TOP == COMB_CP && APPLICABLE(4)) { /* BS c f g x -> c (f x) g */ Cell a, g; a = alloc(2); SET(a+0, ARG(2), ARG(4)); /* f x */ SET(a+1, ARG(1), a+0); /* c (f x) */ g = ARG(3); DROP(4); SET(TOP, a+1, g); /* c (f x) g */ } else if (TOP == COMB_IOTA && APPLICABLE(1)) { /* IOTA x -> x S K */ Cell xs = pair(ARG(1), COMB_S); POP; SET(TOP, xs, COMB_K); } else if (TOP == COMB_KI && APPLICABLE(2)) { /* KI x y -> I y */ DROP(2); car(TOP) = COMB_I; } else if (TOP == COMB_CONS && APPLICABLE(3)) { /* CONS x y f -> f x y */ Cell fx, y; fx = pair(ARG(3), ARG(1)); y = ARG(2); DROP(3); SET(TOP, fx, y); } else if (TOP == COMB_READ && APPLICABLE(2)) { /* READ NIL f -> CONS CHAR(c) (READ NIL) f -> I KI f */ int c = read_char(); if (c == EOF) { POP; SET(TOP, COMB_I, COMB_KI); } else { Cell a = alloc(2); SET(a+0, COMB_CONS, mkchar(c == EOF ? 256 : c)); SET(a+1, COMB_READ, NIL); POP; SET(TOP, a+0, a+1); } } else if (TOP == COMB_WRITE && APPLICABLE(1)) { /* WRITE x -> x PUTC RETURN */ POP; Cell a = pair(cdr(TOP), COMB_PUTC); /* x PUTC */ SET(TOP, a, COMB_RETURN); /* x PUTC RETURN */ } else if (TOP == COMB_PUTC && APPLICABLE(3)) { /* PUTC x y i -> putc(eval(x INC NUM(0))); WRITE y */ Cell a = alloc(2); SET(a+0, ARG(1), COMB_INC); /* x INC */ SET(a+1, a+0, mkint(0)); /* x INC NUM(0) */ DROP(2); eval(a+1); if (!isint(TOP)) errexit("invalid output format (result was not a number)\n"); if (intof(TOP) >= 256) errexit("invalid character %d\n", intof(TOP)); putchar(intof(TOP)); POP; ARG(1) = cdr(TOP); /* y */ POP; car(TOP) = COMB_WRITE; /* WRITE y */ } else if (TOP == COMB_RETURN) return; else if (TOP == COMB_INC && APPLICABLE(1)) { /* INC x -> eval(x)+1 */ Cell c = ARG(1); POP; eval(c); c = POP; if (!isint(c)) errexit("invalid output format (attempted to apply inc to a non-number)\n"); SET(TOP, COMB_I, mkint(intof(c) + 1)); } else if (ischar(TOP) && APPLICABLE(2)) { int c = charof(TOP); if (c <= 0) { /* CHAR(0) f z -> z */ Cell z = ARG(2); DROP(2); SET(TOP, COMB_I, z); } else { /* CHAR(n+1) f z -> f (CHAR(n) f z) */ Cell a = alloc(2); Cell f = ARG(1); SET(a+0, mkchar(c-1), f); /* CHAR(n) f */ SET(a+1, a+0, ARG(2)); /* CHAR(n) f z */ DROP(2); SET(TOP, f, a+1); /* f (CHAR(n) f z) */ } } else if (isint(TOP) && APPLICABLE(1)) errexit("invalid output format (attempted to apply a number)\n"); else return; reductions++; } }
void jrb_delete_node(JRB n) { JRB s, p, gp; char ir; if (isint(n)) { fprintf(stderr, "Cannot delete an internal node: 0x%p\n", (void *)n); exit(1); } if (ishead(n)) { fprintf(stderr, "Cannot delete the head of an jrb_tree: 0x%p\n", (void *)n); exit(1); } delete_item(n); /* Delete it from the list */ p = n->parent; /* The only node */ if (isroot(n)) { p->parent = p; free(n); return; } s = sibling(n); /* The only node after deletion */ if (isroot(p)) { s->parent = p->parent; s->parent->parent = s; setroot(s); free(p); free(n); return; } gp = p->parent; /* Set parent to sibling */ s->parent = gp; if (isleft(p)) { gp->flink = s; setleft(s); } else { gp->blink = s; setright(s); } ir = isred(p); free(p); free(n); if (isext(s)) { /* Update proper rext and lext values */ p = lprev(s); if (!ishead(p)) setrext(p, s); p = rprev(s); if (!ishead(p)) setlext(p, s); } else if (isblack(s)) { fprintf(stderr, "DELETION PROB -- sib is black, internal\n"); exit(1); } else { p = lprev(s); if (!ishead(p)) setrext(p, s->flink); p = rprev(s); if (!ishead(p)) setlext(p, s->blink); setblack(s); return; } if (ir) return; /* Recolor */ n = s; p = n->parent; s = sibling(n); while(isblack(p) && isblack(s) && isint(s) && isblack(s->flink) && isblack(s->blink)) { setred(s); n = p; if (isroot(n)) return; p = n->parent; s = sibling(n); } if (isblack(p) && isred(s)) { /* Rotation 2.3b */ single_rotate(p, isright(n)); setred(p); setblack(s); s = sibling(n); } { JRB x, z; char il; if (isext(s)) { fprintf(stderr, "DELETION ERROR: sibling not internal\n"); exit(1); } il = isleft(n); x = il ? s->flink : s->blink ; z = sibling(x); if (isred(z)) { /* Rotation 2.3f */ single_rotate(p, !il); setblack(z); if (isred(p)) setred(s); else setblack(s); setblack(p); } else if (isblack(x)) { /* Recoloring only (2.3c) */ if (isred(s) || isblack(p)) { fprintf(stderr, "DELETION ERROR: 2.3c not quite right\n"); exit(1); } setblack(p); setred(s); return; } else if (isred(p)) { /* 2.3d */ single_rotate(s, il); single_rotate(p, !il); setblack(x); setred(s); return; } else { /* 2.3e */ single_rotate(s, il); single_rotate(p, !il); setblack(x); return; } } }
BOOLEAN comparetypes(TYPE *typ1, TYPE *typ2, int exact) { if (typ1->type == bt_any || typ2->type == bt_any) return TRUE; while (typ1->type == bt_typedef) typ1 = basetype(typ1); while (typ2->type == bt_typedef) typ2 = basetype(typ2); typ1 = replaceTemplateSelector(typ1); typ2 = replaceTemplateSelector(typ2); if (isDerivedFromTemplate(typ1)) typ1 = typ1->btp; if (isDerivedFromTemplate(typ2)) typ2 = typ2->btp; while (isref(typ1)) typ1 = basetype(typ1)->btp; while (isref(typ2)) typ2 = basetype(typ2)->btp; while (typ1->type == bt_typedef) typ1 = basetype(typ1); while (typ2->type == bt_typedef) typ2 = basetype(typ2); if (typ1->type == bt_templateselector && typ2->type == bt_templateselector) return templateselectorcompare(typ1->sp->templateSelector, typ2->sp->templateSelector); if (typ1->type == bt_templatedecltype && typ2->type == bt_templatedecltype) return templatecompareexpressions(typ1->templateDeclType, typ2->templateDeclType); if (ispointer(typ1) && ispointer(typ2)) { if (exact) { int arr = FALSE; int first = TRUE; while (ispointer(typ1) && ispointer(typ2)) { if (!first && (exact == 1)) if ((isconst(typ2) && !isconst(typ1)) || (isvolatile(typ2) && !isvolatile(typ1))) return FALSE; first = FALSE; typ1 = basetype(typ1); typ2 = basetype(typ2); if (typ1->type != typ2->type) return FALSE; if (arr && typ1->array != typ2->array) return FALSE; if (arr && typ1->size != typ2->size) return FALSE; arr |= typ1->array | typ2->array; typ1 = typ1->btp; typ2 = typ2->btp; } if (exact == 1 && ((isconst(typ2) && !isconst(typ1)) || (isvolatile(typ2) && !isvolatile(typ1)))) return FALSE; return comparetypes(typ1, typ2, TRUE); } else return TRUE; } typ1 = basetype(typ1); typ2 = basetype(typ2); if (exact && (isfunction(typ1) || isfuncptr(typ1)) && (isfunction(typ2) || isfuncptr(typ2))) { HASHREC *hr1; HASHREC *hr2; typ1 = basetype(typ1); typ2 = basetype(typ2); if (ispointer(typ1)) typ1 = basetype(typ1)->btp; if (ispointer(typ2)) typ2 = basetype(typ2)->btp; if (!comparetypes(typ1->btp, typ2->btp, exact)) return FALSE; if (!matchOverload(typ1, typ2, TRUE)) return FALSE; return TRUE; } if (cparams.prm_cplusplus) { if (typ1->scoped != typ2->scoped) return FALSE; if (typ1->type == bt_enum) { if (typ2->type == bt_enum) return typ1->sp == typ2->sp; else return isint(typ2); } else if (typ2->type == bt_enum) { return isint(typ1); } if (typ1->type == typ2->type && typ1->type == bt_memberptr) { if (typ1->sp != typ2->sp) { if (classRefCount(typ1->sp, typ2->sp) != 1) return FALSE; } return comparetypes(typ1->btp, typ2->btp, exact); } } if (typ1->type == typ2->type && (isstructured(typ1) || (exact && typ1->type == bt_enum))) return typ1->sp == typ2->sp; if (typ1->type == typ2->type || (!exact && isarithmetic(typ2) && isarithmetic(typ1))) return TRUE; if (isfunction(typ1) && isfunction(typ2) && typ1->sp->linkage == typ2->sp->linkage) return TRUE; else if (!exact && ((ispointer(typ1) && (isfuncptr(typ2) || isfunction(typ2) || isint(typ2))) || (ispointer(typ2) && (isfuncptr(typ1) || isfunction(typ1) || isint(typ1))))) return (TRUE); else if (typ1->type == bt_enum && isint(typ2)) { return TRUE; } else if (typ2->type == bt_enum && isint(typ1)) { return TRUE; } return FALSE; }