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/troff.d/dpost.d | |
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/troff.d/dpost.d')
-rw-r--r-- | troff/troff.d/dpost.d/Makefile.mk | 2 | ||||
-rw-r--r-- | troff/troff.d/dpost.d/color.c | 2 | ||||
-rw-r--r-- | troff/troff.d/dpost.d/dpost.c | 322 | ||||
-rw-r--r-- | troff/troff.d/dpost.d/dpost.h | 4 | ||||
-rw-r--r-- | troff/troff.d/dpost.d/draw.c | 8 | ||||
-rw-r--r-- | troff/troff.d/dpost.d/gen.h | 27 | ||||
-rw-r--r-- | troff/troff.d/dpost.d/getopt.c | 222 | ||||
-rw-r--r-- | troff/troff.d/dpost.d/misc.c | 27 | ||||
-rw-r--r-- | troff/troff.d/dpost.d/ps_include.c | 21 | ||||
-rw-r--r-- | troff/troff.d/dpost.d/request.c | 8 | ||||
-rw-r--r-- | troff/troff.d/dpost.d/request.h | 2 |
11 files changed, 191 insertions, 454 deletions
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; |