mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-08-15 14:39:26 +02:00
sort changes from Mike
This commit is contained in:
@@ -9,6 +9,26 @@ Mon Mar 29 21:27:56 1993 Jim Meyering (meyering@comco.com)
|
||||
* cut.c, expand.c, join.c, nl.c: Always call error with errno
|
||||
(not zero) after failed fclose or non-zero ferror.
|
||||
|
||||
Sun Mar 28 16:59:31 1993 Mike Haertel (mike@cs.uoregon.edu)
|
||||
|
||||
* configure.in: Add check for working memcmp; use GNU's if
|
||||
the system's doesn't grok the 8th bit.
|
||||
* memcmp.c: Fix it so it groks the 8th bit.
|
||||
TODO: We really need to provide a fast memcmp, since most
|
||||
machines will have a broken memcmp. Probably should get
|
||||
the one from glibc.
|
||||
* sort.c (mergefps): Maintain keybeg and keylim when copying
|
||||
the current line to `saved'.
|
||||
(numcompare): Skip white space here since -n no longer implies -b.
|
||||
(getmonth): Skip white space here since -M no longer implies -b.
|
||||
(compare): Completely overhauled to make the 8th bit work right,
|
||||
also to properly handle the global reverse option.
|
||||
(set_ordering): -n no longer implies -b, according to Posix.
|
||||
For consistency, -M also no longer implies -b.
|
||||
(main): Correct treatment of -r and global keys.
|
||||
(findlines): Clear keybeg and keylim if no keys are used.
|
||||
(sort): Avoid overwriting tempfiles[] array bounds.
|
||||
|
||||
Sun Mar 21 22:29:29 1993 Jim Meyering (meyering@comco.com)
|
||||
|
||||
* pr.c (close_file): Reverse May 13, '92 change, but add the condition
|
||||
|
||||
+49
-26
@@ -554,6 +554,11 @@ findlines (buf, lines)
|
||||
lines->lines[lines->used].keybeg = beg;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lines->lines[lines->used].keybeg = 0;
|
||||
lines->lines[lines->used].keylim = 0;
|
||||
}
|
||||
|
||||
++lines->used;
|
||||
beg = ptr + 1;
|
||||
@@ -630,6 +635,11 @@ numcompare (a, b)
|
||||
|
||||
tmpa = UCHAR (*a), tmpb = UCHAR (*b);
|
||||
|
||||
while (blanks[tmpa])
|
||||
tmpa = UCHAR (*++a);
|
||||
while (blanks[tmpb])
|
||||
tmpb = UCHAR (*++b);
|
||||
|
||||
if (tmpa == '-')
|
||||
{
|
||||
tmpa = UCHAR (*++a);
|
||||
@@ -724,6 +734,9 @@ getmonth (s, len)
|
||||
char month[4];
|
||||
register int i, lo = 0, hi = 12;
|
||||
|
||||
while (len > 0 && blanks[UCHAR(*s)])
|
||||
++s, --len;
|
||||
|
||||
if (len < 3)
|
||||
return 0;
|
||||
|
||||
@@ -877,36 +890,34 @@ compare (a, b)
|
||||
{
|
||||
int diff, tmpa, tmpb, mini;
|
||||
|
||||
/* First try to compare on the specified keys (if any).
|
||||
The only two cases with no key at all are unadorned sort,
|
||||
and unadorned sort -r. */
|
||||
if (keyhead.next)
|
||||
{
|
||||
diff = keycompare (a, b);
|
||||
if (diff)
|
||||
if (diff != 0)
|
||||
return diff;
|
||||
if (!unique && !stable)
|
||||
{
|
||||
tmpa = a->length, tmpb = b->length;
|
||||
diff = memcmp (a->text, b->text, min (tmpa, tmpb));
|
||||
if (!diff)
|
||||
diff = tmpa - tmpb;
|
||||
}
|
||||
if (unique || stable)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* If the keys all compare equal (or no keys were specified)
|
||||
fall through to the default byte-by-byte comparison. */
|
||||
tmpa = a->length, tmpb = b->length;
|
||||
mini = min (tmpa, tmpb);
|
||||
if (mini == 0)
|
||||
diff = tmpa - tmpb;
|
||||
else
|
||||
{
|
||||
tmpa = a->length, tmpb = b->length;
|
||||
mini = min (tmpa, tmpb);
|
||||
if (mini == 0)
|
||||
diff = tmpa - tmpb;
|
||||
else
|
||||
{
|
||||
char *ap = a->text, *bp = b->text;
|
||||
char *ap = a->text, *bp = b->text;
|
||||
|
||||
diff = *ap - *bp;
|
||||
diff = UCHAR (*ap) - UCHAR (*bp);
|
||||
if (diff == 0)
|
||||
{
|
||||
diff = memcmp (ap, bp, mini);
|
||||
if (diff == 0)
|
||||
{
|
||||
diff = memcmp (ap, bp, mini);
|
||||
if (diff == 0)
|
||||
diff = tmpa - tmpb;
|
||||
}
|
||||
diff = tmpa - tmpb;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1069,6 +1080,18 @@ mergefps (fps, nfps, ofp)
|
||||
saved.length = lines[ord[0]].lines[cur[ord[0]]].length;
|
||||
bcopy (lines[ord[0]].lines[cur[ord[0]]].text, saved.text,
|
||||
saved.length + 1);
|
||||
if (lines[ord[0]].lines[cur[ord[0]]].keybeg != NULL)
|
||||
{
|
||||
saved.keybeg = saved.text +
|
||||
(lines[ord[0]].lines[cur[ord[0]]].keybeg
|
||||
- lines[ord[0]].lines[cur[ord[0]]].text);
|
||||
}
|
||||
if (lines[ord[0]].lines[cur[ord[0]]].keylim != NULL)
|
||||
{
|
||||
saved.keylim = saved.text +
|
||||
(lines[ord[0]].lines[cur[ord[0]]].keylim
|
||||
- lines[ord[0]].lines[cur[ord[0]]].text);
|
||||
}
|
||||
savedflag = 1;
|
||||
}
|
||||
}
|
||||
@@ -1308,7 +1331,7 @@ sort (files, nfiles, ofp)
|
||||
{
|
||||
tempfiles = (char **) xmalloc (ntemp * sizeof (char *));
|
||||
i = ntemp;
|
||||
for (node = temphead.next; node; node = node->next)
|
||||
for (node = temphead.next; i > 0; node = node->next)
|
||||
tempfiles[--i] = node->name;
|
||||
merge (tempfiles, ntemp, ofp);
|
||||
free ((char *) tempfiles);
|
||||
@@ -1392,10 +1415,10 @@ set_ordering (s, key, blanktype)
|
||||
key->ignore = nonprinting;
|
||||
break;
|
||||
case 'M':
|
||||
key->skipsblanks = key->skipeblanks = key->month = 1;
|
||||
key->month = 1;
|
||||
break;
|
||||
case 'n':
|
||||
key->skipsblanks = key->skipeblanks = key->numeric = 1;
|
||||
key->numeric = 1;
|
||||
break;
|
||||
case 'r':
|
||||
key->reverse = 1;
|
||||
@@ -1673,9 +1696,9 @@ main (argc, argv)
|
||||
}
|
||||
|
||||
if (!keyhead.next && (gkey.ignore || gkey.translate || gkey.skipsblanks
|
||||
|| gkey.reverse || gkey.skipeblanks
|
||||
|| gkey.month || gkey.numeric))
|
||||
|| gkey.skipeblanks || gkey.month || gkey.numeric))
|
||||
insertkey (&gkey);
|
||||
reverse = gkey.reverse;
|
||||
|
||||
if (nfiles == 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user