summaryrefslogtreecommitdiff
path: root/Build/source/texk
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk')
-rw-r--r--Build/source/texk/makeindexk/ChangeLog9
-rw-r--r--Build/source/texk/makeindexk/mkind.c2
-rw-r--r--Build/source/texk/makeindexk/mkind.h4
-rw-r--r--Build/source/texk/makeindexk/qsort.c51
-rw-r--r--Build/source/texk/makeindexk/qsort.h6
-rw-r--r--Build/source/texk/makeindexk/scanid.c2
-rw-r--r--Build/source/texk/makeindexk/sortid.c41
7 files changed, 63 insertions, 52 deletions
diff --git a/Build/source/texk/makeindexk/ChangeLog b/Build/source/texk/makeindexk/ChangeLog
index 30061dae1db..aab94aaa1ae 100644
--- a/Build/source/texk/makeindexk/ChangeLog
+++ b/Build/source/texk/makeindexk/ChangeLog
@@ -1,3 +1,12 @@
+2012-07-27 Peter Breitenlohner <peb@mppmu.mpg.de>
+
+ Cleanup Nelson Beebe's qqsort() used instead of qsort().
+ * qsort.[ch] (qqsort): Declare exactly as qsort().
+ (qq_compar_fn_t) Declare and use the comparison function type.
+ * mkind.[ch] (idx_gt): Change type 'int' into 'size_t'.
+ * mkind.h, scanid.c: Constify group_type() arg.
+ * sortid.c: Constify all comparison function args.
+
2012-07-26 Peter Breitenlohner <peb@mppmu.mpg.de>
* mkind.[ch] [WIN32]: Use binary mode for input and output
diff --git a/Build/source/texk/makeindexk/mkind.c b/Build/source/texk/makeindexk/mkind.c
index 72f93d0449e..a118fc34687 100644
--- a/Build/source/texk/makeindexk/mkind.c
+++ b/Build/source/texk/makeindexk/mkind.c
@@ -43,7 +43,7 @@ int idx_dot = TRUE; /* flag which shows dot in ilg being
* active */
int idx_tt = 0; /* total entry count (all files) */
int idx_et = 0; /* erroneous entry count (all files) */
-int idx_gt = 0; /* good entry count (all files) */
+size_t idx_gt = 0; /* good entry count (all files) */
FIELD_PTR *idx_key;
FILE *log_fp;
diff --git a/Build/source/texk/makeindexk/mkind.h b/Build/source/texk/makeindexk/mkind.h
index fbc3de0a1f8..e0b2917cd14 100644
--- a/Build/source/texk/makeindexk/mkind.h
+++ b/Build/source/texk/makeindexk/mkind.h
@@ -507,7 +507,7 @@ extern NODE_PTR tail;
extern int idx_dot;
extern int idx_tt;
-extern int idx_gt;
+extern size_t idx_gt;
extern int idx_et;
extern int idx_dc;
@@ -545,7 +545,7 @@ fprintf(ilg_fp, \
}
extern void gen_ind (void);
-extern int group_type (char *str);
+extern int group_type (const char *str);
extern void scan_idx (void);
extern void scan_sty (void);
extern void sort_idx (void);
diff --git a/Build/source/texk/makeindexk/qsort.c b/Build/source/texk/makeindexk/qsort.c
index f784980989a..df95890e68b 100644
--- a/Build/source/texk/makeindexk/qsort.c
+++ b/Build/source/texk/makeindexk/qsort.c
@@ -14,18 +14,17 @@
* the insertion sort threshold, and has been adjusted for records of size 48
* bytes. The MTHREShold is where we stop finding a better median.
*/
+#include "qsort.h" /* qq_compar_fn_t type and qqsort() prototype */
-#include "qsort.h"
+#define THRESH 4 /* threshold for insertion */
+#define MTHRESH 6 /* threshold for median */
-#define THRESH 4 /* threshold for insertion */
-#define MTHRESH 6 /* threshold for median */
+static int qsz; /* size of each record */
+static int thresh; /* THRESHold in chars */
+static int mthresh; /* MTHRESHold in chars */
-static int qsz; /* size of each record */
-static int thresh; /* THRESHold in chars */
-static int mthresh; /* MTHRESHold in chars */
-
-static int (*qcmp) (char*,char*); /* the comparison routine */
-static void qst (char *base, char *max);
+static qq_compar_fn_t qcmp; /* the comparison routine */
+static void qst(char *base, char *max);
/*
* qqsort: First, set up some global parameters for qst to share. Then,
* quicksort with qst(), and then a cleanup insertion sort ourselves. Sound
@@ -33,7 +32,7 @@ static void qst (char *base, char *max);
*/
void
-qqsort(char *base, int n, int size, int (*compar)(char*,char*))
+qqsort(void *base, size_t n, size_t size, qq_compar_fn_t compar)
{
register char *i;
register char *j;
@@ -41,7 +40,7 @@ qqsort(char *base, int n, int size, int (*compar)(char*,char*))
register char *hi;
register char *min;
register char c;
- char *max;
+ char *max;
if (n <= 1)
return;
@@ -49,10 +48,10 @@ qqsort(char *base, int n, int size, int (*compar)(char*,char*))
qcmp = compar;
thresh = qsz * THRESH;
mthresh = qsz * MTHRESH;
- max = base + n * qsz;
+ max = (char *)base + n * qsz;
if (n >= THRESH) {
qst(base, max);
- hi = base + thresh;
+ hi = (char *)base + thresh;
} else {
hi = max;
}
@@ -66,8 +65,8 @@ qqsort(char *base, int n, int size, int (*compar)(char*,char*))
if ((*qcmp) (j, lo) > 0)
j = lo;
}
- if (j != base) { /* swap j into place */
- for (i = base, hi = base + qsz; i < hi;) {
+ if (j != base) { /* swap j into place */
+ for (i = base, hi = i + qsz; i < hi;) {
c = *j;
*j++ = *i;
*i++ = c;
@@ -118,11 +117,11 @@ qst(char *base, char *max)
register char *mid;
register int ii;
register char c;
- char *tmp;
- int lo;
- int hi;
+ void *tmp;
+ int lo;
+ int hi;
- lo = (int)(max - base); /* number of elements as chars */
+ lo = max - base; /* number of elements as chars */
do {
/*
* At the top here, lo is the number of characters of elements in the
@@ -160,10 +159,10 @@ qst(char *base, char *max)
j -= qsz;
continue;
}
- tmp = i + qsz; /* value of i after swap */
- if (i == mid) { /* j <-> mid, new mid is j */
+ tmp = i + qsz; /* value of i after swap */
+ if (i == mid) { /* j <-> mid, new mid is j */
mid = jj = j;
- } else { /* i <-> j */
+ } else { /* i <-> j */
jj = j;
j -= qsz;
}
@@ -171,9 +170,9 @@ qst(char *base, char *max)
}
if (i == mid) {
break;
- } else { /* i <-> mid, new mid is i */
+ } else { /* i <-> mid, new mid is i */
jj = mid;
- tmp = mid = i; /* value of i after swap */
+ tmp = mid = i; /* value of i after swap */
j -= qsz;
}
swap:
@@ -188,12 +187,12 @@ qst(char *base, char *max)
/*
* Look at sizes of the two partitions, do the smaller one first by
* recursion, then do the larger one by making sure lo is its size,
- * base and max are update correctly, and branching back. But only
+ * base and max are updated correctly, and branching back. But only
* repeat (recursively or by branching) if the partition is of at
* least size THRESH.
*/
i = (j = mid) + qsz;
- if ((lo = (int)(j - base)) <= (hi = (int)(max - i))) {
+ if ((lo = j - base) <= (hi = max - i)) {
if (lo >= thresh)
qst(base, j);
base = i;
diff --git a/Build/source/texk/makeindexk/qsort.h b/Build/source/texk/makeindexk/qsort.h
index 3bca7d6dbf2..0c3087c5a1a 100644
--- a/Build/source/texk/makeindexk/qsort.h
+++ b/Build/source/texk/makeindexk/qsort.h
@@ -7,6 +7,8 @@
* Nelson Beebe (beebe@science.utah.edu).
*
*/
+#include <string.h> /* for size_t */
-extern void qqsort (char *base, int n, int size,
- int (*compar)(char*,char*));
+typedef int (*qq_compar_fn_t)(const void *, const void *);
+
+extern void qqsort (void *base, size_t n, size_t size, qq_compar_fn_t compar);
diff --git a/Build/source/texk/makeindexk/scanid.c b/Build/source/texk/makeindexk/scanid.c
index 75916409291..1740b38186c 100644
--- a/Build/source/texk/makeindexk/scanid.c
+++ b/Build/source/texk/makeindexk/scanid.c
@@ -398,7 +398,7 @@ scan_field(int *n, char field[], int len_field, int ck_level, int ck_encap,
}
int
-group_type(char *str)
+group_type(const char *str)
{
int i = 0;
diff --git a/Build/source/texk/makeindexk/sortid.c b/Build/source/texk/makeindexk/sortid.c
index b596846b2d7..2a62d694864 100644
--- a/Build/source/texk/makeindexk/sortid.c
+++ b/Build/source/texk/makeindexk/sortid.c
@@ -34,13 +34,13 @@
static long idx_gc;
-static int check_mixsym (char *x,char *y);
-static int compare (struct KFIELD * *a,struct KFIELD * *b);
-static int compare_one (char *x,char *y);
-static int compare_page (struct KFIELD * *a,struct KFIELD * *b);
-static int compare_string (unsigned char *a,unsigned char *b);
-static int new_strcmp (unsigned char *a, unsigned char *b,
- int option);
+static int check_mixsym (const char *x, const char *y);
+static int compare (const void *va, const void *vb);
+static int compare_one (const char *x, const char *y);
+static int compare_page (const FIELD_PTR *a, const FIELD_PTR *b);
+static int compare_string (const unsigned char *a, const unsigned char *b);
+static int new_strcmp (const unsigned char *a, const unsigned char *b,
+ int option);
void
sort_idx(void)
@@ -56,8 +56,7 @@ sort_idx(void)
#endif
idx_dc = 0;
idx_gc = 0L;
- qqsort((char *) idx_key, (int) idx_gt, (int) sizeof(FIELD_PTR),
- (int (*)(char*,char*))compare);
+ qqsort(idx_key, idx_gt, sizeof(FIELD_PTR), compare);
#ifdef HAVE_SETLOCALE
setlocale(LC_COLLATE, prev_locale);
#endif
@@ -65,8 +64,10 @@ sort_idx(void)
}
static int
-compare(FIELD_PTR *a, FIELD_PTR *b)
+compare(const void *va, const void *vb)
{
+ const FIELD_PTR *a = va;
+ const FIELD_PTR *b = vb;
int i;
int dif;
@@ -90,7 +91,7 @@ compare(FIELD_PTR *a, FIELD_PTR *b)
}
static int
-compare_one(char *x,char *y)
+compare_one(const char *x, const char *y)
{
int m;
int n;
@@ -138,11 +139,11 @@ compare_one(char *x,char *y)
return (1);
/* strings with a leading letter, the ALPHA type */
- return (compare_string((unsigned char*)x, (unsigned char*)y));
+ return (compare_string((const unsigned char*)x, (const unsigned char*)y));
}
static int
-check_mixsym(char *x, char *y)
+check_mixsym(const char *x, const char *y)
{
int m;
int n;
@@ -161,14 +162,14 @@ check_mixsym(char *x, char *y)
static int
-compare_string(unsigned char *a, unsigned char *b)
+compare_string(const unsigned char *a, const unsigned char *b)
{
int i = 0;
int j = 0;
int al;
int bl;
- if (locale_sort) return strcoll((char *)a, (char *)b);
+ if (locale_sort) return strcoll((const char *)a, (const char *)b);
while ((a[i] != NUL) || (b[j] != NUL)) {
if (a[i] == NUL)
@@ -192,11 +193,11 @@ compare_string(unsigned char *a, unsigned char *b)
if (german_sort)
return (new_strcmp(a, b, GERMAN));
else
- return (strcmp((char*)a, (char*)b));
+ return (strcmp((const char*)a, (const char*)b));
}
static int
-compare_page(FIELD_PTR *a, FIELD_PTR *b)
+compare_page(const FIELD_PTR *a, const FIELD_PTR *b)
{
int m = 0;
short i = 0;
@@ -280,8 +281,8 @@ compare_page(FIELD_PTR *a, FIELD_PTR *b)
m = (*a)->lc - (*b)->lc; /* order by input line number */
else /* order non-range items by */
/* their encap strings */
- m = compare_string((unsigned char*)((*a)->encap),
- (unsigned char*)((*b)->encap));
+ m = compare_string((const unsigned char*)((*a)->encap),
+ (const unsigned char*)((*b)->encap));
}
}
else if ((i == (*a)->count) && (i < (*b)->count))
@@ -294,7 +295,7 @@ compare_page(FIELD_PTR *a, FIELD_PTR *b)
static int
-new_strcmp(unsigned char *s1, unsigned char *s2, int option)
+new_strcmp(const unsigned char *s1, const unsigned char *s2, int option)
{
int i;