strfile.c (16262) | strfile.c (17555) |
---|---|
1/*- 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Ken Arnold. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 336 unchanged lines hidden (view full) --- 345 fp = Firstch; 346 while (i--) 347 *lp++ = fp++->pos; 348 (void) fclose(Sort_1); 349 (void) fclose(Sort_2); 350 Tbl.str_flags |= STR_ORDERED; 351} 352 | 1/*- 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Ken Arnold. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 336 unchanged lines hidden (view full) --- 345 fp = Firstch; 346 while (i--) 347 *lp++ = fp++->pos; 348 (void) fclose(Sort_1); 349 (void) fclose(Sort_2); 350 Tbl.str_flags |= STR_ORDERED; 351} 352 |
353int collcmp (c1, c2) 354int c1, c2; 355{ 356 static char s1[2], s2[2]; 357 358 if ( (isascii(c1) && isascii(c2)) 359 || (!isalpha(c1) && !isalpha(c2)) 360 ) 361 return (c1 - c2); 362 if (isalpha(c1) && !isalpha(c2)) { 363 if (isupper(c1)) 364 return ('A' - c2); 365 else 366 return ('a' - c2); 367 } else if (isalpha(c2) && !isalpha(c1)) { 368 if (isupper(c2)) 369 return (c1 - 'A'); 370 else 371 return (c1 - 'a'); 372 } 373 if (isupper(c1) && islower(c2)) 374 return (-1); 375 else if (islower(c1) && isupper(c2)) 376 return (1); 377 s1[0] = c1; 378 s2[0] = c2; 379 return strcoll(s1, s2); 380} 381 | |
382/* 383 * cmp_str: 384 * Compare two strings in the file 385 */ 386int cmp_str(p1, p2) 387STR *p1, *p2; 388{ 389 register int c1, c2; 390 register int n1, n2; 391 int r; 392 393# define SET_N(nf,ch) (nf = (ch == '\n')) 394# define IS_END(ch,nf) (ch == EOF || (ch == (unsigned char) Delimch && nf)) 395 396 c1 = (unsigned char) p1->first; 397 c2 = (unsigned char) p2->first; | 353/* 354 * cmp_str: 355 * Compare two strings in the file 356 */ 357int cmp_str(p1, p2) 358STR *p1, *p2; 359{ 360 register int c1, c2; 361 register int n1, n2; 362 int r; 363 364# define SET_N(nf,ch) (nf = (ch == '\n')) 365# define IS_END(ch,nf) (ch == EOF || (ch == (unsigned char) Delimch && nf)) 366 367 c1 = (unsigned char) p1->first; 368 c2 = (unsigned char) p2->first; |
398 if ((r = collcmp(c1, c2)) != 0) | 369 if ((r = collate_range_cmp(c1, c2)) != 0) |
399 return r; 400 401 (void) fseek(Sort_1, p1->pos, 0); 402 (void) fseek(Sort_2, p2->pos, 0); 403 404 n1 = FALSE; 405 n2 = FALSE; 406 while (!isalnum(c1 = getc(Sort_1)) && c1 != '\0' && c1 != EOF) 407 SET_N(n1, c1); 408 while (!isalnum(c2 = getc(Sort_2)) && c2 != '\0' && c2 != EOF) 409 SET_N(n2, c2); 410 411 while (!IS_END(c1, n1) && !IS_END(c2, n2)) { 412 if (Iflag) { 413 if (isupper(c1)) 414 c1 = tolower(c1); 415 if (isupper(c2)) 416 c2 = tolower(c2); 417 } | 370 return r; 371 372 (void) fseek(Sort_1, p1->pos, 0); 373 (void) fseek(Sort_2, p2->pos, 0); 374 375 n1 = FALSE; 376 n2 = FALSE; 377 while (!isalnum(c1 = getc(Sort_1)) && c1 != '\0' && c1 != EOF) 378 SET_N(n1, c1); 379 while (!isalnum(c2 = getc(Sort_2)) && c2 != '\0' && c2 != EOF) 380 SET_N(n2, c2); 381 382 while (!IS_END(c1, n1) && !IS_END(c2, n2)) { 383 if (Iflag) { 384 if (isupper(c1)) 385 c1 = tolower(c1); 386 if (isupper(c2)) 387 c2 = tolower(c2); 388 } |
418 if ((r = collcmp(c1, c2)) != 0) | 389 if ((r = collate_range_cmp(c1, c2)) != 0) |
419 return r; 420 SET_N(n1, c1); 421 SET_N(n2, c2); 422 c1 = getc(Sort_1); 423 c2 = getc(Sort_2); 424 } 425 if (IS_END(c1, n1)) 426 c1 = 0; 427 if (IS_END(c2, n2)) 428 c2 = 0; | 390 return r; 391 SET_N(n1, c1); 392 SET_N(n2, c2); 393 c1 = getc(Sort_1); 394 c2 = getc(Sort_2); 395 } 396 if (IS_END(c1, n1)) 397 c1 = 0; 398 if (IS_END(c2, n2)) 399 c2 = 0; |
429 return collcmp(c1, c2); | 400 return collate_range_cmp(c1, c2); |
430} 431 432/* 433 * randomize: 434 * Randomize the order of the string table. We must be careful 435 * not to randomize across delimiter boundaries. All 436 * randomization is done within each block. 437 */ --- 22 unchanged lines hidden --- | 401} 402 403/* 404 * randomize: 405 * Randomize the order of the string table. We must be careful 406 * not to randomize across delimiter boundaries. All 407 * randomization is done within each block. 408 */ --- 22 unchanged lines hidden --- |