]> cygwin.com Git - cygwin-apps/setup.git/blob - IniParseFindVisitor.cc
2002-05-19 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / IniParseFindVisitor.cc
1 /*
2 * Copyright (c) 2002 Robert Collins.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by Robert Collins <robertc@hotmail.com>
13 *
14 */
15
16 #if 0
17 static const char *cvsid =
18 "\n%%% $Id$\n";
19 #endif
20
21 #include "IniParseFindVisitor.h"
22 #include "IniDBBuilder.h"
23 #include "io_stream.h"
24 #include "rfc1738.h"
25 #include "ini.h"
26 #include <stdexcept>
27
28 extern int yyparse ();
29
30 IniParseFindVisitor::IniParseFindVisitor(IniDBBuilder &aBuilder, String const &localroot) : _Builder (aBuilder), baseLength (localroot.size()), local_ini(0),
31 error_buf(0), error_count (0),
32 setup_timestamp (0), setup_version() {}
33 IniParseFindVisitor::~IniParseFindVisitor(){}
34
35 /* look for potential packages we can add to the in-memory package
36 * database
37 */
38 void
39 IniParseFindVisitor::visitFile(String const &basePath, const WIN32_FIND_DATA *theFile)
40 {
41 //TODO: Test for case sensitivity issues
42 if (String("setup.ini").casecompare(theFile->cFileName))
43 return;
44
45 String path = basePath + theFile->cFileName;
46
47 io_stream *ini_file = io_stream::open (String ("file://") + path, "rb");
48
49 if (!ini_file)
50 // We don't throw an exception, because while this is fatal to parsing, it
51 // isn't to the visitation.
52 {
53 // This should never happen
54 // If we want to handle it happening, use the log strategy call
55 throw new runtime_error ("IniParseFindVisitor: failed to open ini file, which should never happen");
56 return;
57 }
58
59 // FIXME: use a strategy and tell about this as well.
60 // log (LOG_BABBLE, String ("Found ini file - file://") + local_dir + "/" + path);
61
62 /* Copy leading part of path to temporary buffer and unescape it */
63
64 String prefix (&basePath.cstr_oneuse()[baseLength + 1]);
65 String mirror = rfc1738_unescape_part (prefix.substr(0,prefix.size() - 1));
66 _Builder.parse_mirror = mirror;
67 ini_init (ini_file, &_Builder);
68
69 /*yydebug = 1; */
70
71 if (yyparse () || error_count > 0)
72 // FIXME: use a stragtegy and tell on this.
73 //MessageBox (0, error_buf, error_count == 1 ? "Parse Error" : "Parse Errors", 0);
74 ;
75 else
76 local_ini++;
77
78 if (error_buf)
79 *error_buf = '\0';
80 error_count = 0;
81
82 if (_Builder.timestamp > setup_timestamp)
83 {
84 setup_timestamp = _Builder.timestamp;
85 setup_version = _Builder.version;
86 }
87 }
88
89 int
90 IniParseFindVisitor::iniCount() const
91 {
92 return local_ini;
93 }
94
95 unsigned int
96 IniParseFindVisitor::timeStamp () const
97 {
98 return setup_timestamp;
99 }
100
101 String
102 IniParseFindVisitor::version() const
103 {
104 return setup_version;
105 }
This page took 0.038912 seconds and 5 git commands to generate.