parse.c 44.9 KB
Newer Older
1 2 3 4 5
/* parse.c

   Common parser code for dhcpd and dhclient. */

/*
6
 * Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium.
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
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of The Internet Software Consortium nor the names
 *    of its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * This software has been written for the Internet Software Consortium
 * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
 * Enterprises.  To learn more about the Internet Software Consortium,
 * see ``http://www.vix.com/isc''.  To learn more about Vixie
 * Enterprises, see ``http://www.vix.com''.
 */

#ifndef lint
static char copyright[] =
45
"$Id: parse.c,v 1.11 1998/11/06 02:42:48 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#endif /* not lint */

#include "dhcpd.h"
#include "dhctoken.h"

/* Skip to the semicolon ending the current statement.   If we encounter
   braces, the matching closing brace terminates the statement.   If we
   encounter a right brace but haven't encountered a left brace, return
   leaving the brace in the token buffer for the caller.   If we see a
   semicolon and haven't seen a left brace, return.   This lets us skip
   over:

   	statement;
	statement foo bar { }
	statement foo bar { statement { } }
	statement}
 
	...et cetera. */

void skip_to_semi (cfile)
	FILE *cfile;
{
68
	enum dhcp_token token;
69 70 71 72 73 74
	char *val;
	int brace_count = 0;

	do {
		token = peek_token (&val, cfile);
		if (token == RBRACE) {
75
			token = next_token (&val, cfile);
76 77 78 79 80 81 82 83 84 85
			if (brace_count) {
				if (!--brace_count)
					return;
			} else
				return;
		} else if (token == LBRACE) {
			brace_count++;
		} else if (token == SEMI && !brace_count) {
			token = next_token (&val, cfile);
			return;
86 87 88 89 90 91
		} else if (token == EOL) {
			/* EOL only happens when parsing /etc/resolv.conf,
			   and we treat it like a semicolon because the
			   resolv.conf file is line-oriented. */
			token = next_token (&val, cfile);
			return;
92 93 94 95 96 97 98 99
		}
		token = next_token (&val, cfile);
	} while (token != EOF);
}

int parse_semi (cfile)
	FILE *cfile;
{
100
	enum dhcp_token token;
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
	char *val;

	token = next_token (&val, cfile);
	if (token != SEMI) {
		parse_warn ("semicolon expected.");
		skip_to_semi (cfile);
		return 0;
	}
	return 1;
}

/* string-parameter :== STRING SEMI */

char *parse_string (cfile)
	FILE *cfile;
{
	char *val;
118
	enum dhcp_token token;
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
	char *s;

	token = next_token (&val, cfile);
	if (token != STRING) {
		parse_warn ("filename must be a string");
		skip_to_semi (cfile);
		return (char *)0;
	}
	s = (char *)malloc (strlen (val) + 1);
	if (!s)
		error ("no memory for string %s.", val);
	strcpy (s, val);

	if (!parse_semi (cfile))
		return (char *)0;
	return s;
}

137 138 139 140 141
/*
 * hostname :== IDENTIFIER
 *		| IDENTIFIER DOT
 *		| hostname DOT IDENTIFIER
 */
142 143 144 145 146

char *parse_host_name (cfile)
	FILE *cfile;
{
	char *val;
147
	enum dhcp_token token;
148 149 150 151 152 153 154 155
	int len = 0;
	char *s;
	char *t;
	pair c = (pair)0;
	
	/* Read a dotted hostname... */
	do {
		/* Read a token, which should be an identifier. */
Ted Lemon's avatar
Ted Lemon committed
156 157 158
		token = peek_token (&val, cfile);
		if (!is_identifier (token) && token != NUMBER)
			break;
159
		token = next_token (&val, cfile);
Ted Lemon's avatar
Ted Lemon committed
160

161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
		/* Store this identifier... */
		if (!(s = (char *)malloc (strlen (val) + 1)))
			error ("can't allocate temp space for hostname.");
		strcpy (s, val);
		c = cons ((caddr_t)s, c);
		len += strlen (s) + 1;
		/* Look for a dot; if it's there, keep going, otherwise
		   we're done. */
		token = peek_token (&val, cfile);
		if (token == DOT)
			token = next_token (&val, cfile);
	} while (token == DOT);

	/* Assemble the hostname together into a string. */
	if (!(s = (char *)malloc (len)))
		error ("can't allocate space for hostname.");
	t = s + len;
	*--t = 0;
	while (c) {
		pair cdr = c -> cdr;
		int l = strlen ((char *)(c -> car));
		t -= l;
		memcpy (t, (char *)(c -> car), l);
		/* Free up temp space. */
		free (c -> car);
		free (c);
		c = cdr;
		if (t != s)
			*--t = '.';
	}
	return s;
}

194 195 196 197 198 199 200
/* ip-addr-or-hostname :== ip-address | hostname
   ip-address :== NUMBER DOT NUMBER DOT NUMBER DOT NUMBER
   
   Parse an ip address or a hostname.   If uniform is zero, put in
   an expr_substring node to limit hostnames that evaluate to more
   than one IP address. */

201 202
int parse_ip_addr_or_hostname (expr, cfile, uniform)
	struct expression **expr;
