1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
/***************************************************************************
main.cpp - description
-------------------
begin : Tue May 15 14:30:02 GMT-5 2001
copyright : (C) 2001 by ejoy
email : ejoy@user.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <iostream>
#include <cstdlib>
#include <string>
#include <deque>
#include <algorithm>
using namespace std;
class Word{
public:
Word(){}
Word(const Word& w);
~Word(){};
string mText;
string mCode;
};
Word::Word(const Word& w) {
mText = w.mText;
mCode = w.mCode;
}
bool operator<(const Word& w1,const Word& w2) {
return w1.mCode < w2.mCode;
}
bool operator==(const Word& w1,const Word& w2) {
return (w1.mCode == w2.mCode && w1.mText == w2.mText);
}
void ParseHead(istream& in,ostream& out);
void ParseText(istream& in,ostream& out);
void WriteOption(ostream& out,string& o,string& v);
void ParseOption(string& s,string& o,string& v);
int main(int argc, char *argv[])
{
ParseHead(cin,cout);
ParseText(cin,cout);
return EXIT_SUCCESS;
}
void ParseOption(string& s,string& o,string& v) {
const char* p = s.c_str();
o = "";
v = "";
while (*p != ' ') {
o += *p++;
o += *p++;
}
while (*p == ' ' || *p == '=')
p++;
while (*p && *p != ' ')
v += *p++;
}
void ParseHead(istream& in,ostream& out) {
string s,o,v;
int lines = 0;
out << "[Description]" << endl;
while (in) {
getline(in,s);
lines++;
if (lines >= 28 && lines < 34)
continue;
if (lines == 34)
break; //text area reached
if (s.empty())
continue;
if (s[0] == ' ')
continue; //comments
//now process options
ParseOption(s,o,v);
WriteOption(out,o,v);
}
}
void WriteOption(ostream& out,string& o,string& v) {
if (o == "")
out << "Name=" << v << endl;
else if (o == "Ԫ")
out << "UsedCodes=" << v << endl;
else if (o == "ܼ")
out << "WildChar=" << v << endl;
else if (o == "볤")
out << "MaxCodes=" << v << endl;
}
void ParseText(istream& in,ostream& out) {
out << "[Text]" << endl;
string s,code,text;
deque<class Word> list;
unsigned const char *p;
while (in) {
getline(in,s);
if (s.empty())
continue;
p = (unsigned const char *)s.c_str();
code = "";
while (*p != ' ' && *p < 0xa1)
code += *p++;
while (*p == ' ')
p++;
//now parse a line
while (*p) {
text = "";
while (*p && *p != ' ' && *p != '*') {
text += *p++;
text += *p++;
}
while (*p && (*p == ' ' || *p == '*') )
p++;
Word w;
w.mText = text;
w.mCode = code;
list.push_back(w);
}
}
stable_sort(list.begin(),list.end());
deque<class Word>::iterator w;
for (w = list.begin();w != list.end();w++)
out<<w->mText<<w->mCode<<endl;
}
|