/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1996, by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* ticscan.c Terminal Information Compiler
*
* Copyright 1990, 1992 by Mortice Kern Systems Inc. All rights reserved.
*
* Portions of this code Copyright 1982 by Pavel Curtis.
*
*/
#ifdef M_RCSID
#ifndef lint
#endif
#endif
#include "tic.h"
#include <limits.h>
#include <ctype.h>
long curr_file_pos;
/*f
* Scans the input for the next token, storing the specifics in the
* global structure 'curr_token' and returning one of the following:
*
* NAMES A line beginning in column 1. 'name'
* will be set to point to everything up to
* but not including the first comma on the line.
* BOOLEAN An entry consisting of a name followed by
* a comma. 'name' will be set to point to the
* name of the capability.
* NUMBER An entry of the form
* name#digits,
* 'name' will be set to point to the capability
* name and 'valnumber' to the number given.
* STRING An entry of the form
* name=characters,
* 'name' is set to the capability name and
* 'valstring' to the string of characters, with
* input translations done.
* CANCEL An entry of the form
* name@,
* 'name' is set to the capability name and
* 'valnumber' to -1.
* EOF The end of the file has been reached.
*/
int
{
long number;
int type;
int ch;
register char *ptr;
int dot_flag = 0;
;
}
else
{
if (ch == '.')
{
dot_flag = 1;
;
}
panic_mode(',');
}
if (first_column)
{
else if (ch == '\n') {
panic_mode(',');
}
*ptr = '\0';
}
else
{
{
}
*ptr++ = '\0';
switch (ch)
{
case ',':
break;
case '@':
if (next_char() != ',')
break;
case '#':
number = 0;
if (ch != ',')
break;
case '=':
if (ch != ',')
break;
default:
}
} /* end else (first_column == 0) */
} /* end else (ch != EOF) */
if (dot_flag == 1)
if (debug_level >= 8)
{
switch (type)
{
case BOOLEAN:
break;
case NUMBER:
);
break;
case STRING:
);
break;
case CANCEL:
break;
case NAMES:
break;
case EOF:
break;
default:
}
}
return(type);
}
/*f
* Returns the next character in the input stream. Comments and leading
* white space are stripped. The global state variable 'firstcolumn' is
* set TRUE if the character returned is from the first column of the input
* line. The global variable curr_line is incremented for each new line.
* The global variable curr_file_pos is set to the file offset of the
* beginning of each line.
*/
STATIC int
{
char *rtn_value;
do {
curr_line++;
return (EOF);
curr_column = 0;
curr_column++;
}
return (line[curr_column++]);
}
/*f
* go back one character
*/
STATIC void
{
curr_column--;
if (curr_column < 0)
}
/*f
* Resets the input-reading routines. Used after a seek has been done.
*/
void
{
curr_column = -1;
}
/*f
* Reads characters using next_char() until encountering a comma, newline
* or end-of-file. The returned value is the character which caused
* reading to stop. The following translations are done on the input:
*
* ^X goes to ctrl-X (i.e. X & 037)
* {backslash-E,backslash-n,backslash-r,backslash-b,
* backslash-t,backslash-f} go to
* {ESCAPE,newline,carriage-return,backspace,tab,formfeed}
* {backslash-^,backslash-backslash} go to {carat,backslash}
* backslash-ddd (for ddd = up to three octal digits) goes to
* the character ddd
*
* backslash-e == backslash-E
* backslash-0 == backslash-200
*/
STATIC int
char *ptr;
{
register int count = 0;
if (ch == '^') {
} else if (ch == '\\') {
/* Try to read a three character octal number. */
for (number = i = 0; i < 3; ++i) {
backspace();
break;
}
}
if (0 < i) {
/* Read an octal number. */
} else {
/* Escape mapping translation. */
}
} else {
}
if (500 < ++count)
}
*ptr = '\0';
return (ch);
}
/*f
* Panic mode error recovery - skip everything until a "ch" is found.
*/
void
char ch;
{
int c;
for (;;) {
c = next_char();
if (c == ch)
return;
if (c == EOF);
return;
}
}
/*f
* This routine is a codeset independent method of specifying a translation
* from an unambiguous printable form, to an internal binary value.
* This mapping is defined by Table 2-13 in section 2-12 of POSIX.2.
*
* of additional characters: <escape>, <space>, <colon>, <caret>, <comma>
*
* Assume that the escape lead-in character has been processed and
* any escaped octal sequence.
*/
STATIC int
escape(c)
int c;
{
int i;
static int cntl_code[] = {
-1
};
static int escape_char[] = {
'\0', '\\', 'a', 'b', 'f', 'n', 'r', 't',
'v', 'E', 'e', 's', ':', '^', ',',
-1
};
for (i = 0; escape_char[i] != -1; ++i)
if (c == escape_char[i])
return (cntl_code[i]);
return (c);
}