Sat Aug 22 21:19:41 2009 UTC ()
Only process each number digit once.


(dsl)
diff -r1.25 -r1.26 src/usr.bin/sort/fields.c

cvs diff -r1.25 -r1.26 src/usr.bin/sort/fields.c (expand / switch to unified diff)

--- src/usr.bin/sort/fields.c 2009/08/22 10:53:28 1.25
+++ src/usr.bin/sort/fields.c 2009/08/22 21:19:40 1.26
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: fields.c,v 1.25 2009/08/22 10:53:28 dsl Exp $ */ 1/* $NetBSD: fields.c,v 1.26 2009/08/22 21:19:40 dsl Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2000-2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 2000-2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Ben Harris and Jaromir Dolecek. 8 * by Ben Harris and Jaromir Dolecek.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -56,27 +56,27 @@ @@ -56,27 +56,27 @@
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE. 61 * SUCH DAMAGE.
62 */ 62 */
63 63
64/* Subroutines to generate sort keys. */ 64/* Subroutines to generate sort keys. */
65 65
66#include "sort.h" 66#include "sort.h"
67 67
68#ifndef lint 68#ifndef lint
69__RCSID("$NetBSD: fields.c,v 1.25 2009/08/22 10:53:28 dsl Exp $"); 69__RCSID("$NetBSD: fields.c,v 1.26 2009/08/22 21:19:40 dsl Exp $");
70__SCCSID("@(#)fields.c 8.1 (Berkeley) 6/6/93"); 70__SCCSID("@(#)fields.c 8.1 (Berkeley) 6/6/93");
71#endif /* not lint */ 71#endif /* not lint */
72 72
73#define SKIP_BLANKS(ptr) { \ 73#define SKIP_BLANKS(ptr) { \
74 if (BLANK & d_mask[*(ptr)]) \ 74 if (BLANK & d_mask[*(ptr)]) \
75 while (BLANK & d_mask[*(++(ptr))]); \ 75 while (BLANK & d_mask[*(++(ptr))]); \
76} 76}
77 77
78#define NEXTCOL(pos) { \ 78#define NEXTCOL(pos) { \
79 if (!SEP_FLAG) \ 79 if (!SEP_FLAG) \
80 while (BLANK & l_d_mask[*(++pos)]); \ 80 while (BLANK & l_d_mask[*(++pos)]); \
81 while ((*(pos+1) != '\0') && !((FLD_D | REC_D_F) & l_d_mask[*++pos]));\ 81 while ((*(pos+1) != '\0') && !((FLD_D | REC_D_F) & l_d_mask[*++pos]));\
82} 82}
@@ -325,27 +325,27 @@ number(u_char *pos, const u_char *bufend @@ -325,27 +325,27 @@ number(u_char *pos, const u_char *bufend
325 *pos++ = SIGNED(reverse, t); 325 *pos++ = SIGNED(reverse, t);
326 /* now add each 7-bit block (offset 0x40..0xbf) */ 326 /* now add each 7-bit block (offset 0x40..0xbf) */
327 for (; c >= 0; c--) { 327 for (; c >= 0; c--) {
328 t = exponent >> (c * EXP_ENC_BITS); 328 t = exponent >> (c * EXP_ENC_BITS);
329 t = (t & EXP_ENC_MASK) + 0x40; 329 t = (t & EXP_ENC_MASK) + 0x40;
330 *pos++ = SIGNED(reverse, t); 330 *pos++ = SIGNED(reverse, t);
331 } 331 }
332 } 332 }
333 333
334 /* Now add mantissa, 2 digits per byte */ 334 /* Now add mantissa, 2 digits per byte */
335 for (last_nz_pos = pos; line < lineend; ) { 335 for (last_nz_pos = pos; line < lineend; ) {
336 if (pos >= bufend) 336 if (pos >= bufend)
337 return NULL; 337 return NULL;
338 ch = *line; 338 ch = *line++;
339 val = (ch - '0') * 10; 339 val = (ch - '0') * 10;
340 if (val > 90) { 340 if (val > 90) {
341 if (ch == DECIMAL_POINT && !had_dp) { 341 if (ch == DECIMAL_POINT && !had_dp) {
342 had_dp = 1; 342 had_dp = 1;
343 continue; 343 continue;
344 } 344 }
345 break; 345 break;
346 } 346 }
347 while (line < lineend) { 347 while (line < lineend) {
348 ch = *line++; 348 ch = *line++;
349 if (ch == DECIMAL_POINT && !had_dp) { 349 if (ch == DECIMAL_POINT && !had_dp) {
350 had_dp = 1; 350 had_dp = 1;
351 continue; 351 continue;