Date: Thu, 31 May 2001 16:00:11 -0700 (PDT) From: pete@altadena.net To: FreeBSD-gnats-submit@freebsd.org Subject: gnu/27803: Enhancement to sort(1) Message-ID: <200105312300.f4VN0Bh81406@ns.altadena.net>
next in thread | raw e-mail | index | archive | help
>Number: 27803
>Category: gnu
>Synopsis: Enhancement to sort(1)
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Thu May 31 16:10:03 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Pete Carah
>Release: FreeBSD 4.3-RELEASE i386
>Organization:
Altadena Internet
>Environment:
System: FreeBSD ns.altadena.net 4.3-RELEASE FreeBSD 4.3-RELEASE #0: Sat Apr 28 22:19:41 PDT 2001 pete@ns.altadena.net:/usr/src/sys/compile/PUFFIN i386
>Description:
Enhance sort with -I data type (IP address; parsing and byte
ordering handled with system macros, thus possibly unsuitable
for some systems. I think freebsd always has netinet/*.h, etc.
This probably should be submitted to gnu-bugs instead of here;
if submitted there it will need autoconf stuff to detect the
presence of network code.
>How-To-Repeat:
IP addresses normally sorted lexically; this is a pain
>Fix:
diff -c /usr/src/gnu/usr.bin/sort/sort.c sort/sort.c
*** /usr/src/gnu/usr.bin/sort/sort.c Sun Apr 8 02:21:56 2001
--- sort/sort.c Thu May 31 15:55:47 2001
***************
*** 38,43 ****
--- 38,48 ----
#include "error.h"
#include "xstrtod.h"
+ /* added for -I - uses inet_addr and ntohl macros */
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <arpa/inet.h>
+
#ifdef HAVE_LIMITS_H
#include <limits.h>
#else
***************
*** 99,104 ****
--- 104,110 ----
int skipsblanks; /* Skip leading white space at start. */
int eword; /* Zero-origin first word after field. */
int echar; /* Additional characters in field. */
+ int ipaddr; /* field is an IP address. */
int skipeblanks; /* Skip trailing white space at finish. */
int *ignore; /* Boolean array of characters to ignore. */
char *translate; /* Translation applied to characters. */
***************
*** 1076,1081 ****
--- 1082,1111 ----
return key->reverse ? -diff : diff;
continue;
}
+ else if (key->ipaddr)
+ {
+ unsigned long a, b;
+
+ if (*lima || *limb)
+ {
+ char savea = *lima, saveb = *limb;
+ *lima = *limb = '\0';
+ a = ntohl(inet_addr(texta));
+ b = ntohl(inet_addr(textb));
+ *lima = savea;
+ *limb = saveb;
+ }
+ else
+ {
+ a = ntohl(inet_addr(texta));
+ b = ntohl(inet_addr(textb));
+ }
+
+ if (a > b) return key->reverse ? -1 : 1;
+ else if (b > a) return key->reverse ? 1 : -1;
+
+ continue;
+ }
else if (key->month)
{
diff = getmonth (texta, lena) - getmonth (textb, lenb);
***************
*** 1701,1706 ****
--- 1731,1740 ----
break;
case 'i':
key->ignore = nonprinting;
+ break;
+ case 'I':
+ key->ipaddr = 1;
+ key->skipsblanks = key->skipeblanks = 1;
break;
case 'M':
key->month = 1;
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200105312300.f4VN0Bh81406>
