1 /* $RCSfile: os2.c,v $$Revision: 4.0.1.2 $$Date: 92/06/08 14:32:30 $
3 * (C) Copyright 1989, 1990 Diomidis Spinellis.
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
9 * Revision 4.0.1.2 92/06/08 14:32:30 lwall
10 * patch20: new OS/2 support
12 * Revision 4.0.1.1 91/06/07 11:23:06 lwall
13 * patch4: new copyright notice
15 * Revision 4.0 91/03/20 01:36:21 lwall
18 * Revision 3.0.1.2 90/11/10 01:42:38 lwall
19 * patch38: more msdos/os2 upgrades
21 * Revision 3.0.1.1 90/10/15 17:49:55 lwall
22 * patch29: Initial revision
24 * Revision 3.0.1.1 90/03/27 16:10:41 lwall
25 * patch16: MSDOS support
27 * Revision 1.1 90/03/18 20:32:01 dds
37 * Various Unix compatibility functions for OS/2
50 int ioctl(int handle, unsigned int function, char *data)
60 /* extended chdir() */
64 if ( path[0] != 0 && path[1] == ':' )
65 if ( DosSelectDisk(toupper(path[0]) - '@') )
68 return DosChDir(path, 0L);
74 int setpriority(int class, int pid, int val)
84 return DosSetPrty(flag ? PRTYS_PROCESSTREE : PRTYS_PROCESS, class, val, pid);
87 int getpriority(int which /* ignored */, int pid)
91 if ( DosGetPrty(PRTYS_PROCESS, &val, pid) )
98 /* get parent process id */
109 /* wait for specific pid */
110 int wait4pid(int pid, int *status, int flags)
114 if ( DosCwait(DCWA_PROCESS, flags ? DCWW_NOWAIT : DCWW_WAIT,
115 &res, &endpid, pid) )
117 *status = res.codeResult;
122 int kill(int pid, int sig)
136 DosKillProcess(flag ? DKP_PROCESSTREE : DKP_PROCESS, pid);
140 DosFlagProcess(pid, flag ? FLGP_SUBTREE : FLGP_PID, PFLG_A, 0);
144 DosFlagProcess(pid, flag ? FLGP_SUBTREE : FLGP_PID, PFLG_B, 0);
148 DosFlagProcess(pid, flag ? FLGP_SUBTREE : FLGP_PID, PFLG_C, 0);
155 /* Sleep function. */
159 DosSleep(len * 1000L);
162 /* Just pretend that everyone is a superuser */
183 * The following code is based on the do_exec and do_aexec functions
187 do_aspawn(really,arglast)
191 register STR **st = stack->ary_array;
192 register int sp = arglast[1];
193 register int items = arglast[2] - sp;
200 New(1101,argv, items+1, char*);
202 for (st += ++sp; items > 0; items--,st++) {
209 if (really && *(tmps = str_get(really)))
210 status = spawnvp(P_WAIT,tmps,argv);
212 status = spawnvp(P_WAIT,argv[0],argv);
218 char *getenv(char *name);
231 /* save an extra exec if possible */
232 if ((shell = getenv("COMSPEC")) == 0)
233 shell = "C:\\OS2\\CMD.EXE";
235 /* see if there are shell metacharacters in it */
236 if (strchr(cmd, '>') || strchr(cmd, '<') || strchr(cmd, '|')
237 || strchr(cmd, '&') || strchr(cmd, '^'))
239 return spawnl(P_WAIT,shell,shell,"/C",cmd,(char*)0);
241 New(1102,argv, strlen(cmd) / 2 + 2, char*);
243 New(1103,cmd2, strlen(cmd) + 1, char);
246 for (s = cmd2; *s;) {
247 while (*s && isspace(*s)) s++;
250 while (*s && !isspace(*s)) s++;
256 if ((status = spawnvp(P_WAIT,argv[0],argv)) == -1) {
269 printf("\nUsage: %s [-acdnpPsSvw] [-0[octal]] [-Dnumber] [-i[extension]] [-Idirectory]"
271 printf("\nUsage: %s [-acdnpPsSuUvw] [-Dnumber] [-i[extension]] [-Idirectory]"
273 "\n [-e \"command\"] [-x[directory]] [filename] [arguments]\n", myname);
275 printf("\n -a autosplit mode with -n or -p"
276 "\n -c syntaxcheck only"
277 "\n -d run scripts under debugger"
278 "\n -n assume 'while (<>) { ...script... }' loop arround your script"
279 "\n -p assume loop like -n but print line also like sed"
280 "\n -P run script through C preprocessor befor compilation"
281 "\n -s enable some switch parsing for switches after script name"
282 "\n -S look for the script using PATH environment variable");
284 printf("\n -u dump core after compiling the script"
285 "\n -U allow unsafe operations");
287 printf("\n -v print version number and patchlevel of perl"
288 "\n -w turn warnings on for compilation of your script\n"
289 "\n -0[octal] specify record separator (0, if no argument)"
290 "\n -Dnumber set debugging flags (argument is a bit mask)"
291 "\n -i[extension] edit <> files in place (make backup if extension supplied)"
292 "\n -Idirectory specify include directory in conjunction with -P"
293 "\n -e command one line of script, multiple -e options are allowed"
294 "\n [filename] can be ommitted, when -e is used"
295 "\n -x[directory] strip off text before #!perl line and perhaps cd to directory\n");