home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / dvips583.zip / contrib.zip / dvips / contrib / bbfig / vmsbbfig.c < prev   
C/C++ Source or Header  |  1998-11-03  |  3KB  |  114 lines

  1. /* bbfig.c --
  2.  * Martin Gelbaum, Lawrence Berkeley Laboratory
  3.  * martyg@lbl.gov
  4.  * September 21, 1992
  5.  * Simple VAX C equivalent of Bourne shell script "bbfig"
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <ssdef.h>    /* System status codes */
  10. #include <unixlib>
  11.   
  12. #define BBFIG_HEADER "tex_disk:[tex.dvips.header_files]bb.ps"
  13.  
  14. main(argc,argv)
  15. int argc;     
  16. char **argv;   
  17. {
  18.         FILE *infp, *libfp, *outfp;
  19.     char outfile[1024], buf[BUFSIZ], line[512], *cptr;
  20.  
  21.     if (argc < 2) { error("Usage: bbfig psfile [> outfile]\n"); }
  22.     if ( !strcmp(argv[1], "-help") || !strcmp(argv[1], "-HELP") )
  23.     {
  24.         fprintf(stderr, "bbfig: usage: bbfig psfile [> outfile]\n");
  25.         fflush(stderr); fprintf(stderr, 
  26. "If no output file specified, output file is bbfig_out.ps\n");
  27.         fflush(stderr); fprintf(stderr, 
  28. "Output file shows figure surrounded by box made of dashes\n");
  29.         fflush(stderr); fprintf(stderr, 
  30. "Output file also shows bounding box in default coordinates for use as\n");
  31.         fflush(stderr); fprintf(stderr, 
  32. "Bounding Box comment as second line of PostScript file.\n");
  33.         exit(SS$_NORMAL);
  34.     }
  35.         if ( (libfp = fopen(BBFIG_HEADER,"r")) == NULL)
  36.         {
  37.         error("ABNORMAL EXIT:\nCan't open PostScript macro file %s\n", 
  38.                     BBFIG_HEADER);
  39.         }
  40.         if ( (infp = fopen(*++argv,"r")) == NULL)
  41.         {
  42.         error("ABNORMAL EXIT:\nCan't open user PostScript file %s\n", 
  43.             *argv);
  44.         }
  45.     if (argc >=3)
  46.     {
  47.         argv++;
  48.         if ( (*argv)[0] ==  '>')
  49.         {
  50.             if ((*argv)[1])
  51.             /* We had bbfig file  >outfile */
  52.             {
  53.                 cptr = &(*argv)[1];
  54.                 (void) sprintf(outfile,"%s", cptr);
  55.             }
  56.             else if (*(++argv) != NULL) 
  57.             /* We had bbfig psfile > outfile */
  58.                  { 
  59.                 cptr = *argv;
  60.                 (void) sprintf(outfile,"%s", cptr);
  61.             }
  62.             else
  63.             {
  64.                 error("%s: no filename with '>' option\n",
  65.                                             "ABNORMAL EXIT");
  66.             }
  67.         }
  68.         else
  69.         {
  70.             error("ABNORMAL EXIT: unknown option %c\n",
  71.                     (*argv)[0]);
  72.         }
  73.     }
  74.     else
  75.     {
  76.         /* Default filename is "bbfig_out.ps" */
  77.         sprintf(outfile, "bbfig_out.ps");
  78.     }
  79.     /* Make a standard variable length record file
  80.     * with carriage return carriage control. 
  81.     */
  82.         if ( (outfp = fopen(outfile,"w", "rat=cr", "rfm=var")) == NULL)
  83.         {
  84.         error("ABNORMAL EXIT: can't create text file %s\n", 
  85.             outfile);
  86.         }
  87.     while (fgets(line, 511, libfp))
  88.     {
  89.                         fputs(line, outfp); fflush(outfp);
  90.         }
  91.         (void) fclose (libfp);
  92.     while (fgets(line, 511, infp))
  93.     {
  94.                         fputs(line, outfp); fflush(outfp);
  95.         }
  96.         (void) fclose (infp); (void) fclose (outfp);
  97.     fprintf(stderr, "Output file showing bounding box is %s;\n", outfile);
  98.     fflush(stderr);
  99.     fprintf(stderr, 
  100. "You may print it by lpr to a PostScript printer or\n"); fflush(stderr);
  101.     fprintf(stderr, 
  102. "preview it by gs (ghostscript) on a X11 display ...\n"); fflush(stderr);
  103.     exit(SS$_NORMAL);
  104. }
  105.  
  106. static error(s1,s2)   /* print error message and exit with error status. */
  107. char *s1, *s2;
  108. {
  109.     /* Notice that the first argument (s1) contains the formatting
  110.      * information for fprintf. 
  111.      */
  112.     fprintf(stderr, "bbfig: "); fprintf(stderr, s1, s2); exit(0x10000000);
  113. }
  114.