65,186
社区成员




else if( NULL == href )
{
fprintf( stderr , "warning unexpected CHAR:%x(%c)\n" , *href );
p = text;
}
else if( NULL == href )
{
fprintf( stderr , "warning unexpected CHAR:%x(%c)\n" , *p );
href = text;
}
#include <stdio.h>
#include <ctype.h>
void slove( unsigned char* begin , unsigned char* end )
{
enum { YY_LASTDFA=22, YY_JAMBASE=26 };
static const unsigned char yy_accept[] = {
0, 0, 0, 0, 0, 0, 0, 6, 5, 5,
2, 5, 5, 0, 0, 0, 1, 0, 0, 0,
4, 0, 3, 0
};
static const unsigned char yy_ec[] = {
0, 1, 1, 1, 1, 1, 1, 1, 1, 2,
2, 2, 2, 2, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 2, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 3, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
4, 5, 6, 1, 1, 7, 1, 1, 1, 8,
9, 1, 10, 1, 1, 1, 1, 1, 1, 1,
1, 1, 11, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 7, 1, 1,
1, 8, 9, 1, 10, 1, 1, 1, 1, 1,
1, 1, 1, 1, 11, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1
};
static const unsigned char yy_meta[] = {
0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1
};
static const unsigned char yy_base[] = {
0, 21, 20, 0, 5, 19, 18, 21, 26, 13,
26, 7, 14, 12, 5, 5, 26, 0, 1, 14,
26, 0, 26, 26, 0
};
static const unsigned char yy_def[] = {
0, 24, 24, 24, 24, 24, 24, 23, 23, 23,
23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
23, 19, 23, 0, 23
};
static const unsigned char yy_nxt[] = {
0, 8, 23, 23, 23, 23, 10, 20, 23, 19,
11, 10, 18, 17, 16, 11, 21, 15, 14, 22,
13, 23, 12, 12, 9, 9, 7, 23, 23, 23,
23, 23, 23, 23, 23, 23, 23, 23
};
static const unsigned char yy_chk[] = {
0, 24, 0, 0, 0, 0, 3, 18, 0, 17,
3, 4, 15, 14, 13, 4, 19, 12, 11, 19,
9, 7, 6, 5, 2, 1, 23, 23, 23, 23,
23, 23, 23, 23, 23, 23, 23, 23
};
unsigned char* href = NULL , *title = NULL , *text , *p;
int curr , start = 1 , stbk = 0 , yyc , action = 0;
unsigned char* txtbk = NULL ;
while( 1 )
{
curr = start;
text = begin;
do {
if( begin >= end )
return ; /* done */
yyc = yy_ec[*begin];
if( yy_accept[curr] )
stbk = curr , txtbk = begin;
while( yy_chk[yy_base[curr] + yyc] != curr )
{
if( (curr=yy_def[curr]) >= YY_LASTDFA + 2 )
yyc = yy_meta[ yyc ];
}
curr = yy_nxt[ yy_base[curr] + yyc ];
++begin;
} while( yy_base[curr] != YY_JAMBASE );
if( (action = yy_accept[curr] )== 0 )
begin = txtbk , curr = stbk , action = yy_accept[curr];
switch(action)
{
case 1:
start = 3;
break;
case 2:
title = text + 1;
start = 5;
break;
case 3:
text = p = begin;
for( ; p < end ; ++p )
{
if( isspace(*p) )
;
else if( *p == '\'' || *p == '\"' )
{
if( NULL == href )
{
href = p + 1;
}
else
{
*p = 0;
begin = p + 1;
break;
}
}
else if( NULL == href )
{
fprintf( stderr , "warning unexpected CHAR:%x(%c)\n" , *href );
p = text;
}
}
break;
case 4:
*text = 0;
start = 1;
printf( "match HREF:\"%s\" , title:\"%s\"\n" , href?(char*)href:"<nil>" , title?(char*)title:"<nil>" );
href = title = NULL;
break;
case 5:
break;
}
}
}
#define MAXX_TEST_LENGTH (32*1024)
int main( int argc , char* argv[] )
{
int i , e = 0;
unsigned char buff[ MAXX_TEST_LENGTH + 64 ];
for( i = 1; i < argc; ++i )
{
FILE* ifs = fopen( argv[i] , "rb" );
if( NULL != ifs )
{
size_t szr = fread( buff , 1 , MAXX_TEST_LENGTH , ifs );
fclose( ifs );
buff[szr] = buff[szr+1] = 0;
slove( buff , buff + szr );
}
else
{
++e ;
fprintf( stderr , "ERROR: open %s failed\n" , argv[i] );
}
}
return e;
}
#include <iostream>