diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2013-05-08 22:21:52 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2013-05-08 22:21:52 +0000 |
commit | 2f253cfc85ffd55a8acb988e91f0bc5ab348124c (patch) | |
tree | 4734ccd522c71dd455879162006742002f8c1565 /mkhctype | |
download | HTML-Parser-tarball-master.tar.gz |
HTML-Parser-3.71HEADHTML-Parser-3.71master
Diffstat (limited to 'mkhctype')
-rwxr-xr-x | mkhctype | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/mkhctype b/mkhctype new file mode 100755 index 0000000..eeae40d --- /dev/null +++ b/mkhctype @@ -0,0 +1,57 @@ +#!/usr/bin/perl + +($progname = $0) =~ s,.*/,,; + +print "/* This file is autogenerated by $progname */\n"; + +print <<'EOT'; + +#define HCTYPE_SPACE 0x01 +#define HCTYPE_NAME_FIRST 0x02 +#define HCTYPE_NAME_CHAR 0x04 +#define HCTYPE_NOT_SPACE_GT 0x08 +#define HCTYPE_NOT_SPACE_EQ_GT 0x10 +#define HCTYPE_NOT_SPACE_SLASH_GT 0x20 +#define HCTYPE_NOT_SPACE_EQ_SLASH_GT 0x40 + +#define HCTYPE(c) hctype[(unsigned char)(c)] +#define isHCTYPE(c, w) (HCTYPE(c) & (w)) + +#define isHSPACE(c) isHCTYPE(c, HCTYPE_SPACE) +#define isHNAME_FIRST(c) isHCTYPE(c, HCTYPE_NAME_FIRST) +#define isHNAME_CHAR(c) isHCTYPE(c, HCTYPE_NAME_CHAR) +#define isHNOT_SPACE_GT(c) isHCTYPE(c, HCTYPE_NOT_SPACE_GT) + +typedef unsigned char hctype_t; + +EOT + +print "static hctype_t hctype[] = {\n"; + +for my $c (0 .. 255) { + print " " unless $c % 8; + + local $_ = chr($c); + my $v = 0; + if (/^\s$/) { # isSPACE + $v |= 0x1 + } + elsif ($_ ne ">") { + $v |= 0x08; + $v |= 0x10 if $_ ne "="; + $v |= 0x20 if $_ ne "/"; + $v |= 0x40 if $_ ne "="; + } + + if (/^[\w.\-:]$/) { + $v |= 0x4; + $v |= 0x2 unless /^[\d.-]$/; # XML allow /[:_]/ as first char + } + + printf "0x%02x, ", $v; + unless (($c+1) % 8) { + printf " /* %3d - %3d */\n", $c - 7, $c; + } +} +print "};\n"; + |