This is parse.c in view mode; [Download] [Up]
#include "incl.h"
extern FILE *fpo, *fpi;
extern char *word1, *word2;
extern char buffer[], newbuf[];
extern int inlinecount, outlinecount;
extern int boundingboxOK, boundingboxOPTION;
extern int pagesOK, atend, EndComments;
extern long CurrentPos, BboxPos, ScalePos;
extern double llx, lly, urx, ury, scx, scy;
parse ()
{
/*
** Get and test first line.
*/
fgets (buffer, MAXBUF, fpi);
inlinecount++;
if (buffer[0] == '%' && buffer[1] == '!') {
fprintf (fpo, "%s", FIRSTLINE);
outlinecount++;
BboxPos = ftell (fpo);
fprintf (fpo, "%s\n", BB_BUF);
outlinecount++;
}
else {
fprintf (stderr, "\n*** First line not beginning with %%!\n\n");
return (EXIT_FAILURE);
}
scx = 1.0;
scy = 1.0;
for (fgets (buffer, MAXBUF, fpi); (!(feof (fpi)));
fgets (buffer, MAXBUF, fpi)) {
inlinecount++;
if (buffer[0] == '%' && buffer[1] == '%') {
strcpy (newbuf, buffer);
word1 = strtok (newbuf, " :\n");
word2 = strtok ('\0', " \n\t");
if ((word1 == NULL) || (strcmp (word1, PPPAGESIZE) == 0) ||
(strcmp (word1, PPPAGEBOUNDINGBOX) == 0) ||
(strcmp (word1, PPFEATURE) == 0)) {
sprintf (buffer, "");
}
else if (strcmp (word1, PPPAGE) == 0) {
/*
** This statement means there are more than 1 page.
** Impossible. Statement deleted.
*/
sprintf (buffer, "");
}
else if (strcmp (word1, PPBOUNDINGBOX) == 0) {
if (strcmp (word2, ATEND) == 0) {
atend = TRUE;
sprintf (buffer, "");
}
else {
boundingboxOK = TRUE;
if (!boundingboxOPTION)
sscanf (buffer, "%*s%lf%lf%lf%lf",
&llx, &lly, &urx, &ury);
if (bndbox () == EXIT_FAILURE) return (EXIT_FAILURE);
}
}
else if (strcmp (word1, PPPAGES) == 0) {
pagesOK = TRUE;
sprintf (buffer, "%s: 0 1\n", PPPAGES);
}
else if (strcmp (word1, PPENDCOMMENTS) == 0) {
fprintf (fpo, "%s\n", PPENDCOMMENTS);
/*
** Insert next statement for use with program ``dvialw''
*/
fprintf (fpo, "%s", DVIALW_BEGIN);
/*
** Insert scale statement to reflect to supplied or default
** boundingbox. Boundingbox depends on -w and -h options.
** Insert dummy spaces at the end for this statement may be
** overwritten.
*/
ScalePos = ftell (fpo);
fprintf (fpo, "%.3lf %.3lf %s \n",
scx, scy, SCALE);
outlinecount += 3;
sprintf (buffer, "");
EndComments = TRUE;
}
if (EndComments && !(pagesOK)) {
fprintf (fpo, "%s: 0 1\n", PPPAGES);
outlinecount++;
}
}
else if ((!(EndComments)) && (buffer[0] != '%')) {
comments ();
}
fprintf (fpo, "%s", buffer);
outlinecount++;
}
if (!boundingboxOK && !boundingboxOPTION) {
fprintf (stderr, "\n*** There is no BoundingBox !\n");
fprintf (stderr, "Use -b option.\n\n");
return (EXIT_FAILURE);
}
if (!boundingboxOK && boundingboxOPTION) {
/*
** adjust boundingbox and scale values depending on width (-w)
** height (-h) and space (-s) options.
** Write BoundinBox statement in reserved 2nd output statement.
*/
if (bndbox () == EXIT_FAILURE) return (EXIT_FAILURE);
/*
** Overwrite 'scale' statement.
*/
CurrentPos = ftell (fpo);
fseek (fpo, ScalePos, SEEK_SET);
fprintf (fpo, "%.3lf %.3lf %s", scx, scy, SCALE);
fseek (fpo, CurrentPos, SEEK_SET);
}
/*
** Insert next statement for use with program ``dvialw''
*/
fprintf (fpo, "%s", DVIALW_END);
outlinecount++;
fprintf (stderr, "\n%s\n%s\n%s\n%s\n\n",
" ********* WARNING ********** ",
"When using program `dvialw' the `%end(plot)'",
"statement must be >>before<< a possible",
"`showpage' statement.");
return (EXIT_SUCCESS);
}
bndbox ()
{
if ((urx - llx) == 0 || (ury - lly) == 0) {
fprintf (stderr, "\n*** Illegal BoundingBox values: %d %d %d %d\n\n",
(int)llx, (int)lly, (int)urx, (int)ury);
return (EXIT_FAILURE);
}
/*
** Adjust BoundingBox and scale values depending on width (-w)
** height (-h) and space (-s) options.
*/
if (adj_bbox (urx - llx) == EXIT_FAILURE) return (EXIT_FAILURE);
CurrentPos = ftell (fpo);
fseek (fpo, BboxPos, SEEK_SET);
fprintf (fpo, "%s %d %d %d %d",
PPBOUNDINGBOXC, (int)llx, (int)lly, (int)urx, (int)ury);
fseek (fpo, CurrentPos, SEEK_SET);
sprintf (buffer, "");
return (EXIT_SUCCESS);
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.