MAIN() { #if _typ_long_double long double ldval, ldmax; char *s, *str; ldmax = LDBL_MAX; if(!(s = sfprints("%Le",ldmax)) ) terror("sfprints failed1\n"); if(!(str = malloc(strlen(s)+1)) ) terror("Malloc failed\n"); strcpy(str,s); if(sfsscanf(str,"%Le",&ldval) != 1) terror("sfsscanf failed\n"); if(!(s = sfprints("%Le",ldval)) ) terror("sfprints failed2\n"); if(strcmp(s,str) != 0) terror("Bad conversion, expecting %s and getting %s\n",str,s); #endif TSTEXIT(0); }
static int savenpacoords (char *dir) { Sfio_t *fp; loc_t *locp; int loci; int npanxxi; npa_t *npap; int npai, npa; SUmessage (1, "savenpacoords", "saving file %s/npa.coords", dir); if (!(fp = sfopen (NULL, sfprints ("%s/npa.coords", dir), "w"))) { SUwarning (1, "savenpacoords", "open failed for %s/npa.coords", dir); return -1; } sfsetbuf (fp, NULL, 1048576); for (loci = 0; loci < locn; loci++) { locp = locs[loci]; for (npanxxi = 0; npanxxi < locp->npanxxn; npanxxi++) { npa = locp->npanxxs[npanxxi]->npanxx / 1000; xs[npa] += locp->x, ys[npa] += locp->y, ns[npa]++; } } for (npai = 0; npai < npan; npai++) { npap = npas[npai]; if (ns[npap->npa] > 0) sfprintf ( fp, "%03d %d %d\n", npap->npa, (int) (xs[npap->npa] / (double) ns[npap->npa]), (int) (ys[npap->npa] / (double) ns[npap->npa]) ); } sfclose (fp); return 0; }
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 int loadgrouperso ( DDSschema_t *schemap, char *sofile, int rmflag, DDSgrouper_t *grouperp ) { if ( !(grouperp->handle = dlopen (sofile, RTLD_LAZY)) || !(grouperp->init = (DDSgrouperinitfunc) dlsym ( grouperp->handle, sfprints ("grouper_%s_init", schemap->name) )) || !(grouperp->term = (DDSgroupertermfunc) dlsym ( grouperp->handle, sfprints ("grouper_%s_term", schemap->name) )) || !(grouperp->work = (DDSgrouperworkfunc) dlsym ( grouperp->handle, sfprints ("grouper_%s_work", schemap->name) )) ) { SUwarning (1, "loadgrouperso", "init failed: %s", dlerror ()); return -1; } if (rmflag) unlink (sofile); return 0; }
static int savepolys (char *dir, char *prefix) { char *fname; Sfio_t *fp; item_t *itemp; int itempi; int indi; int pointi, pointj; fname = strdup (sfprints ("%s/%s_polys.ps", dir, prefix)); SUmessage (1, "savepolys", "saving file %s", fname); if (!(fp = sfopen (NULL, fname, "w"))) { SUwarning (1, "savepolys", "open failed for %s", fname); return -1; } sfprintf (fp, "%%!PS\n"); sfprintf (fp, "8 72 mul 10 72 mul scale 0 setlinewidth\n"); sfprintf (fp, "/n { newpath } def\n"); sfprintf (fp, "/m { moveto } def\n"); sfprintf (fp, "/l { lineto } def\n"); sfprintf (fp, "/p { /y exch def /x exch def x y moveto x y lineto } def\n"); sfprintf (fp, "/s { closepath stroke } def\n"); sfprintf (fp, "/f { closepath fill } def\n"); /* (x, y, z) of each point */ for (itempi = 0; itempi < itempn; itempi++) { itemp = itemps[itempi]; if (itemp->pointn == 0) continue; for (pointi = 0, indi = 0; indi < itemp->indn; indi++) { sfprintf ( fp, "n %f %f m\n", X (itemp->points[pointi].x), Y (itemp->points[pointi].y) ); pointi++; for (pointj = 1; pointj < itemp->inds[indi]; pointi++, pointj++) sfprintf ( fp, "%f %f l\n", X (itemp->points[pointi].x), Y (itemp->points[pointi].y) ); sfprintf (fp, "s\n"); } } sfprintf (fp, "showpage\n"); sfclose (fp); return 0; }
void* dllopen(const char* name, int mode) { void* dll; Dllinfo_t* info; char* olibpath; char* path; char* oenv; char* nenv[2]; char* dir; char* base; int len; if (!environ) { nenv[0] = nenv[1] = 0; environ = nenv; } info = dllinfo(); oenv = environ[0]; olibpath = getenv(info->env); if (base = strrchr(name, '/')) { dir = (char*)name; len = ++base - dir; } else { dir = "./"; len = 2; base = (char*)name; } path = sfprints("%-.*s%s%c%s=%-.*s%s%s", len, dir, base, 0, info->env, len, dir, olibpath ? ":" : "", olibpath ? olibpath : ""); environ[0] = path + strlen(path) + 1; state.error = 0; dll = dlopen(path, mode); if (environ == nenv) environ = 0; else environ[0] = oenv; return dll; }
static int savelocstates (char *dir) { Sfio_t *fp; loc_t *locp; int loci; SUmessage (1, "savelocstates", "saving file %s/npanxxloc.states", dir); if (!(fp = sfopen (NULL, sfprints ("%s/npanxxloc.states", dir), "w"))) { SUwarning ( 1, "savelocstates", "open failed for %s/npanxxloc.states", dir ); return -1; } sfsetbuf (fp, NULL, 1048576); for (loci = 0; loci < locn; loci++) { locp = locs[loci]; sfprintf (fp, "%d %s\n", loci, locp->npanxxs[0]->state); } sfclose (fp); return 0; }
tmain() { Sfio_t *f; if (argc > 1) { if (sfopen(sfstdin, argv[1], "r") != sfstdin) terror("Can't reopen stdin"); sfmove(sfstdin, sfstdout, (Sfoff_t)(-1), -1); return 0; } if (!(f = sfopen(NULL, tstfile("sf", 0), "w"))) terror("Opening to write"); if (sfputc(f, 'a') != 'a') terror("sfputc"); if (sfgetc(f) >= 0) terror("sfgetc"); if (!(f = sfopen(f, tstfile("sf", 0), "r"))) terror("Opening to read"); if (sfgetc(f) != 'a') terror("sfgetc2"); if (sfputc(f, 'b') >= 0) terror("sfputc2"); if (!(f = sfopen(f, tstfile("sf", 0), "r+"))) terror("Opening to read/write"); if (sfgetc(f) != 'a') terror("sfgetc3"); if (sfputc(f, 'b') != 'b') terror("sfputc3"); if (sfclose(f) < 0) terror("sfclose"); if (!(f = sfpopen(NULL, sfprints("%s %s", argv[0], tstfile("sf", 0)), "r"))) terror("sfpopen"); if (sfgetc(f) != 'a') terror("sfgetc4"); if (sfgetc(f) != 'b') terror("sfgetc5"); if (sfgetc(f) >= 0) terror("sfgetc6"); if (!(f = sfopen(f, tstfile("sf", 0), "w"))) terror("sfopen"); if (sfputc(f, 'a') != 'a') terror("sfputc1"); sfsetfd(f, -1); if (sfputc(f, 'b') >= 0) terror("sfputc2"); if (sfclose(f) < 0) terror("sfclose"); if (!(f = sfopen(NULL, tstfile("sf", 0), "a+"))) terror("sfopen2"); sfset(f, SF_READ, 0); if (!sfreserve(f, 0, -1)) terror("Failed on buffer getting"); if (sfvalue(f) <= 0) terror("There is no buffer?"); texit(0); }
static int savetris (char *dir, char *prefix) { char *fname; Sfio_t *fp; item_t *itemp; int itempi; int trii; fname = strdup (sfprints ("%s/%s_tris.ps", dir, prefix)); SUmessage (1, "savetris", "saving file %s", fname); if (!(fp = sfopen (NULL, fname, "w"))) { SUwarning (1, "savetris", "open failed for %s", fname); return -1; } sfprintf (fp, "%%!PS\n"); sfprintf (fp, "8 72 mul 10 72 mul scale 0 setlinewidth\n"); sfprintf (fp, "/n { newpath } def\n"); sfprintf (fp, "/m { moveto } def\n"); sfprintf (fp, "/l { lineto } def\n"); sfprintf (fp, "/p { /y exch def /x exch def x y moveto x y lineto } def\n"); sfprintf (fp, "/s { closepath stroke } def\n"); sfprintf (fp, "/f { closepath fill } def\n"); /* (x, y, z) of each point */ for (itempi = 0; itempi < itempn; itempi++) { itemp = itemps[itempi]; if (itemp->trin == 0) continue; for (trii = 0; trii < itemp->trin; trii++) { sfprintf ( fp, "n %f %f m %f %f l %f %f l f\n", X (itemp->tris[trii].a.x), Y (itemp->tris[trii].a.y), X (itemp->tris[trii].b.x), Y (itemp->tris[trii].b.y), X (itemp->tris[trii].c.x), Y (itemp->tris[trii].c.y) ); } } sfprintf (fp, "showpage\n"); sfclose (fp); return 0; }
static int savelocmap (char *dir) { Sfio_t *fp; loc_t *locp; int loci; int npanxxi; SUmessage (1, "savelocmap", "saving file %s/npanxxloc.map", dir); if (!(fp = sfopen (NULL, sfprints ("%s/npanxx2loc.map", dir), "w"))) { SUwarning ( 1, "savelocmap", "open failed for %s/npanxxloc.map", dir ); return -1; } sfsetbuf (fp, NULL, 1048576); for (loci = 0; loci < locn; loci++) { locp = locs[loci]; for (npanxxi = 0; npanxxi < locp->npanxxn; npanxxi++) sfprintf (fp, "%06d %d\n", locp->npanxxs[npanxxi]->npanxx, loci); } sfclose (fp); return 0; }
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; }
static int savelines (char *dir, char *prefix) { char *fname; Sfio_t *fp; item_t *itemp; int itempi; int pointi; double x, y; fname = strdup (sfprints ("%s/%s_lines.ps", dir, prefix)); SUmessage (1, "savepoints", "saving file %s", fname); if (!(fp = sfopen (NULL, fname, "w"))) { SUwarning (1, "savepoints", "open failed for %s", fname); return -1; } sfprintf (fp, "%%!PS\n"); sfprintf (fp, "8 72 mul 10 72 mul scale 0 setlinewidth\n"); sfprintf (fp, "/n { newpath } def\n"); sfprintf (fp, "/m { moveto } def\n"); sfprintf (fp, "/l { lineto } def\n"); sfprintf (fp, "/p { /y exch def /x exch def x y moveto x y lineto } def\n"); sfprintf (fp, "/s { closepath stroke } def\n"); sfprintf (fp, "/f { closepath fill } def\n"); /* (x, y, z) of each point */ for (itempi = 0; itempi < itempn; itempi++) { itemp = itemps[itempi]; if (itemp->pointn == 0) continue; for (x = y = 0.0, pointi = 0; pointi < itemp->pointn; pointi++) x += itemp->points[pointi].x, y += itemp->points[pointi].y; x /= itemp->pointn, y /= itemp->pointn; sfprintf (fp, "n %f %f p s\n", X (x), Y (y)); } sfprintf (fp, "showpage\n"); sfclose (fp); return 0; }
/* Test multiple processes reading/writing from same file ** descriptor. */ MAIN() { char* s; if(argc > 1) { if(strcmp(argv[1],"-r") == 0) /* doing sfgetr */ { if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"Line2") != 0) terror("Coprocess getr did not get Line2\n"); if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"Line3") != 0) terror("Coprocess getr did not get Line3\n"); } else /* doing sfmove */ { Sfio_t* f = sfopen(NIL(Sfio_t*),NIL(char*),"swr"); if(!f) terror("Can't open string stream\n"); if(sfmove(sfstdin,f,(Sfoff_t)2,'\n') != 2) terror("Coprocess sfmove failed\n"); sfseek(f,(Sfoff_t)0,0); if(!(s = sfgetr(f,'\n',1)) || strcmp(s,"Line2") != 0) terror("Coprocess move did not get Line2\n"); if(!(s = sfgetr(f,'\n',1)) || strcmp(s,"Line3") != 0) terror("Coprocess move did not get Line3\n"); } TSTEXIT(0); } if(sfopen(sfstdout, tstfile(0), "w") != sfstdout ) terror("Opening file\n"); if(sfputr(sfstdout,"Line1",'\n') < 0 || sfputr(sfstdout,"Line2",'\n') < 0 || sfputr(sfstdout,"Line3",'\n') < 0 || sfputr(sfstdout,"Line4",'\n') < 0) terror("Writing data\n"); sfopen(sfstdout,"/dev/null","w"); /* testing coprocess calling sfgetr */ if(sfopen(sfstdin, tstfile(0),"r") != sfstdin) terror("Opening to read\n"); if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"Line1") != 0) terror("Did not get Line1 for sfgetr\n"); sfsync(sfstdin); system(sfprints("%s -r",argv[0])); sfseek(sfstdin, (Sfoff_t)lseek(sffileno(sfstdin), (off_t)0, 1), 0); if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"Line4") != 0) terror("Did not get Line4 for sfgetr\n"); /* testing coprocess calling sfmove */ if(sfopen(sfstdin, tstfile(0), "r") != sfstdin) terror("Opening to read\n"); if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"Line1") != 0) terror("Did not get Line1 for sfmove\n"); sfsync(sfstdin); system(sfprints("%s -m",argv[0])); sfseek(sfstdin, (Sfoff_t)lseek(sffileno(sfstdin), (off_t)0, 1), 0); if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"Line4") != 0) terror("Did not get Line4 for sfmove\n"); /* testing the head program */ #ifdef HEAD if(sfopen(sfstdin, tstfile(0), "r") != sfstdin) terror("Opening to read\n"); if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"Line1") != 0) terror("Did not get Line1 for head\n"); sfsync(sfstdin); system("head -2 > /dev/null"); /* for testing the head program */ sfseek(sfstdin, (Sfoff_t)lseek(sffileno(sfstdin), (off_t)0, 1), 0); if(!(s = sfgetr(sfstdin,'\n',1)) || strcmp(s,"Line4") != 0) terror("Did not get Line4 for head\n"); #endif TSTEXIT(0); }
static int flash_getprologue(Pax_t* pax, Format_t* fp, register Archive_t* ap, File_t* f, unsigned char* buf, size_t size) { unsigned char* s; unsigned char* e; unsigned char* t; char* v; int i; off_t n; char version[16]; if (size < sizeof(FLASH_MAGIC) - 1 || memcmp(buf, FLASH_MAGIC, sizeof(FLASH_MAGIC) - 1)) return 0; /* * get the flash format version */ s = buf + sizeof(FLASH_MAGIC) - 1; e = buf + size; v = version; while (v < &version[sizeof(version) - 1] && s < e && *s != '\n') *v++ = *s++; *v = 0; /* * skip over the flash headers to the embedded archive */ s = e; for (;;) { if (s >= e) { if (!(buf = (unsigned char*)paxget(pax, ap, -PAX_DEFBUFFER * PAX_BLOCK, &n))) return -1; s = buf; e = buf + n; } if (t = (unsigned char*)memchr(s, '\n', e - s)) { if ((t - s) == (sizeof(FLASH_DATA) - 1) && !memcmp(s, FLASH_DATA, sizeof(FLASH_DATA) - 1)) { if (paxseek(pax, ap, -(e - t - 1), SEEK_CUR, 0) < 0) return -1; break; } if (t < e) { s = t + 1; continue; } } if (paxseek(pax, ap, -(e - s), SEEK_CUR, 0) < 0) return -1; s = e; } ap->entry = 0; ap->swap = 0; ap->swapio = 0; ap->volume--; i = state.volume[0]; if (getprologue(ap) <= 0) { error(2, "%s: %s format embedded archive expected", ap->name, fp->name); return -1; } state.volume[0] = i; ap->package = strdup(sfprints("%s %s", fp->name, version)); return 1; }
static char *creategrouperstr (DDSschema_t *schemap, DDSexpr_t *gep) { Sfio_t *fp; DDSfield_t *fieldp; int fieldi; char *cstr; if (!(fp = sfopen (NULL, NULL, "sw+"))) { SUwarning (1, "creategrouperstr", "sfopen failed"); return NULL; } sfprintf (fp, "#include <ast.h>\n#include <cdt.h>\n#include <swift.h>\n"); sfprintf (fp, "#include <vmalloc.h>\n#include <dds.h>\n\n"); if (schemap->include) sfprintf (fp, "%s\n\n", schemap->include); sfprintf (fp, "typedef struct __k2chan_t {\n" " Dtlink_t link;\n" " int __key;\n" " char *__name;\n" " void *__chanp;\n" "} __k2chan_t;\n" "static Dtdisc_t __k2chandisc = {\n" " sizeof (Dtlink_t), sizeof (int), 0,\n" " NULL, NULL, NULL, NULL, NULL, NULL\n" "};\n" "static Dt_t *__k2chandict;\n" "static Vmalloc_t *__k2chanvm;\n" "static char *__fmt;\n\n" ); sfprintf (fp, "void *(*openfunc) (char *);\n" "void *(*reopenfunc) (char *);\n\n" "int (*closefunc) (void *);\n" ); sfprintf (fp, "static void *safeopen (char *name) {\n" " void *__chanp;\n" " __k2chan_t *__k2chanp;\n\n" " if ((__chanp = openfunc (name)))\n" " return __chanp;\n" " for (\n" " __k2chanp = dtfirst (__k2chandict); __k2chanp;\n" " __k2chanp = dtnext (__k2chandict, __k2chanp)\n" " )\n" " if (__k2chanp->__chanp) {\n" " closefunc (__k2chanp->__chanp);\n" " __k2chanp->__chanp = NULL;\n" " }\n" " return openfunc (name);\n" "}\n\n" ); sfprintf (fp, "static void *safereopen (char *name) {\n" " void *__chanp;\n" " __k2chan_t *__k2chanp;\n\n" " if ((__chanp = reopenfunc (name)))\n" " return __chanp;\n" " for (\n" " __k2chanp = dtfirst (__k2chandict); __k2chanp;\n" " __k2chanp = dtnext (__k2chandict, __k2chanp)\n" " )\n" " if (__k2chanp->__chanp) {\n" " closefunc (__k2chanp->__chanp);\n" " __k2chanp->__chanp = NULL;\n" " }\n" " return reopenfunc (name);\n" "}\n\n" ); sfprintf (fp, "static int safeclose (__k2chan_t *__k2chanp) {\n" " void *__chanp;\n\n" " if (!(__chanp = __k2chanp->__chanp))\n" " return 0;\n" " __k2chanp->__chanp = NULL;\n" " return closefunc (__chanp) ? 0 : -1;\n" "}\n\n" ); _ddswritestruct (schemap, sfprints ("rec_%s", schemap->name), fp); if (gep->vars) sfprintf (fp, "#line 1 \"VARS\"\n%s\n", gep->vars); sfprintf (fp, "DDS_EXPORT int grouper_%s_init (\n" " char *__prefix, void *(*chopen) (char *),\n" " void *(*chreopen) (char *), int (*chclose) (void *)\n" ") {\n" " if (!(__k2chanvm = vmopen (Vmdcsbrk, Vmbest, 0)) ||\n" " !(__k2chandict = dtopen (&__k2chandisc, Dtset)))\n" " return -1;\n" " openfunc = chopen, reopenfunc = chreopen, closefunc = chclose;\n", schemap->name); sfprintf (fp, " if (strchr (__prefix, '%%'))\n" " __fmt = __prefix;\n" " else if (!(__fmt = vmstrdup (__k2chanvm, sfprints (\n" " \"%%s%%s\", __prefix, \".%%d\"\n" " ))))\n" " return -1;\n" ); sfprintf (fp, " {\n#line 1 \"BEGIN\"\n %s\n }\n" " return 0;\n" "}\n\n", (gep->begin ? gep->begin : "")); sfprintf (fp, "DDS_EXPORT int grouper_%s_term (void) {\n" " __k2chan_t *__k2chanp;\n\n" " {\n#line 1 \"END\"\n %s\n }\n" " for (\n" " __k2chanp = dtfirst (__k2chandict); __k2chanp;\n" " __k2chanp = dtnext (__k2chandict, __k2chanp)\n" " )\n" " if (__k2chanp->__chanp)\n" " safeclose (__k2chanp);\n" " dtclose (__k2chandict);\n" " vmclose (__k2chanvm);\n" " return 0;\n" "}\n\n", schemap->name, (gep->end ? gep->end : "")); sfprintf (fp, "#define GROUP __key\n\n"); for (fieldi = 0; fieldi < schemap->fieldn; fieldi++) { fieldp = &schemap->fields[fieldi]; sfprintf (fp, "#define %s __recp->%s\n", fieldp->name, fieldp->name); } sfprintf (fp, "\n"); sfprintf (fp, "DDS_EXPORT Sfio_t *grouper_%s_work (char *__buf, int __len) {\n" " __k2chan_t *__k2chanp;\n" " int __key;\n" " struct __rec_%s_t *__recp;\n\n" " __recp = (struct __rec_%s_t *) __buf;\n", schemap->name, schemap->name, schemap->name); if (gep->loop) sfprintf ( fp, " {\n#line 1 \"LOOP\"\n %s\n }\n\n", gep->loop ); else sfprintf (fp, "\n __key = 0;\n\n"); sfprintf (fp, " if (__key == -1)\n" " return sfstdin;\n" " if ((__k2chanp = dtmatch (__k2chandict, &__key))) {\n" " if (!__k2chanp->__chanp)\n" " __k2chanp->__chanp = safereopen (__k2chanp->__name);\n" " return __k2chanp->__chanp;\n" " }\n" " if (!(__k2chanp = vmalloc (__k2chanvm, sizeof (__k2chan_t))))\n" " return NULL;\n" " __k2chanp->__key = __key;\n" " if (__k2chanp != (__k2chan_t *) " "dtinsert (__k2chandict, __k2chanp))\n" " return NULL;\n" " __k2chanp->__chanp = NULL;\n" " if (!(__k2chanp->__name = vmstrdup (__k2chanvm, \n" " sfprints (__fmt, __key)\n" " )) || !(__k2chanp->__chanp = safeopen (__k2chanp->__name))\n" " ) {\n" " dtdelete (__k2chandict, __k2chanp);\n" " return NULL;\n" " }\n" " return __k2chanp->__chanp;\n" "}\n" ); if (!(cstr = _ddscopystr (fp))) { SUwarning (1, "creategrouperstr", "copystr failed"); return NULL; } sfclose (fp); return cstr; }
tmain() { Sfio_t *f, *g, *str, *fr, *fw, *sf[2]; int c; char *s; int fd[2]; if(argc > 1) { while((s = sfgetr(sfstdin, '\n', 1)) ) { sfputr(sfstdout, s, '\n'); sfsync(sfstdout); } texit(0); } if(!(str = sfopen(NIL(Sfio_t*),"abc","s")) ) terror("Opening string stream"); if(pipe(fd) < 0) terror("pipe failed"); if(!(fr = sfnew(NIL(Sfio_t*),NIL(Void_t*),(size_t)SF_UNBOUND, fd[0],SF_READ)) ) terror("Opening read pipe stream"); if(!(fw = sfnew(NIL(Sfio_t*),NIL(Void_t*),(size_t)SF_UNBOUND, fd[1],SF_WRITE)) ) terror("Opening write pipe stream"); sf[0] = fr; sf[1] = str; if((c = sfpoll(sf,2,0)) != 1 || sf[0] != str) terror("Only str should be available c=%d",c); sf[0] = fr; if(sfpoll(sf,1,0) != 0 ) terror("Pipe stream should not be ready"); sfputc(fw,'a'); sfsync(fw); sf[0] = fr; if(sfpoll(sf,1,0) != 1 ) terror("Pipe read should be ready"); if((c = sfgetc(fr)) != 'a') terror("Didn't get back right data"); sf[0] = fr; sf[1] = str; if(sfpoll(sf,2,0) != 1 || sf[0] != str) terror("Only str should be available2"); sf[0] = fw; sf[1] = str; if(sfpoll(sf,2,0) != 2) terror("Both str&pipe write should be available"); if(pipe(fd) < 0) terror("Can't create pipe"); if(!(fr = sfnew(fr,NIL(Void_t*),(size_t)SF_UNBOUND,fd[0],SF_READ)) ) terror("Can't create stream"); if(write(fd[1],"0123456789",10) != 10) terror("Can't write to pipe"); if(sfpoll(&fr,1,1000) != 1) terror("Data should be available"); s = sfprints("%s 1", argv[0]); if(!(f = sfpopen(0, s, "w+")) ) terror("Can't create read/write process"); /* this write does not flush yet */ if(sfwrite(f, "abc\n",4) != 4) terror("Writing to pipe"); if(sfpoll(&f, 1, 0) != 1) terror("Poll should succeed"); if(sfvalue(f)&SF_READ) /* data has not been flushed to the child yet */ terror("Read should not be ready"); if(!(sfvalue(f)&SF_WRITE) ) terror("Write should be ready"); if(sfsync(f) < 0) /* now flush data to the child process */ terror("Bad sync"); if(sfpoll(&f, 1, 1000) != 1) terror("Poll should succeed2"); if(!(sfvalue(f)&SF_READ) ) /* the child should have read and rewritten */ terror("Read should be ready"); if(!(sfvalue(f)&SF_WRITE) ) terror("Write should be ready"); if(!(s = sfgetr(f,'\n',1)) || strcmp(s, "abc") != 0) terror("Bad read"); #if _lib_socketpair if(socketpair(AF_UNIX, SOCK_STREAM, 0, fd) != 0) terror("socketpair failed"); if(!(f = sfnew(0,NIL(Void_t*),(size_t)SF_UNBOUND,fd[0],SF_READ|SF_WRITE)) ) terror("Can't create stream with socket file descriptor"); if(!(g = sfnew(0,NIL(Void_t*),(size_t)SF_UNBOUND,fd[1],SF_READ|SF_WRITE)) ) terror("Can't create stream with socket file descriptor"); /* turn off write-capability for f */ sfset(f,SF_WRITE,0); sf[0] = f; sf[1] = g; if(sfpoll(sf,2,0) != 1) terror("Exactly one stream should be ready!"); if(sf[0] != g) terror("Stream g should be ready"); if(sfvalue(g)&SF_READ) terror("Read should not be ready for g"); if(!(sfvalue(g)&SF_WRITE) ) terror("Write should be ready for g"); if(sfwrite(g, "abc\n", 4) != 4 || sfsync(g) < 0) terror("Writing to g socket"); if(sfpoll(sf, 2, 0) != 2) terror("Poll should succeed with both streams"); if(!(sfvalue(f)&SF_READ) ) terror("Read should be ready for f"); if(sfgetc(f) != 'a' ) terror("sfgetc failed"); /* turn back on write-capability for f */ sfset(f,SF_WRITE,1); if(sfwrite(f,"def\n",4) != 4 || sfsync(f) < 0) terror("Writing to f socket"); if(sfpoll(sf, 2, 0) != 2) terror("Poll should succeed for both streams"); if(!sfvalue(f)&SF_READ) terror("Read should be ready for f"); if(!sfvalue(g)&SF_READ) terror("Read should be ready for g"); if(!(s = sfgetr(f,'\n',1)) || strcmp(s,"bc") != 0) terror("f gets wrong data"); if(!(s = sfgetr(g,'\n',1)) || strcmp(s,"def") != 0) terror("g gets wrong data"); if(sfpoll(sf, 2, 0) != 2) terror("Poll should succeed for both streams"); if(sfvalue(f)&SF_READ) terror("Read should not be ready for f"); if(sfvalue(g)&SF_READ) terror("Read should not be ready for g"); #endif texit(0); }
static int genpoints (int attr) { poly_t *pp; int zip, npanxxloc, ctbna; short county, blk; char state, blks; char *s; item_t *itemmem, *itemp; int itemi; int *indp; edge_t *e1p, *e2p; int edgepi; vertex_t *v1p, *v2p, *v3p; int xyi; for ( pp = (poly_t *) dtflatten (polydict); pp; pp = (poly_t *) dtlink (polydict, pp) ) { if (pp->edgepl == 0) continue; e1p = pp->edgeps[0]; if (e1p->p0p == pp) { blks = e1p->blksl; blk = e1p->blkl; ctbna = e1p->ctbnal; county = e1p->countyl; state = e1p->statel; zip = e1p->zipl; npanxxloc = e1p->npanxxlocl; } else { blks = e1p->blksr; blk = e1p->blkr; ctbna = e1p->ctbnar; county = e1p->countyr; state = e1p->stater; zip = e1p->zipr; npanxxloc = e1p->npanxxlocr; } s = NULL; switch (attr) { case T_EATTR_BLKS: if ((state > 0) && (county > 0) && (ctbna > 0) && (blk > 0)) s = sfprints ( "%02d%03d%06d%03d%c", state, county, ctbna, blk, blks ); break; case T_EATTR_BLK: if ((state > 0) && (county > 0) && (ctbna > 0) && (blk > 0)) s = sfprints ("%02d%03d%06d%03d", state, county, ctbna, blk); break; case T_EATTR_BLKG: if ((state > 0) && (county > 0) && (ctbna > 0) && (blk > 0)) s = sfprints ( "%02d%03d%06d%d", state, county, ctbna, blk / 100 ); break; case T_EATTR_CTBNA: if ((state > 0) && (county > 0) && (ctbna > 0)) s = sfprints ("%02d%03d%06d", state, county, ctbna); break; case T_EATTR_COUNTY: if ((state > 0) && (county > 0)) s = sfprints ("%02d%03d", state, county); break; case T_EATTR_STATE: if ((state > 0)) s = sfprints ("%02d", state); break; case T_EATTR_ZIP: if ((zip > 0)) s = sfprints ("%05d", zip); break; case T_EATTR_NPANXXLOC: if ((npanxxloc > -1)) s = sfprints ("%d", npanxxloc); break; case T_EATTR_COUNTRY: s = "USA"; break; } if (!s) continue; if (!(itemmem = malloc (sizeof (item_t)))) { SUwarning (1, "genpoints", "malloc failed for itemmem"); return -1; } itemmem->name = strdup (s); if (!(itemp = dtinsert (itemdict, itemmem))) { SUwarning (1, "genpoints", "dtinsert failed for itemp"); return -1; } if (itemp == itemmem) { itemp->pointn = 0, itemp->pointm = POINTINCR; if (!(itemp->points = malloc (sizeof (point_t) * itemp->pointm))) { SUwarning (1, "genpoints", "malloc failed for points"); return -1; } itemp->indn = 0, itemp->indm = INDINCR; if (!(itemp->inds = malloc (sizeof (int) * itemp->indm))) { SUwarning (1, "genpoints", "malloc failed for inds"); return -1; } itemp->trin = 0, itemp->trim = TRIINCR; if (!(itemp->tris = malloc (sizeof (tri_t) * itemp->trim))) { SUwarning (1, "genpoints", "malloc failed for tris"); return -1; } } orderedges (pp); for (v1p = NULL, edgepi = 0; edgepi < pp->edgepl; edgepi++) { e1p = pp->edgeps[edgepi]; if (!v1p) { if (!(indp = getind (itemp, 0))) { SUwarning (1, "genpoints", "getind failed"); return -1; } if (e1p->p0p == pp) v1p = e1p->v0p, v2p = e1p->v1p; else v1p = e1p->v1p, v2p = e1p->v0p; v3p = v1p; } (*indp)++; if (!getpoint (itemp, v1p->xy)) { SUwarning (1, "genpoints", "getpoint failed (1)"); return -1; } if (v1p == e1p->v0p) { for (xyi = 0; xyi < e1p->xyn; xyi++) { (*indp)++; if (!getpoint (itemp, e1p->xys[xyi])) { SUwarning (1, "genpoints", "getpoint failed (2)"); return -1; } } } else { for (xyi = e1p->xyn - 1; xyi >= 0; xyi--) { (*indp)++; if (!getpoint (itemp, e1p->xys[xyi])) { SUwarning (1, "genpoints", "getpoint failed (3)"); return -1; } } } v1p = NULL; if (edgepi + 1 < pp->edgepl) { e2p = pp->edgeps[edgepi + 1]; if (e2p->v0p == v2p) v1p = e2p->v0p, v2p = e2p->v1p; else if (e2p->v1p == v2p) v1p = e2p->v1p, v2p = e2p->v0p; } if (!v1p) { (*indp)++; if (!getpoint (itemp, v2p->xy)) { SUwarning (1, "genpoints", "getpoint failed (4)"); return -1; } if (savemask & 8) { if (v2p->xy.x != v3p->xy.x || v2p->xy.y != v3p->xy.y) { (*indp)++; if (!getpoint (itemp, v3p->xy)) { SUwarning (1, "genpoints", "getpoint failed (5)"); return -1; } } } } } } itempn = dtsize (itemdict); if (!(itemps = malloc (sizeof (item_t *) * itempn))) { SUwarning (1, "genpoints", "malloc failed for itemps"); return -1; } for ( itemi = 0, itemp = (item_t *) dtflatten (itemdict); itemp; itemp = (item_t *) dtlink (itemdict, itemp) ) itemps[itemi++] = itemp; return 0; }
/* test compliance of certain stdio behaviors */ tmain() { FILE *f, *f2; long s1, s2; int i, k, fd; char buf[128*1024], rbuf[1024], *sp; if(argc > 1) { if(sfwrite(sfstdout,argv[1],strlen(argv[1])) != strlen(argv[1])) terror("Can't write to stdout"); sfsync(sfstdout); return 0; } /* test for shared streams and seek behavior */ if(!(f = fopen(tstfile("sf", 0),"w+")) ) terror("Opening file to read&write"); /* change stdout to a dup of fileno(f) */ fd = dup(1); close(1); dup(fileno(f)); /* write something to the dup file descriptor */ system(sfprints("%s 0123456789", argv[0])); /* change stdout back */ close(1); dup(fd); close(fd); /* this fseek should reset the stream back to where we can read */ fseek(f, 0L, SEEK_SET); /* see if data is any good */ fread(buf, sizeof(buf), 1, f); for(i = 0; i < 10; ++i) if(buf[i] != '0'+i) terror("Bad data0"); /* construct a bunch of lines and out put to f */ sp = buf; for(k = 0; k < sizeof(buf)/10; ++k) { for(i = 0; i < 9; ++i) *sp++ = '0' + i; *sp++ = '\n'; } /* write out a bunch of thing */ fseek(f, 0L, SEEK_SET); if(fwrite(buf, sizeof(buf), 1, f) != 1) terror("Writing data"); if((fd = dup(fileno(f))) < 0) terror("Can't dup file descriptor"); if(!(f2 = fdopen(fd, "r")) ) terror("Can't create stream"); /* read a few bytes from this dup stream */ fseek(f2, 0L, SEEK_SET); rbuf[0] = 0; if(fread(rbuf, 1, 7, f2) != 7) terror("Bad read"); for(i = 0; i < 7; ++i) if(rbuf[i] != '0'+i) terror("Bad data1"); if((s2 = ftell(f2)) != 7) terror("Bad tell location in f2"); /* now seek way off on f */ fseek(f, 1005L, SEEK_SET); rbuf[0] = 0; fread(rbuf, 5, 1, f); for(i = 5; i < 9; ++i) if(rbuf[i-5] != '0'+i) terror("Bad data2"); if(rbuf[i-5] != '\n') terror("Bad data: did not get new-line"); if((s1 = ftell(f)) != 1010) terror("Bad location in f: s1=%lld", (Sflong_t)s1); fseek(f, 0L, SEEK_CUR); /* switch mode so we can write */ if(fputc('x',f) < 0) terror("fputc failed"); if(fflush(f) < 0) terror("fflush failed"); if((s1 = ftell(f)) != 1011) terror("Bad location in f: s1=%lld", (Sflong_t)s1); fseek(f, -1L, SEEK_CUR); /* set the seek location in the file descriptor */ fflush(f2); /* assuming POSIX conformance and to set seek location to 1010 */ if((s2 = ftell(f2)) != 1010) terror("Bad location in f2: s2=%lld", (Sflong_t)s2); fread(rbuf, 10, 1, f2); if(rbuf[0] != 'x') terror("Didn't get x"); for(i = 1; i < 9; ++i) if(rbuf[i] != '0'+i) terror("Bad data3"); if(rbuf[i] != '\n') terror("Did not get new-line"); texit(0); }
int main (int argc, char **argv) { char *ctype, *s1, *s2, *s3, *boundary, *eof, *name; Sfio_t *fp; int state, boundaryn, eofn, atnl, i, n; char c1, c2; if (!(ctype = getenv ("CONTENT_TYPE"))) error (3, "cannot find CONTENT_TYPE env. variable"); if (!(s1 = strchr (ctype, ';'))) error (3, "no field divider"); *s1++ = 0; if (!(s2 = strstr (s1, "boundary="))) error (3, "no boundary field"); s2 += strlen ("boundary="); boundary = strdup (sfprints ("--%s", s2)); boundaryn = strlen (boundary); eof = strdup (sfprints ("%s--", boundary)); eofn = strlen (eof); state = 0; name = NULL; fp = NULL; init (eofn); for (;;) { next: if (state == 0) { /* before eof or boundary */ if (ensurechar ('\n') == -1) error (3, "cannot find NL"); s1 = getcurr (); if (strncmp (s1, eof, eofn) == 0) break; if (strncmp (s1, boundary, boundaryn) == 0) { if (s1[boundaryn] == '\r' && s1[boundaryn + 1] == '\n') advance (boundaryn + 2); else if (s1[boundaryn] == '\n') advance (boundaryn + 1); else error (3, "no CR+NL or NL after boundary"); } else error (3, "boundary or eof not found"); binmode = 0; state = 1; } else if (state == 1) { /* at header section */ if (ensurechar ('\n') == -1) error (3, "cannot find NL"); s1 = getcurr (); if (*s1 == '\r' && *(s1 + 1) == '\n') { advance (2); state = 2; continue; } else if (*s1 == '\n') { advance (1); state = 2; continue; } s3 = strchr (s1, '\n'); c1 = *s3, *s3 = 0; if (strstr (s1, "Content-Type: ")) binmode = 1; if ((s2 = strstr (s1, " name=\""))) { name = s2 + 7; if (!(s2 = strchr (name, '"'))) error (3, "cannot find matching \" for name"); c2 = *s2; *s2 = 0; name = strdup (name); *s2 = c2; if (!(fp = sfopen (NULL, name, "a"))) error (3, "sfopen for name %s failed", name); } *s3 = c1; advance (s3 - s1 + 1); } else if (state == 2) { atnl = 1; wrotenl = 0; for (;;) { next2: ensure (eofn); if ((n = getsize ()) < eofn) error (3, "unexpected EOF"); s1 = getcurr (); if (atnl == 1 && strncmp (s1, boundary, boundaryn) == 0) { if (count2 > 1 && buf2[0] != '\r') sfputc (fp, buf2[0]); if (!binmode && !wrotenl) sfputc (fp, '\n'); count2 = 0; sfclose (fp); state = 0; goto next; } atnl = 0; for (i = 0; i < n; i++) { myputc (fp, s1[i]); if (s1[i] == '\n') { atnl = 1; advance (i + 1); goto next2; } } advance (n); } } } 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; }
static char *createconverterstr ( DDSschema_t *ischemap, DDSschema_t *oschemap, DDSexpr_t *cep ) { Sfio_t *fp; char *cstr; if (!cep->loop) { SUwarning (1, "createconverterstr", "no loop code specified"); return NULL; } if (!(fp = sfopen (NULL, NULL, "sw+"))) { SUwarning (1, "createconverterstr", "sfopen failed"); return NULL; } sfprintf (fp, "#include <ast.h>\n#include <cdt.h>\n#include <swift.h>\n"); sfprintf (fp, "#include <vmalloc.h>\n#include <dds.h>\n\n"); if (ischemap->include) sfprintf (fp, "%s\n\n", ischemap->include); _ddswritestruct (ischemap, sfprints ("inrec_%s", ischemap->name), fp); _ddswritestruct (oschemap, sfprints ("outrec_%s", oschemap->name), fp); if (cep->vars) sfprintf (fp, "#line 1 \"VARS\"\n%s\n", cep->vars); sfprintf (fp, "DDS_EXPORT int converter_%s_init (void) {\n" " {\n#line 1 \"BEGIN\"\n %s\n }\n" " return 0;\n" "}\n\n", ischemap->name, (cep->begin ? cep->begin : "")); sfprintf (fp, "DDS_EXPORT int converter_%s_term (void) {\n" " {\n#line 1 \"END\"\n %s\n }\n" " return 0;\n" "}\n\n", ischemap->name, (cep->end ? cep->end : "")); sfprintf (fp, "#define KEEP __result = 1\n#define DROP __result = 0\n\n"); sfprintf (fp, "#define NREC __nrec\n#define INDEX (*__indexp)\n\n"); sfprintf (fp, "#define IN __inrecp\n"); sfprintf (fp, "#define OUT __outrecp\n\n"); sfprintf ( fp, "#define EMIT (*__emitfunc) (" " __emitfp, __outrecp, __outschemap, __outlen" "), __result = 0\n\n" ); sfprintf (fp, "DDS_EXPORT int converter_%s_work (" " char *__inbuf, int __inlen, DDSschema_t *__inschemap," " char *__outbuf, int __outlen, DDSschema_t *__outschemap," " long long *__indexp, long long __nrec, " " int (*__emitfunc) (Sfio_t *, void *, DDSschema_t *, size_t), " " Sfio_t *__emitfp" ") {\n" " struct __inrec_%s_t *__inrecp;\n" " struct __outrec_%s_t *__outrecp;\n" " int __result = 1;\n\n" " __inrecp = (struct __inrec_%s_t *) __inbuf;\n" " __outrecp = (struct __outrec_%s_t *) __outbuf;\n", ischemap->name, ischemap->name, oschemap->name, ischemap->name, oschemap->name ); sfprintf (fp, " {\n#line 1 \"LOOP\"\n %s\n }\n\n", cep->loop); sfprintf (fp, " return __result;\n"); sfprintf (fp, "}\n"); if (!(cstr = _ddscopystr (fp))) { SUwarning (1, "createconverterstr", "copystr failed"); return NULL; } sfclose (fp); return cstr; }
int IMPLLbegindraw ( char *fprefix, int findex, char *gmattr, char *tlattr, char *tlurl, char *tlobj ) { IMPLLnd_t *ndp; int ndi; UTattr_t *ap; int focusflag; char *gmbg, *gmcl, *gmfn, *gmfs, *gmfcl; int gmlw; char *tllab, *tlcl, *tlfn, *tlfs, *tlinfo; int tlshowtitle; Sfio_t *fp; if (IMPLLndn == 0) return 0; tlshowtitle = FALSE; if (UTsplitattr (UT_ATTRGROUP_MAIN, gmattr) == -1) { SUwarning (0, "IMPLLbegindraw", "cannot parse attrstr"); return -1; } if (UTgetattrs (UT_ATTRGROUP_MAIN) == -1) { SUwarning (0, "IMPLLbegindraw", "cannot get invmap attr"); return -1; } if (UTsplitattr (UT_ATTRGROUP_TITLE, tlattr) == -1) { SUwarning (0, "IMPLLbegindraw", "cannot parse attrstr"); return -1; } if (UTgetattrs (UT_ATTRGROUP_TITLE) == -1) { SUwarning (0, "IMPLLbegindraw", "cannot get title attr"); return -1; } ap = &UTattrgroups[UT_ATTRGROUP_MAIN][UT_ATTR_FLAGS]; focusflag = (ap->value && strstr (ap->value, "focus")) ? TRUE : FALSE; ap = &UTattrgroups[UT_ATTRGROUP_MAIN][UT_ATTR_WIDTH]; width = height = 0; if (ap->value && ap->value[0]) width = atoi (ap->value); if (width <= 0) width = 1000; ap = &UTattrgroups[UT_ATTRGROUP_MAIN][UT_ATTR_HEIGHT]; if (ap->value && ap->value[0]) height = atoi (ap->value); if (height <= 0) height = 600; focusx1 = focusy1 = FLT_LONG_MAX; focusx2 = focusy2 = FLT_LONG_MIN; for (ndi = 0; ndi < IMPLLndn; ndi++) { ndp = IMPLLnds[ndi]; if (!ndp->havecoord) continue; if (focusx1 > ndp->llx) focusx1 = ndp->llx; if (focusy1 > ndp->lly) focusy1 = ndp->lly; if (focusx2 < ndp->llx) focusx2 = ndp->llx; if (focusy2 < ndp->lly) focusy2 = ndp->lly; } ap = &UTattrgroups[UT_ATTRGROUP_TITLE][UT_ATTR_LABEL]; if (ap->value && ap->value[0]) { tllab = ap->value; ap = &UTattrgroups[UT_ATTRGROUP_TITLE][UT_ATTR_COLOR]; tlcl = (ap->value) ? ap->value : "black"; ap = &UTattrgroups[UT_ATTRGROUP_TITLE][UT_ATTR_FONTNAME]; tlfn = (ap->value) ? ap->value : "Times-Roman"; ap = &UTattrgroups[UT_ATTRGROUP_TITLE][UT_ATTR_FONTSIZE]; tlfs = (ap->value) ? ap->value : "8"; tlshowtitle = TRUE; } ap = &UTattrgroups[UT_ATTRGROUP_TITLE][UT_ATTR_INFO]; tlinfo = ap->value; ap = &UTattrgroups[UT_ATTRGROUP_MAIN][UT_ATTR_BGCOLOR]; gmbg = (ap->value && ap->value[0]) ? ap->value : "white"; ap = &UTattrgroups[UT_ATTRGROUP_MAIN][UT_ATTR_COLOR]; gmcl = (ap->value && ap->value[0]) ? ap->value : "black"; ap = &UTattrgroups[UT_ATTRGROUP_MAIN][UT_ATTR_LINEWIDTH]; gmlw = (ap->value && ap->value[0]) ? atoi (ap->value) : 1; ap = &UTattrgroups[UT_ATTRGROUP_MAIN][UT_ATTR_FONTNAME]; gmfn = (ap->value) ? ap->value : "Times-Roman"; ap = &UTattrgroups[UT_ATTRGROUP_MAIN][UT_ATTR_FONTSIZE]; gmfs = (ap->value) ? ap->value : "8"; ap = &UTattrgroups[UT_ATTRGROUP_MAIN][UT_ATTR_FONTCOLOR]; gmfcl = (ap->value) ? ap->value : "black"; sfprintf ( sfstdout, "%s.%d.lllist\n%s.%d.html\n%s.%d.css\n", fprefix, findex, fprefix, findex, fprefix, findex ); if (pagem > 0 && pagei++ % pagem == 0) { sfprintf (sfstdout, "%s.%d.toc\n", fprefix, findex); if (!(fp = sfopen ( NULL, sfprints ("%s.%d.toc", fprefix, findex), "w" ))) { SUwarning (0, "IMPLLbegindraw", "cannot open toc file"); return -1; } sfprintf (fp, "map %d", pagei); sfclose (fp); } if (!(fp = sfopen ( NULL, sfprints ("%s.%d.css", fprefix, findex), "w" ))) { SUwarning (0, "IMPLLbegindraw", "cannot open css file"); return -1; } sfprintf (fp, "<link rel='stylesheet' href='SWIFTLLCSS'/>\n"); sfprintf (fp, "<script src='SWIFTLLJS'></script>\n"); sfclose (fp); if (!(lfp = sfopen ( NULL, sfprints ("%s.%d.lllist", fprefix, findex ), "w"))) { SUwarning (0, "IMPLLbegindraw", "cannot open altlist file"); return -1; } if (!(hfp = sfopen (NULL, sfprints ("%s.%d.html", fprefix, findex), "w"))) { SUwarning (0, "IMPLLbegindraw", "cannot open html file"); return -1; } if (tlshowtitle) { sfprintf ( hfp, "<div class=page style='font-family:%s; font-size:%d; color:%s'>" "</div>\n" ); if ((tlinfo && tlinfo[0]) || (tlurl && tlurl[0])) { if (tlinfo && tlinfo[0]) sfprintf ( hfp, "<a class=page href='%s' title='%s'>%s</a>", tlurl, tlinfo, tllab ); else if (tlobj && tlobj[0]) sfprintf ( hfp, "<a class=page href='%s' title='%s'>%s</a>", tlurl, tlobj, tllab ); else sfprintf (hfp, "<a class=page href='%s'>%s</a>", tlurl, tllab); } else { sfprintf (hfp, "%s", tllab); } sfprintf (hfp, "</div"); } sfprintf ( hfp, "<div class=page id=map%d style='width:%dpx; height:%dpx'></div>\n", findex, width, height ); sfprintf (hfp, "<script>\n"); sfprintf (hfp, "var map%d = L.map('map%d')", findex, findex); if (focusflag) { if (focusx2 - focusx1 > 0.00001 && focusy2 - focusy1 > 0.00001) sfprintf ( hfp, ".fitBounds([[%f,%f],[%f,%f]]);\n", focusy1, focusx1, focusy2, focusx2 ); else sfprintf ( hfp, ".setView([%f,%f], 12);\n", (focusy1 + focusy2) / 2.0, (focusx1 + focusx2) / 2.0 ); } else { sfprintf ( hfp, ".setView([%f,%f], 4);\n", (focusy1 + focusy2) / 2.0, (focusx1 + focusx2) / 2.0 ); } sfprintf ( hfp, "L.tileLayer('SWIFTLLTILESERVER', {" " maxZoom:18, attribution: 'SWIFTLLTILEATTR' " "}).addTo(map%d);\n", findex ); return 0; }