/* Cut down imp driver */

#include <stdio.h>
#include <stdlib.h>
#define TRUE (0==0)
#define FALSE (0!=0)
int main(int argc, char **argv) {
  char *src;
  char command[1024];
  int l;
  int nolink = FALSE;
  if (argc == 1) {
    exit(0);
  }
  if (argc == 2) {
    src = argv[1];
  } else if (argc == 3) {
    if (strcmp(argv[1], "-c") != 0) {
      exit(1);
    }
    nolink = TRUE;
    src = argv[2];
  } else {
  }
  l = strlen(src);
  if ((src[l-1] == 'i') && (src[l-2] == '.')) {
    src[l-2] = '\0';
  }
  if (nolink) {
    sprintf(command, "/bin/csh -c 'p5impcompiler -O %s.i MAP,PPRO,NOTRACE,NOLINE,NOARRAY,NODIAG,NOCHECK,MAXDICT,MAXWORK'\n",
      src);
  } else {
    sprintf(command, "/bin/csh -c 'p5impcompiler -O %s.i MAP,PPRO,NOTRACE,NOLINE,NOARRAY,NODIAG,NOCHECK,MAXDICT,MAXWORK; gcc -o %s %s.o -limp2'\n",
      src, src, src);
    /* |&grep -v s_auxstdata */
  }
  system(command);
  exit(0);
}
