aboutsummaryrefslogtreecommitdiff
path: root/toys/lsb
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-01-22 21:35:48 -0600
committerRob Landley <rob@landley.net>2016-01-22 21:35:48 -0600
commitcf0f037ac861a3f4fd877e79f3e53877a446f722 (patch)
treed141c65d6c3563d271e8049f8229114797f9f86e /toys/lsb
parent83c6d225795f94840b6acbba0955c65ef0340e7e (diff)
downloadtoybox-cf0f037ac861a3f4fd877e79f3e53877a446f722.tar.gz
Factor out insanitize() from seq.c to next_printf() in lib.
Diffstat (limited to 'toys/lsb')
-rw-r--r--toys/lsb/seq.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/toys/lsb/seq.c b/toys/lsb/seq.c
index c6204742..3ff9ca44 100644
--- a/toys/lsb/seq.c
+++ b/toys/lsb/seq.c
@@ -32,22 +32,13 @@ GLOBALS(
// Ensure there's one %f escape with correct attributes
static void insanitize(char *f)
{
- char *s;
- int found = 0;
+ char *s = next_printf(f, 0);
- for (s = f; *s; s++) {
- if (*s != '%') continue;
- if (*++s == '%') continue;
- if (found++) break;
- while (0 <= stridx("0'#-+ ", *s)) s++;
- while (isdigit(*s)) s++;
- if (*s == '.') s++;
- while (isdigit(*s)) s++;
- if (-1 == stridx("aAeEfFgG", *s)) break;
+ if (!s) error_exit("bad -f no %%f");
+ if (-1 == stridx("aAeEfFgG", *s) || (s = next_printf(s, 0))) {
+ // The @ is a byte offset, not utf8 chars. Waiting for somebody to complain.
+ error_exit("bad -f '%s'@%ld", f, s-f+1);
}
-
- // The @ is a byte offset, not utf8 chars. Waiting for somebody to complain...
- if (*s || !found) error_exit("bad -f '%s'@%ld", f, s-f+1);
}
void seq_main(void)