Back to index

tetex-bin  3.0
vmsbbfig.c
Go to the documentation of this file.
00001 /* bbfig.c --
00002  * Martin Gelbaum, Lawrence Berkeley Laboratory
00003  * martyg@lbl.gov
00004  * September 21, 1992
00005  * Simple VAX C equivalent of Bourne shell script "bbfig"
00006  */
00007 
00008 #include <stdio.h>
00009 #include <ssdef.h>   /* System status codes */
00010 #include <unixlib>
00011   
00012 #define BBFIG_HEADER "tex_disk:[tex.dvips.header_files]bb.ps"
00013 
00014 main(argc,argv)
00015 int argc;     
00016 char **argv;   
00017 {
00018         FILE *infp, *libfp, *outfp;
00019        char outfile[1024], buf[BUFSIZ], line[512], *cptr;
00020 
00021        if (argc < 2) { error("Usage: bbfig psfile [> outfile]\n"); }
00022        if ( !strcmp(argv[1], "-help") || !strcmp(argv[1], "-HELP") )
00023        {
00024               fprintf(stderr, "bbfig: usage: bbfig psfile [> outfile]\n");
00025               fflush(stderr); fprintf(stderr, 
00026 "If no output file specified, output file is bbfig_out.ps\n");
00027               fflush(stderr); fprintf(stderr, 
00028 "Output file shows figure surrounded by box made of dashes\n");
00029               fflush(stderr); fprintf(stderr, 
00030 "Output file also shows bounding box in default coordinates for use as\n");
00031               fflush(stderr); fprintf(stderr, 
00032 "Bounding Box comment as second line of PostScript file.\n");
00033               exit(SS$_NORMAL);
00034        }
00035         if ( (libfp = fopen(BBFIG_HEADER,"r")) == NULL)
00036         {
00037               error("ABNORMAL EXIT:\nCan't open PostScript macro file %s\n", 
00038                                    BBFIG_HEADER);
00039         }
00040         if ( (infp = fopen(*++argv,"r")) == NULL)
00041         {
00042               error("ABNORMAL EXIT:\nCan't open user PostScript file %s\n", 
00043                      *argv);
00044         }
00045        if (argc >=3)
00046        {
00047               argv++;
00048               if ( (*argv)[0] ==  '>')
00049               {
00050                      if ((*argv)[1])
00051                      /* We had bbfig file  >outfile */
00052                      {
00053                             cptr = &(*argv)[1];
00054                             (void) sprintf(outfile,"%s", cptr);
00055                      }
00056                      else if (*(++argv) != NULL) 
00057                      /* We had bbfig psfile > outfile */
00058                      { 
00059                             cptr = *argv;
00060                             (void) sprintf(outfile,"%s", cptr);
00061                      }
00062                      else
00063                      {
00064                             error("%s: no filename with '>' option\n",
00065                                           "ABNORMAL EXIT");
00066                      }
00067               }
00068               else
00069               {
00070                      error("ABNORMAL EXIT: unknown option %c\n",
00071                                    (*argv)[0]);
00072               }
00073        }
00074        else
00075        {
00076               /* Default filename is "bbfig_out.ps" */
00077               sprintf(outfile, "bbfig_out.ps");
00078        }
00079        /* Make a standard variable length record file
00080        * with carriage return carriage control. 
00081        */
00082         if ( (outfp = fopen(outfile,"w", "rat=cr", "rfm=var")) == NULL)
00083         {
00084               error("ABNORMAL EXIT: can't create text file %s\n", 
00085                      outfile);
00086         }
00087        while (fgets(line, 511, libfp))
00088        {
00089                         fputs(line, outfp); fflush(outfp);
00090         }
00091         (void) fclose (libfp);
00092        while (fgets(line, 511, infp))
00093        {
00094                         fputs(line, outfp); fflush(outfp);
00095         }
00096         (void) fclose (infp); (void) fclose (outfp);
00097        fprintf(stderr, "Output file showing bounding box is %s;\n", outfile);
00098        fflush(stderr);
00099        fprintf(stderr, 
00100 "You may print it by lpr to a PostScript printer or\n"); fflush(stderr);
00101        fprintf(stderr, 
00102 "preview it by gs (ghostscript) on a X11 display ...\n"); fflush(stderr);
00103        exit(SS$_NORMAL);
00104 }
00105 
00106 static error(s1,s2)   /* print error message and exit with error status. */
00107 char *s1, *s2;
00108 {
00109        /* Notice that the first argument (s1) contains the formatting
00110         * information for fprintf. 
00111         */
00112        fprintf(stderr, "bbfig: "); fprintf(stderr, s1, s2); exit(0x10000000);
00113 }