home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / graphics-0.17 / plot2ps / open.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-11  |  3.2 KB  |  123 lines

  1. /* plot2ps, a utility for converting Unix plot files into postscript.
  2.    Copyright (C) 1989 Free Software Foundation, Inc.
  3.  
  4. Plot2ps is distributed in the hope that it will be useful, but WITHOUT ANY
  5. WARRANTY.  No author or distributor accepts responsibility to anyone for the
  6. consequences of using it or for whether it serves any particular purpose or
  7. works at all, unless he says so in writing.  Refer to the GNU General Public
  8. License for full details.
  9.  
  10. Everyone is granted permission to copy, modify and redistribute plot2ps, but
  11. only under the conditions described in the GNU General Public License.  A copy
  12. of this license is supposed to have been given to you along with plot2ps so
  13. you can know your rights and responsibilities.  It should be in a file named
  14. COPYING.  Among other things, the copyright notice and this notice must be
  15. preserved on all copies.  */
  16.  
  17. /* This file is the openpl routine, which is a standard part of the plot
  18.    library.  It normally opens the device.  We just print out the
  19.    postscript prologue */
  20.  
  21. #include "sys-defines.h"
  22. #include "libplot.h"
  23.  
  24. extern char *header[6];
  25.  
  26. /* USER_HAS_PROLOGUE is a flag. If it is non-zero then the open routine
  27.    should output the user specified prologue contained in the file specified
  28.    in the string USERS_PROLOGUE */
  29.  
  30. int user_has_prologue = 0;
  31.  
  32. /* USERS_PROLOGUE is a string containing the file name for any user specified
  33.    postscript prologue.  This file is a substitute for the prologue contained
  34.    in the file header.c. */
  35.  
  36. char *users_prologue = "";
  37.  
  38. int
  39. openpl ()
  40. {
  41.   int i;
  42.  
  43.   if (!default_font)
  44.     {
  45.       default_font =  (char *) malloc (strlen ("helvetica") + 1);
  46.       strcpy (default_font, "helvetica");
  47.     }
  48.   if (!current_font)
  49.     {
  50.       current_font =  (char *) malloc (strlen ("helvetica") + 1);
  51.       strcpy (current_font, "helvetica");
  52.     }
  53.  
  54.   line_type_setdash_length = 1024;
  55.   line_type_setdash = (char *) malloc (line_type_setdash_length);
  56.   if (line_type_setdash <= (char *) 0)
  57.     {
  58.       perror ("malloc failed:");
  59.       exit (-1);
  60.     }
  61.  
  62.   fputs ("\
  63. %! PS-Adobe-2.0 EPSF-1.2\n\
  64. %%\n\
  65. %%\n\
  66. %%                              TYPE `plot2ps -help' FOR MORE INFORMATION.\n\
  67. %%\n\
  68. %%\n\
  69. %%DocumentFonts: Times-Bold\n\
  70. %%BoundingBox: (atend)", stdout);
  71.  
  72.   if (user_has_prologue)
  73.     {
  74.       FILE *prologuep;
  75.       char buff[1024];
  76.       int bytes_read;
  77.  
  78.       prologuep = fopen (users_prologue, "r");
  79.       if (prologuep == NULL)
  80.     {
  81.       fprintf (stderr, "Unable to open prologue file `%s' for reading. Using builtin prologue.\n", users_prologue);
  82.       for (i=0; header[i][0]>0; i++)
  83.         fputs (header[i], stdout);
  84.     }
  85.       else
  86.     {
  87.       while ( (bytes_read = fread(buff, 1, sizeof(buff), prologuep)) > 0 )
  88.         {
  89.           fwrite (buff, 1, bytes_read, stdout);
  90.         }
  91.       fclose (prologuep);
  92.     }
  93.     }
  94.   else
  95.     {
  96.       for (i=0; header[i][0]>0; i++)
  97.     fputs (header[i], stdout);
  98.     }
  99.  
  100.   fputs ("\n\
  101. %I Idraw 7\n\
  102. \n\
  103. Begin\n\
  104. %I b u\n\
  105. %I cfg u\n\
  106. %I cbg u\n\
  107. %I f u\n\
  108. %I p u\n\
  109. %I t\n[ ", stdout);
  110.   printf ("%g 0 0 %g", SCALING, SCALING);
  111.   fputs (" 0 0 ] concat\n\
  112. /originalCTM matrix currentmatrix def\n\
  113. %\n\
  114. %\n\
  115. %\n\
  116. %                              TYPE `plot2ps -help' FOR MORE INFORMATION.\n\
  117. %\n\
  118. %\n\
  119. \n", stdout);
  120.  
  121.   return 0;
  122. }
  123.