ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/Smersh/Person.cpp
(Generate patch)

Comparing Smersh/Person.cpp (file contents):
Revision 169 by Douglas Thrift, 2004-06-19T17:38:00-07:00 vs.
Revision 170 by Douglas Thrift, 2004-06-19T21:57:10-07:00

# Line 8 | Line 8
8  
9   Person::Person(const string& sn) : name("Unknown Person")
10   {
11 <        if (!sn.empty())
11 >        if (file.empty()) configure();
12 >        if (!sn.empty()) query(sn);
13 > }
14 >
15 > string Person::file;
16 > vector<string> Person::args(1, "smersh");
17 > string Person::separator, Person::begin, Person::end;
18 >
19 > void Person::configure()
20 > {
21 >        ext::Handle<xml::Document> document(xml::Parse("smersh.xml"));
22 >        ext::Handle<xml::Node> smersh(*document/"smersh");
23 >
24 >        file = *smersh/"command"/"file";
25 >
26 >        xml::NodeSet nodes(*smersh/"command"/"arg");
27 >
28 >        for (xml::NodeSet::Iterator node(nodes.Begin()); node != nodes.End();
29 >                ++node) args.push_back(**node);
30 >
31 >        separator = *smersh/"separator";
32 >        begin = *smersh/"begin";
33 >        end = *smersh/"end";
34 >
35 >        if (debug)
36 >        {
37 >                cerr << "file = " << file << '\n'
38 >                        << "args = {\n";
39 >
40 >                for (vector<string>::size_type index(0); index < args.size(); ++index)
41 >                {
42 >                        cerr << "   [" << index << "] = " << args[index] << '\n';
43 >                }
44 >
45 >                cerr << "}\n"
46 >                        << "separator = " << separator << '\n'
47 >                        << "begin = " << begin << '\n'
48 >                        << "end = " << end << '\n';
49 >        }
50 > }
51 >
52 > void Person::query(const string& sn)
53 > {
54 >        vector<string> args(Person::args);
55 >        
56 >        args.push_back(string("SELECT name FROM people, peopleaimmap, aim WHERE p")
57 >                + "eople.id=pid AND aid = aim.id AND sn = LOWER(\'" + sn + "\');");
58 >        
59 >        ipstream sql(file, args);
60 >        bool first(true);
61 >        Matcher separator(this->separator), heading(begin + "\\s*name\\s*" + end),
62 >                matcher(begin + "(.*)" + end);
63 >
64 >        do
65          {
66 < //              EXEC SQL SELECT name INTO :name_ :name_ind
67 < //                      FROM people, peopleaimmap, aim
68 < //                      WHERE people.id=pid AND aid = aim.id AND sn = LOWER(:sn_);
66 >                string line;
67 >
68 >                getline(sql, line);
69 >
70 >                if (debug) cerr << "line = " << line << '\n';
71 >
72 >                if (line == separator) continue;
73 >                else if (line == heading) continue;
74 >                else if (line == matcher)
75 >                {
76 >                        if (first)
77 >                        {
78 >                                name = matcher[1];
79 >                                first = false;
80 >                        }
81 >                        else
82 >                        {
83 >                                Person person;
84 >
85 >                                person.name = matcher[1];
86 >
87 >                                multiple.push_back(person);
88 >                        }
89 >                }
90 >                else break;
91          }
92 +        while (sql.good());
93   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines