batch
This commit is contained in:
3
Makefile
3
Makefile
@ -4,6 +4,7 @@ ifeq ($(DEBUG), 1)
|
||||
LFLAGS += --debug --trace
|
||||
CXXFLAGS += -Wall -Wextra -Wpedantic
|
||||
CXXFLAGS += -DDEBUG -O0 -ggdb -pg -fno-inline
|
||||
.PHONY: ${OUT}
|
||||
else
|
||||
CXXFLAGS += -O3 -fno-stack-protector -fno-exceptions -fno-rtti
|
||||
endif
|
||||
@ -15,7 +16,7 @@ OBJECT.d := object/
|
||||
TEST.d := test/
|
||||
INSTALL.d := /bin/
|
||||
|
||||
SOURCE := main.cpp xml.cpp csml.cpp cli.cpp global.cpp
|
||||
SOURCE := main.cpp xml.cpp csml.cpp cli.cpp global.cpp html_special.cpp
|
||||
OBJECT := $(addprefix ${OBJECT.d}/,${SOURCE})
|
||||
OBJECT := ${OBJECT:.cpp=.o}
|
||||
OBJECT := ${OBJECT:.c=.o}
|
||||
|
@ -20,6 +20,7 @@ const char * const help_message =
|
||||
" -h : print help and quit\n"
|
||||
;
|
||||
|
||||
extern "C"
|
||||
signed parse_round1_arguments(int argc, char * * argv){
|
||||
const char * const optstring = "-" "hv" "cxi:o:q:";
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
/* Parse arguments with perminant effects (-h)
|
||||
* Perform validation.
|
||||
*/
|
||||
extern "C"
|
||||
signed parse_round1_arguments(int argc, char * * argv);
|
||||
|
||||
#define CLI_H
|
||||
|
@ -5,10 +5,11 @@
|
||||
#include <stack>
|
||||
#include <string>
|
||||
|
||||
#include "html_special.hpp"
|
||||
#include "global.hpp"
|
||||
|
||||
std::stack<std::string> tag_stack;
|
||||
std::string tag_candidate = "";
|
||||
static std::stack<std::string> tag_stack;
|
||||
static std::string tag_candidate = "";
|
||||
|
||||
static
|
||||
void _ECHO_CANDIDATE(){
|
||||
@ -25,6 +26,9 @@ static const char COMMENT_END[] = "-->";
|
||||
static const char ATTRIBUTE_VALUE_START[] = "'";
|
||||
static const char ATTRIBUTE_VALUE_END[] = "'";
|
||||
|
||||
static unsigned short current_unicode_size;
|
||||
|
||||
static
|
||||
bool push_tag() {
|
||||
if (tag_candidate == "") {
|
||||
exit(3);
|
||||
@ -38,6 +42,7 @@ bool push_tag() {
|
||||
return true;
|
||||
}
|
||||
|
||||
static
|
||||
bool pop_tag() {
|
||||
if (tag_stack.empty()) {
|
||||
exit(3);
|
||||
@ -50,6 +55,7 @@ bool pop_tag() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
%}
|
||||
|
||||
%option noyywrap
|
||||
@ -60,10 +66,12 @@ bool pop_tag() {
|
||||
%x COMMENT COMMENT_MULTILINE
|
||||
%x IGNORE IGNORE_COUNT_START IGNORE_COUNT_END
|
||||
%x STRING
|
||||
%s UNICODE
|
||||
|
||||
ws [ \t\r\v\f]
|
||||
wsnl [ \t\r\v\f\n]
|
||||
identifier [A-z][A-z0-9]*
|
||||
unicode [\300-\364]
|
||||
|
||||
%%
|
||||
|
||||
@ -87,6 +95,11 @@ identifier [A-z][A-z0-9]*
|
||||
ECHOS(("<" + tag_stack.top() + " ").c_str());
|
||||
BEGIN HEAD;
|
||||
}
|
||||
&#?{identifier}; {
|
||||
ECHO_CANDIDATE;
|
||||
tag_candidate = "";
|
||||
ECHO;
|
||||
}
|
||||
; {
|
||||
ECHOS(("<" + tag_candidate + "/>").c_str());
|
||||
tag_candidate = "";
|
||||
@ -95,6 +108,7 @@ identifier [A-z][A-z0-9]*
|
||||
push_tag();
|
||||
ECHOS(("<" + tag_stack.top() + ">").c_str());
|
||||
if (do_ignore(tag_stack.top())) {
|
||||
buffer = std::string("");
|
||||
BEGIN IGNORE_COUNT_START;
|
||||
}
|
||||
}
|
||||
@ -113,6 +127,19 @@ identifier [A-z][A-z0-9]*
|
||||
tag_candidate = "";
|
||||
ECHOS(">");
|
||||
}
|
||||
{unicode} {
|
||||
ECHO_CANDIDATE;
|
||||
tag_candidate = "";
|
||||
|
||||
const char mask = 0b100000000;
|
||||
const char &header = yytext[0];
|
||||
current_unicode_size = 2;
|
||||
for (int i = 2; (mask >> i) & header; i++) {
|
||||
++current_unicode_size;
|
||||
}
|
||||
yyless(0);
|
||||
BEGIN UNICODE;
|
||||
}
|
||||
.|{wsnl} {
|
||||
ECHO;
|
||||
}
|
||||
@ -177,7 +204,7 @@ identifier [A-z][A-z0-9]*
|
||||
++ignore_count;
|
||||
}
|
||||
.|\n {
|
||||
ECHO;
|
||||
BUFFER(yytext);
|
||||
BEGIN IGNORE;
|
||||
}
|
||||
}
|
||||
@ -188,6 +215,7 @@ identifier [A-z][A-z0-9]*
|
||||
ignore_i = 0;
|
||||
ignore_count = 1;
|
||||
|
||||
ECHOS(buffer.c_str());
|
||||
ECHOS(("</" + tag_stack.top() + ">").c_str());
|
||||
pop_tag();
|
||||
BEGIN BODY;
|
||||
@ -195,10 +223,10 @@ identifier [A-z][A-z0-9]*
|
||||
}
|
||||
.|\n {
|
||||
while (ignore_i--) {
|
||||
ECHOC('}');
|
||||
BUFFER('}');
|
||||
}
|
||||
ignore_i = 1;
|
||||
ECHO;
|
||||
BUFFER(yytext);
|
||||
BEGIN IGNORE;
|
||||
}
|
||||
}
|
||||
@ -211,13 +239,26 @@ identifier [A-z][A-z0-9]*
|
||||
if (ignore_count != 1) {
|
||||
BEGIN IGNORE_COUNT_END;
|
||||
} else {
|
||||
ECHOS(buffer.c_str());
|
||||
ECHOS(("</" + tag_stack.top() + ">").c_str());
|
||||
pop_tag();
|
||||
BEGIN BODY;
|
||||
}
|
||||
}
|
||||
.|\n {
|
||||
ECHO;
|
||||
BUFFER(yytext);
|
||||
}
|
||||
}
|
||||
|
||||
<UNICODE>{
|
||||
(.|\n){4} {
|
||||
static char current_unicode[5];
|
||||
memcpy(current_unicode, yytext, 5);
|
||||
current_unicode[current_unicode_size] = '\0';
|
||||
|
||||
yyless(4 - current_unicode_size);
|
||||
ECHOS(utf8_to_html_special(current_unicode));
|
||||
BEGIN BODY;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,23 +2,29 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
void trim(char * s) {
|
||||
std::vector<std::string> ignore_list;
|
||||
int ignore_count = 1;
|
||||
int ignore_i = 1;
|
||||
std::string buffer;
|
||||
|
||||
void trim(char * const s) {
|
||||
int bp = 0;
|
||||
int len = strlen(s);
|
||||
bool do_break = false;
|
||||
int i = 0;
|
||||
for (;i < len; i++) {
|
||||
if ((s[i] >= 'A' && s[i] <= 'Z')
|
||||
|| (s[i] >= 'a' && s[i] <= 'z')
|
||||
|| (s[i] >= '0' && s[i] <= '9')
|
||||
|| (s[i] == '_')) {
|
||||
s[bp++] = s[i];
|
||||
for (;i < len; i++) {
|
||||
if ((s[i] >= 'A' && s[i] <= 'Z')
|
||||
|| (s[i] >= 'a' && s[i] <= 'z')
|
||||
|| (s[i] >= '0' && s[i] <= '9')
|
||||
|| (s[i] == '_')) {
|
||||
s[bp++] = s[i];
|
||||
do_break = true;
|
||||
} else if (do_break) {
|
||||
} else if (do_break) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
s[bp] = '\0';
|
||||
}
|
||||
|
||||
|
40
source/html_special.cpp
Normal file
40
source/html_special.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include "html_special.hpp"
|
||||
|
||||
const size_t html_special_table_size =
|
||||
sizeof(html_special_table)
|
||||
/
|
||||
sizeof(html_special_table[0]);
|
||||
|
||||
extern "C"
|
||||
const char * html_special_table_lookup(const char * const name) {
|
||||
// XXX: this should be a iterating-decreasing jump search
|
||||
for (size_t i = 0; i < html_special_table_size; i++) {
|
||||
if (!strcmp(name, html_special_table[i][0])) {
|
||||
return html_special_table[i][1];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
const char * html_special_to_utf8(const char * const special) {
|
||||
static std::string r;
|
||||
r = std::string(special);
|
||||
trim(r);
|
||||
uint32_t i(std::stoi(r)); // XXX: with no-exception this is suicide
|
||||
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> conv1;
|
||||
r = conv1.to_bytes(i);
|
||||
return r.c_str();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
const char * utf8_to_html_special(const char * const utf) {
|
||||
for (size_t i = 0; i < html_special_table_size; i++) {
|
||||
if (!strcmp(utf, html_special_table[i][2])) {
|
||||
fflush(stdout);
|
||||
return html_special_table[i][0];
|
||||
}
|
||||
}
|
||||
|
||||
return utf;
|
||||
}
|
@ -1,273 +1,265 @@
|
||||
#ifndef HTML_SPECIAL_HPP
|
||||
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include "global.hpp"
|
||||
|
||||
const char * html_special_table[][2] =
|
||||
extern "C"
|
||||
const char * html_special_table_lookup(const char * const name);
|
||||
|
||||
extern "C"
|
||||
const char * html_special_to_utf8(const char * const special);
|
||||
|
||||
extern "C"
|
||||
const char * utf8_to_html_special(const char * const utf);
|
||||
|
||||
inline
|
||||
const char * const html_special_table[][3] =
|
||||
{
|
||||
{"Á", "Á"},
|
||||
{"á", "á"},
|
||||
{"Â", "Â"},
|
||||
{"â", "â"},
|
||||
{"´", "´"},
|
||||
{"Æ", "Æ"},
|
||||
{"æ", "æ"},
|
||||
{"À", "À"},
|
||||
{"à", "à"},
|
||||
{"Α", "Α"},
|
||||
{"α", "α"},
|
||||
{"&", "&"},
|
||||
{"∧", "∧"},
|
||||
{"∠", "∠"},
|
||||
{"'", "'"},
|
||||
{"Å", "Å"},
|
||||
{"å", "å"},
|
||||
{"≈", "≈"},
|
||||
{"Ã", "Ã"},
|
||||
{"ã", "ã"},
|
||||
{"Ä", "Ä"},
|
||||
{"ä", "ä"},
|
||||
{"„", "„"},
|
||||
{"Β", "Β"},
|
||||
{"β", "β"},
|
||||
{"¦", "¦"},
|
||||
{"•", "•"},
|
||||
{"∩", "∩"},
|
||||
{"Ç", "Ç"},
|
||||
{"ç", "ç"},
|
||||
{"¸", "¸"},
|
||||
{"¢", "¢"},
|
||||
{"Χ", "Χ"},
|
||||
{"χ", "χ"},
|
||||
{"ˆ", "ˆ"},
|
||||
{"♣", "♣"},
|
||||
{"≅", "≅"},
|
||||
{"©", "©"},
|
||||
{"↵", "↵"},
|
||||
{"∪", "∪"},
|
||||
{"¤", "¤"},
|
||||
{"†", "†"},
|
||||
{"‡", "‡"},
|
||||
{"↓", "↓"},
|
||||
{"°", "°"},
|
||||
{"Δ", "Δ"},
|
||||
{"δ", "δ"},
|
||||
{"♦", "♦"},
|
||||
{"÷", "÷"},
|
||||
{"É", "É"},
|
||||
{"é", "é"},
|
||||
{"Ê", "Ê"},
|
||||
{"ê", "ê"},
|
||||
{"È", "È"},
|
||||
{"è", "è"},
|
||||
{"∅", "∅"},
|
||||
{" ", " "},
|
||||
{" ", " "},
|
||||
{"Ε", "Ε"},
|
||||
{"ε", "ε"},
|
||||
{"≡", "≡"},
|
||||
{"Η", "Η"},
|
||||
{"η", "η"},
|
||||
{"Ð", "Ð"},
|
||||
{"ð", "ð"},
|
||||
{"Ë", "Ë"},
|
||||
{"ë", "ë"},
|
||||
{"€", "€"},
|
||||
{"∃", "∃"},
|
||||
{"ƒ", "ƒ"},
|
||||
{"∀", "∀"},
|
||||
{"½", "½"},
|
||||
{"¼", "¼"},
|
||||
{"¾", "¾"},
|
||||
{"Γ", "Γ"},
|
||||
{"γ", "γ"},
|
||||
{"≥", "≥"},
|
||||
{">", ">"},
|
||||
{"↔", "↔"},
|
||||
{"♥", "♥"},
|
||||
{"…", "…"},
|
||||
{"Í", "Í"},
|
||||
{"í", "í"},
|
||||
{"Î", "Î"},
|
||||
{"î", "î"},
|
||||
{"¡", "¡"},
|
||||
{"Ì", "Ì"},
|
||||
{"ì", "ì"},
|
||||
{"∞", "∞"},
|
||||
{"∫", "∫"},
|
||||
{"Ι", "Ι"},
|
||||
{"ι", "ι"},
|
||||
{"¿", "¿"},
|
||||
{"∈", "∈"},
|
||||
{"Ï", "Ï"},
|
||||
{"ï", "ï"},
|
||||
{"Κ", "Κ"},
|
||||
{"κ", "κ"},
|
||||
{"Λ", "Λ"},
|
||||
{"λ", "λ"},
|
||||
{"«", "«"},
|
||||
{"←", "←"},
|
||||
{"⌈", "⌈"},
|
||||
{"“", "“"},
|
||||
{"≤", "≤"},
|
||||
{"⌊", "⌊"},
|
||||
{"∗", "∗"},
|
||||
{"◊", "◊"},
|
||||
{"‎", "‎"},
|
||||
{"‹", "‹"},
|
||||
{"‘", "‘"},
|
||||
{"<", "<"},
|
||||
{"¯", "¯"},
|
||||
{"—", "—"},
|
||||
{"µ", "µ"},
|
||||
{"·", "·"},
|
||||
{"−", "−"},
|
||||
{"Μ", "Μ"},
|
||||
{"μ", "μ"},
|
||||
{"∇", "∇"},
|
||||
{" ", " "},
|
||||
{"–", "–"},
|
||||
{"≠", "≠"},
|
||||
{"∋", "∋"},
|
||||
{"¬", "¬"},
|
||||
{"∉", "∉"},
|
||||
{"⊄", "⊄"},
|
||||
{"Ñ", "Ñ"},
|
||||
{"ñ", "ñ"},
|
||||
{"Ν", "Ν"},
|
||||
{"ν", "ν"},
|
||||
{"Ó", "Ó"},
|
||||
{"ó", "ó"},
|
||||
{"Ô", "Ô"},
|
||||
{"ô", "ô"},
|
||||
{"Œ", "Œ"},
|
||||
{"œ", "œ"},
|
||||
{"Ò", "Ò"},
|
||||
{"ò", "ò"},
|
||||
{"‾", "‾"},
|
||||
{"Ω", "Ω"},
|
||||
{"ω", "ω"},
|
||||
{"Ο", "Ο"},
|
||||
{"ο", "ο"},
|
||||
{"⊕", "⊕"},
|
||||
{"∨", "∨"},
|
||||
{"ª", "ª"},
|
||||
{"º", "º"},
|
||||
{"Ø", "Ø"},
|
||||
{"ø", "ø"},
|
||||
{"Õ", "Õ"},
|
||||
{"õ", "õ"},
|
||||
{"⊗", "⊗"},
|
||||
{"Ö", "Ö"},
|
||||
{"ö", "ö"},
|
||||
{"¶", "¶"},
|
||||
{"∂", "∂"},
|
||||
{"‰", "‰"},
|
||||
{"⊥", "⊥"},
|
||||
{"Φ", "Φ"},
|
||||
{"φ", "φ"},
|
||||
{"Π", "Π"},
|
||||
{"π", "π"},
|
||||
{"ϖ", "ϖ"},
|
||||
{"±", "±"},
|
||||
{"£", "£"},
|
||||
{"′", "′"},
|
||||
{"″", "″"},
|
||||
{"∏", "∏"},
|
||||
{"∝", "∝"},
|
||||
{"Ψ", "Ψ"},
|
||||
{"ψ", "ψ"},
|
||||
{""", """},
|
||||
{"√", "√"},
|
||||
{"»", "»"},
|
||||
{"→", "→"},
|
||||
{"⌉", "⌉"},
|
||||
{"”", "”"},
|
||||
{"®", "®"},
|
||||
{"⌋", "⌋"},
|
||||
{"Ρ", "Ρ"},
|
||||
{"ρ", "ρ"},
|
||||
{"‏", "‏"},
|
||||
{"›", "›"},
|
||||
{"’", "’"},
|
||||
{"‚", "‚"},
|
||||
{"Š", "Š"},
|
||||
{"š", "š"},
|
||||
{"⋅", "⋅"},
|
||||
{"§", "§"},
|
||||
{"­", "­"},
|
||||
{"Σ", "Σ"},
|
||||
{"σ", "σ"},
|
||||
{"ς", "ς"},
|
||||
{"∼", "∼"},
|
||||
{"♠", "♠"},
|
||||
{"⊂", "⊂"},
|
||||
{"⊆", "⊆"},
|
||||
{"∑", "∑"},
|
||||
{"¹", "¹"},
|
||||
{"²", "²"},
|
||||
{"³", "³"},
|
||||
{"⊃", "⊃"},
|
||||
{"⊇", "⊇"},
|
||||
{"ß", "ß"},
|
||||
{"Τ", "Τ"},
|
||||
{"τ", "τ"},
|
||||
{"∴", "∴"},
|
||||
{"Θ", "Θ"},
|
||||
{"θ", "θ"},
|
||||
{"ϑ", "ϑ"},
|
||||
{" ", " "},
|
||||
{"Þ", "Þ"},
|
||||
{"þ", "þ"},
|
||||
{"˜", "˜"},
|
||||
{"×", "×"},
|
||||
{"™", "™"},
|
||||
{"Ú", "Ú"},
|
||||
{"ú", "ú"},
|
||||
{"↑", "↑"},
|
||||
{"Û", "Û"},
|
||||
{"û", "û"},
|
||||
{"Ù", "Ù"},
|
||||
{"ù", "ù"},
|
||||
{"¨", "¨"},
|
||||
{"ϒ", "ϒ"},
|
||||
{"Υ", "Υ"},
|
||||
{"υ", "υ"},
|
||||
{"Ü", "Ü"},
|
||||
{"ü", "ü"},
|
||||
{"Ξ", "Ξ"},
|
||||
{"ξ", "ξ"},
|
||||
{"Ý", "Ý"},
|
||||
{"ý", "ý"},
|
||||
{"¥", "¥"},
|
||||
{"ÿ", "ÿ"},
|
||||
{"Ÿ", "Ÿ"},
|
||||
{"Ζ", "Ζ"},
|
||||
{"ζ", "ζ"},
|
||||
{"‍", "‍"},
|
||||
{"‌", "‌"},
|
||||
{"Á", "Á", "Á"},
|
||||
{"á", "á", "á"},
|
||||
{"Â", "Â", "Â"},
|
||||
{"â", "â", "â"},
|
||||
{"´", "´", "´"},
|
||||
{"Æ", "Æ", "Æ"},
|
||||
{"æ", "æ", "æ"},
|
||||
{"À", "À", "À"},
|
||||
{"à", "à", "à"},
|
||||
{"Α", "Α", "Α"},
|
||||
{"α", "α", "α"},
|
||||
{"&", "&", "&"},
|
||||
{"∧", "∧", "∧"},
|
||||
{"∠", "∠", "∠"},
|
||||
{"'", "'", "'"},
|
||||
{"Å", "Å", "Å"},
|
||||
{"å", "å", "å"},
|
||||
{"≈", "≈", "≈"},
|
||||
{"Ã", "Ã", "Ã"},
|
||||
{"ã", "ã", "ã"},
|
||||
{"Ä", "Ä", "Ä"},
|
||||
{"ä", "ä", "ä"},
|
||||
{"„", "„", "„"},
|
||||
{"Β", "Β", "Β"},
|
||||
{"β", "β", "β"},
|
||||
{"¦", "¦", "¦"},
|
||||
{"•", "•", "•"},
|
||||
{"∩", "∩", "∩"},
|
||||
{"Ç", "Ç", "Ç"},
|
||||
{"ç", "ç", "ç"},
|
||||
{"¸", "¸", "¸"},
|
||||
{"¢", "¢", "¢"},
|
||||
{"Χ", "Χ", "Χ"},
|
||||
{"χ", "χ", "χ"},
|
||||
{"ˆ", "ˆ", "ˆ"},
|
||||
{"♣", "♣", "♣"},
|
||||
{"≅", "≅", "≅"},
|
||||
{"©", "©", "©"},
|
||||
{"↵", "↵", "↵"},
|
||||
{"∪", "∪", "∪"},
|
||||
{"¤", "¤", "¤"},
|
||||
{"†", "†", "†"},
|
||||
{"‡", "‡", "‡"},
|
||||
{"↓", "↓", "↓"},
|
||||
{"°", "°", "°"},
|
||||
{"Δ", "Δ", "Δ"},
|
||||
{"δ", "δ", "δ"},
|
||||
{"♦", "♦", "♦"},
|
||||
{"÷", "÷", "÷"},
|
||||
{"É", "É", "É"},
|
||||
{"é", "é", "é"},
|
||||
{"Ê", "Ê", "Ê"},
|
||||
{"ê", "ê", "ê"},
|
||||
{"È", "È", "È"},
|
||||
{"è", "è", "è"},
|
||||
{"∅", "∅", "∅"},
|
||||
{" ", " ", ""},
|
||||
{" ", " ", ""},
|
||||
{"Ε", "Ε", "Ε"},
|
||||
{"ε", "ε", "ε"},
|
||||
{"≡", "≡", "≡"},
|
||||
{"Η", "Η", "Η"},
|
||||
{"η", "η", "η"},
|
||||
{"Ð", "Ð", "Ð"},
|
||||
{"ð", "ð", "ð"},
|
||||
{"Ë", "Ë", "Ë"},
|
||||
{"ë", "ë", "ë"},
|
||||
{"€", "€", "€"},
|
||||
{"∃", "∃", "∃"},
|
||||
{"ƒ", "ƒ", "ƒ"},
|
||||
{"∀", "∀", "∀"},
|
||||
{"½", "½", "½"},
|
||||
{"¼", "¼", "¼"},
|
||||
{"¾", "¾", "¾"},
|
||||
{"Γ", "Γ", "Γ"},
|
||||
{"γ", "γ", "γ"},
|
||||
{"≥", "≥", "≥"},
|
||||
{">", ">", ">"},
|
||||
{"↔", "↔", "↔"},
|
||||
{"♥", "♥", "♥"},
|
||||
{"…", "…", "…"},
|
||||
{"Í", "Í", "Í"},
|
||||
{"í", "í", "í"},
|
||||
{"Î", "Î", "Î"},
|
||||
{"î", "î", "î"},
|
||||
{"¡", "¡", "¡"},
|
||||
{"Ì", "Ì", "Ì"},
|
||||
{"ì", "ì", "ì"},
|
||||
{"∞", "∞", "∞"},
|
||||
{"∫", "∫", "∫"},
|
||||
{"Ι", "Ι", "Ι"},
|
||||
{"ι", "ι", "ι"},
|
||||
{"¿", "¿", "¿"},
|
||||
{"∈", "∈", "∈"},
|
||||
{"Ï", "Ï", "Ï"},
|
||||
{"ï", "ï", "ï"},
|
||||
{"Κ", "Κ", "Κ"},
|
||||
{"κ", "κ", "κ"},
|
||||
{"Λ", "Λ", "Λ"},
|
||||
{"λ", "λ", "λ"},
|
||||
{"«", "«", "«"},
|
||||
{"←", "←", "←"},
|
||||
{"⌈", "⌈", "⌈"},
|
||||
{"“", "“", "“"},
|
||||
{"≤", "≤", "≤"},
|
||||
{"⌊", "⌊", "⌊"},
|
||||
{"∗", "∗", "∗"},
|
||||
{"◊", "◊", "◊"},
|
||||
{"‎", "‎", ""},
|
||||
{"‹", "‹", "‹"},
|
||||
{"‘", "‘", "‘"},
|
||||
{"<", "<", "<"},
|
||||
{"¯", "¯", "¯"},
|
||||
{"—", "—", "—"},
|
||||
{"µ", "µ", "µ"},
|
||||
{"·", "·", "·"},
|
||||
{"−", "−", "−"},
|
||||
{"Μ", "Μ", "Μ"},
|
||||
{"μ", "μ", "μ"},
|
||||
{"∇", "∇", "∇"},
|
||||
{" ", " ", " "},
|
||||
{"–", "–", "–"},
|
||||
{"≠", "≠", "≠"},
|
||||
{"∋", "∋", "∋"},
|
||||
{"¬", "¬", "¬"},
|
||||
{"∉", "∉", "∉"},
|
||||
{"⊄", "⊄", "⊄"},
|
||||
{"Ñ", "Ñ", "Ñ"},
|
||||
{"ñ", "ñ", "ñ"},
|
||||
{"Ν", "Ν", "Ν"},
|
||||
{"ν", "ν", "ν"},
|
||||
{"Ó", "Ó", "Ó"},
|
||||
{"ó", "ó", "ó"},
|
||||
{"Ô", "Ô", "Ô"},
|
||||
{"ô", "ô", "ô"},
|
||||
{"Œ", "Œ", "Œ"},
|
||||
{"œ", "œ", "œ"},
|
||||
{"Ò", "Ò", "Ò"},
|
||||
{"ò", "ò", "ò"},
|
||||
{"‾", "‾", "‾"},
|
||||
{"Ω", "Ω", "Ω"},
|
||||
{"ω", "ω", "ω"},
|
||||
{"Ο", "Ο", "Ο"},
|
||||
{"ο", "ο", "ο"},
|
||||
{"⊕", "⊕", "⊕"},
|
||||
{"∨", "∨", "∨"},
|
||||
{"ª", "ª", "ª"},
|
||||
{"º", "º", "º"},
|
||||
{"Ø", "Ø", "Ø"},
|
||||
{"ø", "ø", "ø"},
|
||||
{"Õ", "Õ", "Õ"},
|
||||
{"õ", "õ", "õ"},
|
||||
{"⊗", "⊗", "⊗"},
|
||||
{"Ö", "Ö", "Ö"},
|
||||
{"ö", "ö", "ö"},
|
||||
{"¶", "¶", "¶"},
|
||||
{"∂", "∂", "∂"},
|
||||
{"‰", "‰", "‰"},
|
||||
{"⊥", "⊥", "⊥"},
|
||||
{"Φ", "Φ", "Φ"},
|
||||
{"φ", "φ", "φ"},
|
||||
{"Π", "Π", "Π"},
|
||||
{"π", "π", "π"},
|
||||
{"ϖ", "ϖ", "ϖ"},
|
||||
{"±", "±", "±"},
|
||||
{"£", "£", "£"},
|
||||
{"′", "′", "′"},
|
||||
{"″", "″", "″"},
|
||||
{"∏", "∏", "∏"},
|
||||
{"∝", "∝", "∝"},
|
||||
{"Ψ", "Ψ", "Ψ"},
|
||||
{"ψ", "ψ", "ψ"},
|
||||
{""", """, "\""},
|
||||
{"√", "√", "√"},
|
||||
{"»", "»", "»"},
|
||||
{"→", "→", "→"},
|
||||
{"⌉", "⌉", "⌉"},
|
||||
{"”", "”", "”"},
|
||||
{"®", "®", "®"},
|
||||
{"⌋", "⌋", "⌋"},
|
||||
{"Ρ", "Ρ", "Ρ"},
|
||||
{"ρ", "ρ", "ρ"},
|
||||
{"‏", "‏", ""},
|
||||
{"›", "›", "›"},
|
||||
{"’", "’", "’"},
|
||||
{"‚", "‚", "‚"},
|
||||
{"Š", "Š", "Š"},
|
||||
{"š", "š", "š"},
|
||||
{"⋅", "⋅", "⋅"},
|
||||
{"§", "§", "§"},
|
||||
{"­", "­", ""},
|
||||
{"Σ", "Σ", "Σ"},
|
||||
{"σ", "σ", "σ"},
|
||||
{"ς", "ς", "ς"},
|
||||
{"∼", "∼", "∼"},
|
||||
{"♠", "♠", "♠"},
|
||||
{"⊂", "⊂", "⊂"},
|
||||
{"⊆", "⊆", "⊆"},
|
||||
{"∑", "∑", "∑"},
|
||||
{"¹", "¹", "¹"},
|
||||
{"²", "²", "²"},
|
||||
{"³", "³", "³"},
|
||||
{"⊃", "⊃", "⊃"},
|
||||
{"⊇", "⊇", "⊇"},
|
||||
{"ß", "ß", "ß"},
|
||||
{"Τ", "Τ", "Τ"},
|
||||
{"τ", "τ", "τ"},
|
||||
{"∴", "∴", "∴"},
|
||||
{"Θ", "Θ", "Θ"},
|
||||
{"θ", "θ", "θ"},
|
||||
{"ϑ", "ϑ", "ϑ"},
|
||||
{" ", " ", ""},
|
||||
{"Þ", "Þ", "Þ"},
|
||||
{"þ", "þ", "þ"},
|
||||
{"˜", "˜", "˜"},
|
||||
{"×", "×", "×"},
|
||||
{"™", "™", "™"},
|
||||
{"Ú", "Ú", "Ú"},
|
||||
{"ú", "ú", "ú"},
|
||||
{"↑", "↑", "↑"},
|
||||
{"Û", "Û", "Û"},
|
||||
{"û", "û", "û"},
|
||||
{"Ù", "Ù", "Ù"},
|
||||
{"ù", "ù", "ù"},
|
||||
{"¨", "¨", "¨"},
|
||||
{"ϒ", "ϒ", "ϒ"},
|
||||
{"Υ", "Υ", "Υ"},
|
||||
{"υ", "υ", "υ"},
|
||||
{"Ü", "Ü", "Ü"},
|
||||
{"ü", "ü", "ü"},
|
||||
{"Ξ", "Ξ", "Ξ"},
|
||||
{"ξ", "ξ", "ξ"},
|
||||
{"Ý", "Ý", "Ý"},
|
||||
{"ý", "ý", "ý"},
|
||||
{"¥", "¥", "¥"},
|
||||
{"ÿ", "ÿ", "ÿ"},
|
||||
{"Ÿ", "Ÿ", "Ÿ"},
|
||||
{"Ζ", "Ζ", "Ζ"},
|
||||
{"ζ", "ζ", "ζ"},
|
||||
{"‍", "‍", ""},
|
||||
{"‌", "‌", ""},
|
||||
};
|
||||
|
||||
const size_t html_special_table_size = sizeof(html_special_table) / sizeof(html_special_table[0]);
|
||||
|
||||
const char * html_special_table_lookup(const char * const name) {
|
||||
// this should be a iterating-decreasing jump search
|
||||
for (int i = 0; i < html_special_table_size; i++) {
|
||||
if (!strcmp(name, html_special_table[i][0])) {
|
||||
return html_special_table[i][1];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char * html_special_to_utf8(const char * const special) {
|
||||
static std::string r(special);
|
||||
trim(r);
|
||||
uint32_t i(std::stoi(r));
|
||||
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> conv1;
|
||||
r = conv1.to_bytes(i);
|
||||
return r.c_str();
|
||||
}
|
||||
|
||||
#define HTML_SPECIAL_HPP
|
||||
#endif
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <map>
|
||||
|
||||
#include "cli.hpp"
|
||||
#include "scanner.hpp"
|
||||
#include "exit_values.hpp"
|
||||
|
||||
#define DECLARE_LEXER(x) \
|
||||
@ -18,10 +19,6 @@
|
||||
DECLARE_LEXER(csml);
|
||||
DECLARE_LEXER(xml);
|
||||
|
||||
std::vector<std::string> ignore_list;
|
||||
int ignore_count = 1;
|
||||
int ignore_i = 1;
|
||||
|
||||
const char DEFAULT_QUOTE = '\'';
|
||||
char quote = DEFAULT_QUOTE;
|
||||
char * output = NULL;
|
||||
|
@ -4,11 +4,12 @@
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
#define ECHOS(s) { \
|
||||
#define ECHOS(s) do { \
|
||||
const char * const ss = s; \
|
||||
fwrite(ss, strlen(ss), sizeof(char), yyout); \
|
||||
} while (0)
|
||||
#define ECHOC(c) fputc(c, yyout)
|
||||
#define BUFFER(s) buffer += s
|
||||
|
||||
extern std::vector<std::string> ignore_list;
|
||||
|
||||
@ -22,6 +23,7 @@ bool do_ignore(const std::string ¤t_tag) {
|
||||
|
||||
extern int ignore_count; // number of '{' / '}'s to be placed around the current ignored block
|
||||
extern int ignore_i; // number of '}'s so far
|
||||
extern std::string buffer;
|
||||
|
||||
#define SCANNER_H
|
||||
#endif
|
||||
|
22
source/xml.l
22
source/xml.l
@ -6,8 +6,7 @@
|
||||
#include "global.hpp"
|
||||
#include "html_special.hpp"
|
||||
|
||||
bool is_comment_multiline = false;
|
||||
unsigned long long comment_begining;
|
||||
bool is_comment_multiline;
|
||||
std::string current_tag;
|
||||
long ignore_start;
|
||||
|
||||
@ -34,8 +33,9 @@ identifier [A-z][A-z0-9]*
|
||||
BEGIN TAG_START;
|
||||
}
|
||||
\<\!-- {
|
||||
comment_begining = cursor_position;
|
||||
ECHOS("//");
|
||||
is_comment_multiline = false;
|
||||
buffer = std::string("");
|
||||
BUFFER("//");
|
||||
BEGIN COMMENT;
|
||||
}
|
||||
&[A-z]+; {
|
||||
@ -51,18 +51,18 @@ identifier [A-z][A-z0-9]*
|
||||
|
||||
<COMMENT>{
|
||||
. {
|
||||
ECHO;
|
||||
BUFFER(yytext);
|
||||
}
|
||||
\n {
|
||||
BUFFER(yytext);
|
||||
is_comment_multiline = true;
|
||||
}
|
||||
--\> {
|
||||
if (is_comment_multiline) {
|
||||
auto buffer = ftell(yyin);
|
||||
fseek(yyin, comment_begining+1, SEEK_SET);
|
||||
fputc('*', yyin);
|
||||
fseek(yyin, buffer, SEEK_SET);
|
||||
buffer[1] = '*';
|
||||
buffer += "*/";
|
||||
}
|
||||
ECHOS(buffer.c_str());
|
||||
BEGIN INITIAL;
|
||||
}
|
||||
}
|
||||
@ -146,7 +146,7 @@ identifier [A-z][A-z0-9]*
|
||||
dup = strdup(yytext);
|
||||
trim(dup);
|
||||
if (!strcmp(dup, current_tag.c_str())) {
|
||||
for (int i = -1; i < ignore_count; i++) {
|
||||
for (int i = 0; i < ignore_count; i++) {
|
||||
ECHOC('{');
|
||||
}
|
||||
fseek(yyin, ignore_start, SEEK_SET);
|
||||
@ -160,7 +160,7 @@ identifier [A-z][A-z0-9]*
|
||||
\{ {
|
||||
BEGIN IGNORE_COUNT_START;
|
||||
}
|
||||
\{ {
|
||||
\} {
|
||||
BEGIN IGNORE_COUNT_END;
|
||||
}
|
||||
.|\n {
|
||||
|
@ -13,7 +13,7 @@ html {
|
||||
body {
|
||||
hr;
|
||||
div (class: myclass) {
|
||||
lorem > ipsum
|
||||
lorem > ipsum
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
<!-- DOCTYPE HTML -->
|
||||
<html>
|
||||
<head>
|
||||
<!-- for some reason,
|
||||
i feel like commenting styles
|
||||
-->
|
||||
<style>
|
||||
div {
|
||||
color: red;
|
||||
@ -10,7 +13,7 @@
|
||||
<body>
|
||||
<hr/>
|
||||
<div class='myclass'>
|
||||
lorem > ipsum
|
||||
lorem > ipsum ­
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user