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