const char* pzinit(register Pz_t* pz, register const char* name, Pzinit_f initf) { const char* options; const char* usage; char* id; options = pz->disc->options; if (!(usage = (*initf)(pz, pz->disc))) { if (pz->disc && pz->disc->errorf) { if (id = strchr((char*)state.id, ':')) id++; else id = (char*)state.id; (*pz->disc->errorf)(pz, pz->disc, 2, "%s: %s_init: initialization function error", name, id); } return 0; } optget(NiL, usage); if (pz->disc->options != options) { if (!pz->disc->options) pz->options = 0; else if (!(pz->options = vmstrdup(pz->vm, pz->disc->options))) { pznospace(pz); return 0; } } if (pz->options && pzoptions(pz, pz->part, pz->options, 0) < 0) return 0; return usage; }
Pssent_t* psssave(register Pss_t* pss, register Pssent_t* pe) { register unsigned long fields = pss->disc->fields & pss->meth->fields; if ((fields & PSS_args) && pe->args) pe->args = vmstrdup(pss->vm, pe->args); if ((fields & PSS_command) && pe->command) pe->command = vmstrdup(pss->vm, pe->command); if ((fields & PSS_sched) && pe->sched) pe->sched = vmstrdup(pss->vm, pe->sched); if ((fields & PSS_tty) && pe->ttyname) pe->ttyname = vmstrdup(pss->vm, pe->ttyname); pss->ent = 0; return pe; }
char* exstash(Sfio_t* sp, Vmalloc_t* vp) { char* s; return ((s = sfstruse(sp)) && (!vp || (s = vmstrdup(vp, s)))) ? s : exnospace(); }
static int loadextractorso ( DDSschema_t *schemap, char *sofile, int rmflag, DDSextractor_t *extractorp ) { char *ename, *elist; DDSfield_t *fields; int fieldn; if ( !(extractorp->handle = dlopen (sofile, RTLD_LAZY)) || !(extractorp->init = (DDSextractorinitfunc) dlsym ( extractorp->handle, sfprints ("extractor_%s_init", schemap->name) )) || !(extractorp->term = (DDSextractortermfunc) dlsym ( extractorp->handle, sfprints ("extractor_%s_term", schemap->name) )) || !(extractorp->work = (DDSextractorworkfunc) dlsym ( extractorp->handle, sfprints ("extractor_%s_work", schemap->name) )) || !(ename = (char *) dlsym ( extractorp->handle, sfprints ("extractor_%s_ename", schemap->name) )) || !(elist = (char *) dlsym ( extractorp->handle, sfprints ("extractor_%s_elist", schemap->name) )) ) { SUwarning (1, "loadextractorso", "init failed: %s", dlerror ()); return -1; } if (!(elist = vmstrdup (Vmheap, elist))) { SUwarning (1, "loadextractorso", "vmstrdup failed"); return -1; } if ((fieldn = _ddslist2fields (elist, schemap, &fields, NULL, NULL)) < 0) { SUwarning (1, "loadextractorso", "list2fields failed"); return -1; } vmfree (Vmheap, elist); if (!(extractorp->schemap = DDScreateschema ( ename, fields, fieldn, NULL, NULL ))) { SUwarning (1, "loadextractorso", "DDScreateschema failed"); return -1; } if (rmflag) unlink (sofile); return 0; }
static obj_t *objinsert (char *op) { obj_t *objmem, *objp; if (!(objmem = (obj_t *) vmalloc (Vmheap, sizeof (obj_t)))) { sfprintf (sfstderr, "cannot allocate obj\n"); return NULL; } memset (objmem, 0, sizeof (obj_t)); if (!(objmem->obj = vmstrdup (Vmheap, op))) { sfprintf (sfstderr, "cannot allocate obj id\n"); return NULL; } if ((objp = (obj_t *) dtinsert (objdict, objmem)) != objmem) { sfprintf (sfstderr, "cannot insert obj in dict\n"); return NULL; } return objp; }
static opn_t *opninsert ( int kind, char *mname, char *mtype, char *munit, char *op, char *pp, char *np, char *lp ) { opn_t *opnmem, *opnp; if (!(opnmem = (opn_t *) vmalloc (Vmheap, sizeof (opn_t)))) { sfprintf (sfstderr, "cannot allocate opn\n"); return NULL; } memset (opnmem, 0, sizeof (opn_t)); if (!(opnmem->opn = vmstrdup (Vmheap, sfprints ( "%s.%s.%s", op, pp, np )))) { sfprintf (sfstderr, "cannot allocate opn id\n"); return NULL; } if ((opnp = (opn_t *) dtinsert (opndict, opnmem)) != opnmem) { sfprintf (sfstderr, "cannot insert opn in dict\n"); return NULL; } opnp->kind = kind; if ( !(opnp->mname = vmstrdup (Vmheap, mname)) || !(opnp->mtype = vmstrdup (Vmheap, mtype)) || !(opnp->munit = vmstrdup (Vmheap, munit)) || !(opnp->op = vmstrdup (Vmheap, op)) || !(opnp->pp = vmstrdup (Vmheap, pp)) || !(opnp->np = vmstrdup (Vmheap, np)) || !(opnp->lp = vmstrdup (Vmheap, lp)) ) { sfprintf (sfstderr, "cannot allocate o p n\n"); return NULL; } return opnp; }
IMPLLed_t *IMPLLinserted (IMPLLnd_t *ndp1, IMPLLnd_t *ndp2, char *attrstr) { IMPLLed_t ed, *edp, *edmem; UTattr_t *ap; EMbb_t bb; ed.ndp1 = ndp1; ed.ndp2 = ndp2; if ((edp = dtsearch (eddict, &ed))) return edp; if (!(edmem = vmalloc (Vmheap, sizeof (IMPLLed_t)))) { SUwarning (0, "IMPLLinserted", "cannot allocate edmem"); return NULL; } memset (edmem, 0, sizeof (IMPLLed_t)); edmem->ndp1 = ndp1, edmem->ndp2 = ndp2; if ((edp = dtinsert (eddict, edmem)) != edmem) { SUwarning (0, "IMPLLinserted", "cannot insert ed"); vmfree (Vmheap, edmem); return NULL; } if (UTsplitattr (UT_ATTRGROUP_EDGE, attrstr) == -1) { SUwarning (0, "IMPLLinserted", "cannot parse attrstr"); return NULL; } if (UTgetattrs (UT_ATTRGROUP_EDGE) == -1) { SUwarning (0, "IMPLLinserted", "cannot get edge attr"); return NULL; } ap = &UTattrgroups[UT_ATTRGROUP_EDGE][UT_ATTR_LABEL]; if ( ap->value && strcmp (ap->name, "label") == 0 && strncmp (ap->value, "EMBED:", 6) == 0 ) { if (EMparseedge ( ndp1->level, ndp1->id, ndp2->level, ndp2->id, ap->value + 6, EM_DIR_V, &edp->opi, &edp->opn, &bb ) == -1) { SUwarning (0, "IMPLLinserted", "cannot parse edge EM contents"); return NULL; } } ap = &UTattrgroups[UT_ATTRGROUP_EDGE][UT_ATTR_LINEWIDTH]; edp->lw = (ap->value && ap->value[0]) ? atoi (ap->value) : 1; ap = &UTattrgroups[UT_ATTRGROUP_EDGE][UT_ATTR_COLOR]; if (!(edp->cl = vmstrdup ( Vmheap, (ap->value && ap->value[0]) ? ap->value : "black" ))) { SUwarning (0, "IMPLLinserted", "cannot copy edge color"); return NULL; } ap = &UTattrgroups[UT_ATTRGROUP_EDGE][UT_ATTR_FONTNAME]; if (!(edp->fn = vmstrdup ( Vmheap, (ap->value && ap->value[0]) ? ap->value : "abc" ))) { SUwarning (0, "IMPLLinserted", "cannot copy edge font name"); return NULL; } ap = &UTattrgroups[UT_ATTRGROUP_EDGE][UT_ATTR_FONTSIZE]; if (!(edp->fs = vmstrdup ( Vmheap, (ap->value && ap->value[0]) ? ap->value : "10" ))) { SUwarning (0, "IMPLLinserted", "cannot copy edge font size"); return NULL; } ap = &UTattrgroups[UT_ATTRGROUP_EDGE][UT_ATTR_INFO]; if (!(edp->info = vmstrdup ( Vmheap, (ap->value && ap->value[0]) ? ap->value : "" ))) { SUwarning (0, "IMPLLinserted", "cannot copy edge info"); return NULL; } return edp; }
static int load (char *id, char *file) { EMnode_t n, *np, *nmem; EMedge_t e, *ep, *emem; EMrec_t *rp, **rsp; int *rnp, *rmp; Sfio_t *fp; char *line, *s1, *s2, *s3, *s4, *s5, *s6, *s7; if (!(fp = sfopen (NULL, file, "r"))) { SUwarning (0, "load", "cannot open embed info file"); return 0; } while ((line = sfgetr (fp, '\n', 1))) { np = NULL; ep = NULL; if (!(s1 = strchr (line, '|'))) { SUwarning (0, "load", "bad line(1): %s", line); continue; } *s1++ = 0; if (line[0] == 'N' || line[0] == 'n') { if (!(s2 = strchr (s1, '|')) || !(s3 = strchr (s2 + 1, '|'))) { SUwarning (0, "load", "bad line(2): %s", s1); continue; } *s2++ = 0, *s3++ = 0; memset (&n, 0, sizeof (EMnode_t)); strcpy (n.level, s1); strcpy (n.id, s2); if (!(np = dtsearch (nodedict, &n))) { if (!(nmem = vmalloc (Vmheap, sizeof (EMnode_t)))) { SUwarning (0, "load", "cannot allocate nmem"); return -1; } memset (nmem, 0, sizeof (EMnode_t)); strcpy (nmem->level, s1); strcpy (nmem->id, s2); if (!(np = dtinsert (nodedict, nmem))) { SUwarning (0, "load", "cannot insert node"); vmfree (Vmheap, nmem); return -1; } } s1 = s3; rsp = &np->recs, rnp = &np->recn, rmp = &np->recm; } else if (line[0] == 'E' || line[0] == 'e') { if (!(s2 = strchr (s1, '|')) || !(s3 = strchr (s2 + 1, '|'))) { SUwarning (0, "load", "bad line(3): %s", s1); continue; } *s2++ = *s3++ = 0; if (!(s4 = strchr (s3, '|')) || !(s5 = strchr (s4 + 1, '|'))) { SUwarning (0, "load", "bad line(4): %s", s3); continue; } *s4++ = 0, *s5++ = 0; memset (&e, 0, sizeof (EMedge_t)); strcpy (e.level1, s1); strcpy (e.id1, s2); strcpy (e.level2, s3); strcpy (e.id2, s4); if (!(ep = dtsearch (edgedict, &e))) { if (!(emem = vmalloc (Vmheap, sizeof (EMedge_t)))) { SUwarning (0, "load", "cannot allocate emem"); return -1; } memset (emem, 0, sizeof (EMedge_t)); strcpy (emem->level1, s1); strcpy (emem->id1, s2); strcpy (emem->level2, s3); strcpy (emem->id2, s4); if (!(ep = dtinsert (edgedict, emem))) { SUwarning (0, "load", "cannot insert edge"); vmfree (Vmheap, emem); return -1; } } s1 = s5; rsp = &ep->recs, rnp = &ep->recn, rmp = &ep->recm; } if (!(s2 = strchr (s1, '|'))) { SUwarning (0, "load", "bad line(5): %s", s1); continue; } *s2++ = 0; if (*rmp >= *rnp) { if (!(*rsp = vmresize ( Vmheap, *rsp, (*rnp + 5) * sizeof (EMrec_t), VM_RSCOPY ))) { SUwarning (0, "load", "cannot grow recs array"); return -1; } *rnp += 5; } rp = &(*rsp)[*rmp], (*rmp)++; if (!(rp->id = vmstrdup (Vmheap, id))) { SUwarning (0, "load", "cannot copy id"); return -1; } if (s1[0] == 'I' || s1[0] == 'i') { if (!(s3 = strchr (s2, '|'))) { SUwarning (0, "load", "bad line(6): %s", s2); continue; } if (!(s4 = strchr (s3 + 1, '|')) || !(s5 = strchr (s4 + 1, '|'))) { SUwarning (0, "load", "bad line(7): %s", s3); continue; } if (!(s6 = strchr (s5 + 1, '|')) || !(s7 = strchr (s6 + 1, '|'))) { SUwarning (0, "load", "bad line(8): %s", s5); continue; } *s3++ = *s4++ = *s5++ = *s6++ = *s7++ = 0; rp->type = EM_TYPE_I; if (!(rp->u.i.file = vmstrdup (Vmheap, s2))) { SUwarning (0, "load", "cannot copy file"); return -1; } rp->u.i.x1 = atoi (s3), rp->u.i.y1 = atoi (s4); rp->u.i.x2 = atoi (s5), rp->u.i.y2 = atoi (s6); } else if (s1[0] == 'S' || s1[0] == 's') { if (!(s3 = strchr (s2, '|'))) { SUwarning (0, "load", "bad line(9): %s", s2); continue; } if (!(s4 = strchr (s3 + 1, '|')) || !(s5 = strchr (s4 + 1, '|'))) { SUwarning (0, "load", "bad line(10): %s", s3); continue; } if (!(s6 = strchr (s5 + 1, '|')) || !(s7 = strchr (s6 + 1, '|'))) { SUwarning (0, "load", "bad line(11): %s", s5); continue; } *s3++ = *s4++ = *s5++ = *s6++ = *s7++ = 0; rp->type = EM_TYPE_S; if ( !(rp->u.s.fn = vmstrdup (Vmheap, s2)) || !(rp->u.s.fs = vmstrdup (Vmheap, s3)) || !(rp->u.s.flcl = vmstrdup (Vmheap, s4)) || !(rp->u.s.lncl = vmstrdup (Vmheap, s5)) || !(rp->u.s.fncl = vmstrdup (Vmheap, s6)) ) { SUwarning (0, "load", "cannot copy style"); return -1; } } if (!(rp->im = vmstrdup (Vmheap, s7))) { SUwarning (0, "load", "cannot copy image map"); return -1; } } sfclose (fp); return 0; }
int main (int argc, char **argv) { int norun; char *rulesfile, *statefile; int newflag, checkflag; Sfio_t *ifp, *ofp; int osm; DDSschema_t *schemap; DDSheader_t hdr; int ret; VG_alarm_t adata; ruleev_t *ruleevp; cc_t *ccp; nd_t *ndp; ev_t *evp; sl_inv_nd2cc_t *nd2ccp; char *currdate, *s; int maxalarmkeepmin; schemap = NULL; osm = DDS_HDR_NAME | DDS_HDR_DESC; rulesfile = NULL; statefile = NULL; currdate = NULL; newflag = FALSE; checkflag = FALSE; norun = 0; for (;;) { switch (optget (argv, usage)) { case -100: rulesfile = opt_info.arg; continue; case -101: statefile = opt_info.arg; continue; case -102: currdate = opt_info.arg; continue; case -200: newflag = TRUE; continue; case -201: checkflag = TRUE; continue; case -999: SUwarnlevel++; continue; case '?': SUusage (0, "vggce", opt_info.arg); norun = 1; continue; case ':': SUusage (1, "vggce", opt_info.arg); norun = 2; continue; } break; } if (norun) return norun - 1; argc -= opt_info.index, argv += opt_info.index; ifp = ofp = NULL; if (!rulesfile || !statefile || !currdate || strlen (currdate) != 10) { SUwarning (0, "vggce", "missing arguments"); goto failsafe1; } DDSinit (); if (!(ifp = SUsetupinput (sfstdin, 1048576))) { SUwarning (0, "vggce", "setupinput failed"); goto failsafe1; } if (!(ofp = SUsetupoutput (NULL, sfstdout, 1048576))) { SUwarning (0, "vggce", "setupoutput failed"); goto failsafe1; } if ((ret = DDSreadheader (ifp, &hdr)) == -1) { SUwarning (0, "vggce", "DDSreadheader failed"); goto failsafe1; } if (ret == -2) goto done; if (ret == 0) { if (hdr.schemap) schemap = hdr.schemap; } if (!schemap) { SUwarning (0, "vggce", "DDSloadschema failed"); goto failsafe1; } if (!hdr.schemap && schemap) hdr.schemap = schemap; hdr.contents = osm; hdr.vczspec = ""; if (osm && DDSwriteheader (ofp, &hdr) == -1) { SUwarning (0, "vggce", "DDSwriteheader failed"); goto failsafe1; } s = getenv ("DEFAULTTMODE"); if (!(ftmode = vmstrdup (Vmheap, s ? s : VG_ALARM_S_MODE_KEEP))) { SUwarning (0, "vggce", "cannot copy tmode"); goto failsafe1; } if ((rtmode = strchr (ftmode, ':'))) *rtmode++ = 0; else rtmode = ftmode; currtime = 0; maxalarmkeepmin = atoi (getenv ("MAXALARMKEEPMIN")); sl_inv_nd2ccopen (getenv ("INVND2CCFILE")); if (sevmapload (getenv ("SEVMAPFILE")) == -1) { SUwarning (0, "vggce", "cannot load sevmap file"); goto failsafe1; } if (initgraph () == -1) { SUwarning (0, "vggce", "initgraph failed"); goto failsafe1; } if (initcorr () == -1) { SUwarning (0, "vggce", "initcorr failed"); goto failsafe1; } if (loadrules (rulesfile) == -1) { SUwarning (0, "vggce", "loadrules failed"); goto failsafe1; } if (checkflag) goto done; if (!newflag && loadevstate (statefile) == -1) { SUwarning (0, "vggce", "loadstate failed"); goto failsafe1; } ccmark++; evmark++; while (( ret = DDSreadrecord (ifp, &adata, schemap) ) == sizeof (VG_alarm_t)) { VG_warning (0, "GCE INFO", "read alarm %s", adata.s_text); if ( !DATEMATCH (currdate, adata.s_dateissued) || adata.s_sortorder != VG_ALARM_N_SO_NORMAL || adata.s_pmode != VG_ALARM_N_PMODE_PROCESS ) goto write; if (currtime < adata.s_timeissued) currtime = adata.s_timeissued; if (!(ruleevp = matchruleev (&adata))) goto write; if (!(nd2ccp = sl_inv_nd2ccfind (adata.s_level1, adata.s_id1))) goto write; if (!(ccp = insertcc (nd2ccp->sl_cclevel, nd2ccp->sl_ccid, TRUE))) { SUwarning (0, "vggce", "cannot insert cc %s", nd2ccp->sl_ccid); goto failsafe1; } if (ccp->svcpm < 1) goto write; if (!(ndp = findnd (adata.s_level1, adata.s_id1))) { SUwarning (0, "vggce", "cannot find nd %s", adata.s_id1); goto failsafe1; } if (!(evp = insertev ( adata.s_timeissued, adata.s_type, ccp, ndp, ruleevp ))) { SUwarning (0, "vggce", "cannot insert ev"); goto failsafe1; } if (evp->svcpm < 1) goto write; if (insertndevent (ndp, evp) == -1) { SUwarning (0, "vggce", "cannot insert ev in nd"); goto failsafe1; } write: if (DDSwriterecord (ofp, &adata, schemap) != sizeof (VG_alarm_t)) { SUwarning (0, "vggce", "cannot write alarm"); goto failsafe1; } VG_warning (0, "GCE INFO", "wrote alarm"); } ndmark++; if (pruneevs (currtime - 60 * maxalarmkeepmin, 1) == -1) { SUwarning (0, "vggce", "cannot prune evs (1)"); goto failsafe1; } calcsvcvalues (SVC_MODE_NOEV, -1, -1); calcsvcvalues (SVC_MODE_OLDEV, 0, 0); calcsvcvalues (SVC_MODE_NEWEV, 0, 1); if (updatealarms (SVC_MODE_OLDEV, SVC_MODE_NEWEV, 1) == -1) { SUwarning (0, "vggce", "cannot update alarms (1)"); goto failsafe1; } evmark++; // ccmark++; if (pruneevs (currtime - 60 * maxalarmkeepmin, 2) == -1) { SUwarning (0, "vggce", "cannot prune evs"); goto failsafe1; } calcsvcvalues (SVC_MODE_PRUNE, 2, 2); if (updatealarms (SVC_MODE_NEWEV, SVC_MODE_PRUNE, 2) == -1) { SUwarning (0, "vggce", "cannot update alarms (2)"); goto failsafe1; } if (saveevstate (statefile) == -1) { SUwarning (0, "vggce", "savestate failed"); goto failsafe1; } VG_warning (0, "GCE INFO", "events=%d", evpm); if (ret != 0) SUerror ("vggce", "failed to read full record"); done: DDSterm (); return 0; failsafe1: SUwarning (0, "vggce", "IN FAILSAFE MODE"); if (sfmove (ifp, ofp, -1, -1) == -1) SUwarning (0, "vggce", "cannot copy data"); return 101; }
int extoken_fn(register Expr_t* ex) { register int c; register char* s; register int q; char* e; if (ex->eof || ex->errors) return 0; again: for (;;) switch (c = lex(ex)) { case 0: goto eof; case '/': switch (q = lex(ex)) { case '*': for (;;) switch (lex(ex)) { case '\n': BUMP (error_info.line); continue; case '*': switch (lex(ex)) { case 0: goto eof; case '\n': BUMP (error_info.line); break; case '*': exunlex(ex, '*'); break; case '/': goto again; } break; } break; case '/': while ((c = lex(ex)) != '\n') if (!c) goto eof; break; default: goto opeq; } /*FALLTHROUGH*/ case '\n': BUMP (error_info.line); /*FALLTHROUGH*/ case ' ': case '\t': break; case '(': case '{': case '[': ex->input->nesting++; return exlval.op = c; case ')': case '}': case ']': ex->input->nesting--; return exlval.op = c; case '+': case '-': if ((q = lex(ex)) == c) return exlval.op = c == '+' ? INC : DEC; goto opeq; case '*': case '%': case '^': q = lex(ex); opeq: exlval.op = c; if (q == '=') c = '='; else if (q == '%' && c == '%') { if (ex->input->fp) ex->more = (const char*)ex->input->fp; else ex->more = ex->input->sp; goto eof; } else exunlex(ex, q); return c; case '&': case '|': if ((q = lex(ex)) == '=') { exlval.op = c; return '='; } if (q == c) c = c == '&' ? AND : OR; else exunlex(ex, q); return exlval.op = c; case '<': case '>': if ((q = lex(ex)) == c) { exlval.op = c = c == '<' ? LS : RS; if ((q = lex(ex)) == '=') c = '='; else exunlex(ex, q); return c; } goto relational; case '=': case '!': q = lex(ex); relational: if (q == '=') switch (c) { case '<': c = LE; break; case '>': c = GE; break; case '=': c = EQ; break; case '!': c = NE; break; } else exunlex(ex, q); return exlval.op = c; case '#': if (!ex->linewrap && !(ex->disc->flags & EX_PURE)) { s = ex->linep - 1; while (s > ex->line && isspace(*(s - 1))) s--; if (s == ex->line) { switch (extoken_fn(ex)) { case DYNAMIC: case ID: case NAME: s = exlval.id->name; break; default: s = ""; break; } if (streq(s, "include")) { if (extoken_fn(ex) != STRING) exerror("#%s: string argument expected", s); else if (!expush(ex, exlval.string, 1, NiL, NiL)) { setcontext(ex); goto again; } } else exerror("unknown directive"); } } return exlval.op = c; case '\'': case '"': q = c; sfstrset(ex->tmp, 0); ex->input->nesting++; while ((c = lex(ex)) != q) { if (c == '\\') { sfputc(ex->tmp, c); c = lex(ex); } if (!c) { exerror("unterminated %c string", q); goto eof; } if (c == '\n') { BUMP (error_info.line); } sfputc(ex->tmp, c); } ex->input->nesting--; s = sfstruse(ex->tmp); if (q == '"' || (ex->disc->flags & EX_CHARSTRING)) { if (!(exlval.string = vmstrdup(ex->vm, s))) goto eof; stresc(exlval.string); return STRING; } exlval.integer = chrtoi(s); return INTEGER; case '.': if (isdigit(c = lex(ex))) { sfstrset(ex->tmp, 0); sfputc(ex->tmp, '0'); sfputc(ex->tmp, '.'); goto floating; } exunlex(ex, c); return exlval.op = '.'; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': sfstrset(ex->tmp, 0); sfputc(ex->tmp, c); q = INTEGER; if ((c = lex(ex)) == 'x' || c == 'X') { sfputc(ex->tmp, c); for (;;) { switch (c = lex(ex)) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': sfputc(ex->tmp, c); continue; } break; } } else { while (isdigit(c)) { sfputc(ex->tmp, c); c = lex(ex); } if (c == '#') { sfputc(ex->tmp, c); /* s = sfstruse(ex->tmp); */ /* b = strtol(s, NiL, 10); */ do { sfputc(ex->tmp, c); } while (isalnum(c = lex(ex))); } else { if (c == '.') { floating: q = FLOATING; sfputc(ex->tmp, c); while (isdigit(c = lex(ex))) sfputc(ex->tmp, c); } if (c == 'e' || c == 'E') { q = FLOATING; sfputc(ex->tmp, c); if ((c = lex(ex)) == '-' || c == '+') { sfputc(ex->tmp, c); c = lex(ex); } while (isdigit(c)) { sfputc(ex->tmp, c); c = lex(ex); } } } } s = sfstruse(ex->tmp); if (q == FLOATING) exlval.floating = strtod(s, &e); else { if (c == 'u' || c == 'U') { q = UNSIGNED; c = lex(ex); exlval.integer = strToL(s, &e); } else exlval.integer = strToL(s, &e); if (*e) { *--e = 1; exlval.integer *= strton(e, &e, NiL, 0); } } exunlex(ex, c); if (*e || isalpha(c) || c == '_' || c == '$') { exerror("%s: invalid numeric constant", s); goto eof; } return q; default: if (isalpha(c) || c == '_' || c == '$') { sfstrset(ex->tmp, 0); sfputc(ex->tmp, c); while (isalnum(c = lex(ex)) || c == '_' || c == '$') sfputc(ex->tmp, c); exunlex(ex, c); s = sfstruse(ex->tmp); if (!(exlval.id = (Exid_t*)dtmatch(ex->symbols, s))) { if (!(exlval.id = newof(0, Exid_t, 1, strlen(s) - EX_NAMELEN + 1))) { exerror("out of space"); goto eof; } strcpy(exlval.id->name, s); exlval.id->lex = NAME; dtinsert((ex->formals || !ex->symbols->view) ? ex->symbols : ex->symbols->view, exlval.id); } /* * lexical analyzer state controlled by the grammar */ switch (exlval.id->lex) { case DECLARE: if (exlval.id->index == CHAR) { /* * `char*' === `string' * the * must immediately follow char */ if (c == '*') { lex(ex); exlval.id = id_string; } } break; case NAME: /* * action labels are disambiguated from ?: * through the expr.nolabel grammar hook * the : must immediately follow labels */ if (c == ':' && !expr.nolabel) return LABEL; break; case PRAGMA: /* * user specific statement stripped and * passed as string */ { int b; int n; int pc = 0; int po; int t; /*UNDENT...*/ sfstrset(ex->tmp, 0); b = 1; n = 0; po = 0; t = 0; for (c = t = lex(ex);; c = lex(ex)) { switch (c) { case 0: goto eof; case '/': switch (q = lex(ex)) { case '*': for (;;) { switch (lex(ex)) { case '\n': BUMP (error_info.line); continue; case '*': switch (lex(ex)) { case 0: goto eof; case '\n': BUMP (error_info.line); continue; case '*': exunlex(ex, '*'); continue; case '/': break; default: continue; } break; } if (!b++) goto eof; sfputc(ex->tmp, ' '); break; } break; case '/': while ((c = lex(ex)) != '\n') if (!c) goto eof; BUMP (error_info.line); b = 1; sfputc(ex->tmp, '\n'); break; default: b = 0; sfputc(ex->tmp, c); sfputc(ex->tmp, q); break; } continue; case '\n': BUMP (error_info.line); b = 1; sfputc(ex->tmp, '\n'); continue; case ' ': case '\t': if (!b++) goto eof; sfputc(ex->tmp, ' '); continue; case '(': case '{': case '[': b = 0; if (!po) { switch (po = c) { case '(': pc = ')'; break; case '{': pc = '}'; break; case '[': pc = ']'; break; } n++; } else if (c == po) n++; sfputc(ex->tmp, c); continue; case ')': case '}': case ']': b = 0; if (!po) { exunlex(ex, c); break; } sfputc(ex->tmp, c); if (c == pc && --n <= 0) { if (t == po) break; po = 0; } continue; case ';': b = 0; if (!n) break; sfputc(ex->tmp, c); continue; case '\'': case '"': b = 0; sfputc(ex->tmp, c); ex->input->nesting++; q = c; while ((c = lex(ex)) != q) { if (c == '\\') { sfputc(ex->tmp, c); c = lex(ex); } if (!c) { exerror("unterminated %c string", q); goto eof; } if (c == '\n') { BUMP (error_info.line); } sfputc(ex->tmp, c); } ex->input->nesting--; continue; default: b = 0; sfputc(ex->tmp, c); continue; } break; } (*ex->disc->reff)(ex, NiL, exlval.id, NiL, sfstruse(ex->tmp), 0, ex->disc); /*..INDENT*/ } goto again; } return exlval.id->lex; } return exlval.op = c; } eof: ex->eof = 1; return exlval.op = ';'; }
void initGPRState(Gpr_t * state, Vmalloc_t * vm) { state->tgtname = vmstrdup(vm, "gvpr_result"); }
static Extype_t eval(Expr_t* ex, register Exnode_t* expr, void* env) { register Exnode_t* x; register Exnode_t* a; register Extype_t** t; register int n; Extype_t v; Extype_t r; Extype_t i; char* e; Exnode_t tmp; Exassoc_t* assoc; Extype_t args[FRAME+1]; Extype_t save[FRAME]; if (!expr || ex->loopcount) { v.integer = 1; return v; } x = expr->data.operand.left; switch (expr->op) { case BREAK: case CONTINUE: v = eval(ex, x, env); ex->loopcount = v.integer; ex->loopop = expr->op; return v; case CONSTANT: return expr->data.constant.value; case DEC: n = -1; add: if (x->op == DYNAMIC) r = getdyn(ex, x, env, &assoc); else { if (x->data.variable.index) i = eval(ex, x->data.variable.index, env); else i.integer = EX_SCALAR; r = (*ex->disc->getf)(ex, x, x->data.variable.symbol, x->data.variable.reference, env, (int)i.integer, ex->disc); } v = r; switch (x->type) { case FLOATING: v.floating += n; break; case INTEGER: case UNSIGNED: v.integer += n; break; default: goto huh; } set: if (x->op == DYNAMIC) { if (x->type == STRING) { v.string = vmstrdup(ex->vm, v.string); if (e = assoc ? assoc->value.string : x->data.variable.symbol->value->data.constant.value.string) vmfree(ex->vm, e); } if (assoc) assoc->value = v; else x->data.variable.symbol->value->data.constant.value = v; } else { if (x->data.variable.index) i = eval(ex, x->data.variable.index, env); else i.integer = EX_SCALAR; if ((*ex->disc->setf)(ex, x, x->data.variable.symbol, x->data.variable.reference, env, (int)i.integer, v, ex->disc) < 0) exerror("%s: cannot set value", x->data.variable.symbol->name); } if (expr->subop == PRE) r = v; return r; case DYNAMIC: return getdyn(ex, expr, env, &assoc); case EXIT: v = eval(ex, x, env); exit((int)v.integer); /*NOTREACHED*/ v.integer = -1; return v; case IF: v = eval(ex, x, env); if (v.integer) eval(ex, expr->data.operand.right->data.operand.left, env); else eval(ex, expr->data.operand.right->data.operand.right, env); v.integer = 1; return v; case FOR: case WHILE: expr = expr->data.operand.right; for (;;) { r = eval(ex, x, env); if (!r.integer) { v.integer = 1; return v; } if (expr->data.operand.right) { eval(ex, expr->data.operand.right, env); if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop != CONTINUE)) { v.integer = 0; return v; } } if (expr->data.operand.left) eval(ex, expr->data.operand.left, env); } /*NOTREACHED*/ case SWITCH: v = eval(ex, x, env); i.integer = x->type; r.integer = 0; x = expr->data.operand.right; a = x->data.select.statement; n = 0; while (x = x->data.select.next) { if (!(t = x->data.select.constant)) n = 1; else for (; *t; t++) { switch ((int)i.integer) { case INTEGER: case UNSIGNED: if ((*t)->integer == v.integer) break; continue; case STRING: if ((ex->disc->version >= 19981111L && ex->disc->matchf) ? (*ex->disc->matchf)(ex, x, (*t)->string, expr->data.operand.left, v.string, env, ex->disc) : strmatch((*t)->string, v.string)) break; continue; case FLOATING: if ((*t)->floating == v.floating) break; continue; } n = 1; break; } if (n) { if (!x->data.select.statement) { r.integer = 1; break; } r = eval(ex, x->data.select.statement, env); if (ex->loopcount > 0) { ex->loopcount--; break; } } } if (!n && a) { r = eval(ex, a, env); if (ex->loopcount > 0) ex->loopcount--; } return r; case ITERATE: v.integer = 0; if (expr->data.generate.array->op == DYNAMIC) { n = expr->data.generate.index->type == STRING; for (assoc = (Exassoc_t*)dtfirst((Dt_t*)expr->data.generate.array->data.variable.symbol->local.pointer); assoc; assoc = (Exassoc_t*)dtnext((Dt_t*)expr->data.generate.array->data.variable.symbol->local.pointer, assoc)) { v.integer++; if (n) expr->data.generate.index->value->data.constant.value.string = assoc->name; else expr->data.generate.index->value->data.constant.value.integer = strtol(assoc->name, NiL, 0); eval(ex, expr->data.generate.statement, env); if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop != CONTINUE)) { v.integer = 0; break; } } } else { r = (*ex->disc->getf)(ex, expr, expr->data.generate.array->data.variable.symbol, expr->data.generate.array->data.variable.reference, env, 0, ex->disc); for (v.integer = 0; v.integer < r.integer; v.integer++) { expr->data.generate.index->value->data.constant.value.integer = v.integer; eval(ex, expr->data.generate.statement, env); if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop != CONTINUE)) { v.integer = 0; break; } } } return v; case CALL: x = expr->data.call.args; for (n = 0, a = expr->data.call.procedure->value->data.procedure.args; a && x; a = a->data.operand.right) { if (n < elementsof(args)) { save[n] = a->data.operand.left->data.variable.symbol->value->data.constant.value; args[n++] = eval(ex, x->data.operand.left, env); } else a->data.operand.left->data.variable.symbol->value->data.constant.value = eval(ex, x->data.operand.left, env); x = x->data.operand.right; } for (n = 0, a = expr->data.call.procedure->value->data.procedure.args; a && n < elementsof(save); a = a->data.operand.right) a->data.operand.left->data.variable.symbol->value->data.constant.value = args[n++]; if (x) exerror("too many actual args"); else if (a) exerror("not enough actual args"); v = exeval(ex, expr->data.call.procedure->value->data.procedure.body, env); for (n = 0, a = expr->data.call.procedure->value->data.procedure.args; a && n < elementsof(save); a = a->data.operand.right) a->data.operand.left->data.variable.symbol->value->data.constant.value = save[n++]; return v; case FUNCTION: n = 0; args[n++].string = (char*)env; for (x = expr->data.operand.right; x && n < elementsof(args); x = x->data.operand.right) args[n++] = eval(ex, x->data.operand.left, env); return (*ex->disc->getf)(ex, expr->data.operand.left, expr->data.operand.left->data.variable.symbol, expr->data.operand.left->data.variable.reference, args+1, EX_CALL, ex->disc); case ID: if (expr->data.variable.index) i = eval(ex, expr->data.variable.index, env); else i.integer = EX_SCALAR; return (*ex->disc->getf)(ex, expr, expr->data.variable.symbol, expr->data.variable.reference, env, (int)i.integer, ex->disc); case INC: n = 1; goto add; case PRINTF: v.integer = print(ex, expr, env, NiL); return v; case QUERY: print(ex, expr, env, sfstderr); v.integer = !astquery(2, ""); return v; case RETURN: ex->loopret = eval(ex, x, env); ex->loopcount = 32767; ex->loopop = expr->op; return ex->loopret; case SCANF: case SSCANF: v.integer = scan(ex, expr, env, NiL); return v; case SPRINTF: print(ex, expr, env, ex->tmp); v.string = exstash(ex->tmp, ex->ve); return v; case '=': v = eval(ex, expr->data.operand.right, env); if (expr->subop != '=') { r = v; if (x->op == DYNAMIC) v = getdyn(ex, x, env, &assoc); else { if (x->data.variable.index) v = eval(ex, x->data.variable.index, env); else v.integer = EX_SCALAR; v = (*ex->disc->getf)(ex, x, x->data.variable.symbol, x->data.variable.reference, env, (int)v.integer, ex->disc); } switch (x->type) { case FLOATING: switch (expr->subop) { case '+': v.floating += r.floating; break; case '-': v.floating -= r.floating; break; case '*': v.floating *= r.floating; break; case '/': if (r.floating == 0.0) exerror("floating divide by 0"); else v.floating /= r.floating; break; case '%': if ((r.integer = r.floating) == 0) exerror("floating 0 modulus"); else v.floating = ((Sflong_t)v.floating) % r.integer; break; case '&': v.floating = ((Sflong_t)v.floating) & ((Sflong_t)r.floating); break; case '|': v.floating = ((Sflong_t)v.floating) | ((Sflong_t)r.floating); break; case '^': v.floating = ((Sflong_t)v.floating) ^ ((Sflong_t)r.floating); break; case LS: v.floating = ((Sflong_t)v.floating) << ((Sflong_t)r.floating); break; case RS: #if _WIN32 v.floating = (Sflong_t)(((Sfulong_t)v.floating) >> ((Sflong_t)r.floating)); #else v.floating = ((Sfulong_t)v.floating) >> ((Sflong_t)r.floating); #endif break; default: goto huh; } break; case INTEGER: case UNSIGNED: switch (expr->subop) { case '+': v.integer += r.integer; break; case '-': v.integer -= r.integer; break; case '*': v.integer *= r.integer; break; case '/': if (r.integer == 0) exerror("integer divide by 0"); else v.integer /= r.integer; break; case '%': if (r.integer == 0) exerror("integer 0 modulus"); else v.integer %= r.integer; break; case '&': v.integer &= r.integer; break; case '|': v.integer |= r.integer; break; case '^': v.integer ^= r.integer; break; case LS: v.integer <<= r.integer; break; case RS: v.integer = (Sfulong_t)v.integer >> r.integer; break; default: goto huh; } break; case STRING: switch (expr->subop) { case '+': v.string = str_add(ex, v.string, r.string); break; case '|': v.string = str_ior(ex, v.string, r.string); break; case '&': v.string = str_and(ex, v.string, r.string); break; case '^': v.string = str_xor(ex, v.string, r.string); break; case '%': v.string = str_mod(ex, v.string, r.string); break; case '*': v.string = str_mpy(ex, v.string, r.string); break; default: goto huh; } break; default: goto huh; } } else if (x->op == DYNAMIC)
static int recparse ( XMLnode_t *xp, EMrec_t *crecs, int crecn, EMrec_t *drecs, int drecn, int dir, EMbb_t *bbp ) { EMrec_t *recs, *recp; int reci, recj, recn, ri; RIop_t *opp, top; int opi, opk, opl; EMbb_t cbb; EMimage_t *ip, *imem; XMLnode_t *cp, *pp, *tp, *fnp, *fsp, *clp; char *fs, *fn, *cl; int ci; int dw, dh; if (xp->type == XML_TYPE_TEXT) { SUwarning (0, "recparse", "called with text node"); return -1; } opk = EMopm; bbp->w = bbp->h = 0; for (ci = 0; ci < xp->nodem; ci++) { cp = xp->nodes[ci]; if (cp->type == XML_TYPE_TEXT) continue; if (strcmp (cp->tag, "v") == 0 || strcmp (cp->tag, "h") == 0) { opl = EMopm; if (recparse ( cp, crecs, crecn, drecs, drecn, (cp->tag[0] == 'v') ? EM_DIR_V : EM_DIR_H, &cbb ) == -1) { SUwarning (0, "recparse", "cannot parse v list"); return -1; } if (dir == EM_DIR_H) { for (opi = opl; opi < EMopm; opi++) { if (EMops[opi].type == RI_OP_I) { EMops[opi].u.img.rx += bbp->w; EMops[opi].u.img.ry += (bbp->h - cbb.h) / 2; } else if (EMops[opi].type == RI_OP_T) { EMops[opi].u.text.p.x += bbp->w; EMops[opi].u.text.p.y += (bbp->h - cbb.h) / 2; } } bbp->w += cbb.w; if (bbp->h < cbb.h) { dh = cbb.h - bbp->h; bbp->h = cbb.h; for (opi = opk; opi < EMopm; opi++) { if (EMops[opi].type == RI_OP_I) EMops[opi].u.img.ry += dh / 2; else if (EMops[opi].type == RI_OP_T) EMops[opi].u.text.p.y += dh / 2; } } } else { for (opi = opl; opi < EMopm; opi++) { if (EMops[opi].type == RI_OP_I) { EMops[opi].u.img.ry += bbp->h; EMops[opi].u.img.rx += (bbp->w - cbb.w) / 2; } else if (EMops[opi].type == RI_OP_T) { EMops[opi].u.text.p.y += bbp->h; EMops[opi].u.text.p.x += (bbp->w - cbb.w) / 2; } } bbp->h += cbb.h; if (bbp->w < cbb.w) { dw = cbb.w - bbp->w; bbp->w = cbb.w; for (opi = opk; opi < EMopm; opi++) { if (EMops[opi].type == RI_OP_I) EMops[opi].u.img.rx += dw / 2; else if (EMops[opi].type == RI_OP_T) EMops[opi].u.text.p.x += dw / 2; } } } } else if (strcmp (cp->tag, "rimg") == 0) { if (!(tp = XMLfind (cp, "path", XML_TYPE_TEXT, -1, TRUE))) { SUwarning (0, "recparse", "cannot find rimg/path"); continue; } if (!(ip = dtmatch (imagedict, tp->text))) { if (!(imem = vmalloc (Vmheap, sizeof (EMimage_t)))) { SUwarning (0, "recparse", "cannot allocate imem"); return -1; } memset (imem, 0, sizeof (EMimage_t)); if (!(imem->file = vmstrdup (Vmheap, tp->text))) { SUwarning (0, "recparse", "cannot copy image file"); return -1; } if (!(ip = dtinsert (imagedict, imem))) { SUwarning (0, "recparse", "cannot insert image"); vmfree (Vmheap, imem->file); vmfree (Vmheap, imem); return -1; } if (RIloadimage (ip->file, &ip->op) == -1) { SUwarning (0, "recparse", "cannot load image"); continue; } } if (ip->op.type == RI_OP_NOOP) { if ((pp = XMLfind (cp, "alt", XML_TYPE_TAG, -1, TRUE))) { if (recparse ( pp, crecs, crecn, drecs, drecn, dir, &cbb ) == -1) { SUwarning (0, "recparse", "cannot parse alt tag"); return -1; } if (dir == EM_DIR_H) { bbp->w += cbb.w; if (bbp->h < cbb.h) { dh = cbb.h - bbp->h; bbp->h = cbb.h; } } else { bbp->h += cbb.h; if (bbp->w < cbb.w) { dw = cbb.w - bbp->w; bbp->w = cbb.w; } } } } else { if (EMopm >= EMopn) { if (!(EMops = vmresize ( Vmheap, EMops, (EMopn + 100) * sizeof (RIop_t), VM_RSCOPY ))) { SUwarning (0, "recparse", "cannot grow EMops array"); return -1; } EMopn += 100; } opp = &EMops[EMopm++]; *opp = ip->op; if (dir == EM_DIR_H) { opp->u.img.rx = bbp->w + EM_MARGIN_W / 2; opp->u.img.ry = (bbp->h - opp->u.img.ih) / 2; bbp->w += opp->u.img.iw + EM_MARGIN_W; if (bbp->h < opp->u.img.ih + EM_MARGIN_H) { dh = opp->u.img.ih + EM_MARGIN_H - bbp->h; bbp->h = opp->u.img.ih + EM_MARGIN_H; for (opi = opk; opi < EMopm; opi++) { if (EMops[opi].type == RI_OP_I) EMops[opi].u.img.ry += dh / 2; else if (EMops[opi].type == RI_OP_T) EMops[opi].u.text.p.y += dh / 2; } } } else { opp->u.img.rx = (bbp->w - opp->u.img.iw) / 2; opp->u.img.ry = bbp->h + EM_MARGIN_H / 2; if (bbp->w < opp->u.img.iw + EM_MARGIN_W) { dw = opp->u.img.iw + EM_MARGIN_W - bbp->w; bbp->w = opp->u.img.iw + EM_MARGIN_W; for (opi = opk; opi < EMopm; opi++) { if (EMops[opi].type == RI_OP_I) EMops[opi].u.img.rx += dw / 2; else if (EMops[opi].type == RI_OP_T) EMops[opi].u.text.p.x += dw / 2; } } bbp->h += opp->u.img.ih + EM_MARGIN_H; } } } else if (strcmp (cp->tag, "qimg") == 0) { if (!(tp = XMLfind (cp, "path", XML_TYPE_TEXT, -1, TRUE))) { SUwarning (0, "recparse", "cannot find qimg/path"); continue; } for (ri = 0; ri < 2; ri++) { if (ri == 0) recs = crecs, recn = crecn; else recs = drecs, recn = drecn; recj = -1; for (reci = 0; reci < recn; reci++) { recp = &recs[reci]; if (strcmp (recp->id, tp->text) != 0) continue; if (recp->type == EM_TYPE_I) { recj = reci; if (!(ip = dtmatch (imagedict, recp->u.i.file))) { if (!(imem = vmalloc ( Vmheap, sizeof (EMimage_t) ))) { SUwarning ( 0, "recparse", "cannot allocate imem" ); return -1; } memset (imem, 0, sizeof (EMimage_t)); if (!(imem->file = vmstrdup ( Vmheap, recp->u.i.file ))) { SUwarning ( 0, "recparse", "cannot copy image file" ); return -1; } if (!(ip = dtinsert (imagedict, imem))) { SUwarning ( 0, "recparse", "cannot insert image" ); vmfree (Vmheap, imem->file); vmfree (Vmheap, imem); return -1; } if (RIloadimage (ip->file, &ip->op) == -1) { SUwarning (0, "recparse", "cannot load image"); continue; } } if (EMopm >= EMopn) { if (!(EMops = vmresize ( Vmheap, EMops, (EMopn + 100) * sizeof (RIop_t), VM_RSCOPY ))) { SUwarning ( 0, "recparse", "cannot grow EMops array" ); return -1; } EMopn += 100; } opp = &EMops[EMopm++]; *opp = ip->op; opp->u.img.ix = recp->u.i.x1; opp->u.img.iy = recp->u.i.y1; opp->u.img.iw = recp->u.i.x2 - recp->u.i.x1 + 1; opp->u.img.ih = recp->u.i.y2 - recp->u.i.y1 + 1; if (dir == EM_DIR_H) { opp->u.img.rx = bbp->w + EM_MARGIN_W / 2; opp->u.img.ry = (bbp->h - opp->u.img.ih) / 2; bbp->w += opp->u.img.iw + EM_MARGIN_W; if (bbp->h < opp->u.img.ih + EM_MARGIN_H) { dh = opp->u.img.ih + EM_MARGIN_H - bbp->h; bbp->h = opp->u.img.ih + EM_MARGIN_H; for (opi = opk; opi < EMopm; opi++) { if (EMops[opi].type == RI_OP_I) EMops[opi].u.img.ry += dh / 2; else if (EMops[opi].type == RI_OP_T) EMops[opi].u.text.p.y += dh / 2; } } } else { opp->u.img.rx = (bbp->w - opp->u.img.iw) / 2; opp->u.img.ry = bbp->h + EM_MARGIN_H / 2; if (bbp->w < opp->u.img.iw + EM_MARGIN_W) { dw = opp->u.img.iw + EM_MARGIN_W - bbp->w; bbp->w = opp->u.img.iw + EM_MARGIN_W; for (opi = opk; opi < EMopm; opi++) { if (EMops[opi].type == RI_OP_I) EMops[opi].u.img.rx += dw / 2; else if (EMops[opi].type == RI_OP_T) EMops[opi].u.text.p.x += dw / 2; } } bbp->h += opp->u.img.ih + EM_MARGIN_H; } } else if (recp->type == EM_TYPE_S) { recj = reci; if (EMopm + 3 >= EMopn) { if (!(EMops = vmresize ( Vmheap, EMops, (EMopn + 100) * sizeof (RIop_t), VM_RSCOPY ))) { SUwarning ( 0, "recparse", "cannot grow EMops array" ); return -1; } EMopn += 100; } if (recp->u.s.lncl && recp->u.s.lncl[0]) { opp = &EMops[EMopm++]; opp->type = RI_OP_COPYc; opp->u.color.n = 1; opp->u.color.t = recp->u.s.lncl; } if (recp->u.s.fncl && recp->u.s.fncl[0]) { opp = &EMops[EMopm++]; opp->type = RI_OP_COPYFC; opp->u.color.n = 1; opp->u.color.t = recp->u.s.fncl; } if (recp->u.s.flcl && recp->u.s.flcl[0]) { opp = &EMops[EMopm++]; opp->type = RI_OP_COPYC; opp->u.color.n = 1; opp->u.color.t = recp->u.s.flcl; } } } if (recj != -1) break; } } else if (strcmp (cp->tag, "label") == 0) { if (!(fnp = XMLfind (cp, "fontname", XML_TYPE_TEXT, -1, TRUE))) fn = "abc"; else fn = fnp->text; if (!(fsp = XMLfind (cp, "fontsize", XML_TYPE_TEXT, -1, TRUE))) fs = "10"; else fs = fsp->text; if (!(clp = XMLfind (cp, "color", XML_TYPE_TEXT, -1, TRUE))) cl = NULL; else cl = clp->text; if (!(tp = XMLfind (cp, "text", XML_TYPE_TEXT, -1, TRUE))) continue; if (RIgettextsize (tp->text, fn, fs, &top) == -1) { SUwarning (0, "recparse", "cannot get text size"); return -1; } top.u.font.w += 8, top.u.font.h += 4; if (EMopm + 3 >= EMopn) { if (!(EMops = vmresize ( Vmheap, EMops, (EMopn + 100) * sizeof (RIop_t), VM_RSCOPY ))) { SUwarning (0, "recparse", "cannot grow EMops array"); return -1; } EMopn += 100; } opp = &EMops[EMopm++]; *opp = top; opp->type = RI_OP_F; if (cl) { opp = &EMops[EMopm++]; memset (opp, 0, sizeof (RIop_t)); opp->type = RI_OP_FC; if (!(opp->u.color.t = vmstrdup (Vmheap, cl))) { SUwarning (0, "recparse", "cannot copy color"); return -1; } } opp = &EMops[EMopm++]; memset (opp, 0, sizeof (RIop_t)); opp->type = RI_OP_T; opp->u.text.jx = 0; opp->u.text.jy = -1; opp->u.text.w = top.u.font.w - 8; opp->u.text.h = top.u.font.h - 4; if (!(opp->u.text.t = vmstrdup (Vmheap, tp->text))) { SUwarning (0, "recparse", "cannot copy text"); return -1; } if (dir == EM_DIR_H) { opp->u.text.p.x = bbp->w + top.u.font.w / 2 + 4; opp->u.text.p.y = (bbp->h - top.u.font.h) / 2 + 2; bbp->w += top.u.font.w + EM_MARGIN_W; if (bbp->h < top.u.font.h + EM_MARGIN_H) { dh = top.u.font.h + EM_MARGIN_H - bbp->h; bbp->h = top.u.font.h + EM_MARGIN_H; for (opi = opk; opi < EMopm; opi++) { if (EMops[opi].type == RI_OP_I) EMops[opi].u.img.ry += dh / 2; else if (EMops[opi].type == RI_OP_T) EMops[opi].u.text.p.y += dh / 2; } } } else { opp->u.text.p.x = bbp->w / 2 + 0; opp->u.text.p.y = bbp->h + EM_MARGIN_H / 2 + 2; if (bbp->w < top.u.font.w + EM_MARGIN_W) { dw = top.u.font.w + EM_MARGIN_W - bbp->w; bbp->w = top.u.font.w + EM_MARGIN_W; for (opi = opk; opi < EMopm; opi++) { if (EMops[opi].type == RI_OP_I) EMops[opi].u.img.rx += dw / 2; else if (EMops[opi].type == RI_OP_T) EMops[opi].u.text.p.x += dw / 2; } } bbp->h += top.u.font.h + EM_MARGIN_H; } } } return 0; }
int SWMIopnload (char *tfile, char *sfile) { Sfio_t *tfp, *sfp; obj_t *objp; opn_t *opnp; char *line, *mname, *mtype, *munit, *op, *pp, *np, *vp, *tp, *ep, *lp, *s; if (!(objdict = dtopen (&objdisc, Dtset))) { sfprintf (sfstderr, "cannot create obj dict\n"); return -1; } if (!(opndict = dtopen (&opndisc, Dtset))) { sfprintf (sfstderr, "cannot create opn dict\n"); return -1; } if (!(tfp = sfopen (NULL, tfile, "r"))) { sfprintf (sfstderr, "cannot open file %s\n", tfile); return -1; } while ((line = sfgetr (tfp, '\n', 1))) { mname = line; if (!(mtype = strchr (mname, '|'))) { sfprintf (sfstderr, "badly formed opn line %s", line); continue; } if (!(munit = strchr (mtype + 1, '|'))) { sfprintf (sfstderr, "badly formed opn line %s", line); continue; } if (!(op = strchr (munit + 1, '|'))) { sfprintf (sfstderr, "badly formed opn line %s", line); continue; } if (!(tp = strchr (op + 1, '|'))) { sfprintf (sfstderr, "badly formed opn line %s", line); continue; } if (!(ep = strchr (tp + 1, '|'))) { sfprintf (sfstderr, "badly formed opn line %s", line); continue; } if (!(lp = strchr (ep + 1, '|'))) { sfprintf (sfstderr, "badly formed opn line %s", line); continue; } if (!(pp = strchr (op + 1, '.')) || !(np = strchr (pp + 1, '.'))) { sfprintf (sfstderr, "badly formed opn line %s", line); continue; } *mtype++ = 0, *munit++ = 0, *op++ = 0, *tp++ = 0, *ep++ = 0, *lp++ = 0; if (dtmatch (opndict, op)) continue; *pp++ = 0, *np++ = 0; if (!(opnp = opninsert (OPN_KIND_P, mname, mtype, munit, op, pp, np, lp))) { sfprintf (sfstderr, "cannot insert opn\n"); return -1; } if (*tp) { if (strcmp (tp, "simple") == 0) opnp->type = V_TYPE_SIMPLE; else if (strcmp (tp, "withbase") == 0) opnp->type = V_TYPE_WITHBASE; } if (*ep) { if (!(opnp->ep = vmstrdup (Vmheap, ep))) { sfprintf (sfstderr, "cannot allocate ep\n"); return NULL; } } if ((objp = (obj_t *) dtmatch (objdict, op))) { opnp->objp = objp; continue; } if (!(objp = objinsert (op))) { sfprintf (sfstderr, "cannot insert obj\n"); return -1; } opnp->objp = objp; } sfclose (tfp); if (!(sfp = sfopen (NULL, sfile, "r"))) { sfprintf (sfstderr, "cannot open file %s\n", sfile); return -1; } while ((line = sfgetr (sfp, '\n', 1))) { if (!(vp = strrchr (line, '|'))) { sfprintf (sfstderr, "badly formed opn state %s", line); return -1; } *vp++ = 0; op = line; if (!(pp = strchr (op, '.')) || !(np = strchr (pp + 1, '.'))) { sfprintf (sfstderr, "badly formed opn %s", line); continue; } if (!(opnp = (opn_t *) dtmatch (opndict, op))) { *pp++ = 0, *np++ = 0; if (!(opnp = opninsert (OPN_KIND_S, "", "", "", op, pp, np, ""))) { sfprintf (sfstderr, "cannot insert opn\n"); return -1; } if ((objp = (obj_t *) dtmatch (objdict, op))) opnp->objp = objp; } if (strcmp (vp, "NULL") == 0) { opnp->havep = FALSE; } else { opnp->pv = strtoull (vp, &s, 10); if (s && *s) { sfprintf (sfstderr, "cannot calculate previous value\n"); opnp->havep = FALSE; } else opnp->havep = TRUE; } } sfclose (sfp); if (!(kvts = (kvt_t *) vmalloc (Vmheap, 100 * sizeof (kvt_t)))) { sfprintf (sfstderr, "cannot allocate kvt array\n"); return -1; } kvtn = 100; return 0; }
IMPLLnd_t *IMPLLinsertnd (char *level, char *id, short nclass, char *attrstr) { IMPLLnd_t nd, *ndp, *ndmem; UTattr_t *ap; EMbb_t bb; char *s1; memcpy (nd.level, level, SZ_level); memcpy (nd.id, id, SZ_id); if ((ndp = dtsearch (nddict, &nd))) return ndp; if (!(ndmem = vmalloc (Vmheap, sizeof (IMPLLnd_t)))) { SUwarning (0, "IMPLLinsertnd", "cannot allocate ndmem"); return NULL; } memset (ndmem, 0, sizeof (IMPLLnd_t)); memcpy (ndmem->level, level, SZ_level); memcpy (ndmem->id, id, SZ_id); if ((ndp = dtinsert (nddict, ndmem)) != ndmem) { SUwarning (0, "IMPLLinsertnd", "cannot insert nd"); vmfree (Vmheap, ndmem); return NULL; } ndp->nclass = nclass; if (UTsplitattr (UT_ATTRGROUP_NODE, attrstr) == -1) { SUwarning (0, "IMPLLinsertnd", "cannot parse attrstr"); return NULL; } if (UTgetattrs (UT_ATTRGROUP_NODE) == -1) { SUwarning (0, "IMPLLinsertnd", "cannot get node attr"); return NULL; } ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_WIDTH]; if (ap->value && ap->value[0]) ndp->w = atoi (ap->value); else ndp->w = 100; ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_HEIGHT]; if (ap->value && ap->value[0]) ndp->h = atoi (ap->value); else ndp->h = 50; ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_LABEL]; if ( ap->value && strcmp (ap->name, "label") == 0 && strncmp (ap->value, "EMBED:", 6) == 0 ) { if (EMparsenode ( ndp->level, ndp->id, ap->value + 6, EM_DIR_V, &ndp->opi, &ndp->opn, &bb ) == -1) { SUwarning (0, "IMPLLinsertnd", "cannot parse node EM contents"); return NULL; } if (ndp->w < bb.w) ndp->w = bb.w; if (ndp->h < bb.h) ndp->h = bb.h; } ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_LINEWIDTH]; ndp->lw = (ap->value && ap->value[0]) ? atoi (ap->value) : 1; ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_BGCOLOR]; if (!(ndp->bg = vmstrdup ( Vmheap, (ap->value && ap->value[0]) ? ap->value : "white" ))) { SUwarning (0, "IMPLLinsertnd", "cannot copy node bgcolor"); return NULL; } ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_COLOR]; if (!(ndp->cl = vmstrdup ( Vmheap, (ap->value && ap->value[0]) ? ap->value : "black" ))) { SUwarning (0, "IMPLLinsertnd", "cannot copy node color"); return NULL; } ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_FONTNAME]; if (!(ndp->fn = vmstrdup ( Vmheap, (ap->value && ap->value[0]) ? ap->value : "abc" ))) { SUwarning (0, "IMPLLinsertnd", "cannot copy node font name"); return NULL; } ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_FONTSIZE]; if (!(ndp->fs = vmstrdup ( Vmheap, (ap->value && ap->value[0]) ? ap->value : "10" ))) { SUwarning (0, "IMPLLinsertnd", "cannot copy node font size"); return NULL; } ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_INFO]; if (!(ndp->info = vmstrdup ( Vmheap, (ap->value && ap->value[0]) ? ap->value : id ))) { SUwarning (0, "IMPLLinsertnd", "cannot copy node info"); return NULL; } ndp->havecoord = FALSE; ap = &UTattrgroups[UT_ATTRGROUP_NODE][UT_ATTR_COORD]; if (ap->value && ap->value[0] && (s1 = strchr (ap->value, ' '))) { *s1 = 0; ndp->llx = atof (ap->value), ndp->lly = atof (s1 + 1); *s1 = ' '; ndp->havecoord = TRUE; } return ndp; }
int SWMIopnexec (state_t *sp) { char q[1024], opnstr[1024], *name, *origname, *s; opn_t *opnp, *opnbasep, *opntimep, *opnfreqp; obj_t *objp; HRESULT hr; BSTR propb, ctb, wqlb, qb; SAFEARRAY *props; VARIANT var; LONG pu, pl, pi; ULONG ul; double v; kvt_t *kvtp; int kvti; ctb = s2b ("countertype"); wqlb = s2b ("WQL"); for ( objp = (obj_t *) dtfirst (objdict); objp; objp = (obj_t *) dtnext (objdict, objp) ) { sfsprintf (q, 1024, "select * from %s", objp->obj); if (verbose) sfprintf (sfstderr, "query: %s\n", q); if (!(qb = s2b (q))) { sfprintf (sfstderr, "cannot convert obj name %s to bstr\n", objp->obj); return -1; } if ((hr = sp->pSvc->ExecQuery ( wqlb, qb, WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 0, &sp->pEnum )) != S_OK) { sfprintf ( sfstderr, "cannot execute query %s, error %s\n", q, E2ccp (hr) ); return -1; } if (SWMIproxysecurity (sp, sp->pEnum) < 0) { sfprintf (sfstderr, "cannot enable security for query %s\n", q); return -1; } while ( sp->pEnum->Next (30 * 1000, 1, &sp->pClsObj, &ul ) == S_OK && ul == 1) { if ((hr = sp->pClsObj->GetNames ( 0, WBEM_FLAG_ALWAYS | WBEM_FLAG_NONSYSTEM_ONLY, 0, &props )) != S_OK) { sfprintf ( sfstderr, "cannot get props for obj %s, error %s\n", objp->obj, E2ccp (hr) ); return -1; } if( (hr = SafeArrayGetLBound (props, 1, &pl)) != S_OK || (hr = SafeArrayGetUBound (props, 1, &pu)) != S_OK ) { sfprintf ( sfstderr, "cannot get props bounds for %s, error %s\n", objp->obj, E2ccp (hr) ); return -1; } if (pu - pl + 1 > kvtn) { kvtn = pu - pl + 1; if (!(kvts = (kvt_t *) vmresize ( Vmheap, kvts, kvtn * sizeof (kvt_t), VM_RSCOPY ))) { sfprintf (sfstderr, "cannot grow kvt array\n"); return -1; } } name = NULL; for (pi = pl, kvtl = 0; pi <= pu; pi++, kvtl++) { kvtp = &kvts[kvtl]; if ((hr = SafeArrayGetElement (props, &pi, &propb)) != S_OK) { sfprintf ( sfstderr, "cannot get prop name for %d/%s, error %s\n", pi, objp->obj, E2ccp (hr) ); continue; } kvtp->kp = (char *) b2s (propb); if ((hr = sp->pClsObj->Get (propb, 0, &var, 0, 0)) != S_OK) { sfprintf ( sfstderr, "cannot get prop value for %d/%s, error %s\n", pi, objp->obj, E2ccp (hr) ); continue; } if ( !(kvtp->vp = (char *) V2ccp (&var)) || !(kvtp->vp = vmstrdup (Vmheap, kvtp->vp)) ) { kvtl--; continue; } switch (var.vt) { case VT_UI1: kvtp->v = var.bVal; break; case VT_I2: kvtp->v = var.iVal; break; case VT_I4: kvtp->v = var.lVal; break; default: kvtp->v = strtoull (kvtp->vp, &s, 10); break; } if (strcmp (kvtp->kp, "Name") == 0) { if (var.vt == VT_NULL) name = "ALL"; else name = kvtp->vp; origname = name; } if ((hr = sp->pClsObj->GetPropertyQualifierSet ( propb, &sp->pQualSet )) != S_OK) { sfprintf ( sfstderr, "cannot get quals for %d/%s, error %s\n", pi, objp->obj, E2ccp (hr) ); continue; } kvtp->type = V_TYPE_STRING; if ((hr = sp->pQualSet->Get ( ctb, 0, &var, 0 )) == S_OK && var.vt == VT_I4) { switch (var.lVal) { case PERF_COUNTER_RAWCOUNT: case PERF_COUNTER_LARGE_RAWCOUNT: kvtp->type = V_TYPE_SIMPLE; break; case PERF_RAW_FRACTION: kvtp->type = V_TYPE_WITHBASE; break; case PERF_RAW_BASE: case PERF_PRECISION_TIMESTAMP: kvtp->type = V_TYPE_ISBASE; break; case PERF_COUNTER_COUNTER: case PERF_COUNTER_BULK_COUNT: kvtp->type = V_TYPE_WITHTIMENFREQ; break; case PERF_100NSEC_TIMER: kvtp->type = V_TYPE_WITH100NSEC; break; case PERF_100NSEC_TIMER_INV: kvtp->type = V_TYPE_WITH100NSECINV; break; default: kvtp->type = V_TYPE_SIMPLE; break; } } else { if (strcmp (kvtp->kp, "Timestamp_PerfTime") == 0) kvtp->type = V_TYPE_ISTIME; else if (strcmp (kvtp->kp, "Frequency_PerfTime") == 0) kvtp->type = V_TYPE_ISFREQ; else if (strcmp (kvtp->kp, "Timestamp_Sys100NS") == 0) kvtp->type = V_TYPE_IS100NSEC; else if (kvtp->vp[0] == 0 || isdigit (kvtp->vp[0])) kvtp->type = V_TYPE_SIMPLE; } } ::SafeArrayDestroy (props); sp->pClsObj->Release (); for (kvti = 0; kvti < kvtl; kvti++) { kvtp = &kvts[kvti]; sfsprintf (opnstr, 1024, "%s.%s.%s", objp->obj, kvtp->kp, name); if (!(opnp = (opn_t *) dtmatch (opndict, opnstr))) { sfsprintf (opnstr, 1024, "%s.%s.ALL", objp->obj, kvtp->kp); if ((opnp = (opn_t *) dtmatch (opndict, opnstr))) name = "ALL"; else sfsprintf (opnstr, 1024, "%s.%s.%s", objp->obj, kvtp->kp, name); } if (!opnp) { if (kvtp->type < V_TYPE_SUPPORT) continue; if (!(opnp = opninsert ( OPN_KIND_S, "", "", "", objp->obj, kvtp->kp, name, "" ))) { sfprintf (sfstderr, "cannot insert opn\n"); return -1; } opnp->objp = objp; } if (opnp->ep && strstr (origname, opnp->ep)) continue; if (opnp->type == 0) opnp->type = kvtp->type; opnp->vp = kvtp->vp; opnp->cv += kvtp->v; opnp->havec = TRUE; } for (kvti = 0; kvti < kvtl; kvti++) { kvtp = &kvts[kvti]; sfsprintf (opnstr, 1024, "%s.%s.SUM", objp->obj, kvtp->kp); if (!(opnp = (opn_t *) dtmatch (opndict, opnstr))) continue; if (opnp->ep && strstr (origname, opnp->ep)) continue; if (opnp->type == 0) opnp->type = kvtp->type; opnp->vp = kvtp->vp; opnp->cv += kvtp->v; opnp->havec = TRUE; } } } for ( opnp = (opn_t *) dtfirst (opndict); opnp; opnp = (opn_t *) dtnext (opndict, opnp) ) { if (opnp->kind != OPN_KIND_P || !opnp->havec) continue; if (opnp->type >= V_TYPE_SUPPORT) continue; switch (opnp->type) { case V_TYPE_STRING: #if 0 sfprintf ( sfstdout, "rt=STAT type=string name=%s str=%s%s%s%s\n", opnp->mname, opnp->vp, (opnp->lp[0]) ? " label='" : "", (opnp->lp[0]) ? opnp->lp : "", (opnp->lp[0]) ? "'" : "" ); #endif break; case V_TYPE_SIMPLE: sfprintf ( sfstdout, "rt=STAT type=%s name=%s unit=%s num=%lld%s%s%s\n", opnp->mtype, opnp->mname, opnp->munit, opnp->cv, (opnp->lp[0]) ? " label='" : "", (opnp->lp[0]) ? opnp->lp : "", (opnp->lp[0]) ? "'" : "" ); break; case V_TYPE_WITHBASE: sfsprintf (opnstr, 1024, "%s.%s_Base.%s", opnp->op, opnp->pp, opnp->np); if (!(opnbasep = (opn_t *) dtmatch (opndict, opnstr))) { sfprintf (sfstderr, "cannot find base property for %s\n", opnp->opn); continue; } if (!opnbasep->havec) continue; if ((v = (opnbasep->cv == 0) ? 0.00 : 100.0 * ( opnp->cv / (double) opnbasep->cv )) < 0.0) continue; sfprintf ( sfstdout, "rt=STAT type=%s name=%s unit=%s num=%lf%s%s%s\n", opnp->mtype, opnp->mname, opnp->munit, v, (opnp->lp[0]) ? " label='" : "", (opnp->lp[0]) ? opnp->lp : "", (opnp->lp[0]) ? "'" : "" ); break; case V_TYPE_WITHTIMENFREQ: if (!opnp->havep) continue; sfsprintf (opnstr, 1024, "%s.Timestamp_PerfTime.%s", opnp->op, opnp->np); if (!(opntimep = (opn_t *) dtmatch (opndict, opnstr))) { sfprintf (sfstderr, "cannot find time property for %s\n", opnp->opn); continue; } if (!opntimep->havec || !opntimep->havep) continue; sfsprintf (opnstr, 1024, "%s.Frequency_PerfTime.%s", opnp->op, opnp->np); if (!(opnfreqp = (opn_t *) dtmatch (opndict, opnstr))) { sfprintf (sfstderr, "cannot find freq property for %s\n", opnp->opn); continue; } if (!opnfreqp->havec) continue; if ( opnp->cv < opnp->pv || opntimep->cv <= opntimep->pv || opnfreqp->cv == 0 ) continue; if ((v = (opnp->cv - opnp->pv) / ( (opntimep->cv - opntimep->pv) / (double) opnfreqp->cv )) < 0.0) { if (v > -1) v = 0.0; else continue; } sfprintf ( sfstdout, "rt=STAT type=%s name=%s unit=%s num=%lf%s%s%s\n", opnp->mtype, opnp->mname, opnp->munit, v, (opnp->lp[0]) ? " label='" : "", (opnp->lp[0]) ? opnp->lp : "", (opnp->lp[0]) ? "'" : "" ); break; case V_TYPE_WITH100NSEC: case V_TYPE_WITH100NSECINV: if (!opnp->havep) continue; sfsprintf (opnstr, 1024, "%s.Timestamp_Sys100NS.%s", opnp->op, opnp->np); if (!(opntimep = (opn_t *) dtmatch (opndict, opnstr))) { sfprintf (sfstderr, "cannot find time property for %s\n", opnp->opn); continue; } if (!opntimep->havec || !opntimep->havep) continue; if (opnp->cv < opnp->pv || opntimep->cv <= opntimep->pv) continue; if (opnp->type == V_TYPE_WITH100NSEC) { if ((v = 100.0 * ( (opnp->cv - opnp->pv) / ((double) opntimep->cv - opntimep->pv) )) < 0.0) { if (v > -1) v = 0.0; else continue; } sfprintf ( sfstdout, "rt=STAT type=%s name=%s unit=%s num=%lf%s%s%s\n", opnp->mtype, opnp->mname, opnp->munit, v, (opnp->lp[0]) ? " label='" : "", (opnp->lp[0]) ? opnp->lp : "", (opnp->lp[0]) ? "'" : "" ); } else { if ((v = 100.0 * ( 1.0 - (opnp->cv - opnp->pv) / ((double) opntimep->cv - opntimep->pv) )) < 0.0) { if (v > -1) v = 0.0; else continue; } sfprintf ( sfstdout, "rt=STAT type=%s name=%s unit=%s num=%lf%s%s%s\n", opnp->mtype, opnp->mname, opnp->munit, v, (opnp->lp[0]) ? " label='" : "", (opnp->lp[0]) ? opnp->lp : "", (opnp->lp[0]) ? "'" : "" ); } break; } } return 0; }
static char *createextractorstr ( DDSschema_t *schemap, char *ename, char *elist ) { char *elist2; DDSfield_t *fields; int fieldn, fieldi; DDSschema_t *eschemap; Sfio_t *fp; DDSfield_t *fieldp; int i; char *cstr; if (!ename) ename = "extracted"; if (!(elist2 = vmstrdup (Vmheap, elist))) { SUwarning (1, "createextractorstr", "vmstrdup failed"); return NULL; } if ((fieldn = _ddslist2fields (elist, schemap, &fields, NULL, NULL)) < 0) { SUwarning (1, "createextractorstr", "list2fields failed"); return NULL; } if (!(eschemap = DDScreateschema (ename, fields, fieldn, NULL, NULL))) { SUwarning (1, "createextractorstr", "DDScreateschema failed"); return NULL; } if (!(fp = sfopen (NULL, NULL, "sw+"))) { SUwarning (1, "createextractorstr", "sfopen failed"); return NULL; } sfprintf (fp, "#include <ast.h>\n#include <swift.h>\n#include <cdt.h>\n"); sfprintf (fp, "#include <vmalloc.h>\n#include <dds.h>\n\n"); if (schemap->include) sfprintf (fp, "%s\n\n", schemap->include); _ddswritestruct (schemap, sfprints ("irec_%s", schemap->name), fp); _ddswritestruct (eschemap, sfprints ("orec_%s", eschemap->name), fp); sfprintf (fp, "DDS_EXPORT char extractor_%s_ename[] = \"%s\";\n" "DDS_EXPORT char extractor_%s_elist[] = \"%s\";\n\n", schemap->name, ename, schemap->name, elist2); sfprintf (fp, "DDS_EXPORT int extractor_%s_init (void) {\n" " return 0;\n" "}\n\n", schemap->name); sfprintf (fp, "DDS_EXPORT int extractor_%s_term (void) {\n" " return 0;\n" "}\n\n", schemap->name); sfprintf (fp, "DDS_EXPORT int extractor_%s_work (char *__ibuf, int __ilen," " char *__obuf, int __olen) {\n" " struct __irec_%s_t *__irecp;\n\n" " struct __orec_%s_t *__orecp;\n\n" " __irecp = (struct __irec_%s_t *) __ibuf;\n" " __orecp = (struct __orec_%s_t *) __obuf;\n", schemap->name, schemap->name, eschemap->name, schemap->name, eschemap->name ); for (fieldi = 0; fieldi < fieldn; fieldi++) { fieldp = &fields[fieldi]; if (fieldp->n > 1) { for (i = 0; i < fieldp->n; i++) sfprintf ( fp, " __orecp->%s[%d] = __irecp->%s[%d];\n", fieldp->name, i, fieldp->name, i ); } else sfprintf ( fp, " __orecp->%s = __irecp->%s;\n", fieldp->name, fieldp->name ); } sfprintf (fp, " return 0;\n}\n"); if (!(cstr = _ddscopystr (fp))) { SUwarning (1, "createextractorstr", "copystr failed"); return NULL; } sfclose (fp); DDSdestroyschema (eschemap); return cstr; }