10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
220Sstevel@tonic-gate /*
23*350Sdp * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24*350Sdp * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
270Sstevel@tonic-gate /* All Rights Reserved */
280Sstevel@tonic-gate
290Sstevel@tonic-gate
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
320Sstevel@tonic-gate * The Regents of the University of California
330Sstevel@tonic-gate * All Rights Reserved
340Sstevel@tonic-gate *
350Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
360Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
370Sstevel@tonic-gate * contributors.
380Sstevel@tonic-gate */
390Sstevel@tonic-gate
400Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
410Sstevel@tonic-gate
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate * COPYRIGHT NOTICE
440Sstevel@tonic-gate *
450Sstevel@tonic-gate * This software is copyright(C) 1982 by Pavel Curtis
460Sstevel@tonic-gate *
470Sstevel@tonic-gate * Permission is granted to reproduce and distribute
480Sstevel@tonic-gate * this file by any means so long as no fee is charged
490Sstevel@tonic-gate * above a nominal handling fee and so long as this
500Sstevel@tonic-gate * notice is always included in the copies.
510Sstevel@tonic-gate *
520Sstevel@tonic-gate * Other rights are reserved except as explicitly granted
530Sstevel@tonic-gate * by written permission of the author.
540Sstevel@tonic-gate * Pavel Curtis
550Sstevel@tonic-gate * Computer Science Dept.
560Sstevel@tonic-gate * 405 Upson Hall
570Sstevel@tonic-gate * Cornell University
580Sstevel@tonic-gate * Ithaca, NY 14853
590Sstevel@tonic-gate *
600Sstevel@tonic-gate * Ph- (607) 256-4934
610Sstevel@tonic-gate *
620Sstevel@tonic-gate * Pavel.Cornell@Udel-Relay(ARPAnet)
630Sstevel@tonic-gate * decvax!cornell!pavel(UUCPnet)
640Sstevel@tonic-gate */
650Sstevel@tonic-gate
660Sstevel@tonic-gate /*
670Sstevel@tonic-gate * comp_scan.c --- Lexical scanner for terminfo compiler.
680Sstevel@tonic-gate *
690Sstevel@tonic-gate * $Log: RCS/comp_scan.v $
700Sstevel@tonic-gate * Revision 2.1 82/10/25 14:45:55 pavel
710Sstevel@tonic-gate * Added Copyright Notice
720Sstevel@tonic-gate *
730Sstevel@tonic-gate * Revision 2.0 82/10/24 15:17:12 pavel
740Sstevel@tonic-gate * Beta-one Test Release
750Sstevel@tonic-gate *
760Sstevel@tonic-gate * Revision 1.3 82/08/23 22:30:03 pavel
770Sstevel@tonic-gate * The REAL Alpha-one Release Version
780Sstevel@tonic-gate *
790Sstevel@tonic-gate * Revision 1.2 82/08/19 19:10:06 pavel
800Sstevel@tonic-gate * Alpha Test Release One
810Sstevel@tonic-gate *
820Sstevel@tonic-gate * Revision 1.1 82/08/12 18:37:46 pavel
830Sstevel@tonic-gate * Initial revision
840Sstevel@tonic-gate *
850Sstevel@tonic-gate *
860Sstevel@tonic-gate */
870Sstevel@tonic-gate
880Sstevel@tonic-gate
890Sstevel@tonic-gate #include <stdio.h>
900Sstevel@tonic-gate #include <ctype.h>
910Sstevel@tonic-gate #include "compiler.h"
920Sstevel@tonic-gate
930Sstevel@tonic-gate #define iswhite(ch) (ch == ' ' || ch == '\t')
940Sstevel@tonic-gate
950Sstevel@tonic-gate
960Sstevel@tonic-gate static int first_column; /* See 'next_char()' below */
970Sstevel@tonic-gate
98*350Sdp static void backspace(void);
99*350Sdp void reset_input(void);
100*350Sdp void panic_mode(int);
101*350Sdp
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate /*
1050Sstevel@tonic-gate * int
1060Sstevel@tonic-gate * get_token()
1070Sstevel@tonic-gate *
1080Sstevel@tonic-gate * Scans the input for the next token, storing the specifics in the
1090Sstevel@tonic-gate * global structure 'curr_token' and returning one of the following:
1100Sstevel@tonic-gate *
1110Sstevel@tonic-gate * NAMES A line beginning in column 1. 'name'
1120Sstevel@tonic-gate * will be set to point to everything up to
1130Sstevel@tonic-gate * but not including the first comma on the line.
1140Sstevel@tonic-gate * BOOLEAN An entry consisting of a name followed by
1150Sstevel@tonic-gate * a comma. 'name' will be set to point to the
1160Sstevel@tonic-gate * name of the capability.
1170Sstevel@tonic-gate * NUMBER An entry of the form
1180Sstevel@tonic-gate * name#digits,
1190Sstevel@tonic-gate * 'name' will be set to point to the capability
1200Sstevel@tonic-gate * name and 'valnumber' to the number given.
1210Sstevel@tonic-gate * STRING An entry of the form
1220Sstevel@tonic-gate * name=characters,
1230Sstevel@tonic-gate * 'name' is set to the capability name and
1240Sstevel@tonic-gate * 'valstring' to the string of characters, with
1250Sstevel@tonic-gate * input translations done.
1260Sstevel@tonic-gate * CANCEL An entry of the form
1270Sstevel@tonic-gate * name@,
1280Sstevel@tonic-gate * 'name' is set to the capability name and
1290Sstevel@tonic-gate * 'valnumber' to -1.
1300Sstevel@tonic-gate * EOF The end of the file has been reached.
1310Sstevel@tonic-gate *
1320Sstevel@tonic-gate */
1330Sstevel@tonic-gate
1340Sstevel@tonic-gate int
get_token()1350Sstevel@tonic-gate get_token()
1360Sstevel@tonic-gate {
1370Sstevel@tonic-gate long number;
1380Sstevel@tonic-gate int type;
1390Sstevel@tonic-gate register int ch;
1400Sstevel@tonic-gate static char buffer[1024];
1410Sstevel@tonic-gate register char *ptr;
1420Sstevel@tonic-gate int dot_flag = FALSE;
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate while ((ch = next_char()) == '\n' || (isascii(ch) && iswhite(ch)));
1450Sstevel@tonic-gate
1460Sstevel@tonic-gate if (ch == EOF)
1470Sstevel@tonic-gate type = EOF;
1480Sstevel@tonic-gate else {
1490Sstevel@tonic-gate if (ch == '.') {
1500Sstevel@tonic-gate dot_flag = TRUE;
1510Sstevel@tonic-gate
1520Sstevel@tonic-gate while ((ch = next_char()) == ' ' || ch == '\t');
1530Sstevel@tonic-gate }
1540Sstevel@tonic-gate
1550Sstevel@tonic-gate if (! isascii(ch) || ! isalnum(ch)) {
1560Sstevel@tonic-gate warning("Illegal character - '%c'", ch);
1570Sstevel@tonic-gate panic_mode(',');
1580Sstevel@tonic-gate }
1590Sstevel@tonic-gate
1600Sstevel@tonic-gate ptr = buffer;
1610Sstevel@tonic-gate if (ch != '\n') *(ptr++) = ch;
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate if (first_column) {
1640Sstevel@tonic-gate while ((ch = next_char()) != ',' && ch != '\n' && ch != EOF)
1650Sstevel@tonic-gate *(ptr++) = ch;
1660Sstevel@tonic-gate
1670Sstevel@tonic-gate if (ch == EOF)
1680Sstevel@tonic-gate err_abort("Premature EOF");
1690Sstevel@tonic-gate else if (ch == '\n') {
1700Sstevel@tonic-gate warning("Newline in middle of terminal name");
1710Sstevel@tonic-gate panic_mode(',');
1720Sstevel@tonic-gate }
1730Sstevel@tonic-gate
1740Sstevel@tonic-gate *ptr = '\0';
1750Sstevel@tonic-gate curr_token.tk_name = buffer;
1760Sstevel@tonic-gate type = NAMES;
1770Sstevel@tonic-gate } else {
1780Sstevel@tonic-gate ch = next_char();
1790Sstevel@tonic-gate while (isascii(ch) && isalnum(ch)) {
1800Sstevel@tonic-gate *(ptr++) = ch;
1810Sstevel@tonic-gate ch = next_char();
1820Sstevel@tonic-gate }
1830Sstevel@tonic-gate
1840Sstevel@tonic-gate *ptr++ = '\0';
1850Sstevel@tonic-gate switch (ch) {
1860Sstevel@tonic-gate case ',':
1870Sstevel@tonic-gate curr_token.tk_name = buffer;
1880Sstevel@tonic-gate type = BOOLEAN;
1890Sstevel@tonic-gate break;
1900Sstevel@tonic-gate
1910Sstevel@tonic-gate case '@':
1920Sstevel@tonic-gate if (next_char() != ',')
1930Sstevel@tonic-gate warning("Missing comma");
1940Sstevel@tonic-gate curr_token.tk_name = buffer;
1950Sstevel@tonic-gate type = CANCEL;
1960Sstevel@tonic-gate break;
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate case '#':
1990Sstevel@tonic-gate number = 0;
2000Sstevel@tonic-gate if ((ch = next_char()) == ',')
2010Sstevel@tonic-gate warning("Missing numeric value");
2020Sstevel@tonic-gate backspace();
2030Sstevel@tonic-gate if ((ch = next_char()) == '0') {
2040Sstevel@tonic-gate if ((ch = next_char()) == 'x' || ch == 'X') {
2050Sstevel@tonic-gate while (isascii(ch = next_char()) &&
2060Sstevel@tonic-gate isxdigit(ch)) {
2070Sstevel@tonic-gate number *= 16;
2080Sstevel@tonic-gate if (isdigit(ch))
2090Sstevel@tonic-gate number += ch - '0';
2100Sstevel@tonic-gate else if (ch >= 'a' && ch <= 'f')
2110Sstevel@tonic-gate number += 10 + ch - 'a';
2120Sstevel@tonic-gate else
2130Sstevel@tonic-gate number += 10 + ch - 'A';
2140Sstevel@tonic-gate }
2150Sstevel@tonic-gate } else {
2160Sstevel@tonic-gate backspace();
2170Sstevel@tonic-gate while ((ch = next_char()) >= '0' &&
2180Sstevel@tonic-gate ch <= '7')
2190Sstevel@tonic-gate number = number * 8 + ch - '0';
2200Sstevel@tonic-gate }
2210Sstevel@tonic-gate } else {
2220Sstevel@tonic-gate backspace();
2230Sstevel@tonic-gate while (isascii(ch = next_char()) &&
2240Sstevel@tonic-gate isdigit(ch))
2250Sstevel@tonic-gate number = number * 10 + ch - '0';
2260Sstevel@tonic-gate }
2270Sstevel@tonic-gate if (ch != ',')
2280Sstevel@tonic-gate warning("Missing comma");
2290Sstevel@tonic-gate curr_token.tk_name = buffer;
2300Sstevel@tonic-gate curr_token.tk_valnumber = number;
2310Sstevel@tonic-gate type = NUMBER;
2320Sstevel@tonic-gate break;
2330Sstevel@tonic-gate
2340Sstevel@tonic-gate case '=':
2350Sstevel@tonic-gate ch = trans_string(ptr);
2360Sstevel@tonic-gate if (ch != NULL && ch != ',')
2370Sstevel@tonic-gate warning("Missing comma");
2380Sstevel@tonic-gate if (ch == NULL)
2390Sstevel@tonic-gate warning("NULL string value");
2400Sstevel@tonic-gate curr_token.tk_name = buffer;
2410Sstevel@tonic-gate curr_token.tk_valstring = ptr;
2420Sstevel@tonic-gate type = STRING;
2430Sstevel@tonic-gate break;
2440Sstevel@tonic-gate
2450Sstevel@tonic-gate default:
2460Sstevel@tonic-gate warning("Illegal character - '%c'", ch);
2470Sstevel@tonic-gate }
2480Sstevel@tonic-gate } /* end else (first_column == FALSE) */
2490Sstevel@tonic-gate } /* end else (ch != EOF) */
2500Sstevel@tonic-gate
2510Sstevel@tonic-gate if (dot_flag == TRUE)
2520Sstevel@tonic-gate DEBUG(8, "Commented out ", "");
2530Sstevel@tonic-gate
2540Sstevel@tonic-gate if (debug_level >= 8) {
2550Sstevel@tonic-gate fprintf(stderr, "Token: ");
2560Sstevel@tonic-gate switch (type) {
2570Sstevel@tonic-gate case BOOLEAN:
2580Sstevel@tonic-gate fprintf(stderr, "Boolean; name='%s'\n",
2590Sstevel@tonic-gate curr_token.tk_name);
2600Sstevel@tonic-gate break;
2610Sstevel@tonic-gate
2620Sstevel@tonic-gate case NUMBER:
2630Sstevel@tonic-gate fprintf(stderr, "Number; name = '%s', value = %d\n",
2640Sstevel@tonic-gate curr_token.tk_name, curr_token.tk_valnumber);
2650Sstevel@tonic-gate break;
2660Sstevel@tonic-gate
2670Sstevel@tonic-gate case STRING:
2680Sstevel@tonic-gate fprintf(stderr, "String; name = '%s', value = '%s'\n",
2690Sstevel@tonic-gate curr_token.tk_name, curr_token.tk_valstring);
2700Sstevel@tonic-gate break;
2710Sstevel@tonic-gate
2720Sstevel@tonic-gate case CANCEL:
2730Sstevel@tonic-gate fprintf(stderr, "Cancel; name = '%s'\n",
2740Sstevel@tonic-gate curr_token.tk_name);
2750Sstevel@tonic-gate break;
2760Sstevel@tonic-gate
2770Sstevel@tonic-gate case NAMES:
2780Sstevel@tonic-gate fprintf(stderr, "Names; value = '%s'\n",
2790Sstevel@tonic-gate curr_token.tk_name);
2800Sstevel@tonic-gate break;
2810Sstevel@tonic-gate
2820Sstevel@tonic-gate case EOF:
2830Sstevel@tonic-gate fprintf(stderr, "End of file\n");
2840Sstevel@tonic-gate break;
2850Sstevel@tonic-gate
2860Sstevel@tonic-gate default:
2870Sstevel@tonic-gate warning("Bad token type");
2880Sstevel@tonic-gate }
2890Sstevel@tonic-gate }
2900Sstevel@tonic-gate
2910Sstevel@tonic-gate if (dot_flag == TRUE) /* if commented out, use the next one */
2920Sstevel@tonic-gate type = get_token();
2930Sstevel@tonic-gate
2940Sstevel@tonic-gate return (type);
2950Sstevel@tonic-gate }
2960Sstevel@tonic-gate
2970Sstevel@tonic-gate
2980Sstevel@tonic-gate
2990Sstevel@tonic-gate /*
3000Sstevel@tonic-gate * int
3010Sstevel@tonic-gate * next_char()
3020Sstevel@tonic-gate *
3030Sstevel@tonic-gate * Returns the next character in the input stream. Comments and leading
3040Sstevel@tonic-gate * white space are stripped. The global state variable 'firstcolumn' is
3050Sstevel@tonic-gate * set TRUE if the character returned is from the first column of the
3060Sstevel@tonic-gate * inputline. The global variable curr_line is incremented for each new.
3070Sstevel@tonic-gate * line. The global variable curr_file_pos is set to the file offset
3080Sstevel@tonic-gate * of the beginning of each line.
3090Sstevel@tonic-gate *
3100Sstevel@tonic-gate */
3110Sstevel@tonic-gate
3120Sstevel@tonic-gate int curr_column = -1;
3130Sstevel@tonic-gate char line[1024];
3140Sstevel@tonic-gate
3150Sstevel@tonic-gate int
next_char()3160Sstevel@tonic-gate next_char()
3170Sstevel@tonic-gate {
3180Sstevel@tonic-gate char *rtn_value;
3190Sstevel@tonic-gate long ftell();
3200Sstevel@tonic-gate char *p;
3210Sstevel@tonic-gate
3220Sstevel@tonic-gate if (curr_column < 0 || curr_column > 1023 ||
3230Sstevel@tonic-gate line[curr_column] == '\0') {
3240Sstevel@tonic-gate do {
3250Sstevel@tonic-gate curr_file_pos = ftell(stdin);
3260Sstevel@tonic-gate
3270Sstevel@tonic-gate if ((rtn_value = fgets(line, 1024, stdin)) == NULL)
3280Sstevel@tonic-gate return (EOF);
3290Sstevel@tonic-gate curr_line++;
3300Sstevel@tonic-gate p = &line[0];
3310Sstevel@tonic-gate while (*p && iswhite(*p)) {
3320Sstevel@tonic-gate p++;
3330Sstevel@tonic-gate }
3340Sstevel@tonic-gate } while (*p == '#');
3350Sstevel@tonic-gate
3360Sstevel@tonic-gate curr_column = 0;
3370Sstevel@tonic-gate while (isascii(line[curr_column]) && iswhite(line[curr_column]))
3380Sstevel@tonic-gate curr_column++;
3390Sstevel@tonic-gate }
3400Sstevel@tonic-gate
3410Sstevel@tonic-gate if (curr_column == 0 && line[0] != '\n')
3420Sstevel@tonic-gate first_column = TRUE;
3430Sstevel@tonic-gate else
3440Sstevel@tonic-gate first_column = FALSE;
3450Sstevel@tonic-gate
3460Sstevel@tonic-gate return (line[curr_column++]);
3470Sstevel@tonic-gate }
3480Sstevel@tonic-gate
3490Sstevel@tonic-gate
350*350Sdp static void
backspace(void)351*350Sdp backspace(void)
3520Sstevel@tonic-gate {
3530Sstevel@tonic-gate curr_column--;
3540Sstevel@tonic-gate
3550Sstevel@tonic-gate if (curr_column < 0)
356*350Sdp syserr_abort("Backspaced off beginning of line");
3570Sstevel@tonic-gate }
3580Sstevel@tonic-gate
3590Sstevel@tonic-gate
3600Sstevel@tonic-gate
3610Sstevel@tonic-gate /*
3620Sstevel@tonic-gate * reset_input()
3630Sstevel@tonic-gate *
3640Sstevel@tonic-gate * Resets the input-reading routines. Used after a seek has been done.
3650Sstevel@tonic-gate *
3660Sstevel@tonic-gate */
3670Sstevel@tonic-gate
368*350Sdp void
reset_input(void)369*350Sdp reset_input(void)
3700Sstevel@tonic-gate {
3710Sstevel@tonic-gate curr_column = -1;
3720Sstevel@tonic-gate }
3730Sstevel@tonic-gate
3740Sstevel@tonic-gate
3750Sstevel@tonic-gate
3760Sstevel@tonic-gate /*
3770Sstevel@tonic-gate * int
3780Sstevel@tonic-gate * trans_string(ptr)
3790Sstevel@tonic-gate *
3800Sstevel@tonic-gate * Reads characters using next_char() until encountering a comma, a new
3810Sstevel@tonic-gate * entry, or end-of-file. The returned value is the character which
3820Sstevel@tonic-gate * caused reading to stop. The following translations are done on the
3830Sstevel@tonic-gate * input:
3840Sstevel@tonic-gate *
3850Sstevel@tonic-gate * ^X goes to ctrl-X (i.e. X & 037)
3860Sstevel@tonic-gate * {\E,\n,\r,\b,\t,\f} go to
3870Sstevel@tonic-gate * {ESCAPE,newline,carriage-return,backspace,tab,formfeed}
3880Sstevel@tonic-gate * {\^,\\} go to {carat,backslash}
3890Sstevel@tonic-gate * \ddd (for ddd = up to three octal digits) goes to
3900Sstevel@tonic-gate * the character ddd
3910Sstevel@tonic-gate *
3920Sstevel@tonic-gate * \e == \E
3930Sstevel@tonic-gate * \0 == \200
3940Sstevel@tonic-gate *
3950Sstevel@tonic-gate */
3960Sstevel@tonic-gate
3970Sstevel@tonic-gate int
trans_string(char * ptr)3980Sstevel@tonic-gate trans_string(char *ptr)
3990Sstevel@tonic-gate {
4000Sstevel@tonic-gate register int count = 0;
4010Sstevel@tonic-gate int number;
4020Sstevel@tonic-gate register int i;
4030Sstevel@tonic-gate register int ch;
4040Sstevel@tonic-gate
4050Sstevel@tonic-gate while ((ch = next_char()) != ',' && ch != EOF && !first_column) {
4060Sstevel@tonic-gate if (ch == '^') {
4070Sstevel@tonic-gate ch = next_char();
4080Sstevel@tonic-gate if (ch == EOF)
4090Sstevel@tonic-gate err_abort("Premature EOF");
4100Sstevel@tonic-gate
4110Sstevel@tonic-gate if (!isascii(ch) || ! isprint(ch)) {
4120Sstevel@tonic-gate warning("Illegal ^ character - '%c'", ch);
4130Sstevel@tonic-gate }
4140Sstevel@tonic-gate
4150Sstevel@tonic-gate if (ch == '@')
4160Sstevel@tonic-gate *(ptr++) = 0200;
4170Sstevel@tonic-gate else
4180Sstevel@tonic-gate *(ptr++) = ch & 037;
4190Sstevel@tonic-gate } else if (ch == '\\') {
4200Sstevel@tonic-gate ch = next_char();
4210Sstevel@tonic-gate if (ch == EOF)
4220Sstevel@tonic-gate err_abort("Premature EOF");
4230Sstevel@tonic-gate
4240Sstevel@tonic-gate if (ch >= '0' && ch <= '7') {
4250Sstevel@tonic-gate number = ch - '0';
4260Sstevel@tonic-gate for (i = 0; i < 2; i++) {
4270Sstevel@tonic-gate ch = next_char();
4280Sstevel@tonic-gate if (ch == EOF)
4290Sstevel@tonic-gate err_abort("Premature EOF");
4300Sstevel@tonic-gate
4310Sstevel@tonic-gate if (ch < '0' || ch > '7') {
4320Sstevel@tonic-gate backspace();
4330Sstevel@tonic-gate break;
4340Sstevel@tonic-gate }
4350Sstevel@tonic-gate
4360Sstevel@tonic-gate number = number * 8 + ch - '0';
4370Sstevel@tonic-gate }
4380Sstevel@tonic-gate
4390Sstevel@tonic-gate if (number == 0)
4400Sstevel@tonic-gate number = 0200;
4410Sstevel@tonic-gate *(ptr++) = (char)number;
4420Sstevel@tonic-gate } else {
4430Sstevel@tonic-gate switch (ch) {
4440Sstevel@tonic-gate case 'E':
4450Sstevel@tonic-gate case 'e': *(ptr++) = '\033'; break;
4460Sstevel@tonic-gate
4470Sstevel@tonic-gate case 'l':
4480Sstevel@tonic-gate case 'n': *(ptr++) = '\n'; break;
4490Sstevel@tonic-gate
4500Sstevel@tonic-gate case 'r': *(ptr++) = '\r'; break;
4510Sstevel@tonic-gate
4520Sstevel@tonic-gate case 'b': *(ptr++) = '\010'; break;
4530Sstevel@tonic-gate
4540Sstevel@tonic-gate case 's': *(ptr++) = ' '; break;
4550Sstevel@tonic-gate
4560Sstevel@tonic-gate case 'f': *(ptr++) = '\014'; break;
4570Sstevel@tonic-gate
4580Sstevel@tonic-gate case 't': *(ptr++) = '\t'; break;
4590Sstevel@tonic-gate
4600Sstevel@tonic-gate case '\\': *(ptr++) = '\\'; break;
4610Sstevel@tonic-gate
4620Sstevel@tonic-gate case '^': *(ptr++) = '^'; break;
4630Sstevel@tonic-gate
4640Sstevel@tonic-gate case ',': *(ptr++) = ','; break;
4650Sstevel@tonic-gate
4660Sstevel@tonic-gate case ':': *(ptr++) = ':'; break;
4670Sstevel@tonic-gate
4680Sstevel@tonic-gate default:
4690Sstevel@tonic-gate warning("Illegal character in \\ sequence - '%c'",
4700Sstevel@tonic-gate ch);
4710Sstevel@tonic-gate *(ptr++) = ch;
4720Sstevel@tonic-gate } /* endswitch (ch) */
4730Sstevel@tonic-gate } /* endelse (ch < '0' || ch > '7') */
4740Sstevel@tonic-gate } /* end else if (ch == '\\') */
4750Sstevel@tonic-gate else {
4760Sstevel@tonic-gate if (ch != '\n') *(ptr++) = ch;
4770Sstevel@tonic-gate }
4780Sstevel@tonic-gate
4790Sstevel@tonic-gate count ++;
4800Sstevel@tonic-gate
4810Sstevel@tonic-gate if (count > 1000)
4820Sstevel@tonic-gate warning("Very long string found. Missing comma?");
4830Sstevel@tonic-gate } /* end while */
4840Sstevel@tonic-gate
4850Sstevel@tonic-gate if (ch == EOF)
4860Sstevel@tonic-gate warning("Premature EOF - missing comma?");
4870Sstevel@tonic-gate /* start of new description */
4880Sstevel@tonic-gate else if (first_column) {
4890Sstevel@tonic-gate backspace();
4900Sstevel@tonic-gate warning("Missing comma?");
4910Sstevel@tonic-gate /* pretend we did get a comma */
4920Sstevel@tonic-gate ch = ',';
4930Sstevel@tonic-gate }
4940Sstevel@tonic-gate
4950Sstevel@tonic-gate *ptr = '\0';
4960Sstevel@tonic-gate
4970Sstevel@tonic-gate if (count == 0)
4980Sstevel@tonic-gate return (NULL);
4990Sstevel@tonic-gate return (ch);
5000Sstevel@tonic-gate }
5010Sstevel@tonic-gate
5020Sstevel@tonic-gate /*
5030Sstevel@tonic-gate * Panic mode error recovery - skip everything until a "ch" is found.
5040Sstevel@tonic-gate */
505*350Sdp void
panic_mode(int ch)5060Sstevel@tonic-gate panic_mode(int ch)
5070Sstevel@tonic-gate {
508*350Sdp int c;
5090Sstevel@tonic-gate
5100Sstevel@tonic-gate for (;;) {
5110Sstevel@tonic-gate c = next_char();
5120Sstevel@tonic-gate if (c == ch)
5130Sstevel@tonic-gate return;
5140Sstevel@tonic-gate if (c == EOF)
5150Sstevel@tonic-gate return;
5160Sstevel@tonic-gate }
5170Sstevel@tonic-gate }
518