-/* stdin file number. */
-#define STDIN_FILE_NO 0
-
-/* stdout file number. */
-#define STDOUT_FILE_NO 1
-
-/* value of `pipe': port index for reading. */
-#define READ_PORT 0
-
-/* value of `pipe': port index for writing. */
-#define WRITE_PORT 1
-
-/* Pipe waiting from last process, to be used as input for the next one.
- Value is STDIN_FILE_NO if no pipe is waiting
- (i.e. the next command is the first of a group). */
-
-static int last_pipe_input;
-
-/* Fork one piped subcommand. FUNC is the system call to use
- (either execv or execvp). ARGV is the arg vector to use.
- NOT_LAST is nonzero if this is not the last subcommand
- (i.e. its output should be piped to the next one.) */
-
-#ifdef __MSDOS__
-
-#include <process.h>
-static int
-pexecute (search_flag, program, argv, not_last)
- int search_flag;
- char *program;
- char *argv[];
- int not_last;
-{
-#ifdef __GO32__
- int i = (search_flag ? spawnv : spawnvp) (1, program, argv);
-#else
- char *scmd, *rf;
- FILE *argfile;
- int i, el = search_flag ? 0 : 4;
-
- scmd = (char *)malloc (strlen (program) + strlen (temp_filename) + 6 + el);
- rf = scmd + strlen(program) + 2 + el;
- sprintf (scmd, "%s%s @%s.gp", program,
- (search_flag ? "" : ".exe"), temp_filename);
- argfile = fopen (rf, "w");
- if (argfile == 0)
- pfatal_with_name (rf);
-
- for (i=1; argv[i]; i++)
- {
- char *cp;
- for (cp = argv[i]; *cp; cp++)
- {
- if (*cp == '"' || *cp == '\'' || *cp == '\\' || isspace (*cp))
- fputc ('\\', argfile);
- fputc (*cp, argfile);
- }
- fputc ('\n', argfile);
- }
- fclose (argfile);
-
- i = system (scmd);
-
- remove (rf);
-#endif
-
- if (i == -1)
- {
- perror_exec (program);
- return MIN_FATAL_STATUS << 8;
- }
- return i << 8;
-}
-
-#endif
-
-#if !defined(__MSDOS__) && !defined(OS2) && !defined(WINNT)
-
-static int
-pexecute (search_flag, program, argv, not_last)
- int search_flag;
- char *program;
- char *argv[];
- int not_last;
-{
- int (*func)() = (search_flag ? execv : execvp);
- int pid;
- int pdes[2];
- int input_desc = last_pipe_input;
- int output_desc = STDOUT_FILE_NO;
- int retries, sleep_interval;
-
- /* If this isn't the last process, make a pipe for its output,
- and record it as waiting to be the input to the next process. */
-
- if (not_last)
- {
- if (pipe (pdes) < 0)
- pfatal_with_name ("pipe");
- output_desc = pdes[WRITE_PORT];
- last_pipe_input = pdes[READ_PORT];
- }
- else
- last_pipe_input = STDIN_FILE_NO;
-
- /* Fork a subprocess; wait and retry if it fails. */
- sleep_interval = 1;
- for (retries = 0; retries < 4; retries++)
- {
- pid = vfork ();
- if (pid >= 0)
- break;
- sleep (sleep_interval);
- sleep_interval *= 2;
- }
-
- switch (pid)
- {
- case -1:
-#ifdef vfork
- pfatal_with_name ("fork");
-#else
- pfatal_with_name ("vfork");
-#endif
- /* NOTREACHED */
- return 0;
-
- case 0: /* child */
- /* Move the input and output pipes into place, if nec. */
- if (input_desc != STDIN_FILE_NO)
- {
- close (STDIN_FILE_NO);
- dup (input_desc);
- close (input_desc);
- }
- if (output_desc != STDOUT_FILE_NO)
- {
- close (STDOUT_FILE_NO);
- dup (output_desc);
- close (output_desc);
- }
-
- /* Close the parent's descs that aren't wanted here. */
- if (last_pipe_input != STDIN_FILE_NO)
- close (last_pipe_input);
-
- /* Exec the program. */
- (*func) (program, argv);
- perror_exec (program);
- exit (-1);
- /* NOTREACHED */
- return 0;
-
- default:
- /* In the parent, after forking.
- Close the descriptors that we made for this child. */
- if (input_desc != STDIN_FILE_NO)
- close (input_desc);
- if (output_desc != STDOUT_FILE_NO)
- close (output_desc);
-
- /* Return child's process number. */
- return pid;
- }
-}
-
-#endif /* not __MSDOS__ and not OS2 and not WINNT */
-
-#if defined(OS2) || defined(WINNT)
-
-#ifdef WINNT
-
-/* This is a kludge to get around the Microsoft C spawn functions' propensity
- to remove the outermost set of double quotes from all arguments. */
-
-const char * const
-fix_argv (argvec)
- char **argvec;
-{
- int i;
-
- for (i = 1; argvec[i] != 0; i++)
- {
- int len, j;
- char *temp, *newtemp;
-
- temp = argvec[i];
- len = strlen (temp);
- for (j = 0; j < len; j++)
- {
- if (temp[j] == '"')
- {
- newtemp = xmalloc (len + 2);
- strncpy (newtemp, temp, j);
- newtemp [j] = '\\';
- strncpy (&newtemp [j+1], &temp [j], len-j);
- newtemp [len+1] = 0;
- free (temp);
- temp = newtemp;
- len++;
- j++;
- }
- }
-
- argvec[i] = temp;
- }
-
- return (const char* const*) argvec;
-}
-
-#define FIX_ARGV(a) fix_argv(a)
-
-#else
-
-#define FIX_ARGV(a) a
-
-#endif
-
-static int
-pexecute (search_flag, program, argv, not_last)
- int search_flag;
- char *program;
- char *argv[];
- int not_last;
-{
- return (search_flag ? spawnv : spawnvp) (1, program, FIX_ARGV (argv));
-}
-#endif /* OS2 or WINNT */
-
-\f