From 956cb5d55405e38ce591111585a8c1ce30a482f8 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 30 Jan 2025 16:19:48 +0100 Subject: [PATCH] MINOR: tevt/dev: Parse tuple of termination events term_events tool is now able to parse tuple of termination events, as returned by "term_events" sample fetch function. --- dev/term_events/term_events.c | 57 ++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/dev/term_events/term_events.c b/dev/term_events/term_events.c index 4e9b8d0ed..417793fb6 100644 --- a/dev/term_events/term_events.c +++ b/dev/term_events/term_events.c @@ -101,8 +101,14 @@ char *tevt_show_events(char *buf, size_t len, const char *delim, const char *val char loc[5]; int ret; - if (!value) + if (!value || !*value) { + snprintf(buf, len, "##NONE"); goto end; + } + if (strcmp(value, "-") == 0) { + snprintf(buf, len, "##UNK"); + goto end; + } if (strlen(value) % 2 != 0) { snprintf(buf, len, "##INV"); @@ -135,10 +141,47 @@ char *tevt_show_events(char *buf, size_t len, const char *delim, const char *val return buf; } +char *tevt_show_tuple_events(char *buf, size_t len, char *value) +{ + char *p = value; + + /* skip '{' */ + p++; + while (*p) { + char *v; + char c; + + while (*p == ' ' || *p == '\t') + p++; + + v = p; + while (*p && *p != ',' && *p != '}') + p++; + c = *p; + *p = 0; + + tevt_show_events(buf, len, " > ", v); + printf("\t- %s\n", buf); + + *p = c; + if (*p == ',') + p++; + else if (*p == '}') + break; + else { + printf("\t- ##INV\n"); + break; + } + } + + *buf = 0; + return buf; +} + int main(int argc, char **argv) { const char *name = argv[0]; - char line[20]; + char line[128]; char *value; int multi = 0; int use_stdin = 0; @@ -165,7 +208,7 @@ int main(int argc, char **argv) value++; err = value; - while (isalnum((unsigned char)*err)) + while (*err && *err != '\n') err++; *err = 0; } @@ -177,7 +220,13 @@ int main(int argc, char **argv) if (multi) printf("### %-8s : ", value); - tevt_show_events(buf, bsz, " > ", value); + if (*value == '{') { + if (!use_stdin) + printf("\n"); + tevt_show_tuple_events(buf, bsz, value); + } + else + tevt_show_events(buf, bsz, " > ", value); printf("%s\n", buf); } return 0;