4 |
|
// |
5 |
|
// $Id$ |
6 |
|
|
7 |
< |
#include "Tag.hpp" |
7 |
> |
#include "Cleaner.hpp" |
8 |
|
#include "Matcher.hpp" |
9 |
|
|
10 |
|
#include <menes-api/exename.hpp> |
11 |
|
#include <menes-api/files.hpp> |
12 |
|
#include <menes-app/application.hpp> |
13 |
+ |
#include <menes-ext/stack.hpp> |
14 |
|
|
15 |
|
struct IffyCommand : public app::Application |
16 |
|
{ |
52 |
|
|
53 |
|
Iffy::Iffy(const ext::String& in, const ext::String& out) |
54 |
|
{ |
55 |
< |
if (in == "-" && out == "-") |
56 |
< |
{ |
56 |
< |
iffy(api::Cin, api::Cout); |
57 |
< |
} |
58 |
< |
else if (in == "-") |
59 |
< |
{ |
60 |
< |
api::FileWriter fout(out); |
55 |
> |
_H<ios::Reader> rin; |
56 |
> |
_H<ios::Writer> rout; |
57 |
|
|
58 |
< |
iffy(api::Cin, fout); |
59 |
< |
} |
64 |
< |
else if (out == "-") |
65 |
< |
{ |
66 |
< |
api::FileReader fin(in); |
58 |
> |
if (in == "-") rin = &api::Cin; else rin = new api::FileReader(in); |
59 |
> |
if (out == "-") rout = &api::Cout; else rout = new api::FileWriter(out); |
60 |
|
|
61 |
< |
iffy(fin, api::Cout); |
69 |
< |
} |
70 |
< |
else |
71 |
< |
{ |
72 |
< |
api::FileReader fin(in); |
73 |
< |
api::FileWriter fout(out); |
74 |
< |
|
75 |
< |
iffy(fin, fout); |
76 |
< |
} |
61 |
> |
iffy(*rin, *rout); |
62 |
|
} |
63 |
|
|
64 |
|
ext::String Iffy::program; |
66 |
|
|
67 |
|
void Iffy::iffy(ios::Reader& in, ios::Writer& out) |
68 |
|
{ |
69 |
< |
ext::String segment; |
70 |
< |
bool text(true); |
71 |
< |
ios::FormatWriter fout(out); |
69 |
> |
ext::Buffer segment; |
70 |
> |
bool text(false); |
71 |
> |
Cleaner cleaner; |
72 |
|
|
73 |
< |
while (read(in, segment, text)) if (text) |
73 |
> |
while (read(in, segment, (text = !text))) if (text) |
74 |
|
{ |
75 |
< |
fout << segment << ios::Flush; |
91 |
< |
|
92 |
< |
text = false; |
75 |
> |
if (!segment.IsEmpty()) cleaner.insert(segment); |
76 |
|
} |
77 |
|
else |
78 |
|
{ |
79 |
+ |
Matcher matcher; |
80 |
+ |
|
81 |
+ |
if (segment == matcher("^!--( \\(\\d{1,2}:\\d{2}:\\d{2} [AP]M\\))--$")) |
82 |
+ |
{ |
83 |
+ |
cleaner.insert(matcher[1]); |
84 |
+ |
|
85 |
+ |
continue; |
86 |
+ |
} |
87 |
+ |
|
88 |
|
Tag tag(segment); |
89 |
|
|
90 |
|
if (tag == "br") tag = STANDALONE; |
91 |
|
|
92 |
< |
// XXX: automagically fix |
92 |
> |
cleaner.insert(tag); |
93 |
> |
} |
94 |
|
|
95 |
< |
fout << tag << ios::Flush; |
95 |
> |
cleaner.clean(); |
96 |
|
|
97 |
< |
text = true; |
98 |
< |
} |
97 |
> |
ios::FormatWriter fout(out); |
98 |
> |
|
99 |
> |
fout << cleaner << ios::NewLine; |
100 |
|
} |
101 |
|
|
102 |
< |
bool Iffy::read(ios::Reader& in, ext::String& segment, bool text) |
102 |
> |
bool Iffy::read(ios::Reader& in, ext::Buffer& segment, bool text) |
103 |
|
{ |
104 |
|
segment.Clear(); |
105 |
|
|