203 204 205 206
	FILE *cfile;
	int uniform;
{
	char *val;
207
	enum dhcp_token token;
208 209 210
	unsigned char addr [4];
	int len = sizeof addr;
	char *name;
211
	struct expression *x = (struct expression *)0;
212 213 214 215 216

	token = peek_token (&val, cfile);
	if (is_identifier (token)) {
		name = parse_host_name (cfile);
		if (!name)
217 218 219 220 221 222 223 224 225 226
			return 0;
		if (!make_host_lookup (expr, name))
			return 0;
		if (!uniform) {
			if (!make_limit (&x, *expr, 4))
				return 0;
			expression_dereference (expr,
						"parse_ip_addr_or_hostname");
			*expr = x;
		}
227 228
	} else if (token == NUMBER) {
		if (!parse_numeric_aggregate (cfile, addr, &len, DOT, 10, 8))
229 230
			return 0;
		return make_const_data (expr, addr, len, 0, 1);
231 232 233 234 235 236 237
	} else {
		if (token != RBRACE && token != LBRACE)
			token = next_token (&val, cfile);
		parse_warn ("%s (%d): expecting IP address or hostname",
			    val, token);
		if (token != SEMI)
			skip_to_semi (cfile);
238
		return 0;
239 240
	}

241
	return 1;
242 243 244 245 246 247
}	
	
/*
 * ip-address :== NUMBER DOT NUMBER DOT NUMBER DOT NUMBER
 */

248 249 250 251 252
int parse_ip_addr (cfile, addr)
	FILE *cfile;
	struct iaddr *addr;
{
	char *val;
253
	enum dhcp_token token;
254 255 256 257 258 259 260 261

	addr -> len = 4;
	if (parse_numeric_aggregate (cfile, addr -> iabuf,
				     &addr -> len, DOT, 10, 8))
		return 1;
	return 0;
}	

262 263 264 265
/*
 * hardware-parameter :== HARDWARE hardware-type colon-seperated-hex-list SEMI
 * hardware-type :== ETHERNET | TOKEN_RING
 */
266 267 268 269 270 271

void parse_hardware_param (cfile, hardware)
	FILE *cfile;
	struct hardware *hardware;
{
	char *val;
272
	enum dhcp_token token;
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
	int hlen;
	unsigned char *t;

	token = next_token (&val, cfile);
	switch (token) {
	      case ETHERNET:
		hardware -> htype = HTYPE_ETHER;
		break;
	      case TOKEN_RING:
		hardware -> htype = HTYPE_IEEE802;
		break;
	      default:
		parse_warn ("expecting a network hardware type");
		skip_to_semi (cfile);
		return;
	}

	/* Parse the hardware address information.   Technically,
	   it would make a lot of sense to restrict the length of the
	   data we'll accept here to the length of a particular hardware
	   address type.   Unfortunately, there are some broken clients
	   out there that put bogus data in the chaddr buffer, and we accept
	   that data in the lease file rather than simply failing on such
	   clients.   Yuck. */
	hlen = 0;
	t = parse_numeric_aggregate (cfile, (unsigned char *)0, &hlen,
				     COLON, 16, 8);
	if (!t)
		return;
	if (hlen > sizeof hardware -> haddr) {
		free (t);
		parse_warn ("hardware address too long");
	} else {
		hardware -> hlen = hlen;
		memcpy ((unsigned char *)&hardware -> haddr [0],
			t, hardware -> hlen);
		free (t);
	}
	
	token = next_token (&val, cfile);
	if (token != SEMI) {
		parse_warn ("expecting semicolon.");
		skip_to_semi (cfile);
	}
}

/* lease-time :== NUMBER SEMI */

void parse_lease_time (cfile, timep)
	FILE *cfile;
	TIME *timep;
{
	char *val;
326
	enum dhcp_token token;
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357

	token = next_token (&val, cfile);
	if (token != NUMBER) {
		parse_warn ("Expecting numeric lease time");
		skip_to_semi (cfile);
		return;
	}
	convert_num ((unsigned char *)timep, val, 10, 32);
	/* Unswap the number - convert_num returns stuff in NBO. */
	*timep = ntohl (*timep); /* XXX */

	parse_semi (cfile);
}

/* No BNF for numeric aggregates - that's defined by the caller.  What
   this function does is to parse a sequence of numbers seperated by
   the token specified in seperator.  If max is zero, any number of
   numbers will be parsed; otherwise, exactly max numbers are
   expected.  Base and size tell us how to internalize the numbers
   once they've been tokenized. */

unsigned char *parse_numeric_aggregate (cfile, buf,
					max, seperator, base, size)
	FILE *cfile;
	unsigned char *buf;
	int *max;
	int seperator;
	int base;
	int size;
{
	char *val;
358
	enum dhcp_token token;
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
	unsigned char *bufp = buf, *s, *t;
	int count = 0;
	pair c = (pair)0;

	if (!bufp && *max) {
		bufp = (unsigned char *)malloc (*max * size / 8);
		if (!bufp)
			error ("can't allocate space for numeric aggregate");
	} else
		s = bufp;

	do {
		if (count) {
			token = peek_token (&val, cfile);
			if (token != seperator) {
				if (!*max)
					break;
				if (token != RBRACE && token != LBRACE)
					token = next_token (&val, cfile);
				parse_warn ("too few numbers.");
				if (token != SEMI)
					skip_to_semi (cfile);
				return (unsigned char *)0;
			}
			token = next_token (&val, cfile);
		}
		token = next_token (&val, cfile);

		if (token == EOF) {
			parse_warn ("unexpected end of file");
			break;
		}

		/* Allow NUMBER_OR_NAME if base is 16. */
		if (token != NUMBER &&
		    (base != 16 || token != NUMBER_OR_NAME)) {
			parse_warn ("expecting numeric value.");
			skip_to_semi (cfile);
			return (unsigned char *)0;
		}
		/* If we can, convert the number now; otherwise, build
		   a linked list of all the numbers. */
		if (s) {
			convert_num (s, val, base, size);
			s += size / 8;
		} else {
			t = (unsigned char *)malloc (strlen (val) + 1);
			if (!t)
				error ("no temp space for number.");
408 409
			strcpy ((char *)t, val);
			c = cons ((caddr_t)t, c);
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
		}
	} while (++count != *max);

	/* If we had to cons up a list, convert it now. */
	if (c) {
		bufp = (unsigned char *)malloc (count * size / 8);
		if (!bufp)
			error ("can't allocate space for numeric aggregate.");
		s = bufp + count - size / 8;
		*max = count;
	}
	while (c) {
		pair cdr = c -> cdr;
		convert_num (s, (char *)(c -> car), base, size);
		s -= size / 8;
		/* Free up temp space. */
		free (c -> car);
		free (c);
		c = cdr;
	}
	return bufp;
}

