ref: 8eda3492efb3f4ee1f3e9d95593bedced54abe31
parent: 728e4356eb13cdc0a41440264099299676f27d3d
author: Ali Gholami Rudi <ali@rudi.ir>
date: Sat Dec 8 15:56:33 EST 2012
parse arguments of every escape sequence
--- a/out.c
+++ b/out.c
@@ -52,23 +52,30 @@
static char *escarg(char *s, char *d, int cmd)
{
- if (cmd == 's' && (*s == '-' || *s == '+'))
- *d++ = *s++;
- if (*s == '(') {
- s++;
- *d++ = *s++;
- *d++ = *s++;
- } else if (*s == '\'') {
- s++;
- while (*s >= 0 && *s != '\'')
+ int q;
+ if (strchr(ESC_P, cmd)) {
+ if (cmd == 's' && (*s == '-' || *s == '+'))
*d++ = *s++;
- if (*s == '\'')
+ if (*s == '(') {
s++;
- } else {
- *d++ = *s++;
- if (cmd == 's' && s[-1] >= '1' && s[-1] <= '3' && isdigit(*s))
*d++ = *s++;
+ *d++ = *s++;
+ } else {
+ *d++ = *s++;
+ if (cmd == 's' && s[-1] >= '1' && s[-1] <= '3')
+ if (isdigit(*s))
+ *d++ = *s++;
+ }
}
+ if (strchr(ESC_Q, cmd)) {
+ q = *s++;
+ while (*s && *s != q)
+ *d++ = *s++;
+ if (*s == q)
+ s++;
+ }
+ if (cmd == 'z')
+ *d++ = *s++;
*d = '\0';
return s;
}
--- a/ren.c
+++ b/ren.c
@@ -207,39 +207,41 @@
n_u = 0;
}
-static void escarg(char *s, int cmd)
+static void escarg_ren(char *d, int cmd)
{
- int c;
- c = ren_next();
- if (cmd == 's' && (c == '-' || c == '+')) {
- *s++ = c;
+ int c, q;
+ if (strchr(ESC_P, cmd)) {
c = ren_next();
+ if (cmd == 's' && (c == '-' || c == '+')) {
+ *d++ = c;
+ c = ren_next();
+ }
+ if (c == '(') {
+ *d++ = ren_next();
+ *d++ = ren_next();
+ } else {
+ *d++ = c;
+ if (cmd == 's' && c >= '1' && c <= '3') {
+ c = ren_next();
+ if (isdigit(c))
+ *d++ = c;
+ else
+ ren_back(c);
+ }
+ }
}
- if (c == '(') {
- *s++ = ren_next();
- *s++ = ren_next();
- *s = '\0';
- return;
- }
- if (c == '\'') {
+ if (strchr(ESC_Q, cmd)) {
+ q = ren_next();
while (1) {
c = ren_next();
- if (c == '\'' || c < 0)
+ if (c == q || c < 0)
break;
- *s++ = c;
+ *d++ = c;
}
- *s = '\0';
- return;
}
- *s++ = c;
- if (cmd == 's' && c >= '1' && c <= '3') {
- c = ren_next();
- if (isdigit(c))
- *s++ = c;
- else
- ren_back(c);
- }
- *s = '\0';
+ if (cmd == 'z')
+ *d++ = ren_next();
+ *d = '\0';
}
void render(void)
@@ -290,7 +292,7 @@
l += nextchar(c + l);
c[l] = '\0';
} else if (strchr("sf", c[0])) {
- escarg(arg, c[0]);
+ escarg_ren(arg, c[0]);
if (c[0] == 'f')
ren_ft(arg);
if (c[0] == 's')
--- a/xroff.h
+++ b/xroff.h
@@ -18,6 +18,10 @@
#define ADJ_L 0
#define ADJ_B 1
+/* escape sequences */
+#define ESC_Q "bCDhHlLNoSvwxX" /* quoted escape sequences */
+#define ESC_P "*fgkns" /* 1 or 2-char escape sequences */
+
#define LEN(a) (sizeof(a) / sizeof((a)[0]))
/* number registers */