diff -r -u lout-3.13-dist/externs.h lout-3.13/externs.h --- lout-3.13-dist/externs.h Fri Feb 5 04:40:02 1999 +++ lout-3.13/externs.h Tue Feb 9 02:31:00 1999 @@ -2584,12 +2584,11 @@ /***** z39.c String Handler **************************************/ #define AsciiToFull(x) ( (FULL_CHAR *) (x) ) -#if COLLATE #define StringEqual(a, b) (strcoll((char *)(a), (char *)(b))==0) +#if !COLLATE #define StringLessEqual(a, b) (strcoll((char*)(a),(char*)(b))<=0) #else -#define StringEqual(a, b) (strcmp((char *)(a), (char *)(b))==0) -#define StringLessEqual(a, b) (strcmp((char*)(a),(char*)(b))<=0) +extern BOOLEAN StringLessEqual(FULL_CHAR *a, FULL_CHAR *b); #endif #define StringCat(a, b) strcat((char *)(a),(char *)(b)) #define StringCopy(a, b) strcpy((char *)(a),(char *)(b)) @@ -2836,6 +2835,7 @@ #define debugcond3(cat, urg, cond, str, p1, p2, p3) #define debugcond4(cat, urg, cond, str, p1, p2, p3, p4) #define debugcond5(cat, urg, cond, str, p1, p2, p3, p4, p5) +#define debugcond6(cat, urg, cond, str, p1, p2, p3, p4, p5, p6) #define ifdebugcond(cat, urg, cond, x) #define debug_init(str) Error(1, 4, "%s - debug flags not implemented", \ FATAL, no_fpos, str) diff -r -u lout-3.13-dist/z39.c lout-3.13/z39.c --- lout-3.13-dist/z39.c Fri Feb 5 02:17:07 1999 +++ lout-3.13/z39.c Tue Feb 9 01:16:55 1999 @@ -54,6 +54,18 @@ /*****************************************************************************/ +#if COLLATE /* otherwise defined as a macro in externs.h */ +/* NB: must match compare() in z45.c */ +BOOLEAN StringLessEqual(FULL_CHAR *a, FULL_CHAR *b) +{ + int coll = strcoll ((char *)a, (char *)b); + if (coll == 0) /* then disambiguate with strcmp */ + coll = strcmp ((char *)a, (char *)b); + return coll <= 0; +} +#endif /* COLLATE */ + + /*@::StringBeginsWith(), StringContains(), StringInt(), StringFiveInt()@******/ /* */ /* BOOLEAN StringBeginsWith(str, pattern) */ diff -r -u lout-3.13-dist/z45.c lout-3.13/z45.c --- lout-3.13-dist/z45.c Fri Feb 5 02:17:15 1999 +++ lout-3.13/z45.c Tue Feb 9 01:18:48 1999 @@ -120,8 +120,10 @@ { char *text; /* Text of the line. */ int length; /* Length not including final newline. */ - char *keybeg; /* Start of first key. */ - char *keylim; /* Limit of first key. */ +#if COLLATE + char *xfrm; /* == strxfrm(text) */ + int xfrmlen; /* Length not including final zero byte */ +#endif }; /* Arrays of lines. */ @@ -343,6 +345,14 @@ lines->lines[lines->used].text = beg; lines->lines[lines->used].length = ptr - beg; +#if COLLATE + { + int xfrmlen = strxfrm ((char *) 0, beg, 0); + lines->lines[lines->used].xfrmlen = xfrmlen; + lines->lines[lines->used].xfrm = (char *) xmalloc (xfrmlen + 1); + strxfrm (lines->lines[lines->used].xfrm, beg, xfrmlen); + } +#endif /* COLLATE */ ++lines->used; beg = ptr + 1; @@ -351,51 +361,66 @@ buf->left = lim - beg; } +/* Auxiliary function to compare strings A and B that have lengths + ALEN and BLEN, respectively. */ +static int +compare_ascii (a, alen, b, blen) + register char *a, *b; + register int alen, blen; +{ + int diff, mini; + + mini = find_min(alen, blen); + if (mini == 0) + diff = alen - blen; + else + { + diff = *a - *b; + if (diff == 0) + { + diff = memcmp (a, b, mini); + if (diff == 0) + diff = alen - blen; + } + } + return diff; +} + + /* Compare two lines A and B, returning negative, zero, or positive - depending on whether A compares less than, equal to, or greater than B. */ + depending on whether A compares less than, equal to, or greater than B. + NB: must match StringLessEqual */ #if COLLATE + static int compare (a, b) register struct line *a, *b; { int tmpa, tmpb, mini; - tmpa = a->length, tmpb = b->length; - mini = find_min(tmpa, tmpb); - if (mini == 0) - return tmpa - tmpb; - else - return strcoll (a->text, b->text); + tmpa = a->length, tmpb = b->length; + mini = find_min(tmpa, tmpb); + if (mini == 0) + return tmpa - tmpb; + else + { /* NB: see StringLessEqual in z39.c */ + int coll = compare_ascii (a->xfrm, a->xfrmlen, b->xfrm, b->xfrmlen); + if (coll == 0) /* then disambiguate */ + coll = compare_ascii (a->text, a->length, b->text, b->length); + return coll; + } } -#else /* !COLLATE -- good old ASCIIbetical order */ +#else /* !COLLATE */ /* good old ASCIIbetical order */ -static int +static inline int compare (a, b) - register struct line *a, *b; + struct line *a, *b; { - int diff, tmpa, tmpb, mini; - - tmpa = a->length, tmpb = b->length; - mini = find_min(tmpa, tmpb); - if (mini == 0) - diff = tmpa - tmpb; - else - { - char *ap = a->text, *bp = b->text; - - diff = *ap - *bp; - if (diff == 0) - { - diff = memcmp (ap, bp, mini); - if (diff == 0) - diff = tmpa - tmpb; - } - } - - return diff; + return compare_ascii (a->text, a->length, b->text, b->length); } + #endif /* !COLLATE */ /* Sort the array LINES with NLINES members, using TEMP for temporary space. */ @@ -440,9 +465,8 @@ *lo++ = *t++; } -/* Sort NFILES FILES onto OFP. */ - -void SortFile(char *infile, char *outfile) /* name changed from sort_one by JK */ +/* name changed from sort_one by JK */ +void SortFile(char *infile, char *outfile) { struct buffer buf; struct lines lines; @@ -474,6 +498,9 @@ for (i = 0; i < lines.used; ++i) { xfwrite (lines.lines[i].text, 1, lines.lines[i].length, ofp); +#if COLLATE + free (lines.lines[i].xfrm); +#endif putc ('\n', ofp); } }