/[gentoo-alt]/trunk/sys-apps/gawk/files/gawk-3.1.4-uplow.patch
Gentoo

Contents of /trunk/sys-apps/gawk/files/gawk-3.1.4-uplow.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 242 - (show annotations) (download)
Sun Feb 27 23:26:00 2005 UTC (9 years, 5 months ago) by angusyoung
File size: 5636 byte(s)
Bumped gawk from 3.1.4 to 3.1.4-r4

1 Ripped from Fedora.
2
3 --- gawk-3.1.4/builtin.c.uplow 2004-11-09 15:53:03.357118488 +0100
4 +++ gawk-3.1.4/builtin.c 2004-11-09 15:55:25.455516248 +0100
5 @@ -1652,51 +1652,116 @@
6 fflush(rp->fp);
7 }
8
9 +/* wide_tolower_toupper --- lower- or uppercase a multibute string */
10 +
11 +typedef int (*isw_func)(wint_t);
12 +typedef wint_t (*tow_func)(wint_t);
13 +
14 +static NODE *
15 +wide_tolower_toupper(NODE *t1, isw_func iswu, tow_func towl)
16 +{
17 +#ifdef MBS_SUPPORT
18 + register unsigned char *cp, *cpe;
19 + register unsigned char *cp2;
20 + size_t mbclen;
21 + mbstate_t mbs, prev_mbs;
22 + wchar_t wc;
23 + NODE *t2;
24 + /*
25 + * Since the lowercase char and its uppercase equivalent may occupy
26 + * different number of bytes (Turkish `i'), we cannot say the length
27 + * of the output string.
28 + * This approach is adapted from format_tree().
29 + */
30 + unsigned char *obuf;
31 + size_t osiz, ofre;
32 +
33 + /*
34 + * Better 2 spare bytes than 1, consistently with make_str_node().
35 + * And we need gawk_mb_cur_max free bytes before we convert the last
36 + * char, so we add (gawk_mb_cur_max - 1).
37 + */
38 + osiz = t1->stlen + 2 + (gawk_mb_cur_max - 1);
39 + ofre = osiz - 2;
40 + emalloc(obuf, char *, osiz, "wide_tolower_toupper");
41 +
42 + memset(&mbs, 0, sizeof(mbstate_t));
43 + cp = (unsigned char *)t1->stptr;
44 + cpe = (unsigned char *)(t1->stptr + t1->stlen);
45 + cp2 = obuf;
46 + while (cp < cpe) {
47 + if (ofre < gawk_mb_cur_max) {
48 + size_t olen = cp2 - obuf;
49 + ofre += osiz;
50 + osiz *= 2;
51 + erealloc(obuf, char *, osiz, "wide_tolower_toupper");
52 + cp2 = obuf + olen;
53 + }
54 + prev_mbs = mbs;
55 + mbclen = (size_t) mbrtowc(&wc, (char *) cp, cpe - cp,
56 + &mbs);
57 + if (mbclen == 0 || mbclen == (size_t) -1 || mbclen == (size_t) -2) {
58 + /* Null wide char, or a problem appeared. */
59 + *cp2++ = *cp++;
60 + ofre--;
61 + continue;
62 + }
63 +
64 + /* If the character doesn't need change, copy it. */
65 + if (!(*iswu)(wc)) {
66 + ofre -= mbclen;
67 + while (mbclen--)
68 + *cp2++ = *cp++;
69 + continue;
70 + }
71 +
72 + /* Increment the input pointer. */
73 + cp += mbclen;
74 +
75 + /* Write the modified wide character. */
76 + mbclen = wcrtomb((char *) cp2, (*towl)(wc), &prev_mbs);
77 +
78 + if (mbclen > 0 && mbclen < (size_t) -2) {
79 + /* Increment the output pointer. */
80 + cp2 += mbclen;
81 + ofre -= mbclen;
82 + } else {
83 + /* A problem appeared. */
84 + cp2++;
85 + ofre--;
86 + }
87 + }
88 + t2 = make_str_node(obuf, cp2 - obuf, ALREADY_MALLOCED);
89 + t2->flags |= TEMP;
90 + return t2;
91 +#else
92 + cant_happen();
93 + return NULL;
94 +#endif
95 +}
96 +
97 /* do_tolower --- lower case a string */
98
99 NODE *
100 do_tolower(NODE *tree)
101 {
102 NODE *t1, *t2;
103 - register unsigned char *cp, *cp2;
104 -#ifdef MBS_SUPPORT
105 - size_t mbclen = 0;
106 - mbstate_t mbs, prev_mbs;
107 - if (gawk_mb_cur_max > 1)
108 - memset(&mbs, 0, sizeof(mbstate_t));
109 -#endif
110
111 t1 = tree_eval(tree->lnode);
112 if (do_lint && (t1->flags & (STRING|STRCUR)) == 0)
113 lintwarn(_("tolower: received non-string argument"));
114 t1 = force_string(t1);
115 - t2 = tmp_string(t1->stptr, t1->stlen);
116 - for (cp = (unsigned char *)t2->stptr,
117 - cp2 = (unsigned char *)(t2->stptr + t2->stlen); cp < cp2; cp++)
118 -#ifdef MBS_SUPPORT
119 - if (gawk_mb_cur_max > 1) {
120 - wchar_t wc;
121 - prev_mbs = mbs;
122 - mbclen = (size_t) mbrtowc(&wc, (char *) cp, cp2 - cp,
123 - &mbs);
124 - if ((mbclen != 1) && (mbclen != (size_t) -1) &&
125 - (mbclen != (size_t) -2) && (mbclen != 0)) {
126 - /* a multibyte character. */
127 - if (iswupper(wc)) {
128 - wc = towlower(wc);
129 - wcrtomb((char *) cp, wc, &prev_mbs);
130 - }
131 - /* Adjust the pointer. */
132 - cp += mbclen - 1;
133 - } else {
134 - /* Otherwise we treat it as a singlebyte character. */
135 - if (ISUPPER(*cp))
136 - *cp = tolower(*cp);
137 - }
138 - } else
139 -#endif
140 - if (ISUPPER(*cp))
141 - *cp = TOLOWER(*cp);
142 +
143 + if (gawk_mb_cur_max > 1)
144 + t2 = wide_tolower_toupper(t1, &iswupper, &towlower);
145 + else {
146 + register unsigned char *cp, *cpe;
147 + t2 = tmp_string(t1->stptr, t1->stlen);
148 + for (cp = (unsigned char *)t2->stptr,
149 + cpe = (unsigned char *)(t2->stptr + t2->stlen); cp < cpe; cp++)
150 + if (ISUPPER(*cp))
151 + *cp = TOLOWER(*cp);
152 + }
153 free_temp(t1);
154 return t2;
155 }
156 @@ -1707,45 +1772,22 @@
157 do_toupper(NODE *tree)
158 {
159 NODE *t1, *t2;
160 - register unsigned char *cp, *cp2;
161 -#ifdef MBS_SUPPORT
162 - size_t mbclen = 0;
163 - mbstate_t mbs, prev_mbs;
164 - if (gawk_mb_cur_max > 1)
165 - memset(&mbs, 0, sizeof(mbstate_t));
166 -#endif
167
168 t1 = tree_eval(tree->lnode);
169 if (do_lint && (t1->flags & (STRING|STRCUR)) == 0)
170 lintwarn(_("toupper: received non-string argument"));
171 t1 = force_string(t1);
172 - t2 = tmp_string(t1->stptr, t1->stlen);
173 - for (cp = (unsigned char *)t2->stptr,
174 - cp2 = (unsigned char *)(t2->stptr + t2->stlen); cp < cp2; cp++)
175 -#ifdef MBS_SUPPORT
176 - if (gawk_mb_cur_max > 1) {
177 - wchar_t wc;
178 - prev_mbs = mbs;
179 - mbclen = (size_t) mbrtowc(&wc, (char *) cp, cp2 - cp,
180 - &mbs);
181 - if ((mbclen != 1) && (mbclen != (size_t) -1) &&
182 - (mbclen != (size_t) -2) && (mbclen != 0)) {
183 - /* a multibyte character. */
184 - if (iswlower(wc)) {
185 - wc = towupper(wc);
186 - wcrtomb((char *) cp, wc, &prev_mbs);
187 - }
188 - /* Adjust the pointer. */
189 - cp += mbclen - 1;
190 - } else {
191 - /* Otherwise we treat it as a singlebyte character. */
192 - if (ISLOWER(*cp))
193 - *cp = toupper(*cp);
194 - }
195 - } else
196 -#endif
197 - if (ISLOWER(*cp))
198 - *cp = TOUPPER(*cp);
199 +
200 + if (gawk_mb_cur_max > 1)
201 + t2 = wide_tolower_toupper(t1, &iswlower, &towupper);
202 + else {
203 + register unsigned char *cp, *cpe;
204 + t2 = tmp_string(t1->stptr, t1->stlen);
205 + for (cp = (unsigned char *)t2->stptr,
206 + cpe = (unsigned char *)(t2->stptr + t2->stlen); cp < cpe; cp++)
207 + if (ISLOWER(*cp))
208 + *cp = TOUPPER(*cp);
209 + }
210 free_temp(t1);
211 return t2;
212 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20