summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <colomar.6.4.3@gmail.com>2020-04-14 21:06:53 +0200
committerAlejandro Colomar <colomar.6.4.3@gmail.com>2020-04-14 21:06:53 +0200
commit73e24256f0efc41f2f7989cb7ec202ec25143e0b (patch)
tree4aeb13fe67262bfbef210771a3f68d9d01beccf0
parent8a423c3069d988dbff93cfe24aead7b1b79cbcba (diff)
Print output in human readable form
-rw-r--r--src/main.c2
-rw-r--r--src/templates/templates.c28
-rw-r--r--src/templates/templates.h2
3 files changed, 31 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index fe70ffa..6b7616b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -90,7 +90,7 @@ int main (void)
goto err;
if (match_t_outer(symbols[i], &code) < 0)
goto err;
- printf("0b%'.16b\n", code);
+ print_code(code);
}
alx_cv_imwrite(img, "/tmp/wash.png");
diff --git a/src/templates/templates.c b/src/templates/templates.c
index 794b7b3..cb6eaab 100644
--- a/src/templates/templates.c
+++ b/src/templates/templates.c
@@ -265,6 +265,34 @@ err0: alx_cv_deinit_img(out);
return status;
}
+void print_code (uint32_t code)
+{
+ ptrdiff_t base;
+ bool y_n;
+ ptrdiff_t inner;
+ ptrdiff_t outer;
+
+ base = BITFIELD_READ(code, CODE_BASE_POS, CODE_BASE_LEN);
+ y_n = BIT_READ(code, CODE_Y_N_POS);
+ inner = BITFIELD_READ(code, CODE_IN_POS, CODE_IN_LEN);
+ outer = BITFIELD_READ(code, CODE_OUT_POS, CODE_OUT_LEN);
+
+ printf("%s", t_base_meaning[base]);
+ if (!y_n) {
+ printf(" not\n");
+ } else {
+ if (inner || outer)
+ printf(": ");
+ if (inner)
+ printf("%s", t_inner_meaning[inner]);
+ if (inner && outer)
+ printf(", ");
+ if (outer)
+ printf("%s", t_outer_meaning[outer]);
+ fputc('\n', stdout);
+ }
+}
+
/******************************************************************************
******* static function definitions ******************************************
diff --git a/src/templates/templates.h b/src/templates/templates.h
index c8ba037..9c8eaa1 100644
--- a/src/templates/templates.h
+++ b/src/templates/templates.h
@@ -109,6 +109,7 @@ extern const char *const t_base_meaning[T_BASE_QTY];
extern const char *const t_base_fnames[T_BASE_QTY];
extern const char *const t_inner_meaning[T_INNER_MEANING_QTY];
extern const char *const t_inner_fnames[T_INNER_QTY];
+extern const char *const t_outer_meaning[T_OUTER_MEANING_QTY];
extern img_s *base_templates[ARRAY_SIZE(t_base_fnames)];
extern img_s *base_templates_not[ARRAY_SIZE(t_base_fnames)];
@@ -123,6 +124,7 @@ void deinit_templates(void);
int load_templates (void);
int match_t_inner (img_s *restrict sym, uint32_t *code);
int match_t_outer (img_s *restrict sym, uint32_t *code);
+void print_code (uint32_t code);
/******************************************************************************