無題
Posted: 2011年1月31日(月) 12:45
visual studioで
gcc ~.c -g -W -Wall
./a.out < test.html
のようなことをしたいのですがどうすればいいでしょうか
gcc ~.c -g -W -Wall
./a.out < test.html
のようなことをしたいのですがどうすればいいでしょうか
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define BSIZE 4096
char buff[BSIZE];
char *bp;
enum tokentype
{
BEGIN_HTML, END_HTML, BEGIN_BODY, END_BODY,
BEGIN_TABLE, END_TABLE, BEGIN_TR, END_TR, BEGIN_TD, END_TD,
BR, HR, STRING, END
};
enum tokentype token;
void error(char *msg);
void scan();
void prog();
void body();
void line();
void table();
void tr();
void td();
void error(char *msg)
{
if (msg == NULL)
puts("error");
else
puts(msg);
exit(1);
}
void scan()
{
while (isspace(*bp)) {
bp++;
}
if (*bp == '\0') {
token = END;
return;
}
if (strncmp(bp, "<HTML>", 6) == 0) {
token = BEGIN_HTML;
bp += 6;
return;
}
if (strncmp(bp, "</HTML>", 7) == 0) {
token = END_HTML;
bp += 7;
return;
}
if (strncmp(bp, "<BODY>", 6) == 0) {
token = BEGIN_BODY;
bp += 6;
return;
}
if (strncmp(bp, "</BODY>", 7) == 0) {
token = END_BODY;
bp += 7;
return;
}
if (strncmp(bp, "<TABLE>", 7) == 0) {
token = BEGIN_TABLE;
bp += 7;
return;
}
if (strncmp(bp, "</TABLE>", 8) == 0) {
token = END_TABLE;
bp += 8;
return;
}
if (strncmp(bp, "<TR>", 4) == 0) {
token = BEGIN_TR;
bp += 4;
return;
}
if (strncmp(bp, "</TR>", 5) == 0) {
token = END_TR;
bp += 5;
return;
}
if (strncmp(bp, "<TD>", 4) == 0) {
token = BEGIN_TD;
bp += 4;
return;
}
if (strncmp(bp, "</TD>", 5) == 0) {
token = END_TD;
bp += 5;
return;
}
if (strncmp(bp, "<HR>", 4) == 0) {
token = HR;
bp += 4;
return;
}
if (strncmp(bp, "<BR>", 4) == 0) {
token = BR;
bp += 4;
return;
}
if(*bp=='<'){
while(*bp!='>'){
bp++;
}
return;
}
if (isprint(*bp) || isspace(*bp)) {
token = STRING;
bp++;
while ((*bp != '<') && (*bp != '>') && (*bp != '\0')) {
bp++;
}
return;
}
error("unknown token\n");
}
void prog()
{
if (token != BEGIN_HTML)
error("BEGIN_HTML reject");
scan();
body();
if (token != END_HTML)
error("END_HTML reject");
scan();
}
void body()
{
if (token != BEGIN_BODY)
error("BEGIN_BODY reject");
scan();
while (token != END_BODY) {
line();
}
scan();
}
void line()
{
if(token==BEGIN_TABLE){
table();
}else if(token==STRING || token==HR || token==BR){
scan();
}
}
void table()
{
if(token!=BEGIN_TABLE)
error("BEGIN_TABLE reject");
scan();
while(token!=END_TABLE){
tr();
}
scan();
}
void tr()
{
if(token!=BEGIN_TR)
error("BEGIN_TR reject");
scan();
while(token!=END_TD){
td();
}
scan();
}
void td()
{
if (token != BEGIN_TD)
error("BEGIN_TD reject");
scan();
if (token == STRING) {
scan();
}else if (token == BEGIN_TABLE){
table();
}
if (token != END_TD)
error("END_TD reject");
scan();
}
int main()
{
bp = buff;
while (fgets(bp, BSIZE, stdin) != NULL) {
bp += strlen(bp);
}
bp = buff;
scan();
prog();
if (token != END)
error("END reject!");
puts("accept!");
return 0;
}
<!-- Institute of Tech.
Test HTML for htmlchecker -->
<HTML>
<!-- unsupported tag
<HEAD>
<TITLE>
Test Page
</TITLE>
</HEAD>
-->
<BODY>
Sudacci Ponz!!
<HR>
<BR>Institute<BR>of<BR>Technology
<HR>
<TABLE>
<TR><TD>PostScript</TD><TD>UNIX</TD><TD>Mr.President</TD></TR>
<TR><TD>Lenny</TD><TD>Squeeze</TD></TR>
<TR><TD></TD><TD>(*_*)</TD><TD></TD><TD>(^_^)</TD></TR>
</TABLE>
<HR>
<TABLE></TABLE>
GNU/Octave, OctaveForge
<!-- http://www.gnu.org/software/octave/ -->
<TABLE>
<TR>
<TD>Face</TD>
<TD><TABLE><TR><TD>(o_o)</TD></TR><TR><TD>(T_T)</TD></TR></TABLE></TD>
<TD><TABLE><TR><TD>(._.)</TD><TD>(?_?)</TD></TR></TABLE></TD>
</TR>
<TR>
<TD>H/W</TD><TD>S/W</TD><TD>Mr.President</TD>
</TR>
<TR>
<TD>My Favorite Things</TD>
</TR>
</TABLE>
</BODY>
</HTML>
'htmlch.exe': 'C:\Windows\SysWOW64\ntdll.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\kernel32.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\KernelBase.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\msvcr100d.dll' を読み込みました。シンボルが読み込まれました。
'htmlch.exe': 'C:\Windows\SysWOW64\apphelp.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\AppPatch\AcLayers.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\sspicli.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\msvcrt.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\rpcrt4.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\cryptbase.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\sechost.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\user32.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\gdi32.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\lpk.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\usp10.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\advapi32.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\shell32.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\shlwapi.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\ole32.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\oleaut32.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\userenv.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\profapi.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\winspool.drv' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\mpr.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\imm32.dll' を読み込みました。Cannot find or open the PDB file
'htmlch.exe': 'C:\Windows\SysWOW64\msctf.dll' を読み込みました。Cannot find or open the PDB file
プログラム '[3396] htmlch.exe: ネイティブ' はコード 1 (0x1) で終了しました。
であれば構文解析に失敗している可能性が高いので、デバッグしてみる必要があります。zino さんが書きました:softya様
開いてすぐ閉じてしまいますが、かすかにBEGIN_BODY rejectと出ているので
読み込めてはいるみたいです