Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 142 lines (124 sloc) 3.546 kb
63353867 »
2011-12-10 Import Elvis 1.8 (written by Steve Kirkendall)
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
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
10 *
11 * adapted for IBM's OS/2 compiler by herbert
12 * tweaked for DOS/Win32/OS2 portability by Steve Kirkendall
63353867 »
2011-12-10 Import Elvis 1.8 (written by Steve Kirkendall)
13 */
14
15 /* This tiny program executes elvis with the flags that are appropriate
16 * for a given command name. This program is used only on systems that
17 * don't allow UNIX-style file links.
18 *
19 * The benefit of this program is: instead of having 5 copies of elvis
20 * on your disk, you only need one copy of elvis and 4 copies of this
21 * little program.
22 */
23
24 #include <stdio.h>
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
25 #include <string.h>
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
26 #include <stdlib.h>
27 #include <process.h>
28 #include <io.h>
29 #include "osdef.h"
30
31 /* This is the name of the real elvis program, with the directory name or
32 * the ".exe" extension.
33 */
63353867 »
2011-12-10 Import Elvis 1.8 (written by Steve Kirkendall)
34 #define ELVIS "elvis"
35
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
36 /* These are alternative names. You can use these with -DARGV0=... */
37 #define VI "vi"
38 #define EX "ex"
39 #define VIEW "view"
40 #define INPUT "input"
41
42 /* if the shell doesn't set argv[0] to the program name, then argv[0] will
43 * be set to this value. Usually this value is set by compiling elvis with
44 * -DARGV0=EX or something like that, so this is just the default.
45 */
46 #ifndef ARGV0
47 # define ARGV0 VI
48 #endif
49
97d89980 »
2011-12-10 Import Elvis 2.1_4 (written by Steve Kirkendall)
50 /* Win32 seems to have developed an inability to exec() correctly. The shell
51 * thinks the program has exited when in fact it has merely exec'ed some
52 * other function. This messes up the ex/vi/view aliases for elvis. To work
53 * around it, we SPAWN elvis and wait for it to return before the alias exits.
54 * This wastes a little memory, but at least it works.
55 */
56 #if _MSC_VER >= 900 /* 32-bit compiler for Windows */
57 # define execvp(p,a) (i = _spawnvp(_P_WAIT, p,a)); if (i >= 0) exit(i);
58 #endif
59
60
61
63353867 »
2011-12-10 Import Elvis 1.8 (written by Steve Kirkendall)
62 main(argc, argv)
63 int argc;
64 char *argv[];
65 {
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
66 int i, j;
63353867 »
2011-12-10 Import Elvis 1.8 (written by Steve Kirkendall)
67 int letter;
68 char **argblk;
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
69 char fullelvis[256];
70 char *scan;
63353867 »
2011-12-10 Import Elvis 1.8 (written by Steve Kirkendall)
71
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
72 /* if argv[0] isn't set, then set it now */
73 if (!argv[0])
74 argv[0] = ARGV0;
75
63353867 »
2011-12-10 Import Elvis 1.8 (written by Steve Kirkendall)
76 /* allocate enough space for a copy of the argument list, plus a
77 * terminating NULL, plus maybe an added flag.
78 */
79 argblk = (char **) malloc((argc + 2) * sizeof(char *));
80 if (!argblk)
81 {
82 perror(argv[0]);
83 exit(2);
84 }
85
86 /* find the last letter in the invocation name of this program */
87 /* we almost certainly must bypass ".EXE" or ".TTP" from argv[0] */
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
88 i = strlen(argv[0]);
63353867 »
2011-12-10 Import Elvis 1.8 (written by Steve Kirkendall)
89 if (i > 4 && argv[0][i - 4] == '.')
90 i -= 4;
91 letter = argv[0][i - 1];
92
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
93 /* find the name of elvis. First try looking for ELVIS.EXE in the
94 * same directory as the VI.EXE file. If that doesn't work, then
95 * just call it ELVIS and hope that it can be found somewhere in the
96 * execution path.
97 */
98 strcpy(fullelvis, argv[0]);
99 scan = strrchr(fullelvis, '\\');
100 if (scan)
101 {
102 for (scan++, j = 0; ELVIS[j]; )
103 *scan++ = ELVIS[j++];
104 while (i >= 0 && argv[0][i])
105 *scan++ = argv[0][i++];
106 *scan = '\0';
107 if (access(fullelvis, 0) != 0)
108 strcpy(fullelvis, ELVIS);
109 }
8d1ac0c1 »
2011-12-10 Import Elvis 2.1 (written by Steve Kirkendall)
110 else /* no path information in argv[0], try to load via PATH */
111 strcpy(fullelvis, ELVIS);
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
112
63353867 »
2011-12-10 Import Elvis 1.8 (written by Steve Kirkendall)
113 /* copy argv to argblk, possibly inserting a flag such as "-R" */
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
114 argblk[0] = fullelvis;
63353867 »
2011-12-10 Import Elvis 1.8 (written by Steve Kirkendall)
115 i = j = 1;
116 switch (letter)
117 {
118 case 'w': /* "view" */
119 case 'W':
120 argblk[i++] = "-R";
121 break;
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
122
63353867 »
2011-12-10 Import Elvis 1.8 (written by Steve Kirkendall)
123 case 'x': /* "ex" */
124 case 'X':
125 argblk[i++] = "-e";
126 break;
cf92e3be »
2011-12-10 Import Elvis 2.0 (written by Steve Kirkendall)
127
63353867 »
2011-12-10 Import Elvis 1.8 (written by Steve Kirkendall)
128 case 't': /* "input" */
129 case 'T':
130 argblk[i++] = "-i";
131 break;
132 }
133 while (j < argc)
134 {
135 argblk[i++] = argv[j++];
136 }
137 argblk[i] = (char *)0;
138
139 /* execute the real ELVIS program */
140 (void)execvp(argblk[0], argblk);
141 perror(ELVIS);
142 }
Something went wrong with that request. Please try again.