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 "&>>".
27 #ifdef FEATURE_REDIRECTION
38 IsRedirection (TCHAR c)
40 return (c == _T('<')) || (c == _T('>')) || (c == _T('|'));
45 * Gets the redirection info from the command line and copies the
46 * file names into ifn, ofn and efn removing them from the command
49 * Converts remaining command line into a series of null terminated
50 * strings defined by the pipe char '|'. Each string corresponds
51 * to a single executable command. A double null terminates the
54 * Return number of command strings found.
58 INT GetRedirection (LPTSTR s, LPTSTR ifn, LPTSTR ofn, LPTSTR efn, LPINT lpnFlags)
64 /* find and remove all the redirections first */
67 if ((*sp == _T('"')) || (*sp == _T('\'')))
69 /* No redirects inside quotes */
74 while (*sp && *sp != qc);
78 else if ((*sp == _T('<')) || (*sp == _T('>')) ||
79 (*sp == _T('2')) || (*sp == _T('&')))
81 /* MS-DOS ignores multiple redirection symbols and uses the last */
82 /* redirection, so we'll emulate that and not check */
86 /* input redirection */
87 *lpnFlags |= INPUT_REDIRECTION;
89 while( _istspace (*sp) );
92 while (*sp && !IsRedirection (*sp) && !_istspace (*sp))
96 else if (*sp == _T('>'))
98 /* output redirection */
99 *lpnFlags |= OUTPUT_REDIRECTION;
102 /* append request ? */
105 *lpnFlags |= OUTPUT_APPEND;
109 while (_istspace (*sp))
113 while (*sp && !IsRedirection (*sp) && !_istspace (*sp))
117 else if (*sp == _T('2'))
119 /* error redirection */
124 *lpnFlags |= ERROR_REDIRECTION;
127 /* append request ? */
130 *lpnFlags |= ERROR_APPEND;
136 /* no redirection!! copy the '2' character! */
142 while (_istspace (*sp))
146 while (*sp && !IsRedirection (*sp) && !_istspace (*sp))
150 else if (*sp == _T('&'))
152 /* output AND error redirection */
157 *lpnFlags |= (ERROR_REDIRECTION | OUTPUT_REDIRECTION);
160 /* append request ? */
163 *lpnFlags |= (ERROR_APPEND | OUTPUT_APPEND);
169 /* no redirection!! copy the '&' character! */
175 while (_istspace (*sp))
179 while (*sp && !IsRedirection (*sp) && !_istspace (*sp))
180 *ofn++ = *efn++ = *sp++;
181 *ofn = *efn = _T('\0');
190 /* now go for the pipes */
194 if ((*sp == _T('"')) || (*sp == _T('\'')))
200 while (*sp && *sp != qc);
204 else if (*sp == _T('|'))
216 #endif /* FEATURE_REDIRECTION */