void text_term(void) { free(text_n); text_n = NULL; text_n_alloced = 0; savetext(NULL,NULL); }
int search(strings s[], const char * const k, const char * const line) { int i = 0; do if(strcmp(s[i].name, k) == 0) { savetext(s, i, line); return 1; } while(s[++i].name); return 0; }
void main() { Stocks s[SIZE]; load(s, SIZE); sort(s, SIZE); calc(s, SIZE); print(s, SIZE); savetext(s, SIZE); gettextfile(s, SIZE); printf("\n\n=============================after the text file has been retrieved==========================================\n\n"); print(s, SIZE); savebinary(s, SIZE); getbinaryfile(s, SIZE); printf("\n ===================================after the binary file has been retrived ==============================================\n"); print(s, SIZE); system("PAUSE"); }
void miscattrs(Attr *ap, struct objattr *obat) { float *fp; int n; switch (ap->a_type) { case FONT: reset_font((double)ap->a_val.f); break; case SIZE: reset_size(ap->a_sub, (double)ap->a_val.f); break; case SPACE: reset_space(ap->a_sub, (double)ap->a_val.f); break; case TEXTATTR: if (ap->a_val.p != NULL) savetext(ap->a_sub, ap->a_val.p); else /* These type values should be propagated back to other strings */ /* Maybe by calling reset_type, to be added to textgen.c */ text[ntext-1].t_type = ap->a_sub; /* ??? can this ever happen */ /* except after a previous */ /* text in the same object? */ break; case NOEDGE: obat->a_flags &= ~EDGED; break; case LAYER: obat->a_layer = ap->a_val.f; break; case LWEIGHT: obat->a_weight = ap->a_val.f; break; case LCOLOR: obat->a_lcolor = ap->a_val.f; break; case PCOLOR: obat->a_flags |= FILLED; if (ap->a_sub != DEFAULT) obat->a_pcolor = ap->a_val.f; break; case TCOLOR: obat->a_tcolor = ap->a_val.f; break; case DOT: case DASH: n = ap->a_type == DOT ? 3 : 2; if ((fp = (float *)malloc(n * sizeof(float))) == NULL) { yyerror("out of space in miscattrs"); break; } *fp = --n; fp[n] = (ap->a_sub == DEFAULT ? getfval("dashwid") : ap->a_val.f); if (n == 2) fp[1] = -1; /* fill in later, from weight */ ap->a_val.a = fp; /* and fall through to the general case */ case DASHPAT: obat->a_flags |= DOTDASH; obat->a_dashpat.a = ap->a_val.a; break; case HEIGHT: obat->a_ht = ap->a_val.f; break; case WIDTH: obat->a_wid = ap->a_val.f; break; case RADIUS: obat->a_rad = ap->a_val.f; break; case DIAMETER: obat->a_rad = ap->a_val.f / 2; break; } }
obj *linegen(int type) { static double prevdx = HT; static double prevdy = 0; static double prevw = HT10; static double prevh = HT5; int i, j, some, head, ddtype, invis, chop; double ddval, chop1, chop2, x0, y0, x1, y1; double sin(), cos(), atan2(), theta; double defx, defy; obj *p, *ppos; static int xtab[] = { 1, 0, -1, 0 }; /* R=0, U=1, L=2, D=3 */ static int ytab[] = { 0, 1, 0, -1 }; double dx[500], dy[500]; int ndxy; double nx, ny; Attr *ap; nx = curx; ny = cury; defx = getfval("linewid"); defy = getfval("lineht"); prevh = getfval("arrowht"); prevw = getfval("arrowwid"); dx[0] = dy[0] = ndxy = some = head = invis = 0; chop = chop1 = chop2 = 0; ddtype = ddval = 0; for (i = 0; i < nattr; i++) { ap = &attr[i]; switch (ap->a_type) { case TEXTATTR: savetext(ap->a_sub, ap->a_val.p); break; case HEAD: head += ap->a_val.i; break; case INVIS: invis = INVIS; break; case CHOP: if (chop++ == 0) chop1 = chop2 = ap->a_val.f; else chop2 = ap->a_val.f; break; case DOT: case DASH: ddtype = ap->a_type==DOT ? DOTBIT : DASHBIT; if (ap->a_sub == DEFAULT) ddval = getfval("dashwid"); else ddval = ap->a_val.f; break; case SAME: dx[ndxy] = prevdx; dy[ndxy] = prevdy; some++; break; case LEFT: dx[ndxy] -= (ap->a_sub==DEFAULT) ? defx : ap->a_val.f; some++; hvmode = L_DIR; break; case RIGHT: dx[ndxy] += (ap->a_sub==DEFAULT) ? defx : ap->a_val.f; some++; hvmode = R_DIR; break; case UP: dy[ndxy] += (ap->a_sub==DEFAULT) ? defy : ap->a_val.f; some++; hvmode = U_DIR; break; case DOWN: dy[ndxy] -= (ap->a_sub==DEFAULT) ? defy : ap->a_val.f; some++; hvmode = D_DIR; break; case HEIGHT: /* length of arrowhead */ prevh = ap->a_val.f; break; case WIDTH: /* width of arrowhead */ prevw = ap->a_val.f; break; case TO: if (some) { nx += dx[ndxy]; ny += dy[ndxy]; ndxy++; dx[ndxy] = dy[ndxy] = some = 0; } ppos = attr[i].a_val.o; dx[ndxy] = ppos->o_x - nx; dy[ndxy] = ppos->o_y - ny; some++; break; case BY: if (some) { nx += dx[ndxy]; ny += dy[ndxy]; ndxy++; dx[ndxy] = dy[ndxy] = some = 0; } ppos = ap->a_val.o; dx[ndxy] = ppos->o_x; dy[ndxy] = ppos->o_y; some++; break; case THEN: /* turn off any previous accumulation */ if (some) { nx += dx[ndxy]; ny += dy[ndxy]; ndxy++; dx[ndxy] = dy[ndxy] = some = 0; } break; case FROM: case AT: ppos = ap->a_val.o; nx = curx = ppos->o_x; ny = cury = ppos->o_y; break; } } if (some) { nx += dx[ndxy]; ny += dy[ndxy]; ndxy++; defx = dx[ndxy-1]; defy = dy[ndxy-1]; } else { defx *= xtab[hvmode]; defy *= ytab[hvmode]; dx[ndxy] = defx; dy[ndxy] = defy; ndxy++; nx += defx; ny += defy; } prevdx = defx; prevdy = defy; if (chop) { if (chop == 1 && chop1 == 0) /* just said "chop", so use default */ chop1 = chop2 = getfval("circlerad"); theta = atan2(dy[0], dx[0]); x0 = chop1 * cos(theta); y0 = chop1 * sin(theta); curx += x0; cury += y0; dx[0] -= x0; dy[0] -= y0; theta = atan2(dy[ndxy-1], dx[ndxy-1]); x1 = chop2 * cos(theta); y1 = chop2 * sin(theta); nx -= x1; ny -= y1; dx[ndxy-1] -= x1; dy[ndxy-1] -= y1; dprintf("chopping %g %g %g %g; cur=%g,%g end=%g,%g\n", x0, y0, x1, y1, curx, cury, nx, ny); } p = makenode(type, 5 + 2 * ndxy); curx = p->o_val[0] = nx; cury = p->o_val[1] = ny; if (head || type == ARROW) { p->o_nhead = getfval("arrowhead"); p->o_val[2] = prevw; p->o_val[3] = prevh; if (head == 0) head = HEAD2; /* default arrow head */ } p->o_attr = head | invis | ddtype; p->o_val[4] = ndxy; nx = p->o_x; ny = p->o_y; for (i = 0, j = 5; i < ndxy; i++, j += 2) { p->o_val[j] = dx[i]; p->o_val[j+1] = dy[i]; if (type == LINE || type == ARROW) extreme(nx += dx[i], ny += dy[i]); else if (type == SPLINE && i < ndxy-1) { /* to compute approx extreme of spline at p, * compute midway between p-1 and p+1, * then go 3/4 from there to p */ double ex, ey, xi, yi, xi1, yi1; xi = nx + dx[i]; yi = ny + dy[i]; /* p */ xi1 = xi + dx[i+1]; yi1 = yi + dy[i+1]; /* p+1 */ ex = (nx+xi1)/2; ey = (ny+yi1)/2; /* midway */ ex += 0.75*(xi-ex); ey += 0.75*(yi-ey); extreme(ex, ey); nx = xi; ny = yi; } } p->o_ddval = ddval; if (dbg) { printf("S or L from %g %g to %g %g with %d elements:\n", p->o_x, p->o_y, curx, cury, ndxy); for (i = 0, j = 5; i < ndxy; i++, j += 2) printf("%g %g\n", p->o_val[j], p->o_val[j+1]); } extreme(p->o_x, p->o_y); extreme(curx, cury); return(p); }
obj* blockgen(obj *p, obj *q) /* handles [...] */ { int i, invis, at, with; double ddval, h, w, xwith, ywith; double x0, y0, x1, y1, cx, cy; obj *ppos; Attr *ap; invis = at = 0; with = xwith = ywith = 0; ddval = 0; w = p->o_val[2] - p->o_val[0]; h = p->o_val[3] - p->o_val[1]; cx = (p->o_val[2] + p->o_val[0]) / 2; /* geom ctr of [] wrt local orogin */ cy = (p->o_val[3] + p->o_val[1]) / 2; dprintf("cx,cy=%g,%g\n", cx, cy); for (i = 0; i < nattr; i++) { ap = &attr[i]; switch (ap->a_type) { case HEIGHT: h = ap->a_val.f; break; case WIDTH: w = ap->a_val.f; break; case WITH: with = ap->a_val.i; /* corner */ break; case PLACE: /* actually with position ... */ ppos = ap->a_val.o; xwith = cx - ppos->o_x; ywith = cy - ppos->o_y; with = PLACE; break; case AT: case FROM: ppos = ap->a_val.o; curx = ppos->o_x; cury = ppos->o_y; at++; break; case INVIS: invis = INVIS; break; case TEXTATTR: savetext(ap->a_sub, ap->a_val.p); break; } } if (with) { switch (with) { case NORTH: ywith = -h / 2; break; case SOUTH: ywith = h / 2; break; case EAST: xwith = -w / 2; break; case WEST: xwith = w / 2; break; case NE: xwith = -w / 2; ywith = -h / 2; break; case SE: xwith = -w / 2; ywith = h / 2; break; case NW: xwith = w / 2; ywith = -h / 2; break; case SW: xwith = w / 2; ywith = h / 2; break; } curx += xwith; cury += ywith; } if (!at) { if (isright(hvmode)) curx += w / 2; else if (isleft(hvmode)) curx -= w / 2; else if (isup(hvmode)) cury += h / 2; else cury -= h / 2; } x0 = curx - w / 2; y0 = cury - h / 2; x1 = curx + w / 2; y1 = cury + h / 2; extreme(x0, y0); extreme(x1, y1); p->o_x = curx; p->o_y = cury; p->o_nt1 = ntext1; p->o_nt2 = ntext; ntext1 = ntext; p->o_val[0] = w; p->o_val[1] = h; p->o_val[2] = cx; p->o_val[3] = cy; p->o_val[5] = q->o_nobj - 1; /* last item in [...] */ p->o_ddval = ddval; p->o_attr = invis; dprintf("[] %g %g %g %g at %g %g, h=%g, w=%g\n", x0, y0, x1, y1, curx, cury, h, w); if (isright(hvmode)) curx = x1; else if (isleft(hvmode)) curx = x0; else if (isup(hvmode)) cury = y1; else cury = y0; for (i = 0; i <= 5; i++) q->o_val[i] = p->o_val[i]; stack[nstack+1].p_symtab = NULL; /* so won't be found again */ blockadj(p); /* fix up coords for enclosed blocks */ return(p); }
obj *circgen(type) { static float rad[2] = { HT2, WID2 }; static float rad2[2] = { HT2, HT2 }; static float x0, y0, x1, y1, x2, y2; int i, at, t, invis, ddtype, with; float xwith, ywith; float r, r2, ddval; obj *p, *ppos; Attr *ap; at = invis = ddtype = 0; with = xwith = ywith = 0; t = (type == CIRCLE) ? 0 : 1; if (type == CIRCLE) r = r2 = getfval("circlerad"); else if (type == ELLIPSE) { r = getfval("ellipsewid") / 2; r2 = getfval("ellipseht") / 2; } for (i = 0; i < nattr; i++) { ap = &attr[i]; switch (ap->a_type) { case TEXTATTR: savetext(ap->a_sub, ap->a_val.p); break; case RADIUS: r = ap->a_val.f; break; case DIAMETER: case WIDTH: r = ap->a_val.f / 2; break; case HEIGHT: r2 = ap->a_val.f / 2; break; case SAME: r = rad[t]; r2 = rad2[t]; break; case WITH: with = ap->a_val.i; break; case AT: ppos = ap->a_val.o; curx = ppos->o_x; cury = ppos->o_y; at++; break; case INVIS: invis = INVIS; break; case DOT: case DASH: ddtype = ap->a_type==DOT ? DOTBIT : DASHBIT; if (ap->a_sub == DEFAULT) ddval = getfval("dashwid"); else ddval = ap->a_val.f; break; } } if (type == CIRCLE) r2 = r; /* probably superfluous */ if (with) { switch (with) { case NORTH: ywith = -r2; break; case SOUTH: ywith = r2; break; case EAST: xwith = -r; break; case WEST: xwith = r; break; case NE: xwith = -r * 0.707; ywith = -r2 * 0.707; break; case SE: xwith = -r * 0.707; ywith = r2 * 0.707; break; case NW: xwith = r * 0.707; ywith = -r2 * 0.707; break; case SW: xwith = r * 0.707; ywith = r2 * 0.707; break; } curx += xwith; cury += ywith; } if (!at) { if (isright(hvmode)) curx += r; else if (isleft(hvmode)) curx -= r; else if (isup(hvmode)) cury += r2; else cury -= r2; } p = makenode(type, 2); p->o_val[0] = rad[t] = r; p->o_val[1] = rad2[t] = r2; if (r <= 0 || r2 <= 0) { yyerror("%s has invalid radius %g\n", (type==CIRCLE) ? "circle" : "ellipse", r<r2 ? r : r2); } p->o_attr = invis | ddtype; extreme(curx+r, cury+r2); extreme(curx-r, cury-r2); if (type == CIRCLE) dprintf("C %g %g %g\n", curx, cury, r); if (type == ELLIPSE) dprintf("E %g %g %g %g\n", curx, cury, r, r2); if (isright(hvmode)) curx += r; else if (isleft(hvmode)) curx -= r; else if (isup(hvmode)) cury += r2; else cury -= r2; return(p); }
obj *troffgen(char *s) /* save away a string of troff commands */ { savetext(CENTER, s); /* use the existing text mechanism */ return makenode(TROFF, 0); }
obj *textgen(void) { int i, sub, nstr, at, with, hset, invis; double xwith, ywith, h, w, x0, y0, x1, y1; obj *p, *ppos; Attr *ap; at = with = nstr = hset = invis = 0; h = getfval("textht"); w = getfval("textwid"); for (i = 0; i < nattr; i++) { ap = &attr[i]; switch (ap->a_type) { case HEIGHT: h = ap->a_val.f; hset++; break; case WIDTH: w = ap->a_val.f; break; case WITH: with = ap->a_val.i; break; case INVIS: invis = INVIS; break; case AT: ppos = ap->a_val.o; curx = ppos->o_x; cury = ppos->o_y; at++; break; case TEXTATTR: sub = ap->a_sub; if (ap->a_val.p == NULL) /* an isolated modifier */ text[ntext-1].t_type = sub; else { savetext(sub, ap->a_val.p); nstr++; } break; } } if (hset == 0) /* no explicit ht cmd */ h *= nstr; if (with) { xwith = ywith = 0.0; switch (with) { case NORTH: ywith = -h / 2; break; case SOUTH: ywith = h / 2; break; case EAST: xwith = -w / 2; break; case WEST: xwith = w / 2; break; case NE: xwith = -w / 2; ywith = -h / 2; break; case SE: xwith = -w / 2; ywith = h / 2; break; case NW: xwith = w / 2; ywith = -h / 2; break; case SW: xwith = w / 2; ywith = h / 2; break; } curx += xwith; cury += ywith; } if (!at) { if (isright(hvmode)) curx += w / 2; else if (isleft(hvmode)) curx -= w / 2; else if (isup(hvmode)) cury += h / 2; else cury -= h / 2; } x0 = curx - w / 2; y0 = cury - h / 2; x1 = curx + w / 2; y1 = cury + h / 2; extreme(x0, y0); extreme(x1, y1); dprintf("Text h %g w %g at %g,%g\n", h, w, curx, cury); p = makenode(TEXT, 2); p->o_attr = invis; p->o_val[0] = w; p->o_val[1] = h; if (isright(hvmode)) curx = x1; else if (isleft(hvmode)) curx = x0; else if (isup(hvmode)) cury = y1; else cury = y0; return(p); }
obj* movegen(void) { static double prevdx, prevdy; int i, some; double defx, defy, dx, dy; obj *p; obj *ppos; static int xtab[] = { 1, 0, -1, 0 }; /* R=0, U=1, L=2, D=3 */ static int ytab[] = { 0, 1, 0, -1 }; Attr *ap; defx = getfval("movewid"); defy = getfval("moveht"); dx = dy = some = 0; for (i = 0; i < nattr; i++) { ap = &attr[i]; switch (ap->a_type) { case TEXTATTR: savetext(ap->a_sub, ap->a_val.p); break; case SAME: dx = prevdx; dy = prevdy; some++; break; case LEFT: dx -= (ap->a_sub==DEFAULT) ? defx : ap->a_val.f; some++; hvmode = L_DIR; break; case RIGHT: dx += (ap->a_sub==DEFAULT) ? defx : ap->a_val.f; some++; hvmode = R_DIR; break; case UP: dy += (ap->a_sub==DEFAULT) ? defy : ap->a_val.f; some++; hvmode = U_DIR; break; case DOWN: dy -= (ap->a_sub==DEFAULT) ? defy : ap->a_val.f; some++; hvmode = D_DIR; break; case TO: ppos = ap->a_val.o; dx = ppos->o_x - curx; dy = ppos->o_y - cury; some++; break; case BY: ppos = ap->a_val.o; dx = ppos->o_x; dy = ppos->o_y; some++; break; case FROM: case AT: ppos = ap->a_val.o; curx = ppos->o_x; cury = ppos->o_y; break; } } if (some) { defx = dx; defy = dy; } else { defx *= xtab[hvmode]; defy *= ytab[hvmode]; } prevdx = defx; prevdy = defy; extreme(curx, cury); curx += defx; cury += defy; extreme(curx, cury); p = makenode(MOVE, 0); dprintf("M %g %g\n", curx, cury); return(p); }
obj *arcgen(type) /* handles circular and (eventually) elliptical arcs */ { static float prevw = HT10; static float prevh = HT5; static float prevrad = HT2; static int dtox[2][4] ={ 1, -1, -1, 1, 1, 1, -1, -1 }; static int dtoy[2][4] ={ 1, 1, -1, -1, -1, 1, 1, -1 }; static int dctrx[2][4] ={ 0, -1, 0, 1, 0, 1, 0, -1 }; static int dctry[2][4] ={ 1, 0, -1, 0, -1, 0, 1, 0 }; static int nexthv[2][4] ={ U_DIR, L_DIR, D_DIR, R_DIR, D_DIR, R_DIR, U_DIR, L_DIR }; float dx2, dy2, ht, phi, r, d, ddval; int i, head, to, at, cw, invis, ddtype; obj *p, *ppos; float fromx, fromy, tox, toy; Attr *ap; prevrad = getfval("arcrad"); prevh = getfval("arrowht"); prevw = getfval("arrowwid"); fromx = curx; fromy = cury; head = to = at = cw = invis = ddtype = 0; for (i = 0; i < nattr; i++) { ap = &attr[i]; switch (ap->a_type) { case TEXTATTR: savetext(ap->a_sub, ap->a_val.p); break; case HEAD: head += ap->a_val.i; break; case INVIS: invis = INVIS; break; case DOT: case DASH: ddtype = ap->a_type==DOT ? DOTBIT : DASHBIT; if (ap->a_sub == DEFAULT) ddval = getfval("dashwid"); else ddval = ap->a_val.f; break; case HEIGHT: /* length of arrowhead */ prevh = ap->a_val.f; break; case WIDTH: /* width of arrowhead */ prevw = ap->a_val.f; break; case RADIUS: prevrad = ap->a_val.f; break; case DIAMETER: prevrad = ap->a_val.f / 2; break; case CW: cw = 1; break; case FROM: /* start point of arc */ ppos = ap->a_val.o; fromx = ppos->o_x; fromy = ppos->o_y; break; case TO: /* end point of arc */ ppos = ap->a_val.o; tox = ppos->o_x; toy = ppos->o_y; to++; break; case AT: /* center of arc */ ppos = ap->a_val.o; curx = ppos->o_x; cury = ppos->o_y; at = 1; break; case UP: hvmode = U_DIR; break; case DOWN: hvmode = D_DIR; break; case RIGHT: hvmode = R_DIR; break; case LEFT: hvmode = L_DIR; break; } } if (!at && !to) { /* the defaults are mostly OK */ curx = fromx + prevrad * dctrx[cw][hvmode]; cury = fromy + prevrad * dctry[cw][hvmode]; tox = fromx + prevrad * dtox[cw][hvmode]; toy = fromy + prevrad * dtoy[cw][hvmode]; hvmode = nexthv[cw][hvmode]; } else if (!at) { dx2 = (tox - fromx) / 2; dy2 = (toy - fromy) / 2; phi = atan2(dy2, dx2) + (cw ? -PI/2 : PI/2); if (prevrad <= 0.0) prevrad = dx2*dx2+dy2*dy2; for (r=prevrad; (d = r*r - (dx2*dx2+dy2*dy2)) <= 0.0; r *= 2) ; /* this kludge gets around too-small radii */ prevrad = r; ht = sqrt(d); curx = fromx + dx2 + ht * cos(phi); cury = fromy + dy2 + ht * sin(phi); dprintf("dx2,dy2=%g,%g, phi=%g, r,ht=%g,%g\n", dx2, dy2, phi, r, ht); } else if (at && !to) { /* do we have all the cases??? */ tox = fromx + prevrad * dtox[cw][hvmode]; toy = fromy + prevrad * dtoy[cw][hvmode]; hvmode = nexthv[cw][hvmode]; } if (cw) { /* interchange roles of from-to and heads */ float temp; temp = fromx; fromx = tox; tox = temp; temp = fromy; fromy = toy; toy = temp; if (head == HEAD1) head = HEAD2; else if (head == HEAD2) head = HEAD1; } p = makenode(type, 7); arc_extreme(fromx, fromy, tox, toy, curx, cury); p->o_val[0] = fromx; p->o_val[1] = fromy; p->o_val[2] = tox; p->o_val[3] = toy; if (cw) { curx = fromx; cury = fromy; } else { curx = tox; cury = toy; } p->o_val[4] = prevw; p->o_val[5] = prevh; p->o_val[6] = prevrad; p->o_attr = head | (cw ? CW_ARC : 0) | invis | ddtype; if (head) p->o_nhead = getfval("arrowhead"); dprintf("arc rad %g at %g %g from %g %g to %g %g head %g %g\n", prevrad, p->o_x, p->o_y, p->o_val[0], p->o_val[1], p->o_val[2], p->o_val[3], p->o_val[4], p->o_val[5]); return(p); }
obj *boxgen(void) { static double prevh = HT; static double prevw = WID; /* golden mean, sort of */ int i, at, battr, with; double ddval, fillval, xwith, ywith; double h, w, x0, y0, x1, y1; obj *p, *ppos; Attr *ap; h = getfval("boxht"); w = getfval("boxwid"); at = battr = with = 0; ddval = fillval = xwith = ywith = 0; for (i = 0; i < nattr; i++) { ap = &attr[i]; switch (ap->a_type) { case HEIGHT: h = ap->a_val.f; break; case WIDTH: w = ap->a_val.f; break; case SAME: h = prevh; w = prevw; break; case WITH: with = ap->a_val.i; /* corner */ break; case AT: ppos = ap->a_val.o; curx = ppos->o_x; cury = ppos->o_y; at++; break; case INVIS: battr |= INVIS; break; case NOEDGE: battr |= NOEDGEBIT; break; case DOT: case DASH: battr |= ap->a_type==DOT ? DOTBIT : DASHBIT; if (ap->a_sub == DEFAULT) ddval = getfval("dashwid"); else ddval = ap->a_val.f; break; case FILL: battr |= FILLBIT; if (ap->a_sub == DEFAULT) fillval = getfval("fillval"); else fillval = ap->a_val.f; break; case TEXTATTR: savetext(ap->a_sub, ap->a_val.p); break; } } if (with) { switch (with) { case NORTH: ywith = -h / 2; break; case SOUTH: ywith = h / 2; break; case EAST: xwith = -w / 2; break; case WEST: xwith = w / 2; break; case NE: xwith = -w / 2; ywith = -h / 2; break; case SE: xwith = -w / 2; ywith = h / 2; break; case NW: xwith = w / 2; ywith = -h / 2; break; case SW: xwith = w / 2; ywith = h / 2; break; } curx += xwith; cury += ywith; } if (!at) { if (isright(hvmode)) curx += w / 2; else if (isleft(hvmode)) curx -= w / 2; else if (isup(hvmode)) cury += h / 2; else cury -= h / 2; } x0 = curx - w / 2; y0 = cury - h / 2; x1 = curx + w / 2; y1 = cury + h / 2; extreme(x0, y0); extreme(x1, y1); p = makenode(BOX, 2); p->o_val[0] = w; p->o_val[1] = h; p->o_attr = battr; p->o_ddval = ddval; p->o_fillval = fillval; dprintf("B %g %g %g %g at %g %g, h=%g, w=%g\n", x0, y0, x1, y1, curx, cury, h, w); if (isright(hvmode)) curx = x1; else if (isleft(hvmode)) curx = x0; else if (isup(hvmode)) cury = y1; else cury = y0; prevh = h; prevw = w; return(p); }
int loadFile(char *fnam) { unsigned long linenr; char *p; FILE *fin; join(fnam, fEXT); if((fin = fopen(fnam, "rt")) == NULL && (fin = fopen(temp, "rt")) == NULL) { pxerror("opening ", fnam); return 33; } printf("CRITSTRS: load file %s\n", fnam); linenr = 0; while (fgets(temp, sizeof(temp), fin)) { ++linenr; p = strchr(temp, '\0'); if(p[-1] != '\n') { fprintf(stderr, "Line %lu too long\n", linenr); return 41; } /* Cut trailing control characters */ while (--p >= temp && (iscntrl(*p) || isspace(*p))); p[1] = '\0'; switch (*temp) { case ';': case '#': case '\0': /* comment line */ break; case 'S': /* possible help line */ if(isdigit(temp[1])) /* help line */ break; default: /* line */ if((p = strchr(temp, ':')) == NULL) { fprintf(stderr, "Syntax error in line %lu\n", linenr); return 42; } *p = '\0'; if(isdigit(*temp)) { /* error string */ char *q = temp; int nr = 0; do nr = nr * 10 + *q - '0'; while(isdigit(*++q)); if(*q) { fprintf(stderr, "Invalid number in line %lu\n", linenr); return 44; } if(nr < 0 || nr > 255 - STR_ERROR) { fprintf(stderr, "String number too large in line %lu\n" , linenr); return 45; } savetext(strg, STR_ERROR + nr, p + 1); } else { strupr(temp); if(!search(strg, temp, p + 1) && !search(special, temp, p + 1)) { fprintf(stderr, "Unknown string name in line %lu\n" , linenr); return 43; } } } } if(ferror(fin)) { pxerror("reading ", fnam); return 34; } fclose(fin); return 0; }