You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(49) |
Sep
(25) |
Oct
(2) |
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(24) |
Nov
(50) |
Dec
(4) |
2004 |
Jan
(2) |
Feb
(2) |
Mar
(5) |
Apr
|
May
(10) |
Jun
|
Jul
(10) |
Aug
(22) |
Sep
(10) |
Oct
|
Nov
(57) |
Dec
(5) |
2005 |
Jan
(24) |
Feb
(12) |
Mar
|
Apr
|
May
(3) |
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2006 |
Jan
|
Feb
|
Mar
|
Apr
(9) |
May
(5) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
(1) |
From: <le...@us...> - 2002-09-15 12:58:34
|
Update of /cvsroot/meshdb/src/geo/rf In directory usw-pr-cvs1:/tmp/cvs-serv3102/geo/rf Modified Files: main.c Log Message: fix some bugs in psplot add some macros to geodesy.h make compat with openbsd Index: main.c =================================================================== RCS file: /cvsroot/meshdb/src/geo/rf/main.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- main.c 10 Aug 2002 03:51:33 -0000 1.1.1.1 +++ main.c 15 Sep 2002 12:58:29 -0000 1.2 @@ -201,11 +201,11 @@ exit(1); } - if (zone == -1 && togrid) { + if (zone == -1 && togrid) /* calculate which zone a longitude is in */ - zone = 31 + (int)((lon * 180 / M_PI) / 6); - } - geo.lambda0 = ((6*(zone-31)+3)*M_PI/180); + zone = ZONE(lon); + geo.lambda0 = CENTRAL_MERIDIAN(zone); + geodesy_init(&geo); if (togrid) |
From: <le...@us...> - 2002-09-15 07:24:11
|
Update of /cvsroot/meshdb/src/vpf/psplot In directory usw-pr-cvs1:/tmp/cvs-serv5042 Modified Files: Makefile psplot.c Added Files: NOTES Log Message: add abbreviations; add UTM plotting --- NEW FILE: NOTES --- psplot reads a postscript template file, and emits moveto/lineto/fill/stroke commands to draw features from a VPF database. The command line arguments are used to determine what area and size to output. The output postscript is sent to stdout. The default square is 500x500. psplot [-f cmd.file] [-p w h] lat_s lon_w lat_n lon_e Command file The command file is copied as literal postscript text. However if the line starts with the two characters "%." then it is treated as a special command introducer. Commands take the form %. <command> [<args>] [% comment] Commands %.DATABASE <path> %.DATABASE /openbsd/tmp/gm_v1/AUS/globalm DATABASE: sets the root database directory context %.LIBRARY <name> %.LIBRARY area LIBRARY: open a library in the database and load tile information. %.COVERAGE <name> %.COVERAGE bnd COVERAGE: sets the current coverage directory for future feature commands %.FEATURE <name> %.FEATURE oceansea FEATURE: sets the current feature. This selects feature tables and determines what kind of feature (area, line or point) we are dealing with. %.PLOT [<col> <rel> <value> ...] %.PLOT type=26 PLOT: selectively plots the current feature's primitives (lines or area) for only the features that match all the given conditions. If no conditions are provided, all of the feature is plotted. Areas are 'fill'ed and lines are 'stroke'd. %.WHOLEPATH WHOLEPATH: generates a rectangular path that represents the bounds of the plotted area. Usually this is followed by a 'clip' command on a separate line. Index: Makefile =================================================================== RCS file: /cvsroot/meshdb/src/vpf/psplot/Makefile,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Makefile 14 Sep 2002 14:43:55 -0000 1.1 +++ Makefile 15 Sep 2002 07:24:06 -0000 1.2 @@ -5,4 +5,9 @@ DPADD= ${LIBVPF} NOMAN= +LDADD+= -lgeo +LIBGEO= ${.CURDIR}/../../geo/libgeo +LDFLAGS= -L${LIBGEO} -L/usr/local/lib +CFLAGS= -I${LIBGEO} + .include <bsd.prog.mk> Index: psplot.c =================================================================== RCS file: /cvsroot/meshdb/src/vpf/psplot/psplot.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- psplot.c 14 Sep 2002 14:43:55 -0000 1.1 +++ psplot.c 15 Sep 2002 07:24:06 -0000 1.2 @@ -8,51 +8,78 @@ #include <string.h> #include <stdlib.h> #include <stdarg.h> +#include "geodesy.h" #include "vpf.h" +#define RADIANS(deg) ((deg) * M_PI / 180) +#define DEGREES(rad) ((rad) * 180 / M_PI) + +#define VFREE(v) do { \ + if (v) vpf_free(v); \ + v = NULL; \ + } while (0) + +#define TFREE(t) do { \ + if (t) vpfref_free(t); \ + t = NULL; \ + } while (0) + +static void die(const char *fmt, ...); +static void strip(char *, int); + +/* Set by -v flag */ int verbose = 0; +/* Context for current database, library and coverage */ struct vpf *vdb = NULL; struct vpf *vlib = NULL; struct vpf *vcov = NULL; -/* tiles in our area of interest */ +/* Currently selected feature */ +char fname[9]; +char ftype; + +/* Tile names in the current library */ char **tilename; int *tiles; int ntiles; + +/* IF/ELSE/ENDIF tracking */ int ifon = 1; int ifoff = 0; -int lineno = 0; -#define RELNE '!' -#define RELGE '+' -#define RELLE '-' +/* Line number in input file */ +int lineno = 0; -char ftype; -char fname[9]; +/* Multi-character relations reduced to unique char */ +#define RELNE '!' /* != */ +#define RELGE '+' /* >= */ +#define RELLE '-' /* <= */ +/* bounding curvilinear coords for searching */ double ux1, uy1, ux2, uy2; -double pwidth = 500, pheight = 500; -/* parameters */ -double p_scale; +/* Physical output size & scale */ +double pwidth = 500, pheight = 500, pscale; -/* number of postscript points per degree of latitude */ -#define PTDEG 3149603.1496062996 +/* Converting from curvilinear to utm */ +struct geodesy geo = GEODESY_MGA94(0); -#define VFREE(v) do { \ - if (v) vpf_free(v); \ - v = NULL; \ - } while (0) +/* Centre of image in UTM */ +double uce, ucn; -#define TFREE(t) do { \ - if (t) vpfref_free(t); \ - t = NULL; \ - } while (0) +/* parameters */ +double PARAM_scale; -static void die(const char *fmt, ...); -static void strip(char *, int); +/* strings used for possibly abbreviated postscipt ops */ +char ps_moveto[256] = "moveto"; +char ps_lineto[256] = "lineto"; +char ps_stroke[256] = "stroke"; +char ps_fill[256] = "fill"; +char ps_closepath[256]= "closepath"; +char ps_newpath[256] = "newpath"; +/* Remove trailing spaces from a string & nul terminate */ static void strip(buf, buflen) char *buf; @@ -68,8 +95,9 @@ buf[i] = '\0'; } +/* Fatal error */ static void -die(const char *fmt, ...) +die(const char *fmt, ...) /* __dead */ { va_list ap; @@ -81,18 +109,21 @@ exit(1); } +/* Close current feature */ void closefeature() { fname[0] = '\0'; ftype = '\0'; } +/* Close current coverage */ void closecov() { closefeature(); VFREE(vcov); } +/* Close current library */ void closelib() { int i; @@ -104,10 +135,13 @@ free(tilename); free(tiles); ntiles = 0; + tiles = NULL; + tilename = NULL; } VFREE(vlib); } +/* Close current database */ void database(arg) char *arg; @@ -118,27 +152,77 @@ if (!vdb) die("DATABASE: %s", arg); } +/* + * Project lat/long coord to UTM and then + * transform into to postscript coords. + */ void printcoord(x, y) double x, y; { + double e, n; + + geodesy_geo2grid(&geo, RADIANS(y), RADIANS(x), + &e, &n, NULL, NULL); + printf("%.5g %.5g ", + pscale * (e-uce) + (pwidth/2), + pscale * (n-ucn) + (pheight/2)); +/* printf("%.9g %.9g ", (x - ux1) * pwidth / (ux2 - ux1), (y - uy1) * pheight / (uy2 - uy1)); +*/ } -/* Plot a path enclosing the screen. (user to fill/stroke/clip) */ +/* + * Emit postscript path representing logically + * clipped area (ux1,uy1)-(ux2,uy2). Used for + * debugging. Should always appear *outside* the + * pwidth/pheight rectangle. + */ + +#define WPSEGS 4 void wholepath() { - printcoord(ux1, uy1); printf("moveto\n"); - printcoord(ux1, uy2); printf("lineto\n"); - printcoord(ux2, uy2); printf("lineto\n"); - printcoord(ux2, uy1); printf("lineto\n"); - printf("closepath\n"); + double qy = uy2-uy1; + double qx = ux2-ux1; + double x, y; + struct { double ox, oy, dx, dy; } edge[] = { + { 0, 0, +1, 0 }, + { 1, 0, 0, +1 }, + { 1, 1, -1, 0 }, + { 0, 1, 0, -1 } + }; + int i, j; + + for (j = 0; j < 4; j++) + for (i = 0; i < WPSEGS; i++) { + x = ux1 + qx*(edge[j].ox + (edge[j].dx * i) / WPSEGS); + y = uy1 + qy*(edge[j].oy + (edge[j].dy * i) / WPSEGS); + + printcoord(x, y); + puts((!i && !j) ? ps_moveto : ps_lineto); + } + puts(ps_closepath); } -/* Scan the 'tileref' coverage and store tile IDs and subdir names */ +/* + * Emit postscript to clip output to the user's desired rectangle + */ +void +clip() +{ + printf("%s 0 0 %s %.2g 0 %s %.2g %.2g %s 0 %.2g %s %s clip", + ps_newpath, + ps_moveto, pwidth, + ps_lineto, pwidth, pheight, + ps_lineto, pheight, + ps_lineto, + ps_closepath); +} + +/* Load the definitions of the tiles we can see from the library */ void tile_init() { @@ -210,10 +294,9 @@ vlib = vpf_new_subdir(vdb, arg); if (!vlib) die("LIBRARY: %s", arg); - /* Look for a tileref coverage */ + /* Search for a tileref coverage in 'cat' */ t = vpf_table(vlib, "cat"); if (!t) die("cat: %s", vpf_error(vlib)); - vpftab_bind(t, "8T:coverage_name", name); while (vpftab_fetch(t)) { strip(name, sizeof name); @@ -245,9 +328,10 @@ { struct vpftab *fca; - /* Figure out what kind of coverage it is */ if (!vcov) die("feature: no COVERAGE"); closefeature(); + + /* Figure out what kind of feature we are opening */ fca = vpf_table(vcov, "fca"); if (!fca) die("fca: %s", vpf_error(vcov)); vpftab_bind(fca, "8T:fclass,1T:type", fname, &ftype); @@ -268,6 +352,8 @@ * If the edge is totally invisible, ignore it, * unless lineto is specifified, and then we simply * approximate the edge! + * We also have to be very careful with the direction + * we draw the edge. */ void plotedge(id, edg, ebr, zlen, zarray, bound, rfp, rface, lineto, mandatory) @@ -305,33 +391,28 @@ printcoord(zarray[0][0], zarray[0][1]); else printcoord(zarray[len-1][0], zarray[len-1][1]); - printf("moveto\n"); + puts(ps_moveto); } if (fwd) printcoord(zarray[len-1][0], zarray[len-1][1]); else printcoord(zarray[0][0], zarray[0][1]); - printf("lineto\n"); + puts(ps_lineto); return; } if (fwd) for (i = 0; i < len; i++) { printcoord(zarray[i][0], zarray[i][1]); - if (i || lineto) - printf("lineto\n"); - else - printf("moveto\n"); + puts((i||lineto) ? ps_lineto : ps_moveto); } else for (i = len - 1; i >= 0; i--) { printcoord(zarray[i][0], zarray[i][1]); - if (i < len-1 || lineto) - printf("lineto\n"); - else - printf("moveto\n"); + puts((i < len-1 || lineto) ? ps_lineto : ps_moveto); } } +/* Plot the parts of a feature that match the given predicates */ void plot(arg) char *arg; @@ -376,21 +457,24 @@ if (!ftype) die("plot: no FEATURE"); - /* Figure out some table and column names */ + /* Figure out the feature table name */ snprintf(ftable, sizeof ftable, "%s.%cft", fname, tolower(ftype)); snprintf(ftableidtype, sizeof ftableidtype, "I:%s_id", ftable); - /* Open the feature table */ + /* Can we open the feature table? */ ft = vpf_table(vcov, ftable); if (!ft) die("%s: %s", ftable, vpf_error(vcov)); - /* Parse and bind the search terms! */ + /* Parse the selector predicates, if any */ for (s = arg; *s;) { char bbuf[30]; + /* skip white */ while (*s == ' ') s++; if (!*s) break; + + /* Get the column name */ cn = s; while (*s && *s != ' ' && *s != '<' && @@ -398,13 +482,17 @@ *s != '!') s++; ch = *s; *s++ = '\0'; + /* Does the column exist? */ colidx = vpftab_colindex(ft, cn); if (colidx < 0) die("unknown column %s in feature %s", cn, fname); vpftab_info(ft, colidx, &ci); + /* Skip white */ while (ch == ' ') ch = *s++; + + /* Get the relation (=,<.>,!=,<=,>=) */ if (ch == '!' && *s == '=') { rel = RELNE; s++; } else if (ch == '<' && *s == '=') @@ -415,26 +503,36 @@ { rel = ch; } else die("expected <,>,=,!=,<=,>= at %c%s", ch, s); - while (*s == ' ') s++; + /* Skip white */ + while (*s == ' ') + s++; + + /* Parse the right hand side, and bind the column */ if (ci.datatype == 'T') { if (rel != '=' && rel != RELNE) die("expected = or != for string compare of col %s", cn); + + /* Expect a quoted string (e.g.: "foo") */ if (*s != '"') die("expected '\"' at %s", s); s++; mstr[nmstr] = s; while (*s && *s != '"') s++; if (*s != '"') die("expected '\"' at %s", s); *s++ = '\0'; + + /* Bind the string */ astrlen[nmstr] = sizeof astr[nmstr] - 1; snprintf(bbuf, sizeof bbuf, "*T:%s", cn); if (!vpftab_bind(ft, bbuf, &astrlen[nmstr], astr[nmstr])) die("%s", vpf_error(vcov)); + mstrrel[nmint] = rel; if (verbose) printf("%% filter (string) %s %c \"%s\"\n", cn, rel, mstr[nmstr]); nmstr++; } else if (ci.number == 1 && (ci.datatype == 'I' || ci.datatype == 'S')) { + /* Right hand side should be an integer number */ t = s; mint[nmint] = strtol(t, &s, 0); if (t == s) die("expected number at %s", t); @@ -447,6 +545,7 @@ printf("%% filter (int) %s %c %d\n", cn, rel, mint[nmint]); nmint++; } else if (ci.number == 1 && (ci.datatype == 'R' || ci.datatype == 'F')) { + /* Right hand side should be a real number */ t = s; mreal[nmreal] = strtod(t, &s); if (t == s) die("expected number at %s", t); @@ -463,7 +562,7 @@ cn, ci.number, ci.datatype); } - /* Start plotting tiles */ + /* Look for features in each visible tile */ for (ti = 0; ti < ntiles; ti++) { /* Open up a tile directory */ tile = tiles[ti]; @@ -478,7 +577,8 @@ case 'L': si = vpf_si(v, "esi"); break; default: die("unknown feature type %c", ftype); } - /* No index means no data! */ + + /* No spatial index means no data! */ if (!si) { vpf_free(v); continue; } /* Open up tables depending on feature primitive type */ @@ -574,6 +674,7 @@ printf(" ]\n"); } + /* Check each of the given condition relations */ matches = 1; for (i = 0; matches && i < nmint; i++) switch (mintrel[i]) { @@ -602,15 +703,14 @@ } } if (!matches) - continue; - - /* Check against matching expression */ + continue; /* something didn't match */ + /* Now plot the feature! */ switch (ftype) { case 'P': break; case 'A': /* start plotting the ring paths. */ - printf("newpath\n"); + puts(ps_newpath); if (verbose) printf("%% ring_ptr is %d\n", ring_ptr); vpftab_seek(rng, ring_ptr); @@ -641,19 +741,19 @@ printf("%% next edge = %d\n", cur); plotedge(cur, edg, ebr, &zlen, zarray, bound, &rf.id, ringface, 1, 1); } - printf("closepath\n"); + puts(ps_closepath); } /* NB outer ring is clockwise; inner rings are ccw! */ - printf("fill\n"); + puts(ps_fill); break; case 'L': plotedge(primid, edg, ebr, &zlen, zarray, bound, NULL, 0, 0, 0); - printf("stroke\n"); + puts(ps_stroke); break; } } - /* cleanup */ + /* release allocated storage */ vpftab_free(tt); switch (ftype) { case 'P': vpftab_free(end); @@ -670,26 +770,11 @@ } } + /* Release the feature table */ vpftab_free(ft); } -/* push a length (measured in degrees) onto the postscript stack */ -void -pushlen(buf) - char *buf; -{ - double num; - char *ret; - - if (*buf == '\0') num = 1.0; - else { - num = strtod(buf, &ret); - if (ret == buf) die("expected floating point number at %s", buf); - } - printf("%.9g\n", num * pwidth / (ux2 - ux1)); -} - -/* Compute the truth of a '[!]<param> [<rel> <rhs>]' expression */ +/* Evaluate the expression in an IF/ELSE command. Return true/false */ int ifeval(buf) char *buf; @@ -745,7 +830,7 @@ } if (strcmp(param_name, "scale") == 0) - param_val = p_scale; + param_val = PARAM_scale; else die("unknown parameter '%s'", param_name); @@ -767,6 +852,47 @@ return negated ? !truth : truth; } +/* Set up postscript abbreviations */ +void +abbrev(arg) + char *arg; +{ + struct { + const char *name; + char *buf; + } abbrevs[] = { + { "moveto", ps_moveto }, + { "lineto", ps_lineto }, + { "stroke", ps_stroke }, + { "fill", ps_fill }, + { "closepath", ps_closepath }, + { "newpath", ps_newpath }, + }; + char *p, *name, *buf, *b, i; + + p = arg; + for (;;) { + /* Skip whitespace */ + while (*p == ' ' || *p == '\t') + p++; + if (!*p) break; + name = p; + while (*p && *p != '=') p++; + if (*p != '=') die("expected '=' in ABBREV at %s", p); + *p++ = '\0'; + buf = NULL; + for (i = 0; i < (sizeof abbrevs / sizeof abbrevs[0]); i++) + if (strcmp(abbrevs[i].name, name) == 0) + { buf = abbrevs[i].buf; break; } + if (!buf) die("unknown abbreviation '%s'", name); + for (b = buf; *p && *p != ' ' && *p != '\t'; ) + *b++ = *p++; + *b = '\0'; + if (verbose) + printf("%% abbreviating '%s' as '%s'\n", name, buf); + } +} + /* Process a "%.COMMAND" line including .IF/.ENDIF expressions */ void command(buf) @@ -787,13 +913,16 @@ { "FEATURE", feature }, { "PLOT", plot }, { "WHOLEPATH", wholepath }, - { "PUSHLEN", pushlen }, + { "CLIP", clip }, + { "ABBREV", abbrev }, }; - /* Find command text */ + /* Skip whitespace: 1st word is the command */ cmd = buf; - while (*cmd == ' ' || *cmd == '\t') cmd++; - /* Skip command text */ + while (*cmd == ' ' || *cmd == '\t') + cmd++; + + /* Skip command to get to the argument text */ for (arg = cmd; *arg; arg++) if (*arg == ' ' || *arg == '\t') { /* Terminate command word */ @@ -868,10 +997,11 @@ return; } - /* Ignore command if we are if'd out */ + /* Ignore command if we are in an 'IF false' block */ if (ifoff) return; + /* Locate the command function and call it */ for (i = 0; i < sizeof cmdtab / sizeof cmdtab[0]; i++) if (strcmp(cmd, cmdtab[i].cmd) == 0) { (*cmdtab[i].fn)(arg); @@ -880,6 +1010,64 @@ fprintf(stderr, "unknown command '%s'\n", cmd); } +/* Compute scales & extents of map to plot */ +void +initarea(lat, lon, zoom) + double lat, lon, zoom; +{ + int dx, dy; + double ty, tx; + double e, n; + + /* Initialise the UTM-curvilinear conversion constants */ + geo.lambda0 = CENTRAL_MERIDIAN(ZONEDEG(lon)); + geodesy_init(&geo); + + /* + * 'zoom' indicates the number of UTM metres that one pixel + * (postscript point) should span. + */ + + pscale = 1/zoom; + + uy1 = uy2 = RADIANS(lat); + ux1 = ux2 = RADIANS(lon); + geodesy_geo2grid(&geo, RADIANS(lat), RADIANS(lon), &uce, &ucn, + NULL, NULL); + + if (verbose) { + fprintf(stderr, "central meridian at longitude %g\n", DEGREES(geo.lambda0)); + fprintf(stderr, "uce,ucn=(%g,%g)\n", uce, ucn); + } + + for (dx = -1; dx <= 1; dx++) + for (dy = -1; dy <= 1; dy++) + { + e = uce + dx*zoom*pwidth/2; + n = ucn + dy*zoom*pheight/2; + geodesy_grid2geo(&geo, e, n, &ty, &tx, NULL, NULL); + if (verbose) + fprintf(stderr, "can see lat %g lon %g at e %g n %g\n", + DEGREES(ty), DEGREES(tx), e, n); + if (ty < uy1) uy1 = ty; + if (ty > uy2) uy2 = ty; + if (tx < ux1) ux1 = tx; + if (tx > ux2) ux2 = tx; + } + ux1 = DEGREES(ux1); + uy1 = DEGREES(uy1); + ux2 = DEGREES(ux2); + uy2 = DEGREES(uy2); + if (verbose) { + fprintf(stderr, "ux1,uxy=(%g,%g) ux2,uy2=(%g,%g)\n", ux1, uy1, ux2, uy2); + } + + + /* 1 point(pixel) on map represents : PARAM_scale points in reality */ + /* Assume 72 points per inch */ + PARAM_scale = zoom / (0.0254/72); +} + int main(argc, argv) int argc; @@ -891,8 +1079,10 @@ int i; int sol = 1; int error = 0; + double lat=0, lon=0, zoom=0; - while ((ch = getopt(argc, argv, "g:f:")) != -1) + /* Parse command line options */ + while ((ch = getopt(argc, argv, "f:g:v")) != -1) switch (ch) { case 'f': if (in) fclose(in); @@ -906,39 +1096,43 @@ else pheight = strtod(p, NULL); break; + case 'v': + verbose = 1; + break; default: error = 1; } - if (argc - optind != 4) + if (argc - optind == 3) { + lat = strtod(argv[optind+0], NULL); + lon = strtod(argv[optind+1], NULL); + zoom = strtod(argv[optind+2], NULL); + } else error = 1; if (error) { fprintf(stderr, "usage: %s [-g WxH]" - " [-f file]" - " lat_s lon_w lat_n lon_e\n", + " [-f file] [-v]" + " lat lon zoom\n", argv[0]); exit(1); } - uy1 = strtod(argv[optind+0], NULL); - ux1 = strtod(argv[optind+1], NULL); - uy2 = strtod(argv[optind+2], NULL); - ux2 = strtod(argv[optind+3], NULL); - - /* 1 point on map represents : p_scale points in reality */ - p_scale = ((ux2 - ux1) * PTDEG) / pwidth; - - if (verbose) fprintf(stderr, "SCALE is 1:%f\n", p_scale); + initarea(lat, lon, zoom); + if (verbose) fprintf(stderr, "SCALE is 1:%f\n", PARAM_scale); + /* Use standard input if a file was not given */ if (in == NULL) in = stdin; + /* Reach lines from the input file */ while ((ch = getc(in)) != EOF) if (sol && ch == '%') { + /* Got a '%', hoping for a '.' now */ ch = getc(in); sol = 0; if (ch == '.') { + /* Capture up to next %/newline */ for (i = 0; i < sizeof buf - 1; i++) { ch = getc(in); if (ch == '\n' || ch == '\r') { @@ -965,7 +1159,9 @@ if (sol) lineno++; } + /* Make sure IF/ENDIF were balanced */ if (ifoff || ifon != 1) die("missing ENDIF(s)"); + exit(0); } |
Update of /cvsroot/meshdb/src/vpf/libvpf In directory usw-pr-cvs1:/tmp/cvs-serv13680/libvpf Added Files: Makefile vpf.c vpf.h vpf_join.c vpf_select.c vpf_si.c vpf_si.h vpf_theme.c vpfint.h vpfpath.h Log Message: got VPF stuff working on OpenBSD/sparc using www.iscgm.org data --- NEW FILE: Makefile --- # $Id: Makefile,v 1.1 2002/09/14 14:43:54 leonard Exp $ SRCS= vpf.c vpf_join.c vpf_select.c vpf_si.c vpf_theme.c LIB= vpf NOMAN= LDADD= -lm NOPIC= .include <bsd.lib.mk> --- NEW FILE: vpf.c --- /* $Id: vpf.c,v 1.1 2002/09/14 14:43:55 leonard Exp $ */ /* David Leonard, 2002. Public domain */ /* Vector Product Format MIL-STD-2407 database access */ #include <stdio.h> #include <fcntl.h> #include <stdarg.h> #include <string.h> #include <stdlib.h> #include <errno.h> #include <unistd.h> #include <ctype.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/param.h> #include <sys/mman.h> #include "vpf.h" [...1183 lines suppressed...] tt->t.cells = (struct cell **)malloc(t->ncols * sizeof (struct cell *)); if (tt->t.cells == NULL) { free(tt->cells); free(tt); vpf_seterror(v, "malloc"); return NULL; } tt->table = t; tt->row = 0; /* Fill in the cell pointers for fetching later */ for (i = 0; i < t->ncols; i++) { tt->t.cells[i] = &tt->cells[i]; tt->t.cells[i]->col = &t->col[i]; tt->t.cells[i]->count = t->col[i].count; tt->t.cells[i]->data = NULL; } return (struct vpftab *)tt; } --- NEW FILE: vpf.h --- /* $Id: vpf.h,v 1.1 2002/09/14 14:43:55 leonard Exp $ */ /* David Leonard, 2002. Public domain */ #ifndef _h_vpf_ #define _h_vpf_ /*------------------------------------------------------------ * types */ /* machine types */ typedef int16_t vpf_short_t; /* 16-bit signed int */ typedef int32_t vpf_long_t; /* 32-bit signed int */ typedef float vpf_float_t; /* 32-bit IEEE */ typedef double vpf_double_t; /* 64-bit IEEE */ typedef char *vpf_string_t; /* ascii string */ /* api types */ typedef struct vpf_date { unsigned short year; /* 0=null date */ unsigned char month, day; /* 0=no info */ double time; /* seconds after 0:00 */ double tz; /* seconds west */ } vpf_date_t; typedef struct vpf_triplet { vpf_long_t id; vpf_long_t tile_id; vpf_long_t ext_id; char valid; #define TRIPLET_ID 0x1 #define TRIPLET_TILE_ID 0x2 #define TRIPLET_EXT_ID 0x4 } vpf_triplet_t; /* opaque object types */ struct vpf; /* libarary context */ struct vpftab; /* table result */ struct vpfsi; /* spatial index */ /* column info for vpftab_info() */ struct vpf_colinfo { char name[20]; char datatype; #define DATATYPE_ISO8859 'L' #define DATATYPE_ASCII 'T' #define DATATYPE_ISO6937 'N' #define DATATYPE_ISO10646 'M' #define DATATYPE_FLOAT 'F' #define DATATYPE_DOUBLE 'R' #define DATATYPE_SHORT 'S' #define DATATYPE_LONG 'I' #define DATATYPE_FLOAT_PAIRS 'C' #define DATATYPE_DOUBLE_PAIRS 'B' #define DATATYPE_FLOAT_TRIPLES 'Z' #define DATATYPE_DOUBLE_TRIPLES 'Y' #define DATATYPE_DATE 'D' #define DATATYPE_NULL 'X' #define DATATYPE_TRIPLET 'K' #define KEYTYPE_PRIMARY 'P' #define KEYTYPE_UNIQUE 'U' #define KEYTYPE_NONUNIQUE 'N' char keytype; int number; const char *desc; const char *vdt; const char *ti; const char *narrative; }; /* column info for vpf_table_info() */ struct vpf_tabinfo { const char *name; const char *narrative; const char *desc; const char *idxname; }; /* spatial index info */ struct vpf_siinfo { vpf_float_t x1, y1, x2, y2; int nprim, nnode; }; /*------------------------------------------------------------ * macros */ /* 'null' testing */ #define NULL_SHORT ((vpf_short_t)0x8000) #define NULL_LONG ((vpf_long_t)0x80000000L) #define NULL_FLOAT ((vpf_float_t)(0.0/0.0)) /* NaN */ #define NULL_DOUBLE ((vpf_double_t)(0.0/0.0)) /* NaN */ #define DOUBLE_IS_NULL(d) (isnan(d)) #define FLOAT_IS_NULL(f) (isnanf(f)) /* XXX means -lm */ #define DATE_IS_NULL(d) ((d).year == 0) #define TRIPLET_IS_NULL(t) ((t).valid == 0) #define STRING_IS_NULL(s) ((s)[0] == '\0') /*------------------------------------------------------------ * prototypes */ /* VPF directory/error context */ struct vpf * vpf_new(const char *dirpath); struct vpf * vpf_new_subdir(struct vpf *, const char *dir); void vpf_free(struct vpf *); const char * vpf_error(struct vpf *); /* Returns err str or NULL */ /* get info about a physical table */ int vpf_table_info(struct vpf *, const char *name, struct vpf_tabinfo *); /* table queries */ struct vpftab * vpf_table(struct vpf *, const char *name); struct vpftab * vpf_select(struct vpftab *t, int (*fn)(struct vpftab *, void *), void *); struct vpftab * vpf_join(struct vpftab *t1, const char *col1, struct vpftab *t2, const char *col2); void vpftab_rewind(struct vpftab *); void vpftab_free(struct vpftab *); void vpftab_seek(struct vpftab *, int); /* table access */ int vpftab_bind(struct vpftab *, const char *fmt, ...); void vpftab_unbind(struct vpftab *); int vpftab_fetch(struct vpftab *); int vpftab_value(struct vpftab *, const char *fmt, ...); /* table information */ int vpftab_colindex(struct vpftab *, const char *); int vpftab_cols(struct vpftab *); void vpftab_info(struct vpftab *, int colindex, struct vpf_colinfo *); /* Spatial index searching */ struct vpfsi * vpf_si(struct vpf *v, const char *name); struct vpftab * vpf_si_search_at(struct vpfsi *, /* contains/near x,y */ const char *colname, vpf_float_t x, vpf_float_t y); struct vpftab * vpf_si_search_in(struct vpfsi *, /* intersect/near x,y */ const char *colname, vpf_float_t minx, vpf_float_t miny, vpf_float_t maxx, vpf_float_t maxy); void vpf_si_info(struct vpfsi *, struct vpf_siinfo *); struct vpftab * vpf_theme(struct vpftab *t, const char *colname, ...); #endif /* _h_vpf_ */ --- NEW FILE: vpf_join.c --- /* $Id: vpf_join.c,v 1.1 2002/09/14 14:43:55 leonard Exp $ */ /* David Leonard, 2002. Public domain */ /* Vector Product Format MIL-STD-2407 database access */ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/param.h> #include "vpf.h" #include "vpfint.h" struct vpftab_join { struct vpftab t; struct vpftab *t1, *t2; struct cell *cell1, *cell2; int started; int datasize; int cell2off; }; static int join_findcol(struct vpftab *, const char *); static int join_fetch(struct vpftab *); static void join_rewind(struct vpftab *); static void join_free(struct vpftab *); static void join_info(struct vpftab *, int, struct vpf_colinfo *); static int join_findcol(t, name) struct vpftab *t; const char *name; { int cell1, cell2; struct vpftab_join *jt = (struct vpftab_join *)t; /* Allow explicit prefix form 1.colname, etc */ if (name[0] == '1' && name[1] == '.') return FINDCOL(jt->t1, name + 2); if (name[0] == '2' && name[1] == '.') { cell2 = FINDCOL(jt->t2, name + 2); if (cell2 < 0) return -1; else return cell2 + jt->cell2off; } /* Check both sub-tables for the name */ cell1 = FINDCOL(jt->t1, name); cell2 = FINDCOL(jt->t2, name); if (cell1 >= 0 && cell2 >= 0) { vpf_seterror(t->v, "findcol: ambiguous join column: %s", name); return -1; } if (cell1 >= 0) return cell1; if (cell2 >= 0) return cell2 + jt->cell2off; return -1; } static int join_fetch(t) struct vpftab *t; { struct vpftab_join *jt = (struct vpftab_join *)t; int size; for (;;) { if (!jt->started) { if (!(*jt->t1->meth->fetch)(jt->t1)) return 0; (*jt->t2->meth->rewind)(jt->t2); jt->started = 1; } if (!(*jt->t2->meth->fetch)(jt->t2)) { jt->started = 0; continue; } if (jt->cell1->count != jt->cell2->count) continue; if (jt->datasize == -1) size = TRIPLETSIZE(*jt->cell1->data) + 1; else size = jt->cell1->count * jt->datasize; if (memcmp(jt->cell1->data, jt->cell2->data, size) == 0) return 1; } } static void join_rewind(t) struct vpftab *t; { struct vpftab_join *jt = (struct vpftab_join *)t; (*jt->t1->meth->rewind)(jt->t1); (*jt->t2->meth->rewind)(jt->t2); jt->started = 0; } static void join_free(t) struct vpftab *t; { struct vpftab_join *jt = (struct vpftab_join *)t; free(jt->t.cells); free(jt); } static void join_info(t, index, ci) struct vpftab *t; int index; struct vpf_colinfo *ci; { struct vpftab_join *jt = (struct vpftab_join *)t; int ambiguous = 0; if (index < jt->cell2off) { (*jt->t1->meth->info)(jt->t1, index, ci); if (FINDCOL(jt->t2, ci->name) >= 0) ambiguous = 1; } else { (*jt->t2->meth->info)(jt->t2, index - jt->cell2off, ci); if (FINDCOL(jt->t1, ci->name) >= 0) ambiguous = 2; } if (ambiguous) { char nname[20]; snprintf(nname, sizeof nname, "%d.%s", ambiguous, ci->name); strcpy(ci->name, nname); } } static struct vpftab_methods join_methods = { join_findcol, join_fetch, join_rewind, join_free, join_info, NULL }; /* Create a virtual table context that joins two tables at the given cols */ struct vpftab * vpf_join(t1, name1, t2, name2) struct vpftab *t1, *t2; const char *name1, *name2; { struct vpftab_join *jt; int cell1, cell2, cell2off; struct col *col1, *col2; int i; cell1 = FINDCOL(t1, name1); if (cell1 < 0) { vpf_seterror(t1->v, "join: unknown column %s", name1); return NULL; } cell2 = FINDCOL(t2, name2); if (cell2 < 0) { vpf_seterror(t2->v, "join: unknown column %s", name2); return NULL; } col1 = t1->cells[cell1]->col; col2 = t2->cells[cell2]->col; /* must be identical types to join on */ if (col1->count != col2->count || col1->datatype != col2->datatype) { vpf_seterror(t1->v, "join: incompatible columns " "%d%c:%s - %d%c:%s", col1->count, col1->datatype, name1, col2->count, col2->datatype, name2); return NULL; } /* must have same endianess */ if (col1->t->endian != col2->t->endian) { vpf_seterror(t1->v, "join: incompatible table endianess"); return NULL; } jt = NEW(struct vpftab_join); if (!jt) { vpf_seterror(t1->v, "malloc"); return NULL; } TABINIT(t1->v, &jt->t, &join_methods); /* Combine the cell lists from the two sub tables */ jt->t.ncells = t1->ncells + t2->ncells; jt->t.cells = (struct cell **)malloc( jt->t.ncells * sizeof (struct cell *)); cell2off = t1->ncells; for (i = 0; i < t1->ncells; i++) jt->t.cells[i] = t1->cells[i]; for (i = 0; i < t2->ncells; i++) jt->t.cells[cell2off+i] = t2->cells[i]; jt->t1 = t1; jt->t2 = t2; jt->cell1 = t1->cells[cell1]; jt->cell2 = t2->cells[cell2]; jt->started = 0; jt->datasize = DATASIZE(col1->datatype); jt->cell2off = cell2off; return (struct vpftab *)jt; } --- NEW FILE: vpf_select.c --- /* $Id: vpf_select.c,v 1.1 2002/09/14 14:43:55 leonard Exp $ */ /* David Leonard, 2002. Public domain */ /* Vector Product Format MIL-STD-2407 database access */ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/param.h> #include "vpf.h" #include "vpfint.h" struct vpftab_select { struct vpftab t; struct vpftab *under; int (*fn)(struct vpftab *, void *); void *closure; }; static int sel_findcol(struct vpftab *, const char *); static int sel_fetch(struct vpftab *); static void sel_rewind(struct vpftab *); static void sel_free(struct vpftab *); static void sel_info(struct vpftab *, int, struct vpf_colinfo *); static int sel_findcol(t, name) struct vpftab *t; const char *name; { struct vpftab_select *st = (struct vpftab_select *)t; return FINDCOL(st->under, name); } static int sel_fetch(t) struct vpftab *t; { struct vpftab_select *st = (struct vpftab_select *)t; while (vpftab_fetch(st->under)) /* NB binds */ if ((*st->fn)(st->under, st->closure)) return 1; return 0; } static void sel_rewind(t) struct vpftab *t; { struct vpftab_select *st = (struct vpftab_select *)t; (*st->under->meth->rewind)(st->under); } static void sel_free(t) struct vpftab *t; { struct vpftab_select *st = (struct vpftab_select *)t; /* (*st->under->meth->free)(st->under); */ free(st); } static void sel_info(t, index, ci) struct vpftab *t; int index; struct vpf_colinfo *ci; { struct vpftab_select *st = (struct vpftab_select *)t; (*st->under->meth->info)(st->under, index, ci); } static struct vpftab_methods sel_methods = { sel_findcol, sel_fetch, sel_rewind, sel_free, sel_info, NULL }; struct vpftab * vpf_select(t, fn, closure) struct vpftab *t; int (*fn)(struct vpftab *, void *); void *closure; { struct vpftab_select *st; st = NEW(struct vpftab_select); if (st == NULL) { vpf_seterror(t->v, "malloc"); return NULL; } TABINIT(t->v, &st->t, &sel_methods); st->t.ncells = t->ncells; st->t.cells = t->cells; st->under = t; st->fn = fn; st->closure = closure; return (struct vpftab *)st; } --- NEW FILE: vpf_si.c --- /* $Id: vpf_si.c,v 1.1 2002/09/14 14:43:55 leonard Exp $ */ /* David Leonard, 2002. Public domain */ /* Vector Product Format MIL-STD-2407 database access */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <sys/types.h> #include <sys/param.h> #include <sys/stat.h> #include <sys/mman.h> #include "vpf.h" #include "vpfint.h" #include "vpf_si.h" #undef DEBUG #ifdef DEBUG #undef dprintf #define dprintf(fmt, arg...) fprintf(stderr, fmt , ## arg) #endif static struct vpftab *vpftab_si_new(struct vpfsi *, const char *, int, vpf_float_t, vpf_float_t, vpf_float_t, vpf_float_t); /* Find a cached spatial index file, or open one */ struct vpfsi * vpf_si(v, name) struct vpf *v; const char *name; { struct vpfsi *si; struct spatialhdr *h; for (si = v->si_head; si; si = si->next) if (strcmp(si->name, name) == 0) return si; si = NEW(struct vpfsi); if (!si) { vpf_seterror(v, "malloc"); return NULL; } if (!vpf_mapfile(v, name, (void **)&si->base, &si->baselen)) { free(si); return NULL; } strcpy(si->name, name); si->endian = v->last_endian; h = (struct spatialhdr *)si->base; if (si->endian == ENDIAN_LSB) { si->nnode = letoh32(h->nnode); si->numprim = letoh32(h->numprim); si->xmin = letoh32f(h->xmin); si->xmax = letoh32f(h->xmax); si->ymin = letoh32f(h->ymin); si->ymax = letoh32f(h->ymax); } else { si->nnode = betoh32(h->nnode); si->numprim = betoh32(h->numprim); si->xmin = betoh32f(h->xmin); si->xmax = betoh32f(h->xmax); si->ymin = betoh32f(h->ymin); si->ymax = betoh32f(h->ymax); } si->cell = (struct spatial *)(h + 1) - 1; si->bin = (char *)(si->cell + si->nnode + 1); si->v = v; si->next = v->si_head; if (si->next) si->next->prevp = &si->next; si->prevp = &v->si_head; v->si_head = si; return si; } /* Create a table of ids that 'contain' (x,y) */ struct vpftab * vpf_si_search_at(si, name, x, y) struct vpfsi *si; const char *name; vpf_float_t x, y; { return vpftab_si_new(si, name, 1, x, y, 0, 0); } /* Create a table of ids that 'intersect' (minx,miny,maxx,maxy) */ struct vpftab * vpf_si_search_in(si, name, minx, miny, maxx, maxy) struct vpfsi *si; const char *name; vpf_float_t minx, miny, maxx, maxy; { return vpftab_si_new(si, name, 0, minx, miny, maxx, maxy); } /* Add a node to the list of nodes to be searched */ static void search_add(st, n, vert, bx1,by1,bx2,by2) struct vpftab_si *st; int n, vert; unsigned char bx1,by1,bx2,by2; { int offset, count; struct srch *srch; struct vpfsi *si = st->si; /* ignore trying to add non-existent nodes */ if (n > si->nnode) return; if (si->endian == ENDIAN_LSB) { offset = letoh32(si->cell[n].offset); count = letoh32(si->cell[n].count); } else { offset = betoh32(si->cell[n].offset); count = betoh32(si->cell[n].count); } srch = NEW(struct srch); srch->node = n; srch->bx1 = bx1; srch->by1 = by1; srch->bx2 = bx2; srch->by2 = by2; srch->vert = vert; srch->prim = (struct prim *)(si->bin + offset); srch->count = count; dprintf("si: push node %d, len %d %c (%u,%u),(%u,%u)\n", srch->node, srch->count, srch->vert ? 'V':'H', srch->bx1,srch->by1,srch->bx2,srch->by2); /* Link into table */ srch->next = st->srch; st->srch = srch; } /* Pop off a node from the list of nodes to search */ static struct srch * search_pop(st) struct vpftab_si *st; { struct srch *s; s = st->srch; if (s) st->srch = s->next; if (s) dprintf("si: pop node %d\n", s->node); return s; } /* Get bounds information about a spatial index */ void vpf_si_info(si, i) struct vpfsi *si; struct vpf_siinfo *i; { i->x1 = si->xmin; i->y1 = si->ymin; i->x2 = si->xmax; i->y2 = si->ymax; i->nnode = si->nnode; i->nprim = si->numprim; } /* Free a spatial index (called by vpf_free) */ void vpfsi_free(si) struct vpfsi *si; { /* disconnect */ if (si->next) si->next->prevp = si->prevp; *si->prevp = si->next; /* deallocate */ munmap(si->base, si->baselen); free(si); } /*------------------------------------------------------------ * si table methods */ static int si_findcol(t, name) struct vpftab *t; const char *name; { struct vpftab_si *st = (struct vpftab_si *)t; if (strcmp(name, st->col.name) != 0) return -1; return 0; } static int si_fetch(t) struct vpftab *t; { struct vpftab_si *st = (struct vpftab_si *)t; struct prim *p; int sel; unsigned char mx, my; for (;;) { #ifdef DEBUG { struct srch *s; dprintf("cur is "); if (st->cur) { dprintf("node %d pos %d\n", st->cur->node, st->curpos); } else { dprintf("NULL\n"); } dprintf("stack is ["); for (s = st->srch; s; s = s->next) dprintf(" %d", s->node); dprintf("]\n"); } #endif /* If we have exhausted the current node, add relevant children */ if (st->cur && st->curpos >= st->cur->count) { struct srch *cur = st->cur; int n = cur->node; if (st->at) { /* Check the half-spaces that contain the search cell */ if (cur->vert) { my = (cur->by1 + cur->by2+1)/2; dprintf("si: push? %d\n", n*2); if (st->y1 < my) search_add(st, n*2+1, 0, cur->bx1,cur->by1,cur->bx2,my-1); dprintf("si: push? %d\n", n*2+1); if (st->y1 >= my) search_add(st, n*2, 0, cur->bx1,my,cur->bx2,cur->by2); } else { mx = (cur->bx1 + cur->bx2+1)/2; dprintf("si: push? %d\n", n*2); if (st->x1 < mx) search_add(st, n*2+1, 1, cur->bx1,cur->by1,mx-1,cur->by2); dprintf("si: push? %d\n", n*2+1); if (st->x1 >= mx) search_add(st, n*2, 1, mx,cur->by1,cur->bx2,cur->by2); } } else { /* Check the half-spaces that intersect the search rectangle */ if (cur->vert) { my = (cur->by1+cur->by2+1)/2; dprintf("si: push? %d\n", n*2); if (st->y1 < my) search_add(st, n*2+1, 0, cur->bx1,cur->by1,cur->bx2,my-1); dprintf("si: push? %d\n", n*2+1); if (st->y2 >= my) search_add(st, n*2, 0, cur->bx1,my,cur->bx2,cur->by2); } else { mx = (cur->bx1+cur->bx2+1)/2; dprintf("si: push? %d\n", n*2); if (st->x1 < mx) search_add(st, n*2+1, 1, cur->bx1,cur->by1,mx-1,cur->by2); dprintf("si: push? %d\n", n*2+1); if (st->x2 >= mx) search_add(st, n*2, 1, mx,cur->by1,cur->bx2,cur->by2); } } /* Kill the exhausted node */ free(cur); st->cur = NULL; } /* Fetch a current node if we don't have one already */ if (!st->cur) { st->cur = search_pop(st); if (!st->cur) return 0; /* exhausted */ st->curpos = 0; } /* Move pointer and return matching primitive */ while (st->curpos < st->cur->count) { struct srch *cur = st->cur; p = cur->prim + st->curpos; dprintf("si: primitive at (%u,%u),(%u,%u)\n", p->x1, p->y1, p->x2, p->y2); sel = st->at ? p->x1 <= st->x1 && st->x1 <= p->x2 && p->y1 <= st->y1 && st->y1 <= p->y2 : (p->x1 <= st->x2 || st->x1 <= p->x2) && (p->y1 <= st->y2 || st->y1 <= p->y2); st->curpos++; if (sel) { dprintf("si: primitive MATCH\n"); /* Return the primitive if it matched */ st->cell.data = (char *)&p->id; st->cell.count = 1; return 1; } } } } static void si_rewind(t) struct vpftab *t; { struct vpftab_si *st = (struct vpftab_si *)t; struct srch *s; /* remove existing search nodes */ while ((s = search_pop(st)) != NULL) free(s); if (st->cur) free(st->cur); /* add a root search */ search_add(st, 1, 0, 0,0,255,255); st->cur = NULL; st->curpos = 0; st->row = 0; } static void si_free(t) struct vpftab *t; { struct vpftab_si *st = (struct vpftab_si *)t; struct srch *s; while ((s = search_pop(st)) != NULL) free(s); if (st->cur) free(st->cur); free(st); } static void si_info(t, cellnum, ci) struct vpftab *t; int cellnum; struct vpf_colinfo *ci; { struct vpftab_si *st = (struct vpftab_si *)t; strcpy(ci->name, st->col.name); ci->datatype = st->col.datatype; ci->number = st->col.count; ci->desc = st->col.desc; ci->vdt = st->col.vdt; ci->ti = st->col.ti; ci->narrative = st->col.narrative; ci->keytype = st->col.keytype; } static struct vpftab_methods si_methods = { si_findcol, si_fetch, si_rewind, si_free, si_info, NULL }; /* Clip a floating point number to 0..255 */ static unsigned char clip(v) vpf_float_t v; { if (v < 0) return 0; if (v >= 256) return 255; return rintf(v); } /* Create a virtual table result that we fetch the primitives from */ static struct vpftab * vpftab_si_new(si, name, at, x1, y1, x2, y2) struct vpfsi *si; const char *name; int at; vpf_float_t x1, y1, x2, y2; { struct vpftab_si *st; st = NEW(struct vpftab_si); TABINIT(si->v, &st->t, &si_methods); st->t.cells = &st->cellp; st->t.ncells = 1; st->si = si; st->at = at; st->srch = NULL; st->cur = NULL; st->x1 = clip(255.0 * (x1 - si->xmin) / (si->xmax - si->xmin)); st->y1 = clip(255.0 * (y1 - si->ymin) / (si->ymax - si->ymin)); if (!at) { st->x2 = clip(255.0 * (x2 - si->xmin) / (si->xmax - si->xmin) + 1); st->y2 = clip(255.0 * (y2 - si->ymin) / (si->ymax - si->ymin) + 1); } else { st->x2 = st->y2 = 0; } st->curpos = 0; st->col.t = &st->table; st->col.name = st->name; st->col.datatype = DATATYPE_LONG; st->col.datasize = DATASIZE(DATATYPE_LONG); st->col.count = 1; st->col.keytype = 'N'; /* XXX primary? unique? */ st->col.desc = NULL; st->col.narrative = NULL; st->col.vdt = NULL; st->col.ti = NULL; st->cell.col = &st->col; st->cellp = &st->cell; st->table.v = si->v; strcpy(st->table.name, si->name); st->table.next = NULL; /* not linked */ st->table.base = NULL; st->table.basesize = 0; st->table.endian = si->endian; st->table.ncols = 1; st->table.col = &st->col; st->table.idx = NULL; st->table.row1 = NULL; st->table.rowsize = 0; st->table.nrows = 0; st->table.desc = NULL; st->table.narrative = NULL; st->row = 0; strcpy(st->name, name); dprintf("si target (%u,%u) (%u,%u)\n", st->x1, st->y1, st->x2, st->y2); si_rewind((struct vpftab *)st); return (struct vpftab *)st; } --- NEW FILE: vpf_si.h --- /* $Id: vpf_si.h,v 1.1 2002/09/14 14:43:55 leonard Exp $ */ /* David Leonard, 2002. Public domain. */ /* Spatial index files (5.4.2) */ struct spatialhdr { vpf_long_t numprim; vpf_float_t xmin, ymin, xmax, ymax; vpf_long_t nnode; }; struct spatial { vpf_long_t offset; /* bytes */ vpf_long_t count; /* integer units */ }; struct prim { unsigned char x1, y1, x2, y2; vpf_long_t id; }; /* Handle to an opened spatial index file */ struct vpfsi { struct vpf *v; struct vpfsi *next, **prevp; char name[16]; char *base; int baselen; struct spatial *cell; /* indexed by nodeid */ char *bin; int32_t numprim; float xmin, ymin, xmax, ymax; int32_t nnode; char endian; }; /* A node yet to be searched */ struct srch { struct srch * next; vpf_long_t node; unsigned char bx1, bx2, by1, by2; int vert; struct prim * prim; int count; /* number of primitives */ }; /* A vpftab that maps onto a spatial index */ struct vpftab_si { struct vpftab t; struct vpfsi *si; int at; /* 0=in 1=at */ unsigned char x1, x2, y1, y2; struct srch *srch, *cur; int curpos; /* current position in top node */ struct cell cell, *cellp; /* single cell*/ struct col col; /* single column type */ struct table table; int row; char name[16]; }; --- NEW FILE: vpf_theme.c --- /* $Id: vpf_theme.c,v 1.1 2002/09/14 14:43:55 leonard Exp $ */ /* David Leonard, 2002. Public domain */ /* Vector Product Format MIL-STD-2407 database access */ #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <sys/types.h> #include <sys/param.h> #include "vpf.h" #include "vpfint.h" struct vpftab_theme { struct vpftab t; struct vpftab *under; vpf_short_t datacp; char indextype; /* I or B */ char idtype; /* S or I */ char *entries; int nentries; int curentry; char endian; }; static int theme_findcol(struct vpftab *, const char *); static int theme_fetch(struct vpftab *); static void theme_rewind(struct vpftab *); static void theme_free(struct vpftab *); static void theme_info(struct vpftab *, int, struct vpf_colinfo *); static int theme_findcol(t, name) struct vpftab *t; const char *name; { struct vpftab_theme *th = (struct vpftab_theme *)t; return FINDCOL(th->under, name); } static int theme_fetch(t) struct vpftab *t; { struct vpftab_theme *th = (struct vpftab_theme *)t; int row; if (th->curentry >= th->nentries) return 0; if (th->indextype == 'I') { if (th->idtype == 'S') { vpf_short_t s; memcpy(&s, th->entries + sizeof s * th->curentry, sizeof s); row = H16(th->endian, s); } else { vpf_long_t s; memcpy(&s, th->entries + sizeof s * th->curentry, sizeof s); row = H32(th->endian, s); } } else { /* * XXX - section 5.4.3 of MIL-STD-2407 does not explain * how to access bit arrays!!? */ return 0; } th->curentry++; vpftab_seek(th->under, row); return (*th->under->meth->fetch)(th->under); } static void theme_rewind(t) struct vpftab *t; { struct vpftab_theme *th = (struct vpftab_theme *)t; /* (*jt->t1->meth->rewind)(th->under); */ th->curentry = 0; } static void theme_free(t) struct vpftab *t; { struct vpftab_theme *th = (struct vpftab_theme *)t; free(th); } static void theme_info(t, index, ci) struct vpftab *t; int index; struct vpf_colinfo *ci; { struct vpftab_theme *th = (struct vpftab_theme *)t; return (*th->under->meth->info)(th->under, index, ci); } static struct vpftab_methods theme_methods = { theme_findcol, theme_fetch, theme_rewind, theme_free, theme_info, NULL }; /* Create a virtual table context that joins two tables at the given cols */ struct vpftab * vpf_theme(struct vpftab *t, const char *colname, ...) { struct vpftab_theme *th; struct col *col; int cell; char ctype; const char *s, *name; int count; va_list ap; vpf_float_t v_float = 0; vpf_double_t v_double = 0; vpf_short_t v_short = 0; vpf_long_t v_long = 0; char *v_string = NULL; char *key, *a, *b; int keysz, i; vpf_long_t l; char endian; int ndent; convfn_t convfn; /* Parse the index key type from colname */ s = colname; if (*s >= '0' && *s <= '9') { count = 0; while (*s >= '0' && *s <= '9') count = 10 * count + (*s++ - '0'); } else count = 1; ctype = *s++; if (!ctype || *s != ':') { vpf_seterror(t->v, "vpf_theme: expeceted 'type:name' argument"); return NULL; } /* Find the column & check for sanity */ name = s + 1; cell = FINDCOL(t, name); if (cell < 0) { vpf_seterror(t->v, "unknown column %s", name); return NULL; } col = t->cells[cell]->col; if (!col->ti) { vpf_seterror(t->v, "column %s has no thematic index", name); return NULL; } if (col->datatype != ctype) { vpf_seterror(t->v, "column %s has type %d%c, not %d%c", name, col->count, col->datatype, count, ctype); return NULL; } /* Now, copy out the data */ va_start(ap, colname); switch (ctype) { case 'I': v_long = va_arg(ap, vpf_long_t); break; case 'T': v_string = va_arg(ap, void *); break; case 'S': v_short = va_arg(ap, vpf_short_t); break; case 'F': v_float = va_arg(ap, vpf_float_t); break; case 'R': v_double = va_arg(ap, vpf_double_t); break; default: vpf_seterror(t->v, "unknown type %c", ctype); va_end(ap); return NULL; } va_end(ap); keysz = count * DATASIZE(ctype); endian = col->t->endian; /* Map the thematic index */ if (col->theme_base == NULL) { if (!vpf_mapfile(t->v, col->ti, (void **)&col->theme_base, &col->theme_size)) return NULL; } /* Check that the thematic index's header is what we expect */ memcpy(&l, col->theme_base + 14, sizeof l); if (H32(endian, l) != count || col->theme_base[13] != ctype) { vpf_seterror(t->v, "TI keytype is %d%c, not %d%c !?!\n", H32(endian, l), col->theme_base[13], count, ctype); return NULL; } /* Allocate space for key coping */ if ((key = alloca(keysz)) == NULL) { vpf_seterror(t->v, "alloca"); return NULL; } /* Allocate a new table structure */ th = NEW(struct vpftab_theme); if (!th) { vpf_seterror(t->v, "malloc"); return NULL; } TABINIT(t->v, &th->t, &theme_methods); th->t.ncells = t->ncells; th->t.cells = t->cells; th->under = t; th->indextype = col->theme_base[12]; /* I or B */ th->idtype = col->theme_base[18]; /* S or I */ th->curentry = 0; th->endian = endian; ndent = H32(endian, *(vpf_long_t *)(col->theme_base + 4)); convfn = vpf_find_convfn(ctype, ctype, col->t->endian); /* XXX if (sorted) bsearch(); */ /* sorted = (col->theme_base[56] == 'S'); */ /* Linear search */ for (i = 0; i < ndent; i++) { int match, j; b = col->theme_base + 60 + i * (keysz + 8); for (j = 0, a = key; j < count; j++) (*convfn)(&a, &b); switch (ctype) { case 'I': match = (*(vpf_long_t *)key == v_long); break; case 'T': match = (memcmp(key, v_string, keysz) == 0); break; case 'S': match = (*(vpf_short_t *)key == v_short); break; case 'F': match = (*(vpf_float_t *)key == v_float); break; case 'R': match = (*(vpf_double_t *)key == v_double); break; default: match = 0; } if (match) break; } if (i < ndent) { memcpy(&l, col->theme_base + 60 + i * (keysz + 8) + keysz, sizeof l); th->entries = col->theme_base + H32(endian, l); memcpy(&l, col->theme_base + 60 + i * (keysz + 8) + keysz + 4, sizeof l); th->nentries = H32(endian, l); if (th->nentries == 0) { th->entries = col->theme_base + 60 + i * (keysz + 8) + keysz; if (th->idtype == 'S') { memcpy(&th->datacp, th->entries, sizeof th->datacp); th->entries = (char *)&th->datacp; } th->nentries = 1; } } else { th->entries = NULL; th->nentries = 0; } return (struct vpftab *)th; } --- NEW FILE: vpfint.h --- /* $Id: vpfint.h,v 1.1 2002/09/14 14:43:55 leonard Exp $ */ /* David Leonard, 2002. Public domain. */ /* integer endian conversion macros */ #define H(e,lsb,msb,i) ((e) == ENDIAN_MSB ? msb(i) : lsb(i)) #define H32(e,i) H(e, letoh32, betoh32, i) #define H16(e,i) H(e, letoh16, betoh16, i) /* Variable index file (5.4.1.3) */ struct varidx { int32_t nentries; int32_t vpfhdrlen; /* in bytes */ struct { int32_t offset; /* in bytes */ int32_t size; /* in bytes */ } loc[1]; }; /* Thematic index header (5.4.3) */ struct tihdr { int32_t hdrlen; /* bytes in hdr + directory */ int32_t ndirents; int32_t srcrows; char titype; #define TITYPE_INVERTED 'I' #define TITYPE_BITARRAY 'B' char idxdatatype; /* see DATATYPE_* (only [ITSFR]) */ char dentsz[2]; /* XXX unaligned! */ char datatype; /* I or S */ char srctab[12]; /* source table */ char srccol[25]; /* source table */ char sorted; /* 'S' if sorted ascending */ char reserved[3]; }; /* A column - name and type */ struct col { struct table *t; /* containing table */ char *name; /* name */ char datatype; /* data type */ int datasize; /* size of one data unit */ int count; /* -1 means variable (32bit int preceeds) */ int keytype; /* P, U or N */ char *desc; /* descriptive string */ char *narrative; /* name of narrative table name */ char *vdt; /* value description table name */ char *ti; /* thematic index table name */ char *theme_base; /* thematic index map */ size_t theme_size; }; /* Header (5.4.1.1) */ struct table { struct vpf *v; /* vpf context */ char name[16]; /* table name */ struct table *next; /* linked list */ char *base; /* mmapped file */ size_t basesize; /* extent of mmap */ char endian; #define ENDIAN_LSB 'L' #define ENDIAN_MSB 'M' int ncols; struct col *col; char idxname[13]; struct varidx *idx; /* variable index file - mapped */ size_t idxsize; /* extent of variable index mmap */ char *row1; int rowsize; /* len of each row */ int nrows; char *private; /* writable copy of header with nuls */ char *desc; char *narrative; /* name of narrative table */ }; /* A column cell in a vpftab */ struct cell { struct col *col; char *data; /* set when a row is fetched */ int count; /* set when a row is fetched */ }; /* A function type that performs data copying/conversion */ typedef void (*convfn_t)(char **, char **); /* Binding between memory locations and a to-be-fetched table cell */ struct binding { int cellnum; int dim; /* multiplier for copying */ int maxcount; int *countret; convfn_t fn; char *target; }; /* Method table for vpftab objects */ struct vpftab_methods { int (*findcol)(struct vpftab *, const char *); int (*fetch)(struct vpftab *); void (*rewind)(struct vpftab *); void (*free)(struct vpftab *); void (*info)(struct vpftab *, int, struct vpf_colinfo *); void (*seek)(struct vpftab *, int); }; /* An abstract table context */ struct vpftab { struct vpf *v; /* Bindings set up by vpf_bind() */ int nbindings; struct binding *bindings; /* Cells allocated at creation, contents updated on fetch */ int ncells; struct cell **cells; struct vpftab_methods *meth; }; #define dprintf(fmt, args...) /* nothing */ #define DATASIZE(c) \ (((c) == DATATYPE_ISO8859 || \ (c) == DATATYPE_ASCII || \ (c) == DATATYPE_ISO6937 || \ (c) == DATATYPE_ISO10646) ? 1 \ :(c) == DATATYPE_FLOAT ? 4 \ :(c) == DATATYPE_DOUBLE ? 8 \ :(c) == DATATYPE_SHORT ? 2 \ :(c) == DATATYPE_LONG ? 4 \ :(c) == DATATYPE_FLOAT_PAIRS ? 2*4 \ :(c) == DATATYPE_DOUBLE_PAIRS ? 2*8 \ :(c) == DATATYPE_FLOAT_TRIPLES ? 3*4 \ :(c) == DATATYPE_DOUBLE_TRIPLES ? 3*8 \ :(c) == DATATYPE_DATE ? 20 \ :(c) == DATATYPE_NULL ? 0 \ :(c) == DATATYPE_TRIPLET ? -1 \ :-2) /* Common VPF context structure */ struct vpf { struct table *table_head; /* linked list of cached tables */ struct vpfsi *si_head; /* spatial index tables */ char errbuf[1024]; char dirpath[MAXPATHLEN]; char last_endian; }; /* Triplet operations */ extern int vpf_triplet_sizetab[4]; #define TRIPLETSIZE(h) \ (vpf_triplet_sizetab[((h)>>6)&3] + \ vpf_triplet_sizetab[((h)>>4)&3] + \ vpf_triplet_sizetab[((h)>>2)&3]) /* Endian macros for floating point and double types */ #define convf(ft,it,x,fn) ({ \ union { it i; ft f; } _u; \ _u.f = (x); _u.i = fn(_u.i); \ _u.f; \ }) #define letoh32f(x) convf(vpf_float_t, u_int32_t, x, letoh32) #define letoh64f(x) convf(vpf_double_t, u_int64_t, x, letoh64) #define betoh32f(x) convf(vpf_float_t, u_int32_t, x, betoh32) #define betoh64f(x) convf(vpf_double_t, u_int64_t, x, betoh64) #define NEW(t) (t *)malloc(sizeof (t)) #define FINDCOL(t, n) (*(t)->meth->findcol)(t, n) #define TABINIT(vv, t, m) do { \ (t)->v = (vv); \ (t)->nbindings = 0; \ (t)->bindings = NULL; \ (t)->cells = NULL; \ (t)->ncells = 0; \ (t)->meth = (m); \ } while (0) void vpf_seterror(struct vpf *, const char *, ...); int vpf_mapfile(struct vpf *, const char *, void **, size_t *); void vpfsi_free(struct vpfsi* si); convfn_t vpf_find_convfn(char, char, char); --- NEW FILE: vpfpath.h --- /* $Id: vpfpath.h,v 1.1 2002/09/14 14:43:55 leonard Exp $ */ /* David Leonard, 2002. Public domain. */ /* Reserved filenames (5.3.1.2) */ #define FILE_CAT "cat" /* Coverage attribute table */ #define FILE_CND "cnd" /* Connected Node Primitive */ #define FILE_CSI "csi" /* Connected Node Spatial Index */ #define FILE_DHT "dht" /* Database Header Table */ #define FILE_DQT "dqt" /* Data Quality Table */ #define FILE_EBR "ebr" /* Edge Bounding Rectangle */ #define FILE_EDG "edg" /* Edge Primitive */ #define FILE_END "end" /* Entity Node Primitive */ #define FILE_ESI "esi" /* Edge Spatial Index */ #define FILE_FAC "fac" /* Face Primitive */ #define FILE_FBR "fbr" /* Face Bounding Rectangle */ #define FILE_FCA "fca" /* Face Primitive */ #define FILE_FBR "fbr" /* Face Bounding Rectangle */ #define FILE_FCA "fca" /* Feature Class Attribute Table */ #define FILE_FCS "fcs" /* Feature Class Scehema Table */ #define FILE_FSI "fsi" /* Face Spatial Index */ #define FILE_GRT "grt" /* Geographic Reference Table */ #define FILE_LAT "lat" /* Library Attribute Table */ #define FILE_LHT "lht" /* Library Header Table */ #define FILE_NSI "nsi" /* Entity Node Spatial Index */ #define FILE_RNG "rng" /* Ring Table */ #define FILE_TXT "txt" /* Text Primitive */ #define FILE_TSI "tsi" /* Text Spatial Index */ #define FILE_CHARVDT "char.vdt" /* Character Value Description Table */ #define FILE_INTVDT "int.vdt" /* Integer Value Description Table */ /* Reserved directory names */ #define DIR_LIBREF "libref" /* Library reference coverage */ #define DIR_DQ "dq" /* Data quality coverage */ #define DIR_TILEREF "tileref" /* Tile reference coverage */ #define DIR_GAZETTE "gazette" /* Names reference coverage */ /* Reserved table name extensions */ #define EXT_ABR ".abr" /* Area Bounding Rectangle Table */ #define EXT_AFT ".aft" /* Area Feature Table */ #define EXT_AJT ".ajt" /* Area Join Table */ #define EXT_ATI ".ati" /* Area Thematic Index */ #define EXT_CBR ".cbr" /* Complex Bounding Rectangle Table */ #define EXT_CFT ".cft" /* Complex Feature Table */ #define EXT_CJT ".cjt" /* Complex Join Table */ #define EXT_CTI ".cti" /* Complex Thematic Index */ #define EXT_DOC ".doc" /* Narrative Table */ #define EXT_DPT ".dpt" /* Diagnostic Point Table */ #define EXT_FIT ".fit" /* Feature Index Table */ #define EXT_FTI ".fti" /* Feature Index Table Thematic Index */ #define EXT_JTI ".jti" /* Join Thematic Index */ #define EXT_LBR ".lbr" /* Line Bounding Rectangle Table */ #define EXT_LFT ".lft" /* Line Feature Table */ #define EXT_LJT ".ljt" /* Line Join Table */ #define EXT_LTI ".lti" /* Line Thematic Index */ #define EXT_PBR ".pbr" /* Point Bounding Rectangle Table */ #define EXT_PFT ".pft" /* Point Feature Table */ #define EXT_PJT ".pjt" /* Point Join Table */ #define EXT_PTI ".pti" /* Point Thematic Index */ #define EXT_RAT ".rat" /* Related Attribute Table */ #define EXT_RPT ".rpt" /* Registration Point Table */ #define EXT_TFT ".tft" /* Text Feature Table */ #define EXT_TTI ".tti" /* Text Thematic Index */ |
From: <le...@us...> - 2002-09-14 14:43:58
|
Update of /cvsroot/meshdb/src/vpf/psplot In directory usw-pr-cvs1:/tmp/cvs-serv13680/psplot Added Files: Makefile psplot.c Log Message: got VPF stuff working on OpenBSD/sparc using www.iscgm.org data --- NEW FILE: Makefile --- # $Id: Makefile,v 1.1 2002/09/14 14:43:55 leonard Exp $ PROG= psplot LDADD= -lvpf -lm DPADD= ${LIBVPF} NOMAN= .include <bsd.prog.mk> --- NEW FILE: psplot.c --- /* $Id: psplot.c,v 1.1 2002/09/14 14:43:55 leonard Exp $ */ /* David Leonard, 2002. Public domain. */ #include <stdio.h> #include <math.h> #include <ctype.h> #include <unistd.h> #include <string.h> #include <stdlib.h> #include <stdarg.h> #include "vpf.h" int verbose = 0; struct vpf *vdb = NULL; struct vpf *vlib = NULL; struct vpf *vcov = NULL; /* tiles in our area of interest */ char **tilename; int *tiles; int ntiles; int ifon = 1; int ifoff = 0; int lineno = 0; #define RELNE '!' #define RELGE '+' #define RELLE '-' char ftype; char fname[9]; double ux1, uy1, ux2, uy2; double pwidth = 500, pheight = 500; /* parameters */ double p_scale; /* number of postscript points per degree of latitude */ #define PTDEG 3149603.1496062996 #define VFREE(v) do { \ if (v) vpf_free(v); \ v = NULL; \ } while (0) #define TFREE(t) do { \ if (t) vpfref_free(t); \ t = NULL; \ } while (0) static void die(const char *fmt, ...); static void strip(char *, int); static void strip(buf, buflen) char *buf; int buflen; { int i; buf[buflen - 1] = '\0'; for (i = 0; buf[i]; i++) ; while (i > 0 && buf[i-1] == ' ') i--; buf[i] = '\0'; } static void die(const char *fmt, ...) { va_list ap; va_start(ap, fmt); fprintf(stderr, "line %d: error: ", lineno); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); va_end(ap); exit(1); } void closefeature() { fname[0] = '\0'; ftype = '\0'; } void closecov() { closefeature(); VFREE(vcov); } void closelib() { int i; closecov(); if (tiles) { for (i = 0; i < ntiles; i++) free(tilename[i]); free(tilename); free(tiles); ntiles = 0; } VFREE(vlib); } void database(arg) char *arg; { closelib(); VFREE(vdb); vdb = vpf_new(arg); if (!vdb) die("DATABASE: %s", arg); } void printcoord(x, y) double x, y; { printf("%.9g %.9g ", (x - ux1) * pwidth / (ux2 - ux1), (y - uy1) * pheight / (uy2 - uy1)); } /* Plot a path enclosing the screen. (user to fill/stroke/clip) */ void wholepath() { printcoord(ux1, uy1); printf("moveto\n"); printcoord(ux1, uy2); printf("lineto\n"); printcoord(ux2, uy2); printf("lineto\n"); printcoord(ux2, uy1); printf("lineto\n"); printf("closepath\n"); } /* Scan the 'tileref' coverage and store tile IDs and subdir names */ void tile_init() { struct vpf *vtile; struct vpfsi *si; struct vpftab *fsi, *tileref, *t; int i; vpf_long_t id = 0; char buf[10], *p; vtile = vpf_new_subdir(vlib, "tileref"); if (!vtile) die("tile_init"); tileref = vpf_table(vtile, "tileref.aft"); if (!tileref) die("tileref/tileref.aft"); si = vpf_si(vtile, "fsi"); if (!si) die("problem opening tileref/fsi"); if (verbose) printf("%% tiles intersecting (%g,%g) (%g,%g)\n", ux1, uy1, ux2, uy2); fsi = vpf_si_search_in(si, "id", ux1, uy1, ux2, uy2); /* count the number of tiles */ ntiles = 0; while (vpftab_fetch(fsi)) ntiles++; vpftab_rewind(fsi); /* join fsi with tileref.aft */ t = vpf_join(fsi, "id", tileref, "fac_id"); /* pull out the face numbers */ if (!vpftab_bind(t, "I:2.id,9T:2.tile_name", &id, buf)) die("bind: %s", vpf_error(vtile)); tiles = (int *)malloc((1+ntiles) * sizeof (int)); tilename = (char **)malloc((1+ntiles) * sizeof (char *)); for (i = 0; i < ntiles; i++) { vpftab_fetch(t); strip(buf, sizeof buf); for (p = buf; *p; p++) if (*p == '\\') *p = '/'; else *p = tolower(*p); tiles[i] = id; tilename[i] = strdup(buf); if (verbose) printf("%% tile %d = %s\n", tiles[i], tilename[i]); } vpftab_free(t); vpftab_free(fsi); vpftab_free(tileref); vpf_free(vtile); /* implicitly frees si */ } /* Set current library */ void library(arg) char *arg; { struct vpftab *t; char name[9]; if (!vdb) die("no DATABASE"); closelib(); vlib = vpf_new_subdir(vdb, arg); if (!vlib) die("LIBRARY: %s", arg); /* Look for a tileref coverage */ t = vpf_table(vlib, "cat"); if (!t) die("cat: %s", vpf_error(vlib)); vpftab_bind(t, "8T:coverage_name", name); while (vpftab_fetch(t)) { strip(name, sizeof name); if (verbose) printf("%% coverage: '%s'\n", name); if (strcmp(name, "tileref") == 0) { tile_init(); break; } } vpftab_free(t); } /* Set current coverage */ void coverage(arg) const char *arg; { closecov(); vcov = vpf_new_subdir(vlib, arg); } /* Set the current feature */ void feature(arg) const char *arg; { struct vpftab *fca; /* Figure out what kind of coverage it is */ if (!vcov) die("feature: no COVERAGE"); closefeature(); fca = vpf_table(vcov, "fca"); if (!fca) die("fca: %s", vpf_error(vcov)); vpftab_bind(fca, "8T:fclass,1T:type", fname, &ftype); while (vpftab_fetch(fca)) { strip(fname, sizeof fname); if (strcmp(fname, arg) == 0) { if (verbose) printf("%% found feature %s, type %c)\n", arg, ftype); vpftab_free(fca); return; } } die("%s: unknown feature", arg); } /* * fetch an edge and plot it with moveto/lineto. * If the edge is totally invisible, ignore it, * unless lineto is specifified, and then we simply * approximate the edge! */ void plotedge(id, edg, ebr, zlen, zarray, bound, rfp, rface, lineto, mandatory) int id; struct vpftab *edg, *ebr; int *zlen; vpf_float_t (*zarray)[3]; vpf_float_t *bound; vpf_triplet_t *rfp; int rface; int lineto, mandatory; { int i, invisible, len, fwd; vpftab_seek(ebr, id); if (vpftab_fetch(ebr)) invisible = (ux2 < bound[0] || bound[2] < ux1 || uy2 < bound[1] || bound[3] < uy1); else invisible = 0; vpftab_seek(edg, id); vpftab_fetch(edg); if (rfp) fwd = (rfp->id == rface); else fwd = 1; len = *zlen; if (invisible) { if (!mandatory) return; if (!lineto) { if (fwd) printcoord(zarray[0][0], zarray[0][1]); else printcoord(zarray[len-1][0], zarray[len-1][1]); printf("moveto\n"); } if (fwd) printcoord(zarray[len-1][0], zarray[len-1][1]); else printcoord(zarray[0][0], zarray[0][1]); printf("lineto\n"); return; } if (fwd) for (i = 0; i < len; i++) { printcoord(zarray[i][0], zarray[i][1]); if (i || lineto) printf("lineto\n"); else printf("moveto\n"); } else for (i = len - 1; i >= 0; i--) { printcoord(zarray[i][0], zarray[i][1]); if (i < len-1 || lineto) printf("lineto\n"); else printf("moveto\n"); } } void plot(arg) char *arg; { int ti; vpf_long_t tile; vpf_long_t primid; struct vpf *v; struct vpfsi *si = NULL; char ftable[20]; char ftableidtype[23]; struct vpftab *tt, *ft; struct vpftab *edg = NULL; struct vpftab *ebr = NULL; struct vpftab *fac = NULL; struct vpftab *fbr = NULL; struct vpftab *end = NULL; struct vpftab *rng = NULL; vpf_float_t zarray[1024][3]; int zlen, i; int ring_ptr, cur; int start_edge, ringface; vpf_triplet_t lf, rf, le, re; vpf_float_t bound[4]; vpf_long_t ftableid; /* Match params */ char *s, *t, *cn, ch, rel=0; vpf_long_t mint[10], aint[10]; char mintrel[10]; int nmint = 0; vpf_double_t mreal[10], areal[10]; char mrealrel[10]; int nmreal = 0; char * mstr[10], astr[10][100]; int astrlen[10]; char mstrrel[10]; int nmstr = 0; int colidx; int matches; struct vpf_colinfo ci; if (!ftype) die("plot: no FEATURE"); /* Figure out some table and column names */ snprintf(ftable, sizeof ftable, "%s.%cft", fname, tolower(ftype)); snprintf(ftableidtype, sizeof ftableidtype, "I:%s_id", ftable); /* Open the feature table */ ft = vpf_table(vcov, ftable); if (!ft) die("%s: %s", ftable, vpf_error(vcov)); /* Parse and bind the search terms! */ for (s = arg; *s;) { char bbuf[30]; /* skip white */ while (*s == ' ') s++; if (!*s) break; cn = s; while (*s && *s != ' ' && *s != '<' && *s != '>' && *s != '=' && *s != '!') s++; ch = *s; *s++ = '\0'; colidx = vpftab_colindex(ft, cn); if (colidx < 0) die("unknown column %s in feature %s", cn, fname); vpftab_info(ft, colidx, &ci); while (ch == ' ') ch = *s++; if (ch == '!' && *s == '=') { rel = RELNE; s++; } else if (ch == '<' && *s == '=') { rel = RELLE; s++; } else if (ch == '>' && *s == '=') { rel = RELGE; s++; } else if (ch == '<' || ch == '>' || ch == '=') { rel = ch; } else die("expected <,>,=,!=,<=,>= at %c%s", ch, s); while (*s == ' ') s++; if (ci.datatype == 'T') { if (rel != '=' && rel != RELNE) die("expected = or != for string compare of col %s", cn); if (*s != '"') die("expected '\"' at %s", s); s++; mstr[nmstr] = s; while (*s && *s != '"') s++; if (*s != '"') die("expected '\"' at %s", s); *s++ = '\0'; astrlen[nmstr] = sizeof astr[nmstr] - 1; snprintf(bbuf, sizeof bbuf, "*T:%s", cn); if (!vpftab_bind(ft, bbuf, &astrlen[nmstr], astr[nmstr])) die("%s", vpf_error(vcov)); mstrrel[nmint] = rel; if (verbose) printf("%% filter (string) %s %c \"%s\"\n", cn, rel, mstr[nmstr]); nmstr++; } else if (ci.number == 1 && (ci.datatype == 'I' || ci.datatype == 'S')) { t = s; mint[nmint] = strtol(t, &s, 0); if (t == s) die("expected number at %s", t); if (*s && *s != ' ') die("expected space at %s", s); snprintf(bbuf, sizeof bbuf, "I:%s", cn); if (!vpftab_bind(ft, bbuf, &aint[nmint])) die("%s", vpf_error(vcov)); mintrel[nmint] = rel; if (verbose) printf("%% filter (int) %s %c %d\n", cn, rel, mint[nmint]); nmint++; } else if (ci.number == 1 && (ci.datatype == 'R' || ci.datatype == 'F')) { t = s; mreal[nmreal] = strtod(t, &s); if (t == s) die("expected number at %s", t); if (*s && *s != ' ') die("expected space at %s", s); snprintf(bbuf, sizeof bbuf, "R:%s", cn); if (!vpftab_bind(ft, bbuf, &areal[nmreal])) die("%s", vpf_error(vcov)); mrealrel[nmreal] = rel; if (verbose) printf("%% filter (int) %s %c %g\n", cn, rel, mreal[nmreal]); nmreal++; } else die("don't know how to handle column %s of type %d%c", cn, ci.number, ci.datatype); } /* Start plotting tiles */ for (ti = 0; ti < ntiles; ti++) { /* Open up a tile directory */ tile = tiles[ti]; v = vpf_new_subdir(vcov, tilename[ti]); if (verbose) printf("%% ftype=%c @%d:%s\n", ftype, tile, tilename[ti]); /* Try opening the spatial index */ switch (ftype) { case 'P': si = vpf_si(v, "nsi"); break; case 'A': si = vpf_si(v, "fsi"); break; case 'L': si = vpf_si(v, "esi"); break; default: die("unknown feature type %c", ftype); } /* No index means no data! */ if (!si) { vpf_free(v); continue; } /* Open up tables depending on feature primitive type */ switch (ftype) { case 'P': end = vpf_table(v, "end"); break; case 'A': fac = vpf_table(v, "fac"); vpftab_bind(fac, "I:ring_ptr", &ring_ptr); vpftab_bind(fac, ftableidtype, &ftableid); edg = vpf_table(v, "edg"); zlen = 1024; vpftab_bind(edg, "*Z:coordinates", &zlen, zarray); vpftab_bind(edg, "K:right_face,K:left_face,K:right_edge,K:left_edge", &rf, &lf, &re, &le); rng = vpf_table(v, "rng"); vpftab_bind(rng, "I:face_id,I:start_edge", &ringface, &start_edge); fbr = vpf_table(v, "fbr"); vpftab_bind(fbr, "F:xmin,F:ymin,F:xmax,F:ymax", &bound[0], &bound[1], &bound[2], &bound[3]); ebr = vpf_table(v, "ebr"); vpftab_bind(ebr, "F:xmin,F:ymin,F:xmax,F:ymax", &bound[0], &bound[1], &bound[2], &bound[3]); break; case 'L': edg = vpf_table(v, "edg"); zlen = 1024; vpftab_bind(edg, "*Z:coordinates", &zlen, zarray); vpftab_bind(edg, ftableidtype, &ftableid); ebr = vpf_table(v, "ebr"); vpftab_bind(ebr, "F:xmin,F:ymin,F:xmax,F:ymax", &bound[0], &bound[1], &bound[2], &bound[3]); break; } /* * Get list of (edge|node|face) primitives from * a spatial index search. */ tt = vpf_si_search_in(si, "id", ux1, uy1, ux2, uy2); if (!tt) die("%s spatial index: %s", fname, vpf_error(v)); if (!vpftab_bind(tt, "I:id", &primid)) die("%s", vpf_error(v)); while (vpftab_fetch(tt)) { switch (ftype) { case 'P': break; case 'A': if (verbose) printf("%% face id %d\n", primid); /* does face really intersect view region? */ vpftab_seek(fbr, primid); if (!vpftab_fetch(fbr)) break; if (ux2 < bound[0]/*x1*/ || bound[2]/*x2*/ < ux1 || uy2 < bound[1]/*y1*/ || bound[3]/*y2*/ < uy1) continue; /* while */ /* find if it is actually in our feature table */ vpftab_seek(fac, primid); vpftab_fetch(fac); if (verbose) printf("%% ftableid is %d\n", ftableid); if (ftableid == NULL_LONG) continue; /* while */ break; case 'L': if (verbose) printf("%% edge id %d\n", primid); /* find if it is actually in our feature table */ vpftab_seek(edg, primid); vpftab_fetch(edg); if (verbose) printf("%% ftableid is %d\n", ftableid); if (ftableid == NULL_LONG) continue; break; } /* Fetch */ vpftab_seek(ft, ftableid); vpftab_fetch(ft); if (verbose) { printf("%% int ["); for (i = 0; i < nmint; i++) printf(" %d", aint[i]); printf(" ] real ["); for (i = 0; i < nmreal; i++) printf(" %g", areal[i]); printf(" ] str ["); for (i = 0; i < nmstr; i++) printf(" '%.*s'", astrlen[i], astr[i]); printf(" ]\n"); } matches = 1; for (i = 0; matches && i < nmint; i++) switch (mintrel[i]) { case '=': matches = (aint[i] == mint[i]); break; case RELNE: matches = (aint[i] != mint[i]); break; case '<': matches = (aint[i] < mint[i]); break; case '>': matches = (aint[i] > mint[i]); break; case RELLE: matches = (aint[i] <= mint[i]); break; case RELGE: matches = (aint[i] >= mint[i]); break; } for (i = 0; matches && i < nmreal; i++) switch (mintrel[i]) { case '=': matches = (areal[i] == mreal[i]); break; case RELNE: matches = (areal[i] != mreal[i]); break; case '<': matches = (areal[i] < mreal[i]); break; case '>': matches = (areal[i] > mreal[i]); break; case RELLE: matches = (areal[i] <= mreal[i]); break; case RELGE: matches = (areal[i] >= mreal[i]); break; } for (i = 0; matches && i < nmstr; i++) { astr[i][astrlen[i]] = '\0'; strip(astr[i], sizeof astr[i]); switch (mintrel[i]) { case '=': matches = (strcmp(astr[i], mstr[i]) == 0); break; case RELNE: matches = (strcmp(astr[i], mstr[i]) != 0); break; } } if (!matches) continue; /* Check against matching expression */ switch (ftype) { case 'P': break; case 'A': /* start plotting the ring paths. */ printf("newpath\n"); if (verbose) printf("%% ring_ptr is %d\n", ring_ptr); vpftab_seek(rng, ring_ptr); while (vpftab_fetch(rng)) { if (ringface != primid) break; /* Plot the current ring around face 'primid' */ if (verbose) printf("%% start_edge = %d\n", start_edge); cur = start_edge; plotedge(cur, edg, ebr, &zlen, zarray, bound, &rf.id, ringface, 0, 1); /* plot remaining edges */ for (;;) { if (verbose) printf("%% rf=%d re=%d lf=%d le=%d\n", rf.id, re.id, lf.id, le.id); /* figure out if edge is forward or backward */ if (rf.id == primid) cur = re.id; else if (lf.id == primid) cur = le.id; else die("edge %d not adj to face %d", cur,primid); /* stop when we repeat edges */ if (cur == start_edge) break; if (verbose) printf("%% next edge = %d\n", cur); plotedge(cur, edg, ebr, &zlen, zarray, bound, &rf.id, ringface, 1, 1); } printf("closepath\n"); } /* NB outer ring is clockwise; inner rings are ccw! */ printf("fill\n"); break; case 'L': plotedge(primid, edg, ebr, &zlen, zarray, bound, NULL, 0, 0, 0); printf("stroke\n"); break; } } /* cleanup */ vpftab_free(tt); switch (ftype) { case 'P': vpftab_free(end); break; case 'A': vpftab_free(fac); vpftab_free(edg); vpftab_free(rng); vpftab_free(fbr); vpftab_free(ebr); break; case 'L': vpftab_free(edg); vpftab_free(ebr); break; } } vpftab_free(ft); } /* push a length (measured in degrees) onto the postscript stack */ void pushlen(buf) char *buf; { double num; char *ret; if (*buf == '\0') num = 1.0; else { num = strtod(buf, &ret); if (ret == buf) die("expected floating point number at %s", buf); } printf("%.9g\n", num * pwidth / (ux2 - ux1)); } /* Compute the truth of a '[!]<param> [<rel> <rhs>]' expression */ int ifeval(buf) char *buf; { char *param_name, *s, *t; double param_val = 0, rhs; char rel = 0; int negated = 0, truth = 0; s = buf; if (*s == '!') { negated = 1; s++; while (*s == ' '|| *s == '\t') s++; } param_name = s; for (; *s; s++) if (*s == '<' || *s == ' ' || *s == '\t' || *s == '>' || *s == '!' || *s == '=') break; if (!*s) { rel = RELNE; rhs = 0.0; } else { *s++ = '\0'; while (*s == ' ' || *s == '\t') s++; if (s[0] == '<' && s[1] == '=') { rel = RELLE; s++; } else if (s[0] == '>' && s[1] == '=') { rel = RELGE; s++; } else if (s[0] == '!' && s[1] == '=') { rel = RELNE; s++; } else if (s[0] == '=' && s[1] == '=') { rel = '='; s++; } else if (*s == '<' || *s == '>' || *s == '=') rel = *s; else die("expected <,<=,>,>=,!=,== at %s", s); s++; while (*s == ' ' || *s == '\t') s++; t = s; rhs = strtod(s, &s); if (s == t) die("expected floating point number at %s", t); while (*s == ' ' || *s == '\t') s++; if (*s) die("garbage at end of IF expression: %s", s); } if (strcmp(param_name, "scale") == 0) param_val = p_scale; else die("unknown parameter '%s'", param_name); switch (rel) { case '=': truth = param_val == rhs ;break; case RELNE: truth = param_val != rhs ;break; case '<': truth = param_val < rhs ;break; case RELLE: truth = param_val <= rhs ;break; case '>': truth = param_val > rhs ;break; case RELGE: truth = param_val >= rhs ;break; } if (verbose) printf("%% compute %s(%s(=%g) %c %g -> %s)\n", negated ? "!" : "", param_name, param_val, rel, rhs, truth ? "true" : "false"); return negated ? !truth : truth; } /* Process a "%.COMMAND" line including .IF/.ENDIF expressions */ void command(buf) char *buf; { char *cmd; char *arg; char *s; int i; struct { const char *cmd; void (*fn)(const char *); } cmdtab[] = { { "DATABASE", database }, { "LIBRARY", library }, { "COVERAGE", coverage }, { "FEATURE", feature }, { "PLOT", plot }, { "WHOLEPATH", wholepath }, { "PUSHLEN", pushlen }, }; /* Find command text */ cmd = buf; while (*cmd == ' ' || *cmd == '\t') cmd++; /* Skip command text */ for (arg = cmd; *arg; arg++) if (*arg == ' ' || *arg == '\t') { /* Terminate command word */ *arg++ = '\0'; /* Skip whitespace after command word */ while (*arg == ' ' || *arg == '\t') arg++; break; } /* Remove trailing space from argument text */ if (*arg) { for (s = arg; *s; s++) ; s--; while (s > arg && (*s == ' ' || *s == '\t')) *s-- = '\0'; } if (verbose) printf("%% cmd='%s' arg='%s'\n", cmd, arg); /* Handle if/endifs */ if (strcmp(cmd, "IF") == 0) { if (!ifoff && ifeval(arg)) ifon++; else ifoff++; if (verbose) printf("%% ifon=%d ifoff=%d\n", ifon, ifoff); return; } if (strcmp(cmd, "ELIF") == 0) { if (!ifoff) { if (ifon == 1) die("unexpected ELIF"); ifon--; ifoff++; } else { ifoff--; if (!ifoff && ifeval(arg)) ifon++; else ifoff++; } if (verbose) printf("%% ifon=%d ifoff=%d\n", ifon, ifoff); return; } if (strcmp(cmd, "ELSE") == 0) { if (*arg) die ("unexpected argument to ELSE"); if (!ifoff) { ifon--; if (!ifon) die("unexpected ELSE"); ifoff++; } else { ifoff--; if (!ifoff && ifeval(arg)) ifon++; else ifoff++; } if (verbose) printf("%% ifon=%d ifoff=%d\n", ifon, ifoff); return; } if (strcmp(cmd, "ENDIF") == 0) { if (*arg) die ("unexpected argument to ENDIF"); if (ifoff) ifoff--; else { ifon--; if (!ifon) die("unexpected ENDIF"); } if (verbose) printf("%% ifon=%d ifoff=%d\n", ifon, ifoff); return; } /* Ignore command if we are if'd out */ if (ifoff) return; for (i = 0; i < sizeof cmdtab / sizeof cmdtab[0]; i++) if (strcmp(cmd, cmdtab[i].cmd) == 0) { (*cmdtab[i].fn)(arg); return; } fprintf(stderr, "unknown command '%s'\n", cmd); } int main(argc, argv) int argc; char *argv[]; { FILE *in = NULL; int ch; char buf[1024], *p; int i; int sol = 1; int error = 0; while ((ch = getopt(argc, argv, "g:f:")) != -1) switch (ch) { case 'f': if (in) fclose(in); in = fopen(optarg, "r"); if (!in) error = 1; break; case 'g': pwidth = strtod(optarg, &p); if (p == optarg || *p != 'x') error = 1; else pheight = strtod(p, NULL); break; default: error = 1; } if (argc - optind != 4) error = 1; if (error) { fprintf(stderr, "usage: %s [-g WxH]" " [-f file]" " lat_s lon_w lat_n lon_e\n", argv[0]); exit(1); } uy1 = strtod(argv[optind+0], NULL); ux1 = strtod(argv[optind+1], NULL); uy2 = strtod(argv[optind+2], NULL); ux2 = strtod(argv[optind+3], NULL); /* 1 point on map represents : p_scale points in reality */ p_scale = ((ux2 - ux1) * PTDEG) / pwidth; if (verbose) fprintf(stderr, "SCALE is 1:%f\n", p_scale); if (in == NULL) in = stdin; while ((ch = getc(in)) != EOF) if (sol && ch == '%') { ch = getc(in); sol = 0; if (ch == '.') { for (i = 0; i < sizeof buf - 1; i++) { ch = getc(in); if (ch == '\n' || ch == '\r') { sol = 1; lineno++; break; } buf[i] = (ch == '%') ? '\0' : ch; } buf[i] = '\0'; command(buf); } else { if (!ifoff) { putchar('%'); putchar(ch); } sol = (ch == '\n' || ch == '\r'); if (sol) lineno++; } } else { if (!ifoff) putchar(ch); sol = (ch == '\n' || ch == '\r'); if (sol) lineno++; } if (ifoff || ifon != 1) die("missing ENDIF(s)"); exit(0); } |
From: <le...@us...> - 2002-09-14 14:43:56
|
Update of /cvsroot/meshdb/src/vpf/dump In directory usw-pr-cvs1:/tmp/cvs-serv13680/dump Added Files: Makefile vpfdump.c Log Message: got VPF stuff working on OpenBSD/sparc using www.iscgm.org data --- NEW FILE: Makefile --- # $Id: Makefile,v 1.1 2002/09/14 14:43:54 leonard Exp $ PROG= vpfdump LDADD= -lvpf -lm DPADD= ${LIBVPF} NOMAN= .include <bsd.prog.mk> --- NEW FILE: vpfdump.c --- /* David Leonard, 2002. Public domain. */ /* $Id: vpfdump.c,v 1.1 2002/09/14 14:43:54 leonard Exp $ */ /* * This is a VPF utility program to: * show a physical table header * show a physical table's content * compute a table join, and show result * perform a spatial index search */ #include <stdio.h> #include <math.h> #include <unistd.h> #include <string.h> #include <stdlib.h> #include "vpf.h" #define MAX(a,b) ((a) > (b) ? (a) : (b)) struct x { char type; int width; int count; char name[20]; char q[1+1+1+16+1]; }; /* Macro to carefully append text to a finite string buffer */ #define aprintf(s, end, fmt, arg...) do { \ if (s < end - 1) { \ s += snprintf(s, end - s, fmt , ## arg); \ if (s > end) s = end; \ } \ } while (0) /* Compute the string representation of a cell within a table */ static void strval(v, t, x, buf, buflen) struct vpf *v; struct vpftab *t; struct x *x; char *buf; int buflen; { char *s; char *end = buf + buflen; int i; int count; int sz; void *a; switch (x->type) { case 'L': case 'T': case 'M': case 'N': { count = x->count; if (count > buflen - 1) count = buflen - 1; vpftab_value(t, x->q, &count, buf); while (count > 0 && buf[count-1] == ' ') count--; buf[count] = '\0'; return; } case 'X': buf[0] = '\0'; return; } switch (x->type) { case 'I': sz = sizeof (vpf_long_t); break; case 'S': sz = sizeof (vpf_short_t); break; case 'F': sz = sizeof (vpf_float_t); break; case 'R': sz = sizeof (vpf_double_t); break; case 'B': sz = 2 * sizeof (vpf_double_t); break; case 'C': sz = 2 * sizeof (vpf_float_t); break; case 'Y': sz = 3 * sizeof (vpf_double_t); break; case 'Z': sz = 3 * sizeof (vpf_float_t); break; case 'D': sz = sizeof (vpf_date_t); break; case 'K': sz = sizeof (vpf_triplet_t); break; default: fprintf(stderr, "unknown type %c\n", x->type); exit(1); } count = x->count; a = malloc(count * sz); if (a == NULL) { fprintf(stderr, "malloc\n"); exit(1); } vpftab_value(t, x->q, &count, a); s = buf; for (i = 0; i < count && s < end - 1; i++) { if (i) aprintf(s, end, " "); switch (x->type) { case 'I': if (((vpf_long_t *)a)[i] == NULL_LONG) aprintf(s, end, "-"); else aprintf(s, end, "%d", ((vpf_long_t *)a)[i]); break; case 'S': if (((vpf_short_t *)a)[i] == NULL_SHORT) aprintf(s, end, "-"); else aprintf(s, end, "%d", ((vpf_short_t *)a)[i]); break; case 'F': if (FLOAT_IS_NULL(((vpf_float_t *)a)[i])) aprintf(s, end, "-"); else aprintf(s, end, "%g", ((vpf_float_t *)a)[i]); break; case 'R': if (DOUBLE_IS_NULL(((vpf_double_t *)a)[i])) aprintf(s, end, "-"); else aprintf(s, end, "%g", ((vpf_double_t *)a)[i]); break; case 'B': if (DOUBLE_IS_NULL(((vpf_double_t *)a)[i*2+0]) &&DOUBLE_IS_NULL(((vpf_double_t *)a)[i*2+1])) aprintf(s, end, "-"); else aprintf(s, end, "%g,%g", ((vpf_double_t *)a)[i*2+0], ((vpf_double_t *)a)[i*2+1]); break; case 'C': if (FLOAT_IS_NULL(((vpf_float_t *)a)[i*2+0]) &&FLOAT_IS_NULL(((vpf_float_t *)a)[i*2+1])) aprintf(s, end, "-"); else aprintf(s, end, "%g,%g", ((vpf_float_t *)a)[i*2+0], ((vpf_float_t *)a)[i*2+1]); break; case 'Y': if (DOUBLE_IS_NULL(((vpf_double_t *)a)[i*3+0]) &&DOUBLE_IS_NULL(((vpf_double_t *)a)[i*3+1]) &&DOUBLE_IS_NULL(((vpf_double_t *)a)[i*3+2])) aprintf(s, end, "-"); else aprintf(s, end, "%g,%g,%g", ((vpf_double_t *)a)[i*3+0], ((vpf_double_t *)a)[i*3+1], ((vpf_double_t *)a)[i*3+2]); break; case 'Z': if (FLOAT_IS_NULL(((vpf_float_t *)a)[i*3+0]) &&FLOAT_IS_NULL(((vpf_float_t *)a)[i*3+1]) &&FLOAT_IS_NULL(((vpf_float_t *)a)[i*3+2])) aprintf(s, end, "-"); else aprintf(s, end, "%g,%g,%g", ((vpf_float_t *)a)[i*3+0], ((vpf_float_t *)a)[i*3+1], ((vpf_float_t *)a)[i*3+2]); break; case 'D': { vpf_date_t *d = (vpf_date_t *)a + i; if (DATE_IS_NULL(*d)) { aprintf(s, end, "-"); break; } aprintf(s, end, "%04d", d->year); if (d->month) { aprintf(s, end, "-%02d", d->month); if (d->day) { aprintf(s, end, "-%02d", d->day); if (!DOUBLE_IS_NULL(d->time)) { aprintf(s, end, "-%02d:%02d:%04.1f", (int)d->time / 3600, ((int)d->time / 60) % 60, d->time - 60*((int)d->time / 60)); if (!DOUBLE_IS_NULL(d->tz)) aprintf(s, end, "%+03d%02d", (int)d->tz / 60, (int)(d->tz < 0 ? -d->tz : d->tz) % 60); } } } } break; case 'K': { vpf_triplet_t *k = (vpf_triplet_t *)a + i; if (TRIPLET_IS_NULL(*k)) { aprintf(s, end, "-"); break; } if (k->valid & TRIPLET_ID) aprintf(s, end, "%d", k->id); else aprintf(s, end, "-"); if (k->valid & (TRIPLET_TILE_ID|TRIPLET_EXT_ID)) { aprintf(s, end, "/"); if (k->valid & TRIPLET_TILE_ID) aprintf(s, end, "%d", k->tile_id); aprintf(s, end, ":"); if (k->valid & TRIPLET_EXT_ID) aprintf(s, end, "%d", k->ext_id); } } break; } } free(a); } /* Print all the rows in the table, projecting only the given columns */ static void printrows(v, t, fmt) struct vpf *v; struct vpftab *t; char **fmt; { char **fmtp; struct x *x; int i, ncols, cidx, rows; char buf[1024]; struct vpf_colinfo ci; if (fmt == NULL || (strcmp(*fmt, "*") == 0 && fmt[1] == NULL)) { ncols = vpftab_cols(t); x = (struct x *)malloc(ncols * sizeof (struct x)); for (i = 0; i < ncols; i++) { vpftab_info(t, i, &ci); strcpy(x[i].name, ci.name); } } else { ncols = 0; for (fmtp = fmt; *fmtp; fmtp++) ncols++; x = (struct x *)malloc(ncols * sizeof (struct x)); for (i = 0; i < ncols; i++) strcpy(x[i].name, fmt[i]); } for (i = 0; i < ncols; i++) { cidx = vpftab_colindex(t, x[i].name); if (cidx < 0) { fprintf(stderr, "printrow: unknown column %s\n", x[i].name); exit(1); } vpftab_info(t, cidx, &ci); x[i].type = ci.datatype; x[i].count = 0; snprintf(x[i].q, sizeof x[i].q, "*%c:%s", x[i].type, x[i].name); x[i].width = strlen(x[i].name); } /* walk through, finding the max width/count of each column */ rows = 0; while (vpftab_fetch(t)) { for (i = 0; i < ncols; i++) { int count = 0; int width; if (!vpftab_value(t, x[i].q, &count, NULL)) { fprintf(stderr, "%s: %s\n", x[i].q, vpf_error(v)); exit(1); } if (count > x[i].count) x[i].count = count; strval(v, t, &x[i], buf, sizeof buf); width = strlen(buf); if (width > x[i].width) x[i].width = width; } rows++; } if (rows == 1) { /* Print the single row sideways! */ int width = 0; for (i = 0; i < ncols; i++) { int nlen = strlen(x[i].name); if (nlen > width) width = nlen; } vpftab_rewind(t); vpftab_fetch(t); for (i = 0; i < ncols; i++) { strval(v, t, &x[i], buf, sizeof buf); printf("%s:%*s %s\n", x[i].name, width - strlen(x[i].name), "", buf); } return; } /* print a header */ for (i = 0; i < ncols; i++) switch (x[i].type) { case 'I': case 'S': case 'F': case 'R': printf("%*s ", x[i].width, x[i].name); break; default: printf("%-*s ", x[i].width, x[i].name); break; } putchar('\n'); for (i = 0; i < ncols; i++) { int k; for (k = 0; k < x[i].width; k++) putchar('-'); putchar(' '); } putchar('\n'); /* print the columns */ vpftab_rewind(t); while (vpftab_fetch(t)) { for (i = 0; i < ncols; i++) { strval(v, t, &x[i], buf, sizeof buf); switch (x[i].type) { case 'I': case 'S': case 'F': case 'R': printf("%*s ", x[i].width, buf); break; default: printf("%-*s ", x[i].width, buf); break; } } putchar('\n'); } } /* Print information about the column types of a table */ static void printheader(t) struct vpftab *t; { int i, ncols; struct vpf_colinfo ci; int vdt_width = 3, ti_width = 2, nar_width = 4, desc_width = 4; ncols = vpftab_cols(t); for (i = 0; i < ncols; i++) { vpftab_info(t, i, &ci); if (ci.vdt) vdt_width=MAX(vdt_width, strlen(ci.vdt)); if (ci.ti) ti_width=MAX(ti_width, strlen(ci.ti)); if (ci.narrative) nar_width=MAX(nar_width, strlen(ci.narrative)); if (ci.desc) desc_width=MAX(desc_width, strlen(ci.desc)); } printf("%4s %-16s %c %-*s %-*s %-*s %-*s\n", "Type", "Name", ' ', vdt_width, "VDT", ti_width, "TI", nar_width, "Narr", desc_width, "Desc"); for (i = 0; i < ncols; i++) { vpftab_info(t, i, &ci); if (ci.number == -1) printf(" *"); else if (ci.number > 1) printf("%3d", ci.number); else printf(" "); printf("%c:%-16s %c %-*s %-*s %-*s %-*s\n", ci.datatype, ci.name, ci.keytype == KEYTYPE_PRIMARY ? 'P' : ci.keytype == KEYTYPE_UNIQUE ? 'U' : ' ', vdt_width, ci.vdt ? ci.vdt : "-", ti_width, ci.ti ? ci.ti : "-", nar_width, ci.narrative ? ci.narrative : "-", desc_width, ci.desc ? ci.desc : ""); } } int main(argc, argv) int argc; char *argv[]; { char *dir = NULL; char *table = NULL; char **fmt = NULL; int fmtc; int ch; struct vpf *v; struct vpftab *t = NULL; struct vpftab *tbak; enum { Table, Join, Spatial } mode = Table; int error = 0; char **jargs = NULL; char *ticol = NULL, *tivalstr = NULL; /* Process command-line arguments */ while ((ch = getopt(argc, argv, "s:d:j:t:")) != -1) switch (ch) { case 'd': dir = optarg; break; case 's': mode = Spatial; table = optarg; break; case 'j': mode = Join; jargs = argv + optind - 1; if (optind + 3 > argc) error = 1; else optind += 3; break; case 't': ticol = optarg; tivalstr = argv[optind]; optind++; break; default: error = 1; } if (mode == Table) { if (optind < argc) table = argv[optind++]; else error = 1; } fmt = argv + optind; fmtc = argc - optind; if (mode == Spatial && fmtc != 0 && fmtc != 2 && fmtc != 4) error = 1; if (error) { fprintf(stderr, "usage:\t%s [-d dir] table [*|col...]\n", argv[0]); fprintf(stderr, "\t%s [-d dir] -j t1 c1 t2 c2} [*|col...]\n", argv[0]); fprintf(stderr, "\t%s [-d dir] -s t1 [x y [x2 y2]]\n", argv[0]); fprintf(stderr, "\t%s [-d dir] [-t col val] table [*|col]\n", argv[0]); exit(1); } /* Create a new VPF directory context */ v = vpf_new(dir); if (v == NULL) { fprintf(stderr, "%s: vpf_new failed\n", argv[0]); exit(1); } if (mode == Join || mode == Table) { if (mode == Join) { struct vpftab *t1, *t2; /* Compute a table join */ if ((t1 = vpf_table(v, jargs[0])) == NULL || (t2 = vpf_table(v, jargs[2])) == NULL || (t = vpf_join(t1, jargs[1], t2, jargs[3])) == NULL) { fprintf(stderr, "%s\n", vpf_error(v)); exit(1); } } if (mode == Table) { struct vpf_tabinfo ti; /* Create a result set from a physical table */ if ((t = vpf_table(v, table)) == NULL || !vpf_table_info(v, table, &ti)) { fprintf(stderr, "%s\n", vpf_error(v)); exit(1); } if (*fmt) printf("table: %s - %s\n", ti.name, ti.desc); else { printf("'%s': %s\n", ti.name, ti.desc); if (ti.narrative) printf(" narrative: %s\n", ti.narrative); if (ti.idxname) printf(" indexfile: %s\n", ti.idxname); } } if (ticol) { char colfmt[25]; struct vpf_colinfo ci; int cindex; vpf_short_t vs; vpf_long_t vl; vpf_float_t vf; vpf_double_t vd; fprintf(stderr, "ticol=%s tivalstr=%s\n", ticol, tivalstr); tbak = t; cindex = vpftab_colindex(tbak, ticol); if (cindex < 0) { fprintf(stderr, "unknown thematic column %s\n", ticol); exit(1); } vpftab_info(tbak, cindex, &ci); snprintf(colfmt, sizeof colfmt, "%d%c:%s", ci.number, ci.datatype, ticol); switch (ci.datatype) { case 'S': vs = atoi(tivalstr); t = vpf_theme(tbak, colfmt, vs); break; case 'I': vl = atol(tivalstr); t = vpf_theme(tbak, colfmt, vl); break; case 'F': vf = atof(tivalstr); t = vpf_theme(tbak, colfmt, vf); break; case 'R': vd = atol(tivalstr); t = vpf_theme(tbak, colfmt, vd); break; case 'T': t = vpf_theme(tbak, colfmt, tivalstr); break; default: fprintf(stderr, "unsupported col type %d%c", ci.number, ci.datatype); exit(1); } if (!t) { fprintf(stderr, "vpf_theme: %s\n", vpf_error(v)); exit(1); } if (ci.datatype != 'T' && ci.number != 1) { fprintf(stderr, "unsupported col type %d%c", ci.number, ci.datatype); exit(1); } } else tbak = NULL; /* Only print the header if no columns given */ if (!*fmt) printheader(t); else printrows(v, t, fmt); vpftab_free(t); if (tbak) vpftab_free(tbak); } if (mode == Spatial) { struct vpfsi *si; float x, y, x2, y2; si = vpf_si(v, table); if (!si) { fprintf(stderr, "%s: %s\n", table, vpf_error(v)); exit(1); } if (fmtc == 0) { struct vpf_siinfo info; /* Print information about the spatial index */ vpf_si_info(si, &info); printf("Spatial index: %s\n", table); printf("prims: %d\n", info.nprim); printf("nodes: %d\n", info.nnode); printf("bbox: (%g,%g), (%g,%g)\n", info.x1, info.y1, info.x2, info.y2); } if (fmtc == 2) { /* * Find primitives that 'are near or enclose' * point (x,y) */ x = atof(fmt[0]); y = atof(fmt[1]); t = vpf_si_search_at(si, "id", x, y); printrows(v, t, NULL); vpftab_free(t); } if (fmtc == 4) { /* * Find primitives that 'are near or inside of' * rectangle (x,y,x2,y2) */ x = atof(fmt[0]); y = atof(fmt[1]); x2 = atof(fmt[2]); y2 = atof(fmt[3]); t = vpf_si_search_in(si, "id", x, y, x2, y2); printrows(v, t, NULL); vpftab_free(t); } } vpf_free(v); exit(0); } |
From: <le...@us...> - 2002-09-14 14:43:56
|
Update of /cvsroot/meshdb/src/vpf In directory usw-pr-cvs1:/tmp/cvs-serv13680 Added Files: Makefile.inc Log Message: got VPF stuff working on OpenBSD/sparc using www.iscgm.org data --- NEW FILE: Makefile.inc --- # $Id: Makefile.inc,v 1.1 2002/09/14 14:43:53 leonard Exp $ CPPFLAGS = -I${.CURDIR}/../libvpf LDFLAGS = -L${.CURDIR}/../libvpf LIBVPF = ${.CURDIR}/../libvpf/libvpf.a DEBUG= -ggdb -Wall |
From: <le...@us...> - 2002-09-14 14:37:09
|
Update of /cvsroot/meshdb/src/vpf/dump In directory usw-pr-cvs1:/tmp/cvs-serv12075/dump Log Message: Directory /cvsroot/meshdb/src/vpf/dump added to the repository |
From: <le...@us...> - 2002-09-14 14:37:09
|
Update of /cvsroot/meshdb/src/vpf/psplot In directory usw-pr-cvs1:/tmp/cvs-serv12075/psplot Log Message: Directory /cvsroot/meshdb/src/vpf/psplot added to the repository |
From: <le...@us...> - 2002-09-14 14:37:09
|
Update of /cvsroot/meshdb/src/vpf/libvpf In directory usw-pr-cvs1:/tmp/cvs-serv12075/libvpf Log Message: Directory /cvsroot/meshdb/src/vpf/libvpf added to the repository |
From: <le...@us...> - 2002-09-14 14:35:56
|
Update of /cvsroot/meshdb/src/vpf In directory usw-pr-cvs1:/tmp/cvs-serv11605/vpf Log Message: Directory /cvsroot/meshdb/src/vpf added to the repository |
From: <le...@us...> - 2002-08-28 22:42:34
|
Update of /cvsroot/meshdb/www/db2 In directory usw-pr-cvs1:/tmp/cvs-serv2829 Modified Files: map2d.php Log Message: on error, return an image with the error message in it. (mapblast changed their map URL method) Index: map2d.php =================================================================== RCS file: /cvsroot/meshdb/www/db2/map2d.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- map2d.php 10 Aug 2002 11:42:39 -0000 1.3 +++ map2d.php 28 Aug 2002 22:42:29 -0000 1.4 @@ -68,7 +68,27 @@ $errmsg = fread($fp, 8192); fclose($fp); unlink($errfile); - die("wget or png conversion failed: $mburl (via $http_proxy)\n$errmsg"); + $e = "$mburl (via $http_proxy)\n". + "wget or png conversion failed\n". + $errmsg; + + $im = ImageCreate($w,$h); + $black = ImageColorAllocate($im, 0, 0, 0); + $orange = ImageColorAllocate($im, 220, 210, 60); + ImageFilledRectangle($im, 0,0,$w,$h, $orange); + + $elines = explode("\n",$e); + $y = $h/2; + foreach ($elines as $e1) { + ImageString($im, 1, 10, $y, $e1, $black); + $y += 10; + } + + header("Content-type: image/png"); + ImagePNG($im); + + ImageDestroy($im); + exit; } unlink($errfile); $fp = fopen($tmpfile, "r"); |
From: <le...@us...> - 2002-08-26 14:21:09
|
Update of /cvsroot/meshdb/www/db2 In directory usw-pr-cvs1:/tmp/cvs-serv1417 Modified Files: cookies.php index.php view.php Log Message: add the map choice thingy to the index page Index: cookies.php =================================================================== RCS file: /cvsroot/meshdb/www/db2/cookies.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- cookies.php 26 Aug 2002 04:46:51 -0000 1.3 +++ cookies.php 26 Aug 2002 14:21:02 -0000 1.4 @@ -58,7 +58,7 @@ "0" => "sort by NodeID", "1" => "sort by distance" )), - "viewmaplist" => array("Order of maps to show in view page", + "viewmaplist" => array("Order of maps to show in index/view page", "text", "Whitespace-separated list of map types<br>" ."Default: <code>net loc ter elev</code>"), ); Index: index.php =================================================================== RCS file: /cvsroot/meshdb/www/db2/index.php,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- index.php 10 Aug 2002 11:46:37 -0000 1.4 +++ index.php 26 Aug 2002 14:21:02 -0000 1.5 @@ -250,9 +250,16 @@ </td> +<? + $maps = explode(" ", trim($PREF["viewmaplist"])); + if (count($maps)) { +?> <td> <table> +<? foreach ($maps as $maptype) { + if ($maptype == "net") { ?> + <tr><th class="major">Network connectivity view</th></tr> <tr><td valign=top><img width=<?=$len?> height=<?=$len?> @@ -260,8 +267,9 @@ src="map4b.php?<?=$mapargb?>&nonumbers=1" ></td> </tr> +<? } else if ($maptype == "loc") { ?> - <tr><th class="major">Topographic view</th></tr> + <tr><th class="major">Location view</th></tr> <tr> <td valign=top><img width=<?=$len?> height=<?=$len?> @@ -270,16 +278,25 @@ ></td> </tr> - <tr><th class="major">Geographic view</th></tr> +<? } else if ($maptype == "ter") { ?> + + <tr><th class="major">Terrain view</th></tr> <tr><td valign=top><img width=<?=$len?> height=<?=$len?> usemap="#summarymap" src="map3b.php?<?=$mapargb?>" ></td> </tr> - +<? } else if ($maptype == "elev") { + /* ignore elevation */ + } else { ?> + <tr><th class="major">Unknown: <?=htmlspecialchars($maptype)?> + </th></tr> +<? } + } /* foreach */ ?> </table> </td> +<? } /* if maps */ ?> </tr> </table> Index: view.php =================================================================== RCS file: /cvsroot/meshdb/www/db2/view.php,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- view.php 26 Aug 2002 04:44:20 -0000 1.3 +++ view.php 26 Aug 2002 14:21:02 -0000 1.4 @@ -355,8 +355,8 @@ $h2 = doubleval($h2); $w = $IMGWIDTH; - $h = $IMGHEIGHT / 2; - $elevarg = "e1=$e1&n1=$n1&h1=$h1&e2=$e2&n2=$n2&h2=$h2&w=$w&h=$h"; + $hh = $IMGHEIGHT / 2; + $elevarg = "e1=$e1&n1=$n1&h1=$h1&e2=$e2&n2=$n2&h2=$h2&w=$w&h=$hh"; $elevarg = htmlspecialchars($elevarg); $info = split(" ", mybacktick("bin/elev -z ${ZONE} -a $e1 $n1 $h1 -b $e2 $n2 $h2")); @@ -397,7 +397,7 @@ <tr><td><table> <tr><td valign=top><?printf("%.0f", $altmax)?>m</td> <td class="figure" colspan=2 rowspan=2><img - width="<?=$w?>" height="<?=$h?>" + width="<?=$w?>" height="<?=$hh?>" src="elev.php?<?=$elevarg?>"></td></tr> <tr><td valign=bottom> <?printf("%.0f", $altmin)?>m</td></tr> <tr><td></td> @@ -439,7 +439,10 @@ <? } /* elevation diagram */ - } /* map == "elev" */ + } else if ($maptype == "elev") { ?> + <tr><th class="minor">Unknown: <?=htmlspecialchars($maptype)?></th></tr> +<? + } } /* foreach maptype */ ?> </table> |
From: <yo...@us...> - 2002-08-26 13:16:57
|
Update of /cvsroot/meshdb/www/db2 In directory usw-pr-cvs1:/tmp/cvs-serv9057 Modified Files: about.html Log Message: updated url to melbwiress database Index: about.html =================================================================== RCS file: /cvsroot/meshdb/www/db2/about.html,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- about.html 10 Aug 2002 06:23:15 -0000 1.2 +++ about.html 26 Aug 2002 13:16:53 -0000 1.3 @@ -19,7 +19,7 @@ Some other wireless node registries: <ul> <li><a href="http://www.nodedb.com/">NodeDB.com</a> -<li><a href="http://melbwireless.dyndns.org/locfinder">Melbourne: digital and wireless</a> +<li><a href="http://melbourne.wireless.org.au/nodes">Melbourne: digital and wireless</a> <li><a href="http://www.shmoo.com/cgi-bin/gawd/gawd.cgi/">Global access wireless database (GAWD)</a> </ul> </p> |
From: <le...@us...> - 2002-08-26 04:46:54
|
Update of /cvsroot/meshdb/www/db2 In directory usw-pr-cvs1:/tmp/cvs-serv14448 Modified Files: cookies.inc cookies.php Log Message: oops, nearbyrange experimental stuff somehow got in there Index: cookies.inc =================================================================== RCS file: /cvsroot/meshdb/www/db2/cookies.inc,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- cookies.inc 26 Aug 2002 04:44:20 -0000 1.2 +++ cookies.inc 26 Aug 2002 04:46:51 -0000 1.3 @@ -12,7 +12,6 @@ "viewzoom" => "1", "viewpeersortdist" => "1", "_moddate" => "0", - "nearbyrange" => "1", "viewmaplist" => "net loc ter elev", ); Index: cookies.php =================================================================== RCS file: /cvsroot/meshdb/www/db2/cookies.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- cookies.php 26 Aug 2002 04:44:20 -0000 1.2 +++ cookies.php 26 Aug 2002 04:46:51 -0000 1.3 @@ -61,8 +61,6 @@ "viewmaplist" => array("Order of maps to show in view page", "text", "Whitespace-separated list of map types<br>" ."Default: <code>net loc ter elev</code>"), - "nearbyrange" => array("Nearby range", - "text", "Range (in km) to list nearby people on the view page"), ); ?> |
From: <le...@us...> - 2002-08-26 04:44:28
|
Update of /cvsroot/meshdb/www/db2 In directory usw-pr-cvs1:/tmp/cvs-serv14065 Modified Files: cookies.inc cookies.php view.php Log Message: add preference to change the order of maps displayed on the view page; make the path loss info prettier Index: cookies.inc =================================================================== RCS file: /cvsroot/meshdb/www/db2/cookies.inc,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- cookies.inc 10 Aug 2002 03:34:07 -0000 1.1.1.1 +++ cookies.inc 26 Aug 2002 04:44:20 -0000 1.2 @@ -12,6 +12,9 @@ "viewzoom" => "1", "viewpeersortdist" => "1", "_moddate" => "0", + "nearbyrange" => "1", + "viewmaplist" => "net loc ter elev", + ); $PREF_integers = array("imgsz", "myid", "indexlimit", Index: cookies.php =================================================================== RCS file: /cvsroot/meshdb/www/db2/cookies.php,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- cookies.php 10 Aug 2002 03:33:24 -0000 1.1.1.1 +++ cookies.php 26 Aug 2002 04:44:20 -0000 1.2 @@ -58,6 +58,11 @@ "0" => "sort by NodeID", "1" => "sort by distance" )), + "viewmaplist" => array("Order of maps to show in view page", + "text", "Whitespace-separated list of map types<br>" + ."Default: <code>net loc ter elev</code>"), + "nearbyrange" => array("Nearby range", + "text", "Range (in km) to list nearby people on the view page"), ); ?> @@ -99,7 +104,7 @@ } ?> </select> <? } ?> - </td><td class="desc"><?=htmlspecialchars($v[2])?></td> + </td><td class="desc"><?=$v[2]?></td> </tr> <? } ?> @@ -113,10 +118,12 @@ </table> </form> +<!-- <blockquote> cookies are bad m'kay ;) <br>- evilbunny </blockquote> +--> <hr> <? include("footer.inc"); ?> Index: view.php =================================================================== RCS file: /cvsroot/meshdb/www/db2/view.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- view.php 16 Aug 2002 00:32:05 -0000 1.2 +++ view.php 26 Aug 2002 04:44:20 -0000 1.3 @@ -188,7 +188,8 @@ </td> <? - if ($hasloc) { + $maps = explode(" ", trim($PREF["viewmaplist"])); + if ($hasloc && count($maps)) { $w = $IMGWIDTH; $h = $IMGHEIGHT; if (isset($_GET["zoom"])) @@ -257,6 +258,9 @@ <td> <table> <tr><th class="major">Maps</th></tr> +<? + foreach ($maps as $maptype) { + if ($maptype == "net") { ?> <tr><th class="minor">Network</th></tr> <tr><td class="figure"><img width=<?=$w?> height=<?=$h?> usemap="#nodes" @@ -271,7 +275,7 @@ <font color=gray>-</font> inactive, <font color=gray>O</font> multipeer </td></tr> - + <? } else if ($maptype == "loc") { ?> <tr><th class="minor">Location</th></tr> <tr><td class="figure"><map name="nodes"><?=$mapdef?> </map><img width=<?=$w?> height=<?=$h?> @@ -285,7 +289,7 @@ <br> Map data from <a href="http://www.mapblast.com/">MapBlast!</a> </td></tr> - + <? } else if ($maptype == "ter") { ?> <tr><th class="minor">Terrain</th></tr> <tr><td class="figure"><img width=<?=$w?> height=<?=$h?> usemap="#nodes" @@ -302,6 +306,7 @@ high <font color=green><?=$maxalt?></font>m </td></tr> + <? } else if ($maptype == "elev") { ?> <tr><th class="minor">Elevation diagram</th></tr> <tr><td><form action="view.php"> Peer node: @@ -339,8 +344,7 @@ </form> <?=$peermsg?> </td></tr> - -<? +<? if ($peerid != "") { $n1 = doubleval($physloc["n"]); $e1 = doubleval($physloc["e"]); @@ -391,11 +395,11 @@ ?> <tr><td><table> - <tr><td class="caption" valign=top><?printf("%.0f", $altmax)?>m</td> + <tr><td valign=top><?printf("%.0f", $altmax)?>m</td> <td class="figure" colspan=2 rowspan=2><img width="<?=$w?>" height="<?=$h?>" src="elev.php?<?=$elevarg?>"></td></tr> - <tr><td class="caption" valign=bottom><?printf("%.0f", $altmin)?>m</td></tr> + <tr><td valign=bottom> <?printf("%.0f", $altmin)?>m</td></tr> <tr><td></td> <td colspan=2 class="caption" align=center><?=$distance?></td></tr> <tr><td></td> @@ -418,30 +422,25 @@ Inclination: <?=$incl2?>° </td> </tr> - <tr><td></td> - <td class="caption" colspan=2> - <!-- - Surface plot range: - low <?printf("%.2f", $altmin)?>m - high <?printf("%.2f", $altmax)?>m - <br> - Distance: <?=$distance?> - --> - <? if ($distance > 0) { ?> - <br> - Clear path loss:<ul> - <li> - <?printf("%.2f", $pathloss24);?>dB <small>@ 2.4GHz</small> - <li> - <?printf("%.2f", $pathloss58);?>dB <small>@ 5.8GHz</small> - </ul> - <? } ?> - </td></tr> - </table></td></tr> + </table> + <? if ($distance > 0) { ?> + <p> + Clear path loss: + <ul> + <li> + <?printf("%.2f", $pathloss24);?>dB <small>@ 2.4GHz</small> + <li> + <?printf("%.2f", $pathloss58);?>dB <small>@ 5.8GHz</small> + </ul> + </p> + <? } ?> + </td></tr> <? } /* elevation diagram */ + } /* map == "elev" */ + } /* foreach maptype */ ?> </table> </td> |
From: <le...@us...> - 2002-08-22 15:32:32
|
Update of /cvsroot/meshdb/src/mailt In directory usw-pr-cvs1:/tmp/cvs-serv832 Modified Files: view.c Log Message: complete quoted-printable support hackery Index: view.c =================================================================== RCS file: /cvsroot/meshdb/src/mailt/view.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- view.c 22 Aug 2002 15:19:14 -0000 1.2 +++ view.c 22 Aug 2002 15:32:28 -0000 1.3 @@ -410,7 +410,7 @@ if (isplain) { printf("<PRE WRAP=AUTO>"); - printesc(bs, pe); + printescqp(bs, pe, isqp(ps, bs)); printf("</PRE>\n"); } else if (bdry2) { showmixed(v2, ps, pe, &c, id); @@ -459,7 +459,7 @@ if (isplain) { printf("<PRE WRAP=AUTO>"); - printesc(bs, pe); + printescqp(bs, pe, isqp(ps, bs)); printf("</PRE>\n"); shown = index; break; @@ -494,6 +494,8 @@ cstring_t p, s, e, he, hs; cstring_t bodystart, bodyend; int killed = (o->m[id].flags & FLAGS_KILLED); + int qp; + cstring_t ha, hb; m = o->m + id; printf("Content-type: text/html\n\n"); @@ -540,27 +542,29 @@ } printf("<TABLE CLASS=header>"); - if (find1hdr(m, o->mbox, "from", &s, &e)) { + ha = o->mbox + m->pos; + hb = o->mbox + m->pos + m->hdrlen; + if (findhdr(ha, hb, "from", &s, &e)) { printf("<TR><TH>From:</TH><TD><SPAN CLASS=email>"); printesc(s, e); printf("</SPAN></TD></TR>\n"); } - if (find1hdr(m, o->mbox, "to", &s, &e)) { + if (findhdr(ha, hb, "to", &s, &e)) { printf("<TR><TH>To:</TH><TD><SPAN CLASS=email>"); printesc(s, e); printf("</SPAN></TD></TR>\n"); } - if (find1hdr(m, o->mbox, "reply-to", &s, &e)) { + if (findhdr(ha, hb, "reply-to", &s, &e)) { printf("<TR><TH>Reply-To:</TH><TD><SPAN CLASS=email>"); printesc(s, e); printf("</SPAN></TD></TR>\n"); } - if (find1hdr(m, o->mbox, "date", &s, &e)) { + if (findhdr(ha, hb, "date", &s, &e)) { printf("<TR><TH>Date:</TH><TD>"); printesc(s, e); printf("</TD></TR>\n"); } - if (find1hdr(m, o->mbox, "subject", &s, &e)) { + if (findhdr(ha, hb, "subject", &s, &e)) { printf("<TR><TH>Subject:</TH><TD>"); printesc(s, e); printf("</TD></TR>\n"); @@ -574,7 +578,7 @@ * Do the same with multipart/signed */ - if (find1hdr(m, o->mbox, "content-type", &hs, &he)) { + if (findhdr(ha, hb, "content-type", &hs, &he)) { cstring_t *v; v = hdr_split(hs, he); s = o->mbox + m->pos; @@ -592,6 +596,7 @@ "Attachment of type %s</a>", id, v[0], v[0]); } else { textplain: + qp = isqp(ha, hb); bodystart = o->mbox + m->pos + m->hdrlen; bodyend = bodystart + m->bodylen; @@ -611,7 +616,7 @@ while (q < bodyend && *q != '\n') q++; if (gt) printf("<SPAN class=indent%d>", gt); - printesc(p, q); + printescqp(p, q, qp); if (gt) printf("</SPAN>"); p = q; if (p < bodyend && *p == '\n') { @@ -620,7 +625,7 @@ } } #else - printesc(bodystart, bodyend); + printescqp(bodystart, bodyend, qp); #endif printf("</PRE>"); } @@ -656,7 +661,7 @@ printf("</UL>\n"); } - if (find1hdr(m, o->mbox, "message-id", &s, &e)) { + if (findhdr(ha, hb, "message-id", &s, &e)) { printf("<P>[%ld] <SPAN CLASS=messageid>", id); printesc(s, e); printf("</SPAN></P\n"); |
From: <le...@us...> - 2002-08-22 15:19:19
|
Update of /cvsroot/meshdb/src/mailt In directory usw-pr-cvs1:/tmp/cvs-serv29489 Modified Files: view.c Log Message: add initial quoted-printable support hacks Index: view.c =================================================================== RCS file: /cvsroot/meshdb/src/mailt/view.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- view.c 10 Aug 2002 03:45:14 -0000 1.1.1.1 +++ view.c 22 Aug 2002 15:19:14 -0000 1.2 @@ -12,21 +12,72 @@ #define indexfile "subjects.php" static char *relpath; +static int +isqp(hs, bs) + cstring_t hs, bs; +{ + cstring_t hstart, hend, *v; -/* Print a string, substituting HTML enities <, & and > */ + if (findhdr(hs, bs, "content-transfer-encoding", &hstart, &hend)) { + v = hdr_split(hstart, hend); + return v[0] && strcasecmp(v[0], "quoted-printable") == 0; + } else + return 0; +} + +/* Print a [quoted-printable] string, substituting HTML enities <, & and > */ static void -printesc(s, e) +printescqp(s, e, qp) cstring_t s, e; + int qp; { cstring_t p; + char a,b,c; + for (p = s; p < e; p++) { - if (*p == '&') + c = *p; + if (qp && c == '=') { + a = *++p; + if (a == '\n' || a == '\r') + continue; + if (a == '?') { + /* eek! an RFC2047 'encoded-word' */ + cstring_t charset, encoding, text; + charset = ++p; + while (p < e && *p != '?') p++; + if (p<e) p++; + encoding = p; + while (p < e && *p != '?') p++; + if (p<e) p++; + text = p; + while (p+1 < e && !(p[0]=='?' && p[1]=='=')) + p++; + if (p<e) + printf("<span charset=\"%.*s\">", + encoding - 1 - charset, charset); + if (p<e && (*encoding == 'q' || *encoding=='Q')) + { + printescqp(text,p,1); + } else + printescqp(text,p,0); + if (p<e) + printf("</span>"); + if (p+1<e) p++; + continue; + } + b = *++p; + if (a >= 'A') a = a - 'A' + 10; + if (b >= 'A') b = b - 'A' + 10; + c = (a-'0')*16 + (b-'0'); + } + + if (c == '&') printf("&"); - else if (*p == '<') + else if (c == '<') printf("<"); - else if (*p == '>') + else if (c == '>') printf(">"); - else if (*p == '@') + else if (c == '@') printf("-at-"); else if (memcmp("http:", p, 5) == 0 || memcmp("ftp:", p, 5) == 0 || @@ -38,17 +89,35 @@ *u == ')' || *u == '}' ) break; - printf("<a href=\"%.*s\">%c", u - p, p, *p); - printesc(p + 1, u); + /* p..u is an URL */ + printf("<a href=\"%c", c); + printescqp(p+1,u,qp); + printf("\">%c", c); + printescqp(p+1,u,qp); printf("</a>"); p = u - 1; - } else if (*p > '~') - printf("<i>\\x%02x</i>", *p); + } else if (c > '~') + printf("<i>\\x%02x</i>", c); else - putchar(*p); + putchar(c); } } +static void +printesc(s, e) + cstring_t s, e; +{ + cstring_t p; + int qp = 0; + + for (p = s; p+1 < e; p++) + if (p[0] == '=' && p[1] == '?') { + qp = 1; + break; + } + printescqp(s, e, qp); +} + /* Return separator if the content-type is a multipart category or null */ static cstring_t ismultipart(v) @@ -523,6 +592,7 @@ "Attachment of type %s</a>", id, v[0], v[0]); } else { textplain: + bodystart = o->mbox + m->pos + m->hdrlen; bodyend = bodystart + m->bodylen; printf("<PRE WRAP=AUTO>"); |
From: <le...@us...> - 2002-08-22 14:09:15
|
Update of /cvsroot/meshdb/src/mailt In directory usw-pr-cvs1:/tmp/cvs-serv4199 Modified Files: Makefile Added Files: msgid.c Log Message: add a program that finds a message index by Message-Id --- NEW FILE: msgid.c --- /* $Id: msgid.c,v 1.1 2002/08/22 14:09:10 leonard Exp $ */ /* * This program searches for an (unkilled) message with the given * message id. */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <time.h> #include "index.h" #include "open.h" #include "util.h" int main(argc, argv) int argc; char *argv[]; { struct open o; struct mail0 *m0; struct mail *m; msgid_t i, kid; cstring_t mbox, mid, midend; int error = 0; int ch; cstring_t mboxname, indexname = NULL; /* Process command line options */ while ((ch = getopt(argc, argv, "i:")) != -1 && !error) switch (ch) { case 'i': /* index file name */ indexname = optarg; break; default: error = 1; break; } if (optind + 2 != argc && optind + 1 != argc) error = 1; if (error) { fprintf(stderr, "usage: %s [-i index] mbox [message-id]\n", argv[0]); exit(1); } mboxname = argv[optind]; if (optind + 2 == argc) mid = argv[optind+1]; else mid = NULL; if (open_and_load(&o, mboxname, indexname, READWRITE) == -1) exit(1); m = o.m; m0 = o.m0; mbox = o.mbox; /* Search for the first message with that ID */ if (mid) midend = mid + strlen(mid); for (i = 1; i < m0->msgs; i++) { cstring_t s, e; if ((m[i].flags & FLAGS_KILLED) == FLAGS_KILLED) continue; if (find1hdr(m+i, mbox, "message-id", &s, &e) && msgid(s, e, &s, &e)) { if (mid && msgideq(s, e, mid, midend)) { kid = i; break; } if (!mid) printf("%ld %.*s\n", i, e-s, s); } } if (mid) { if (i >= m0->msgs) { fprintf(stderr, "couldn't find message-id <%s>\n", mid); exit(1); } printf("%ld\n", kid); } exit(0); } Index: Makefile =================================================================== RCS file: /cvsroot/meshdb/src/mailt/Makefile,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Makefile 10 Aug 2002 03:45:13 -0000 1.1.1.1 +++ Makefile 22 Aug 2002 14:09:10 -0000 1.2 @@ -7,7 +7,7 @@ LIBS= libmail.a LDLIBS= -lmail -PROGS= update t mkill view size +PROGS= update t mkill view size msgid RANLIB= ranlib WEBHOME= $$HOME/publicweb |
From: <yo...@us...> - 2002-08-21 15:31:22
|
Update of /cvsroot/meshdb/www/deal/templates In directory usw-pr-cvs1:/tmp/cvs-serv14931 Modified Files: index_page.tpl Log Message: updated url to tib Index: index_page.tpl =================================================================== RCS file: /cvsroot/meshdb/www/deal/templates/index_page.tpl,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- index_page.tpl 17 Aug 2002 02:29:44 -0000 1.3 +++ index_page.tpl 21 Aug 2002 15:31:16 -0000 1.4 @@ -4,7 +4,7 @@ <span class="gen"> This is a user-contributed database of component prices that people have spotted in Australia. If you know of a great deal, or the price of a component that other people might be interested in, add it! <br /><br /> -See also: <a href="http://www.wireless.org.au/tib/" class="genlink">The Incredible Bulk</a> - bulk orders organised by Melbourne Wireless. +See also: <a href="http://melbourne.wireless.org.au/tib/" class="genlink">The Incredible Bulk</a> - bulk orders organised by Melbourne Wireless. <br /><br /> The table below is sorted by class, and then by price.<br /> @@ -39,4 +39,4 @@ <tr> <td class="row2" colspan="9"> </td> </tr> -</table> \ No newline at end of file +</table> |
From: <unl...@us...> - 2002-08-17 09:21:18
|
Update of /cvsroot/meshdb/www/deal/db/schema In directory usw-pr-cvs1:/tmp/cvs-serv20143/db/schema Modified Files: deal.sql Log Message: User contact details are important I guess :) Index: deal.sql =================================================================== RCS file: /cvsroot/meshdb/www/deal/db/schema/deal.sql,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- deal.sql 17 Aug 2002 09:09:21 -0000 1.3 +++ deal.sql 17 Aug 2002 09:21:15 -0000 1.4 @@ -76,6 +76,7 @@ user_fname varchar(100) default NULL, user_lname varchar(100) default NULL, user_email varchar(100) NOT NULL default '', + user_contact text, PRIMARY KEY (user_id) ) TYPE=MyISAM COMMENT='Users'; # -------------------------------------------------------- |
From: <unl...@us...> - 2002-08-17 09:09:24
|
Update of /cvsroot/meshdb/www/deal/db/schema In directory usw-pr-cvs1:/tmp/cvs-serv17923/db/schema Modified Files: deal.sql Log Message: Redundancy might be bad as school when learning about schemas. But it sure as hell beats sub selects. Modified deals table accordingly. Index: deal.sql =================================================================== RCS file: /cvsroot/meshdb/www/deal/db/schema/deal.sql,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- deal.sql 17 Aug 2002 09:07:49 -0000 1.2 +++ deal.sql 17 Aug 2002 09:09:21 -0000 1.3 @@ -8,6 +8,7 @@ vendor_id mediumint(9) NOT NULL default '0', product_id mediumint(9) NOT NULL default '0', deal_quantity smallint(6) NOT NULL default '0', + deal_quantity_remaining smallint(6) NOT NULL default '0', deal_unit_price float NOT NULL default '0', deal_spotted int(11) unsigned NOT NULL default '0', deal_expires int(11) unsigned NOT NULL default '0', |
From: <unl...@us...> - 2002-08-17 09:07:52
|
Update of /cvsroot/meshdb/www/deal/db/schema In directory usw-pr-cvs1:/tmp/cvs-serv17695/db/schema Modified Files: deal.sql Log Message: OK some major changes here. Remember that this system is designed to handle purchases (be it bulk or single) and the hardware pool. So I've changed the shema to what I think it should be like. I think the system should be able to handle these as integrated systems. User data being shared. Basically this is an enhanced version of the melbourne bulk thing. But a bit more usefull. Index: deal.sql =================================================================== RCS file: /cvsroot/meshdb/www/deal/db/schema/deal.sql,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- deal.sql 14 Aug 2002 03:49:18 -0000 1.1 +++ deal.sql 17 Aug 2002 09:07:49 -0000 1.2 @@ -1,25 +1,18 @@ -# Host: localhost -# Generation Time: Aug 11, 2002 at 04:32 -# Server version: 3.23.49 -# PHP Version: 4.1.2 -# Database : `meshdb` -# -------------------------------------------------------- - # # Table structure for table `deal` # -DROP TABLE IF EXISTS deal; + CREATE TABLE deal ( deal_id mediumint(9) NOT NULL auto_increment, + user_id mediumint(9) NOT NULL default '0', vendor_id mediumint(9) NOT NULL default '0', product_id mediumint(9) NOT NULL default '0', - deal_minimum_quantity smallint(6) NOT NULL default '0', + deal_quantity smallint(6) NOT NULL default '0', deal_unit_price float NOT NULL default '0', deal_spotted int(11) unsigned NOT NULL default '0', deal_expires int(11) unsigned NOT NULL default '0', - deal_spotter varchar(255) default NULL, + deal_payment_due int(11) unsigned NOT NULL default '0', deal_description text, - deal_key varchar(16) NOT NULL default '', deal_url varchar(255) default NULL, deal_status tinyint(1) NOT NULL default '1', PRIMARY KEY (deal_id) @@ -27,21 +20,28 @@ # -------------------------------------------------------- # +# Table structure for table `deal_users` +# + +CREATE TABLE deal_users ( + deal_id mediumint(9) NOT NULL default '0', + user_id mediumint(9) NOT NULL default '0', + KEY deal_id (deal_id) +) TYPE=MyISAM COMMENT='Users who are interested in a deal.'; +# -------------------------------------------------------- + +# # Table structure for table `donation` # -DROP TABLE IF EXISTS donation; + CREATE TABLE donation ( donation_id mediumint(9) NOT NULL auto_increment, donation_class varchar(255) default NULL, donation_description text, donation_description_url varchar(255) default NULL, - donation_donator varchar(255) default NULL, - donation_donator_email varchar(255) default NULL, - donation_donator_url varchar(255) default NULL, + donation_donator_id mediumint(9) NOT NULL default '0', donation_donated_when int(11) unsigned NOT NULL default '0', - donation_user varchar(255) default NULL, - donation_user_email varchar(255) default NULL, - donation_user_url varchar(255) default NULL, + donation_user_id mediumint(9) NOT NULL default '0', donation_user_used int(11) unsigned NOT NULL default '0', donation_user_lost int(11) unsigned NOT NULL default '0', donation_status tinyint(1) NOT NULL default '1', @@ -52,7 +52,7 @@ # # Table structure for table `product` # -DROP TABLE IF EXISTS product; + CREATE TABLE product ( product_id mediumint(9) NOT NULL auto_increment, product_class varchar(255) default NULL, @@ -65,9 +65,24 @@ # -------------------------------------------------------- # +# Table structure for table `user` +# + +CREATE TABLE user ( + user_id mediumint(9) NOT NULL auto_increment, + username varchar(100) NOT NULL default '', + user_password varchar(32) NOT NULL default '', + user_fname varchar(100) default NULL, + user_lname varchar(100) default NULL, + user_email varchar(100) NOT NULL default '', + PRIMARY KEY (user_id) +) TYPE=MyISAM COMMENT='Users'; +# -------------------------------------------------------- + +# # Table structure for table `vendor` # -DROP TABLE IF EXISTS vendor; + CREATE TABLE vendor ( vendor_id mediumint(9) NOT NULL auto_increment, vendor_name varchar(255) default NULL, |
From: <unl...@us...> - 2002-08-17 02:29:47
|
Update of /cvsroot/meshdb/www/deal/includes In directory usw-pr-cvs1:/tmp/cvs-serv22433/deal/includes Modified Files: page_tail.php Log Message: Working on the templating design, going to start on the actual SQL of the system, with the templating system, then people will be able to have a look at how the functionality works and hack on it also. Notes to Dave: I don't believe there is any overkill at all. If my overkill you mean flexible, functional, stable, reusable, readable code/design. Then yes it probably is overkill. That's how I do stuff though. Index: page_tail.php =================================================================== RCS file: /cvsroot/meshdb/www/deal/includes/page_tail.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- page_tail.php 14 Aug 2002 03:49:18 -0000 1.1 +++ page_tail.php 17 Aug 2002 02:29:44 -0000 1.2 @@ -49,9 +49,13 @@ $endtime = $mtime; $totaltime = ($endtime - $starttime); - -echo '<br /><center><font size="-2">Created this page in '. $totaltime .' seconds : ' . $db->num_queries . ' queries executed.</font></center>'; - +// +// Show Debugging +// +if (DEBUG == TRUE) +{ + echo '<br /><center><font size="-2">Created this page in '. $totaltime .' seconds : ' . $db->num_queries . ' queries executed.</font></center>'; +} // // Close our DB connection. |
From: <unl...@us...> - 2002-08-17 02:29:47
|
Update of /cvsroot/meshdb/www/deal In directory usw-pr-cvs1:/tmp/cvs-serv22433/deal Modified Files: index.php Log Message: Working on the templating design, going to start on the actual SQL of the system, with the templating system, then people will be able to have a look at how the functionality works and hack on it also. Notes to Dave: I don't believe there is any overkill at all. If my overkill you mean flexible, functional, stable, reusable, readable code/design. Then yes it probably is overkill. That's how I do stuff though. Index: index.php =================================================================== RCS file: /cvsroot/meshdb/www/deal/index.php,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- index.php 16 Aug 2002 09:49:01 -0000 1.6 +++ index.php 17 Aug 2002 02:29:44 -0000 1.7 @@ -48,15 +48,24 @@ // Assign variables in template values $template->assign_vars(array( 'SECTION_HEADER' => 'Retail Price Database', - 'MESSAGE2' => 'foo bar!', - 'MESSAGE3' => $foo) + 'TH_CLASS' => 'Class', + 'TH_PRODUCT' => 'Product', + 'TH_OEM' => 'Manufacturer', + 'TH_UNITPRICE' => 'Unit Price', + 'TH_MINQTY' => 'Minumum Quantity', + 'TH_VENDOR' => 'Vendor', + 'TH_SPOTTOR' => 'Spotted By', + 'TH_EXPIRES' => 'Expires', + 'TH_NOTE' => 'Notes') ); + - + + // End Body $template->pparse('index'); - + // // Include Footer |
From: <unl...@us...> - 2002-08-17 02:29:47
|
Update of /cvsroot/meshdb/www/deal/templates In directory usw-pr-cvs1:/tmp/cvs-serv22433/deal/templates Modified Files: index_page.tpl overall_footer.tpl overall_header.tpl stylesheet.css Log Message: Working on the templating design, going to start on the actual SQL of the system, with the templating system, then people will be able to have a look at how the functionality works and hack on it also. Notes to Dave: I don't believe there is any overkill at all. If my overkill you mean flexible, functional, stable, reusable, readable code/design. Then yes it probably is overkill. That's how I do stuff though. Index: index_page.tpl =================================================================== RCS file: /cvsroot/meshdb/www/deal/templates/index_page.tpl,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- index_page.tpl 16 Aug 2002 13:14:25 -0000 1.2 +++ index_page.tpl 17 Aug 2002 02:29:44 -0000 1.3 @@ -1,23 +1,42 @@ <span class="sectionheader">{SECTION_HEADER}</span><br /> <!-- Content // --> -<span class="text"> +<span class="gen"> -This is a user-contributed database of component prices that people have spotted in Australia. If you know of a great deal, or the price of a component that other people might be interested in, add it! <br /> +This is a user-contributed database of component prices that people have spotted in Australia. If you know of a great deal, or the price of a component that other people might be interested in, add it! <br /><br /> See also: <a href="http://www.wireless.org.au/tib/" class="genlink">The Incredible Bulk</a> - bulk orders organised by Melbourne Wireless. -<br /> -The table below is sorted by class, and then by price.<br /> - - -<!-- -<span class="header">Retail prices database</span><br /> -<span class="gentext"> -This is a user-contributed database of component prices that people have spotted in Australia. If you know of a great deal, or the price of a component that other people might be interested in, add it! <br /> -See also: <a href="http://www.wireless.org.au/tib/" class="genlink">The Incredible Bulk</a> - bulk orders organised by Melbourne Wireless -<br /> +<br /><br /> The table below is sorted by class, and then by price.<br /> +<!-- Prices Table --> +<table width="100%" cellpadding="2" cellspacing="1" border="0" class="table"> + <tr> + <th height="25" nowrap="nowrap"> {TH_CLASS} </th> + <th height="25" nowrap="nowrap"> {TH_PRODUCT} </th> + <th height="25" nowrap="nowrap"> {TH_OEM} </th> + <th height="25" nowrap="nowrap"> {TH_UNITPRICE} </th> + <th height="25" nowrap="nowrap"> {TH_MINQTY} </th> + <th height="25" nowrap="nowrap"> {TH_VENDOR} </th> + <th height="25" nowrap="nowrap"> {TH_SPOTTOR} </th> + <th height="25" nowrap="nowrap"> {TH_EXPIRES} </th> + <th height="25" nowrap="nowrap"> {TH_NOTE} </th> + </tr> + <!-- 1BEGIN products --> + <tr> + <td class="row1" align="center" valign="middle">{products.PRODUCT_CLASS}</td> + <td class="row1" width="100%" height="50"><a href="{PRODUCTS_DB_LINK}?product={products.PRODUCT_ID}" class="gen">{products.PRODUCT_NAME}</a></td> + <td class="row1" align="center" valign="middle">{products.PRODUCT_OEM}</td> + <td class="row1" align="center" valign="middle">{products.DEAL_UNITPRICE}</td> + <td class="row1" align="center" valign="middle">{products.DEAL_MINQTY}</td> + <td class="row1" align="center" valign="middle">{products.DEAL_VENDOR}</td> + <td class="row1" align="center" valign="middle">{products.DEAL_SPOTTOR}</td> + <td class="row1" align="center" valign="middle">{products.DEAL_EXPIRES}</td> + <td class="row1" align="center" valign="middle">{products.DEAL_NOTE}</td> + </tr> + + <!-- 1END products --> -{MESSAGE} <br /><br /> -{MESSAGE2} ---> + <tr> + <td class="row2" colspan="9"> </td> + </tr> +</table> \ No newline at end of file Index: overall_footer.tpl =================================================================== RCS file: /cvsroot/meshdb/www/deal/templates/overall_footer.tpl,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- overall_footer.tpl 16 Aug 2002 13:14:25 -0000 1.2 +++ overall_footer.tpl 17 Aug 2002 02:29:44 -0000 1.3 @@ -1,5 +1,5 @@ <hr> -<div align="right"><span class="textsmall"> +<div align="right"><span class="gensmall"> Technical enquiries about this web site should be directed to <a href="mailto:david.leonard+meshweb@itee.uq.edu.au"">David Leonard</a>. <br /> Kindly hosted by the <a href="/">Dept of Information Technology & Electrical Engineering, UQ</a>. <br /> <a href="http://www.itee.uq.edu.au/~mesh/logo/">Logo</a> designed by Matt Gleeson.</span> Index: overall_header.tpl =================================================================== RCS file: /cvsroot/meshdb/www/deal/templates/overall_header.tpl,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- overall_header.tpl 16 Aug 2002 13:14:25 -0000 1.2 +++ overall_header.tpl 17 Aug 2002 02:29:44 -0000 1.3 @@ -15,11 +15,11 @@ </tr> <tr> <td bgcolor="#DFDFDF" height="1" colspan="2"></td></tr> - <tr> <td colspan="2" class="text"> - <a href="{PRICES_DB_LINK}" class="text">{PRICES_DB}</a> : - <a href="{PRODUCTS_DB_LINK}" class="text">{PRODUCTS_DB}</a> : - <a href="{VENDORS_DB_LINK}" class="text">{VENDORS_DB}</a> :: - <a href="{HWPOOL_DB_LINK}" class="text">{HWPOOL_DB}</a> + <tr> <td colspan="2"> + <a href="{PRICES_DB_LINK}">{PRICES_DB}</a> : + <a href="{PRODUCTS_DB_LINK}">{PRODUCTS_DB}</a> : + <a href="{VENDORS_DB_LINK}">{VENDORS_DB}</a> :: + <a href="{HWPOOL_DB_LINK}">{HWPOOL_DB}</a> </td> </tr> Index: stylesheet.css =================================================================== RCS file: /cvsroot/meshdb/www/deal/templates/stylesheet.css,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- stylesheet.css 16 Aug 2002 13:14:25 -0000 1.2 +++ stylesheet.css 17 Aug 2002 02:29:44 -0000 1.3 @@ -11,19 +11,43 @@ .sectionheader { font-weight: bold; font-size: 18px; font-family: "Trebuchet MS",Verdana, Arial, Helvetica, sans-serif; - text-decoration: none; line-height : 120%; color : #006699; + text-decoration: none; line-height : 120%; color : #DD6900; } +/* General font families for common tags */ +font,th,td,p,span { font-family: Verdana, Arial, Helvetica, sans-serif; font-size : 12px; } +a:link,a:active,a:visited { color : #000000; text-decoration: underline; } +a:hover { color : #DD6900; } -.text { font-size: 12px; font-family: Verdana, Arial, Helvetica, sans-serif; } +/* Table Header cells */ +th { + color: #000000; font-size: 11px; + background-color: #DEE3E7; height: 25px; +} -.textsmall { font-size: 10px; font-family: Arial, Helvetica, sans-serif; } +/* Tables */ +.table { background-color: #FFFFFF; border: 1px #006699 solid; } -/* General font families for common tags */ -font,th,td,p { font-family: Verdana, Arial, Helvetica, sans-serif } -a:link,a:active,a:visited { color : #000000; } -a:hover { text-decoration: underline; color : #DD6900; } +/* Main table cell colours and backgrounds */ +td.row1 { background-color: #EFEFEF; } +td.row2 { background-color: #D1D7DC; } +td.row3 { background-color: #DEE3E7; } + + +/* The buttons used for styling in message post */ +.formfield { + background-color : #fefefe; + color : #000000; + font-size: 12px; font-family: Verdana, Arial, Helvetica, sans-serif; +} + +/* General text */ +.gen { font-size : 12px; } +.genmed { font-size : 11px; } +.gensmall { font-size : 10px; } +.gen,.genmed,.gensmall { color : #000000; } + |