use m4_normalize on the output strings to remove trailing spaces/tabs and consolidate...
[AROS.git] / workbench / c / Shell / interpreter.c
blob5dfc5fd9b41acccb405b7166304bcf5cc0b813cc
1 /*
2 Copyright (C) 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/exec.h>
8 #include "Shell.h"
10 void initDefaultInterpreterState(ShellState *ss)
12 LONG i;
14 ss->argcount = 0;
16 /* Preset the first bytes to "C:" to handle C: multiassigns */
17 ss->command[0] = 'C';
18 ss->command[1] = ':';
20 for (i = 0; i < MAXARGS; ++i)
22 struct SArg *a = ss->args + i;
24 a->namelen = 0;
25 a->name[0] = '\0';
26 a->len = 0;
27 a->def = 0;
28 a->deflen = 0;
29 a->type = NORMAL;
31 ss->arg[i] = 0;
34 ss->bra = '<';
35 ss->ket = '>';
36 ss->dollar = '$';
37 ss->dot = '.';
39 ss->stack = NULL;
42 LONG pushInterpreterState(ShellState *ss)
44 ShellState *tmp_ss = (ShellState *)AllocMem(sizeof(*ss), MEMF_LOCAL);
46 if (tmp_ss)
48 *tmp_ss = *ss;
49 initDefaultInterpreterState(ss);
50 ss->stack = tmp_ss;
51 return 0;
54 return ERROR_NO_FREE_STORE;
57 void popInterpreterState(ShellState *ss)
59 ShellState *tmp_ss = ss->stack;
60 struct SArg *a;
61 LONG i;
63 for (i = 0; i < ss->argcount; ++i)
65 a = ss->args + i;
67 if (a->def)
68 FreeMem((APTR) a->def, a->deflen + 1);
71 if (tmp_ss)
73 *ss = *tmp_ss;
74 FreeMem(tmp_ss, sizeof(*ss));
76 else
77 initDefaultInterpreterState(ss);