version 1.265, 2020/11/02 08:21:30 |
version 1.266, 2020/11/09 09:10:10 |
|
|
#define FORMAT_PANES 0x200 |
#define FORMAT_PANES 0x200 |
#define FORMAT_PRETTY 0x400 |
#define FORMAT_PRETTY 0x400 |
#define FORMAT_LENGTH 0x800 |
#define FORMAT_LENGTH 0x800 |
|
#define FORMAT_WIDTH 0x1000 |
|
|
/* Limit on recursion. */ |
/* Limit on recursion. */ |
#define FORMAT_LOOP_LIMIT 10 |
#define FORMAT_LOOP_LIMIT 10 |
|
|
|
|
/* |
/* |
* Modifiers are a ; separated list of the forms: |
* Modifiers are a ; separated list of the forms: |
* l,m,C,b,d,n,t,q,E,T,S,W,P,<,> |
* l,m,C,b,d,n,t,w,q,E,T,S,W,P,<,> |
* =a |
* =a |
* =/a |
* =/a |
* =/a/ |
* =/a/ |
|
|
cp++; |
cp++; |
|
|
/* Check single character modifiers with no arguments. */ |
/* Check single character modifiers with no arguments. */ |
if (strchr("lbdnqETSWP<>", cp[0]) != NULL && |
if (strchr("lbdnqwETSWP<>", cp[0]) != NULL && |
format_is_end(cp[1])) { |
format_is_end(cp[1])) { |
format_add_modifier(&list, count, cp, 1, NULL, 0); |
format_add_modifier(&list, count, cp, 1, NULL, 0); |
cp++; |
cp++; |
|
|
if (errptr != NULL) |
if (errptr != NULL) |
width = 0; |
width = 0; |
break; |
break; |
|
case 'w': |
|
modifiers |= FORMAT_WIDTH; |
|
break; |
case 'e': |
case 'e': |
if (fm->argc < 1 || fm->argc > 3) |
if (fm->argc < 1 || fm->argc > 3) |
break; |
break; |
|
|
format_log(es, "applied padding width %d: %s", width, value); |
format_log(es, "applied padding width %d: %s", width, value); |
} |
} |
|
|
/* Replace with the length if needed. */ |
/* Replace with the length or width if needed. */ |
if (modifiers & FORMAT_LENGTH) { |
if (modifiers & FORMAT_LENGTH) { |
xasprintf(&new, "%zu", strlen(value)); |
xasprintf(&new, "%zu", strlen(value)); |
free(value); |
free(value); |
value = new; |
value = new; |
format_log(es, "replacing with length: %s", new); |
format_log(es, "replacing with length: %s", new); |
} |
} |
|
if (modifiers & FORMAT_WIDTH) { |
|
xasprintf(&new, "%u", format_width(value)); |
|
free(value); |
|
value = new; |
|
format_log(es, "replacing with width: %s", new); |
|
} |
|
|
/* Expand the buffer and copy in the value. */ |
/* Expand the buffer and copy in the value. */ |
valuelen = strlen(value); |
valuelen = strlen(value); |
|
|
break; |
break; |
fmt += n + 1; |
fmt += n + 1; |
continue; |
continue; |
case '}': |
|
case '#': |
case '#': |
|
/* |
|
* If ##[ (with two or more #s), then it is a style and |
|
* can be left for format_draw to handle. |
|
*/ |
|
ptr = fmt; |
|
n = 2; |
|
while (*ptr == '#') { |
|
ptr++; |
|
n++; |
|
} |
|
if (*ptr == '[') { |
|
format_log(es, "found #*%zu[", n); |
|
while (len - off < n + 2) { |
|
buf = xreallocarray(buf, 2, len); |
|
len *= 2; |
|
} |
|
memcpy(buf + off, fmt - 2, n + 1); |
|
off += n + 1; |
|
fmt = ptr + 1; |
|
continue; |
|
} |
|
/* FALLTHROUGH */ |
|
case '}': |
case ',': |
case ',': |
format_log(es, "found #%c", ch); |
format_log(es, "found #%c", ch); |
while (len - off < 2) { |
while (len - off < 2) { |