summaryrefslogtreecommitdiffstats
path: root/games/fortune/strfile
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1996-06-09 19:41:31 +0000
committerache <ache@FreeBSD.org>1996-06-09 19:41:31 +0000
commitf7458dfe5bdb551307603c2e36e959aa4d328798 (patch)
tree79438e1d88d972e9af661601d07f2fd01dde6b42 /games/fortune/strfile
parent3973c485bd3c9ad043575f0f636e55bc2ad116ac (diff)
downloadFreeBSD-src-f7458dfe5bdb551307603c2e36e959aa4d328798.zip
FreeBSD-src-f7458dfe5bdb551307603c2e36e959aa4d328798.tar.gz
Handle sorting in better way
Diffstat (limited to 'games/fortune/strfile')
-rw-r--r--games/fortune/strfile/strfile.c50
1 files changed, 34 insertions, 16 deletions
diff --git a/games/fortune/strfile/strfile.c b/games/fortune/strfile/strfile.c
index 4ce0928..a432e05 100644
--- a/games/fortune/strfile/strfile.c
+++ b/games/fortune/strfile/strfile.c
@@ -350,6 +350,35 @@ void do_order()
Tbl.str_flags |= STR_ORDERED;
}
+int collcmp (c1, c2)
+int c1, c2;
+{
+ static char s1[2], s2[2];
+
+ if ( (isascii(c1) && isascii(c2))
+ || (!isalpha(c1) && !isalpha(c2))
+ )
+ return (c1 - c2);
+ if (isalpha(c1) && !isalpha(c2)) {
+ if (isupper(c1))
+ return ('A' - c2);
+ else
+ return ('a' - c2);
+ } else if (isalpha(c2) && !isalpha(c1)) {
+ if (isupper(c2))
+ return (c1 - 'A');
+ else
+ return (c1 - 'a');
+ }
+ if (isupper(c1) && islower(c2))
+ return (-1);
+ else if (islower(c1) && isupper(c2))
+ return (1);
+ s1[0] = c1;
+ s2[0] = c2;
+ return strcoll(s1, s2);
+}
+
/*
* cmp_str:
* Compare two strings in the file
@@ -359,18 +388,15 @@ STR *p1, *p2;
{
register int c1, c2;
register int n1, n2;
- static char s1[2], s2[2];
int r;
# define SET_N(nf,ch) (nf = (ch == '\n'))
# define IS_END(ch,nf) (ch == EOF || (ch == (unsigned char) Delimch && nf))
- s1[0] = c1 = (unsigned char) p1->first;
- s2[0] = c2 = (unsigned char) p2->first;
- if ((r = strcoll(s1, s2)) != 0)
+ c1 = (unsigned char) p1->first;
+ c2 = (unsigned char) p2->first;
+ if ((r = collcmp(c1, c2)) != 0)
return r;
- if (c1 != c2)
- return c1 - c2;
(void) fseek(Sort_1, p1->pos, 0);
(void) fseek(Sort_2, p2->pos, 0);
@@ -389,12 +415,8 @@ STR *p1, *p2;
if (isupper(c2))
c2 = tolower(c2);
}
- s1[0] = c1;
- s2[0] = c2;
- if ((r = strcoll(s1, s2)) != 0)
+ if ((r = collcmp(c1, c2)) != 0)
return r;
- if (c1 != c2)
- return c1 - c2;
SET_N(n1, c1);
SET_N(n2, c2);
c1 = getc(Sort_1);
@@ -404,11 +426,7 @@ STR *p1, *p2;
c1 = 0;
if (IS_END(c2, n2))
c2 = 0;
- s1[0] = c1;
- s2[0] = c2;
- if ((r = strcoll(s1, s2)) != 0)
- return r;
- return c1 - c2;
+ return collcmp(c1, c2);
}
/*
OpenPOWER on IntegriCloud