File: execmd.c

package info (click to toggle)
icmake 6.22-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,120 kB
  • ctags: 1,045
  • sloc: ansic: 9,241; makefile: 1,138; asm: 126; sh: 124
file content (71 lines) | stat: -rw-r--r-- 1,803 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
\funcref{execmd}{char $**$execmd (\params)}
    {
        {char} {**cmd} {{\em argv}-like array of command}
        {int} {mode} {execution mode}
    }
    {spawn\_err(), error()}
    {fun\_exec()}
    {execmd.c}
    {

        This function is called from {\em fun\_exec()} to execute a command.
        The command is held in the {\em argv}-like array {\em cmd}. The same
        array is returned, since {\em execmd()} may have to resize it to add a
        command tail.

        The return register is set to the exit status of the program.

        The maker aborts when:

        \begin{itemize}

            \item the indicated program cannot not be executed,

            \item the indicated program can be executed but returns a
            non-zero exit status while the execution mode allows checking.

        \end{itemize}

        {\bf Note that} the strings pointed to by the {\em cmd} array are not
        freed.
    }
*/

#include "icm-exec.h"

char **execmd (cmd, mode)
char **cmd;
int mode;
{
    register int
        i,
        ret;					/* exit status */
 
    if (strlen (cmdtail))			/* add cmd tail */
        cmd = addcmd (cmd, cmdtail);

    if (echo)					/* re-echo if requested */
    {
        for (i = 0; cmd [i]; i++)
            printf ("%s ", cmd [i]);
        putchar ('\n');
    }
    fflush (stdout);
    
#ifdef MSDOS    
    _heapmin ();				/* max memory under DOS */
#endif    

						/* try to execute */
    ret = _spawnvp (P_WAIT, cmd [0], (const char **) cmd);
    
    						/* if non-zero return and */
    if (ret && P_CHECKMODE (mode))		/* if checking requested.. */
        error ("execute - program indicates failure (status %d)", ret);

    reg.type = e_int;				/* return exit status */
    reg.vu.intval = ret;			/* as e_int */

    return (cmd);
}