[BusyBox-cvs] CVS update of busybox/libbb (process_escape_sequence.c)

Erik Andersen andersen at codepoet.org
Mon Jul 26 11:28:47 UTC 2004


    Date: Monday, July 26, 2004 @ 05:28:47
  Author: andersen
    Path: /var/cvs/busybox/libbb

Modified: process_escape_sequence.c (1.5 -> 1.6)

Allow hex escape sequences


Index: busybox/libbb/process_escape_sequence.c
diff -u busybox/libbb/process_escape_sequence.c:1.5 busybox/libbb/process_escape_sequence.c:1.6
--- busybox/libbb/process_escape_sequence.c:1.5	Mon Mar 15 01:28:43 2004
+++ busybox/libbb/process_escape_sequence.c	Mon Jul 26 05:28:47 2004
@@ -22,35 +22,42 @@
  *
  */
 
+#include <string.h>
 #include <stdio.h>
 #include <limits.h>
+#include <ctype.h>
 #include "libbb.h"
 
+#define isodigit(c) ((c) >= '0' && (c) <= '7')
+#define hextobin(c) ((c)>='a'&&(c)<='f' ? (c)-'a'+10 : (c)>='A'&&(c)<='F' ? (c)-'A'+10 : (c)-'0')
+#define octtobin(c) ((c) - '0')
 char bb_process_escape_sequence(const char **ptr)
 {
+	const char *p, *q;
+	unsigned int num_digits, r, n, hexescape;
 	static const char charmap[] = {
 		'a',  'b',  'f',  'n',  'r',  't',  'v',  '\\', 0,
 		'\a', '\b', '\f', '\n', '\r', '\t', '\v', '\\', '\\' };
 
-	const char *p;
-	const char *q;
-	unsigned int num_digits;
-	unsigned int r;
-	unsigned int n;
-
-	n = 0;
+	n = r = hexescape = num_digits = 0;
 	q = *ptr;
 
-	num_digits = 0;
+	if (*q == 'x') {
+		hexescape++;
+		++q;
+	}
+
 	do {
-		if (((unsigned int)(*q - '0')) <= 7) {
-			r = n * 8 + (*q - '0');
-			if (r <= UCHAR_MAX) {
-				n = r;
-				++q;
-				if (++num_digits < 3) {
-					continue;
-				}
+		if (hexescape && isxdigit(*q)) {
+			r = n * 16 + hextobin(*q);
+		} else if (isodigit(*q)) {
+			r = n * 8 + octtobin(*q);
+		}
+		if (r <= UCHAR_MAX) {
+			n = r;
+			++q;
+			if (++num_digits < 3) {
+				continue;
 			}
 		}
 		break;



More information about the busybox-cvs mailing list