void convert_num (buf, str, base, size)
	unsigned char *buf;
	char *str;
	int base;
	int size;
{
	char *ptr = str;
	int negative = 0;
	u_int32_t val = 0;
	int tval;
	int max;

	if (*ptr == '-') {
		negative = 1;
		++ptr;
	}

	/* If base wasn't specified, figure it out from the data. */
	if (!base) {
		if (ptr [0] == '0') {
			if (ptr [1] == 'x') {
				base = 16;
				ptr += 2;
			} else if (isascii (ptr [1]) && isdigit (ptr [1])) {
				base = 8;
				ptr += 1;
			} else {
				base = 10;
			}
		} else {
			base = 10;
		}
	}

	do {
		tval = *ptr++;
		/* XXX assumes ASCII... */
		if (tval >= 'a')
			tval = tval - 'a' + 10;
		else if (tval >= 'A')
			tval = tval - 'A' + 10;
		else if (tval >= '0')
			tval -= '0';
		else {
			warn ("Bogus number: %s.", str);
			break;
		}
		if (tval >= base) {
			warn ("Bogus number: %s: digit %d not in base %d\n",
			      str, tval, base);
			break;
		}
		val = val * base + tval;
	} while (*ptr);

	if (negative)
		max = (1 << (size - 1));
	else
		max = (1 << (size - 1)) + ((1 << (size - 1)) - 1);
	if (val > max) {
		switch (base) {
		      case 8:
			warn ("value %s%o exceeds max (%d) for precision.",
			      negative ? "-" : "", val, max);
			break;
		      case 16:
			warn ("value %s%x exceeds max (%d) for precision.",
			      negative ? "-" : "", val, max);
			break;
		      default:
			warn ("value %s%u exceeds max (%d) for precision.",
			      negative ? "-" : "", val, max);
			break;
		}
	}

	if (negative) {
		switch (size) {
		      case 8:
			*buf = -(unsigned long)val;
			break;
		      case 16:
			putShort (buf, -(unsigned long)val);
			break;
		      case 32:
			putLong (buf, -(unsigned long)val);
			break;
		      default:
			warn ("Unexpected integer size: %d\n", size);
			break;
		}
	} else {
		switch (size) {
		      case 8:
			*buf = (u_int8_t)val;
			break;
		      case 16:
			putUShort (buf, (u_int16_t)val);
			break;
		      case 32:
			putULong (buf, val);
			break;
		      default:
			warn ("Unexpected integer size: %d\n", size);
			break;
		}
	}
}

542 543 544 545 546 547 548 549
/*
 * date :== NUMBER NUMBER SLASH NUMBER SLASH NUMBER 
 *		NUMBER COLON NUMBER COLON NUMBER SEMI
 *
 * Dates are always in GMT; first number is day of week; next is
 * year/month/day; next is hours:minutes:seconds on a 24-hour
 * clock.
 */
550 551 552 553 554 555 556

