gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot/printf_check.cpp
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2012年07月30日 15:05:50 +0200
committerFrancesco Abbate <francesco.bbt@gmail.com>2012年07月30日 15:05:50 +0200
commit64e594860a92fdd912d08398baf1ad4b013068a8 (patch)
tree3600a1977ffd9a15d9511e432b8d3e0dd6dd2049 /agg-plot/printf_check.cpp
parent84b06bc0e6f54aabaed1d401465edc3cd1ed62de (diff)
downloadgsl-shell-64e594860a92fdd912d08398baf1ad4b013068a8.tar.gz
Implement a local function to parse printf templates
The header file <printf.h> seems to be absent on MinGW and broken on Linux so it is better to not rely on this header file.
Diffstat (limited to 'agg-plot/printf_check.cpp')
-rw-r--r--agg-plot/printf_check.cpp 78
1 files changed, 78 insertions, 0 deletions
diff --git a/agg-plot/printf_check.cpp b/agg-plot/printf_check.cpp
new file mode 100644
index 00000000..3e8e50b2
--- /dev/null
+++ b/agg-plot/printf_check.cpp
@@ -0,0 +1,78 @@
+
+#include "printf_check.h"
+
+static const char* match_plain_chars(const char *p)
+{
+ for (/* */; *p; p++) {
+ for (/* */; *p != '%'; p++) {
+ if (*p == 0)
+ return 0;
+ }
+ p ++;
+ if (*p != '%')
+ return p;
+ }
+ return 0;
+}
+
+static const char* match_integer(const char* p)
+{
+ if (int(*p) >= int('1') && int(*p) <= int('9'))
+ p++;
+ while (int(*p) >= int('0') && int(*p) <= int('9'))
+ p++;
+
+ return p;
+}
+
+int check_printf_argument(const char *label, const char*& tail, arg_type_e& arg_type)
+{
+ const char* p = match_plain_chars(label);
+
+ if (!p) return 0;
+
+ if (*p)
+ {
+ const char c = *p;
+ if (c == '0' || c == '-' || c == '+' || c == ' ' || c == '#' || c == '\'')
+ {
+ p ++;
+ if (*p == 0) goto error_exit;
+ }
+ }
+ else
+ goto error_exit;
+
+ p = match_integer(p);
+ if (*p == 0) goto error_exit;
+
+ if (*p == '.')
+ {
+ p++;
+ if (*p == 0) goto error_exit;
+ p = match_integer(p);
+ if (*p == 0) goto error_exit;
+ }
+
+ if (*p == 'l') {
+ p++;
+ if (*p == 0) goto error_exit;
+ }
+
+ if (*p)
+ {
+ const char s = *p;
+ if (s == 'd' || s == 'i' || s == 'd' || s == 'u' || s == 'x' || s == 'X' || s == 'o') {
+ tail = p + 1;
+ arg_type = argument_int;
+ return 1;
+ } else if (s == 'f' || s == 'g' || s == 'e' || s == 'E' || s == 'G') {
+ tail = p + 1;
+ arg_type = argument_double;
+ return 1;
+ }
+ }
+
+ error_exit:
+ return (-1);
+}
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月18日 14:47:41 +0000

AltStyle によって変換されたページ (->オリジナル) /