1 /* $Header: os2.c,v 3.0.1.1 90/10/15 17:49:55 lwall Locked $
3 * (C) Copyright 1989, 1990 Diomidis Spinellis.
5 * You may distribute under the terms of the GNU General Public License
6 * as specified in the README file that comes with the perl 3.0 kit.
9 * Revision 3.0.1.1 90/10/15 17:49:55 lwall
10 * patch29: Initial revision
12 * Revision 3.0.1.1 90/03/27 16:10:41 lwall
13 * patch16: MSDOS support
15 * Revision 1.1 90/03/18 20:32:01 dds
25 * Various Unix compatibility functions for OS/2
38 int ioctl(int handle, unsigned int function, char *data)
52 if ( path[0] != 0 && path[1] == ':' )
53 DosSelectDisk(tolower(path[0]) - '@');
61 int setpriority(int class, int pid, int val)
71 return DosSetPrty(flag ? PRTYS_PROCESSTREE : PRTYS_PROCESS, class, val, pid);
74 int getpriority(int which /* ignored */, int pid)
78 if ( DosGetPrty(PRTYS_PROCESS, &val, pid) )
85 /* get parent process id */
98 int kill(int pid, int sig)
112 DosKillProcess(flag ? DKP_PROCESSTREE : DKP_PROCESS, pid);
116 DosFlagProcess(pid, flag ? FLGP_SUBTREE : FLGP_PID, PFLG_A, 0);
120 DosFlagProcess(pid, flag ? FLGP_SUBTREE : FLGP_PID, PFLG_B, 0);
124 DosFlagProcess(pid, flag ? FLGP_SUBTREE : FLGP_PID, PFLG_C, 0);
131 /* Sleep function. */
135 DosSleep(len * 1000L);
138 /* Just pretend that everyone is a superuser */
159 * The following code is based on the do_exec and do_aexec functions
163 do_aspawn(really,arglast)
167 register STR **st = stack->ary_array;
168 register int sp = arglast[1];
169 register int items = arglast[2] - sp;
176 New(1101,argv, items+1, char*);
178 for (st += ++sp; items > 0; items--,st++) {
185 if (really && *(tmps = str_get(really)))
186 status = spawnvp(P_WAIT,tmps,argv);
188 status = spawnvp(P_WAIT,argv[0],argv);
194 char *getenv(char *name);
207 /* save an extra exec if possible */
208 if ((shell = getenv("COMSPEC")) == 0)
209 shell = "C:\\OS2\\CMD.EXE";
211 /* see if there are shell metacharacters in it */
212 if (strchr(cmd, '>') || strchr(cmd, '<') || strchr(cmd, '|')
213 || strchr(cmd, '&') || strchr(cmd, '^'))
215 return spawnl(P_WAIT,shell,shell,"/C",cmd,(char*)0);
217 New(1102,argv, strlen(cmd) / 2 + 2, char*);
219 New(1103,cmd2, strlen(cmd) + 1, char);
222 for (s = cmd2; *s;) {
223 while (*s && isspace(*s)) s++;
226 while (*s && !isspace(*s)) s++;
232 if ((status = spawnvp(P_WAIT,argv[0],argv)) == -1) {
245 printf("\nUsage: %s [-acdnpsSvw] [-Dnumber] [-i[extension]] [-Idirectory]"
247 printf("\nUsage: %s [-acdnpPsSuUvw] [-Dnumber] [-i[extension]] [-Idirectory]"
249 "\n [-e \"command\"] [-x[directory]] [filename] [arguments]\n", myname);
251 printf("\n -a autosplit mode with -n or -p"
252 "\n -c syntaxcheck only"
253 "\n -d run scripts under debugger"
254 "\n -n assume 'while (<>) { ...script... }' loop arround your script"
255 "\n -p assume loop like -n but print line also like sed"
257 "\n -P run script through C preprocessor befor compilation"
259 "\n -s enable some switch parsing for switches after script name"
260 "\n -S look for the script using PATH environment variable");
262 printf("\n -u dump core after compiling the script"
263 "\n -U allow unsafe operations");
265 printf("\n -v print version number and patchlevel of perl"
266 "\n -w turn warnings on for compilation of your script\n"
267 "\n -Dnumber set debugging flags"
268 "\n -i[extension] edit <> files in place (make backup if extension supplied)"
269 "\n -Idirectory specify include directory in conjunction with -P"
270 "\n -e command one line of script, multiple -e options are allowed"
271 "\n [filename] can be ommitted, when -e is used"
272 "\n -x[directory] strip off text before #!perl line and perhaps cd to directory\n");