TIME parse_date (cfile)
	FILE *cfile;
{
	struct tm tm;
	int guess;
	char *val;
557
	enum dhcp_token token;
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
	static int months [11] = { 31, 59, 90, 120, 151, 181,
					  212, 243, 273, 304, 334 };

	/* Day of week... */
	token = next_token (&val, cfile);
	if (token != NUMBER) {
		parse_warn ("numeric day of week expected.");
		if (token != SEMI)
			skip_to_semi (cfile);
		return (TIME)0;
	}
	tm.tm_wday = atoi (val);

	/* Year... */
	token = next_token (&val, cfile);
	if (token != NUMBER) {
		parse_warn ("numeric year expected.");
		if (token != SEMI)
			skip_to_semi (cfile);
		return (TIME)0;
	}
579 580 581 582 583

	/* Note: the following is not a Y2K bug - it's a Y1.9K bug.   Until
	   somebody invents a time machine, I think we can safely disregard
	   it.   This actually works around a stupid Y2K bug that was present
	   in a very early beta release of dhcpd. */
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
	tm.tm_year = atoi (val);
	if (tm.tm_year > 1900)
		tm.tm_year -= 1900;

	/* Slash seperating year from month... */
	token = next_token (&val, cfile);
	if (token != SLASH) {
		parse_warn ("expected slash seperating year from month.");
		if (token != SEMI)
			skip_to_semi (cfile);
		return (TIME)0;
	}

	/* Month... */
	token = next_token (&val, cfile);
	if (token != NUMBER) {
		parse_warn ("numeric month expected.");
		if (token != SEMI)
			skip_to_semi (cfile);
		return (TIME)0;
	}
	tm.tm_mon = atoi (val) - 1;

	/* Slash seperating month from day... */
	token = next_token (&val, cfile);
	if (token != SLASH) {
		parse_warn ("expected slash seperating month from day.");
		if (token != SEMI)
			skip_to_semi (cfile);
		return (TIME)0;
	}

	/* Month... */
	token = next_token (&val, cfile);
	if (token != NUMBER) {
		parse_warn ("numeric day of month expected.");
		if (token != SEMI)
			skip_to_semi (cfile);
		return (TIME)0;
	}
	tm.tm_mday = atoi (val);

	/* Hour... */
	token = next_token (&val, cfile);
	if (token != NUMBER) {
		parse_warn ("numeric hour expected.");
		if (token != SEMI)
			skip_to_semi (cfile);
		return (TIME)0;
	}
	tm.tm_hour = atoi (val);

	/* Colon seperating hour from minute... */
	token = next_token (&val, cfile);
	if (token != COLON) {
		parse_warn ("expected colon seperating hour from minute.");
		if (token != SEMI)
			skip_to_semi (cfile);
		return (TIME)0;
	}

	/* Minute... */
	token = next_token (&val, cfile);
	if (token != NUMBER) {
		parse_warn ("numeric minute expected.");
		if (token != SEMI)
			skip_to_semi (cfile);
		return (TIME)0;
	}
	tm.tm_min = atoi (val);

	/* Colon seperating minute from second... */
	token = next_token (&val, cfile);
	if (token != COLON) {
		parse_warn ("expected colon seperating hour from minute.");
		if (token != SEMI)
			skip_to_semi (cfile);
		return (TIME)0;
	}

	/* Minute... */
	token = next_token (&val, cfile);
	if (token != NUMBER) {
		parse_warn ("numeric minute expected.");
		if (token != SEMI)
			skip_to_semi (cfile);
		return (TIME)0;
	}
	tm.tm_sec = atoi (val);
	tm.tm_isdst = 0;

	/* XXX */ /* We assume that mktime does not use tm_yday. */
	tm.tm_yday = 0;

	/* Make sure the date ends in a semicolon... */
Ted Lemon's avatar
Ted Lemon committed
679
	if (!parse_semi (cfile))
680 681 682 683
		return 0;

	/* Guess the time value... */
	guess = ((((((365 * (tm.tm_year - 70) +	/* Days in years since '70 */
684
		      (tm.tm_year - 69) / 4 +	/* Leap days since '70 */
685 686 687 688
		      (tm.tm_mon		/* Days in months this year */
		       ? months [tm.tm_mon - 1]
		       : 0) +
		      (tm.tm_mon > 1 &&		/* Leap day this year */
689 690
		       !((tm.tm_year - 72) & 3)) +
		      tm.tm_mday - 1) * 24) +	/* Day of month */
691 692 693 694 695 696 697 698 699 700 701 702 703 704
		    tm.tm_hour) * 60) +
		  tm.tm_min) * 60) + tm.tm_sec;

	/* This guess could be wrong because of leap seconds or other
	   weirdness we don't know about that the system does.   For
	   now, we're just going to accept the guess, but at some point
	   it might be nice to do a successive approximation here to
	   get an exact value.   Even if the error is small, if the
	   server is restarted frequently (and thus the lease database
	   is reread), the error could accumulate into something
	   significant. */

	return guess;
}
705

706 707 708 709 710
/*
 * option-name :== IDENTIFIER |
 		   IDENTIFIER . IDENTIFIER
 */

711 712 713 714
struct option *parse_option_name (cfile)
	FILE *cfile;
{
	char *val;
715
	enum dhcp_token token;
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
	char *vendor;
	struct universe *universe;
	struct option *option;

	token = next_token (&val, cfile);
	if (!is_identifier (token)) {
		parse_warn ("expecting identifier after option keyword.");
		if (token != SEMI)
			skip_to_semi (cfile);
		return (struct option *)0;
	}
	vendor = malloc (strlen (val) + 1);
	if (!vendor)
		error ("no memory for vendor information.");
	strcpy (vendor, val);
	token = peek_token (&val, cfile);
	if (token == DOT) {
		/* Go ahead and take the DOT token... */
		token = next_token (&val, cfile);

		/* The next token should be an identifier... */
		token = next_token (&val, cfile);
		if (!is_identifier (token)) {
			parse_warn ("expecting identifier after '.'");
			if (token != SEMI)
				skip_to_semi (cfile);
			return (struct option *)0;
		}

		/* Look up the option name hash table for the specified
		   vendor. */
		universe = ((struct universe *)
			    hash_lookup (&universe_hash,
					 (unsigned char *)vendor, 0));
		/* If it's not there, we can't parse the rest of the
		   declaration. */
		if (!universe) {
			parse_warn ("no vendor named %s.", vendor);
			skip_to_semi (cfile);
			return (struct option *)0;
		}
	} else {
		/* Use the default hash table, which contains all the
		   standard dhcp option names. */
		val = vendor;
		universe = &dhcp_universe;
	}

	/* Look up the actual option info... */
	option = (struct option *)hash_lookup (universe -> hash,
					       (unsigned char *)val, 0);

	/* If we didn't get an option structure, it's an undefined option. */
	if (!option) {
		if (val == vendor)
			parse_warn ("no option named %s", val);
		else
			parse_warn ("no option named %s for vendor %s",
				    val, vendor);
		skip_to_semi (cfile);
		return (struct option *)0;
	}

	/* Free the initial identifier token. */
	free (vendor);
	return option;
}

784 785 786 787 788
/*
 * colon-seperated-hex-list :== NUMBER |
 *				NUMBER COLON colon-seperated-hex-list
 */

789 790
int parse_cshl (data, cfile)
	struct data_string *data;
