1*7c478bd9Sstevel@tonic-gate %{ 2*7c478bd9Sstevel@tonic-gate /* 3*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 4*7c478bd9Sstevel@tonic-gate * 5*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 6*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 7*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 8*7c478bd9Sstevel@tonic-gate * with the License. 9*7c478bd9Sstevel@tonic-gate * 10*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 12*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 13*7c478bd9Sstevel@tonic-gate * and limitations under the License. 14*7c478bd9Sstevel@tonic-gate * 15*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 16*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 18*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 19*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 20*7c478bd9Sstevel@tonic-gate * 21*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 22*7c478bd9Sstevel@tonic-gate * 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1991, 2001 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 27*7c478bd9Sstevel@tonic-gate 28*7c478bd9Sstevel@tonic-gate #include <stdio.h> 29*7c478bd9Sstevel@tonic-gate #include <string.h> 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #define TRUE 1 32*7c478bd9Sstevel@tonic-gate #define FALSE 0 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate extern int stdin_only; 35*7c478bd9Sstevel@tonic-gate extern char curr_file[]; /* Name of file currently being read. */ 36*7c478bd9Sstevel@tonic-gate extern int curr_linenum; /* line number in the current input file */ 37*7c478bd9Sstevel@tonic-gate extern int warn_linenum; /* line number of current warning message */ 38*7c478bd9Sstevel@tonic-gate extern int optind; 39*7c478bd9Sstevel@tonic-gate extern int gargc; 40*7c478bd9Sstevel@tonic-gate extern char **gargv; 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate extern void handle_macro_line(void); 43*7c478bd9Sstevel@tonic-gate extern void handle_cplus_comment_line(void); 44*7c478bd9Sstevel@tonic-gate extern void handle_open_comment(void); 45*7c478bd9Sstevel@tonic-gate extern void handle_close_comment(void); 46*7c478bd9Sstevel@tonic-gate extern void handle_gettext(void); 47*7c478bd9Sstevel@tonic-gate extern void handle_dgettext(void); 48*7c478bd9Sstevel@tonic-gate extern void handle_dcgettext(void); 49*7c478bd9Sstevel@tonic-gate extern void handle_textdomain(void); 50*7c478bd9Sstevel@tonic-gate extern void handle_character(void); 51*7c478bd9Sstevel@tonic-gate extern void handle_open_paren(void); 52*7c478bd9Sstevel@tonic-gate extern void handle_close_paren(void); 53*7c478bd9Sstevel@tonic-gate extern void handle_esc_newline(void); 54*7c478bd9Sstevel@tonic-gate extern void handle_comma(void); 55*7c478bd9Sstevel@tonic-gate extern void handle_newline(void); 56*7c478bd9Sstevel@tonic-gate extern void handle_quote(void); 57*7c478bd9Sstevel@tonic-gate extern void handle_spaces(void); 58*7c478bd9Sstevel@tonic-gate extern void handle_spaces(void); 59*7c478bd9Sstevel@tonic-gate extern void handle_character(void); 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate /* 62*7c478bd9Sstevel@tonic-gate * The following lex rule basically wants to recognize tokens 63*7c478bd9Sstevel@tonic-gate * that can change the current state of scanning source code. 64*7c478bd9Sstevel@tonic-gate * Evertime such tokens are recognized, the specific handler will be 65*7c478bd9Sstevel@tonic-gate * executed. All other tokens are treated as regular characters and 66*7c478bd9Sstevel@tonic-gate * they are all handled the same way. 67*7c478bd9Sstevel@tonic-gate * The tricky part was not to miss any specification in ANSI-C code 68*7c478bd9Sstevel@tonic-gate * that looks like a meaningful token but not a meaningful one and 69*7c478bd9Sstevel@tonic-gate * should be treated as regular characters. 70*7c478bd9Sstevel@tonic-gate * For example, 71*7c478bd9Sstevel@tonic-gate * c= '"';d='"'; printf("\"" "\(\)\\\""); 72*7c478bd9Sstevel@tonic-gate * c = ABgettext("Not a gettext"); 73*7c478bd9Sstevel@tonic-gate * c = gettextXY("Not a gettext"); 74*7c478bd9Sstevel@tonic-gate * c = ABgettextXY("Not a gettext"); 75*7c478bd9Sstevel@tonic-gate */ 76*7c478bd9Sstevel@tonic-gate %} 77*7c478bd9Sstevel@tonic-gate 78*7c478bd9Sstevel@tonic-gate IDCHARS [a-zA-Z0-9_] 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate %% 81*7c478bd9Sstevel@tonic-gate ^#(.*\\\n)**.*\n { handle_macro_line(); } 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate \/\/ { handle_cplus_comment_line(); } 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate \/\* { handle_open_comment(); } 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate \*\/ { handle_close_comment(); } 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate dcgettext { handle_dcgettext(); } 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate dgettext { handle_dgettext(); } 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate gettext { handle_gettext(); } 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate textdomain { handle_textdomain(); } 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate {IDCHARS}+ | 98*7c478bd9Sstevel@tonic-gate \'\"\' | 99*7c478bd9Sstevel@tonic-gate \'\\\"\' | 100*7c478bd9Sstevel@tonic-gate \\\\ | 101*7c478bd9Sstevel@tonic-gate \\\" | 102*7c478bd9Sstevel@tonic-gate \\\( | 103*7c478bd9Sstevel@tonic-gate \\\) { handle_character(); } 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate \( { handle_open_paren(); } 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate \) { handle_close_paren(); } 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate \\\n { handle_esc_newline(); } 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate \, { handle_comma(); } 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate \n { handle_newline(); } 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate \" { handle_quote(); } 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate " " { handle_spaces(); } 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate "\t" { handle_spaces(); } 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate . { handle_character(); } 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate %% 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate /* 126*7c478bd9Sstevel@tonic-gate * Since multiple files can be processed, yywrap() should keep feeding 127*7c478bd9Sstevel@tonic-gate * all input files specified. 128*7c478bd9Sstevel@tonic-gate */ 129*7c478bd9Sstevel@tonic-gate int 130*7c478bd9Sstevel@tonic-gate yywrap(void) 131*7c478bd9Sstevel@tonic-gate { 132*7c478bd9Sstevel@tonic-gate FILE *fp; 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate if ((optind >= gargc) || (stdin_only == TRUE)) { 135*7c478bd9Sstevel@tonic-gate return (1); 136*7c478bd9Sstevel@tonic-gate } else { 137*7c478bd9Sstevel@tonic-gate /* 138*7c478bd9Sstevel@tonic-gate * gargv still contains not-processed input files. 139*7c478bd9Sstevel@tonic-gate */ 140*7c478bd9Sstevel@tonic-gate (void) freopen(gargv[optind], "r", stdin); 141*7c478bd9Sstevel@tonic-gate if ((fp = freopen(gargv[optind], "r", stdin)) == NULL) { 142*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "ERROR, can't open input file: %s\n", 143*7c478bd9Sstevel@tonic-gate gargv[optind]); 144*7c478bd9Sstevel@tonic-gate } 145*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 146*7c478bd9Sstevel@tonic-gate (void) printf("In yywrap(), opening file %d, <%s>\n", 147*7c478bd9Sstevel@tonic-gate optind, gargv[optind]); 148*7c478bd9Sstevel@tonic-gate #endif 149*7c478bd9Sstevel@tonic-gate /* 150*7c478bd9Sstevel@tonic-gate * Reset global file name and line number for the new file. 151*7c478bd9Sstevel@tonic-gate */ 152*7c478bd9Sstevel@tonic-gate (void) strcpy(curr_file, gargv[optind]); 153*7c478bd9Sstevel@tonic-gate curr_linenum = 0; 154*7c478bd9Sstevel@tonic-gate warn_linenum = 0; 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate optind++; 157*7c478bd9Sstevel@tonic-gate 158*7c478bd9Sstevel@tonic-gate return (0); 159*7c478bd9Sstevel@tonic-gate } 160*7c478bd9Sstevel@tonic-gate 161*7c478bd9Sstevel@tonic-gate } /* yywrap */ 162