--- /sys/games/lib/fortunes Fri Jul 12 22:12:05 2013 +++ /sys/games/lib/fortunes Wed Sep 25 22:18:11 2013 @@ -4313,3 +4313,4 @@ DSM Terminator [ ABORT ] Finished [ 0 request(s) + 0 call(s) distributed in 5ms] Microsoft Office PowerPoint has encountered a problem and cannot exit. We are sorry for the inconvenience. dd: argument 18446744073709551615 out of range +A policeman's job is only easy in a police state. - Orson Welles --- /sys/man/1/pcc Fri Mar 8 21:14:03 2013 +++ /sys/man/1/pcc Thu Sep 26 23:50:12 2013 @@ -129,6 +129,14 @@ Print an assembly language version of the object code on standard output. .TP +.B -T +Pass type signatures on all external and global entities. +The signature is based on the C +.B signof +operator. +See +.IR dynld (2). +.TP .B -a Instead of compiling, print on standard output acid functions (see .IR acid (1)) --- /sys/src/cmd/awk/mkfile Thu Nov 7 17:42:12 2002 +++ /sys/src/cmd/awk/mkfile Fri Sep 27 03:35:55 2013 @@ -28,7 +28,7 @@ ${TARG:%=/386/bin/%}\ #include #include #include +#include #include #include +#include #include #include @@ -70,9 +74,6 @@ */ #define INIT_BITS 9 /* initial number of bits/code */ -void onintr(int); -void oops(int); - #define ARGVAL() (*++(*argv) || (--argc && *++argv)) int n_bits; /* number of bits/code */ @@ -107,9 +108,22 @@ code_int free_ent = 0; /* first unused entry */ int exit_stat = 0; -code_int getcode(); +void cl_block(void); +void cl_hash(count_int); +void compress(void); +void copystat(char *, char *); +void decompress(void); +int foreground(void); +code_int getcode(void); +void onintr(int); +void oops(int); +void output(code_int); +void prratio(FILE *, long, long); +void version(void); +void writeerr(void); -Usage() +void +Usage(void) { #ifdef DEBUG fprintf(stderr,"Usage: compress [-cdfDV] [-b maxbits] [file ...]\n"); @@ -443,6 +457,7 @@ } } exit(exit_stat); + return 0; } static int offset; @@ -465,10 +480,11 @@ * file size for noticeable speed improvement on small files. Please direct * questions about this implementation to ames!jaw. */ -compress() +void +compress(void) { code_int ent, hsize_reg; - code_int i = 0; + code_int i; int c, disp, hshift; long fcode; @@ -584,6 +600,7 @@ uchar lmask[9] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00}; uchar rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff}; +void output( code ) code_int code; { @@ -695,7 +712,8 @@ * be stored in the compressed file. The tables used herein are shared * with those of the compress() routine. See the definitions above. */ -decompress() +void +decompress(void) { int finchar; code_int code, oldcode, incode; @@ -948,18 +966,20 @@ } #endif /* DEBUG */ -writeerr() +void +writeerr(void) { perror(ofname); unlink(ofname); exit(1); } +void copystat(ifname, ofname) char *ifname, *ofname; { int mode; - time_t timep[2]; + time_t timep[2]; /* should be struct utimbuf */ struct stat statbuf; fclose(stdout); @@ -986,7 +1006,7 @@ timep[0] = statbuf.st_atime; timep[1] = statbuf.st_mtime; /* Update last accessed and modified times */ - utime(ofname, timep); + utime(ofname, (struct utimbuf *)timep); // if (unlink(ifname)) /* Remove input file */ // perror(ifname); return; /* success */ @@ -1001,7 +1021,8 @@ * This routine returns 1 if we are running in the foreground and stderr * is a tty. */ -foreground() +int +foreground(void) { if(bgnd_flag) /* background? */ return 0; @@ -1012,6 +1033,7 @@ void onintr(int x) { + USED(x); unlink(ofname); exit(1); } @@ -1019,13 +1041,15 @@ void oops(int x) /* wild pointer -- assume bad input */ { + USED(x); if (do_decomp == 1) fprintf(stderr, "uncompress: corrupt input\n"); unlink(ofname); exit(1); } -cl_block () /* table clear for block compress */ +void +cl_block(void) /* table clear for block compress */ { long rat; @@ -1065,8 +1089,8 @@ } } -cl_hash(hsize) /* reset code table */ -count_int hsize; +void +cl_hash(count_int hsize) /* reset code table */ { count_int *htab_p = htab+hsize; long i; @@ -1096,6 +1120,7 @@ *--htab_p = m1; } +void prratio(stream, num, den) FILE *stream; long num, den; @@ -1113,7 +1138,8 @@ fprintf(stream, "%d.%02d%%", q / 100, q % 100); } -version() +void +version(void) { fprintf(stderr, "%s\n", rcs_ident); fprintf(stderr, "Options: "); --- /sys/src/cmd/compress/mkfile Fri Sep 8 03:37:23 2006 +++ /sys/src/cmd/compress/mkfile Fri Sep 27 03:34:53 2013 @@ -7,4 +7,4 @@ #include -#include +#include #include -#define F1 0 -#define F2 1 -#define F0 3 +enum { + F1, + F2, + NIN, + F0, +}; + #define NFLD 100 /* max field per line */ -#define comp() runecmp(ppi[F1][j1],ppi[F2][j2]) +#define comp() runestrcmp(ppi[F1][j1], ppi[F2][j2]) -FILE *f[2]; -Rune buf[2][BUFSIZ]; /*input lines */ -Rune *ppi[2][NFLD+1]; /* pointers to fields in lines */ -Rune *s1,*s2; -int j1 = 1; /* join of this field of file 1 */ -int j2 = 1; /* join of this field of file 2 */ -int olist[2*NFLD]; /* output these fields */ -int olistf[2*NFLD]; /* from these files */ -int no; /* number of entries in olist */ +Biobuf *f[NIN]; +Rune buf[NIN][Bsize]; /* input lines */ +Rune *ppi[NIN][NFLD+1]; /* pointers to fields in lines */ Rune sep1 = ' '; /* default field separator */ Rune sep2 = '\t'; -char *sepstr=" "; -int discard; /* count of truncated lines */ -Rune null[BUFSIZ] = L""; +int j1 = 1; /* join of this field of file 1 */ +int j2 = 1; /* join of this field of file 2 */ int a1; int a2; -char *getoptarg(int*, char***); -void output(int, int); -int input(int); -void oparse(char*); -void error(char*, char*); -void seek1(void), seek2(void); -Rune *strtorune(Rune *, char *); +int olist[NIN*NFLD]; /* output these fields */ +int olistf[NIN*NFLD]; /* from these files */ +int no; /* number of entries in olist */ +char *sepstr = " "; +int discard; /* count of truncated lines */ +Rune null[Bsize] = L""; +Biobuf binbuf, boutbuf; +Biobuf *bin, *bout; + +char *getoptarg(int*, char***); +int input(int); +void join(int); +void oparse(char*); +void output(int, int); +Rune *strtorune(Rune *, char *); void main(int argc, char **argv) { int i; + vlong off1, off2; + bin = &binbuf; + bout = &boutbuf; + Binit(bin, 0, OREAD); + Binit(bout, 1, OWRITE); + + argv0 = argv[0]; while (argc > 1 && argv[1][0] == '-') { if (argv[1][1] == '\0') break; @@ -57,7 +69,7 @@ a2++; break; default: - error("incomplete option -a",""); + sysfatal("incomplete option -a"); } break; case 'e': @@ -112,49 +124,41 @@ proceed: for (i = 0; i < no; i++) if (olist[i]-- > NFLD) /* 0 origin */ - error("field number too big in -o",""); - if (argc != 3) - error("usage: join [-1 x -2 y] [-o list] file1 file2",""); + sysfatal("field number too big in -o"); + if (argc != 3) { + fprint(2, "usage: join [-1 x -2 y] [-o list] file1 file2\n"); + exits("usage"); + } if (j1 < 1 || j2 < 1) - error("invalid field indices", ""); + sysfatal("invalid field indices"); j1--; j2--; /* everyone else believes in 0 origin */ - s1 = ppi[F1][j1]; - s2 = ppi[F2][j2]; + if (strcmp(argv[1], "-") == 0) - f[F1] = stdin; - else if ((f[F1] = fopen(argv[1], "r")) == 0) - error("can't open %s", argv[1]); - if(strcmp(argv[2], "-") == 0) { - f[F2] = stdin; - } else if ((f[F2] = fopen(argv[2], "r")) == 0) - error("can't open %s", argv[2]); - - if(ftell(f[F2]) >= 0) - seek2(); - else if(ftell(f[F1]) >= 0) - seek1(); - else - error("neither file is randomly accessible",""); + f[F1] = bin; + else if ((f[F1] = Bopen(argv[1], OREAD)) == 0) + sysfatal("can't open %s: %r", argv[1]); + if(strcmp(argv[2], "-") == 0) + f[F2] = bin; + else if ((f[F2] = Bopen(argv[2], OREAD)) == 0) + sysfatal("can't open %s: %r", argv[2]); + + off1 = Boffset(f[F1]); + off2 = Boffset(f[F2]); + if(Bseek(f[F2], 0, 2) >= 0){ + Bseek(f[F2], off2, 0); + join(F2); + }else if(Bseek(f[F1], 0, 2) >= 0){ + Bseek(f[F1], off1, 0); + Bseek(f[F2], off2, 0); + join(F1); + }else + sysfatal("neither file is randomly accessible"); if (discard) - error("some input line was truncated", ""); + sysfatal("some input line was truncated"); exits(""); } -int -runecmp(Rune *a, Rune *b) -{ - while(*a == *b) { - if(*a == '\0') - return 0; - a++; - b++; - } - if(*a < *b) - return -1; - return 1; -} - char * runetostr(char *buf, Rune *r) { @@ -177,90 +181,71 @@ return buf; } -/* lazy. there ought to be a clean way to combine seek1 & seek2 */ -#define get1() n1=input(F1) -#define get2() n2=input(F2) +void +readboth(int n[]) +{ + n[F1] = input(F1); + n[F2] = input(F2); +} void -seek2() +seekbotreadboth(int seekf, vlong bot, int n[]) { - int n1, n2; - int top2=0; - int bot2 = ftell(f[F2]); - get1(); - get2(); - while(n1>0 && n2>0 || (a1||a2) && n1+n2>0) { - if(n1>0 && n2>0 && comp()>0 || n1==0) { - if(a2) output(0, n2); - bot2 = ftell(f[F2]); - get2(); - } else if(n1>0 && n2>0 && comp()<0 || n2==0) { - if(a1) output(n1, 0); - get1(); - } else /*(n1>0 && n2>0 && comp()==0)*/ { - while(n2>0 && comp()==0) { - output(n1, n2); - top2 = ftell(f[F2]); - get2(); - } - fseek(f[F2], bot2, 0); - get2(); - get1(); - for(;;) { - if(n1>0 && n2>0 && comp()==0) { - output(n1, n2); - get2(); - } else if(n1>0 && n2>0 && comp()<0 || n2==0) { - fseek(f[F2], bot2, 0); - get2(); - get1(); - } else /*(n1>0 && n2>0 && comp()>0 || n1==0)*/{ - fseek(f[F2], top2, 0); - bot2 = top2; - get2(); - break; - } - } - } - } + Bseek(f[seekf], bot, 0); + readboth(n); } + void -seek1() +join(int seekf) { - int n1, n2; - int top1=0; - int bot1 = ftell(f[F1]); - get1(); - get2(); - while(n1>0 && n2>0 || (a1||a2) && n1+n2>0) { - if(n1>0 && n2>0 && comp()>0 || n1==0) { - if(a2) output(0, n2); - get2(); - } else if(n1>0 && n2>0 && comp()<0 || n2==0) { - if(a1) output(n1, 0); - bot1 = ftell(f[F1]); - get1(); - } else /*(n1>0 && n2>0 && comp()==0)*/ { - while(n2>0 && comp()==0) { - output(n1, n2); - top1 = ftell(f[F1]); - get1(); + int cmp, less; + int n[NIN]; + vlong top, bot; + + less = seekf == F2; + top = 0; + bot = Boffset(f[seekf]); + readboth(n); + while(n[F1]>0 && n[F2]>0 || (a1||a2) && n[F1]+n[F2]>0) { + cmp = comp(); + if(n[F1]>0 && n[F2]>0 && cmp>0 || n[F1]==0) { + if(a2) + output(0, n[F2]); + if (seekf == F2) + bot = Boffset(f[seekf]); + n[F2] = input(F2); + } else if(n[F1]>0 && n[F2]>0 && cmp<0 || n[F2]==0) { + if(a1) + output(n[F1], 0); + if (seekf == F1) + bot = Boffset(f[seekf]); + n[F1] = input(F1); + } else { + /* n[F1]>0 && n[F2]>0 && cmp==0 */ + while(n[F2]>0 && cmp==0) { + output(n[F1], n[F2]); + top = Boffset(f[seekf]); + n[seekf] = input(seekf); + cmp = comp(); } - fseek(f[F1], bot1, 0); - get2(); - get1(); + seekbotreadboth(seekf, bot, n); for(;;) { - if(n1>0 && n2>0 && comp()==0) { - output(n1, n2); - get1(); - } else if(n1>0 && n2>0 && comp()>0 || n1==0) { - fseek(f[F1], bot1, 0); - get2(); - get1(); - } else /*(n1>0 && n2>0 && comp()<0 || n2==0)*/{ - fseek(f[F1], top1, 0); - bot1 = top1; - get1(); + cmp = comp(); + if(n[F1]>0 && n[F2]>0 && cmp==0) { + output(n[F1], n[F2]); + n[seekf] = input(seekf); + } else if(n[F1]>0 && n[F2]>0 && + (less? cmp<0 :cmp>0) || n[seekf]==0) + seekbotreadboth(seekf, bot, n); + else { + /* + * n[F1]>0 && n[F2]>0 && + * (less? cmp>0 :cmp<0) || + * n[seekf==F1? F2: F1]==0 + */ + Bseek(f[seekf], top, 0); + bot = top; + n[seekf] = input(seekf); break; } } @@ -271,50 +256,63 @@ int input(int n) /* get input line and split into fields */ { - int i, c; + int c, i, len; + char *line; Rune *bp; Rune **pp; - char line[BUFSIZ]; bp = buf[n]; pp = ppi[n]; - if (fgets(line, BUFSIZ, f[n]) == 0) + line = Brdline(f[n], '\n'); + if (line == nil) return(0); + len = Blinelen(f[n]) - 1; + c = line[len]; + line[len] = '\0'; strtorune(bp, line); + line[len] = c; /* restore delimiter */ + if (c != '\n') + discard++; + i = 0; do { i++; if (sep1 == ' ') /* strip multiples */ while ((c = *bp) == sep1 || c == sep2) bp++; /* skip blanks */ - *pp++ = bp; /* record beginning */ - while ((c = *bp) != sep1 && c != '\n' && c != sep2 && c != '\0') + *pp++ = bp; /* record beginning */ + while ((c = *bp) != sep1 && c != sep2 && c != '\0') bp++; - *bp++ = '\0'; /* mark end by overwriting blank */ - } while (c != '\n' && c != '\0' && i < NFLD-1); - if (c != '\n') - discard++; + *bp++ = '\0'; /* mark end by overwriting blank */ + } while (c != '\0' && i < NFLD-1); *pp = 0; return(i); } void +prfields(int f, int on, int jn) +{ + int i; + char buf[Bsize]; + + for (i = 0; i < on; i++) + if (i != jn) + Bprint(bout, "%s%s", sepstr, runetostr(buf, ppi[f][i])); +} + +void output(int on1, int on2) /* print items from olist */ { int i; Rune *temp; - char buf[BUFSIZ]; + char buf[Bsize]; if (no <= 0) { /* default case */ - printf("%s", runetostr(buf, on1? ppi[F1][j1]: ppi[F2][j2])); - for (i = 0; i < on1; i++) - if (i != j1) - printf("%s%s", sepstr, runetostr(buf, ppi[F1][i])); - for (i = 0; i < on2; i++) - if (i != j2) - printf("%s%s", sepstr, runetostr(buf, ppi[F2][i])); - printf("\n"); + Bprint(bout, "%s", runetostr(buf, on1? ppi[F1][j1]: ppi[F2][j2])); + prfields(F1, on1, j1); + prfields(F2, on2, j2); + Bputc(bout, '\n'); } else { for (i = 0; i < no; i++) { if (olistf[i]==F0 && on1>j1) @@ -328,24 +326,15 @@ *temp==0) temp = null; } - printf("%s", runetostr(buf, temp)); + Bprint(bout, "%s", runetostr(buf, temp)); if (i == no - 1) - printf("\n"); + Bputc(bout, '\n'); else - printf("%s", sepstr); + Bprint(bout, "%s", sepstr); } } } -void -error(char *s1, char *s2) -{ - fprintf(stderr, "join: "); - fprintf(stderr, s1, s2); - fprintf(stderr, "\n"); - exits(s1); -} - char * getoptarg(int *argcp, char ***argvp) { @@ -354,7 +343,7 @@ if(argv[1][2] != 0) return &argv[1][2]; if(argc<=2 || argv[2][0]=='-') - error("incomplete option %s", argv[1]); + sysfatal("incomplete option %s", argv[1]); *argcp = argc-1; *argvp = ++argv; return argv[1]; @@ -379,7 +368,7 @@ } /* fall thru */ default: - error("invalid -o list", ""); + sysfatal("invalid -o list"); } if(s[1] == ',') s++; --- /sys/src/cmd/lp/lpsend.c Wed May 30 01:34:58 2012 +++ /sys/src/cmd/lp/lpsend.c Fri Sep 27 02:45:53 2013 @@ -138,8 +138,7 @@ int pass(int inpfd, int outfd, int bsize) { - int bcnt = 0; - int rv = 0; + int rv, bcnt; for(bcnt=bsize; bcnt > 0; bcnt -= rv) { alarm(WRNETIMEOUT); /* to break hanging */ @@ -227,7 +226,6 @@ void main(int argc, char *argv[]) { - char *devdir; int i, rv, netfd, bsize, datafd; #ifndef plan9 void (*oldhandler)(); --- /sys/src/cmd/lp/mkfile Mon Jul 22 22:09:28 2013 +++ /sys/src/cmd/lp/mkfile Fri Sep 27 02:45:39 2013 @@ -12,7 +12,7 @@ BIN=/$objtype/bin/aux type) { case Free: /* free string */ @@ -482,7 +483,11 @@ ep = ebuf; } -void yywrap(void) {} +int +yywrap(void) +{ + return 1; /* read eof; did not switch inputs */ +} char *newfile = 0; /* filename for file copy */ char *untilstr = 0; /* string that terminates a thru */ --- /sys/src/cmd/pic/mkfile Sun Dec 12 02:10:42 1999 +++ /sys/src/cmd/pic/mkfile Fri Sep 27 03:09:21 2013 @@ -27,7 +27,7 @@ o_fillval); } - if (p->o_type == BLOCK) + if (p->o_type == BLOCK){ ; /* nothing at all */ - else if (invis && !fill) + }else if (invis && !fill){ ; /* nothing at all */ - else if (p->o_attr & (DOTBIT|DASHBIT)) + }else if (p->o_attr & (DOTBIT|DASHBIT)) dotbox(x0, y0, x1, y1, p->o_attr, p->o_ddval); else box(x0, y0, x1, y1); --- /sys/src/cmd/postscript/common/bbox.c Sun Dec 12 02:10:53 1999 +++ /sys/src/cmd/postscript/common/bbox.c Fri Sep 27 00:23:20 2013 @@ -1,5 +1,4 @@ /* - * * Boundingbox code for PostScript translators. The boundingbox for each page * is accumulated in bbox - the one for the whole document goes in docbbox. A * call to writebbox() puts out an appropriate comment, updates docbbox, and @@ -7,10 +6,13 @@ * is that we're really printing the current page only if output is now going * to stdout - a valid assumption for all supplied translators. Needs the math * library. - * */ +#define _RESEARCH_SOURCE + #include +#include +#include #include #include #include @@ -32,19 +34,20 @@ double ctm[6] = {1.0, 0.0, 0.0, 1.0, 0.0, 0.0}; double matrix1[6], matrix2[6]; -/*****************************************************************************/ +void concat(double []); +void resetbbox(int); +void rotate(double); +void scale(double, double); +void translate(double, double); +void writebbox(FILE *, char *, int); +void cover(x, y) - double x, y; - { - /* - * * Adds point (x, y) to bbox. Coordinates are in user space - the transformation * to default coordinates happens in writebbox(). - * */ if ( bbox.set == FALSE ) { @@ -60,30 +63,23 @@ bbox.urx = x; if ( y > bbox.ury ) bbox.ury = y; - } /* End else */ - -} /* End of cover */ - -/*****************************************************************************/ + } +} +void writebbox(fp, keyword, slop) - FILE *fp; /* the comment is written here */ char *keyword; /* the boundingbox comment string */ int slop; /* expand (or contract?) the box a bit */ - { - Bbox ubbox; /* user space bounding box */ double x, y; /* - * * Transforms the numbers in the bbox[] using ctm[], adjusts the corners a bit * (depending on slop) and then writes comment. If *keyword is BoundingBox use * whatever's been saved in docbbox, otherwise assume the comment is just for * the current page. - * */ if ( strcmp(keyword, BOUNDINGBOX) == 0 ) @@ -108,55 +104,39 @@ bbox.lly -= slop + 0.5; bbox.urx += slop + 0.5; bbox.ury += slop + 0.5; - fprintf(fp, "%s %d %d %d %d\n", keyword, (int)bbox.llx, (int)bbox.lly,(int)bbox.urx, (int)bbox.ury); + fprintf(fp, "%s %d %d %d %d\n", keyword, (int)bbox.llx, (int)bbox.lly, + (int)bbox.urx, (int)bbox.ury); bbox = ubbox; - } /* End if */ - - resetbbox((fp == stdout) ? TRUE : FALSE); - -} /* End of writebbox */ - -/*****************************************************************************/ - -resetbbox(output) - - int output; + } + resetbbox(fp == stdout); +} +void +resetbbox(int output) { - /* - * * Adds bbox to docbbox and resets bbox for the next page. Only update docbbox * if we really did output on the last page. - * */ if ( docbbox.set == TRUE ) { cover(docbbox.llx, docbbox.lly); cover(docbbox.urx, docbbox.ury); - } /* End if */ + } if ( output == TRUE ) { docbbox = bbox; docbbox.set = TRUE; - } /* End if */ + } bbox.set = FALSE; +} -} /* End of resetbbox */ - -/*****************************************************************************/ - -scale(sx, sy) - - double sx, sy; - +void +scale(double sx, double sy) { - /* - * * Scales the default matrix. - * */ matrix1[0] = sx; @@ -167,21 +147,13 @@ matrix1[5] = 0; concat(matrix1); +} -} /* End of scale */ - -/*****************************************************************************/ - -translate(tx, ty) - - double tx, ty; - +void +translate(double tx, double ty) { - /* - * * Translates the default matrix. - * */ matrix1[0] = 1.0; @@ -192,24 +164,17 @@ matrix1[5] = ty; concat(matrix1); +} -} /* End of translate */ - -/*****************************************************************************/ - -rotate(angle) - - double angle; - +void +rotate(double angle) { /* - * * Rotates by angle degrees. - * */ - angle *= 3.1416 / 180; + angle *= M_PI / 180; matrix1[0] = matrix1[3] = cos(angle); matrix1[1] = sin(angle); @@ -218,23 +183,15 @@ matrix1[5] = 0.0; concat(matrix1); +} -} /* End of rotate */ - -/*****************************************************************************/ - -concat(m1) - - double m1[]; - +void +concat(double m1[]) { - double m2[6]; /* - * * Replaces the ctm[] by the result of the matrix multiplication m1[] x ctm[]. - * */ m2[0] = ctm[0]; @@ -250,8 +207,4 @@ ctm[3] = m1[2] * m2[1] + m1[3] * m2[3]; ctm[4] = m1[4] * m2[0] + m1[5] * m2[2] + m2[4]; ctm[5] = m1[4] * m2[1] + m1[5] * m2[3] + m2[5]; - -} /* End of concat */ - -/*****************************************************************************/ - +} --- /sys/src/cmd/postscript/common/ext.h Sun Dec 12 02:10:54 1999 +++ /sys/src/cmd/postscript/common/ext.h Fri Sep 27 00:48:06 2013 @@ -1,7 +1,5 @@ /* - * * External varibles - most are in glob.c. - * */ extern char **argv; /* global so everyone can use them */ @@ -27,14 +25,10 @@ extern char *optarg; /* for getopt() */ extern int optind; -extern void interrupt(); +extern int cat(char *); +extern void error(int, char *, ...); +extern int in_olist(int); +extern void interrupt(int); +extern int out_list(char *); +extern int setencoding(char *); extern char *tempnam(char*,char*); -/* - * extern char *malloc(); - * extern char *calloc(); - * extern char *strtok(); - * extern long ftell(); - * extern double atof(); - * extern double sqrt(); - * extern double atan2(); - */ --- /sys/src/cmd/postscript/common/gen.h Sun Dec 12 02:10:53 1999 +++ /sys/src/cmd/postscript/common/gen.h Fri Sep 27 00:12:31 2013 @@ -1,8 +1,6 @@ /* - * * A few definitions that shouldn't have to change. Used by most programs in * this package. - * */ #define PROGRAMVERSION "3.3.2" @@ -62,4 +60,3 @@ #define ABS(A) ((A) >= 0 ? (A) : -(A)) #define MIN(A, B) ((A) < (B) ? (A) : (B)) #define MAX(A, B) ((A) > (B) ? (A) : (B)) - --- /sys/src/cmd/postscript/common/getopt.c Thu Mar 8 19:11:52 2007 +++ /sys/src/cmd/postscript/common/getopt.c Fri Sep 27 00:32:14 2013 @@ -1,14 +1,21 @@ #ifndef _POSIX_SOURCE #include #include +#else +#define _BSD_EXTENSION +#include +#include +#include #endif + #include + #define ERR(str, chr) if(opterr){fprintf(stderr, "%s%s%c\n", argv[0], str, chr);} + int opterr = 1; int optind = 1; int optopt; char *optarg; -char *strchr(); int getopt (argc, argv, opts) --- /sys/src/cmd/postscript/common/misc.c Sun Dec 12 02:10:53 1999 +++ /sys/src/cmd/postscript/common/misc.c Fri Sep 27 00:48:49 2013 @@ -1,10 +1,13 @@ /* - * * General purpose routines. - * */ +#define _BSD_EXTENSION + #include +#include +#include +#include #include #include #include @@ -16,21 +19,15 @@ int nolist = 0; /* number of specified ranges */ int olist[50]; /* processing range pairs */ -/*****************************************************************************/ - +int out_list(str) - char *str; - { - int start, stop; /* - * * Grab page ranges from str, save them in olist[], and update the nolist * count. Range syntax matches nroff/troff syntax. - * */ while ( *str && nolist < sizeof(olist) - 2 ) { @@ -40,33 +37,25 @@ stop = str_convert(&str, 9999); if ( start > stop ) - error(FATAL, "illegal range %d-%d", start, stop); + error(FATAL, "illegal range %d-%d", start, stop, 0); olist[nolist++] = start; olist[nolist++] = stop; if ( *str != '\0' ) str++; - } /* End while */ - + } olist[nolist] = 0; - -} /* End of out_list */ - -/*****************************************************************************/ + return 0; +} in_olist(num) - int num; - { - int i; /* - * * Return ON if num is in the current page range list. Print everything if * there's no list. - * */ if ( nolist == 0 ) return(ON); @@ -74,27 +63,19 @@ for ( i = 0; i < nolist; i += 2 ) if ( num >= olist[i] && num <= olist[i+1] ) return(ON); - return(OFF); +} -} /* End of in_olist */ - -/*****************************************************************************/ - +int setencoding(name) - char *name; - { - char path[150]; /* - * * Include the font encoding file selected by name. It's a full pathname if * it begins with /, otherwise append suffix ".enc" and look for the file in * ENCODINGDIR. Missing files are silently ignored. - * */ if ( name == NULL ) @@ -106,52 +87,35 @@ if ( cat(path) == TRUE ) writing = strncmp(name, "UTF", 3) == 0; - -} /* End of setencoding */ - -/*****************************************************************************/ + return 0; +} cat(file) - char *file; - { - int fd_in; int fd_out; char buf[512]; int count; /* - * * Copy *file to stdout. Return FALSE is there was a problem. - * */ fflush(stdout); - if ( (fd_in = open(file, O_RDONLY)) == -1 ) return(FALSE); - fd_out = fileno(stdout); while ( (count = read(fd_in, buf, sizeof(buf))) > 0 ) write(fd_out, buf, count); - close(fd_in); - return(TRUE); - -} /* End of cat */ - -/*****************************************************************************/ +} str_convert(str, err) - char **str; int err; - { - int i; /* @@ -168,63 +132,40 @@ i = 10 * i + **str - '0'; return(i); +} -} /* End of str_convert */ - -/*****************************************************************************/ - -error(kind, mesg, a1, a2, a3) - - int kind; - char *mesg; - unsigned a1, a2, a3; - +void +error(int kind, char *fmt, ...) { + char buf[256]; + va_list arg; -/* - * - * Print an error message and quit if kind is FATAL. - * - */ - - if ( mesg != NULL && *mesg != '\0' ) { - fprintf(stderr, "%s: ", prog_name); - fprintf(stderr, mesg, a1, a2, a3); - if ( lineno > 0 ) - fprintf(stderr, " (line %d)", lineno); - if ( position > 0 ) - fprintf(stderr, " (near byte %d)", position); - putc('\n', stderr); - } /* End if */ - - if ( kind == FATAL && ignore == OFF ) { - if ( temp_file != NULL ) - unlink(temp_file); - exit(x_stat | 01); - } /* End if */ - -} /* End of error */ - -/*****************************************************************************/ - -void interrupt(sig) - - int sig; - -{ + if (fmt) { + va_start(arg, fmt); + vsnprintf(buf, sizeof buf, fmt, arg); + va_end(arg); + fprintf(stderr, "%s: %s", prog_name, buf); + if (lineno > 0) + fprintf(stderr, " (line %d)", lineno); + if (position > 0) + fprintf(stderr, " (near byte %d)", position); + putc('\n', stderr); + } + if (kind == FATAL && ignore == OFF) { + if (temp_file != NULL) + unlink(temp_file); + exit(x_stat | 01); + } +} /* - * * Signal handler for translators. - * */ - +void +interrupt(int sig) +{ + USED(sig); if ( temp_file != NULL ) unlink(temp_file); - exit(1); - -} /* End of interrupt */ - -/*****************************************************************************/ - +} --- /sys/src/cmd/postscript/common/mkfile Mon Apr 8 22:14:26 2013 +++ /sys/src/cmd/postscript/common/mkfile Thu Sep 26 23:56:45 2013 @@ -18,5 +18,5 @@ - +#include +#include #include "gen.h" /* general purpose definitions */ +#include "ext.h" #include "request.h" /* a few special definitions */ #include "path.h" /* for the default request file */ @@ -20,27 +20,22 @@ int nextreq = 0; /* goes in request[nextreq] */ char *requestfile = REQUESTFILE; /* default lookup file */ -/*****************************************************************************/ - -saverequest(want) - - char *want; /* grab code for this stuff */ - -{ - - char *page; /* and save it for this page */ - char *strtok(); +void dumprequest(char *, char *, FILE *); +void writerequest(int, FILE *); /* - * * Save the request until we get to appropriate page - don't even bother with * the lookup right now. Format of *want string is "request", "request:page", or * "request:page:file", and we assume we can change the string here as needed. * If page is omitted or given as 0 the request will be done globally. If *want * includes a file, request and page must also be given, and in that case *file * will be used for the lookup. - * */ +void +saverequest(want) + char *want; /* grab code for this stuff */ +{ + char *page; /* and save it for this page */ if ( nextreq < MAXREQUEST ) { request[nextreq].want = strtok(want, ": "); @@ -51,55 +46,39 @@ request[nextreq].file = requestfile; nextreq++; } else error(NON_FATAL, "too many requests - ignoring %s", want); +} -} /* End of saverequest */ - -/*****************************************************************************/ - +/* + * Writes out all the requests that have been saved for page. Page 0 refers to + * the global environment and is done during initial setup. + */ +void writerequest(page, fp_out) - int page; /* write everything for this page */ FILE *fp_out; /* to this file */ - { - int i; /* loop index */ -/* - * - * Writes out all the requests that have been saved for page. Page 0 refers to - * the global environment and is done during initial setup. - * - */ - for ( i = 0; i < nextreq; i++ ) if ( request[i].page == page ) dumprequest(request[i].want, request[i].file, fp_out); - -} /* End of writerequest */ - -/*****************************************************************************/ - -dumprequest(want, file, fp_out) - - char *want; /* look for this string */ - char *file; /* in this file */ - FILE *fp_out; /* and write the value out here */ - -{ - - char buf[100]; /* line buffer for reading *file */ - FILE *fp_in; +} /* - * * Looks for *want in the request file and if it's found the associated value * is copied to the output file. Keywords (ie. the *want strings) begin an @ in * the first column of file, while the values (ie. the stuff that's copied to * the output file) starts on the next line and extends to the next keyword or * to the end of file. - * */ +void +dumprequest(want, file, fp_out) + char *want; /* look for this string */ + char *file; /* in this file */ + FILE *fp_out; /* and write the value out here */ +{ + char buf[100]; /* line buffer for reading *file */ + FILE *fp_in; if ( (fp_in = fopen(file, "r")) != NULL ) { while ( fgets(buf, sizeof(buf), fp_in) != NULL ) @@ -111,9 +90,5 @@ fprintf(fp_out, "%s", buf); else break; fclose(fp_in); - } /* End if */ - -} /* End of dumprequest */ - -/*****************************************************************************/ - + } +} --- /sys/src/cmd/postscript/common/tempnam.c Sat Aug 1 02:05:10 2009 +++ /sys/src/cmd/postscript/common/tempnam.c Fri Sep 27 00:32:21 2013 @@ -1,7 +1,10 @@ #if defined(V9) || defined(BSD4_2) || defined(plan9) +#define _BSD_EXTENSION + #include #include #include +#include #include #include #include --- /sys/src/cmd/postscript/download/download.c Thu Jun 13 22:54:08 2013 +++ /sys/src/cmd/postscript/download/download.c Fri Sep 27 01:34:32 2013 @@ -50,6 +50,8 @@ * be a more general program (e.g. scan for other comments). */ +#define _BSD_EXTENSION + #include #include #include @@ -83,15 +85,20 @@ FILE *fp_in = stdin; /* next input file */ FILE *fp_temp = NULL; /* for copying stdin */ -/*****************************************************************************/ +void arguments(void); +void copyfonts(char *); +void copyinput(void); +void done(void); +void download(void); +void init_signals(void); +void options(void); +void readmap(void); +void readresident(void); main(agc, agv) - int agc; char *agv[]; - { - /* * * Host resident font downloader. The input files are assumed to be part of a @@ -111,19 +118,14 @@ arguments(); /* then process non-option arguments */ done(); /* and clean things up */ exit(x_stat); /* not much could be wrong */ + return 0; +} -} /* End of main */ - -/*****************************************************************************/ - -init_signals() - +void +init_signals(void) { - /* - * * Makes sure we handle interrupts properly. - * */ if ( signal(SIGINT, interrupt) == SIG_IGN ) { @@ -133,18 +135,14 @@ } else { signal(SIGHUP, interrupt); signal(SIGQUIT, interrupt); - } /* End else */ + } signal(SIGTERM, interrupt); +} -} /* End of init_signals */ - -/*****************************************************************************/ - -options() - +void +options(void) { - int ch; /* return value from getopt() */ char *optnames = "c:fm:p:r:H:T:DI"; @@ -207,29 +205,23 @@ argc -= optind; /* get ready for non-option args */ argv += optind; +} -} /* End of options */ - -/*****************************************************************************/ - -readmap() - +void +readmap(void) { - char *path; char *ptr; int fd; struct stat sbuf; /* - * * Initializes the map table by reading an ASCII mapping file. If mapname begins * with a / it's the map table. Otherwise hostfontdir, mapname, and suffix are * combined to build the final pathname. If we can open the file we read it all * into memory, erase comments, and separate the font and file name pairs. When * we leave next points to the next free slot in the map[] array. If it's zero * nothing was in the file or we couldn't open it. - * */ if ( hostfontdir == NULL || mapname == NULL ) @@ -268,29 +260,23 @@ break; if ( map[next].file == NULL ) error(FATAL, "map table format error - check %s", path); - } /* End for */ - } /* End if */ - -} /* End of readmap */ - -/*****************************************************************************/ - -readresident() + } + } +} +void +readresident(void) { - FILE *fp; char *path; int ch; int n; /* - * * Reads a file that lists the resident fonts for a particular printer and marks * each font as already downloaded. Nothing's done if the file can't be read or * there's no mapping file. Comments, as in the map file, begin with a % and * extend to the end of the line. Added for Unix 4.0 lp. - * */ if ( next == 0 || (printer == NULL && residentfonts == NULL) ) @@ -308,16 +294,12 @@ else if ( (n = lookup(buf)) < next ) map[n].downloaded = TRUE; fclose(fp); - } /* End if */ - -} /* End of readresident */ - -/*****************************************************************************/ - -arguments() + } +} +void +arguments(void) { - /* * * Makes sure all the non-option command line arguments are processed. If we get @@ -343,34 +325,23 @@ fclose(fp_temp); argc--; argv++; - } /* End while */ - } /* End else */ - -} /* End of arguments */ - -/*****************************************************************************/ - -done() + } + } +} +void +done(void) { - /* - * * Clean things up before we quit. - * */ - if ( temp_file != NULL ) unlink(temp_file); +} -} /* End of done */ - -/*****************************************************************************/ - -download() - +void +download(void) { - int infontlist = FALSE; /* @@ -407,32 +378,24 @@ } else if ( buf[2] == '+' && infontlist == TRUE ) copyfonts(buf); else infontlist = FALSE; - } /* End while */ - } /* End if */ - + } + } copyinput(); +} -} /* End of download */ - -/*****************************************************************************/ - +void copyfonts(list) - char *list; - { - char *font; char *path; int n; /* - * * list points to a %%DocumentFonts: or continuation comment. What follows the * the keyword will be a list of fonts separated by white space (or (atend)). * Look for each font in the map table and if it's found copy the font file to * stdout (once only). - * */ strtok(list, " \n"); /* skip to the font list */ @@ -441,7 +404,7 @@ if ( strcmp(font, ATEND) == 0 ) { atend = TRUE; break; - } /* End if */ + } if ( (n = lookup(font)) < next ) { if ( *map[n].file != '/' ) { if ( (path = malloc(strlen(hostfontdir)+strlen(map[n].file)+2)) == NULL ) @@ -451,17 +414,13 @@ free(path); } else cat(map[n].file); map[n].downloaded = TRUE; - } /* End if */ - } /* End while */ - -} /* End of copyfonts */ - -/*****************************************************************************/ - -copyinput() + } + } +} +void +copyinput(void) { - /* * * Copies the input file to stdout. If fp_temp isn't NULL seek to the start and @@ -481,17 +440,11 @@ while ( fgets(buf, sizeof(buf), fp_in) != NULL ) printf("%s", buf); - -} /* End of copyinput */ - -/*****************************************************************************/ +} lookup(font) - char *font; - { - int i; /* --- /sys/src/cmd/postscript/download/mkfile Sat Mar 18 02:57:08 2000 +++ /sys/src/cmd/postscript/download/mkfile Fri Sep 27 01:34:32 2013 @@ -19,7 +19,7 @@ 74) { Bprint(ioutb, "\n"); lsf = 0; @@ -705,7 +705,7 @@ cmap2ascii85(foo, c85); if (strcmp((char *)c85, "z") == 0 ) strcpy((char *)c85, "!!!!!"); - Bprint(ioutb, "%.*s", nrest+1, c85); + Bprint(ioutb, "%.*s", nrest+1, (char *)c85); } Bprint(ioutb, "\n~>"); Bprint(ioutb, "\n"); --- /sys/src/cmd/postscript/postprint/postprint.c Sun Dec 12 02:11:08 1999 +++ /sys/src/cmd/postscript/postprint/postprint.c Fri Sep 27 01:34:21 2013 @@ -1,5 +1,4 @@ /* - * * postprint - PostScript translator for ASCII files. * * A simple program that translates ASCII files into PostScript. All it really @@ -75,10 +74,11 @@ * The -P option passes arbitrary PostScript through to the output file. Among * other things it can be used to set (or change) values that can't be accessed by * other options. - * */ #include +#include +#include #include #include #ifdef plan9 --- /sys/src/cmd/postscript/postreverse/postreverse.c Sun Dec 12 02:11:09 1999 +++ /sys/src/cmd/postscript/postreverse/postreverse.c Fri Sep 27 02:40:19 2013 @@ -1,5 +1,4 @@ /* - * * postreverse - reverse the page order in certain PostScript files. * * Page reversal relies on being able to locate sections of a document using file @@ -67,10 +66,15 @@ * then processes that file. That means the input is read three times (rather than * two) whenever we handle stdin. That's expensive, and shouldn't be too difficult * to fix, but I haven't gotten around to it yet. - * */ +#define _BSD_EXTENSION +#define _POSIX_SOURCE + #include +#include +#include +#include #include #include #include @@ -101,23 +105,16 @@ FILE *fp_in; /* stuff is read from this file */ FILE *fp_out = stdout; /* and written here */ -/*****************************************************************************/ - main(agc, agv) - int agc; char *agv[]; - { - /* - * * A simple program that reverses the pages in specially formatted PostScript * files. Will work with all the translators in this package, and should handle * any document that conforms to Adobe's version 1.0 or 2.0 file structuring * conventions. Only one input file is allowed, and it can either be a named (on * the command line) file or stdin. - * */ argc = agc; /* other routines may want them */ @@ -131,19 +128,13 @@ done(); /* and clean things up */ exit(x_stat); /* not much could be wrong */ - -} /* End of main */ - -/*****************************************************************************/ + return 0; +} init_signals() - { - /* - * * Makes sure we handle interrupts properly. - * */ if ( signal(SIGINT, interrupt) == SIG_IGN ) { @@ -153,18 +144,13 @@ } else { signal(SIGHUP, interrupt); signal(SIGQUIT, interrupt); - } /* End else */ + } signal(SIGTERM, interrupt); - -} /* End of init_signals */ - -/*****************************************************************************/ +} options() - { - int ch; /* return value from getopt() */ char *optnames = "n:o:rvT:DI"; --- /sys/src/cmd/postscript/tcpostio/dial.c Wed Feb 9 14:55:57 2000 +++ /sys/src/cmd/postscript/tcpostio/dial.c Fri Sep 27 01:49:30 2013 @@ -1,5 +1,11 @@ +#define _BSD_EXTENSION +#define _NET_EXTENSION +#define _POSIX_SOURCE + #include #include +#include +#include #include #include #include --- /sys/src/cmd/postscript/tcpostio/mkfile Sat Mar 18 02:58:19 2000 +++ /sys/src/cmd/postscript/tcpostio/mkfile Fri Sep 27 01:49:24 2013 @@ -10,7 +10,7 @@ syms --- /sys/src/cmd/postscript/tcpostio/tcpostio.c Sat Feb 12 01:35:06 2000 +++ /sys/src/cmd/postscript/tcpostio/tcpostio.c Fri Sep 27 01:52:56 2013 @@ -1,20 +1,23 @@ +#define _BSD_EXTENSION +#define _NET_EXTENSION +#define _POSIX_SOURCE + #include #include - -#ifdef plan9 -#include -#endif - +#include +#include #include +#include #include #include +#include #include #include - #include +#include extern int dial_debug; -extern int dial(char*, char*, char*, int*); +extern int dial(char*, char*, char*, int*); /* debug = 0 for no debugging */ @@ -346,7 +349,7 @@ if (n > 0) { fprintf(stderr, "more fds selected than requested!\n"); exit(1); - }; + }; } while ((progstate != FATAL_ERROR) && (progstate != OVER_AND_OUT)); if (progstate == FATAL_ERROR) @@ -361,7 +364,7 @@ unsigned char proto; int progstate = START; int i, n, nfds; - int bytesread, bytesent = 0; + int bytesread, bytesent = 0; nfds = ((pipefd>printerfd)?pipefd:printerfd) + 1; @@ -463,10 +466,10 @@ void main(int argc, char *argv[]) { int c, usgflg=0, infd, printerfd; - int cpid; + int cpid, sprv; int pipefd[2]; char *dialstr; - unsigned long rprv, sprv; + unsigned long rprv; dialstr = 0; @@ -484,14 +487,15 @@ case '?': fprintf(stderr, "unknown option %c\n", c); usgflg++; + break; } if (optind < argc) dialstr = argv[optind++]; - else { + else usgflg++; - } if (usgflg) { - fprintf(stderr, "usage: %s [-b baudrate] net!host!service [infile]\n", argv[0]); + fprintf(stderr, "usage: %s [-b baudrate] net!host!service [infile]\n", + argv[0]); exit (2); } if (optind < argc) { @@ -504,10 +508,13 @@ } else infd = 0; - if (debug & 02) fprintf(stderr, "blocksize=%d\n", blocksize); - if (debug) fprintf(stderr, "dialing address=%s\n", dialstr); + if (debug & 02) + fprintf(stderr, "blocksize=%d\n", blocksize); + if (debug) + fprintf(stderr, "dialing address=%s\n", dialstr); printerfd = dial(dialstr, 0, 0, 0); - if (printerfd < 0) exit(1); + if (printerfd < 0) + exit(1); fprintf(stderr, "printer startup\n"); @@ -519,16 +526,19 @@ case -1: perror("fork error"); exit(1); - case 0: + case 0: /* child - to printer */ close(pipefd[1]); - sprv = sendfile(infd, printerfd, pipefd[0]); /* child - to printer */ - if (debug) fprintf(stderr, "to remote - exiting\n"); + sprv = sendfile(infd, printerfd, pipefd[0]); + if (debug) + fprintf(stderr, "to remote - exiting\n"); exit(sprv); - default: + default: /* parent - from printer */ close(pipefd[0]); - rprv = readprinter(printerfd, pipefd[1]); /* parent - from printer */ - if (debug) fprintf(stderr, "from remote - exiting\n"); - while(wait(&sprv) != cpid); + rprv = readprinter(printerfd, pipefd[1]); + if (debug) + fprintf(stderr, "from remote - exiting\n"); + while(wait(&sprv) != cpid) + ; exit(rprv|sprv); } } --- /sys/src/cmd/postscript/text2post/mkfile Tue Jul 7 19:03:03 2009 +++ /sys/src/cmd/postscript/text2post/mkfile Thu Sep 26 01:03:01 2013 @@ -14,7 +14,7 @@ BIN=$POSTBIN Biobufhdr); - if ((bfile = Bopen(filename, OREAD)) == 0) { + if ((bfile = Bopen(filename, OREAD)) == nil) return(1); - } - Bfile = &(bfile->Biobufhdr); - while ((n=Bread(Bfile, buf, Bsize)) > 0) { - if (Bwrite(Bstdout, buf, n) != n) { - return(1); - } - } - if (n != 0) { + while ((n = Bread(bfile, buf, Bsize)) > 0) + if (Bwrite(bout, buf, n) != n) + break; + Bterm(bfile); + if (n != 0) return(1); - } return(0); } @@ -183,16 +174,14 @@ char *ts; int tabstop; - Bprint(Bstdout, "%s", CONFORMING); - Bprint(Bstdout, "%s %s\n", VERSION, PROGRAMVERSION); - Bprint(Bstdout, "%s %s\n", DOCUMENTFONTS, ATEND); - Bprint(Bstdout, "%s %s\n", PAGES, ATEND); - Bprint(Bstdout, "%s", ENDCOMMENTS); - - if (cat(POSTPRINT)) { - Bprint(Bstderr, "can't read %s", POSTPRINT); - exits("prologue"); - } + Bprint(bout, "%s", CONFORMING); + Bprint(bout, "%s %s\n", VERSION, PROGRAMVERSION); + Bprint(bout, "%s %s\n", DOCUMENTFONTS, ATEND); + Bprint(bout, "%s %s\n", PAGES, ATEND); + Bprint(bout, "%s", ENDCOMMENTS); + + if (cat(POSTPRINT)) + sysfatal("can't read %s: %r", POSTPRINT); if (DOROUND) cat(ROUNDPAGE); @@ -203,45 +192,46 @@ tabstop = strtol(ts, nil, 0); if(tabstop == 0) tabstop = 8; - Bprint(Bstdout, "/f {findfont pointsize scalefont setfont} bind def\n"); - Bprint(Bstdout, "/tabwidth /Courier f ("); + Bprint(bout, "/f {findfont pointsize scalefont setfont} bind def\n"); + Bprint(bout, "/tabwidth /Courier f ("); while(tabstop--) - Bputc(Bstdout, 'n'); - Bprint(Bstdout, ") stringwidth pop def\n"); - Bprint(Bstdout, "/tab {tabwidth 0 ne {currentpoint 3 1 roll exch tabwidth mul add tabwidth\n"); - Bprint(Bstdout, "\tdiv truncate tabwidth mul exch moveto} if} bind def\n"); - Bprint(Bstdout, "/spacewidth /%s f ( ) stringwidth pop def\n", fontname[0].str); - Bprint(Bstdout, "/sp {spacewidth mul 0 rmoveto} bind def\n"); - Bprint(Bstdout, "%s", ENDPROLOG); - Bprint(Bstdout, "%s", BEGINSETUP); - Bprint(Bstdout, "mark\n"); + Bputc(bout, 'n'); + Bprint(bout, ") stringwidth pop def\n"); + Bprint(bout, "/tab {tabwidth 0 ne {currentpoint 3 1 roll exch tabwidth mul add tabwidth\n"); + Bprint(bout, "\tdiv truncate tabwidth mul exch moveto} if} bind def\n"); + Bprint(bout, "/spacewidth /%s f ( ) stringwidth pop def\n", fontname[0].str); + Bprint(bout, "/sp {spacewidth mul 0 rmoveto} bind def\n"); + Bprint(bout, "%s", ENDPROLOG); + Bprint(bout, "%s", BEGINSETUP); + Bprint(bout, "mark\n"); if (formsperpage > 1) { - Bprint(Bstdout, "%s %d\n", FORMSPERPAGE, formsperpage); - Bprint(Bstdout, "/formsperpage %d def\n", formsperpage); + Bprint(bout, "%s %d\n", FORMSPERPAGE, formsperpage); + Bprint(bout, "/formsperpage %d def\n", formsperpage); } - if (aspectratio != 1) Bprint(Bstdout, "/aspectratio %g def\n", aspectratio); - if (copies != 1) Bprint(Bstdout, "/#copies %d store\n", copies); - if (landscape) Bprint(Bstdout, "/landscape true def\n"); - if (magnification != 1) Bprint(Bstdout, "/magnification %s def\n", magnification); - if (pointsize != 10) Bprint(Bstdout, "/pointsize %d def\n", pointsize); - if (xoffset != .25) Bprint(Bstdout, "/xoffset %g def\n", xoffset); - if (yoffset != .25) Bprint(Bstdout, "/yoffset %g def\n", yoffset); + if (aspectratio != 1) Bprint(bout, "/aspectratio %g def\n", aspectratio); + if (copies != 1) Bprint(bout, "/#copies %d store\n", copies); + if (landscape) Bprint(bout, "/landscape true def\n"); + if (magnification != 1) Bprint(bout, "/magnification %g def\n", magnification); + if (pointsize != 10) Bprint(bout, "/pointsize %d def\n", pointsize); + if (xoffset != .25) Bprint(bout, "/xoffset %g def\n", xoffset); + if (yoffset != .25) Bprint(bout, "/yoffset %g def\n", yoffset); cat(ENCODINGDIR"/Latin1.enc"); - if (passthrough != 0) Bprint(Bstdout, "%s\n", passthrough); - Bprint(Bstdout, "setup\n"); + if (passthrough != 0) Bprint(bout, "%s\n", passthrough); + Bprint(bout, "setup\n"); if (formsperpage > 1) { cat(FORMFILE); - Bprint(Bstdout, "%d setupforms \n", formsperpage); + Bprint(bout, "%d setupforms \n", formsperpage); } if (cat(UNKNOWNCHAR)) - Bprint(Bstderr, "cannot open %s\n", UNKNOWNCHAR); - Bprint(Bstdout, "%s", ENDSETUP); + fprint(2, "cannot open %s: %r\n", UNKNOWNCHAR); + Bprint(bout, "%s", ENDSETUP); } int pageon(void) { - if (pplist == 0 && page_no != 0) return(1); /* no page list, print all pages */ + if (pplist == 0 && page_no != 0) + return(1); /* no page list, print all pages */ if (page_no/8 < pplistmaxsize && (pplist[page_no/8] & 1<<(page_no%8))) return(1); else @@ -255,10 +245,10 @@ ++page_no; if (pageon()) { ++pages_printed; - Bprint(Bstdout, "%s %d %d\n", PAGE, page_no, pages_printed); - Bprint(Bstdout, "/saveobj save def\n"); - Bprint(Bstdout, "mark\n"); - Bprint(Bstdout, "%d pagesetup\n", pages_printed); + Bprint(bout, "%s %d %d\n", PAGE, page_no, pages_printed); + Bprint(bout, "/saveobj save def\n"); + Bprint(bout, "mark\n"); + Bprint(bout, "%d pagesetup\n", pages_printed); } } @@ -267,17 +257,17 @@ line_no = 0; char_no = 0; if (pageon()) { - Bprint(Bstdout, "cleartomark\n"); - Bprint(Bstdout, "showpage\n"); - Bprint(Bstdout, "saveobj restore\n"); - Bprint(Bstdout, "%s %d %d\n", ENDPAGE, page_no, pages_printed); + Bprint(bout, "cleartomark\n"); + Bprint(bout, "showpage\n"); + Bprint(bout, "saveobj restore\n"); + Bprint(bout, "%s %d %d\n", ENDPAGE, page_no, pages_printed); } } void startstring(void) { if (!in_string) { - if (pageon()) Bprint(Bstdout, "("); + if (pageon()) Bprint(bout, "("); in_string = 1; } } @@ -285,7 +275,7 @@ void endstring(void) { if (in_string) { - if (pageon()) Bprint(Bstdout, ") show "); + if (pageon()) Bprint(bout, ") show "); in_string = 0; } } @@ -294,7 +284,7 @@ prspace(void) { if (spaces) { endstring(); - if (pageon()) Bprint(Bstdout, "%d sp ", spaces); + if (pageon()) Bprint(bout, "%d sp ", spaces); spaces = 0; } } @@ -303,7 +293,7 @@ prtab(void) { if (tabs) { endstring(); - if (pageon()) Bprint(Bstdout, "%d tab ", tabs); + if (pageon()) Bprint(bout, "%d tab ", tabs); tabs = 0; } } @@ -321,7 +311,7 @@ page_no = 0; spaces = 0; fontname[0].used++; - while ((r=Bgetrune(Bstdin)) >= 0) { + while ((r = Bgetrune(bin)) >= 0) { thischar = r & 0xff; thisfont = (r>>8) & 0xff; @@ -329,7 +319,7 @@ startpage(); if (line_no == 1 && char_no == 1) { - if (pageon()) Bprint(Bstdout, " /%s f\n", fontname[thisfont].str); + if (pageon()) Bprint(bout, " /%s f\n", fontname[thisfont].str); lastfont = thisfont; } @@ -344,14 +334,13 @@ case '\n': case '\f': startstring(); - if (pageon()) Bprint(Bstdout, ")l\n"); + if (pageon()) Bprint(bout, ")l\n"); char_no = 1; in_string = 0; spaces = 0; tabs = 0; - if (++line_no > linesperpage || r == '\f') { + if (++line_no > linesperpage || r == '\f') endpage(); - } lastchar = -1; continue; case '\t': @@ -364,7 +353,7 @@ /* just toss out backspaces for now */ if (lastchar != -1) { endstring(); - if (pageon()) Bprint(Bstdout, "(%s) stringwidth pop neg 0 rmoveto ", charcode[lastchar].str); + if (pageon()) Bprint(bout, "(%s) stringwidth pop neg 0 rmoveto ", charcode[lastchar].str); } char_no++; lastchar = -1; @@ -376,7 +365,7 @@ prspace(); prtab(); endstring(); - Bprint(Bstdout, "pw "); + Bprint(bout, "pw "); char_no++; lastchar = -1; continue; @@ -385,24 +374,24 @@ if (thisfont != lastfont) { endstring(); if (pageon()) { - Bprint(Bstdout, "/%s f\n", fontname[thisfont].str); + Bprint(bout, "/%s f\n", fontname[thisfont].str); } fontname[thisfont].used++; } prspace(); prtab(); startstring(); - if (pageon()) Bprint(Bstdout, "%s", charcode[thischar].str); -/* if (pageon()) Bprint(Bstdout, "%2.2x", thischar); /* try hex strings*/ + if (pageon()) Bprint(bout, "%s", charcode[thischar].str); +/* if (pageon()) Bprint(bout, "%2.2x", thischar); /* try hex strings*/ char_no++; lastchar = thischar; lastfont = thisfont; } if (line_no != 0 || char_no != 0) { if (char_no != 1) { - Bprint(Bstderr, "premature EOF: newline appended\n"); + fprint(2, "premature EOF: newline appended\n"); startstring(); - if (pageon()) Bprint(Bstdout, ")l\n"); + if (pageon()) Bprint(bout, ")l\n"); } endpage(); } @@ -411,10 +400,12 @@ void pagelist(char *list) { char c; - int n, m; - int state, start, end; + int n, state, start; + unsigned m; - if (list == 0) return; + if (list == 0) + return; + start = 0; state = 1; while ((c=*list) != '\0') { n = 0; @@ -425,13 +416,12 @@ switch (state) { case 1: start = n; + /* fall through */ case 2: if (n/8+1 > pplistmaxsize) { pplistmaxsize = n/8+1; - if ((pplist = realloc(pplist, n/8+1)) == 0) { - Bprint(Bstderr, "cannot allocate memory for page list\n"); - exits("malloc"); - } + if ((pplist = realloc(pplist, n/8+1)) == 0) + sysfatal("malloc"); } for (m=start; m<=n; m++) pplist[m/8] |= 1<<(m%8); @@ -456,110 +446,95 @@ finish(void) { int i; - Bprint(Bstdout, "%s", TRAILER); - Bprint(Bstdout, "done\n"); - Bprint(Bstdout, "%s", DOCUMENTFONTS); + Bprint(bout, "%s", TRAILER); + Bprint(bout, "done\n"); + Bprint(bout, "%s", DOCUMENTFONTS); for (i=0; iBiobufhdr); - - if ((bstdout = (Biobuf *)malloc(sizeof(Biobuf))) == nil) - exits("malloc"); - if (Binit(bstdout, 1, OWRITE) == Beof) - exits("Binit"); - Bstdout = &(bstdout->Biobufhdr); + bin = &inbuf; + bout = &outbuf; + if (Binit(bout, 1, OWRITE) == Beof) + sysfatal("Binit"); ARGBEGIN{ - case 'a': /* aspect ratio */ - aspectratio = atof(ARGF()); - break; - case 'c': /* copies */ - copies = atoi(ARGF()); - break; - case 'f': /* primary font, for now */ - t = ARGF(); - fontname[0].str = malloc(strlen(t)+1); - strcpy(fontname[0].str, t); - break; - case 'l': /* lines per page */ - linesperpage = atoi(ARGF()); - break; - case 'm': /* magnification */ - magnification = atof(ARGF()); - break; - case 'n': /* forms per page */ - formsperpage = atoi(ARGF()); - break; - case 'o': /* output page list */ - pagelist(ARGF()); - break; - case 'p': /* landscape or portrait mode */ - if ( ARGF()[0] == 'l' ) - landscape = 1; - else - landscape = 0; - break; - case 's': /* point size */ - pointsize = atoi(ARGF()); - break; - case 'x': /* shift things horizontally */ - xoffset = atof(ARGF()); - break; - - case 'y': /* and vertically on the page */ - yoffset = atof(ARGF()); - break; - case 'P': /* PostScript pass through */ - t = ARGF(); - i = strlen(t) + 1; - passthrough = malloc(i); - if (passthrough == 0) { - Bprint(Bstderr, "cannot allocate memory for argument string\n"); - exits("malloc"); - } - strncpy(passthrough, t, i); - break; - default: /* don't know what to do for ch */ - Bprint(Bstderr, "unknown option %C\n", ARGC()); - break; + case 'a': /* aspect ratio */ + aspectratio = atof(ARGF()); + break; + case 'c': /* copies */ + copies = atoi(ARGF()); + break; + case 'f': /* primary font, for now */ + t = ARGF(); + fontname[0].str = malloc(strlen(t)+1); + strcpy(fontname[0].str, t); + break; + case 'l': /* lines per page */ + linesperpage = atoi(ARGF()); + break; + case 'm': /* magnification */ + magnification = atof(ARGF()); + break; + case 'n': /* forms per page */ + formsperpage = atoi(ARGF()); + break; + case 'o': /* output page list */ + pagelist(ARGF()); + break; + case 'p': /* landscape or portrait mode */ + if ( ARGF()[0] == 'l' ) + landscape = 1; + else + landscape = 0; + break; + case 's': /* point size */ + pointsize = atoi(ARGF()); + break; + case 'x': /* shift things horizontally */ + xoffset = atof(ARGF()); + break; + + case 'y': /* and vertically on the page */ + yoffset = atof(ARGF()); + break; + case 'P': /* PostScript pass through */ + t = ARGF(); + i = strlen(t) + 1; + passthrough = malloc(i); + if (passthrough == 0) + sysfatal("malloc"); + strncpy(passthrough, t, i); + break; + default: + fprint(2, "unknown option %C\n", ARGC()); + break; }ARGEND; + prologues(); if (argc <= 0) { - if ((bstdin = (Biobuf *)malloc(sizeof(Biobuf))) == nil) - exits("malloc"); - if (Binit(bstdin, 0, OREAD) == Beof) { - fprint(2, "cannot Binit stdin\n"); - exits("Binit"); - } - Bstdin = &(bstdin->Biobufhdr); + if (Binit(bin, 0, OREAD) == Beof) + sysfatal("cannot Binit stdin"); txt2post(); } for (i=0; iBiobufhdr); txt2post(); + Bterm(bin); } finish(); exits(""); --- /sys/src/cmd/postscript/tr2post/Bgetfield.c Sun Dec 12 02:11:12 1999 +++ /sys/src/cmd/postscript/tr2post/Bgetfield.c Thu Sep 26 01:42:21 2013 @@ -7,45 +7,47 @@ int isspace(Rune r) { - return(r==' ' || r=='\t' || r=='\n' || r == '\r' || r=='\f'); + return r==' ' || r=='\t' || r=='\n' || r=='\r' || r=='\f'; } int Bskipws(Biobufhdr *bp) { - int r; - char c[UTFmax]; - int sindex = 0; + int r, sindex = 0; /* skip over initial white space */ do { r = Bgetrune(bp); - if (r == '\n') inputlineno++; - sindex++; + if (r == '\n') + inputlineno++; + sindex++; } while (r>=0 && isspace(r)); - if (r<0) { + if (r<0) return(-1); - } else if (!isspace(r)) { + else if (!isspace(r)) { Bungetrune(bp); --sindex; } - return(sindex); + return sindex; } int asc2dig(char c, int base) { if (c >= '0' && c <= '9') - if (base == 8 && c > '7') return(-1); - else return(c - '0'); - + if (base == 8 && c > '7') + return(-1); + else + return(c - '0'); if (base == 16) - if (c >= 'a' && c <= 'f') return(10 + c - 'a'); - else if (c >= 'A' && c <= 'F') return(10 + c - 'A'); - + if (c >= 'a' && c <= 'f') + return(10 + c - 'a'); + else if (c >= 'A' && c <= 'F') + return(10 + c - 'A'); return(-1); } -/* get a string of type: "d" for decimal integer, "u" for unsigned, - * "s" for string", "c" for char, +/* + * get a string of type: "d" for decimal integer, "u" for unsigned, + * "s" for string", "c" for char, * return the number of characters gotten for the field. If nothing * was gotten and the end of file was reached, a negative value * from the Bgetrune is returned. @@ -53,20 +55,21 @@ int Bgetfield(Biobufhdr *bp, int type, void *thing, int size) { - int r; - Rune R; - char c[UTFmax]; - int sindex = 0, i, j, n = 0; - int negate = 0; int base = 10; - BOOLEAN bailout = FALSE; int dig; - unsigned int u = 0; + int negate = 0; + int sindex = 0, i, j, n = 0; + long r; + Rune R; + unsigned u = 0; + BOOLEAN bailout = FALSE; + char c[UTFmax]; /* skip over initial white space */ if (Bskipws(bp) < 0) return(-1); + r = 0; switch (type) { case 'd': while (!bailout && (r = Bgetrune(bp))>=0) { @@ -81,7 +84,7 @@ case '0': base = 8; continue; - default: + default: break; } break; @@ -90,11 +93,15 @@ base = 16; continue; } + break; } - if ((dig = asc2dig(r, base)) == -1) bailout = TRUE; - else n = dig + (n * base); + if ((dig = asc2dig(r, base)) == -1) + bailout = TRUE; + else + n = dig + (n * base); } - if (r < 0) return(-1); + if (r < 0) + return(-1); *(int *)thing = (negate)?-n:n; Bungetrune(bp); break; @@ -112,24 +119,30 @@ base = 16; continue; } + break; } - if ((dig = asc2dig(r, base)) == -1) bailout = TRUE; - else u = dig + (n * base); + if ((dig = asc2dig(r, base)) == -1) + bailout = TRUE; + else + u = dig + (n * base); } *(int *)thing = u; - if (r < 0) return(-1); + if (r < 0) + return(-1); Bungetrune(bp); break; case 's': j = 0; - while ((size>j+UTFmax) && (r = Bgetrune(bp))>=0 && !isspace(r)) { + while (size > j+UTFmax && (r = Bgetrune(bp)) >= 0 && + !isspace(r)) { R = r; i = runetochar(&(((char *)thing)[j]), &R); j += i; sindex++; } - ((char *)thing)[j++] = '\0'; - if (r < 0) return(-1); + ((char *)thing)[j] = '\0'; + if (r < 0) + return(-1); Bungetrune(bp); break; case 'r': @@ -138,7 +151,8 @@ sindex++; return(sindex); } - if (r <= 0) return(-1); + if (r <= 0) + return(-1); Bungetrune(bp); break; default: --- /sys/src/cmd/postscript/tr2post/chartab.c Thu Jan 13 23:20:32 2000 +++ /sys/src/cmd/postscript/tr2post/chartab.c Thu Sep 26 02:12:09 2013 @@ -39,7 +39,7 @@ mountfont(int pos, char *fontname) { int i; - if (debug) Bprint(Bstderr, "mountfont(%d, %s)\n", pos, fontname); + if (debug) fprint(2, "mountfont(%d, %s)\n", pos, fontname); if (pos < 0 || pos >= fontmnt) error(FATAL, "cannot mount a font at position %d,\n can only mount into postions 0-%d\n", pos, fontmnt-1); @@ -58,7 +58,7 @@ error(FATAL, "Font at position %d was not initialized, botch!\n", fontpos); curtrofffontid = findtfn(fontmtab[fontpos], 1); - if (debug) Bprint(Bstderr, "settrfont()-> curtrofffontid=%d\n", curtrofffontid); + if (debug) fprint(2, "settrfont()-> curtrofffontid=%d\n", curtrofffontid); curfontpos = fontpos; if (curtrofffontid < 0) { int i; @@ -120,23 +120,23 @@ return(-1); } -char postroffdirname[] = "/sys/lib/postscript/troff"; /* "/sys/lib/postscript/troff/"; */ -char troffmetricdirname[] = "/sys/lib/troff/font"; /* "/sys/lib/troff/font/devutf/"; */ +char postroffdirname[] = "/sys/lib/postscript/troff"; /* "/sys/lib/postscript/troff/"; */ +char troffmetricdirname[] = "/sys/lib/troff/font"; /* "/sys/lib/troff/font/devutf/"; */ int readpsfontdesc(char *fontname, int trindex) { - static char *filename = 0; - Biobuf *bfd; - Biobufhdr *Bfd; - int warn = 0, errorflg = 0, line =1, rv; - int start, end, offset; + int errorflg = 0, line = 1, rv, start, end, offset; int startfont, endfont, startchar, endchar, i, pfid; char psfontnam[128]; struct troffont *tp; - struct charent *cp[]; + Biobuf *bfd; + Biobufhdr *Bfd; + static char *filename = 0; - if (debug) Bprint(Bstderr, "readpsfontdesc(%s,%d)\n", fontname, trindex); - filename=galloc(filename, strlen(postroffdirname)+1+strlen(fontname)+1, "readpsfontdesc: cannot allocate memory\n"); + if (debug) + fprint(2, "readpsfontdesc(%s,%d)\n", fontname, trindex); + filename = galloc(filename, strlen(postroffdirname)+1+strlen(fontname)+1, + "readpsfontdesc: cannot allocate memory\n"); sprint(filename, "%s/%s", postroffdirname, fontname); bfd = Bopen(filename, OREAD); @@ -144,7 +144,7 @@ error(WARNING, "cannot open file %s\n", filename); return(0); } - Bfd = &(bfd->Biobufhdr); + Bfd = &bfd->Biobufhdr; do { offset = 0; @@ -156,14 +156,15 @@ errorflg = 1; error(WARNING, "file %s:%d illegal end value\n", filename, line); } else if (rv < 0) break; - if ((rv=Bgetfield(Bfd, 'd', &offset, 0)) < 0) { + if (Bgetfield(Bfd, 'd', &offset, 0) < 0) { errorflg = 1; error(WARNING, "file %s:%d illegal offset value\n", filename, line); } if ((rv=Bgetfield(Bfd, 's', psfontnam, 128)) == 0) { errorflg = 1; error(WARNING, "file %s:%d illegal fontname value\n", filename, line); - } else if (rv < 0) break; + } else if (rv < 0) + break; Brdline(Bfd, '\n'); if (!errorflg) { struct psfent *psfentp; @@ -174,22 +175,25 @@ pfid = findpfn(psfontnam, 1); if (startfont != endfont) { error(WARNING, "font descriptions must not cross 256 glyph block boundary\n"); - errorflg = 1; break; } - tp = &(troffontab[trindex]); - tp->psfmap = galloc(tp->psfmap, ++(tp->psfmapsize)*sizeof(struct psfent), "readpsfontdesc():psfmap"); + tp = &troffontab[trindex]; + tp->psfmap = galloc(tp->psfmap, ++tp->psfmapsize * + sizeof(struct psfent), + "readpsfontdesc():psfmap"); psfentp = &(tp->psfmap[tp->psfmapsize-1]); psfentp->start = start; psfentp->end = end; psfentp->offset = offset; psfentp->psftid = pfid; if (debug) { - Bprint(Bstderr, "\tpsfmap->start=0x%x\n", start); - Bprint(Bstderr, "\tpsfmap->end=0x%x\n", end); - Bprint(Bstderr, "\tpsfmap->offset=0x%x\n", offset); - Bprint(Bstderr, "\tpsfmap->pfid=0x%x\n", pfid); + fprint(2, "\tpsfmap->start=0x%x\n", start); + fprint(2, "\tpsfmap->end=0x%x\n", end); + fprint(2, "\tpsfmap->offset=0x%x\n", offset); + fprint(2, "\tpsfmap->pfid=0x%x\n", pfid); } + SET(i); + USED(i, startchar, endchar); /* for (i=startchar; i<=endchar; i++) { tp->charent[startfont][i].postfontid = pfid; @@ -197,9 +201,10 @@ } */ if (debug) { - Bprint(Bstderr, "%x %x ", start, end); - if (offset) Bprint(Bstderr, "%x ", offset); - Bprint(Bstderr, "%s\n", psfontnam); + fprint(2, "%x %x ", start, end); + if (offset) + fprint(2, "%x ", offset); + fprint(2, "%s\n", psfontnam); } line++; } @@ -210,20 +215,21 @@ int readtroffmetric(char *fontname, int trindex) { - static char *filename = 0; + int ntoken, errorflg = 0, line = 1, rv; + int width, flag, charnum, thisfont, thischar; + char stoken[128], *str; + struct charent **cp; + BOOLEAN specharflag; Biobuf *bfd; Biobufhdr *Bfd; - int warn = 0, errorflg = 0, line =1, rv; - struct troffont *tp; - struct charent **cp; - char stoken[128], *str; - int ntoken; Rune troffchar, quote; - int width, flag, charnum, thisfont, thischar; - BOOLEAN specharflag; + static char *filename = 0; - if (debug) Bprint(Bstderr, "readtroffmetric(%s,%d)\n", fontname, trindex); - filename=galloc(filename, strlen(troffmetricdirname)+4+strlen(devname)+1+strlen(fontname)+1, "readtroffmetric():filename"); + if (debug) + fprint(2, "readtroffmetric(%s,%d)\n", fontname, trindex); + filename = galloc(filename, strlen(troffmetricdirname) + 4 + + strlen(devname) + 1 + strlen(fontname) + 1, + "readtroffmetric():filename"); sprint(filename, "%s/dev%s/%s", troffmetricdirname, devname, fontname); bfd = Bopen(filename, OREAD); @@ -231,18 +237,19 @@ error(WARNING, "cannot open file %s\n", filename); return(0); } - Bfd = &(bfd->Biobufhdr); + Bfd = &bfd->Biobufhdr; do { - /* deal with the few lines at the beginning of the + /* + * deal with the few lines at the beginning of the * troff font metric files. */ if ((rv=Bgetfield(Bfd, 's', stoken, 128)) == 0) { errorflg = 1; error(WARNING, "file %s:%d illegal token\n", filename, line); - } else if (rv < 0) break; - if (debug) { - Bprint(Bstderr, "%s\n", stoken); - } + } else if (rv < 0) + break; + if (debug) + fprint(2, "%s\n", stoken); if (strcmp(stoken, "name") == 0) { if ((rv=Bgetfield(Bfd, 's', stoken, 128)) == 0) { @@ -271,7 +278,7 @@ if (*cp == 0) *cp = galloc(0, sizeof(struct charent), "readtroffmetric:charent"); (*cp)->postfontid = thisfont; - (*cp)->postcharid = thischar; + (*cp)->postcharid = thischar; (*cp)->troffcharwidth = ntoken; (*cp)->name = galloc(0, 2, "readtroffmetric: char name"); (*cp)->next = 0; @@ -282,7 +289,7 @@ line++; break; } - if (!errorflg) { + if (!errorflg) { line++; } } while(!errorflg && rv>=0); @@ -296,15 +303,14 @@ /* if this character is a quote we have to use the previous characters info */ if ((rv=Bgetfield(Bfd, 'r', "e, 0)) == 0) { errorflg = 1; - error(WARNING, "file %s:%d illegal width or quote token <0x%x> rv=%d\n", filename, line, quote, rv); + error(WARNING, "file %s:%d illegal width or quote token <0x%x> rv=%d\n", + filename, line, quote, rv); } else if (rv < 0) break; if (quote == '"') { /* need some code here */ - goto flush; - } else { + } else Bungetrune(Bfd); - } if ((rv=Bgetfield(Bfd, 'd', &width, 0)) == 0) { errorflg = 1; @@ -317,23 +323,24 @@ if ((rv=Bgetfield(Bfd, 'd', &charnum, 0)) == 0) { errorflg = 1; error(WARNING, "file %s:%d illegal character number token <0x%x> rv=%d\n", filename, line, troffchar, rv); - } else if (rv < 0) break; + } else if (rv < 0) + break; flush: str = Brdline(Bfd, '\n'); /* stash the crap from the end of the line for debugging */ if (debug) { if (str == 0) { - Bprint(Bstderr, "premature EOF\n"); + fprint(2, "premature EOF\n"); return(0); } str[Blinelen(Bfd)-1] = '\0'; } line++; chartorune(&troffchar, stoken); - if (specharflag) { + if (specharflag) if (debug) - Bprint(Bstderr, "%s %d %d 0x%x %s # special\n",stoken, width, flag, charnum, str); - } + fprint(2, "%s %d %d 0x%x %s # special\n", + stoken, width, flag, charnum, str); if (strcmp(stoken, "---") == 0) { thisfont = RUNEGETGROUP(charnum); thischar = RUNEGETCHAR(charnum); @@ -342,25 +349,30 @@ thisfont = RUNEGETGROUP(troffchar); thischar = RUNEGETCHAR(troffchar); } - for (cp = &(troffontab[trindex].charent[thisfont][thischar]); *cp != 0; cp = &((*cp)->next)) + for (cp = &troffontab[trindex].charent[thisfont][thischar]; + *cp != 0; cp = &(*cp)->next) if ((*cp)->name) { - if (debug) Bprint(Bstderr, "installing <%s>, found <%s>\n", stoken, (*cp)->name); + if (debug) + fprint(2, "installing <%s>, found <%s>\n", + stoken, (*cp)->name); if (strcmp((*cp)->name, stoken) == 0) break; } - if (*cp == 0) *cp = galloc(0, sizeof(struct charent), "readtroffmetric:charent"); + if (*cp == 0) + *cp = galloc(0, sizeof(struct charent), + "readtroffmetric:charent"); (*cp)->postfontid = RUNEGETGROUP(charnum); - (*cp)->postcharid = RUNEGETCHAR(charnum); + (*cp)->postcharid = RUNEGETCHAR(charnum); (*cp)->troffcharwidth = width; (*cp)->name = galloc(0, strlen(stoken)+1, "readtroffmetric: char name"); (*cp)->next = 0; strcpy((*cp)->name, stoken); if (debug) { if (specharflag) - Bprint(Bstderr, "%s", stoken); + fprint(2, "%s", stoken); else - Bputrune(Bstderr, troffchar); - Bprint(Bstderr, " %d %d 0x%x %s # psfontid=0x%x pscharid=0x%x thisfont=0x%x thischar=0x%x\n", + fprint(2, "%C", troffchar); + fprint(2, " %d %d 0x%x %s # psfontid=0x%x pscharid=0x%x thisfont=0x%x thischar=0x%x\n", width, flag, charnum, str, (*cp)->postfontid, (*cp)->postcharid, @@ -384,10 +396,8 @@ struct troffont *tp; int i, j; - if (debug) { - if (fontname==0) fprint(2, "findtfn(0x%x,%d)\n", fontname, insflg); - else fprint(2, "findtfn(%s,%d)\n", fontname, insflg); - } + if (debug) + fprint(2, "findtfn(%s,%d)\n", fontname, insflg); for (i=0; i= 0) { -/* Bprint(Bstderr, "r=<%c>,0x%x\n", r, r); */ -/* Bflush(Bstderr); */ switch (r) { case 's': /* set point size */ Bgetfield(Bp, 'd', &fontsize, 0); @@ -95,6 +94,8 @@ } } endpage(); - if (debug) Bprint(Bstderr, "r=0x%x\n", r); - if (debug) Bprint(Bstderr, "leaving conv\n"); + if (debug) { + fprint(2, "r=%#ux\n", r); + fprint(2, "leaving conv\n"); + } } --- /sys/src/cmd/postscript/tr2post/devcntl.c Sat Mar 17 01:33:25 2001 +++ /sys/src/cmd/postscript/tr2post/devcntl.c Thu Sep 26 01:42:03 2013 @@ -48,13 +48,12 @@ {"ExportPS", notavail("ExportPS")}, {NULL, NULL} }; -*/ + */ void devcntl(Biobufhdr *inp) { - char cmd[50], buf[256], str[MAXTOKENSIZE], *line; - int c, n, linelen; + int c, n; /* * @@ -102,16 +101,18 @@ break; case 'T': /* device name */ - Bgetfield(inp, 's', &devname, 16); + Bgetfield(inp, 's', devname, 16); if (debug) Bprint(Bstderr, "devname=%s\n", devname); break; case 'E': /* input encoding - not in troff yet */ - Bgetfield(inp, 's', &str, 100); -/* if ( strcmp(str, "UTF") == 0 ) - reading = UTFENCODING; - else reading = ONEBYTE; - */ + Bgetfield(inp, 's', str, 100); +/* + if (strcmp(str, "UTF") == 0) + reading = UTFENCODING; + else + reading = ONEBYTE; + */ break; case 'X': /* copy through - from troff */ @@ -175,4 +176,3 @@ while ((c = Bgetc(inp)) != '\n' && c != Beof); inputlineno++; } - --- /sys/src/cmd/postscript/tr2post/draw.c Sat Mar 17 01:33:25 2001 +++ /sys/src/cmd/postscript/tr2post/draw.c Thu Sep 26 01:36:20 2013 @@ -6,10 +6,11 @@ #include "tr2post.h" BOOLEAN drawflag = FALSE; -BOOLEAN inpath = FALSE; /* TRUE if we're putting pieces together */ +BOOLEAN inpath = FALSE; /* TRUE if we're putting pieces together */ void cover(double x, double y) { + USED(x, y); } void @@ -17,30 +18,24 @@ int x[100], y[100]; int i, N; /* - * * Spline drawing routine for Postscript printers. The complicated stuff is * handled by procedure Ds, which should be defined in the library file. I've * seen wrong implementations of troff's spline drawing, so fo the record I'll * write down the parametric equations and the necessary conversions to Bezier * cubic splines (as used in Postscript). * - * * Parametric equation (x coordinate only): * - * * (x2 - 2 * x1 + x0) 2 (x0 + x1) * x = ------------------ * t + (x1 - x0) * t + --------- * 2 2 * - * * The coefficients in the Bezier cubic are, * - * * A = 0 * B = (x2 - 2 * x1 + x0) / 2 * C = x1 - x0 * - * * while the current point is, * * current-point = (x0 + x1) / 2 @@ -48,12 +43,10 @@ * Using the relationships given in the Postscript manual (page 121) it's easy to * see that the control points are given by, * - * * x0' = (x0 + 5 * x1) / 6 * x1' = (x2 + 5 * x1) / 6 * x2' = (x1 + x2) / 2 * - * * where the primed variables are the ones used by curveto. The calculations * shown above are done in procedure Ds using the coordinates set up in both * the x[] and y[] arrays. @@ -61,9 +54,7 @@ * A simple test of whether your spline drawing is correct would be to use cip * to draw a spline and some tangent lines at appropriate points and then print * the file. - * */ - for (N=2; N @@ -40,14 +38,10 @@ #include "ext.h" #include "common.h" #include "tr2post.h" -/* PostScript file structuring comments */ -#include "comments.h" -/* general purpose definitions */ -/* #include "gen.h" */ -/* just for TEMPDIR definition */ -#include "path.h" -/* external variable declarations */ -/* #include "ext.h" */ +#include "comments.h" /* PostScript file structuring comments */ +/* #include "gen.h" */ /* general purpose definitions */ +#include "path.h" /* just for TEMPDIR definition */ +/* #include "ext.h" */ /* external variable declarations */ Biobuf *bfp_pic = NULL; Biobufhdr *Bfp_pic; @@ -60,31 +54,28 @@ extern int devres, hpos, vpos; extern int picflag; -/*****************************************************************************/ - void picture(Biobufhdr *inp, char *buf) { - int poffset; /* page offset */ - int indent; /* indent */ - int length; /* line length */ + int i; + int indent; + int length; /* line length */ + int outline = 0; /* draw a box around the picture? */ + int page = 1; /* page number pulled from name[] */ + int poffset; /* page offset */ + int scaleboth = 0; /* scale both dimensions? */ int totrap; /* distance to next trap */ - char name[100]; /* picture file and page string */ + int whiteout = 0; /* white out the box? */ + char flags[20]; /* miscellaneous stuff */ char hwo[40], *p; /* height, width and offset strings */ - char flags[20]; /* miscellaneous stuff */ - int page = 1; /* page number pulled from name[] */ - double frame[4]; /* height, width, y, and x offsets from hwo[] */ + char name[100]; /* picture file and page string */ char units; /* scale indicator for frame dimensions */ - int whiteout = 0; /* white out the box? */ - int outline = 0; /* draw a box around the picture? */ - int scaleboth = 0; /* scale both dimensions? */ double adjx = 0.5; /* left-right adjustment */ double adjy = 0.5; /* top-bottom adjustment */ + double frame[4]; /* height, width, y, and x offsets from hwo[] */ double rot = 0; /* rotation in clockwise degrees */ - Biobufhdr *fp_in; /* for *name */ - int i; /* loop index */ + Biobufhdr *fp_in; /* for *name */ /* - * * Called from devcntrl() after an 'x X PI' command is found. The syntax of that * command is: * @@ -107,9 +98,8 @@ * clockwise degrees, is set by the a flag. If it's not followed by an angle * the current rotation angle is incremented by 90 degrees, otherwise the angle * is set by the number that immediately follows the a. - * */ - + USED(inp); if (!picflag) /* skip it */ return; endstring(); @@ -182,18 +172,15 @@ Bprint(Bstdout, "/saveobj save def\n"); Bprint(Bstdout, "mark\n"); Bterm(fp_in); - } /* - * * Responsible for finding and opening the next picture file. If we've accumulated * any in-line pictures fp_pic won't be NULL and we'll look there first. If *path * is found in *fp_pic we create another temp file, open it for update, unlink it, * copy in the picture, seek back to the start of the new temp file, and return * the file pointer to the caller. If fp_pic is NULL or the lookup fails we just * open file *path and return the resulting file pointer to the caller. - * */ Biobufhdr * picopen(char *path) { @@ -201,13 +188,11 @@ /* long pos; /* current position */ /* long total; /* and sizes - from *fp_pic */ Biobuf *bfp; - Biobufhdr *Bfp; /* and pointer for the new temp file */ - if ((bfp = Bopen(path, OREAD)) == 0) error(FATAL, "can't open %s\n", path); - Bfp = &(bfp->Biobufhdr); - return(Bfp); + return bfp; + #ifdef UNDEF if (Bfp_pic != NULL) { Bseek(Bfp_pic, 0L, 0); @@ -227,22 +212,16 @@ Bseek(Bfp_pic, total+pos, 0); } } - if ((bfp = Bopen(path, OREAD)) == 0) - Bfp = 0; - else - Bfp = &(bfp->Biobufhdr); - return(Bfp); + return Bopen(path, OREAD); #endif } /* - * * Adds an in-line picture file to the end of temporary file *Bfp_pic. All pictures * grabbed from the input file are saved in the same temp file. Each is preceeded * by a one line header that includes the original picture file pathname and the * size of the picture in bytes. The in-line picture file is opened for update, * left open, and unlinked so it disappears when we do. - * */ /* *fp; /* current input file */ /* *buf; /* whatever followed "x X InlinePicture" */ @@ -253,33 +232,27 @@ char name[100]; /* picture file pathname */ long total; /* and size - both from *buf */ - if (Bfp_pic == NULL ) { tmpnam(pictmpname); if ((bfp_pic = Bopen(pictmpname, ORDWR)) == 0) error(FATAL, "can't open in-line picture file %s", ipictmpname); unlink(pictmpname); } - if ( sscanf(buf, "%s %ld", name, &total) != 2 ) error(FATAL, "in-line picture error"); - fseek(Bfp_pic, 0L, 2); fprintf(Bfp_pic, "%s %ld\n", name, total); getc(fp); fflush(fp_pic); piccopy(fp, fp_pic, total); ungetc('\n', fp); - } #endif /* - * * Copies total bytes from file fp_in to fp_out. Used to append picture files to * *fp_pic and then copy them to yet another temporary file immediately before * they're used (in picture()). - * */ /* *fp_in; input */ /* *fp_out; and output file pointers */ --- /sys/src/cmd/postscript/tr2post/ps_include.c Sun Mar 11 01:41:42 2012 +++ /sys/src/cmd/postscript/tr2post/ps_include.c Thu Sep 26 01:32:48 2013 @@ -13,7 +13,6 @@ static void copy(Biobufhdr *fin, Biobufhdr *fout, Section *s) { - int cond; if (s->end <= s->start) return; Bseek(fin, s->start, 0); @@ -34,7 +33,6 @@ } /* - * * Reads a PostScript file (*fin), and uses structuring comments to locate the * prologue, trailer, global definitions, and the requested page. After the whole * file is scanned, the special ps_include PostScript definitions are copied to @@ -44,7 +42,6 @@ * * By default we assume the picture is 8.5 by 11 inches, but the BoundingBox * comment, if found, takes precedence. - * */ /* *fin, *fout; /* input and output files */ /* page_no; /* physical page number from *fin */ @@ -60,25 +57,25 @@ ps_include(Biobufhdr *fin, Biobufhdr *fout, int page_no, int whiteout, int outline, int scaleboth, double cx, double cy, double sx, double sy, double ax, double ay, double rot) { - char **strp; - int foundpage = 0; /* found the page when non zero */ - int foundpbox = 0; /* found the page bounding box */ - int nglobal = 0; /* number of global defs so far */ - int maxglobal = 0; /* and the number we've got room for */ - Section prolog, page, trailer; /* prologue, page, and trailer offsets */ - Section *global; /* offsets for all global definitions */ - double llx, lly; /* lower left and */ - double urx, ury; /* upper right corners - default coords */ - double w = whiteout != 0; /* mostly for the var() macro */ - double o = outline != 0; - double s = scaleboth != 0; - int i; /* loop index */ + int foundpage = 0; /* found the page when non zero */ + int foundpbox = 0; /* found the page bounding box */ + int i; + int maxglobal = 0; /* the number we've got room for */ + int nglobal = 0; /* number of global defs so far */ + char **strp; + double llx, lly; /* lower left and */ + double o = outline != 0; + double s = scaleboth != 0; + double urx, ury; /* upper right corners - default coords */ + double w = whiteout != 0; /* mostly for the var() macro */ + Section *global; /* offsets for all global definitions */ + Section prolog, page, trailer; /* prologue, page, and trailer offsets */ #define has(word) (strncmp(buf, word, strlen(word)) == 0) #define grab(n) ((Section *)(nglobal \ ? realloc((char *)global, n*sizeof(Section)) \ : calloc(n, sizeof(Section)))) - + global = nil; llx = lly = 0; /* default BoundingBox - 8.5x11 inches */ urx = 72 * 8.5; ury = 72 * 11.0; --- /sys/src/cmd/postscript/tr2post/tr2post.c Sun Mar 11 01:38:32 2012 +++ /sys/src/cmd/postscript/tr2post/tr2post.c Thu Sep 26 01:41:54 2013 @@ -26,7 +26,6 @@ char tmpfilename[MAXTOKENSIZE]; char copybuf[BUFSIZ]; - struct charent **build_char_list = 0; int build_char_cnt = 0; @@ -43,13 +42,13 @@ Bprint(Bstdout, "%s", ENDCOMMENTS); if (cat(DPOST)) { - Bprint(Bstderr, "can't read %s\n", DPOST); + fprint(2, "can't read %s\n", DPOST); exits("dpost prologue"); } if (drawflag) { if (cat(DRAW)) { - Bprint(Bstderr, "can't read %s\n", DRAW); + fprint(2, "can't read %s\n", DRAW); exits("draw prologue"); } } @@ -84,7 +83,7 @@ for (i=0; iname); if (cat(charlibname)) - Bprint(Bstderr, "cannot open %s\n", charlibname); + fprint(2, "cannot open %s\n", charlibname); } Bprint(Bstdout, "%s", ENDSETUP); @@ -103,118 +102,103 @@ char *t; programname = argv[0]; - if (Binit(&bstderr, 2, OWRITE) == Beof) { - exits("Binit"); - } + if (Binit(&bstderr, 2, OWRITE) == Beof) + sysfatal("Binit"); Bstderr = &bstderr.Biobufhdr; tmpnam(tmpfilename); - if ((bstdout=Bopen(tmpfilename, OWRITE)) == 0) { - Bprint(Bstderr, "cannot open temporary file %s\n", tmpfilename); - exits("Bopen"); - } + if ((bstdout=Bopen(tmpfilename, OWRITE)) == 0) + sysfatal("cannot open temporary file %s: %r", tmpfilename); atexit(cleanup); Bstdout = &bstdout->Biobufhdr; - + ARGBEGIN{ - case 'a': /* aspect ratio */ - aspectratio = atof(ARGF()); - break; - case 'c': /* copies */ - copies = atoi(ARGF()); - break; - case 'd': - debug = 1; - break; - case 'm': /* magnification */ - magnification = atof(ARGF()); - break; - case 'n': /* forms per page */ - formsperpage = atoi(ARGF()); - break; - case 'o': /* output page list */ - pagelist(ARGF()); - break; - case 'p': /* landscape or portrait mode */ - if ( ARGF()[0] == 'l' ) - landscape = 1; - else - landscape = 0; - break; - case 'x': /* shift things horizontally */ - xoffset = atof(ARGF()); - break; - case 'y': /* and vertically on the page */ - yoffset = atof(ARGF()); - break; - case 'P': /* PostScript pass through */ - t = ARGF(); - i = strlen(t) + 1; - passthrough = malloc(i); - if (passthrough == 0) { - Bprint(Bstderr, "cannot allocate memory for argument string\n"); - exits("malloc"); - } - strncpy(passthrough, t, i); - break; - default: /* don't know what to do for ch */ - Bprint(Bstderr, "unknown option %C\n", ARGC()); - break; + case 'a': /* aspect ratio */ + aspectratio = atof(ARGF()); + break; + case 'c': /* copies */ + copies = atoi(ARGF()); + break; + case 'd': + debug = 1; + break; + case 'm': /* magnification */ + magnification = atof(ARGF()); + break; + case 'n': /* forms per page */ + formsperpage = atoi(ARGF()); + break; + case 'o': /* output page list */ + pagelist(ARGF()); + break; + case 'p': /* landscape or portrait mode */ + if ( ARGF()[0] == 'l' ) + landscape = 1; + else + landscape = 0; + break; + case 'x': /* shift things horizontally */ + xoffset = atof(ARGF()); + break; + case 'y': /* and vertically on the page */ + yoffset = atof(ARGF()); + break; + case 'P': /* PostScript pass through */ + t = ARGF(); + i = strlen(t) + 1; + passthrough = malloc(i); + if (passthrough == 0) + sysfatal("malloc"); + strncpy(passthrough, t, i); + break; + default: /* don't know what to do for ch */ + fprint(2, "unknown option %C\n", ARGC()); + break; }ARGEND; + readDESC(); if (argc == 0) { - if ((binp = (Biobuf *)malloc(sizeof(Biobuf))) == nil) { - Bprint(Bstderr, "malloc failed.\n"); - exits("malloc"); - } - if (Binit(binp, 0, OREAD) == Beof) { - Bprint(Bstderr, "Binit of failed.\n"); - exits("Binit"); - } - Binp = &(binp->Biobufhdr); - if (debug) Bprint(Bstderr, "using standard input\n"); + if ((binp = (Biobuf *)malloc(sizeof(Biobuf))) == nil) + sysfatal("malloc"); + if (Binit(binp, 0, OREAD) == Beof) + sysfatal("Binit of failed."); + Binp = &binp->Biobufhdr; + if (debug) fprint(2, "using standard input\n"); conv(Binp); Bterm(Binp); } for (i=0; iBiobufhdr); + Binp = &binp->Biobufhdr; inputfilename = argv[i]; conv(Binp); Bterm(Binp); } Bterm(Bstdout); - if ((ifd=open(tmpfilename, OREAD)) < 0) { - Bprint(Bstderr, "open of %s failed.\n", tmpfilename); - exits("open"); - } + if ((ifd=open(tmpfilename, OREAD)) < 0) + sysfatal("open of %s failed: %r", tmpfilename); bstdout = galloc(0, sizeof(Biobuf), "bstdout"); - if (Binit(bstdout, 1, OWRITE) == Beof) { - Bprint(Bstderr, "Binit of failed.\n"); - exits("Binit"); - } + if (Binit(bstdout, 1, OWRITE) == Beof) + sysfatal("Binit of failed."); Bstdout = &(bstdout->Biobufhdr); prologues(); Bflush(Bstdout); - tot = 0; i = 0; + tot = 0; while ((i=read(ifd, copybuf, BUFSIZ)) > 0) { if (write(1, copybuf, i) != i) { - Bprint(Bstderr, "write error on copying from temp file.\n"); + fprint(2, "write error on copying from temp file.\n"); exits("write"); } tot += i; } - if (debug) Bprint(Bstderr, "copied %d bytes to final output i=%d\n", tot, i); - if (i < 0) { - Bprint(Bstderr, "read error on copying from temp file.\n"); - exits("read"); - } + if (debug) fprint(2, "copied %d bytes to final output i=%d\n", tot, i); + if (i < 0) + sysfatal("read error copying from temp file: %r"); finish(); - exits(""); } --- /sys/src/cmd/postscript/tr2post/utils.c Sun Dec 12 02:11:12 1999 +++ /sys/src/cmd/postscript/tr2post/utils.c Thu Sep 26 01:59:39 2013 @@ -40,18 +40,22 @@ if ((xexpecthmot+1)) { delta = x - expecthmot; if (curtrofffontid <0 || curtrofffontid >= troffontcnt) { - Bprint(Bstderr, "troffontcnt=%d curtrofffontid=%d\n", troffontcnt, curtrofffontid); - Bflush(Bstderr); + fprint(2, "troffontcnt=%d curtrofffontid=%d\n", + troffontcnt, curtrofffontid); exits(""); } - if (delta == troffontab[curtrofffontid].spacewidth*fontsize/10 && isinstring()) { - if (pageon()) runeout(' '); + if (delta == troffontab[curtrofffontid].spacewidth*fontsize/10 && + isinstring()) { + if (pageon()) + runeout(' '); } else { - if (pageon()) { + if (pageon()) { endstring(); /* Bprint(Bstdout, " %d 0 rmoveto ", delta); */ /* Bprint(Bstdout, " %d %d m ", hpos+x, vpos); */ - if (debug) Bprint(Bstderr, "x=%d expecthmot=%d\n", x, expecthmot); + if (debug) + fprint(2, "x=%d expecthmot=%d\n", + x, expecthmot); } } } @@ -72,7 +76,7 @@ for (cp = &(troffontab[trfid].charent[RUNEGETGROUP(rune)][RUNEGETCHAR(rune)]); *cp != 0; cp = &((*cp)->next)) { if ((*cp)->name) { - if (debug) Bprint(Bstderr, "looking for <%s>, have <%s> in font %s\n", stoken, (*cp)->name, troffontab[trfid].trfontid); + if (debug) fprint(2, "looking for <%s>, have <%s> in font %s\n", stoken, (*cp)->name, troffontab[trfid].trfontid); if (strcmp((*cp)->name, stoken) == 0) break; } @@ -89,44 +93,56 @@ struct charent **cp; struct troffont *tfp; struct psfent *psfp; - int i, t; + int i, t, mi, wid; int fontid; /* this is the troff font table index, not the mounted font table index */ - int mi, fi, wid; Rune r; + mi = 0; settrfont(); /* check current font for the character, special or not */ fontid = curtrofffontid; -if (debug) fprint(2, " looking through current font: trying %s\n", troffontab[fontid].trfontid); + if (debug) + fprint(2, "\tlooking through current font: trying %s\n", + troffontab[fontid].trfontid); cp = findglyph(fontid, rune, stoken); - if (*cp != 0) goto foundit; + if (*cp != 0) + goto foundit; if (specialflag) { - if (expecthmot) hmot(0); + if (expecthmot) + hmot(0); /* check special fonts for the special character */ /* cycle through the (troff) mounted fonts starting at the next font */ for (mi=0; mi troff font %s\n", rune, stoken, - troffontab[curtrofffontid].trfontid); + error(WARNING, "cannot find glyph, rune=0x%x stoken=<%s> troff font %s\n", + rune, stoken, troffontab[curtrofffontid].trfontid); expecthmot = 0; return; } foundit: t = (((*cp)->postfontid&0xff)<<8) | ((*cp)->postcharid&0xff); - if (debug) { - Bprint(Bstderr, "runeout(0x%x)<%C> postfontid=0x%x postcharid=0x%x troffcharwidth=%d\n", - rune, rune, (*cp)->postfontid, (*cp)->postcharid, (*cp)->troffcharwidth); - } - - tfp = &(troffontab[fontid]); + if (debug) + fprint(2, "runeout(0x%x)<%C> postfontid=0x%x postcharid=0x%x troffcharwidth=%d\n", + rune, rune, (*cp)->postfontid, (*cp)->postcharid, + (*cp)->troffcharwidth); + + tfp = &troffontab[fontid]; + psfp = nil; for (i=0; ipsfmapsize; i++) { psfp = &(tfp->psfmap[i]); - if(t>=psfp->start && t<=psfp->end) break; + if(t>=psfp->start && t<=psfp->end) + break; } if (i >= tfp->psfmapsize) error(FATAL, "character <0x%x> does not have a Postscript font defined.\n", rune); @@ -187,44 +205,47 @@ if (t == 0x0001) { /* character is in charlib */ endstring(); if (pageon()) { - struct charent *tcp; - Bprint(Bstdout, "%d %d m ", hpos, vpos); /* if char is unicode character rather than name, clean up for postscript */ wid = chartorune(&r, (*cp)->name); if(' 'troffcharwidth, (*cp)->name); + Bprint(Bstdout, "%d build_%s\n", + (*cp)->troffcharwidth, (*cp)->name); else{ if((*cp)->name[wid] != 0) error(FATAL, "character <%s> badly named\n", (*cp)->name); - Bprint(Bstdout, "%d build_X%.4x\n", (*cp)->troffcharwidth, r); + Bprint(Bstdout, "%d build_X%.4x\n", + (*cp)->troffcharwidth, r); } - /* stash charent pointer in a list so that we can print these character definitions - * in the prologue. + /* + * stash charent pointer in a list so that we can + * print these character definitions in the prologue. */ for (i=0; itroffcharwidth * fontsize / unitwidth; } else if (isinstring() || rune != ' ') { startstring(); - if (pageon()) { + if (pageon()) if (rune == ' ') Bprint(Bstdout, " "); else Bprint(Bstdout, "%s", charcode[RUNEGETCHAR(t)].str); - } expecthmot = (*cp)->troffcharwidth * fontsize / unitwidth; } } -/* runeout puts a symbol into a string (queue) to be output. +/* + * runeout puts a symbol into a string (queue) to be output. * It also has to keep track of the current and last symbol * output to check that the spacing is correct by default * or needs to be adjusted with a spacing operation. @@ -243,22 +264,23 @@ void specialout(char *stoken) { Rune rune; - int i; - i = chartorune(&rune, stoken); + chartorune(&rune, stoken); glyphout(rune, stoken, TRUE); } void graphfunc(Biobufhdr *bp) { + USED(bp); } long nametorune(char *name) { + USED(name); return(0); } void notavail(char *msg) { - Bprint(Bstderr, "%s is not available at this time.\n", msg); + fprint(2, "%s is not available at this time.\n", msg); } --- /sys/src/cmd/troff/fns.h Sun Dec 12 02:14:53 1999 +++ /sys/src/cmd/troff/fns.h Fri Sep 27 04:03:30 2013 @@ -3,10 +3,6 @@ */ int pclose(FILE*); long filesize(int fd); -int open(char *, int); -int read(int, char *, int); -int lseek(int, long, int); -int close(int); int getpid(void); /* --- /sys/src/cmd/troff/mkfile Mon Mar 10 23:08:28 2008 +++ /sys/src/cmd/troff/mkfile Fri Sep 27 04:03:39 2013 @@ -27,7 +27,7 @@ BIN=/$objtype/bin = 040) /* zapped: && i < 0177 */ goto g4; i = ifilt[i]; @@ -741,6 +739,7 @@ char buf[100], *p; int i, n, c; + n = c = 0; for (i = 0, p = buf; i < MB_CUR_MAX; i++) { if ((c = getc(fp)) == EOF) return c; @@ -911,7 +910,6 @@ getname(void) { int j, k; - Tchar i; lgf++; for (k = 0; k < NS - 1; k++) { @@ -929,10 +927,10 @@ void caseso(void) { FILE *fp; - char *p, *q; lgf++; nextf[0] = 0; + fp = NULL; if (skip() || !getname() || (fp = fopen(nextf, "r")) == NULL || ifi >= NSO) { ERROR "can't open file %s", nextf WARN; done(02); --- /sys/src/cmd/troff/n10.c Sun Dec 12 02:14:53 1999 +++ /sys/src/cmd/troff/n10.c Fri Sep 27 04:03:54 2013 @@ -39,7 +39,7 @@ } for (;;) { if (quote && *s == '"') { - s++; + s++; /* pointless */ break; } if (!quote && (*s == ' ' || *s == '\t' || *s == '\n' || *s == '\0')) @@ -74,14 +74,13 @@ static int getnrfont(FILE *fp) /* read the nroff description file */ { - FILE *fin; Chwid chtemp[NCHARS]; static Chwid chinit; int i, nw, n, wid, code, type; - char buf[100], ch[100], s1[100], s2[100], cmd[300]; + char buf[100], ch[100], s1[100], s2[100]; wchar_t wc; - + code = 0; /* no idea what this should be */ chinit.wid = 1; chinit.str = ""; for (i = 0; i < ALPHABET; i++) { @@ -114,6 +113,7 @@ #endif /*UNICODE*/ } else { if (strcmp(ch, "---") == 0) { /* no name */ + /* code used to be uninitialised here */ sprintf(ch, "%d", code); type = Number; } else @@ -139,7 +139,7 @@ void n_ptinit(void) { int i; - char *p, *cp; + char *p; char opt[50], cmd[100]; FILE *fp; --- /sys/src/cmd/troff/n2.c Sat Jun 17 19:01:28 2000 +++ /sys/src/cmd/troff/n2.c Fri Sep 27 04:03:54 2013 @@ -137,7 +137,6 @@ void outascii(Tchar i) /* print i in best-guess ascii */ { - char *p; int j = cbits(i); /* is this ever called with NROFF set? probably doesn't work at all. */ --- /sys/src/cmd/troff/n3.c Fri Mar 16 06:01:33 2001 +++ /sys/src/cmd/troff/n3.c Fri Sep 27 04:03:54 2013 @@ -64,7 +64,7 @@ char *grow(char *ptr, int num, int size) /* make array bigger */ { - char *p, new; + char *p; if (ptr == NULL) p = (char *) calloc(num, size); @@ -176,8 +176,7 @@ void caserm(void) { - int j; - int k = 0; + int j, k; lgf++; g0: @@ -249,7 +248,7 @@ savoff = offset; offset = apptr; wbf((Tchar) IMP); - offset = savoff; + offset = savoff; /* pointless */ } offset = dip->op; if (req != '.') @@ -307,7 +306,6 @@ Offset finds(int mn) { int i; - Tchar j = IMP; Offset savip; oldmn = findmn(mn); @@ -383,6 +381,7 @@ flushi(); nlflg = 0; state = 1; + savoff = 0; /* state 0 eat up * state 1 look for . @@ -506,7 +505,7 @@ if (i == 0) contabp[savslot].emx = offset; off = boffset(offset); - blist[j].bp[off++] = i; + blist[j].bp[off] = i; offset++; if (pastend(offset)) { /* off the end of this block */ if (blist[j].nextoff == -1) { --- /sys/src/cmd/troff/n5.c Sun Dec 12 02:14:53 1999 +++ /sys/src/cmd/troff/n5.c Fri Sep 27 04:03:54 2013 @@ -83,6 +83,7 @@ { Tchar i; + i = 0; if (skip() || ismot(i = getch()) || cbits(i) == ' ' || cbits(i) == '\n') { ch = i; return(c); @@ -431,7 +432,7 @@ else { extern int error; int savtrac = trace; - i = trace = 0; + trace = 0; noscale++; i = inumb(&trace); noscale--; @@ -472,7 +473,7 @@ sprintf(&tmbuf[i], "\\N'%s'", p+1); break; case Troffchar: - if ((j = strlen(p+1)) == 2) + if (strlen(p+1) == 2) sprintf(&tmbuf[i], "\\(%s", p+1); else sprintf(&tmbuf[i], "\\C'%s'", p+1); --- /sys/src/cmd/troff/n6.c Sun Dec 12 02:14:54 1999 +++ /sys/src/cmd/troff/n6.c Fri Sep 27 04:03:54 2013 @@ -83,9 +83,9 @@ i = cbits(getch()); if (isdigit(i)) { /* \sd or \sdd */ i -= '0'; - if (i == 0) /* \s0 */ + if (i == 0) { /* \s0 */ ; - else if (i <= 3 && (ch=getch()) && isdigit(cbits(ch))) { /* \sdd */ + } else if (i <= 3 && (ch=getch()) && isdigit(cbits(ch))) { /* \sdd */ ch = 0; } } else if (i == '(') { /* \s(dd */ @@ -294,7 +294,7 @@ { int i, j, k; - k = 0; + j = k = 0; bd0: if (skip() || !(i = getrq()) || (j = findft(i)) == -1) { if (k) --- /sys/src/cmd/troff/n7.c Sun Dec 12 02:14:54 1999 +++ /sys/src/cmd/troff/n7.c Fri Sep 27 04:03:54 2013 @@ -4,6 +4,7 @@ #ifdef STRICT /* not in ANSI or POSIX */ +#undef isascii #define isascii(a) ((a) >= 0 && (a) <= 127) #endif @@ -354,6 +355,7 @@ int i, j, nlss; int opn; + nlss = 0; if (a) goto nl1; if (dip != d) { @@ -656,7 +658,7 @@ int noword; int obits; - noword = 0; + j = noword = 0; if (x) if (pendw) { *pendw = 0; --- /sys/src/cmd/troff/n8.c Thu May 10 20:57:02 2007 +++ /sys/src/cmd/troff/n8.c Fri Sep 27 04:03:55 2013 @@ -306,12 +306,11 @@ void digram(void) { - Tchar *w; - int val; - Tchar *nhyend, *maxw; - int maxval; + int maxval, val; + Tchar *nhyend, *maxw, *w; extern char bxh[26][13], bxxh[26][13], xxh[26][13], xhx[26][13], hxx[26][13]; + maxw = 0; again: if (!(w = chkvow(hyend + 1))) return; --- /sys/src/cmd/troff/n9.c Sun Dec 12 02:14:54 1999 +++ /sys/src/cmd/troff/n9.c Fri Sep 27 04:03:55 2013 @@ -331,20 +331,18 @@ Tchar setfield(int x) { - Tchar ii, jj, *fp; - int i, j; - int length, ws, npad, temp, type; + Tchar rchar, ii, jj, *fp; Tchar **pp, *padptr[NPP]; Tchar fbuf[FBUFSZ]; - int savfc, savtc, savlc; - Tchar rchar; - int savepos; + int i, j, length, ws, npad, temp, type, savepos, savfc, savtc, savlc; static Tchar wbuf[] = { WORDSP, 0}; if (x == tabch) rchar = tabc | chbits; - else if (x == ldrch) + else if (x == ldrch) rchar = dotc | chbits; + else + rchar = 0; temp = npad = ws = 0; savfc = fc; savtc = tabch; --- /sys/src/cmd/troff/t10.c Sat May 10 20:38:32 2008 +++ /sys/src/cmd/troff/t10.c Fri Sep 27 04:03:55 2013 @@ -156,11 +156,11 @@ int ptout0(Tchar *pi) { - int j, k, w; - int z, dx, dy, dx2, dy2, n; - Tchar i; + int j, k, w, z, dx, dy, dx2, dy2, n; int outsize; /* size of object being printed */ + Tchar i; + w = 0; outsize = 1; /* default */ i = *pi; k = cbits(i); --- /sys/src/cmd/troff/t11.c Sun Dec 12 02:14:54 1999 +++ /sys/src/cmd/troff/t11.c Fri Sep 27 04:03:55 2013 @@ -103,6 +103,7 @@ chtemp[i] = chinit; /* zero out to begin with */ ftemp->specfont = ftemp->ligfont = 0; ftemp->defaultwidth = ftemp->spacewidth = Inch * Unitwidth / 72 / 3; /* should be rounded */ + nw = code = 0; while (fscanf(fin, "%s", cmd) != EOF) { if (strcmp(cmd, "name") == 0) fscanf(fin, "%s", ftemp->longname); --- /sys/src/cmd/troff/t6.c Sun Dec 12 02:14:54 1999 +++ /sys/src/cmd/troff/t6.c Fri Sep 27 04:03:55 2013 @@ -214,7 +214,6 @@ Tchar t_setch(int c) { - int j; char temp[50]; char *s; @@ -232,6 +231,8 @@ return chadd(temp, Troffchar, Install) | chbits; /* add name even if haven't seen it */ #else if (NROFF) { + int j; + j = chadd(temp, Troffchar, Lookup); if ( j == -1) return 0; @@ -397,6 +398,7 @@ int i, j; i = cbits(getch()); + j = i; /* make compiler happy */ if (isdigit(i)) { /* \sd or \sdd */ i -= '0'; if (i == 0) /* \s0 */ @@ -705,7 +707,7 @@ setfp(int pos, int f, char *truename, int print) /* mount font f at position pos[0...nfonts] */ { - char pathname[NS], shortname[NS], *sl; + char pathname[NS], shortname[NS]; zapwcache(0); if (truename) @@ -785,7 +787,7 @@ return; } zapwcache(0); - k = 0; + j = k = 0; bd0: if (skip() || !(i = getrq()) || (j = findft(i)) == -1) { if (k) --- /sys/src/cmd/troff/tdef.h Tue Nov 1 13:36:41 2005 +++ /sys/src/cmd/troff/tdef.h Fri Sep 27 04:03:30 2013 @@ -1,5 +1,9 @@ +#define _BSD_EXTENSION +#define _POSIX_SOURCE + #include #include +#include #include #include #include