From: Karel Zak Date: Wed, 9 Mar 2016 14:51:28 +0000 (+0100) Subject: look: consider blanks as directory characters X-Git-Tag: v2.28-rc1~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b480fe67b0641cd8dbb0ef3cedb7c4666f5b209;p=thirdparty%2Futil-linux.git look: consider blanks as directory characters This change introduces regression, but it seems better than to be incompatible with "sort -d" if we assume that "sort -d" is the right way how to prepare files for look(1). It seems (from man page) that the original goal has been compatibility with sort -d, but this feature has never been fully implemented. Addresses: https://github.com/karelzak/util-linux/issues/284 Signed-off-by: Karel Zak --- diff --git a/misc-utils/look.1 b/misc-utils/look.1 index e96a4318dc..4de5f0ed7b 100644 --- a/misc-utils/look.1 +++ b/misc-utils/look.1 @@ -68,12 +68,16 @@ alphabetic characters is ignored. Use the alternative dictionary file. .TP .BR \-d , " \-\-alphanum" -Use normal dictionary character set and order, i.e. only alphanumeric characters -are compared. (This is on by default if no file is specified.) +Use normal dictionary character set and order, i.e. only blanks and +alphanumeric characters are compared. This is on by default if no file is +specified. + +Note that blanks have been added to dictionary character set for +compatibility with \fBsort \-d\fR command since version 2.28. .TP .BR \-f , " \-\-ignore\-case" -Ignore the case of alphabetic characters. (This is on by default if no file is -specified.) +Ignore the case of alphabetic characters. This is on by default if no file is +specified. .TP .BR \-t , " \-\-terminate " \fIcharacter\fR Specify a string termination character, i.e. only the characters @@ -105,10 +109,6 @@ the alternative dictionary .SH "SEE ALSO" .BR grep (1), .BR sort (1) -.SH COMPATIBILITY -The original manual page stated that tabs and blank characters participated -in comparisons when the \fB\-\-alphanum\fR option was specified. This was -incorrect, and the current man page matches the historic implementation. .SH HISTORY The .B look diff --git a/misc-utils/look.c b/misc-utils/look.c index 96a02c41d7..f0cc1d7f19 100644 --- a/misc-utils/look.c +++ b/misc-utils/look.c @@ -174,7 +174,7 @@ look(char *front, char *back) /* Reformat string string to avoid doing it multiple times later. */ if (dflag) { for (readp = writep = string; (ch = *readp++) != 0;) { - if (isalnum(ch)) + if (isalnum(ch) || isblank(ch)) *(writep++) = ch; } *writep = '\0'; @@ -333,7 +333,7 @@ compare(char *s2, char *s2end) { p = comparbuf; i = stringlen; while(s2 < s2end && *s2 != '\n' && i) { - if (!dflag || isalnum(*s2)) + if (!dflag || isalnum(*s2) || isblank(*s2)) { *p++ = *s2; i--; @@ -361,7 +361,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out) fputs(USAGE_OPTIONS, out); fputs(_(" -a, --alternative use the alternative dictionary\n"), out); - fputs(_(" -d, --alphanum compare only alphanumeric characters\n"), out); + fputs(_(" -d, --alphanum compare only blanks and alphanumeric characters\n"), out); fputs(_(" -f, --ignore-case ignore case differences when comparing\n"), out); fputs(_(" -t, --terminate define the string-termination character\n"), out);