HTML command names

This commit is contained in:
Matteo Bini 2024-08-26 15:26:22 +02:00
parent 3dcf820a24
commit 337061a3f4
1 changed files with 76 additions and 104 deletions

180
srohtml.c
View File

@ -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, "<time datetime=\"");
array_strcat(&body, date);
if (strcmp(hours, "")) {
array_strcat(&body, "T");
array_strcat(&body, hours);
}
array_strcat(&body, "\">");
array_strcat_html(&body, in, tag_content);
array_strcat(&body, "</time>");
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<footer>\n");
if (pub_date != NULL) {
if (publication_date != NULL) {
array_strcat(&body, "\t\t\t<p>Pubblicazione: <time datetime=\"");
array_strcat(&body, pub_date);
array_strcat(&body, publication_date);
array_strcat(&body, "\">");
sscanf(pub_date, "%4i-%2i-%2i", &tm_year, &tm_mon, &tm_mday);
sscanf(publication_date, "%4i-%2i-%2i", &tm_year, &tm_mon, &tm_mday);
tm_pd.tm_mday = tm_mday;
tm_pd.tm_mon = --tm_mon;
tm_pd.tm_year = tm_year - 1900;
@ -783,7 +755,7 @@ footer(void)
array_strcat(&body, str);
array_strcat(&body, "</time></p>\n");
free(pub_date);
free(publication_date);
}
s = time(NULL);
@ -858,7 +830,6 @@ footnotes(void)
free(cur->href);
cur++;
}
free(sitography.data);
array_strcat(&body, "\t\t</div>\n");
}
@ -1049,6 +1020,8 @@ main (int argc, char *argv[])
free(head.data);
free(body.data);
free(index.data);
free(sitography.data);
return 0;
}
@ -1145,7 +1118,6 @@ nav_index(FILE *f)
fputs("</nav>\n", f);
free(nav_cls.data);
free(index.data);
}
void