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

This is gnuplot.c in view mode; [Download] [Up]

#include "incl.h"

extern FILE   *fpo, *fpi;
extern char    buffer[];
extern int     inlinecount, outlinecount;
extern double  llx, lly, urx, ury;
extern double  scx, scy, defaultwidth;

gnuplot ()
{
char    str1[MAXWORD+1];
char    str2[MAXWORD+1];
char    str3[MAXWORD+1];
int     landscape, n;
double  tmp;

/*
** Scan file for statement "90 rotate".
** When found the 'landscape' option was used.
*/
   landscape = FALSE;
   for (fgets (buffer, MAXBUF, fpi); (!(feof (fpi)));
			             fgets (buffer, MAXBUF, fpi)) {
      n = sscanf (buffer, "%s%s%s", str1, str2, str3);
      if (n == 2 && strcmp (str2, ROTATE) == 0) {
         landscape = TRUE;
         break;
      }
   }
   rewind (fpi);
/*
** Replace first line
*/
   fgets (buffer, MAXBUF, fpi);
   inlinecount++;
   fprintf (fpo, "%s", FIRSTLINE);
/*
** For GNUPLOT 3.0 the boundingbox statement always looks like:
**
** %%BoundingBox: 50 50 urx ury
**
** Scan file for BoundingBox statement.
** - Subtract 50 from boundingbox values to correct for the elimination
**   of statement: "50 50 translate".
** - If landscape = TRUE then
**   Swap x and y values to correct for the elimination of statement:
***   "90 rotate".
** - Calculate initial scaling factors for default width MAX_WIDTH.
** - Change boundingbox values to correct for the initial scaling.
*/
   for (fgets (buffer, MAXBUF, fpi); (!(feof (fpi)));
			             fgets (buffer, MAXBUF, fpi)) {
      inlinecount++;
      sscanf (buffer, "%s", str1);
      if (strcmp (str1, PPBOUNDINGBOXC) == 0) {
         sscanf (buffer, "%*s%lf%lf%lf%lf", &llx, &lly, &urx, &ury);
         llx -= 50;
         lly -= 50;
         urx -= 50;
         ury -= 50;

         if (landscape) {
            tmp = llx; llx = lly; lly = tmp;
            tmp = urx; urx = ury; ury = tmp;
         }

         tmp = defaultwidth / (urx - llx);
         scx = tmp;
         scy = tmp;

         llx *= scx;
         lly *= scy;
         urx *= scx;
         ury *= scy;

         break;
      }
      else {
         fprintf (fpo, "%s", buffer);
         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++;
/*
** Scan rest of file.
** Delete statements:
**     50 50 translate
**     90 rotate         (only present when 'landscape' option was used)
**     0 -5040 translate (only present when 'landscape' option was used)
** Edit statement:
**     0.100 0.100 scale
*/
   for (fgets (buffer, MAXBUF, fpi); (!(feof (fpi)));
			             fgets (buffer, MAXBUF, fpi)) {
      inlinecount++;
      n = sscanf (buffer, "%s%s%s", str1, str2, str3);
      if (strcmp (str1, PPENDCOMMENTS) == 0) {
         fprintf (fpo, "%s", buffer);
/*
**       Insert next statement for use with program ``dvialw''
*/
         fprintf (fpo, "%s", DVIALW_BEGIN);
         outlinecount += 2;
      }
      else if (n == 3 && strcmp (str3, TRANSLATE) == 0) {
         if (strcmp (str1, CURRENTPOINT) == 0) {
            fprintf (fpo, "%s", buffer);
            outlinecount++;
         }
         else continue;
      }
      else if (n == 3 && strcmp (str3, SCALE) == 0) {
         scx *= atof (str1);
         scy *= atof (str2);
         fprintf (fpo, "%.3lf %.3lf %s\n", scx, scy, SCALE);
         outlinecount++;
      }
      else if (landscape && n == 2 && strcmp (str2, ROTATE) == 0) {
         continue;
      }
      else if (strcmp (str1, SHOWPAGE) == 0) {
/*
**       Insert next statement for use with program ``dvialw''
*/
         fprintf (fpo, "%s", DVIALW_END);
         fprintf (fpo, "%s", buffer);
         outlinecount += 2;
      }
      else {
         fprintf (fpo, "%s", buffer);
         outlinecount++;
      }
   }
   return (EXIT_SUCCESS);
}

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