strfile.c (16140) | strfile.c (16262) |
---|---|
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 |
|
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; | 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; |
362 static char s1[2], s2[2]; | |
363 int r; 364 365# define SET_N(nf,ch) (nf = (ch == '\n')) 366# define IS_END(ch,nf) (ch == EOF || (ch == (unsigned char) Delimch && nf)) 367 | 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 |
368 s1[0] = c1 = (unsigned char) p1->first; 369 s2[0] = c2 = (unsigned char) p2->first; 370 if ((r = strcoll(s1, s2)) != 0) | 396 c1 = (unsigned char) p1->first; 397 c2 = (unsigned char) p2->first; 398 if ((r = collcmp(c1, c2)) != 0) |
371 return r; | 399 return r; |
372 if (c1 != c2) 373 return c1 - c2; | |
374 375 (void) fseek(Sort_1, p1->pos, 0); 376 (void) fseek(Sort_2, p2->pos, 0); 377 378 n1 = FALSE; 379 n2 = FALSE; 380 while (!isalnum(c1 = getc(Sort_1)) && c1 != '\0' && c1 != EOF) 381 SET_N(n1, c1); 382 while (!isalnum(c2 = getc(Sort_2)) && c2 != '\0' && c2 != EOF) 383 SET_N(n2, c2); 384 385 while (!IS_END(c1, n1) && !IS_END(c2, n2)) { 386 if (Iflag) { 387 if (isupper(c1)) 388 c1 = tolower(c1); 389 if (isupper(c2)) 390 c2 = tolower(c2); 391 } | 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 } |
392 s1[0] = c1; 393 s2[0] = c2; 394 if ((r = strcoll(s1, s2)) != 0) | 418 if ((r = collcmp(c1, c2)) != 0) |
395 return r; | 419 return r; |
396 if (c1 != c2) 397 return c1 - c2; | |
398 SET_N(n1, c1); 399 SET_N(n2, c2); 400 c1 = getc(Sort_1); 401 c2 = getc(Sort_2); 402 } 403 if (IS_END(c1, n1)) 404 c1 = 0; 405 if (IS_END(c2, n2)) 406 c2 = 0; | 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; |
407 s1[0] = c1; 408 s2[0] = c2; 409 if ((r = strcoll(s1, s2)) != 0) 410 return r; 411 return c1 - c2; | 429 return collcmp(c1, c2); |
412} 413 414/* 415 * randomize: 416 * Randomize the order of the string table. We must be careful 417 * not to randomize across delimiter boundaries. All 418 * randomization is done within each block. 419 */ --- 22 unchanged lines hidden --- | 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 --- |