ftp.nice.ch/pub/next/unix/postscript/ps2eps.1.0.NIHS.bsd.tar.gz#/ps2eps-1.0/src/mathcad.c

This is mathcad.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;

mathcad ()
{
char str[MAXBUF+1];

/*
** Get and test first line.
*/
   fgets (buffer, MAXBUF, fpi);
   inlinecount++;
   if (buffer[0] == EOT) {
      fgets (buffer, MAXBUF, fpi);
      inlinecount++;
   }
   if (buffer[0] == '%' && buffer[1] == '!') {
      fprintf (fpo, "%s", FIRSTLINE);
      outlinecount++;
/*
**    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);

      fprintf (fpo, "%s %d %d %d %d\n",
               PPBOUNDINGBOXC, (int)llx, (int)lly, (int)urx, (int)ury);
      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++;
      str[0] = '\0';
      sscanf (buffer, "%s", str);
      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, 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.
*/
            fprintf (fpo, "%.3lf %.3lf %s", scx, scy, SCALE);
            outlinecount++;
            sprintf (buffer, "");
            EndComments = TRUE;
         }
         if (EndComments && !(pagesOK)) {
            fprintf (fpo, "%s: 0 1\n", PPPAGES);
            outlinecount++;
         }
      }
      else if ((!(EndComments)) && (buffer[0] != '%')) {
         comments ();
      }
      else if (strcmp (str, Ba4) == 0) {
         fprintf (fpo, "%s%s", PPP, buffer);
         fgets (buffer, MAXBUF, fpi);
         inlinecount++;
         fprintf (fpo, "%s%s", PPP, buffer);
         outlinecount += 2;
         sprintf (buffer, "");
      }
      else if (strcmp (str, Ba4BSTOPPED) == 0) {
         fprintf (fpo, "%s%s", PPP, buffer);
         outlinecount++;
         sprintf (buffer, "");
      }

      fprintf (fpo, "%s", buffer);
      outlinecount++;
   }
/*
** 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);
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.