\n");
indentation++;
free(ind);
ind = NULL;
indent_str(&ind, indentation);
- string_cat(&body, ind);
- string_cat(&body, "
\n");
+ array_strcat(&body, ind);
+ array_strcat(&body, "
\n");
free(ind);
}
@@ -590,21 +592,21 @@ cmd_no(const char *line)
line += stread_param(line, &title);
if (space)
- string_cat(&body, " ");
+ array_strcat(&body, " ");
sprintf(index, "%u", add_note(href, desc));
- string_cat(&body, "
[");
- string_cat(&body, index);
- string_cat(&body, "]");
+ array_strcat(&body, ">[");
+ array_strcat(&body, index);
+ array_strcat(&body, "]");
free(desc);
free(href);
@@ -620,8 +622,8 @@ cmd_p(void)
indent_str(&ind, indentation);
- string_cat(&body, ind);
- string_cat(&body, "
");
+ array_strcat(&body, ind);
+ array_strcat(&body, "
");
strcpy(tag_closure, "
");
free(ind);
@@ -660,14 +662,14 @@ cmd_q(const char *line)
line += stread_param(line, &cite);
if (space)
- string_cat(&body, " ");
- string_cat(&body, "
");
+ array_strcat(&body, ">");
space = 0;
strcpy(tag_closure, "
");
@@ -678,9 +680,9 @@ cmd_q(const char *line)
void
cmd_st(const char *line)
{
- size_t len;
+ char *bodystr;
- len = strlen(body.str);
+ bodystr = body.data;
/* move past "ST" */
line += 2;
@@ -688,11 +690,11 @@ cmd_st(const char *line)
if (line[0] == ' ')
line++;
- if (space && len > 0 && body.str[len - 1] != '\'')
- string_cat(&body, " ");
- string_cat(&body, "
");
- string_cat(&body, line);
- string_cat(&body, "");
+ if (space && body.length > 0 && bodystr[body.length - 1] != '\'')
+ array_strcat(&body, " ");
+ array_strcat(&body, "
");
+ array_strcat(&body, line);
+ array_strcat(&body, "");
}
void
@@ -708,16 +710,16 @@ cmd_tm(const char *line)
line += stread_param(line, &in);
if (space)
- string_cat(&body, " ");
- string_cat(&body, "
");
+ array_strcat(&body, "\">");
+ array_strcat_html(&body, in, tag_content);
+ array_strcat(&body, "");
free(date);
free(hours);
@@ -734,12 +736,12 @@ cmd_ur(const char *line)
line++;
if (space)
- string_cat(&body, " ");
- string_cat(&body, "<
");
- string_cat_html(&body, line, tag_content);
- string_cat(&body, ">");
+ array_strcat(&body, " ");
+ array_strcat(&body, "<
");
+ array_strcat_html(&body, line, tag_content);
+ array_strcat(&body, ">");
}
void
@@ -766,20 +768,20 @@ footer(void)
max = 16;
- string_cat(&body, "\t\t
\n");
}
void
@@ -818,46 +820,47 @@ footnotes(void)
char id[NOTES_MAX_DIGITS + 1];
char pad[6 * (NOTES_MAX_DIGITS - 1) + 1];
- if (sitography.index == 0)
+ if (sitography.length == 0)
return;
- string_cat(&body, "\t\t
\n");
- string_cat(&body, "\t\t
\n");
- string_cat(&body, "\t\t\t
Sitografia
\n");
+ array_strcat(&body, "\t\t
\n");
+ array_strcat(&body, "\t\t
\n");
+ array_strcat(&body, "\t\t\t
Sitografia
\n");
- sprintf(id, "%u", sitography.index);
+ cur = sitography.data;
+ sprintf(id, "%u", sitography.length);
dig_num = strlen(id);
- for (i = 0; i < sitography.index; i++) {
- cur = sitography.notes + i;
+ for (i = 0; i < sitography.length; i++) {
sprintf(id, "%u", i + 1);
- string_cat(&body, "\t\t\t
");
+ array_strcat(&body, "\t\t\t");
strcpy(pad, "");
for (x = strlen(id); x < dig_num; x++)
strcat(pad, " ");
- string_cat(&body, pad);
- string_cat(&body, "");
- string_cat(&body, id);
- string_cat(&body, " ");
+ array_strcat(&body, pad);
+ array_strcat(&body, "");
+ array_strcat(&body, id);
+ array_strcat(&body, "
");
if (strcmp(cur->desc, "")) {
- string_cat_html(&body, cur->desc, tag_content);
- string_cat(&body, " ");
+ array_strcat_html(&body, cur->desc, tag_content);
+ array_strcat(&body, " ");
}
- string_cat(&body, "<href);
- string_cat(&body, "\">");
- string_cat_html(&body, cur->href, tag_content);
- string_cat(&body, ">
\n");
+ array_strcat(&body, "<
href);
+ array_strcat(&body, "\">");
+ array_strcat_html(&body, cur->href, tag_content);
+ array_strcat(&body, ">\n");
free(cur->desc);
free(cur->href);
+ cur++;
}
- free(sitography.notes);
+ free(sitography.data);
- string_cat(&body, "\t\t
\n");
+ array_strcat(&body, "\t\t
\n");
}
int
@@ -914,15 +917,6 @@ fread_line(FILE *file, char **str, size_t *len)
return c == EOF ? EOF : i;
}
-void
-free_closures(closures *dst)
-{
- int i;
-
- for (i = 0; i < dst->index; i++)
- free(dst->tags[i].name);
-}
-
void
indent_str(char **str, const int ind)
{
@@ -938,6 +932,17 @@ indent_str(char **str, const int ind)
(*str)[ind] = '\0';
}
+void
+array_init(array *a, const size_t size, size_t num)
+{
+ num = num == 0 ? 1 : num;
+
+ a->data = safe_malloc(size * num);
+ a->length = 0;
+ a->size = num;
+ a->unit_size = size;
+}
+
int
main (int argc, char *argv[])
{
@@ -968,23 +973,12 @@ main (int argc, char *argv[])
return 1;
}
- head.size = BODY_START_SIZE / 4;
- head.str = safe_malloc(sizeof(char) * head.size);
- strcpy(head.str, "");
+ array_init(&head, sizeof(char), BODY_START_SIZE / 4);
+ array_init(&body, sizeof(char), BODY_START_SIZE);
+ array_init(&index, sizeof(index_title), INDEX_START);
+ array_init(&sitography, sizeof(note), NOTES_START);
- body.size = BODY_START_SIZE;
- body.str = safe_malloc(sizeof(char) * body.size);
- strcpy(body.str, "");
-
- page_index.index = 0;
- page_index.size = INDEX_START;
- page_index.titles = safe_malloc(sizeof(index_title) * page_index.size);
-
- sitography.index = 0;
- sitography.size = NOTES_START;
- sitography.notes = malloc(sizeof(note) * sitography.size);
-
- string_cat(&body, "\t\n");
+ array_strcat(&body, "\t\n");
len = 0;
line = NULL;
@@ -1004,8 +998,8 @@ main (int argc, char *argv[])
line[0] != '.' &&
line[0] != ';' &&
line[0] != '?')
- string_cat(&body, " ");
- string_cat_html(&body, line, tag_content);
+ array_strcat(&body, " ");
+ array_strcat_html(&body, line, tag_content);
space = 1;
}
free(line);
@@ -1023,7 +1017,7 @@ main (int argc, char *argv[])
footnotes();
footer();
- string_cat(&body, "\t\n\n");
+ array_strcat(&body, "\t