1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 #include <precomp.h>
23 #include "adc_cmd_parse.hxx"
24
25
26 // NOT FULLY DEFINED SERVICES
27 #include <cosv/tpl/tpltools.hxx>
28 #include <adc_cl.hxx>
29 #include "adc_cmds.hxx"
30 #include "cmd_run.hxx"
31
32
33
34 namespace autodoc
35 {
36 namespace command
37 {
38
39 namespace
40 {
41
42 const String C_FileEnding_hxx("*.hxx");
43 const String C_FileEnding_h("*.h");
44 const String C_FileEnding_idl("*.idl");
45 const String C_FileEnding_java("*.java");
46
47 inline void
CHECK(bool b,const String & text)48 CHECK( bool b, const String & text )
49 {
50 if (NOT b)
51 throw X_CommandLine( text );
52 }
53
54 } // anonymous namespace
55
56
57
58 //************************** S_LanguageInfo ***********************//
59
~S_LanguageInfo()60 S_LanguageInfo::~S_LanguageInfo()
61 {
62 }
63
64 void
do_Init(opt_iter & it,opt_iter itEnd)65 S_LanguageInfo::do_Init( opt_iter & it,
66 opt_iter itEnd )
67 {
68 ++it; // Cur is language.
69 CHECKOPT( it != itEnd AND
70 ( *it == C_arg_Cplusplus OR
71 *it == C_arg_Idl OR
72 *it == C_arg_Java ),
73 "language",
74 C_opt_LangAll );
75
76 if ( *it == C_arg_Cplusplus ) {
77 eLanguage = cpp;
78 }
79 else if ( *it == C_arg_Idl ) {
80 eLanguage = idl;
81 }
82 else if ( *it == C_arg_Java ) {
83 eLanguage = java;
84 }
85 else {
86 csv_assert(false);
87 }
88
89 switch (eLanguage)
90 {
91 case cpp: aExtensions.push_back( C_FileEnding_hxx );
92 aExtensions.push_back( C_FileEnding_h );
93 CommandLine::Get_().Set_CppUsed();
94 break;
95 case idl: aExtensions.push_back( C_FileEnding_idl );
96 CommandLine::Get_().Set_IdlUsed();
97 break;
98 case java: aExtensions.push_back( C_FileEnding_java );
99 break;
100 default: // do nothing.
101 ;
102 }
103
104 ++it; // Cur is next option.
105 }
106
107 void
InitExtensions(opt_iter & it,opt_iter itEnd)108 S_LanguageInfo::InitExtensions( opt_iter & it,
109 opt_iter itEnd )
110 {
111 ++it;
112 CHECKOPT( it != itEnd AND (*it).char_at(0) == '.',
113 "extensions",
114 C_opt_ExtensionsAll );
115
116 StreamLock slCheck(150);
117 slCheck() << C_opt_ExtensionsAll
118 << " used without previous "
119 << C_opt_LangAll;
120
121 CHECK( eLanguage != none,
122 slCheck().c_str() );
123
124 do {
125 aExtensions.push_back(*it);
126 ++it;
127 } while (it != itEnd AND (*it).char_at(0) == '.');
128 }
129
130
131
132 //************************** Parse ***********************//
133
Parse()134 Parse::Parse()
135 : sRepositoryName(),
136 aGlobalLanguage(),
137 aProjects(),
138 sDevelopersManual_RefFilePath()
139 {
140 }
141
~Parse()142 Parse::~Parse()
143 {
144 csv::erase_container_of_heap_ptrs(aProjects);
145 }
146
147 void
do_Init(opt_iter & it,opt_iter itEnd)148 Parse::do_Init( opt_iter & it,
149 opt_iter itEnd )
150 {
151 for ( ; it != itEnd; )
152 {
153 if (*it == C_opt_Name)
154 do_clName(it, itEnd);
155 else if (*it == C_opt_LangAll)
156 aGlobalLanguage.Init(it, itEnd);
157 else if (*it == C_opt_ExtensionsAll)
158 aGlobalLanguage.InitExtensions(it, itEnd);
159 else if (*it == C_opt_DevmanFile)
160 do_clDevManual(it, itEnd);
161 else if (*it == C_opt_Project)
162 do_clProject(it, itEnd);
163 else if ( *it == C_opt_SourceTree
164 OR *it == C_opt_SourceDir
165 OR *it == C_opt_SourceFile )
166 do_clDefaultProject(it, itEnd);
167 else
168 break;
169 } // for
170 }
171
172 void
do_clName(opt_iter & it,opt_iter itEnd)173 Parse::do_clName( opt_iter & it,
174 opt_iter itEnd )
175 {
176 ++it;
177 CHECKOPT( it != itEnd AND (*it).char_at(0) != '-',
178 "name",
179 C_opt_Name );
180 sRepositoryName = *it;
181 ++it;
182 }
183
184 void
do_clDevManual(opt_iter & it,opt_iter itEnd)185 Parse::do_clDevManual( opt_iter & it,
186 opt_iter itEnd )
187 {
188 ++it;
189 CHECKOPT( it != itEnd AND (*it).char_at(0) != '-',
190 "link file path",
191 C_opt_DevmanFile );
192 sDevelopersManual_RefFilePath = *it;
193 ++it;
194 }
195
196 void
do_clProject(opt_iter & it,opt_iter itEnd)197 Parse::do_clProject( opt_iter & it,
198 opt_iter itEnd )
199 {
200 if ( aProjects.size() == 1 )
201 {
202 if ( aProjects.front()->IsDefault() )
203 throw X_CommandLine( "Both, named projects and a default project, cannot be used together." );
204 }
205
206 S_ProjectData * dpProject = new S_ProjectData(aGlobalLanguage);
207 ++it;
208 dpProject->Init(it, itEnd);
209 aProjects.push_back(dpProject);
210 }
211
212 void
do_clDefaultProject(opt_iter & it,opt_iter itEnd)213 Parse::do_clDefaultProject( opt_iter & it,
214 opt_iter itEnd )
215 {
216 if ( aProjects.size() > 0 )
217 {
218 throw X_CommandLine( "Both, named projects and a default project, cannot be used together." );
219 }
220
221 S_ProjectData * dpProject = new S_ProjectData( aGlobalLanguage,
222 S_ProjectData::default_prj );
223 dpProject->Init(it, itEnd);
224 aProjects.push_back(dpProject);
225 }
226
227 bool
do_Run() const228 Parse::do_Run() const
229 {
230 run::Parser
231 aParser(*this);
232 return aParser.Perform();
233 }
234
235 int
inq_RunningRank() const236 Parse::inq_RunningRank() const
237 {
238 return static_cast<int>(rank_Parse);
239 }
240
241
242
243 //************************** S_Sources ***********************//
244
245 void
do_Init(opt_iter & it,opt_iter itEnd)246 S_Sources::do_Init( opt_iter & it,
247 opt_iter itEnd )
248 {
249 StringVector *
250 pList = 0;
251 csv_assert((*it)[0] == '-');
252
253 for ( ; it != itEnd; ++it)
254 {
255 if ((*it)[0] == '-')
256 {
257 if (*it == C_opt_SourceTree)
258 pList = &aTrees;
259 else if (*it == C_opt_SourceDir)
260 pList = &aDirectories;
261 else if (*it == C_opt_SourceFile)
262 pList = &aFiles;
263 else
264 return;
265 }
266 else
267 pList->push_back(*it);
268 } // end for
269 }
270
271
272
273 //************************** S_ProjectData ***********************//
274
275
S_ProjectData(const S_LanguageInfo & i_globalLanguage)276 S_ProjectData::S_ProjectData( const S_LanguageInfo & i_globalLanguage )
277 : sName(),
278 aRootDirectory(),
279 aLanguage(i_globalLanguage),
280 aFiles(),
281 bIsDefault(false)
282 {
283 }
284
S_ProjectData(const S_LanguageInfo & i_globalLanguage,E_Default)285 S_ProjectData::S_ProjectData( const S_LanguageInfo & i_globalLanguage,
286 E_Default )
287 : sName(),
288 aRootDirectory("."),
289 aLanguage(i_globalLanguage),
290 aFiles(),
291 bIsDefault(true)
292 {
293 }
294
~S_ProjectData()295 S_ProjectData::~S_ProjectData()
296 {
297 }
298
299 void
do_Init(opt_iter & it,opt_iter itEnd)300 S_ProjectData::do_Init( opt_iter & it,
301 opt_iter itEnd )
302 {
303 if (NOT IsDefault())
304 {
305 CHECKOPT( it != itEnd AND (*it).char_at(0) != '-',
306 "name",
307 C_opt_Project );
308 sName = *it;
309 ++it;
310
311 CHECKOPT( it != itEnd AND (*it).char_at(0) != '-',
312 "root directory",
313 C_opt_Project );
314 aRootDirectory.Set((*it).c_str(), true);
315 ++it;
316 }
317
318 for ( ; it != itEnd; )
319 {
320 if ( *it == C_opt_SourceTree
321 OR *it == C_opt_SourceDir
322 OR *it == C_opt_SourceFile )
323 aFiles.Init(it, itEnd);
324 // else if (*it == C_opt_Lang)
325 // aLanguage.Init(it, itEnd);
326 // else if (*it == C_opt_Extensions)
327 // aLanguage.InitExtensions(it, itEnd);
328 else
329 break;
330 } // for
331 }
332
333 } // namespace command
334 } // namespace autodoc
335
336
337
338