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