Attempt to fix tell m-w
This commit is contained in:
@@ -29,7 +29,8 @@ all: $(BINDIR)/asciipasswd \
|
|||||||
$(BINDIR)/shopconv \
|
$(BINDIR)/shopconv \
|
||||||
$(BINDIR)/sign \
|
$(BINDIR)/sign \
|
||||||
$(BINDIR)/split \
|
$(BINDIR)/split \
|
||||||
$(BINDIR)/wld2html
|
$(BINDIR)/wld2html \
|
||||||
|
$(BINDIR)/webster
|
||||||
|
|
||||||
asciipasswd: $(BINDIR)/asciipasswd
|
asciipasswd: $(BINDIR)/asciipasswd
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
pid = atoi(argv[2]);
|
pid = atoi(argv[2]);
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf),
|
snprintf(buf, sizeof(buf),
|
||||||
"lynx -accept_all_cookies -source http://www.thefreedictionary.com/%s"
|
"lynx -accept_all_cookies -source http://www.thefreedictionary.com/%s"
|
||||||
" >webster.html", argv[1]);
|
" >webster.html", argv[1]);
|
||||||
system(buf);
|
system(buf);
|
||||||
@@ -41,9 +41,9 @@ int main(int argc, char **argv)
|
|||||||
void parse_webster_html(char *arg) {
|
void parse_webster_html(char *arg) {
|
||||||
FILE *infile, *outfile;
|
FILE *infile, *outfile;
|
||||||
char scanbuf[MEM_USE], outline[MEM_USE], *p, *q;
|
char scanbuf[MEM_USE], outline[MEM_USE], *p, *q;
|
||||||
|
|
||||||
outfile = fopen("websterinfo", "w");
|
outfile = fopen("websterinfo", "w");
|
||||||
if (!outfile)
|
if (!outfile)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
infile = fopen("webster.html", "r");
|
infile = fopen("webster.html", "r");
|
||||||
@@ -54,13 +54,13 @@ void parse_webster_html(char *arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unlink("webster.html"); /* We can still read */
|
unlink("webster.html"); /* We can still read */
|
||||||
|
|
||||||
for ( ; get_line(infile, buf)!=0; ) {
|
for ( ; get_line(infile, buf)!=0; ) {
|
||||||
|
|
||||||
if (strncmp(buf, "<script>write_ads(AdsNum, 0)</script>", 37) != 0)
|
if (strncmp(buf, "<script>write_ads(AdsNum, 0, 1)</script>", 40) != 0)
|
||||||
continue; // read until we hit the line with results in it.
|
continue; // read until we hit the line with results in it.
|
||||||
|
|
||||||
p = buf+37;
|
p = buf+40;
|
||||||
|
|
||||||
if (strncmp(p, "<br>", 4) == 0)
|
if (strncmp(p, "<br>", 4) == 0)
|
||||||
{
|
{
|
||||||
@@ -71,9 +71,9 @@ void parse_webster_html(char *arg) {
|
|||||||
{
|
{
|
||||||
while (strncmp(p, "ds-list", 7)) //seek to the definition
|
while (strncmp(p, "ds-list", 7)) //seek to the definition
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
strncpy(scanbuf, p, sizeof(scanbuf)); // strtok on a copy.
|
strncpy(scanbuf, p, sizeof(scanbuf)); // strtok on a copy.
|
||||||
|
|
||||||
p = strtok(scanbuf, ">"); // chop the line at the end of tags: <br><b>word</b> becomes "<br" "<b" "word</b"
|
p = strtok(scanbuf, ">"); // chop the line at the end of tags: <br><b>word</b> becomes "<br" "<b" "word</b"
|
||||||
p = strtok(NULL, ">"); // skip the rest of this tag.
|
p = strtok(NULL, ">"); // skip the rest of this tag.
|
||||||
|
|
||||||
@@ -82,51 +82,51 @@ void parse_webster_html(char *arg) {
|
|||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
q = outline;
|
q = outline;
|
||||||
|
|
||||||
while (*p != '<')
|
while (*p != '<')
|
||||||
{
|
{
|
||||||
assert(p < scanbuf+sizeof(scanbuf));
|
assert(p < scanbuf+sizeof(scanbuf));
|
||||||
*q++ = *p++;
|
*q++ = *p++;
|
||||||
}
|
}
|
||||||
if (!strncmp(p, "<br", 3) || !strncmp(p, "<p", 2) || !strncmp(p, "<div class=\"ds-list\"", 23) || !strncmp(p, "<div class=\"sds-list\"", 24))
|
if (!strncmp(p, "<br", 3) || !strncmp(p, "<p", 2) || !strncmp(p, "<div class=\"ds-list\"", 23) || !strncmp(p, "<div class=\"sds-list\"", 24))
|
||||||
*q++ = '\n';
|
*q++ = '\n';
|
||||||
// if it's not a <br> tag or a <div class="sds-list"> or <div class="ds-list"> tag, ignore it.
|
// if it's not a <br> tag or a <div class="sds-list"> or <div class="ds-list"> tag, ignore it.
|
||||||
|
|
||||||
*q++='\0';
|
*q++='\0';
|
||||||
fprintf(outfile, "%s", outline);
|
fprintf(outfile, "%s", outline);
|
||||||
|
|
||||||
if (!strncmp(p, "</table", 7))
|
if (!strncmp(p, "</table", 7))
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
p = strtok(NULL, ">");
|
p = strtok(NULL, ">");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strncmp(p, "<div>", 5) == 0) // not found, but suggestions are ample:
|
else if (strncmp(p, "<div>", 5) == 0) // not found, but suggestions are ample:
|
||||||
{
|
{
|
||||||
strncpy(scanbuf, p, sizeof(scanbuf)); // strtok on a copy.
|
strncpy(scanbuf, p, sizeof(scanbuf)); // strtok on a copy.
|
||||||
|
|
||||||
p = strtok(scanbuf, ">"); // chop the line at the end of tags: <br><b>word</b> becomes "<br>" "<b>" "word</b>"
|
p = strtok(scanbuf, ">"); // chop the line at the end of tags: <br><b>word</b> becomes "<br>" "<b>" "word</b>"
|
||||||
p = strtok(NULL, ">"); // skip the rest of this tag.
|
p = strtok(NULL, ">"); // skip the rest of this tag.
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
q = outline;
|
q = outline;
|
||||||
|
|
||||||
while (*p != '<')
|
while (*p != '<')
|
||||||
*q++ = *p++;
|
*q++ = *p++;
|
||||||
|
|
||||||
if (!strncmp(p, "<td ", 4))
|
if (!strncmp(p, "<td ", 4))
|
||||||
*q++ = '\n';
|
*q++ = '\n';
|
||||||
// if it's not a <td> tag, ignore it.
|
// if it's not a <td> tag, ignore it.
|
||||||
|
|
||||||
*q++='\0';
|
*q++='\0';
|
||||||
fprintf(outfile, "%s", outline);
|
fprintf(outfile, "%s", outline);
|
||||||
|
|
||||||
if (!strncmp(p, "</table", 7))
|
if (!strncmp(p, "</table", 7))
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
p = strtok(NULL, ">");
|
p = strtok(NULL, ">");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -137,16 +137,16 @@ void parse_webster_html(char *arg) {
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
fclose(infile);
|
fclose(infile);
|
||||||
|
|
||||||
fprintf(outfile, "~");
|
fprintf(outfile, "~");
|
||||||
fclose(outfile);
|
fclose(outfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get_line reads the next non-blank line off of the input stream.
|
/* get_line reads the next non-blank line off of the input stream.
|
||||||
* The newline character is removed from the input.
|
* The newline character is removed from the input.
|
||||||
*/
|
*/
|
||||||
int get_line(FILE * fl, char *buf)
|
int get_line(FILE * fl, char *buf)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user