2004-01-05 02:25:38 +01:00
|
|
|
/* Lexical analyzer for dgamelaunch's configuration file. */
|
|
|
|
|
|
|
|
%{
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "y.tab.h"
|
|
|
|
#include "dgamelaunch.h"
|
|
|
|
|
|
|
|
unsigned int line = 1, col = 0;
|
|
|
|
|
|
|
|
#define YY_USER_ACTION col += yyleng;
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
2004-02-01 09:10:18 +01:00
|
|
|
NUMBER -?[0-9]+
|
2004-01-05 02:25:38 +01:00
|
|
|
VALUE \".*\"
|
|
|
|
MALSTRING \"[^\"\n]*\n
|
|
|
|
WHITE [\t ]*
|
|
|
|
COMMENT ^#.*
|
|
|
|
|
2004-01-16 03:32:33 +01:00
|
|
|
%%
|
2004-01-05 02:25:38 +01:00
|
|
|
|
2004-02-01 09:10:18 +01:00
|
|
|
{NUMBER} {
|
|
|
|
unsigned int x;
|
|
|
|
errno = 0;
|
|
|
|
|
|
|
|
if (atoi(yytext) < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"%s:%d: negative value not accepted! Fix it now!\n",
|
|
|
|
config, line);
|
|
|
|
graceful_exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
x = strtoul(yytext, NULL, 10);
|
|
|
|
|
|
|
|
if (errno == ERANGE)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s:%d: %s is too big! Fix it now!\n",
|
|
|
|
config, line, yytext);
|
|
|
|
graceful_exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
yylval.i = x;
|
|
|
|
return TYPE_NUMBER;
|
|
|
|
}
|
|
|
|
|
2004-01-05 02:25:38 +01:00
|
|
|
{VALUE} {
|
|
|
|
yytext[yyleng - 1] = '\0'; /* Kill the trailing quote */
|
2004-01-16 03:32:33 +01:00
|
|
|
yylval.s = strdup(yytext + 1); /* kill leading quote */
|
2004-01-05 02:25:38 +01:00
|
|
|
return TYPE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
{MALSTRING} {
|
|
|
|
/* yytext already contains a newline, no need for one here */
|
|
|
|
fprintf(stderr, "%s: unterminated string constant at line %d, start column %d: %s\n", config, line, col - yyleng + 1, yytext);
|
|
|
|
}
|
|
|
|
|
|
|
|
{WHITE} { }
|
|
|
|
{COMMENT} { }
|
|
|
|
|
|
|
|
"=" { return '='; }
|
|
|
|
"shed_user" { return TYPE_SUSER; }
|
|
|
|
"shed_group" { return TYPE_SGROUP; }
|
|
|
|
"shed_uid" { return TYPE_SUID; }
|
|
|
|
"shed_gid" { return TYPE_SGID; }
|
|
|
|
"maxusers" { return TYPE_MAX; }
|
|
|
|
|
|
|
|
"chroot_path" { return TYPE_PATH_CHROOT; }
|
|
|
|
"nethack" { return TYPE_PATH_NETHACK; }
|
|
|
|
"dglroot" { return TYPE_PATH_DGLDIR; }
|
|
|
|
"spooldir" { return TYPE_PATH_SPOOL; }
|
|
|
|
"banner" { return TYPE_PATH_BANNER; }
|
|
|
|
"rc_template" { return TYPE_PATH_CANNED; }
|
2004-01-21 02:57:44 +01:00
|
|
|
"passwd" { return TYPE_PATH_PASSWD; }
|
|
|
|
"lockfile" { return TYPE_PATH_LOCKFILE; }
|
2004-01-05 02:25:38 +01:00
|
|
|
|
|
|
|
\n { line++; col = 0; }
|
|
|
|
|
|
|
|
. {
|
|
|
|
fprintf(stderr, "%s: unrecognized token \"%s\" at line %d, column %d\n", config, yytext, line, col);
|
|
|
|
}
|
|
|
|
|
|
|
|
%%
|