scan.l (87052) | scan.l (87243) |
---|---|
1%x string name charmap defn nchar subs subs2 2%{ 3/*- 4 * Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua> 5 * at Electronni Visti IA, Kiev, Ukraine. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 11 unchanged lines hidden (view full) --- 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. | 1%x string name charmap defn nchar subs subs2 2%{ 3/*- 4 * Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua> 5 * at Electronni Visti IA, Kiev, Ukraine. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 11 unchanged lines hidden (view full) --- 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. |
28 * 29 * $FreeBSD: head/usr.bin/colldef/scan.l 87052 2001-11-28 09:50:24Z ache $ | |
30 */ 31 | 28 */ 29 |
30#include <sys/cdefs.h> 31 32__FBSDID("$FreeBSD: head/usr.bin/colldef/scan.l 87243 2001-12-02 23:40:46Z markm $"); 33 |
|
32#include <ctype.h> 33#include <err.h> 34#include <unistd.h> 35#include <string.h> 36#include <sysexits.h> 37#include "collate.h" 38#include "common.h" 39#include "y.tab.h" 40 41int line_no = 1, save_no, fromsubs; 42u_char buf[BUFSIZE], *ptr; 43FILE *map_fp; 44YY_BUFFER_STATE main_buf, map_buf; 45#ifdef FLEX_DEBUG 46YYSTYPE yylval; 47#endif /* FLEX_DEBUG */ | 34#include <ctype.h> 35#include <err.h> 36#include <unistd.h> 37#include <string.h> 38#include <sysexits.h> 39#include "collate.h" 40#include "common.h" 41#include "y.tab.h" 42 43int line_no = 1, save_no, fromsubs; 44u_char buf[BUFSIZE], *ptr; 45FILE *map_fp; 46YY_BUFFER_STATE main_buf, map_buf; 47#ifdef FLEX_DEBUG 48YYSTYPE yylval; 49#endif /* FLEX_DEBUG */ |
50int yylex(void); |
|
48%} 49%% 50<INITIAL,charmap,nchar,subs,subs2>[ \t]+ ; 51<subs2>\" { ptr = buf; BEGIN(string); } 52<subs>\< { ptr = buf; fromsubs = 1; BEGIN(name); } 53<INITIAL>\< { ptr = buf; fromsubs = 0; BEGIN(name); } 54^#.*\n line_no++; 55^\n line_no++; --- 105 unchanged lines hidden (view full) --- 161} 162<string>\" { 163 *ptr = '\0'; 164 strcpy(yylval.str, buf); 165 BEGIN(subs2); 166 return STRING; 167} 168<name,defn>. { | 51%} 52%% 53<INITIAL,charmap,nchar,subs,subs2>[ \t]+ ; 54<subs2>\" { ptr = buf; BEGIN(string); } 55<subs>\< { ptr = buf; fromsubs = 1; BEGIN(name); } 56<INITIAL>\< { ptr = buf; fromsubs = 0; BEGIN(name); } 57^#.*\n line_no++; 58^\n line_no++; --- 105 unchanged lines hidden (view full) --- 164} 165<string>\" { 166 *ptr = '\0'; 167 strcpy(yylval.str, buf); 168 BEGIN(subs2); 169 return STRING; 170} 171<name,defn>. { |
169 char *s = (map_fp != NULL) ? map_name : "input"; | 172 const char *s = (map_fp != NULL) ? map_name : "input"; |
170 171 if (!isascii(*yytext) || !isprint(*yytext)) 172 errx(EX_UNAVAILABLE, "non-ASCII or non-printable character 0x%02x not allowed in the map/name near line %u of %s", 173 *yytext, line_no, s); 174 if(ptr >= buf + sizeof(buf) - 1) 175 errx(EX_UNAVAILABLE, "map/name buffer overflow near line %u of %s, character '%c'", 176 line_no, s, *yytext); 177 *ptr++ = *yytext; --- 36 unchanged lines hidden (view full) --- 214} 215<string>\\a { 216 if(ptr >= buf + sizeof(buf) - 1) 217 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\a'", 218 line_no); 219 *ptr++ = '\a'; 220} 221<name,string,defn>\n { | 173 174 if (!isascii(*yytext) || !isprint(*yytext)) 175 errx(EX_UNAVAILABLE, "non-ASCII or non-printable character 0x%02x not allowed in the map/name near line %u of %s", 176 *yytext, line_no, s); 177 if(ptr >= buf + sizeof(buf) - 1) 178 errx(EX_UNAVAILABLE, "map/name buffer overflow near line %u of %s, character '%c'", 179 line_no, s, *yytext); 180 *ptr++ = *yytext; --- 36 unchanged lines hidden (view full) --- 217} 218<string>\\a { 219 if(ptr >= buf + sizeof(buf) - 1) 220 errx(EX_UNAVAILABLE, "string buffer overflow near line %u, character '\\a'", 221 line_no); 222 *ptr++ = '\a'; 223} 224<name,string,defn>\n { |
222 char *s = (map_fp != NULL) ? map_name : "input"; | 225 const char *s = (map_fp != NULL) ? map_name : "input"; |
223 224 errx(EX_UNAVAILABLE, "unterminated map/name/string near line %u of %s", line_no, s); 225} 226<name,string,nchar><<EOF>> { | 226 227 errx(EX_UNAVAILABLE, "unterminated map/name/string near line %u of %s", line_no, s); 228} 229<name,string,nchar><<EOF>> { |
227 char *s = (map_fp != NULL) ? map_name : "input"; | 230 const char *s = (map_fp != NULL) ? map_name : "input"; |
228 229 errx(EX_UNAVAILABLE, "premature EOF in the name/string/char near line %u of %s", line_no, s); 230} 231<string>\\x[0-9a-f]{2} { 232 u_int v; 233 234 sscanf(&yytext[2], "%x", &v); 235 *ptr++ = (u_char)v; --- 63 unchanged lines hidden --- | 231 232 errx(EX_UNAVAILABLE, "premature EOF in the name/string/char near line %u of %s", line_no, s); 233} 234<string>\\x[0-9a-f]{2} { 235 u_int v; 236 237 sscanf(&yytext[2], "%x", &v); 238 *ptr++ = (u_char)v; --- 63 unchanged lines hidden --- |