char *string(const char *str) { const char *s; for (s = str; *s; s++) ; return stringn(str, s - str); }
/* * Draw text between pointers p and q with first character centered at x, y. * Use color c. Centered if cen is non-zero, right-justified if right is non-zero. * Returns the y coordinate for any following line of text. */ int m_text(int x, int y, char *p, char *q, int c, int cen, int right){ Point tsize; USED(c); tsize=stringsize(font, p); if(cen) x -= tsize.x/2; else if(right) x -= tsize.x; stringn(offscreen, Pt(x, y-tsize.y/2), getcolor(c), ZP, font, p, q-p); return y+tsize.y; }
char *stringd(long n) { char str[25], *s = str + sizeof (str); unsigned long m; if (n == LONG_MIN) m = (unsigned long)LONG_MAX + 1; else if (n < 0) m = -n; else m = n; do *--s = m%10 + '0'; while ((m /= 10) != 0); if (n < 0) *--s = '-'; return stringn(s, str + sizeof (str) - s); }
/* resynch - set line number/file name in # n [ "file" ], #pragma, etc. */ static void resynch(void) { for (cp++; *cp == ' ' || *cp == '\t'; ) cp++; if (limit - cp < MAXLINE) fillbuf(); if (strncmp((char *)cp, "pragma", 6) == 0) { cp += 6; pragma(); } else if (strncmp((char *)cp, "ident", 5) == 0) { cp += 5; ident(); } else if (*cp >= '0' && *cp <= '9') { line: for (lineno = 0; *cp >= '0' && *cp <= '9'; ) lineno = 10*lineno + *cp++ - '0'; lineno--; while (*cp == ' ' || *cp == '\t') cp++; if (*cp == '"') { file = (char *)++cp; while (*cp && *cp != '"' && *cp != '\n') cp++; file = stringn(file, (char *)cp - file); if (*cp == '\n') warning("missing \" in preprocessor line\n"); if (firstfile == 0) firstfile = file; } } else if (strncmp((char *)cp, "line", 4) == 0) { for (cp += 4; *cp == ' ' || *cp == '\t'; ) cp++; if (*cp >= '0' && *cp <= '9') goto line; if (Aflag >= 2) warning("unrecognized control line\n"); } else if (Aflag >= 2 && *cp != '\n') warning("unrecognized control line\n"); while (*cp) if (*cp++ == '\n') if (cp == limit + 1) { nextline(); if (cp == limit) break; } else break; }
/* main_init - process program arguments */ void main_init(int argc, char *argv[]) { char *infile = NULL, *outfile = NULL; int i; static int inited; if (inited) return; inited = 1; type_init(argc, argv); for (i = 1; i < argc; i++) if (strcmp(argv[i], "-g") == 0 || strcmp(argv[i], "-g2") == 0) glevel = 2; else if (strncmp(argv[i], "-g", 2) == 0) { /* -gn[,x] */ char *p = strchr(argv[i], ','); glevel = atoi(argv[i]+2); if (p) { comment = p + 1; if (glevel == 0) glevel = 1; if (stabIR.stabline == NULL) { stabIR.stabline = IR->stabline; stabIR.stabend = IR->stabend; IR->stabline = stabline; IR->stabend = stabend; } } } else if (strcmp(argv[i], "-x") == 0) xref++; else if (strcmp(argv[i], "-A") == 0) { ++Aflag; } else if (strcmp(argv[i], "-P") == 0) Pflag++; else if (strcmp(argv[i], "-w") == 0) wflag++; else if (strcmp(argv[i], "-n") == 0) { if (!YYnull) { YYnull = install(string("_YYnull"), &globals, GLOBAL, PERM); YYnull->type = func(voidptype, NULL, 1); YYnull->sclass = EXTERN; (*IR->defsymbol)(YYnull); } } else if (strncmp(argv[i], "-n", 2) == 0) { /* -nvalid[,check] */ char *p = strchr(argv[i], ','); if (p) { YYcheck = install(string(p+1), &globals, GLOBAL, PERM); YYcheck->type = func(voidptype, NULL, 1); YYcheck->sclass = EXTERN; (*IR->defsymbol)(YYcheck); p = stringn(argv[i]+2, p - (argv[i]+2)); } else p = string(argv[i]+2); YYnull = install(p, &globals, GLOBAL, PERM); YYnull->type = func(voidptype, NULL, 1); YYnull->sclass = EXTERN; (*IR->defsymbol)(YYnull); } else if (strcmp(argv[i], "-v") == 0) fprint(stderr, "%s %s\n", argv[0], rcsid); else if (strncmp(argv[i], "-s", 2) == 0) density = strtod(&argv[i][2], NULL); else if (strncmp(argv[i], "-errout=", 8) == 0) { FILE *f = fopen(argv[i]+8, "w"); if (f == NULL) { fprint(stderr, "%s: can't write errors to `%s'\n", argv[0], argv[i]+8); exit(EXIT_FAILURE); } fclose(f); f = freopen(argv[i]+8, "w", stderr); assert(f); } else if (strncmp(argv[i], "-e", 2) == 0) { int x; if ((x = strtol(&argv[i][2], NULL, 0)) > 0) errlimit = x; } else if (strncmp(argv[i], "-little_endian=", 15) == 0) IR->little_endian = argv[i][15] - '0'; else if (strncmp(argv[i], "-mulops_calls=", 18) == 0) IR->mulops_calls = argv[i][18] - '0'; else if (strncmp(argv[i], "-wants_callb=", 13) == 0) IR->wants_callb = argv[i][13] - '0'; else if (strncmp(argv[i], "-wants_argb=", 12) == 0) IR->wants_argb = argv[i][12] - '0'; else if (strncmp(argv[i], "-left_to_right=", 15) == 0) IR->left_to_right = argv[i][15] - '0'; else if (strncmp(argv[i], "-wants_dag=", 11) == 0) IR->wants_dag = argv[i][11] - '0'; else if (*argv[i] != '-' || strcmp(argv[i], "-") == 0) { if (infile == NULL) infile = argv[i]; else if (outfile == NULL) outfile = argv[i]; } if (infile != NULL && strcmp(infile, "-") != 0 && freopen(infile, "r", stdin) == NULL) { fprint(stderr, "%s: can't read `%s'\n", argv[0], infile); exit(EXIT_FAILURE); } if (outfile != NULL && strcmp(outfile, "-") != 0 && freopen(outfile, "w", stdout) == NULL) { fprint(stderr, "%s: can't write `%s'\n", argv[0], outfile); exit(EXIT_FAILURE); } }
void tkcvstextdraw(Image *img, TkCitem *i, TkEnv *pe) { TkEnv *e; TkCtext *t; Point o, dp; Rectangle r; char *p, *next; Image *pen; int len, lw, end, start; t = TKobj(TkCtext, i); e = i->env; pen = t->pen; if(pen == nil) { if (e->set & (1<<TkCfill)) pen = tkgc(e, TkCfill); else pen = img->display->black; } o = addpt(t->anchorp, i->p.drawpt[0]); p = t->text; while(p && *p) { next = tkcvstextgetl(t, e->font, p, &len); dp = o; if(t->justify != Tkleft) { lw = stringnwidth(e->font, p, len); if(t->justify == Tkcenter) dp.x += (t->pixwidth - lw)/2; else if(t->justify == Tkright) dp.x += t->pixwidth - lw; } lw = p - t->text; if(t->self != -1 && lw+len > t->self) { if(t->sell >= t->self) { start = t->self - lw; end = t->sell - lw; } else { start = t->sell - lw; end = t->self - lw; } if(start < 0) r.min.x = o.x; else r.min.x = dp.x + stringnwidth(e->font, p, start); r.min.y = dp.y; if(end > len) r.max.x = o.x + t->pixwidth; else r.max.x = dp.x + stringnwidth(e->font, p, end); r.max.y = dp.y + e->font->height; tktextsdraw(img, r, pe, t->sbw); r.max.y = dp.y; if(start > 0) stringn(img, dp, pen, dp, e->font, p, start); if(end > start) stringn(img, r.min, tkgc(pe, TkCselectfgnd), r.min, e->font, p+start, end-start); if(len > end) stringn(img, r.max, pen, r.max, e->font, p+end, len-end); } else stringn(img, dp, pen, dp, e->font, p, len); if(t->focus) { lw = p - t->text; if(t->icursor >= lw && t->icursor <= lw+len) { lw = t->icursor - lw; if(lw > 0) lw = stringnwidth(e->font, p, lw); r.min.x = dp.x + lw; r.min.y = dp.y - 1; r.max.x = r.min.x + 2; r.max.y = r.min.y + e->font->height + 1; draw(img, r, pen, nil, ZP); } } o.y += e->font->height; p = next; } }
#include "c.h" static char rcsid[] = "$Name: v4_2 $($Id: main.c,v 1.1 2002/08/28 23:12:44 drh Exp $)"; static void typestab(Symbol, void *); static void stabline(Coordinate *); static void stabend(Coordinate *, Symbol, Coordinate **, Symbol *, Symbol *); Interface *IR = NULL; int Aflag; /* >= 0 if -A specified */ int Pflag; /* != 0 if -P specified */ int glevel; /* == [0-9] if -g[0-9] specified */ int xref; /* != 0 for cross-reference data */ Symbol YYnull; /* _YYnull symbol if -n or -nvalidate specified */ Symbol YYcheck; /* _YYcheck symbol if -nvalidate,check specified */ static char *comment; static Interface stabIR; static char *currentfile; /* current file name */ static int currentline; /* current line number */ static FILE *srcfp; /* stream for current file, if non-NULL */ static int srcpos; /* position of srcfp, if srcfp is non-NULL */ int main(int argc, char *argv[]) { int i, j; for (i = argc - 1; i > 0; i--) if (strncmp(argv[i], "-target=", 8) == 0) break; if (i > 0) { char *s = strchr(argv[i], '\\'); if (s != NULL) *s = '/'; for (j = 0; bindings[j].name && bindings[j].ir; j++) if (strcmp(&argv[i][8], bindings[j].name) == 0) { IR = bindings[j].ir; break; } if (s != NULL) *s = '\\'; } if (!IR) { fprint(stderr, "%s: unknown target", argv[0]); if (i > 0) fprint(stderr, " `%s'", &argv[i][8]); fprint(stderr, "; must specify one of\n"); for (i = 0; bindings[i].name; i++) fprint(stderr, "\t-target=%s\n", bindings[i].name); exit(EXIT_FAILURE); } init(argc, argv); t = gettok(); (*IR->progbeg)(argc, argv); for (i = 1; i < argc; i++) if (strcmp(argv[i], "-n") == 0) { if (!YYnull) { YYnull = install(string("_YYnull"), &globals, GLOBAL, PERM); YYnull->type = func(voidptype, NULL, 1); YYnull->sclass = EXTERN; (*IR->defsymbol)(YYnull); } } else if (strncmp(argv[i], "-n", 2) == 0) { /* -nvalid[,check] */ char *p = strchr(argv[i], ','); if (p) { YYcheck = install(string(p+1), &globals, GLOBAL, PERM); YYcheck->type = func(voidptype, NULL, 1); YYcheck->sclass = EXTERN; (*IR->defsymbol)(YYcheck); p = stringn(argv[i]+2, p - (argv[i]+2)); } else p = string(argv[i]+2); YYnull = install(p, &globals, GLOBAL, PERM); YYnull->type = func(voidptype, NULL, 1); YYnull->sclass = EXTERN; (*IR->defsymbol)(YYnull); } else { profInit(argv[i]); traceInit(argv[i]); } if (glevel && IR->stabinit) (*IR->stabinit)(firstfile, argc, argv); program(); if (events.end) apply(events.end, NULL, NULL); memset(&events, 0, sizeof events); if (glevel || xref) { Symbol symroot = NULL; Coordinate src; foreach(types, GLOBAL, typestab, &symroot); foreach(identifiers, GLOBAL, typestab, &symroot); src.file = firstfile; src.x = 0; src.y = lineno; if ((glevel > 2 || xref) && IR->stabend) (*IR->stabend)(&src, symroot, ltov(&loci, PERM), ltov(&symbols, PERM), NULL); else if (IR->stabend) (*IR->stabend)(&src, NULL, NULL, NULL, NULL); } finalize(); (*IR->progend)(); deallocate(PERM); return errcnt > 0; }
int eenter(char *ask, char *buf, int len, Mouse *m) { int done, down, tick, n, h, w, l, i; Image *b, *save, *backcol, *bordcol; Point p, o, t; Rectangle r, sc; Event ev; Rune k; o = screen->r.min; backcol = allocimagemix(display, DPurpleblue, DWhite); bordcol = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPurpleblue); if(backcol == nil || bordcol == nil) return -1; while(ecankbd()) ekbd(); if(m) o = m->xy; if(buf && len > 0) n = strlen(buf); else { buf = nil; len = 0; n = 0; } k = -1; tick = n; save = nil; done = down = 0; p = stringsize(font, " "); h = p.y; w = p.x; b = screen; sc = b->clipr; replclipr(b, 0, b->r); while(!done){ p = stringsize(font, buf ? buf : ""); if(ask && ask[0]){ if(buf) p.x += w; p.x += stringwidth(font, ask); } r = rectaddpt(insetrect(Rpt(ZP, p), -4), o); p.x = 0; r = rectsubpt(r, p); p = ZP; if(r.min.x < screen->r.min.x) p.x = screen->r.min.x - r.min.x; if(r.min.y < screen->r.min.y) p.y = screen->r.min.y - r.min.y; r = rectaddpt(r, p); p = ZP; if(r.max.x > screen->r.max.x) p.x = r.max.x - screen->r.max.x; if(r.max.y > screen->r.max.y) p.y = r.max.y - screen->r.max.y; r = rectsubpt(r, p); r = insetrect(r, -2); if(save == nil){ save = allocimage(display, r, b->chan, 0, DNofill); if(save == nil){ n = -1; break; } draw(save, r, b, nil, r.min); } draw(b, r, backcol, nil, ZP); border(b, r, 2, bordcol, ZP); p = addpt(r.min, Pt(6, 6)); if(ask && ask[0]){ p = string(b, p, bordcol, ZP, font, ask); if(buf) p.x += w; } if(buf){ t = p; p = stringn(b, p, display->black, ZP, font, buf, utfnlen(buf, tick)); draw(b, Rect(p.x-1, p.y, p.x+2, p.y+3), display->black, nil, ZP); draw(b, Rect(p.x, p.y, p.x+1, p.y+h), display->black, nil, ZP); draw(b, Rect(p.x-1, p.y+h-3, p.x+2, p.y+h), display->black, nil, ZP); p = string(b, p, display->black, ZP, font, buf+tick); } flushimage(display, 1); nodraw: i = Ekeyboard; if(m != nil) i |= Emouse; replclipr(b, 0, sc); i = eread(i, &ev); /* screen might have been resized */ if(b != screen || !eqrect(screen->clipr, sc)){ freeimage(save); save = nil; } b = screen; sc = b->clipr; replclipr(b, 0, b->r); switch(i){ default: done = 1; n = -1; break; case Ekeyboard: k = ev.kbdc; if(buf == nil || k == Keof || k == '\n'){ done = 1; break; } if(k == Knack || k == Kesc){ done = !n; buf[n = tick = 0] = 0; break; } if(k == Ksoh || k == Khome){ tick = 0; continue; } if(k == Kenq || k == Kend){ tick = n; continue; } if(k == Kright){ if(tick < n) tick += chartorune(&k, buf+tick); continue; } if(k == Kleft){ for(i = 0; i < n; i += l){ l = chartorune(&k, buf+tick); if(i+l >= tick){ tick = i; break; } } continue; } if(k == Ketb){ while(tick > 0){ tick--; if(tick == 0 || strchr(" !\"#$%&'()*+,-./:;<=>?@`[\\]^{|}~", buf[tick-1])) break; } buf[n = tick] = 0; break; } if(k == Kbs){ if(tick <= 0) continue; for(i = 0; i < n; i += l){ l = chartorune(&k, buf+i); if(i+l >= tick){ memmove(buf+i, buf+i+l, n - (i+l)); buf[n -= l] = 0; tick -= l; break; } } break; } if(k < 0x20 || k == Kdel || (k & 0xFF00) == KF || (k & 0xFF00) == Spec) continue; if((len-n) <= (l = runelen(k))) continue; memmove(buf+tick+l, buf+tick, n - tick); runetochar(buf+tick, &k); buf[n += l] = 0; tick += l; break; case Emouse: *m = ev.mouse; if(!ptinrect(m->xy, r)){ down = 0; goto nodraw; } if(m->buttons & 7){ down = 1; if(buf && m->xy.x >= (t.x - w)){ down = 0; for(i = 0; i < n; i += l){ l = chartorune(&k, buf+i); t.x += stringnwidth(font, buf+i, 1); if(t.x > m->xy.x) break; } tick = i; } continue; } done = down; break; } if(save){ draw(b, save->r, save, nil, save->r.min); freeimage(save); save = nil; } } replclipr(b, 0, sc); freeimage(backcol); freeimage(bordcol); flushimage(display, 1); return n; }
static void asdl_defstring(int len, char *str) { put(rcc_Defstring(Text_box(stringn(str, len), len))); }