\n");
indentation++;
free(ind);
ind = NULL;
- indent_str(&ind);
+ indent_str(&ind, indentation);
string_cat(&body, ind);
string_cat(&body, "
\n");
@@ -435,7 +551,7 @@ cmd_no(const char *line)
string_cat(&body, "\"");
if (strcmp(title, "")) {
string_cat(&body, " title=\"");
- string_cat_html(&body, title, 1);
+ string_cat_html(&body, title, tag_attribute);
string_cat(&body, "\"");
}
string_cat(&body, ">[");
@@ -454,11 +570,11 @@ cmd_p(void)
ind = NULL;
- indent_str(&ind);
+ indent_str(&ind, indentation);
string_cat(&body, ind);
string_cat(&body, "
");
- strcpy(closure, "
");
+ strcpy(tag_closure, "");
free(ind);
}
@@ -500,12 +616,12 @@ cmd_q(const char *line)
string_cat(&body, "
");
space = 0;
- strcpy(closure, "
");
+ strcpy(tag_closure, "");
free(cite);
@@ -514,13 +630,17 @@ cmd_q(const char *line)
void
cmd_st(const char *line)
{
+ size_t len;
+
+ len = strlen(body.str);
+
/* move past "ST" */
line += 2;
/* move past space, if present */
if (line[0] == ' ')
line++;
- if (space && body.str[body.len - 1] != '\'')
+ if (space && len > 0 && body.str[len - 1] != '\'')
string_cat(&body, " ");
string_cat(&body, "
");
string_cat(&body, line);
@@ -548,7 +668,7 @@ cmd_tm(const char *line)
string_cat(&body, hours);
}
string_cat(&body, "\">");
- string_cat_html(&body, in, 0);
+ string_cat_html(&body, in, tag_content);
string_cat(&body, "");
free(date);
@@ -568,12 +688,24 @@ cmd_ur(const char *line)
if (space)
string_cat(&body, " ");
string_cat(&body, "<");
- string_cat_html(&body, line, 0);
+ string_cat_html(&body, line, tag_content);
string_cat(&body, ">");
}
+void
+findent(const int ind, FILE *f)
+{
+ char *str;
+
+ str = NULL;
+
+ indent_str(&str, ind);
+ fputs(str, f);
+ free(str);
+}
+
void
footer(void)
{
@@ -620,10 +752,10 @@ footer(void)
string_cat(&body, "\">");
strftime(str, max, "%x", now);
- string_cat_html(&body, str, 0);
+ string_cat_html(&body, str, tag_content);
strftime(str, max, " %R", now);
- string_cat_html(&body, str, 0);
+ string_cat_html(&body, str, tag_content);
string_cat(&body, "\n");
string_cat(&body, "\t\t\n");
@@ -633,7 +765,8 @@ void
footnotes(void)
{
note *cur;
- size_t i, dig_num, x;
+ int i;
+ size_t dig_num, x;
char id[NOTES_MAX_DIGITS + 1];
char pad[6 * (NOTES_MAX_DIGITS - 1) + 1];
@@ -663,13 +796,13 @@ footnotes(void)
string_cat(&body, id);
string_cat(&body, " ");
if (strcmp(cur->desc, "")) {
- string_cat_html(&body, cur->desc, 0);
+ string_cat_html(&body, cur->desc, tag_content);
string_cat(&body, " ");
}
string_cat(&body, "<href);
string_cat(&body, "\">");
- string_cat_html(&body, cur->href, 0);
+ string_cat_html(&body, cur->href, tag_content);
string_cat(&body, ">\n");
free(cur->desc);
free(cur->href);
@@ -679,6 +812,33 @@ footnotes(void)
string_cat(&body, "\t\t \n");
}
+int
+fputs_html(const char *str, FILE *f, const html_val_type t)
+{
+ size_t i, len;
+ int res;
+
+ len = strlen(str);
+ res = 0;
+
+ for (i = 0; i < len; i++) {
+ if (res == EOF)
+ return EOF;
+ if (t == tag_attribute && str[i] == '"')
+ res = fputs(""", f);
+ else if (str[i] == '&')
+ res = fputs("&", f);
+ else if (str[i] == '<')
+ res = fputs("<", f);
+ else if (str[i] == '>')
+ res = fputs(">", f);
+ else
+ res = fputc(str[i], f);
+ }
+
+ return 1;
+}
+
size_t
fread_line(FILE *file, char **str, size_t *len)
{
@@ -707,14 +867,23 @@ fread_line(FILE *file, char **str, size_t *len)
}
void
-indent_str(char **str)
+free_closures(closures *dst)
{
int i;
- *str = safe_malloc(sizeof(char) * (indentation + 1));
- for (i = 0; i < indentation; i++)
+ for (i = 0; i < dst->index; i++)
+ free(dst->tags[i].name);
+}
+
+void
+indent_str(char **str, const int ind)
+{
+ int i;
+
+ *str = safe_malloc(sizeof(char) * (ind + 1));
+ for (i = 0; i < ind; i++)
(*str)[i] = '\t';
- (*str)[indentation] = '\0';
+ (*str)[ind] = '\0';
}
int
@@ -748,21 +917,23 @@ main (int argc, char *argv[])
}
head.size = BODY_START_SIZE / 4;
- head.str = safe_malloc(head.size);
+ head.str = safe_malloc(sizeof(char) * head.size);
strcpy(head.str, "");
- head.len = 0;
body.size = BODY_START_SIZE;
- body.str = safe_malloc(body.size);
+ body.str = safe_malloc(sizeof(char) * body.size);
strcpy(body.str, "");
- body.len = 0;
- string_cat(&body, "\t\n");
+ 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");
+
len = 0;
line = NULL;
while (fread_line(in, &line, &len) != EOF) {
@@ -782,7 +953,7 @@ main (int argc, char *argv[])
line[0] != ';' &&
line[0] != '?')
string_cat(&body, " ");
- string_cat_html(&body, line, 0);
+ string_cat_html(&body, line, tag_content);
space = 1;
}
free(line);
@@ -793,7 +964,7 @@ main (int argc, char *argv[])
if (in != stdin)
fclose(in);
- if (strcmp(closure, ""))
+ if (strcmp(tag_closure, ""))
cmd_close();
page_head();
@@ -812,12 +983,104 @@ main (int argc, char *argv[])
}
fputs(head.str, out);
- fputs(body.str, out);
+
+ {
+ char c;
+ c = body.str[index_position];
+ body.str[index_position] = '\0';
+ fputs(body.str, out);
+ if (index_position)
+ nav_index(out);
+ body.str[index_position] = c;
+ fputs(body.str + index_position, out);
+ }
+
fclose(out);
return 0;
}
+void
+nav_index(FILE *f)
+{
+ int i, n;
+ int ind;
+ closure *tag;
+ closures nav_cls;
+ index_title *next_title, *title;
+
+ ind = 2;
+ nav_cls.index = 0;
+ nav_cls.size = 4;
+ nav_cls.tags = safe_malloc(sizeof(closure) * nav_cls.size);
+ tag = NULL;
+
+ findent(ind++, f);
+ fputs("