home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gcc / ixemulsrc.lha / ixemul / utils / ixrun.c < prev    next >
C/C++ Source or Header  |  1996-12-11  |  2KB  |  76 lines

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <proto/dos.h>
  5.  
  6. char VERSION[] = "\000$VER: ixrun 1.0 (10.11.95)";
  7.  
  8. static void usage(void)
  9. {
  10.   fprintf(stderr, "Usage: ixrun [-n | -q] filename [arguments...]
  11. -n\tdon't add quotes (\") around the arguments
  12. -q\tadd quotes (\") around the arguments (default)
  13. -nv\tas -n, but print the command line to standard error, don't execute it
  14. -qv\tas -q, but print the command line to standard error, don't execute it\n");
  15.   exit(1);
  16. }
  17.  
  18. main(int argc, char **argv)
  19. {
  20.   char *p;
  21.   long size, i, first_opt = 1, add_quotes = 2, debug = 0;
  22.  
  23.   if (argc == 1)
  24.     usage();
  25.   if (!strcmp(argv[1], "-q") || !strcmp(argv[1], "-qv"))
  26.   {
  27.     if (argc == 2)
  28.       usage();
  29.     first_opt++;
  30.     debug = !strcmp(argv[1], "-qv");
  31.   }
  32.   if (!strcmp(argv[1], "-n") || !strcmp(argv[1], "-nv"))
  33.   {
  34.     if (argc == 2)
  35.       usage();
  36.     add_quotes = 0;
  37.     first_opt++;
  38.     debug = !strcmp(argv[1], "-nv");
  39.   }
  40.   if (argv[first_opt][0] == '/' && (p = strchr(argv[first_opt] + 1, '/')))
  41.   {
  42.     *p = ':';
  43.     (argv[first_opt])++;
  44.   }
  45.   for (size = strlen(argv[first_opt]) + 1, i = first_opt + 1; argv[i]; i++)
  46.     size += strlen(argv[i]) + 1 + add_quotes;
  47.   p = malloc(size);
  48.   if (p == NULL)
  49.   {
  50.     fprintf(stderr, "couldn't allocate %d bytes\n", size);
  51.     exit(1);
  52.   }
  53.   strcpy(p, argv[first_opt]);
  54.   for (i = first_opt + 1; argv[i]; i++)
  55.   {
  56.     if (add_quotes)
  57.       strcat(p, " \"");
  58.     else
  59.       strcat(p, " ");
  60.     strcat(p, argv[i]);
  61.     if (add_quotes)
  62.       strcat(p, "\"");
  63.   }
  64.   if (debug)
  65.     fprintf(stderr, "command line = '%s'\n", p);
  66.   else
  67.   {
  68.     int result, omask;
  69.  
  70.     omask = sigsetmask(~0);
  71.     result = !Execute(p, NULL, NULL);
  72.     sigsetmask(omask);
  73.     exit(result);
  74.   }
  75. }
  76.