2 * REDIR.C - redirection handling.
7 * 12/15/95 (Tim Norman)
10 * 12 Jul 98 (Hans B Pufal)
11 * Rewrote to make more efficient and to conform to new command.c
12 * and batch.c processing.
14 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
15 * Added config.h include
17 * 22-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
19 * Added new error redirection "2>" and "2>>".
21 * 26-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
22 * Added new error AND output redirection "&>" and "&>>".
25 #define WIN32_LEAN_AND_MEAN
29 #ifdef FEATURE_REDIRECTION
40 IsRedirection (TCHAR c
)
42 return (c
== _T('<')) || (c
== _T('>')) || (c
== _T('|'));
47 * Gets the redirection info from the command line and copies the
48 * file names into ifn, ofn and efn removing them from the command
51 * Converts remaining command line into a series of null terminated
52 * strings defined by the pipe char '|'. Each string corresponds
53 * to a single executable command. A double null terminates the
56 * Return number of command strings found.
60 INT
GetRedirection (LPTSTR s
, LPTSTR ifn
, LPTSTR ofn
, LPTSTR efn
, LPINT lpnFlags
)
66 /* find and remove all the redirections first */
69 if ((*sp
== _T('"')) || (*sp
== _T('\'')))
71 /* No redirects inside quotes */
80 else if ((*sp
== _T('<')) || (*sp
== _T('>')) ||
81 (*sp
== _T('2')) || (*sp
== _T('&')))
83 /* MS-DOS ignores multiple redirection symbols and uses the last */
84 /* redirection, so we'll emulate that and not check */
88 /* input redirection */
89 *lpnFlags
|= INPUT_REDIRECTION
;
90 while (_istspace (*sp
))
94 while (*sp
&& !IsRedirection (*sp
) && !_istspace (*sp
))
98 else if (*sp
== _T('>'))
100 /* output redirection */
101 *lpnFlags
|= OUTPUT_REDIRECTION
;
104 /* append request ? */
107 *lpnFlags
|= OUTPUT_APPEND
;
111 while (_istspace (*sp
))
115 while (*sp
&& !IsRedirection (*sp
) && !_istspace (*sp
))
119 else if (*sp
== _T('2'))
121 /* error redirection */
126 *lpnFlags
|= ERROR_REDIRECTION
;
129 /* append request ? */
132 *lpnFlags
|= ERROR_APPEND
;
138 /* no redirection!! copy the '2' character! */
144 while (_istspace (*sp
))
148 while (*sp
&& !IsRedirection (*sp
) && !_istspace (*sp
))
152 else if (*sp
== _T('&'))
154 /* output AND error redirection */
159 *lpnFlags
|= (ERROR_REDIRECTION
| OUTPUT_REDIRECTION
);
162 /* append request ? */
165 *lpnFlags
|= (ERROR_APPEND
| OUTPUT_APPEND
);
171 /* no redirection!! copy the '&' character! */
177 while (_istspace (*sp
))
181 while (*sp
&& !IsRedirection (*sp
) && !_istspace (*sp
))
182 *ofn
++ = *efn
++ = *sp
++;
183 *ofn
= *efn
= _T('\0');
192 /* now go for the pipes */
196 if ((*sp
== _T('"')) || (*sp
== _T('\'')))
206 else if (*sp
== _T('|'))
218 #endif /* FEATURE_REDIRECTION */