17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*d2117003Sdp * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*d2117003Sdp * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate /* 317c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 327c478bd9Sstevel@tonic-gate * The Regents of the University of California 337c478bd9Sstevel@tonic-gate * All Rights Reserved 347c478bd9Sstevel@tonic-gate * 357c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 367c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 377c478bd9Sstevel@tonic-gate * contributors. 387c478bd9Sstevel@tonic-gate */ 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate /* 437c478bd9Sstevel@tonic-gate * COPYRIGHT NOTICE 447c478bd9Sstevel@tonic-gate * 457c478bd9Sstevel@tonic-gate * This software is copyright(C) 1982 by Pavel Curtis 467c478bd9Sstevel@tonic-gate * 477c478bd9Sstevel@tonic-gate * Permission is granted to reproduce and distribute 487c478bd9Sstevel@tonic-gate * this file by any means so long as no fee is charged 497c478bd9Sstevel@tonic-gate * above a nominal handling fee and so long as this 507c478bd9Sstevel@tonic-gate * notice is always included in the copies. 517c478bd9Sstevel@tonic-gate * 527c478bd9Sstevel@tonic-gate * Other rights are reserved except as explicitly granted 537c478bd9Sstevel@tonic-gate * by written permission of the author. 547c478bd9Sstevel@tonic-gate * Pavel Curtis 557c478bd9Sstevel@tonic-gate * Computer Science Dept. 567c478bd9Sstevel@tonic-gate * 405 Upson Hall 577c478bd9Sstevel@tonic-gate * Cornell University 587c478bd9Sstevel@tonic-gate * Ithaca, NY 14853 597c478bd9Sstevel@tonic-gate * 607c478bd9Sstevel@tonic-gate * Ph- (607) 256-4934 617c478bd9Sstevel@tonic-gate * 627c478bd9Sstevel@tonic-gate * Pavel.Cornell@Udel-Relay(ARPAnet) 637c478bd9Sstevel@tonic-gate * decvax!cornell!pavel(UUCPnet) 647c478bd9Sstevel@tonic-gate */ 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate /* 677c478bd9Sstevel@tonic-gate * comp_scan.c --- Lexical scanner for terminfo compiler. 687c478bd9Sstevel@tonic-gate * 697c478bd9Sstevel@tonic-gate * $Log: RCS/comp_scan.v $ 707c478bd9Sstevel@tonic-gate * Revision 2.1 82/10/25 14:45:55 pavel 717c478bd9Sstevel@tonic-gate * Added Copyright Notice 727c478bd9Sstevel@tonic-gate * 737c478bd9Sstevel@tonic-gate * Revision 2.0 82/10/24 15:17:12 pavel 747c478bd9Sstevel@tonic-gate * Beta-one Test Release 757c478bd9Sstevel@tonic-gate * 767c478bd9Sstevel@tonic-gate * Revision 1.3 82/08/23 22:30:03 pavel 777c478bd9Sstevel@tonic-gate * The REAL Alpha-one Release Version 787c478bd9Sstevel@tonic-gate * 797c478bd9Sstevel@tonic-gate * Revision 1.2 82/08/19 19:10:06 pavel 807c478bd9Sstevel@tonic-gate * Alpha Test Release One 817c478bd9Sstevel@tonic-gate * 827c478bd9Sstevel@tonic-gate * Revision 1.1 82/08/12 18:37:46 pavel 837c478bd9Sstevel@tonic-gate * Initial revision 847c478bd9Sstevel@tonic-gate * 857c478bd9Sstevel@tonic-gate * 867c478bd9Sstevel@tonic-gate */ 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate #include <stdio.h> 907c478bd9Sstevel@tonic-gate #include <ctype.h> 917c478bd9Sstevel@tonic-gate #include "compiler.h" 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate #define iswhite(ch) (ch == ' ' || ch == '\t') 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate static int first_column; /* See 'next_char()' below */ 977c478bd9Sstevel@tonic-gate 98*d2117003Sdp static void backspace(void); 99*d2117003Sdp void reset_input(void); 100*d2117003Sdp void panic_mode(int); 101*d2117003Sdp 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate /* 1057c478bd9Sstevel@tonic-gate * int 1067c478bd9Sstevel@tonic-gate * get_token() 1077c478bd9Sstevel@tonic-gate * 1087c478bd9Sstevel@tonic-gate * Scans the input for the next token, storing the specifics in the 1097c478bd9Sstevel@tonic-gate * global structure 'curr_token' and returning one of the following: 1107c478bd9Sstevel@tonic-gate * 1117c478bd9Sstevel@tonic-gate * NAMES A line beginning in column 1. 'name' 1127c478bd9Sstevel@tonic-gate * will be set to point to everything up to 1137c478bd9Sstevel@tonic-gate * but not including the first comma on the line. 1147c478bd9Sstevel@tonic-gate * BOOLEAN An entry consisting of a name followed by 1157c478bd9Sstevel@tonic-gate * a comma. 'name' will be set to point to the 1167c478bd9Sstevel@tonic-gate * name of the capability. 1177c478bd9Sstevel@tonic-gate * NUMBER An entry of the form 1187c478bd9Sstevel@tonic-gate * name#digits, 1197c478bd9Sstevel@tonic-gate * 'name' will be set to point to the capability 1207c478bd9Sstevel@tonic-gate * name and 'valnumber' to the number given. 1217c478bd9Sstevel@tonic-gate * STRING An entry of the form 1227c478bd9Sstevel@tonic-gate * name=characters, 1237c478bd9Sstevel@tonic-gate * 'name' is set to the capability name and 1247c478bd9Sstevel@tonic-gate * 'valstring' to the string of characters, with 1257c478bd9Sstevel@tonic-gate * input translations done. 1267c478bd9Sstevel@tonic-gate * CANCEL An entry of the form 1277c478bd9Sstevel@tonic-gate * name@, 1287c478bd9Sstevel@tonic-gate * 'name' is set to the capability name and 1297c478bd9Sstevel@tonic-gate * 'valnumber' to -1. 1307c478bd9Sstevel@tonic-gate * EOF The end of the file has been reached. 1317c478bd9Sstevel@tonic-gate * 1327c478bd9Sstevel@tonic-gate */ 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate int 1357c478bd9Sstevel@tonic-gate get_token() 1367c478bd9Sstevel@tonic-gate { 1377c478bd9Sstevel@tonic-gate long number; 1387c478bd9Sstevel@tonic-gate int type; 1397c478bd9Sstevel@tonic-gate register int ch; 1407c478bd9Sstevel@tonic-gate static char buffer[1024]; 1417c478bd9Sstevel@tonic-gate register char *ptr; 1427c478bd9Sstevel@tonic-gate int dot_flag = FALSE; 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate while ((ch = next_char()) == '\n' || (isascii(ch) && iswhite(ch))); 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate if (ch == EOF) 1477c478bd9Sstevel@tonic-gate type = EOF; 1487c478bd9Sstevel@tonic-gate else { 1497c478bd9Sstevel@tonic-gate if (ch == '.') { 1507c478bd9Sstevel@tonic-gate dot_flag = TRUE; 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate while ((ch = next_char()) == ' ' || ch == '\t'); 1537c478bd9Sstevel@tonic-gate } 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate if (! isascii(ch) || ! isalnum(ch)) { 1567c478bd9Sstevel@tonic-gate warning("Illegal character - '%c'", ch); 1577c478bd9Sstevel@tonic-gate panic_mode(','); 1587c478bd9Sstevel@tonic-gate } 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate ptr = buffer; 1617c478bd9Sstevel@tonic-gate if (ch != '\n') *(ptr++) = ch; 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate if (first_column) { 1647c478bd9Sstevel@tonic-gate while ((ch = next_char()) != ',' && ch != '\n' && ch != EOF) 1657c478bd9Sstevel@tonic-gate *(ptr++) = ch; 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate if (ch == EOF) 1687c478bd9Sstevel@tonic-gate err_abort("Premature EOF"); 1697c478bd9Sstevel@tonic-gate else if (ch == '\n') { 1707c478bd9Sstevel@tonic-gate warning("Newline in middle of terminal name"); 1717c478bd9Sstevel@tonic-gate panic_mode(','); 1727c478bd9Sstevel@tonic-gate } 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate *ptr = '\0'; 1757c478bd9Sstevel@tonic-gate curr_token.tk_name = buffer; 1767c478bd9Sstevel@tonic-gate type = NAMES; 1777c478bd9Sstevel@tonic-gate } else { 1787c478bd9Sstevel@tonic-gate ch = next_char(); 1797c478bd9Sstevel@tonic-gate while (isascii(ch) && isalnum(ch)) { 1807c478bd9Sstevel@tonic-gate *(ptr++) = ch; 1817c478bd9Sstevel@tonic-gate ch = next_char(); 1827c478bd9Sstevel@tonic-gate } 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate *ptr++ = '\0'; 1857c478bd9Sstevel@tonic-gate switch (ch) { 1867c478bd9Sstevel@tonic-gate case ',': 1877c478bd9Sstevel@tonic-gate curr_token.tk_name = buffer; 1887c478bd9Sstevel@tonic-gate type = BOOLEAN; 1897c478bd9Sstevel@tonic-gate break; 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate case '@': 1927c478bd9Sstevel@tonic-gate if (next_char() != ',') 1937c478bd9Sstevel@tonic-gate warning("Missing comma"); 1947c478bd9Sstevel@tonic-gate curr_token.tk_name = buffer; 1957c478bd9Sstevel@tonic-gate type = CANCEL; 1967c478bd9Sstevel@tonic-gate break; 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate case '#': 1997c478bd9Sstevel@tonic-gate number = 0; 2007c478bd9Sstevel@tonic-gate if ((ch = next_char()) == ',') 2017c478bd9Sstevel@tonic-gate warning("Missing numeric value"); 2027c478bd9Sstevel@tonic-gate backspace(); 2037c478bd9Sstevel@tonic-gate if ((ch = next_char()) == '0') { 2047c478bd9Sstevel@tonic-gate if ((ch = next_char()) == 'x' || ch == 'X') { 2057c478bd9Sstevel@tonic-gate while (isascii(ch = next_char()) && 2067c478bd9Sstevel@tonic-gate isxdigit(ch)) { 2077c478bd9Sstevel@tonic-gate number *= 16; 2087c478bd9Sstevel@tonic-gate if (isdigit(ch)) 2097c478bd9Sstevel@tonic-gate number += ch - '0'; 2107c478bd9Sstevel@tonic-gate else if (ch >= 'a' && ch <= 'f') 2117c478bd9Sstevel@tonic-gate number += 10 + ch - 'a'; 2127c478bd9Sstevel@tonic-gate else 2137c478bd9Sstevel@tonic-gate number += 10 + ch - 'A'; 2147c478bd9Sstevel@tonic-gate } 2157c478bd9Sstevel@tonic-gate } else { 2167c478bd9Sstevel@tonic-gate backspace(); 2177c478bd9Sstevel@tonic-gate while ((ch = next_char()) >= '0' && 2187c478bd9Sstevel@tonic-gate ch <= '7') 2197c478bd9Sstevel@tonic-gate number = number * 8 + ch - '0'; 2207c478bd9Sstevel@tonic-gate } 2217c478bd9Sstevel@tonic-gate } else { 2227c478bd9Sstevel@tonic-gate backspace(); 2237c478bd9Sstevel@tonic-gate while (isascii(ch = next_char()) && 2247c478bd9Sstevel@tonic-gate isdigit(ch)) 2257c478bd9Sstevel@tonic-gate number = number * 10 + ch - '0'; 2267c478bd9Sstevel@tonic-gate } 2277c478bd9Sstevel@tonic-gate if (ch != ',') 2287c478bd9Sstevel@tonic-gate warning("Missing comma"); 2297c478bd9Sstevel@tonic-gate curr_token.tk_name = buffer; 2307c478bd9Sstevel@tonic-gate curr_token.tk_valnumber = number; 2317c478bd9Sstevel@tonic-gate type = NUMBER; 2327c478bd9Sstevel@tonic-gate break; 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate case '=': 2357c478bd9Sstevel@tonic-gate ch = trans_string(ptr); 2367c478bd9Sstevel@tonic-gate if (ch != NULL && ch != ',') 2377c478bd9Sstevel@tonic-gate warning("Missing comma"); 2387c478bd9Sstevel@tonic-gate if (ch == NULL) 2397c478bd9Sstevel@tonic-gate warning("NULL string value"); 2407c478bd9Sstevel@tonic-gate curr_token.tk_name = buffer; 2417c478bd9Sstevel@tonic-gate curr_token.tk_valstring = ptr; 2427c478bd9Sstevel@tonic-gate type = STRING; 2437c478bd9Sstevel@tonic-gate break; 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate default: 2467c478bd9Sstevel@tonic-gate warning("Illegal character - '%c'", ch); 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate } /* end else (first_column == FALSE) */ 2497c478bd9Sstevel@tonic-gate } /* end else (ch != EOF) */ 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate if (dot_flag == TRUE) 2527c478bd9Sstevel@tonic-gate DEBUG(8, "Commented out ", ""); 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate if (debug_level >= 8) { 2557c478bd9Sstevel@tonic-gate fprintf(stderr, "Token: "); 2567c478bd9Sstevel@tonic-gate switch (type) { 2577c478bd9Sstevel@tonic-gate case BOOLEAN: 2587c478bd9Sstevel@tonic-gate fprintf(stderr, "Boolean; name='%s'\n", 2597c478bd9Sstevel@tonic-gate curr_token.tk_name); 2607c478bd9Sstevel@tonic-gate break; 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate case NUMBER: 2637c478bd9Sstevel@tonic-gate fprintf(stderr, "Number; name = '%s', value = %d\n", 2647c478bd9Sstevel@tonic-gate curr_token.tk_name, curr_token.tk_valnumber); 2657c478bd9Sstevel@tonic-gate break; 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate case STRING: 2687c478bd9Sstevel@tonic-gate fprintf(stderr, "String; name = '%s', value = '%s'\n", 2697c478bd9Sstevel@tonic-gate curr_token.tk_name, curr_token.tk_valstring); 2707c478bd9Sstevel@tonic-gate break; 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate case CANCEL: 2737c478bd9Sstevel@tonic-gate fprintf(stderr, "Cancel; name = '%s'\n", 2747c478bd9Sstevel@tonic-gate curr_token.tk_name); 2757c478bd9Sstevel@tonic-gate break; 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate case NAMES: 2787c478bd9Sstevel@tonic-gate fprintf(stderr, "Names; value = '%s'\n", 2797c478bd9Sstevel@tonic-gate curr_token.tk_name); 2807c478bd9Sstevel@tonic-gate break; 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate case EOF: 2837c478bd9Sstevel@tonic-gate fprintf(stderr, "End of file\n"); 2847c478bd9Sstevel@tonic-gate break; 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate default: 2877c478bd9Sstevel@tonic-gate warning("Bad token type"); 2887c478bd9Sstevel@tonic-gate } 2897c478bd9Sstevel@tonic-gate } 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate if (dot_flag == TRUE) /* if commented out, use the next one */ 2927c478bd9Sstevel@tonic-gate type = get_token(); 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate return (type); 2957c478bd9Sstevel@tonic-gate } 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate 2997c478bd9Sstevel@tonic-gate /* 3007c478bd9Sstevel@tonic-gate * int 3017c478bd9Sstevel@tonic-gate * next_char() 3027c478bd9Sstevel@tonic-gate * 3037c478bd9Sstevel@tonic-gate * Returns the next character in the input stream. Comments and leading 3047c478bd9Sstevel@tonic-gate * white space are stripped. The global state variable 'firstcolumn' is 3057c478bd9Sstevel@tonic-gate * set TRUE if the character returned is from the first column of the 3067c478bd9Sstevel@tonic-gate * inputline. The global variable curr_line is incremented for each new. 3077c478bd9Sstevel@tonic-gate * line. The global variable curr_file_pos is set to the file offset 3087c478bd9Sstevel@tonic-gate * of the beginning of each line. 3097c478bd9Sstevel@tonic-gate * 3107c478bd9Sstevel@tonic-gate */ 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate int curr_column = -1; 3137c478bd9Sstevel@tonic-gate char line[1024]; 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate int 3167c478bd9Sstevel@tonic-gate next_char() 3177c478bd9Sstevel@tonic-gate { 3187c478bd9Sstevel@tonic-gate char *rtn_value; 3197c478bd9Sstevel@tonic-gate long ftell(); 3207c478bd9Sstevel@tonic-gate char *p; 3217c478bd9Sstevel@tonic-gate 3227c478bd9Sstevel@tonic-gate if (curr_column < 0 || curr_column > 1023 || 3237c478bd9Sstevel@tonic-gate line[curr_column] == '\0') { 3247c478bd9Sstevel@tonic-gate do { 3257c478bd9Sstevel@tonic-gate curr_file_pos = ftell(stdin); 3267c478bd9Sstevel@tonic-gate 3277c478bd9Sstevel@tonic-gate if ((rtn_value = fgets(line, 1024, stdin)) == NULL) 3287c478bd9Sstevel@tonic-gate return (EOF); 3297c478bd9Sstevel@tonic-gate curr_line++; 3307c478bd9Sstevel@tonic-gate p = &line[0]; 3317c478bd9Sstevel@tonic-gate while (*p && iswhite(*p)) { 3327c478bd9Sstevel@tonic-gate p++; 3337c478bd9Sstevel@tonic-gate } 3347c478bd9Sstevel@tonic-gate } while (*p == '#'); 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate curr_column = 0; 3377c478bd9Sstevel@tonic-gate while (isascii(line[curr_column]) && iswhite(line[curr_column])) 3387c478bd9Sstevel@tonic-gate curr_column++; 3397c478bd9Sstevel@tonic-gate } 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate if (curr_column == 0 && line[0] != '\n') 3427c478bd9Sstevel@tonic-gate first_column = TRUE; 3437c478bd9Sstevel@tonic-gate else 3447c478bd9Sstevel@tonic-gate first_column = FALSE; 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate return (line[curr_column++]); 3477c478bd9Sstevel@tonic-gate } 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate 350*d2117003Sdp static void 351*d2117003Sdp backspace(void) 3527c478bd9Sstevel@tonic-gate { 3537c478bd9Sstevel@tonic-gate curr_column--; 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate if (curr_column < 0) 3567c478bd9Sstevel@tonic-gate syserr_abort("Backspaced off beginning of line"); 3577c478bd9Sstevel@tonic-gate } 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate /* 3627c478bd9Sstevel@tonic-gate * reset_input() 3637c478bd9Sstevel@tonic-gate * 3647c478bd9Sstevel@tonic-gate * Resets the input-reading routines. Used after a seek has been done. 3657c478bd9Sstevel@tonic-gate * 3667c478bd9Sstevel@tonic-gate */ 3677c478bd9Sstevel@tonic-gate 368*d2117003Sdp void 369*d2117003Sdp reset_input(void) 3707c478bd9Sstevel@tonic-gate { 3717c478bd9Sstevel@tonic-gate curr_column = -1; 3727c478bd9Sstevel@tonic-gate } 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate /* 3777c478bd9Sstevel@tonic-gate * int 3787c478bd9Sstevel@tonic-gate * trans_string(ptr) 3797c478bd9Sstevel@tonic-gate * 3807c478bd9Sstevel@tonic-gate * Reads characters using next_char() until encountering a comma, a new 3817c478bd9Sstevel@tonic-gate * entry, or end-of-file. The returned value is the character which 3827c478bd9Sstevel@tonic-gate * caused reading to stop. The following translations are done on the 3837c478bd9Sstevel@tonic-gate * input: 3847c478bd9Sstevel@tonic-gate * 3857c478bd9Sstevel@tonic-gate * ^X goes to ctrl-X (i.e. X & 037) 3867c478bd9Sstevel@tonic-gate * {\E,\n,\r,\b,\t,\f} go to 3877c478bd9Sstevel@tonic-gate * {ESCAPE,newline,carriage-return,backspace,tab,formfeed} 3887c478bd9Sstevel@tonic-gate * {\^,\\} go to {carat,backslash} 3897c478bd9Sstevel@tonic-gate * \ddd (for ddd = up to three octal digits) goes to 3907c478bd9Sstevel@tonic-gate * the character ddd 3917c478bd9Sstevel@tonic-gate * 3927c478bd9Sstevel@tonic-gate * \e == \E 3937c478bd9Sstevel@tonic-gate * \0 == \200 3947c478bd9Sstevel@tonic-gate * 3957c478bd9Sstevel@tonic-gate */ 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate int 3987c478bd9Sstevel@tonic-gate trans_string(char *ptr) 3997c478bd9Sstevel@tonic-gate { 4007c478bd9Sstevel@tonic-gate register int count = 0; 4017c478bd9Sstevel@tonic-gate int number; 4027c478bd9Sstevel@tonic-gate register int i; 4037c478bd9Sstevel@tonic-gate register int ch; 4047c478bd9Sstevel@tonic-gate 4057c478bd9Sstevel@tonic-gate while ((ch = next_char()) != ',' && ch != EOF && !first_column) { 4067c478bd9Sstevel@tonic-gate if (ch == '^') { 4077c478bd9Sstevel@tonic-gate ch = next_char(); 4087c478bd9Sstevel@tonic-gate if (ch == EOF) 4097c478bd9Sstevel@tonic-gate err_abort("Premature EOF"); 4107c478bd9Sstevel@tonic-gate 4117c478bd9Sstevel@tonic-gate if (!isascii(ch) || ! isprint(ch)) { 4127c478bd9Sstevel@tonic-gate warning("Illegal ^ character - '%c'", ch); 4137c478bd9Sstevel@tonic-gate } 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate if (ch == '@') 4167c478bd9Sstevel@tonic-gate *(ptr++) = 0200; 4177c478bd9Sstevel@tonic-gate else 4187c478bd9Sstevel@tonic-gate *(ptr++) = ch & 037; 4197c478bd9Sstevel@tonic-gate } else if (ch == '\\') { 4207c478bd9Sstevel@tonic-gate ch = next_char(); 4217c478bd9Sstevel@tonic-gate if (ch == EOF) 4227c478bd9Sstevel@tonic-gate err_abort("Premature EOF"); 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate if (ch >= '0' && ch <= '7') { 4257c478bd9Sstevel@tonic-gate number = ch - '0'; 4267c478bd9Sstevel@tonic-gate for (i = 0; i < 2; i++) { 4277c478bd9Sstevel@tonic-gate ch = next_char(); 4287c478bd9Sstevel@tonic-gate if (ch == EOF) 4297c478bd9Sstevel@tonic-gate err_abort("Premature EOF"); 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate if (ch < '0' || ch > '7') { 4327c478bd9Sstevel@tonic-gate backspace(); 4337c478bd9Sstevel@tonic-gate break; 4347c478bd9Sstevel@tonic-gate } 4357c478bd9Sstevel@tonic-gate 4367c478bd9Sstevel@tonic-gate number = number * 8 + ch - '0'; 4377c478bd9Sstevel@tonic-gate } 4387c478bd9Sstevel@tonic-gate 4397c478bd9Sstevel@tonic-gate if (number == 0) 4407c478bd9Sstevel@tonic-gate number = 0200; 4417c478bd9Sstevel@tonic-gate *(ptr++) = (char)number; 4427c478bd9Sstevel@tonic-gate } else { 4437c478bd9Sstevel@tonic-gate switch (ch) { 4447c478bd9Sstevel@tonic-gate case 'E': 4457c478bd9Sstevel@tonic-gate case 'e': *(ptr++) = '\033'; break; 4467c478bd9Sstevel@tonic-gate 4477c478bd9Sstevel@tonic-gate case 'l': 4487c478bd9Sstevel@tonic-gate case 'n': *(ptr++) = '\n'; break; 4497c478bd9Sstevel@tonic-gate 4507c478bd9Sstevel@tonic-gate case 'r': *(ptr++) = '\r'; break; 4517c478bd9Sstevel@tonic-gate 4527c478bd9Sstevel@tonic-gate case 'b': *(ptr++) = '\010'; break; 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate case 's': *(ptr++) = ' '; break; 4557c478bd9Sstevel@tonic-gate 4567c478bd9Sstevel@tonic-gate case 'f': *(ptr++) = '\014'; break; 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate case 't': *(ptr++) = '\t'; break; 4597c478bd9Sstevel@tonic-gate 4607c478bd9Sstevel@tonic-gate case '\\': *(ptr++) = '\\'; break; 4617c478bd9Sstevel@tonic-gate 4627c478bd9Sstevel@tonic-gate case '^': *(ptr++) = '^'; break; 4637c478bd9Sstevel@tonic-gate 4647c478bd9Sstevel@tonic-gate case ',': *(ptr++) = ','; break; 4657c478bd9Sstevel@tonic-gate 4667c478bd9Sstevel@tonic-gate case ':': *(ptr++) = ':'; break; 4677c478bd9Sstevel@tonic-gate 4687c478bd9Sstevel@tonic-gate default: 4697c478bd9Sstevel@tonic-gate warning("Illegal character in \\ sequence - '%c'", 4707c478bd9Sstevel@tonic-gate ch); 4717c478bd9Sstevel@tonic-gate *(ptr++) = ch; 4727c478bd9Sstevel@tonic-gate } /* endswitch (ch) */ 4737c478bd9Sstevel@tonic-gate } /* endelse (ch < '0' || ch > '7') */ 4747c478bd9Sstevel@tonic-gate } /* end else if (ch == '\\') */ 4757c478bd9Sstevel@tonic-gate else { 4767c478bd9Sstevel@tonic-gate if (ch != '\n') *(ptr++) = ch; 4777c478bd9Sstevel@tonic-gate } 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate count ++; 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate if (count > 1000) 4827c478bd9Sstevel@tonic-gate warning("Very long string found. Missing comma?"); 4837c478bd9Sstevel@tonic-gate } /* end while */ 4847c478bd9Sstevel@tonic-gate 4857c478bd9Sstevel@tonic-gate if (ch == EOF) 4867c478bd9Sstevel@tonic-gate warning("Premature EOF - missing comma?"); 4877c478bd9Sstevel@tonic-gate /* start of new description */ 4887c478bd9Sstevel@tonic-gate else if (first_column) { 4897c478bd9Sstevel@tonic-gate backspace(); 4907c478bd9Sstevel@tonic-gate warning("Missing comma?"); 4917c478bd9Sstevel@tonic-gate /* pretend we did get a comma */ 4927c478bd9Sstevel@tonic-gate ch = ','; 4937c478bd9Sstevel@tonic-gate } 4947c478bd9Sstevel@tonic-gate 4957c478bd9Sstevel@tonic-gate *ptr = '\0'; 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate if (count == 0) 4987c478bd9Sstevel@tonic-gate return (NULL); 4997c478bd9Sstevel@tonic-gate return (ch); 5007c478bd9Sstevel@tonic-gate } 5017c478bd9Sstevel@tonic-gate 5027c478bd9Sstevel@tonic-gate /* 5037c478bd9Sstevel@tonic-gate * Panic mode error recovery - skip everything until a "ch" is found. 5047c478bd9Sstevel@tonic-gate */ 505*d2117003Sdp void 5067c478bd9Sstevel@tonic-gate panic_mode(int ch) 5077c478bd9Sstevel@tonic-gate { 508*d2117003Sdp int c; 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate for (;;) { 5117c478bd9Sstevel@tonic-gate c = next_char(); 5127c478bd9Sstevel@tonic-gate if (c == ch) 5137c478bd9Sstevel@tonic-gate return; 5147c478bd9Sstevel@tonic-gate if (c == EOF) 5157c478bd9Sstevel@tonic-gate return; 5167c478bd9Sstevel@tonic-gate } 5177c478bd9Sstevel@tonic-gate } 518