diff options
author | Baptiste Daroussin <bapt@FreeBSD.org> | 2016-10-23 00:24:25 +0000 |
---|---|---|
committer | Baptiste Daroussin <bapt@FreeBSD.org> | 2016-10-23 00:24:25 +0000 |
commit | ab1717bb35d85041e0184f79daa1313a1306dc01 (patch) | |
tree | fa0739f76b49b902269f8f7c1e1c7c5ea30c0556 | |
parent | aa7798c94fa57f6c00fab4393c9fe91334864371 (diff) |
Import heirloom doctools snapshot 20161016vendor/heirloom-doctools/20161016
Notes
Notes:
svn path=/vendor/heirloom-doctools/dist/; revision=307809
svn path=/vendor/heirloom-doctools/20161016/; revision=307810; tag=vendor/heirloom-doctools/20161016
128 files changed, 1161 insertions, 2358 deletions
diff --git a/checknr/checknr.c b/checknr/checknr.c index b7dde0af2004..a98b0adc2d04 100644 --- a/checknr/checknr.c +++ b/checknr/checknr.c @@ -179,7 +179,6 @@ static void checkknown(char *mac); static void addcmd(char *line); static void addmac(char *mac); static int binsrch(char *mac); -static char *fgetline(char **line, size_t *linesize, size_t *llen, FILE *fp); static void growstk(void) @@ -307,7 +306,7 @@ process(FILE *f) int pl; stktop = -1; - for (lineno = 1; fgetline(&line, &linesize, NULL, f); lineno++) { + for (lineno = 1; getline(&line, &linesize, f) > 0; lineno++) { if (line[0] == '.') { /* * find and isolate the macro/command name. @@ -636,34 +635,3 @@ binsrch(char *mac) slot = bot; /* place it would have gone */ return (-1); } - -#define LSIZE 256 - -static char * -fgetline(char **line, size_t *linesize, size_t *llen, FILE *fp) -{ - int c; - size_t n = 0; - - if (*line == NULL || *linesize < LSIZE + n + 1) - *line = realloc(*line, *linesize = LSIZE + n + 1); - for (;;) { - if (n >= *linesize - LSIZE / 2) - *line = realloc(*line, *linesize += LSIZE); - c = getc(fp); - if (c != EOF) { - (*line)[n++] = c; - (*line)[n] = '\0'; - if (c == '\n') - break; - } else { - if (n > 0) - break; - else - return NULL; - } - } - if (llen) - *llen = n; - return *line; -} diff --git a/compat.c b/compat.c new file mode 100644 index 000000000000..85a46b18d66e --- /dev/null +++ b/compat.c @@ -0,0 +1,47 @@ +/* Carsten Kunze, 2016 */ + +#include <string.h> + +#ifndef HAVE_STRLCPY +size_t +strlcpy(char *dst, const char *src, size_t dstsize) { + size_t srcsize; + /* Not conform to strlcpy, but avoids to access illegal memory in case + * of unterminated strings */ + for (srcsize = 0; srcsize < dstsize; srcsize++) + if (!src[srcsize]) + break; + if (dstsize > srcsize) + dstsize = srcsize; + else if (dstsize) + dstsize--; + if (dstsize) + /* assumes non-overlapping buffers */ + memcpy(dst, src, dstsize); + dst[dstsize] = 0; + return srcsize; +} +#endif + +#ifndef HAVE_STRLCAT +size_t +strlcat(char *dst, const char *src, size_t dstsize) { + size_t ld, ls; + for (ld = 0; ld < dstsize - 1; ld++) + if (!dst[ld]) + break; + dst += ld; + dstsize -= ld; + for (ls = 0; ls < dstsize; ls++) + if (!src[ls]) + break; + if (dstsize > ls) + dstsize = ls; + else if (dstsize) + dstsize--; + if (dstsize) + memcpy(dst, src, dstsize); + dst[dstsize] = 0; + return ld + ls; +} +#endif diff --git a/eqn/checkeq.d/checkeq.c b/eqn/checkeq.d/checkeq.c index e925a17b0dfd..046b44011856 100644 --- a/eqn/checkeq.d/checkeq.c +++ b/eqn/checkeq.d/checkeq.c @@ -31,7 +31,6 @@ static const char sccsid[] USED = "@(#)/usr/ucb/checkeq.sl 4.1 (gritter) 9/15/05 #include <stdlib.h> static void check(FILE *); -static char *fgetline(char **, size_t *, FILE *); static FILE *fin; static int delim = '$'; @@ -62,7 +61,7 @@ check(FILE *f) size_t insize = 0; start = eq = line = ndel = totdel = 0; - while (fgetline(&in, &insize, f) != NULL) { + while (getline(&in, &insize, f) > 0) { line++; ndel = 0; for (p = in; *p; p++) @@ -127,22 +126,3 @@ check(FILE *f) if (eq) printf(" Unfinished EQ\n"); } - -static char * -fgetline(char **lp, size_t *zp, FILE *fp) -{ - size_t n = 0; - int c; - - while ((c = getc(fp)) != EOF) { - if (n >= *zp) - *lp = realloc(*lp, *zp += 600); - (*lp)[n++] = c; - if (c == '\n') - break; - } - if (n >= *zp) - *lp = realloc(*lp, *zp += 600); - (*lp)[n] = 0; - return c != EOF ? *lp : NULL; -} diff --git a/eqn/diacrit.c b/eqn/diacrit.c index 07d0e1759467..e8265a2a0c2b 100644 --- a/eqn/diacrit.c +++ b/eqn/diacrit.c @@ -35,7 +35,7 @@ diacrit(int p1, int type) { t = oalloc(); #ifdef NEQN nrwid(p1, ps, p1); - printf(".nr 10 %gu\n", max(eht[p1]-ebase[p1]-VERT(2),0)); + printf(".nr 10 %gu\n", (float)max(eht[p1]-ebase[p1]-VERT(2),0)); #else /* NEQN */ effps = EFFPS(ps); nrwid(p1, effps, p1); @@ -29,11 +29,6 @@ #include <inttypes.h> #include "global.h" -#if defined (__GLIBC__) && defined (_IO_getc_unlocked) -#undef getc -#define getc(f) _IO_getc_unlocked(f) -#endif - #define FATAL 1 #define ROM '1' #ifndef NEQN @@ -92,8 +87,8 @@ extern int markline; /* 1 if this EQ/EN contains mark or lineup */ extern char *progname; typedef struct s_tbl { - char *name; - char *defn; + const char *name; + const char *defn; struct s_tbl *next; } tbl; extern char *spaceval; /* use in place of normal \x (for pic) */ @@ -125,7 +120,6 @@ int eqn(int, char **); int getline(char **, size_t *); void do_inline(void); void putout(int); -float max(float, float); int oalloc(void); void ofree(int); void setps(float); @@ -137,7 +131,7 @@ void error(int, const char *, ...); /* lex.c */ int gtc(void); int openinfile(void); -void pbstr(register char *); +void pbstr(register const char *); int yylex(void); int getstr(char *, register int); int cstr(char *, int, int); @@ -147,7 +141,7 @@ char *strsave(char *); void include(void); void delim(void); /* lookup.c */ -tbl *lookup(tbl **, char *, char *); +tbl *lookup(tbl **, const char *, const char *); void init_tbl(void); /* mark.c */ void mark(int); @@ -161,7 +155,7 @@ void move(int, int, int); void boverb(int, int); /* paren.c */ void paren(int, int, int); -void brack(int, char *, char *, char *); +void brack(int, const char *, const char *, const char *); /* pile.c */ void lpile(int, int, int); /* shift.c */ diff --git a/eqn/eqnbox.c b/eqn/eqnbox.c index c51f0a4b95dc..2a9a4bc5d832 100644 --- a/eqn/eqnbox.c +++ b/eqn/eqnbox.c @@ -37,7 +37,7 @@ eqnbox(int p1, int p2, int lu) { #else /* NEQN */ int b, h; #endif /* NEQN */ - char *sh; + const char *sh; yyval.token = p1; b = max(ebase[p1], ebase[p2]); diff --git a/eqn/eqnchar.d/genutf8.c b/eqn/eqnchar.d/genutf8.c index d43b3624411d..f9575121f29a 100644 --- a/eqn/eqnchar.d/genutf8.c +++ b/eqn/eqnchar.d/genutf8.c @@ -14,7 +14,7 @@ #include <wctype.h> #include <stdio.h> -const char *const ctl[] = { +static const char *const ctl[] = { "nul", "soh", "stx", diff --git a/eqn/funny.c b/eqn/funny.c index ba230e21ce3f..71f8d7caa239 100644 --- a/eqn/funny.c +++ b/eqn/funny.c @@ -32,7 +32,7 @@ extern YYSTYPE yyval; void funny(int n) { - char *f = NULL; + const char *f = NULL; yyval.token = oalloc(); switch(n) { diff --git a/eqn/integral.c b/eqn/integral.c index 55c2eb4949cb..b2dffa72023e 100644 --- a/eqn/integral.c +++ b/eqn/integral.c @@ -56,7 +56,7 @@ integral(int p, int p1, int p2) { void setintegral(void) { - char *f; + const char *f; yyval.token = oalloc(); f = "\\(is"; @@ -26,9 +26,9 @@ #include <stdlib.h> #include <libgen.h> -char *in; /* input buffer */ -size_t insize; /* input buffer size */ -int noeqn; +static char *in; /* input buffer */ +static size_t insize; /* input buffer size */ +static int noeqn; int main(int argc,char **argv) { @@ -95,7 +95,8 @@ eqn(int argc,char **argv) { int getline(char **sp, size_t *np) { - register int c, n = 0, esc = 0, par = 0, brack = 0; + register int c, esc = 0, par = 0, brack = 0; + size_t n = 0; char *xp; for (;;) { c = gtc(); @@ -225,11 +226,6 @@ putout(int p1) { } -float -max(float i,float j) { - return (i>j ? i : j); -} - int oalloc(void) { int i; diff --git a/eqn/lex.c b/eqn/lex.c index 2e7884efc170..6815801c92d3 100644 --- a/eqn/lex.c +++ b/eqn/lex.c @@ -34,12 +34,12 @@ extern YYSTYPE yyval; #define SSIZE 400 -char token[SSIZE]; -int sp; +static char token[SSIZE]; +static int sp; #define putbak(c) *ip++ = c; #define PUSHBACK 300 /* maximum pushback characters */ -char ibuf[PUSHBACK+SSIZE]; /* pushback buffer for definitions, etc. */ -char *ip = ibuf; +static char ibuf[PUSHBACK+SSIZE]; /* pushback buffer for definitions, etc. */ +static char *ip = ibuf; int gtc(void) { @@ -77,9 +77,9 @@ openinfile(void) } void -pbstr(register char *str) +pbstr(register const char *str) { - register char *p; + register const char *p; p = str; while (*p++); diff --git a/eqn/lookup.c b/eqn/lookup.c index 7b303fe9e0d4..fb31d181aea3 100644 --- a/eqn/lookup.c +++ b/eqn/lookup.c @@ -33,8 +33,8 @@ tbl *keytbl[TBLSIZE]; /* key words */ tbl *restbl[TBLSIZE]; /* reserved words */ tbl *deftbl[TBLSIZE]; /* user-defined names */ -struct { - char *key; +static struct { + const char *key; int keyval; } keyword[] ={ { "sub", SUB }, @@ -104,9 +104,9 @@ struct { { NULL, 0 } }; -struct { - char *res; - char *resval; +static struct { + const char *res; + const char *resval; } resword[] ={ { ">=", "\\(>=" }, { "<=", "\\(<=" }, @@ -220,11 +220,11 @@ struct { }; tbl * -lookup(tbl **tblp, char *name, char *defn) /* find name in tbl. if defn non-null, install */ +lookup(tbl **tblp, const char *name, const char *defn) /* find name in tbl. if defn non-null, install */ { register tbl *p; register int h; - register unsigned char *s = (unsigned char *)name; + register unsigned const char *s = (unsigned const char *)name; for (h = 0; *s != '\0'; ) h += *s++; diff --git a/eqn/matrix.c b/eqn/matrix.c index 53b674f4b227..85228e0572e0 100644 --- a/eqn/matrix.c +++ b/eqn/matrix.c @@ -52,7 +52,7 @@ matrix(int p1) { int hb, b; #endif /* NEQN */ int nrow, ncol, i, j, k, val[100]; - char *space; + const char *space; space = "\\ \\ "; nrow = lp[p1]; /* disaster if rows inconsistent */ diff --git a/eqn/paren.c b/eqn/paren.c index a55febdb9635..38cef5961173 100644 --- a/eqn/paren.c +++ b/eqn/paren.c @@ -163,7 +163,7 @@ paren(int leftc, int p1, int rightc) { } void -brack(int m, char *t, char *c, char *b) { +brack(int m, const char *t, const char *c, const char *b) { int j; printf("\\b'%s", t); for( j=0; j<m; j++) diff --git a/eqn/shift.c b/eqn/shift.c index 666a9c07a21c..d86c0acfd298 100644 --- a/eqn/shift.c +++ b/eqn/shift.c @@ -35,7 +35,7 @@ bshiftb(int p1, int dir, int p2) { #ifndef NEQN float shval, d1, h1, b1, h2, b2; float diffps, effps, effps2; - char *sh1, *sh2; + const char *sh1, *sh2; #else /* NEQN */ int shval, d1, h1, b1, h2, b2; #endif /* NEQN */ diff --git a/eqn/text.c b/eqn/text.c index 7b7b58ff7f9f..6ad51c550f06 100644 --- a/eqn/text.c +++ b/eqn/text.c @@ -30,17 +30,17 @@ extern YYSTYPE yyval; -int csp; -int psp; +static int csp; +static int psp; #define CSSIZE 400 -char cs[420]; +static char cs[420]; -int lf, rf; /* temporary spots for left and right fonts */ +static int lf, rf; /* temporary spots for left and right fonts */ void text(int t,char *p1) { int c; - char *p; + const char *p; tbl *tp; extern tbl *restbl; diff --git a/grap/coord.c b/grap/coord.c index 491c41e9a4c8..a06d74840fea 100644 --- a/grap/coord.c +++ b/grap/coord.c @@ -13,6 +13,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> +#include "global.h" #include "grap.h" #include "y.tab.h" diff --git a/grap/grap.h b/grap/grap.h index cbba8eb38d0f..a543ca736755 100644 --- a/grap/grap.h +++ b/grap/grap.h @@ -143,9 +143,6 @@ extern int pointsize, ps_set; #define Exp(x) errcheck(exp(x), "exp") #define Sqrt(x) errcheck(sqrt(x), "sqrt") -#define min(x,y) (((x) <= (y)) ? (x) : (y)) -#define max(x,y) (((x) >= (y)) ? (x) : (y)) - extern void yyerror(char *); extern void coord_x(Point); extern void coord_y(Point); diff --git a/grap/input.c b/grap/input.c index 33451da2cb44..022613e26493 100644 --- a/grap/input.c +++ b/grap/input.c @@ -18,11 +18,6 @@ #include "grap.h" #include "y.tab.h" -#if defined (__GLIBC__) && defined (_IO_getc_unlocked) -#undef getc -#define getc(f) _IO_getc_unlocked(f) -#endif - Infile infile[10]; Infile *curfile = infile; @@ -596,33 +591,3 @@ void shell_exec(void) /* do it */ else system(shellbuf); } - -#define LSIZE 128 - -char *fgetline(char **line, size_t *linesize, size_t *llen, FILE *fp) -{ - int c; - size_t n = 0; - - if (*line == NULL || *linesize < LSIZE + n + 1) - *line = realloc(*line, *linesize = LSIZE + n + 1); - for (;;) { - if (n >= *linesize - LSIZE / 2) - *line = realloc(*line, *linesize += LSIZE); - c = getc(fp); - if (c != EOF) { - (*line)[n++] = c; - (*line)[n] = '\0'; - if (c == '\n') - break; - } else { - if (n > 0) - break; - else - return NULL; - } - } - if (llen) - *llen = n; - return *line; -} diff --git a/grap/main.c b/grap/main.c index ac35127bf3f5..eb4478945c02 100644 --- a/grap/main.c +++ b/grap/main.c @@ -156,12 +156,11 @@ void getdata(void) /* read input */ char *buf = NULL, *buf1 = NULL; size_t size = 0; int ln; - char *fgetline(char **, size_t *, size_t *, FILE *); fin = curfile->fin; curfile->lineno = 0; printf(".lf 1 %s\n", curfile->fname); - while (fgetline(&buf, &size, NULL, fin) != NULL) { + while (getline(&buf, &size, fin) > 0) { curfile->lineno++; if (*buf == '.' && *(buf+1) == 'G' && *(buf+2) == '1') { setup(); diff --git a/grap/misc.c b/grap/misc.c index fa0360403b81..13e947d02cc0 100644 --- a/grap/misc.c +++ b/grap/misc.c @@ -45,14 +45,11 @@ void setsize(int op, double expr) char *tostring(char *s) { - register char *p; - size_t l; + char *p; - l = strlen(s)+1; - p = malloc(l); + p = strdup(s); if (p == NULL) FATAL("out of space in tostring on %s", s); - n_strcpy(p, s, l); return(p); } diff --git a/include/global.h b/include/global.h index 8e41045d1aa8..e0a1c31135b9 100644 --- a/include/global.h +++ b/include/global.h @@ -15,3 +15,23 @@ #else # define n_wcscpy(dst, src, size ) wcscpy(dst, src) #endif + +#define min(x,y) ((x) < (y) ? (x) : (y)) +#define max(x,y) ((x) > (y) ? (x) : (y)) +#define prefix(str, pfx) (strncmp(pfx, str, strlen(pfx)) == 0) + +#undef __unused +#define __unused __attribute__((unused)) + +#ifdef __GLIBC__ +#ifdef _IO_getc_unlocked +#undef getc +#define getc(f) _IO_getc_unlocked(f) +#endif +#ifdef _IO_putc_unlocked +#undef putc +#undef putchar +#define putc(c, f) _IO_putc_unlocked(c, f) +#define putchar(c) _IO_putc_unlocked(c, stdout) +#endif +#endif diff --git a/mpm/Makefile.mk b/mpm/Makefile.mk index 849a45041259..cc6e7892d6f4 100644 --- a/mpm/Makefile.mk +++ b/mpm/Makefile.mk @@ -1,6 +1,6 @@ OBJ = misc.o page.o queue.o range.o slug.o version.o -FLAGS = $(EUC) $(DEFINES) +FLAGS = $(EUC) $(DEFINES) -I../include .c.o: $(CC) $(CFLAGS) $(WARN) $(FLAGS) $(CPPFLAGS) -c $< diff --git a/mpm/misc.h b/mpm/misc.h index d46efd75be4c..75aed6cff620 100644 --- a/mpm/misc.h +++ b/mpm/misc.h @@ -16,20 +16,8 @@ #include <math.h> #include <ctype.h> #include <string.h> +#include "global.h" -#ifdef __GLIBC__ -#ifdef _IO_getc_unlocked -#undef getc -#define getc(f) _IO_getc_unlocked(f) -#endif -#ifdef _IO_putc_unlocked -#undef putc -#undef putchar -#define putc(c, f) _IO_putc_unlocked(c, f) -#define putchar(c) _IO_putc_unlocked(c, stdout) -#endif -#endif /* __GLIBC__ */ - extern char *progname; extern int linenum; extern int wantwarn; @@ -39,11 +27,6 @@ extern void WARNING(const char *, ...); #define eq(s,t) (strcmp(s,t) == 0) -inline int max(int x, int y) { return x > y ? x : y; } -inline int min(int x, int y) { return x > y ? y : x; } -// already defined in stdlib.h: -//inline int abs(int x) { return (x >= 0) ? x : -x; } - extern int dbg; extern int pn, userpn; // actual and user-defined page numbers diff --git a/pic/arcgen.c b/pic/arcgen.c index c828fef601d5..2e1f850e879d 100644 --- a/pic/arcgen.c +++ b/pic/arcgen.c @@ -30,7 +30,7 @@ obj *arcgen(int type) /* handles circular and (eventually) elliptical arcs */ static int nexthv[2][4] ={ {U_DIR, L_DIR, D_DIR, R_DIR}, {D_DIR, R_DIR, U_DIR, L_DIR} }; double dx2, dy2, ht, phi, r, d; - int i, head, to, at, cw, invis, ddtype, battr; + int i, head, to, at, _cw, invis, ddtype, battr; obj *p, *ppos; double fromx, fromy, tox = 0, toy = 0, fillval = 0; Attr *ap; @@ -40,7 +40,7 @@ obj *arcgen(int type) /* handles circular and (eventually) elliptical arcs */ prevw = getfval("arrowwid"); fromx = curx; fromy = cury; - head = to = at = cw = invis = ddtype = battr = 0; + head = to = at = _cw = invis = ddtype = battr = 0; for (i = 0; i < nattr; i++) { ap = &attr[i]; switch (ap->a_type) { @@ -66,7 +66,7 @@ obj *arcgen(int type) /* handles circular and (eventually) elliptical arcs */ prevrad = ap->a_val.f / 2; break; case CW: - cw = 1; + _cw = 1; break; case FROM: /* start point of arc */ ppos = ap->a_val.o; @@ -107,16 +107,16 @@ obj *arcgen(int type) /* handles circular and (eventually) elliptical arcs */ } } if (!at && !to) { /* the defaults are mostly OK */ - curx = fromx + prevrad * dctrx[cw][hvmode]; - cury = fromy + prevrad * dctry[cw][hvmode]; - tox = fromx + prevrad * dtox[cw][hvmode]; - toy = fromy + prevrad * dtoy[cw][hvmode]; - hvmode = nexthv[cw][hvmode]; + curx = fromx + prevrad * dctrx[_cw][hvmode]; + cury = fromy + prevrad * dctry[_cw][hvmode]; + tox = fromx + prevrad * dtox[_cw][hvmode]; + toy = fromy + prevrad * dtoy[_cw][hvmode]; + hvmode = nexthv[_cw][hvmode]; } else if (!at) { dx2 = (tox - fromx) / 2; dy2 = (toy - fromy) / 2; - phi = atan2(dy2, dx2) + (cw ? -PI/2 : PI/2); + phi = atan2(dy2, dx2) + (_cw ? -PI/2 : PI/2); if (prevrad <= 0.0) prevrad = dx2*dx2+dy2*dy2; for (r=prevrad; (d = r*r - (dx2*dx2+dy2*dy2)) <= 0.0; r *= 2) @@ -129,11 +129,11 @@ obj *arcgen(int type) /* handles circular and (eventually) elliptical arcs */ dx2, dy2, phi, r, ht); } else if (at && !to) { /* do we have all the cases??? */ - tox = fromx + prevrad * dtox[cw][hvmode]; - toy = fromy + prevrad * dtoy[cw][hvmode]; - hvmode = nexthv[cw][hvmode]; + tox = fromx + prevrad * dtox[_cw][hvmode]; + toy = fromy + prevrad * dtoy[_cw][hvmode]; + hvmode = nexthv[_cw][hvmode]; } - if (cw) { /* interchange roles of from-to and heads */ + if (_cw) { /* interchange roles of from-to and heads */ double temp; temp = fromx; fromx = tox; tox = temp; temp = fromy; fromy = toy; toy = temp; @@ -148,7 +148,7 @@ obj *arcgen(int type) /* handles circular and (eventually) elliptical arcs */ p->o_val[1] = fromy; p->o_val[2] = tox; p->o_val[3] = toy; - if (cw) { + if (_cw) { curx = fromx; cury = fromy; } else { @@ -158,7 +158,7 @@ obj *arcgen(int type) /* handles circular and (eventually) elliptical arcs */ p->o_val[4] = prevw; p->o_val[5] = prevh; p->o_val[6] = prevrad; - p->o_attr = head | (cw ? CW_ARC : 0) | invis | ddtype | battr; + p->o_attr = head | (_cw ? CW_ARC : 0) | invis | ddtype | battr; p->o_fillval = fillval; if (head) p->o_nhead = getfval("arrowhead"); @@ -191,36 +191,36 @@ void arc_extreme(double x0, double y0, double x1, double y1, double xc, double y /* start, end, center */ { /* assumes center isn't too far out */ - double r, xmin, ymin, xmax, ymax; + double r, _xmin, _ymin, _xmax, _ymax; int j, k; x0 -= xc; y0 -= yc; /* move to center */ x1 -= xc; y1 -= yc; - xmin = (x0<x1)?x0:x1; ymin = (y0<y1)?y0:y1; - xmax = (x0>x1)?x0:x1; ymax = (y0>y1)?y0:y1; + _xmin = (x0<x1)?x0:x1; _ymin = (y0<y1)?y0:y1; + _xmax = (x0>x1)?x0:x1; _ymax = (y0>y1)?y0:y1; r = sqrt(x0*x0 + y0*y0); if (r > 0.0) { j = quadrant(x0,y0); k = quadrant(x1,y1); if (j == k && y1*x0 < x1*y0) { /* viewed as complex numbers, if Im(z1/z0)<0, arc is big */ - if( xmin > -r) xmin = -r; if( ymin > -r) ymin = -r; - if( xmax < r) xmax = r; if( ymax < r) ymax = r; + if( _xmin > -r) _xmin = -r; if( _ymin > -r) _ymin = -r; + if( _xmax < r) _xmax = r; if( _ymax < r) _ymax = r; } else { while (j != k) { switch (j) { - case 1: if( ymax < r) ymax = r; break; /* north */ - case 2: if( xmin > -r) xmin = -r; break; /* west */ - case 3: if( ymin > -r) ymin = -r; break; /* south */ - case 4: if( xmax < r) xmax = r; break; /* east */ + case 1: if( _ymax < r) _ymax = r; break; /* north */ + case 2: if( _xmin > -r) _xmin = -r; break; /* west */ + case 3: if( _ymin > -r) _ymin = -r; break; /* south */ + case 4: if( _xmax < r) _xmax = r; break; /* east */ } j = j%4 + 1; } } } - xmin += xc; ymin += yc; - xmax += xc; ymax += yc; - extreme(xmin, ymin); - extreme(xmax, ymax); + _xmin += xc; _ymin += yc; + _xmax += xc; _ymax += yc; + extreme(_xmin, _ymin); + extreme(_xmax, _ymax); } int diff --git a/pic/blockgen.c b/pic/blockgen.c index 6489a2e6f789..866183a37f0a 100644 --- a/pic/blockgen.c +++ b/pic/blockgen.c @@ -20,8 +20,8 @@ struct pushstack stack[NBRACK]; int nstack = 0; -struct pushstack bracestack[NBRACE]; -int nbstack = 0; +static struct pushstack bracestack[NBRACE]; +static int nbstack = 0; void blockadj(obj *); diff --git a/pic/for.c b/pic/for.c index 9323aecae54a..d2f08cb1f210 100644 --- a/pic/for.c +++ b/pic/for.c @@ -25,10 +25,10 @@ typedef struct { char *str; /* string to push back */ } For; -For forstk[10]; /* stack of for loops */ -For *forp = forstk; /* pointer to current top */ +static For forstk[10]; /* stack of for loops */ +static For *forp = forstk; /* pointer to current top */ -void setfval(char *, double); +void setfval(const char *, double); void nextfor(void); void forloop(char *var, double from, double to, int op, diff --git a/pic/input.c b/pic/input.c index 900d98557676..d052f67ed5a9 100644 --- a/pic/input.c +++ b/pic/input.c @@ -18,11 +18,6 @@ #include "pic.h" #include "y.tab.h" -#if defined (__GLIBC__) && defined (_IO_getc_unlocked) -#undef getc -#define getc(f) _IO_getc_unlocked(f) -#endif - Infile infile[10]; Infile *curfile = infile; @@ -33,10 +28,12 @@ Src *srcp = src; void do_thru(void); int nextchar(void); int getarg(char *); -void freedef(char *); -int baldelim(int, char *); +int baldelim(int, const char *); +static void popsrc(void); + +static char *addnewline(char *); -void pushsrc(int type, char *ptr) /* new input source */ +void pushsrc(int type, const char *ptr) /* new input source */ { if (++srcp >= src + MAXSRC) FATAL("inputs nested too deep"); @@ -70,7 +67,7 @@ void pushsrc(int type, char *ptr) /* new input source */ } } -void popsrc(void) /* restore an old one */ +static void popsrc(void) /* restore an old one */ { if (srcp <= src) FATAL("too many inputs popped"); @@ -102,7 +99,7 @@ void popsrc(void) /* restore an old one */ srcp--; } -void definition(char *s) /* collect definition for s and install */ +void definition(const char *s) /* collect definition for s and install */ /* definitions picked up lexically */ { char *p; @@ -125,7 +122,7 @@ void definition(char *s) /* collect definition for s and install */ dprintf("installing %s as `%s'\n", s, p); } -char *delimstr(char *s) /* get body of X ... X */ +char *delimstr(const char *s) /* get body of X ... X */ /* message if too big */ { int c, delim, rdelim, n, deep; @@ -160,7 +157,7 @@ char *delimstr(char *s) /* get body of X ... X */ return tostring(buf); } -int baldelim(int c, char *s) /* replace c by balancing entry in s */ +int baldelim(int c, const char *s) /* replace c by balancing entry in s */ { for ( ; *s; s += 2) if (*s == c) @@ -178,9 +175,9 @@ void undefine(char *s) /* undefine macro */ } -Arg args[10]; /* argument frames */ -Arg *argfp = args; /* frame pointer */ -int argcnt; /* number of arguments seen so far */ +static Arg args[10]; /* argument frames */ +static Arg *argfp = args; /* frame pointer */ +static int argcnt; /* number of arguments seen so far */ void dodef(struct symtab *stp) /* collect args and switch input to defn */ { @@ -239,13 +236,13 @@ int getarg(char *p) /* pick up single argument, store in p, return length */ } #define PBSIZE 2000 -char pbuf[PBSIZE]; /* pushback buffer */ -char *pb = pbuf-1; /* next pushed back character */ +static char pbuf[PBSIZE]; /* pushback buffer */ +static char *pb = pbuf-1; /* next pushed back character */ -char ebuf[200]; /* collect input here for error reporting */ -char *ep = ebuf; +static char ebuf[200]; /* collect input here for error reporting */ +static char *ep = ebuf; -int begin = 0; +static int begin = 0; extern int thru; extern struct symtab *thrudef; extern char *untilstr; @@ -429,7 +426,7 @@ int unput(int c) return c; } -void pbstr(char *s) +void pbstr(const char *s) { pushsrc(String, s); } @@ -450,7 +447,6 @@ void eprint(void); void yyerror(char *s) { - extern char *cmdname; int ern = errno; /* cause some libraries clobber it */ if (synerr) @@ -498,7 +494,7 @@ void eprint(void) /* try to print context around error */ void yywrap(void) {} -char *newfile = 0; /* filename for file copy */ +static char *newfile = 0; /* filename for file copy */ char *untilstr = 0; /* string that terminates a thru */ int thru = 0; /* 1 if copying thru macro */ struct symtab *thrudef = 0; /* macro being used */ @@ -513,7 +509,7 @@ void copydef(struct symtab *p) /* remember macro symtab ptr */ thrudef = p; } -struct symtab *copythru(char *s) /* collect the macro name or body for thru */ +struct symtab *copythru(const char *s) /* collect the macro name or body for thru */ { struct symtab *p; char *q, *addnewline(char *); @@ -545,7 +541,7 @@ struct symtab *copythru(char *s) /* collect the macro name or body for thru */ return p; } -char *addnewline(char *p) /* add newline to end of p */ +static char *addnewline(char *p) /* add newline to end of p */ { int n; @@ -584,7 +580,7 @@ void copy(void) /* begin input from file, etc. */ } } -char shellbuf[1000], *shellp; +static char shellbuf[1000], *shellp; void shell_init(void) /* set up to interpret a shell command */ { @@ -608,33 +604,3 @@ void shell_exec(void) /* do it */ else system(shellbuf); } - -#define LSIZE 128 - -char *fgetline(char **line, size_t *linesize, size_t *llen, FILE *fp) -{ - int c; - size_t n = 0; - - if (*line == NULL || *linesize < LSIZE + n + 1) - *line = realloc(*line, *linesize = LSIZE + n + 1); - for (;;) { - if (n >= *linesize - LSIZE / 2) - *line = realloc(*line, *linesize += LSIZE); - c = getc(fp); - if (c != EOF) { - (*line)[n++] = c; - (*line)[n] = '\0'; - if (c == '\n') - break; - } else { - if (n > 0) - break; - else - return NULL; - } - } - if (llen) - *llen = n; - return *line; -} diff --git a/pic/main.c b/pic/main.c index 2dc452dec061..75ed59185837 100644 --- a/pic/main.c +++ b/pic/main.c @@ -44,9 +44,8 @@ double deltx = 6; /* max x value in output, for scaling */ double delty = 6; /* max y value in output, for scaling */ int dbg = 0; int lineno = 0; -char *filename = "-"; int synerr = 0; -int anyerr = 0; /* becomes 1 if synerr ever 1 */ +static int anyerr = 0; /* becomes 1 if synerr ever 1 */ char *cmdname; int Sflag; @@ -57,7 +56,6 @@ double ymax = -30000; void fpecatch(int); void getdata(void), setdefaults(void); -void setfval(char *, double); int getpid(void); int @@ -122,7 +120,7 @@ void fpecatch(int n) FATAL("floating point exception %d", n); } -char *grow(char *ptr, char *name, int num, int size) /* make array bigger */ +char *grow(char *ptr, const char *name, int num, int size) /* make array bigger */ { char *p; @@ -136,7 +134,7 @@ char *grow(char *ptr, char *name, int num, int size) /* make array bigger */ } static struct { - char *name; + const char *name; double val; short scalable; /* 1 => adjust when "scale" changes */ } defaults[] ={ @@ -210,13 +208,12 @@ void getdata(void) char *p, *buf = NULL, *buf1 = NULL; size_t size = 0; int ln; - void reset(void), openpl(char *), closepl(char *), print(void); + void reset(void), openpl(char *), closepl(char *); int yyparse(void); - char *fgetline(char **, size_t *, size_t *, FILE *); curfile->lineno = 0; printlf(1, curfile->fname); - while (fgetline(&buf, &size, NULL, curfile->fin) != NULL) { + while (getline(&buf, &size, curfile->fin) > 0) { curfile->lineno++; if (buf[0] == '.' && buf[1] == 'l' && buf[2] == 'f') { buf1 = realloc(buf1, size); @@ -289,7 +286,6 @@ void reset(void) obj *op; int i; extern int nstack; - extern void freesymtab(struct symtab *); for (i = 0; i < nobj; i++) { op = objlist[i]; diff --git a/pic/misc.c b/pic/misc.c index 4aa9b06d5c4c..73ea3d7db771 100644 --- a/pic/misc.c +++ b/pic/misc.c @@ -93,8 +93,8 @@ double getcomp(obj *p, int t) /* return component of a position */ return 0; } -double exprlist[100]; -int nexpr = 0; +static double exprlist[100]; +static int nexpr = 0; void exprsave(double f) { @@ -177,16 +177,13 @@ void printpos(obj *p) /* print position for debugging */ printf("%g, %g\n", p->o_x, p->o_y); } -char *tostring(char *s) +char *tostring(const char *s) { - register char *p; - size_t l; + char *p; - l = strlen(s)+1; - p = malloc(l); + p = strdup(s); if (p == NULL) FATAL("out of space in tostring on %s", s); - n_strcpy(p, s, l); return(p); } diff --git a/pic/pic.h b/pic/pic.h index de6a8cc05d31..e6f614d230ae 100644 --- a/pic/pic.h +++ b/pic/pic.h @@ -162,24 +162,33 @@ extern int hvmode; extern int codegen; extern char *PEstring; extern int Sflag; +extern char *cmdname; -char *tostring(char *); -char *grow(char *, char *, int, int); -double getfval(char *), getcomp(obj *, int), getblkvar(obj *, char *); -YYSTYPE getvar(char *); -struct symtab *lookup(char *), *makevar(char *, int, YYSTYPE); -char *ifstat(double, char *, char *), *delimstr(char *), *sprintgen(char *); +char *tostring(const char *); +char *grow(char *, const char *, int, int); +double getfval(const char *), getcomp(obj *, int), getblkvar(obj *, char *); +YYSTYPE getvar(const char *); +struct symtab *lookup(const char *), *makevar(char *, int, YYSTYPE); +char *ifstat(double, char *, char *), *delimstr(const char *), *sprintgen(char *); void forloop(char *var, double from, double to, int op, double by, char *_str); int setdir(int), curdir(void); +void pbstr(const char *); +void endfor(void); +void dodef(struct symtab *stp); +void freedef(char *); +void undefine(char *s); +void print(void); void resetvar(void); void checkscale(char *); -void pushsrc(int, char *); +void pushsrc(int, const char *); void copy(void); void copyuntil(char *); void copyfile(char *); void copydef(struct symtab *); -void definition(char *); -struct symtab *copythru(char *); +void definition(const char *); +void freesymtab(struct symtab *); +void setfval(const char *s, double f); +struct symtab *copythru(const char *); #ifdef FLEX_SCANNER int xxinput(void); int xxunput(int); @@ -190,6 +199,9 @@ int input(void); int unput(int); #endif /* !FLEX_SCANNER */ void extreme(double, double); +void shell_exec(void); +void shell_init(void); +void shell_text(char *); extern double deltx, delty; extern int lineno; @@ -219,6 +231,22 @@ void printpos(obj *); void exprsave(double); void addtattr(int); void printlf(int, char *); +void openpl(char *); +void closepl(char *); +void hvflush(void); +void flyback(void); +void troff(char *); +void label(char *, int, int); +void line(double, double, double, double); +void fillstart(double); +void fillend(int, int); +void box(double, double, double, double); +void circle(double, double, double); +void spline(double, double, double, ofloat *, int, double); +void ellipse(double, double, double, double); +void arc(double, double, double, double, double, double); +void dot(void); +void arrow(double, double, double, double, double, double, double, int); struct pushstack { double p_x; diff --git a/pic/picl.l b/pic/picl.l index f1c2d80e3ac2..bffecb429081 100644 --- a/pic/picl.l +++ b/pic/picl.l @@ -43,15 +43,8 @@ #define witchcraft yybgin-yysvec-1 #endif /* !FLEX_SCANNER */ -extern char *filename; extern struct symtab symtab[]; -void pbstr(char *); -void dodef(struct symtab *stp); -void undefine(char *s); -void shell_init(void), shell_exec(void), shell_text(char *); -void endfor(void); - int yyback(int *, int); int yylook(void); int yywrap(void); @@ -59,9 +52,9 @@ int yywrap(void); #define CADD cbuf[clen++]=yytext[0]; \ if (clen>=CBUFLEN-1) { WARNING("string too long", cbuf); BEGIN A; } #define CBUFLEN 500 -char cbuf[CBUFLEN]; -int c, clen, cflag, delim; -int ifsw = 0; /* 1 if if statement in progress */ +static char cbuf[CBUFLEN]; +static int c, clen, delim; +static int ifsw = 0; /* 1 if if statement in progress */ %} A [a-zA-Z_] @@ -304,10 +297,3 @@ FWS ([ \t]|\\\n) <A>. return(yylval.i = yytext[0]); %% - -#ifdef FLEX_SCANNER -void xxcruft(void) -{ - unput(0); -} -#endif /* FLEX_SCANNER */ diff --git a/pic/pltroff.c b/pic/pltroff.c index 5ec5f5396536..051906babfbd 100644 --- a/pic/pltroff.c +++ b/pic/pltroff.c @@ -14,32 +14,27 @@ #include <math.h> #include <string.h> #include "pic.h" -extern int dbg; -#define abs(n) (n >= 0 ? n : -(n)) -#define max(x,y) ((x)>(y) ? (x) : (y)) +extern int dbg; -char *textshift = "\\v'.2m'"; /* move text this far down */ +static const char *textshift = "\\v'.2m'"; /* move text this far down */ /* scaling stuff defined by s command as X0,Y0 to X1,Y1 */ /* output dimensions set by -l,-w options to 0,0 to hmax, vmax */ /* default output is 6x6 inches */ -double xscale; -double yscale; - -double hpos = 0; /* current horizontal position in output coordinate system */ -double vpos = 0; /* current vertical position; 0 is top of page */ +static double xscale; +static double yscale; -double htrue = 0; /* where we really are */ -double vtrue = 0; +static double hpos = 0; /* current horizontal position in output coordinate system */ +static double vpos = 0; /* current vertical position; 0 is top of page */ -double X0, Y0; /* left bottom of input */ -double X1, Y1; /* right top of input */ +static double htrue = 0; /* where we really are */ +static double vtrue = 0; -double hmax; /* right end of output */ -double vmax; /* top of output (down is positive) */ +static double X0, Y0; /* left bottom of input */ +static double X1, Y1; /* right top of input */ extern double deltx; extern double delty; @@ -157,11 +152,6 @@ void vgoto(double n) vpos = n; } -double fabs(double x) -{ - return x < 0 ? -x : x; -} - void hvflush(void) /* get to proper point for output */ { if (fabs(hpos-htrue) >= 0.0005) { @@ -264,7 +254,7 @@ void arrow(double x0, double y0, double x1, double y1, double w, double h, printf(".\\}\n"); } -double lastgray = 0; +static double lastgray = 0; void fillstart(double v) /* this works only for postscript, obviously. */ { /* uses drechsler's dpost conventions... */ @@ -274,7 +264,7 @@ void fillstart(double v) /* this works only for postscript, obviously. */ flyback(); } -void fillend(int vis, int fill) +void fillend(int vis, int fill __unused) { hvflush(); printf("\\X'EndObject gsave eofill grestore %g setgray %s'\n", @@ -325,7 +315,7 @@ void circle(double x, double y, double r) flyback(); } -void spline(double x, double y, double n, ofloat *p, int dashed, double ddval) +void spline(double x, double y, double n, ofloat *p, int dashed __unused, double ddval __unused) { int i; double dx, dy; @@ -354,7 +344,7 @@ void ellipse(double x, double y, double r1, double r2) hvflush(); ir1 = xsc(r1); ir2 = ysc(r2); - printf("\\D'e%.3fi %.3fi'\n", 2 * ir1, 2 * abs(ir2)); + printf("\\D'e%.3fi %.3fi'\n", 2 * ir1, 2 * fabs(ir2)); flyback(); } diff --git a/pic/symtab.c b/pic/symtab.c index d2bb09c7a147..9ef859b522e4 100644 --- a/pic/symtab.c +++ b/pic/symtab.c @@ -17,7 +17,7 @@ #include "pic.h" #include "y.tab.h" -YYSTYPE getvar(char *s) /* return value of variable s (usually pointer) */ +YYSTYPE getvar(const char *s) /* return value of variable s (usually pointer) */ { struct symtab *p; static YYSTYPE bug; @@ -33,7 +33,7 @@ YYSTYPE getvar(char *s) /* return value of variable s (usually pointer) */ return(p->s_val); } -double getfval(char *s) /* return float value of variable s */ +double getfval(const char *s) /* return float value of variable s */ { YYSTYPE y; @@ -41,7 +41,7 @@ double getfval(char *s) /* return float value of variable s */ return y.f; } -void setfval(char *s, double f) /* set variable s to f */ +void setfval(const char *s, double f) /* set variable s to f */ { struct symtab *p; @@ -70,7 +70,7 @@ struct symtab *makevar(char *s, int t, YYSTYPE v) /* make variable named s in ta return(p); } -struct symtab *lookup(char *s) /* find s in symtab */ +struct symtab *lookup(const char *s) /* find s in symtab */ { int i; struct symtab *p; diff --git a/picpack/Makefile.mk b/picpack/Makefile.mk index cf72048bbdda..2dbad352069a 100644 --- a/picpack/Makefile.mk +++ b/picpack/Makefile.mk @@ -1,4 +1,4 @@ -OBJ = picpack.o getopt.o +OBJ = picpack.o FLAGS = -I../troff/troff.d/dpost.d diff --git a/picpack/getopt.c b/picpack/getopt.c deleted file mode 100644 index bb8c53d072cb..000000000000 --- a/picpack/getopt.c +++ /dev/null @@ -1,222 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ -/* - * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany - * - * Sccsid @(#)getopt.c 1.10 (gritter) 12/16/07 - */ -/* from OpenSolaris "getopt.c 1.23 05/06/08 SMI" */ - -/* Copyright (c) 1988 AT&T */ -/* All Rights Reserved */ - - -/* - * See getopt(3C) and SUS/XPG getopt() for function definition and - * requirements. - * - * This actual implementation is a bit looser than the specification - * as it allows any character other than ':' to be used as an option - * character - The specification only guarantees the alnum characters - * ([a-z][A-Z][0-9]). - */ - -#include <sys/types.h> -#include <string.h> -#include <stdio.h> - -extern ssize_t write(int, const void *, size_t); - -char *optarg = NULL; -int optind = 1; -int opterr = 1; -int optopt = 0; - -#define ERR(s, c) err(s, c, optstring, argv[0]) -static void -err(const char *s, int c, const char *optstring, const char *argv0) -{ - char errbuf[256], *ep = errbuf; - const char *cp; - - if (opterr && optstring[0] != ':') { - for (cp = argv0; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++) - *ep = *cp; - for (cp = ": "; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++) - *ep = *cp; - for (cp = s; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++) - *ep = *cp; - for (cp = " -- "; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++) - *ep = *cp; - if (ep<&errbuf[sizeof errbuf]) - *ep++ = c; - if (ep<&errbuf[sizeof errbuf]) - *ep++ = '\n'; - write(2, errbuf, ep - errbuf); - } -} - -/* - * getopt_sp is required to keep state between successive calls to getopt() - * while extracting aggregated options (ie: -abcd). Hence, getopt() is not - * thread safe or reentrant, but it really doesn't matter. - * - * So, why isn't this "static" you ask? Because the historical Bourne - * shell has actually latched on to this little piece of private data. - */ -int getopt_sp = 1; - -/* - * Determine if the specified character (c) is present in the string - * (optstring) as a regular, single character option. If the option is found, - * return a pointer into optstring pointing at the option character, - * otherwise return null. The character ':' is not allowed. - */ -static char * -parse(const char *optstring, const char c) -{ - char *cp = (char *)optstring; - - if (c == ':') - return (NULL); - do { - if (*cp == c) - return (cp); - } while (*cp++ != '\0'); - return (NULL); -} - -/* - * External function entry point. - */ -int -getopt(int argc, char *const *argv, const char *optstring) -{ - char c; - char *cp; - - /* - * Has the end of the options been encountered? The following - * implements the SUS requirements: - * - * If, when getopt() is called: - * argv[optind] is a null pointer - * *argv[optind] is not the character '-' - * argv[optind] points to the string "-" - * getopt() returns -1 without changing optind. If - * argv[optind] points to the string "--" - * getopt() returns -1 after incrementing optind. - */ - if (getopt_sp == 1) { - if (optind >= argc || argv[optind][0] != '-' || - argv[optind] == NULL || argv[optind][1] == '\0') - return (EOF); - else if (strcmp(argv[optind], "--") == 0) { - optind++; - return (EOF); - } - } - - /* - * Getting this far indicates that an option has been encountered. - * Note that the syntax of optstring applies special meanings to - * the characters ':' and '(', so they are not permissible as - * option letters. A special meaning is also applied to the ')' - * character, but its meaning can be determined from context. - * Note that the specification only requires that the alnum - * characters be accepted. - */ - optopt = c = (unsigned char)argv[optind][getopt_sp]; - optarg = NULL; - if ((cp = parse(optstring, c)) == NULL) { - /* LINTED: variable format specifier */ - ERR("illegal option", c); - if (argv[optind][++getopt_sp] == '\0') { - optind++; - getopt_sp = 1; - } - return ('?'); - } - optopt = c = *cp; - - /* - * A valid option has been identified. If it should have an - * option-argument, process that now. SUS defines the setting - * of optarg as follows: - * - * 1. If the option was the last character in the string pointed to - * by an element of argv, then optarg contains the next element - * of argv, and optind is incremented by 2. If the resulting - * value of optind is not less than argc, this indicates a - * missing option-argument, and getopt() returns an error - * indication. - * - * 2. Otherwise, optarg points to the string following the option - * character in that element of argv, and optind is incremented - * by 1. - * - * The second clause allows -abcd (where b requires an option-argument) - * to be interpreted as "-a -b cd". - */ - if (*(cp + 1) == ':') { - /* The option takes an argument */ - if (argv[optind][getopt_sp+1] != '\0') { - optarg = &argv[optind++][getopt_sp+1]; - } else if (++optind >= argc) { - /* LINTED: variable format specifier */ - ERR("option requires an argument", c); - getopt_sp = 1; - optarg = NULL; - return (optstring[0] == ':' ? ':' : '?'); - } else - optarg = argv[optind++]; - getopt_sp = 1; - } else { - /* The option does NOT take an argument */ - if (argv[optind][++getopt_sp] == '\0') { - getopt_sp = 1; - optind++; - } - optarg = NULL; - } - return (c); -} /* getopt() */ - -#ifdef __APPLE__ -/* - * Starting with Mac OS 10.5 Leopard, <unistd.h> turns getopt() - * into getopt$UNIX2003() by default. Consequently, this function - * is called instead of the one defined above. However, optind is - * still taken from this file, so in effect, options are not - * properly handled. Defining an own getopt$UNIX2003() function - * works around this issue. - */ -int -getopt$UNIX2003(int argc, char *const argv[], const char *optstring) -{ - return getopt(argc, argv, optstring); -} -#endif /* __APPLE__ */ diff --git a/picpack/picpack.c b/picpack/picpack.c index 5401b00aaea6..52976a577c65 100644 --- a/picpack/picpack.c +++ b/picpack/picpack.c @@ -112,7 +112,7 @@ static const char sccsid[] USED = "@(#)picpack.sl 5.1 (gritter) 10/25/05"; #include "glob.c" -static char *keys[11] = {".BP", ".PI", NULL}; +static const char *keys[11] = {".BP", ".PI", NULL}; static int quiet = FALSE; static FILE *fp_in; /* input */ @@ -126,8 +126,6 @@ static void do_inline(char *); static int gotpicfile(char *); static void addpicfile(char *); -char *fgetline(char **line, size_t *linesize, size_t *llen, FILE *fp); - /*****************************************************************************/ @@ -418,7 +416,7 @@ picpack(void) */ - while ( fgetline(&line, &linesize, NULL, fp_in) != NULL ) { + while ( getline(&line, &linesize, fp_in) > 0 ) { for ( i = 0; keys[i] != NULL; i++ ) if ( strncmp(line, keys[i], strlen(keys[i])) == 0 ) { if ( sscanf(line, "%*s %s", name) == 1 ) { @@ -564,53 +562,6 @@ addpicfile(char *name) } /* End of addpicfile */ -/*****************************************************************************/ - -void * -srealloc(void *p, size_t size) -{ - if ((p = realloc(p, size)) == NULL) { - write(2, "Can't malloc\n", 13); - _exit(0177); - } - return p; -} - -#define LSIZE 128 /* initial line size */ - -#if defined (__GLIBC__) && defined (_IO_getc_unlocked) -#undef getc -#define getc(f) _IO_getc_unlocked(f) -#endif - -char * -fgetline(char **line, size_t *linesize, size_t *llen, FILE *fp) -{ - int c; - size_t n = 0; - - if (*line == NULL || *linesize < LSIZE + n + 1) - *line = srealloc(*line, *linesize = LSIZE + n + 1); - for (;;) { - if (n >= *linesize - LSIZE / 2) - *line = srealloc(*line, *linesize += LSIZE); - c = getc(fp); - if (c != EOF) { - (*line)[n++] = c; - (*line)[n] = '\0'; - if (c == '\n') - break; - } else { - if (n > 0) - break; - else - return NULL; - } - } - if (llen) - *llen = n; - return *line; -} /* from OpenSolaris "misc.c 1.6 05/06/08 SMI" */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ @@ -622,7 +573,7 @@ fgetline(char **line, size_t *linesize, size_t *llen, FILE *fp) * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany */ void -error(int kind, char *mesg, ...) +error(int kind, const char *mesg, ...) { diff --git a/ptx/Makefile.mk b/ptx/Makefile.mk index dfef54161fe5..c20c920512fb 100644 --- a/ptx/Makefile.mk +++ b/ptx/Makefile.mk @@ -1,6 +1,6 @@ OBJ = ptx.o -FLAGS = -DLIBDIR='"$(LIBDIR)"' $(EUC) +FLAGS = -DLIBDIR='"$(LIBDIR)"' $(EUC) -I../include .c.o: $(CC) $(CFLAGS) $(WARN) $(CPPFLAGS) $(FLAGS) -c $< diff --git a/ptx/ptx.c b/ptx/ptx.c index 1a07f3d5179c..26f1c13f73ca 100644 --- a/ptx/ptx.c +++ b/ptx/ptx.c @@ -76,6 +76,8 @@ static const char sccsid[] USED = "@(#)/usr/ucb/ptx.sl 1.5 (gritter) 11/6/05"; #include <unistd.h> #include <locale.h> #include <limits.h> +#include "global.h" + #define DEFLTX LIBDIR "/eign" #define TILDE 0177 #define SORT "sort" @@ -87,17 +89,6 @@ static const char sccsid[] USED = "@(#)/usr/ucb/ptx.sl 1.5 (gritter) 11/6/05"; #define isabreak(c) (btable[c]) -#ifdef __GLIBC__ -#ifdef _IO_getc_unlocked -#undef getc -#define getc(f) _IO_getc_unlocked(f) -#endif -#ifdef _IO_putc_unlocked -#undef putc -#define putc(c, f) _IO_putc_unlocked(c, f) -#endif -#endif - #define getline xxgetline static int status; @@ -125,7 +116,7 @@ static int wlen; static int rflag; static int halflen; static wchar_t *strtbufp, *endbufp; -static char *empty = ""; +static const char *empty = ""; static char *infile; static FILE *inptr /*= stdin*/; @@ -149,8 +140,8 @@ static void cmpline(const wchar_t *); static int cmpword(const wchar_t *, const wchar_t *, const wchar_t *); static void putline(const wchar_t *, const wchar_t *); static void getsort(void); -static wchar_t *rtrim(const wchar_t *, const wchar_t *, int); -static wchar_t *ltrim(const wchar_t *, const wchar_t *, int); +static const wchar_t *rtrim(const wchar_t *, const wchar_t *, int); +static const wchar_t *ltrim(const wchar_t *, const wchar_t *, int); static void putout(const wchar_t *, const wchar_t *); static void onintr(int); static int hash(const wchar_t *, const wchar_t *); @@ -236,7 +227,7 @@ main(int argc,char **argv) int pid; wchar_t *pend; - char *xfile; + const char *xfile; FILE *xptr; setlocale(LC_CTYPE, ""); @@ -543,7 +534,7 @@ getsort(void) { register int c; register wchar_t *tilde = NULL, *linep, *ref; - wchar_t *p1a,*p1b,*p2a,*p2b,*p3a,*p3b,*p4a,*p4b; + const wchar_t *p1a,*p1b,*p2a,*p2b,*p3a,*p3b,*p4a,*p4b; int w; if((sortptr = fopen(sortfile,"r")) == NULL) @@ -618,7 +609,7 @@ getsort(void) } } -static wchar_t * +static const wchar_t * rtrim(const wchar_t *a,const wchar_t *c,int d) { const wchar_t *b,*x; @@ -628,10 +619,10 @@ rtrim(const wchar_t *a,const wchar_t *c,int d) b = x; if(b<c&&!iswspace(b[0])) b++; - return((wchar_t *)b); + return(b); } -static wchar_t * +static const wchar_t * ltrim(const wchar_t *c,const wchar_t *b,int d) { const wchar_t *a,*x; @@ -641,7 +632,7 @@ ltrim(const wchar_t *c,const wchar_t *b,int d) a = x; if(a>c&&!iswspace(a[-1])) a--; - return((wchar_t *)a); + return(a); } static void diff --git a/refer/Makefile.mk b/refer/Makefile.mk index b4c678517e90..60d3b6ee583d 100644 --- a/refer/Makefile.mk +++ b/refer/Makefile.mk @@ -18,6 +18,7 @@ FLAGS = -DMACDIR='"$(MACDIR)"' -DREFDIR='"$(REFDIR)"' $(EUC) $(DEFINES) \ $(CC) $(CFLAGS) $(WARN) $(FLAGS) $(CPPFLAGS) -c $< all: refer addbib lookbib sortbib roffbib indxbib mkey inv hunt papers/runinv + cd papers && PATH=..:$$PATH sh runinv refer: $(ROBJ) $(CC) $(CFLAGS) $(LDFLAGS) $(ROBJ) $(LIBS) -o $@ @@ -74,7 +75,9 @@ install: all papers/Rbstjissue $(ROOT)$(REFDIR)/papers/Rbstjissue $(INSTALL) -c -m 644 papers/Rv7man $(ROOT)$(REFDIR)/papers/Rv7man $(INSTALL) -c papers/runinv $(ROOT)$(REFDIR)/papers/runinv - cd $(ROOT)$(REFDIR)/papers && PATH=$(ROOT)$(REFDIR):$$PATH ./runinv + for i in a b c; do \ + $(INSTALL) -m 644 papers/Ind.i$$i $(ROOT)$(REFDIR)/papers/; \ + done for i in addbib.1 lookbib.1 refer.1 roffbib.1 sortbib.1; \ do \ $(INSTALL) -c -m 644 $$i $(ROOT)$(MANDIR)/man1/$$i || exit; \ @@ -85,7 +88,8 @@ install: all clean: rm -f $(ROBJ) refer $(AOBJ) addbib $(LOBJ) lookbib \ $(SOBJ) sortbib roffbib indxbib $(MOBJ) mkey \ - $(IOBJ) inv $(HOBJ) hunt papers/runinv core log *~ + $(IOBJ) inv $(HOBJ) hunt papers/runinv core log *~ \ + papers/Ind.i? mrproper: clean diff --git a/refer/deliv2.c b/refer/deliv2.c index 4d1682b30454..ccfd994dc21a 100644 --- a/refer/deliv2.c +++ b/refer/deliv2.c @@ -49,23 +49,13 @@ err (const char *s, ...) exit(1); } -int -prefix(const char *t, const char *s) -{ - int c; - - while ((c= *t++) == *s++) - if (c==0) return(1); - return(c==0 ? 1: 0); -} - -char * +const char * mindex(const char *s, int c) { register const char *p; for( p=s; *p; p++) if (*p ==c) - return((char *)p); + return(p); return(0); } diff --git a/refer/glue1.c b/refer/glue1.c index 4b1d789ad46f..8d03ad97e19e 100644 --- a/refer/glue1.c +++ b/refer/glue1.c @@ -50,8 +50,8 @@ static int full = 1000; static int tags = 0; char *sinput, *soutput, *tagout; long indexdate = 0; -int soutlen = 1000; -int taglen = 1000; +static int soutlen = 1000; +static int taglen = 1000; void huntmain(int argc,char **argv) diff --git a/refer/glue3.c b/refer/glue3.c index 24db28dd08bb..5b560bdcba46 100644 --- a/refer/glue3.c +++ b/refer/glue3.c @@ -31,20 +31,20 @@ #define move(x, y) close(y); dup(x); close(x); int -corout(char *in, char *out, char *rprog, char *arg, int outlen) +corout(char *_in, char *out, const char *rprog, char *arg, int outlen) { int pipev[2], fr1, fr2, fw1, fw2, n; int pid; # if D1 fprintf(stderr, "in corout, rprog /%s/ in /%s/\n", - rprog ? rprog : "", strlen(in) ? in : ""); + rprog ? rprog : "", strlen(_in) ? _in : ""); # endif if (strcmp (rprog, "hunt") ==0) - return(callhunt(in, out, arg, outlen)); + return(callhunt(_in, out, arg, outlen)); if (strcmp (rprog, "deliv")==0) - return(dodeliv(in, out, arg, outlen)); + return(dodeliv(_in, out, arg, outlen)); pipe (pipev); fr1= pipev[0]; fw1 = pipev[1]; @@ -64,8 +64,8 @@ corout(char *in, char *out, char *rprog, char *arg, int outlen) } close(fw2); close(fr1); - if (strlen(in) > 0) - write (fw1, in , strlen(in)); + if (strlen(_in) > 0) + write (fw1, _in , strlen(_in)); close(fw1); while (wait(0) != pid); n = read (fr2, out, outlen); @@ -77,7 +77,7 @@ corout(char *in, char *out, char *rprog, char *arg, int outlen) # define ALEN 50 int -callhunt(char *in, char *out, char *arg, int outlen) +callhunt(char *_in, char *out, char *arg, int outlen) { char *argv[20], abuff[ALEN]; int argc; @@ -85,7 +85,7 @@ callhunt(char *in, char *out, char *arg, int outlen) extern int onelen; argv[0] = "hunt"; argv[1] = "-i"; - argv[2] = in; + argv[2] = _in; argv[3] = "-t"; argv[4] = out; argv[5] = (char *)(intptr_t)outlen; @@ -104,7 +104,7 @@ callhunt(char *in, char *out, char *arg, int outlen) } int -dodeliv(char *in, char *out, char *arg, int outlen) +dodeliv(char *_in, char *out, char *arg, int outlen) { char *mout; int mlen; @@ -114,7 +114,7 @@ dodeliv(char *in, char *out, char *arg, int outlen) if (arg && arg[0]) chdir(arg); - mlen = findline(in, &mout, outlen,0L); + mlen = findline(_in, &mout, outlen,0L); if (mlen>0) { diff --git a/refer/glue4.c b/refer/glue4.c index 4c7133429d78..84636d189c05 100644 --- a/refer/glue4.c +++ b/refer/glue4.c @@ -35,7 +35,7 @@ extern char gfile[]; extern char usedir[]; int -grepcall (char *in, char *out, char *arg) +grepcall (char *_in, char *out, char *arg) { char line[200], *s, argig[100], *cv[50]; char *inp, inb[500]; @@ -44,11 +44,11 @@ grepcall (char *in, char *out, char *arg) int sv0, sv1; n_strcpy (argig, arg, sizeof(argig)); n_strcat(argig, ".ig", sizeof(argig)); - n_strcpy (inp=inb, in, sizeof(inb)); + n_strcpy (inp=inb, _in, sizeof(inb)); if (gfile[0]==0) sprintf(gfile, "/tmp/rj%dg", (int)getpid()); # if D1 - fprintf(stderr, "in grepcall, gfile %s in %o out %o\n", gfile,in,out); + fprintf(stderr, "in grepcall, gfile %s in %o out %o\n", gfile,_in,out); # endif for(cv[nv++] = "fgrep"; (c = *inp); inp++) { diff --git a/refer/glue5.c b/refer/glue5.c index 85a693cb82fb..b106bc07d659 100644 --- a/refer/glue5.c +++ b/refer/glue5.c @@ -38,7 +38,7 @@ */ #define MAXSIZ 700 #define QSIZE 400 -struct words { +static struct words { char inp; char out; struct words *nst; @@ -47,16 +47,16 @@ struct words { } *www, *smax, *q; -char buf[2*BUFSIZ]; -int nsucc; -int need; -char *instr; -int inct; -int rflag; -int xargc; -char **xargv; -int numwords; -int nfound; +static char buf[2*BUFSIZ]; +static int nsucc; +static int need; +static char *instr; +static int inct; +static int rflag; +static int xargc; +static char **xargv; +static int numwords; +static int nfound; static int flag = 0; static void execute(void); diff --git a/refer/hunt1.c b/refer/hunt1.c index 01539be40528..fb317d32788e 100644 --- a/refer/hunt1.c +++ b/refer/hunt1.c @@ -31,15 +31,12 @@ # include <limits.h> # include "refer..c" extern char refdir[]; -extern int keepold; -extern char *fgnames[]; -extern char **fgnamp; FILE *fd =NULL; int lmaster =500; int *hfreq, hfrflg; int colevel =0; -int measure=0; -int soutlen =1000; +static int measure=0; +static int soutlen =1000; int reached =0; int iflong =0; int prfreqs =0; diff --git a/refer/hunt2.c b/refer/hunt2.c index 5513b419072e..804316436abb 100644 --- a/refer/hunt2.c +++ b/refer/hunt2.c @@ -25,11 +25,9 @@ #include "refer..c" static int *coord = 0; -int hh[50]; -extern int *hfreq, hfrflg; -extern int prfreqs; +static int hh[50]; union ptr { - unsigned *a; + unsigned *a; long *b; }; diff --git a/refer/hunt5.c b/refer/hunt5.c index 56729c97ff88..75403d70947b 100644 --- a/refer/hunt5.c +++ b/refer/hunt5.c @@ -24,6 +24,7 @@ #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> +#include "refer..c" extern char *soutput, *tagout, usedir[]; union ptr { diff --git a/refer/hunt6.c b/refer/hunt6.c index b21fe57fee60..dc7a686b8f5b 100644 --- a/refer/hunt6.c +++ b/refer/hunt6.c @@ -29,7 +29,6 @@ #include "refer..c" #define TXTLEN 1000 -char *outbuf = 0; extern char *soutput; extern int soutlen, iflong; extern long indexdate; diff --git a/refer/hunt7.c b/refer/hunt7.c index dcb98f58256d..5f229a3a1d2f 100644 --- a/refer/hunt7.c +++ b/refer/hunt7.c @@ -32,13 +32,13 @@ #define FGSIZE 150 int keepold = 1; /* keep old things for fgrep search */ -char fgspace[FGSIZE]; -char *fgp = fgspace; +static char fgspace[FGSIZE]; +static char *fgp = fgspace; char *fgnames[FGCT]; char **fgnamp = fgnames; int -findline(char *in, char **out, int outlen, long indexdate) +findline(char *_in, char **out, int outlen, long _indexdate) { static char name[100] = ""; char *p, **ftp; @@ -50,17 +50,17 @@ findline(char *in, char **out, int outlen, long indexdate) int k, nofil; # if D1 - fprintf(stderr, "findline: %s\n", in); + fprintf(stderr, "findline: %s\n", _in); # endif - if (mindex(in, '!')) + if (mindex(_in, '!')) /* return(remote(in, *out)); /\* Does NOTHING */ return(0); - nofil = in[0]==0; - for(p=in; *p && *p != ':' && *p != ';'; p++) + nofil = _in[0]==0; + for(p=_in; *p && *p != ':' && *p != ';'; p++) ; if (*p) *p++=0; - else p=in; + else p=_in; k = sscanf(p, "%ld,%ld", &lp, &llen); # ifdef D1 fprintf(stderr, "p %s k %d lp %ld llen %ld\n",p,k,lp,llen); @@ -74,7 +74,7 @@ findline(char *in, char **out, int outlen, long indexdate) fprintf(stderr, "lp %ld llen %ld\n",lp, llen); # endif # ifdef D1 - fprintf(stderr, "fa now %o, p %o in %o %s\n",fa, p,in,in); + fprintf(stderr, "fa now %o, p %o in %o %s\n",fa, p,in,_in); # endif if (nofil) { @@ -84,24 +84,24 @@ findline(char *in, char **out, int outlen, long indexdate) fa = stdin; } else - if (strcmp (name, in) != 0 || 1) + if (strcmp (name, _in) != 0 || 1) { # if D1 - fprintf(stderr, "old: %s new %s not equal\n",name,in); + fprintf(stderr, "old: %s new %s not equal\n",name,_in); # endif if (fa != NULL) - fa = freopen(in, "r", fa); + fa = freopen(_in, "r", fa); else - fa = fopen(in, "r"); + fa = fopen(_in, "r"); # if D1 if (fa==NULL) - fprintf(stderr, "failed to (re)open *%s*\n",in); + fprintf(stderr, "failed to (re)open *%s*\n",_in); # endif if (fa == NULL) return(0); /* err("Can't open %s", in); */ - strcpy(name, in); - if (gdate(fa) > indexdate && indexdate != 0) + strcpy(name, _in); + if (gdate(fa) > _indexdate && _indexdate != 0) { if (keepold) { @@ -121,7 +121,7 @@ findline(char *in, char **out, int outlen, long indexdate) } # if D1 else - fprintf(stderr, "old %s new %s same fa %o\n", name,in,fa); + fprintf(stderr, "old %s new %s same fa %o\n", name,_in,fa); # endif if (fa != NULL) { diff --git a/refer/hunt8.c b/refer/hunt8.c index e1a05b0dac1e..b229ad9667f4 100644 --- a/refer/hunt8.c +++ b/refer/hunt8.c @@ -30,8 +30,6 @@ #include "refer..c" #define unopen(fil) {if (fil!=NULL) {fclose(fil); fil=NULL;}} -extern long indexdate; - void runbib (const char *s) { diff --git a/refer/hunt9.c b/refer/hunt9.c index 1602c7dd1006..779a8112df2d 100644 --- a/refer/hunt9.c +++ b/refer/hunt9.c @@ -21,8 +21,10 @@ * Sccsid @(#)hunt9.c 1.3 (gritter) 10/22/05 */ +#include "refer..c" + void -remote(const char *in, const char *out) +remote(const char *_in __unused, const char *out __unused) { /* "in" is a long distance file name: get it */ ; diff --git a/refer/inv1.c b/refer/inv1.c index 0d4747455575..51378f71b387 100644 --- a/refer/inv1.c +++ b/refer/inv1.c @@ -47,7 +47,7 @@ main(int argc, char **argv) */ FILE *fa, *fb, *fc, *fta, *ftb; - FILE *fd = NULL; + FILE *_fd = NULL; int nhash = 256; int appflg = 1; int keepkey = 0, pipein = 0; @@ -56,8 +56,8 @@ main(int argc, char **argv) char *remove = NULL; int chatty = 0, docs, hashes; long keys; - int iflong =0; - char *sortdir; + int _iflong =0; + const char *sortdir; sortdir = (access("/crp/tmp", 06)==0) ? "/crp/tmp" : "/var/tmp"; while (argc>1 && argv[1][0] == '-') @@ -132,8 +132,8 @@ main(int argc, char **argv) } fc = fopen(nmc, appflg ? "a" : "w"); if (keepkey) - fd = keepkey ? fopen(nmd, "w") : 0; - docs = newkeys(fta, stdin, fc, nhash, fd, &iflong); + _fd = keepkey ? fopen(nmd, "w") : 0; + docs = newkeys(fta, stdin, fc, nhash, _fd, &_iflong); fclose(stdin); if (remove != NULL) unlink(remove); @@ -160,7 +160,7 @@ main(int argc, char **argv) fta = fopen(tmpa, "r"); fa = fopen(nma, "w"); fb = fopen(nmb, "w"); - whash(fta, fa, fb, nhash, iflong, &keys, &hashes); + whash(fta, fa, fb, nhash, _iflong, &keys, &hashes); fclose(fta); # ifndef D1 unlink(tmpa); diff --git a/refer/inv2.c b/refer/inv2.c index 8a04d2c6e786..7f2a73d3d071 100644 --- a/refer/inv2.c +++ b/refer/inv2.c @@ -28,7 +28,7 @@ #define LINESIZ 1250 int -newkeys (FILE *outf, FILE *inf, FILE *recf, int nhash, FILE *fd, int *iflong) +newkeys (FILE *outf, FILE *inf, FILE *recf, int nhash, FILE *_fd, int *_iflong) { /* reads key lines from inf; hashes and writes on outf; * writes orig key on recf, records pointer on outf too. @@ -51,7 +51,7 @@ newkeys (FILE *outf, FILE *inf, FILE *recf, int nhash, FILE *fd, int *iflong) while (*p != '\t') p++; *p++ =0; fputs(line, recf); - if (fd) + if (_fd) { snprintf(bkeys, sizeof(bkeys), ";%ld", ld); ll = strlen(p); @@ -61,7 +61,7 @@ newkeys (FILE *outf, FILE *inf, FILE *recf, int nhash, FILE *fd, int *iflong) lt += strlen(bkeys); fputs(bkeys, recf); ld += ll; - fputs(p, fd); + fputs(p, _fd); } putc('\n',recf); for(s=p; *s; s++); @@ -72,7 +72,7 @@ newkeys (FILE *outf, FILE *inf, FILE *recf, int nhash, FILE *fd, int *iflong) } else more=1; - assert (fd==0 || more==0); + assert (_fd==0 || more==0); nk = getargs(p, keyv); if (more) nk--; @@ -102,8 +102,8 @@ newkeys (FILE *outf, FILE *inf, FILE *recf, int nhash, FILE *fd, int *iflong) lp += (strlen(line)+lt+1); ndoc++; } - *iflong = (lp>=65536L); - if (sizeof(int)>2) *iflong=1; /* force long on VAX */ + *_iflong = (lp>=65536L); + if (sizeof(int)>2) *_iflong=1; /* force long on VAX */ fclose(recf); return(ndoc); } diff --git a/refer/inv3.c b/refer/inv3.c index 294b3eda0a88..e5eb9e6725bb 100644 --- a/refer/inv3.c +++ b/refer/inv3.c @@ -21,6 +21,8 @@ * Sccsid @(#)inv3.c 1.3 (gritter) 10/22/05 */ +#include "refer..c" + int getargs(char *s, char **arps) { diff --git a/refer/inv5.c b/refer/inv5.c index 02e81e59c339..3061bd96a328 100644 --- a/refer/inv5.c +++ b/refer/inv5.c @@ -30,7 +30,7 @@ int recopy (FILE *ft, FILE *fb, FILE *fa, int nhash) { /* copy fb (old hash items/pointers) to ft (new ones) */ - int n, i, iflong; + int n, i, _iflong; int *hpt_s = 0; int (*getfun)(FILE *); long *hpt_l = 0; @@ -41,8 +41,8 @@ recopy (FILE *ft, FILE *fb, FILE *fa, int nhash) return 0; } fread(&n, sizeof(n), 1, fa); - fread(&iflong, sizeof(iflong), 1, fa); - if (iflong) + fread(&_iflong, sizeof(_iflong), 1, fa); + if (_iflong) { hpt_l = calloc(sizeof(*hpt_l), n+1); n =fread(hpt_l, sizeof(*hpt_l), n, fa); @@ -55,7 +55,7 @@ recopy (FILE *ft, FILE *fb, FILE *fa, int nhash) if (n!= nhash) fprintf(stderr, "Changing hash value to old %d\n",n); fclose(fa); - if (iflong) + if (_iflong) getfun = (int(*)(FILE *))getl; else #ifdef EUC @@ -65,7 +65,7 @@ recopy (FILE *ft, FILE *fb, FILE *fa, int nhash) #endif for(i=0; i<n; i++) { - if (iflong) + if (_iflong) lp = hpt_l[i]; else lp = hpt_s[i]; diff --git a/refer/inv6.c b/refer/inv6.c index a6540f0cdf03..dcc1d45c1df7 100644 --- a/refer/inv6.c +++ b/refer/inv6.c @@ -27,7 +27,7 @@ #include "refer..c" void -whash(FILE *ft, FILE *fa, FILE *fb, int nhash, int iflong, long *ptotct, int *phused) +whash(FILE *ft, FILE *fa, FILE *fb, int nhash, int _iflong, long *ptotct, int *phused) { char line[100]; int hash = 0, hused = 0; @@ -38,12 +38,12 @@ whash(FILE *ft, FILE *fa, FILE *fb, int nhash, int iflong, long *ptotct, int *ph int k; long lp; long *hpt; - int *hfreq; + int *_hfreq; hpt = calloc (nhash+1, sizeof(*hpt)); assert (hpt != NULL); - hfreq = calloc (nhash, sizeof(*hfreq)); - assert (hfreq != NULL); + _hfreq = calloc (nhash, sizeof(*_hfreq)); + assert (_hfreq != NULL); hpt[0] = 0; lp= 0; while (fgets(line, 100, ft)) @@ -53,38 +53,38 @@ whash(FILE *ft, FILE *fa, FILE *fb, int nhash, int iflong, long *ptotct, int *ph if (hash < k) { hused++; - if (iflong) putl(-1L, fb); + if (_iflong) putl(-1L, fb); else putw(-1, fb); - hfreq[hash]=ct; + _hfreq[hash]=ct; while (hash<k) { hpt[++hash] = lp; - hfreq[hash] = 0; + _hfreq[hash] = 0; } - hpt[hash] = lp += iflong? sizeof(long) : sizeof(int); + hpt[hash] = lp += _iflong? sizeof(long) : sizeof(int); opoint= -1; ct=0; } if (point!=opoint) { - if (iflong) + if (_iflong) putl(opoint=point, fb); else putw( (int)(opoint=point), fb); - lp += iflong? sizeof(long) : sizeof(int); + lp += _iflong? sizeof(long) : sizeof(int); ct++; } } - if (iflong) putl(-1L, fb); + if (_iflong) putl(-1L, fb); else putw(-1,fb); while (hash<nhash) hpt[++hash]=lp; fwrite(&nhash, sizeof(nhash), 1, fa); - fwrite(&iflong, sizeof(iflong), 1, fa); + fwrite(&_iflong, sizeof(_iflong), 1, fa); fwrite(hpt, sizeof(*hpt), nhash, fa); free(hpt); - fwrite (hfreq, sizeof(*hfreq), nhash, fa); - free(hfreq); + fwrite (_hfreq, sizeof(*_hfreq), nhash, fa); + free(_hfreq); *ptotct = totct; *phused = hused; } diff --git a/refer/mkey1.c b/refer/mkey1.c index 57cfc518e0a6..db00d569b59f 100644 --- a/refer/mkey1.c +++ b/refer/mkey1.c @@ -32,7 +32,7 @@ int keycount = 100; int labels = 1; int minlen = 3; extern int comcount; -char *iglist = "XYZ#"; +const char *iglist = "XYZ#"; int main (int argc,char **argv) diff --git a/refer/mkey2.c b/refer/mkey2.c index 6b55d8fa8bae..e3aae17cdc74 100644 --- a/refer/mkey2.c +++ b/refer/mkey2.c @@ -32,8 +32,10 @@ static long lp, lim; static int alph, used, prevc; static char *p, key[20]; +void chkey(int c, const char *name); + void -dofile(FILE *f, char *name) +dofile(FILE *f, const char *name) { /* read file f & spit out keys & ptrs */ @@ -122,15 +124,15 @@ grec (char *s, FILE *f) char * trimnl(char *ln) { - register char *p = ln; - while (*p) p++; - p--; - if (*p == '\n') *p=0; + register char *ptr = ln; + while (*ptr) ptr++; + ptr--; + if (*ptr == '\n') *ptr=0; return(ln); } void -chkey (int c, char *name) +chkey(int c, const char *name) { extern int labels; extern int wholefile; diff --git a/refer/refer..c b/refer/refer..c index d98f71626558..86eaf73431f4 100644 --- a/refer/refer..c +++ b/refer/refer..c @@ -46,10 +46,10 @@ extern FILE *in; extern int endpush, sort, labels, keywant, bare; extern int biblio, science, postpunct; -extern char *smallcaps; +extern const char *smallcaps; extern char *comname; -extern char *keystr; -extern char *convert; +extern const char *keystr; +extern const char *convert; extern int authrev; extern int nmlen, dtlen; extern char *rdata[], **search; @@ -61,14 +61,28 @@ extern char tfile[]; extern char gfile[]; extern char ofile[]; extern char hidenam[]; -extern char *Ifile; extern int Iline; +extern const char *Ifile; extern int Iline; extern FILE *fo, *ftemp; +extern char *fgnames[]; +extern char **fgnamp; +extern int keepold; +extern int lmaster; +extern int reached; +extern int colevel; +extern int prfreqs; +extern int typeindex; +extern long indexdate; +extern int *hfreq; +extern int hfrflg; +extern int iflong; +extern FILE *fd; +extern char usedir[]; +extern char *sinput, *soutput, *tagout; /* deliv2.c */ int hash(const char *); void err(const char *, ...); -int prefix(const char *, const char *); -char *mindex(const char *, int); +const char *mindex(const char *, int); void *zalloc(int, int); /* glue1.c */ void huntmain(int, char **); @@ -78,7 +92,7 @@ int setfrom(int); void savedir(void); void restodir(void); /* glue3.c */ -int corout(char *, char *, char *, char *, int); +int corout(char *, char *, const char *, char *, int); int callhunt(char *, char *, char *, int); int dodeliv(char *, char *, char *, int); /* glue4.c */ @@ -124,11 +138,10 @@ void whash(FILE *, FILE *, FILE *, int, int, long *, int *); void putl(long, FILE *); long getl(FILE *); /* mkey2.c */ -void dofile(FILE *, char *); +void dofile(FILE *, const char *); int outkey(char *, int, int); long grec(char *, FILE *); char *trimnl(char *); -void chkey(int, char *); /* mkey3.c */ int common(char *); void cominit(void); @@ -138,8 +151,6 @@ void doref(char *); int newline(const char *); void choices(char *); int control(int); -/* refer3.c */ -int corout(char *, char *, char *, char *, int); /* refer4.c */ void output(const char *); void append(char *); @@ -148,7 +159,7 @@ char *trimnl(char *); /* refer5.c */ void putsig(int, char **, int, char *, char *, int); char *fpar(int, char **, char *, size_t, int, int, int); -void putkey(int, char **, int, char *); +void putkey(int, char **, int, const char *); void tokeytab(const char *, int); int keylet(char *, int); void mycpy(char *, const char *); @@ -158,7 +169,7 @@ char *artskp(char *); /* refer6.c */ void putref(int, char **); int tabs(char **, char *); -char *class(int, char **); +const char *class(int, char **); int hastype(int, char **, int); char *caps(char *, char *); char *revauth(char *, char *); diff --git a/refer/refer0.c b/refer/refer0.c index 7ad95a2968ab..68ec0b068fd0 100644 --- a/refer/refer0.c +++ b/refer/refer0.c @@ -35,9 +35,9 @@ int biblio = 0; int science = 0; int postpunct = 0; int authrev = 0; -char *smallcaps = ""; -char *keystr = "AD"; -char *convert = "X.AP"; +const char *smallcaps = ""; +const char *keystr = "AD"; +const char *convert = "X.AP"; int nmlen = 0, dtlen = 0; char *rdata[NSERCH]; char **search = rdata; @@ -50,5 +50,5 @@ char tfile[NTFILE]; char ofile[NTFILE]; char gfile[NTFILE]; char hidenam[NTFILE]; -char *Ifile = "standard input"; +const char *Ifile = "standard input"; int Iline = 0; diff --git a/refer/refer1.c b/refer/refer1.c index 5243fe307979..39a4b4d89222 100644 --- a/refer/refer1.c +++ b/refer/refer1.c @@ -25,6 +25,7 @@ #include <locale.h> #include <stdlib.h> #include <unistd.h> +#include <string.h> #include "refer..c" static void signals(void); @@ -146,7 +147,7 @@ main(int argc,char **argv) /* process command-line arguments */ doref(line); else if (biblio && Iline == 1 && *line == '%') doref(line); - else if (!prefix(".[", line)) + else if (!prefix(line, ".[")) output(line); else doref(line); @@ -173,7 +174,7 @@ signals(void) signal(SIGTERM, intr); } -static void intr(int unused) +static void intr(int unused __unused) { signal(SIGINT, SIG_IGN); cleanup(); diff --git a/refer/refer2.c b/refer/refer2.c index cf94dcd3a265..8f0578df09fe 100644 --- a/refer/refer2.c +++ b/refer/refer2.c @@ -48,7 +48,7 @@ doref(char *line1) n_strcat(dbuff, line1, sizeof(dbuff)); while (input(line, sizeof(line))) { /* get query */ Iline++; - if (prefix(".]", line)) + if (prefix(line, ".]")) break; if (biblio && line[0] == '\n') break; diff --git a/refer/refer3.c b/refer/refer3.c index 85cb5c82177c..181af00105fe 100644 --- a/refer/refer3.c +++ b/refer/refer3.c @@ -28,7 +28,7 @@ #define move(x, y) close(y); dup(x); close(x); int -corout(char *in, char *out, char *rprog, char *arg, int outlen) +corout(char *_in, char *out, const char *rprog, char *arg, int outlen) { int pipev[2], fr1, fr2, fw1, fw2, n; int pid, status; @@ -50,7 +50,7 @@ corout(char *in, char *out, char *rprog, char *arg, int outlen) } close(fw2); close(fr1); - write(fw1, in , strlen(in)); + write(fw1, _in , strlen(_in)); close(fw1); while (wait(&status) != pid); n = read(fr2, out, outlen); diff --git a/refer/refer5.c b/refer/refer5.c index ee9ea3f4b771..b2b5497d92b1 100644 --- a/refer/refer5.c +++ b/refer/refer5.c @@ -109,9 +109,9 @@ putsig (int nf, char **flds, int nref, char *nstline, else snprintf(t, sizeof(t), "%d", nref); } - another = (sd = lookat()) ? prefix(".[", sd) : 0; + another = (sd = lookat()) ? prefix(sd, ".[") : 0; if (another && (strcmp(".[\n", sd) != SAME)) - fprintf(stderr, (char *)"File %s line %d: punctuation ignored from: %s", + fprintf(stderr, "File %s line %d: punctuation ignored from: %s", Ifile, Iline, sd); if ((strlen(sig) + strlen(t)) > MXSIG) err("sig overflow (%d)", MXSIG); @@ -196,7 +196,7 @@ putsig (int nf, char **flds, int nref, char *nstline, } char * -fpar (int nf, char **flds, char *out, size_t outsiz, int c, int seq, +fpar (int nf, char **flds, char *out, size_t outsiz __unused, int c, int seq, int prepend) { char *p, *s; @@ -207,11 +207,11 @@ fpar (int nf, char **flds, char *out, size_t outsiz, int c, int seq, /* for titles use first word otherwise last */ if (c == 'T' || c == 'J') { p = flds[i]+3; - if (prefix("A ", p)) + if (prefix(p, "A ")) p += 2; - if (prefix("An ", p)) + if (prefix(p, "An ")) p += 3; - if (prefix("The ", p)) + if (prefix(p, "The ")) p += 4; mycpy2(out, p, 20); return(out); @@ -240,7 +240,7 @@ fpar (int nf, char **flds, char *out, size_t outsiz, int c, int seq, } void -putkey(int nf, char **flds, int nref, char *keystr) +putkey(int nf, char **flds, int nref, const char *_keystr) { char t1[50], *sf; int ctype, i, count; @@ -249,9 +249,9 @@ putkey(int nf, char **flds, int nref, char *keystr) if (nf <= 0) fprintf(fo, "%s%c%c", labtab[nref], labc[nref], sep); else { - while ((ctype = *keystr++)) { - count = atoi(keystr); - if (*keystr=='+') + while ((ctype = *_keystr++)) { + count = atoi(_keystr); + if (*_keystr=='+') count=999; if (count <= 0) count = 1; diff --git a/refer/refer6.c b/refer/refer6.c index 91a8abb71a64..e9f5ab4c6a9a 100644 --- a/refer/refer6.c +++ b/refer/refer6.c @@ -144,7 +144,7 @@ tabs (char **sv, char *line) return(n-1); } -char * +const char * class (int nt, char **tv) { if (hastype (nt, tv, 'J')) diff --git a/refer/refer7.c b/refer/refer7.c index 6a185f0c7d02..64e867ee12e5 100644 --- a/refer/refer7.c +++ b/refer/refer7.c @@ -27,7 +27,7 @@ #include <string.h> #include <unistd.h> -int newr[250]; +static int newr[250]; int chkdup(const char *tag) diff --git a/refer/refer8.c b/refer/refer8.c index 31feb951f194..3d88f1cf61f2 100644 --- a/refer/refer8.c +++ b/refer/refer8.c @@ -29,7 +29,7 @@ static int peeked = 0; static char *noteof = (char *) 1; char * -input(char *s, size_t l) +input(char *s, size_t l __unused) { if (peeked) { peeked = 0; diff --git a/refer/shell.c b/refer/shell.c index 3dbc9f41aa98..bb7fd1232ff4 100644 --- a/refer/shell.c +++ b/refer/shell.c @@ -26,6 +26,9 @@ * IF THERE ARE NO EXCHANGES (IEX=0) ON A SWEEP * THE COMPARISON GAP (IGAP) IS HALVED FOR THE NEXT SWEEP */ + +#include "refer..c" + void shell (int n, int (*comp)(int, int), int (*exch)(int, int)) { diff --git a/refer/sortbib.c b/refer/sortbib.c index be70a7003c2a..c6dbcdc7c5f3 100644 --- a/refer/sortbib.c +++ b/refer/sortbib.c @@ -32,11 +32,11 @@ #define BUF BUFSIZ #define MXFILES 16 -char tempfile[32]; /* temporary file for sorting keys */ -int tmpfd = -1; -char *keystr = "AD"; /* default sorting on author and date */ -int multauth = 0; /* by default sort on senior author only */ -int oneauth; /* has there been author in the record? */ +static char tempfile[32]; /* temporary file for sorting keys */ +static int tmpfd = -1; +static char *keystr = "AD"; /* default sorting on author and date */ +static int multauth = 0; /* by default sort on senior author only */ +static int oneauth; /* has there been author in the record? */ static void sortbib(FILE *, FILE *, int); static void deliver(FILE **, FILE *); @@ -295,11 +295,11 @@ article(const char *str) /* see if string contains an article */ } static void -eval(char *keystr) /* evaluate key string for A+ marking */ +eval(char *kstr) /* evaluate key string for A+ marking */ { int i, j; - for (i = 0, j = 0; keystr[i]; i++, j++) + for (i = 0, j = 0; kstr[i]; i++, j++) { if (keystr[i] == '+') { @@ -308,9 +308,9 @@ eval(char *keystr) /* evaluate key string for A+ marking */ } if (keystr[i] == 0) break; - keystr[j] = keystr[i]; + kstr[j] = kstr[i]; } - keystr[j] = 0; + kstr[j] = 0; } static void @@ -321,7 +321,7 @@ error(const char *s) /* exit in case of various system errors */ } static void -onintr(int unused) /* remove tempfile in case of interrupt */ +onintr(int unused __unused) /* remove tempfile in case of interrupt */ { fprintf(stderr, "\nInterrupt\n"); unlink(tempfile); diff --git a/refer/tick.c b/refer/tick.c index f11885f6c4e1..73c626c40fe1 100644 --- a/refer/tick.c +++ b/refer/tick.c @@ -26,6 +26,7 @@ # include "time.h" # include "stdio.h" # include "sys/types.h" +# include "refer..c" struct tbuffer { long proc_user_time; diff --git a/tbl/Makefile.mk b/tbl/Makefile.mk index 13910de6b9e4..1d90f5f23e9a 100644 --- a/tbl/Makefile.mk +++ b/tbl/Makefile.mk @@ -1,7 +1,7 @@ OBJ = t0.o t1.o t2.o t3.o t4.o t5.o t6.o t7.o t8.o t9.o tb.o tc.o te.o \ tf.o tg.o ti.o tm.o ts.o tt.o tu.o tv.o version.o -FLAGS = -DMACDIR='"$(MACDIR)"' +FLAGS = -DMACDIR='"$(MACDIR)"' -I../include .c.o: $(CC) $(CFLAGS) $(WARN) $(FLAGS) $(CPPFLAGS) -c $< @@ -26,11 +26,7 @@ # include <stdio.h> # include <ctype.h> # include <inttypes.h> - -# if defined (__GLIBC__) && defined (_IO_getc_unlocked) -# undef getc -# define getc(f) _IO_getc_unlocked(f) -# endif +# include "global.h" # define MAXCHS 2000 # define MAXSTR 1024 @@ -80,7 +76,8 @@ extern int *sep; extern int *used, *lused, *rused; extern int *linestop; extern char *leftover; -extern char *last, *ifile; +extern char *last; +extern const char *ifile; extern int *topat; extern intptr_t texname; extern int texct; @@ -146,8 +143,8 @@ void deftail(void); void putline(int, int); void puttext(char *, char *, char *); void funnies(int, int); -void putfont(char *); -void putsize(char *); +void putfont(const char *); +void putsize(const char *); /* t9.c */ int yetmore(void); int domore(char *); @@ -162,7 +159,7 @@ void release(void); int choochar(void); int point(int); /* te.c */ -int error(char *); +int error(const char *); char *errmsg(int); char *gets1(char **, char **, size_t *); void un1getc(int); @@ -190,17 +187,11 @@ int up1(int); char *maknew(char *); int ineqn(char *, char *); /* ts.c */ -int match(char *, char *); -int prefix(char *, char *); -int cprefix(char *, char *); +int cprefix(const char *, const char *); int letter(int); -int numb(char *); -int digit(int); -int max(int, int); void tcopy(char *, char *); /* tt.c */ int ctype(int, int); -int min(int, int); int fspan(int, int); int lspan(int, int); int ctspan(int, int); @@ -69,7 +69,7 @@ int *linestop; /* linestop[MAXLIN] */ int *topat; /* topat[MAXLIN] */ int nlin, ncol; int iline = 1; -char *ifile = "Input"; +const char *ifile = "Input"; intptr_t texname = 'a'; int texct = 0; int texct2 = -1; @@ -50,12 +50,13 @@ extern FILE *_f[]; # define ever (;;) +# ifndef gcos +static void badsig(int); +# endif + int main(int argc, char *argv[]) { -# ifndef gcos -void badsig(int); -# endif progname = basename(argv[0]); # ifndef gcos signal(SIGPIPE, badsig); @@ -85,8 +86,8 @@ fclose(tabin); free(line); return(0); } -int sargc; -char **sargv; +static int sargc; +static char **sargv; void setinp(int argc, char **argv) { @@ -104,17 +105,17 @@ swapin(void) while (sargc>0 && **sargv=='-') /* Mem fault if no test on sargc */ { if (sargc<=0) return(0); - if (match("-me", *sargv)) + if (strcmp("-me", *sargv) == 0) { *sargv = MEMACSS; break; } - if (match("-ms", *sargv)) + if (strcmp("-ms", *sargv) == 0) { *sargv = MACROSS; break; } - if (match("-mm", *sargv)) + if (strcmp("-mm", *sargv) == 0) { *sargv = PYMACSS; break; @@ -146,7 +147,7 @@ swapin(void) } } } - else if (match("-g", *sargv)) + else if (strcmp("-g", *sargv) == 0) { Graphics=1; utf8 = 0; @@ -181,7 +182,7 @@ swapin(void) } # ifndef gcos void -badsig(int unused) +badsig(int unused __unused) { signal(SIGPIPE, SIG_IGN); exit(0); @@ -25,7 +25,9 @@ # include "t..c" # include <string.h> # include <stdlib.h> -struct optstr {char *optnam; int *optadd;} options [] = { +# include "global.h" + +static struct optstr {const char *optnam; int *optadd;} options [] = { { "expand", &expflg }, { "EXPAND", &expflg }, { "center", &ctrflg }, @@ -82,7 +84,7 @@ getcomm(void) { if (!letter(c)) continue; found=0; for(lp= options; lp->optnam; lp++) { - if (prefix(lp->optnam, cp)) { + if (prefix(cp, lp->optnam)) { cp += strlen(lp->optnam); if (letter(*cp)) return @@ -26,7 +26,10 @@ # include "t..c" # include <stdlib.h> # include <string.h> -int oncol; +# include <ctype.h> +# include "global.h" + +static int oncol; static int morecols(int); static int moreheads(int); static void initspec(int); @@ -190,7 +193,7 @@ readspec(void) else *snp++=c; else - if (digit(c)) + if (isdigit(c)) *snp++ = c; else break; if (snp-temp>20) @@ -215,7 +218,7 @@ readspec(void) else *snp++=c; else - if (digit(c)) + if (isdigit(c)) *snp++ = c; else break; if (snp-temp>20) @@ -290,10 +293,10 @@ readspec(void) case '5': case '6': case '7': case '8': case '9': sn[0] = c; snp=sn+1; - while (digit(*snp++ = c = get1char())) + while (isdigit(*snp++ = c = get1char())) ; un1getc(c); - sep[icol-1] = max(sep[icol-1], numb(sn)); + sep[icol-1] = max(sep[icol-1], strtol(sn, NULL, 10)); continue; case '|': lefline[nclin][icol]++; @@ -26,6 +26,7 @@ # include <string.h> # include "t..c" # include <inttypes.h> +# include <global.h> static int morelines(int); @@ -93,7 +94,7 @@ gettbl(void) table[nlin][icol].col = cstore; table[nlin][icol].rcol=0; ch=1; - if (match(cstore, "T{")) { /* text follows */ + if (strcmp(cstore, "T{") == 0) { /* text follows */ /* get_text was originally gettext and was renamed */ if ((table[nlin][icol].col = get_text(cstore, nlin, icol, @@ -214,13 +215,15 @@ vspand(int ir, int ij, int ifform) if (fullbot[ir]) return(0); return(vspen(table[ir][ij].col)); } -int + +int vspen(char *s) { if (s==0) return(0); if (!point((intptr_t)s)) return(0); - return(match(s, SPAN)); + return(strcmp(s, SPAN) == 0); } + static int morelines(int n) { @@ -26,8 +26,8 @@ # include "t..c" # include <inttypes.h> # define realsplit ((ct=='a'||ct=='n') && table[nl][c].rcol) -int watchout; -int once; +static int watchout; +static int once; void putline ( /* i is line number for deciding format */ @@ -140,9 +140,9 @@ putline ( for(c=0; c<ncol; c++) { if (utf8 || tlp) { - char *s = table[nl][c ? c-1 : 0].col; - if ((lwid = lefdata(i, c)) && (!ifline(s) || - *s == '\\')) { + char *_s = table[nl][c ? c-1 : 0].col; + if ((lwid = lefdata(i, c)) && (!ifline(_s) || + *_s == '\\')) { tohcol(c); fprintf(tabout, "%s", tlp ? "|" : @@ -412,13 +412,13 @@ funnies(int stl, int lin) fprintf(tabout,"\n"); } void -putfont(char *fn) +putfont(const char *fn) { if (fn && *fn) fprintf(tabout, fn[1] ? "\\f(%.2s" : "\\f%.2s", fn); } void -putsize(char *s) +putsize(const char *s) { if (s && *s) fprintf(tabout, "\\s%s",s); @@ -59,9 +59,9 @@ if (!point((intptr_t)s)) return(1); if (*s==0) return(0); return(1); } -int spcount = 0; -int maxvec = 0; -char **spvecs; +static int spcount = 0; +static int maxvec = 0; +static char **spvecs; char * chspace(void) { @@ -111,9 +111,9 @@ for (i = 0; i < spcount; i++) } static int MAXPC; -char *thisvec; -int tpcount = -1; -char **tpvecs; +static char *thisvec; +static int tpcount = -1; +static char **tpvecs; struct colstr * alocv(int n) { @@ -29,7 +29,7 @@ int choochar(void) { /* choose funny characters to delimit fields */ int had[128], ilin, icol, k; - char *s; + const char *s; for(icol=0; icol<128; icol++) had[icol]=0; F1 = F2 = 0; @@ -43,7 +43,7 @@ choochar(void) { s = table[ilin][icol].col; if (point((intptr_t)s)) while (*s) { - if (*s > 0 && *(unsigned char *)s <= 127) + if (*s > 0 && *(unsigned const char *)s <= 127) had[(int)*s++]=1; else s++; @@ -51,7 +51,7 @@ choochar(void) { s=table[ilin][icol].rcol; if (point((intptr_t)s)) while (*s) { - if (*s > 0 && *(unsigned char *)s <= 127) + if (*s > 0 && *(unsigned const char *)s <= 127) had[(int)*s++]=1; else s++; @@ -28,7 +28,7 @@ # include <stdlib.h> int -error(char *s) { +error(const char *s) { fprintf(stderr, "\n%s: line %d: %s\n", ifile, iline, s); fprintf(stderr, "%s quits\n", progname); return -1; @@ -43,8 +43,9 @@ char * gets1(char **bp, char **sp, size_t *zp) { char *s, *p = 0; -int c, n = 0; +int c; int nbl; +size_t n = 0; for (;;) { iline++; @@ -91,8 +92,8 @@ for (;;) return(p); } # define BACKMAX 500 -char backup[BACKMAX]; -char *backp = backup; +static char backup[BACKMAX]; +static char *backp = backup; void un1getc(int c) { @@ -25,6 +25,7 @@ # include "t..c" # include <stdlib.h> # include <inttypes.h> +# include <string.h> /* get_text was originally gettext and was renamed */ char * @@ -34,7 +35,7 @@ get_text(char *sp, int ilin, int icol, char *fn, char *sz) char *line = NULL; size_t linesize = 0; char *oname; - char *vs; + const char *vs; if (texname==0) texct2 = texname = 300; if (texct2>0 && point(texct2)) { error("Too many text block diversions"); @@ -76,7 +77,7 @@ get_text(char *sp, int ilin, int icol, char *fn, char *sz) while (gets1(&line, &line, &linesize)) { if (line[0]=='T' && line[1]=='}' && line[2]== tab) break; - if (match("T}", line)) break; + if (strcmp("T}", line) == 0) break; fprintf(tabout, "%s\n", line); } if (fn && *fn) fprintf(tabout, ".ft \\n(%d\n", S1); @@ -38,13 +38,13 @@ maknew(char *str) if (ba==0) { for (dpoint=0; *str; str++) { if ((*str&0377)==decimalpoint && !ineqn(str,p) && - ((str>p && digit(*(str-1))) || - digit(*(str+1)))) + ((str>p && isdigit(*(str-1))) || + isdigit(*(str+1)))) dpoint=str; } if (dpoint==0) for(; str>p; str--) { - if (digit( * (str-1) ) && !ineqn(str, p)) + if (isdigit( * (str-1) ) && !ineqn(str, p)) break; } if (!dpoint && p==str) /* not numerical, don't split */ @@ -21,29 +21,13 @@ * Sccsid @(#)ts.c 1.3 (gritter) 7/23/05 */ - /* ts.c: minor string processing subroutines */ -int -match(char *s1, char *s2) -{ - while (*s1 == *s2) - if (*s1++ == '\0') - return(1); - else - s2++; - return(0); -} +#include "t..c" -int -prefix(char *small, char *big) { - int c; - while ((c= *small++) == *big++) - if (c==0) return(1); - return(c==0); -} + /* ts.c: minor string processing subroutines */ /* returns: 1 for match, 0 else */ int -cprefix(char *ctl, char *line) +cprefix(const char *ctl, const char *line) { char c; @@ -54,35 +38,17 @@ cprefix(char *ctl, char *line) return !c; } -int +int letter(int ch) - { +{ if (ch >= 'a' && ch <= 'z') return(1); if (ch >= 'A' && ch <= 'Z') return(1); return(0); - } -int -numb(char *str) - { - /* convert to integer */ - int k; - for (k=0; *str >= '0' && *str <= '9'; str++) - k = k*10 + *str - '0'; - return(k); - } -int -digit(int x) - { - return(x>= '0' && x<= '9'); - } -int -max(int a, int b) -{ -return( a>b ? a : b); } -void + +void tcopy(char *s, char *t) { while ((*s++ = *t++)); @@ -34,11 +34,7 @@ ctype(int il, int ic) il = stynum[il]; return(style[il][ic]); } -int -min(int a, int b) -{ -return(a<b ? a : b); -} + int fspan(int i, int c) { @@ -32,7 +32,7 @@ * bl | || * c |< ~ >| */ -static char *udbdc[2][3][3][3] = { /* vs. uhbdc */ +static const char *udbdc[2][3][3][3] = { /* vs. uhbdc */ { { { NULL , /* 0000 */ NULL , /* 0001 */ NULL } , /* 0002 */ @@ -89,8 +89,8 @@ static char *udbdc[2][3][3][3] = { /* vs. uhbdc */ "\\U'2563'" /* â•£ */ } } } /* 1222 */ }; -static char *grbe(int i, int lintype); -static char *glibe(int, int, int, int, int); +static const char *grbe(int i, int lintype); +static const char *glibe(int, int, int, int, int); void makeline(int i, int c, int lintype) @@ -133,7 +133,7 @@ fullwide(int i, int lintype) void drawline(int i, int cl, int cr, int lintype, int noheight, int shortl) { - char *exhr, *exhl, *lnch; + const char *exhr, *exhl, *lnch; int lcount, ln, linpos, oldpos, nodata; lcount=0; exhr=exhl= ""; @@ -251,7 +251,7 @@ drawline(int i, int cl, int cr, int lintype, int noheight, int shortl) fprintf(tabout, "\\v'+.5m'"); if (!shortl && (utf8 || tlp)) { int corred, c, ccr, licr; - char *s; + const char *s; ccr = cr; if (ccr == cl) ccr++; corred = 0; @@ -280,8 +280,8 @@ drawline(int i, int cl, int cr, int lintype, int noheight, int shortl) } } -static char *glibe(int i, int c, int cl, int cr, int lintype) { - char *s = NULL; +static const char *glibe(int i, int c, int cl, int cr, int lintype) { + const char *s = NULL; int tl, bl; int cx = c == cl ? 0 : c == cr ? 2 : 1 ; @@ -310,7 +310,7 @@ static char *glibe(int i, int c, int cl, int cr, int lintype) { return s; } -static char *grbe(int i, int lintype) { +static const char *grbe(int i, int lintype) { int tl, bl; lintype = lintype == '=' ? 1 : 0; tl = !i ? 0 : @@ -27,7 +27,7 @@ void drawvert(int start, int end, int c, int lwid) { - char *exb=0, *ext=0; + const char *exb=0, *ext=0; int tp=0, sl, ln, pos, epb, ept, vm; end++; vm='v'; diff --git a/troff/ext.h b/troff/ext.h index ec171f1c0685..91815e91ffaf 100644 --- a/troff/ext.h +++ b/troff/ext.h @@ -266,7 +266,7 @@ extern int chompend; /* n1.c */ extern void mainloop(void); -extern int tryfile(char *, char *, int); +extern int tryfile(const char *, char *, int); extern void catch(int); extern void kcatch(int); extern void init0(void); @@ -276,9 +276,7 @@ extern void cvtime(void); extern int ctoi(register char *); extern void mesg(int); extern void errprint(const char *, ...); -#define fdprintf xxfdprintf -extern void fdprintf(int, char *, ...); -extern char *roff_sprintf(char *, size_t, char *, ...); +extern char *roff_sprintf(char *, size_t, const char *, ...); extern int control(register int, register int); extern int getrq2(void); extern int getrq(int); @@ -286,7 +284,7 @@ extern tchar getch(void); extern void setxon(void); extern tchar getch0(void); extern void pushback(register tchar *); -extern void cpushback(register char *); +extern void cpushback(register const char *); extern tchar *growpbbuf(void); extern int nextfile(void); extern int popf(void); @@ -316,7 +314,7 @@ extern int issame(tchar, tchar); extern int pchar(register tchar); extern void pchar1(register tchar); extern void outascii(tchar); -extern void oputs(register char *); +extern void oputs(register const char *); extern void flusho(void); extern void caseoutput(void); extern void done(int); @@ -373,7 +371,7 @@ extern void casepc(void); extern void casechop(void); extern void casepm(void); extern void stackdump(void); -extern char *macname(int); +extern const char *macname(int); extern int maybemore(int, int); extern tchar setuc(void); extern int makerq(const char *); @@ -388,7 +386,7 @@ extern struct numtab *usedr(register int); extern int fnumb(register int, register int (*)(tchar)); extern int decml(register int, register int (*)(tchar)); extern int roman(int, int (*)(tchar)); -extern int roman0(int, int (*)(tchar), char *, char *); +extern int roman0(int, int (*)(tchar), const char *, const char *); extern int abc(int, int (*)(tchar)); extern int abc0(int, int (*)(tchar)); extern int hatoi(void); @@ -444,8 +442,6 @@ extern void casehylen(void); extern void casehypp(void); extern void casepshape(void); extern void caselpfx(void); -extern int max(int, int); -extern int min(int, int); extern void casece(void); extern void caserj(void); extern void casebrnl(void); diff --git a/troff/libhnj/hnjalloc.c b/troff/libhnj/hnjalloc.c index d0a8b9d48bf0..7a98642b16d2 100644 --- a/troff/libhnj/hnjalloc.c +++ b/troff/libhnj/hnjalloc.c @@ -45,9 +45,14 @@ #include <stdlib.h> #include <stdio.h> #include "hyphen.h" +#include "hnjalloc.h" + +#ifndef __unused +#define __unused __attribute__ ((unused)) +#endif void * -hnj_malloc (int size, HyphenDict *hp) +hnj_malloc (int size, HyphenDict *hp __unused) { void *p; @@ -70,7 +75,7 @@ hnj_malloc (int size, HyphenDict *hp) } void * -hnj_realloc (void *p, int size, HyphenDict *hp) +hnj_realloc (void *p, int size, HyphenDict *hp __unused) { #if 0 if (hp && p >= (void *)hp->space && p < (void *)&hp->space[hp->spacesize]) @@ -86,7 +91,7 @@ hnj_realloc (void *p, int size, HyphenDict *hp) } void -hnj_free (void *p, HyphenDict *hp) +hnj_free (void *p, HyphenDict *hp __unused) { #if 0 if (hp && p >= (void *)hp->space && p < (void *)&hp->space[hp->spacesize]) diff --git a/troff/n1.c b/troff/n1.c index e56735fc94ff..f77a8c979ca8 100644 --- a/troff/n1.c +++ b/troff/n1.c @@ -50,7 +50,7 @@ * contributors. */ -char *xxxvers = "@(#)roff:n1.c 2.13"; +/* const char *xxxvers = "@(#)roff:n1.c 2.13"; */ /* * n1.c * @@ -94,12 +94,12 @@ static int max_recursion_depth = MAX_RECURSION_DEPTH; static int max_tail_depth; jmp_buf sjbuf; -filep ipl[NSO]; -long offl[NSO]; -long ioff; -char *ttyp; +static filep ipl[NSO]; +static long offl[NSO]; +static long ioff; +static const char *ttyp; char *cfname[NSO+1]; /*file name stack*/ -int cfline[NSO]; /*input line count stack*/ +static int cfline[NSO]; /*input line count stack*/ static int cfpid[NSO+1]; /* .pso process IDs */ char *progname; /* program name (troff) */ #ifdef EUC @@ -110,14 +110,6 @@ wchar_t twc = 0; static unsigned char escoff[126-31]; static void initg(void); -static void printlong(long, int); -static void printn(long, long); -static char *sprintlong(char *s, long, int); -static char *sprintn(char *s, long n, int b); -#ifndef NROFF -#define vfdprintf xxvfdprintf -static void vfdprintf(int fd, const char *fmt, va_list ap); -#endif static tchar setyon(void); static void _setenv(void); static tchar setZ(void); @@ -140,7 +132,7 @@ main(int argc, char **argv) register char *p; register int j; char **oargv; - char *s; + const char *s; size_t l; setlocale(LC_CTYPE, ""); @@ -166,10 +158,7 @@ main(int argc, char **argv) signal(SIGPIPE, catch); signal(SIGTERM, kcatch); oargv = argv; - s = "<standard input>"; - l = strlen(s) + 1; - cfname[0] = malloc(l); - n_strcpy(cfname[0], s, l); + cfname[0] = strdup("<standard input>"); init0(); #ifdef EUC localize(); @@ -435,7 +424,7 @@ Lt: int -tryfile(register char *pat, register char *fn, int idx) +tryfile(register const char *pat, register char *fn, int idx) { size_t l = strlen(pat) + strlen(fn) + 1; mfiles[idx] = malloc(l); @@ -446,13 +435,13 @@ tryfile(register char *pat, register char *fn, int idx) else return(1); } -void catch(int unused) +void catch(int unused __unused) { done3(01); } -void kcatch(int unused) +void kcatch(int unused __unused) { signal(SIGTERM, SIG_IGN); done3(01); @@ -469,7 +458,7 @@ init0(void) void -init1(char a) +init1(char a __unused) { register int i; @@ -579,7 +568,7 @@ mesg(int f) } } -void +static void verrprint(const char *s, va_list ap) { fprintf(stderr, "%s: ", progname); @@ -608,296 +597,21 @@ errprint(const char *s, ...) /* error message printer */ va_end(ap); } - -#ifndef NROFF -/* - * Scaled down version of C Library printf. - * Only %s %u %d (==%u) %o %c %x %D are recognized. - */ -#undef putchar -#define putchar(n) (*pfbp++ = (n)) /* NO CHECKING! */ - -static char pfbuf[NTM]; -static char *pfbp = pfbuf; - -void -fdprintf(int fd, char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vfdprintf(fd, fmt, ap); - va_end(ap); -} - -static void -vfdprintf(int fd, const char *fmt, va_list ap) -{ - register int c; - char *s; - register int i; - - pfbp = pfbuf; -loop: - while ((c = *fmt++) != '%') { - if (c == '\0') { - if (fd == 2) - write(STDERR_FILENO, pfbuf, pfbp - pfbuf); - else { - *pfbp = 0; - pfbp = pfbuf; - while (*pfbp) { - *obufp++ = *pfbp++; - if (obufp >= &obuf[OBUFSZ]) - flusho(); - } - } - return; - } - putchar(c); - } - c = *fmt++; - if (c == 'd' || c == 'u' || c == 'o' || c == 'x') { - i = va_arg(ap, int); - printlong(i, c); - } else if (c == 'c') { - if (c > 0177 || c < 040) - putchar('\\'); - putchar(va_arg(ap, int) & 0177); - } else if (c == 's') { - s = va_arg(ap, char *); - while ((c = *s++)) - putchar(c); - } else if (c == 'D') { - printn(va_arg(ap, long), 10); - } else if (c == 'O') { - printn(va_arg(ap, long), 8); - } else if (c == 'e' || c == 'E' || - c == 'f' || c == 'F' || - c == 'g' || c == 'G') { - char tmp[40]; - char fmt[] = "%%"; - fmt[1] = c; - snprintf(s = tmp, sizeof(tmp), fmt, va_arg(ap, double)); - while ((c = *s++)) - putchar(c); - } else if (c == 'p') { - i = (intptr_t)va_arg(ap, void *); - putchar('0'); - putchar('x'); - printlong(i, 'x'); - } else if (c == 'l') { - c = *fmt++; - if (c == 'd' || c == 'u' || c == 'o' || c == 'x') { - i = va_arg(ap, long); - printlong(i, c); - } else if (c == 'c') { - i = va_arg(ap, int); - if (c & ~0177) { -#ifdef EUC - char mb[MB_LEN_MAX]; - int j, n; - n = wctomb(mb, i); - for (j = 0; j < n; j++) - putchar(mb[j]&0377); -#endif /* EUC */ - } else - putchar(i); - } - } else if (c == 'C') { - extern int nchtab; - tchar t = va_arg(ap, tchar); - if ((i = cbits(t)) < 0177) { - putchar(i); - } else if (i < 128 + nchtab) { - putchar('\\'); - putchar('('); - putchar(chname[chtab[i-128]]); - putchar(chname[chtab[i-128]+1]); - } - else if ((i = tr2un(i, fbits(t))) != -1) - goto U; - } else if (c == 'U') { - i = va_arg(ap, int); - U: - putchar('U'); - putchar('+'); - if (i < 0x1000) - putchar('0'); - if (i < 0x100) - putchar('0'); - if (i < 0x10) - putchar('0'); - printn((long)i, 16); -#ifdef EUC - if (iswprint(i)) { - char mb[MB_LEN_MAX]; - int j, n; - n = wctomb(mb, i); - putchar(' '); - putchar('('); - for (j = 0; j < n; j++) - putchar(mb[j]&0377); - putchar(')'); - } -#endif /* EUC */ - } - goto loop; -} -#endif /* !NROFF */ - - -static void -printlong(long i, int fmt) -{ - switch (fmt) { - case 'd': - if (i < 0) { - putchar('-'); - i = -i; - } - /*FALLTHRU*/ - case 'u': - printn(i, 10); - break; - case 'o': - printn(i, 8); - break; - case 'x': - printn(i, 16); - break; - } -} - -/* - * Print an unsigned integer in base b. - */ -static void printn(register long n, register long b) -{ - register long a; - - if (n < 0) { /* shouldn't happen */ - putchar('-'); - n = -n; - } - if ((a = n / b)) - printn(a, b); - putchar("0123456789ABCDEF"[(int)(n%b)]); -} - -/* scaled down version of library roff_sprintf */ -/* same limits as fdprintf */ /* returns pointer to \0 that ends the string */ /* VARARGS2 */ -char *roff_sprintf(char *str, size_t size, char *fmt, ...) +char *roff_sprintf(char *str, size_t size, const char *fmt, ...) { - register int c; - char *s; - long i; + int ret; va_list ap; - char *buf = str; va_start(ap, fmt); -loop: - while ((c = *fmt++) != '%') { - if (c == '\0') { - *str = 0; - va_end(ap); - return str; - } - *str++ = c; - } - c = *fmt++; - if (c == 'd' || c == 'u' || c == 'o' || c == 'x') { - i = va_arg(ap, int); - str = sprintlong(str, i, c); - } else if (c == 'c') { - if (c > 0177 || c < 040) - *str++ = '\\'; - *str++ = va_arg(ap, int) & 0177; - } else if (c == 's') { - s = va_arg(ap, char *); - while ((c = *s++)) - *str++ = c; - } else if (c == 'D') { - str = sprintn(str, va_arg(ap, long), 10); - } else if (c == 'O') { - str = sprintn(str, va_arg(ap, unsigned) , 8); - } else if (c == 'e' || c == 'E' || - c == 'f' || c == 'F' || - c == 'g' || c == 'G') { - char fmt[] = "%%"; - fmt[1] = c; - str += snprintf(str, size - (str - buf), fmt, va_arg(ap, - double)); - } else if (c == 'p') { - i = (intptr_t)va_arg(ap, void *); - *str++ = '0'; - *str++ = 'x'; - str = sprintlong(str, i, 'x'); - } else if (c == 'l') { - c = *fmt++; - if (c == 'd' || c == 'u' || c == 'o' || c == 'x') { - i = va_arg(ap, long); - printlong(i, c); - } else if (c == 'c') { - i = va_arg(ap, int); - if (i & ~0177) { -#ifdef EUC - int n; - n = wctomb(str, i); - if (n > 0) - str += n; -#endif /* EUC */ - } else - *str++ = i; - } - } - goto loop; -} - -static char * -sprintlong(char *s, long i, int fmt) -{ - switch (fmt) { - case 'd': - if (i < 0) { - *s++ = '-'; - i = -i; - } - /*FALLTHRU*/ - case 'u': - s = sprintn(s, i, 10); - break; - case 'o': - s = sprintn(s, i, 8); - break; - case 'x': - s = sprintn(s, i, 16); - break; - } - return s; -} - -/* - * Print an unsigned integer in base b. - */ -static char *sprintn(register char *s, register long n, int b) -{ - register long a; + ret = vsnprintf(str, size, fmt, ap); + va_end(ap); - if (n < 0) { /* shouldn't happen */ - *s++ = '-'; - n = -n; - } - if ((a = n / b)) - s = sprintn(s, a, b); - *s++ = "0123456789ABCDEF"[(int)(n%b)]; - return s; + return (str + ret); } - int control(register int a, register int b) { @@ -1475,7 +1189,7 @@ copy: void setxon(void) /* \X'...' for copy through */ { - tchar xbuf[NC]; + tchar _xbuf[NC]; register tchar *i; tchar c, delim; int k; @@ -1483,10 +1197,10 @@ setxon(void) /* \X'...' for copy through */ if (ismot(c = getch())) return; delim = c; - i = xbuf; + i = _xbuf; *i++ = XON; charf++; - while (k = cbits(c = getch()), !issame(c, delim) && k != '\n' && i < xbuf+NC-1) { + while (k = cbits(c = getch()), !issame(c, delim) && k != '\n' && i < _xbuf+NC-1) { if (k == ' ') setcbits(c, UNPAD); *i++ = c | ZBIT; @@ -1496,7 +1210,7 @@ setxon(void) /* \X'...' for copy through */ charf--; *i++ = XOFF; *i = 0; - pushback(xbuf); + pushback(_xbuf); } static tchar @@ -1644,9 +1358,9 @@ pushback(register tchar *b) } void -cpushback(register char *b) +cpushback(register const char *b) { - register char *ob = b; + register const char *ob = b; while (*b++) ; @@ -1677,8 +1391,6 @@ int nextfile(void) { register char *p; - char *s; - size_t l; n0: if (ifile) @@ -1699,10 +1411,7 @@ n0: nfo++; numtab[CD].val = ifile = stdi = mflg = 0; free(cfname[ifi]); - s = "<standard input>"; - l = strlen(s) + 1; - cfname[ifi] = malloc(l); - n_strcpy(cfname[ifi], s, l); + cfname[ifi] = strdup("<standard input>"); ioff = 0; return(0); } @@ -1712,19 +1421,14 @@ n1: if (p[0] == '-' && p[1] == 0) { ifile = 0; free(cfname[ifi]); - s = "<standard input>"; - l = strlen(s) + 1; - cfname[ifi] = malloc(l); - n_strcpy(cfname[ifi], s, l); + cfname[ifi] = strdup("<standard input>"); } else if ((ifile = open(p, O_RDONLY)) < 0) { errprint("cannot open file %s", p); nfo -= mflg; done(02); } else { free(cfname[ifi]); - l = strlen(p) + 1; - cfname[ifi] = malloc(l); - n_strcpy(cfname[ifi], p, l); + cfname[ifi] = strdup(p); } nfo++; ioff = 0; @@ -1873,22 +1577,23 @@ getname(void) tchar setuc(void) { - char c, d, b[NC], *bp; - int i = 0, n; + char c, _d, b[NC], *bp; + int n; + size_t i = 0; tchar r = 0; #ifndef NROFF extern int nchtab; #endif - d = getach(); + _d = getach(); do { c = getach(); if (i >= sizeof b) goto rtn; b[i++] = c; - } while (c && c != d); + } while (c && c != _d); b[--i] = 0; - if (i == 0 || c != d) + if (i == 0 || c != _d) goto rtn; n = strtol(b, &bp, 16); if (n == 0 || *bp != '\0') @@ -2251,7 +1956,7 @@ caserecursionlimit(void) } void -casechar(int flag) +casechar(int flag __unused) { #ifndef NROFF extern int ps2cc(const char *); @@ -2376,15 +2081,15 @@ prepchar(struct fmtchar *fp) { static int charcount; filep startb; - tchar t; + tchar _t; if ((startb = alloc()) == 0) { errprint("out of space"); return -1; } - t = 0; - setsbits(t, charcount); - charcount = sbits(t); + _t = 0; + setsbits(_t, charcount); + charcount = sbits(_t); if (dip != d) wbt(0); if (charcount >= charoutsz) { @@ -2503,28 +2208,28 @@ setZ(void) } tchar -sfmask(tchar t) +sfmask(tchar _t) { - while (isxfunc(t, CHAR)) - t = charout[sbits(t)].ch; - if (t == XFUNC || t == SLANT || (t & SFMASK) == 0) + while (isxfunc(_t, CHAR)) + _t = charout[sbits(_t)].ch; + if (_t == XFUNC || _t == SLANT || (_t & SFMASK) == 0) return chbits; - return t & SFMASK; + return _t & SFMASK; } int -issame(tchar c, tchar d) +issame(tchar c, tchar _d) { - if (ismot(c) || ismot(d)) + if (ismot(c) || ismot(_d)) return 0; while (isxfunc(c, CHAR)) c = charout[sbits(c)].ch; - while (isxfunc(d, CHAR)) - d = charout[sbits(d)].ch; - if (cbits(c) != cbits(d)) + while (isxfunc(_d, CHAR)) + _d = charout[sbits(_d)].ch; + if (cbits(c) != cbits(_d)) return 0; - if (cbits(c) == XFUNC && cbits(d) == XFUNC) - return fbits(c) == fbits(d); + if (cbits(c) == XFUNC && cbits(_d) == XFUNC) + return fbits(c) == fbits(_d); return 1; } diff --git a/troff/n2.c b/troff/n2.c index cb481f7dc720..c61985e17a36 100644 --- a/troff/n2.c +++ b/troff/n2.c @@ -52,6 +52,7 @@ * output, cleanup */ +#include <stdio.h> #include <stdlib.h> #include <signal.h> #include <unistd.h> @@ -69,7 +70,7 @@ #include "ext.h" extern jmp_buf sjbuf; -int toolate; +static int toolate; int error; static void outtp(tchar); @@ -213,8 +214,8 @@ pchar1(register tchar i) return; } } - if (cbits(i) == 'x') - fmtchar = fmtchar; +/* if (cbits(i) == 'x') + fmtchar = fmtchar; */ if (_olt) { _olp[0] = i; olt[nolt++] = fetchrq(_olp); @@ -236,10 +237,10 @@ outtp(tchar i) #ifdef EUC if (iscopy(i)) - fdprintf(ptid, "%lc", j); + dprintf(ptid, "%lc", j); else #endif /* EUC */ - fdprintf(ptid, "%c", j); + dprintf(ptid, "%c", j); #endif } @@ -333,7 +334,7 @@ oput(i) */ void -oputs(register char *i) +oputs(register const char *i) { while (*i != 0) oput(*i++&0377); diff --git a/troff/n3.c b/troff/n3.c index 0798375c05e7..cf9adf31c6c8 100644 --- a/troff/n3.c +++ b/troff/n3.c @@ -70,14 +70,14 @@ #include <unistd.h> #define MHASH(x) ((x>>6)^x)&0177 -struct contab **mhash; /* size must be 128 == the 0177 on line above */ +static struct contab **mhash; /* size must be 128 == the 0177 on line above */ #define blisti(i) (((i)-ENV_BLK*BLK) / BLK) -filep *blist; -int nblist; -int pagech = '%'; -int strflg; +static filep *blist; +static int nblist; +static int pagech = '%'; +static int strflg; -tchar *wbuf; +static tchar *wbuf; tchar *corebuf; struct contab *oldmn; @@ -96,10 +96,10 @@ static void caseindex(void); static void caseasciify(void); static void caseunformat(int); static int getls(int, int *, int); -static void addcon(int, char *, void(*)(int)); +static void addcon(int, const char *, void(*)(int)); static const struct { - char *n; + const char *n; void (*f)(int); } longrequests[] = { { "aln", (void(*)(int))casealn }, @@ -704,16 +704,14 @@ copyb(void) int req; filep savoff = 0, tailoff = 0; tchar tailc = 0; - char *contp, *mn; - size_t l; + const char *contp; + char *mn; if (skip(0) || !(j = getrq(1))) j = '.'; req = j; contp = macname(req); - l = strlen(contp) + 1; - mn = malloc(l); - n_strcpy(mn, contp, l); + mn = strdup(contp); copyf++; flushi(); nlflg = 0; @@ -836,7 +834,7 @@ ffree ( /*free blist[i] and blocks pointed to*/ { register int j; - while (blist[j = blisti(i)] != (unsigned) ~0) { + while (blist[j = blisti(i)] != (int) ~0) { i = (filep) blist[j]; blist[j] = 0; } @@ -873,7 +871,7 @@ wbf ( /*store i into blist[offset] (?) */ errprint("Out of temp file space"); done2(01); } - if (blist[j] == (unsigned) ~0) { + if (blist[j] == (int) ~0) { if (alloc() == 0) { errprint("Out of temp file space"); done2(01); @@ -926,7 +924,7 @@ rbf (void) /*return next char from blist[] block*/ /* this is an inline expansion of incoff: also dirty */ p = ++ip; if ((p & (BLK - 1)) == 0) { - if ((ip = blist[blisti(p-1)]) == (unsigned) ~0) { + if ((ip = blist[blisti(p-1)]) == (int) ~0) { errprint("Bad storage allocation"); ip = 0; done2(-5); @@ -958,7 +956,7 @@ incoff ( /*get next blist[] block*/ { p++; if ((p & (BLK - 1)) == 0) { - if ((p = blist[blisti(p-1)]) == (unsigned) ~0) { + if ((p = blist[blisti(p-1)]) == (int) ~0) { errprint("Bad storage allocation"); done2(-5); } @@ -971,7 +969,7 @@ tchar popi(void) { register struct s *p; - tchar c, d; + tchar c, _d; if (frame == stk) return(0); @@ -987,11 +985,11 @@ popi(void) lastpbp = p->lastpbp; c = p->pch; if (p->loopf & LOOP_NEXT) { - d = ch; + _d = ch; ch = c; pushi(p->newip, p->mname, p->flags); c = 0; - ch = d; + ch = _d; } else if (p->loopf & LOOP_FREE) ffree(p->newip); @@ -1413,7 +1411,7 @@ void caseals(void) { struct contab *contp; - int i, j, t; + int i, j, _t; int flags = 0; if (skip(1)) @@ -1428,19 +1426,19 @@ caseals(void) } if (contp->nlink == 0) { munhash(contp); - t = makerq(NULL); - contp->rq = t; + _t = makerq(NULL); + contp->rq = _t; maddhash(contp); if (contp->flags & FLAG_LOCAL) dl++; if (finds(j, 0, 0) != 0 && newmn) { - newmn->als = t; + newmn->als = _t; newmn->rq = j; maddhash(newmn); contp->nlink = 1; } } else - t = j; + _t = j; if (contp->flags & FLAG_LOCAL) dl++; if (finds(i, 0, !dl) != 0) { @@ -1451,7 +1449,7 @@ caseals(void) if (newmn) { if (newmn->rq) munhash(newmn); - newmn->als = t; + newmn->als = _t; newmn->rq = i; newmn->flags |= flags; maddhash(newmn); @@ -1538,7 +1536,7 @@ prwatch(struct contab *contp, int rq, int prc) 000 }; char *buf = NULL; - char *local; + const char *local; filep savip; tchar c; int j, k; @@ -2155,7 +2153,7 @@ stackdump (void) /* dumps stack of macros in process */ static char laststr[NC+1]; -char * +const char * macname(int rq) { static char buf[4][3]; @@ -2186,7 +2184,7 @@ static tchar mgetach(void) { tchar i; - int j; + size_t j; lgf++; i = getch(); @@ -2215,8 +2213,8 @@ int maybemore(int sofar, int flags) { char c, buf[NC+1], pb[] = { '\n', 0 }; - int i = 2, n, _raw = raw, _init = init, _app = app; - size_t l; + int n, _raw = raw, _init = init, _app = app; + size_t i = 2; if (xflag < 2) return sofar; @@ -2264,9 +2262,7 @@ maybemore(int sofar, int flags) } if (n >= alcd) had = realloc(had, (alcd += 20) * sizeof *had); - l = strlen(buf) + 1; - had[n] = malloc(l); - n_strcpy(had[n], buf, l); + had[n] = strdup(buf); hadn = n+1; mapadd(buf, n); } @@ -2283,8 +2279,8 @@ static int getls(int termc, int *strp, int create) { char c, buf[NC+1]; - int i = 0, j = -1, n = -1; - size_t l; + int j = -1, n = -1; + size_t i = 0; do { c = xflag < 3 ? getach() : mgetach(); @@ -2311,9 +2307,7 @@ getls(int termc, int *strp, int create) if (hadn++ >= alcd) had = realloc(had, (alcd += 20) * sizeof *had); - l = strlen(buf) + 1; - had[n] = malloc(l); - n_strcpy(had[n], buf, l); + had[n] = strdup(buf); hadn = n + 1; mapadd(buf, n); } else { @@ -2331,7 +2325,6 @@ makerq(const char *name) static int t; char _name[20]; int n; - size_t l; if (name == NULL) { roff_sprintf(_name, sizeof(_name), "\13%d", ++t); @@ -2343,23 +2336,21 @@ makerq(const char *name) return MAXRQ2 + n; if (hadn++ >= alcd) had = realloc(had, (alcd += 20) * sizeof *had); - l = strlen(name) + 1; - had[n] = malloc(l); - n_strcpy(had[n], name, l); + had[n] = strdup(name); hadn = n + 1; mapadd(name, n); return MAXRQ2 + n; } static void -addcon(int t, char *rs, void(*f)(int)) +addcon(int _t, const char *rs, void(*f)(int)) { int n = hadn; if (hadn++ >= alcd) had = realloc(had, (alcd += 20) * sizeof *had); had[n] = rs; - contab[t].rq = MAXRQ2 + n; - contab[t].f = f; + contab[_t].rq = MAXRQ2 + n; + contab[_t].f = f; mapadd(rs, n); } diff --git a/troff/n4.c b/troff/n4.c index 8c81de5770ef..8bb19fd68cfc 100644 --- a/troff/n4.c +++ b/troff/n4.c @@ -67,10 +67,10 @@ */ -int regcnt = NNAMES; +static int regcnt = NNAMES; int falsef = 0; /* on if inside false branch of if */ #define NHASH(i) ((i>>6)^i)&0177 -struct numtab **nhash; /* size must be 128 == the 0177 on line above */ +static struct numtab **nhash; /* size must be 128 == the 0177 on line above */ static void nrehash(struct numtab *, int, struct numtab **); static struct numtab *_findr(register int i, int, int, int, int *); @@ -311,7 +311,7 @@ sl: case 'Y': if (xflag) { TMYES; - cpushback((char *)revision); + cpushback(revision); return(0); } /*FALLTHRU*/ @@ -571,8 +571,8 @@ setn(void) _setn(0); } -tchar numbuf[17]; -tchar *numbufp; +static tchar numbuf[17]; +static tchar *numbufp; int wrc(tchar i) @@ -798,7 +798,7 @@ roman(int i, int (*f)(tchar)) int -roman0(int i, int (*f)(tchar), char *onesp, char *fivesp) +roman0(int i, int (*f)(tchar), const char *onesp, const char *fivesp) { register int q, rem, k; @@ -1355,11 +1355,11 @@ a1: i = dfactd; } if (!field) { - tchar t, tp[2]; - int f, d, n; - t = getch(); - if (cbits(t) != ';') { - tp[0] = t; + tchar _t, tp[2]; + int _f, _d, n; + _t = getch(); + if (cbits(_t) != ';') { + tp[0] = _t; tp[1] = 0; pushback(tp); ch = ii; @@ -1367,15 +1367,15 @@ a1: } newscale: /* (c;e) */ - f = dfact; - d = dfactd; + _f = dfact; + _d = dfactd; n = noscale; dfact = j; dfactd = i; noscale = _noscale; acc = _atoi0(flt); - dfact = f; - dfactd = d; + dfact = _f; + dfactd = _d; noscale = n; return(acc); } @@ -1782,7 +1782,7 @@ caseunwatchn(void) void prwatchn(struct numtab *numtp) { - char *local; + const char *local; if (numtp == NULL) return; @@ -1886,18 +1886,18 @@ _inumb(int *n, float *fp, int flt, int *relative) float atop(void) { - float t; + float _t; noscale++; - t = atof(); + _t = atof(); noscale--; - if (t < -INFPENALTY) - t = -INFPENALTY; - else if (t > INFPENALTY) - t = INFPENALTY; + if (_t < -INFPENALTY) + _t = -INFPENALTY; + else if (_t > INFPENALTY) + _t = INFPENALTY; else - t *= PENALSCALE; - return t; + _t *= PENALSCALE; + return _t; } @@ -1923,7 +1923,7 @@ quant(int n, int m) tchar -moflo(int n) +moflo(int n __unused) { if (warn & WARN_RANGE) errprint("value too large for motion"); diff --git a/troff/n5.c b/troff/n5.c index c21a4a30b38c..0819514d8443 100644 --- a/troff/n5.c +++ b/troff/n5.c @@ -278,7 +278,7 @@ casehlm(void) void casehcode(void) { - tchar c, d; + tchar c, _d; int k; lgf++; @@ -288,15 +288,15 @@ casehcode(void) c = getch(); if (skip(1)) break; - d = getch(); - if (c && d && !ismot(c) && !ismot(d)) { + _d = getch(); + if (c && _d && !ismot(c) && !ismot(_d)) { if ((k = cbits(c)) >= nhcode) { hcode = realloc(hcode, (k+1) * sizeof *hcode); memset(&hcode[nhcode], 0, (k+1-nhcode) * sizeof *hcode); nhcode = k+1; } - hcode[k] = cbits(d); + hcode[k] = cbits(_d); } } while (!skip(0)); } @@ -324,26 +324,26 @@ casehylen(void) void casehypp(void) { - float t; + float _t; if (skip(0)) hypp = hypp2 = hypp3 = 0; else { - t = atop(); + _t = atop(); if (!nonumb) - hypp = t; + hypp = _t; if (skip(0)) hypp2 = hypp3 = 0; else { - t = atop(); + _t = atop(); if (!nonumb) - hypp2 = t; + hypp2 = _t; if (skip(0)) hypp3 = 0; else { - t = atop(); + _t = atop(); if (!nonumb) - hypp3 = t; + hypp3 = _t; } } } @@ -418,25 +418,6 @@ caselpfx(void) } } -int -max(int aa, int bb) -{ - if (aa > bb) - return(aa); - else - return(bb); -} - -int -min(int aa, int bb) -{ - if (aa < bb) - return(aa); - else - return(bb); -} - - static void cerj(int dorj) { @@ -2440,13 +2421,13 @@ caseab(void) #ifdef USG #include <termios.h> #define ECHO_USG (ECHO | ECHOE | ECHOK | ECHONL) -struct termios ttys; +static struct termios ttys; #else #include <sgtty.h> struct sgttyb ttys[2]; #endif /* USG */ -int ttysave[2] = {-1, -1}; +static int ttysave[2] = {-1, -1}; void save_tty(void) /*save any tty settings that may be changed*/ diff --git a/troff/n7.c b/troff/n7.c index 89c6a4e2755a..6b13c7bdc05f 100644 --- a/troff/n7.c +++ b/troff/n7.c @@ -78,7 +78,7 @@ tchar gettch(void); #if defined (EUC) && defined (NROFF) && defined (ZWDELIMS) wchar_t cwc, owc, wceoll; #endif /* EUC && NROFF && ZWDELIMS */ -int brflg; +static int brflg; #undef iswascii #define iswascii(c) (((c) & ~(wchar_t)0177) == 0) @@ -1228,7 +1228,7 @@ int getword(int x) { register int j, k = 0, w; - register tchar i = 0, *wp, nexti, gotspc = 0, t; + register tchar i = 0, *wp, nexti, gotspc = 0, _t; int noword, n, inword = 0; int lastsp = ' '; static int dv; @@ -1340,21 +1340,21 @@ getword(int x) a0: #endif /* EUC && NROFF && ZWDELIMS */ if (spbits && xflag) { - t = lastsp | spbits; - w = width(t); + _t = lastsp | spbits; + w = width(_t); } else { - t = lastsp | chbits; + _t = lastsp | chbits; w = sps; } cdp = cht = 0; if (chompend) { chompend = 0; } else { - storeword(t, w + k); + storeword(_t, w + k); } if (spflg) { if (xflag == 0 || ses != 0) - storeword(t | SENTSP, ses); + storeword(_t | SENTSP, ses); spflg = 0; } if (!nwd) @@ -1384,21 +1384,21 @@ g0: } if (maybreak(j, dv)) { if (wordp > word + 1) { - int i; + int _i; if (!xflag) hyoff = 2; if (gemu && hyp > hyptr && wordp > word && hyp[-1] == wordp && ( - (i = cbits(wordp[-1])) == '-' - || i == EMDASH)) + (_i = cbits(wordp[-1])) == '-' + || _i == EMDASH)) hyp--; *hyp++ = wordp + 1; if (hyp > (hyptr + NHYP - 1)) hyp = hyptr + NHYP - 1; } } else { - int i = cbits(j); - dv = alph(j) || (i >= '0' && i <= '9'); + int _i = cbits(j); + dv = alph(j) || (_i >= '0' && _i <= '9'); } if (xflag && nhychar(j)) hyoff = 2; @@ -1411,10 +1411,10 @@ g0: nexti = GETCH(); if (ev == oev) { if (cbits(nexti) == '\n') - t = ' ' | chbits; + _t = ' ' | chbits; else - t = nexti; - k = kernadjust(i, t); + _t = nexti; + k = kernadjust(i, _t); wne += k; widthp += k; numtab[HP].val += k; @@ -1627,7 +1627,7 @@ sethtdp(void) } static void -leftend(tchar c, int hang, int dolpfx) +leftend(tchar c __unused, int hang, int dolpfx) { int k, w; @@ -1788,35 +1788,35 @@ lspcomp(int idiff) static double penalty(int k, int s, int h, int h2, int h3) { - double t, d; + double _t, _d; - t = nel - k; - t = t >= 0 ? t * 5 / 3 : -t; + _t = nel - k; + _t = _t >= 0 ? _t * 5 / 3 : -_t; if (ad && !admod) { - d = s; + _d = s; if (k - s && (letsps || lshmin || lshmax)) - d += (double)(k - s) / 100; - if (d) - t /= d; + _d += (double)(k - s) / 100; + if (_d) + _t /= _d; } else - t /= nel / 10; + _t /= nel / 10; if (h && hypp) - t += hypp; + _t += hypp; if (h2 && hypp2) - t += hypp2; + _t += hypp2; if (h3 && hypp3) - t += hypp3; - t = t * t * t; - if (t > MAXPENALTY) - t = MAXPENALTY; - return t; + _t += hypp3; + _t = _t * _t * _t; + if (_t > MAXPENALTY) + _t = MAXPENALTY; + return _t; } static void parcomp(int start) { double *cost, *_cost; - long double t; + long double _t; int *prevbreak, *hypc, *_hypc, *brcnt, *_brcnt; int i, j, k, m, h, v, s; @@ -1855,13 +1855,13 @@ parcomp(int start) if (v - m - pglgeh[j] <= nel) { if (!spread && j == pgwords - 1 && pgpenal[j] == 0) - t = 0; + _t = 0; else - t = penalty(v, s, pghyphw[j], + _t = penalty(v, s, pghyphw[j], pghyphw[j] && hypc[i-1], pghyphw[j] && j >= pglastw); - t += pgpenal[j]; - t += cost[i-1]; + _t += pgpenal[j]; + _t += cost[i-1]; /*fprintf(stderr, "%c%c%c%c to %c%c%c%c " "t=%g cost[%d]=%g " "brcnt=%d oldbrcnt=%d\n", @@ -1877,7 +1877,7 @@ parcomp(int start) 1 + brcnt[i-1], brcnt[j] );*/ - if ((double)t <= cost[j]) { + if ((double)_t <= cost[j]) { if (pghyphw[j]) h = hypc[i-1] + 1; else @@ -1892,15 +1892,15 @@ parcomp(int start) */ if (hlm < 0 || h <= hlm) { hypc[j] = h; - cost[j] = t; + cost[j] = _t; prevbreak[j] = i; brcnt[j] = 1 + brcnt[i-1]; } } } else { if (j == i) { - t = 1 + cost[i-1]; - cost[j] = t; + _t = 1 + cost[i-1]; + cost[j] = _t; prevbreak[j] = i; brcnt[j] = 1 + brcnt[i-1]; } @@ -2191,7 +2191,7 @@ pbreak(int sprd, int lastf, struct s *s) } } -void +static void parpr(struct s *s) { int i, j, k = 0, nw = 0, w, stretches, _spread = spread, hc; diff --git a/troff/n8.c b/troff/n8.c index fa8c484db773..65e9a1b01b8a 100644 --- a/troff/n8.c +++ b/troff/n8.c @@ -67,12 +67,12 @@ * hyphenation */ -int *hbuf; -int NHEX; -int *nexth; -tchar *hyend; +static int *hbuf; +static int NHEX; +static int *nexth; +static tchar *hyend; #define THRESH 160 /*digram goodness threshold*/ -int thresh = THRESH; +static int thresh = THRESH; static void hyphenhnj(void); @@ -550,9 +550,7 @@ casehylang(void) path = malloc(l); snprintf(path, l, "%s/hyph_%s.dic", HYPDIR, hylang); } else { - l = strlen(hylang) + 1; - path = malloc(l); - n_strcpy(path, hylang, l); + path = strdup(hylang); } if ((dicthnj = hnj_hyphen_load(path)) == NULL) { errprint("Can't load %s", path); diff --git a/troff/n9.c b/troff/n9.c index 44b9ee0c0ecc..9e81a65120c7 100644 --- a/troff/n9.c +++ b/troff/n9.c @@ -278,7 +278,7 @@ void setvline(void) { register int i; - tchar c, d, delim, rem, ver, neg; + tchar c, _d, delim, rem, ver, neg; int cnt, v; tchar vlbuf[NC]; register tchar *vlp; @@ -298,8 +298,8 @@ setvline(void) if (c = getch(), issame(c, delim)) { c = BOXRULE | chbits; /*default box rule*/ } else { - d = getch(); - if (!issame(d, delim)) + _d = getch(); + if (!issame(_d, delim)) nodelim(delim); } c |= ZBIT; @@ -473,7 +473,8 @@ setfield(int x) { register tchar ii, jj, *fp; register int i, j, k; - int length, ws, npad, temp, type; + int length, ws, npad, temp; + unsigned int type; tchar **pp, *padptr[NPP]; tchar fbuf[FBUFSZ]; int savfc, savtc, savlc; @@ -678,11 +679,11 @@ rtn: static int readpenalty(int *valp) { - int n, t; + int n, _t; - t = dpenal ? dpenal - INFPENALTY0 - 1 : 0; + _t = dpenal ? dpenal - INFPENALTY0 - 1 : 0; noscale++; - n = inumb(&t); + n = inumb(&_t); noscale--; if (nonumb) return 0; @@ -734,10 +735,10 @@ setdpenal(void) tchar mkxfunc(int f, int s) { - tchar t = XFUNC; - setfbits(t, f); - setsbits(t, s); - return t; + tchar _t = XFUNC; + setfbits(_t, f); + setsbits(_t, s); + return _t; } void @@ -798,11 +799,12 @@ popinlev(void) #ifdef EUC /* locale specific initialization */ +wchar_t *wddelim(wchar_t, wchar_t, int); +int wdbindf(wchar_t, wchar_t, int); + void localize(void) { - extern int wdbindf(wchar_t, wchar_t, int); - extern wchar_t *wddelim(wchar_t, wchar_t, int); char *codeset; codeset = nl_langinfo(CODESET); @@ -832,13 +834,13 @@ localize(void) #ifndef __sun int -wdbindf(wchar_t wc1, wchar_t wc2, int type) +wdbindf(wchar_t wc1 __unused, wchar_t wc2 __unused, int type __unused) { return 6; } wchar_t * -wddelim(wchar_t wc1, wchar_t wc2, int type) +wddelim(wchar_t wc1 __unused, wchar_t wc2 __unused, int type __unused) { return L" "; } @@ -1148,7 +1150,8 @@ static int warn1(void) { char name[NC]; - int i, n, sign; + int n, sign; + size_t i; tchar c; switch (cbits(c = getch())) { diff --git a/troff/nroff.d/draw.c b/troff/nroff.d/draw.c index 5d0e7021ace0..c73ae300c7fb 100644 --- a/troff/nroff.d/draw.c +++ b/troff/nroff.d/draw.c @@ -58,9 +58,9 @@ static void free_node(struct bst_node *); static int coordcmp(union bst_val, union bst_val); static void postproc(struct bst_node *); static void chkcoord(uint64_t); -static void drawat(int, int, char *); +static void drawat(int, int, const char *); -struct bst coords = { +static struct bst coords = { NULL, coordcmp }; @@ -167,7 +167,7 @@ chkcoord(uint64_t xy) { } static void -drawat(int x, int y, char *s) { +drawat(int x, int y, const char *s) { size_t l = 0; char buf[100]; x -= po + in + ne; diff --git a/troff/nroff.d/n10.c b/troff/nroff.d/n10.c index 569b766051ef..bb315e8b52c7 100644 --- a/troff/nroff.d/n10.c +++ b/troff/nroff.d/n10.c @@ -75,9 +75,8 @@ Device interfaces struct t t; /* terminal characteristics */ -int dtab; -int plotmode; -int esct; +static int dtab; +static int esct; int nchtab; @@ -357,7 +356,7 @@ skipstr ( /* skip over leading space plus string */ char * getstr ( /* find next string in s, copy to t */ char *s, - char *t + char *_t ) { int quote = 0; @@ -376,37 +375,37 @@ getstr ( /* find next string in s, copy to t */ if (!quote && (*s == ' ' || *s == '\t' || *s == '\n')) break; if (*s != '\\') - *t++ = *s++; + *_t++ = *s++; else { s++; /* skip \\ */ if (isdigit((unsigned char)s[0]) && isdigit((unsigned char)s[1]) && isdigit((unsigned char)s[2])) { - *t++ = (s[0]-'0')<<6 | (s[1]-'0')<<3 | (s[2]-'0'); + *_t++ = (s[0]-'0')<<6 | (s[1]-'0')<<3 | (s[2]-'0'); s += 2; } else if (s[0] == 'x' && isxdigit((unsigned char)s[1]) && isxdigit((unsigned char)s[2])) { - *t++ = hex2nibble(s[1]) << 4 | + *_t++ = hex2nibble(s[1]) << 4 | hex2nibble(s[2]) ; s += 2; } else if (isdigit((unsigned char)s[0])) { - *t++ = *s - '0'; + *_t++ = *s - '0'; } else if (*s == 'b') { - *t++ = '\b'; + *_t++ = '\b'; } else if (*s == 'n') { - *t++ = '\n'; + *_t++ = '\n'; } else if (*s == 'r') { - *t++ = '\r'; + *_t++ = '\r'; } else if (*s == 't') { - *t++ = '\t'; + *_t++ = '\t'; } else { - *t++ = *s; + *_t++ = *s; } s++; } } - *t = '\0'; + *_t = '\0'; return s; } @@ -432,7 +431,7 @@ specnames(void) { static struct { int *n; - char *v; + const char *v; } spnames[] = { { &c_hyphen, "hy" }, { &c_emdash, "em" }, @@ -462,7 +461,7 @@ specnames(void) int -findch(char *s) { +findch(const char *s) { struct bst_node *n; if (bst_srch(&chnames, (union bst_val)(void *)s, &n)) return 0; @@ -492,7 +491,6 @@ twdone(void) restore_tty(); } - void ptout(tchar i) { @@ -738,7 +736,7 @@ void move(void) { register int k; - register char *i, *j; + register const char *i, *j; char *p, *q; int iesct, dt; @@ -833,7 +831,7 @@ dostop(void) /*ARGSUSED*/ void -newpage(int unused) +newpage(int unused __unused) { realpage++; } diff --git a/troff/nroff.d/n6.c b/troff/nroff.d/n6.c index 280989942ce9..3754bd939dff 100644 --- a/troff/nroff.d/n6.c +++ b/troff/nroff.d/n6.c @@ -52,11 +52,11 @@ #include <stdio.h> #include <string.h> -#ifdef EUC +//#ifdef EUC #include <limits.h> #include <stdlib.h> #include <wchar.h> -#endif +//#endif #include <ctype.h> #include "tdef.h" #include "tw.h" @@ -68,7 +68,7 @@ */ int initbdtab[NFONT+1] ={ 0, 0, 0, 3, 3, 0, }; -int sbold = 0; +static int sbold = 0; int initfontlab[NFONT+1] = { 0, 'R', 'I', 'B', PAIR('B','I'), 'S', 0 }; extern int nchtab; @@ -221,7 +221,7 @@ setabs (void) /* set absolute char from \C'...' */ } int -tr2un(tchar c, int f) +tr2un(tchar c, int f __unused) { int k; diff --git a/troff/nroff.d/pt.h b/troff/nroff.d/pt.h index aa6be91dacb5..2f095f371265 100644 --- a/troff/nroff.d/pt.h +++ b/troff/nroff.d/pt.h @@ -10,7 +10,7 @@ extern char *skipstr(char *); extern char *getstr(char *, char *); extern char *getint(char *, int *); extern void specnames(void); -extern int findch(register char *); +extern int findch(register const char *); extern void twdone(void); extern void ptout1(void); extern char *plot(char *); diff --git a/troff/tdef.h b/troff/tdef.h index f5b3d4de7e0d..38620c4ede8a 100644 --- a/troff/tdef.h +++ b/troff/tdef.h @@ -415,6 +415,7 @@ extern int c_rooten; extern int c_boxrule; extern int c_lefthand; extern int c_dagger; +extern int c_isalnum; struct lgtab { struct lgtab *next; diff --git a/troff/troff.d/Makefile.mk b/troff/troff.d/Makefile.mk index c5064cde9e3c..630646cd7917 100644 --- a/troff/troff.d/Makefile.mk +++ b/troff/troff.d/Makefile.mk @@ -62,5 +62,5 @@ version.o: ../version.c otfdump_vs.o: ../version.c afm.o: dev.h afm.h otf.o: dev.h afm.h unimap.h -otfdump.o: afm.h afm.c otf.c otfdump.c dpost.d/getopt.c dev.h +otfdump.o: afm.h afm.c otf.c otfdump.c dev.h fontmap.o: fontmap.h diff --git a/troff/troff.d/afm.c b/troff/troff.d/afm.c index f87dcefaaf58..b5bea1c35e6f 100644 --- a/troff/troff.d/afm.c +++ b/troff/troff.d/afm.c @@ -31,6 +31,10 @@ #include "dev.h" #include "afm.h" +#ifndef __unused +#define __unused __attribute__((unused)) +#endif + extern char *chname; extern short *chtab; extern int nchtab; @@ -44,9 +48,9 @@ static void addkernpair(struct afmtab *, char *_line); /* * This table maps troff special characters to PostScript names. */ -const struct names { - char *trname; - char *psname; +static const struct names { + const char *trname; + const char *psname; } names[] = { { "hy", "hyphen" }, { "ct", "cent" }, @@ -81,7 +85,7 @@ const struct names { /* * Names for Symbol fonts only. */ -const struct names greeknames[] = { +static const struct names greeknames[] = { { "*A", "Alpha" }, { "*B", "Beta" }, { "*C", "Xi" }, @@ -133,7 +137,7 @@ const struct names greeknames[] = { { 0, 0 } }; -const struct names mathnames[] = { +static const struct names mathnames[] = { { "!=", "notequal" }, { "**", "asteriskmath" }, { "+-", "plusminus" }, @@ -187,7 +191,7 @@ const struct names mathnames[] = { { 0, 0 }, }; -const struct names largenames[] = { +static const struct names largenames[] = { { "bv", "braceex" }, { "lb", "braceleftbt" }, { "lc", "bracketlefttp" }, @@ -203,7 +207,7 @@ const struct names largenames[] = { { 0, 0 } }; -const struct names punctnames[] = { +static const struct names punctnames[] = { { "or", "bar" }, { "\\-","endash" }, { "aa","acute" }, @@ -216,7 +220,7 @@ const struct names punctnames[] = { /* * These names are only used with the S font. */ -const struct names Snames[] = { +static const struct names Snames[] = { { "br", "parenleftex" }, { "ul", "underscore" }, { "vr", "bracketleftex" }, @@ -226,7 +230,7 @@ const struct names Snames[] = { /* * These names are only used with the S1 font. */ -const struct names S1names[] = { +static const struct names S1names[] = { { "ru", "underscore" }, { 0, 0 } }; @@ -499,7 +503,7 @@ nextprime(int n) 268435399, 536870909, 1073741789, 2147483647 }; int mprime = 7; - int i; + size_t i; for (i = 0; i < sizeof primes / sizeof *primes; i++) if ((mprime = primes[i]) >= (n < 65536 ? n*4 : @@ -530,7 +534,7 @@ struct namecache * afmnamelook(struct afmtab *a, const char *name) { struct namecache *np; - unsigned h, c, n = 0; + int h, c, n = 0; h = pjw(name) % a->nameprime; np = &a->namecache[c = h]; @@ -632,7 +636,7 @@ afmremap(struct afmtab *a) #ifndef DUMP static int -asciiequiv(int code, const char *psc, enum spec s) +asciiequiv(int code __unused, const char *psc, enum spec s) { int i; @@ -655,7 +659,7 @@ asciiequiv(int code, const char *psc, enum spec s) } static char * -thisword(const char *text, const char *wrd) +thisword(char *text, const char *wrd) { while (*text == *wrd) text++, wrd++; @@ -665,7 +669,7 @@ thisword(const char *text, const char *wrd) *text == '\r') { while (*text != 0 && (*text == ' ' || *text == '\t')) text++; - return (char *)text; + return text; } return NULL; } @@ -890,9 +894,7 @@ afmget(struct afmtab *a, char *contents, size_t size) cp = a->file; else cp++; - l = strlen(cp) + 1; - a->base = malloc(l); - n_strcpy(a->base, cp, l); + a->base = strdup(cp); if ((cp = strrchr(a->base, '.')) != NULL) *cp = '\0'; if (dev.allpunct) @@ -988,8 +990,8 @@ afmget(struct afmtab *a, char *contents, size_t size) * troff and dpost need it in combination with AFM support. */ void -makefont(int nf, char *devfontab, char *devkerntab, char *devcodetab, - char *devfitab, int nw) +makefont(int nf, const char *devfontab, const char *devkerntab, + const char *devcodetab, const char *devfitab, int nw) { int i; diff --git a/troff/troff.d/afm.h b/troff/troff.d/afm.h index 5c18a38f99f7..59c601905917 100644 --- a/troff/troff.d/afm.h +++ b/troff/troff.d/afm.h @@ -123,7 +123,7 @@ extern int afmget(struct afmtab *, char *, size_t); extern int otfget(struct afmtab *, char *, size_t); extern struct namecache *afmnamelook(struct afmtab *, const char *); extern int afmgetkern(struct afmtab *, int, int); -extern void makefont(int, char *, char *, char *, char *, int); +extern void makefont(int, const char *, const char *, const char *, const char *, int); extern int unitconv(int); extern void afmalloc(struct afmtab *, int); extern void afmremap(struct afmtab *); diff --git a/troff/troff.d/devaps/Makefile.mk b/troff/troff.d/devaps/Makefile.mk index 92e3d7f1c3fd..e38fffbdd64b 100644 --- a/troff/troff.d/devaps/Makefile.mk +++ b/troff/troff.d/devaps/Makefile.mk @@ -1,4 +1,4 @@ -OBJ = daps.o build.o draw.o getopt.o version.o +OBJ = daps.o build.o draw.o version.o FONTS = B I R S CT CW CX GB GI GR GS HI HK HX PO PX S1 SC SM TX DESC \ C G H BI CE CI HB HL MB MI MR MX PA PB PI TB diff --git a/troff/troff.d/devaps/getopt.c b/troff/troff.d/devaps/getopt.c deleted file mode 100644 index bb8c53d072cb..000000000000 --- a/troff/troff.d/devaps/getopt.c +++ /dev/null @@ -1,222 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ -/* - * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany - * - * Sccsid @(#)getopt.c 1.10 (gritter) 12/16/07 - */ -/* from OpenSolaris "getopt.c 1.23 05/06/08 SMI" */ - -/* Copyright (c) 1988 AT&T */ -/* All Rights Reserved */ - - -/* - * See getopt(3C) and SUS/XPG getopt() for function definition and - * requirements. - * - * This actual implementation is a bit looser than the specification - * as it allows any character other than ':' to be used as an option - * character - The specification only guarantees the alnum characters - * ([a-z][A-Z][0-9]). - */ - -#include <sys/types.h> -#include <string.h> -#include <stdio.h> - -extern ssize_t write(int, const void *, size_t); - -char *optarg = NULL; -int optind = 1; -int opterr = 1; -int optopt = 0; - -#define ERR(s, c) err(s, c, optstring, argv[0]) -static void -err(const char *s, int c, const char *optstring, const char *argv0) -{ - char errbuf[256], *ep = errbuf; - const char *cp; - - if (opterr && optstring[0] != ':') { - for (cp = argv0; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++) - *ep = *cp; - for (cp = ": "; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++) - *ep = *cp; - for (cp = s; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++) - *ep = *cp; - for (cp = " -- "; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++) - *ep = *cp; - if (ep<&errbuf[sizeof errbuf]) - *ep++ = c; - if (ep<&errbuf[sizeof errbuf]) - *ep++ = '\n'; - write(2, errbuf, ep - errbuf); - } -} - -/* - * getopt_sp is required to keep state between successive calls to getopt() - * while extracting aggregated options (ie: -abcd). Hence, getopt() is not - * thread safe or reentrant, but it really doesn't matter. - * - * So, why isn't this "static" you ask? Because the historical Bourne - * shell has actually latched on to this little piece of private data. - */ -int getopt_sp = 1; - -/* - * Determine if the specified character (c) is present in the string - * (optstring) as a regular, single character option. If the option is found, - * return a pointer into optstring pointing at the option character, - * otherwise return null. The character ':' is not allowed. - */ -static char * -parse(const char *optstring, const char c) -{ - char *cp = (char *)optstring; - - if (c == ':') - return (NULL); - do { - if (*cp == c) - return (cp); - } while (*cp++ != '\0'); - return (NULL); -} - -/* - * External function entry point. - */ -int -getopt(int argc, char *const *argv, const char *optstring) -{ - char c; - char *cp; - - /* - * Has the end of the options been encountered? The following - * implements the SUS requirements: - * - * If, when getopt() is called: - * argv[optind] is a null pointer - * *argv[optind] is not the character '-' - * argv[optind] points to the string "-" - * getopt() returns -1 without changing optind. If - * argv[optind] points to the string "--" - * getopt() returns -1 after incrementing optind. - */ - if (getopt_sp == 1) { - if (optind >= argc || argv[optind][0] != '-' || - argv[optind] == NULL || argv[optind][1] == '\0') - return (EOF); - else if (strcmp(argv[optind], "--") == 0) { - optind++; - return (EOF); - } - } - - /* - * Getting this far indicates that an option has been encountered. - * Note that the syntax of optstring applies special meanings to - * the characters ':' and '(', so they are not permissible as - * option letters. A special meaning is also applied to the ')' - * character, but its meaning can be determined from context. - * Note that the specification only requires that the alnum - * characters be accepted. - */ - optopt = c = (unsigned char)argv[optind][getopt_sp]; - optarg = NULL; - if ((cp = parse(optstring, c)) == NULL) { - /* LINTED: variable format specifier */ - ERR("illegal option", c); - if (argv[optind][++getopt_sp] == '\0') { - optind++; - getopt_sp = 1; - } - return ('?'); - } - optopt = c = *cp; - - /* - * A valid option has been identified. If it should have an - * option-argument, process that now. SUS defines the setting - * of optarg as follows: - * - * 1. If the option was the last character in the string pointed to - * by an element of argv, then optarg contains the next element - * of argv, and optind is incremented by 2. If the resulting - * value of optind is not less than argc, this indicates a - * missing option-argument, and getopt() returns an error - * indication. - * - * 2. Otherwise, optarg points to the string following the option - * character in that element of argv, and optind is incremented - * by 1. - * - * The second clause allows -abcd (where b requires an option-argument) - * to be interpreted as "-a -b cd". - */ - if (*(cp + 1) == ':') { - /* The option takes an argument */ - if (argv[optind][getopt_sp+1] != '\0') { - optarg = &argv[optind++][getopt_sp+1]; - } else if (++optind >= argc) { - /* LINTED: variable format specifier */ - ERR("option requires an argument", c); - getopt_sp = 1; - optarg = NULL; - return (optstring[0] == ':' ? ':' : '?'); - } else - optarg = argv[optind++]; - getopt_sp = 1; - } else { - /* The option does NOT take an argument */ - if (argv[optind][++getopt_sp] == '\0') { - getopt_sp = 1; - optind++; - } - optarg = NULL; - } - return (c); -} /* getopt() */ - -#ifdef __APPLE__ -/* - * Starting with Mac OS 10.5 Leopard, <unistd.h> turns getopt() - * into getopt$UNIX2003() by default. Consequently, this function - * is called instead of the one defined above. However, optind is - * still taken from this file, so in effect, options are not - * properly handled. Defining an own getopt$UNIX2003() function - * works around this issue. - */ -int -getopt$UNIX2003(int argc, char *const argv[], const char *optstring) -{ - return getopt(argc, argv, optstring); -} -#endif /* __APPLE__ */ diff --git a/troff/troff.d/dpost.d/Makefile.mk b/troff/troff.d/dpost.d/Makefile.mk index 36847f46d999..d3d161638b4c 100644 --- a/troff/troff.d/dpost.d/Makefile.mk +++ b/troff/troff.d/dpost.d/Makefile.mk @@ -1,7 +1,7 @@ BST = ../../../stuff/bst OBJ = dpost.o draw.o color.o pictures.o ps_include.o afm.o \ - makedev.o glob.o misc.o request.o version.o getopt.o \ + makedev.o glob.o misc.o request.o version.o \ asciitype.o otf.o ../fontmap.o $(BST)/bst.o FLAGS = -I. -I.. -DFNTDIR='"$(FNTDIR)"' -DPSTDIR='"$(PSTDIR)"' $(EUC) \ diff --git a/troff/troff.d/dpost.d/color.c b/troff/troff.d/dpost.d/color.c index 4568aec09177..95e30d15fa04 100644 --- a/troff/troff.d/dpost.d/color.c +++ b/troff/troff.d/dpost.d/color.c @@ -181,7 +181,7 @@ newcolor ( char *p; /* next character in *name */ - int i; /* goes in color[i] */ + size_t i; /* goes in color[i] */ /* diff --git a/troff/troff.d/dpost.d/dpost.c b/troff/troff.d/dpost.d/dpost.c index f27d33cbd4f8..dd5c5465721b 100644 --- a/troff/troff.d/dpost.d/dpost.c +++ b/troff/troff.d/dpost.d/dpost.c @@ -281,31 +281,20 @@ #include "afm.h" #include "fontmap.h" +char *progname; +static const char *prologue = DPOST; /* the basic PostScript prologue */ +const char *colorfile = COLOR; /* things needed for color support */ +const char *drawfile = DRAW; /* and drawing */ +static const char *cutmarksfile = CUTMARKS; +static const char *formfile = FORMFILE; /* stuff for multiple pages per sheet */ +const char *baselinefile = BASELINE; -#if defined (__GLIBC__) && defined (_IO_getc_unlocked) -#undef getc -#define getc(f) _IO_getc_unlocked(f) -#endif -#if defined (__GLIBC__) && defined (_IO_putc_unlocked) -#undef putc -#define putc(c, f) _IO_putc_unlocked(c, f) -#endif - - -char *progname; -char *prologue = DPOST; /* the basic PostScript prologue */ -char *colorfile = COLOR; /* things needed for color support */ -char *drawfile = DRAW; /* and drawing */ -char *cutmarksfile = CUTMARKS; -char *formfile = FORMFILE; /* stuff for multiple pages per sheet */ -char *baselinefile = BASELINE; +static const char *fontdir = FONTDIR; /* binary device directories found here */ +static char *hostfontdir = NULL; /* host resident font directory */ -char *fontdir = FONTDIR; /* binary device directories found here */ -char *hostfontdir = NULL; /* host resident font directory */ - -int formsperpage = 1; /* page images on each piece of paper */ -int copies = 1; /* and this many copies of each sheet */ -int picflag = ON; /* enable/disable picture inclusion */ +static int formsperpage = 1; /* page images on each piece of paper */ +static int copies = 1; /* and this many copies of each sheet */ +int picflag = ON; /* enable/disable picture inclusion */ /* @@ -325,7 +314,7 @@ int picflag = ON; /* enable/disable picture inclusion */ int encoding = DFLTENCODING; int realencoding = DFLTENCODING; int maxencoding = MAXENCODING; -int eflag; +static int eflag; int LanguageLevel; /* PostScript output language level */ static int Binary; /* PostScript output contains binary data */ @@ -341,10 +330,10 @@ static int Binary; /* PostScript output contains binary data */ */ -char seenfonts[MAXINTERNAL+1]; -int docfonts = 0; -struct afmtab **afmfonts; -int afmcount = 0; +static char seenfonts[MAXINTERNAL+1]; +static int docfonts = 0; +static struct afmtab **afmfonts; +static int afmcount = 0; /* * @@ -359,8 +348,8 @@ int afmcount = 0; #define devname troff_devname -char devname[20] = ""; /* job is formatted for this printer */ -char *realdev = DEVNAME; /* a good description of target printer */ +static char devname[20] = ""; /* job is formatted for this printer */ +static const char *realdev = DEVNAME; /* a good description of target printer */ /* @@ -373,12 +362,12 @@ char *realdev = DEVNAME; /* a good description of target printer */ struct dev dev; /* DESC starts this way */ struct Font **fontbase; /* FONT files begin this way */ -int *pstab; /* list of available sizes */ -int nsizes = 1; /* and the number of sizes in that list */ -int smnt; /* index of first special font */ +static int *pstab; /* list of available sizes */ +static int nsizes = 1; /* and the number of sizes in that list */ +static int smnt; /* index of first special font */ int nchtab; /* number of special character names */ -int fsize; /* max size of a font files in bytes */ -int unitwidth; /* set to dev.unitwidth */ +static int fsize; /* max size of a font files in bytes */ +static int unitwidth; /* set to dev.unitwidth */ char *chname; /* special character strings */ short *chtab; /* used to locate character names */ unsigned short **fitab; /* locates char info on each font */ @@ -402,7 +391,7 @@ char **kerntab; /* for makefont() */ */ -char *downloaded; /* nonzero means it's been downloaded */ +static char *downloaded; /* nonzero means it's been downloaded */ /* @@ -416,22 +405,22 @@ char *downloaded; /* nonzero means it's been downloaded */ int nfonts = 0; /* number of font positions */ int size = 1; /* current size - internal value */ #define FRACTSIZE -23 /* if size == FRACTSIZE then ... */ -float fractsize = 0; /* fractional point size */ -int font = 0; /* font position we're using now */ -int subfont = 0; /* extra encoding vector */ +static float fractsize = 0; /* fractional point size */ +static int font = 0; /* font position we're using now */ +static int subfont = 0; /* extra encoding vector */ int hpos = 0; /* where troff wants to be - horizontally */ int vpos = 0; /* same but vertically */ -float lastw = 0; /* width of the last input character */ -int track = 0; /* tracking hint from troff */ -int lasttrack = 0; /* previous tracking hint */ -int tracked; /* records need to flush track */ -int lastc = 0; /* and its name (or index) */ +static float lastw = 0; /* width of the last input character */ +static int track = 0; /* tracking hint from troff */ +static int lasttrack = 0; /* previous tracking hint */ +static int tracked; /* records need to flush track */ +static int lastc = 0; /* and its name (or index) */ int res; /* resolution assumed in input file */ -float widthfac = 1.0; /* for emulation = res/dev.res */ -float horscale = 1.0; /* horizontal font scaling */ -float lasthorscale = 1.0; /* last horizontal font scaling */ -int wordspace = 0; /* w command was last */ +static float widthfac = 1.0; /* for emulation = res/dev.res */ +static float horscale = 1.0; /* horizontal font scaling */ +static float lasthorscale = 1.0; /* last horizontal font scaling */ +static int wordspace = 0; /* w command was last */ /* @@ -443,13 +432,13 @@ int wordspace = 0; /* w command was last */ */ -int lastsize = -1; /* last internal size we used */ -float lastfractsize = -1; /* last fractional size */ -int lastfont = -1; /* last font we told printer about */ -int lastsubfont = -1; /* last extra encoding vector */ -float lastx = -1; /* printer's current position */ -int lasty = -1; -int savey = -1; +static int lastsize = -1; /* last internal size we used */ +static float lastfractsize = -1; /* last fractional size */ +static int lastfont = -1; /* last font we told printer about */ +static int lastsubfont = -1; /* last extra encoding vector */ +static float lastx = -1; /* printer's current position */ +static int lasty = -1; +static int savey = -1; int lastend; /* where last character on this line was */ @@ -466,7 +455,7 @@ int lastend; /* where last character on this line was */ */ -struct { +static struct { struct afmtab *afm; /* AFM data, if any */ char *name; /* name of the font loaded here */ @@ -493,9 +482,9 @@ struct { */ -int gotspecial = FALSE; -int gotregular = FALSE; -int seenpage = FALSE; +static int gotspecial = FALSE; +static int gotregular = FALSE; +static int seenpage = FALSE; /* @@ -511,10 +500,10 @@ int seenpage = FALSE; */ -float pointslop = SLOP; /* horizontal error in points */ -int Sflag; /* unless -S gives explicit slop */ -int slop; /* and machine units */ -int rvslop; /* to extend box in reverse video mode */ +static float pointslop = SLOP; /* horizontal error in points */ +static int Sflag; /* unless -S gives explicit slop */ +static int slop; /* and machine units */ +static int rvslop; /* to extend box in reverse video mode */ /* @@ -530,11 +519,11 @@ int rvslop; /* to extend box in reverse video mode */ */ -int textcount = 0; /* strings accumulated so far */ -int stringstart = 0; /* where the next one starts */ -int laststrstart = INT_MIN; /* save for optimization */ -int spacecount = 0; /* spaces seen so far on current line */ -int charcount = 0; /* characters on current line */ +static int textcount = 0; /* strings accumulated so far */ +static int stringstart = 0; /* where the next one starts */ +static int laststrstart = INT_MIN; /* save for optimization */ +static int spacecount = 0; /* spaces seen so far on current line */ +static int charcount = 0; /* characters on current line */ /* @@ -547,9 +536,9 @@ int charcount = 0; /* characters on current line */ */ -char strings[STRINGSPACE]; -char *strptr; -Line line[MAXSTACK+3]; +static char strings[STRINGSPACE]; +static char *strptr; +static Line line[MAXSTACK+3]; /* @@ -572,8 +561,8 @@ Line line[MAXSTACK+3]; */ -Devfontmap *devfontmap = NULL; /* device level */ -Fontmap fontmap[] = FONTMAP; /* and general mapping tables - emulation */ +static Devfontmap *devfontmap = NULL; /* device level */ +static Fontmap fontmap[] = FONTMAP; /* and general mapping tables - emulation */ /* @@ -642,16 +631,16 @@ int printed = 0; /* charge for this many pages */ */ -FILE *tf = NULL; /* PostScript output goes here */ -FILE *gf = NULL; /* global data goes here */ -FILE *rf = NULL; /* resource data goes here */ -FILE *sf = NULL; /* supplied resource comments go here */ -FILE *nf = NULL; /* needed resource comments go here */ -FILE *pf = NULL; /* elements of _custompagesetup */ -int sfcount; /* count of supplied resources */ -int nfcount; /* count of needed resources */ -int ostdout; /* old standard output */ -FILE *fp_acct = NULL; /* accounting stuff written here */ +FILE *tf = NULL; /* PostScript output goes here */ +FILE *gf = NULL; /* global data goes here */ +FILE *rf = NULL; /* resource data goes here */ +FILE *sf = NULL; /* supplied resource comments go here */ +FILE *nf = NULL; /* needed resource comments go here */ +FILE *pf = NULL; /* elements of _custompagesetup */ +static int sfcount; /* count of supplied resources */ +static int nfcount; /* count of needed resources */ +static int ostdout; /* old standard output */ +static FILE *fp_acct = NULL; /* accounting stuff written here */ /* @@ -664,7 +653,7 @@ FILE *fp_acct = NULL; /* accounting stuff written here */ */ -char temp[4096]; +static char temp[4096]; /*****************************************************************************/ @@ -771,7 +760,7 @@ main(int agc, char *agv[]) } /* End of main */ /*****************************************************************************/ -int +static int putint(int n, FILE *fp) { char buf[20]; @@ -801,7 +790,7 @@ putint(int n, FILE *fp) return c; } -int +static int putstring1(const char *sp, int n, FILE *fp) { /* @@ -815,7 +804,7 @@ putstring1(const char *sp, int n, FILE *fp) return n + 2; } -int +static int putstring(const char *sp, int n, FILE *fp) { int c = 0, m; @@ -865,7 +854,7 @@ init_signals(void) /*****************************************************************************/ static char * -pdfdate(time_t *tp, char *buf, size_t size) +pdfdate(time_t *tp, char *buf, size_t sz) { struct tm *tmptr; int tzdiff, tzdiff_hour, tzdiff_min; @@ -877,7 +866,7 @@ pdfdate(time_t *tp, char *buf, size_t size) tmptr = localtime(tp); if (tmptr->tm_isdst > 0) tzdiff_hour++; - snprintf(buf, size, "(D:%04d%02d%02d%02d%02d%02d%+03d'%02d')", + snprintf(buf, sz, "(D:%04d%02d%02d%02d%02d%02d%+03d'%02d')", tmptr->tm_year + 1900, tmptr->tm_mon + 1, tmptr->tm_mday, tmptr->tm_hour, tmptr->tm_min, tmptr->tm_sec, @@ -1257,14 +1246,6 @@ setpaths ( /*****************************************************************************/ -static int -prefix(const char *str, const char *pfx) -{ - while (*pfx && *str == *pfx) - str++, pfx++; - return *str == 0; -} - static void setmarks(char *str) { @@ -1651,7 +1632,7 @@ devcntrl( char str[4096], *buf, str1[4096]; - int c, n, size; + int c, n, sz; /* @@ -1665,7 +1646,7 @@ devcntrl( */ - buf = malloc(size = 4096); + buf = malloc(sz = 4096); sget(str, sizeof str, fp); /* get the control function name */ switch ( str[0] ) { /* only the first character counts */ @@ -1707,7 +1688,7 @@ devcntrl( case 'f': /* load font in a position */ fscanf(fp, "%d", &n); sget(str, sizeof str, fp); - fgets(buf, size, fp); /* in case there's a filename */ + fgets(buf, sz, fp); /* in case there's a filename */ ungetc('\n', fp); /* fgets() goes too far */ str1[0] = '\0'; /* in case there's nothing to come in */ c = 0; @@ -1747,15 +1728,15 @@ devcntrl( ungetc(c, fp); n = 0; for (;;) { - fgets(&buf[n], size - n, fp); + fgets(&buf[n], sz - n, fp); if ((c = getc(fp)) != '+') { ungetc(c, fp); break; } while (buf[n]) n++; - if (size - n < 4096) - buf = realloc(buf, size += 4096); + if (sz - n < 4096) + buf = realloc(buf, sz += 4096); lineno++; } if ( strcmp(str, "PI") == 0 || strcmp(str, "PictureInclusion") == 0 ) @@ -1913,7 +1894,7 @@ fontinit(void) void loadfont ( int n, /* load this font position */ - char *s, /* with the file for this font */ + const char *s, /* with the file for this font */ char *s1, /* taken from here - possibly */ int forcespecial, /* this is definitively a special font */ int spec /* map specification */ @@ -1926,7 +1907,7 @@ loadfont ( char *fpout = NULL; /* for reading *s file */ int fin; /* for reading *s.afm file */ int nw; /* number of width table entries */ - char *p; + const char *p; char *path; size_t l; @@ -1991,9 +1972,7 @@ loadfont ( goto fail; } close(fin); - l = strlen(path) + 1; - a->path = malloc(l); - n_strcpy(a->path, path, l); + a->path = strdup(path); if (path != temp) free(path); a->file = s; @@ -2098,7 +2077,7 @@ loadspecial(void) /*****************************************************************************/ -char *defaultFonts[] = +static const char *defaultFonts[] = { "R", "I", "B", "BI", "CW", "H", "HB", "HX", "S1", "S", NULL }; void @@ -2165,9 +2144,9 @@ fontprint ( /*****************************************************************************/ -char * +const char * mapfont ( - char *name /* troff wanted this font */ + const char *name /* troff wanted this font */ ) @@ -2390,7 +2369,7 @@ t_init(void) if (eflag == 0) realencoding = encoding = dev.encoding; if (encoding == 5) { - LanguageLevel = MAX(LanguageLevel, 2); + LanguageLevel = max(LanguageLevel, 2); Binary++; } slop = pointslop * res / POINTS + .5; @@ -2433,13 +2412,13 @@ static struct supplylist { } *supplylist; void -t_supply(char *font) /* supply a font */ +t_supply(char *fnt) /* supply a font */ { struct supplylist *sp; char *np, *file, *type = NULL, c; - while (*font == ' ' || *font == '\t') - font++; + while (*fnt == ' ' || *fnt == '\t') + fnt++; for (np = font; *np && *np != ' ' && *np != '\t' && *np != '\n'; np++); if (*np == '\0' || *np == '\n') return; @@ -2459,10 +2438,10 @@ t_supply(char *font) /* supply a font */ *np = '\0'; } for (sp = supplylist; sp; sp = sp->next) - if (strcmp(sp->font, font) == 0) + if (strcmp(sp->font, fnt) == 0) return; sp = calloc(1, sizeof *sp); - sp->font = strdup(font); + sp->font = strdup(fnt); sp->file = afmdecodepath(file); sp->type = type && *type ? strdup(type) : NULL; sp->next = supplylist; @@ -2483,11 +2462,11 @@ static const char ps_truetypefont[] = "%!PS-TrueTypeFont"; static const char hex[] = "0123456789abcdef"; static void -supplypfb(char *font, char *path, FILE *fp) +supplypfb(char *fnt, char *path, FILE *fp) { char buf[30]; - long length; - int i, c = EOF, n, type = 0, lastc = EOF; + size_t i, n, length; + int c = EOF, type = 0, lastch = EOF; if (fread(buf, 1, 6, fp) != 6) error(FATAL, "no data in %s", path); @@ -2508,10 +2487,10 @@ supplypfb(char *font, char *path, FILE *fp) length--; } if (sfcount++ == 0) - fprintf(sf, "%%%%DocumentSuppliedResources: font %s\n", font); + fprintf(sf, "%%%%DocumentSuppliedResources: font %s\n", fnt); else - fprintf(sf, "%%%%+ font %s\n", font); - fprintf(rf, "%%%%BeginResource: font %s\n", font); + fprintf(sf, "%%%%+ font %s\n", fnt); + fprintf(rf, "%%%%BeginResource: font %s\n", fnt); for (;;) { switch (type) { case 1: @@ -2524,13 +2503,13 @@ supplypfb(char *font, char *path, FILE *fp) else length--; putc('\n', rf); - lastc = '\n'; + lastch = '\n'; break; case 0: continue; default: putc(c, rf); - lastc = c; + lastch = c; } } if (c == EOF) @@ -2546,12 +2525,12 @@ supplypfb(char *font, char *path, FILE *fp) putc(hex[buf[i]&017], rf); } putc('\n', rf); - lastc = '\n'; + lastch = '\n'; length -= n; } break; case 3: - if (lastc != '\n') + if (lastch != '\n') putc('\n', rf); fprintf(rf, "%%%%EndResource\n"); fclose(fp); @@ -2569,24 +2548,23 @@ supplypfb(char *font, char *path, FILE *fp) } static void -supplyotf(char *font, char *path, FILE *fp) +supplyotf(char *fnt, char *path, FILE *fp) { static int cffcount; struct stat st; char *contents; - size_t size, offset, length; - int i; + size_t sz, offset, length, i; int fsType; const char StartData[] = " StartData "; if (fstat(fileno(fp), &st) < 0) error(FATAL, "cannot stat %s", path); - size = st.st_size; - contents = malloc(size); - if (fread(contents, 1, size, fp) != size) + sz = st.st_size; + contents = malloc(sz); + if (fread(contents, 1, sz, fp) != sz) error(FATAL, "cannot read %s", path); fclose(fp); - if ((fsType = otfcff(path, contents, size, &offset, &length)) < 0) { + if ((fsType = otfcff(path, contents, sz, &offset, &length)) < 0) { free(contents); return; } @@ -2602,19 +2580,19 @@ supplyotf(char *font, char *path, FILE *fp) needresource("procset FontSetInit 0 0"); } if (sfcount++ == 0) - fprintf(sf, "%%%%DocumentSuppliedResources: font %s\n", font); + fprintf(sf, "%%%%DocumentSuppliedResources: font %s\n", fnt); else - fprintf(sf, "%%%%+ font %s\n", font); - fprintf(rf, "%%%%BeginResource: font %s\n", font); + fprintf(sf, "%%%%+ font %s\n", fnt); + fprintf(rf, "%%%%BeginResource: font %s\n", fnt); fprintf(rf, "/FontSetInit /ProcSet findresource begin\n"); if (encoding == 5) { fprintf(rf, "%%%%BeginData: %ld Binary Bytes\n", - (long)(length + 13 + strlen(font) + 12)); - fprintf(rf, "/%s %12ld StartData ", font, (long)length); + (long)(length + 13 + strlen(fnt) + 12)); + fprintf(rf, "/%s %12ld StartData ", fnt, (long)length); fwrite(&contents[offset], 1, length, rf); fprintf(rf, "\n%%%%EndData\n"); } else { - fprintf(rf, "/%s %ld ", font, (long)length); + fprintf(rf, "/%s %ld ", fnt, (long)length); fprintf(rf, "currentfile /ASCIIHexDecode filter cvx exec\n"); for (i = 0; StartData[i]; i++) { putc(hex[(StartData[i]&0360)>>4], rf); @@ -2631,39 +2609,39 @@ supplyotf(char *font, char *path, FILE *fp) } fprintf(rf, "%%%%EndResource\n"); free(contents); - LanguageLevel = MAX(LanguageLevel, 3); + LanguageLevel = max(LanguageLevel, 3); } static void -supplyttf(char *font, char *path, FILE *fp) +supplyttf(char *fnt, char *path, FILE *fp) { struct stat st; char *contents; - size_t size; + size_t sz; if (fstat(fileno(fp), &st) < 0) error(FATAL, "cannot stat %s", path); - size = st.st_size; - contents = malloc(size); - if (fread(contents, 1, size, fp) != size) + sz = st.st_size; + contents = malloc(sz); + if (fread(contents, 1, sz, fp) != sz) error(FATAL, "cannot read %s", path); fclose(fp); if (sfcount++ == 0) - fprintf(sf, "%%%%DocumentSuppliedResources: font %s\n", font); + fprintf(sf, "%%%%DocumentSuppliedResources: font %s\n", fnt); else - fprintf(sf, "%%%%+ font %s\n", font); - fprintf(rf, "%%%%BeginResource: font %s\n", font); - otft42(font, path, contents, size, rf); + fprintf(sf, "%%%%+ font %s\n", fnt); + fprintf(rf, "%%%%BeginResource: font %s\n", fnt); + otft42(fnt, path, contents, sz, rf); fprintf(rf, "%%%%EndResource\n"); free(contents); - LanguageLevel = MAX(LanguageLevel, 2); + LanguageLevel = max(LanguageLevel, 2); } static void -supply1(char *font, char *file, char *type) +supply1(char *fnt, char *file, char *type) { FILE *fp; - char line[4096], c; + char linebuf[4096], c; if (strchr(file, '/') == 0) { snprintf(temp, sizeof temp, "%s/dev%s/%s.%s", @@ -2679,48 +2657,48 @@ supply1(char *font, char *file, char *type) c == 0 || c == 't' ? "ttf" : "anything"; } if (strcmp(type, "pfb") == 0) { - supplypfb(font, file, fp); + supplypfb(fnt, file, fp); return; } if (strcmp(type, "otf") == 0) { - supplyotf(font, file, fp); + supplyotf(fnt, file, fp); return; } if (strcmp(type, "ttf") == 0) { - supplyttf(font, file, fp); + supplyttf(fnt, file, fp); return; } - if (fgets(line, sizeof line, fp) == NULL) + if (fgets(linebuf, sizeof linebuf, fp) == NULL) error(FATAL, "missing data in %s", file); - if (strncmp(line, ps_adobe_font_, strlen(ps_adobe_font_)) && - strncmp(line, ps_truetypefont, strlen(ps_truetypefont))) + if (strncmp(linebuf, ps_adobe_font_, strlen(ps_adobe_font_)) && + strncmp(linebuf, ps_truetypefont, strlen(ps_truetypefont))) error(FATAL, "file %s does not start with \"%s\" or \"%s\"", file, ps_adobe_font_, ps_truetypefont); if (sfcount++ == 0) - fprintf(sf, "%%%%DocumentSuppliedResources: font %s\n", font); + fprintf(sf, "%%%%DocumentSuppliedResources: font %s\n", fnt); else - fprintf(sf, "%%%%+ font %s\n", font); - fprintf(rf, "%%%%BeginResource: font %s\n", font); - while (fgets(line, sizeof line, fp) != NULL) - fputs(line, rf); + fprintf(sf, "%%%%+ font %s\n", fnt); + fprintf(rf, "%%%%BeginResource: font %s\n", fnt); + while (fgets(linebuf, sizeof linebuf, fp) != NULL) + fputs(linebuf, rf); fclose(fp); fprintf(rf, "%%%%EndResource\n"); } static void -t_dosupply(const char *font) +t_dosupply(const char *fnt) { struct supplylist *sp; for (sp = supplylist; sp; sp = sp->next) - if (strcmp(sp->font, font) == 0) { + if (strcmp(sp->font, fnt) == 0) { if (sp->done == 0) { supply1(sp->font, sp->file, sp->type); sp->done = 1; } return; } - needresource("font %s", font); + needresource("font %s", fnt); } /*****************************************************************************/ @@ -3388,7 +3366,7 @@ t_slant ( void t_reset ( - int c /* pause or restart */ + int c __unused /* pause or restart */ ) @@ -3722,7 +3700,7 @@ oprep(int stext) if (stext) { starttext(); - if ( ABS(hpos - lastx) > slop ) + if ( fabsf(hpos - lastx) > slop ) endstring(); } wordspace = 0; @@ -4251,7 +4229,7 @@ charlib ( char *name; /* name of the character */ char tname[10]; /* in case it's a single ASCII character */ - char *filename; /* real file name */ + const char *filename; /* real file name */ /* @@ -4321,7 +4299,7 @@ charlib ( int doglobal ( - char *name /* copy this to the output - globally */ + const char *name /* copy this to the output - globally */ ) @@ -4599,7 +4577,7 @@ orderbookmarks(void) int counts[MAXBOOKMARKLEVEL+1]; int refs[MAXBOOKMARKLEVEL+1]; - int i, j, k, t; + size_t i, j, k, t; int lvl = 0; /* diff --git a/troff/troff.d/dpost.d/dpost.h b/troff/troff.d/dpost.d/dpost.h index ca96c570f1e7..9ec006ea32b6 100644 --- a/troff/troff.d/dpost.d/dpost.h +++ b/troff/troff.d/dpost.d/dpost.h @@ -148,8 +148,8 @@ typedef struct { typedef struct { - char *name; /* font name we're looking for */ - char *use; /* and this is what we should use */ + const char *name; /* font name we're looking for */ + const char *use; /* and this is what we should use */ } Fontmap; diff --git a/troff/troff.d/dpost.d/draw.c b/troff/troff.d/dpost.d/draw.c index 68d3215b4418..11e91f5d24e8 100644 --- a/troff/troff.d/dpost.d/draw.c +++ b/troff/troff.d/dpost.d/draw.c @@ -139,9 +139,9 @@ #include "ext.h" /* external variable definitions */ -int gotdraw = FALSE; /* TRUE when *drawfile has been added */ -int gotbaseline = FALSE; /* TRUE after *baselinefile is added */ -int inpath = FALSE; /* TRUE if we're putting pieces together */ +static int gotdraw = FALSE; /* TRUE when *drawfile has been added */ +static int gotbaseline = FALSE; /* TRUE after *baselinefile is added */ +static int inpath = FALSE; /* TRUE if we're putting pieces together */ /* @@ -349,7 +349,7 @@ drawspline( int x[100], y[100]; - int i, N; + size_t i, N; /* diff --git a/troff/troff.d/dpost.d/gen.h b/troff/troff.d/dpost.d/gen.h index 6e0a2bb1ef86..e0d02d4b2ab2 100644 --- a/troff/troff.d/dpost.d/gen.h +++ b/troff/troff.d/dpost.d/gen.h @@ -61,20 +61,6 @@ extern const char creator[]; #define PI 3.141592654 #endif - -/* - * - * A few simple macros. - * - */ - - -#define ABS(A) ((A) >= 0 ? (A) : -(A)) -#undef MIN -#define MIN(A, B) ((A) < (B) ? (A) : (B)) -#undef MAX -#define MAX(A, B) ((A) > (B) ? (A) : (B)) - /* color.c */ void getcolor(void); void newcolor(char *); @@ -91,11 +77,11 @@ void account(void); void conv(register FILE *); void devcntrl(FILE *); void fontinit(void); -void loadfont(int, char *, char *, int, int); +void loadfont(int, const char *, char *, int, int); void loadspecial(void); void loaddefault(void); void fontprint(int); -char *mapfont(char *); +const char *mapfont(const char *); void getdevmap(void); char *mapdevfont(char *); void reset(void); @@ -130,7 +116,7 @@ void endline(void); void addchar(int); void addoctal(int); void charlib(int); -int doglobal(char *); +int doglobal(const char *); void documentfont(const char *); void documentfonts(void); void redirect(int); @@ -150,10 +136,11 @@ void drawtext(char *); void settext(char *); /* glob.c */ /* misc.c */ -void error(int, char *, ...); +void interrupt(int); +void error(int, const char *, ...); void out_list(char *); int in_olist(int); -int cat(char *, FILE *); +int cat(const char *, FILE *); int str_convert(char **, int); char *tempname(const char *); int psskip(size_t, FILE *); @@ -170,5 +157,5 @@ void ps_include(const char *, FILE *, FILE *, int, int, int, int, /* request.c */ void saverequest(char *); void writerequest(int, FILE *); -void dumprequest(char *, char *, FILE *); +void dumprequest(char *, const char *, FILE *); /* tempnam.c */ diff --git a/troff/troff.d/dpost.d/getopt.c b/troff/troff.d/dpost.d/getopt.c deleted file mode 100644 index bb8c53d072cb..000000000000 --- a/troff/troff.d/dpost.d/getopt.c +++ /dev/null @@ -1,222 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - */ -/* - * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany - * - * Sccsid @(#)getopt.c 1.10 (gritter) 12/16/07 - */ -/* from OpenSolaris "getopt.c 1.23 05/06/08 SMI" */ - -/* Copyright (c) 1988 AT&T */ -/* All Rights Reserved */ - - -/* - * See getopt(3C) and SUS/XPG getopt() for function definition and - * requirements. - * - * This actual implementation is a bit looser than the specification - * as it allows any character other than ':' to be used as an option - * character - The specification only guarantees the alnum characters - * ([a-z][A-Z][0-9]). - */ - -#include <sys/types.h> -#include <string.h> -#include <stdio.h> - -extern ssize_t write(int, const void *, size_t); - -char *optarg = NULL; -int optind = 1; -int opterr = 1; -int optopt = 0; - -#define ERR(s, c) err(s, c, optstring, argv[0]) -static void -err(const char *s, int c, const char *optstring, const char *argv0) -{ - char errbuf[256], *ep = errbuf; - const char *cp; - - if (opterr && optstring[0] != ':') { - for (cp = argv0; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++) - *ep = *cp; - for (cp = ": "; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++) - *ep = *cp; - for (cp = s; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++) - *ep = *cp; - for (cp = " -- "; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++) - *ep = *cp; - if (ep<&errbuf[sizeof errbuf]) - *ep++ = c; - if (ep<&errbuf[sizeof errbuf]) - *ep++ = '\n'; - write(2, errbuf, ep - errbuf); - } -} - -/* - * getopt_sp is required to keep state between successive calls to getopt() - * while extracting aggregated options (ie: -abcd). Hence, getopt() is not - * thread safe or reentrant, but it really doesn't matter. - * - * So, why isn't this "static" you ask? Because the historical Bourne - * shell has actually latched on to this little piece of private data. - */ -int getopt_sp = 1; - -/* - * Determine if the specified character (c) is present in the string - * (optstring) as a regular, single character option. If the option is found, - * return a pointer into optstring pointing at the option character, - * otherwise return null. The character ':' is not allowed. - */ -static char * -parse(const char *optstring, const char c) -{ - char *cp = (char *)optstring; - - if (c == ':') - return (NULL); - do { - if (*cp == c) - return (cp); - } while (*cp++ != '\0'); - return (NULL); -} - -/* - * External function entry point. - */ -int -getopt(int argc, char *const *argv, const char *optstring) -{ - char c; - char *cp; - - /* - * Has the end of the options been encountered? The following - * implements the SUS requirements: - * - * If, when getopt() is called: - * argv[optind] is a null pointer - * *argv[optind] is not the character '-' - * argv[optind] points to the string "-" - * getopt() returns -1 without changing optind. If - * argv[optind] points to the string "--" - * getopt() returns -1 after incrementing optind. - */ - if (getopt_sp == 1) { - if (optind >= argc || argv[optind][0] != '-' || - argv[optind] == NULL || argv[optind][1] == '\0') - return (EOF); - else if (strcmp(argv[optind], "--") == 0) { - optind++; - return (EOF); - } - } - - /* - * Getting this far indicates that an option has been encountered. - * Note that the syntax of optstring applies special meanings to - * the characters ':' and '(', so they are not permissible as - * option letters. A special meaning is also applied to the ')' - * character, but its meaning can be determined from context. - * Note that the specification only requires that the alnum - * characters be accepted. - */ - optopt = c = (unsigned char)argv[optind][getopt_sp]; - optarg = NULL; - if ((cp = parse(optstring, c)) == NULL) { - /* LINTED: variable format specifier */ - ERR("illegal option", c); - if (argv[optind][++getopt_sp] == '\0') { - optind++; - getopt_sp = 1; - } - return ('?'); - } - optopt = c = *cp; - - /* - * A valid option has been identified. If it should have an - * option-argument, process that now. SUS defines the setting - * of optarg as follows: - * - * 1. If the option was the last character in the string pointed to - * by an element of argv, then optarg contains the next element - * of argv, and optind is incremented by 2. If the resulting - * value of optind is not less than argc, this indicates a - * missing option-argument, and getopt() returns an error - * indication. - * - * 2. Otherwise, optarg points to the string following the option - * character in that element of argv, and optind is incremented - * by 1. - * - * The second clause allows -abcd (where b requires an option-argument) - * to be interpreted as "-a -b cd". - */ - if (*(cp + 1) == ':') { - /* The option takes an argument */ - if (argv[optind][getopt_sp+1] != '\0') { - optarg = &argv[optind++][getopt_sp+1]; - } else if (++optind >= argc) { - /* LINTED: variable format specifier */ - ERR("option requires an argument", c); - getopt_sp = 1; - optarg = NULL; - return (optstring[0] == ':' ? ':' : '?'); - } else - optarg = argv[optind++]; - getopt_sp = 1; - } else { - /* The option does NOT take an argument */ - if (argv[optind][++getopt_sp] == '\0') { - getopt_sp = 1; - optind++; - } - optarg = NULL; - } - return (c); -} /* getopt() */ - -#ifdef __APPLE__ -/* - * Starting with Mac OS 10.5 Leopard, <unistd.h> turns getopt() - * into getopt$UNIX2003() by default. Consequently, this function - * is called instead of the one defined above. However, optind is - * still taken from this file, so in effect, options are not - * properly handled. Defining an own getopt$UNIX2003() function - * works around this issue. - */ -int -getopt$UNIX2003(int argc, char *const argv[], const char *optstring) -{ - return getopt(argc, argv, optstring); -} -#endif /* __APPLE__ */ diff --git a/troff/troff.d/dpost.d/misc.c b/troff/troff.d/dpost.d/misc.c index 3d6692b72021..b5dc8a4e4858 100644 --- a/troff/troff.d/dpost.d/misc.c +++ b/troff/troff.d/dpost.d/misc.c @@ -51,18 +51,19 @@ #include <string.h> #include <fcntl.h> +#include "global.h" #include "gen.h" /* a few general purpose definitions */ #include "ext.h" /* external variable declarations */ #include "path.h" #include "asciitype.h" -static int nolist = 0; /* number of specified ranges */ +static size_t nolist = 0; /* number of specified ranges */ static int olist[512]; /* processing range pairs */ void -error(int kind, char *mesg, ...) +error(int kind, const char *mesg, ...) { @@ -102,7 +103,7 @@ error(int kind, char *mesg, ...) /*****************************************************************************/ /* for the AFM handling functions from troff */ -void +static void verrprint(char *fmt, va_list ap) { fprintf(stderr, "%s: ", prog_name); @@ -176,7 +177,7 @@ in_olist ( { - int i; /* just a loop index */ + size_t i; /* just a loop index */ /* @@ -202,9 +203,9 @@ in_olist ( /*****************************************************************************/ -int +int cat ( - char *file, /* copy this file to out */ + const char *file, /* copy this file to out */ FILE *out ) @@ -284,11 +285,7 @@ str_convert ( void interrupt( - - - int sig) /* signal that we caught */ - - + int sig __unused) /* signal that we caught */ { @@ -325,11 +322,6 @@ tempname(const char *sfx) /*****************************************************************************/ -#if defined (__GLIBC__) && defined (_IO_getc_unlocked) -#undef getc -#define getc(f) _IO_getc_unlocked(f) -#endif - #define LSIZE 512 int psskip(size_t n, FILE *fp) @@ -379,7 +371,8 @@ char *psgetline(char **line, size_t *linesize, size_t *llen, FILE *fp) int sget(char *buf, size_t size, FILE *fp) { - int c, n = 0; + int c; + size_t n = 0; do c = getc(fp); diff --git a/troff/troff.d/dpost.d/ps_include.c b/troff/troff.d/dpost.d/ps_include.c index 758bde956243..3b463daf29d9 100644 --- a/troff/troff.d/dpost.d/ps_include.c +++ b/troff/troff.d/dpost.d/ps_include.c @@ -46,6 +46,7 @@ #include "ext.h" #include "path.h" #include "asciitype.h" +#include "global.h" #define var(x) fprintf(fout, "/%s %g def\n", #x, x) @@ -60,7 +61,7 @@ static size_t bufsize; typedef struct {long start, end;} Section; static void copy(FILE *, FILE *, Section *); -static char *_has(const char *, const char *); +static char *_has(char *, const char *); static void addfonts(char *); /*****************************************************************************/ @@ -98,7 +99,7 @@ ps_include( double o = outline != 0; double s = scaleboth != 0; int i; /* loop index */ - int lineno = 0; + int lno = 0; int epsf = 0; int hires = 0; int state = 0; @@ -142,7 +143,7 @@ ps_include( fseek(fin, 0L, SEEK_SET); while ( psgetline(&buf, &bufsize, NULL, fin) != NULL ) { - if (++lineno == 1 && strncmp(buf, "%!PS-", 5) == 0) { + if (++lno == 1 && strncmp(buf, "%!PS-", 5) == 0) { for (bp = buf; !spacechar(*bp&0377); bp++); while (*bp && *bp != '\n' && *bp != '\r' && spacechar(*bp&0377)) @@ -199,7 +200,7 @@ ps_include( } else if (has("%%LanguageLevel:")) { int n; sscanf(buf, "%%%%LanguageLevel: %d", &n); - LanguageLevel = MAX(LanguageLevel, n); + LanguageLevel = max(LanguageLevel, n); } else if ((bp = has("%%DocumentNeededFonts:")) != NULL || (bp = has("%%DocumentFonts:")) != NULL) { cont = DOCUMENTFONTS; @@ -324,18 +325,18 @@ copy(FILE *fin, FILE *fout, Section *s) } static char * -_has(const char *buf, const char *word) +_has(char *buffer, const char *word) { int n; n = strlen(word); - if (strncmp(buf, word, n) != 0) + if (strncmp(buffer, word, n) != 0) return NULL; - if (buf[n] == ' ' || buf[n] == '\t' || buf[n] == '\r' || - buf[n] == '\n' || buf[n] == 0) { - while (buf[n] == ' ' || buf[n] == '\t') + if (buffer[n] == ' ' || buffer[n] == '\t' || buffer[n] == '\r' || + buffer[n] == '\n' || buffer[n] == 0) { + while (buffer[n] == ' ' || buffer[n] == '\t') n++; - return (char *)&buf[n]; + return &buffer[n]; } return NULL; } diff --git a/troff/troff.d/dpost.d/request.c b/troff/troff.d/dpost.d/request.c index 3cf447b42741..5e87b2ed740b 100644 --- a/troff/troff.d/dpost.d/request.c +++ b/troff/troff.d/dpost.d/request.c @@ -53,9 +53,9 @@ #include "path.h" /* for the default request file */ -Request request[MAXREQUEST]; /* next page or global request */ -int nextreq = 0; /* goes in request[nextreq] */ -char *requestfile = REQUESTFILE; /* default lookup file */ +static Request request[MAXREQUEST]; /* next page or global request */ +static int nextreq = 0; /* goes in request[nextreq] */ +static const char *requestfile = REQUESTFILE; /* default lookup file */ /*****************************************************************************/ @@ -138,7 +138,7 @@ dumprequest( char *want, /* look for this string */ - char *file, /* in this file */ + const char *file, /* in this file */ FILE *fp_out /* and write the value out here */ ) diff --git a/troff/troff.d/dpost.d/request.h b/troff/troff.d/dpost.d/request.h index 829c7020d636..348f0f951c10 100644 --- a/troff/troff.d/dpost.d/request.h +++ b/troff/troff.d/dpost.d/request.h @@ -51,7 +51,7 @@ typedef struct { char *want; int page; - char *file; + const char *file; } Request; diff --git a/troff/troff.d/draw.c b/troff/troff.d/draw.c index d05e5a747667..e513bd08b61c 100644 --- a/troff/troff.d/draw.c +++ b/troff/troff.d/draw.c @@ -63,7 +63,7 @@ extern int DY; /* step size in y */ extern int drawdot; /* character to use when drawing */ extern int drawsize; /* shrink point size by this facter */ -int maxdots = 32000; /* maximum number of dots in an object */ +static int maxdots = 32000; /* maximum number of dots in an object */ #define sgn(n) ((n > 0) ? 1 : ((n < 0) ? -1 : 0)) #define abs(n) ((n) >= 0 ? (n) : -(n)) @@ -76,7 +76,7 @@ extern void vgoto(int); extern int t_size(int); extern void put1(int); -void drawline(int, int, char *); +void drawline(int, int, const char *); void drawwig(char *); char *getstr(char *, char *); void drawcirc(int); @@ -87,7 +87,7 @@ void conicarc(int, int, int, int, int, int, int, int); void putdot(int, int); void -drawline(int dx, int dy, char *s) /* draw line from here to dx, dy using s */ +drawline(int dx, int dy, const char *s __unused) /* draw line from here to dx, dy using s */ { int xd, yd; float val, slope; @@ -171,8 +171,9 @@ drawwig(char *s) /* draw wiggly line */ { int x[50], y[50], xp, yp, pxp, pyp; float t1, t2, t3, w; - int i, j, numdots, N; - int osize; + int j, numdots; + size_t i, N; + size_t osize; char temp[50], *p; osize = size; diff --git a/troff/troff.d/fontmap.c b/troff/troff.d/fontmap.c index afe8b44afdb8..0ba21280b5d7 100644 --- a/troff/troff.d/fontmap.c +++ b/troff/troff.d/fontmap.c @@ -46,7 +46,7 @@ static char *filepath; static char *bufp; static char *bufe; -struct bst map = { +static struct bst map = { NULL, mapcmp }; @@ -94,8 +94,8 @@ rdftmap(char *path) { free(buf); } -char * -mapft(char *name) { +const char * +mapft(const char *name) { struct bst_node *n; if (map.root && !bst_srch(&map, (union bst_val)(void *)name, &n)) name = n->data.p; diff --git a/troff/troff.d/fontmap.h b/troff/troff.d/fontmap.h index 1b01d565ed13..da753c616ad7 100644 --- a/troff/troff.d/fontmap.h +++ b/troff/troff.d/fontmap.h @@ -1,2 +1,2 @@ void rdftmap(char *); -char *mapft(char *); +const char *mapft(const char *); diff --git a/troff/troff.d/otf.c b/troff/troff.d/otf.c index 1f3643030cf9..abaec6f55c8f 100644 --- a/troff/troff.d/otf.c +++ b/troff/troff.d/otf.c @@ -41,6 +41,10 @@ #include "dev.h" #include "afm.h" +#ifndef __unused +#define __unused __attribute__((unused)) +#endif + extern struct dev dev; extern char *chname; extern short *chtab; @@ -56,8 +60,8 @@ static unsigned short numTables; static int ttf; static const char *filename; unsigned short unitsPerEm; -short xMin, yMin, xMax, yMax; -short indexToLocFormat; +static short xMin, yMin, xMax, yMax; +static short indexToLocFormat; static struct afmtab *a; static int nc; static int fsType; @@ -103,26 +107,26 @@ static struct table { int in_sfnts; uint32_t checksum; } tables[] = { - { "CFF ", &pos_CFF, 0 }, - { "cmap", &pos_cmap, 0 }, - { "cvt ", &pos_cvt, 1 }, - { "fpgm", &pos_fpgm, 1 }, - { "GPOS", &pos_GPOS, 0 }, - { "GSUB", &pos_GSUB, 0 }, - { "head", &pos_head, 2 }, - { "hhea", &pos_hhea, 1 }, - { "hmtx", &pos_hmtx, 1 }, - { "kern", &pos_kern, 0 }, - { "loca", &pos_loca, 1 }, - { "maxp", &pos_maxp, 1 }, - { "name", &pos_name, 0 }, - { "OS/2", &pos_OS_2, 0 }, - { "post", &pos_post, 0 }, - { "prep", &pos_prep, 1 }, - { "vhea", &pos_vhea, 1 }, - { "vmtx", &pos_vmtx, 1 }, - { "glyf", &pos_glyf, 3 }, /* holds glyph data */ - { NULL, NULL, 0 } + { "CFF ", &pos_CFF, 0, 0 }, + { "cmap", &pos_cmap, 0, 0 }, + { "cvt ", &pos_cvt, 1, 0 }, + { "fpgm", &pos_fpgm, 1, 0 }, + { "GPOS", &pos_GPOS, 0, 0 }, + { "GSUB", &pos_GSUB, 0, 0 }, + { "head", &pos_head, 2, 0 }, + { "hhea", &pos_hhea, 1, 0 }, + { "hmtx", &pos_hmtx, 1, 0 }, + { "kern", &pos_kern, 0, 0 }, + { "loca", &pos_loca, 1, 0 }, + { "maxp", &pos_maxp, 1, 0 }, + { "name", &pos_name, 0, 0 }, + { "OS/2", &pos_OS_2, 0, 0 }, + { "post", &pos_post, 0, 0 }, + { "prep", &pos_prep, 1, 0 }, + { "vhea", &pos_vhea, 1, 0 }, + { "vmtx", &pos_vmtx, 1, 0 }, + { "glyf", &pos_glyf, 3, 0 }, /* holds glyph data */ + { NULL, NULL, 0, 0 } }; static unsigned short *gid2sid; @@ -1699,7 +1703,7 @@ free_INDEX(struct INDEX *ip) } static struct INDEX * -get_INDEX(long *op) +get_INDEX(unsigned long *op) { struct INDEX *ip; int i; @@ -1898,7 +1902,7 @@ otfalloc(int _nc) static void get_CFF(void) { - long o; + size_t o; char buf[4]; if (pos_CFF < 0) @@ -1936,7 +1940,7 @@ get_CFF(void) /*ARGSUSED*/ static void -get_ttf_post_1_0(int o) +get_ttf_post_1_0(int o __unused) { int i; @@ -1948,9 +1952,9 @@ get_ttf_post_1_0(int o) static void get_ttf_post_2_0(int o) { - int numberOfGlyphs; - int numberNewGlyphs; - int i, j, n; + size_t numberOfGlyphs; + size_t numberNewGlyphs; + size_t i, j, n; char *cp, *sp; numberOfGlyphs = pbe16(&contents[o+32]); @@ -1991,8 +1995,8 @@ get_ttf_post_2_0(int o) static void get_ttf_post_2_5(int o) { - int numberOfGlyphs; - int i, offset; + size_t numberOfGlyphs, i; + int offset; numberOfGlyphs = pbe16(&contents[o+32]); if (34+numberOfGlyphs > table_directories[pos_post].length) @@ -2055,8 +2059,14 @@ addunimap(int gid, int c) } #endif /* !DPOST && !DUMP */ +#if defined(DPOST) || defined(DUMP) +#define __actual_use __unused +#else +#define __actual_use +#endif + static void -addunitab(int c, int u) +addunitab(int c __actual_use, int u __actual_use) { #if !defined (DPOST) && !defined (DUMP) if (c >= a->nunitab) { @@ -2099,7 +2109,8 @@ get_ms_unicode_cmap4(int o, int addchar) int idDelta; int idRangeOffset; /* int glyphIdArray; */ - int c, e, i, d, r, s, gid, x; + int c, e, i, d, r, s, gid; + size_t x; /* length = */ pbe16(&contents[o+2]); segCount = pbe16(&contents[o+6]) / 2; @@ -2176,11 +2187,11 @@ get_ms_unicode_cmap(int o, int addchar) static int get_cmap(int addchar) { - int numTables; + size_t nTables, i; int platformID; int encodingID; int offset; - int i, o; + int o; int want_tbl; int gotit = 0; @@ -2195,8 +2206,8 @@ get_cmap(int addchar) error("can only handle version 0 cmap tables"); return gotit; } - numTables = pbe16(&contents[o+2]); - if (4 + 8*numTables > table_directories[pos_cmap].length) { + nTables = pbe16(&contents[o+2]); + if (4 + 8*nTables > table_directories[pos_cmap].length) { if (addchar) error("cmap table too small for values inside"); return gotit; @@ -2204,7 +2215,7 @@ get_cmap(int addchar) if (addchar) otfalloc(numGlyphs); want_tbl = -1; - for (i = 0; i < numTables; i++) { + for (i = 0; i < nTables; i++) { platformID = pbe16(&contents[o+4+8*i]); encodingID = pbe16(&contents[o+4+8*i+2]); if ((platformID == 3 && encodingID == 10) || @@ -2221,7 +2232,7 @@ get_cmap(int addchar) } static void -get_ttf_post_3_0(int o) +get_ttf_post_3_0(int o __unused) { int i, n; int gotit; @@ -3294,7 +3305,7 @@ CalcTableChecksum(uint32_t sum, const char *cp, int length) } static void -sfnts1(struct table *tp, int *offset, uint32_t *ccs, FILE *fp) +sfnts1(struct table *tp, int *offset, uint32_t *ccs, FILE *fp __unused) { int o, length; @@ -3396,30 +3407,30 @@ static void build_sfnts(FILE *fp) { int i, o, n; - unsigned short numTables; + unsigned short nTables; unsigned short searchRange; unsigned short entrySelector; unsigned short rangeShift; uint32_t ccs; - numTables = 0; + nTables = 0; for (i = 0; tables[i].name; i++) if (tables[i].in_sfnts && *tables[i].pos >= 0) - numTables++; + nTables++; entrySelector = 0; - for (searchRange = 1; searchRange*2 < numTables; searchRange *= 2) + for (searchRange = 1; searchRange*2 < nTables; searchRange *= 2) entrySelector++; searchRange *= 16; - rangeShift = numTables * 16 - searchRange; + rangeShift = nTables * 16 - searchRange; fprintf(fp, "<%08X%04hX%04hX%04hX%04hX\n", 0x00010000, - numTables, searchRange, entrySelector, rangeShift); - ccs = 0x00010000 + (numTables<<16) + searchRange + + nTables, searchRange, entrySelector, rangeShift); + ccs = 0x00010000 + (nTables<<16) + searchRange + (entrySelector<<16) + rangeShift; - o = 12 + numTables * 16; + o = 12 + nTables * 16; for (i = 0; tables[i].name; i++) if (tables[i].in_sfnts && *tables[i].pos >= 0) sfnts1(&tables[i], &o, &ccs, fp); - o = 12 + numTables * 16; + o = 12 + nTables * 16; n = 0; for (i = 0; tables[i].name; i++) { if (tables[i].in_sfnts && *tables[i].pos >= 0) { @@ -3437,7 +3448,7 @@ build_sfnts(FILE *fp) int otft42(char *font, char *path, char *_contents, size_t _size, FILE *fp) { - char *cp; + const char *cp; int ok = 0; int i; diff --git a/troff/troff.d/otfdump.c b/troff/troff.d/otfdump.c index cb6b7f940b76..283e6ae07d1d 100644 --- a/troff/troff.d/otfdump.c +++ b/troff/troff.d/otfdump.c @@ -39,9 +39,9 @@ static void print(enum show, const char *, ...); #define DUMP #include <stdio.h> +#include <unistd.h> #include "otf.c" #include "afm.c" -#include "dpost.d/getopt.c" #include <libgen.h> @@ -109,7 +109,6 @@ dump(const char *name) struct stat st; FILE *fp; char *cp; - size_t l; if ((fp = fopen(filename = name, "r")) == NULL) { errprint("%s: cannot open", filename); @@ -118,9 +117,7 @@ dump(const char *name) memset(&A, 0, sizeof A); a = &A; a->file = a->path = (char *)filename; - l = strlen(filename) + 1; - a->base = malloc(l); - n_strcpy(a->base, filename, l); + a->base = strdup(filename); a->base = basename(a->base); if ((cp = strrchr(a->base, '.')) != NULL) *cp = '\0'; diff --git a/troff/troff.d/pt.h b/troff/troff.d/pt.h index e047255d0194..fcd6c7b5b927 100644 --- a/troff/troff.d/pt.h +++ b/troff/troff.d/pt.h @@ -80,12 +80,12 @@ extern double u2pts(int); /* t10.c */ extern void ptinit(void); extern void specnames(void); -extern int findch(register char *); +extern int findch(register const char *); extern void ptout(register tchar); extern tchar *ptout0(tchar *, tchar *); extern void ptps(void); extern void ptfont(void); -extern void ptfpcmd(int, char *, char *, int); +extern void ptfpcmd(int, const char *, char *, int); extern void ptlead(void); extern void ptesc(void); extern void newpage(int); diff --git a/troff/troff.d/t10.c b/troff/troff.d/t10.c index 52cfc40c0751..f858225de80e 100644 --- a/troff/troff.d/t10.c +++ b/troff/troff.d/t10.c @@ -50,6 +50,7 @@ * contributors. */ +#include <stdio.h> #include <stdlib.h> #include "tdef.h" #include <ctype.h> @@ -89,7 +90,7 @@ int Hor; int Vert; int Unitwidth; int nfonts; -int nsizes; +static int nsizes; int nchtab; int lettrack; float horscale; @@ -289,22 +290,22 @@ ptinit(void) kern = xflag; if (ascii) return; - fdprintf(ptid, "x T %s\n", devname); - fdprintf(ptid, "x res %d %d %d\n", Inch, Hor, Vert); - fdprintf(ptid, "x init\n"); /* do initialization for particular device */ + dprintf(ptid, "x T %s\n", devname); + dprintf(ptid, "x res %d %d %d\n", Inch, Hor, Vert); + dprintf(ptid, "x init\n"); /* do initialization for particular device */ /* for (i = 1; i <= nfonts; i++) - fdprintf(ptid, "x font %d %s\n", i, fontbase[i]->namefont); - fdprintf(ptid, "x xxx fonts=%d sizes=%d unit=%d\n", nfonts, nsizes, Unitwidth); - fdprintf(ptid, "x xxx nchtab=%d lchname=%d nfitab=%d\n", + dprintf(ptid, "x font %d %s\n", i, fontbase[i]->namefont); + dprintf(ptid, "x xxx fonts=%d sizes=%d unit=%d\n", nfonts, nsizes, Unitwidth); + dprintf(ptid, "x xxx nchtab=%d lchname=%d nfitab=%d\n", dev.nchtab, dev.lchname, dev.nchtab+128-32); - fdprintf(ptid, "x xxx sizes:\nx xxx "); + dprintf(ptid, "x xxx sizes:\nx xxx "); for (i = 0; i < nsizes; i++) - fdprintf(ptid, " %d", pstab[i]); - fdprintf(ptid, "\nx xxx chars:\nx xxx "); + dprintf(ptid, " %d", pstab[i]); + dprintf(ptid, "\nx xxx chars:\nx xxx "); for (i = 0; i < dev.nchtab; i++) - fdprintf(ptid, " %s", &chname[chtab[i]]); - fdprintf(ptid, "\nx xxx\n"); + dprintf(ptid, " %s", &chname[chtab[i]]); + dprintf(ptid, "\nx xxx\n"); */ #ifdef EUC ptlocale(setlocale(LC_CTYPE, NULL)); @@ -317,7 +318,7 @@ specnames(void) { static struct { int *n; - char *v; + const char *v; } spnames[] = { { &c_hyphen , "hy" }, { &c_emdash , "em" }, @@ -348,7 +349,7 @@ specnames(void) } int -findch(register char *s) /* find char s in chname */ +findch(register const char *s) /* find char s in chname */ { register int i; @@ -414,9 +415,9 @@ ptout(register tchar i) if (linkout) ptlink(linkout); /* - fdprintf(ptid, "x xxx end of line: hpos=%d, vpos=%d\n", hpos, vpos); + dprintf(ptid, "x xxx end of line: hpos=%d, vpos=%d\n", hpos, vpos); */ - fdprintf(ptid, "n%d %d\n", b, a); /* be nice to chuck */ + dprintf(ptid, "n%d %d\n", b, a); /* be nice to chuck */ } tchar * @@ -455,7 +456,7 @@ ptout0(tchar *pi, tchar *pend) ptlead(); if (esc) ptesc(); - fdprintf(ptid, "x X "); + dprintf(ptid, "x X "); /* * not guaranteed of finding a XOFF if a word overflow * error occured, so also bound this loop by olinep @@ -479,9 +480,9 @@ ptout0(tchar *pi, tchar *pend) ptps(); j = f = u2pts(sbits(i)); if (j != f && xflag && dev.anysize) - fdprintf(ptid, "x H -23 %g\n", f); + dprintf(ptid, "x H -23 %g\n", f); else - fdprintf(ptid, "x H %d\n", j); + dprintf(ptid, "x H %d\n", j); return(pi+outsize); } if (k == SLANT) { @@ -490,7 +491,7 @@ ptout0(tchar *pi, tchar *pend) if (xfont != mfont) ptfont(); } - fdprintf(ptid, "x S %d\n", (int)sbits(i)-180); + dprintf(ptid, "x S %d\n", (int)sbits(i)-180); return(pi+outsize); } if (k == WORDSP) { @@ -626,23 +627,23 @@ ptout0(tchar *pi, tchar *pend) switch ((c=cbits(pi[1]))) { case DRAWCIRCLE: /* circle */ case DRAWCIRCLEFI: - fdprintf(ptid, "D%c %d\n", c, dx); /* dx is diameter */ + dprintf(ptid, "D%c %d\n", c, dx); /* dx is diameter */ w = 0; hpos += dx; break; case DRAWELLIPSE: case DRAWELLIPSEFI: - fdprintf(ptid, "D%c %d %d\n", c, dx, dy); + dprintf(ptid, "D%c %d %d\n", c, dx, dy); w = 0; hpos += dx; break; case DRAWLINE: /* line */ k = cbits(pi[2]); - fdprintf(ptid, "D%c %d %d ", DRAWLINE, dx, dy); + dprintf(ptid, "D%c %d %d ", DRAWLINE, dx, dy); if (k < 128) - fdprintf(ptid, "%c\n", k); + dprintf(ptid, "%c\n", k); else - fdprintf(ptid, "%s\n", &chname[chtab[k - 128]]); + dprintf(ptid, "%s\n", &chname[chtab[k - 128]]); w = 0; hpos += dx; vpos += dy; @@ -654,7 +655,7 @@ ptout0(tchar *pi, tchar *pend) dy2 = absmot(pi[6]); if (isnmot(pi[6])) dy2 = -dy2; - fdprintf(ptid, "D%c %d %d %d %d\n", DRAWARC, + dprintf(ptid, "D%c %d %d %d %d\n", DRAWARC, dx, dy, dx2, dy2); w = 0; hpos += dx + dx2; @@ -662,13 +663,13 @@ ptout0(tchar *pi, tchar *pend) break; case DRAWSPLINE: /* spline */ default: /* something else; copy it like spline */ - fdprintf(ptid, "D%c %d %d", (int)cbits(pi[1]), dx, dy); + dprintf(ptid, "D%c %d %d", (int)cbits(pi[1]), dx, dy); w = 0; hpos += dx; vpos += dy; if (cbits(pi[3]) == DRAWFCN || cbits(pi[4]) == DRAWFCN) { /* it was somehow defective */ - fdprintf(ptid, "\n"); + dprintf(ptid, "\n"); break; } for (n = 5; cbits(pi[n]) != DRAWFCN; n += 2) { @@ -678,11 +679,11 @@ ptout0(tchar *pi, tchar *pend) dy = absmot(pi[n+1]); if (isnmot(pi[n+1])) dy = -dy; - fdprintf(ptid, " %d %d", dx, dy); + dprintf(ptid, " %d %d", dx, dy); hpos += dx; vpos += dy; } - fdprintf(ptid, "\n"); + dprintf(ptid, "\n"); break; } for (n = 3; cbits(pi[n]) != DRAWFCN; n++) @@ -715,7 +716,7 @@ ptout0(tchar *pi, tchar *pend) if (esc += bd) ptesc(); if (k < 128) { - fdprintf(ptid, "c%c\n", k); + dprintf(ptid, "c%c\n", k); } else pnc(k, a); if (z) @@ -734,13 +735,13 @@ pnc(int k, struct afmtab *a) { if (k >= nchtab + 128) { if (a && (j = a->fitab[k-nchtab-128-32]) < a->nchars && a->nametab[j] != NULL) { - fdprintf(ptid, "CPS%s\n", a->nametab[j]); + dprintf(ptid, "CPS%s\n", a->nametab[j]); } else { - fdprintf(ptid, "N%d\n", + dprintf(ptid, "N%d\n", k - (html ? 0 : (nchtab + 128)) ); } } else { - fdprintf(ptid, "C%s\n", &chname[chtab[k - 128]]); + dprintf(ptid, "C%s\n", &chname[chtab[k - 128]]); } } @@ -766,7 +767,7 @@ pthorscale(int always) { if (horscale || mhorscale) { if (always || mhorscale != horscale) - fdprintf(ptid, "x X HorScale %g\n", + dprintf(ptid, "x X HorScale %g\n", horscale ? horscale : 1.0); mhorscale = horscale; } else @@ -778,7 +779,7 @@ pttrack(int always) { if (xflag && (lasttrack || lettrack || mtrack)) { if (always || mtrack != (lasttrack + lettrack)) - fdprintf(ptid, "x X Track %d\n", lasttrack + lettrack); + dprintf(ptid, "x X Track %d\n", lasttrack + lettrack); mtrack = lasttrack + lettrack; } else mtrack = 0; @@ -804,9 +805,9 @@ ptps(void) if ((z = zoomtab[xfont]) != 0 && dev.anysize && xflag) s *= z; if (dev.anysize && xflag && (!found || (z != 0 && z != 1))) - fdprintf(ptid, "s-23 %g\n", s); + dprintf(ptid, "s-23 %g\n", s); else - fdprintf(ptid, "s%d\n", (int)s); /* really should put out string rep of size */ + dprintf(ptid, "s%d\n", (int)s); /* really should put out string rep of size */ mpts = i; mzoom = z; pttrack(0); @@ -817,24 +818,24 @@ void ptfont(void) { mfont = xfont; - fdprintf(ptid, "f%d\n", xfont); + dprintf(ptid, "f%d\n", xfont); mtrack = 0; pttrack(1); pthorscale(1); } void -ptfpcmd(int f, char *s, char *path, int flags) +ptfpcmd(int f, const char *s, char *path, int flags) { if (ascii) return; - fdprintf(ptid, "x font %d %s", f, s); + dprintf(ptid, "x font %d %s", f, s); if (path) { - fdprintf(ptid, " %s", path); + dprintf(ptid, " %s", path); if (flags) - fdprintf(ptid, " %d", flags); + dprintf(ptid, " %d", flags); } - fdprintf(ptid, "\n"); + dprintf(ptid, "\n"); ptfont(); /* make sure that it gets noticed */ } @@ -843,7 +844,7 @@ ptlead(void) { vpos += lead; if (!ascii) - fdprintf(ptid, "V%d\n", vpos); + dprintf(ptid, "V%d\n", vpos); lead = 0; } @@ -857,9 +858,9 @@ ptesc(void) oput(esc/10 + '0'); oput(esc%10 + '0'); } else - fdprintf(ptid, "%d", esc); + dprintf(ptid, "%d", esc); } else - fdprintf(ptid, "H%d\n", hpos); + dprintf(ptid, "H%d\n", hpos); esc = 0; } @@ -868,7 +869,7 @@ ptsupplyfont(char *fontname, char *file) { if (ascii) return; - fdprintf(ptid, "x X SupplyFont %s %s\n", fontname, file); + dprintf(ptid, "x X SupplyFont %s %s\n", fontname, file); } void @@ -876,7 +877,7 @@ ptpapersize(void) { if (ascii || mediasize.flag == 0) return; - fdprintf(ptid, "x X PaperSize %d %d %d\n", + dprintf(ptid, "x X PaperSize %d %d %d\n", mediasize.val[2], mediasize.val[3], mediasize.flag&2?1:0); } @@ -885,7 +886,7 @@ static void cut1(const char *name, struct box *bp) { if (bp->flag) - fdprintf(ptid, "x X %s %d %d %d %d\n", name, + dprintf(ptid, "x X %s %d %d %d %d\n", name, bp->val[0], bp->val[1], bp->val[2], bp->val[3]); } @@ -913,7 +914,7 @@ ptlocale(const char *cp) } if (ascii || realpage == 0 || lp == NULL || dev.lc_ctype == 0) return; - fdprintf(ptid, "x X LC_CTYPE %s\n", lp); + dprintf(ptid, "x X LC_CTYPE %s\n", lp); } static void @@ -926,9 +927,9 @@ ptanchor(int n) for (rp = anchors; rp; rp = rp->next) if (rp->cnt == n) { if (html) { - fdprintf(ptid, "x X Anchor %s\n", rp->name); + dprintf(ptid, "x X Anchor %s\n", rp->name); } else { - fdprintf(ptid, "x X Anchor %d,%d %s\n", + dprintf(ptid, "x X Anchor %d,%d %s\n", vpos + lead - lss, hpos + esc, rp->name); } break; @@ -943,15 +944,15 @@ _ptlink(int n, struct ref *rstart, const char *type) if (ascii) return; if (html && !n) { - fdprintf(ptid, "x X %s\n", type); + dprintf(ptid, "x X %s\n", type); return; } for (rp = rstart; rp; rp = rp->next) if (rp->cnt == n) { if (html) - fdprintf(ptid, "x X %s %s\n", type, rp->name); + dprintf(ptid, "x X %s %s\n", type, rp->name); else - fdprintf(ptid, "x X %s %d,%d,%d,%d %s\n", + dprintf(ptid, "x X %s %d,%d,%d,%d %s\n", type, linkhp, vpos + pts2u(1), hpos + esc, vpos - pts * 8 / 10, @@ -992,7 +993,7 @@ ptyon(int i) ptlead(); if (esc) ptesc(); - fdprintf(ptid, "x X "); + dprintf(ptid, "x X "); savip = ip; ip = (filep)cp->mx; app = 1; @@ -1084,7 +1085,7 @@ newpage(int n) /* called at end of each output page (we hope) */ vpos = 0; if (ascii) return; - fdprintf(ptid, "p%d\n", n); /* new page */ + dprintf(ptid, "p%d\n", n); /* new page */ for (i = 0; i <= nfonts; i++) { if (fontbase[i] == NULL) continue; @@ -1092,13 +1093,13 @@ newpage(int n) /* called at end of each output page (we hope) */ struct afmtab *a = afmtab[(fontbase[i]->afmpos)-1]; if (a->encpath == NULL) a->encpath = afmencodepath(a->path); - fdprintf(ptid, "x font %d %s %s %d\n", i, + dprintf(ptid, "x font %d %s %s %d\n", i, macname(fontlab[i]), a->encpath, (int)a->spec); if (a->supply) ptsupplyfont(a->fontname, a->supply); } else if (fontbase[i]->namefont[0]) - fdprintf(ptid, "x font %d %s\n", i, macname(fontlab[i])); + dprintf(ptid, "x font %d %s\n", i, macname(fontlab[i])); } ptps(); ptfont(); @@ -1110,13 +1111,13 @@ newpage(int n) /* called at end of each output page (we hope) */ void pttrailer(void) { - fdprintf(ptid, "x trailer\n"); + dprintf(ptid, "x trailer\n"); } void ptstop(void) { - fdprintf(ptid, "x stop\n"); + dprintf(ptid, "x stop\n"); } void @@ -1126,11 +1127,11 @@ dostop(void) return; ptlead(); vpos = 0; - /* fdprintf(ptid, "x xxx end of page\n");*/ + /* dprintf(ptid, "x xxx end of page\n");*/ if (!nofeed) pttrailer(); ptlead(); - fdprintf(ptid, "x pause\n"); + dprintf(ptid, "x pause\n"); flusho(); mpts = mfont = 0; ptesc(); diff --git a/troff/troff.d/t6.c b/troff/troff.d/t6.c index bf7909cfd7b3..b1ae66504c63 100644 --- a/troff/troff.d/t6.c +++ b/troff/troff.d/t6.c @@ -92,7 +92,7 @@ int **ftrtab; struct lgtab **lgtab; int ***lgrevtab; struct tracktab *tracktab; -int sbold = 0; +static int sbold = 0; int kern = 0; struct box mediasize, bleedat, trimat, cropat; int psmaxcode; @@ -100,7 +100,7 @@ struct ref *anchors, *links, *ulinks; static int _minflg; int lastrst; int lastrsb; -int spacewidth; +static int spacewidth; static void kernsingle(int **); static int _ps2cc(const char *name, int create); @@ -248,7 +248,7 @@ getcw(register int i) goto g1; } if ((j = fitab[xfont][i]) == 0) { /* it's not on current font */ - int ii, jj, t; + int ii, jj, _t; /* search through search list of xfont * to see what font it ought to be on. * first searches explicit fallbacks, then @@ -259,8 +259,8 @@ getcw(register int i) for (jj = 0; fallbacktab[xfont][jj] != 0; jj++) { if ((ii = findft(fallbacktab[xfont][jj],0)) < 0) continue; - t = ftrans(ii, i + 32) - 32; - j = fitab[ii][t]; + _t = ftrans(ii, i + 32) - 32; + j = fitab[ii][_t]; if (j != 0) { xfont = ii; goto found; @@ -271,8 +271,8 @@ getcw(register int i) for (ii=smnt, jj=0; jj < nfonts; jj++, ii=ii % nfonts + 1) { if (fontbase[ii] == NULL) continue; - t = ftrans(ii, i + 32) - 32; - j = fitab[ii][t]; + _t = ftrans(ii, i + 32) - 32; + j = fitab[ii][_t]; if (j != 0) { /* * troff traditionally relies on the @@ -288,8 +288,8 @@ getcw(register int i) found: p = fontab[ii]; k = *(p + j); if (afmtab && - (t=fontbase[ii]->afmpos-1)>=0) { - a = afmtab[t]; + (_t=fontbase[ii]->afmpos-1)>=0) { + a = afmtab[_t]; if (a->bbtab[j]) { lastrst = a->bbtab[j][3]; lastrsb = a->bbtab[j][1]; @@ -459,20 +459,20 @@ getdescender(void) } int -kernadjust(tchar c, tchar d) +kernadjust(tchar c, tchar e) { lastkern = 0; - if (!kern || ismot(c) || ismot(d) || html) + if (!kern || ismot(c) || ismot(e) || html) return 0; if (!isdi(c)) { c = trtab[cbits(c)] | (c & SFMASK); c = ftrans(fbits(c), cbits(c)) | (c & SFMASK); } - if (!isdi(d)) { - d = trtab[cbits(d)] | (d & SFMASK); - d = ftrans(fbits(d), cbits(d)) | (d & SFMASK); + if (!isdi(e)) { + e = trtab[cbits(e)] | (e & SFMASK); + e = ftrans(fbits(e), cbits(e)) | (e & SFMASK); } - return getkw(c, d); + return getkw(c, e); } #define kprime 1021 @@ -486,17 +486,17 @@ static struct knode { } **ktable; static void -kadd(tchar c, tchar d, int n) +kadd(tchar c, tchar e, int n) { struct knode *kn; int h; if (ktable == NULL) ktable = calloc(kprime, sizeof *ktable); - h = khash(c, d); + h = khash(c, e); kn = calloc(1, sizeof *kn); kn->c = c; - kn->d = d; + kn->d = e; kn->n = n; kn->next = ktable[h]; ktable[h] = kn; @@ -554,22 +554,22 @@ found: } static struct knode * -klook(tchar c, tchar d) +klook(tchar c, tchar e) { struct knode *kp; int h; c = findchar(c); - d = findchar(d); - h = khash(c, d); + e = findchar(e); + h = khash(c, e); for (kp = ktable[h]; kp; kp = kp->next) - if (kp->c == c && kp->d == d) + if (kp->c == c && kp->d == e) break; return kp && kp->n != INT_MAX ? kp : NULL; } int -getkw(tchar c, tchar d) +getkw(tchar c, tchar e) { struct knode *kp; struct afmtab *a; @@ -578,27 +578,27 @@ getkw(tchar c, tchar d) if (isxfunc(c, CHAR)) c = charout[sbits(c)].ch; - if (isxfunc(d, CHAR)) - d = charout[sbits(d)].ch; + if (isxfunc(e, CHAR)) + e = charout[sbits(e)].ch; lastkern = 0; - if (!kern || iszbit(c) || iszbit(d) || ismot(c) || ismot(d)) + if (!kern || iszbit(c) || iszbit(e) || ismot(c) || ismot(e)) return 0; - if (sbits(c) != sbits(d)) + if (sbits(c) != sbits(e)) return 0; f = fbits(c); - g = fbits(d); + g = fbits(e); if ((s = sbits(c)) == 0) { s = xpts; if (f == 0) f = xfont; } i = cbits(c); - j = cbits(d); + j = cbits(e); if (i == SLANT || j == SLANT || i == XFUNC || j == XFUNC || cstab[f]) return 0; k = 0; if (i >= 32 && j >= 32) { - if (ktable != NULL && (kp = klook(c, d)) != NULL) + if (ktable != NULL && (kp = klook(c, e)) != NULL) k = kp->n; else if ((n = (fontbase[f]->afmpos)-1) >= 0 && n == (fontbase[g]->afmpos)-1 && @@ -616,8 +616,8 @@ getkw(tchar c, tchar d) } if (j>32 && kernafter != NULL && kernafter[fbits(c)] != NULL) k += kernafter[fbits(c)][i]; - if (i>32 && kernbefore != NULL && kernbefore[fbits(d)] != NULL) - k += kernbefore[fbits(d)][j]; + if (i>32 && kernbefore != NULL && kernbefore[fbits(e)] != NULL) + k += kernbefore[fbits(e)][j]; } if (k != 0) { k = (k * u2pts(s) + (Unitwidth / 2)) / Unitwidth; @@ -713,9 +713,9 @@ postchar(const char *temp, int *fp) return 0; } -const struct amap { - char *alias; - char *trname; +static const struct amap { + const char *alias; + const char *trname; } amap[] = { { "lq", "``" }, { "rq", "''" }, @@ -726,13 +726,14 @@ tchar setch(int delim) { register int j; char temp[NC]; - tchar c, d[2] = {0, 0}; - int f, n; + tchar c, e[2] = {0, 0}; + int f; + size_t n; const struct amap *ap; n = 0; if (delim == 'C') - d[0] = getach(); + e[0] = getach(); do { c = getach(); if (c == 0 && n < 2) @@ -741,7 +742,7 @@ setch(int delim) { temp[n-1] = 0; break; } - if ((delim == '[' && c == ']') || (delim == 'C' && c == d[0])) { + if ((delim == '[' && c == ']') || (delim == 'C' && c == e[0])) { temp[n] = 0; break; } @@ -754,7 +755,7 @@ setch(int delim) { for (ap = amap; ap->alias; ap++) if (!strcmp(ap->alias, temp)) { size_t l; - char *s = ap->trname; + const char *s = ap->trname; if ((l = strlen(s) + 1) > NC) { fprintf(stderr, "%s %i: strlen(%s)+1 > %d\n", __FILE__, __LINE__, s, NC); @@ -767,8 +768,8 @@ setch(int delim) { nodelim(']'); return ' '; } - if (delim == 'C' && c != d[0]) { - nodelim(d[0]); + if (delim == 'C' && c != e[0]) { + nodelim(e[0]); return ' '; } c = 0; @@ -780,7 +781,6 @@ setch(int delim) { && isxdigit((unsigned)temp[2]) && isxdigit((unsigned)temp[3]) && isxdigit((unsigned)temp[4])) { - int n; n = strtol(temp + 1, NULL, 16); if (n) c = setuc0(n); @@ -816,7 +816,7 @@ setch(int delim) { c = 0; } if (c == 0 && warn & WARN_CHAR) - errprint("missing glyph \\%c%s%s%s%s", delim, d, temp, d, + errprint("missing glyph \\%c%s%s%s%s", delim, e, temp, e, delim == '[' ? "]" : ""); if (c == 0 && !tryglf) c = ' '; @@ -843,7 +843,8 @@ findft(register int i, int required) { register int k; int nk; - char *mn, *mp; + const char *mn; + char *mp; if ((k = i - '0') >= 0 && k <= nfonts && k < smnt && fontbase[k]) return(k); @@ -1270,7 +1271,8 @@ tchar getlg(tchar i) { tchar j, k, pb[NC]; struct lgtab *lp; - int c, f, n, lgn; + int c, f; + size_t n, lgn; f = fbits(i); if (lgtab[f] == NULL) /* font lacks ligatures */ @@ -1504,7 +1506,8 @@ getflig(int f, int mode) { int delete, allnum; tchar from[NC], to; - int c, i, j; + int c; + size_t i, j; char number[NC]; if (skip(0)) @@ -1597,14 +1600,9 @@ casefp(int spec) goto bad; setfp(i, j, 0); } else { /* 3rd argument = filename */ - size_t l; - l = strlen(nextf) + 1; - file = malloc(l); - n_strcpy(file, nextf, l); + file = strdup(nextf); if (!skip(0) && getname()) { - l = strlen(nextf) + 1; - supply = malloc(l); - n_strcpy(supply, nextf, l); + supply = strdup(nextf); } else supply = NULL; if (loadafm(i?i:-1, j, file, supply, 0, spec) == 0) { @@ -1637,7 +1635,8 @@ casefps(void) { SPEC_NONE, NULL } }; char name[NC]; - int c = 0, i; + int c = 0; + size_t i; enum spec s = SPEC_NONE; if (skip(1)) @@ -1663,7 +1662,8 @@ casefps(void) int setfp(int pos, int f, char *truename) /* mount font f at position pos[0...nfonts] */ { - char longname[4096], *shortname, *ap; + char longname[4096], *ap; + const char *shortname; char *fpout; int i, nw; @@ -1974,7 +1974,7 @@ tchar xlss(void) struct afmtab **afmtab; int nafm; -char * +static char * onefont(char *prefix, char *file, char *type) { char *path, *fp, *tp; @@ -2009,9 +2009,7 @@ getfontpath(char *file, char *type) size_t l; if ((troffonts = getenv("TROFFONTS")) != NULL) { - l = strlen(troffonts) + 1; - tp = malloc(l); - n_strcpy(tp, troffonts, l); + tp = strdup(troffonts); troffonts = tp; do { for (tq = tp; *tq && *tq != ':'; tq++); @@ -2091,9 +2089,7 @@ loadafm(int nf, int rq, char *file, char *supply, int required, enum spec spec) break; } a->path = path; - l = strlen(file) + 1; - a->file = malloc(l); - n_strcpy(a->file, file, l); + a->file = strdup(file); a->spec = spec; a->rq = rq; a->Font.namefont[0] = rq&0377; @@ -2193,7 +2189,7 @@ done: afmtab = realloc(afmtab, (nafm+1) * sizeof *afmtab); return 1; } -int +static int tracknum(void) { skip(1); @@ -2337,7 +2333,7 @@ static void setpapersize(int setmedia) { const struct { - char *name; + const char *name; int width; int heigth; } papersizes[] = { @@ -2380,7 +2376,8 @@ setpapersize(int setmedia) { NULL, 0, 0 } }; int c; - int x = 0, y = 0, n; + int x = 0, y = 0; + size_t n; char buf[NC]; lgf++; @@ -2499,7 +2496,7 @@ casekernpair(void) { int savfont = font, savfont1 = font1; int f, g, i, j, n; - tchar c, d, *cp = NULL, *dp = NULL; + tchar c, e, *cp = NULL, *dp = NULL; int a = 0, b = 0; lgf++; @@ -2555,12 +2552,12 @@ casekernpair(void) if (c == UNPAD) c = ' '; setfbits(c, f); - if ((d = cbits(dp[j])) == 0) + if ((e = cbits(dp[j])) == 0) continue; - if (d == UNPAD) - d = ' '; - setfbits(d, g); - kadd(c, d, n); + if (e == UNPAD) + e = ' '; + setfbits(e, g); + kadd(c, e, n); } done: free(cp); @@ -2666,7 +2663,8 @@ static int getfeature(struct afmtab *a, int f) { char name[NC]; - int ch1, ch2, c, i, j, minus; + int ch1, ch2, c, j, minus; + size_t i; struct feature *fp; if (skip(0)) @@ -2948,9 +2946,9 @@ _setlink(struct ref **rstart, int oncode, int offcode, int *cnt) { struct ref *rp; char *np; - int sv; + int _sv; - sv = linkin; + _sv = linkin; if ((linkin = !linkin)) { if ((np = getref()) != NULL) { rp = calloc(1, sizeof *rp); @@ -2965,7 +2963,7 @@ _setlink(struct ref **rstart, int oncode, int offcode, int *cnt) return mkxfunc(oncode, 0); } } else - return mkxfunc(offcode, sv > 0 ? sv : 0); + return mkxfunc(offcode, _sv > 0 ? _sv : 0); } tchar diff --git a/vgrind/vfontedpr.c b/vgrind/vfontedpr.c index 9f833730f4b8..232ff198e1cc 100644 --- a/vgrind/vfontedpr.c +++ b/vgrind/vfontedpr.c @@ -23,11 +23,7 @@ #ifdef EUC #include <wchar.h> #endif - -#if defined (__GLIBC__) && defined (_IO_getc_unlocked) -#undef getc -#define getc(f) _IO_getc_unlocked(f) -#endif +#include "global.h" #define boolean int #define TRUE 1 |