element* findobject(scope* pscope, namenode* node, kindof kind){ if(LDEBUG) fprintf(stderr, "findobject(): finding %s in scope %s\n", node->name.c_str(), pscope->lexeme.c_str()); //printsymtbl(pscope->symtbl); //if(pscope == NULL) return NULL; element* e; namenode* n = new namenode(); n->name = node->name; n->next = NULL; element* first = findtype(pscope, n, KALL); if(first!=NULL){ if(LDEBUG) fprintf(stderr, "findobject(): %s found\n", node->name.c_str()); e = findobjectinthisorsuper(first, node->next, true); return e; } scope* s = pscope->parent; unordered_map<string, element*>::iterator it; while(s != NULL){ //printf("findtype(): finding %s in scope %s\n", node->name.c_str(), s->lexeme.c_str()); //printsymtbl(s->symtbl); n->name = node->name; n->next = NULL; first = findtype(pscope, n, KALL); if(first!=NULL){ e = findobjectinthisorsuper(first, node->next, true); if(e!=NULL && (kind == KALL || e->kind == kind)) return e; } s = s->parent; } fprintf(stderr, "error at line #%d: %s does not exist or is not accessible in this scope\n", line_number, node->name.c_str()); here(35); return makeIllegalNode(); }
/* * NAME: find() * DESCRIPTION: generic routine to locate and return a resource */ static const byte *find(rsrcmap *map, const char *type, int (*compare)(rsrcmap *, const byte *, const void *), const void *key) { const byte *ptr; short nitems; unsigned short rlistoff; ptr = findtype(map, type); if (ptr == 0) goto fail; ptr += 4; d_fetchsw(&ptr, &nitems); d_fetchuw(&ptr, &rlistoff); for (ptr = map->tlist + rlistoff; nitems >= 0; ptr += 12, --nitems) { if (compare(map, ptr, key)) break; } if (nitems < 0) ERROR(EINVAL, "resource not found"); return ptr; fail: return 0; }
void CTestCase::findsymbol(string symbol,string methodbody,string classname,CReadCpp *p) { int pos = methodbody.find(symbol); if(pos!=string::npos) { string valuename = ""; string typeofname =""; for(int i=pos-1;methodbody.at(i)!=' '&&methodbody.at(i)!='\t';i--) { valuename = methodbody.at(i) + valuename; } int pos2 = methodbody.find(valuename); typeofname = findtype(methodbody,valuename,pos); if(pos2 == string::npos) { for(int i=0;i<p->headfile.size();i++) { string headname = p->headfile.at(i); map<string,CReadH*>::iterator it; map<string,string>::iterator ite; it = hmap.find(headname); ite = it->second->classdef.find(classname); if(ite != it->second->classdef.end()) string typeofname = findtype(ite->second,valuename,ite->second.length()); } } if(typeofname!="") { map<string,CReadH*>::iterator it; for(it = hmap.begin();it!=hmap.end();++it) { map<string,string>::iterator ite; ite = it->second->classdef.find(typeofname); if(ite!=it->second->classdef.end()) { lastans += classname+" called "+typeofname + "\n"; break; } } } } }
/* * NAME: rsrc->count() * DESCRIPTION: return the number of resources of a given type */ int rsrc_count(rsrcfile *rfile, const char *type) { const byte *ptr; ptr = findtype(&rfile->map, type); if (ptr == 0) return 0; return d_getsw(ptr + 4) + 1; }
int public_userlistcmd(nick *np, channel *cp, int argc, char **argv) { account *tmp, **list; nicklist *nlp; bucket *bp; chanlevel *clp; char buffer[512], formatspace[512]; int i, j, x, count, state, nicks; i = j = x = count = state = 0; if (!argc && CAtleastVoice(np->account->dbuser)) /* So the user can safely request the global userlist too */ cp = NULL; if (!cp && !CAtleastVoice(np->account->dbuser)) { irc_write(QUEUE_NORMAL, "NOTICE %s :try userlist <#channel>", np->name); return 0; } else if (cp && (((clp = findchanlevel(cp, np->account)) && CAtleastKnown(clp)) || (CAtleastOp(np->account->dbuser)))) { /* View the userlist for a channel */ printlog("Userlist - channel %s", cp->name); for (i = DBF_OWNER; i; i >>= 1) { buffer[0] = '\0'; count = 0; for (clp = cp->chanlevels; clp; clp = clp->nextbychan) { if ((clp->flags & i) && !(clp->account->status & USTAT_ISMARKED)) { if (clp->account->loggedin) { nicks = 0; for (nlp = clp->account->nicks; nlp; nlp = nlp->next) { snprintf(formatspace, sizeof(formatspace), "%s%s%s%s%s", (count++ && !nicks) ? " " : "", !nicks ? "[" : "", nicks ? ", " : "", nlp->nick->name, (nlp->next == NULL) ? "]" : ""); strcat(buffer, formatspace); } } else { snprintf(formatspace, sizeof(formatspace), "%s[#%s]", count++ ? " " : "", clp->account->name); strcat(buffer, formatspace); } clp->account->status |= USTAT_ISMARKED; } if ((count > 10) || (count && strlen(buffer))) { if (!state) { irc_write(QUEUE_SLOW, "NOTICE %s :userlist for %s:", np->name, cp->name); state = 1; } irc_write(QUEUE_SLOW, "NOTICE %s :channel %s%s: %s", np->name, findtype(i), (count == 1) ? "" : "s", buffer); count = 0; } } } for (clp = cp->chanlevels; clp; clp = clp->nextbychan) clp->account->status &= ~USTAT_ISMARKED; } else {
/* * Look at the string 'bp' and decode the boot device. * Boot names look like: '/pci/scsi@c/disk@0,0/bsd' * '/pci/mac-io/ide@20000/disk@0,0/bsd * '/pci/mac-io/ide/disk/bsd * '/ht@0,f2000000/pci@2/bcom5704@4/bsd' */ void parseofwbp(char *bp) { int ptype; char *dev, *cp; struct devmap *dp; cp = bp; do { while(*cp && *cp != '/') cp++; dp = findtype(&cp); if (!dp->att) { printf("Warning: bootpath unrecognized: %s\n", bp); return; } } while((dp->type & T_IFACE) == 0); if (dp->att && dp->type == T_IFACE) { bootdev_class = DV_IFNET; bootdev_type = dp->type; strlcpy(bootdev, dp->dev, sizeof bootdev); return; } dev = dp->dev; while(*cp && *cp != '/') cp++; ptype = dp->type; dp = findtype(&cp); if (dp->att && dp->type == T_DISK) { bootdev_class = DV_DISK; bootdev_type = ptype; bootdev_unit = getpno(&cp); return; } printf("Warning: boot device unrecognized: %s\n", bp); }
/* * NAME: rsrc->getind() * DESCRIPTION: return a resource by type/index */ void *rsrc_getind(rsrcfile *rfile, const char *type, int index) { const byte *ptr; short nitems; rsrchandle *rsrc; ptr = findtype(&rfile->map, type); if (ptr == 0) goto fail; nitems = d_getsw(ptr + 4) + 1; if (index < 1 || index > nitems) ERROR(EINVAL, "index out of range"); rsrc = load(rfile, rfile->map.tlist + d_getsw(ptr + 6) + 12 * (index - 1)); if (rsrc == 0) goto fail; return getrdata(rsrc); fail: return 0; }
/* * It all starts here... */ int main(int argc, char *argv[]) { int i; char tmpfname[256], *cp, *ifile; opterr = nflag = mflag = 0; active = NULL; fofile = hofile = NULL; /* * Deal with the command-line options. */ while ((i = getopt(argc, argv, "h:t:o:xNmv")) != -1) { switch (i) { case 'h': hofile = optarg; break; case 't': if ((active = findtype(optarg)) == NULL) { fprintf(stderr, "dbow: unsupported code type: %s\n", optarg); exit(1); } break; case 'o': fofile = optarg; break; #ifdef YYDEBUG case 'x': yydebug = 1; break; #endif case 'm': mflag = 1; break; case 'N': nflag = 1; break; case 'v': printf("DBOW version %s\n", DBOW_VERSION); exit(0); break; default: usage(); break; } } /* * The default generator is for C code. */ if (active == NULL && (active = findtype("c")) == NULL) { fprintf(stderr, "dbow: can't find default generator type.\n"); exit(1); } /* * Make sure we have an input file, and call the lexical * analyzer to open it. Report an error if that doesn't work. */ if ((argc - optind) != 1) usage(); ifile = strdup(argv[optind]); if (lexopen(ifile) < 0) { fprintf(stderr, "dbow: "); perror(ifile); exit(1); } /* * If no output file has been specified, then carve an * output file by changing the <file>.d to <file>.<fext> * where 'fext' is the generators file extension. */ if (fofile == NULL) { strncpy(tmpfname, ifile, sizeof(tmpfname) - 5); if ((cp = strrchr(tmpfname, '.')) != NULL && cp[1] == 'd' && cp[2] == '\0') { *cp = '\0'; } else cp = strchr(tmpfname, '\0'); *cp++ = '.'; if (mflag) strcpy(cp, "m4"); else strcpy(cp, active->fext); if ((cp = strrchr(tmpfname, '/')) != NULL) cp++; else cp = tmpfname; fofile = strdup(cp); } /* * Open the pipe to the M4 command. * XXX - don't use M4 when generating SQL (for now!). */ if (mflag || active->cdtype == CDT_DBASE) { if (strcmp(fofile, "-") == 0) fofp = stdout; else if ((fofp = fopen(fofile, "w")) == NULL) { fprintf(stderr, "dbow: cannot open file for writing: "); perror(fofile); exit(1); } hofile = NULL; } else fofp = m4open(fofile, active); linesync(ifile, 1, fofp); if (hofile == NULL) hofp = fofp; else { hofp = m4open(hofile, active); linesync(ifile, 1, hofp); } tofp = NULL; /* * Parse the input file using YACC and close the input stream. * If there are no errors, call each table generator. */ nerrors = 0; yyparse(); lexclose(); if (nerrors == 0) { /* * Perform function optimizations and check all * tables to make sure they have the basic quorum * of functions. */ functioncleanup(); /* * If we've diverted the prolog to a separate file, then * we'll need to include it in the main file. */ if (fofp != hofp) fileinc(hofile, fofp); doproto(ifile, 0); docode(NULL, 0); /* * Emit the epilog code. */ genepilog(fofp); if (hofp != fofp) genepilog(hofp); if (tofp != NULL) { fclose(tofp); if ((tofp = fopen(tofile, "r")) != NULL) { while ((i = fgetc(tofp)) != EOF) fputc(i, fofp); fclose(tofp); } unlink(tofile); } } /* * Close out the output file (and delete it if it's bad), * then exit. */ pclose(fofp); if (hofp != fofp) pclose(hofp); exit(nerrors > 0 ? 1 : 0); }
/* * Read a type and return the index of this type. */ static u_short inptype(const char *cp, const char **epp) { char c, s, *eptr; const char *ep; type_t *tp; int narg, i, osdef = 0; size_t tlen; u_short tidx, sidx; int h; /* If we have this type already, return it's index. */ tlen = gettlen(cp, &ep); h = thash(cp, tlen); if ((tidx = findtype(cp, tlen, h)) != 0) { *epp = ep; return (tidx); } /* No, we must create a new type. */ tp = xalloc(sizeof (type_t)); tidx = storetyp(tp, cp, tlen, h); c = *cp++; while (c == 'c' || c == 'v') { if (c == 'c') { tp->t_const = 1; } else { tp->t_volatile = 1; } c = *cp++; } if (c == 's' || c == 'u' || c == 'l' || c == 'e') { s = c; c = *cp++; } else { s = '\0'; } switch (c) { case 'C': tp->t_tspec = s == 's' ? SCHAR : (s == 'u' ? UCHAR : CHAR); break; case 'S': tp->t_tspec = s == 'u' ? USHORT : SHORT; break; case 'I': tp->t_tspec = s == 'u' ? UINT : INT; break; case 'L': tp->t_tspec = s == 'u' ? ULONG : LONG; break; case 'Q': tp->t_tspec = s == 'u' ? UQUAD : QUAD; break; case 'D': tp->t_tspec = s == 's' ? FLOAT : (s == 'l' ? LDOUBLE : DOUBLE); break; case 'V': tp->t_tspec = VOID; break; case 'P': tp->t_tspec = PTR; break; case 'A': tp->t_tspec = ARRAY; break; case 'F': case 'f': osdef = c == 'f'; tp->t_tspec = FUNC; break; case 'T': tp->t_tspec = s == 'e' ? ENUM : (s == 's' ? STRUCT : UNION); break; } switch (tp->t_tspec) { case ARRAY: tp->t_dim = (int)strtol(cp, &eptr, 10); cp = eptr; sidx = inptype(cp, &cp); /* force seq. point! (ditto below) */ tp->t_subt = TP(sidx); break; case PTR: sidx = inptype(cp, &cp); tp->t_subt = TP(sidx); break; case FUNC: c = *cp; if (isdigit((u_char)c)) { if (!osdef) tp->t_proto = 1; narg = (int)strtol(cp, &eptr, 10); cp = eptr; if ((tp->t_args = calloc((size_t)(narg + 1), sizeof (type_t *))) == NULL) nomem(); for (i = 0; i < narg; i++) { if (i == narg - 1 && *cp == 'E') { tp->t_vararg = 1; cp++; } else { sidx = inptype(cp, &cp); tp->t_args[i] = TP(sidx); } } } sidx = inptype(cp, &cp); tp->t_subt = TP(sidx); break; case ENUM: tp->t_tspec = INT; tp->t_isenum = 1; /* FALLTHROUGH */ case STRUCT: case UNION: switch (*cp++) { case '1': tp->t_istag = 1; tp->t_tag = hsearch(inpname(cp, &cp), 1); break; case '2': tp->t_istynam = 1; tp->t_tynam = hsearch(inpname(cp, &cp), 1); break; case '3': tp->t_isuniqpos = 1; tp->t_uniqpos.p_line = strtol(cp, &eptr, 10); cp = eptr; cp++; /* xlate to 'global' file name. */ tp->t_uniqpos.p_file = addoutfile(inpfns[strtol(cp, &eptr, 10)]); cp = eptr; cp++; tp->t_uniqpos.p_uniq = strtol(cp, &eptr, 10); cp = eptr; break; } break; case LONG: case VOID: case LDOUBLE: case DOUBLE: case FLOAT: case UQUAD: case QUAD: case ULONG: case UINT: case INT: case USHORT: case SHORT: case UCHAR: case SCHAR: case CHAR: case UNSIGN: case SIGNED: case NOTSPEC: break; } *epp = cp; return (tidx); }
int main(int argc, char *argv[]) { char *types = NULL, data[512] = "", *resolvpath = NULL; char *files[] = { "/proc/mounts", "/etc/fstab", NULL }; const char *source, *target; struct mntent *me = NULL; int aflag = 0, oflag = 0, status = 0, i, r; unsigned long flags = 0; FILE *fp; ARGBEGIN { case 'B': argflags |= MS_BIND; break; case 'M': argflags |= MS_MOVE; break; case 'R': argflags |= MS_REC; break; case 'a': aflag = 1; break; case 'o': oflag = 1; argopts = EARGF(usage()); parseopts(argopts, &flags, data, sizeof(data)); break; case 't': types = EARGF(usage()); break; case 'n': break; default: usage(); } ARGEND; if (argc < 1 && aflag == 0) { if (!(fp = fopen(files[0], "r"))) eprintf("fopen %s:", files[0]); concat(fp, files[0], stdout, "<stdout>"); fclose(fp); return 0; } if (aflag == 1) goto mountall; source = argv[0]; target = argv[1]; if (!target) { target = argv[0]; source = NULL; if (!(resolvpath = realpath(target, NULL))) eprintf("realpath %s:", target); target = resolvpath; } for (i = 0; files[i]; i++) { if (!(fp = setmntent(files[i], "r"))) { if (strcmp(files[i], "/proc/mounts") != 0) weprintf("setmntent %s:", files[i]); continue; } while ((me = getmntent(fp))) { if (strcmp(me->mnt_dir, target) == 0 || strcmp(me->mnt_fsname, target) == 0 || (source && strcmp(me->mnt_dir, source) == 0) || (source && strcmp(me->mnt_fsname, source) == 0)) { if (!source) { target = me->mnt_dir; source = me->mnt_fsname; } if (!oflag) parseopts(me->mnt_opts, &flags, data, sizeof(data)); if (!types) types = me->mnt_type; goto mountsingle; } } endmntent(fp); fp = NULL; } if (!source) eprintf("can't find %s in /etc/fstab\n", target); mountsingle: r = mounthelper(source, target, types); if (r == -1) status = 1; if (r > 0 && mount(source, target, types, argflags | flags, data) < 0) { weprintf("mount: %s:", source); status = 1; } if (fp) endmntent(fp); free(resolvpath); return status; mountall: if (!(fp = setmntent("/etc/fstab", "r"))) eprintf("setmntent %s:", "/etc/fstab"); while ((me = getmntent(fp))) { /* has "noauto" option or already mounted: skip */ if (hasmntopt(me, MNTOPT_NOAUTO) || mounted(me->mnt_dir)) continue; flags = 0; parseopts(me->mnt_opts, &flags, data, sizeof(data)); /* if -t types specified: * if non-match, skip * if match and prefixed with "no", skip */ if (types && ((types[0] == 'n' && types[1] == 'o' && findtype(types + 2, me->mnt_type)) || (!findtype(types, me->mnt_type)))) continue; r = mounthelper(me->mnt_fsname, me->mnt_dir, me->mnt_type); if (r > 0 && mount(me->mnt_fsname, me->mnt_dir, me->mnt_type, argflags | flags, data) < 0) { weprintf("mount: %s:", me->mnt_fsname); status = 1; } } endmntent(fp); return status; }