home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / elvis_1.4.tar.Z / elvis_1.4.tar / alias.c next >
C/C++ Source or Header  |  1990-12-06  |  2KB  |  103 lines

  1. /* alias.c */
  2.  
  3. /* Author:
  4.  *        Peter Reinig
  5.  *        Universitaet Kaiserslautern
  6.  *        Postfach 3049
  7.  *        7650 Kaiserslautern
  8.  *        W. Germany
  9.  *        reinig@physik.uni-kl.de
  10.  */
  11.  
  12. /* This tiny program executes elvis with the flags that are appropriate
  13.  * for a given command name.  This program is used only on systems that
  14.  * don't allow UNIX-style file links.
  15.  *
  16.  * The benefit of this program is: instead of having 5 copies of elvis
  17.  * on your disk, you only need one copy of elvis and 4 copies of this
  18.  * little program.
  19.  */
  20.  
  21. #include <stdio.h>
  22. #include "config.h"
  23.  
  24. #if OSK
  25. #define ELVIS    "/dd/usr/cmds/elvis"
  26. #else
  27. #define ELVIS    "elvis"
  28. #endif
  29.  
  30. extern char **environ;
  31. extern int errno;
  32. extern char *malloc();
  33.  
  34. main(argc, argv)
  35.     int    argc;
  36.     char    *argv[];
  37. {
  38.     int    pid, i, j;
  39.     int    letter;
  40.     char    **argblk;
  41. #if OSK
  42.     extern int chainc();
  43. #endif
  44.  
  45.     /* allocate enough space for a copy of the argument list, plus a
  46.      * terminating NULL, plus maybe an added flag.
  47.      */
  48.     argblk = (char **) malloc((argc + 2) * sizeof(char *));
  49.     if (!argblk)
  50.     {
  51. #if OSK
  52.         _errmsg(errno, "Can't get enough memory\n");
  53. #else
  54.         perror(argv[0]);
  55. #endif
  56.         exit(2);
  57.     }
  58.  
  59.     /* find the last letter in the invocation name of this program */
  60.     i = strlen(argv[0]);
  61. #if MSDOS || TOS
  62.     /* we almost certainly must bypass ".EXE" or ".TTP" from argv[0] */
  63.     if (i > 4 && argv[0][i - 4] == '.')
  64.         i -= 4;
  65. #endif
  66.     letter = argv[0][i - 1];
  67.  
  68.     /* copy argv to argblk, possibly inserting a flag such as "-R" */
  69.     argblk[0] = ELVIS;
  70.     i = j = 1;
  71.     switch (letter)
  72.     {
  73.       case 'w':            /* "view" */
  74.       case 'W':
  75.         argblk[i++] = "-R";
  76.         break;
  77. #if !OSK
  78.       case 'x':            /* "ex" */
  79.       case 'X':
  80.         argblk[i++] = "-e";
  81.         break;
  82. #endif
  83.       case 't':            /* "input" */
  84.       case 'T':
  85.         argblk[i++] = "-i";
  86.         break;
  87.     }
  88.     while (j < argc)
  89.     {
  90.         argblk[i++] = argv[j++];
  91.     }
  92.     argblk[i] = (char *)0;
  93.  
  94.     /* execute the real ELVIS program */
  95. #if OSK
  96.     pid = os9exec(chainc, argblk[0], argblk, environ, 0, 0, 3);
  97.     fprintf(stderr, "%s: cannot execute\n", argblk[0]);
  98. #else
  99.     (void)execvp(argblk[0], argblk);
  100.     perror(ELVIS);
  101. #endif
  102. }
  103.