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 /troff | |
parent | aa7798c94fa57f6c00fab4393c9fe91334864371 (diff) | |
download | src-ab1717bb35d85041e0184f79daa1313a1306dc01.tar.gz src-ab1717bb35d85041e0184f79daa1313a1306dc01.zip |
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
Diffstat (limited to 'troff')
39 files changed, 666 insertions, 1462 deletions
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 |