");
else
{ LATEX_CLOSES_T(T_DESC)
LATEX_OPEN(tagnr)
}
else if (CLOSE_TAG(T_DD))
LATEX_CLOSES(tagnr)
else if (OPEN_TAG(T_A))
{ int j;
for (j = stack_depth - 1;
j >= 0 && stack[j].closing == C_OPT; j--)
if (stack[j].tagkind == T_A)
{ LATEX_CLOSES(H_A);
break;
}
if (a_href && href_status == REF_OKAY)
{ if (active_href && freport != NULL)
fprintf(freport,
"%s (%d) : nested href\n", html_fn, ln);
active_href = TRUE;
}
LATEX_OPEN_C(tagnr, a_href ? C_YES : C_OPT);
}
else if (CLOSE_TAG(T_A))
{
LATEX_CLOSES(tagnr)
}
else if (OPEN_TAG(T_VERB))
LATEX_OPEN(tagnr)
else if (CLOSE_TAG(T_VERB))
LATEX_CLOSES_K()
else if (OPEN_TAG(T_P))
{ if (stack[stack_depth-1].tagkind == T_P)
LATEX_CLOSES(H_P);
if (in_header && freport != NULL && option_info)
fprintf(freport, "%s (%d) : ignored in header\n",
html_fn, ln);
LATEX_OPEN(tagnr)
}
else if (CLOSE_TAG(T_P))
LATEX_CLOSES(tagnr)
else if (OPEN_TAG(T_CHAR))
{ int j;
bool found = FALSE;
for (j = stack_depth - 1; j >= 0; j--)
if (stack[j].tagnr == tagnr)
{ found = TRUE;
break;
}
if (found && j == stack_depth - 1)
{ REPLACE_TAG();
LATEX_CLOSES(tagnr)
}
else
{ if (found && freport != NULL)
fprintf(freport, "%s (%d) : nested <%s>\n",
html_fn, ln, html_com);
LATEX_OPEN(tagnr)
}
}
else if (CLOSE_TAG(T_CHAR))
LATEX_CLOSES(tagnr)
else if (OPEN_TAG(T_IMG))
;
else
{ if (freport != NULL)
fprintf(freport, "%s (%d) : tag %s not processed\n",
html_fn, ln, tags[tagnr].name);
}
}
}
/* read > and skip till first non-space */
if (ch != '\0' && ch == '>')
{
if ((ch = *s++) == '\n') ln++;
}
}
else if (freport == NULL)
{
if (first && !isspace(ch) && !in_header && !in_head)
{
if (cur_section == NULL)
{
add_section(in_file, 0);
cur_section->title = "";
cur_section->names = cur_names;
cur_names = NULL;
}
if (cur_names != NULL)
{ /* Introduce fake section */
add_section(in_file, 10);
cur_section->title = "";
cur_section->names = cur_names;
cur_names = NULL;
}
cur_section->has_text = TRUE;
}
if (in_header && ch != '\n' && i_st < 999) section_title[i_st++] = ch;
if ((ch = *s++) == '\n') ln++;
}
else
{
int ch_val = (ch + 256)%256;
bool skip = FALSE;
if (ch == '\n')
skip = TRUE;
else if (ch_val >= 160 && ch_val <= 255 &&
ch_table[ch-160] != NULL)
{
fprintf(freport,
"%s (%d) : Replace character %d by `&%s;'.\n",
html_fn, ln, ch_val, ch_table[ch_val-160]);
skip = TRUE;
}
else if (ch == '&')
{ int i = 0;
bool correct = FALSE;
char html_ch[10];
int v;
if (in_header && i_st < 999) section_title[i_st++] = ch;
if ((ch = *s++) == '\n') ln++;
if (isalpha(ch))
{
while (isalpha(ch))
{
if (i < 9)
html_ch[i++] = ch;
if (in_header && i_st < 999) section_title[i_st++] = ch;
if ((ch = *s++) == '\n') ln++;
}
html_ch[i] = '\0';
for (v = 0; v < NR_CH_TABLE; v++)
if ( ch_table[v] != NULL
&& !strcmp(html_ch, ch_table[v]))
{ correct = TRUE;
break;
}
if (ch == ';')
{
if (i < 9)
html_ch[i++] = ch;
html_ch[i] = '\0';
if (in_header && i_st < 999) section_title[i_st++] = ch;
if ((ch = *s++) == '\n') ln++;
}
else
fprintf(freport,
"%s (%d) : Place ';' after sequence `&%s'.\n",
html_fn, ln, html_ch);
if (!correct)
fprintf(freport,
"%s (%d) : Unknown sequence `&%s'.\n",
html_fn, ln, html_ch);
}
else if (ch == '#')
{ int code = 0;
if (in_header && i_st < 999) section_title[i_st++] = ch;
if ((ch = *s++) == '\n') ln++;
html_ch[i++] = '#';
while (isdigit(ch))
{
if (i < 9)
html_ch[i++] = ch;
code = code * 10 + ch - '0';
if (in_header && i_st < 999) section_title[i_st++] = ch;
if ((ch = *s++) == '\n') ln++;
}
html_ch[i] = '\0';
if (ch == ';')
{
if (i < 9)
html_ch[i++] = ch;
html_ch[i] = '\0';
if (in_header && i_st < 999) section_title[i_st++] = ch;
if ((ch = *s++) == '\n') ln++;
}
else
fprintf(freport,
"%s (%d) : Place ';' after sequence `&%s'.\n",
html_fn, ln, html_ch);
if ((code >= ' ' && code < 127))
{
fprintf(freport,
"%s (%d) : Replace sequence `&%s' by '%c'.\n",
html_fn, ln, html_ch, code);
}
else if (code >= 160 && code <= 255
&& ch_table[code-160] != 0)
{
fprintf(freport,
"%s (%d) : Replace sequence `&%s' by '&%s;'.\n",
html_fn, ln, html_ch, ch_table[code-160]);
}
else
fprintf(freport,
"%s (%d) : Unknown sequence `&%s;'.\n",
html_fn, ln, html_ch);
}
else
{
fprintf(freport,
"%s (%d) : Replace `&' by `&'.\n",
html_fn, ln - (ch == '\n'));
}
}
else if (ch == '>')
{ fprintf(freport,
"%s (%d) : Replace `>' by `>'.\n",
html_fn, ln);
skip = TRUE;
}
else if ((ch >= ' ' && ch_val < 127) || ch == '\t')
skip = TRUE;
else
{
fprintf(freport,
"%s (%d) : Unknown character %d (decimal)\n",
html_fn, ln, ch_val);
skip = TRUE;
}
if (skip)
if ((ch = *s++) == '\n') ln++;
}
}
/* In case no header occured, dump label */
while (stack_depth > 0)
{ if ( freport != NULL
&& (!option_pedantic || stack[stack_depth-1].tagnr != T_HTML))
fprintf(freport, "%s (%d) : add %s>.\n",
html_fn, ln,
tags[stack[stack_depth-1].tagnr].name);
latex_close(fout, freport, ln, html_fn);
}
#ifdef DEBUG_REFBY
if (first)
print_sections(in_file->sections);
#endif
}
void check_exists_file(char *html_fn, FILE *freport)
{
file_p in_file = find_file(html_fn);
if (in_file->exists)
in_file->exists = file_exists(html_fn);
if (!in_file->exists)
{ if (freport != NULL)
{
if (in_file->nr_refs > 1 || option_warn)
fprintf(freport, "%s (0) : does not exist\n", html_fn);
}
}
in_file->read |= R_READ;
in_file->read |= R_INCLUDED;
}
void scan_a_js_file(char *js_fn, FILE *freport)
{
file_p in_file = find_file(js_fn);
char *s = NULL, ch;
int ln = 1;
/*printf("Include JS file %s\n", js_fn);*/
s = get_contents(in_file, freport);
if (s == NULL)
return;
in_file->read |= R_READ;
in_file->read |= R_INCLUDED;
if ((ch = *s++) == '\n') ln++;
while(ch != '\0')
{
if (ch == '/' && *s == '/')
{
do
{ if ((ch = *s++) == '\n') ln++;
}
while (ch != '\0' && ch != '\n');
}
else if (ch == '"' || ch == '\'')
{ char fn[101];
int i = 0;
char quote = ch;
if ((ch = *s++) == '\n') ln++;
while (ch != quote && ch != '\0' && ch != '\n')
{ if (ch == '\\')
{ if ((ch = *s++) == '\n') ln++;
if (ch != '\0' && ch != '\n')
{ if (i < 100)
fn[i++] = ch;
if ((ch = *s++) == '\n') ln++;
}
}
else
{ if (i < 100)
fn[i++] = ch;
if ((ch = *s++) == '\n') ln++;
}
}
if (ch == quote)
if ((ch = *s++) == '\n') ln++;
fn[i] = '\0';
/*printf("Found string |%s|\n", fn);*/
if ( !strcmp(fn + strlen(fn) - 4, ".jpg")
|| !strcmp(fn + strlen(fn) - 4, ".gif"))
{ file_p img_file = find_file(fn);
if (img_file->read & R_INDIR)
img_file->read |= R_INCLUDED;
else if (!img_file->exists)
{ if (freport)
fprintf(freport, "%s (%d) : file '%s' does not exist.\n",
js_fn, ln, fn);
}
}
}
else
{ if ((ch = *s++) == '\n') ln++;
}
}
}
void accept_root_URL(URL, fout, freport) char *URL; FILE *fout, *freport;
{ int strlen_URL = strlen(URL);
document_URL = NALLOC(char, strlen_URL + 2);
strcpy(document_URL, URL);
if (document_URL[strlen_URL - 1] != '/')
{ document_URL[strlen_URL] = '/';
document_URL[strlen_URL + 1] = '\0';
}
server_URL = NULL;
{ int i;
for (i = 0; URL[i] != '\0' && URL[i] != ':'; i++);
if (URL[i] != '\0' && URL[i+1] == '/' && URL[i+2] == '/')
{ i += 3;
while (URL[i] != '\0' && URL[i] != '/')
i++;
if (URL[i] == '/')
file_URL = document_URL + i;
else
file_URL = "/";
URL[i] = '\0';
server_URL = SALLOC(URL);
strcpy(server_URL, URL);
}
}
if (server_URL == NULL)
{ if (freport != NULL)
fprintf(freport, " : illegal URL `%s'\n", document_URL);
document_URL = NULL;
}
}
void scan_not_included_files(freport, first, included)
FILE *freport; bool first, included;
{
if (first)
{ bool found = TRUE;
while (found)
{ file_p file = the_files;
found = FALSE;
while (file != NULL && !found)
{ DEBUG_P4("%s %d %d %d ",
file->name, file->exists, !(file->read & R_READ),
!is_URL(file->name));
DEBUG_P3("%d %d %d\n",
is_html(file->name),
file->name[0] != '.', file->name[1] != '.');
if ( file->exists && !(file->read & R_READ)
&& (file->read & R_DOREAD)
&& !is_URL(file->name)
&& (file->name[0] != '.' || file->name[1] != '.'))
found = TRUE;
else
file = file->next;
}
if (found)
{
if (is_html(file->name))
scan_a_file(file->name, NULL, freport, 1, first, included);
else if (!is_URL(file->name))
check_exists_file(file->name, freport);
}
}
}
else
{ file_p file = the_files;
for (file = the_files; file != NULL; file = file->next)
if ( (file->read & R_DOREAD)
&& !is_URL(file->name)
&& is_html(file->name)
&& (file->name[0] != '.' || file->name[1] != '.')
&& strcmp(file->name, "brexrefs.html"))
scan_a_file(file->name, NULL, freport, 1, first, FALSE);
else if ((file->read & R_INCLUDED) && is_js(file->name))
scan_a_js_file(file->name, freport);
}
}
void read_dir(void)
{
FILE *f;
char fn[400];
/*fprintf(stderr, "Scan directory\n");
system("dir \\www >\\www\\compare\\dir.txt");
fprintf(stderr, "Ready\n");*/
f = fopen("compare\\dir.txt", "r");
if (f==NULL)
return;
while (fgets(fn, 399, f))
{
file_p file;
if (fn[strlen(fn)-1]=='\n')
fn[strlen(fn)-1] = '\0';
if (fn[16] == ' ' && strlen(fn) >= 45)
{
char size[30];
file = find_file(fn+44);
file->read |= R_INDIR;
strncpy(size, fn+16, 6);
strncpy(size+6, fn+23, 3);
size[9] = '\0';
sscanf(size, "%ld", &file->size_local);
{
long int year, mon, day, hour, min;
char *d = fn+28;
char *t = strstr(d, ":") - 2;
year = (d[6] - '0')*10 + d[7] - '0';
year += (year < 50) ? 2000 : 1900;
if (t[5] == 'p' || t[5] == 'm')
{ mon = (d[0] - '0')*10 + d[1] - '0';
day = (d[3] - '0')*10 + d[4] - '0';
}
else
{ day = (d[0] - '0')*10 + d[1] - '0';
mon = (d[3] - '0')*10 + d[4] - '0';
}
hour = t[1] - '0';
if (t[0] != ' ') hour += (t[0] - '0')*10;
min = (t[3] - '0')*10 + t[4] - '0';
if (hour == 12 && t[5] == 'a') hour -= 12;
if (t[5] == 'p') hour += 12;
file->date_days = year * 10000 + mon * 100 + day;
file->date_mins = hour * 60 + min;
}
}
}
fclose(f);
}
int month_of(char *s)
{
static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
int i;
for (i = 0; i < 12; i++)
if (strncmp(s, months[i], 3) == 0)
return i+1;
return 0;
}
void add_size(long size, char *fn)
{
int l = strlen(fn);
char *ext = fn + strlen(fn);
while (ext > fn && *(ext-1) != '.') ext--;
if (!strcmp(fn + l - 6, "_c.txt"))
{
add_other_ext("C",size);
}
else if (!strcmp(fn + l - 8, "_pas.txt"))
{
add_other_ext("Pascal",size);
}
else
{
add_other_ext(ext, size);
}
}
void compare(bool execute)
{
FILE *fls = fopen("compare\\ls.txt", "r");
FILE *fout = fopen("cp2ftp.bat", "w");
char buffer[500];
time_t timeinsec;
struct tm timem;
file_p a_file;
long oldsize = 0L;
long sizecopied = 0L;
long newsize = 0L;
long removesize = 0L;
int i;
time(&timeinsec);
memcpy(&timem, localtime(&timeinsec), sizeof(struct tm));
while (fgets(buffer,499, fls))
{
if (buffer[0] == '-')
{
file_p file;
long size_ftp;
bool notincluded;
if (buffer[strlen(buffer)-1] == '\n')
buffer[strlen(buffer)-1] = '\0';
sscanf(buffer+21, "%ld", &size_ftp);
file = find_file(buffer+46);
file->on_ftp = TRUE;
notincluded = !(file->read & R_INCLUDED) && (file->read & R_INDIR)
&& file->exists;
if (file->size_local == -1 || notincluded)
{
printf("remove %s\n", file->name);
removesize += size_ftp;
/*add_size(-size_ftp, file->name);*/
}
else if ( !notincluded )
{
long int fyear, fmon, fday, fhour = 23, fmin = 59, fd=0, fm=0;
long int ld = file->date_days,
lm = file->date_mins;
char *d;
int newer = 0;
int diffsize = 0;
int picture = 0;
d = buffer + 33;
fmon = month_of(d);
fday = d[5] - '0';
if (d[4] != ' ') fday += (d[4] - '0')*10;
if ( d[9] == ':' )
{
fhour = d[8] - '0';
if (d[7] != ' ') fhour += (d[7] - '0')*10;
fmin = (d[10] - '0')*10 + d[11] - '0';
fyear = timem.tm_year;
if (fmon * 100 + fday > (timem.tm_mon+1) * 100 + timem.tm_mday)
fyear = fyear - 1;
fyear += 1900;
if (fyear < 1980)
fyear += 100;
}
else
{
sscanf(d+7, "%ld", &fyear);
}
fd = fyear * 10000 + fmon * 100 + fday;
fm = fhour * 60 + fmin;
/*printf("%s\n %ld %ld %ld %ld %ld %ld\n",
buffer, size_ftp, fyear, fmon, fday, fhour, fmin);
printf("%-15.15s %8ld %8ld %ld %ld\n",
file->name, ld, fd, lm, fm);*/
/*printf("%-30.30s", file->name);*/
oldsize += size_ftp > 0 ? size_ftp : 0;
newer = ld > fd || (ld == fd && lm > (fm + 60));
diffsize = size_ftp != file->size_local;
/*printf(" %s %s", newer ? "newer" : " ",
diffsize ? "diffsize" : " ");*/
picture = strcmp(file->name + strlen(file->name)-4, ".jpg") == 0;
if (!strcmp(file->name, "Fhome.html"))
newer = TRUE;
if (diffsize || (!picture && newer))
{
printf("copy %s", file->name);
if (diffsize) printf(" diffsize");
if (!picture && newer) printf(" newer");
printf("\n");
if (execute)
fprintf(fout, "copy \"%s\" \"ftp\\%s\"\n", file->name, file->name);
sizecopied += file->size_local;
newsize += file->size_local;
add_size(file->size_local, file->name);
}
else
{
newsize += size_ftp > 0 ? size_ftp : 0;
add_size(size_ftp > 0 ? size_ftp : 0, file->name);
}
/*printf("\n");*/
}
}
}
fclose(fls);
for (a_file = the_files; a_file != NULL ; a_file = a_file->next)
{
/*printf("New? %s %ld %d %d %d\n",
a_file->name, a_file->size_local,
a_file->on_ftp, a_file->read, a_file->exists);*/
if ( a_file->size_local >= 0 && !a_file->on_ftp)
{
bool notincluded = !(a_file->read & R_INCLUDED) && (a_file->read & R_INDIR)
&& a_file->exists;
if (!notincluded)
{
printf("copy %s new\n", a_file->name);
if (execute)
fprintf(fout, "copy \"%s\" \"ftp\\%s\"\n", a_file->name, a_file->name);
sizecopied += a_file->size_local;
newsize += a_file->size_local;
add_size(a_file->size_local, a_file->name);
}
}
}
printf("\n\nOld size %ld bytes, New size is %ld bytes\n",
oldsize, newsize);
printf("Have to copy %ld bytes\n", sizecopied);
printf("Could remove %ld bytes\n", removesize);
printf("Netto new size: %ld bytes\n", newsize - removesize);
printf("\n");
{
FILE *f = fopen("Fhome.html", "w");
file_p fhome_file = find_file("Fhome.html");
char *cont = fhome_file->contents;
char linebuf[1000];
char *start_stat = "";
char *end_stat = "";
if (f != NULL && cont != NULL && *cont != '\0')
{
linebuf[0] = '\0';
for(;*cont != '\0';)
{
int i;
for (i = 0; *cont != '\0' && *cont != '\n'; i++, cont++)
linebuf[i] = *cont;
linebuf[i] = '\0';
cont++;
if (!strcmp(linebuf, start_stat))
break;
fprintf(f, "%s\n", linebuf);
}
fprintf(f, "%s\n", linebuf);
fprintf(f, "consists of %d HTML-files", nr_ext_files("html"));
fprintf(f, " with a total size of %ld characters,\n", size_ext_files("html"));
fprintf(f, "having %ld internal links and %ld external links.\n",
nr_int_links, nr_ext_links + nr_broken_ext_links);
if (nr_broken_ext_links != 0)
fprintf(f, "(About %ld of the external links are broken.)\n",
nr_broken_ext_links);
fprintf(f, "Furthermore, it contains %d C program files ", nr_ext_files("C"));
fprintf(f, "with a total size of %ld characters,\n", size_ext_files("C"));
fprintf(f, "and %d PASCAL program files ", nr_ext_files("Pascal"));
fprintf(f, "with a total size of %ld characters.\n", size_ext_files("Pascal"));
fprintf(f, "There are %d text files with a total size of %ld characters.\n",
nr_ext_files("txt"), size_ext_files("txt"));
fprintf(f, "With respect to images, this site containts %d GIF images\n"
"(total size %ld bytes), and %d JPEG images (total size %ld bytes).\n",
nr_ext_files("gif"), size_ext_files("gif"),
nr_ext_files("jpg"), size_ext_files("jpg"));
fprintf(f, "With respect to sounds, it contains %d WAV files\n"
"with a total size of %ld bytes.\n",
nr_ext_files("wav"), size_ext_files("wav"));
fprintf(f, "It also contains %d PostScript files (total size %ld bytes),\n",
nr_ext_files("ps") + nr_ext_files("eps"),
size_ext_files("ps") + size_ext_files("eps"));
fprintf(f, "%d LaTeX files (total size %ld characters), and\n",
nr_ext_files("tex"), size_ext_files("tex"));
fprintf(f, "%d gzipped tar files (total size %ld bytes).\n",
nr_ext_files("tgz"), size_ext_files("tgz"));
fprintf(f, "It also uses %d JavaScript files with \n"
"code with a total size of %ld bytes.\n",
nr_ext_files("js"), size_ext_files("js"));
for(;;)
{
int i;
for (i = 0; *cont != '\0' && *cont != '\n'; i++, cont++)
linebuf[i] = *cont;
linebuf[i] = '\0';
cont++;
if (!strcmp(linebuf, end_stat))
break;
}
fprintf(f, "%s\n", linebuf);
for (; *cont != '\0'; cont++)
fprintf(f, "%c", *cont);
fclose(f);
}
}
for (i = 0; i < nr_other_ext; i++)
if (other_ext_nr[i] > 1)
printf("%ld bytes in %d \"%s\"-files.\n",
other_ext_size[i], other_ext_nr[i], other_ext_name[i]);
else
printf("%ld bytes in one \"%s\"-file.\n",
other_ext_size[i], other_ext_name[i]);
printf("\n\n");
fclose(fout);
}
bool is_oneway(section_p sect)
{
for (; sect; sect = sect->parent)
if (sect->oneway)
return TRUE;
return FALSE;
}
void build_refered_by()
{ file_p file;
/* For all files */
for (file = the_files; file; file = file->next)
{
/* For all sections in these files */
section_p section;
for (section = file->sections; section; next_section(§ion, NULL))
if (!is_oneway(section))
{
/* For all links in those sections */
href_p href;
for (href = section->hrefs; href; href = href->next)
{
section_p refered_section = NULL;
/* Determine the section being linked to: */
if (href->name != NULL)
refered_section = section_with_name(href->file->sections,
href->name);
else
refered_section = href->file->sections;
/* Make a direct reference in the link to the section: */
href->section = refered_section;
/* Add the section of the file to the referenced section in the link: */
if (refered_section)
{ section_list_p *r_section_list = &refered_section->refered_by;
#ifdef DEBUG_REFBY
printf("%s.%s -> %ld %s.%s\n",
href->file->name, href->name,
(long)refered_section,
refered_section->file->name,
refered_section->names ? refered_section->names->name : "(null)");
#endif
while ((*r_section_list)
&& (*r_section_list)->section != section)
r_section_list = &(*r_section_list)->next;
if (*r_section_list == NULL)
{ *r_section_list = ALLOC(section_list_t);
(*r_section_list)->next = NULL;
(*r_section_list)->section = section;
}
}
}
}
}
}
void print_file_section(file_p file, section_p section)
{
static section_p cur_section = NULL;
if (section != cur_section)
{
if (cur_section != NULL && cur_section->file != file)
printf("\n");
printf("In file %s", file->name);
if (section->names)
printf(", at line %ld", section->names->line);
if (section->title[0] != '\0')
printf(", in section '%s'", section->title);
printf(":\n");
cur_section = section;
}
}
#ifdef DEBUG_REFBY
void print_section(section_p section)
{
if (section == NULL)
printf("[NULL]");
else
printf("[%ld %s'%s']", (long)section,
section->file && section->file->name ? section->file->name : "",
section->title);
}
#endif
int cur_level;
void set_level_found(int level)
{
#ifdef DEBUG_REFBY
printf("%*.*s #set\n", level*2, level*2, "");
#endif
if (level < cur_level)
cur_level = level;
}
void check_section_or_parent(section_p from, section_p to, int level)
{
#ifdef DEBUG_REFBY
printf("%*.*s check_section_or_parent ", level*2, level*2, "");
print_section(from);
print_section(to);
printf("\n");
#endif
if (from == to)
{ set_level_found(level);
return;
}
if (from->file == to->file)
{
for (to = to->parent; to; to = to->parent)
{ if (++level >= cur_level)
return;
#ifdef DEBUG_REFBY
printf("%*.*s = parent ", level*2, level*2, "");
print_section(to);
printf("\n");
#endif
if (from == to)
{ set_level_found(level);
return;
}
}
}
}
void search_my_parents(section_p from, section_p to, int level)
{
section_p parent;
#ifdef DEBUG_REFBY
printf("%*.*s search_my_parents ", level*2, level*2, "");
print_section(from);
print_section(to);
printf("\n");
#endif
for (parent = from->parent; parent; parent = parent->parent)
{ if (++level >= cur_level)
return;
#ifdef DEBUG_REFBY
printf("%*.*s = parent ", level*2, level*2, "");
print_section(parent);
printf("\n");
#endif
if (parent == to)
{ set_level_found(level);
return;
}
}
}
void search_subsections(section_p from, section_p to, int level)
{
#ifdef DEBUG_REFBY
printf("%*.*s search_subsections ", level*2, level*2, "");
print_section(from);
print_section(to);
printf("\n");
#endif
if (level >= cur_level)
return;
{ href_p href;
for (href = from->hrefs; href; href = href->next)
if (href->section)
check_section_or_parent(href->section, to, level);
}
/* check all sub section for the same: */
{ section_p nested;
for (nested = from->nested; nested; nested = nested->next)
search_subsections(nested, to, level+1);
}
}
void search_parents(section_p from, section_p to, int level)
{
#ifdef DEBUG_REFBY
printf("%*.*s search_parents ", level*2, level*2, "");
print_section(from);
print_section(to);
printf("\n");
#endif
for (; from; from = from->parent)
{ if (++level >= cur_level)
return;
{ href_p href;
for (href = from->hrefs; href; href = href->next)
{
if (level >= cur_level)
return;
if (href->section)
check_section_or_parent(href->section, to, level);
}
}
}
}
void search_chain(section_p from, section_p to, int level)
{
#ifdef DEBUG_REFBY
printf("%*.*s search_chain ", level*2, level*2, "");
print_section(from);
print_section(to);
printf("\n");
#endif
if (level >= cur_level)
return;
{ href_p href;
for (href = from->hrefs; href; href = href->next)
if (href->section)
{ check_section_or_parent(href->section, to, level);
search_chain(href->section, to, level+3);
}
}
}
int search_for_reference_to(section_p from, section_p to)
{
cur_level = 10;
search_my_parents(from, to, 1);
search_subsections(from, to, 1);
search_parents(from, to, 1);
search_chain(from, to, 1);
return cur_level;
}
void analyze_all_sections()
{ file_p file;
/* For all files */
for (file = the_files; file; file = file->next)
{
/* For all sections in these files */
section_p section;
/* print_sections(file->sections); */
for (section = file->sections; section; next_section(§ion, NULL))
{ name_p name;
section_list_p refered_by;
int c = 0;
#ifdef DEBUG_REFBY
printf("Analyzing section: "); print_section(section); printf("\n");
#endif
if (section->level == 10 && 0)
{
print_file_section(file, section);
printf("- Name %s has no section title\n", section->names->name);
}
for (name = section->names; name; name = name->next)
{
if (!(name->status & NAME_REFERENCED))
{
print_file_section(file, section);
printf("- Name %s is not referenced\n", name->name);
}
c++;
}
if (c > 1)
{
print_file_section(file, section);
printf("- Has more than one name\n");
}
if (section->hrefs != NULL && option_warn)
{
section_p sect = section;
while (sect->names == NULL
&& sect->parent != NULL && !sect->parent->has_text)
sect = sect->parent;
if (sect->names == NULL)
{
print_file_section(file, section);
printf("- Might add name to section\n");
}
}
/* For all of the sections that link to this section: */
for (refered_by = section->refered_by; refered_by; refered_by = refered_by->next)
{ section_p ref_by_sect;
int level;
/* Determine the section that should be referenced */
ref_by_sect = refered_by->section;
while (ref_by_sect->parent != NULL &&
ref_by_sect->names == NULL)
ref_by_sect = ref_by_sect->parent;
#ifdef DEBUG_REFBY
printf(" Section that needs to be referenced: "); print_section(ref_by_sect); printf("\n");
#endif
level = search_for_reference_to(section, ref_by_sect);
#ifdef DEBUG_REFBY
if (level != 10)
{
print_file_section(file, section);
printf(" Has level %d return reference to %s '%s'\n",
level,
refered_by->section->file->name,
refered_by->section->title);
}
#endif
/*
if (level == 10 && streq(refered_by->section->file->name, "brexrefs.html"))
level = -2;
*/
if (level == 10)
{ section_p sect;
print_file_section(file, section);
printf("section->file->name);
for (sect = refered_by->section; sect; sect = sect->parent)
if (sect->names)
break;
if (sect && sect->names)
printf("#%s", sect->names->name);
printf("\">");
if (refered_by->section->parent != NULL &&
!refered_by->section->parent->has_text)
printf("%s: ", refered_by->section->parent->title);
printf("%s ", refered_by->section->title);
printf("\n");
}
}
}
}
}
int main(argc, argv)
int argc;
char **argv;
{ FILE *fin;
char *fn = NULL,
*html_fn,
*outfn = NULL,
*reffn;
bool option_scan_not_inc = FALSE,
option_cross_ref = FALSE,
option_compare = FALSE,
option_compare_copy = FALSE;
/* global options */
option_info = FALSE;
option_warn = FALSE;
option_pedantic = FALSE;
option_bibliography = FALSE;
printf("%s: Version %s\nWritten by %s\n\n",
"chkhtml", VERSION, WRITTEN_BY);
{ int i;
bool error = FALSE;
for (i = 1; i < argc; i++)
{ if (argv[i][0] == '-')
{ if (argv[i][1] == 'o')
{ if (argv[i][2] != '\0')
outfn = argv[i] + 2;
else if (i + 1 < argc)
outfn = argv[++i];
else
printf("Argument of -o option missing\n");
}
else if (argv[i][1] == 'i' && argv[i][2] == '\0')
{ option_warn = TRUE;
option_info = TRUE;
}
else if (argv[i][1] == 'w' && argv[i][2] == '\0')
option_warn = TRUE;
else if (argv[i][1] == 'p' && argv[i][2] == '\0')
option_pedantic = TRUE;
else if (argv[i][1] == 's' && argv[i][2] == '\0')
{
option_scan_not_inc = TRUE;
option_compare = TRUE;
option_compare_copy = TRUE;
}
else if (argv[i][1] == 'r')
{ if (argv[i][2] != '\0')
accept_root_URL(argv[i] + 2, stdout, NULL);
else if (i + 1 < argc)
accept_root_URL(argv[++i], stdout, NULL);
else
printf("Argument of -r option missing\n");
}
else if (argv[i][1] == 'b' && argv[i][2] == '\0')
option_bibliography = TRUE;
#ifdef DYN_DEBUG
else if (argv[i][1] == 'd')
option_debug = TRUE;
#endif
else if (streq(argv[i], "-cr"))
option_cross_ref = TRUE;
else
{ printf("Unknown option %s\n", argv[i]);
error = TRUE;
}
}
else if (fn == NULL)
fn = argv[i];
else
{ printf("Too many input filenames\n");
error = TRUE;
}
}
if (fn == NULL)
{ printf("No input filename given\n");
error = TRUE;
}
else
{ fin = fopen(fn, "r");
if (fin == NULL)
{ printf("Error: Cannot open file: `%s'.\n", fn);
error = TRUE;
}
}
if (error)
{ printf("Usages: html2tex [options] \n");
printf("\nOptions:\n");
printf(" -o : specify output file\n");
printf(" -i : print info\n");
printf(" -w : print warnings (and info)\n");
printf(" -r : root URL of document\n");
printf(" -b : make bibliography\n");
printf(" -cr : generate cross-reference\n");
printf(" -c : check html file\n");
printf(" -s : scan not included files\n");
#ifdef DYN_DEBUG
printf(" -d : print (a lot of) debugging information\n");
#endif
return 1;
}
if (streq(fn + strlen(fn) - 5, ".html"))
{ is_html_fn = TRUE;
html_fn = SALLOC(fn);
strcpy(html_fn, fn);
fn[strlen(fn) - 5] = '\0';
}
}
reffn = NALLOC(char, strlen(fn) + 5);
strcpy(reffn, fn);
strcat(reffn, ".ref");
read_dir();
f_ext_dest = fopen("compare\\ext_dest.txt", "w");
f_broken_ext_dest = fopen("compare\\broken_ext_dest.txt", "w");
scan_a_file(html_fn, (FILE *)NULL, (FILE *)NULL, 0, TRUE, TRUE);
if (option_scan_not_inc)
scan_not_included_files(NULL, TRUE, is_html_fn);
{ file_p file;
for (file = the_files; file != NULL; file = file->next)
file->read &= ~R_READ;
}
fclose(f_ext_dest);
fclose(f_broken_ext_dest);
rewind(fin);
nr_other_ext = 0;
nr_int_links = 0;
nr_ext_links = 0;
nr_broken_ext_links = 0;
scan_a_file(html_fn, (FILE *)NULL, stdout, 0, FALSE, TRUE);
if (option_scan_not_inc)
{ file_p file;
scan_not_included_files(stdout, FALSE, is_html_fn);
for (file = the_files; file != NULL; file = file->next)
if (!(file->read & R_INCLUDED) && (file->read & R_INDIR)
&& file->exists)
printf("%s (0) : not included\n", file->name);
}
DEBUG_PRINT(("ready reading\n"));
DEBUG_PRINT(("\n\n\n"));
if (option_compare)
compare(option_compare_copy);
build_refered_by();
analyze_all_sections();
return 0;
}