791 792 793 794 795 796 797
	FILE *cfile;
{
	char ibuf [128];
	int ilen = 0;
	int tlen = 0;
	struct option_tag *sl = (struct option_tag *)0;
	struct option_tag *next, **last = &sl;
798
	enum dhcp_token token;
799
	char *val;
800
	unsigned char *rvp;
801 802 803 804 805 806 807 808 809 810

	do {
		token = next_token (&val, cfile);
		if (token != NUMBER && token != NUMBER_OR_NAME) {
			parse_warn ("expecting hexadecimal number.");
			skip_to_semi (cfile);
			for (; sl; sl = next) {
				next = sl -> next;
				dfree (sl, "parse_cshl");
			}
811
			return 0;
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833
		}
		if (ilen == sizeof ibuf) {
			next = (struct option_tag *)
				dmalloc (ilen - 1 +
					 sizeof (struct option_tag),
					 "parse_cshl");
			if (!next)
				error ("no memory for string list.");
			memcpy (next -> data, ibuf, ilen);
			*last = next;
			last = &next -> next;
			tlen += ilen;
			ilen = 0;
		}
		convert_num (&ibuf [ilen++], val, 16, 8);

		token = peek_token (&val, cfile);
		if (token != COLON)
			break;
		token = next_token (&val, cfile);
	} while (1);

834
	if (!buffer_allocate (&data -> buffer, tlen + ilen, "parse_cshl"))
835
		error ("no memory to store octet data.");
836 837 838 839 840
	data -> data = &data -> buffer -> data [0];
	data -> len = tlen + ilen;
	data -> terminated = 0;

	rvp = &data -> data [0];
841 842 843 844 845 846 847 848 849
	while (sl) {
		next = sl -> next;
		memcpy (rvp, sl -> data, sizeof ibuf);
		rvp += sizeof ibuf;
		dfree (sl, "parse_cshl");
		sl = next;
	}
	
	memcpy (rvp, ibuf, ilen);
850
	return 1;
851
}
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875

/*
 * executable-statements :== executable-statement executable-statements |
 *			     executable-statement
 *
 * executable-statement :==
 *	IF if-statement |
 * 	ADD class-name SEMI |
 *	BREAK SEMI |
 *	OPTION option-parameter SEMI |
 *	SUPERSEDE option-parameter SEMI |
 *	PREPEND option-parameter SEMI |
 *	APPEND option-parameter SEMI
 */

struct executable_statement *parse_executable_statements (cfile, lose)
	FILE *cfile;
	int *lose;
{
	struct executable_statement *head, **next;

	next = &head;
	while ((*next = parse_executable_statement (cfile, lose)))
		next = &((*next) -> next);
876
	if (!*lose)
877 878 879 880 881 882 883 884
		return head;
	return (struct executable_statement *)0;
}

struct executable_statement *parse_executable_statement (cfile, lose)
	FILE *cfile;
	int *lose;
{
885
	enum dhcp_token token;
886 887 888 889 890 891 892 893 894 895
	char *val;
	struct executable_statement *stmt, base;
	struct class *cta;
	struct option *option;

	switch (peek_token (&val, cfile)) {
	      case IF:
		stmt = parse_if_statement (cfile, lose);
		return stmt;
	      case ADD:
896
		token = next_token (&val, cfile);
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
		token = next_token (&val, cfile);
		if (token != STRING) {
			parse_warn ("expecting class name.");
			skip_to_semi (cfile);
			*lose = 1;
			return (struct executable_statement *)0;
		}
		cta = find_class (val);
		if (!cta) {
			parse_warn ("unknown class %s.", val);
			skip_to_semi (cfile);
			*lose = 1;
			return (struct executable_statement *)0;
		}
		if (!parse_semi (cfile)) {
			*lose = 1;
			return (struct executable_statement *)0;
		}
		memset (&base, 0, sizeof base);
		base.op = add_statement;
		base.data.add = cta;
		break;

	      case BREAK:
		token = next_token (&val, cfile);
		if (!parse_semi (cfile)) {
			*lose = 1;
			return (struct executable_statement *)0;
		}
		memset (&base, 0, sizeof base);
		base.op = break_statement;
		break;

Ted Lemon's avatar
Ted Lemon committed
930 931 932 933 934 935 936
	      case SEND:
		*lose = 1;
		parse_warn ("send not appropriate here.");
		skip_to_semi (cfile);
		return (struct executable_statement *)0;

	      case SUPERSEDE:
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
	      case OPTION:
		token = next_token (&val, cfile);
		option = parse_option_name (cfile);
		if (!option) {
			*lose = 1;
			return (struct executable_statement *)0;
		}
		return parse_option_statement (cfile, 1, option,
					       supersede_option_statement);

	      case DEFAULT:
		token = next_token (&val, cfile);
		option = parse_option_name (cfile);
		if (!option) {
			*lose = 1;
			return (struct executable_statement *)0;
		}
		return parse_option_statement (cfile, 1, option,
					       default_option_statement);

	      case PREPEND:
		token = next_token (&val, cfile);
		option = parse_option_name (cfile);
		if (!option) {
			*lose = 1;
			return (struct executable_statement *)0;
		}
		return parse_option_statement (cfile, 1, option,
					       prepend_option_statement);

	      case APPEND:
		token = next_token (&val, cfile);
		option = parse_option_name (cfile);
		if (!option) {
			*lose = 1;
			return (struct executable_statement *)0;
		}
		return parse_option_statement (cfile, 1, option,
					       append_option_statement);

	      default:
		*lose = 0;
		return (struct executable_statement *)0;
	}

	stmt = ((struct executable_statement *)
		dmalloc (sizeof (struct executable_statement),
			 "parse_executable_statement"));
	if (!stmt)
		error ("no memory for new statement.");
	*stmt = base;
	return stmt;
}

