5 * The contents of this file are subject to the terms of the
6 * Common Development and Distribution License, Version 1.0 only
7 * (the "License"). You may not use this file except in compliance
10 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 * or http://www.opensolaris.org/os/licensing.
12 * See the License for the specific language governing permissions
13 * and limitations under the License.
15 * When distributing Covered Code, include this CDDL HEADER in each
16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 * If applicable, add the following below this CDDL HEADER, with the
18 * fields enclosed by brackets "[]" replaced with your own identifying
19 * information: Portions Copyright [yyyy] [name of copyright owner]
25 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
29 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
30 /* All Rights Reserved */
32 /* Copyright (c) 1987, 1988 Microsoft Corporation */
33 /* All Rights Reserved */
36 * Copyright 2013 Damian Bogel. All rights reserved.
40 * egrep -- print lines containing (or not containing) a regular expression
43 * 0 - ok, and some matches
44 * 1 - ok, but no matches
45 * 2 - some error; matches irrelevant
47 %token CHAR MCHAR DOT MDOT CCL NCCL MCCL NMCCL OR CAT STAR PLUS QUEST
49 %left CHAR MCHAR DOT CCL NCCL MCCL NMCCL
'('
64 #define STDIN_FILENAME gettext("(standard input)")
66 #define BLKSIZE 512 /* size of reported disk blocks */
73 #define RIGHT '\n' /* serves as record separator and as $ */
74 #define LEFT '\n' /* beginning of line */
75 int gotofn
[NSTATES
][NCHARS
];
88 int maxlin
, maxclin
, maxwclin
, maxpos
;
142 { $$
= node
(CAT
, $1, $2); }
144 { $$
= node
(CAT
, $2, $3); }
146 { $$
= node
(CAT
, $2, $3); }
148 { $$
= node
(CAT
, $1, $2); }
155 $$
= unary
(STAR
, $$
);
159 { $$
= iflag
&& isalpha
($1) ?
160 node
(OR
, enter
(tolower
($1)), enter
(toupper
($1))) : enter
($1); }
162 { $$
= (iflag
&& iswalpha
(lyylval
)) ?
163 node
(OR
, mchar
(towlower
(lyylval
)), mchar
(towupper
(lyylval
))) :
172 { $$
= cclenter
(CCL
); }
174 { $$
= cclenter
(NCCL
); }
182 { $$
= node
(OR
, $1, $3); }
184 { $$
= node
(CAT
, $1, $2); }
186 { $$
= unary
(STAR
, $1); }
188 { $$
= unary
(PLUS
, $1); }
190 { $$
= unary
(QUEST
, $1); }
197 void add
(int *, int);
199 void execute
(char *);
208 fprintf
(stderr
, "egrep: %s\n", s
);
216 int cclcnt
, x
, ccount
, oldccount
;
227 case
'|': return
(OR
);
228 case
'*': return
(STAR
);
229 case
'+': return
(PLUS
);
230 case
'?': return
(QUEST
);
231 case
'(': return
(c
);
232 case
')': return
(c
);
233 case
'.': return
(DOT
);
234 case
'\0': return
(0);
235 case RIGHT
: return
(OR
);
237 x
= (multibyte ? MCCL
: CCL
);
240 if
((c
= nextch
()) == '^') {
241 x
= (multibyte ? NMCCL
: NCCL
);
246 if
(iflag
&& iswalpha
(c
))
248 if
(c
== '\0') synerror
();
249 if
(c
== '-' && cclcnt
> 0 && lc
!= 0) {
250 if
((c
= nextch
()) != 0) {
252 chars
[nxtchar
++] = '-';
256 if
(iflag
&& iswalpha
(c
))
259 (c
& WCHAR_CSMASK
) == (lc
& WCHAR_CSMASK
) &&
261 !iswcntrl
(c
) && !iswcntrl
(lc
)) {
262 if
(nxtchar
>= maxclin
)
263 if
(allocchars
() == 0)
265 chars
[nxtchar
++] = '-';
270 ccount
= oldccount
= nxtchar
;
271 if
(ccount
+ MB_LEN_MAX
>= maxclin
)
272 if
(allocchars
() == 0)
274 ccount
+= wctomb
(&chars
[ccount
], c
);
275 cclcnt
+= ccount
- oldccount
;
276 nxtchar
+= ccount
- oldccount
;
278 } while
((c
= nextch
()) != ']');
279 chars
[count
] = cclcnt
;
283 if
((c
= nextch
()) == '\0') synerror
();
300 char multic
[MB_LEN_MAX
];
303 if
((length
= _mbftowc
(multic
, &lc
, mgetc
, &d
)) < 0)
309 if
((length
= mbtowc
(&lc
, input
, MB_LEN_MAX
)) == -1)
321 return
(getc
(expfile
));
327 fprintf
(stderr
, gettext
("egrep: syntax error\n"));
348 right
[linno
] = count
;
353 node
(int x
, int l
, int r
)
383 if
((chars
= realloc
(chars
, maxclin
)) == (char *)0)
392 if
((name
= (int *)realloc
(name
, maxlin
*sizeof
(int))) == (int *)0)
394 if
((left
= (int *)realloc
(left
, maxlin
*sizeof
(int))) == (int *)0)
396 if
((right
= (int *)realloc
(right
, maxlin
*sizeof
(int))) == (int *)0)
398 if
((parent
= (int *)realloc
(parent
, maxlin
*sizeof
(int))) == (int *)0)
400 if
((foll
= (int *)realloc
(foll
, maxlin
*sizeof
(int))) == (int *)0)
402 if
((tmpstat
= (int *)realloc
(tmpstat
, maxlin
*sizeof
(int))) == (int *)0)
404 if
((initstat
= (int *)realloc
(initstat
, maxlin
*sizeof
(int))) == (int *)0)
412 fprintf
(stderr
, gettext
("egrep: regular expression too long\n"));
422 for
(i
=1; i
<=line
; i
++) tmpstat
[i
] = 0;
426 else if
(right
[v
] == 0) cfoll
(left
[v
]);
439 for
(i
=3; i
<=line
; i
++) tmpstat
[i
] = 0;
440 if
(cstate
(line
-1)==0) {
445 for
(i
=3; i
<=line
; i
++) initstat
[i
] = tmpstat
[i
];
446 count
--; /*leave out position 1 */
450 istat
= nxtst
(1, LEFT
);
457 int pos
, curpos
, number
, newpos
;
458 num
= positions
[state
[s
]];
460 for
(i
=3; i
<=line
; i
++) tmpstat
[i
] = initstat
[i
];
462 for
(i
=0; i
<num
; i
++) {
463 curpos
= positions
[pos
];
468 ||
(k
== DOT
&& dot
(c
))
469 ||
(k
== MDOT
&& mdot
(c
))
470 ||
(k
== CCL
&& dot
(c
) && member
(c
, right
[curpos
], 1))
471 ||
(k
== NCCL
&& dot
(c
) && member
(c
, right
[curpos
], 0))
472 ||
(k
== MCCL
&& mdot
(c
) && member
(c
, right
[curpos
], 1))
474 number
= positions
[foll
[curpos
]];
475 newpos
= foll
[curpos
] + 1;
476 for
(k
=0; k
<number
; k
++) {
477 if
(tmpstat
[positions
[newpos
]] != 1) {
478 tmpstat
[positions
[newpos
]] = 1;
487 if
(++nstate
>= NSTATES
) {
488 for
(i
=1; i
<NSTATES
; i
++)
490 for
(i
=1; i
<NSTATES
; i
++)
491 for
(k
=0; k
<NCHARS
; k
++)
497 if
(tmpstat
[line
] == 1) out
[nstate
] = 1;
501 if
(tmpstat
[line
] == 1) out
[nstate
] = 1;
502 gotofn
[s
][c
] = nstate
;
506 gotofn
[s
][c
] = xstate
;
517 if
(tmpstat
[v
] != 1) {
523 else if
(right
[v
] == 0) {
524 if
(cstate
(left
[v
]) == 0) return
(0);
525 else if
(name
[v
] == PLUS
) return
(1);
528 else if
(name
[v
] == CAT
) {
529 if
(cstate
(left
[v
]) == 0 && cstate
(right
[v
]) == 0) return
(0);
532 else
{ /* name[v] == OR */
533 b
= cstate
(right
[v
]);
534 if
(cstate
(left
[v
]) == 0 || b
== 0) return
(0);
543 if
(multibyte
&& c
>= 0200 && (!iscntrl
(c
) || c
== SS2
&& eucw2 || c
== SS3
&& eucw3
))
545 if
(c
== RIGHT || c
== LEFT
)
553 if
(c
>= 0200 && !iscntrl
(c
))
559 member
(int symb
, int set
, int torf
)
561 int i
, num
, pos
, c
, lc
;
562 if
(symb
== RIGHT || symb
== LEFT
)
568 symb
= tolower
(symb
);
569 for
(i
=0; i
<num
; i
++) {
570 c
= (unsigned char)chars
[pos
++];
571 if
(c
== '-' && lc
!= 0 && ++i
< num
) {
572 c
= (unsigned char)chars
[pos
++];
573 if
(lc
<= symb
&& symb
<= c
)
587 for
(i
=1; i
<=n
; i
++) {
588 if
(positions
[state
[i
]] == count
) {
590 for
(j
=0; j
< count
; j
++)
591 if
(tmpstat
[positions
[pos
++]] != 1) goto nxt
;
601 add
(int *array
, int n
)
604 if
(nxtpos
+ count
>= maxpos
) {
605 maxpos
+= MAXPOS
+ count
;
606 if
((positions
= (int *)realloc
(positions
, maxpos
*sizeof
(int))) == (int *)0)
610 positions
[nxtpos
++] = count
;
611 for
(i
=3; i
<= line
; i
++) {
612 if
(tmpstat
[i
] == 1) {
613 positions
[nxtpos
++] = i
;
622 if
(v
== line
) return
;
626 case PLUS
: cstate
(v
);
631 case QUEST
: follow
(p
);
634 case CAT
: if
(v
== left
[p
]) {
635 if
(cstate
(right
[p
]) == 0) {
642 case FINAL
: if
(tmpstat
[line
] != 1) {
650 #define USAGE "[ -bchHilnsqv ] [ -e exp ] [ -f file ] [ strings ] [ file ] ..."
653 main
(int argc
, char **argv
)
659 (void)setlocale
(LC_ALL
, "");
661 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
662 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't. */
664 (void) textdomain
(TEXT_DOMAIN
);
666 while
((c
= getopt
(argc
, argv
, "ybcie:f:Hhlnvsq")) != -1)
684 expfile
= fopen
(optarg
, "r");
685 if
(expfile
== NULL
) {
687 gettext
("egrep: can't open %s\n"), optarg
);
693 if
(!lflag
) /* H is excluded by l as in GNU grep */
695 hflag
= 0; /* H excludes h */
700 Hflag
= 0; /* h excludes H */
710 Hflag
= 0; /* l excludes H */
718 case
's': /* Solaris: legacy option */
729 if
(errflag ||
((argc
<= 0) && !fflag
&& !eflag
)) {
730 fprintf
(stderr
, gettext
("usage: egrep %s\n"), gettext
(USAGE
));
733 if
(!eflag
&& !fflag
) {
734 input
= argv
[optind
];
739 argv
= &argv
[optind
];
741 /* allocate initial space for arrays */
742 if
((name
= (int *)malloc
(MAXLIN
*sizeof
(int))) == (int *)0)
744 if
((left
= (int *)malloc
(MAXLIN
*sizeof
(int))) == (int *)0)
746 if
((right
= (int *)malloc
(MAXLIN
*sizeof
(int))) == (int *)0)
748 if
((parent
= (int *)malloc
(MAXLIN
*sizeof
(int))) == (int *)0)
750 if
((foll
= (int *)malloc
(MAXLIN
*sizeof
(int))) == (int *)0)
752 if
((tmpstat
= (int *)malloc
(MAXLIN
*sizeof
(int))) == (int *)0)
754 if
((initstat
= (int *)malloc
(MAXLIN
*sizeof
(int))) == (int *)0)
756 if
((chars
= (char *)malloc
(MAXLIN
)) == (char *)0)
758 if
((lower
= (wchar_t *)malloc
(MAXLIN
*sizeof
(wchar_t))) == (wchar_t *)0)
760 if
((upper
= (wchar_t *)malloc
(MAXLIN
*sizeof
(wchar_t))) == (wchar_t *)0)
762 if
((positions
= (int *)malloc
(MAXPOS
*sizeof
(int))) == (int *)0)
777 else while
(--argc
>= 0) {
778 if
(reinit
== 1) clearg
();
781 return
(badbotch ?
2 : nsucc
==0);
795 char *ptr
, *ptrend
, *lastptr
;
802 if
((buf
= malloc
(lBufSiz
+ EBUFSIZ
)) == NULL
) {
803 exit
(2); /* out of memory - BAIL */
807 if
((f
= fopen
(file
, "r")) == NULL
) {
809 gettext
("egrep: can't open %s\n"), file
);
815 file
= STDIN_FILENAME
;
819 if
((count
= read
(fileno
(f
), buf
, EBUFSIZ
)) <= 0) {
822 if
(cflag
&& !qflag
) {
823 if
(Hflag ||
(nfile
> 1 && !hflag
))
824 fprintf
(stdout
, "%s:", file
);
825 fprintf
(stdout
, "%lld\n", tln
);
833 if
((ptrend
= memchr
(ptr
, '\n', buf
+ count
- ptr
)) == NULL
) {
835 move the unused partial record to the head of the buffer
838 count
= buf
+ count
- ptr
;
839 memmove
(buf
, ptr
, count
);
844 Get a bigger buffer if this one is full
846 if
(count
> lBufSiz
) {
851 if
((buf
= realloc
(buf
, lBufSiz
+ EBUFSIZ
)) == NULL
) {
852 exit
(2); /* out of memory - BAIL */
859 if
((count1
= read
(fileno
(f
), p
, EBUFSIZ
)) > 0) {
864 ptrend
= ptr
+ count
;
875 if
(multibyte
&& p
> ptr
) {
881 length
= mbtowc
(&wchar
, p
, MB_LEN_MAX
);
892 length
= mbtowc
(&wchar
, lastptr
, MB_LEN_MAX
);
903 c
= (unsigned char)*p
++;
904 if
((t
= gotofn
[cstat
][c
]) == 0)
905 cstat
= nxtst
(cstat
, c
);
919 if
(lflag || qflag
) {
921 (void) printf
("%s\n", file
);
928 if
(Hflag ||
(nfile
> 1 && !hflag
))
931 nchars
= blkno
- (buf
+ count
- ptrend
) - 2;
934 printf
("%lld:", nchars
/BLKSIZE
);
937 printf
("%lld:", lnum
);
939 nchars
= ptrend
- ptr
+ 1;
941 nchars
= ptrend
- ptr
;
942 fwrite
(ptr
, (size_t)1, (size_t)nchars
, stdout
);
948 if
(ptr
>= buf
+ count
) {
950 if
((count
= read
(fileno
(f
), buf
, EBUFSIZ
)) <= 0)
959 if
(cflag
&& !qflag
) {
960 if
(Hflag ||
(nfile
> 1 && !hflag
))
962 printf
("%lld\n", tln
);
970 for
(i
=1; i
<=nstate
; i
++)
972 for
(i
=1; i
<=nstate
; i
++)
973 for
(k
=0; k
<NCHARS
; k
++)
979 for
(i
=3; i
<=line
; i
++) tmpstat
[i
] = 0;
980 if
(cstate
(line
-1)==0) {
985 for
(i
=3; i
<=line
; i
++) initstat
[i
] = tmpstat
[i
];
986 count
--; /*leave out position 1 */
990 istat
= nxtst
(1, LEFT
);
999 for
(i
= 1; i
< (int) eucw1
; i
++)
1000 x2
= node
(CAT
, x2
, enter
(MDOT
));
1001 x1
= node
(OR
, x1
, x2
);
1004 for
(i
= 1; i
<= (int) eucw2
; i
++)
1005 x2
= node
(CAT
, x2
, enter
(MDOT
));
1006 x1
= node
(OR
, x1
, x2
);
1010 for
(i
= 1; i
<= (int) eucw3
; i
++)
1011 x2
= node
(CAT
, x2
, enter
(MDOT
));
1012 x1
= node
(OR
, x1
, x2
);
1020 char multichar
[MB_LEN_MAX
+1];
1024 length
= wctomb
(multichar
, c
);
1026 *(p
+ length
) = '\0';
1027 x1
= enter
((unsigned char)*p
++);
1028 while
(lc
= (unsigned char)*p
++)
1029 x1
= node
(CAT
, x1
, enter
(lc
));
1037 char multic1
[MB_LEN_MAX
];
1038 char multic2
[MB_LEN_MAX
];
1039 int x1
, x2
, length
, current
, last
, cclcnt
;
1042 last
= genrange
(type
);
1043 nxtchar
= count
+ 1;
1045 /* create usual character class for single byte characters */
1046 while
(current
<= last
&& (isascii
(c
= lower
[current
]) || c
<= 0377 && iscntrl
(c
))) {
1048 chars
[nxtchar
++] = c
;
1049 if
(lower
[current
] != upper
[current
]) {
1050 chars
[nxtchar
++] = '-';
1051 chars
[nxtchar
++] = upper
[current
];
1058 chars
[count
] = cclcnt
;
1062 /* single byte part of character class */
1063 x2
= cclenter
(type
);
1064 else if
(type
== NCCL
)
1065 /* all single byte characters match */
1067 while
(current
<= last
) {
1068 if
(upper
[current
] == lower
[current
])
1069 x1
= mchar
(lower
[current
]);
1071 length
= wctomb
(multic1
, lower
[current
]);
1072 wctomb
(multic2
, upper
[current
]);
1073 x1
= range
((unsigned char *)multic1
,
1074 (unsigned char *)multic2
, length
);
1077 x2
= node
(OR
, x2
, x1
);
1086 range
(unsigned char *p1
, unsigned char *p2
, int length
)
1088 char multic
[MB_LEN_MAX
+1];
1092 return
(classenter
(*p1
, *p2
));
1094 return
(node
(CAT
, enter
(p1
[0]), range
(p1
+1, p2
+1, length
- 1)));
1096 for
(i
= 1; i
< length
; i
++)
1098 x1
= node
(CAT
, enter
(p1
[0]),
1099 range
(p1
+1, (unsigned char *)multic
, length
- 1));
1100 if
((unsigned char)(p1
[0] + 1) < p2
[0]) {
1101 x2
= classenter
(p1
[0] + 1, p2
[0] - 1);
1102 for
(i
= 1; i
< length
; i
++)
1103 x2
= node
(CAT
, x2
, enter
(MDOT
));
1104 x1
= node
(OR
, x1
, x2
);
1107 for
(i
= 1; i
< length
; i
++)
1109 x2
= node
(CAT
, enter
(p2
[0]),
1110 range
((unsigned char *)multic
, p2
+1, length
- 1));
1111 return node
(OR
, x1
, x2
);
1115 classenter
(int x1
, int x2
)
1117 static int max
, min
;
1120 for
(i
= 0200; i
<= 0377; i
++)
1124 for
(i
= 0377; i
>= 0200; i
--)
1129 if
(x1
<= min
&& x2
>= max
)
1131 if
(nxtchar
+ 4 >= maxclin
)
1132 if
(allocchars
() == 0)
1135 chars
[nxtchar
++] = x1
;
1136 chars
[nxtchar
++] = '-';
1137 chars
[nxtchar
++] = x2
;
1139 return cclenter
(MCCL
);
1146 int current
, nel
, i
, last
, length
;
1150 p
= &chars
[count
+1];
1151 endp
= &chars
[count
+1] + chars
[count
];
1154 /* convert character class into union of ranges */
1156 length
= mbtowc
(&c
, p
, MB_LEN_MAX
);
1158 if
(c
== '-' && lc
!= 0) {
1159 length
= mbtowc
(&c
, p
, MB_LEN_MAX
);
1160 upper
[current
-1] = c
;
1164 upper
[current
++] = c
;
1169 /* sort lower and upper bounds of ranges */
1170 qsort
((char *)lower
, nel
, sizeof
(wchar_t), compare
);
1171 qsort
((char *)upper
, nel
, sizeof
(wchar_t), compare
);
1174 /* combine overlapping or adjacent ranges */
1175 for
(i
= 0; i
< last
; i
++)
1176 if
(upper
[i
] >= lower
[i
+1] - 1)
1177 upper
[current
] = upper
[i
+1];
1179 lower
[++current
] = lower
[i
+1];
1180 upper
[current
] = upper
[i
+1];
1183 /* find complement of character class */
1186 while
(i
<= current
&& isascii
(c
=lower
[i
]) || c
<= 0377 && iscntrl
(c
))
1189 /* match all multibyte characters */
1191 lower
[i
] = maxmin
(WCHAR_CS2
, 0);
1192 upper
[i
++] = maxmin
(WCHAR_CS2
, 1);
1195 lower
[i
] = maxmin
(WCHAR_CS3
, 0);
1196 upper
[i
++] = maxmin
(WCHAR_CS3
, 1);
1198 lower
[i
] = maxmin
(WCHAR_CS1
, 0);
1199 upper
[i
++] = maxmin
(WCHAR_CS1
, 1);
1203 if
(next
+ current
+ 2 >= maxwclin
) {
1204 maxwclin
+= MAXLIN
+ next
+ current
+ 2;
1205 if
((lower
= (wchar_t *)realloc
(lower
, maxwclin
*sizeof
(wchar_t))) == (wchar_t *)0 ||
1206 (upper
= (wchar_t *)realloc
(upper
, maxwclin
* sizeof
(wchar_t))) == (wchar_t *)0)
1209 if
(eucw2
&& lower
[i
] > maxmin
(WCHAR_CS2
, 0)) {
1210 lower
[next
] = maxmin
(WCHAR_CS2
, 0);
1211 if
((lower
[i
] & WCHAR_CSMASK
) != WCHAR_CS2
) {
1212 upper
[next
++] = maxmin
(WCHAR_CS2
, 1);
1213 if
((lower
[i
] & WCHAR_CSMASK
) == WCHAR_CS1
&& eucw3
) {
1214 lower
[next
] = maxmin
(WCHAR_CS3
, 0);
1215 upper
[next
++] = maxmin
(WCHAR_CS3
, 1);
1217 if
(lower
[i
] > maxmin
(lower
[i
] & WCHAR_CSMASK
, 0)) {
1218 lower
[next
] = maxmin
(lower
[i
] & WCHAR_CSMASK
, 0);
1219 upper
[next
++] = lower
[i
] - 1;
1222 upper
[next
++] = lower
[i
] - 1;
1223 } else if
(lower
[i
] > maxmin
(lower
[i
] & WCHAR_CSMASK
, 0)) {
1224 lower
[next
] = maxmin
(lower
[i
] & WCHAR_CSMASK
, 0);
1225 upper
[next
++] = lower
[i
] - 1;
1227 for
(j
= i
; j
< current
; j
++) {
1228 if
(upper
[j
] < maxmin
(upper
[j
] & WCHAR_CSMASK
, 1)) {
1229 lower
[next
] = upper
[j
] + 1;
1230 if
((upper
[j
] & WCHAR_CSMASK
) != (lower
[j
+1] & WCHAR_CSMASK
)) {
1231 upper
[next
++] = maxmin
(upper
[j
] & WCHAR_CSMASK
, 1);
1232 if
(eucw3
&& (upper
[j
] & WCHAR_CSMASK
) == WCHAR_CS2
&& (lower
[j
+1] & WCHAR_CSMASK
) == WCHAR_CS1
) {
1233 lower
[next
] = maxmin
(WCHAR_CS3
, 0);
1234 upper
[next
++] = maxmin
(WCHAR_CS3
, 1);
1236 if
(lower
[j
+1] > maxmin
(lower
[j
+1] & WCHAR_CSMASK
, 0)) {
1237 lower
[next
] = maxmin
(lower
[j
+1] & WCHAR_CSMASK
, 0);
1238 upper
[next
++] = lower
[j
+1] - 1;
1241 upper
[next
++] = lower
[j
+1] - 1;
1242 } else if
(lower
[j
+1] > maxmin
(lower
[j
+1], 0)) {
1243 lower
[next
] = maxmin
(lower
[j
+1], 0);
1244 upper
[next
++] = lower
[j
+1] - 1;
1247 if
(upper
[current
] < maxmin
(upper
[current
] & WCHAR_CSMASK
, 1)) {
1248 lower
[next
] = upper
[current
] + 1;
1249 upper
[next
++] = maxmin
(upper
[current
] & WCHAR_CSMASK
, 1);
1251 if
((upper
[current
] & WCHAR_CSMASK
) != WCHAR_CS1
) {
1252 if
((upper
[current
] & WCHAR_CSMASK
) == WCHAR_CS2
&& eucw3
) {
1253 lower
[next
] = maxmin
(WCHAR_CS3
, 0);
1254 upper
[next
++] = maxmin
(WCHAR_CS3
, 1);
1256 lower
[next
] = maxmin
(WCHAR_CS1
, 0);
1257 upper
[next
++] = maxmin
(WCHAR_CS1
, 1);
1259 for
(j
= current
+ 1; j
< next
; j
++) {
1260 lower
[i
] = lower
[j
];
1261 upper
[i
++] = upper
[j
];
1269 compare
(wchar_t *c
, wchar_t *d
)
1279 maxmin
(wchar_t c
, int flag
)
1281 static wchar_t minmax1
[2], minmax2
[2], minmax3
[2];
1284 /* compute min and max process codes for all code sets */
1286 char multic
[MB_LEN_MAX
], minmax
[2];
1287 for
(i
= 0377; i
>= 0200; i
--)
1291 for
(i
= 0240; i
<= 0377; i
++)
1295 for
(i
= 0; i
<= 1; i
++) {
1296 length
= MB_LEN_MAX
;
1298 multic
[length
] = minmax
[i
];
1299 mbtowc
(&minmax1
[i
], multic
, MB_LEN_MAX
);
1302 mbtowc
(&minmax2
[i
], multic
, MB_LEN_MAX
);
1306 mbtowc
(&minmax3
[i
], multic
, MB_LEN_MAX
);
1311 case WCHAR_CS1
: return minmax1
[flag
];
1312 case WCHAR_CS2
: return minmax2
[flag
];
1313 case WCHAR_CS3
: return minmax3
[flag
];