|
|
1.1 ! root 1: #include <stdio.h> ! 2: #include "grap.h" ! 3: #include "y.tab.h" ! 4: ! 5: line(type, p1, p2, desc) /* draw a line segment */ ! 6: Point p1, p2; ! 7: Attr *desc; ! 8: { ! 9: fprintf(tfd, "%s %s from %s", ! 10: type==LINE ? "line" : "arrow", desc_str(desc), xyname(p1)); ! 11: fprintf(tfd, " to %s", xyname(p2)); /* 'cause xyname is botched */ ! 12: fprintf(tfd, "\n"); ! 13: range(p1); ! 14: range(p2); ! 15: } ! 16: ! 17: circle(r, pt) /* draw a circle */ ! 18: double r; ! 19: Point pt; ! 20: { ! 21: if (r > 0.0) ! 22: fprintf(tfd, "circle rad %g at %s\n", r, xyname(pt)); ! 23: else ! 24: fprintf(tfd, "\"\\s-3\\(ob\\s0\" at %s\n", xyname(pt)); ! 25: range(pt); ! 26: } ! 27: ! 28: char *xyname(pt) /* generate xy name macro for point p */ ! 29: Point pt; ! 30: { ! 31: static char buf[200]; ! 32: Obj *p; ! 33: ! 34: p = pt.obj; ! 35: if (p->log & XFLAG) { ! 36: if (pt.x <= 0.0) ! 37: fatal("can't take log of x coord %g", pt.x); ! 38: logit(pt.x); ! 39: } ! 40: if (p->log & YFLAG) { ! 41: if (pt.y <= 0.0) ! 42: fatal("can't take log of y coord %g", pt.y); ! 43: logit(pt.y); ! 44: } ! 45: sprintf(buf, "xy_%s(%g,%g)", p->name, pt.x, pt.y); ! 46: return buf; /* WATCH IT: static */ ! 47: } ! 48: ! 49: pic(s) /* fire out pic stuff directly */ ! 50: char *s; ! 51: { ! 52: while (*s == ' ') ! 53: s++; ! 54: fprintf(tfd, "%s\n", s); ! 55: } ! 56: ! 57: int auto_x = 0; /* counts abscissa if none provided */ ! 58: ! 59: numlist() /* print numbers in default way */ ! 60: { ! 61: Obj *p; ! 62: Point pt; ! 63: int i; ! 64: static char *spot = "\\s-5\\(bu\\s0"; ! 65: Attr *ap; ! 66: ! 67: p = pt.obj = lookup(curr_coord, 1); ! 68: if (nnum == 1) { ! 69: nnum = 2; ! 70: num[1] = num[0]; ! 71: num[0] = ++auto_x; ! 72: } ! 73: pt.x = num[0]; ! 74: if (p->attr && p->attr->sval) ! 75: spot = p->attr->sval; ! 76: for (i = 1; i < nnum; i++) { ! 77: pt.y = num[i]; ! 78: if (p->attr == 0 || p->attr->type == 0) { ! 79: ap = makesattr(tostring(spot), 0); ! 80: plot(ap, pt); ! 81: } else ! 82: next(p, pt, p->attr); ! 83: } ! 84: nnum = 0; ! 85: } ! 86: ! 87: plot(sl, pt) /* put stringlist sl at point pt */ ! 88: Attr *sl; ! 89: Point pt; ! 90: { ! 91: fprintf(tfd, "%s at %s\n", slprint(sl), xyname(pt)); ! 92: range(pt); ! 93: freeattr(sl); ! 94: } ! 95: ! 96: plotnum(f, fmt, pt) /* plot value f at point */ ! 97: double f; ! 98: char *fmt; ! 99: Point pt; ! 100: { ! 101: char buf[100]; ! 102: ! 103: if (fmt) { ! 104: sprintf(buf, fmt, f); ! 105: free(fmt); ! 106: } else if (f >= 0.0) ! 107: sprintf(buf, "%g", f); ! 108: else ! 109: sprintf(buf, "\\-%g", -f); ! 110: fprintf(tfd, "\"%s\" at %s\n", buf, xyname(pt)); ! 111: range(pt); ! 112: } ! 113: ! 114: drawdesc(type, p, desc, s) /* set line description for p */ ! 115: int type; ! 116: Obj *p; ! 117: Attr *desc; ! 118: char *s; ! 119: { ! 120: p->attr = desc; ! 121: p->attr->sval = s; ! 122: if (type == NEW) { ! 123: p->first = 0; /* so it really looks new */ ! 124: auto_x = 0; ! 125: } ! 126: } ! 127: ! 128: next(p, pt, desc) /* add component to a path */ ! 129: Obj *p; ! 130: Point pt; ! 131: Attr *desc; ! 132: { ! 133: char *s; ! 134: ! 135: if (p->first == 0) { ! 136: p->first++; ! 137: fprintf(tfd, "L%s: %s\n", p->name, xyname(pt)); ! 138: } else { ! 139: fprintf(tfd, "line %s from L%s to %s; L%s: Here\n", ! 140: desc_str(desc->type ? desc : p->attr), ! 141: p->name, xyname(pt), p->name); ! 142: } ! 143: if (p->attr && (s=p->attr->sval)) { ! 144: /* BUG: should fix size here */ ! 145: fprintf(tfd, "\"%s\" at %s\n", s, xyname(pt)); ! 146: } ! 147: range(pt); ! 148: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.