2 Copyright (C) 1995-2011, The AROS Development Team. All rights reserved.
12 #include <aros/debug.h>
14 #define PIPE_NAME "PIPE "
16 static BOOL
checkPipe(STRPTR pchar
, STRPTR mchar
, STRPTR in
, LONG inlen
)
20 int mcharn
= strlen(mchar
), pcharn
= strlen(pchar
);
22 for (n
= 0; n
< inlen
; n
++)
33 if (mcharn
> 0 && c
== mchar
[0] && memcmp(&in
[n
], mchar
, mcharn
) == 0)
36 if (pcharn
> 0 && c
== pchar
[0] && memcmp(&in
[n
], pchar
, pcharn
) == 0)
42 LONG
readLine(ShellState
*ss
, struct CommandLineInterface
*cli
, Buffer
*out
, WORD
*moreLeft
)
44 BPTR fh
= cli
->cli_CurrentInput
;
45 STRPTR buf
= out
->buf
; /* pre-allocated by caller */
49 TEXT pchar
[3], mchar
[3];
51 len
= GetVar("_pchar", pchar
, sizeof pchar
, GVF_LOCAL_ONLY
| LV_VAR
);
56 len
= GetVar("_mchar", mchar
, sizeof mchar
, GVF_LOCAL_ONLY
| LV_VAR
);
60 ss
->pchar0
= pchar
[0];
61 ss
->mchar0
= mchar
[0];
63 for (i
= 0, j
= 0; i
< LINE_MAX
; ++i
)
73 if (!quoted
&& c
== ';' && c
!= mchar
[0] ) /* comment line */
78 else if (c
== '\n') /* end of line */
82 /* '+' continuation */
83 if (j
> 0 && buf
[j
-1]=='+') {
93 if (c
== '\n') /* end of line */
98 D(bug("[Shell] ERROR_LINE_TOO_LONG\n"));
99 return ERROR_LINE_TOO_LONG
;
103 bufferAppend(buf
, j
, out
, SysBase
);
105 if (checkPipe(pchar
, mchar
, buf
, j
))
106 bufferInsert(PIPE_NAME
, strlen(PIPE_NAME
), out
, SysBase
);
108 *moreLeft
= (c
!= ENDSTREAMCH
);
110 D(bug("[Shell] readLine %d%s: %s", j
, *moreLeft
? "" : "'", buf
));