1 %{ 2 /*- 3 * SPDX-License-Identifier: BSD-3-Clause 4 * 5 * Copyright (c) 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Paul Borman at Krystal Technologies. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36 #ifndef lint 37 #if 0 38 static char sccsid[] = "@(#)lex.l 8.1 (Berkeley) 6/6/93"; 39 #endif 40 #endif /* not lint */ 41 42 #include <sys/cdefs.h> 43 __FBSDID("$FreeBSD: stable/12/usr.bin/mklocale/lex.l 326025 2017-11-20 19:49:47Z pfg $"); 44 45 #include <ctype.h> 46 #include <stdio.h> 47 #include <stdlib.h> 48 49 #include "ldef.h" 50 #include "y.tab.h" 51 #include "extern.h" 52 53 #define YY_DECL int yylex(void) 54 %} 55 56 ODIGIT [0-7] 57 DIGIT [0-9] 58 XDIGIT [0-9a-fA-F] 59 W [\t\n\r ] 60 61 %% 62 \'.\' { yylval.rune = (unsigned char)yytext[1]; 63 return(RUNE); } 64 65 '\\a' { yylval.rune = '\a'; 66 return(RUNE); } 67 '\\b' { yylval.rune = '\b'; 68 return(RUNE); } 69 '\\f' { yylval.rune = '\f'; 70 return(RUNE); } 71 '\\n' { yylval.rune = '\n'; 72 return(RUNE); } 73 '\\r' { yylval.rune = '\r'; 74 return(RUNE); } 75 '\\t' { yylval.rune = '\t'; 76 return(RUNE); } 77 '\\v' { yylval.rune = '\v'; 78 return(RUNE); } 79 80 0x{XDIGIT}+ { yylval.rune = strtol(yytext, 0, 16); 81 return(RUNE); } 82 0{ODIGIT}+ { yylval.rune = strtol(yytext, 0, 8); 83 return(RUNE); } 84 {DIGIT}+ { yylval.rune = strtol(yytext, 0, 10); 85 return(RUNE); } 86 87 88 MAPLOWER { return(MAPLOWER); } 89 MAPUPPER { return(MAPUPPER); } 90 TODIGIT { return(DIGITMAP); } 91 INVALID { return(INVALID); } 92 93 ALPHA { yylval.i = _CTYPE_A|_CTYPE_R|_CTYPE_G; 94 return(LIST); } 95 CONTROL { yylval.i = _CTYPE_C; 96 return(LIST); } 97 DIGIT { yylval.i = _CTYPE_D|_CTYPE_R|_CTYPE_G; 98 return(LIST); } 99 GRAPH { yylval.i = _CTYPE_G|_CTYPE_R; 100 return(LIST); } 101 LOWER { yylval.i = _CTYPE_L|_CTYPE_R|_CTYPE_G; 102 return(LIST); } 103 PUNCT { yylval.i = _CTYPE_P|_CTYPE_R|_CTYPE_G; 104 return(LIST); } 105 SPACE { yylval.i = _CTYPE_S; 106 return(LIST); } 107 UPPER { yylval.i = _CTYPE_U|_CTYPE_R|_CTYPE_G; 108 return(LIST); } 109 XDIGIT { yylval.i = _CTYPE_X|_CTYPE_R|_CTYPE_G; 110 return(LIST); } 111 BLANK { yylval.i = _CTYPE_B; 112 return(LIST); } 113 PRINT { yylval.i = _CTYPE_R; 114 return(LIST); } 115 IDEOGRAM { yylval.i = _CTYPE_I|_CTYPE_R|_CTYPE_G; 116 return(LIST); } 117 SPECIAL { yylval.i = _CTYPE_T|_CTYPE_R|_CTYPE_G; 118 return(LIST); } 119 PHONOGRAM { yylval.i = _CTYPE_Q|_CTYPE_R|_CTYPE_G; 120 return(LIST); } 121 SWIDTH0 { yylval.i = _CTYPE_SW0; return(LIST); } 122 SWIDTH1 { yylval.i = _CTYPE_SW1; return(LIST); } 123 SWIDTH2 { yylval.i = _CTYPE_SW2; return(LIST); } 124 SWIDTH3 { yylval.i = _CTYPE_SW3; return(LIST); } 125 126 VARIABLE[\t ] { static char vbuf[1024]; 127 char *v = vbuf; 128 while ((*v = input()) && *v != '\n') 129 ++v; 130 if (*v) { 131 unput(*v); 132 *v = 0; 133 } 134 yylval.str = vbuf; 135 return(VARIABLE); 136 } 137 138 ENCODING { return(ENCODING); } 139 140 \".*\" { char *e = yytext + 1; 141 yylval.str = e; 142 while (*e && *e != '"') 143 ++e; 144 *e = 0; 145 return(STRING); } 146 147 \<|\(|\[ { return(LBRK); } 148 149 \>|\)|\] { return(RBRK); } 150 151 \- { return(THRU); } 152 \.\.\. { return(THRU); } 153 154 \: { return(':'); } 155 156 {W}+ ; 157 158 ^\#.*\n ; 159 \/\* { char lc = 0; 160 do { 161 while ((lc) != '*') 162 if ((lc = input()) == 0) 163 break; 164 } while((lc = input()) != '/'); 165 } 166 167 \\$ ; 168 . { printf("Lex is skipping '%s'\n", yytext); } 169 %% 170 171 #if !defined(yywrap) 172 int 173 yywrap(void) 174 { 175 return(1); 176 } 177 #endif 178