/*
 * if-statement :== boolean-expression LBRACE executable-statements RBRACE
 *						else-statement
 *
 * else-statement :== <null> |
 *		      ELSE LBRACE executable-statements RBRACE |
 *		      ELSE IF if-statement |
 *		      ELSIF if-statement
 */

struct executable_statement *parse_if_statement (cfile, lose)
	FILE *cfile;
	int *lose;
{
1005
	enum dhcp_token token;
1006 1007 1008 1009 1010 1011
	char *val;
	struct executable_statement *stmt;
	struct expression *if_condition;
	struct executable_statement *true, *false;

	token = next_token (&val, cfile);
1012 1013
	if_condition = (struct expression *)0;
	if (!parse_boolean_expression (&if_condition, cfile, lose)) {
1014 1015 1016 1017
		if (!*lose)
			parse_warn ("boolean expression expected.");
		return (struct executable_statement *)0;
	}
1018 1019 1020
#if defined (DEBUG_EXPRESSION_PARSE)
	print_expression ("if condition", if_condition);
#endif
1021 1022 1023 1024 1025 1026 1027 1028 1029
	token = next_token (&val, cfile);
	if (token != LBRACE) {
		parse_warn ("left brace expected.");
		skip_to_semi (cfile);
		*lose = 1;
		return (struct executable_statement *)0;
	}
	true = parse_executable_statements (cfile, lose);
	token = next_token (&val, cfile);
1030 1031 1032 1033 1034 1035 1036
	if (*lose) {
		/* Try to even things up. */
		do {
			token = next_token (&val, cfile);
		} while (token != EOF && token != RBRACE);
		return (struct executable_statement *)0;
	}
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
	if (token != RBRACE) {
		parse_warn ("right brace expected.");
		skip_to_semi (cfile);
		*lose = 1;
		return (struct executable_statement *)0;
	}
	token = peek_token (&val, cfile);
	if (token == ELSE) {
		token = next_token (&val, cfile);
		token = peek_token (&val, cfile);
		if (token == IF) {
			token = next_token (&val, cfile);
			false = parse_if_statement (cfile, lose);
			if (*lose)
				return (struct executable_statement *)0;
		} else if (token != LBRACE) {
			parse_warn ("left brace or if expected.");
			skip_to_semi (cfile);
			*lose = 1;
			return (struct executable_statement *)0;
		} else {
			token = next_token (&val, cfile);
Ted Lemon's avatar
Ted Lemon committed
1059
			false = parse_executable_statements (cfile, lose);
1060 1061
			if (*lose)
				return (struct executable_statement *)0;
Ted Lemon's avatar
Ted Lemon committed
1062 1063 1064 1065 1066 1067 1068
			token = next_token (&val, cfile);
			if (token != RBRACE) {
				parse_warn ("right brace expected.");
				skip_to_semi (cfile);
				*lose = 1;
				return (struct executable_statement *)0;
			}
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
		}
	} else if (token == ELSIF) {
		token = next_token (&val, cfile);
		false = parse_if_statement (cfile, lose);
		if (*lose)
			return (struct executable_statement *)0;
	} else
		false = (struct executable_statement *)0;
	
	stmt = ((struct executable_statement *)
		dmalloc (sizeof (struct executable_statement),
			 "parse_if_statement"));
	if (!stmt)
		error ("no memory for if statement.");
	memset (stmt, 0, sizeof *stmt);
	stmt -> op = if_statement;
	stmt -> data.ie.expr = if_condition;
	stmt -> data.ie.true = true;
	stmt -> data.ie.false = false;
	return stmt;
}

/*
 * boolean_expression :== CHECK STRING |
 *  			  NOT boolean-expression |
 *			  data-expression EQUAL data-expression |
 *			  boolean-expression AND boolean-expression |
 *			  boolean-expression OR boolean-expression
1097
 *			  EXISTS OPTION-NAME
1098 1099
 */
   			  
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174
int parse_boolean_expression (expr, cfile, lose)
	struct expression **expr;
	FILE *cfile;
	int *lose;
{
	/* Parse an expression... */
	if (!parse_expression (expr, cfile, lose, context_boolean,
			       (struct expression **)0, expr_none))
		return 0;

	if (!is_boolean_expression (*expr)) {
		parse_warn ("Expecting a boolean expression.");
		*lose = 1;
		return 0;
	}
	return 1;
}

/*
 * data_expression :== SUBSTRING LPAREN data-expression COMMA
 *					numeric-expression COMMA
 *					numeric-expression RPAREN |
 *		       SUFFIX LPAREN data_expression COMMA
 *		       		     numeric-expression |
 *		       OPTION option_name |
 *		       HARDWARE |
 *		       PACKET LPAREN numeric-expression COMMA
 *				     numeric-expression RPAREN |
 *		       STRING |
 *		       colon_seperated_hex_list
 */

int parse_data_expression (expr, cfile, lose)
	struct expression **expr;
	FILE *cfile;
	int *lose;
{
	/* Parse an expression... */
	if (!parse_expression (expr, cfile, lose, context_data,
			       (struct expression **)0, expr_none))
		return 0;

	if (!is_data_expression (*expr)) {
		parse_warn ("Expecting a data expression.");
		*lose = 1;
		return 0;
	}
	return 1;
}

/*
 * numeric-expression :== EXTRACT_INT LPAREN data-expression
 *					     COMMA number RPAREN |
 *			  NUMBER
 */

