dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / sgs / lex / common / yyless.c
blob87ddeae83a3d33d418e8f8cb4bb9d3ebfa88f7cf
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
22 /* Copyright (c) 1988 AT&T */
23 /* All Rights Reserved */
27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include <sys/euc.h>
34 #include <stdlib.h>
35 #include <widec.h>
36 #include <limits.h>
37 #include <inttypes.h>
38 #include <unistd.h>
40 #pragma weak yyprevious
41 extern int yyprevious;
43 #ifndef JLSLEX
44 #define CHR char
46 #pragma weak yyinput
47 #pragma weak yyleng
48 #pragma weak yyunput
49 #pragma weak yytext
50 extern CHR yytext[];
52 #define YYTEXT yytext
53 #define YYLENG yyleng
54 #define YYINPUT yyinput
55 #define YYUNPUT yyunput
56 #define YYOUTPUT yyoutput
57 #endif
59 #ifdef WOPTION
60 #define CHR wchar_t
62 #pragma weak yyinput
63 #pragma weak yyleng
64 #pragma weak yyunput
65 #pragma weak yytext
66 extern CHR yytext[];
68 #define YYTEXT yytext
69 #define YYLENG yyleng
70 #define YYINPUT yyinput
71 #define YYUNPUT yyunput
72 #define YYOUTPUT yyoutput
73 #endif
75 #ifdef EOPTION
76 #define CHR wchar_t
78 #pragma weak yyleng
79 extern int yyleng;
80 #pragma weak yytext
81 extern CHR yytext[];
82 #pragma weak yywinput
83 #pragma weak yywleng
84 #pragma weak yywunput
85 #pragma weak yywtext
86 extern CHR yywtext[];
88 #define YYTEXT yywtext
89 #define YYLENG yywleng
90 #define YYINPUT yywinput
91 #define YYUNPUT yywunput
92 #define YYOUTPUT yywoutput
93 #endif
95 extern int YYLENG;
96 #if defined(__STDC__)
97 extern void YYUNPUT(int);
98 #endif
100 #if defined(__cplusplus) || defined(__STDC__)
101 /* XCU4: type of yyless() changes to int */
103 yyless(int x)
104 #else
105 yyless(x)
106 int x;
107 #endif
109 register CHR *lastch, *ptr;
111 lastch = YYTEXT+YYLENG;
112 if (x >= 0 && x <= YYLENG)
113 ptr = x + YYTEXT;
114 else {
115 #ifdef _LP64
116 static int seen = 0;
118 if (!seen) {
119 (void) write(2,
120 "warning: yyless pointer arg truncated\n",
121 39);
122 seen = 1;
124 #endif /* _LP64 */
126 * The cast on the next line papers over an unconscionable nonportable
127 * glitch to allow the caller to hand the function a pointer instead of
128 * an integer and hope that it gets figured out properly. But it's
129 * that way on all systems.
131 ptr = (CHR *)(intptr_t)x;
133 while (lastch > ptr)
134 YYUNPUT(*--lastch);
135 *lastch = 0;
136 if (ptr > YYTEXT)
137 yyprevious = *--lastch;
138 YYLENG = ptr-YYTEXT;
139 #ifdef EOPTION
140 yyleng = wcstombs((char *)yytext, YYTEXT, YYLENG*MB_LEN_MAX);
141 #endif
142 return (0);