From 337061a3f425115d4e20ff148dee5f9df55cc53b Mon Sep 17 00:00:00 2001 From: Matteo Bini Date: Mon, 26 Aug 2024 15:26:22 +0200 Subject: [PATCH] HTML command names --- srohtml.c | 180 +++++++++++++++++++++++------------------------------- 1 file changed, 76 insertions(+), 104 deletions(-) diff --git a/srohtml.c b/srohtml.c index 37f77d1..1247e50 100644 --- a/srohtml.c +++ b/srohtml.c @@ -56,27 +56,26 @@ static void *array_push(array *a); static char *array_strcat(array *dst, const char *src); static char *array_strcat_html(array *dst, const char *src, const html_val_type t); static void cmd(char *line); -static void cmd_close(void); static void cmd_a(const char *line); static void cmd_au_de_ti(char **dst, const char *line); static void cmd_br(void); -static void cmd_dt(const char *line); +static void cmd_close(void); static void cmd_em(const char *line); -static void cmd_fi(const char *line); +static void cmd_figure(const char *line); static void cmd_h(const char *line); static void cmd_hr(void); static void cmd_i(const char *line); -static void cmd_in(const char *line); -static void cmd_la(const char *line); -static void cmd_le(void); -static void cmd_ls(void); -static void cmd_no(const char *line); +static void cmd_index(const char *line); +static void cmd_lang(const char *line); +static void cmd_license_end(void); +static void cmd_license_start(void); +static void cmd_note(const char *line); static void cmd_p(void); -static void cmd_pd(const char *line); +static void cmd_publication_date(const char *line); static void cmd_q(const char *line); -static void cmd_st(const char *line); -static void cmd_tm(const char *line); -static void cmd_ur(const char *line); +static void cmd_strong(const char *line); +static void cmd_time(const char *line); +static void cmd_url(const char *line); static void findent(const int ind, FILE *f); static void footer(void); static void footnotes(void); @@ -108,7 +107,7 @@ char *index_heading_id = NULL; size_t index_position = 0; char *language = NULL; int licence_container = 0; -char *pub_date = NULL; +char *publication_date = NULL; array sitography; int space = 0; char tag_closure[CLS_MAX]; @@ -196,18 +195,18 @@ cmd(char *line) if (!strncmp(line, "A", cmdlen)) cmd_a(line); - else if (!strncmp(line, "AU", cmdlen)) + else if (!strncmp(line, "AUTHOR", cmdlen)) cmd_au_de_ti(&author, line); else if (!strncmp(line, "BR", cmdlen)) cmd_br(); - else if (!strncmp(line, "DE", cmdlen)) + else if (!strncmp(line, "DESCRIPTION", cmdlen)) cmd_au_de_ti(&description, line); - else if (!strncmp(line, "DT", cmdlen)) - cmd_dt(line); + else if (!strncmp(line, "TIME", cmdlen)) + cmd_time(line); else if (!strncmp(line, "EM", cmdlen)) cmd_em(line); - else if (!strncmp(line, "FI", cmdlen)) - cmd_fi(line); + else if (!strncmp(line, "FIGURE", cmdlen)) + cmd_figure(line); else if (!strncmp(line, "H1", cmdlen)) cmd_h(line); else if (!strncmp(line, "H2", cmdlen)) @@ -224,30 +223,28 @@ cmd(char *line) cmd_hr(); else if (!strncmp(line, "I", cmdlen)) cmd_i(line); - else if (!strncmp(line, "IN", cmdlen)) - cmd_in(line); - else if (!strncmp(line, "LA", cmdlen)) - cmd_la(line); - else if (!strncmp(line, "LE", cmdlen)) - cmd_le(); - else if (!strncmp(line, "LS", cmdlen)) - cmd_ls(); - else if (!strncmp(line, "NO", cmdlen)) - cmd_no(line); + else if (!strncmp(line, "INDEX", cmdlen)) + cmd_index(line); + else if (!strncmp(line, "LANG", cmdlen)) + cmd_lang(line); + else if (!strncmp(line, "LICENSE_END", cmdlen)) + cmd_license_end(); + else if (!strncmp(line, "LICENSE_START", cmdlen)) + cmd_license_start(); + else if (!strncmp(line, "NOTE", cmdlen)) + cmd_note(line); else if (!strncmp(line, "P", cmdlen)) cmd_p(); - else if (!strncmp(line, "PD", cmdlen)) - cmd_pd(line); + else if (!strncmp(line, "PUBLICATION_DATE", cmdlen)) + cmd_publication_date(line); else if (!strncmp(line, "Q", cmdlen)) cmd_q(line); - else if (!strncmp(line, "ST", cmdlen)) - cmd_st(line); - else if (!strncmp(line, "TI", cmdlen)) + else if (!strncmp(line, "STRONG", cmdlen)) + cmd_strong(line); + else if (!strncmp(line, "TITLE", cmdlen)) cmd_au_de_ti(&title, line); - else if (!strncmp(line, "TM", cmdlen)) - cmd_tm(line); - else if (!strncmp(line, "UR", cmdlen)) - cmd_ur(line); + else if (!strncmp(line, "URL", cmdlen)) + cmd_url(line); } void @@ -294,7 +291,11 @@ void cmd_au_de_ti(char **dst, const char *line) { /* move past command */ - line += 2; + line = strchr(line, ' '); + + if (line == NULL) + return; + /* move past ' ', if present */ if (line[0] == ' ') line++; @@ -365,15 +366,15 @@ cmd_close(void) } void -cmd_dt(const char *line) +cmd_time(const char *line) { char *datetime, *in; datetime = NULL; in = NULL; - /* move past "DT" */ - line += 2; + /* move past "TIME" */ + line += 4; /* move past arguments, once found them */ line += stread_param(line, &datetime); line += stread_param(line, &in); @@ -410,15 +411,15 @@ cmd_em(const char *line) } void -cmd_fi(const char *line) +cmd_figure(const char *line) { char *ind, *src; ind = NULL; src = NULL; - /* move past "FI" */ - line += 2; + /* move past "FIGURE" */ + line += 6; /* move past argument, once found it */ line += stread_param(line, &src); @@ -497,10 +498,10 @@ cmd_i(const char *line) } void -cmd_in(const char *line) +cmd_index(const char *line) { - /* move past "IN" */ - line += 2; + /* move past "INDEX" */ + line += 5; /* move past arguments, once found them */ line += stread_param(line, &index_heading); line += stread_param(line, &index_heading_id); @@ -518,10 +519,10 @@ cmd_in(const char *line) } void -cmd_la(const char *line) +cmd_lang(const char *line) { - /* move past "LA" */ - line += 2; + /* move past "LANG" */ + line += 4; /* move past ' ', if present */ if (line[0] == ' ') line++; @@ -538,7 +539,7 @@ cmd_la(const char *line) } void -cmd_le(void) +cmd_license_end(void) { char *ind; @@ -553,7 +554,7 @@ cmd_le(void) } void -cmd_ls(void) +cmd_license_start(void) { char *ind; @@ -575,7 +576,7 @@ cmd_ls(void) } void -cmd_no(const char *line) +cmd_note(const char *line) { char *desc, *href, *title; char index[NOTES_MAX_DIGITS + 1]; @@ -584,8 +585,8 @@ cmd_no(const char *line) href = NULL; title = NULL; - /* move past "NO" */ - line += 2; + /* move past "NOTE" */ + line += 4; /* move past arguments, once found them */ line += stread_param(line, &href); line += stread_param(line, &desc); @@ -630,10 +631,10 @@ cmd_p(void) } void -cmd_pd(const char *line) +cmd_publication_date(const char *line) { - /* move past "PD" */ - line += 2; + /* move past "PUBLICATION_DATE" */ + line += 16; /* move past ' ', if present */ if (line[0] == ' ') line++; @@ -641,12 +642,12 @@ cmd_pd(const char *line) if (strlen(line) != DATE_LEN) return; - if (pub_date == NULL) { - pub_date = safe_malloc(sizeof(char) * (DATE_LEN + 1)); - pub_date[DATE_LEN] = '\0'; + if (publication_date == NULL) { + publication_date = safe_malloc(sizeof(char) * (DATE_LEN + 1)); + publication_date[DATE_LEN] = '\0'; } - strncpy(pub_date, line, DATE_LEN); + strncpy(publication_date, line, DATE_LEN); } void @@ -678,14 +679,14 @@ cmd_q(const char *line) } void -cmd_st(const char *line) +cmd_strong(const char *line) { char *bodystr; bodystr = body.data; - /* move past "ST" */ - line += 2; + /* move past "STRONG" */ + line += 6; /* move past space, if present */ if (line[0] == ' ') line++; @@ -698,39 +699,10 @@ cmd_st(const char *line) } void -cmd_tm(const char *line) +cmd_url(const char *line) { - char *date, *hours, *in; - - /* move past "TM" */ - line += 2; - /* move past arguments, once found them */ - line += stread_param(line, &date); - line += stread_param(line, &hours); - line += stread_param(line, &in); - - if (space) - array_strcat(&body, " "); - array_strcat(&body, ""); - - free(date); - free(hours); - free(in); -} - -void -cmd_ur(const char *line) -{ - /* move past "UR" */ - line += 2; + /* move past "URL" */ + line += 3; /* move past ' ', if present */ if (line[0] == ' ') line++; @@ -770,12 +742,12 @@ footer(void) array_strcat(&body, "\t\t