summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/mplibdir/mpxout.w
diff options
context:
space:
mode:
authorTaco Hoekwater <taco@elvenkind.com>2010-04-01 09:45:59 +0000
committerTaco Hoekwater <taco@elvenkind.com>2010-04-01 09:45:59 +0000
commita70bac8e552ba0a1dd94fde08771e9f63388e632 (patch)
treef14f4f2cd4b0fcc30171ac0adde983b1a1c5249d /Build/source/texk/web2c/mplibdir/mpxout.w
parent794fada92e1b6f6b42e9a379fe6f1024af92c6d0 (diff)
the sources for metapost 1.211
git-svn-id: svn://tug.org/texlive/trunk@17649 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/mplibdir/mpxout.w')
-rw-r--r--Build/source/texk/web2c/mplibdir/mpxout.w199
1 files changed, 109 insertions, 90 deletions
diff --git a/Build/source/texk/web2c/mplibdir/mpxout.w b/Build/source/texk/web2c/mplibdir/mpxout.w
index 616ba9ae90c..6f7859b98ad 100644
--- a/Build/source/texk/web2c/mplibdir/mpxout.w
+++ b/Build/source/texk/web2c/mplibdir/mpxout.w
@@ -1,4 +1,4 @@
-% $Id: mpxout.w 1061 2009-05-27 13:01:37Z taco $
+% $Id: mpxout.w 1219 2010-04-01 09:05:51Z taco $
%
% Copyright 2008-2009 Taco Hoekwater.
%
@@ -260,6 +260,8 @@ static void mpx_abort(MPX mpx, const char *msg, ...) {
va_start(ap, msg);
fprintf(stderr, "fatal: ");
(void)vfprintf(stderr, msg, ap);
+ va_end(ap);
+ va_start(ap, msg);
mpx_printf(mpx, "fatal", msg, ap);
va_end(ap);
mpx->history=mpx_fatal_error;
@@ -400,7 +402,7 @@ static char *mpx_getline(MPX mpx, FILE *mpfile) {
if (mpx->buf==NULL)
mpx->buf = xmalloc(mpx->bufsize,1);
while ((c = getc(mpfile)) != EOF && c != '\n' && c != '\r') {
- mpx->buf[loc++] = c;
+ mpx->buf[loc++] = (char)c;
if (loc == mpx->bufsize) {
char *temp = mpx->buf;
unsigned n = mpx->bufsize + (mpx->bufsize>>4);
@@ -447,7 +449,14 @@ a percent sign, or an alphabetic token \.{btex}, \.{etex}, or
\.{verbatimtex}. (An alphabetic token is a maximal sequence of letters
and underscores.) If there are several possible substrings $t$, we
choose the leftmost one. If there is no such $t$, we set $b=s$ and return 0.
-
+
+Various values are defined, so that |mpx_copy_mpto| can distinguish between
+\.{verbatimtex} ... \.{etex} and \.{btex} ... \.{etex} (the former has no
+whitespace corrections applied).
+
+@d VERBATIM_TEX 1
+@d B_TEX 2
+
@c
static int mpx_getbta(MPX mpx, char *s) {
int ok = 1; /* zero if last character was |a-z|, |A-Z|, or |_| */
@@ -465,24 +474,27 @@ static int mpx_getbta(MPX mpx, char *s) {
return 1;
case 'b':
if (ok && mpx_match_str(mpx->tt, "btex")) {
- mpx->aa = mpx->tt + 4;
- return 1;
- } else
- ok = 0;
+ mpx->aa = mpx->tt + 4;
+ return 1;
+ } else {
+ ok = 0;
+ }
break;
case 'e':
if (ok && mpx_match_str(mpx->tt, "etex")) {
- mpx->aa = mpx->tt + 4;
- return 1;
- } else
- ok = 0;
+ mpx->aa = mpx->tt + 4;
+ return 1;
+ } else {
+ ok = 0;
+ }
break;
case 'v':
if (ok && mpx_match_str(mpx->tt, "verbatimtex")) {
- mpx->aa = mpx->tt + 11;
- return 1;
- } else
- ok = 0;
+ mpx->aa = mpx->tt + 11;
+ return 1;
+ } else {
+ ok = 0;
+ }
break;
default:
if ((*(mpx->tt) >= 'a' && *(mpx->tt) <= 'z') ||
@@ -498,61 +510,66 @@ static int mpx_getbta(MPX mpx, char *s) {
}
@ @c
-static void mpx_copy_mpto (MPX mpx, FILE *outfile) {
+static void mpx_copy_mpto (MPX mpx, FILE *outfile, int textype) {
char *s; /* where a string to print stops */
char *t; /* for finding start of last line */
char c;
char *res = NULL;
do {
- if (mpx->aa == NULL || *mpx->aa == 0) {
- if ((mpx->aa = mpx_getline(mpx,mpx->mpfile)) == NULL) {
- mpx_error(mpx,"btex section does not end");
- return;
+ if (mpx->aa == NULL || *mpx->aa == 0) {
+ if ((mpx->aa = mpx_getline(mpx,mpx->mpfile)) == NULL) {
+ mpx_error(mpx,"btex section does not end");
+ return;
+ }
}
- }
- if (mpx_getbta(mpx, mpx->aa) && *(mpx->tt) == 'e') {
- s = mpx->tt;
- } else {
- if (mpx->tt == NULL) {
- mpx_error(mpx,"btex section does not end");
- return;
- } else if (*(mpx->tt) == 'b') {
- mpx_error(mpx,"btex in TeX mode");
- return;
- } else if (*(mpx->tt) == 'v') {
- mpx_error(mpx,"verbatimtex in TeX mode");
- return;
+ if (mpx_getbta(mpx, mpx->aa) && *(mpx->tt) == 'e') {
+ s = mpx->tt;
+ } else {
+ if (mpx->tt == NULL) {
+ mpx_error(mpx,"btex section does not end");
+ return;
+ } else if (*(mpx->tt) == 'b') {
+ mpx_error(mpx,"btex in TeX mode");
+ return;
+ } else if (*(mpx->tt) == 'v') {
+ mpx_error(mpx,"verbatimtex in TeX mode");
+ return;
+ }
+ s = mpx->aa;
}
- s = mpx->aa;
- }
- c = *s;
- *s = 0;
- if (res==NULL) {
- res = xmalloc(strlen(mpx->bb)+2,1);
- res = strncpy(res,mpx->bb,(strlen(mpx->bb)+1));
- } else {
- res = xrealloc(res,strlen(res)+strlen(mpx->bb)+2,1);
- res = strncat(res,mpx->bb, strlen(mpx->bb));
- }
- if (c == '\0')
+ c = *s;
+ *s = 0;
+ if (res==NULL) {
+ res = xmalloc(strlen(mpx->bb)+2,1);
+ res = strncpy(res,mpx->bb,(strlen(mpx->bb)+1));
+ } else {
+ res = xrealloc(res,strlen(res)+strlen(mpx->bb)+2,1);
+ res = strncat(res,mpx->bb, strlen(mpx->bb));
+ }
+ if (c == '\0')
res = strncat(res, "\n", 1);
- *s = c;
+ *s = c;
} while (*(mpx->tt) != 'e');
- /* whitespace at the end */
- for (s = res + strlen(res) - 1;
+ s = res;
+ if (textype != VERBATIM_TEX) {
+ /* whitespace at the end */
+ for (s = res + strlen(res) - 1;
s >= res && (*s == ' ' || *s == '\t' || *s == '\r' || *s == '\n'); s--);
- t = s;
- *(++s) = '\0';
- /* whitespace at the start */
- for (s = res;
+ t = s;
+ *(++s) = '\0';
+ /* whitespace at the start */
+ for (s = res;
s < (res + strlen(res)) && (*s == ' ' || *s == '\t' || *s == '\r'
|| *s == '\n'); s++);
- for (; *t != '\n' && t > s; t--);
+ for (; *t != '\n' && t > s; t--);
+ }
fprintf(outfile,"%s", s);
- /* put no |%| at end if it's only 1 line total, starting with |%|;
- * this covers the special case |%&format| in a single line. */
- if (t != s || *t != '%')
- fprintf(outfile,"%%");
+ if (textype != VERBATIM_TEX) {
+ /* put no |%| at end if it's only 1 line total, starting with |%|;
+ * this covers the special case |%&format| in a single line. */
+ if (t != s || *t != '%')
+ fprintf(outfile,"%%");
+ }
free(res);
}
@@ -630,14 +647,14 @@ static void mpx_mpto(MPX mpx, char *tmpname, char *mptexpre) {
fprintf(outfile,mpx_pretex1[mode], mpx->lnno, mpname);
else
fprintf(outfile,mpx_pretex[mode], mpx->lnno, mpname);
- mpx_copy_mpto(mpx, outfile);
+ mpx_copy_mpto(mpx, outfile, B_TEX);
fprintf(outfile,"%s", mpx_posttex[mode]);
} else if (*(mpx->tt) == 'v') {
if (mpx->verbcnt++ == 0 && mpx->texcnt == 0)
fprintf(outfile,mpx_preverb1[mode], mpx->lnno, mpname);
else
fprintf(outfile,mpx_preverb[mode], mpx->lnno, mpname);
- mpx_copy_mpto(mpx, outfile);
+ mpx_copy_mpto(mpx, outfile, VERBATIM_TEX);
fprintf(outfile,"%s", mpx_postverb[mode]);
} else {
mpx_error(mpx,"unmatched etex");
@@ -1091,7 +1108,7 @@ n=mpx_get_byte(mpx); /* that is the area */
n=n+mpx_get_byte(mpx);
mpx->font_name[mpx->nfonts]=xmalloc((size_t)(n+1),1);
for (k=0;k<n;k++)
- mpx->font_name[mpx->nfonts][k]=mpx_get_byte(mpx);
+ mpx->font_name[mpx->nfonts][k]=(char)mpx_get_byte(mpx);
mpx->font_name[mpx->nfonts][k]=0
@ The scaled size and design size are stored in \.{DVI} units divided by $2^{20}$.
@@ -1185,7 +1202,7 @@ static void mpx_in_TFM (MPX mpx,web_integer f) {
web_integer k; /* index for loops */
int lh; /* length of the header data, in four-byte words */
int nw; /* number of words in the width table */
- unsigned wp; /* new value of |info_ptr| after successful input */
+ unsigned int wp; /* new value of |info_ptr| after successful input */
@<Read past the header data; |abort| if there is a problem@>;
@<Store character-width indices at the end of the |width| table@>;
@<Read the width values into the |in_width| table@>;
@@ -1201,10 +1218,10 @@ mpx_read_tfm_word(mpx);
mpx->font_bc[f]=mpx->b0*(int)(256)+mpx->b1;
mpx->font_ec[f]=mpx->b2*(int)(256)+mpx->b3;
if ( mpx->font_ec[f]<mpx->font_bc[f] ) mpx->font_bc[f]=mpx->font_ec[f]+1;
-if ( mpx->info_ptr+mpx->font_ec[f]-mpx->font_bc[f]+1>max_widths )
+if ( mpx->info_ptr+(unsigned int)mpx->font_ec[f]-(unsigned int)mpx->font_bc[f]+1>max_widths )
mpx_abort(mpx,"DVItoMP capacity exceeded (width table size=%d)!",max_widths);
@.DVItoMP capacity exceeded...@>
-wp=mpx->info_ptr+mpx->font_ec[f]-mpx->font_bc[f]+1;
+wp=mpx->info_ptr+(unsigned int)mpx->font_ec[f]-(unsigned int)mpx->font_bc[f]+1;
mpx_read_tfm_word(mpx); nw=mpx->b0*256+mpx->b1;
if ( (nw==0)||(nw>256) )
font_abort("Bad TFM file for ",f);
@@ -1270,7 +1287,7 @@ floor(mpx->dvi_scale*mpx->font_scaled_size[cur_font]*char_width(cur_font,p))
if ( mpx->in_width[0]!=0 )
font_abort("Bad TFM file for ",f); /* the first width should be zero */
@.Bad TFM file@>
-mpx->info_base[f]=(int)(mpx->info_ptr-mpx->font_bc[f]);
+mpx->info_base[f]=(int)(mpx->info_ptr-(unsigned int)mpx->font_bc[f]);
if ( wp>0 ) {
for (k=(int)mpx->info_ptr;k<=(int)wp-1;k++) {
mpx->width[k]=mpx->in_width[mpx->width[k]];
@@ -1358,7 +1375,7 @@ if ( c>mpx->font_ec[f] ) mpx->font_ec[f]=c;
char_width(f,c)=w
@ @<Store the character packet in |cmd_buf|@>=
-if ( mpx->n_cmds+p>=virtual_space )
+if ( mpx->n_cmds+(unsigned int)p>=virtual_space )
mpx_abort(mpx,"DVItoMP capacity exceeded (virtual font space=%d)",virtual_space);
@.DVItoMP capacity exceeded...@>
start_cmd(f,c)=(web_integer)mpx->n_cmds;
@@ -2591,8 +2608,9 @@ static void *destroy_avl_entry (void *pa) {
return NULL;
}
static void *copy_avl_entry (const void *pa) { /* never used */
- avl_entry *p, *q;
- p = (avl_entry *) pa;
+ const avl_entry *p;
+ avl_entry *q;
+ p = (const avl_entry *) pa;
q = malloc(sizeof(avl_entry));
if (q!=NULL) {
q->name = strdup(p->name);
@@ -2670,7 +2688,7 @@ static int mpx_get_int_map(MPX mpx, char *s) {
register int i;
if (s == NULL)
goto BAD;
- i = strtol(s, &(mpx->arg_tail), 0);
+ i = (int)strtol(s, &(mpx->arg_tail), 0);
if (s == mpx->arg_tail)
goto BAD;
return i;
@@ -2699,15 +2717,15 @@ static float mpx_get_float(MPX mpx, char *s) {
}
x = 0.0;
while (d = *s - '0', 0 <= d && d <= 9) {
- x = 10.0 * x + d;
+ x = (float)10.0 * x + (float)d;
digits++;
s++;
}
if (*s == '.') {
y = 1.0;
while (d = *++s - '0', 0 <= d && d <= 9) {
- y /= 10.0;
- x += y * d;
+ y /= (float)10.0;
+ x += y * (float)d;
digits++;
}
}
@@ -2772,8 +2790,8 @@ static void mpx_read_fmap(MPX mpx, const char *dbase) {
if (nam==buf)
continue;
tmp = xmalloc(sizeof(avl_entry),1);
- tmp->name = xmalloc (1,(buf-nam)+1);
- strncpy(tmp->name,nam,(buf-nam));
+ tmp->name = xmalloc (1,(size_t)(buf-nam)+1);
+ strncpy(tmp->name,nam,(unsigned int)(buf-nam));
tmp->name[(buf-nam)] = '\0';
tmp->num = (int)mpx->nfonts++;
assert(avl_ins (tmp, mpx->trfonts, avl_false) > 0);
@@ -3075,7 +3093,7 @@ static void mpx_set_num_char(MPX mpx, int f, int c) {
mpx->str_size = mpx->cursize;
}
mpx_print_char(mpx, (unsigned char)c);
- mpx->dmp_str_h2 = hh + char_width(f,c);
+ mpx->dmp_str_h2 = hh + (float)char_width(f,c);
}
@ Output a string.
@@ -3088,10 +3106,10 @@ static void mpx_set_string(MPX mpx, char *cname) {
return;
hh = (float)mpx->h;
mpx_set_num_char(mpx,(int)mpx->curfont, *cname);
- hh += char_width(mpx->curfont,(int)*cname);
+ hh += (float)char_width(mpx->curfont,(int)*cname);
while (*++cname) {
mpx_print_char(mpx,(unsigned char)*cname);
- hh += char_width(mpx->curfont,(int)*cname);
+ hh += (float)char_width(mpx->curfont,(int)*cname);
}
mpx->h = (web_integer)floor(hh+0.5);
mpx_finish_last_char(mpx);
@@ -3151,7 +3169,7 @@ static char *mpx_copy_spec_char(MPX mpx, char *cname) {
if (c == EOF)
mpx_abort(mpx, "vardef in charlib/%s has no arguments", cname);
putc(c, mpx->mpxfile);
- *t++ = c;
+ *t++ = (char)c;
}
putc(c, mpx->mpxfile);
*t++ = '\0';
@@ -3225,7 +3243,7 @@ OUT_LABEL:
fprintf(mpx->mpxfile, "_s(%s(_n%d)", sp->mac,f);
fprintf(mpx->mpxfile, ",%.5f,%.4f,%.4f)",
(mpx->cursize/mpx->font_design_size[f])*1.00375,
- (double)((mpx->h*mpx->unit)/100.0), YCORR-mpx->v*mpx->unit);
+ (double)(((float)mpx->h*mpx->unit)/100.0), YCORR-(float)mpx->v*mpx->unit);
mpx_slant_and_ht(mpx);
fprintf(mpx->mpxfile, ";\n");
}
@@ -3287,13 +3305,13 @@ The tables below give the Bezier control points for MetaPost's cubic
approximation to the first octant of a unit circle.
@c
-static const float xx[] = { 1.0, 1.0, 0.8946431597, 0.7071067812 };
-static const float yy[] = { 0.0, 0.2652164899, 0.5195704026, 0.7071067812 };
+static const float xx[] = { 1.0, 1.0, (float)0.8946431597, (float)0.7071067812 };
+static const float yy[] = { 0.0, (float)0.2652164899, (float)0.5195704026, (float)0.7071067812 };
@ @c
static float mpx_circangle(float t) {
float ti;
- ti = floor(t);
+ ti = (float)floor(t);
t -= ti;
return (float) atan(mpx_b_eval(yy, t) /
mpx_b_eval(xx, t)) + ti * Speed;
@@ -3404,10 +3422,10 @@ static
void mpx_do_arc(MPX mpx, float cx, float cy, float ax, float ay, float bx, float by) {
float t1, t2;
- t1 = mpx_circtime(atan2(ay, ax));
- t2 = mpx_circtime(atan2(by, bx));
+ t1 = mpx_circtime((float)atan2(ay, ax));
+ t2 = mpx_circtime((float)atan2(by, bx));
if (t2 < t1)
- t2 += 8.0;
+ t2 += (float)8.0;
fprintf(mpx->mpxfile, "subpath (%.5f,%.5f) of\n", t1, t2);
fprintf(mpx->mpxfile,
" makepath(pencircle scaled %.3f shifted (%.3f,%.3f));\n",
@@ -3431,7 +3449,7 @@ static void mpx_do_graphic(MPX mpx, char *s) {
if (s[0] == 'F' && s[1] == 'd')
return;
mpx->gx = (float) mpx->h;
- mpx->gy = YCORR / mpx->unit - ((float) mpx->v);
+ mpx->gy = (float)YCORR / mpx->unit - ((float) mpx->v);
if (!mpx->graphics_used)
mpx_prepare_graphics(mpx);
fprintf(mpx->mpxfile, "D(%.4f) ", LWscale * mpx->cursize);
@@ -3522,7 +3540,7 @@ static int mpx_do_x_cmd(MPX mpx, char *s0)
mpx->unit = mpx_get_float(mpx,s);
if (mpx->unit <= 0.0)
mpx_abort(mpx,"Bad resolution: x %s", s0);
- mpx->unit = 72.0 / mpx->unit;
+ mpx->unit = (float)72.0 / mpx->unit;
break;
case 'f':
while (*s != ' ' && *s != '\t')
@@ -3560,11 +3578,11 @@ static int mpx_do_x_cmd(MPX mpx, char *s0)
case 'S':
while (*s != ' ' && *s != '\t')
s++;
- mpx->Xslant = mpx_get_float(mpx,s) * (PI / 180.0);
- x = cos(mpx->Xslant);
+ mpx->Xslant = mpx_get_float(mpx,s) * ((float)PI / (float)180.0);
+ x = (float)cos(mpx->Xslant);
if (-1e-4 < x && x < 1e-4)
mpx_abort(mpx,"Excessive slant");
- mpx->Xslant = sin(mpx->Xslant) / x;
+ mpx->Xslant = (float)sin(mpx->Xslant) / x;
break;
default:
/* do nothing */ ;
@@ -3916,7 +3934,8 @@ First, here is a helper for messaging.
@c
static char *mpx_print_command (MPX mpx, int cmdlength, char **cmdline) {
char *s, *t;
- int i,l;
+ int i;
+ size_t l;
(void)mpx;
l = 0;
for (i = 0; i < cmdlength ; i++) {