2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
9 #include <dos/dosextens.h>
10 #include <dos/dos.h> /* for BPTR */
14 #define FILE_MAX 256 /* max length of file name */
15 #define LINE_MAX 512 /* max length of full command line */
18 /* Template options (copied *AND MODIFIED* from ReadArgs) */
19 #define REQUIRED 0x80 /* /A */
20 #define KEYWORD 0x40 /* /K */
21 #define MULTIPLE 0x20 /* /M */
22 #define NORMAL 0x00 /* No option */
23 #define SWITCH 0x01 /* /S, implies /K */
24 #define TOGGLE 0x02 /* /T, implies /K */
25 #define NUMERIC 0x04 /* /N */
26 #define REST 0x08 /* /F */
41 typedef struct _ShellState
48 TEXT command
[FILE_MAX
+ 2]; /* command buffer */
50 BPTR oldHomeDir
; /* shared lock on program file's directory */
54 LONG argcount
; /* script args count */
55 struct SArg args
[MAXARGS
]; /* args definitions */
56 IPTR arg
[MAXARGS
]; /* args values */
57 struct RDArgs
*arg_rd
; /* Current RDArgs return state */
59 TEXT bra
, ket
, dollar
, dot
;
62 struct _ShellState
*stack
;
64 ULONG flags
; /* DOS/CliInit*() flags cache */
70 #define DOSBase (ss->ss_DOSBase)
71 #define SysBase ((struct ExecBase *)ss->ss_SysBase)
73 /* Function: convertLine
75 * Action: Parses a command line and returns a filtered version (removing
76 * redirections, incorporating embedded commands, taking care of
77 * variable references and aliases.
79 * Input: ShellState *ss -- this state
80 * Buffer *in -- input string
81 * Buffer *out -- output command string
82 * BOOL *haveCommand -- true if line have command
84 * Output: LONG -- error code or 0 if everything went OK
86 LONG
convertLine(ShellState
*ss
, Buffer
*in
, Buffer
*out
, BOOL
*haveCommand
);
88 LONG
convertLineDot(ShellState
*ss
, Buffer
*in
);
92 * Action: Read one line of a stream into a buffer.
94 * Input: ShellState *ss -- this state
95 * struct CommandLineInterface *cli -- the CLI
96 * Buffer *out -- the result
97 * BOOL *moreLeft -- not end of stream result
99 * Note: This routine reads a full command line.
100 * As a side effect, it also updates ss->pchar0 and ss->mchar0
102 * Output: SIPTR -- DOS error code
104 LONG
readLine(ShellState
*ss
, struct CommandLineInterface
*cli
, Buffer
*out
, BOOL
*moreLeft
);
106 /* Function: checkLine
108 * Action: Parse a command line and do consistency checks
110 * Input: ShellState *ss -- this state
111 * Buffer *in -- the input buffer
112 * Buffer *out -- the result will be stored here
113 * BOOL echo -- true if command echoed
115 * Output: LONG -- DOS error code
117 LONG
checkLine(ShellState
*ss
, Buffer
*in
, Buffer
*out
, BOOL echo
);
119 /* Function: releaseFiles
121 * Action: Deallocate file resources used for redirecion and reinstall
122 * standard input and output streams.
124 * Input: ShellState *ss -- this state
128 void releaseFiles(ShellState
*ss
);
130 /* Function: interact
132 * Action: Execute a commandfile and then perform standard shell user
135 * Input: ShellState *is -- this state
137 * Output: LONG -- error code
139 LONG
interact(ShellState
*ss
);
142 /* Function: Redirection_release
144 * Action: Release resources allocated in the state
146 * Input: ShellState *ss -- this state
150 void Redirection_release(ShellState
*ss
);
152 /* Function: Redirection_init
154 * Action: Initialize a state structure
156 * Input: ShellState *ss -- this state
158 * Output: LONG -- DOS error code
160 LONG
Redirection_init(ShellState
*ss
);
164 * Action: Set the current command (standard) path.
166 * Input: BPTR lock -- a lock on the directory
168 * Notes: This will set the current directory name via
169 * SetCurrentDirName() even though this is not used later.
173 void setPath(ShellState
*ss
, BPTR lock
);
175 /* Function: cliPrompt
177 * Action: Print the prompt to indicate that user input is viable.
179 * Input: ShellState *ss -- this state
183 void cliPrompt(ShellState
*ss
);
185 /* Other internal functions
189 void initDefaultInterpreterState(ShellState
*ss
);
190 void popInterpreterState(ShellState
*ss
);
191 LONG
pushInterpreterState(ShellState
*ss
);
193 LONG
convertArg(ShellState
*ss
, Buffer
*in
, Buffer
*out
, BOOL
*quoted
);
194 LONG
convertBackTicks(ShellState
*ss
, Buffer
*in
, Buffer
*out
, BOOL
*quoted
);
195 LONG
convertRedir(ShellState
*ss
, Buffer
*in
, Buffer
*out
);
196 LONG
convertVar(ShellState
*ss
, Buffer
*in
, Buffer
*out
, BOOL
*quoted
);
197 LONG
l2a(LONG x
, STRPTR buf
); /* long to ascii */
199 void cliEcho(ShellState
*ss
, CONST_STRPTR args
);
200 LONG
cliLen(CONST_STRPTR s
);
201 BOOL
cliNan(CONST_STRPTR s
);
202 void cliVarNum(ShellState
*ss
, CONST_STRPTR name
, LONG value
);