Debian Codegraph @

texk/makeindexk/scanid.c

raw
1 /*
2 *
3 * This file is part of
4 * MakeIndex - A formatter and format independent index processor
5 *
6 * Copyright (C) 1998-2011 by the TeX Live project.
7 * Copyright (C) 1989 by Chen & Harrison International Systems, Inc.
8 * Copyright (C) 1988 by Olivetti Research Center
9 * Copyright (C) 1987 by Regents of the University of California
10 *
11 * Author:
12 * Pehong Chen
13 * Chen & Harrison International Systems, Inc.
14 * Palo Alto, California
15 * USA
16 *
17 * Contributors:
18 * Please refer to the CONTRIB file that comes with this release
19 * for a list of people who have contributed to this and/or previous
20 * release(s) of MakeIndex.
21 *
22 * All rights reserved by the copyright holders. See the copyright
23 * notice distributed with this software for a complete description of
24 * the conditions under which it is made available.
25 *
26 */
27
28 #include "mkind.h"
29 #include "scanid.h"
30
31 #define CHECK_LENGTH() if (i > len_field) goto FIELD_OVERFLOW
32
33 int idx_lc; /* line count */
34 int idx_tc; /* total entry count */
35 int idx_ec; /* erroneous entry count */
36 int idx_dc; /* number of dots printed so far */
37
38 static int first_entry = TRUE;
39 static int comp_len;
40 static char key[ARGUMENT_MAX];
41 static char no[NUMBER_MAX];
42
43 NODE_PTR head;
44 NODE_PTR tail;
45
46 static void flush_to_eol (void);
47 static int make_key (void);
48 static void make_string (char **ppstr,int n);
49 static int scan_alpha_lower (char *no,int *npg,short *count);
50 static int scan_alpha_upper (char *no,int *npg,short *count);
51 static int scan_arabic (char *no,int *npg,short *count);
52 static int scan_arg1 (void);
53 static int scan_arg2 (void);
54 static int scan_field (int *n,char field[],int len_field,
55 int ck_level, int ck_encap,int ck_actual);
56 static int scan_key (struct KFIELD *data);
57 static int scan_no (char *no,int *npg,short *count,short *type);
58 static int scan_roman_lower (char *no,int *npg,short *count);
59 static int scan_roman_upper (char *no,int *npg,short *count);
60 static void search_quote (char **sort_key,char **actual_key);
61
62 void
63 scan_idx(void)
64 {
65 char keyword[ARRAY_MAX];
66 int c;
67 int i = 0;
68 int not_eof = TRUE;
69 int arg_count = -1;
70
71 MESSAGE1("Scanning input file %s...", idx_fn);
72 idx_lc = idx_tc = idx_ec = idx_dc = 0;
73 comp_len = strlen(page_comp);
74 while (not_eof) {
75 switch (c = GET_CHAR(idx_fp)) {
76 case EOF:
77 if (arg_count == 2) {
78 idx_lc++;
79 if (make_key())
80 IDX_DOT(DOT_MAX);
81 arg_count = -1;
82 } else {
83 if (arg_count > -1) {
84 idx_lc++;
85 IDX_ERROR("Missing arguments -- need two (premature EOF).\n");
86 arg_count = -2;
87 }
88 not_eof = FALSE;
89 }
90 break;
91
92 case LFD:
93 idx_lc++;
94 if (arg_count == 2) {
95 if (make_key())
96 IDX_DOT(DOT_MAX);
97 arg_count = -1;
98 } else if (arg_count > -1) {
99 IDX_ERROR("Missing arguments -- need two (premature LFD).\n");
100 arg_count = -1;
101 }
102 case TAB:
103 case SPC:
104 break;
105
106 default:
107 switch (arg_count) {
108 case -1:
109 i = 0;
110 keyword[i++] = (char) c;
111 arg_count++;
112 idx_tc++;
113 break;
114 case 0:
115 if (c == idx_aopen) {
116 arg_count++;
117 keyword[i] = NUL;
118 if (STREQ(keyword, idx_keyword)) {
119 if (!scan_arg1()) {
120 arg_count = -1;
121 }
122 } else {
123 IDX_SKIPLINE;
124 IDX_ERROR1("Unknown index keyword %s.\n", keyword);
125 }
126 } else {
127 if (i < ARRAY_MAX)
128 keyword[i++] = (char) c;
129 else {
130 IDX_SKIPLINE;
131 IDX_ERROR2("Index keyword %s too long (max %d).\n",
132 keyword, ARRAY_MAX);
133 }
134 }
135 break;
136 case 1:
137 if (c == idx_aopen) {
138 arg_count++;
139 if (!scan_arg2()) {
140 arg_count = -1;
141 }
142 } else {
143 IDX_SKIPLINE;
144 IDX_ERROR1(
145 "No opening delimiter for second argument (illegal character `%c').\n", c);
146 }
147 break;
148 case 2:
149 IDX_SKIPLINE;
150 IDX_ERROR1(
151 "No closing delimiter for second argument (illegal character `%c').\n", c);
152 break;
153 }
154 break;
155 }
156 }
157
158 /* fixup the total counts */
159 idx_tt += idx_tc;
160 idx_et += idx_ec;
161
162 DONE(idx_tc - idx_ec, "entries accepted", idx_ec, "rejected");
163 CLOSE(idx_fp);
164 }
165
166 static void
167 flush_to_eol(void)
168 { /* flush to end-of-line, or end-of-file, whichever is first */
169 int a;
170
171 while ( ((a = GET_CHAR(idx_fp)) != LFD) && (a != EOF) )
172 /* NO-OP */;
173 }
174
175 static int
176 make_key(void)
177 {
178 NODE_PTR ptr;
179 int i;
180 static size_t len = sizeof(NODE);
181
182 /* allocate and initialize a node */
183
184 #ifdef DEBUG
185 totmem += len;
186 (void)fprintf(stderr,"make_key(): malloc(%d)\ttotmem = %ld\n",
187 len,totmem);
188 #endif /* DEBUG */
189
190 if ((ptr = malloc(len)) == NULL)
191 fprintf (stderr, "Not enough core...abort.\n");
192
193 memset(ptr, 0, len);
194 /* Initialize dangling pointers
195 * Note: it would be a nice work to redesign the code to use NULL for
196 * comparision ... nevertheless, using local "" in a global environment
197 * isn't the hit because the allocation of the keys with german_sort may
198 * crash with a nitpicking memory allocation (Linux, libc-5.4.46).
199 * <[email protected]>
200 */
201 for (i = 0; i < FIELD_MAX; i++)
202 {
203 make_string(&(ptr->data.sf[i]), 1);
204 make_string(&(ptr->data.af[i]), 1);
205 }
206 make_string(&(ptr->data.encap), 1);
207 ptr->data.lpg[0] = NUL;
208 ptr->data.count = 0;
209 ptr->data.type = EMPTY;
210
211 /* process index key */
212 if (!scan_key(&(ptr->data)))
213 return (FALSE);
214
215 /* determine group type */
216 ptr->data.group = group_type(ptr->data.sf[0]);
217
218 /* process page number */
219 strcpy(ptr->data.lpg, no);
220 if (!scan_no(no, ptr->data.npg, &(ptr->data.count), &(ptr->data.type)))
221 return (FALSE);
222
223 if (first_entry) {
224 head = tail = ptr;
225 first_entry = FALSE;
226 } else {
227 tail->next = ptr;
228 tail = ptr;
229 }
230 ptr->data.lc = idx_lc;
231 ptr->data.fn = idx_fn;
232 tail->next = NULL;
233
234 return (TRUE);
235 }
236
237 static void
238 make_string(char **ppstr, int n)
239 {
240 if (*ppstr) /* Do NOT leaking here, <[email protected]> */
241 free(*ppstr);
242
243 /* Note: we have always allocate the correct amount of memory to
244 * avoid chrashes because the string length of the actual and
245 * sort key may differ at german_sort and strange indexentries
246 * <[email protected]>
247 */
248 (*ppstr) = malloc(n);
249 if (!(*ppstr))
250 fprintf (stderr, "Not enough core...abort.\n");
251 memset(*ppstr, 0, n); /* Always zero anything, <[email protected]> */
252 }
253
254 static int
255 scan_key(FIELD_PTR data)
256 {
257 int i = 0; /* current level */
258 int n = 0; /* index to the key[] array */
259 int second_round = FALSE;
260 int last = FIELD_MAX - 1;
261 size_t len;
262
263 while (TRUE) {
264 if (key[n] == NUL)
265 break;
266 len = strlen(key);
267 if (key[n] == idx_encap)
268 {
269 n++;
270 make_string(&(data->encap), len + 1);
271 if (scan_field(&n, data->encap, len, FALSE, FALSE, FALSE))
272 break;
273 else
274 return (FALSE);
275 }
276 if (key[n] == idx_actual) {
277 n++;
278
279 make_string(&(data->af[i]), len + 1);
280 if (i == last)
281 {
282 if (!scan_field(&n, data->af[i], len, FALSE, TRUE, FALSE))
283 return (FALSE);
284 }
285 else
286 {
287 if (!scan_field(&n, data->af[i], len, TRUE, TRUE, FALSE))
288 return (FALSE);
289 }
290 } else {
291 /* Next nesting level */
292 if (second_round) {
293 i++;
294 n++;
295 }
296
297 make_string(&(data->sf[i]), len + 1);
298 if (i == last)
299 {
300 if (!scan_field(&n, data->sf[i], len, FALSE, TRUE, TRUE))
301 return (FALSE);
302 }
303 else
304 {
305 if (!scan_field(&n, data->sf[i], len, TRUE, TRUE, TRUE))
306 return (FALSE);
307 }
308 second_round = TRUE;
309 if (german_sort && strchr(data->sf[i], '"'))
310 {
311 make_string(&(data->af[i]),strlen(data->sf[i]) + 1);
312 search_quote(&(data->sf[i]), &(data->af[i]));
313 }
314 }
315 }
316
317 /* check for empty fields which shouldn't be empty */
318 if (*data->sf[0] == NUL) {
319 NULL_RTN;
320 }
321 for (i = 1; i < FIELD_MAX - 1; i++)
322 if ((*data->sf[i] == NUL) &&
323 ((*data->af[i] != NUL) || (*data->sf[i + 1] != NUL))) {
324 NULL_RTN;
325 }
326 /* i == FIELD_MAX-1 */
327 if ((*data->sf[i] == NUL) && (*data->af[i] != NUL)) {
328 NULL_RTN;
329 }
330 return (TRUE);
331 }
332
333 static int
334 scan_field(int *n, char field[], int len_field, int ck_level, int ck_encap,
335 int ck_actual)
336 {
337 int i = 0;
338 int nbsh; /* backslash count */
339
340 if (compress_blanks && ((key[*n] == SPC) || (key[*n] == TAB)))
341 ++* n;
342
343 while (TRUE) {
344 nbsh = 0;
345 while (key[*n] == idx_escape)
346 {
347 nbsh++;
348 field[i++] = key[*n];
349 CHECK_LENGTH();
350 ++*n;
351 }
352
353 if (key[*n] == idx_quote)
354 {
355 if (nbsh % 2 == 0)
356 field[i++] = key[++*n];
357 else
358 field[i++] = key[*n];
359 CHECK_LENGTH();
360 }
361 else if ((ck_level && (key[*n] == idx_level)) ||
362 (ck_encap && (key[*n] == idx_encap)) ||
363 (ck_actual && (key[*n] == idx_actual)) ||
364 (key[*n] == NUL))
365 {
366 if ((i > 0) && compress_blanks && (field[i - 1] == SPC))
367 field[i - 1] = NUL;
368 else
369 field[i] = NUL;
370 return (TRUE);
371 } else {
372 field[i++] = key[*n];
373 CHECK_LENGTH();
374 if ((!ck_level) && (key[*n] == idx_level)) {
375 IDX_ERROR2("Extra `%c' at position %d of first argument.\n",
376 idx_level, *n + 1);
377 return (FALSE);
378 } else if ((!ck_encap) && (key[*n] == idx_encap)) {
379 IDX_ERROR2("Extra `%c' at position %d of first argument.\n",
380 idx_encap, *n + 1);
381 return (FALSE);
382 } else if ((!ck_actual) && (key[*n] == idx_actual)) {
383 IDX_ERROR2("Extra `%c' at position %d of first argument.\n",
384 idx_actual, *n + 1);
385 return (FALSE);
386 }
387 }
388 /* check if max field length is reached */
389 if (i > len_field)
390 {
391 FIELD_OVERFLOW:
392 if (!ck_encap) {
393 IDX_ERROR1("Encapsulator of page number too long (max. %d).\n",
394 len_field);
395 } else if (ck_actual) {
396 IDX_ERROR1("Index sort key too long (max. %d).\n", len_field);
397 } else {
398 IDX_ERROR1("Text of key entry too long (max. %d).\n", len_field);
399 }
400 return (FALSE);
401 }
402 ++*n;
403 }
404 }
405
406 int
407 group_type(const char *str)
408 {
409 int i = 0;
410
411 while ((str[i] != NUL) && ISDIGIT(str[i]))
412 i++;
413
414 if (str[i] == NUL) {
415 sscanf(str, "%d", &i);
416 return (i);
417 } else if (ISSYMBOL(str[0]))
418 return (SYMBOL);
419 else
420 return (ALPHA);
421 }
422
423 static int
424 scan_no(char no[], int npg[], short *count, short *type)
425 {
426 int i = 1;
427 static int type_guess[PAGEFIELD_MAX] =
428 {EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY};
429
430 /* heuristic detection if a letter is Roman or Alpha ::
431 "IVX" as roman number since I=1, V=5, X=10 are quite small
432 "LCDM" as alphabet since L=50, C=100, D=100, M=1000 are quite large */
433 if (isdigit((unsigned char)no[0])) {
434 type_guess[*count] = ARAB;
435 } else if (IS_ROMAN_LOWER(no[0]) && IS_ALPHA_LOWER(no[0])
436 && strchr(page_prec,ROMAN_LOWER) && strchr(page_prec,ALPHA_LOWER)) {
437 if (strspn(no,"ivxlcdm")==1 /* ambiguous */
438 && type_guess[*count] != ROML && type_guess[*count] != ALPL) {
439 type_guess[*count] = strspn(no,"ivx")==1 ? ROML : ALPL;
440 }
441 if (strspn(no,"ivxlcdm")>1) type_guess[*count] = ROML;
442 } else if (IS_ROMAN_UPPER(no[0]) && IS_ALPHA_UPPER(no[0])
443 && strchr(page_prec,ROMAN_UPPER) && strchr(page_prec,ALPHA_UPPER)) {
444 if (strspn(no,"IVXLCDM")==1 /* ambiguous */
445 && type_guess[*count] != ROMU && type_guess[*count] != ALPU) {
446 type_guess[*count] = strspn(no,"IVX")==1 ? ROMU : ALPU;
447 }
448 if (strspn(no,"IVXLCDM")>1) type_guess[*count] = ROMU;
449 } else if (IS_ROMAN_LOWER(no[0]) && strchr(page_prec,ROMAN_LOWER)) {
450 type_guess[*count] = ROML;
451 } else if (IS_ROMAN_UPPER(no[0]) && strchr(page_prec,ROMAN_UPPER)) {
452 type_guess[*count] = ROMU;
453 } else if (IS_ALPHA_LOWER(no[0]) && strchr(page_prec,ALPHA_LOWER)) {
454 type_guess[*count] = ALPL;
455 } else if (IS_ALPHA_UPPER(no[0]) && strchr(page_prec,ALPHA_UPPER)) {
456 type_guess[*count] = ALPU;
457 } else {
458 type_guess[*count] = EMPTY;
459 }
460
461 if (isdigit((unsigned char)no[0])) {
462 *type = ARAB;
463 if (!scan_arabic(no, npg, count))
464 return (FALSE);
465 /* simple heuristic to determine if a letter is Roman or Alpha */
466 } else if (IS_ROMAN_LOWER(no[0]) && strchr(page_prec,ROMAN_LOWER) &&
467 (!strchr(page_prec,ALPHA_LOWER) || type_guess[*count] == ROML) ) {
468 *type = ROML;
469 if (!scan_roman_lower(no, npg, count))
470 return (FALSE);
471 /* simple heuristic to determine if a letter is Roman or Alpha */
472 } else if (IS_ROMAN_UPPER(no[0]) && strchr(page_prec,ROMAN_UPPER) &&
473 (!strchr(page_prec,ALPHA_UPPER) || type_guess[*count] == ROMU) ) {
474 *type = ROMU;
475 if (!scan_roman_upper(no, npg, count))
476 return (FALSE);
477 } else if (IS_ALPHA_LOWER(no[0]) && strchr(page_prec,ALPHA_LOWER)) {
478 *type = ALPL;
479 if (!scan_alpha_lower(no, npg, count))
480 return (FALSE);
481 } else if (IS_ALPHA_UPPER(no[0]) && strchr(page_prec,ALPHA_UPPER)) {
482 *type = ALPU;
483 if (!scan_alpha_upper(no, npg, count))
484 return (FALSE);
485 } else {
486 IDX_ERROR2("Illegal page number %s or page_precedence %s.\n",
487 no, page_prec);
488 return (FALSE);
489 }
490 return (TRUE);
491 }
492
493
494 static int
495 scan_arabic(char no[], int npg[], short *count)
496 {
497 short i = 0;
498 char str[ARABIC_MAX+1]; /* space for trailing NUL */
499
500 while ((no[i] != NUL) && (i <= ARABIC_MAX) && (!IS_COMPOSITOR)) {
501 if (isdigit((unsigned char)no[i])) {
502 str[i] = no[i];
503 i++;
504 } else {
505 IDX_ERROR2("Illegal Arabic digit: position %d in %s.\n", i + 1, no);
506 return (FALSE);
507 }
508 }
509 if (i > ARABIC_MAX) {
510 IDX_ERROR2("Arabic page number %s too big (max %d digits).\n",
511 no, ARABIC_MAX);
512 return (FALSE);
513 }
514 str[i] = NUL;
515
516 ENTER(strtoint(str) + page_offset[ARAB]);
517
518 if (IS_COMPOSITOR)
519 return (scan_no(&no[i + comp_len], npg, count, &i));
520 else
521 return (TRUE);
522 }
523
524
525 static int
526 scan_roman_lower(char no[], int npg[], short *count)
527 {
528 short i = 0;
529 int inp = 0;
530 int prev = 0;
531 int the_new;
532
533 while ((no[i] != NUL) && (i < ROMAN_MAX) && (!IS_COMPOSITOR)) {
534 if ((IS_ROMAN_LOWER(no[i])) &&
535 ((the_new = ROMAN_LOWER_VAL(no[i])) != 0)) {
536 if (prev == 0)
537 prev = the_new;
538 else {
539 if (prev < the_new) {
540 prev = the_new - prev;
541 the_new = 0;
542 }
543 inp += prev;
544 prev = the_new;
545 }
546 } else {
547 IDX_ERROR2("Illegal Roman number: position %d in %s.\n", i + 1, no);
548 return (FALSE);
549 }
550 i++;
551 }
552 if (i == ROMAN_MAX) {
553 IDX_ERROR2("Roman page number %s too big (max %d digits).\n",
554 no, ROMAN_MAX);
555 return (FALSE);
556 }
557 inp += prev;
558
559 ENTER(inp + page_offset[ROML]);
560
561 if (IS_COMPOSITOR)
562 return (scan_no(&no[i + comp_len], npg, count, &i));
563 else
564 return (TRUE);
565 }
566
567
568 static int
569 scan_roman_upper(char no[], int npg[], short *count)
570 {
571 short i = 0;
572 int inp = 0;
573 int prev = 0;
574 int the_new;
575
576 while ((no[i] != NUL) && (i < ROMAN_MAX) && (!IS_COMPOSITOR)) {
577 if ((IS_ROMAN_UPPER(no[i])) &&
578 ((the_new = ROMAN_UPPER_VAL(no[i])) != 0)) {
579 if (prev == 0)
580 prev = the_new;
581 else {
582 if (prev < the_new) {
583 prev = the_new - prev;
584 the_new = 0;
585 }
586 inp += prev;
587 prev = the_new;
588 }
589 } else {
590 IDX_ERROR2("Illegal Roman number: position %d in %s.\n", i + 1, no);
591 return (FALSE);
592 }
593 i++;
594 }
595 if (i == ROMAN_MAX) {
596 IDX_ERROR2("Roman page number %s too big (max %d digits).\n",
597 no, ROMAN_MAX);
598 return (FALSE);
599 }
600 inp += prev;
601
602 ENTER(inp + page_offset[ROMU]);
603
604 if (IS_COMPOSITOR)
605 return (scan_no(&no[i + comp_len], npg, count, &i));
606 else
607 return (TRUE);
608 }
609
610
611 static int
612 scan_alpha_lower(char no[], int npg[], short *count)
613 {
614 short i;
615
616 ENTER(ALPHA_VAL(no[0]) + page_offset[ALPL]);
617
618 i = 1;
619 if (IS_COMPOSITOR)
620 return (scan_no(&no[comp_len + 1], npg, count, &i));
621 else
622 return (TRUE);
623 }
624
625
626 static int
627 scan_alpha_upper(char no[], int npg[], short *count)
628 {
629 short i;
630
631 ENTER(ALPHA_VAL(no[0]) + page_offset[ALPU]);
632
633 i = 1;
634 if (IS_COMPOSITOR)
635 return (scan_no(&no[comp_len + 1], npg, count, &i));
636 else
637 return (TRUE);
638 }
639
640
641 static int
642 scan_arg1(void)
643 {
644 int i = 0;
645 int n = 0; /* delimiter count */
646 int a;
647
648 if (compress_blanks)
649 while (((a = GET_CHAR(idx_fp)) == SPC) || (a == TAB));
650 else
651 a = GET_CHAR(idx_fp);
652
653 while ((i < ARGUMENT_MAX) && (a != EOF))
654 {
655 if ((a == idx_quote) || (a == idx_escape))
656 { /* take next character literally */
657 key[i++] = (char) a; /* but preserve quote or escape */
658 a = GET_CHAR(idx_fp);
659 key[i++] = (char) a; /* save literal character */
660 }
661 else if (a == idx_aopen)
662 { /* opening delimiters within the argument list */
663 key[i++] = (char) a;
664 n++;
665 }
666 else if (a == idx_aclose)
667 {
668 if (n == 0) /* end of argument */
669 {
670 if (compress_blanks && key[i - 1] == SPC)
671 key[i - 1] = NUL;
672 else
673 key[i] = NUL;
674 return (TRUE);
675 }
676 else /* nested delimiters */
677 {
678 key[i++] = (char) a;
679 n--;
680 }
681 }
682 else
683 {
684 switch (a)
685 {
686 case LFD:
687 idx_lc++;
688 IDX_ERROR("Incomplete first argument (premature LFD).\n");
689 return (FALSE);
690 case TAB:
691 case SPC:
692 /* compress successive SPC's to one SPC */
693 if (compress_blanks)
694 {
695 if ((i > 0) && (key[i - 1] != SPC) && (key[i - 1] != TAB))
696 key[i++] = SPC;
697 break;
698 }
699 default:
700 key[i++] = (char) a;
701 break;
702 }
703 }
704 a = GET_CHAR(idx_fp);
705 }
706
707 flush_to_eol(); /* Skip to end of line */
708 idx_lc++;
709 IDX_ERROR1("First argument too long (max %d).\n", ARGUMENT_MAX);
710 return (FALSE);
711 }
712
713
714 static int
715 scan_arg2(void)
716 {
717 int i = 0;
718 int a;
719 int hit_blank = FALSE;
720
721 while (((a = GET_CHAR(idx_fp)) == SPC) || (a == TAB));
722
723 while (i < NUMBER_MAX) {
724 if (a == idx_aclose) {
725 no[i] = NUL;
726 return (TRUE);
727 } else
728 switch (a) {
729 case LFD:
730 idx_lc++;
731 IDX_ERROR("Incomplete second argument (premature LFD).\n");
732 return (FALSE);
733 case TAB:
734 case SPC:
735 hit_blank = TRUE;
736 break;
737 default:
738 if (hit_blank) {
739 flush_to_eol(); /* Skip to end of line */
740 idx_lc++;
741 IDX_ERROR("Illegal space within numerals in second argument.\n");
742 return (FALSE);
743 }
744 no[i++] = (char) a;
745 break;
746 }
747 a = GET_CHAR(idx_fp);
748 }
749 flush_to_eol(); /* Skip to end of line */
750 idx_lc++;
751 IDX_ERROR1("Second argument too long (max %d).\n", NUMBER_MAX);
752 return (FALSE);
753 }
754
755
756 static void
757 search_quote(char **sort_key, char **actual_key)
758 {
759 char *ptr; /* pointer to sort_key */
760 const char *sort; /* contains sorting text */
761 int char_found = FALSE;
762
763 strcpy(*actual_key, *sort_key);
764 ptr = strchr(*sort_key, '"'); /* look for first double quote */
765 while (ptr != (char*)NULL)
766 {
767 sort = NULL;
768 switch (*(ptr + 1))
769 { /* skip to umlaut or sharp S */
770 case 'a':
771 case 'A':
772 sort = isupper((unsigned char)*(ptr + 1)) ? "Ae" : "ae";
773 break;
774 case 'o':
775 case 'O':
776 sort = isupper((unsigned char)*(ptr + 1)) ? "Oe" : "oe";
777 break;
778 case 'u':
779 case 'U':
780 sort = isupper((unsigned char)*(ptr + 1)) ? "Ue" : "ue";
781 break;
782 case 's':
783 sort = "ss";
784 break;
785 default:
786 break;
787 }
788 if (sort != NULL)
789 {
790 char_found = TRUE;
791 *ptr = sort[0]; /* write to sort_key */
792 *(ptr + 1) = sort[1];
793 }
794 ptr = strchr(ptr + 1, '"'); /* next double quote */
795 }
796 if (!char_found) /* reset actual_key ? */
797 make_string(actual_key, 1);
798 return;
799 }