diff options
author | Taco Hoekwater <taco@elvenkind.com> | 2006-11-28 13:24:53 +0000 |
---|---|---|
committer | Taco Hoekwater <taco@elvenkind.com> | 2006-11-28 13:24:53 +0000 |
commit | 2316028a0dedb2fa848c9e3bacaad4580dcc4290 (patch) | |
tree | 750b5fe86da1917f5482b7d0e643e77a3b31594e /Build | |
parent | c8a7170337d602789e93f5b765c5b9c06f50b0d7 (diff) |
MetaPost 0.992 plus support files
git-svn-id: svn://tug.org/texlive/trunk@2554 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build')
-rw-r--r-- | Build/source/texk/web2c/dvitomp.ch | 8 | ||||
-rw-r--r-- | Build/source/texk/web2c/dvitomp.web | 2 | ||||
-rw-r--r-- | Build/source/texk/web2c/mp.web | 26 | ||||
-rw-r--r-- | Build/source/texk/web2c/mpware/Makefile.in | 10 | ||||
-rw-r--r-- | Build/source/texk/web2c/mpware/dmp.c | 1091 | ||||
-rw-r--r-- | Build/source/texk/web2c/mpware/dmp.h | 5 | ||||
-rw-r--r-- | Build/source/texk/web2c/mpware/dmp_ffile.c | 357 | ||||
-rw-r--r-- | Build/source/texk/web2c/mpware/makempx.in | 5 | ||||
-rw-r--r-- | Build/source/texk/web2c/mpware/mpto.c | 583 | ||||
-rw-r--r-- | Build/source/texk/web2c/mpware/newer.c | 103 |
10 files changed, 1274 insertions, 916 deletions
diff --git a/Build/source/texk/web2c/dvitomp.ch b/Build/source/texk/web2c/dvitomp.ch index 99e2127f9e2..65ae6e931d7 100644 --- a/Build/source/texk/web2c/dvitomp.ch +++ b/Build/source/texk/web2c/dvitomp.ch @@ -26,12 +26,12 @@ @z @x [1] Duplicate banner line for use in |print_version_and_exit|. -@d banner=='% Written by DVItoMP, Version 0.99' +@d banner=='% Written by DVItoMP, Version 0.992' {the first line of the output file} @y -@d banner=='% Written by DVItoMP, Version 0.99/color' +@d banner=='% Written by DVItoMP, Version 0.992/color' {the first line of the output file} -@d term_banner=='This is DVItoMP, Version 0.99/color' +@d term_banner=='This is DVItoMP, Version 0.992/color' {the same in the usual format, as it would be shown on a terminal} @z @@ -442,7 +442,7 @@ begin usage_help (DVITOMP_HELP, nil); end else if argument_is ('version') then begin - print_version_and_exit (term_banner, 'AT&T Bell Laboraties', 'John Hobby'); + print_version_and_exit (term_banner, 'AT&T Bell Laboraties', 'John Hobby.'); end; {Else it was a flag; |getopt| has already done the assignment.} until getopt_return_val = -1; diff --git a/Build/source/texk/web2c/dvitomp.web b/Build/source/texk/web2c/dvitomp.web index 4bb39349828..01c76c6b72a 100644 --- a/Build/source/texk/web2c/dvitomp.web +++ b/Build/source/texk/web2c/dvitomp.web @@ -65,7 +65,7 @@ an ``\.{MPX}'' file. The |banner| string defined here should be changed whenever \.{DVItoMP} gets modified. -@d banner=='% Written by DVItoMP, Version 0.99' +@d banner=='% Written by DVItoMP, Version 0.992' {the first line of the output file} @ This program is written in standard \PASCAL, except where it is necessary diff --git a/Build/source/texk/web2c/mp.web b/Build/source/texk/web2c/mp.web index 0773f08620a..640eb4a1114 100644 --- a/Build/source/texk/web2c/mp.web +++ b/Build/source/texk/web2c/mp.web @@ -97,8 +97,8 @@ undergoes any modifications, so that it will be clear which version of @^extensions to \MP@> @^system dependencies@> -@d banner=='This is MetaPost, Version 0.99' {printed when \MP\ starts} -@d metapost_version=="0.99" +@d banner=='This is MetaPost, Version 0.992' {printed when \MP\ starts} +@d metapost_version=="0.992" @ Different \PASCAL s have slightly different conventions, and the present @!@:PASCAL H}{\ph@> @@ -23156,6 +23156,10 @@ end; if (font_is_subsetted(#))and(font_is_included(#))and(internal[prologues]=three) then print(fm_font_subset_name(#)) else print(font_ps_name[#]); + if str_vs_str(font_name[#],"psyrgo")=0 then begin + ps_print("-Slanted"); end; + if str_vs_str(font_name[#],"zpzdr-reversed")=0 then begin + ps_print("-Reverse"); end; if applied_reencoding(#) then begin ps_print("-"); ps_print(font_enc_name[#]); end; if fm_font_slant(#)<>0 then begin @@ -23179,6 +23183,9 @@ begin print_nl("/fcp{findfont dup length dict begin{1 index/FID ne{def}{pop pop}ifelse}forall}bd"); print_nl("/fmc{FontMatrix dup length array copy dup dup}bd/fmd{/FontMatrix exch def}bd"); print_nl("/Amul{4 -1 roll exch mul 1000 div}bd/ExtendFont{fmc 0 get Amul 0 exch put fmd}bd"); + if internal[gtroffmode]>0 then begin + print_nl("/ScaleFont{dup fmc 0 get Amul 0 exch put dup dup 3 get Amul 3 exch put fmd}bd"); + end; print_nl("/SlantFont{fmc 2 get dup 0 eq{pop 1}if Amul FontMatrix 0 get mul 2 exch put fmd}bd"); print_nl("%%EndResource"); @<Include encodings and fonts for edge structure~|h|@>; @@ -23213,7 +23220,8 @@ begin end @ @<Write font definition@>= -if (applied_reencoding(f))or(fm_font_slant(f)<>0)or(fm_font_extend(f)<>0) then begin +if (applied_reencoding(f))or(fm_font_slant(f)<>0)or(fm_font_extend(f)<>0)or@| + (str_vs_str(font_name[f],"psyrgo")=0)or(str_vs_str(font_name[f],"zpzdr-reversed")=0) then begin if (font_is_subsetted(f))and(font_is_included(f))and(internal[prologues]=three) then ps_name_out(fm_font_subset_name(f),true) else ps_name_out(font_ps_name[f],true); @@ -23232,7 +23240,17 @@ if (applied_reencoding(f))or(fm_font_slant(f)<>0)or(fm_font_extend(f)<>0) then b print_int(fm_font_extend(f)); ps_print(" ExtendFont "); end; - ps_print("currentdict end"); + if str_vs_str(font_name[f],"psyrgo")=0 then begin + ps_print(" 890 ScaleFont "); + ps_print(" 277 SlantFont "); + end; + if str_vs_str(font_name[f],"zpzdr-reversed")=0 then begin + ps_print(" FontMatrix [-1 0 0 1 0 0] matrix concatmatrix /FontMatrix exch def "); + ps_print("/Metrics 2 dict dup begin "); + ps_print("/space[0 -278]def "); + ps_print("/a12[-904 -939]def "); + ps_print("end def "); + end; ps_print("currentdict end"); print_ln; ps_print_defined_name(f); ps_print(" exch definefont pop"); diff --git a/Build/source/texk/web2c/mpware/Makefile.in b/Build/source/texk/web2c/mpware/Makefile.in index 62af826f805..2b86d7c955e 100644 --- a/Build/source/texk/web2c/mpware/Makefile.in +++ b/Build/source/texk/web2c/mpware/Makefile.in @@ -12,19 +12,17 @@ default: all all: $(programs) dmp: dmp.o dmp_ffile.o - $(kpathsea_link) dmp.o dmp_ffile.o $(LIBS) + $(kpathsea_link) dmp.o dmp_ffile.o $(LOADLIBES) mpto: mpto.o $(kpathsea_link) mpto.o newer: newer.o $(link_command) newer.o -makempx: makempx.in Makefile.in - sed -e 's,@BINDIR@,$(bindir),g' -e 's,@web2cver@,@WEB2CVERSION@,g' \ - <$(srcdir)/makempx.in >$@ - -chmod a+x $@ +makempx: makempx.o + $(kpathsea_link) makempx.o $(LOADLIBES) dmp.o dmp_ffile.o: dmp.h -newer.o dmp.o: ../c-auto.h +newer.o dmp.o makempx.o: ../c-auto.h checkdir = $(srcdir)/../check check: mpto makempx newer dmp diff --git a/Build/source/texk/web2c/mpware/dmp.c b/Build/source/texk/web2c/mpware/dmp.c index 9debc6510d7..cf876f8aa91 100644 --- a/Build/source/texk/web2c/mpware/dmp.c +++ b/Build/source/texk/web2c/mpware/dmp.c @@ -23,8 +23,8 @@ * gets modified. */ -char *banner="% Written by DMP, Version 0.991"; /* first line of output */ -char *term_banner="This is DMP, Version 0.991"; +char *banner = "% Written by DMP, Version 0.992"; /* first line of output */ +char *term_banner = "This is DMP, Version 0.992"; #include <stdio.h> #include <stdlib.h> @@ -42,17 +42,16 @@ char *term_banner="This is DMP, Version 0.991"; #define PI 3.14159265358979323846 #endif -#define POOLMAX 65000 /* total characters in all font and char names */ -#define FCOUNT 100 /* maximum number of fonts */ -#define SHIFTS 100 /* maximum number of characters with special shifts */ -#define line_length 79 /* maximum output line length (must be at least 60) */ -#define Hprime 307 /* much bigger than max(chars/font,fonts/job) */ -#define MAXCHARS 256 /* character codes fall in the range 0..MAXCHARS-1 */ -#define LLENGTH 1024 /* one more than maximum line length for troff output */ +#define FCOUNT 100 /* maximum number of fonts */ +#define SHIFTS 100 /* maximum number of characters with special shifts */ +#define line_length 79 /* maximum output line length (must be at least 60) */ +#define Hprime 307 /* much bigger than max(chars/font,fonts/job) */ +#define MAXCHARS 256 /* character codes fall in the range 0..MAXCHARS-1 */ +#define LLENGTH 1024 /* one more than maximum line length for troff output */ #define is_specchar(c) (!gflag && (c)<=2) /* does charcode c identify a special char? */ -#define LWscale 0.03 /* line width for graphics as a fraction of pointsize */ -#define YCORR 12.0 /* V coordinate of reference point in (big) points */ +#define LWscale 0.03 /* line width for graphics as a fraction of pointsize */ +#define YCORR 12.0 /* V coordinate of reference point in (big) points */ char strpool[POOLMAX]; /* text for font names and char names */ int poolsize = 0; /* chars used so far in strpool */ @@ -60,21 +59,21 @@ int poolsize = 0; /* chars used so far in strpool */ char *texname[FCOUNT]; /* TeX names (null-terminated strings) */ int font_num[FCOUNT]; /* external font numbers */ float font_design_size[FCOUNT]; /* design size in TeX points */ -struct hcell *charcodes[FCOUNT];/* hash tables for translating char names */ +struct hcell *charcodes[FCOUNT]; /* hash tables for translating char names */ int next_specfnt[FCOUNT]; /* used to link special fonts together */ float charwd[FCOUNT][MAXCHARS]; /* width/ptsize indexed [font num][char code] */ -int nfonts; /* no. of internal font nums (texname indices)*/ +int nfonts; /* no. of internal font nums (texname indices) */ int shiftchar[SHIFTS]; /* charcode of character to shift, else -1 */ -float shifth[SHIFTS],shiftv[SHIFTS]; /* shift vals/fontsize (y is upward) */ +float shifth[SHIFTS], shiftv[SHIFTS]; /* shift vals/fontsize (y is upward) */ int shiftptr = 0; /* number of entries in shift tables */ int shiftbase[FCOUNT]; /* initial index into shifth,shiftv,shiftchar */ -int specfnt = FCOUNT; /* int. num. of first special font (or FCOUNT)*/ +int specfnt = FCOUNT; /* int. num. of first special font (or FCOUNT) */ int *specf_tail = &specfnt; /* tail of specfnt list (*specf_tail==FCOUNT) */ FILE *trf; /* the input file (troff output) */ FILE *mpxf; /* the output file */ struct hcell *trfonts; /* hash tab for internal nums of troff fonts */ -float unit = 0.0; /* (big) points per troff unit (0 when unset)*/ -int h,v; /* current position in tr. units (v downward)*/ +float unit = 0.0; /* (big) points per troff unit (0 when unset) */ +int h, v; /* current position in tr. units (v downward) */ float cursize; /* current type size in (big) points */ int curfont; /* internal number for current font */ float Xslant; /* degrees additional slant for all fonts */ @@ -85,23 +84,29 @@ int lnno = 0; /* line num. in troff output file (our input) */ float sizescale; /* groff font size scaling factor */ int gflag = 0; /* non-zero if using groff fonts */ -void quit(char *msg1, char *msg2, char *msg3) +void +quit(char *msg1, char *msg2, char *msg3) { - fprintf(stderr,"DMP abort at troff output line %d:\n%s%s%s\n", - lnno, msg1, msg2, msg3); + fprintf(stderr, "DMP abort at troff output line %d:\n%s%s%s\n", + lnno, msg1, msg2, msg3); exit(1); } -void warn(char *msg1, char *msg2, char *msg3) +void +warn(char *msg1, char *msg2, char *msg3) { - fprintf(stderr,"DMP warning at troff output line %d:\n%s%s%s\n", - lnno, msg1, msg2, msg3); + fprintf(stderr, "DMP warning at troff output line %d:\n%s%s%s\n", + lnno, msg1, msg2, msg3); } -void add_to_pool(char c) +void +add_to_pool(char c) { - if (poolsize==POOLMAX) quit("Need to increase POOLMAX","",""); - else strpool[poolsize++] = c; + if (poolsize == POOLMAX) { + fprintf(stderr, "%s", strpool); + quit("Need to increase POOLMAX", "", ""); + } else + strpool[poolsize++] = c; } @@ -112,25 +117,27 @@ void add_to_pool(char c) ***************************************************************/ typedef struct hcell { - char* lab; + char *lab; int datum; } Hcell; #define new_htab (Hcell*) calloc((unsigned)Hprime, (unsigned)sizeof(Hcell)) -int hash(char *s) +int +hash(char *s) { register int r; - for(r=0; *s!=0; s++) { - /* GROFF - in font metrics file the character name may be 8bit - groff_font(5): Groff supports eight bit characters; - groff_out(5): Note that single characters can have the - eighth bit set, as can the names of fonts and special - characters. - */ - r = (r<<1) + *(unsigned char*)s; - while (r>=Hprime) r-=Hprime; + for (r = 0; *s != 0; s++) { + /* GROFF - in font metrics file the character name may be 8bit + groff_font(5): Groff supports eight bit characters; + groff_out(5): Note that single characters can have the + eighth bit set, as can the names of fonts and special + characters. + */ + r = (r << 1) + *(unsigned char *) s; + while (r >= Hprime) + r -= Hprime; } return r; } @@ -141,35 +148,44 @@ int hash(char *s) */ Hcell *failure; /* null unless last hfind failed (used below) */ -int *hfind(char *s, Hcell* htab) +int * +hfind(char *s, Hcell * htab) { register Hcell *p; register int cnt = Hprime; failure = (Hcell *) 0; p = &htab[hash(s)]; do { - if (p->lab==NULL) { + if (p->lab == NULL) { failure = p; - if (s<&strpool[0] || s>=&strpool[POOLMAX]) { + if (s < &strpool[0] || s >= &strpool[POOLMAX]) { p->lab = &strpool[poolsize]; - do add_to_pool(*s); while (*s++!='\0'); - } else p->lab = s; + do + add_to_pool(*s); + while (*s++ != '\0'); + } else + p->lab = s; return &p->datum; } - if (strcmp(s, p->lab)==0) return &p->datum; - if (p==htab) p= &htab[Hprime-1]; - else p--; + if (strcmp(s, p->lab) == 0) + return &p->datum; + if (p == htab) + p = &htab[Hprime - 1]; + else + p--; } while (--cnt >= 0); - quit("Need to increase Hprime","",""); - return (int*)0; /* keep lint happy */ + quit("Need to increase Hprime", "", ""); + return (int *) 0; /* keep lint happy */ } /* If the last hfind() failed, undo the insertion and return zero (FALSE). */ -int hfound(void) +int +hfound(void) { - if (failure==(Hcell *)0) return 1; + if (failure == (Hcell *) 0) + return 1; failure->lab = NULL; return 0; } @@ -184,22 +200,27 @@ int hfound(void) numbers from strings but they give no indication of how much of the string is consumed. These homemade versions don't parse scientific notation. */ -char *arg_tail; /* char after the number just gotten; NULL on failure */ +char *arg_tail; /* char after the number just gotten; NULL on failure */ -int get_int(char *s) +int +get_int(char *s) { register int i, d, neg; - if (s==NULL) goto bad; - for (neg=0;; s++) - if (*s=='-') neg=!neg; - else if (*s!=' ' && *s!='\t') break; - if (i= *s-'0', 0>i||i>9) goto bad; - while (d= *++s-'0', 0<=d&&d<=9) - i = 10*i + d; + if (s == NULL) + goto bad; + for (neg = 0;; s++) + if (*s == '-') + neg = !neg; + else if (*s != ' ' && *s != '\t') + break; + if (i = *s - '0', 0 > i || i > 9) + goto bad; + while (d = *++s - '0', 0 <= d && d <= 9) + i = 10 * i + d; arg_tail = s; return neg ? -i : i; -bad:arg_tail = NULL; + bad:arg_tail = NULL; return 0; } @@ -208,14 +229,17 @@ bad:arg_tail = NULL; a 0 it will be interpreted as octal; if it starts with 0x or 0X it will be intepreted as hexadecimal. */ -int get_int_map (char *s) +int +get_int_map(char *s) { register int i; - if (s==NULL) goto bad; - i=strtol(s,&arg_tail,0); - if (s==arg_tail) goto bad; + if (s == NULL) + goto bad; + i = strtol(s, &arg_tail, 0); + if (s == arg_tail) + goto bad; return i; -bad:arg_tail = NULL; + bad:arg_tail = NULL; return 0; } @@ -224,31 +248,35 @@ bad:arg_tail = NULL; number is not being used for character positioning. (For non-PostScript applications h and v are usually in pixels and should be integers.) */ -float get_float(char *s) +float +get_float(char *s) { register int d, neg, digits; register float x, y; digits = 0; - if (s!=NULL) { - for (neg=0;; s++) - if (*s=='-') neg=!neg; - else if (*s!=' ' && *s!='\t') break; + if (s != NULL) { + for (neg = 0;; s++) + if (*s == '-') + neg = !neg; + else if (*s != ' ' && *s != '\t') + break; x = 0.0; - while (d= *s-'0', 0<=d&&d<=9) { - x = 10.0*x + d; - digits++; s++; + while (d = *s - '0', 0 <= d && d <= 9) { + x = 10.0 * x + d; + digits++; + s++; } - if (*s=='.') { + if (*s == '.') { y = 1.0; - while (d= *++s-'0', 0<=d&&d<=9) { + while (d = *++s - '0', 0 <= d && d <= 9) { y /= 10.0; - x += y*d; + x += y * d; digits++; } } } - if (digits==0) { + if (digits == 0) { arg_tail = NULL; return 0.0; } @@ -262,13 +290,14 @@ float get_float(char *s) used anyway - thus just skip the value, eat all non-space chars. */ -float get_float_map (char *s) +float +get_float_map(char *s) { - if (s!=NULL) { - while (isspace(*s)) - s++; - while (!isspace(*s) && *s) - s++; + if (s != NULL) { + while (isspace(*s)) + s++; + while (!isspace(*s) && *s) + s++; } arg_tail = s; return 0; @@ -285,30 +314,41 @@ float get_float_map (char *s) PostScript name. ("\t" means one or more tabs.) */ -void read_fmap( char *dbase) +void +read_fmap(char *dbase) { FILE *fin; int c; /* last character read */ char *nam; /* a font name being read */ nfonts = 0; - fin = fsearch(dbase,"",DB_TYPE); + fin = fsearch(dbase, "", DB_TYPE); trfonts = new_htab; - while ((c=getc(fin))!=EOF) { - if (nfonts==FCOUNT) quit("Need to increase FCOUNT","",""); + while ((c = getc(fin)) != EOF) { + if (nfonts == FCOUNT) + quit("Need to increase FCOUNT", "", ""); nam = &strpool[poolsize]; - for (;c!='\t'; c=getc(fin)) add_to_pool(c); + for (; c != '\t'; c = getc(fin)) { + if (c == EOF) + break; + add_to_pool(c); + } add_to_pool(0); *hfind(nam, trfonts) = nfonts; texname[nfonts] = &strpool[poolsize]; do { poolsize = texname[nfonts] - strpool; - do c=getc(fin); while (c=='\t'); - for (;c!='\t' && c!='\n'; c=getc(fin)) + do + c = getc(fin); + while (c == '\t'); + for (; c != '\t' && c != '\n'; c = getc(fin)) { + if (c == EOF) + break; add_to_pool(c); + } add_to_pool(0); - } while (c=='\t'); - font_num[nfonts] = -1; /* indicate font is not mounted */ + } while (c == '\t'); + font_num[nfonts] = -1; /* indicate font is not mounted */ nfonts++; } fclose(fin); @@ -329,28 +369,33 @@ void read_fmap( char *dbase) becomes redundant. Simply keeping an empty "trchars.adj" file around will do fine without requiring any changes to this program. */ -void read_char_adj(char *adjfile) +void +read_char_adj(char *adjfile) { - FILE* fin; + FILE *fin; char buf[200]; int i; fin = fsearch(adjfile, "", DB_TYPE); - for (i=0; i<nfonts; i++) + for (i = 0; i < nfonts; i++) shiftbase[i] = 0; - while (fgets(buf,200,fin)!=NULL) { - if (shiftptr==SHIFTS-1) quit("Need to increase SHIFTS","",""); - if (buf[0]!=' ' && buf[0]!='\t') { - for (i=0; buf[i]!='\0'; i++) - if (buf[i]=='\n') buf[i]='\0'; + while (fgets(buf, 200, fin) != NULL) { + if (shiftptr == SHIFTS - 1) + quit("Need to increase SHIFTS", "", ""); + if (buf[0] != ' ' && buf[0] != '\t') { + for (i = 0; buf[i] != '\0'; i++) + if (buf[i] == '\n') + buf[i] = '\0'; shiftchar[shiftptr++] = -1; - shiftbase[*hfind(buf,trfonts)] = shiftptr; - if (!hfound()) quit(adjfile," refers to unknown font ",buf); + shiftbase[*hfind(buf, trfonts)] = shiftptr; + if (!hfound()) + quit(adjfile, " refers to unknown font ", buf); } else { shiftchar[shiftptr] = get_int(buf); shifth[shiftptr] = get_float(arg_tail); shiftv[shiftptr] = -get_float(arg_tail); - if (arg_tail==NULL) quit("Bad shift entry : \"",buf,"\""); + if (arg_tail == NULL) + quit("Bad shift entry : \"", buf, "\""); shiftptr++; } } @@ -361,62 +406,63 @@ void read_char_adj(char *adjfile) /* Read the DESC file of the troff device to gather information about sizescale and whether running under groff. */ -void read_desc(void) +void +read_desc(void) { /* Ignore all commands not specially handled. This relieves of collecting commands without arguments here and also makes the program more robust in case of future DESC extensions. - */ - const char* const k1[] = { + */ + const char *const k1[] = { "res", "hor", "vert", "unitwidth", "paperwidth", "paperlength", "biggestfont", "spare2", "encoding", NULL }; - const char* const g1[] = { + const char *const g1[] = { "family", "paperheight", "postpro", "prepro", "print", "image_generator", "broken", NULL }; char cmd[200]; - FILE* fp; + FILE *fp; int i, n; fp = fsearch("DESC", "", TRFONTS_TYPE); - while (fscanf(fp, "%199s", cmd)!=EOF) { - if (*cmd=='#') { - while ((i = getc(fp))!=EOF && i!='\n'); + while (fscanf(fp, "%199s", cmd) != EOF) { + if (*cmd == '#') { + while ((i = getc(fp)) != EOF && i != '\n'); continue; } - if (strcmp(cmd, "fonts")==0) { - if (fscanf(fp, "%d", &n)!=1) + if (strcmp(cmd, "fonts") == 0) { + if (fscanf(fp, "%d", &n) != 1) return; for (i = 0; i < n; i++) - if (fscanf(fp, "%*s")==EOF) + if (fscanf(fp, "%*s") == EOF) return; - } else if (strcmp(cmd, "sizes")==0) { - while (fscanf(fp, "%d", &n)==1 && n!=0); - } else if (strcmp(cmd, "styles")==0 || - strcmp(cmd, "papersize")==0) { + } else if (strcmp(cmd, "sizes") == 0) { + while (fscanf(fp, "%d", &n) == 1 && n != 0); + } else if (strcmp(cmd, "styles") == 0 || + strcmp(cmd, "papersize") == 0) { gflag++; - while ((i = getc(fp))!=EOF && i!='\n'); - } else if (strcmp(cmd, "sizescale")==0) { - if (fscanf(fp, "%d", &n)==1) + while ((i = getc(fp)) != EOF && i != '\n'); + } else if (strcmp(cmd, "sizescale") == 0) { + if (fscanf(fp, "%d", &n) == 1) sizescale = n; gflag++; - } else if (strcmp(cmd, "charset")==0) { + } else if (strcmp(cmd, "charset") == 0) { return; } else { for (i = 0; k1[i]; i++) - if (strcmp(cmd, k1[i])==0) { - if (fscanf(fp, "%*s")==EOF) + if (strcmp(cmd, k1[i]) == 0) { + if (fscanf(fp, "%*s") == EOF) return; break; } - if (k1[i]==0) + if (k1[i] == 0) for (i = 0; g1[i]; i++) - if (strcmp(cmd, g1[i])==0) { - if (fscanf(fp, "%*s")==EOF) + if (strcmp(cmd, g1[i]) == 0) { + if (fscanf(fp, "%*s") == EOF) return; gflag = 1; break; @@ -437,39 +483,42 @@ void read_desc(void) because the latter source reflects alterations made only by dpost (the troff output driver that is bypassed when using MetaPost). */ -void read_tfm(int f) +void +read_tfm(int f) { - FILE* tf; + FILE *tf; long a = 0; - int sizes[5]; /* file & header lengths, bc, ec, words in wd table */ - long wd[256]; /* the width table (font size relative, scaled 2^20) */ + int sizes[5]; /* file & header lengths, bc, ec, words in wd table */ + long wd[256]; /* the width table (font size relative, scaled 2^20) */ int i, j; - long wtmp; /* needed to a floating exception on certain machines */ + long wtmp; /* needed to a floating exception on certain machines */ tf = fsearch(texname[f], ".tfm", TEXFONTS_TYPE); - for (i=0; i<5; i++) { + for (i = 0; i < 5; i++) { sizes[i] = getc(tf); - sizes[i] = (sizes[i]<<8) | (getc(tf) & 0377); + sizes[i] = (sizes[i] << 8) | (getc(tf) & 0377); } - if (sizes[1]<2 || sizes[2]<0 || sizes[3]<sizes[2]-1 || sizes[3]>255 - || sizes[0]<sizes[1]+sizes[3]-sizes[2]+sizes[4]+7) - quit("Bad tfm file: ",texname[f],".tfm"); - for (i=2*5; i<28; i++) + if (sizes[1] < 2 || sizes[2] < 0 || sizes[3] < sizes[2] - 1 + || sizes[3] > 255 + || sizes[0] < sizes[1] + sizes[3] - sizes[2] + sizes[4] + 7) + quit("Bad tfm file: ", texname[f], ".tfm"); + for (i = 2 * 5; i < 28; i++) (void) getc(tf); - for (i=0; i<4; i++) - a = (a<<8) | (long) (getc(tf) & 0377); - font_design_size[f] = ((float) a)/1048576.0; - fseek(tf, (long)(28+4*(sizes[1]+sizes[3]-sizes[2])), 0); - for (i=0; i<sizes[4]; i++) { + for (i = 0; i < 4; i++) + a = (a << 8) | (long) (getc(tf) & 0377); + font_design_size[f] = ((float) a) / 1048576.0; + fseek(tf, (long) (28 + 4 * (sizes[1] + sizes[3] - sizes[2])), 0); + for (i = 0; i < sizes[4]; i++) { wd[i] = 0L; - for (j=0; j<4; j++) - wd[i] = (wd[i]<<8) | (long) (getc(tf) & 0377); + for (j = 0; j < 4; j++) + wd[i] = (wd[i] << 8) | (long) (getc(tf) & 0377); } - fseek(tf, (long)(24+4*sizes[1]), 0); - for (i=sizes[2]; i<=sizes[3]; i++) { + fseek(tf, (long) (24 + 4 * sizes[1]), 0); + for (i = sizes[2]; i <= sizes[3]; i++) { wtmp = wd[getc(tf) & 0377]; - charwd[f][i] = ((double) wtmp)/1048576.0/unit; - for (j=3; --j>=0;) (void) getc(tf); + charwd[f][i] = ((double) wtmp) / 1048576.0 / unit; + for (j = 3; --j >= 0;) + (void) getc(tf); } fclose(tf); } @@ -491,58 +540,63 @@ void read_tfm(int f) 2. The `charcode' field parsed by "lastcode = get_int(arg_tail);" may be given either in decimal, octal, or hexadecimal format. */ -int scan_desc_line(int f, char *lin) +int +scan_desc_line(int f, char *lin) { static int lastcode; char *s; s = &strpool[poolsize]; - while (*lin!=' ' && *lin!='\t' && *lin!='\0') + while (*lin != ' ' && *lin != '\t' && *lin != '\0') add_to_pool(*lin++); add_to_pool('\0'); - while (*lin==' ' || *lin=='\t') lin++; - if (*lin=='"') { - if (lastcode<MAXCHARS) - *hfind(s,charcodes[f]) = lastcode; + while (*lin == ' ' || *lin == '\t') + lin++; + if (*lin == '"') { + if (lastcode < MAXCHARS) + *hfind(s, charcodes[f]) = lastcode; } else { - (void) get_float_map(lin); - (void) get_int(arg_tail); - lastcode = get_int_map(arg_tail); - if (arg_tail==NULL) return 0; - if (lastcode<MAXCHARS) - *hfind(s,charcodes[f]) = lastcode; - } + (void) get_float_map(lin); + (void) get_int(arg_tail); + lastcode = get_int_map(arg_tail); + if (arg_tail == NULL) + return 0; + if (lastcode < MAXCHARS) + *hfind(s, charcodes[f]) = lastcode; + } return 1; } /* Read the font description file for the font with the given troff name and update the data structures. The result is the internal font number. */ -int read_fontdesc(char *nam) /* troff name */ -{ +int +read_fontdesc(char *nam) +{ /* troff name */ char buf[200]; - FILE* fin; /* input file */ + FILE *fin; /* input file */ int f; /* internal font number */ - if (unit==0.0) quit("Resolution is not set soon enough","",""); + if (unit == 0.0) + quit("Resolution is not set soon enough", "", ""); f = *hfind(nam, trfonts); if (!hfound()) - quit("Font was not in map file","",""); + quit("Font was not in map file", "", ""); fin = fsearch(nam, "", TRFONTS_TYPE); for (;;) { - if (fgets(buf,200,fin)==NULL) - quit("Description file for ",nam," ends unexpectedly"); - if (strncmp(buf,"special",7)==0) { + if (fgets(buf, 200, fin) == NULL) + quit("Description file for ", nam, " ends unexpectedly"); + if (strncmp(buf, "special", 7) == 0) { *specf_tail = f; next_specfnt[f] = FCOUNT; specf_tail = &next_specfnt[f]; - } else if (strncmp(buf,"charset",7)==0) + } else if (strncmp(buf, "charset", 7) == 0) break; } charcodes[f] = new_htab; - while (fgets(buf,200,fin)!=NULL) + while (fgets(buf, 200, fin) != NULL) if (scan_desc_line(f, buf) == 0) - quit(nam," has a bad line in its description file: ",buf); + quit(nam, " has a bad line in its description file: ", buf); fclose(fin); return f; } @@ -569,53 +623,58 @@ int read_fontdesc(char *nam) /* troff name */ and an ampersand should come next. The starting condition state=initial is a lot like state=special, except no ampersand is required. */ -#define special 0 /* the state after printing a `char' expression */ -#define normal 1 /* the state value in a quoted string */ -#define initial 2 /* initial state */ +#define special 0 /* the state after printing a `char' expression */ +#define normal 1 /* the state value in a quoted string */ +#define initial 2 /* initial state */ int state = initial; -int print_col = 0; /* there are at most this many characters on the current line */ +int print_col = 0; /* there are at most this many characters on the current line */ /* To print a string on the MPX file, initialize print_col, ensure that state=initial, and pass the characters one-at-a-time to print_char. */ -void print_char(char cc) +void +print_char(char cc) { - int printable; /* nonzero if it is safe to print c */ - int l; /* number of chars in c or the `char' expression */ - int c; /* equal to cc mod 256, but always positive */ - - c = cc&0377; - printable = isprint(c) && c<128; /* avoid high-bit-on Latin-1 chars */ - if (printable) l=1; - else if (c<10) l=5; - else if (c<100) l=6; - else l=7; - if (print_col+l>line_length-2) { - if (state==normal) { - putc('"',mpxf); + int printable; /* nonzero if it is safe to print c */ + int l; /* number of chars in c or the `char' expression */ + int c; /* equal to cc mod 256, but always positive */ + + c = cc & 0377; + printable = isprint(c) && c < 128; /* avoid high-bit-on Latin-1 chars */ + if (printable) + l = 1; + else if (c < 10) + l = 5; + else if (c < 100) + l = 6; + else + l = 7; + if (print_col + l > line_length - 2) { + if (state == normal) { + putc('"', mpxf); state = special; } - putc('\n',mpxf); + putc('\n', mpxf); print_col = 0; } - if (state==normal) - if (printable) putc(c,mpxf); + if (state == normal) + if (printable) + putc(c, mpxf); else { - fprintf(mpxf,"\"&char%d",c); + fprintf(mpxf, "\"&char%d", c); print_col += 2; - } - else { - if (state==special) { - putc('&',mpxf); + } else { + if (state == special) { + putc('&', mpxf); print_col++; } if (printable) { - fprintf(mpxf,"\"%c",c); + fprintf(mpxf, "\"%c", c); print_col++; } else - fprintf(mpxf,"char%d",c); + fprintf(mpxf, "char%d", c); } print_col += l; state = printable ? normal : special; @@ -625,15 +684,16 @@ void print_char(char cc) /* The end_char_string procedure gets the string ended properly and ensures that there is room for |l| more characters on the output line. */ -void end_char_string(int l) +void +end_char_string(int l) { - while (state>special) { - putc('"',mpxf); + while (state > special) { + putc('"', mpxf); print_col++; state--; } - if (print_col+l>line_length) { - putc('\n',mpxf); + if (print_col + l > line_length) { + putc('\n', mpxf); print_col = 0; } state = initial; /* get ready to print the next string */ @@ -648,7 +708,7 @@ void end_char_string(int l) char font_used[FCOUNT]; /* nonzero for fonts used on this page */ int fonts_used; /* nonzero if any font been used on this page */ int graphics_used; /* nonzero if any graphics seen on this page */ -float str_h1,str_v; /* corrected start pos for current out string */ +float str_h1, str_v; /* corrected start pos for current out string */ float str_h2; /* where the current output string ends */ int str_f; /* internal font num for cur. output string */ float str_size; /* point size for this text string */ @@ -657,22 +717,26 @@ float str_size; /* point size for this text string */ /* Before using any fonts we need to define a MetaPost macro for typesetting character strings. */ -void prepare_font_use(void) +void +prepare_font_use(void) { int k; - for (k=0;k<nfonts;k++) font_used[k]=0; + for (k = 0; k < nfonts; k++) + font_used[k] = 0; fonts_used = 1; - fprintf(mpxf,"string n[];\n"); - fprintf(mpxf,"vardef s(expr t,m,x,y) =\n"); - fprintf(mpxf," addto p also t scaled(m*1.00375) shifted(x,y); enddef;\n"); + fprintf(mpxf, "string n[];\n"); + fprintf(mpxf, "vardef s(expr t,m,x,y) =\n"); + fprintf(mpxf, + " addto p also t scaled(m*1.00375) shifted(x,y); enddef;\n"); } /* Do what is necessary when the font with internal number f is used for the first time on a page. */ -void first_use(int f) +void +first_use(int f) { font_used[f] = 1; fprintf(mpxf, "n%d=\"%s\";\n", font_num[f], texname[f]); @@ -682,41 +746,44 @@ void first_use(int f) /* Print any transformations required by the current Xslant and Xheight settings. */ -void slant_and_ht(void) +void +slant_and_ht(void) { int i = 0; - if (Xslant!=0.0) { - fprintf(mpxf," slanted%.5f",Xslant); + if (Xslant != 0.0) { + fprintf(mpxf, " slanted%.5f", Xslant); i++; } - if (Xheight!=cursize && Xheight!=0.0 && cursize!=0.0) { - fprintf(mpxf," yscaled%.4f", Xheight/cursize); + if (Xheight != cursize && Xheight != 0.0 && cursize != 0.0) { + fprintf(mpxf, " yscaled%.4f", Xheight / cursize); i++; } - if (i>0) fprintf(mpxf, "\n "); + if (i > 0) + fprintf(mpxf, "\n "); } /* We maintain the invariant that str_f is -1 when there is no output string under construction. */ -void finish_last_char(void) +void +finish_last_char(void) { - float m,x,y; /* font scale, MetaPost coords of reference point */ - - if (str_f>=0) { - m = str_size/font_design_size[str_f]; - x = str_h1*unit; - y = YCORR-str_v*unit; - if (fabs(x)>=4096.0 || fabs(y)>=4096.0 || m>=4096.0 || m<0) { - warn("text out of range ignored","",""); + float m, x, y; /* font scale, MetaPost coords of reference point */ + + if (str_f >= 0) { + m = str_size / font_design_size[str_f]; + x = str_h1 * unit; + y = YCORR - str_v * unit; + if (fabs(x) >= 4096.0 || fabs(y) >= 4096.0 || m >= 4096.0 || m < 0) { + warn("text out of range ignored", "", ""); end_char_string(67); - } - else end_char_string(47); - fprintf(mpxf,")infont n%d", font_num[str_f]); + } else + end_char_string(47); + fprintf(mpxf, ")infont n%d", font_num[str_f]); slant_and_ht(); - fprintf(mpxf,",%.5f,%.4f,%.4f);\n", m, x,y); + fprintf(mpxf, ",%.5f,%.4f,%.4f);\n", m, x, y); str_f = -1; } } @@ -724,48 +791,54 @@ void finish_last_char(void) /* Output character number c in the font with internal number f. */ -void set_num_char(int f,int c) +void +set_num_char(int f, int c) { float hh, vv; /* corrected versions of h, v */ int i; hh = h; vv = v; - for (i=shiftbase[f]; shiftchar[i]>=0; i++) - if (shiftchar[i]==c) { - hh += (cursize/unit)*shifth[i]; - vv += (cursize/unit)*shiftv[i]; + for (i = shiftbase[f]; shiftchar[i] >= 0; i++) + if (shiftchar[i] == c) { + hh += (cursize / unit) * shifth[i]; + vv += (cursize / unit) * shiftv[i]; break; } /* if (c==0) quit("attempt to typeset an invalid character","",""); */ - if (hh-str_h2>=1.0 || str_h2-hh>=1.0 || vv-str_v>=1.0 || str_v-vv>=1.0 - || f!=str_f || cursize!=str_size) { - if (str_f>=0) finish_last_char(); + if (hh - str_h2 >= 1.0 || str_h2 - hh >= 1.0 || vv - str_v >= 1.0 + || str_v - vv >= 1.0 || f != str_f || cursize != str_size) { + if (str_f >= 0) + finish_last_char(); else if (!fonts_used) prepare_font_use(); /* first font usage on this page */ if (!font_used[f]) first_use(f); /* first use of font f on this page */ - fprintf(mpxf,"s(("); + fprintf(mpxf, "s(("); print_col = 3; - str_f=f; str_v=vv; str_h1=hh; + str_f = f; + str_v = vv; + str_h1 = hh; str_size = cursize; } print_char(c); - str_h2 = hh + cursize*charwd[f][c]; + str_h2 = hh + cursize * charwd[f][c]; } /* Output a string. */ -void set_string (char *cname) +void +set_string(char *cname) { - float hh; /* corrected version of h, current horisontal position */ + float hh; /* corrected version of h, current horisontal position */ - if (!*cname) return; + if (!*cname) + return; hh = h; - set_num_char(curfont,*cname); - hh+= cursize*charwd[curfont][*cname]; - while (*++cname){ - print_char(*cname); - hh += cursize*charwd[curfont][*cname]; + set_num_char(curfont, *cname); + hh += cursize * charwd[curfont][*cname]; + while (*++cname) { + print_char(*cname); + hh += cursize * charwd[curfont][*cname]; } h = rint(hh); finish_last_char(); @@ -773,20 +846,24 @@ void set_string (char *cname) /* The following initialization and clean-up is required. */ -void start_picture(void) +void +start_picture(void) { fonts_used = graphics_used = 0; str_f = -1; str_v = 0.0; str_h2 = 0.0; str_size = 0.0; - fprintf(mpxf,"begingroup save C,D,p,s,n; picture p; p=nullpicture;\n"); + fprintf(mpxf, + "begingroup save C,D,p,s,n; picture p; p=nullpicture;\n"); } -void stop_picture(void) +void +stop_picture(void) { - if (str_f>=0) finish_last_char(); - fprintf(mpxf,"p endgroup\n"); + if (str_f >= 0) + finish_last_char(); + fprintf(mpxf, "p endgroup\n"); } @@ -800,8 +877,8 @@ void stop_picture(void) the vardef macro, puts it in the string pool, and index where the string starts. The name should be C.<something>. */ -char specintro[] = "vardef "; /* MetaPost name follows this */ -#define speci 7 /* length of the above string */ +char specintro[] = "vardef "; /* MetaPost name follows this */ +#define speci 7 /* length of the above string */ /* TH: A bit of trickery is added here for case-insensitive file systems. This aliasing allows the CHARLIB directory @@ -814,38 +891,43 @@ char specintro[] = "vardef "; /* MetaPost name follows this */ else ungetc(c,deff) -int copy_spec_char(char *cname) +int +copy_spec_char(char *cname) { - int k = 0; /* how much of specintro so far */ + int k = 0; /* how much of specintro so far */ FILE *deff; int c, s; - if (strcmp(cname,"ao") == 0) { - deff = fsearch("ao.x", "", CHARLIB_TYPE); - test_redo_search; - } else if (strcmp(cname,"lh") == 0) { - deff = fsearch("lh.x", "", CHARLIB_TYPE); - test_redo_search; - } else if (strcmp(cname,"~=") == 0) { - deff = fsearch("twiddle", "", CHARLIB_TYPE); - test_redo_search; - } else { - deff = fsearch(cname, "", CHARLIB_TYPE); - } - while (k<speci) { - if ((c=getc(deff))==EOF) - quit("No vardef in charlib/",cname,""); + if (strcmp(cname, "ao") == 0) { + deff = fsearch("ao.x", "", CHARLIB_TYPE); + test_redo_search; + } else if (strcmp(cname, "lh") == 0) { + deff = fsearch("lh.x", "", CHARLIB_TYPE); + test_redo_search; + } else if (strcmp(cname, "~=") == 0) { + deff = fsearch("twiddle", "", CHARLIB_TYPE); + test_redo_search; + } else { + deff = fsearch(cname, "", CHARLIB_TYPE); + } + while (k < speci) { + if ((c = getc(deff)) == EOF) + quit("No vardef in charlib/", cname, ""); putc(c, mpxf); - if (c==specintro[k]) k++; else k=0; + if (c == specintro[k]) + k++; + else + k = 0; } s = poolsize; - while ((c=getc(deff))!='(') { - if (c==EOF) quit("vardef in charlib/",cname," has no arguments"); + while ((c = getc(deff)) != '(') { + if (c == EOF) + quit("vardef in charlib/", cname, " has no arguments"); putc(c, mpxf); add_to_pool(c); } putc(c, mpxf); add_to_pool('\0'); - while ((c=getc(deff))!=EOF) + while ((c = getc(deff)) != EOF) putc(c, mpxf); return s; } @@ -856,36 +938,43 @@ int copy_spec_char(char *cname) If the character is not in the current font we have to search the special fonts. */ -Hcell *spec_tab = (Hcell*)0; +Hcell *spec_tab = (Hcell *) 0; -void set_char(char *cname) +void +set_char(char *cname) { int f, c, *flagp; - if (*cname==' '||*cname=='\t') return; + if (*cname == ' ' || *cname == '\t') + return; f = curfont; c = *hfind(cname, charcodes[f]); if (!hfound()) { - for (f=specfnt; f!=FCOUNT; f=next_specfnt[f]) { + for (f = specfnt; f != FCOUNT; f = next_specfnt[f]) { c = *hfind(cname, charcodes[f]); - if (hfound()) goto out; + if (hfound()) + goto out; } - quit("There is no character ",cname,""); + quit("There is no character ", cname, ""); } -out:if (!is_specchar(c)) set_num_char(f,c); + out:if (!is_specchar(c)) + set_num_char(f, c); else { - if (str_f>=0) finish_last_char(); - if (!fonts_used) prepare_font_use(); - if (!font_used[f]) first_use(f); - if (spec_tab==(Hcell*)0) + if (str_f >= 0) + finish_last_char(); + if (!fonts_used) + prepare_font_use(); + if (!font_used[f]) + first_use(f); + if (spec_tab == (Hcell *) 0) spec_tab = new_htab; flagp = hfind(cname, spec_tab); - if (*flagp==0) + if (*flagp == 0) *flagp = copy_spec_char(cname); /* this won't be zero */ fprintf(mpxf, "s(%s(n%d)", &strpool[*flagp], font_num[f]); slant_and_ht(); fprintf(mpxf, ",%.5f,%.4f,%.4f);\n", - cursize/font_design_size[f], h*unit, YCORR-v*unit); + cursize / font_design_size[f], h * unit, YCORR - v * unit); } } @@ -898,19 +987,21 @@ out:if (!is_specchar(c)) set_num_char(f,c); /* Mount the font with troff name nam at external font number n and read any necessary font files. */ -void do_font_def(int n, char *nam) +void +do_font_def(int n, char *nam) { int f, k; f = *hfind(nam, trfonts); if (!hfound()) - quit("Font ",nam," was not in map file"); - if (font_design_size[f]==0) { + quit("Font ", nam, " was not in map file"); + if (font_design_size[f] == 0) { read_fontdesc(nam); read_tfm(f); } - for (k=0; k<nfonts; k++) - if (font_num[k]==n) font_num[k]= -1; + for (k = 0; k < nfonts; k++) + if (font_num[k] == n) + font_num[k] = -1; font_num[f] = n; } @@ -925,14 +1016,16 @@ void do_font_def(int n, char *nam) /* Given the control points of a cubic Bernstein polynomial, evaluate it at t. */ -float Beval(float *xx, float t) +float +Beval(float *xx, float t) { float zz[4]; register int i, j; - for (i=0; i<=3; i++) zz[i]=xx[i]; - for (i=3; i>0; i--) - for (j=0; j<i; j++) - zz[j] += t*(zz[j+1]-zz[j]); + for (i = 0; i <= 3; i++) + zz[i] = xx[i]; + for (i = 3; i > 0; i--) + for (j = 0; j < i; j++) + zz[j] += t * (zz[j + 1] - zz[j]); return zz[0]; } @@ -941,29 +1034,31 @@ float Beval(float *xx, float t) The tables below give the Bezier control points for MetaPost's cubic approximation to the first octant of a unit circle. */ -float xx[4] = {1.0, 1.0, 0.8946431597, 0.7071067812}; -float yy[4] = {0.0, 0.2652164899, 0.5195704026, 0.7071067812}; +float xx[4] = { 1.0, 1.0, 0.8946431597, 0.7071067812 }; +float yy[4] = { 0.0, 0.2652164899, 0.5195704026, 0.7071067812 }; -float circangle(float t) +float +circangle(float t) { float ti; ti = floor(t); t -= ti; - return (float) atan(Beval(yy,t)/Beval(xx,t)) + ti*Speed; + return (float) atan(Beval(yy, t) / Beval(xx, t)) + ti * Speed; } /* Find the spline parameter where `makepath pencircle' comes closest to (cos(a)/2,sin(a)/2). */ -float circtime(float a) +float +circtime(float a) { int i; float t; - t = a/Speed; - for (i=2; --i>=0;) - t += (a - circangle(t))/Speed; + t = a / Speed; + for (i = 2; --i >= 0;) + t += (a - circangle(t)) / Speed; return t; } @@ -973,12 +1068,14 @@ float circtime(float a) Troff Graphics ***************************************************************/ -float gx, gy; /* current point for graphics (init. (h,YCORR/unit-v) */ +float gx, gy; /* current point for graphics (init. (h,YCORR/unit-v) */ -void prepare_graphics(void) +void +prepare_graphics(void) { - fprintf(mpxf,"vardef D(expr d)expr q =\n"); - fprintf(mpxf," addto p doublepath q withpen pencircle scaled d; enddef;\n"); + fprintf(mpxf, "vardef D(expr d)expr q =\n"); + fprintf(mpxf, + " addto p doublepath q withpen pencircle scaled d; enddef;\n"); graphics_used = 1; } @@ -988,17 +1085,19 @@ void prepare_graphics(void) of the string s or NULL if nothing could be read from s, it provides the argument for the next iteration. */ -char *do_line(char *s) +char * +do_line(char *s) { float dh, dv; - fprintf(mpxf, "(%.3f,%.3f)", gx*unit, gy*unit); + fprintf(mpxf, "(%.3f,%.3f)", gx * unit, gy * unit); dh = get_float(s); dv = get_float(arg_tail); - if (arg_tail==NULL) return NULL; + if (arg_tail == NULL) + return NULL; gx += dh; gy -= dv; - fprintf(mpxf,"--\n"); + fprintf(mpxf, "--\n"); return arg_tail; } @@ -1010,34 +1109,40 @@ char *do_line(char *s) terminate the iteration by printing last time's ending point and returning NULL. */ -char * spline_seg(char *s) +char * +spline_seg(char *s) { float dh1, dv1, dh2, dv2; dh1 = get_float(s); dv1 = get_float(arg_tail); - if (arg_tail==NULL) quit("Missing spline increments","",""); + if (arg_tail == NULL) + quit("Missing spline increments", "", ""); s = arg_tail; - fprintf(mpxf, "(%.3f,%.3f)", (gx+.5*dh1)*unit, (gy-.5*dv1)*unit); + fprintf(mpxf, "(%.3f,%.3f)", (gx + .5 * dh1) * unit, + (gy - .5 * dv1) * unit); gx += dh1; gy -= dv1; dh2 = get_float(s); dv2 = get_float(arg_tail); - if (arg_tail==NULL) return NULL; + if (arg_tail == NULL) + return NULL; fprintf(mpxf, "..\ncontrols (%.3f,%.3f) and (%.3f,%.3f)..\n", - (gx-dh1/6.0)*unit, (gy+dv1/6.0)*unit, (gx+dh2/6.0)*unit, - (gy-dv2/6.0)*unit); + (gx - dh1 / 6.0) * unit, (gy + dv1 / 6.0) * unit, + (gx + dh2 / 6.0) * unit, (gy - dv2 / 6.0) * unit); return s; } /* Draw an ellipse with the given major and minor axes. */ -void do_ellipse(float a, float b) +void +do_ellipse(float a, float b) { fprintf(mpxf, "makepath(pencircle xscaled %.3f\n yscaled %.3f", - a*unit, b*unit); - fprintf(mpxf, " shifted (%.3f,%.3f));\n", (gx+.5*a)*unit, gy*unit); + a * unit, b * unit); + fprintf(mpxf, " shifted (%.3f,%.3f));\n", (gx + .5 * a) * unit, + gy * unit); gx += a; } @@ -1045,16 +1150,19 @@ void do_ellipse(float a, float b) /* Draw a counter-clockwise arc centered at (cx,cy) with initial and final radii (ax,ay) and (bx,by) respectively. */ -void do_arc(float cx, float cy, float ax, float ay, float bx, float by) +void +do_arc(float cx, float cy, float ax, float ay, float bx, float by) { float t1, t2; t1 = circtime(atan2(ay, ax)); t2 = circtime(atan2(by, bx)); - if (t2 < t1) t2 += 8.0; + if (t2 < t1) + t2 += 8.0; fprintf(mpxf, "subpath (%.5f,%.5f) of\n", t1, t2); - fprintf(mpxf, " makepath(pencircle scaled %.3f shifted (%.3f,%.3f));\n", - 2.0*sqrt(ax*ax+ay*ay)*unit, cx*unit, cy*unit); + fprintf(mpxf, + " makepath(pencircle scaled %.3f shifted (%.3f,%.3f));\n", + 2.0 * sqrt(ax * ax + ay * ay) * unit, cx * unit, cy * unit); gx = cx + bx; gy = cy + by; } @@ -1063,29 +1171,34 @@ void do_arc(float cx, float cy, float ax, float ay, float bx, float by) /* string s is everything following the initial `D' in a troff graphics command. */ -void do_graphic(char *s) +void +do_graphic(char *s) { float h1, v1, h2, v2; finish_last_char(); /* GROFF uses Fd to set fill color for solid drawing objects to the default, so just ignore that. - */ - if (s[0] == 'F' && s[1] == 'd') return; + */ + if (s[0] == 'F' && s[1] == 'd') + return; gx = (float) h; - gy = YCORR/unit - ((float) v); - if (!graphics_used) prepare_graphics(); - fprintf(mpxf,"D(%.4f) ", LWscale*cursize); + gy = YCORR / unit - ((float) v); + if (!graphics_used) + prepare_graphics(); + fprintf(mpxf, "D(%.4f) ", LWscale * cursize); switch (*s++) { case 'c': h1 = get_float(s); - if (arg_tail==NULL) quit("Bad argument in ",s-2,""); - do_ellipse(h1,h1); + if (arg_tail == NULL) + quit("Bad argument in ", s - 2, ""); + do_ellipse(h1, h1); break; case 'e': h1 = get_float(s); v1 = get_float(arg_tail); - if (arg_tail==NULL) quit("Bad argument in ",s-2,""); - do_ellipse(h1,v1); + if (arg_tail == NULL) + quit("Bad argument in ", s - 2, ""); + do_ellipse(h1, v1); break; case 'A': fprintf(mpxf, "reverse "); @@ -1095,28 +1208,34 @@ void do_graphic(char *s) v1 = get_float(arg_tail); h2 = get_float(arg_tail); v2 = get_float(arg_tail); - if (arg_tail==NULL) quit("Bad argument in ",s-2,""); - do_arc(gx+h1, gy-v1, -h1, v1, h2, -v2); + if (arg_tail == NULL) + quit("Bad argument in ", s - 2, ""); + do_arc(gx + h1, gy - v1, -h1, v1, h2, -v2); break; - case 'l': case 'p': - while (s!=NULL) + case 'l': + case 'p': + while (s != NULL) s = do_line(s); fprintf(mpxf, ";\n"); break; case 'q': - do s = spline_seg(s); while (s!=NULL); + do + s = spline_seg(s); + while (s != NULL); fprintf(mpxf, ";\n"); break; case '~': - fprintf(mpxf, "(%.3f,%.3f)--", gx*unit, gy*unit); - do s = spline_seg(s); while (s!=NULL); - fprintf(mpxf, "--(%.3f,%.3f);\n", gx*unit, gy*unit); + fprintf(mpxf, "(%.3f,%.3f)--", gx * unit, gy * unit); + do + s = spline_seg(s); + while (s != NULL); + fprintf(mpxf, "--(%.3f,%.3f);\n", gx * unit, gy * unit); break; default: - quit("Unknown drawing function",s-2,""); + quit("Unknown drawing function", s - 2, ""); } - h = (int) floor(gx+.5); - v = (int) floor(YCORR/unit+.5-gy); + h = (int) floor(gx + .5); + v = (int) floor(YCORR / unit + .5 - gy); } @@ -1125,68 +1244,84 @@ void do_graphic(char *s) Interpreting Troff Output ***************************************************************/ -void change_font(int f) +void +change_font(int f) { - for (curfont=0; curfont<nfonts; curfont++) - if (font_num[curfont]==f) return; - quit("Bad font setting","",""); + for (curfont = 0; curfont < nfonts; curfont++) + if (font_num[curfont] == f) + return; + quit("Bad font setting", "", ""); } /* String s0 is everything following the initial `x' in a troff device control command. A zero result indicates a stop command. */ -int do_x_cmd(char *s0) +int +do_x_cmd(char *s0) { float x; int n; char *s; s = s0; - while (*s==' ' || *s=='\t') s++; + while (*s == ' ' || *s == '\t') + s++; switch (*s++) { case 'r': - if (unit!=0.0) quit("Attempt to reset resolution","",""); - while (*s!=' ' && *s!='\t') s++; + if (unit != 0.0) + quit("Attempt to reset resolution", "", ""); + while (*s != ' ' && *s != '\t') + s++; unit = get_float(s); - if (unit<=0.0) quit("Bad resolution: x",s0,""); - unit = 72.0/unit; + if (unit <= 0.0) + quit("Bad resolution: x", s0, ""); + unit = 72.0 / unit; break; case 'f': - while (*s!=' ' && *s!='\t') s++; + while (*s != ' ' && *s != '\t') + s++; n = get_int(s); - if (arg_tail==NULL) quit("Bad font def: x",s0,""); + if (arg_tail == NULL) + quit("Bad font def: x", s0, ""); s = arg_tail; - while (*s==' ' || *s=='\t') s++; + while (*s == ' ' || *s == '\t') + s++; do_font_def(n, s); break; case 's': return 0; case 'H': - while (*s!=' ' && *s!='\t') s++; + while (*s != ' ' && *s != '\t') + s++; Xheight = get_float(s); /* GROFF troff output is scaled groff_out(5): The argument to the s command is in scaled - points (units of points/n, where n is the argument - to the sizescale command in the DESC file.) The - argument to the x Height command is also in scaled points. - sizescale for groff devps is 1000 - */ + points (units of points/n, where n is the argument + to the sizescale command in the DESC file.) The + argument to the x Height command is also in scaled points. + sizescale for groff devps is 1000 + */ if (sizescale) { - if(unit != 0.0) Xheight *= unit; /* ??? */ - else Xheight /= sizescale; + if (unit != 0.0) + Xheight *= unit; /* ??? */ + else + Xheight /= sizescale; } - if (Xheight==cursize) Xheight=0.0; + if (Xheight == cursize) + Xheight = 0.0; break; case 'S': - while (*s!=' ' && *s!='\t') s++; - Xslant = get_float(s)*(PI/180.0); + while (*s != ' ' && *s != '\t') + s++; + Xslant = get_float(s) * (PI / 180.0); x = cos(Xslant); - if (-1e-4<x && x<1e-4) quit("Excessive slant","",""); - Xslant = sin(Xslant)/x; + if (-1e-4 < x && x < 1e-4) + quit("Excessive slant", "", ""); + Xslant = sin(Xslant) / x; break; default: - /* do nothing */; + /* do nothing */ ; } return 1; } @@ -1205,118 +1340,142 @@ int do_x_cmd(char *s0) must be disabled by removing the line "tcommand" from the DESC file in the $(prefix)/lib/groff/devps directory. */ -int do_page(void) +int +do_page(void) { char buf[LLENGTH]; char a, *c, *cc; h = v = 0; - while (fgets(buf,LLENGTH,trf)!=NULL) { - for (c=buf; *c!='\n'; c++) - if (*c=='\0') quit("Need to increase LLENGTH","",""); + while (fgets(buf, LLENGTH, trf) != NULL) { + for (c = buf; *c != '\n'; c++) + if (*c == '\0') + quit("Need to increase LLENGTH", "", ""); *c = '\0'; lnno++; c = buf; - while (*c!='\0') { - switch(*c) { - case ' ': case '\t': case 'w': + while (*c != '\0') { + switch (*c) { + case ' ': + case '\t': + case 'w': c++; break; case 's': - cursize = get_float(c+1); + cursize = get_float(c + 1); /* GROFF troff output is scaled groff_out(5): The argument to the s command is in scaled - points (units of points/n, where n is the argument - to the sizescale command in the DESC file.) The - argument to the x Height command is also in scaled - points. - sizescale for groff devps is 1000 - */ + points (units of points/n, where n is the argument + to the sizescale command in the DESC file.) The + argument to the x Height command is also in scaled + points. + sizescale for groff devps is 1000 + */ if (sizescale) { - if (unit != 0.0) cursize *= unit; /* ??? */ - else cursize /= sizescale; + if (unit != 0.0) + cursize *= unit; /* ??? */ + else + cursize /= sizescale; } goto iarg; case 'f': - change_font(get_int(c+1)); + change_font(get_int(c + 1)); goto iarg; case 'c': - if (c[1]=='\0') quit("Bad c command in troff output","",""); - cc = c+2; + if (c[1] == '\0') + quit("Bad c command in troff output", "", ""); + cc = c + 2; goto set; case 'C': - cc=c; do cc++; while (*cc!=' ' && *cc!='\t' && *cc!='\0'); + cc = c; + do + cc++; + while (*cc != ' ' && *cc != '\t' && *cc != '\0'); goto set; case 'N': - set_num_char(curfont, get_int(c+1)); + set_num_char(curfont, get_int(c + 1)); goto iarg; case 'H': - h = get_int(c+1); + h = get_int(c + 1); goto iarg; case 'V': - v = get_int(c+1); + v = get_int(c + 1); goto iarg; case 'h': - h += get_int(c+1); + h += get_int(c + 1); goto iarg; case 'v': - v += get_int(c+1); + v += get_int(c + 1); goto iarg; - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - if (c[1]<'0' || c[1]>'9' || c[2]=='\0') - quit("Bad nnc command in troff output","",""); - h += 10*(c[0]-'0') + c[1]-'0'; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (c[1] < '0' || c[1] > '9' || c[2] == '\0') + quit("Bad nnc command in troff output", "", ""); + h += 10 * (c[0] - '0') + c[1] - '0'; c++; - cc = c+2; + cc = c + 2; goto set; case 'p': return 1; case 'n': - (void) get_int(c+1); + (void) get_int(c + 1); (void) get_int(arg_tail); goto iarg; case 'D': - do_graphic(c+1); + do_graphic(c + 1); goto eoln; case 'x': - if (!do_x_cmd(c+1)) return 0; + if (!do_x_cmd(c + 1)) + return 0; goto eoln; case '#': goto eoln; case 'F': - /* GROFF uses this command to report filename */ - goto eoln; + /* GROFF uses this command to report filename */ + goto eoln; case 'm': - /* GROFF uses this command to control color */ + /* GROFF uses this command to control color */ goto eoln; case 'u': - /* GROFF uses this command to output a word with additional - white space between characters, not implemented - */ + /* GROFF uses this command to output a word with additional + white space between characters, not implemented + */ quit("Bad command in troff output\n", - "change the DESC file for your GROFF PostScript device, ", - "remove tcommand"); + "change the DESC file for your GROFF PostScript device, ", + "remove tcommand"); case 't': - /* GROFF uses this command to output a word */ - cc=c; do cc++; while (*cc!=' ' && *cc!='\t' && *cc!='\0'); - a= *cc; *cc='\0'; - set_string(++c); - c = cc; - *c = a; - continue; + /* GROFF uses this command to output a word */ + cc = c; + do + cc++; + while (*cc != ' ' && *cc != '\t' && *cc != '\0'); + a = *cc; + *cc = '\0'; + set_string(++c); + c = cc; + *c = a; + continue; default: - quit("Bad command in troff output","",""); + quit("Bad command in troff output", "", ""); } continue; - set:a= *cc; *cc='\0'; + set:a = *cc; + *cc = '\0'; set_char(++c); c = cc; *c = a; continue; - iarg:c = arg_tail; + iarg:c = arg_tail; } - eoln:/* do nothing */; + eoln: /* do nothing */ ; } return 0; } @@ -1326,55 +1485,59 @@ int do_page(void) Main Program ***************************************************************/ -void usage (char *name, int status) +void +usage(char *name, int status) { FILE *f = status == 0 ? stdout : stderr; - fputs ("Usage: dmp [OPTION]... DITROFFFILE [MPXFILE]\n\ + fputs("Usage: dmp [OPTION]... DITROFFFILE [MPXFILE]\n\ Translate DITROFFFILE to the MetaPost MPXFILE or standard output.\n\ \n\ --help display this help and exit\n\ --version output version information and exit\n", f); - putc ('\n', f); - fputs ("Email bug reports to metapost@tug.org.\n", f); + putc('\n', f); + fputs("Email bug reports to metapost@tug.org.\n", f); exit(status); } -int main(int argc, char **argv) +int +main(int argc, char **argv) { int more; - fsearch_init(); + fsearch_init(argc, argv); trf = stdin; mpxf = stdout; if (argc == 1) { - fputs ("dmp: Need one or two file arguments.\n", stderr); - fputs ("Try `dmp --help' for more information.\n", stderr); - exit(1); - } else if (argc > 1 && (strcmp (argv[1], "--help") == 0 - || strcmp (argv[1], "-help") == 0)) { - usage (argv[0], 0); - } else if (argc > 1 && (strcmp (argv[1], "--version") == 0 - || strcmp (argv[1], "-version") == 0)) { - fputs (term_banner,stdout); - fputs ("\nThis program is in the public domain.\n\ -Primary author of dmp: John Hobby.\n", stdout); - exit (0); + fputs("dmp: Need one or two file arguments.\n", stderr); + fputs("Try `dmp --help' for more information.\n", stderr); + exit(1); + } else if (argc > 1 && (strcmp(argv[1], "--help") == 0 + || strcmp(argv[1], "-help") == 0)) { + usage(argv[0], 0); + } else if (argc > 1 && (strcmp(argv[1], "--version") == 0 + || strcmp(argv[1], "-version") == 0)) { + fputs(term_banner, stdout); + fputs("\nThis program is in the public domain.\n\ +Primary author of dmp: John Hobby.\n\ +Current maintainer: Taco Hoekwater.\n", stdout); + exit(0); } - if (argc>3) usage(argv[0], 1); - if (argc>1) { + if (argc > 3) + usage(argv[0], 1); + if (argc > 1) { trf = fopen(argv[1], "r"); - if (trf==(FILE*)0) { - fprintf (stderr, "%s: ", argv[0]); - perror (argv[1]); - exit(1); + if (trf == (FILE *) 0) { + fprintf(stderr, "%s: ", argv[0]); + perror(argv[1]); + exit(1); } - if (argc>2) { + if (argc > 2) { mpxf = fopen(argv[2], "w"); - if (mpxf==(FILE*)0) { - fprintf (stderr, "%s: ", argv[0]); - perror (argv[2]); - exit(1); + if (mpxf == (FILE *) 0) { + fprintf(stderr, "%s: ", argv[0]); + perror(argv[2]); + exit(1); } } } @@ -1382,17 +1545,17 @@ Primary author of dmp: John Hobby.\n", stdout); read_desc(); read_fmap(dbname); if (!gflag) - read_char_adj(adjname); + read_char_adj(adjname); if (do_page()) { do { - h=0; v=0; + h = 0; + v = 0; Xslant = Xheight = 0.0; start_picture(); more = do_page(); stop_picture(); - fprintf(mpxf,"mpxbreak\n"); + fprintf(mpxf, "mpxbreak\n"); } while (more); } exit(0); } - diff --git a/Build/source/texk/web2c/mpware/dmp.h b/Build/source/texk/web2c/mpware/dmp.h index 33873188205..4cb6b874249 100644 --- a/Build/source/texk/web2c/mpware/dmp.h +++ b/Build/source/texk/web2c/mpware/dmp.h @@ -10,10 +10,9 @@ #define TRFONTS_TYPE 4 extern FILE *fsearch(char *nam, char *ext, int path_type); -extern void fsearch_init(void); -extern void pathexpand(char *buf, int dirlen, int bufsize); +extern void fsearch_init(int argc, char **argv); -#define POOLMAX 65000 /* total characters in all font and char names */ +#define POOLMAX 65000 /* total characters in all font and char names */ extern int poolsize; /* chars used so far in strpool */ extern char strpool[]; /* chars used so far in strpool */ diff --git a/Build/source/texk/web2c/mpware/dmp_ffile.c b/Build/source/texk/web2c/mpware/dmp_ffile.c index 3a7f475f8f7..cc1eb8c8491 100644 --- a/Build/source/texk/web2c/mpware/dmp_ffile.c +++ b/Build/source/texk/web2c/mpware/dmp_ffile.c @@ -1,11 +1,65 @@ /* $Id: dmp_ffile.c,v 1.4 2005/08/24 10:54:02 taco Exp $ - Public domain. */ + * + * File searching for dmp. This is a unified source file implementing two + * different strategies: kpathsea lookups vs. recursive searching. + * + * There is a #define to switch between the two personalities, with + * kpathsea the default option + * + * Public domain. + */ #include <stdlib.h> #include <stdio.h> #include "dmp.h" +#ifndef FFSEARCH + +#include "config.h" +#include <kpathsea/tex-file.h> +#include <kpathsea/c-ctype.h> +#include <kpathsea/c-pathch.h> + +static int + kpse_types[5] = { 0, + kpse_tfm_format, /* tex fonts */ + kpse_mpsupport_format, /* mapfile */ + kpse_mpsupport_format, /* charlib */ + kpse_troff_font_format +}; + + +void +fsearch_init(int argc, char **argv) +{ + kpse_set_progname(argv[0]); +} + +FILE * +fsearch(char *nam, char *ext, int path_type) +{ + { + FILE *f = NULL; + int format; + format = kpse_types[path_type]; + string fname = kpse_find_file(nam, format, true); + const_string mode = kpse_format_info[format].binmode + ? FOPEN_RBIN_MODE : FOPEN_R_MODE; + if (fname) { + f = xfopen(fname, mode); + } + if (f == NULL) + quit("Cannot find ", nam, ext); + return f; + } + +} + +#else + +void pathexpand(char *buf, int dirlen, int bufsize); + /* Where dmp looks for tex font metric files */ #define TEXFONTS ".:/usr/lib/tex/fonts/tfm" @@ -35,60 +89,68 @@ char *trpath = TRFONTS; /* search path for troff font data */ #endif #endif -void fsearch_init(void) +void +fsearch_init(int argc, char **argv) { - char *envpath; - - if ((envpath = getenv("TEXFONTS")) != NULL) - tfmpath = envpath; - if ((envpath = getenv("MPPOOL")) != NULL) { - dbpath = envpath; - charpath = envpath; - } - if ((envpath = getenv("TRFONTS")) != NULL) - trpath = envpath; + char *envpath; + + if ((envpath = getenv("TEXFONTS")) != NULL) + tfmpath = envpath; + if ((envpath = getenv("MPPOOL")) != NULL) { + dbpath = envpath; + charpath = envpath; + } + if ((envpath = getenv("TRFONTS")) != NULL) + trpath = envpath; } -FILE *fsearch(char *nam, char *ext, int path_type) +FILE * +fsearch(char *nam, char *ext, int path_type) { FILE *f; char *s, *p; int dirlen; - char *path; - if (path_type == TEXFONTS_TYPE) { - path = tfmpath; - } else if (path_type == DB_TYPE) { - path = dbpath; - } else if (path_type == CHARLIB_TYPE) { - path = charpath; - /* somewhat sneaky trick to unify 'fsearch' API with - the smallest possible code impact */ - ext = nam; - nam = "charlib/"; - } else if (path_type == TRFONTS_TYPE) { - path = trpath; - } - - if (nam[0]=='/') /* file name has absolute path */ + char *path; + if (path_type == TEXFONTS_TYPE) { + path = tfmpath; + } else if (path_type == DB_TYPE) { + path = dbpath; + } else if (path_type == CHARLIB_TYPE) { + path = charpath; + /* somewhat sneaky trick to unify 'fsearch' API with + the smallest possible code impact */ + ext = nam; + nam = "charlib/"; + } else if (path_type == TRFONTS_TYPE) { + path = trpath; + } + + if (nam[0] == '/') /* file name has absolute path */ path = NULL; do { s = &strpool[poolsize]; - if (path!=NULL) { - while ((*path!=PATH_DELIM) && (*path!='\0')) + if (path != NULL) { + while ((*path != PATH_DELIM) && (*path != '\0')) add_to_pool(*path++); - if (*path=='\0') path=NULL; else path++; + if (*path == '\0') + path = NULL; + else + path++; add_to_pool('/'); } dirlen = &strpool[poolsize] - s; - for (p=nam; *p!='\0'; p++) add_to_pool(*p); - for (p=ext; *p!='\0'; p++) add_to_pool(*p); + for (p = nam; *p != '\0'; p++) + add_to_pool(*p); + for (p = ext; *p != '\0'; p++) + add_to_pool(*p); add_to_pool('\0'); - pathexpand(s, dirlen, &strpool[POOLMAX]-s); + pathexpand(s, dirlen, &strpool[POOLMAX] - s); f = fopen(s, "r"); poolsize = s - &strpool[0]; - } while (f==NULL && path!=NULL); - if (f==NULL) quit("Cannot find ",nam,ext); + } while (f == NULL && path != NULL); + if (f == NULL) + quit("Cannot find ", nam, ext); return f; } @@ -102,15 +164,15 @@ FILE *fsearch(char *nam, char *ext, int path_type) #ifdef BSD #include <sys/types.h> #include <sys/dir.h> -#define DIRentry struct direct /* readdir() returns pointer to this */ -#define de_name d_name /* field in DIRentry for file name */ +#define DIRentry struct direct /* readdir() returns pointer to this */ +#define de_name d_name /* field in DIRentry for file name */ #else /* This is for SYSV and _POSIX_SOURCE; I don't know about other systems */ #include <dirent.h> -#define DIRentry struct dirent /* readdir() returns pointer to this */ -#define de_name d_name /* field in DIRentry for file name */ +#define DIRentry struct dirent /* readdir() returns pointer to this */ +#define de_name d_name /* field in DIRentry for file name */ #endif @@ -130,78 +192,83 @@ extern int access(); /* The PEDEBUG flag is meant for seperate debugging of this file. Do not set it when compiling MetaPost. */ -int myaccess(nam, mode) +int +myaccess(nam, mode) { - int r; - r = access(nam, mode); - printf("can%s access %s\n", (r==0 ? "" : "not"), nam); - return r; + int r; + r = access(nam, mode); + printf("can%s access %s\n", (r == 0 ? "" : "not"), nam); + return r; } #else #define myaccess access #endif -void move_str(dest, src) /* strcpy() for overlapping strings */ - char *dest, *src; +void +move_str(dest, src) /* strcpy() for overlapping strings */ +char *dest, *src; { - char *s, *d; - int n; - - if (dest < src) { - while (*src != '\0') - *dest++ = *src++; - *dest = '\0'; - } else { - n = strlen(src); - d = dest + n; - s = src + n; - *d = '\0'; - while (s != src) - *--d = *--s; - } + char *s, *d; + int n; + + if (dest < src) { + while (*src != '\0') + *dest++ = *src++; + *dest = '\0'; + } else { + n = strlen(src); + d = dest + n; + s = src + n; + *d = '\0'; + while (s != src) + *--d = *--s; + } } /* Find the first "//" within the first dirlen characters of buf[], or return * zero to indicate failure. */ -char* find_dblslash(buf, dirlen) - char* buf; - int dirlen; +char * +find_dblslash(buf, dirlen) +char *buf; +int dirlen; { - char* p; - int k; - - k = 0; - dirlen--; - while ((p = strchr(buf+k, '/')) != 0) { - if (p-buf >= dirlen) - return 0; - if (p[1]=='/') - return p; - k = 1 + p-buf; - } - return 0; + char *p; + int k; + + k = 0; + dirlen--; + while ((p = strchr(buf + k, '/')) != 0) { + if (p - buf >= dirlen) + return 0; + if (p[1] == '/') + return p; + k = 1 + p - buf; + } + return 0; } /* Pretend the string ends at endp and call opendir(). */ -DIR* pe_opendir(buf, endp) - char *buf, *endp; +DIR * +pe_opendir(buf, endp) +char *buf, *endp; { - DIR* dirp; - char s; + DIR *dirp; + char s; - s = *endp; - *endp = '\0'; - dirp = opendir(buf); + s = *endp; + *endp = '\0'; + dirp = opendir(buf); #ifdef PEDEBUG - printf("%s directory %s\n", (dirp==0 ? "cannot open" : "opening"), buf); + printf("%s directory %s\n", (dirp == 0 ? "cannot open" : "opening"), + buf); #endif - *endp = s; - return dirp; + *endp = s; + return dirp; } @@ -215,51 +282,52 @@ DIR* pe_opendir(buf, endp) * The algorithm is depth-first search with pruning based on the idea that * directories contain files or subdirectories, but not both. */ -int expand_dblslash(buf, slash, tail, lim, tailp) - char *buf, *slash, *lim; - int tail; - char** tailp; +int +expand_dblslash(buf, slash, tail, lim, tailp) +char *buf, *slash, *lim; +int tail; +char **tailp; { - DIR* dirp; - DIRentry* de; - char *t, *tt; /* old and new positions of tail string */ - char *ds; - int r; - - t = slash + 1; - *tailp = t; - dirp = pe_opendir(buf, slash); - if (dirp==0) - return -2; - if (myaccess(buf, 04) == 0) { - closedir(dirp); - return (slash-buf) + 1 + tail; + DIR *dirp; + DIRentry *de; + char *t, *tt; /* old and new positions of tail string */ + char *ds; + int r; + + t = slash + 1; + *tailp = t; + dirp = pe_opendir(buf, slash); + if (dirp == 0) + return -2; + if (myaccess(buf, 04) == 0) { + closedir(dirp); + return (slash - buf) + 1 + tail; + } + while ((de = readdir(dirp)) != 0) { + ds = de->de_name; + if (ds[0] == '.' && (ds[1] == 0 || ds[1] == '.' && ds[2] == 0)) + continue; + tt = slash + 2 + strlen(ds); + if (tt > lim) { + *slash = '\0'; + fprintf(stderr, "> %s/%s/%s\n", buf, de->de_name, t); + fprintf(stderr, "! Fatal error: %s\n", + "// expansion makes path name too long"); + exit(1); } - while ((de = readdir(dirp)) != 0) { - ds = de->de_name; - if (ds[0]=='.' && (ds[1]==0 || ds[1]=='.' && ds[2]==0)) - continue; - tt = slash + 2 + strlen(ds); - if (tt > lim) { - *slash = '\0'; - fprintf(stderr,"> %s/%s/%s\n", buf, de->de_name, t); - fprintf(stderr,"! Fatal error: %s\n", - "// expansion makes path name too long"); - exit(1); - } - move_str(tt, t); - strcpy(slash+1, ds); - tt[-1] = '/'; - r = expand_dblslash(buf, tt-1, tail, lim, &t); - if (r != -1) { - *tailp = t; - closedir(dirp); - return (r<0) ? -1 : r; - } + move_str(tt, t); + strcpy(slash + 1, ds); + tt[-1] = '/'; + r = expand_dblslash(buf, tt - 1, tail, lim, &t); + if (r != -1) { + *tailp = t; + closedir(dirp); + return (r < 0) ? -1 : r; } - closedir(dirp); - *tailp = t; - return -1; + } + closedir(dirp); + *tailp = t; + return -1; } @@ -270,17 +338,20 @@ int expand_dblslash(buf, slash, tail, lim, tailp) * intermediate directories. If the expansion fails, buf will contain an * invalid path name. */ -void pathexpand(buf, dirlen, bufsize) - char* buf; /* input path */ - int dirlen; /* limit search to buf[0]..buf[dirlen-1] */ - int bufsize; /* number of character in buf array */ +void +pathexpand(buf, dirlen, bufsize) +char *buf; /* input path */ +int dirlen; /* limit search to buf[0]..buf[dirlen-1] */ +int bufsize; /* number of character in buf array */ { - char *p; - int tail, junk; - - if ((p = find_dblslash(buf, dirlen)) != 0) { - tail = strlen(p+1); - move_str(p, p+1); - expand_dblslash(buf, p, tail, buf+bufsize-tail-1, &junk); - } + char *p; + int tail, junk; + + if ((p = find_dblslash(buf, dirlen)) != 0) { + tail = strlen(p + 1); + move_str(p, p + 1); + expand_dblslash(buf, p, tail, buf + bufsize - tail - 1, &junk); + } } + +#endif /* FFSEARCH */ diff --git a/Build/source/texk/web2c/mpware/makempx.in b/Build/source/texk/web2c/mpware/makempx.in index 0f1c660ca40..45cd678ec64 100644 --- a/Build/source/texk/web2c/mpware/makempx.in +++ b/Build/source/texk/web2c/mpware/makempx.in @@ -6,7 +6,7 @@ # Public domain. # # -version=0.99 +version=0.992 : ${DMP=dmp} : ${DVITOMP=dvitomp} @@ -61,7 +61,8 @@ while test $# -gt 0; do -version|--version) echo "`basename $0` $version" echo "There is NO warranty. This script is public domain. -Primary author: John Hobby." +Primary author: John Hobby. +Current maintainer: Taco Hoekwater." exit 0;; -troff|--troff) mode=troff;; -tex|--tex) mode=tex;; diff --git a/Build/source/texk/web2c/mpware/mpto.c b/Build/source/texk/web2c/mpware/mpto.c index 99678221e4b..27d687493bd 100644 --- a/Build/source/texk/web2c/mpware/mpto.c +++ b/Build/source/texk/web2c/mpware/mpto.c @@ -34,115 +34,163 @@ use smaller values than that */ #define bufsize 1000 -char* tex_predoc = ""; -char* tex_postdoc = "\\end{document}\n"; -char* tex_pretex1 = "\\gdef\\mpxshipout{\\shipout\\hbox\\bgroup%\n" - " \\setbox0=\\hbox\\bgroup}%\n" - "\\gdef\\stopmpxshipout{\\egroup" - " \\dimen0=\\ht0 \\advance\\dimen0\\dp0\n" - " \\dimen1=\\ht0 \\dimen2=\\dp0\n" - " \\setbox0=\\hbox\\bgroup\n" - " \\box0\n" - " \\ifnum\\dimen0>0 \\vrule width1sp height\\dimen1 depth\\dimen2 \n" - " \\else \\vrule width1sp height1sp depth0sp\\relax\n" - " \\fi\\egroup\n" - " \\ht0=0pt \\dp0=0pt \\box0 \\egroup}\n" - "\\mpxshipout%% line %d %s\n"; -char* tex_pretex = "\\mpxshipout%% line %d %s\n"; -char* tex_posttex = "\\stopmpxshipout\n"; -char* tex_preverb1 = ""; /* if very first instance */ -char* tex_preverb = "%% line %d %s\n"; /* all other instances */ -char* tex_postverb = "%\n"; +char *tex_predoc = ""; +char *tex_postdoc = "\\end{document}\n"; +char *tex_pretex1 = "\\gdef\\mpxshipout{\\shipout\\hbox\\bgroup%\n" + " \\setbox0=\\hbox\\bgroup}%\n" + "\\gdef\\stopmpxshipout{\\egroup" + " \\dimen0=\\ht0 \\advance\\dimen0\\dp0\n" + " \\dimen1=\\ht0 \\dimen2=\\dp0\n" + " \\setbox0=\\hbox\\bgroup\n" + " \\box0\n" + " \\ifnum\\dimen0>0 \\vrule width1sp height\\dimen1 depth\\dimen2 \n" + " \\else \\vrule width1sp height1sp depth0sp\\relax\n" + " \\fi\\egroup\n" + " \\ht0=0pt \\dp0=0pt \\box0 \\egroup}\n" + "\\mpxshipout%% line %d %s\n"; +char *tex_pretex = "\\mpxshipout%% line %d %s\n"; +char *tex_posttex = "\\stopmpxshipout\n"; +char *tex_preverb1 = ""; /* if very first instance */ +char *tex_preverb = "%% line %d %s\n"; /* all other instances */ +char *tex_postverb = "%\n"; /* According to CSTR #54 the ".lf" directive should be ".lf %d %s", * not ".lf line %d %s" as used in the original code. This affects * troff_pretex1, troff_pretex, troff_preverb1, troff_preverb. */ -char* troff_predoc = ".po 0\n"; -char* troff_postdoc = ""; -char* troff_pretex1 = ".lf %d %s\n"; /* first instance */ -char* troff_pretex = ".bp\n.lf %d %s\n"; /* subsequent instances */ -char* troff_posttex = "\n"; -char* troff_preverb1 = ".lf %d %s\n"; -char* troff_preverb = ".lf %d %s\n"; -char* troff_postverb = "\n"; +char *troff_predoc = ".po 0\n"; +char *troff_postdoc = ""; +char *troff_pretex1 = ".lf %d %s\n"; /* first instance */ +char *troff_pretex = ".bp\n.lf %d %s\n"; /* subsequent instances */ +char *troff_posttex = "\n"; +char *troff_preverb1 = ".lf %d %s\n"; +char *troff_preverb = ".lf %d %s\n"; +char *troff_postverb = "\n"; -char* predoc; -char* postdoc; -char* pretex1; -char* pretex; -char* posttex; -char* preverb1; -char* preverb; -char* postverb; +char *predoc; +char *postdoc; +char *pretex1; +char *pretex; +char *posttex; +char *preverb1; +char *preverb; +char *postverb; char *mpname; FILE *mpfile; -int lnno = 0; /* current line number */ -int texcnt = 0; /* btex..etex blocks so far */ -int verbcnt = 0; /* verbatimtex..etex blocks so far */ -char *bb, *tt, *aa; /* start of before, token, and after strings */ -char buf[bufsize]; /* the input line */ +int lnno = 0; /* current line number */ +int texcnt = 0; /* btex..etex blocks so far */ +int verbcnt = 0; /* verbatimtex..etex blocks so far */ +char *bb, *tt, *aa; /* start of before, token, and after strings */ +char buf[bufsize]; /* the input line */ -void -err (char * msg) +void +err(char *msg) { - fprintf(stderr, "mpto: %s:%d: %s\n",mpname, lnno, msg); - exit(1); + fprintf(stderr, "mpto: %s:%d: %s\n", mpname, lnno, msg); + exit(1); } void -usage (char *progn) +usage(char *progn) { - fprintf(stderr, "Try `%s --help' for more information\n", progn); - exit(1); + fprintf(stderr, "Try `%s --help' for more information\n", progn); + exit(1); } char * -getline(void) /* returns NULL on EOF or error, otherwise buf */ -{ - int c; - unsigned loc = 0; - while ((c = getc (mpfile)) != EOF && c != '\n' && c != '\r') { - buf[loc++] = c; - if (loc == bufsize) - err("Line is too long"); - } - if (c == EOF) return NULL; - buf[loc] = 0; - if (c == '\r') { - c = getc(mpfile); - if (c != '\n') ungetc(c, mpfile); - } - lnno++; - return buf; +getline(void) +{ /* returns NULL on EOF or error, otherwise buf */ + int c; + unsigned loc = 0; + while ((c = getc(mpfile)) != EOF && c != '\n' && c != '\r') { + buf[loc++] = c; + if (loc == bufsize) + err("Line is too long"); + } + if (c == EOF) + return NULL; + buf[loc] = 0; + if (c == '\r') { + c = getc(mpfile); + if (c != '\n') + ungetc(c, mpfile); + } + lnno++; + return buf; } /* Return nonzero if a prefix of string s matches the null-terminated string t * and the next character is not a letter of an underscore. */ -int -match_str (char *s, char *t) +int +match_str(char *s, char *t) { - while (*t!=0) { - if (*s!=*t) return 0; - s++; t++; - } - switch (*s) { - case 'a': case 'c': case 'd': case 'f': case 'g': case 'h': - case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': - case 'o': case 'p': case 'q': case 'r': case 's': case 't': - case 'u': case 'w': case 'x': case 'y': case 'z': case '_': - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': - case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': case 'b': case 'e': case 'v': - return 0; - default: - return 1; - } + while (*t != 0) { + if (*s != *t) + return 0; + s++; + t++; + } + switch (*s) { + case 'a': + case 'c': + case 'd': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'w': + case 'x': + case 'y': + case 'z': + case '_': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case 'b': + case 'e': + case 'v': + return 0; + default: + return 1; + } } @@ -155,211 +203,270 @@ match_str (char *s, char *t) * no such t, we set b=s and return 0. */ int -getbta (char *s) +getbta(char *s) { - int ok=1; /* zero if last character was a-z, A-Z, or _ */ + int ok = 1; /* zero if last character was a-z, A-Z, or _ */ - bb = s; - for (tt=bb; *tt!=0; tt++) - switch (*tt) { - case '"': case '%': - aa = tt+1; - return 1; - case 'b': - if (ok && match_str(tt,"btex")) { - aa = tt+4; - return 1; - } else ok=0; - break; - case 'e': - if (ok && match_str(tt,"etex")) { - aa = tt+4; - return 1; - } else ok=0; - break; - case 'v': - if (ok && match_str(tt,"verbatimtex")) { - aa = tt+11; - return 1; - } else ok=0; - break; - case 'a': case 'c': case 'd': case 'f': case 'g': case 'h': - case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': - case 'o': case 'p': case 'q': case 'r': case 's': case 't': - case 'u': case 'w': case 'x': case 'y': case 'z': case '_': - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': - case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': - case 'Y': case 'Z': - ok = 0; - break; - default: - ok = 1; - } - aa = tt; - return 0; + bb = s; + for (tt = bb; *tt != 0; tt++) + switch (*tt) { + case '"': + case '%': + aa = tt + 1; + return 1; + case 'b': + if (ok && match_str(tt, "btex")) { + aa = tt + 4; + return 1; + } else + ok = 0; + break; + case 'e': + if (ok && match_str(tt, "etex")) { + aa = tt + 4; + return 1; + } else + ok = 0; + break; + case 'v': + if (ok && match_str(tt, "verbatimtex")) { + aa = tt + 11; + return 1; + } else + ok = 0; + break; + case 'a': + case 'c': + case 'd': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'w': + case 'x': + case 'y': + case 'z': + case '_': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + ok = 0; + break; + default: + ok = 1; + } + aa = tt; + return 0; } void copytex(void) { - char *s; /* where a string to print stops */ - char c; + char *s; /* where a string to print stops */ + char c; - while (*aa==' ' || *aa=='\t') aa++; - if (*aa==0) - if ((aa=getline())==NULL) - err("btex section does not end"); - do { if (*aa==0) - if ((aa=getline())==NULL) - err("btex section does not end"); - else printf("\n"); - if (getbta(aa) && *tt=='e') { - s = tt-1; - while (s>=bb && (*s==' ' || *s=='\t')) - s--; - s++; - } else { - if (*tt=='b') err("btex in TeX mode"); - if (*tt=='v') err("verbatimtex in TeX mode"); - s = aa; - } - c = *s; - *s = 0; - printf("%s", bb); - *s = c; - } while (*tt!='e'); + while (*aa == ' ' || *aa == '\t') + aa++; + if (*aa == 0) + if ((aa = getline()) == NULL) + err("btex section does not end"); + do { + if (*aa == 0) + if ((aa = getline()) == NULL) + err("btex section does not end"); + else + printf("\n"); + if (getbta(aa) && *tt == 'e') { + s = tt - 1; + while (s >= bb && (*s == ' ' || *s == '\t')) + s--; + s++; + } else { + if (*tt == 'b') + err("btex in TeX mode"); + if (*tt == 'v') + err("verbatimtex in TeX mode"); + s = aa; + } + c = *s; + *s = 0; + printf("%s", bb); + *s = c; + } while (*tt != 'e'); } void do_line(void) { - aa = buf; - while (getbta(aa)) - if (*tt=='%') break; - else if (*tt=='"') { - do if (!getbta(aa)) err("string does not end"); - while (*tt!='"'); - } else if (*tt=='b') { - if (texcnt++ ==0) printf(pretex1,lnno,mpname); - else printf(pretex,lnno,mpname); - copytex(); - printf("%s",posttex); - } else if (*tt=='v') { - if (verbcnt++ ==0 && texcnt==0) - printf(preverb1,lnno,mpname); - else printf(preverb,lnno,mpname); - copytex(); - printf("%s",postverb); - } else err("unmatched etex"); + aa = buf; + while (getbta(aa)) + if (*tt == '%') + break; + else if (*tt == '"') { + do + if (!getbta(aa)) + err("string does not end"); + while (*tt != '"'); + } else if (*tt == 'b') { + if (texcnt++ == 0) + printf(pretex1, lnno, mpname); + else + printf(pretex, lnno, mpname); + copytex(); + printf("%s", posttex); + } else if (*tt == 'v') { + if (verbcnt++ == 0 && texcnt == 0) + printf(preverb1, lnno, mpname); + else + printf(preverb, lnno, mpname); + copytex(); + printf("%s", postverb); + } else + err("unmatched etex"); } - + int main(int argc, char **argv) { - int mode; + int mode; if (argc == 1) { - fputs ("mpto: Need exactly one file argument.\n", stderr); - fputs ("Try `mpto --help' for more information.\n", stderr); - exit(1); - } else if (argc > 1 && (strcmp (argv[1], "--help") == 0 - || strcmp (argv[1], "-help") == 0)) { - fputs ("Usage: mpto [-tex|-troff] MPFILE",stdout); + fputs("mpto: Need exactly one file argument.\n", stderr); + fputs("Try `mpto --help' for more information.\n", stderr); + exit(1); + } else if (argc > 1 && (strcmp(argv[1], "--help") == 0 + || strcmp(argv[1], "-help") == 0)) { + fputs("Usage: mpto [-tex|-troff] MPFILE", stdout); #ifdef AMIGA - fputs (" [-E<errlog-file>]",stdout); + fputs(" [-E<errlog-file>]", stdout); #endif - fputs ("\n Strip btex..etex and verbatimtex...etex parts from MetaPost input\n\ + fputs("\n Strip btex..etex and verbatimtex...etex parts from MetaPost input\n\ file MPFILE, converting to either TeX or troff (TeX by default).\n\ \n\ --help display this help and exit\n\ ---version output version information and exit\n",stdout); - fputs ("\nEmail bug reports to metapost@tug.org.\n", stdout); - exit (0); - } else if (argc > 1 && (strcmp (argv[1], "--version") == 0 - || strcmp (argv[1], "-version") == 0)) { - printf ("mpto 0.99\n\ +--version output version information and exit\n", + stdout); + fputs("\nEmail bug reports to metapost@tug.org.\n", stdout); + exit(0); + } else if (argc > 1 && (strcmp(argv[1], "--version") == 0 + || strcmp(argv[1], "-version") == 0)) { + printf("mpto 0.992\n\ This program is in the public domain.\n\ -Primary author of mpto: John Hobby.\n"); - exit (0); +Primary author of mpto: John Hobby.\n\ +Current maintainer: Taco Hoekwater.\n"); + exit(0); } else if (argc == 2) { - mpname = argv[1]; - mode = 0; + mpname = argv[1]; + mode = 0; #ifdef AMIGA } else if (argc == 3) { - if (strcmp (argv[1], "-tex") == 0) { + if (strcmp(argv[1], "-tex") == 0) { mpname = argv[2]; mode = 0; - } else if (strcmp (argv[1], "-troff") == 0) { + } else if (strcmp(argv[1], "-troff") == 0) { mpname = argv[2]; mode = 1; - } else if (strncmp(argv[2], "-E", 2) || (argv[2]+2 == NULL)) { + } else if (strncmp(argv[2], "-E", 2) || (argv[2] + 2 == NULL)) { usage(argv[0]); - } else { + } else { mpname = argv[1]; - freopen(argv[2]+2, "w", stderr); - } + freopen(argv[2] + 2, "w", stderr); + } } else if (argc == 4) { - if (strcmp (argv[1], "-tex") == 0) { + if (strcmp(argv[1], "-tex") == 0) { mode = 0; - } else if (strcmp (argv[1], "-troff") == 0) { + } else if (strcmp(argv[1], "-troff") == 0) { mode = 1; - } else { + } else { usage(argv[0]); - } - if (strncmp(argv[3], "-E", 2) || (argv[3]+2 == NULL)) { + } + if (strncmp(argv[3], "-E", 2) || (argv[3] + 2 == NULL)) { usage(argv[0]); - } else { + } else { mpname = argv[2]; - freopen(argv[3]+2, "w", stderr); - } -#else /* not AMIGA */ + freopen(argv[3] + 2, "w", stderr); + } +#else /* not AMIGA */ } else if (argc == 3) { - if (strcmp (argv[1], "-tex") == 0) { - mode = 0; - } else if (strcmp (argv[1], "-troff") == 0) { - mode = 1; - } else { - usage (argv[0]); - } - mpname = argv[2]; -#endif /* not AMIGA */ + if (strcmp(argv[1], "-tex") == 0) { + mode = 0; + } else if (strcmp(argv[1], "-troff") == 0) { + mode = 1; + } else { + usage(argv[0]); + } + mpname = argv[2]; +#endif /* not AMIGA */ } else { - usage(argv[0]); + usage(argv[0]); } mpfile = fopen(mpname, "r"); - if (mpfile==NULL) { - fprintf (stderr, "%s: ", argv[0]); - perror (mpname); - exit (1); + if (mpfile == NULL) { + fprintf(stderr, "%s: ", argv[0]); + perror(mpname); + exit(1); } /* This is far from elegant, but life is short. */ if (mode == 0) { - predoc = tex_predoc; - postdoc = tex_postdoc; - pretex1 = tex_pretex1; - pretex = tex_pretex; - posttex = tex_posttex; - preverb1 = tex_preverb1; - preverb = tex_preverb; - postverb = tex_postverb; + predoc = tex_predoc; + postdoc = tex_postdoc; + pretex1 = tex_pretex1; + pretex = tex_pretex; + posttex = tex_posttex; + preverb1 = tex_preverb1; + preverb = tex_preverb; + postverb = tex_postverb; } else { - predoc = troff_predoc; - postdoc = troff_postdoc; - pretex1 = troff_pretex1; - pretex = troff_pretex; - posttex = troff_posttex; - preverb1 = troff_preverb1; - preverb = troff_preverb; - postverb = troff_postverb; + predoc = troff_predoc; + postdoc = troff_postdoc; + pretex1 = troff_pretex1; + pretex = troff_pretex; + posttex = troff_posttex; + preverb1 = troff_preverb1; + preverb = troff_preverb; + postverb = troff_postverb; } - printf("%s",predoc); - while (getline()!=NULL) - do_line(); - printf("%s",postdoc); + printf("%s", predoc); + while (getline() != NULL) + do_line(); + printf("%s", postdoc); exit(0); } diff --git a/Build/source/texk/web2c/mpware/newer.c b/Build/source/texk/web2c/mpware/newer.c index 55e9fb4958a..a19d646b9f9 100644 --- a/Build/source/texk/web2c/mpware/newer.c +++ b/Build/source/texk/web2c/mpware/newer.c @@ -9,7 +9,7 @@ */ #ifdef HAVE_CONFIG_H -#include "c-auto.h" /* In case we need, e.g., _POSIX_SOURCE */ +#include "c-auto.h" /* In case we need, e.g., _POSIX_SOURCE */ #include "config.h" #endif #include <stdio.h> @@ -53,26 +53,26 @@ main(int argc, char **argv) struct stat source_stat, target_stat; while ((argc > 1) && (argv[1][0] == '-')) { - if (strcmp(argv[1], "-v") == 0 || - strcmp(argv[1], "-verbose") == 0 || - strcmp(argv[1], "--verbose") == 0) { + if (strcmp(argv[1], "-v") == 0 || + strcmp(argv[1], "-verbose") == 0 || + strcmp(argv[1], "--verbose") == 0) { - verbose = 1; - argv++; - argc--; + verbose = 1; + argv++; + argc--; - } else if (strcmp(argv[1], "-q") == 0 || - strcmp(argv[1], "-quiet") == 0 || - strcmp(argv[1], "--quiet") == 0) { + } else if (strcmp(argv[1], "-q") == 0 || + strcmp(argv[1], "-quiet") == 0 || + strcmp(argv[1], "--quiet") == 0) { - quiet = 1; - argv++; - argc--; + quiet = 1; + argv++; + argc--; - } else if (strcmp(argv[1], "-help") == 0 || - strcmp(argv[1], "--help") == 0) { + } else if (strcmp(argv[1], "-help") == 0 || + strcmp(argv[1], "--help") == 0) { - fputs("Usage: newer [OPTION] src1 [ src2 ... srcN ] target\n\ + fputs("Usage: newer [OPTION] src1 [ src2 ... srcN ] target\n\ Exit successfully if `src1' ... `srcN' exist and at least\n\ one of them is not older than `target'.\n\ Also exit successfully if `target' doesn't exist.\n\ @@ -81,55 +81,56 @@ main(int argc, char **argv) --quiet Do not print anything\n\ --verbose List missing files, including missing target files\n\ --version Output version information and exit\n\n", stdout); - fputs ("Email bug reports to metapost@tug.org.\n", stdout); - exit(0); + fputs("Email bug reports to metapost@tug.org.\n", stdout); + exit(0); - } else if (strcmp(argv[1], "-version") == 0 || - strcmp(argv[1], "--version") == 0) { + } else if (strcmp(argv[1], "-version") == 0 || + strcmp(argv[1], "--version") == 0) { - fputs("newer 0.99\n\ + fputs("newer 0.992\n\ This program is in the public domain.\n\ -Primary author of newer: John Hobby.\n", stdout); - exit(0); +Primary author of newer: John Hobby.\n\ +Current maintainer: Taco Hoekwater.\n", stdout); + exit(0); - } else { + } else { - fprintf(stderr, "newer: Unknown option \"%s\"\n", argv[1]); - fputs("Try `newer --help' for more information.\n", stderr); - exit(1); + fprintf(stderr, "newer: Unknown option \"%s\"\n", argv[1]); + fputs("Try `newer --help' for more information.\n", stderr); + exit(1); - } + } } - + /* do we have at least two arguments? */ if (argc < 3) { - fputs ("newer: Too few arguments.\n\ + fputs("newer: Too few arguments.\n\ Try `newer --help' for more information.\n", stderr); - exit(1); + exit(1); } - + /* check the target file */ - if (stat(argv[argc-1], &target_stat) < 0) { - if (verbose && !quiet) { - fprintf(stderr, "newer: target file `%s' doesn't exist.\n", - argv[argc-1]); - } - missing_target = 1; + if (stat(argv[argc - 1], &target_stat) < 0) { + if (verbose && !quiet) { + fprintf(stderr, "newer: target file `%s' doesn't exist.\n", + argv[argc - 1]); + } + missing_target = 1; } - + /* check the source files */ - for (i = 1; i < (argc-1); i++) { - if (stat(argv[i], &source_stat) < 0) { + for (i = 1; i < (argc - 1); i++) { + if (stat(argv[i], &source_stat) < 0) { if (!quiet) { - fprintf (stderr, "newer: source file `%s' doesn't exist.\n", - argv[i]); - } + fprintf(stderr, "newer: source file `%s' doesn't exist.\n", + argv[i]); + } missing_source = 1; - } else if (!missing_target) { - if (NEWER(source_stat, target_stat)) { - result = exit_true; - } - } + } else if (!missing_target) { + if (NEWER(source_stat, target_stat)) { + result = exit_true; + } + } } /* Adjust result for cases when source or target is missing: @@ -137,9 +138,9 @@ Try `newer --help' for more information.\n", stderr); * missing target => exit_true */ if (missing_source) { - result = exit_false; + result = exit_false; } else if (missing_target) { - result = exit_true; + result = exit_true; } return result; |