Fixes to typos in comments etc.
[AROS.git] / workbench / c / Shell / Shell.h
blob5de5c71f6b536805321842705bfac47fd69745bb
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #ifndef SHELL_H
7 #define SHELL_H 1
9 #include <dos/dosextens.h>
10 #include <dos/dos.h> /* for BPTR */
12 #include "buffer.h"
14 #define FILE_MAX 256 /* max length of file name */
15 #define LINE_MAX 512 /* max length of full command line */
17 /* TODO move */
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 */
28 #define MAXARGS 32
29 #define MAXARGLEN 32
31 struct SArg
33 TEXT name[MAXARGLEN];
34 LONG namelen;
35 LONG len;
36 IPTR def;
37 LONG deflen;
38 UBYTE type;
41 typedef struct _ShellState
43 BPTR newIn;
44 BPTR newOut;
45 BPTR oldIn;
46 BPTR oldOut;
48 TEXT command[FILE_MAX + 2]; /* command buffer */
50 BPTR oldHomeDir; /* shared lock on program file's directory */
52 LONG cliNumber;
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;
60 TEXT mchar0, pchar0;
62 struct _ShellState *stack;
64 ULONG flags; /* DOS/CliInit*() flags cache */
66 APTR ss_DOSBase;
67 APTR ss_SysBase;
68 } ShellState;
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);
90 /* Function: executeLine
92 * Action: Execute one line of commands
94 * Input: ShellState *ss -- this state
95 * STRPTR commandArgs -- arguments of the 'command'
97 * Output: LONG -- error code or 0 if everything went OK
99 LONG executeLine(ShellState *ss, STRPTR commandArgs);
101 /* Function: readLine
103 * Action: Read one line of a stream into a buffer.
105 * Input: ShellState *ss -- this state
106 * struct CommandLineInterface *cli -- the CLI
107 * Buffer *out -- the result
108 * BOOL *moreLeft -- not end of stream result
110 * Note: This routine reads a full command line.
111 * As a side effect, it also updates ss->pchar0 and ss->mchar0
113 * Output: SIPTR -- DOS error code
115 LONG readLine(ShellState *ss, struct CommandLineInterface *cli, Buffer *out, BOOL *moreLeft);
117 /* Function: checkLine
119 * Action: Parse a command line and do consistency checks
121 * Input: ShellState *ss -- this state
122 * Buffer *in -- the input buffer
123 * Buffer *out -- the result will be stored here
124 * BOOL echo -- true if command echoed
126 * Output: LONG -- DOS error code
128 LONG checkLine(ShellState *ss, Buffer *in, Buffer *out, BOOL echo);
130 /* Function: releaseFiles
132 * Action: Deallocate file resources used for redirecion and reinstall
133 * standard input and output streams.
135 * Input: ShellState *ss -- this state
137 * Output: --
139 void releaseFiles(ShellState *ss);
141 /* Function: interact
143 * Action: Execute a commandfile and then perform standard shell user
144 * interaction.
146 * Input: ShellState *is -- this state
148 * Output: LONG -- error code
150 LONG interact(ShellState *ss);
153 /* Function: Redirection_release
155 * Action: Release resources allocated in the state
157 * Input: ShellState *ss -- this state
159 * Output: --
161 void Redirection_release(ShellState *ss);
163 /* Function: Redirection_init
165 * Action: Initialize a state structure
167 * Input: ShellState *ss -- this state
169 * Output: LONG -- DOS error code
171 LONG Redirection_init(ShellState *ss);
173 /* Function: setPath
175 * Action: Set the current command (standard) path.
177 * Input: BPTR lock -- a lock on the directory
179 * Notes: This will set the current directory name via
180 * SetCurrentDirName() even though this is not used later.
182 * Output: --
184 void setPath(ShellState *ss, BPTR lock);
186 /* Function: cliPrompt
188 * Action: Print the prompt to indicate that user input is viable.
190 * Input: ShellState *ss -- this state
192 * Output: --
194 void cliPrompt(ShellState *ss);
196 /* Other internal functions
198 * FIXME: some doc ?
200 void initDefaultInterpreterState(ShellState *ss);
201 void popInterpreterState(ShellState *ss);
202 LONG pushInterpreterState(ShellState *ss);
204 LONG convertArg(ShellState *ss, Buffer *in, Buffer *out, BOOL *quoted);
205 LONG convertBackTicks(ShellState *ss, Buffer *in, Buffer *out, BOOL *quoted);
206 LONG convertRedir(ShellState *ss, Buffer *in, Buffer *out);
207 LONG convertVar(ShellState *ss, Buffer *in, Buffer *out, BOOL *quoted);
208 LONG l2a(LONG x, STRPTR buf); /* long to ascii */
210 void cliEcho(ShellState *ss, CONST_STRPTR args);
211 LONG cliLen(CONST_STRPTR s);
212 BOOL cliNan(CONST_STRPTR s);
213 void cliVarNum(ShellState *ss, CONST_STRPTR name, LONG value);
215 #endif