home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / languages / pascal / PTC / _PtC1 / driver__c < prev    next >
Encoding:
Text File  |  1991-03-02  |  2.2 KB  |  82 lines

  1. /*
  2.  *    this driver is for the new Acorn DDE -- it assumes
  3.  *    the parameter is a fully-qualified filename.  I'm
  4.  *    not allowed to release any DDE utilities yet (having
  5.  *    signed a non-disclosure agreement), but if you want
  6.  *    to use this file as a prototype for a driver you are
  7.  *    welcome to.
  8.  */
  9.  
  10.  
  11. #include <stdio.h>
  12. #include <ctype.h>
  13. #include <string.h>
  14. #include <stdarg.h>
  15. #include <stdlib.h>
  16.  
  17. void error(int rc) {
  18.   fprintf(stderr, "ptc: error %d\n", rc); exit(rc);
  19. }
  20.  
  21. int systemf(char *fmt,...)
  22. {
  23. static char comm[256];
  24. va_list argptr;
  25. int rc;
  26.  
  27.    va_start(argptr, fmt);
  28.    vsprintf(comm, fmt, argptr);
  29.    va_end(argptr);
  30.    fprintf(stderr, "PTC: %s", comm);
  31.    rc = (system(comm));
  32.    fprintf(stderr, " -> %d\n", rc);
  33.    return(rc);
  34. }
  35.  
  36. int main(int argc, char **argv) {
  37. char *cp, *leaf, *ptcargsp;
  38. char buff[256], infile[256], outfile[256],
  39.      outfile_c[256], outdir[256], ptcargs[256];
  40. int rc;
  41.  
  42.   if (argc != 3) error(1);
  43.   strcpy(infile, argv[1]);
  44.   strcpy(outfile, argv[2]);
  45.   if (strcmp(infile, outfile) != 0) error(2);
  46.   strcpy(buff, infile);
  47.   leaf = buff;
  48.   cp = strrchr(buff, '.');
  49.   if (cp == NULL) error(3);
  50.   *cp = '\0'; leaf = cp+1;
  51.   cp -= 2;
  52.   if (cp[0] == '.' && tolower(cp[1]) == 'p') {
  53.     *cp = '\0';
  54.   }
  55.   strcpy(outdir, buff);
  56.   sprintf(outfile, "%s.c.%s", outdir, leaf);
  57.   sprintf(outfile_c, "%s.%s.c", outdir, leaf);
  58.   ptcargsp = getenv("PTC$Args");
  59.   if (ptcargs != NULL) {
  60.     strcpy(ptcargs, ptcargsp);
  61.   } else {
  62.     strcpy(ptcargs,
  63.      "-J$.clib,<PTC$Dir> ptc:ptcerror.o ptc:argvgt.o ptc:fopen.o ptc:getl.o");
  64.   }
  65.   /*fprintf(stderr, "PTC: <ptc$args> = %s\n", ptcargs);*/
  66.   if (strcmp(leaf, "PTC") == 0) {
  67.     sprintf(ptcargs+strlen(ptcargs), " -o %s.!RunImage", outdir);
  68.   } else {
  69.     sprintf(ptcargs+strlen(ptcargs), " -o %s.%s", outdir, leaf);
  70.   }
  71.   systemf("cdir %s.c", outdir); 
  72.   systemf("cdir %s.h", outdir); 
  73.   if ((rc = systemf("<ptc$dir>.!RunImage < %s > %s", infile, outfile)) != 0) {
  74.     exit(rc);
  75.   }
  76.   systemf("<ptc$dir>.toansip %s > <ptc$dir>.temp", outfile);
  77.   systemf("<ptc$dir>.mkptypesp -e -s -A %s", outfile);
  78.   systemf("copy <ptc$dir>.temp %s f~q~c~vd", outfile);
  79.   systemf("CHAIN:ptccc %s %s", outfile_c, ptcargs);
  80.   return(0);
  81. }
  82.