constants; abandon old double-underscore convention for internal
functions and variables.
- * $Id: testrig.c,v 1.3 1999/05/06 19:51:35 mdw Exp $
+ * $Id: testrig.c,v 1.4 1999/05/19 19:02:17 mdw Exp $
*
* Generic test driver
*
*
* Generic test driver
*
/*----- Revision history --------------------------------------------------*
*
* $Log: testrig.c,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: testrig.c,v $
+ * Revision 1.4 1999/05/19 19:02:17 mdw
+ * Aesthetic changes: fix spelling of `initialize'; use uppercase token
+ * constants; abandon old double-underscore convention for internal
+ * functions and variables.
+ *
* Revision 1.3 1999/05/06 19:51:35 mdw
* Reformatted the LGPL notice a little bit.
*
* Revision 1.3 1999/05/06 19:51:35 mdw
* Reformatted the LGPL notice a little bit.
*
/*----- Static variables --------------------------------------------------*/
/*----- Static variables --------------------------------------------------*/
- tok_eof = 0x100,
- tok_word
+ TOK_EOF = 0x100,
+ TOK_WORD
};
/*----- Main code ---------------------------------------------------------*/
};
/*----- Main code ---------------------------------------------------------*/
-/* --- @test__decode@ --- *
*
* Arguments: @int tok@ = token type to decode
*
*
* Arguments: @int tok@ = token type to decode
*
* Use: Produces a readable representation of a token.
*/
* Use: Produces a readable representation of a token.
*/
-static const char *test__decode(int tok)
+static const char *decode(int t)
- switch (tok) {
- case tok_eof:
+ switch (t) {
+ case TOK_EOF:
- case tok_word:
- return (test__tok.buf);
+ case TOK_WORD:
+ return (tok.buf);
buf[1] = 0;
return (buf);
}
return ("<buggy-program>");
}
buf[1] = 0;
return (buf);
}
return ("<buggy-program>");
}
-/* --- @test__gettok@ --- *
*
* Arguments: @FILE *fp@ = file handle to read from
*
*
* Arguments: @FILE *fp@ = file handle to read from
*
* Use: Reads a token from the input stream.
*/
* Use: Reads a token from the input stream.
*/
-static int test__gettok(FILE *fp)
+static int gettok(FILE *fp)
{
int ch;
/* --- Clear the token accumulator --- */
{
int ch;
/* --- Clear the token accumulator --- */
- dstr_reset(&test__tok);
/* --- Prime the lookahead character --- */
/* --- Prime the lookahead character --- */
/* --- End of file --- */
case EOF:
/* --- End of file --- */
case EOF:
/* --- Quote characters --- */
/* --- Quote characters --- */
if (ch == EOF)
ch = '\\';
}
if (ch == EOF)
ch = '\\';
}
- DPUTZ(&test__tok);
- return (tok_word);
+ DPUTZ(&tok);
+ return (TOK_WORD);
}
/* --- Anything else is either a word or self-delimiting --- */
}
/* --- Anything else is either a word or self-delimiting --- */
default:
if (isalnum((unsigned char)ch)) {
for (;;) {
default:
if (isalnum((unsigned char)ch)) {
for (;;) {
ch = getc(fp);
if (ch == EOF ||
ch == ';' ||
ch = getc(fp);
if (ch == EOF ||
ch == ';' ||
- DPUTZ(&test__tok);
- return (tok_word);
+ DPUTZ(&tok);
+ return (TOK_WORD);
int fail = 0, ok = 1;
int sofar = 0;
int fail = 0, ok = 1;
int sofar = 0;
- /* --- Silly bits of initialisation --- */
+ /* --- Silly bits of initialization --- */
die(1, "couldn't open test vector file `%s': %s", vec, strerror(errno));
for (;;) {
die(1, "couldn't open test vector file `%s': %s", vec, strerror(errno));
for (;;) {
- int tok = test__gettok(fp);
/* --- This is a reasonable place to stop --- */
/* --- This is a reasonable place to stop --- */
break;
/* --- Pick out the chunk name --- */
break;
/* --- Pick out the chunk name --- */
- if (tok != tok_word)
- die(1, "expected <word>; found `%s'", test__decode(tok));
+ if (t != TOK_WORD)
+ die(1, "expected <word>; found `%s'", decode(t));
/* --- Find the right chunk block --- */
for (cch = chunk; ; cch++) {
if (!cch->name)
goto skip_chunk;
/* --- Find the right chunk block --- */
for (cch = chunk; ; cch++) {
if (!cch->name)
goto skip_chunk;
- if (strcmp(test__tok.buf, cch->name) == 0)
+ if (strcmp(tok.buf, cch->name) == 0)
break;
}
/* --- Past the open brace to the first chunk --- */
break;
}
/* --- Past the open brace to the first chunk --- */
- if ((tok = test__gettok(fp)) != '{')
- die(1, "expected '{'; found `%s'", test__decode(tok));
+ if ((t = gettok(fp)) != '{')
+ die(1, "expected '{'; found `%s'", decode(t));
/* --- Start on the test data now --- */
/* --- Start on the test data now --- */
- tok = test__gettok(fp);
/* --- Accept a close brace --- */
/* --- Accept a close brace --- */
break;
/* --- Otherwise I expect a list of words --- */
for (i = 0; cch->f[i]; i++) {
dstr_reset(&dv[i]);
break;
/* --- Otherwise I expect a list of words --- */
for (i = 0; cch->f[i]; i++) {
dstr_reset(&dv[i]);
- if (tok != tok_word)
- die(1, "expected <word>; found `%s'", test__decode(tok));
- cch->f[i]->cvt(test__tok.buf, &dv[i]);
- tok = test__gettok(fp);
+ if (t != TOK_WORD)
+ die(1, "expected <word>; found `%s'", decode(t));
+ cch->f[i]->cvt(tok.buf, &dv[i]);
+ t = gettok(fp);
}
/* --- And a terminating semicolon --- */
}
/* --- And a terminating semicolon --- */
- if (tok != ';')
- die(1, "expected `;'; found `%s'", test__decode(tok));
+ if (t != ';')
+ die(1, "expected `;'; found `%s'", decode(t));
/* --- Run the test code --- */
/* --- Run the test code --- */
- if ((tok = test__gettok(fp)) != '{')
- die(1, "expected '{'; found `%s'", test__decode(tok));
+ if ((t = gettok(fp)) != '{')
+ die(1, "expected '{'; found `%s'", decode(t));
- tok = test__gettok(fp);
- if (tok == '}')
+ t = gettok(fp);
+ if (t == '}')
- while (tok == tok_word)
- tok = test__gettok(fp);
- if (tok != ';')
- die(1, "expected `;'; found `%s'", test__decode(tok));
+ while (t == TOK_WORD)
+ t = gettok(fp);
+ if (t != ';')
+ die(1, "expected `;'; found `%s'", decode(t));