forked from Stichting-MINIX-Research-Foundation/minix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdbexp.c
More file actions
157 lines (142 loc) · 2.86 KB
/
Copy pathmdbexp.c
File metadata and controls
157 lines (142 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* mdbexp.c - MINIX expresion parser
*
* Written by Bruce D. Szablak
*
* This free software is provided for non-commerical use. No warrantee
* of fitness for any use is implied. You get what you pay for. Anyone
* may make modifications and distribute them, but please keep this header
* in the distribution.
*/
#include "mdb.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "proto.h"
FORWARD _PROTOTYPE(long value , (char *s , char **s_p , int *seg_p ));
FORWARD _PROTOTYPE(long lookup , (char *s , char **s_p , int *seg_p ));
#define idchar(c) (isalpha(c) || isdigit(c) || (c) == '_')
/*
* Get an expression for mdb
*/
PUBLIC char *getexp(buf, exp_p, seg_p)
char *buf;
int *seg_p;
long *exp_p;
{
long v = 0L;
buf = skip(buf);
if ((isalpha(*buf) && (isspace(buf[1]) || buf[1] == ';'))
|| *buf == '\n'
|| *buf == ';'
|| *buf == '/'
|| *buf == '!'
|| *buf == '?'
|| *buf == '@'
|| *buf == '#') {
*exp_p = 0L;
return buf;
}
v = value(buf, &buf, seg_p);
buf = skip(buf);
if (*buf == '+')
v += value(skip(buf + 1), &buf, seg_p);
else if (*buf == '-')
v -= value(skip(buf + 1), &buf, seg_p);
*exp_p = v;
return skip(buf);
}
/*
* Get value
*
* \c escaped characters
* digits number
* $xx registers
* \n 0L
* then calls lookup for symbols
*/
PRIVATE long value(s, s_p, seg_p)
char *s, **s_p;
int *seg_p;
{
long k;
if (*s == '\'') { /* handle character constants here */
*s_p = s + 2;
return s[1];
}
if (*s == '-' || isdigit(*s))
return strtol(s, s_p, 0);
if (*s == '$') {
k = reg_addr(s + 1);
*s_p = s + 3;
return get_reg(curpid, k);
k = reg_addr(s + 1);
*s_p = s + 3;
return get_reg(curpid, k);
}
if (*s == '\n') {
*s_p = s + 1;
return 0L;
}
return lookup(s, s_p, seg_p);
}
/*
* Lookup symbol - return value
* Handle special cases: _start T: D: S:
* then call symbolvalue()
*/
PRIVATE long lookup(s, s_p, seg_p)
char *s, **s_p;
int *seg_p;
{
long value;
char c;
int l;
for (l = 1; idchar(s[l]); ++l) {}
c = s[l];
s[l] = 0;
if (strcmp("_start", s) == 0) {
*seg_p = T;
if (c == ':') c = '+';
*(*s_p = s + 6) = c;
return st_addr;
}
if (strcmp("T", s) == 0) {
*seg_p = T;
if (c == ':') c = '+';
*(*s_p = s + 1) = c;
return st_addr;
}
if (strcmp("D", s) == 0) {
*seg_p = D;
if (c == ':') c = '+';
*(*s_p = s + 1) = c;
return sd_addr;
}
if (strcmp("S", s) == 0) {
*seg_p = S;
if (c == ':') c = '+';
*(*s_p = s + 1) = c;
return sk_addr;
}
if ((value = symbolvalue(s, TRUE)) != 0L) {
*seg_p = T;
*(*s_p = s + l) = c;
return value;
}
if ((value = symbolvalue(s, FALSE)) != 0L) {
*seg_p = D;
*(*s_p = s + l) = c;
return value;
}
Printf("%s: ", s);
mdb_error("symbol not found\n");
}
/* Skip spaces */
PUBLIC char *skip(s)
register char *s;
{
while (isspace(*s)) ++s;
return *s ? s : s - 1;
}