home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / gle / glecmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-29  |  4.4 KB  |  172 lines

  1. /* This is the gle command which translates to run the individual
  2.    gle programs:
  3.       gle myfile -dps       ---> gle_ps myfile
  4.  
  5.           gle myfile /nomaxpath -dlj -old -noflip
  6.                ---> gle_dvi myfile /nomaxpath
  7.                ---> gle_dviprint -dlj -out myfile.hp -old -noflip
  8. */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <sys/types.h>
  13. #include <sys/wait.h>
  14. #include "glepath.h"
  15.  
  16. #define false 0
  17. #define true (!false)
  18. main(int argc,char *argv[])
  19. {
  20.     static char buff[200];
  21.     static char glefile[200];
  22.     static char device[200];
  23.     static char outfile[200];
  24.     static char bmpdev[100];
  25.     static char gleoptions[200];
  26.     static char devoptions[200];
  27.     static char bindir[200];
  28.     char *s;
  29.     FILE *f;
  30.     int i;
  31.     int gotdevice;
  32.  
  33. /*  Get the directory containing the gle_* binaries */
  34.     s = getenv("GLE_TOP");
  35.     if (s!=NULL) {
  36.         strcpy(bindir,s);
  37.     } else {
  38.         strcpy(bindir,GLEBINS);
  39.     }
  40.     if (bindir[strlen(bindir)-1] != '/')
  41.         strcat(bindir,"/");
  42.  
  43.     if (argc<2) {
  44.       printf("Usage: gle filename.gle -ddevice\n");
  45.       printf("    gle test -dx    (Xwindows) \n");
  46.       printf("    gle test -dtek  (TEK4010) \n");
  47.       printf("    gle test -dhpgl (HP Plotters) \n");
  48.       printf("    gle test -dps   (PostScript) \n");
  49.       printf("    gle test -deps   (Encapsulated PostScript) \n");
  50.       printf("    gle test -depson [-hires] (For dot matrix printers) \n");
  51.       printf("    gle test -dlj [-hires] (For HP Laserjet printers) \n");
  52.       printf("    gle test -dpj [-hires] (For HP Paintjet printers) \n");
  53.       printf("    surface test.sur -dx (Surface utility) \n");
  54.       printf("    contour         (Contour plots) \n");
  55.       printf("    fitls           (Fit n variable equation to data)\n");
  56.       printf("    fitz            (Fits even surface to xyz data)\n");
  57.       printf("    letz            (Creates surface from eqn) \n");
  58.       printf("    manip test.dat  (Data editor) \n");
  59.       printf("To find out what drivers are available type in:\n");
  60.       printf("         ls %sgle_* \n", bindir);
  61.       printf(" \n");
  62.       return 0;
  63.     }
  64.  
  65. /*  Parse the arguments on the command line.
  66.     Options before device spec (-dxx) are put in gleoptions and those after
  67.       are put in devoptions.  This allows passing options to gle_dviprint.
  68. */
  69.     strcpy(device,"vt");
  70.     gotdevice = false;
  71.     for (i=1;i<argc;i++) {
  72.         if (strncmp(argv[i],"-d",2)==0) {
  73.         strcpy(device,argv[i]+2);
  74.         gotdevice = true;
  75.         }
  76.         else if (isalnum(*argv[i]))
  77.         strcpy(glefile,argv[i]);
  78.         else {
  79.         if (gotdevice) {
  80.             strcat(devoptions," ");
  81.             strcat(devoptions,argv[i]);
  82.         } else {
  83.             strcat(gleoptions," ");
  84.             strcat(gleoptions,argv[i]);
  85.         }
  86.         }
  87.     }
  88.  
  89. /*  Make the output file name */
  90.     strcpy(outfile,glefile);
  91.     s = strchr(outfile,'.');
  92.     if (s!=NULL) *s = 0;
  93.     strcat(outfile,".");
  94.  
  95. /*
  96.     if (strcmp(device,"lj")==0) {
  97.       strcat(outfile,"hp");
  98.     } else if (strcmp(device,"pj")==0) {
  99.       strcat(outfile,"hp");
  100.     } else if (strcmp(device,"epson")==0) {
  101.       strcat(outfile,"prn");
  102.     } else
  103. */
  104.       strcat(outfile,device);
  105.  
  106.     sprintf(buff,"%sgle_",bindir);           /* , GLEBINS); */
  107.     sprintf(bmpdev,"%sgle_dviprint",bindir);
  108.  
  109. /*  Do special stuff for the bitmapped devices (dvi) */
  110.     if (strcmp(device,"epson")==0) {
  111.       strcpy(device,"dvi");
  112.       strcat(bmpdev," -depson -out ");
  113.       strcat(bmpdev,outfile);
  114.       strcat(bmpdev,devoptions);
  115.     }
  116.     if (strcmp(device,"lj")==0) {
  117.       strcpy(device,"dvi");
  118.       strcat(bmpdev," -dlj -out ");
  119.       strcat(bmpdev,outfile);
  120.       strcat(bmpdev,devoptions);
  121.     }
  122.     if (strcmp(device,"bmptest")==0) {
  123.       strcpy(device,"dvi");
  124.       strcat(bmpdev," -dvt -out ");
  125.       strcat(bmpdev,outfile);
  126.       strcat(bmpdev,devoptions);
  127.     }
  128.     if (strcmp(device,"pj")==0) {
  129.       strcpy(device,"dvi");
  130.       strcat(bmpdev," -dpj -out ");
  131.       strcat(bmpdev,outfile);
  132.       strcat(bmpdev,devoptions);
  133.     }
  134.  
  135.     if (strcmp(device,"eps")==0) {
  136.       strcat(buff,"ps");
  137.       strcat(gleoptions," /eps");
  138.     } else {
  139.       strcat(buff,device);
  140.     }
  141.     strcat(buff," ");
  142.     strcat(buff,glefile);
  143.     strcat(buff," /output=");
  144.     strcat(buff,outfile);
  145.     strcat(buff,gleoptions);
  146.     if (strcmp(device,"dvi")!=0) {
  147.       strcat(buff,devoptions);
  148.     }
  149.     /*printf("%s\n",buff);*/
  150.  
  151. /*  Make the command script file glecmd.tmp */
  152.     f = fopen("glecmd.tmp","w");
  153.     fprintf(f,"echo %s\n",buff);
  154.     fprintf(f,"%s\n",buff);
  155.     if (strcmp(device,"dvi")==0) {
  156.      /* printf("%s\n",bmpdev); */
  157.       fprintf(f,"echo %s\n",bmpdev);
  158.       fprintf(f,"%s\n",bmpdev);
  159.     }
  160.     fclose(f);
  161.     if (chmod("glecmd.tmp",0x1ff)!=0)
  162.                printf("chmod +x failed on glecmd.tmp \n");
  163.     execlp("sh","sh","-c", "./glecmd.tmp",0);
  164. /*
  165.     execlp("sh","sh","-c", buff,0);
  166. */
  167. }
  168.  
  169.  
  170.  
  171.  
  172.