22 if (in.eof())
return 0;
23 if (c1 == c)
return c;
36 if (in.eof())
return 0;
37 if (c1 != c)
return c1;
49 if ((c =
rflush(in,
' ')) == 0)
return false;
52 if (!(in >> u))
return false;
57 void Misc::writeNode(ostream& os,
int u,
int n) {
59 if (u != Null) os <<
nam(u);
68 return s1.length() > 0 && s2.find(s1) == 0;
80 in.get(c1);
if (!in.good())
return false;
81 if (c1 ==
'\n') { in.putback(c1);
return false; }
82 if (isspace(c1))
continue;
83 if (!islower(c1))
return false;
94 assert(0 <= x && x <= 26);
95 if (x == 0) out <<
"Null";
106 s =
""; inword =
false;
108 in.get(c);
if (!in.good())
return false;
109 if (c ==
'\n') { in.putback(c);
return inword; }
111 if (inword) { in.putback(c);
return true; }
114 if (!isalpha(c) && !isdigit(c) && c !=
'_' && c !=
'/' && c !=
'@' && c !=
'.') {
115 in.putback(c);
return inword;
117 s += c; inword =
true;
128 s =
""; inword =
false;
130 in.get(c);
if (!in.good())
return false;
131 if (c ==
'\n') { in.putback(c);
return inword; }
133 if (inword) { in.putback(c);
return true; }
136 if (!isalpha(c) && !isdigit(c) && c !=
'_') {
137 in.putback(c);
return inword;
139 if (!inword && !isalpha(c)) {
140 in.putback(c);
return false;
142 s += c; inword =
true;
153 char c;
bool instring =
false;
156 in.get(c);
if (!in.good())
return false;
158 if (instring)
return true;
160 }
else if (instring) {
172 in.get(c);
if (!in.good())
return false;
173 if (c ==
'\n') { in.putback(c);
return false; }
174 if (isspace(c))
continue;
175 if (!isdigit(c) && c !=
'-')
return false;
177 if (in >> j) { i = j;
return true; }
188 in.get(c);
if (!in.good())
return false;
189 if (c ==
'\n') { in.putback(c);
return false; }
190 if (isspace(c))
continue;
191 if (!isdigit(c))
return false;
193 if (in >> i)
return true;
200 if (
readNum(in,j)) { i = j;
return true; }
206 if (
readNum(in,j)) { i = j;
return true; }
219 in.get(c);
if (!in.good())
return false;
220 if (c ==
'#') {com =
true;
continue; }
221 if (c ==
'\n') {com =
false;
continue; }
222 if (com || isspace(c))
continue;
223 in.putback(c);
return true;
233 in.get(c1);
if (!in.good())
return false;
234 if (c1 == c)
return true;
235 else if (c1 ==
'\n' || !isspace(c1))
246 for (i = 1; i <= n; i++) p[i] = i;
247 for (i = 1; i <= n; i++) {
249 k = p[i]; p[i] = p[j]; p[j] = k;
256 for (
int i = 0; i < n; i++)
257 if (*s++ ==
'\0')
return i;
264 if (gettimeofday(&now, NULL) < 0)
265 fatal(
"Misc::getTime: gettimeofday failure");
277 static struct timeval prevTimeval = { 0, 0 };
279 if (prevTimeval.tv_sec == 0 && prevTimeval.tv_usec == 0) {
281 if (gettimeofday(&prevTimeval, NULL) < 0)
282 fatal(
"Misc::getTime: gettimeofday failure");
287 struct timeval nowTimeval;
288 if (gettimeofday(&nowTimeval, NULL) < 0)
289 fatal(
"Misc::getTime: gettimeofday failure");
290 uint32_t dsec = nowTimeval.tv_sec; dsec -= prevTimeval.tv_sec;
291 uint32_t dusec = nowTimeval.tv_usec - prevTimeval.tv_usec;
292 if (nowTimeval.tv_usec < prevTimeval.tv_usec) {
293 dusec = nowTimeval.tv_usec + (1000000 - prevTimeval.tv_usec);
296 now += 1000000*dsec + dusec;
297 prevTimeval = nowTimeval;
313 static struct timeval prevTimeval = { 0, 0 };
315 if (prevTimeval.tv_sec == 0 && prevTimeval.tv_usec == 0) {
317 if (gettimeofday(&prevTimeval, NULL) < 0)
318 fatal(
"Misc::getTime: gettimeofday failure");
323 struct timeval nowTimeval;
324 if (gettimeofday(&nowTimeval, NULL) < 0)
325 fatal(
"Misc::getTime: gettimeofday failure");
326 time_t dsec = nowTimeval.tv_sec - prevTimeval.tv_sec;
327 suseconds_t dusec = nowTimeval.tv_usec - prevTimeval.tv_usec;
328 if (nowTimeval.tv_usec < prevTimeval.tv_usec) {
329 dusec = nowTimeval.tv_usec + (1000000 - prevTimeval.tv_usec);
332 prevTimeval = nowTimeval;
333 uint64_t diff = dsec; diff *= 1000000; diff += dusec; diff *= 1000;