summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1997-11-06 14:37:34 +0000
committerJim Meyering <jim@meyering.net>1997-11-06 14:37:34 +0000
commita313a7d147cb0c098982762d724715db3b2e931e (patch)
tree7497ff47aeaaefeac95a94291e92c5bb87e692ef
parenta8da87911ca012a74ac96eb9be69028163f4adbc (diff)
downloadcoreutils-a313a7d147cb0c098982762d724715db3b2e931e.tar.xz
(getmonth): Remove HAVE_ALLOCA #ifdefs.
We always have alloca. (keycompare): Don't use variable size arrays (it's a gcc-extension). Rewrite code that increments new lengths when not `ignoring'.
-rw-r--r--src/sort.c54
1 files changed, 28 insertions, 26 deletions
diff --git a/src/sort.c b/src/sort.c
index add9779d0..70b970ae9 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -1467,12 +1467,7 @@ getmonth (const char *s, int len)
if (len == 0)
return 0;
-#ifdef HAVE_ALLOCA
month = (char *) alloca (len + 1);
-#else
- month = (char *) malloc (len + 1);
-#endif
-
for (i = 0; i < len; ++i)
month[i] = fold_toupper[UCHAR (s[i])];
while (blanks[UCHAR (month[i - 1])])
@@ -1493,10 +1488,6 @@ getmonth (const char *s, int len)
result = (!strncmp (month, monthtab[lo].name, len) ? monthtab[lo].val : 0);
-#ifndef HAVE_ALLOCA
- free (month);
-#endif
-
return result;
}
@@ -1656,32 +1647,43 @@ keycompare (const struct line *a, const struct line *b)
can select a faster sort that is similar to ascii sort */
else if (need_locale)
{
- /* FIXME: rewrite not to use variable size arrays */
- unsigned char copy_a[lena + 1], copy_b[lenb + 1];
- int la, lb, i;
-
- /* We can't use strcoll directly on the two strings, but rather must
- extract the text for the key and do the proper 'ignore' and
- 'translate' before comparing. */
- for (la = lb = i = 0; i < max (lena, lenb); i++)
+ /* FIXME: consider making parameters non-const, then when
+ both ignore and translate are NULL (which should be most
+ of the time) we could temporarily NUL-terminate them in
+ place and avoid the copy. */
+
+ unsigned char *copy_a = (unsigned char *) alloca (lena + 1);
+ unsigned char *copy_b = (unsigned char *) alloca (lenb + 1);
+ int new_len_a, new_len_b, i;
+
+ /* We can't use strcoll directly on the two strings,
+ but rather must extract the text for the key
+ (to NUL-terminate for strcoll) and handle any
+ 'ignore' and/or 'translate' before comparing. */
+ for (new_len_a = new_len_b = i = 0; i < max (lena, lenb); i++)
{
if (i < lena)
{
- copy_a[la] = translate ? translate[UCHAR (texta[i])] : texta
- [i];
- la = ignore ? (ignore[UCHAR (texta[i])] ? la : la + 1) : la
- + 1;
+ copy_a[new_len_a] = (translate
+ ? translate[UCHAR (texta[i])]
+ : texta[i]);
+ if (!ignore || !ignore[UCHAR (texta[i])])
+ ++new_len_a;
}
if (i < lenb)
{
- copy_b[lb] = translate ? translate[UCHAR (textb[i])] : textb
- [i];
- lb = ignore ? (ignore[UCHAR (textb[i])] ? lb : lb + 1) : lb
- + 1;
+ copy_b[new_len_b] = (translate
+ ? translate[UCHAR (textb[i])]
+ : textb [i]);
+ if (!ignore || !ignore[UCHAR (textb[i])])
+ ++new_len_b;
}
}
- copy_a[la] = copy_b[lb] = 0;
+
+ copy_a[new_len_a] = copy_b[new_len_b] = 0;
+
diff = strcoll (copy_a, copy_b);
+
if (diff)
return key->reverse ? -diff : diff;
continue;