revert between 56095 -> 55830 in arch
[AROS.git] / workbench / c / Shell / convertVar.c
blob9bbbd55f25149067c69a258901dcc6c415cf914d
1 /*
2 Copyright (C) 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/dos.h>
8 #include <ctype.h>
10 #include "Shell.h"
12 #include <aros/debug.h>
14 /* environment variables handling (locals and globals) */
15 LONG convertVar(ShellState *ss, Buffer *in, Buffer *out, BOOL *quoted)
17 STRPTR p = in->buf + in->cur;
18 STRPTR s = p + 1;
19 LONG bra = (*s == '{' ? 2 : 0);
20 TEXT varName[257];
21 TEXT varValue[256];
22 LONG i, len;
24 if (bra)
25 ++s;
27 for (i = 0; i < 256; ++i)
29 if (bra)
31 if (*s == '\0' || *s == '}')
32 break;
34 else
36 if (!isalnum(*s))
37 break;
40 varName[i] = *s++;
43 if (i >= 256) /* FIXME setup a VAR_MAX constant */
44 return ERROR_LINE_TOO_LONG;
46 varName[i] = '\0';
48 if (bra)
50 if (*s == '}')
51 s++;
52 else
53 bra--;
56 if ((bra != 1) && (i > 0) && ((len = GetVar(varName, varValue, 256, LV_VAR)) != -1))
58 D(bug("[Shell] found var: %s = %s\n", varName, varValue));
59 bufferAppend(varValue, len, out, SysBase);
61 else
63 D(bug("[Shell] var not found: %s\n", varName));
64 bufferAppend(p, ++i + bra, out, SysBase);
67 in->cur = s - in->buf;
68 return 0;