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