1 /*
2  * Copyright 1993, 1995 Christopher Seiwald.
3  *
4  * This file is part of Jam - see jam.c for Copyright information.
5  */
6 
7 /*
8  * execcmd.h - execute a shell script.
9  *
10  * Defines the interface to be implemented in platform specific implementation
11  * modules as well as different shared utility functions prepared in the
12  * execcmd.c module.
13  */
14 
15 #ifndef EXECCMD_H
16 #define EXECCMD_H
17 
18 #include "config.h"
19 #include "lists.h"
20 #include "strings.h"
21 #include "timestamp.h"
22 
23 
24 typedef struct timing_info
25 {
26     double system;
27     double user;
28     timestamp start;
29     timestamp end;
30 } timing_info;
31 
32 typedef void (* ExecCmdCallback)
33 (
34     void * const closure,
35     int const status,
36     timing_info const * const,
37     char const * const cmd_stdout,
38     char const * const cmd_stderr,
39     int const cmd_exit_reason
40 );
41 
42 /* Global initialization.  Must be called after setting
43  * globs.jobs.  May be called multiple times. */
44 void exec_init( void );
45 /* Global cleanup */
46 void exec_done( void );
47 
48 /* Status codes passed to ExecCmdCallback routines. */
49 #define EXEC_CMD_OK    0
50 #define EXEC_CMD_FAIL  1
51 #define EXEC_CMD_INTR  2
52 
53 int exec_check
54 (
55     string const * command,
56     LIST * * pShell,
57     int * error_length,
58     int * error_max_length
59 );
60 
61 /* exec_check() return codes. */
62 #define EXEC_CHECK_OK             101
63 #define EXEC_CHECK_NOOP           102
64 #define EXEC_CHECK_LINE_TOO_LONG  103
65 #define EXEC_CHECK_TOO_LONG       104
66 
67 /* Prevents action output from being written
68  * immediately to stdout/stderr.
69  */
70 #define EXEC_CMD_QUIET 1
71 
72 void exec_cmd
73 (
74     string const * command,
75     int flags,
76     ExecCmdCallback func,
77     void * closure,
78     LIST * shell
79 );
80 
81 void exec_wait();
82 
83 
84 /******************************************************************************
85  *                                                                            *
86  * Utility functions defined in the execcmd.c module.                         *
87  *                                                                            *
88  ******************************************************************************/
89 
90 /* Constructs a list of command-line elements using the format specified by the
91  * given shell list.
92  */
93 void argv_from_shell( char const * * argv, LIST * shell, char const * command,
94     int const slot );
95 
96 /* Interrupt routine bumping the internal interrupt counter. Needs to be
97  * registered by platform specific exec*.c modules.
98  */
99 void onintr( int disp );
100 
101 /* Returns whether an interrupt has been detected so far. */
102 int interrupted( void );
103 
104 /* Checks whether the given shell list is actually a request to execute raw
105  * commands without an external shell.
106  */
107 int is_raw_command_request( LIST * shell );
108 
109 /* Utility worker for exec_check() checking whether all the given command lines
110  * are under the specified length limit.
111  */
112 int check_cmd_for_too_long_lines( char const * command, int const max,
113     int * const error_length, int * const error_max_length );
114 
115 #endif
116