tic_parse.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* 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-1999 by Sun Microsystems, Inc.
* All rights reserved.
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* *******************************************************************
* COPYRIGHT NOTICE *
* ********************************************************************
* This software is copyright (C) 1982 by Pavel Curtis *
* *
* Permission is granted to reproduce and distribute *
* this file by any means so long as no fee is charged *
* above a nominal handling fee and so long as this *
* notice is always included in the copies. *
* *
* Other rights are reserved except as explicitly granted *
* by written permission of the author. *
* Pavel Curtis *
* Computer Science Dept. *
* 405 Upson Hall *
* Cornell University *
* Ithaca, NY 14853 *
* *
* Ph- (607) 256-4934 *
* *
* Pavel.Cornell@Udel-Relay (ARPAnet) *
* decvax!cornell!pavel (UUCPnet) *
* ********************************************************************
*/
/*
* comp_parse.c -- The high-level (ha!) parts of the compiler,
* that is, the routines which drive the scanner,
* etc.
*
* $Log: RCS/comp_parse.v $
* Revision 2.1 82/10/25 14:45:43 pavel
* Added Copyright Notice
*
* Revision 2.0 82/10/24 15:16:39 pavel
* Beta-one Test Release
*
* Revision 1.3 82/08/23 22:29:39 pavel
* The REAL Alpha-one Release Version
*
* Revision 1.2 82/08/19 19:09:53 pavel
* Alpha Test Release One
*
* Revision 1.1 82/08/12 18:37:12 pavel
* Initial revision
*
*
*/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include "curses_inc.h"
#include "compiler.h"
#include "object.h"
extern char check_only;
extern char *progname;
char *string_table;
int next_free; /* next free character in string_table */
unsigned int table_size = 0; /* current string_table size */
short term_names; /* string table offset - current terminal */
int part2 = 0; /* set to allow old compiled defns to be used */
int complete = 0; /* 1 if entry done with no forward uses */
struct use_item {
long offset;
};
struct use_header {
};
int use_count = 0;
/*
* The use_list is a doubly-linked list with NULLs terminating the lists:
*
* use_item use_item use_item
* --------- --------- ---------
* | | | | | | offset
* |-------| |-------| |-------|
* | ----+-->| ----+-->| NULL | fptr
* |-------| |-------| |-------|
* | NULL |<--+---- |<--+---- | bptr
* --------- --------- ---------
* ^ ^
* | ------------------ |
* | | | | |
* +--+---- | ----+---+
* | | |
* ------------------
* head tail
* use_list
*
*/
/*
* compile()
*
* Main loop of the compiler.
*
* get_token()
* if curr_token != NAMES
* err_abort()
* while (not at end of file)
* do an entry
*
*/
void
compile()
{
char line[1024];
int token_type;
int old_use_count;
token_type = get_token();
if (token_type != NAMES)
"File does not start with terminal names in column one");
while (token_type != EOF)
old_use_count = -1;
reset_input();
"Token after a seek not NAMES");
if (complete)
}
reset_input();
"Token after a seek not NAMES");
if (complete)
}
DEBUG(2,
"Finished a pass through enqueued forward USE's\n", "");
}
}
"\nError in following up use-links. Either there is\n");
"a loop in the links or they reference non-existant\n");
"terminals. The following is a list of the entries\n");
}
exit(1);
}
}
char *str;
{
char line[512];
}
}
/*
* int
* do_entry(item_ptr)
*
* Compile one entry. During the first pass, item_ptr is NULL. In pass
* two, item_ptr points to the current entry in the use_list.
*
* found-forward-use = FALSE
* re-initialise internal arrays
* save names in string_table
* get_token()
* while (not EOF and not NAMES)
* if found-forward-use
* do nothing
* else if 'use'
* if handle_use() < 0
* found-forward-use = TRUE
* else
* check for existance and type-correctness
* enter cap into structure
* if STRING
* save string in string_table
* get_token()
* if ! found-forward-use
* dump compiled entry into filesystem
*
*/
int
{
long entry_offset;
register int token_type;
register struct name_table_entry *entry_ptr;
int found_forward_use = FALSE;
complete = 0;
for (token_type = get_token();
token_type = get_token()) {
if (found_forward_use)
/* do nothing */;
} else {
warning("Unknown Capability - '%s'",
continue;
}
if (token_type != CANCEL &&
warning("Wrong type used for capability '%s'",
switch (token_type) {
case CANCEL:
case BOOLEAN:
break;
case NUMBER:
break;
case STRING:
break;
}
break;
case BOOLEAN:
break;
case NUMBER:
break;
case STRING:
break;
default:
warning("Unknown token type");
panic_mode(',');
continue;
}
} /* end else cur_token.name != "use" */
} /* endwhile (not EOF and not NAMES) */
if (found_forward_use)
return (token_type);
complete = 1;
return (token_type);
}
/*
Change all cancellations to a non-entry.
For booleans, @ -> false
For nums, @ -> -1
For strings, @ -> -1
This only has to be done for entries which
have to be compatible with the pre-Vr3 format.
*/
#ifndef NOCANCELCOMPAT
short Booleans[];
short Numbers[];
short Strings[];
{
register int i;
for (i = 0; i < BoolCount; i++) {
if (Booleans[i] == -2)
}
for (i = 0; i < NumCount; i++) {
if (Numbers[i] == -2)
Numbers[i] = -1;
}
for (i = 0; i < StrCount; i++) {
if (Strings[i] == -2)
Strings[i] = -1;
}
}
#endif /* NOCANCELCOMPAT */
/*
Change the cancellation signal from the -2 used internally to
the 2 used within the binary.
*/
short Booleans[];
{
register int i;
for (i = 0; i < BoolCount; i++) {
if (Booleans[i] == -2)
Booleans[i] = 2;
}
}
/*
* enqueue(offset)
*
* Put a record of the given offset onto the use-list.
*
*/
long offset;
{
syserr_abort("Not enough memory for use_list element");
} else {
}
use_count ++;
}
/*
* dequeue(ptr)
*
* remove the pointed-to item from the use_list
*
*/
{
else
else
use_count --;
}
/*
* invalid_term_name(name)
*
* Look for invalid characters in a term name. These include
* space, tab and '/'.
*
* Generate an error message if given name does not begin with a
* digit or letter, then exit.
*
* return TRUE if name is invalid.
*
*/
static int invalid_term_name(name)
register char *name;
{
int error = 0;
error++;
continue;
return (1);
if (error) {
"Terminal names must start with a letter or digit\n");
exit(1);
}
return (0);
}
/*
* dump_structure()
*
* Save the compiled version of a description in the filesystem.
*
* make a copy of the name-list
* break it up into first-name and all-but-last-name
* if necessary
* clear CANCELS out of the structure
* creat(first-name)
* write object information to first-name
* close(first-name)
* for each valid name
* link to first-name
*
*/
short Booleans[];
short Numbers[];
short Strings[];
{
char name_list[1024];
int len;
int alphastart = 0;
/* Set othernames to 1 past first '|' in the list. */
/* Null out that '|' in the process. */
if (other_names)
*other_names++ = '\0';
if (invalid_term_name(first_name))
else if (len == 1)
check_dir(first_name[0]);
warning("'%s' filename too long, truncating to '%.16s'\n",
(unsigned)term_names + string_table);
}
if (!check_only) {
syserr_abort("Can't open %s/%s\n",
}
#ifndef NOCANCELCOMPAT
/* if there is no '+' in the name, eliminate */
/* cancellation markings. */
else
#endif /* NOCANCELCOMPAT */
if (!check_only) {
syserr_abort("Error in writing %s/%s",
}
}
while (other_names) {
if (other_names)
*other_names++ = '\0';
if (*cur_name == '\0')
continue;
continue;
} else if (len == 1) {
continue;
}
if (invalid_term_name(cur_name)) {
if (other_names)
warning("'%s': bad term name found in list.",
cur_name);
continue;
}
if (other_names) {
} else {
continue;
}
}
warning("Terminal name '%s' synonym for itself",
} else {
if (!check_only) {
"'%s' defined in more than one entry.", cur_name);
"Entry being used is '%s'.\n",
(unsigned)term_names +
}
syserr_abort("Can't link %s to %s",
}
}
if (!alphastart) {
warning("At least one synonym should begin with a letter.");
}
}
/*
* int
* write_object(fp, Booleans, Numbers, Strings)
*
* Write out the compiled entry to the given file.
* Return 0 if OK or -1 if not.
*
*/
int
short Booleans[];
short Numbers[];
short Strings[];
{
char *namelist;
short namelen;
char zero = '\0';
register int i;
register int l_next_free;
l_next_free++;
if (must_swap()) {
} else {
}
for (i = 0; i < BoolCount; i++)
return (-1);
return (-1);
if (must_swap()) {
for (i = 0; i < NumCount; i++)
for (i = 0; i < StrCount; i++)
}
!= StrCount ||
!= l_next_free)
return (-1);
return (0);
}
/*
* int
* save_str(string)
*
* copy string into next free part of string_table, doing a realloc()
* if necessary. return offset of beginning of string from start of
* string_table.
*
*/
int
char *string;
{
int old_next_free;
/* Do not let an offset be 255. It reads as -1 in Vr2 binaries. */
next_free++;
if (table_size == 0) {
syserr_abort("Out of memory");
table_size = 1024;
}
== NULL)
syserr_abort("Out of memory");
table_size += 1024;
}
return (old_next_free);
}
/*
* init_structure(Booleans, Numbers, Strings)
*
* Initialise the given arrays
* Reset the next_free counter to zero.
*
*/
short Booleans[];
{
int i;
for (i = 0; i < BoolCount; i++)
for (i = 0; i < NumCount; i++)
Numbers[i] = -1;
for (i = 0; i < StrCount; i++)
Strings[i] = -1;
next_free = 0;
}
/*
* int
* handle_use(item_ptr, entry_offset, Booleans, Numbers, Strings)
*
* Merge the compiled file whose name is in cur_token.valstring
* with the current entry.
*
* if it's a forward use-link
* if item_ptr == NULL
* queue it up for later handling
* else
* ignore it (we're already going through the queue)
* else it's a backward use-link
* read in the object file for that terminal
* merge contents with current structure
*
* Returned value is 0 if it was a backward link and we
* successfully read it in, -1 if a forward link.
*/
int
long entry_offset;
short Booleans[];
short Numbers[];
short Strings[];
{
struct _bool_struct use_bools;
struct _num_struct use_nums;
struct _str_struct use_strs;
char filename[50];
int i;
return (-1);
} else {
syserr_abort("Error in re-reading compiled file %s",
filename);
for (i = 0; i < BoolCount; i++) {
Booleans[i] = -2;
}
for (i = 0; i < NumCount; i++) {
if (Numbers[i] == -1)
}
for (i = 0; i < StrCount; i++) {
if (Strings[i] == -1)
if (US[i] == (char *)-1)
Strings[i] = -2;
else if (US[i] != (char *)0)
}
}
return (0);
}