Remove debugging statement.
[oweals/busybox.git] / tr.c
diff --git a/tr.c b/tr.c
index ce15cfdf8bad1341568a74286889ed676f745c7f..5b7b8d091a5952c24a69fe4627c47f8fd05d82fa 100644 (file)
--- a/tr.c
+++ b/tr.c
 #include <unistd.h>
 #include <sys/types.h>
 #include "busybox.h"
-#define BB_DECLARE_EXTERN
-#define bb_need_write_error
-#include "messages.c"
 
-static const int ASCII = 0377;
+/* This must be a #define, since when DODEBUG and BUFFERS_GO_IN_BSS are
+ * enabled, we otherwise get a "storage size isn't constant error. */
+#define ASCII 0377
 
-/* some glabals shared across this file */
+/* some "globals" shared across this file */
 static char com_fl, del_fl, sq_fl;
 static short in_index, out_index;
 /* these last are pointers to static buffers declared in tr_main */
@@ -55,7 +54,7 @@ static void convert()
                if (in_index == read_chars) {
                        if ((read_chars = read(0, (char *) pinput, BUFSIZ)) <= 0) {
                                if (write(1, (char *) poutput, out_index) != out_index)
-                                       write(2, write_error, strlen(write_error));
+                                       error_msg("%s", write_error);
                                exit(0);
                        }
                        in_index = 0;
@@ -68,10 +67,8 @@ static void convert()
                        continue;
                poutput[out_index++] = last = coded;
                if (out_index == BUFSIZ) {
-                       if (write(1, (char *) poutput, out_index) != out_index) {
-                               write(2, write_error, strlen(write_error));
-                               exit(1);
-                       }
+                       if (write(1, (char *) poutput, out_index) != out_index)
+                               error_msg_and_die("%s", write_error);
                        out_index = 0;
                }
        }
@@ -93,6 +90,10 @@ static void map(register unsigned char *string1, unsigned int string1_len,
        }
 }
 
+/* supported constructs:
+ *   Ranges,  e.g.,  [0-9]  ==>  0123456789
+ *   Escapes, e.g.,  \a     ==>  Control-G
+ */
 static unsigned int expand(const char *arg, register unsigned char *buffer)
 {
        unsigned char *buffer_start = buffer;
@@ -102,6 +103,16 @@ static unsigned int expand(const char *arg, register unsigned char *buffer)
                if (*arg == '\\') {
                        arg++;
                        *buffer++ = process_escape_sequence(&arg);
+               } else if (*(arg+1) == '-') {
+                       ac = *(arg+2);
+                       if(ac == 0) {
+                               *buffer++ = *arg++;
+                               continue;
+                       }
+                       i = *arg;
+                       while (i <= ac)
+                               *buffer++ = i++;
+                       arg += 3; /* Skip the assumed a-z */
                } else if (*arg == '[') {
                        arg++;
                        i = *arg++;
@@ -113,7 +124,7 @@ static unsigned int expand(const char *arg, register unsigned char *buffer)
                        ac = *arg++;
                        while (i <= ac)
                                *buffer++ = i++;
-                       arg++;                          /* Skip ']' */
+                       arg++;                          /* Skip the assumed ']' */
                } else
                        *buffer++ = *arg++;
        }