home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / mfjobpat.zip / mfjob.c < prev    next >
C/C++ Source or Header  |  1994-11-18  |  2KB  |  75 lines

  1. #define MAXLEN    256
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <process.h>
  7. #ifdef __TURBOC__
  8. #include <dir.h>
  9. #else
  10. #include <io.h>
  11. #endif
  12.  
  13. #ifdef __TURBOC__
  14. int main(int argc, char **argv)
  15. #else
  16. int main(int argc, const char **argv)
  17. #endif
  18. {
  19.   FILE *infile, *outfile;
  20.   char line[MAXLEN], *c;
  21.   char emtexdir[MAXLEN], tfmdir[MAXLEN];
  22.   char tempname[MAXLEN] = "ndvXXXXX";
  23.   int  rc;
  24.  
  25.   if (argc <= 1)
  26.     {
  27.       printf("usage: mfjob <filename>\n");
  28.       return(1);
  29.     }
  30.   if (strstr(argv[1], "dv") || strstr(argv[1], "DV"))
  31.     {
  32.       strcpy(emtexdir, ((c = getenv("EMTEXDIR")) != NULL) ? c : "C:\\EMTEX");
  33.       if ((c = getenv("TEXTFM")) == NULL)
  34.         {
  35.           strcpy(tfmdir, emtexdir);
  36.           strcat(tfmdir, "\\TFM");
  37.         }
  38.       else
  39.         {
  40.           strcpy(tfmdir, c);
  41.           if ((c = strstr(tfmdir, ";")) != NULL)
  42.             *c = '\0';
  43.         }
  44.       mktemp(tempname);
  45.       strcat(tempname, ".mfj");
  46.       if ((infile = fopen(argv[1], "r")) == NULL)
  47.         {
  48.           printf("cannot open input file.\n");
  49.           return(1);
  50.         }
  51.       if ((outfile = fopen(tempname, "w")) == NULL)
  52.         {
  53.           printf("cannot open temporary file.\n");
  54.           return(1);
  55.         }
  56.       while (fgets(line, MAXLEN, infile))
  57.         {
  58.           fputs(line, outfile);
  59.           if (strnicmp("output", line, 6) == 0)
  60.             {
  61.               sprintf(line, "output=tfm[%s\\@f];\n", tfmdir);
  62.               fputs(line, outfile);
  63.             }
  64.         }
  65.       fclose(infile);
  66.       fclose(outfile);
  67.       argv[1] = tempname;
  68.     }
  69.   argv[0] = "mfjob.org";
  70.   rc = spawnvp(P_WAIT, argv[0], argv);
  71.   if (argv[1] == tempname)
  72.     remove(tempname);
  73.   return(rc);
  74. }
  75.