1 /* Utilities to execute a program in a subprocess (possibly linked by pipes
2 with other subprocesses), and wait for it. MPW specialization.
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003
4 Free Software Foundation, Inc.
6 This file is part of the libiberty library.
7 Libiberty is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 Libiberty is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with libiberty; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #include "pex-common.h"
29 /* MPW pexecute doesn't actually run anything; instead, it writes out
30 script commands that, when run, will do the actual executing.
32 For example, in GCC's case, GCC will write out several script commands:
39 and then exit. None of the above programs will have run yet. The task
40 that called GCC will then execute the script and cause cpp,etc. to run.
41 The caller must invoke pfinish before calling exit. This adds
42 the finishing touches to the generated script. */
44 static int first_time
= 1;
46 extern void mpwify_filename
PARAMS ((const char *, char *));
49 pexecute (program
, argv
, this_pname
, temp_base
, errmsg_fmt
, errmsg_arg
, flags
)
52 const char *this_pname
;
53 const char *temp_base
;
54 char **errmsg_fmt
, **errmsg_arg
;
61 mpwify_filename (program
, tmpprogram
);
64 printf ("Set Failed 0\n");
68 fputs ("If {Failed} == 0\n", stdout
);
69 /* If being verbose, output a copy of the command. It should be
70 accurate enough and escaped enough to be "clickable". */
71 if (flags
& PEXECUTE_VERBOSE
)
73 fputs ("\tEcho ", stdout
);
75 fputs (tmpprogram
, stdout
);
78 for (i
=1; argv
[i
]; i
++)
81 /* See if we have an argument that needs fixing. */
82 if (strchr(argv
[i
], '/'))
84 tmpname
= (char *) xmalloc (256);
85 mpwify_filename (argv
[i
], tmpname
);
88 for (cp
= argv
[i
]; *cp
; cp
++)
90 /* Write an Option-d escape char in front of special chars. */
91 if (strchr("'+", *cp
))
92 fputc ('\266', stdout
);
100 fputs ("\t", stdout
);
101 fputs (tmpprogram
, stdout
);
104 for (i
=1; argv
[i
]; i
++)
106 /* See if we have an argument that needs fixing. */
107 if (strchr(argv
[i
], '/'))
109 tmpname
= (char *) xmalloc (256);
110 mpwify_filename (argv
[i
], tmpname
);
113 if (strchr (argv
[i
], ' '))
114 fputc ('\'', stdout
);
115 for (cp
= argv
[i
]; *cp
; cp
++)
117 /* Write an Option-d escape char in front of special chars. */
118 if (strchr("'+", *cp
))
119 fputc ('\266', stdout
);
122 if (strchr (argv
[i
], ' '))
123 fputc ('\'', stdout
);
127 fputs ("\n", stdout
);
129 /* Output commands that arrange to clean up and exit if a failure occurs.
130 We have to be careful to collect the status from the program that was
131 run, rather than some other script command. Also, we don't exit
132 immediately, since necessary cleanups are at the end of the script. */
133 fputs ("\tSet TmpStatus {Status}\n", stdout
);
134 fputs ("\tIf {TmpStatus} != 0\n", stdout
);
135 fputs ("\t\tSet Failed {TmpStatus}\n", stdout
);
136 fputs ("\tEnd\n", stdout
);
137 fputs ("End\n", stdout
);
139 /* We're just composing a script, can't fail here. */
144 pwait (pid
, status
, flags
)
153 /* Write out commands that will exit with the correct error code
154 if something in the script failed. */
159 printf ("\tExit \"{Failed}\"\n");
This page took 0.032146 seconds and 4 git commands to generate.