2 * mdbexp.c - MINIX expresion parser
4 * Written by Bruce D. Szablak
6 * This free software is provided for non-commerical use. No warrantee
7 * of fitness for any use is implied. You get what you pay for. Anyone
8 * may make modifications and distribute them, but please keep this header
19 FORWARD
_PROTOTYPE(long value
, (char *s
, char **s_p
, int *seg_p
));
20 FORWARD
_PROTOTYPE(long lookup
, (char *s
, char **s_p
, int *seg_p
));
22 #define idchar(c) (isalpha(c) || isdigit(c) || (c) == '_')
25 * Get an expression for mdb
27 PUBLIC
char *getexp(buf
, exp_p
, seg_p
)
35 if ((isalpha(*buf
) && (isspace(buf
[1]) || buf
[1] == ';'))
46 v
= value(buf
, &buf
, seg_p
);
49 v
+= value(skip(buf
+ 1), &buf
, seg_p
);
51 v
-= value(skip(buf
+ 1), &buf
, seg_p
);
59 * \c escaped characters
63 * then calls lookup for symbols
65 PRIVATE
long value(s
, s_p
, seg_p
)
71 if (*s
== '\'') { /* handle character constants here */
75 if (*s
== '-' || isdigit(*s
))
76 return strtol(s
, s_p
, 0);
80 return get_reg(curpid
, k
);
83 return get_reg(curpid
, k
);
89 return lookup(s
, s_p
, seg_p
);
93 * Lookup symbol - return value
94 * Handle special cases: _start T: D: S:
95 * then call symbolvalue()
97 PRIVATE
long lookup(s
, s_p
, seg_p
)
105 for (l
= 1; idchar(s
[l
]); ++l
) {}
109 if (strcmp("_start", s
) == 0) {
111 if (c
== ':') c
= '+';
115 if (strcmp("T", s
) == 0) {
117 if (c
== ':') c
= '+';
121 if (strcmp("D", s
) == 0) {
123 if (c
== ':') c
= '+';
127 if (strcmp("S", s
) == 0) {
129 if (c
== ':') c
= '+';
134 if ((value
= symbolvalue(s
, TRUE
)) != 0L) {
140 if ((value
= symbolvalue(s
, FALSE
)) != 0L) {
147 mdb_error("symbol not found\n");
154 while (isspace(*s
)) ++s
;
155 return *s
? s
: s
- 1;