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 27*7c478bd9Sstevel@tonic-gate #include <stdio.h> 28*7c478bd9Sstevel@tonic-gate #include <string.h> 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #define TRUE 1 31*7c478bd9Sstevel@tonic-gate #define FALSE 0 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate extern int stdin_only; 34*7c478bd9Sstevel@tonic-gate extern char curr_file[]; /* Name of file currently being read. */ 35*7c478bd9Sstevel@tonic-gate extern int curr_linenum; /* line number in the current input file */ 36*7c478bd9Sstevel@tonic-gate extern int warn_linenum; /* line number of current warning message */ 37*7c478bd9Sstevel@tonic-gate extern int optind; 38*7c478bd9Sstevel@tonic-gate extern int gargc; 39*7c478bd9Sstevel@tonic-gate extern char **gargv; 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate extern void handle_macro_line(void); 42*7c478bd9Sstevel@tonic-gate extern void handle_cplus_comment_line(void); 43*7c478bd9Sstevel@tonic-gate extern void handle_open_comment(void); 44*7c478bd9Sstevel@tonic-gate extern void handle_close_comment(void); 45*7c478bd9Sstevel@tonic-gate extern void handle_gettext(void); 46*7c478bd9Sstevel@tonic-gate extern void handle_dgettext(void); 47*7c478bd9Sstevel@tonic-gate extern void handle_dcgettext(void); 48*7c478bd9Sstevel@tonic-gate extern void handle_textdomain(void); 49*7c478bd9Sstevel@tonic-gate extern void handle_character(void); 50*7c478bd9Sstevel@tonic-gate extern void handle_open_paren(void); 51*7c478bd9Sstevel@tonic-gate extern void handle_close_paren(void); 52*7c478bd9Sstevel@tonic-gate extern void handle_esc_newline(void); 53*7c478bd9Sstevel@tonic-gate extern void handle_comma(void); 54*7c478bd9Sstevel@tonic-gate extern void handle_newline(void); 55*7c478bd9Sstevel@tonic-gate extern void handle_quote(void); 56*7c478bd9Sstevel@tonic-gate extern void handle_spaces(void); 57*7c478bd9Sstevel@tonic-gate extern void handle_spaces(void); 58*7c478bd9Sstevel@tonic-gate extern void handle_character(void); 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate /* 61*7c478bd9Sstevel@tonic-gate * The following lex rule basically wants to recognize tokens 62*7c478bd9Sstevel@tonic-gate * that can change the current state of scanning source code. 63*7c478bd9Sstevel@tonic-gate * Evertime such tokens are recognized, the specific handler will be 64*7c478bd9Sstevel@tonic-gate * executed. All other tokens are treated as regular characters and 65*7c478bd9Sstevel@tonic-gate * they are all handled the same way. 66*7c478bd9Sstevel@tonic-gate * The tricky part was not to miss any specification in ANSI-C code 67*7c478bd9Sstevel@tonic-gate * that looks like a meaningful token but not a meaningful one and 68*7c478bd9Sstevel@tonic-gate * should be treated as regular characters. 69*7c478bd9Sstevel@tonic-gate * For example, 70*7c478bd9Sstevel@tonic-gate * c= '"';d='"'; printf("\"" "\(\)\\\""); 71*7c478bd9Sstevel@tonic-gate * c = ABgettext("Not a gettext"); 72*7c478bd9Sstevel@tonic-gate * c = gettextXY("Not a gettext"); 73*7c478bd9Sstevel@tonic-gate * c = ABgettextXY("Not a gettext"); 74*7c478bd9Sstevel@tonic-gate */ 75*7c478bd9Sstevel@tonic-gate %} 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate IDCHARS [a-zA-Z0-9_] 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate %% 80*7c478bd9Sstevel@tonic-gate ^#(.*\\\n)**.*\n { handle_macro_line(); } 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate \/\/ { handle_cplus_comment_line(); } 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate \/\* { handle_open_comment(); } 85*7c478bd9Sstevel@tonic-gate 86*7c478bd9Sstevel@tonic-gate \*\/ { handle_close_comment(); } 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate dcgettext { handle_dcgettext(); } 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate dgettext { handle_dgettext(); } 91*7c478bd9Sstevel@tonic-gate 92*7c478bd9Sstevel@tonic-gate gettext { handle_gettext(); } 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate textdomain { handle_textdomain(); } 95*7c478bd9Sstevel@tonic-gate 96*7c478bd9Sstevel@tonic-gate {IDCHARS}+ | 97*7c478bd9Sstevel@tonic-gate \'\"\' | 98*7c478bd9Sstevel@tonic-gate \'\\\"\' | 99*7c478bd9Sstevel@tonic-gate \\\\ | 100*7c478bd9Sstevel@tonic-gate \\\" | 101*7c478bd9Sstevel@tonic-gate \\\( | 102*7c478bd9Sstevel@tonic-gate \\\) { handle_character(); } 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate \( { handle_open_paren(); } 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate \) { handle_close_paren(); } 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate \\\n { handle_esc_newline(); } 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate \, { handle_comma(); } 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate \n { handle_newline(); } 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate \" { handle_quote(); } 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate " " { handle_spaces(); } 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate "\t" { handle_spaces(); } 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate . { handle_character(); } 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate %% 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate /* 125*7c478bd9Sstevel@tonic-gate * Since multiple files can be processed, yywrap() should keep feeding 126*7c478bd9Sstevel@tonic-gate * all input files specified. 127*7c478bd9Sstevel@tonic-gate */ 128*7c478bd9Sstevel@tonic-gate int 129*7c478bd9Sstevel@tonic-gate yywrap(void) 130*7c478bd9Sstevel@tonic-gate { 131*7c478bd9Sstevel@tonic-gate FILE *fp; 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate if ((optind >= gargc) || (stdin_only == TRUE)) { 134*7c478bd9Sstevel@tonic-gate return (1); 135*7c478bd9Sstevel@tonic-gate } else { 136*7c478bd9Sstevel@tonic-gate /* 137*7c478bd9Sstevel@tonic-gate * gargv still contains not-processed input files. 138*7c478bd9Sstevel@tonic-gate */ 139*7c478bd9Sstevel@tonic-gate (void) freopen(gargv[optind], "r", stdin); 140*7c478bd9Sstevel@tonic-gate if ((fp = freopen(gargv[optind], "r", stdin)) == NULL) { 141*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "ERROR, can't open input file: %s\n", 142*7c478bd9Sstevel@tonic-gate gargv[optind]); 143*7c478bd9Sstevel@tonic-gate } 144*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 145*7c478bd9Sstevel@tonic-gate (void) printf("In yywrap(), opening file %d, <%s>\n", 146*7c478bd9Sstevel@tonic-gate optind, gargv[optind]); 147*7c478bd9Sstevel@tonic-gate #endif 148*7c478bd9Sstevel@tonic-gate /* 149*7c478bd9Sstevel@tonic-gate * Reset global file name and line number for the new file. 150*7c478bd9Sstevel@tonic-gate */ 151*7c478bd9Sstevel@tonic-gate (void) strcpy(curr_file, gargv[optind]); 152*7c478bd9Sstevel@tonic-gate curr_linenum = 0; 153*7c478bd9Sstevel@tonic-gate warn_linenum = 0; 154*7c478bd9Sstevel@tonic-gate 155*7c478bd9Sstevel@tonic-gate optind++; 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate return (0); 158*7c478bd9Sstevel@tonic-gate } 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gate } /* yywrap */ 161