Publication date as pointer

This commit is contained in:
Matteo Bini 2024-07-15 17:07:06 +02:00
parent e54e680d3e
commit 31f41d2485
1 changed files with 23 additions and 20 deletions

View File

@ -75,7 +75,7 @@ int licence_container = 0;
int space = 0;
string head;
string body;
char pub_date[DATE_LEN + 1] = "";
char *pub_date = NULL;
references sitography;
char *title = NULL;
@ -385,19 +385,21 @@ cmd_p(void)
void
cmd_pd(const char *line)
{
size_t len;
/* move past "PD" */
line += 2;
len = strlen(line);
/* move past ' ' after PD */
if (len && line[0] == ' ') {
/* move past ' ', if present */
if (line[0] == ' ')
line++;
len--;
if (len == DATE_LEN)
strncpy(pub_date, line, DATE_LEN);
if (strlen(line) != DATE_LEN)
return;
if (pub_date == NULL) {
pub_date = safe_malloc(sizeof(char) * (DATE_LEN + 1));
pub_date[DATE_LEN] = '\0';
}
strncpy(pub_date, line, DATE_LEN);
}
void
@ -477,7 +479,7 @@ footer(void)
string_cat(&body, "\t\t<footer>\n");
if (strcmp(pub_date, "")) {
if (pub_date != NULL) {
string_cat(&body, "\t\t\t<p>Pubblicazione: <time datetime=\"");
string_cat(&body, pub_date);
string_cat(&body, "\">");
@ -489,6 +491,8 @@ footer(void)
strftime(str, max, "%x", &tm_pd);
string_cat(&body, str);
string_cat(&body, "</time></p>\n");
free(pub_date);
}
s = time(NULL);
@ -705,6 +709,8 @@ page_head(void)
string_cat(&head, " lang=\"");
string_cat_html(&head, language, 1);
string_cat(&head, "\"");
free(language);
}
string_cat(&head, ">\n");
@ -718,12 +724,16 @@ page_head(void)
string_cat(&head, "\t\t<meta name=\"author\" content=\"");
string_cat_html(&head, author, 1);
string_cat(&head, "\">\n");
free(author);
}
if (description != NULL) {
string_cat(&head, "\t\t<meta name=\"description\" content=\"");
string_cat_html(&head, description, 1);
string_cat(&head, "\">\n");
free(description);
}
string_cat(&head, "\t\t<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n");
@ -806,18 +816,11 @@ page_head(void)
string_cat(&head, "\t\t<title>");
string_cat_html(&head, title, 0);
string_cat(&head, "</title>\n");
free(title);
}
string_cat(&head, "\t</head>\n");
if (author != NULL)
free(author);
if (description != NULL)
free(description);
if (language != NULL)
free(language);
if (title != NULL)
free(title);
}
void