changeset 450:d8ff3b0980cf

Minor cleanups to echo: collapse together three tolower() calls, make indent/brackets a bit more regular/obvious, and replace some spaces with tabs in help text (in a way that won't matter until I finish rewriting scripts/config2help.py in C).
author Rob Landley <rob@landley.net>
date Sat, 11 Feb 2012 13:42:24 -0600
parents d3544d2cdb26
children f4cc0a2aa440
files toys/echo.c
diffstat 1 files changed, 22 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/toys/echo.c	Sat Feb 11 14:58:50 2012 +0100
+++ b/toys/echo.c	Sat Feb 11 13:42:24 2012 -0600
@@ -17,19 +17,19 @@
 	  Write each argument to stdout, with one space between each, followed
 	  by a newline.
 
-	  -n    No trailing newline.
-	  -e    Process the following escape sequences:
-	   \\     backslash
+	  -n	No trailing newline.
+	  -e	Process the following escape sequences:
+	   \\	 backslash
 	   \0NNN octal values (1 to 3 digits)
-	   \a    alert (beep/flash)
-	   \b    backspace
-	   \c    stop output here (avoids trailing newline)
-	   \f    form feed
-	   \n    newline
-	   \r    carriage return
-	   \t    horizontal tab
-	   \v    vertical tab
-	   \xHH  hexadecimal values (1 to 2 digits)
+	   \a	 alert (beep/flash)
+	   \b	 backspace
+	   \c	 stop output here (avoids trailing newline)
+	   \f	 form feed
+	   \n	 newline
+	   \r	 carriage return
+	   \t	 horizontal tab
+	   \v	 vertical tab
+	   \xHH	 hexadecimal values (1 to 2 digits)
 */
 
 #include "toys.h"
@@ -66,17 +66,20 @@
 							c = 0;
 							while (arg[j]>='0' && arg[j]<='7' && n++<3)
 								c = (c*8)+arg[j++]-'0';
-						}
-						else if (d == 'x') {
+						} else if (d == 'x') {
 							int n = 0;
 							c = 0;							
-							while (n++<2)
+							while (n++<2) {
 								if (arg[j]>='0' && arg[j]<='9')
 									c = (c*16)+arg[j++]-'0';
-								else if (tolower(arg[j])>='a' && tolower(arg[j])<='f')
-									c = (c*16)+tolower(arg[j++])-'a'+10;
-								else
-									break;							
+								else {
+									int temp = tolower(arg[j]);
+									if (temp>='a' && temp<='f') {
+										c = (c*16)+temp-'a'+10;
+										j++;
+									} else break;
+								}
+							}
 						}
 					}
 				}