2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-08-29 13:28:14 +00:00

Add new tokens; fix line number/character number counter code

This commit is contained in:
Ted Lemon 1996-08-27 09:39:17 +00:00
parent c83a6d68e4
commit 58304e8edb
2 changed files with 104 additions and 18 deletions

View File

@ -42,17 +42,19 @@
#ifndef lint #ifndef lint
static char copyright[] = static char copyright[] =
"@(#) Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; "$Id: conflex.c,v 1.13 1996/08/27 09:39:17 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */ #endif /* not lint */
#include "dhcpd.h" #include "dhcpd.h"
#include "dhctoken.h" #include "dhctoken.h"
#include <ctype.h> #include <ctype.h>
static int line; int lexline;
int lexchar;
static int lpos; static int lpos;
int tlpos; static int line;
int tline; static int tlpos;
static int tline;
char *tlname; char *tlname;
static int token; static int token;
static int ugflag; static int ugflag;
@ -67,6 +69,13 @@ static int read_number PROTO ((int, FILE *));
static int read_num_or_atom PROTO ((int, FILE *)); static int read_num_or_atom PROTO ((int, FILE *));
static int intern PROTO ((char *, int)); static int intern PROTO ((char *, int));
void new_parse (name)
char *name;
{
tlname = name;
lpos = line = 1;
}
static int get_char (cfile) static int get_char (cfile)
FILE *cfile; FILE *cfile;
{ {
@ -89,8 +98,12 @@ static int get_token (cfile)
int c; int c;
int ttok; int ttok;
static char tb [2]; static char tb [2];
int l, p;
do { do {
l = line;
p = lpos;
c = get_char (cfile); c = get_char (cfile);
if (isascii (c) && isspace (c)) if (isascii (c) && isspace (c))
continue; continue;
@ -98,19 +111,25 @@ static int get_token (cfile)
skip_to_eol (cfile); skip_to_eol (cfile);
continue; continue;
} }
tlpos = lpos;
tline = line;
if (c == '"') { if (c == '"') {
lexline = l;
lexchar = p;
ttok = read_string (cfile); ttok = read_string (cfile);
break; break;
} }
if ((isascii (c) && isdigit (c)) || c == '-') { if ((isascii (c) && isdigit (c)) || c == '-') {
lexline = l;
lexchar = p;
ttok = read_number (c, cfile); ttok = read_number (c, cfile);
break; break;
} else if (isascii (c) && isalpha (c)) { } else if (isascii (c) && isalpha (c)) {
lexline = l;
lexchar = p;
ttok = read_num_or_atom (c, cfile); ttok = read_num_or_atom (c, cfile);
break; break;
} else { } else {
lexline = l;
lexchar = p;
tb [0] = c; tb [0] = c;
tb [1] = 0; tb [1] = 0;
tval = tb; tval = tb;
@ -128,6 +147,8 @@ int next_token (rval, cfile)
int rv; int rv;
if (token) { if (token) {
lexchar = tlpos;
lexline = tline;
rv = token; rv = token;
token = 0; token = 0;
} else { } else {
@ -145,8 +166,15 @@ int peek_token (rval, cfile)
char **rval; char **rval;
FILE *cfile; FILE *cfile;
{ {
if (!token) int x;
if (!token) {
tlpos = lexchar;
tline = lexline;
token = get_token (cfile); token = get_token (cfile);
x = lexchar; lexchar = tlpos; tlpos = x;
x = lexline; lexline = tline; tline = x;
}
if (rval) if (rval)
*rval = tval; *rval = tval;
#ifdef DEBUG_TOKENS #ifdef DEBUG_TOKENS
@ -268,6 +296,9 @@ static int intern (atom, dfv)
return dfv; return dfv;
switch (tolower (atom [0])) { switch (tolower (atom [0])) {
case 'b':
if (!strcasecmp (atom + 1, "oot-unknown-clients"))
return BOOT_UNKNOWN_CLIENTS;
case 'c': case 'c':
if (!strcasecmp (atom + 1, "lass")) if (!strcasecmp (atom + 1, "lass"))
return CLASS; return CLASS;
@ -277,8 +308,14 @@ static int intern (atom, dfv)
case 'd': case 'd':
if (!strcasecmp (atom + 1, "efault-lease-time")) if (!strcasecmp (atom + 1, "efault-lease-time"))
return DEFAULT_LEASE_TIME; return DEFAULT_LEASE_TIME;
if (!strcasecmp (atom + 1, "ynamic-bootp")) if (!strncasecmp (atom + 1, "ynamic-bootp", 12)) {
return DYNAMIC_BOOTP; if (!atom [13])
return DYNAMIC_BOOTP;
else if (!strcasecmp (atom + 13, "-lease-cutoff"))
return DYNAMIC_BOOTP_LEASE_CUTOFF;
else if (!strcasecmp (atom + 13, "-lease-length"))
return DYNAMIC_BOOTP_LEASE_LENGTH;
}
break; break;
case 'e': case 'e':
if (!strcasecmp (atom + 1, "thernet")) if (!strcasecmp (atom + 1, "thernet"))
@ -295,6 +332,8 @@ static int intern (atom, dfv)
case 'g': case 'g':
if (!strcasecmp (atom + 1, "iaddr")) if (!strcasecmp (atom + 1, "iaddr"))
return GIADDR; return GIADDR;
if (!strcasecmp (atom + 1, "roup"))
return GROUP;
break; break;
case 'h': case 'h':
if (!strcasecmp (atom + 1, "ost")) if (!strcasecmp (atom + 1, "ost"))
@ -313,6 +352,8 @@ static int intern (atom, dfv)
case 'n': case 'n':
if (!strcasecmp (atom + 1, "etmask")) if (!strcasecmp (atom + 1, "etmask"))
return NETMASK; return NETMASK;
if (!strcasecmp (atom + 1, "ext-server"))
return NEXT_SERVER;
break; break;
case 'p': case 'p':
if (!strcasecmp (atom + 1, "acket")) if (!strcasecmp (atom + 1, "acket"))
@ -343,6 +384,8 @@ static int intern (atom, dfv)
case 't': case 't':
if (!strcasecmp (atom + 1, "imestamp")) if (!strcasecmp (atom + 1, "imestamp"))
return TIMESTAMP; return TIMESTAMP;
if (!strcasecmp (atom + 1, "oken-ring"))
return TOKEN_RING;
break; break;
case 'u': case 'u':
if (!strcasecmp (atom + 1, "id")) if (!strcasecmp (atom + 1, "id"))

View File

@ -42,17 +42,19 @@
#ifndef lint #ifndef lint
static char copyright[] = static char copyright[] =
"@(#) Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; "$Id: conflex.c,v 1.13 1996/08/27 09:39:17 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */ #endif /* not lint */
#include "dhcpd.h" #include "dhcpd.h"
#include "dhctoken.h" #include "dhctoken.h"
#include <ctype.h> #include <ctype.h>
static int line; int lexline;
int lexchar;
static int lpos; static int lpos;
int tlpos; static int line;
int tline; static int tlpos;
static int tline;
char *tlname; char *tlname;
static int token; static int token;
static int ugflag; static int ugflag;
@ -67,6 +69,13 @@ static int read_number PROTO ((int, FILE *));
static int read_num_or_atom PROTO ((int, FILE *)); static int read_num_or_atom PROTO ((int, FILE *));
static int intern PROTO ((char *, int)); static int intern PROTO ((char *, int));
void new_parse (name)
char *name;
{
tlname = name;
lpos = line = 1;
}
static int get_char (cfile) static int get_char (cfile)
FILE *cfile; FILE *cfile;
{ {
@ -89,8 +98,12 @@ static int get_token (cfile)
int c; int c;
int ttok; int ttok;
static char tb [2]; static char tb [2];
int l, p;
do { do {
l = line;
p = lpos;
c = get_char (cfile); c = get_char (cfile);
if (isascii (c) && isspace (c)) if (isascii (c) && isspace (c))
continue; continue;
@ -98,19 +111,25 @@ static int get_token (cfile)
skip_to_eol (cfile); skip_to_eol (cfile);
continue; continue;
} }
tlpos = lpos;
tline = line;
if (c == '"') { if (c == '"') {
lexline = l;
lexchar = p;
ttok = read_string (cfile); ttok = read_string (cfile);
break; break;
} }
if ((isascii (c) && isdigit (c)) || c == '-') { if ((isascii (c) && isdigit (c)) || c == '-') {
lexline = l;
lexchar = p;
ttok = read_number (c, cfile); ttok = read_number (c, cfile);
break; break;
} else if (isascii (c) && isalpha (c)) { } else if (isascii (c) && isalpha (c)) {
lexline = l;
lexchar = p;
ttok = read_num_or_atom (c, cfile); ttok = read_num_or_atom (c, cfile);
break; break;
} else { } else {
lexline = l;
lexchar = p;
tb [0] = c; tb [0] = c;
tb [1] = 0; tb [1] = 0;
tval = tb; tval = tb;
@ -128,6 +147,8 @@ int next_token (rval, cfile)
int rv; int rv;
if (token) { if (token) {
lexchar = tlpos;
lexline = tline;
rv = token; rv = token;
token = 0; token = 0;
} else { } else {
@ -145,8 +166,15 @@ int peek_token (rval, cfile)
char **rval; char **rval;
FILE *cfile; FILE *cfile;
{ {
if (!token) int x;
if (!token) {
tlpos = lexchar;
tline = lexline;
token = get_token (cfile); token = get_token (cfile);
x = lexchar; lexchar = tlpos; tlpos = x;
x = lexline; lexline = tline; tline = x;
}
if (rval) if (rval)
*rval = tval; *rval = tval;
#ifdef DEBUG_TOKENS #ifdef DEBUG_TOKENS
@ -268,6 +296,9 @@ static int intern (atom, dfv)
return dfv; return dfv;
switch (tolower (atom [0])) { switch (tolower (atom [0])) {
case 'b':
if (!strcasecmp (atom + 1, "oot-unknown-clients"))
return BOOT_UNKNOWN_CLIENTS;
case 'c': case 'c':
if (!strcasecmp (atom + 1, "lass")) if (!strcasecmp (atom + 1, "lass"))
return CLASS; return CLASS;
@ -277,8 +308,14 @@ static int intern (atom, dfv)
case 'd': case 'd':
if (!strcasecmp (atom + 1, "efault-lease-time")) if (!strcasecmp (atom + 1, "efault-lease-time"))
return DEFAULT_LEASE_TIME; return DEFAULT_LEASE_TIME;
if (!strcasecmp (atom + 1, "ynamic-bootp")) if (!strncasecmp (atom + 1, "ynamic-bootp", 12)) {
return DYNAMIC_BOOTP; if (!atom [13])
return DYNAMIC_BOOTP;
else if (!strcasecmp (atom + 13, "-lease-cutoff"))
return DYNAMIC_BOOTP_LEASE_CUTOFF;
else if (!strcasecmp (atom + 13, "-lease-length"))
return DYNAMIC_BOOTP_LEASE_LENGTH;
}
break; break;
case 'e': case 'e':
if (!strcasecmp (atom + 1, "thernet")) if (!strcasecmp (atom + 1, "thernet"))
@ -295,6 +332,8 @@ static int intern (atom, dfv)
case 'g': case 'g':
if (!strcasecmp (atom + 1, "iaddr")) if (!strcasecmp (atom + 1, "iaddr"))
return GIADDR; return GIADDR;
if (!strcasecmp (atom + 1, "roup"))
return GROUP;
break; break;
case 'h': case 'h':
if (!strcasecmp (atom + 1, "ost")) if (!strcasecmp (atom + 1, "ost"))
@ -313,6 +352,8 @@ static int intern (atom, dfv)
case 'n': case 'n':
if (!strcasecmp (atom + 1, "etmask")) if (!strcasecmp (atom + 1, "etmask"))
return NETMASK; return NETMASK;
if (!strcasecmp (atom + 1, "ext-server"))
return NEXT_SERVER;
break; break;
case 'p': case 'p':
if (!strcasecmp (atom + 1, "acket")) if (!strcasecmp (atom + 1, "acket"))
@ -343,6 +384,8 @@ static int intern (atom, dfv)
case 't': case 't':
if (!strcasecmp (atom + 1, "imestamp")) if (!strcasecmp (atom + 1, "imestamp"))
return TIMESTAMP; return TIMESTAMP;
if (!strcasecmp (atom + 1, "oken-ring"))
return TOKEN_RING;
break; break;
case 'u': case 'u':
if (!strcasecmp (atom + 1, "id")) if (!strcasecmp (atom + 1, "id"))