int parse_numeric_expression (expr, cfile, lose)
	struct expression **expr;
	FILE *cfile;
	int *lose;
{
	/* Parse an expression... */
	if (!parse_expression (expr, cfile, lose, context_numeric,
			       (struct expression **)0, expr_none))
		return 0;

	if (!is_numeric_expression (*expr)) {
		parse_warn ("Expecting a numeric expression.");
		*lose = 1;
		return 0;
	}
	return 1;
}

/* Parse a subexpression that does not contain a binary operator. */
1175

1176 1177
int parse_non_binary (expr, cfile, lose, context)
	struct expression **expr;
1178 1179
	FILE *cfile;
	int *lose;
1180
	enum expression_context context;
1181
{
1182
	enum dhcp_token token;
1183 1184
	char *val;
	struct collection *col;
1185
	struct option *option;
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197

	token = peek_token (&val, cfile);

	/* Check for unary operators... */
	switch (token) {
	      case CHECK:
		token = next_token (&val, cfile);
		token = next_token (&val, cfile);
		if (token != STRING) {
			parse_warn ("string expected.");
			skip_to_semi (cfile);
			*lose = 1;
1198
			return 0;
1199 1200 1201 1202 1203 1204 1205
		}
		for (col = collections; col; col = col -> next)
			if (!strcmp (col -> name, val))
				break;
		if (!col) {
			parse_warn ("unknown collection.");
			*lose = 1;
1206
			return 0;
1207
		}
1208 1209 1210 1211 1212
		if (!expression_allocate (expr, "parse_expression: CHECK"))
			error ("can't allocate expression");
		(*expr) -> op = expr_check;
		(*expr) -> data.check = col;
		break;
1213 1214 1215

	      case NOT:
		token = next_token (&val, cfile);
1216 1217 1218 1219 1220
		if (!expression_allocate (expr, "parse_expression: NOT"))
			error ("can't allocate expression");
		(*expr) -> op = expr_not;
		if (!parse_non_binary (&(*expr) -> data.not,
				       cfile, lose, context)) {
1221
			if (!*lose) {
1222
				parse_warn ("expression expected");
1223 1224 1225
				skip_to_semi (cfile);
			}
			*lose = 1;
1226 1227
			expression_dereference (expr, "parse_expression: NOT");
			return 0;
1228 1229 1230
		}
		break;

1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241
	      case EXISTS:
		token = next_token (&val, cfile);
		if (!expression_allocate (expr, "parse_expression: EXISTS"))
			error ("can't allocate expression");
		(*expr) -> op = expr_exists;
		(*expr) -> data.option = parse_option_name (cfile);
		if (!(*expr) -> data.option) {
			*lose = 1;
			expression_dereference (expr,
						"parse_expression: EXISTS");
			return 0;
1242
		}
1243
		break;
1244 1245 1246

	      case SUBSTRING:
		token = next_token (&val, cfile);
1247 1248 1249
		if (!expression_allocate (expr, "parse_expression: SUBSTRING"))
			error ("can't allocate expression");
		(*expr) -> op = expr_substring;
1250 1251 1252 1253

		token = next_token (&val, cfile);
		if (token != LPAREN) {
		      nolparen:
1254 1255
			expression_dereference (expr,
						"parse_expression: nolparen");
1256 1257
			parse_warn ("left parenthesis expected.");
			*lose = 1;
1258
			return 0;
1259 1260
		}

1261 1262
		if (!parse_data_expression (&(*expr) -> data.substring.expr,
					    cfile, lose)) {
1263
		      nodata:
1264 1265
			expression_dereference (expr,
						"parse_expression: nodata");
1266 1267 1268
			parse_warn ("expecting data expression.");
			skip_to_semi (cfile);
			*lose = 1;
1269
			return 0;
1270 1271 1272 1273 1274
		}

		token = next_token (&val, cfile);
		if (token != COMMA) {
		      nocomma:
1275 1276
			expression_dereference (expr,
						"parse_expression: nocomma1");
1277 1278
			parse_warn ("comma expected.");
			*lose = 1;
1279 1280

			return 0;
1281 1282
		}

1283 1284
		if (!parse_numeric_expression
		    (&(*expr) -> data.substring.offset,cfile, lose)) {
1285 1286 1287 1288 1289 1290
		      nonum:
			if (!*lose) {
				parse_warn ("expecting numeric expression.");
				skip_to_semi (cfile);
				*lose = 1;
			}
1291 1292 1293
			expression_dereference (expr,
						"parse_expression: nonum");
			return 0;
1294 1295 1296 1297 1298 1299
		}

		token = next_token (&val, cfile);
		if (token != COMMA)
			goto nocomma;

1300 1301
		if (!parse_numeric_expression
		    (&(*expr) -> data.substring.len, cfile, lose))
1302 1303 1304 1305 1306 1307 1308
			goto nonum;

		token = next_token (&val, cfile);
		if (token != RPAREN) {
		      norparen:
			parse_warn ("right parenthesis expected.");
			*lose = 1;
1309 1310 1311
			expression_dereference (expr,
						"parse_expression: norparen");
			return 0;
1312
		}
1313
		break;
1314 1315 1316

	      case SUFFIX:
		token = next_token (&val, cfile);
1317 1318 1319
		if (!expression_allocate (expr, "parse_expression: SUFFIX"))
			error ("can't allocate expression");
		(*expr) -> op = expr_suffix;
1320 1321 1322 1323 1324

		token = next_token (&val, cfile);
		if (token != LPAREN)
			goto nolparen;

1325 1326
		if (!parse_data_expression (&(*expr) -> data.suffix.expr,
					    cfile, lose))
1327 1328 1329 1330 1331 1332
			goto nodata;

		token = next_token (&val, cfile);
		if (token != COMMA)
			goto nocomma;

1333 1334
		if (!parse_data_expression (&(*expr) -> data.suffix.len,
					    cfile, lose))
1335 1336 1337 1338 1339
			goto nonum;

		token = next_token (&val, cfile);
		if (token != RPAREN)
			goto norparen;
1340
		break;
1341 1342 1343

	      case OPTION:
		token = next_token (&val, cfile);
1344 1345 1346 1347 1348
		if (!expression_allocate (expr, "parse_expression: OPTION"))
			error ("can't allocate expression");
		(*expr) -> op = expr_option;
		(*expr) -> data.option = parse_option_name (cfile);
		if (!(*expr) -> data.option) {
1349
			*lose = 1;
1350 1351 1352
			expression_dereference (expr,
						"parse_expression: OPTION");
			return 0;
1353
		}
1354
		break;
1355 1356 1357

	      case HARDWARE:
		token = next_token (&val, cfile);
1358 1359 1360 1361
		if (!expression_allocate (expr, "parse_expression: HARDWARE"))
			error ("can't allocate expression");
		(*expr) -> op = expr_hardware;
		break;
1362 1363 1364

	      case PACKET:
		token = next_token (&val, cfile);
1365 1366 1367
		if (!expression_allocate (expr, "parse_expression: PACKET"))
			error ("can't allocate expression");
		(*expr) -> op = expr_packet;
1368 1369 1370 1371 1372

		token = next_token (&val, cfile);
		if (token != LPAREN)
			goto nolparen;

1373 1374
		if (!parse_numeric_expression (&(*expr) -> data.packet.offset,
					       cfile, lose))
1375 1376 1377 1378 1379 1380
			goto nonum;

		token = next_token (&val, cfile);
		if (token != COMMA)
			goto nocomma;

1381 1382
		if (!parse_numeric_expression (&(*expr) -> data.packet.len,
					       cfile, lose))
1383 1384 1385 1386 1387
			goto nonum;

		token = next_token (&val, cfile);
		if (token != RPAREN)
			goto norparen;
1388
		break;
1389 1390 1391
		
	      case STRING:
		token = next_token (&val, cfile);
1392 1393 1394
		if (!make_const_data (expr, val, strlen (val), 1, 1))
			error ("can't make constant string expression.");
		break;
1395 1396 1397 1398 1399 1400 1401

	      case EXTRACT_INT:
		token = next_token (&val, cfile);	
		token = next_token (&val, cfile);
		if (token != LPAREN) {
			parse_warn ("left parenthesis expected.");
			*lose = 1;
1402
			return 0;
1403 1404
		}

1405 1406 1407 1408 1409 1410
		if (!expression_allocate (expr,
					  "parse_expression: EXTRACT_INT"))
			error ("can't allocate expression");

		if (!parse_data_expression (&(*expr) -> data.extract_int,
					    cfile, lose)) {
1411 1412 1413
			parse_warn ("expecting data expression.");
			skip_to_semi (cfile);
			*lose = 1;
1414 1415 1416
			expression_dereference
				(expr, "parse_expression: EXTRACT_INT");
			return 0;
1417 1418 1419 1420 1421 1422
		}

		token = next_token (&val, cfile);
		if (token != COMMA) {
			parse_warn ("comma expected.");
			*lose = 1;
1423
			return 0;
1424 1425 1426 1427 1428 1429
		}

		token = next_token (&val, cfile);
		if (token != NUMBER) {
			parse_warn ("number expected.");
			*lose = 1;
1430
			return 0;
1431 1432 1433
		}
		switch (atoi (val)) {
		      case 8:
1434
			(*expr) -> op = expr_extract_int8;
1435 1436 1437
			break;

		      case 16:
1438
			(*expr) -> op = expr_extract_int16;
1439 1440 1441
			break;

		      case 32:
1442
			(*expr) -> op = expr_extract_int32;
1443 1444 1445 1446 1447 1448
			break;

		      default:
			parse_warn ("unsupported integer size %d", atoi (val));
			*lose = 1;
			skip_to_semi (cfile);
1449 1450 1451
			expression_dereference
				(expr, "parse_expression: EXTRACT_INT");
			return 0;
1452 1453 1454 1455 1456 1457
		}

		token = next_token (&val, cfile);
		if (token != RPAREN) {
			parse_warn ("right parenthesis expected.");
			*lose = 1;
1458
			return 0;
1459
		}
1460
		break;
1461 1462
	
	      case NUMBER:
1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474
		if (!expression_allocate (expr,
					  "parse_expression: NUMBER"))
			error ("can't allocate expression");

		/* If we're in a numeric context, this should just be a
		   number, by itself. */
		if (context == context_numeric) {
			next_token (&val, cfile);	/* Eat the number. */
			(*expr) -> op = expr_const_int;
			(*expr) -> data.const_int = atoi (val);
			break;
		}
1475

1476 1477 1478 1479 1480 1481 1482 1483 1484 1485
	      case NUMBER_OR_NAME:
		(*expr) -> op = expr_const_data;
		if (!parse_cshl (&(*expr) -> data.const_data, cfile)) {
			expression_dereference (expr,
						"parse_expression: cshl");
			return 0;
		}
		break;

		/* Not a valid start to an expression... */
1486
	      default:
1487
		return 0;
1488
	}
1489
	return 1;
1490 1491
}

1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633
/* Parse an expression. */

int parse_expression (expr, cfile, lose, context, plhs, binop)
	struct expression **expr;
	FILE *cfile;
	int *lose;
	enum expression_context