]>
Commit | Line | Data |
---|---|---|
b401ef47 RC |
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" | |
67829ce0 | 22 | #include "IniParseFeedback.h" |
b401ef47 RC |
23 | #include "IniDBBuilder.h" |
24 | #include "io_stream.h" | |
25 | #include "rfc1738.h" | |
26 | #include "ini.h" | |
27 | #include <stdexcept> | |
28 | ||
29 | extern int yyparse (); | |
30 | ||
67829ce0 | 31 | IniParseFindVisitor::IniParseFindVisitor(IniDBBuilder &aBuilder, String const &localroot, IniParseFeedback const &feedback) : _Builder (aBuilder), _feedback (feedback), baseLength (localroot.size()), local_ini(0), |
b401ef47 RC |
32 | error_buf(0), error_count (0), |
33 | setup_timestamp (0), setup_version() {} | |
34 | IniParseFindVisitor::~IniParseFindVisitor(){} | |
35 | ||
36 | /* look for potential packages we can add to the in-memory package | |
37 | * database | |
38 | */ | |
39 | void | |
40 | IniParseFindVisitor::visitFile(String const &basePath, const WIN32_FIND_DATA *theFile) | |
41 | { | |
42 | //TODO: Test for case sensitivity issues | |
43 | if (String("setup.ini").casecompare(theFile->cFileName)) | |
44 | return; | |
45 | ||
46 | String path = basePath + theFile->cFileName; | |
47 | ||
48 | io_stream *ini_file = io_stream::open (String ("file://") + path, "rb"); | |
49 | ||
50 | if (!ini_file) | |
51 | // We don't throw an exception, because while this is fatal to parsing, it | |
52 | // isn't to the visitation. | |
53 | { | |
54 | // This should never happen | |
55 | // If we want to handle it happening, use the log strategy call | |
56 | throw new runtime_error ("IniParseFindVisitor: failed to open ini file, which should never happen"); | |
57 | return; | |
58 | } | |
59 | ||
67829ce0 | 60 | _feedback.babble (String ("Found ini file - ") + path); |
b401ef47 RC |
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) | |
67829ce0 | 72 | _feedback.error(error_buf); |
b401ef47 RC |
73 | else |
74 | local_ini++; | |
75 | ||
76 | if (error_buf) | |
77 | *error_buf = '\0'; | |
78 | error_count = 0; | |
79 | ||
80 | if (_Builder.timestamp > setup_timestamp) | |
81 | { | |
82 | setup_timestamp = _Builder.timestamp; | |
83 | setup_version = _Builder.version; | |
84 | } | |
85 | } | |
86 | ||
87 | int | |
88 | IniParseFindVisitor::iniCount() const | |
89 | { | |
90 | return local_ini; | |
91 | } | |
92 | ||
93 | unsigned int | |
94 | IniParseFindVisitor::timeStamp () const | |
95 | { | |
96 | return setup_timestamp; | |
97 | } | |
98 | ||
99 | String | |
100 | IniParseFindVisitor::version() const | |
101 | { | |
102 | return setup_version; | |
103 | } |