aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c18
-rw-r--r--lib/lib.h1
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/lib.c b/lib/lib.c
index b0ac4715..6559030c 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -1015,3 +1015,21 @@ char *show_uuid(char *uuid)
return libbuf;
}
+
+// Returns pointer to letter at end, 0 if none. *start = initial %
+char *next_printf(char *s, char **start)
+{
+ for (; *s; s++) {
+ if (*s != '%') continue;
+ if (*++s == '%') continue;
+ if (start) *start = s-1;
+ while (0 <= stridx("0'#-+ ", *s)) s++;
+ while (isdigit(*s)) s++;
+ if (*s == '.') s++;
+ while (isdigit(*s)) s++;
+
+ return s;
+ }
+
+ return 0;
+}
diff --git a/lib/lib.h b/lib/lib.h
index f1cea22e..e3dbc462 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -196,6 +196,7 @@ int yesno(int def);
int qstrcmp(const void *a, const void *b);
void create_uuid(char *uuid);
char *show_uuid(char *uuid);
+char *next_printf(char *s, char **start);
#define HR_SPACE 1 // Space between number and units
#define HR_B 2 // Use "B" for single byte units