yyless.c (3021B)
1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* Copyright (c) 1988 AT&T */ 23 /* All Rights Reserved */ 24 25 26 /* 27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 28 * Use is subject to license terms. 29 */ 30 31 /* from OpenSolaris "yyless.c 6.14 05/06/08 SMI" */ 32 33 /* 34 * Portions Copyright (c) 2005 Gunnar Ritter, Freiburg i. Br., Germany 35 * 36 * Sccsid @(#)yyless.c 1.6 (gritter) 11/27/05 37 */ 38 39 #include <stdlib.h> 40 #ifdef __sun 41 #include <sys/euc.h> 42 #include <widec.h> 43 #endif 44 #include <limits.h> 45 #include <inttypes.h> 46 #include <unistd.h> 47 48 extern int yyprevious; 49 50 #ifndef JLSLEX 51 #define CHR char 52 53 extern CHR yytext[]; 54 55 #define YYTEXT yytext 56 #define YYLENG yyleng 57 #define YYINPUT yyinput 58 #define YYUNPUT yyunput 59 #define YYOUTPUT yyoutput 60 #endif 61 62 #ifdef WOPTION 63 #define CHR wchar_t 64 65 extern CHR yytext[]; 66 67 #define YYTEXT yytext 68 #define YYLENG yyleng 69 #define YYINPUT yyinput 70 #define YYUNPUT yyunput 71 #define YYOUTPUT yyoutput 72 #define yyless yyless_w 73 #endif 74 75 #ifdef EOPTION 76 #define CHR wchar_t 77 78 extern int yyleng; 79 extern CHR yytext[]; 80 extern CHR yywtext[]; 81 82 #define YYTEXT yywtext 83 #define YYLENG yywleng 84 #define YYINPUT yywinput 85 #define YYUNPUT yywunput 86 #define YYOUTPUT yywoutput 87 #define yyless yyless_e 88 #endif 89 90 extern int YYLENG; 91 #if defined(__STDC__) 92 extern void YYUNPUT(int); 93 #endif 94 95 #if defined(__cplusplus) || defined(__STDC__) 96 /* XCU4: type of yyless() changes to int */ 97 int 98 yyless(int x) 99 #else 100 yyless(x) 101 int x; 102 #endif 103 { 104 register CHR *lastch, *ptr; 105 106 lastch = YYTEXT+YYLENG; 107 if (x >= 0 && x <= YYLENG) 108 ptr = x + YYTEXT; 109 else { 110 if (sizeof (int) != sizeof (intptr_t)) { 111 static int seen = 0; 112 113 if (!seen) { 114 write(2, 115 "warning: yyless pointer arg truncated\n", 39); 116 seen = 1; 117 } 118 } 119 /* 120 * The cast on the next line papers over an unconscionable nonportable 121 * glitch to allow the caller to hand the function a pointer instead of 122 * an integer and hope that it gets figured out properly. But it's 123 * that way on all systems. 124 */ 125 ptr = (CHR *)(intptr_t)x; 126 } 127 while (lastch > ptr) 128 YYUNPUT(*--lastch); 129 *lastch = 0; 130 if (ptr > YYTEXT) 131 yyprevious = *--lastch; 132 YYLENG = ptr-YYTEXT; 133 #ifdef EOPTION 134 yyleng = wcstombs((char *)yytext, YYTEXT, YYLENG*MB_LEN_MAX); 135 #endif 136 return (0); 137 }