~lidaobing/+junk/zhcon

« back to all changes in this revision

Viewing changes to tools/uc2win.cpp

  • Committer: LI Daobing
  • Date: 2008-11-04 04:39:18 UTC
  • Revision ID: lidaobing@gmail.com-20081104043918-nfwwvgfb0uied0mt
import 1:0.2.6-5.1

Show diffs side-by-side

added added

removed removed

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