Merge lp:~paul-lucas/zorba/pjl-misc into lp:zorba

Proposed by Paul J. Lucas
Status: Merged
Approved by: Paul J. Lucas
Approved revision: 11425
Merged at revision: 11694
Proposed branch: lp:~paul-lucas/zorba/pjl-misc
Merge into: lp:zorba
Diff against target: 9065 lines (+3292/-3960)
80 files modified
bin/CMakeLists.txt (+3/-4)
bin/path_util.cpp (+0/-85)
bin/path_util.h (+0/-41)
bin/timers.cpp (+176/-0)
bin/timers.h (+73/-0)
bin/util.cpp (+0/-37)
bin/util.h (+25/-19)
bin/zorbacmd.cpp (+536/-971)
bin/zorbacmd_args.cpp (+783/-0)
bin/zorbacmd_props.cpp (+45/-199)
bin/zorbacmd_props.h (+101/-107)
bin/zorbacmdproperties.txt (+0/-40)
bin/zorbacmdproperties_base.cpp (+0/-374)
bin/zorbacmdproperties_base.h (+0/-142)
include/zorba/properties.h (+400/-0)
include/zorba/properties_base.h (+7/-130)
include/zorba/util/fs_util.h (+41/-0)
include/zorba/util/smart_ptr.h (+6/-0)
include/zorba/zorba.h (+14/-5)
src/api/CMakeLists.txt (+1/-0)
src/api/properties.cpp (+79/-366)
src/api/zorbaimpl.cpp (+3/-3)
src/api/zorbaimpl.h (+1/-1)
src/compiler/api/compiler_api.cpp (+2/-2)
src/compiler/api/compilercb.cpp (+11/-12)
src/compiler/codegen/plan_visitor.cpp (+6/-9)
src/compiler/expression/expr_base.cpp (+1/-1)
src/compiler/expression/expr_put.cpp (+3/-4)
src/compiler/parser/xquery_driver.cpp (+6/-5)
src/compiler/rewriter/framework/default_optimizer.cpp (+9/-9)
src/compiler/rewriter/framework/rule_driver.cpp (+3/-3)
src/compiler/rewriter/rules/flwor_rules.cpp (+2/-2)
src/compiler/rewriter/rules/index_join_rule.cpp (+2/-2)
src/compiler/rewriter/rules/index_matching_rule.cpp (+1/-1)
src/compiler/rewriter/rules/type_rules.cpp (+1/-1)
src/compiler/translator/translator.cpp (+10/-11)
src/diagnostics/zorba_exception.cpp (+15/-6)
src/functions/function_impl.h (+2/-2)
src/runtime/api/plan_wrapper.cpp (+2/-2)
src/runtime/base/plan_iterator.cpp (+2/-2)
src/runtime/full_text/apply.cpp (+3/-3)
src/runtime/full_text/ftcontains_visitor.cpp (+3/-3)
src/runtime/jsound/jsound_util.cpp (+2/-2)
src/runtime/spec/printer_visitor_cpp.xq (+15/-10)
src/runtime/visitors/pregenerated/printer_visitor.cpp (+3/-3)
src/runtime/visitors/printer_visitor_impl.cpp (+15/-15)
src/store/naive/CMakeLists.txt (+0/-1)
src/store/naive/properties.cpp (+0/-115)
src/store/naive/properties.h (+0/-74)
src/store/naive/store.cpp (+3/-8)
src/store/naive/store_properties.h (+0/-112)
src/store/naive/store_properties.txt (+0/-2)
src/system/CMakeLists.txt (+4/-3)
src/system/properties.cpp (+0/-182)
src/system/properties.h (+0/-126)
src/system/zorba_properties.h (+0/-145)
src/system/zorba_properties.txt (+0/-49)
src/unit_tests/test_stemmer.cpp (+1/-4)
src/unit_tests/test_thesaurus.cpp (+2/-5)
src/unit_tests/test_tokenizer.cpp (+1/-4)
src/util/fs_util.cpp (+16/-2)
src/zorbautils/CMakeLists.txt (+0/-1)
src/zorbautils/properties_base.cpp (+0/-192)
test/driver/testdriver.cpp (+0/-9)
test/driver/testdriver_common.cpp (+13/-10)
test/driver/testdriver_mt.cpp (+0/-4)
test/driver/updtestdriver.cpp (+0/-3)
test/extern/test_extern_func.cpp (+0/-4)
test/iterplans/CMakeLists.txt (+7/-1)
test/iterplans/apitest.cpp (+156/-239)
test/iterplans/apitest_args.cpp (+541/-0)
test/iterplans/apitest_props.cpp (+50/-0)
test/iterplans/apitest_props.h (+81/-0)
test/unit/context_item.cpp (+0/-4)
test/unit/ext_in_opt.cpp (+0/-4)
test/unit/main_sequential.cpp (+0/-4)
test/unit/no_folding.cpp (+0/-4)
test/unit/plan_serializer.cpp (+4/-9)
test/unit/staticcollectionmanager.cpp (+0/-4)
test/unit/streamable_string.cpp (+0/-2)
To merge this branch: bzr merge lp:~paul-lucas/zorba/pjl-misc
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Paul J. Lucas Approve
Review via email: mp+205515@code.launchpad.net

Commit message

Major clean-up of properties, zorbacmd, and apitest command-line arguments.

Description of the change

Major clean-up of properties, zorbacmd, and apitest command-line arguments.

To post a comment you must log in.
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/205515

Progress dashboard at http://jenkins.zorba.io:8180/view/ValidationQueue

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue result for https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/205515

Stage "BuildZorbaUbuntu" failed.

Check compiler output at http://jenkins.zorba.io:8180/job/BuildZorbaUbuntu/513/parsed_console to view the results.

lp:~paul-lucas/zorba/pjl-misc updated
11426. By Paul J. Lucas

Fixed abort.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/205515

Progress dashboard at http://jenkins.zorba.io:8180/view/ValidationQueue

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue result for https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/205515

Stage "BuildZorbaUbuntu" failed.

Check compiler output at http://jenkins.zorba.io:8180/job/BuildZorbaUbuntu/514/parsed_console to view the results.

lp:~paul-lucas/zorba/pjl-misc updated
11427. By Paul J. Lucas

More fixes.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/205515

Progress dashboard at http://jenkins.zorba.io:8180/view/ValidationQueue

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue result for https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/205515

Stage "BuildZorbaUbuntu" failed.

Check compiler output at http://jenkins.zorba.io:8180/job/BuildZorbaUbuntu/515/parsed_console to view the results.

lp:~paul-lucas/zorba/pjl-misc updated
11428. By Paul J. Lucas

More fixes.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/205515

Progress dashboard at http://jenkins.zorba.io:8180/view/ValidationQueue

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue result for https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/205515

Stage "BuildZorbaUbuntu" failed.

Check compiler output at http://jenkins.zorba.io:8180/job/BuildZorbaUbuntu/516/parsed_console to view the results.

lp:~paul-lucas/zorba/pjl-misc updated
11429. By Paul J. Lucas

More fixes.

11430. By Paul J. Lucas

More fixes.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/205515

Progress dashboard at http://jenkins.zorba.io:8180/view/ValidationQueue

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue result for https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/205515

Stage "TestZorbaUbuntu" failed.
34 tests failed (8754 total tests run).

Check test results at http://jenkins.zorba.io:8180/job/TestZorbaUbuntu/454/testReport/ to view the results.

lp:~paul-lucas/zorba/pjl-misc updated
11431. By Paul J. Lucas

Added endl.

11432. By Paul J. Lucas

Memory fixes.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/205515

Progress dashboard at http://jenkins.zorba.io:8180/view/ValidationQueue

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting criteria failed for the following merge proposals:

https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/205515 :
Votes: {'Approve': 1}

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue result for https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/205515

Stage "CommitZorba" failed.

Check console output at http://jenkins.zorba.io:8180/job/CommitZorba/287/console to view the results.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/205515

Progress dashboard at http://jenkins.zorba.io:8180/view/ValidationQueue

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue succeeded - proposal merged!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/CMakeLists.txt'
2--- bin/CMakeLists.txt 2014-01-31 23:27:47 +0000
3+++ bin/CMakeLists.txt 2014-02-11 00:42:47 +0000
4@@ -44,11 +44,10 @@
5 ENDIF (ZORBA_WITH_DEBUGGER)
6
7 SET(SRCS
8+ zorbacmd_args.cpp
9+ zorbacmd_props.cpp
10+ timers.cpp
11 zorbacmd.cpp
12- zorbacmdproperties_base.cpp
13- zorbacmdproperties.cpp
14- util.cpp
15- path_util.cpp
16 )
17
18 ZORBA_GENERATE_EXE("zorbacmd" "${SRCS}" "" "zorba" "bin")
19
20=== removed file 'bin/path_util.cpp'
21--- bin/path_util.cpp 2013-05-31 03:38:45 +0000
22+++ bin/path_util.cpp 1970-01-01 00:00:00 +0000
23@@ -1,85 +0,0 @@
24-/*
25- * Copyright 2006-2008 The FLWOR Foundation.
26- *
27- * Licensed under the Apache License, Version 2.0 (the "License");
28- * you may not use this file except in compliance with the License.
29- * You may obtain a copy of the License at
30- *
31- * http://www.apache.org/licenses/LICENSE-2.0
32- *
33- * Unless required by applicable law or agreed to in writing, software
34- * distributed under the License is distributed on an "AS IS" BASIS,
35- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36- * See the License for the specific language governing permissions and
37- * limitations under the License.
38- */
39-
40-#include "path_util.h"
41-
42-#include <cstdlib>
43-
44-#include <zorba/static_context.h>
45-#include <zorba/util/fs_util.h>
46-
47-#include "util.h"
48-#include "zorbacmdproperties.h"
49-
50-namespace zorba {
51-
52-namespace PathUtil {
53-
54-void
55-tokenizePath(
56- const std::string& aPathStr,
57- std::vector<String>& aResult)
58-{
59- std::vector<std::string> lPath;
60-#ifdef WIN32
61- Util::tokenize(aPathStr, ";", lPath);
62-#else
63- Util::tokenize(aPathStr, ":", lPath);
64-#endif
65- for (std::vector<std::string>::iterator lIter = lPath.begin();
66- lIter != lPath.end(); ++lIter) {
67- aResult.push_back(*lIter);
68- }
69-}
70-
71-void
72-setPathsOnContext(
73- const ZorbaCMDProperties& aProperties,
74- StaticContext_t& aStaticCtx)
75-{
76- std::vector<String> lPath;
77- std::string lPathStr;
78-
79- // Compute the current working directory to append to all paths.
80- std::string lCWD( fs::curdir() );
81-
82- // setModulePaths() *overwrites* the URI path and lib path, so there's no
83- // sense in calling both. So if --module-path exists, just use it.
84- aProperties.getModulePath(lPathStr);
85- if (lPathStr.length() > 0) {
86- tokenizePath(lPathStr, lPath);
87- lPath.push_back(lCWD);
88- aStaticCtx->setModulePaths(lPath);
89- }
90- else {
91- // Compute and set URI path
92- aProperties.getURIPath(lPathStr);
93- tokenizePath(lPathStr, lPath);
94- lPath.push_back(lCWD);
95- aStaticCtx->setURIPath(lPath);
96- lPath.clear();
97-
98- // Compute and set lib path
99- aProperties.getLibPath(lPathStr);
100- tokenizePath(lPathStr, lPath);
101- lPath.push_back(lCWD);
102- aStaticCtx->setLibPath(lPath);
103- }
104-}
105-
106-} /* namespace ModulePath */
107-
108-} /* namespace zorba */
109
110=== removed file 'bin/path_util.h'
111--- bin/path_util.h 2013-02-07 17:24:36 +0000
112+++ bin/path_util.h 1970-01-01 00:00:00 +0000
113@@ -1,41 +0,0 @@
114-/*
115- * Copyright 2006-2008 The FLWOR Foundation.
116- *
117- * Licensed under the Apache License, Version 2.0 (the "License");
118- * you may not use this file except in compliance with the License.
119- * You may obtain a copy of the License at
120- *
121- * http://www.apache.org/licenses/LICENSE-2.0
122- *
123- * Unless required by applicable law or agreed to in writing, software
124- * distributed under the License is distributed on an "AS IS" BASIS,
125- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
126- * See the License for the specific language governing permissions and
127- * limitations under the License.
128- */
129-#ifndef ZORBA_MODULE_PATH_H
130-#define ZORBA_MODULE_PATH_H
131-
132-#include <vector>
133-#include <string>
134-#include <zorba/api_shared_types.h>
135-
136-class ZorbaCMDProperties;
137-
138-namespace zorba {
139-
140- class String;
141-
142- namespace PathUtil {
143-
144- void
145- setPathsOnContext(const ZorbaCMDProperties& aProperties,
146- zorba::StaticContext_t& aStaticCtx);
147-
148- void
149- tokenizePath(const std::string& aPathStr, std::vector<String>& aResult);
150-
151- }
152-} /* namespace zorba */
153-
154-#endif
155
156=== added file 'bin/timers.cpp'
157--- bin/timers.cpp 1970-01-01 00:00:00 +0000
158+++ bin/timers.cpp 2014-02-11 00:42:47 +0000
159@@ -0,0 +1,176 @@
160+/*
161+ * Copyright 2006-2008 The FLWOR Foundation.
162+ *
163+ * Licensed under the Apache License, Version 2.0 (the "License");
164+ * you may not use this file except in compliance with the License.
165+ * You may obtain a copy of the License at
166+ *
167+ * http://www.apache.org/licenses/LICENSE-2.0
168+ *
169+ * Unless required by applicable law or agreed to in writing, software
170+ * distributed under the License is distributed on an "AS IS" BASIS,
171+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
172+ * See the License for the specific language governing permissions and
173+ * limitations under the License.
174+ */
175+
176+// local
177+#include "timers.h"
178+
179+using namespace std;
180+
181+///////////////////////////////////////////////////////////////////////////////
182+
183+#define INIT_TIMER(KIND) \
184+ elapsed_##KIND##_walltime( 0 ), \
185+ elapsed_##KIND##_cputime( 0 )
186+
187+#define START_TIMER(KIND) \
188+ zorba::time::get_current_walltime( start_##KIND##_walltime ); \
189+ zorba::time::get_current_cputime( start_##KIND##_cputime )
190+
191+#define STOP_TIMER(KIND) \
192+ zorba::time::get_current_walltime( stop_##KIND##_walltime ); \
193+ elapsed_##KIND##_walltime += zorba::time::get_walltime_elapsed( start_##KIND##_walltime, stop_##KIND##_walltime ); \
194+ zorba::time::get_current_cputime( stop_##KIND##_cputime ); \
195+ elapsed_##KIND##_cputime += zorba::time::get_cputime_elapsed( start_##KIND##_cputime, stop_##KIND##_cputime )
196+
197+Timers::Timers( unsigned long num_execs ) :
198+ num_execs_( num_execs ),
199+ INIT_TIMER( init ),
200+ INIT_TIMER( deinit ),
201+ INIT_TIMER( comp ),
202+ INIT_TIMER( exec ),
203+ INIT_TIMER( load ),
204+ INIT_TIMER( unload ),
205+ INIT_TIMER( plan_save ),
206+ INIT_TIMER( plan_load ),
207+ INIT_TIMER( total )
208+{
209+}
210+
211+void Timers::startTimer( kind k, unsigned long iteration ) {
212+ if ( iteration == 0 && num_execs_ > 1 )
213+ return;
214+ switch ( k ) {
215+ case init:
216+ START_TIMER( init );
217+ break;
218+ case deinit:
219+ START_TIMER( deinit );
220+ break;
221+ case total:
222+ START_TIMER( total );
223+ break;
224+ case comp:
225+ START_TIMER( comp );
226+ break;
227+ case exec:
228+ START_TIMER( exec );
229+ break;
230+ case unload:
231+ START_TIMER( unload );
232+ break;
233+ case plan_save:
234+ START_TIMER( plan_save );
235+ break;
236+ case plan_load:
237+ START_TIMER( plan_load );
238+ break;
239+ } // switch
240+}
241+
242+void Timers::stopTimer( kind k, unsigned long iteration ) {
243+ if ( iteration == 0 && num_execs_ > 1 )
244+ return;
245+ switch ( k ) {
246+ case init:
247+ STOP_TIMER( init );
248+ break;
249+ case deinit:
250+ STOP_TIMER( deinit );
251+ break;
252+ case total:
253+ STOP_TIMER( total );
254+ break;
255+ case comp:
256+ STOP_TIMER( comp );
257+ break;
258+ case exec:
259+ STOP_TIMER( exec );
260+ break;
261+ case unload:
262+ STOP_TIMER( unload );
263+ break;
264+ case plan_save:
265+ STOP_TIMER( plan_save );
266+ break;
267+ case plan_load:
268+ STOP_TIMER( plan_load );
269+ break;
270+ } // switch
271+}
272+
273+ostream& Timers::print( ostream &os, bool serializePlan ) {
274+ os.precision( 3 );
275+ os.setf( ios::fixed );
276+
277+ os << "\nNumber of executions = " << num_execs_ << endl;
278+
279+ unsigned long timeDiv = num_execs_ == 1 ? 1 : (num_execs_ - 1);
280+ double cWalltime = elapsed_comp_walltime / timeDiv;
281+ double eWalltime = elapsed_exec_walltime / timeDiv;
282+ double lWalltime = elapsed_load_walltime / timeDiv;
283+ double uWalltime = elapsed_unload_walltime / timeDiv;
284+ double psWalltime = elapsed_plan_save_walltime / timeDiv;
285+ double plWalltime = elapsed_plan_load_walltime / timeDiv;
286+ double tWalltime = elapsed_total_walltime / timeDiv;
287+
288+ double cCputime = elapsed_comp_cputime / timeDiv;
289+ double eCputime = elapsed_exec_cputime / timeDiv;
290+ double lCputime = elapsed_load_cputime / timeDiv;
291+ double uCputime = elapsed_unload_cputime / timeDiv;
292+ double psCputime = elapsed_plan_save_cputime / timeDiv;
293+ double plCputime = elapsed_plan_load_cputime / timeDiv;
294+ double tCputime = elapsed_total_cputime / timeDiv;
295+
296+ os << "Engine Startup Time : " << elapsed_init_walltime
297+ << " (user: " << elapsed_init_cputime << ")"
298+ << " milliseconds" << endl;
299+
300+ os << "Average Compilation Time: " << cWalltime
301+ << " (user: " << cCputime << ")"
302+ << " milliseconds" << endl;
303+
304+ if ( serializePlan ) {
305+ os << "Average Plan Saving Time: " << psWalltime
306+ << " (user: " << psCputime << ")"
307+ << " milliseconds" << endl;
308+
309+ os << "Average Plan Loading Time: " << plWalltime
310+ << " (user: " << plCputime << ")"
311+ << " milliseconds" << endl;
312+ }
313+
314+ os << "Average Execution Time : " << eWalltime - lWalltime
315+ << " (user: " << eCputime - lCputime << ")"
316+ << " milliseconds" << endl;
317+
318+ os << "Average Loading Time : " << lWalltime
319+ << " (user: " << lCputime << ")"
320+ << " milliseconds" << endl;
321+
322+ os << "Average Unloading Time : " << uWalltime
323+ << " (user: " << uCputime << ")"
324+ << " milliseconds" << endl;
325+
326+ os << "Average Total Time : " << tWalltime
327+ << " (user: " << tCputime << ")"
328+ << " milliseconds" << endl;
329+
330+ return os;
331+}
332+
333+///////////////////////////////////////////////////////////////////////////////
334+
335+/* vim:set et sw=2 ts=2: */
336
337=== added file 'bin/timers.h'
338--- bin/timers.h 1970-01-01 00:00:00 +0000
339+++ bin/timers.h 2014-02-11 00:42:47 +0000
340@@ -0,0 +1,73 @@
341+/*
342+ * Copyright 2006-2008 The FLWOR Foundation.
343+ *
344+ * Licensed under the Apache License, Version 2.0 (the "License");
345+ * you may not use this file except in compliance with the License.
346+ * You may obtain a copy of the License at
347+ *
348+ * http://www.apache.org/licenses/LICENSE-2.0
349+ *
350+ * Unless required by applicable law or agreed to in writing, software
351+ * distributed under the License is distributed on an "AS IS" BASIS,
352+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
353+ * See the License for the specific language governing permissions and
354+ * limitations under the License.
355+ */
356+
357+#ifndef ZORBA_CMD_TIMERS_H
358+#define ZORBA_CMD_TIMERS_H
359+
360+// standard
361+#include <iostream>
362+
363+// Zorba
364+#include <zorba/util/time.h>
365+
366+///////////////////////////////////////////////////////////////////////////////
367+
368+#define DECLARE_TIMER(KIND) \
369+ zorba::time::walltime start_##KIND##_walltime; \
370+ zorba::time::walltime stop_##KIND##_walltime; \
371+ zorba::time::cputime start_##KIND##_cputime; \
372+ zorba::time::cputime stop_##KIND##_cputime; \
373+ double elapsed_##KIND##_walltime; \
374+ double elapsed_##KIND##_cputime
375+
376+struct Timers {
377+ enum kind {
378+ init,
379+ deinit,
380+ comp,
381+ exec,
382+ unload,
383+ plan_save,
384+ plan_load,
385+ total
386+ };
387+
388+ unsigned long num_execs_;
389+
390+ DECLARE_TIMER( init );
391+ DECLARE_TIMER( deinit );
392+ DECLARE_TIMER( comp );
393+ DECLARE_TIMER( exec );
394+ DECLARE_TIMER( load );
395+ DECLARE_TIMER( unload );
396+ DECLARE_TIMER( plan_save );
397+ DECLARE_TIMER( plan_load );
398+ DECLARE_TIMER( total );
399+
400+ Timers( unsigned long num_execs );
401+
402+ void startTimer( kind, unsigned long iteration );
403+ void stopTimer( kind, unsigned long iteration );
404+
405+ std::ostream& print( std::ostream&, bool );
406+};
407+
408+#undef DECLARE_TIMER
409+
410+///////////////////////////////////////////////////////////////////////////////
411+
412+#endif /* ZORBA_CMD_TIMERS_H */
413+/* vim:set et sw=2 ts=2: */
414
415=== removed file 'bin/util.cpp'
416--- bin/util.cpp 2013-02-07 17:24:36 +0000
417+++ bin/util.cpp 1970-01-01 00:00:00 +0000
418@@ -1,37 +0,0 @@
419-/*
420- * Copyright 2006-2008 The FLWOR Foundation.
421- *
422- * Licensed under the Apache License, Version 2.0 (the "License");
423- * you may not use this file except in compliance with the License.
424- * You may obtain a copy of the License at
425- *
426- * http://www.apache.org/licenses/LICENSE-2.0
427- *
428- * Unless required by applicable law or agreed to in writing, software
429- * distributed under the License is distributed on an "AS IS" BASIS,
430- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
431- * See the License for the specific language governing permissions and
432- * limitations under the License.
433- */
434-
435-#include "util.h"
436-
437-namespace zorba {
438-
439- void
440- Util::tokenize(const std::string& str,
441- const std::string& delimiters,
442- std::vector<std::string>& tokens)
443- {
444- std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
445-
446- std::string::size_type pos = str.find_first_of(delimiters, lastPos);
447-
448- while (std::string::npos != pos || std::string::npos != lastPos) {
449- tokens.push_back(str.substr(lastPos, pos - lastPos));
450- lastPos = str.find_first_not_of(delimiters, pos);
451- pos = str.find_first_of(delimiters, lastPos);
452- }
453- }
454-
455-} /* namespace zorba */
456
457=== modified file 'bin/util.h'
458--- bin/util.h 2013-02-07 17:24:36 +0000
459+++ bin/util.h 2014-02-11 00:42:47 +0000
460@@ -13,23 +13,29 @@
461 * See the License for the specific language governing permissions and
462 * limitations under the License.
463 */
464-#ifndef ZORBA_UTIL_H
465-#define ZORBA_UTIL_H
466-
467+
468+#ifndef ZORBA_CMD_UTIL_H
469+#define ZORBA_CMD_UTIL_H
470+
471+#include <string>
472 #include <vector>
473-#include <string>
474-
475-namespace zorba {
476-
477- class Util {
478- public:
479- static void
480- tokenize(const std::string& str,
481- const std::string& delimiters,
482- std::vector<std::string>& tokens);
483-
484- };
485-} /* namespace zorba */
486-
487-#endif
488-
489+
490+///////////////////////////////////////////////////////////////////////////////
491+
492+template<class InStringType,class OutStringType>
493+void tokenize( InStringType const &s, char delim,
494+ std::vector<OutStringType> *tokens ) {
495+ typename InStringType::size_type last_pos = s.find_first_not_of( delim, 0 );
496+ typename InStringType::size_type pos = s.find_first_of( delim, last_pos );
497+
498+ while ( pos != InStringType::npos || last_pos != InStringType::npos ) {
499+ tokens->push_back( s.substr( last_pos, pos - last_pos ).c_str() );
500+ last_pos = s.find_first_not_of( delim, pos );
501+ pos = s.find_first_of( delim, last_pos );
502+ }
503+}
504+
505+///////////////////////////////////////////////////////////////////////////////
506+
507+#endif /* ZORBA_CMD_UTIL_H */
508+/* vim:set et sw=2 ts=2: */
509
510=== modified file 'bin/zorbacmd.cpp'
511--- bin/zorbacmd.cpp 2013-09-17 21:12:49 +0000
512+++ bin/zorbacmd.cpp 2014-02-11 00:42:47 +0000
513@@ -14,34 +14,34 @@
514 * limitations under the License.
515 */
516
517-#include "zorbacmdproperties.h"
518-
519+// standard
520+#include <cassert>
521+#include <fstream>
522 #include <iostream>
523-#include <fstream>
524 #include <sstream>
525+#include <string>
526 #include <vector>
527-#include <string>
528-#include <cassert>
529
530 #ifdef WIN32
531 #include <windows.h>
532-#define sleep(s) Sleep(s*1000)
533-#endif
534+#endif /* WIN32 */
535
536-#include <zorba/zorba.h>
537-#include <zorba/zorba_exception.h>
538-#include <zorba/xquery_exception.h>
539+// Zorba
540+#include <zorba/audit.h>
541+#include <zorba/audit_scoped.h>
542 #include <zorba/document_manager.h>
543+#include <zorba/internal/unique_ptr.h>
544 #include <zorba/item_sequence.h>
545 #include <zorba/iterator.h>
546-#include <zorba/xquery_functions.h>
547-#include <zorba/uri_resolvers.h>
548+#include <zorba/properties.h>
549 #include <zorba/serialization_callback.h>
550-#include <zorba/audit.h>
551-#include <zorba/audit_scoped.h>
552 #include <zorba/store_manager.h>
553+#include <zorba/uri_resolvers.h>
554 #include <zorba/util/fs_util.h>
555-#include <zorba/internal/unique_ptr.h>
556+#include <zorba/xquery_exception.h>
557+#include <zorba/xquery_functions.h>
558+#include <zorba/zorba.h>
559+#include <zorba/zorba_exception.h>
560
561 //#define DO_AUDIT
562
563@@ -50,850 +50,464 @@
564 #include <zorba/audit_scoped.h>
565 #endif
566
567+// local
568+#include "timers.h"
569 #include "util.h"
570-#include "path_util.h"
571-
572-// Timing utilities, including wall-clock timing
573-#include <zorba/util/time.h>
574+#include "zorbacmd_props.h"
575
576 // toggle this to allow configuration via a system properties file
577 // (see src/system/properties.*)
578 #define ZORBACMD_LOAD_SYSTEM_PROPERTIES 1
579
580-#if ZORBACMD_LOAD_SYSTEM_PROPERTIES
581-# include "system/properties.h"
582-#endif
583-
584-//#define DO_AUDIT
585-
586+using namespace std;
587 using namespace zorba;
588-namespace zorbatm = zorba::time;
589-
590-const char *copyright_str =
591- "Copyright 2006-2009 The FLWOR Foundation.\n"
592+
593+extern char const* get_help_msg();
594+extern int parse_args( int argc, char const *argv[] );
595+static void set_paths_on_sctx( StaticContext_t& );
596+
597+///////////////////////////////////////////////////////////////////////////////
598+
599+static const char copyright[] =
600+ "Copyright 2006-2014 The FLWOR Foundation.\n"
601 "License: Apache License 2.0: <http://www.apache.org/licenses/LICENSE-2.0>";
602
603 #ifndef ZORBA_NO_FULL_TEXT
604-OneToOneURIMapper theStopWordsMapper(EntityData::STOP_WORDS);
605-OneToOneURIMapper theThesaurusMapper(EntityData::THESAURUS);
606-#endif
607-
608-
609-/*******************************************************************************
610-
611-********************************************************************************/
612-class URIMapperSerializationCallback : public SerializationCallback
613-{
614+static OneToOneURIMapper stop_words_mapper( EntityData::STOP_WORDS );
615+static OneToOneURIMapper thesaurus_mapper( EntityData::THESAURUS );
616+#endif /* ZORBA_NO_FULL_TEXT */
617+
618+class URIMapperSerializationCallback : public SerializationCallback {
619+public:
620+ void addURIMapper( URIMapper* mapper ) {
621+ theURIMappers.push_back( mapper );
622+ }
623+
624+ URIMapper* getURIMapper( size_t i ) const {
625+ return theURIMappers[i];
626+ }
627+
628 private:
629- std::vector<URIMapper*> theURIMappers;
630-
631-public:
632- void addURIMapper(URIMapper* mapper) { theURIMappers.push_back(mapper); }
633-
634- URIMapper* getURIMapper(size_t i) const { return theURIMappers[i]; }
635+ vector<URIMapper*> theURIMappers;
636 };
637
638-
639-URIMapperSerializationCallback theSerializationCallback;
640-
641-/*******************************************************************************
642-
643-********************************************************************************/
644-static void print_exception( ZorbaException const &e,
645- ZorbaCMDProperties const &props ) {
646- using namespace std;
647-
648- if ( props.printErrorsAsXml() )
649- if ( props.indent() )
650+URIMapperSerializationCallback serialization_callback;
651+
652+static void print_exception( ZorbaException const &e ) {
653+ ZorbaCmdProperties &zc_props = ZorbaCmdProperties::instance();
654+ if ( zc_props.print_errors_as_xml_ )
655+ if ( zc_props.indent_ )
656 cerr << ZorbaException::format_xml_indented;
657 else
658 cerr << ZorbaException::format_xml;
659 else
660 cerr << ZorbaException::format_text;
661-
662 cerr << e << endl;
663 }
664
665-/*******************************************************************************
666+static void print_help() {
667+ cout << "Zorba NoSQL Query Processor\n";
668+ cout << "Available options:\n";
669+ cout << get_help_msg();
670+}
671
672-********************************************************************************/
673-bool populateStaticContext(
674- Zorba* zorba,
675- zorba::StaticContext_t& sctx,
676- const ZorbaCMDProperties& props)
677-{
678- try
679- {
680+static bool populateStaticContext( Zorba *zorba, StaticContext_t &sctx ) {
681+ ZorbaCmdProperties &zc_props = ZorbaCmdProperties::instance();
682+ try {
683 // add the following module path to the static context (in this order)
684 // 1. command-line properties
685 // 2. environment ZORBA_MODULE_PATH
686 // 3. current working directory
687- {
688- std::vector<String> lModulePath;
689- PathUtil::setPathsOnContext(props, sctx);
690- }
691-
692- if (props.boundarySpace().size() != 0 )
693- {
694- sctx->setBoundarySpacePolicy(props.boundarySpace().compare("preserve") == 0 ?
695- preserve_space :
696- strip_space);
697- }
698-
699- if (props.constructionMode().size() != 0)
700- {
701- sctx->setConstructionMode(props.boundarySpace().compare("preserve") == 0 ?
702- preserve_cons :
703- strip_cons);
704- }
705-
706- if (props.orderingMode().size() != 0 )
707- {
708- sctx->setOrderingMode(props.boundarySpace().compare("ordered") == 0 ?
709- ordered :
710- unordered);
711- }
712-
713- if (props.baseUri().size() != 0 )
714- sctx->setBaseURI( props.baseUri() );
715+ set_paths_on_sctx( sctx );
716+
717+ if ( !zc_props.boundary_space_.empty() )
718+ sctx->setBoundarySpacePolicy(
719+ zc_props.boundary_space_ == "preserve" ? preserve_space : strip_space
720+ );
721+
722+ if ( !zc_props.construction_mode_.empty() )
723+ sctx->setConstructionMode(
724+ zc_props.boundary_space_ == "preserve" ? preserve_cons : strip_cons
725+ );
726+
727+ if ( !zc_props.ordering_mode_.empty() )
728+ sctx->setOrderingMode(
729+ zc_props.boundary_space_ == "ordered" ? ordered : unordered
730+ );
731+
732+ if ( !zc_props.base_uri_.empty() )
733+ sctx->setBaseURI( zc_props.base_uri_ );
734 }
735- catch (const zorba::ZorbaException& ze)
736- {
737- std::cerr << ze << std::endl;
738+ catch ( ZorbaException const &ze ) {
739+ cerr << ze << endl;
740 return false;
741 }
742
743- if (props.defaultCollation().size() != 0 )
744- {
745- try
746- {
747- sctx->addCollation( props.defaultCollation() );
748+ if ( !zc_props.default_collation_.empty() ) {
749+ try {
750+ sctx->addCollation( zc_props.default_collation_ );
751 }
752- catch (zorba::ZorbaException const&)
753- {
754- std::cerr << "the given collation {" << props.defaultCollation()
755- << "} is not a valid collation." << std::endl;
756+ catch ( ZorbaException const& ) {
757+ cerr << "the given collation {" << zc_props.default_collation_
758+ << "} is not a valid collation." << endl;
759 return false;
760 }
761-
762- sctx->setDefaultCollation( props.defaultCollation() );
763+ sctx->setDefaultCollation( zc_props.default_collation_ );
764 }
765
766- ZorbaCMDProperties::Options_t::const_iterator lIter = props.optionsBegin();
767- ZorbaCMDProperties::Options_t::const_iterator end = props.optionsEnd();
768- for (; lIter != end; ++lIter)
769- {
770- try
771- {
772- Item lQName = zorba->getItemFactory()->createQName(lIter->clark_qname);
773- sctx->declareOption(lQName, lIter->value);
774+ sctx_opts::const_iterator i = zc_props.sctx_opts_.begin();
775+ sctx_opts::const_iterator const end = zc_props.sctx_opts_.end();
776+ for ( ; i != end; ++i ) {
777+ try {
778+ Item name( zorba->getItemFactory()->createQName( i->clark_qname ) );
779+ sctx->declareOption( name, i->value );
780 }
781- catch (zorba::ZorbaException const& e)
782- {
783- std::cerr << "unable to set static context option with qname "
784- << lIter->clark_qname << ": " << e.what() << std::endl;
785+ catch ( ZorbaException const &e) {
786+ cerr << "unable to set static context option with qname "
787+ << i->clark_qname << ": " << e.what() << endl;
788 return false;
789 }
790 }
791
792 #ifdef DO_AUDIT
793- zorba::audit::Provider* lAuditProvider = zorba->getAuditProvider();
794- zorba::audit::Configuration* config = lAuditProvider->createConfiguration();
795- std::vector<zorba::String> property_names;
796- zorba::audit::Configuration::getPropertyNames(property_names);
797+ audit::Provider* lAuditProvider = zorba->getAuditProvider();
798+ audit::Configuration* config = lAuditProvider->createConfiguration();
799+ vector<String> property_names;
800+ audit::Configuration::getPropertyNames(property_names);
801
802 bool lIsStatic;
803
804- lIsStatic = zorba::audit::Configuration::
805+ lIsStatic = audit::Configuration::
806 enableProperty(config, property_names, "xquery/compilation/parse-duration");
807 assert(lIsStatic);
808
809- lIsStatic = zorba::audit::Configuration::
810+ lIsStatic = audit::Configuration::
811 enableProperty(config, property_names, "xquery/compilation/translation-duration");
812 assert(lIsStatic);
813
814- lIsStatic = zorba::audit::Configuration::
815+ lIsStatic = audit::Configuration::
816 enableProperty(config, property_names, "xquery/compilation/optimization-duration");
817 assert(lIsStatic);
818
819- lIsStatic = zorba::audit::Configuration::
820+ lIsStatic = audit::Configuration::
821 enableProperty(config, property_names, "xquery/compilation/codegeneration-duration");
822 assert(lIsStatic);
823
824- zorba::audit::Event* event = lAuditProvider->createEvent(config);
825+ audit::Event *event = lAuditProvider->createEvent(config);
826
827- sctx->setAuditEvent(event);
828-#endif // DO_AUDIT
829+ sctx->setAuditEvent( event );
830+#endif /* DO_AUDIT */
831
832 #ifndef ZORBA_NO_FULL_TEXT
833 {
834- ZorbaCMDProperties::FullText_t::const_iterator lIter = props.stopWordsBegin();
835- ZorbaCMDProperties::FullText_t::const_iterator end = props.stopWordsEnd();
836- for (; lIter != end; ++lIter)
837- {
838- theStopWordsMapper.addMapping(lIter->uri, lIter->value);
839- }
840+ ft_mappings::const_iterator i = zc_props.stop_words_mapping_.begin();
841+ ft_mappings::const_iterator const end = zc_props.stop_words_mapping_.end();
842+ for (; i != end; ++i)
843+ stop_words_mapper.addMapping( i->uri, i->value );
844
845- if (props.serializePlan() || props.loadPlan())
846- {
847- theSerializationCallback.addURIMapper(&theStopWordsMapper);
848- }
849+ if ( zc_props.serialize_plan_ || zc_props.load_plan_ )
850+ serialization_callback.addURIMapper( &stop_words_mapper );
851 else
852- {
853- sctx->registerURIMapper(&theStopWordsMapper);
854- }
855+ sctx->registerURIMapper( &stop_words_mapper );
856 }
857
858 {
859- ZorbaCMDProperties::FullText_t::const_iterator lIter = props.thesaurusBegin();
860- ZorbaCMDProperties::FullText_t::const_iterator end = props.thesaurusEnd();
861- for (; lIter != end; ++lIter)
862- {
863- theThesaurusMapper.addMapping(lIter->uri, lIter->value);
864- }
865+ ft_mappings::const_iterator i = zc_props.thesaurus_mapping_.begin();
866+ ft_mappings::const_iterator const end = zc_props.thesaurus_mapping_.end();
867+ for ( ; i != end; ++i )
868+ thesaurus_mapper.addMapping( i->uri, i->value );
869
870- if (props.serializePlan() || props.loadPlan())
871- {
872- theSerializationCallback.addURIMapper(&theStopWordsMapper);
873- }
874+ if ( zc_props.serialize_plan_ || zc_props.load_plan_ )
875+ serialization_callback.addURIMapper( &stop_words_mapper );
876 else
877- {
878- sctx->registerURIMapper(&theThesaurusMapper);
879- }
880+ sctx->registerURIMapper( &thesaurus_mapper );
881 }
882 #endif /* ZORBA_NO_FULL_TEXT */
883
884 return true;
885 }
886
887-
888-/*******************************************************************************
889-
890-********************************************************************************/
891-bool populateDynamicContext(
892- Zorba* zorba,
893- XmlDataManager* xmlMgr,
894- zorba::DynamicContext* aDynamicContext,
895- const ZorbaCMDProperties& props)
896-{
897- if ( props.contextItem().size() != 0 )
898- {
899- std::ifstream lInStream(props.contextItem().c_str());
900- Item lDoc = xmlMgr->parseXML(lInStream);
901- aDynamicContext->setContextItem(lDoc);
902+bool populateDynamicContext( Zorba *zorba, XmlDataManager *xmlMgr,
903+ DynamicContext *dctx ) {
904+ ZorbaCmdProperties const &zc_props = ZorbaCmdProperties::instance();
905+
906+ if ( !zc_props.ctx_item_.empty() ) {
907+ ifstream is( zc_props.ctx_item_.c_str() );
908+ Item doc( xmlMgr->parseXML( is ) );
909+ dctx->setContextItem( doc );
910 }
911
912- ZorbaCMDProperties::ExternalVars_t::const_iterator lIter;
913- ZorbaCMDProperties::ExternalVars_t::const_iterator end = props.externalVarsEnd();
914- for (lIter = props.externalVarsBegin();
915- lIter != end;
916- ++lIter)
917- {
918- try
919- {
920- if ((*lIter).inline_file)
921- {
922- std::ifstream lInStream((*lIter).var_value.c_str());
923- Item lDoc = xmlMgr->parseXML(lInStream);
924- aDynamicContext->setVariable((*lIter).var_name, lDoc);
925- }
926- else
927- {
928- zorba::Item lItem = zorba->getItemFactory()->createString((*lIter).var_value);
929- aDynamicContext->setVariable((*lIter).var_name, lItem);
930+ external_vars::const_iterator i = zc_props.external_vars_.begin();
931+ external_vars::const_iterator const end = zc_props.external_vars_.end();
932+ for ( ; i != end; ++i ) {
933+ try {
934+ if ( i->inline_file ) {
935+ ifstream is( i->var_value.c_str() );
936+ Item doc( xmlMgr->parseXML( is ) );
937+ dctx->setVariable( i->var_name, doc );
938+ } else {
939+ Item item( zorba->getItemFactory()->createString( i->var_value ) );
940+ dctx->setVariable( i->var_name, item );
941 }
942 }
943- catch (...)
944- {
945+ catch ( ... ) {
946 // Let normal exception handling display the error message; here we
947 // just want to tell the user what variable binding caused the problem
948- std::cerr << "While binding external variable $"
949- << lIter->var_name << ": ";
950+ cerr << "While binding external variable $" << i->var_name << ": ";
951 throw;
952 }
953 }
954 return true;
955 }
956
957-
958-/*******************************************************************************
959-
960-********************************************************************************/
961-bool createSerializerOptions(
962- Zorba_SerializerOptions_t& lSerOptions,
963- const ZorbaCMDProperties& props)
964-{
965- if ( props.indent() )
966- lSerOptions.indent = ZORBA_INDENT_YES;
967-
968- if ( props.omitXmlDeclaration() )
969- lSerOptions.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
970-
971- if ( props.byteOrderMark() )
972- lSerOptions.byte_order_mark = ZORBA_BYTE_ORDER_MARK_YES;
973-
974- if ( props.serializeHtml() )
975- lSerOptions.ser_method = ZORBA_SERIALIZATION_METHOD_HTML;
976- else if ( props.serializeText() )
977- lSerOptions.ser_method = ZORBA_SERIALIZATION_METHOD_TEXT;
978-
979- return true;
980+static void set_serializer_opts( Zorba_SerializerOptions_t &ser_opts ) {
981+ ZorbaCmdProperties &zc_props = ZorbaCmdProperties::instance();
982+
983+ if ( zc_props.indent_ )
984+ ser_opts.indent = ZORBA_INDENT_YES;
985+
986+ if ( zc_props.omit_xml_declaration_ )
987+ ser_opts.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
988+
989+ if ( zc_props.byte_order_mark_ )
990+ ser_opts.byte_order_mark = ZORBA_BYTE_ORDER_MARK_YES;
991+
992+ if ( zc_props.serialize_html_ )
993+ ser_opts.ser_method = ZORBA_SERIALIZATION_METHOD_HTML;
994+ else if ( zc_props.serialize_text_ )
995+ ser_opts.ser_method = ZORBA_SERIALIZATION_METHOD_TEXT;
996 }
997
998
999-/*******************************************************************************
1000+/******************************************************************************
1001 Fullfills the command-line "as-file" (-f) switch, or if not requested, infers
1002 -f for file:// queries. Returns an URI or the empty string.
1003-********************************************************************************/
1004-std::string parseFileURI(bool asPath, const std::string &str)
1005-{
1006- if (asPath)
1007- return str;
1008+ ******************************************************************************/
1009
1010- // otherwise, the user still might have meant a file
1011+static string parse_file_uri( string const &uri ) {
1012 #ifdef WIN32
1013 // file:///c:/ returns c:<backslash>
1014 // file://localhost returns \\localhost
1015 // BUG: it seems that <a>/x returns <a>\x
1016 static const char *file3 = "file:///";
1017 static const char *file2 = "file://";
1018- std::string fpath;
1019- if(str.compare(0, strlen(file3), file3) == 0) {
1020- fpath = str.substr(strlen(file3));
1021- } else if(str.compare(0, strlen(file2), file2) == 0) {
1022+ string fpath;
1023+ if ( uri.compare( 0, strlen( file3 ), file3 ) == 0 ) {
1024+ fpath = uri.substr( strlen( file3 ) );
1025+ } else if ( uri.compare( 0, strlen( file2 ), file2 ) == 0 ) {
1026 fpath = fs::dir_separator;
1027- fpath += str.substr(strlen(file2));
1028+ fpath += uri.substr( strlen( file2 ) );
1029 }
1030 // replace all slash with backslash
1031- std::string::size_type off=0;
1032- while ((off=fpath.find('/', off)) != std::string::npos)
1033- fpath.replace(off, 1, 1, fs::dir_separator);
1034+ string::size_type off=0;
1035+ while ( (off = fpath.find( '/', off )) != string::npos )
1036+ fpath.replace( off, 1, 1, fs::dir_separator );
1037 return fpath;
1038
1039-#else // for UNIX
1040-
1041- static const char *pfx = "file://";
1042- static unsigned plen = strlen (pfx);
1043- if (str.compare (0, plen, pfx) == 0)
1044- return str.substr (plen);
1045+#else /* for UNIX */
1046+ static const char pfx[] = "file://";
1047+ if ( uri.compare( 0, 7, pfx ) == 0 )
1048+ return uri.substr( 7 );
1049 else
1050 return "";
1051-#endif
1052-}
1053-
1054-
1055-//
1056-// Timing utilities and class
1057-//
1058-
1059-#define DECLARE_TIMER(kind) \
1060- zorbatm::walltime start##kind##Walltime; \
1061- zorbatm::walltime stop##kind##Walltime; \
1062- zorbatm::cputime start##kind##Cputime; \
1063- zorbatm::cputime stop##kind##Cputime; \
1064- double elapsed##kind##Walltime; \
1065- double elapsed##kind##Cputime
1066-
1067-#define START_TIMER(kind) \
1068- zorbatm::get_current_walltime(start##kind##Walltime); \
1069- zorbatm::get_current_cputime(start##kind##Cputime);
1070-
1071-#define STOP_TIMER(kind) \
1072- zorbatm::get_current_walltime(stop##kind##Walltime); \
1073- elapsed##kind##Walltime += zorbatm::get_walltime_elapsed(start##kind##Walltime, \
1074- stop##kind##Walltime); \
1075- \
1076- zorbatm::get_current_cputime(stop##kind##Cputime); \
1077- elapsed##kind##Cputime += zorbatm::get_cputime_elapsed(start##kind##Cputime, \
1078- stop##kind##Cputime);
1079-
1080-
1081-
1082-struct TimingInfo
1083-{
1084- typedef enum
1085- {
1086- INIT_TIMER,
1087- DEINIT_TIMER,
1088- COMP_TIMER,
1089- EXEC_TIMER,
1090- UNLOAD_TIMER,
1091- PLAN_SAVE_TIMER,
1092- PLAN_LOAD_TIMER,
1093- TOTAL_TIMER
1094- } TimerKind;
1095-
1096- unsigned long numExecs;
1097-
1098- DECLARE_TIMER(Init);
1099- DECLARE_TIMER(Deinit);
1100- DECLARE_TIMER(Comp);
1101- DECLARE_TIMER(Exec);
1102- DECLARE_TIMER(Load);
1103- DECLARE_TIMER(Unload);
1104- DECLARE_TIMER(PlanSave);
1105- DECLARE_TIMER(PlanLoad);
1106- DECLARE_TIMER(Total);
1107-
1108- TimingInfo(unsigned long num)
1109- :
1110- numExecs(num),
1111- elapsedInitWalltime(0),
1112- elapsedInitCputime(0),
1113- elapsedDeinitWalltime(0),
1114- elapsedDeinitCputime(0),
1115- elapsedCompWalltime(0),
1116- elapsedCompCputime(0),
1117- elapsedExecWalltime(0),
1118- elapsedExecCputime(0),
1119- elapsedLoadWalltime(0),
1120- elapsedLoadCputime(0),
1121- elapsedUnloadWalltime(0),
1122- elapsedUnloadCputime(0),
1123-
1124- elapsedPlanSaveWalltime(0),
1125- elapsedPlanSaveCputime(0),
1126-
1127- elapsedPlanLoadWalltime(0),
1128- elapsedPlanLoadCputime(0),
1129-
1130- elapsedTotalWalltime(0),
1131- elapsedTotalCputime(0)
1132- {
1133- }
1134-
1135- void startTimer(TimerKind kind, unsigned long iteration);
1136- void stopTimer(TimerKind kind, unsigned long iteration);
1137-
1138- std::ostream& print(std::ostream& os, bool);
1139-};
1140-
1141-
1142-void
1143-TimingInfo::startTimer(TimerKind kind, unsigned long iteration)
1144-{
1145- if (iteration == 0 && numExecs > 1)
1146- return;
1147-
1148- switch (kind)
1149- {
1150- case INIT_TIMER:
1151- START_TIMER(Init);
1152- break;
1153-
1154- case DEINIT_TIMER:
1155- START_TIMER(Deinit);
1156- break;
1157-
1158- case TOTAL_TIMER:
1159- START_TIMER(Total);
1160- break;
1161-
1162- case COMP_TIMER:
1163- START_TIMER(Comp);
1164- break;
1165-
1166- case EXEC_TIMER:
1167- START_TIMER(Exec);
1168- break;
1169-
1170- case UNLOAD_TIMER:
1171- START_TIMER(Unload);
1172- break;
1173-
1174- case PLAN_SAVE_TIMER:
1175- START_TIMER(PlanSave);
1176- break;
1177-
1178- case PLAN_LOAD_TIMER:
1179- START_TIMER(PlanLoad);
1180- break;
1181- }
1182-}
1183-
1184-
1185-void
1186-TimingInfo::stopTimer(TimerKind kind, unsigned long iteration)
1187-{
1188- if (iteration == 0 && numExecs > 1)
1189- return;
1190-
1191- switch (kind)
1192- {
1193- case INIT_TIMER:
1194- {
1195- STOP_TIMER(Init);
1196- break;
1197- }
1198- case DEINIT_TIMER:
1199- {
1200- STOP_TIMER(Deinit);
1201- break;
1202- }
1203- case TOTAL_TIMER:
1204- {
1205- STOP_TIMER(Total);
1206- break;
1207- }
1208- case COMP_TIMER:
1209- {
1210- STOP_TIMER(Comp);
1211- break;
1212- }
1213- case EXEC_TIMER:
1214- {
1215- STOP_TIMER(Exec);
1216- break;
1217- }
1218- case UNLOAD_TIMER:
1219- {
1220- STOP_TIMER(Unload);
1221- break;
1222- }
1223- case PLAN_SAVE_TIMER:
1224- {
1225- STOP_TIMER(PlanSave);
1226- break;
1227- }
1228- case PLAN_LOAD_TIMER:
1229- {
1230- STOP_TIMER(PlanLoad);
1231- break;
1232- }
1233- }
1234-}
1235-
1236-
1237-std::ostream&
1238-TimingInfo::print(std::ostream& os, bool serializePlan)
1239-{
1240- os.precision(3);
1241- os.setf(std::ios::fixed);
1242-
1243- os << "\nNumber of executions = " << numExecs << std::endl;
1244-
1245- unsigned long timeDiv = numExecs == 1 ? 1 : (numExecs - 1);
1246- double cWalltime = elapsedCompWalltime / timeDiv;
1247- double eWalltime = elapsedExecWalltime / timeDiv;
1248- double lWalltime = elapsedLoadWalltime / timeDiv;
1249- double uWalltime = elapsedUnloadWalltime / timeDiv;
1250- double psWalltime = elapsedPlanSaveWalltime / timeDiv;
1251- double plWalltime = elapsedPlanLoadWalltime / timeDiv;
1252- double tWalltime = elapsedTotalWalltime / timeDiv;
1253-
1254- double cCputime = elapsedCompCputime / timeDiv;
1255- double eCputime = elapsedExecCputime / timeDiv;
1256- double lCputime = elapsedLoadCputime / timeDiv;
1257- double uCputime = elapsedUnloadCputime / timeDiv;
1258- double psCputime = elapsedPlanSaveCputime / timeDiv;
1259- double plCputime = elapsedPlanLoadCputime / timeDiv;
1260- double tCputime = elapsedTotalCputime / timeDiv;
1261-
1262- os << "Engine Startup Time : " << elapsedInitWalltime
1263- << " (user: " << elapsedInitCputime << ")"
1264- << " milliseconds" << std::endl;
1265-
1266- os << "Average Compilation Time: " << cWalltime
1267- << " (user: " << cCputime << ")"
1268- << " milliseconds" << std::endl;
1269-
1270- if (serializePlan)
1271- {
1272- os << "Average Plan Saving Time: " << psWalltime
1273- << " (user: " << psCputime << ")"
1274- << " milliseconds" << std::endl;
1275-
1276- os << "Average Plan Loading Time: " << plWalltime
1277- << " (user: " << plCputime << ")"
1278- << " milliseconds" << std::endl;
1279- }
1280-
1281- os << "Average Execution Time : " << eWalltime - lWalltime
1282- << " (user: " << eCputime - lCputime << ")"
1283- << " milliseconds" << std::endl;
1284-
1285- os << "Average Loading Time : " << lWalltime
1286- << " (user: " << lCputime << ")"
1287- << " milliseconds" << std::endl;
1288-
1289- os << "Average Unloading Time : " << uWalltime
1290- << " (user: " << uCputime << ")"
1291- << " milliseconds" << std::endl;
1292-
1293- os << "Average Total Time : " << tWalltime
1294- << " (user: " << tCputime << ")"
1295- << " milliseconds" << std::endl;
1296-
1297- return os;
1298-}
1299-
1300-
1301-void
1302-removeOutputFileIfNeeded(const ZorbaCMDProperties& lProperties)
1303-{
1304+#endif /* WIN32 */
1305+}
1306+
1307+static void remove_output_file() {
1308 #ifdef ZORBA_WITH_FILE_ACCESS
1309- if ( !lProperties.outputFile().empty() )
1310- fs::remove( lProperties.outputFile(), true );
1311+ ZorbaCmdProperties &zc_props = ZorbaCmdProperties::instance();
1312+ if ( !zc_props.output_file_.empty() )
1313+ fs::remove( zc_props.output_file_, true );
1314 #endif /* ZORBA_WITH_FILE_ACCESS */
1315 }
1316
1317-
1318-int
1319-compileAndExecute(
1320- zorba::Zorba* zorbaInstance,
1321- zorba::XmlDataManager* xmlDataMgr,
1322- const ZorbaCMDProperties& properties,
1323- zorba::StaticContext_t& staticContext,
1324- const std::string& qfilepath,
1325- std::istream& qfile,
1326- std::ostream& outputStream,
1327- TimingInfo& timing)
1328-{
1329- unsigned long lNumExecutions = properties.multiple();
1330- bool doTiming = properties.timing();
1331- bool serializePlan = properties.serializePlan();
1332- bool savePlan = properties.savePlan();
1333- bool loadPlan = properties.loadPlan();
1334- std::ostringstream lOut;
1335- Zorba_CompilerHints lHints;
1336-
1337- std::unique_ptr<std::fstream> planFile;
1338- std::fstream* planFilep = NULL;
1339-
1340- if (qfilepath.rfind(".jq") == qfilepath.size() - 3)
1341- {
1342- staticContext->setJSONiqVersion(zorba::jsoniq_version_1_0);
1343- }
1344-
1345- if (serializePlan)
1346- {
1347- if (savePlan || loadPlan)
1348- {
1349- std::cerr << "The --serialize-plan option cannot be used together with the --compile-plan or --execute-plan options" << std::endl;
1350- exit(1);
1351+static int compileAndExecute( Zorba *zorba, XmlDataManager *xmlDataMgr,
1352+ StaticContext_t &sctx,
1353+ string const &qfilepath,
1354+ istream &qstream,
1355+ ostream &outputStream,
1356+ Timers &timers ) {
1357+ Properties const &z_props = Properties::instance();
1358+ ZorbaCmdProperties const &zc_props = ZorbaCmdProperties::instance();
1359+
1360+ unsigned long lNumExecutions = zc_props.multiple_;
1361+ ostringstream lOut;
1362+ Zorba_CompilerHints hints;
1363+
1364+ unique_ptr<fstream> planFile;
1365+ fstream *planFilep = NULL;
1366+
1367+ if ( zc_props.jsoniq_ || fs::extension( qfilepath ) == "jq" )
1368+ sctx->setJSONiqVersion( jsoniq_version_1_0 );
1369+
1370+ if ( zc_props.serialize_plan_ ) {
1371+ if ( zc_props.load_plan_ || zc_props.save_plan_ ) {
1372+ cerr << "The --serialize-plan option cannot be used together with the --compile-plan or --execute-plan options" << endl;
1373+ exit( 1 );
1374 }
1375
1376- std::string planFilePath = qfilepath;
1377+ string planFilePath = qfilepath;
1378 planFilePath += ".plan";
1379- planFile.reset(new std::fstream(planFilePath.c_str(),
1380- std::fstream::in |
1381- std::fstream::out |
1382- std::fstream::trunc |
1383- std::fstream::binary));
1384+ planFile.reset(
1385+ new fstream(
1386+ planFilePath.c_str(), ios::in | ios::out | ios::trunc | ios::binary
1387+ )
1388+ );
1389 planFilep = planFile.get();
1390 assert(planFilep->good());
1391 }
1392
1393- if (savePlan && loadPlan)
1394- {
1395- std::cerr << "The --compile-plan and --execute-plan options cannot be used together" << std::endl;
1396- exit(1);
1397+ if ( zc_props.save_plan_ && zc_props.load_plan_ ) {
1398+ cerr << "The --compile-plan and --execute-plan options cannot be used together" << endl;
1399+ exit( 1 );
1400 }
1401
1402 // default is O1 in the Zorba_CompilerHints constructor
1403- if (properties.optimizationLevel() == "O0")
1404- {
1405- lHints.opt_level = ZORBA_OPT_LEVEL_O0;
1406- }
1407- else if (properties.optimizationLevel() == "O2")
1408- {
1409- lHints.opt_level = ZORBA_OPT_LEVEL_O2;
1410- }
1411-
1412- lHints.for_serialization_only = true;
1413-
1414-#if ZORBACMD_LOAD_SYSTEM_PROPERTIES
1415- if (Properties::instance()->serializeOnlyQuery() == 0)
1416- {
1417- lHints.for_serialization_only = false;
1418- }
1419-#endif
1420-
1421- // default is false
1422- if (properties.libModule())
1423- {
1424- lHints.lib_module = true;
1425- }
1426-
1427- Zorba_SerializerOptions lSerOptions;
1428+ switch ( z_props.getOptimizationLevel() ) {
1429+ case 0: hints.opt_level = ZORBA_OPT_LEVEL_O0; break;
1430+ case 2: hints.opt_level = ZORBA_OPT_LEVEL_O2; break;
1431+ }
1432+
1433+ hints.for_serialization_only = zc_props.serialize_only_query_;
1434+ hints.lib_module = zc_props.lib_module_;
1435+
1436+ Zorba_SerializerOptions ser_opts;
1437 try {
1438- lSerOptions.set( properties.getSerializerParameters() );
1439+ ser_opts.set( zc_props.serialization_params_ );
1440 }
1441- catch ( zorba::ZorbaException const &e ) {
1442- std::cerr << e << std::endl;
1443+ catch ( ZorbaException const &e ) {
1444+ cerr << e << endl;
1445 return 11;
1446 }
1447- createSerializerOptions(lSerOptions, properties);
1448+ set_serializer_opts( ser_opts );
1449
1450- zorba::XQuery_t query;
1451+ XQuery_t query;
1452 DiagnosticHandler diagnosticHandler;
1453
1454- for (unsigned long i = 0; i < lNumExecutions; ++i)
1455- {
1456- // start the total timer
1457- if (doTiming)
1458- timing.startTimer(TimingInfo::TOTAL_TIMER, i);
1459-
1460+ for ( unsigned long exec = 0; exec < lNumExecutions; ++exec ) {
1461+ if ( zc_props.timing_ )
1462+ timers.startTimer( Timers::total, exec );
1463+
1464 //
1465 // Compile the query
1466 // Compilation is done only once, unless timing is needed
1467 //
1468- if (doTiming || i == 0)
1469- {
1470+ if ( zc_props.timing_ || exec == 0 ) {
1471 // go back to the beginning of the stream
1472- qfile.clear();
1473- qfile.seekg(0);
1474- assert (qfile.tellg() >= 0);
1475+ qstream.clear();
1476+ qstream.seekg( 0 );
1477+ assert( qstream.tellg() >= 0 );
1478
1479- try
1480- {
1481- // start the compilation timer
1482- if (doTiming)
1483- timing.startTimer(TimingInfo::COMP_TIMER, i);
1484+ try {
1485+ if ( zc_props.timing_ )
1486+ timers.startTimer( Timers::comp, exec );
1487
1488 // Create and compile the query
1489- query = zorbaInstance->createQuery();
1490- query->registerDiagnosticHandler(&diagnosticHandler);
1491- query->setFileName(qfilepath);
1492-
1493- if (loadPlan)
1494- {
1495- query->loadExecutionPlan(qfile, &theSerializationCallback);
1496-
1497- // stop the compilation timer
1498- if (doTiming)
1499- timing.stopTimer(TimingInfo::COMP_TIMER, i);
1500- }
1501- else
1502- {
1503- query->compile(qfile, staticContext, lHints);
1504-
1505- // stop the compilation timer
1506- if (doTiming)
1507- timing.stopTimer(TimingInfo::COMP_TIMER, i);
1508+ query = zorba->createQuery();
1509+ query->registerDiagnosticHandler( &diagnosticHandler );
1510+ query->setFileName( qfilepath );
1511+
1512+ if ( zc_props.load_plan_ ) {
1513+ query->loadExecutionPlan( qstream, &serialization_callback );
1514+ if ( zc_props.timing_ )
1515+ timers.stopTimer( Timers::comp, exec );
1516+ } else {
1517+ query->compile( qstream, sctx, hints );
1518+
1519+ if ( zc_props.timing_ )
1520+ timers.stopTimer( Timers::comp, exec );
1521
1522 // Serialize the execution plan, if requested
1523- if (serializePlan)
1524- {
1525+ if ( zc_props.serialize_plan_ ) {
1526 planFilep->clear();
1527- planFilep->seekp(0);
1528-
1529- // start the plan-save timer
1530- if (doTiming)
1531- timing.startTimer(TimingInfo::PLAN_SAVE_TIMER, i);
1532-
1533- query->saveExecutionPlan(*planFilep);
1534-
1535- // stop the plan-save timer
1536- if (doTiming)
1537- timing.stopTimer(TimingInfo::PLAN_SAVE_TIMER, i);
1538-
1539+ planFilep->seekp( 0 );
1540+
1541+ if ( zc_props.timing_ )
1542+ timers.startTimer( Timers::plan_save, exec );
1543+ query->saveExecutionPlan( *planFilep );
1544+ if ( zc_props.timing_ )
1545+ timers.stopTimer( Timers::plan_save, exec );
1546 planFilep->flush();
1547 }
1548 }
1549 }
1550- catch (zorba::XQueryException const& qe)
1551- {
1552- print_exception( qe, properties );
1553+ catch ( XQueryException const &qe ) {
1554+ print_exception( qe );
1555 return 11;
1556 }
1557- catch (zorba::ZorbaException const& ze)
1558- {
1559- std::cerr << ze << std::endl;
1560+ catch ( ZorbaException const &ze ) {
1561+ cerr << ze << endl;
1562 return 12;
1563 }
1564- } // if (doTiming || i == 0)
1565+ } // if (zc_props.timing_ || exec == 0)
1566
1567 //
1568- // Run the query, unless compileOnly has been requested.
1569+ // Run the query, unless compile-only has been requested.
1570 //
1571- if ( ! properties.compileOnly() && ! properties.libModule() )
1572- {
1573- try
1574- {
1575+ if ( !zc_props.compile_only_ && !zc_props.lib_module_ ) {
1576+ try {
1577 // load the execution plan, if requested
1578- if (serializePlan)
1579- {
1580- planFilep->seekg(0);
1581- assert(planFilep->good());
1582-
1583- // start the plan-load timer
1584- if (doTiming)
1585- timing.startTimer(TimingInfo::PLAN_LOAD_TIMER, i);
1586-
1587- query = zorbaInstance->createQuery();
1588- query->loadExecutionPlan(*planFilep, &theSerializationCallback);
1589-
1590- // stop the plan-load timer
1591- if (doTiming)
1592- timing.stopTimer(TimingInfo::PLAN_LOAD_TIMER, i);
1593+ if ( zc_props.serialize_plan_ ) {
1594+ planFilep->seekg( 0 );
1595+ assert( planFilep->good() );
1596+
1597+ if ( zc_props.timing_ )
1598+ timers.startTimer( Timers::plan_load, exec );
1599+
1600+ query = zorba->createQuery();
1601+ query->loadExecutionPlan( *planFilep, &serialization_callback );
1602+
1603+ if ( zc_props.timing_ )
1604+ timers.stopTimer( Timers::plan_load, exec );
1605 }
1606
1607- // start the execution timer
1608- if (doTiming)
1609- timing.startTimer(TimingInfo::EXEC_TIMER, i);
1610+ if ( zc_props.timing_ )
1611+ timers.startTimer( Timers::exec, exec );
1612
1613 // Populate the dynamic context
1614- zorba::DynamicContext* lDynamicContext = query->getDynamicContext();
1615- try
1616- {
1617- if ( ! populateDynamicContext(zorbaInstance,
1618- xmlDataMgr,
1619- lDynamicContext,
1620- properties) )
1621- {
1622- properties.printHelp(std::cout);
1623+ try {
1624+ DynamicContext *const dctx = query->getDynamicContext();
1625+ if ( !populateDynamicContext( zorba, xmlDataMgr, dctx ) ) {
1626+ print_help();
1627 return 21;
1628 }
1629 }
1630- catch (zorba::XQueryException const& qe)
1631- {
1632- print_exception( qe, properties );
1633+ catch ( XQueryException const &qe ) {
1634+ print_exception( qe );
1635 return 22;
1636 }
1637- catch (zorba::ZorbaException const& ze)
1638- {
1639- std::cerr << ze << std::endl;
1640+ catch ( ZorbaException const &ze ) {
1641+ cerr << ze << endl;
1642 return 23;
1643 }
1644
1645 // run the query
1646- if (properties.noSerializer())
1647- {
1648+ if ( zc_props.no_serializer_ )
1649 query->executeSAX();
1650- }
1651- else if (savePlan)
1652- {
1653- query->saveExecutionPlan(outputStream);
1654- }
1655+ else if ( zc_props.save_plan_ )
1656+ query->saveExecutionPlan( outputStream );
1657 else
1658- {
1659- query->execute(outputStream, &lSerOptions);
1660- }
1661-
1662- if (properties.trailingNl())
1663- outputStream << std::endl;
1664-
1665+ query->execute( outputStream, &ser_opts );
1666+
1667+ if ( zc_props.trailing_nl_ )
1668+ outputStream << endl;
1669+
1670 query->close();
1671
1672- // stop the execution timer
1673- if (doTiming)
1674- timing.stopTimer(TimingInfo::EXEC_TIMER, i);
1675+ if ( zc_props.timing_ )
1676+ timers.stopTimer( Timers::exec, exec );
1677
1678- if (i > 0 || lNumExecutions == 1)
1679- {
1680- timing.elapsedLoadWalltime += query->getDocLoadingTime();
1681- timing.elapsedLoadCputime += query->getDocLoadingUserTime();
1682+ if ( exec > 0 || lNumExecutions == 1 ) {
1683+ timers.elapsed_load_walltime += query->getDocLoadingTime();
1684+ timers.elapsed_load_cputime += query->getDocLoadingUserTime();
1685 }
1686 }
1687- catch (zorba::XQueryException const& qe)
1688- {
1689- print_exception( qe, properties );
1690+ catch ( XQueryException const &qe ) {
1691+ print_exception( qe );
1692 return 31;
1693 }
1694- catch (zorba::ZorbaException const& ze)
1695- {
1696- std::cerr << ze << std::endl;
1697+ catch ( ZorbaException const &ze ) {
1698+ cerr << ze << endl;
1699 return 32;
1700 }
1701 }
1702@@ -901,423 +515,374 @@
1703 //
1704 // Delete all loaded docs from the store, if timing has been requested
1705 //
1706- if (doTiming)
1707- {
1708- timing.startTimer(TimingInfo::UNLOAD_TIMER, i);
1709+ if ( zc_props.timing_ ) {
1710+ timers.startTimer( Timers::unload, exec );
1711
1712- DocumentManager* docMgr = xmlDataMgr->getDocumentManager();
1713+ DocumentManager *const docMgr = xmlDataMgr->getDocumentManager();
1714 ItemSequence_t docsSeq = docMgr->availableDocuments();
1715- Iterator_t lIter = docsSeq->getIterator();
1716- lIter->open();
1717+ Iterator_t i( docsSeq->getIterator() );
1718+ i->open();
1719
1720 Item uri;
1721- std::vector<Item> docURIs;
1722- while (lIter->next(uri))
1723- {
1724- docURIs.push_back(uri);
1725- }
1726- lIter->close();
1727-
1728- size_t numDocs = docURIs.size();
1729-
1730- for (size_t k = 0; k < numDocs; ++k)
1731- {
1732- docMgr->remove(docURIs[k].getStringValue());
1733- }
1734-
1735- timing.stopTimer(TimingInfo::UNLOAD_TIMER, i);
1736+ vector<Item> docURIs;
1737+ while ( i->next( uri ) )
1738+ docURIs.push_back( uri );
1739+ i->close();
1740+
1741+ for ( vector<Item>::const_iterator
1742+ i = docURIs.begin(); i != docURIs.end(); ++i ) {
1743+ docMgr->remove( i->getStringValue() );
1744+ }
1745+
1746+ timers.stopTimer( Timers::unload, exec );
1747 }
1748
1749- // stop the total timer
1750- if (doTiming)
1751- timing.stopTimer(TimingInfo::TOTAL_TIMER, i);
1752+ if ( zc_props.timing_ )
1753+ timers.stopTimer( Timers::total, exec );
1754
1755 #ifdef DO_AUDIT
1756- audit::Event* event = staticContext->getAuditEvent();
1757- std::cerr << *event << std::endl;
1758-#endif
1759+ cerr << *sctx->getAuditEvent() << endl;
1760+#endif /* DO_AUDIT */
1761 } // for each execution
1762
1763 return 0;
1764 }
1765
1766-/////////////////////////////////////////////////////////////////////////////////
1767-// //
1768-// Main //
1769-// //
1770-/////////////////////////////////////////////////////////////////////////////////
1771+static void set_paths_on_sctx( StaticContext_t &sctx ) {
1772+ ZorbaCmdProperties &zc_props = ZorbaCmdProperties::instance();
1773+ vector<String> paths;
1774+
1775+ // Compute the current working directory to append to all paths.
1776+ string const cwd( fs::curdir() );
1777+
1778+ // setModulePaths() *overwrites* the URI path and lib path, so there's no
1779+ // sense in calling both. So if --module-path exists, just use it.
1780+
1781+ if ( !zc_props.module_path_.empty() ) {
1782+ tokenize( zc_props.module_path_, fs::path_separator, &paths );
1783+ paths.push_back( cwd );
1784+ sctx->setModulePaths( paths );
1785+ } else {
1786+ // Compute and set URI path
1787+ tokenize( zc_props.uri_path_, fs::path_separator, &paths );
1788+ paths.push_back( cwd );
1789+ sctx->setURIPath( paths );
1790+ paths.clear();
1791+
1792+ // Compute and set lib path
1793+ tokenize( zc_props.lib_path_, fs::path_separator, &paths );
1794+ paths.push_back( cwd );
1795+ sctx->setLibPath( paths );
1796+ }
1797+}
1798+
1799+///////////////////////////////////////////////////////////////////////////////
1800+// //
1801+// Main //
1802+// //
1803+///////////////////////////////////////////////////////////////////////////////
1804
1805 #ifndef _WIN32_WCE
1806-int
1807-main(int argc, char* argv[])
1808+int main( int argc, char const *argv[] ) {
1809 #else
1810-int
1811-_tmain(int argc, _TCHAR* argv[])
1812-#endif
1813-{
1814-#if ZORBACMD_LOAD_SYSTEM_PROPERTIES
1815- // only configurable via a config file or environment vars
1816- zorba::Properties::load(0, NULL);
1817-#endif
1818-
1819- // parse the command line and/or the properties file
1820- ZorbaCMDProperties properties;
1821- if (!properties.loadProperties(argc, argv))
1822- {
1823- return 1;
1824- }
1825-
1826- TimingInfo engineTiming(properties.multiple());
1827-
1828- bool doTiming = properties.timing();
1829- bool debug = false;
1830+int _tmain( int argc, _TCHAR const *argv[] ) {
1831+#endif
1832+ int const optind = parse_args( argc, argv );
1833+ argc -= optind;
1834+ argv += optind;
1835+
1836+ Properties const &z_props = Properties::instance();
1837+ ZorbaCmdProperties const &zc_props = ZorbaCmdProperties::instance();
1838+
1839+ Timers timers( zc_props.multiple_ );
1840+
1841 #ifdef ZORBA_WITH_DEBUGGER
1842- debug = (properties.debug());
1843+ bool const debug = zc_props.debug_;
1844+#else
1845+ bool const debug = false;
1846 #endif
1847
1848- // libModule assumes compileOnly even if compileOnly is false
1849- bool compileOnly = (properties.compileOnly() || properties.libModule() );
1850+ // libModule assumes compile-only even if compile-only is false
1851+ bool const compile_only = zc_props.compile_only_ || zc_props.lib_module_;
1852
1853 // write to file or standard out
1854- std::unique_ptr<std::ostream>
1855- lFileStream(
1856- #ifdef ZORBA_WITH_FILE_ACCESS
1857- properties.outputFile().size() > 0 ?
1858- new std::ofstream(properties.outputFile().c_str()) : 0
1859- #else /* ZORBA_WITH_FILE_ACCESS */
1860- 0
1861- #endif /* ZORBA_WITH_FILE_ACCESS */
1862- );
1863+ unique_ptr<ostream> out_stream_ptr(
1864+#ifdef ZORBA_WITH_FILE_ACCESS
1865+ !zc_props.output_file_.empty() ?
1866+ new ofstream( zc_props.output_file_.c_str() ) : 0
1867+#else /* ZORBA_WITH_FILE_ACCESS */
1868+ 0
1869+#endif /* ZORBA_WITH_FILE_ACCESS */
1870+ );
1871
1872- std::ostream* lOutputStream = lFileStream.get();
1873- if ( lOutputStream == 0 )
1874- {
1875- lOutputStream = &std::cout;
1876- }
1877+ ostream *out_stream = out_stream_ptr.get();
1878+ if ( !out_stream )
1879+ out_stream = &cout;
1880 #ifdef ZORBA_WITH_FILE_ACCESS
1881- else if ( !lOutputStream->good() )
1882- {
1883- std::cerr << "could not write to output file {" << properties.outputFile()
1884- << "}" << std::endl;
1885+ else if ( !out_stream->good() ) {
1886+ cerr << "could not write to output file {" << zc_props.output_file_
1887+ << '}' << endl;
1888 return 2;
1889 }
1890 #endif /* ZORBA_WITH_FILE_ACCESS */
1891
1892- if (properties.queriesOrFilesBegin() == properties.queriesOrFilesEnd())
1893- {
1894- std::cerr << "no queries submitted." << std::endl;
1895- properties.printHelp(std::cout);
1896+ if ( zc_props.queries_or_files_.empty() ) {
1897+ cerr << "no queries submitted." << endl;
1898+ print_help();
1899 return 3;
1900 }
1901
1902- // Add command line --classpath option in front of config/env CLASSPATH
1903- Properties* globaproperties = Properties::instance();
1904- std::string cmdJvmClassPath;
1905- properties.getJVMClassPath(cmdJvmClassPath);
1906- std::string configJvmClassPath;
1907- globaproperties->getJVMClassPath(configJvmClassPath);
1908- globaproperties->setJVMClassPath(cmdJvmClassPath +
1909- fs::path_separator + configJvmClassPath);
1910-
1911 // Start the engine
1912
1913- engineTiming.startTimer(TimingInfo::INIT_TIMER, 2);
1914-
1915- void* store = zorba::StoreManager::getStore();
1916-
1917- zorba::Zorba* lZorbaInstance = zorba::Zorba::getInstance(store);
1918-
1919- zorba::XmlDataManager_t xmlDataMgr = lZorbaInstance->getXmlDataManager();
1920+ timers.startTimer( Timers::init, 2 );
1921+
1922+ void *const store = StoreManager::getStore();
1923+ Zorba *const zorba = Zorba::getInstance( store );
1924+
1925+ XmlDataManager_t xmlDataMgr = zorba->getXmlDataManager();
1926
1927 #ifdef DO_AUDIT
1928- zorba::audit::Provider* lAuditProvider = lZorbaInstance->getAuditProvider();
1929-
1930- zorba::audit::Configuration* config = lAuditProvider->createConfiguration();
1931-
1932- std::vector<zorba::String> property_names;
1933- zorba::audit::Configuration::getPropertyNames(property_names);
1934-
1935- zorba::audit::Configuration::
1936+ audit::Provider* lAuditProvider = zorba->getAuditProvider();
1937+
1938+ audit::Configuration* config = lAuditProvider->createConfiguration();
1939+
1940+ vector<String> property_names;
1941+ audit::Configuration::getPropertyNames(property_names);
1942+
1943+ audit::Configuration::
1944 enableProperty(config, property_names, "xquery/compilation/parse-duration");
1945
1946- zorba::audit::Configuration::
1947+ audit::Configuration::
1948 enableProperty(config, property_names, "xquery/compilation/translation-duration");
1949
1950- zorba::audit::Configuration::
1951+ audit::Configuration::
1952 enableProperty(config, property_names, "xquery/compilation/optimization-duration");
1953
1954- zorba::audit::Configuration::
1955+ audit::Configuration::
1956 enableProperty(config, property_names, "xquery/compilation/codegeneration-duration");
1957 #endif
1958
1959 {
1960- engineTiming.stopTimer(TimingInfo::INIT_TIMER, 2);
1961+ timers.stopTimer( Timers::init, 2 );
1962
1963 // For each query ...
1964
1965- int queryNo;
1966- ZorbaCMDProperties::QueriesOrFiles_t::const_iterator lIter;
1967- for (queryNo = 1, lIter = properties.queriesOrFilesBegin();
1968- lIter != properties.queriesOrFilesEnd();
1969- ++queryNo, ++lIter)
1970- {
1971+ int query_no;
1972+ vector<string>::const_iterator i;
1973+ for ( query_no = 1, i = zc_props.queries_or_files_.begin();
1974+ i != zc_props.queries_or_files_.end(); ++query_no, ++i ) {
1975 //
1976 // Read the query (either from a file or given as parameter)
1977 //
1978- std::string fURI = *lIter;
1979- std::string fname = parseFileURI (properties.asFiles (), fURI);
1980- std::string path( fname );
1981- bool asFile = !fname.empty();
1982- std::unique_ptr<std::istream> qfile;
1983+ string const uri( *i );
1984+ string const fname( zc_props.as_files_ ? uri : parse_file_uri( uri ) );
1985+ string path( fname );
1986+ bool const as_file = !fname.empty();
1987+ unique_ptr<istream> qstream;
1988
1989- if (asFile)
1990- {
1991+ if ( as_file ) {
1992 fs::make_absolute( &path );
1993- qfile.reset( new std::ifstream( path.c_str() ) );
1994- }
1995- else
1996- {
1997- qfile.reset(new std::istringstream(fURI));
1998+ qstream.reset( new ifstream( path.c_str() ) );
1999+ } else {
2000+ qstream.reset( new istringstream( uri ) );
2001 }
2002
2003- if (asFile && (!qfile->good() || qfile->eof()))
2004- {
2005- std::cerr << "file {" << fname << "} not found or not readable." << std::endl;
2006- properties.printHelp(std::cout);
2007+ if ( as_file && (!qstream->good() || qstream->eof()) ) {
2008+ cerr << "file {" << fname << "} not found or not readable." << endl;
2009+ print_help();
2010 return 3;
2011- }
2012- else if (fURI.empty ())
2013- {
2014- std::cerr << "empty query." << std::endl;
2015- properties.printHelp(std::cout);
2016+ } else if ( uri.empty() ) {
2017+ cerr << "empty query." << endl;
2018+ print_help();
2019 return 3;
2020 }
2021
2022 //
2023 // Print the query if requested
2024 //
2025- if (properties.printQuery())
2026- {
2027- *lOutputStream << "\nQuery number " << queryNo << " :\n";
2028- std::copy (std::istreambuf_iterator<char> (*qfile),
2029- std::istreambuf_iterator<char> (),
2030- std::ostreambuf_iterator<char> (*lOutputStream));
2031- *lOutputStream << std::endl;
2032- // go back to the beginning
2033- qfile->seekg(0);
2034+ if ( zc_props.print_query_ ) {
2035+ *out_stream << "\nQuery number " << query_no << " :\n";
2036+ copy(
2037+ istreambuf_iterator<char>( *qstream ),
2038+ istreambuf_iterator<char>(),
2039+ ostreambuf_iterator<char>( *out_stream )
2040+ );
2041+ *out_stream << endl;
2042+ qstream->seekg( 0 );
2043 }
2044
2045 //
2046- // Create the static context and populate it with info taken from the properties
2047+ // Create the static context and populate it with info taken from the
2048+ // properties
2049 //
2050- zorba::StaticContext_t lStaticContext = lZorbaInstance->createStaticContext();
2051+ StaticContext_t sctx = zorba->createStaticContext();
2052
2053- if (! populateStaticContext(lZorbaInstance, lStaticContext, properties) )
2054- {
2055- properties.printHelp(std::cout);
2056+ if ( !populateStaticContext( zorba, sctx ) ) {
2057+ print_help();
2058 return 3;
2059 }
2060
2061 #ifdef DO_AUDIT
2062- zorba::audit::Event* event = lAuditProvider->createEvent(config);
2063- lStaticContext->setAuditEvent(event);
2064+ audit::Event *event = lAuditProvider->createEvent( config );
2065+ sctx->setAuditEvent( event );
2066 #endif // DO_AUDIT
2067
2068- if (!asFile && properties.baseUri().size() == 0 )
2069- {
2070+ if ( !as_file && zc_props.base_uri_.empty() ) {
2071 // No user set base URI. Set the cwd to be used as base-uri in order
2072 // to make the doc function doc("mydoc.xml") work
2073- std::string p( fs::curdir() );
2074- std::stringstream lTmp;
2075- std::vector<std::string> lTokens;
2076- std::string const delim( 1, fs::dir_separator );
2077- Util::tokenize(p.c_str(), delim, lTokens);
2078+ string p( fs::curdir() );
2079+ stringstream lTmp;
2080+ vector<string> lTokens;
2081+ tokenize( p, fs::dir_separator, &lTokens );
2082
2083 lTmp << "file://";
2084- for (std::vector<std::string>::const_iterator lIter = lTokens.begin();
2085- lIter != lTokens.end(); ++lIter)
2086- {
2087- zorba::String lTmpString(*lIter);
2088- lTmp << '/' << fn::encode_for_uri( lTmpString );
2089+ for ( vector<string>::const_iterator i = lTokens.begin();
2090+ i != lTokens.end(); ++i ) {
2091+ String s( *i );
2092+ lTmp << '/' << fn::encode_for_uri( s );
2093 }
2094
2095 lTmp << '/';
2096-
2097- lStaticContext->setBaseURI(lTmp.str());
2098+ sctx->setBaseURI( lTmp.str() );
2099 }
2100
2101 // Parse the query
2102- if (properties.parseOnly())
2103- {
2104- try
2105- {
2106- zorba::XQuery_t lQuery = lZorbaInstance->createQuery();
2107- if (asFile)
2108- {
2109- lQuery->setFileName(path);
2110- }
2111+ if ( zc_props.parse_only_ ) {
2112+ try {
2113+ XQuery_t lQuery = zorba->createQuery();
2114+ if ( as_file )
2115+ lQuery->setFileName( path );
2116
2117- lQuery->parse (*qfile);
2118+ lQuery->parse (*qstream);
2119 }
2120- catch (zorba::ZorbaException const& ze)
2121- {
2122- std::cerr << ze << std::endl;
2123+ catch ( ZorbaException const &ze ) {
2124+ cerr << ze << endl;
2125 return 6;
2126 }
2127 }
2128
2129 // Compile and run it if necessary.
2130 // Print timing information if requested.
2131- else if (!debug)
2132- {
2133- if (compileOnly)
2134- {
2135- try
2136- {
2137- zorba::XQuery_t aQuery = lZorbaInstance->createQuery();
2138- if (asFile)
2139- {
2140- aQuery->setFileName(path);
2141- }
2142-
2143- aQuery->parse(*qfile);
2144-
2145- qfile->clear();
2146- qfile->seekg(0); // go back to the beginning
2147+ else if ( !debug ) {
2148+ if ( compile_only ) {
2149+ try {
2150+ XQuery_t aQuery = zorba->createQuery();
2151+ if ( as_file )
2152+ aQuery->setFileName( path );
2153+
2154+ aQuery->parse( *qstream );
2155+ qstream->clear();
2156+ qstream->seekg( 0 );
2157 }
2158- catch (zorba::XQueryException const& qe)
2159- {
2160- print_exception( qe, properties );
2161+ catch ( XQueryException const &qe ) {
2162+ print_exception( qe );
2163 return 6;
2164 }
2165 }
2166
2167- TimingInfo queryTiming(properties.multiple());
2168+ Timers queryTiming( zc_props.multiple_ );
2169
2170- int status = compileAndExecute(lZorbaInstance,
2171+ int status = compileAndExecute(zorba,
2172 xmlDataMgr,
2173- properties,
2174- lStaticContext,
2175+ sctx,
2176 path,
2177- *qfile,
2178- *lOutputStream,
2179+ *qstream,
2180+ *out_stream,
2181 queryTiming);
2182- if (status != 0)
2183- {
2184+ if ( status != 0 ) {
2185 // reset the file handler (in case output option was provided)
2186 // in order to delete the created output file
2187- lFileStream.reset();
2188- removeOutputFileIfNeeded(properties);
2189+ out_stream_ptr.reset();
2190+ remove_output_file();
2191 return status;
2192 }
2193
2194- if (doTiming)
2195- {
2196- bool serializePlan = properties.serializePlan();
2197- queryTiming.print(std::cout, serializePlan);
2198- }
2199+ if ( zc_props.timing_ )
2200+ queryTiming.print( cout, zc_props.serialize_plan_ );
2201 }
2202
2203 #ifdef ZORBA_WITH_DEBUGGER
2204- // Debug the query. Do not allow "compileOnly" flags and inline queries
2205- else if (debug)
2206- {
2207- if (compileOnly)
2208- {
2209- std::cerr << "cannot debug a query if the compileOnly option is specified"
2210- << std::endl;
2211+ // Debug the query. Do not allow "compile_only" flags and inline queries
2212+ else if ( debug ) {
2213+ if ( compile_only ) {
2214+ cerr << "cannot debug a query if the --compile-only option is specified"
2215+ << endl;
2216 return 7;
2217 }
2218
2219- if (!asFile)
2220- {
2221- std::cerr << "Cannot debug inline queries." << std::endl;
2222+ if ( !as_file ) {
2223+ cerr << "Cannot debug inline queries." << endl;
2224 return 8;
2225 }
2226
2227- std::unique_ptr<std::istream> lXQ(new std::ifstream(path.c_str()));
2228- std::string lFileName(path);
2229-
2230- zorba::XQuery_t lQuery;
2231-
2232- try
2233- {
2234- lQuery = lZorbaInstance->createQuery();
2235- lQuery->setFileName(lFileName);
2236- lQuery->setDebugMode(true);
2237-
2238- Zorba_CompilerHints lHints;
2239- lHints.opt_level = ZORBA_OPT_LEVEL_O0;
2240-
2241- lQuery->compile(*lXQ.get(), lHints);
2242- zorba::DynamicContext* lDynamicContext = lQuery->getDynamicContext();
2243- if (!populateDynamicContext(lZorbaInstance,
2244- xmlDataMgr,
2245- lDynamicContext,
2246- properties))
2247+ unique_ptr<istream> lXQ( new ifstream( path.c_str() ) );
2248+
2249+ XQuery_t query;
2250+
2251+ try {
2252+ query = zorba->createQuery();
2253+ query->setFileName( path );
2254+ query->setDebugMode( true );
2255+
2256+ Zorba_CompilerHints hints;
2257+ hints.opt_level = ZORBA_OPT_LEVEL_O0;
2258+
2259+ query->compile( *lXQ.get(), hints );
2260+ if (!populateDynamicContext(zorba, xmlDataMgr,
2261+ query->getDynamicContext()))
2262 {
2263 return 9;
2264 }
2265
2266- std::string lHost = properties.debugHost();
2267- if (lHost == "") {
2268- lHost = "127.0.0.1";
2269- }
2270-
2271- Zorba_SerializerOptions lSerOptions(properties.getSerializerParameters());
2272- createSerializerOptions(lSerOptions, properties);
2273-
2274- if (!properties.hasNoLogo())
2275- {
2276- std::cout << "Zorba XQuery Debugger Server\n" << copyright_str << std::endl;
2277- }
2278-
2279- lQuery->debug(*lOutputStream, lSerOptions, lHost, properties.getDebugPort());
2280+ Zorba_SerializerOptions ser_opts( zc_props.serialization_params_ );
2281+ set_serializer_opts( ser_opts );
2282+
2283+ if ( !zc_props.no_logo_ )
2284+ cout << "Zorba XQuery Debugger Server\n" << copyright << endl;
2285+
2286+ query->debug( *out_stream, ser_opts, zc_props.debug_host_, zc_props.debug_port_ );
2287 }
2288- catch (zorba::XQueryException const& qe)
2289- {
2290- print_exception( qe, properties );
2291+ catch ( XQueryException const &qe ) {
2292+ print_exception( qe );
2293 return 5;
2294 }
2295- catch (zorba::ZorbaException const& ze)
2296- {
2297- std::cerr << ze << std::endl;
2298+ catch ( ZorbaException const &ze ) {
2299+ cerr << ze << endl;
2300 return 6;
2301 }
2302 } // else if (debug)
2303-#endif
2304+#endif /* ZORBA_WITH_DEBUGGER */
2305
2306 #ifdef DO_AUDIT
2307- lAuditProvider->submitEvent(event);
2308+ lAuditProvider->submitEvent( event );
2309 #endif
2310
2311 } // for each query
2312
2313 }
2314
2315- if (doTiming)
2316- {
2317- engineTiming.startTimer(TimingInfo::DEINIT_TIMER, 2);
2318- }
2319+ if ( zc_props.timing_ )
2320+ timers.startTimer( Timers::deinit, 2 );
2321
2322 #ifdef DO_AUDIT
2323 lAuditProvider->destroyConfiguration(config);
2324-#endif
2325-
2326- xmlDataMgr = NULL;
2327-
2328- lZorbaInstance->shutdown();
2329- zorba::StoreManager::shutdownStore(store);
2330-
2331- if (doTiming)
2332- {
2333- engineTiming.stopTimer(TimingInfo::DEINIT_TIMER, 2);
2334-
2335- std::cout << std::endl << "Engine Shutdown Time : "
2336- << engineTiming.elapsedDeinitWalltime
2337- << " (user: " << engineTiming.elapsedDeinitCputime << ")"
2338- << " milliseconds" << std::endl;
2339+#endif /* DO_AUDIT */
2340+
2341+ zorba->shutdown();
2342+ StoreManager::shutdownStore( store );
2343+
2344+ if ( zc_props.timing_ ) {
2345+ timers.stopTimer( Timers::deinit, 2 );
2346+
2347+ cout << endl << "Engine Shutdown Time : "
2348+ << timers.elapsed_deinit_walltime
2349+ << " (user: " << timers.elapsed_deinit_cputime << ")"
2350+ << " milliseconds" << endl;
2351 }
2352+
2353 return 0;
2354 }
2355+
2356+///////////////////////////////////////////////////////////////////////////////
2357+
2358 /* vim:set et sw=2 ts=2: */
2359
2360=== added file 'bin/zorbacmd_args.cpp'
2361--- bin/zorbacmd_args.cpp 1970-01-01 00:00:00 +0000
2362+++ bin/zorbacmd_args.cpp 2014-02-11 00:42:47 +0000
2363@@ -0,0 +1,783 @@
2364+/*
2365+ * Copyright 2006-2008 The FLWOR Foundation.
2366+ *
2367+ * Licensed under the Apache License, Version 2.0 (the "License");
2368+ * you may not use this file except in compliance with the License.
2369+ * You may obtain a copy of the License at
2370+ *
2371+ * http://www.apache.org/licenses/LICENSE-2.0
2372+ *
2373+ * Unless required by applicable law or agreed to in writing, software
2374+ * distributed under the License is distributed on an "AS IS" BASIS,
2375+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2376+ * See the License for the specific language governing permissions and
2377+ * limitations under the License.
2378+ */
2379+
2380+// standard
2381+#include <algorithm>
2382+#include <cstdlib>
2383+#include <cctype>
2384+#include <iostream>
2385+
2386+// Zorba
2387+#include <zorba/zorba.h>
2388+#include <zorba/properties.h>
2389+
2390+// local
2391+#include "zorbacmd_props.h"
2392+
2393+using namespace std;
2394+using namespace zorba;
2395+
2396+///////////////////////////////////////////////////////////////////////////////
2397+
2398+static char const* check_args() {
2399+ ZorbaCmdProperties const &zc_props = ZorbaCmdProperties::instance();
2400+
2401+ if ( !( zc_props.boundary_space_.empty() ||
2402+ zc_props.boundary_space_ == "preserve" ||
2403+ zc_props.boundary_space_ == "strip" ) )
2404+ return "Only strip and preserve are allowed as values for the option boundary-space";
2405+
2406+ if ( !( zc_props.construction_mode_.empty() ||
2407+ zc_props.construction_mode_ == "preserve" ||
2408+ zc_props.construction_mode_ == "strip" ) )
2409+ return "Only strip and preserve are allowed as values for the option construction-mode";
2410+
2411+ if ( zc_props.optimization_level_ > 2 )
2412+ return "only 0, 1 and 2 are allowed as values for the option --optimization-level";
2413+
2414+ if ( !( zc_props.ordering_mode_.empty() ||
2415+ zc_props.ordering_mode_ == "ordered" ||
2416+ zc_props.ordering_mode_ == "unordered" ) )
2417+ return "Only ordered and unordered are allowed as values for the option ordering-mode";
2418+
2419+ if ( zc_props.queries_or_files_.empty() )
2420+ return "No queries submitted\nUsage: zorba -q '1 + 1' execute an inline query \n zorba file.xq execute a query from a file";
2421+
2422+ return 0;
2423+}
2424+
2425+///////////////////////////////////////////////////////////////////////////////
2426+
2427+#define HELP_OPT(ARG) ARG "\n"
2428+
2429+char const* get_help_msg() {
2430+ return
2431+
2432+ ////////// a //////////////////////////////////////////////////////////////
2433+
2434+#ifndef NDEBUG
2435+ HELP_OPT( "--abort" )
2436+ "Call abort(3) when a ZorbaException is thrown.\n\n"
2437+#endif /* NDEBUG */
2438+
2439+ HELP_OPT( "--as-files, -f" )
2440+ "Treat all -q arguments as file paths instead of URIs or inline queries. This option is deprecated and will be defaulted to true in the future, so any entry in the command line is going to be treated as files.\n\n"
2441+
2442+ ////////// b //////////////////////////////////////////////////////////////
2443+
2444+ HELP_OPT( "--base-uri" )
2445+ "Set the base URI property of the static context.\n\n"
2446+
2447+ HELP_OPT( "--boundary-space" )
2448+ "Set the boundary-space policy ('strip' or 'preserve') in the static context.\n\n"
2449+
2450+ HELP_OPT( "--byte-order-mark" )
2451+ "Set the byte-order-mark for the serializer.\n\n"
2452+
2453+ ////////// c //////////////////////////////////////////////////////////////
2454+
2455+ HELP_OPT( "--classpath" )
2456+ "JVM classpath to be used by modules using Java implementations\n\n"
2457+
2458+ HELP_OPT( "--compile-only" )
2459+ "Only compile (don't execute).\n\n"
2460+
2461+ HELP_OPT( "--compile-plan," )
2462+ "Do not execute the query; just compile it and save the execution plan in the file specified with the -o option.\n\n"
2463+
2464+ HELP_OPT( "--construction-mode" )
2465+ "Set the construction mode ('strip' or 'preserve') in the static context.\n\n"
2466+
2467+ HELP_OPT( "--context-item" )
2468+ "Set the context item to the XML document in a given file.\n\n"
2469+
2470+ ////////// d //////////////////////////////////////////////////////////////
2471+
2472+#ifdef ZORBA_WITH_DEBUGGER
2473+ HELP_OPT( "--debug, -d" )
2474+ "Launch the Zorba debugger server and connect to a DBGP-enabled debugger client.\n\n"
2475+#endif /* ZORBA_WITH_DEBUGGER */
2476+
2477+ HELP_OPT( "--debug-file" )
2478+ "Sets the file to write developer debugging information to.\n\n"
2479+
2480+#ifdef ZORBA_WITH_DEBUGGER
2481+ HELP_OPT( "--debug-host, -h" )
2482+ "The host where the DBGP-enabled debugger client listens for connections. Defaults to: 127.0.0.1\n\n"
2483+
2484+ HELP_OPT( "--debug-port, -p" )
2485+ "The port on which the DBGP-enabled debugger client listens for connections. Defaults to: 28028\n\n"
2486+#endif /* ZORBA_WITH_DEBUGGER */
2487+
2488+ HELP_OPT( "--default-collation" )
2489+ "Add the given collation and set the value of the default collation in the static context to the given collation.\n\n"
2490+
2491+ HELP_OPT( "--disable-http-resolution" )
2492+ "Do not use HTTP to resolve URIs.\n\n"
2493+
2494+ HELP_OPT( "--dump-lib" )
2495+ "Dump function library.\n\n"
2496+
2497+ ////////// e //////////////////////////////////////////////////////////////
2498+
2499+ HELP_OPT( "--execute-plan" )
2500+ "Do not compile the query; instead load the execution plan from the file specified by the -f -q options (or by any file specified without any other argument), and execute the loaded plan.\n\n"
2501+
2502+ HELP_OPT( "--external-variable, -e" )
2503+ "Provide the value for a variable given a file (name=file) or a value (name:=value)\n\n"
2504+
2505+ ////////// f //////////////////////////////////////////////////////////////
2506+
2507+ HELP_OPT( "--force-gflwor" )
2508+ "Force the compiler to generate GFLWOR iterators.\n\n"
2509+
2510+ ////////// h //////////////////////////////////////////////////////////////
2511+
2512+ HELP_OPT( "--help, -h" )
2513+ "Print this help message.\n\n"
2514+
2515+ ////////// i //////////////////////////////////////////////////////////////
2516+
2517+ HELP_OPT( "--indent, -i" )
2518+ "Indent output.\n\n"
2519+
2520+ HELP_OPT( "--infer-joins" )
2521+ "Infer joins.\n\n"
2522+
2523+ HELP_OPT( "--inline-udf" )
2524+ "Inline user-defined functions.\n\n"
2525+
2526+ ////////// j //////////////////////////////////////////////////////////////
2527+
2528+ HELP_OPT( "--jsoniq, -j" )
2529+ "Force queries to be considered JSONiq.\n\n"
2530+
2531+ ////////// l //////////////////////////////////////////////////////////////
2532+
2533+ HELP_OPT( "--lib-module, -l" )
2534+ "Query compiler option to treat the query as a library module. If this is set --compile-only option is also set to true.\n\n"
2535+
2536+ HELP_OPT( "--lib-path" )
2537+ "Library path (list of directories) where Zorba will look for dynamic libraries (e.g., module external function implementations.\n\n"
2538+
2539+ HELP_OPT( "--loop-hosting" )
2540+ "Hoist expressions out of loops.\n\n"
2541+
2542+ ////////// m //////////////////////////////////////////////////////////////
2543+
2544+ HELP_OPT( "--max-udf-call-depth" )
2545+ "Maximum stack depth of user-defined function calls.\n\n"
2546+
2547+ HELP_OPT( "--module-path" )
2548+ "Path (list of directories) to add to both the URI and Library paths.\n\n"
2549+
2550+ HELP_OPT( "--multiple, -m" )
2551+ "Execute the given queries multiple times.\n\n"
2552+
2553+ ////////// n //////////////////////////////////////////////////////////////
2554+
2555+ HELP_OPT( "--no-copy-optim" )
2556+ "Apply the no-copy optimization.\n\n"
2557+
2558+ HELP_OPT( "--no-logo" )
2559+ "Print no logo when starting.\n\n"
2560+
2561+ HELP_OPT( "--no-serializer" )
2562+ "Do not serialize (discard) result.\n\n"
2563+
2564+ HELP_OPT( "--no-tree-ids" )
2565+ "Suppress IDs and locations from compiler tree dumps.\n\n"
2566+
2567+ ////////// o //////////////////////////////////////////////////////////////
2568+
2569+ HELP_OPT( "--omit-xml-declaration, -r" )
2570+ "Omit the XML declaration from the result.\n\n"
2571+
2572+ HELP_OPT( "--optimization-level, -O" )
2573+ "Optimization level for the query compiler [0-2], default: 1\n\n"
2574+
2575+ HELP_OPT( "--option" )
2576+ "Set an XQuery option in the static context. The QName of the option is passed as a string in the notation by James Clark (i.e. {namespace}localname). For example, --option {http://zorba.io/}option=value\n\n"
2577+
2578+ HELP_OPT( "--ordering-mode" )
2579+ "Set the ordering mode ('ordered' or 'unordered') in the static context.\n\n"
2580+
2581+#ifdef ZORBA_WITH_FILE_ACCESS
2582+ HELP_OPT( "--output-file, -o" )
2583+ "Write the result to the given file.\n\n"
2584+#endif /* ZORBA_WITH_FILE_ACCESS */
2585+
2586+ ////////// p //////////////////////////////////////////////////////////////
2587+
2588+ HELP_OPT( "--parse-only" )
2589+ "Stop after parsing the query.\n\n"
2590+
2591+ HELP_OPT( "--print-ast" )
2592+ "Print the abstract syntax tree.\n\n"
2593+
2594+ HELP_OPT( "--print-errors-as-xml, -x" )
2595+ "Print the errors as XML.\n\n"
2596+
2597+ HELP_OPT( "--print-intermediate-opt" )
2598+ "Print intermediate optimizations.\n\n"
2599+
2600+ HELP_OPT( "--print-item-flow" )
2601+ "Print items produced by all iterators.\n\n"
2602+
2603+ HELP_OPT( "--print-iterator-tree" )
2604+ "Print the iterator tree.\n\n"
2605+
2606+ HELP_OPT( "--print-locations" )
2607+ "Print parser locations for compiler expressions.\n\n"
2608+
2609+ HELP_OPT( "--print-optimized" )
2610+ "Print the optimized expression tree.\n\n"
2611+
2612+ HELP_OPT( "--print-query" )
2613+ "Print the queries.\n\n"
2614+
2615+ HELP_OPT( "--print-static-types" )
2616+ "Print static type inference.\n\n"
2617+
2618+ HELP_OPT( "--print-translated" )
2619+ "Print the normalized expression tree.\n\n"
2620+
2621+ ////////// q //////////////////////////////////////////////////////////////
2622+
2623+ HELP_OPT( "--query, -q" )
2624+ "Query test or file URI (file://...)\n\n"
2625+
2626+ ////////// s //////////////////////////////////////////////////////////////
2627+
2628+ HELP_OPT( "--serialization-parameter, -z" )
2629+ "Set serialization parameter in the form of a parameter=value pair (see http://www.w3.org/TR/xslt-xquery-serialization/#serparam, e.g.: -z method=xhtml -z doctype-system=DTD/xhtml1-strict.dtd -z indent=yes).\n\n"
2630+
2631+ HELP_OPT( "--serialize-html" )
2632+ "Serialize the result as HTML.\n\n"
2633+
2634+ HELP_OPT( "--serialize-plan, -s" )
2635+ "Serialize and then load the query execution plan.\n\n"
2636+
2637+ HELP_OPT( "--serialize-only-query" )
2638+ "Serialize only query.\n\n"
2639+
2640+ HELP_OPT( "--serialize-plan, s" )
2641+ "Serialize and then load the query execution plan.\n\n"
2642+
2643+ HELP_OPT( "--serialize-text" )
2644+ "Serialize the result as text.\n\n"
2645+
2646+ HELP_OPT( "--stable-iterator-ids" )
2647+ "Print the iterator plan with stable IDs.\n\n"
2648+
2649+#ifndef ZORBA_NO_FULL_TEXT
2650+ HELP_OPT( "--stop-words" )
2651+ "Mapping specifying a stop-words URI to another.\n\n"
2652+
2653+ ////////// t //////////////////////////////////////////////////////////////
2654+
2655+ HELP_OPT( "--thesaurus" )
2656+ "Mapping specifying a thesaurus URI to another.\n\n"
2657+#endif /* ZORBA_NO_FULL_TEXT */
2658+
2659+ HELP_OPT( "--timing, -t" )
2660+ "Print timing information. In case of multiple queries, the timing information is provided per query. Both wallclock time and user time (which excludes I/O, network delays and other kernel waits) are shown.\n\n"
2661+
2662+ HELP_OPT( "--timeout" )
2663+ "Specify a timeout in seconds. After the specified time, the execution of the query will be aborted.\n\n"
2664+
2665+ HELP_OPT( "--trace-parsing" )
2666+ "Trace parsing.\n\n"
2667+
2668+ HELP_OPT( "--trace-scanning" )
2669+ "Trace scanning.\n\n"
2670+
2671+#ifndef NDEBUG
2672+ HELP_OPT( "--trace-codegen" )
2673+ "Trace code generatio.\n\n"
2674+
2675+ HELP_OPT( "--trace-fulltext" )
2676+ "Trace full-text.\n\n"
2677+
2678+ HELP_OPT( "--trace-translator" )
2679+ "Trace the translator.\n\n"
2680+#endif /* NDEBUG */
2681+
2682+ HELP_OPT( "--trailing-nl" )
2683+ "Print a trailing newline after the result of the query.\n\n"
2684+
2685+ ////////// u //////////////////////////////////////////////////////////////
2686+
2687+ HELP_OPT( "--uri-path" )
2688+ "URI path (list of directories) added to the built-in URI resolver, i.e. where to find modules/schemas to import.\n\n"
2689+
2690+ ////////// v //////////////////////////////////////////////////////////////
2691+
2692+ HELP_OPT( "--version, -v" )
2693+ "Print the version number and exit.\n\n"
2694+
2695+ ;
2696+}
2697+
2698+///////////////////////////////////////////////////////////////////////////////
2699+
2700+static bool split_key_value( char const *s, char const *split,
2701+ string *key, string *value ) {
2702+ char const *const p = strstr( s, split );
2703+ size_t const split_len = strlen( split );
2704+ if ( !p || p == s /* =xxx */ || !p[ split_len ] /* xxx= */ )
2705+ return false;
2706+ key->assign( s, 0, p - s );
2707+ value->assign( p + split_len );
2708+ return true;
2709+}
2710+
2711+inline char to_lower( char c ) {
2712+ return tolower( c );
2713+}
2714+
2715+template<class StringType> inline
2716+typename enable_if<ZORBA_IS_STRING(StringType),void>::type
2717+to_lower( StringType &s ) {
2718+ transform(
2719+ s.begin(), s.end(), s.begin(), static_cast<char (*)(char)>( to_lower )
2720+ );
2721+}
2722+
2723+static bool bool_of( char const *s ) {
2724+ string b( s );
2725+ to_lower( b );
2726+ if ( b == "t" || b == "true" || b == "y" || b == "yes" || b == "1" )
2727+ return true;
2728+ if ( b == "f" || b == "false" || b == "n" || b == "no" || b == "0" )
2729+ return false;
2730+ cerr << '"' << s << "\": invalid boolean value" << endl;
2731+ exit( 1 );
2732+}
2733+
2734+///////////////////////////////////////////////////////////////////////////////
2735+
2736+#define IS_LONG_OPT(OPT) (strcmp( *argv, (OPT) ) == 0)
2737+#define IS_SHORT_OPT(OPT) (strncmp( *argv, (OPT), 2 ) == 0)
2738+#define IS_OPT(LOPT,SOPT) (IS_LONG_OPT(LOPT) || IS_SHORT_OPT(SOPT))
2739+
2740+#define PARSE_ARG(ARG) \
2741+ int offset = 2; \
2742+ if ( (*argv)[1] == '-' || !(*argv)[2] ) { offset = 0; ++argv; } \
2743+ if ( !*argv ) { error = "No value given for " #ARG " option"; break; }
2744+
2745+#define ARG_VAL (*argv + offset)
2746+
2747+template<typename T> inline
2748+void atoi( char const *s, T *result, int offset = 0 ) {
2749+ istringstream iss( s + offset );
2750+ iss >> *result;
2751+}
2752+
2753+#define SET_ZCPROP(PROP) \
2754+ atoi( *argv, &zc_props.PROP, offset )
2755+
2756+template<class C,typename T> inline
2757+void atoi( char const *s, C &c, void (C::*f)( T ), int offset = 0 ) {
2758+ T temp;
2759+ atoi( s, &temp, offset );
2760+ (c.*f)( temp );
2761+}
2762+
2763+#define SET_ZPROP(PROP) \
2764+ atoi( *argv, z_props, &Properties::set##PROP, offset )
2765+
2766+int parse_args( int argc, char const *argv[] ) {
2767+ bool got_as_files = false;
2768+ char const *error = 0;
2769+ Properties &z_props = Properties::instance();
2770+ ZorbaCmdProperties &zc_props = ZorbaCmdProperties::instance();
2771+
2772+ char const **const argv_orig = argv;
2773+ for ( ++argv; *argv; ++argv ) {
2774+
2775+ ////////// a //////////////////////////////////////////////////////////////
2776+
2777+#ifndef NDEBUG
2778+ if ( IS_LONG_OPT( "--abort" ) )
2779+ z_props.setAbort( true );
2780+ else
2781+#endif /* NDEBUG */
2782+ if ( IS_OPT( "--as-files", "-f" ) ) {
2783+ zc_props.as_files_ = true;
2784+ got_as_files = true;
2785+ }
2786+
2787+ ////////// b //////////////////////////////////////////////////////////////
2788+
2789+ else if ( IS_LONG_OPT( "--base-uri" ) ) {
2790+ PARSE_ARG( "--base-uri" );
2791+ zc_props.base_uri_ = ARG_VAL;
2792+ }
2793+ else if ( IS_LONG_OPT( "--boundary-space" ) ) {
2794+ PARSE_ARG( "--boundary-space" );
2795+ zc_props.boundary_space_ = ARG_VAL;
2796+ }
2797+ else if ( IS_LONG_OPT( "--byte-order-mark" ) )
2798+ zc_props.byte_order_mark_ = true;
2799+
2800+ ////////// c //////////////////////////////////////////////////////////////
2801+
2802+ else if ( IS_LONG_OPT( "--classpath" ) ) {
2803+ PARSE_ARG( "--classpath" );
2804+ z_props.setJVMClassPath( ARG_VAL );
2805+ }
2806+ else if ( IS_LONG_OPT( "--compile-only" ) )
2807+ zc_props.compile_only_ = true;
2808+ else if ( IS_LONG_OPT( "--compile-plan" ) )
2809+ zc_props.save_plan_ = true;
2810+ else if ( IS_LONG_OPT( "--construction-mode" ) ) {
2811+ PARSE_ARG( "--construction-mode" );
2812+ zc_props.construction_mode_ = ARG_VAL;
2813+ }
2814+ else if ( IS_LONG_OPT( "--context-item" ) ) {
2815+ PARSE_ARG( "--context-item" );
2816+ zc_props.ctx_item_ = ARG_VAL;
2817+ }
2818+
2819+ ////////// d //////////////////////////////////////////////////////////////
2820+
2821+#ifdef ZORBA_WITH_DEBUGGER
2822+ else if ( IS_OPT( "--debug", "-d" ) )
2823+ zc_props.debug_ = true;
2824+#endif /* ZORBA_WITH_DEBUGGER */
2825+ else if ( IS_LONG_OPT( "--debug-file" ) ) {
2826+ PARSE_ARG( "--debug-file" );
2827+ z_props.setDebugFile( ARG_VAL );
2828+ }
2829+#ifdef ZORBA_WITH_DEBUGGER
2830+ else if ( IS_OPT( "--debug-host", "-h" ) ) {
2831+ PARSE_ARG( "--debug-host" );
2832+ zc_props.debug_host_ = ARG_VAL;
2833+ }
2834+ else if ( IS_OPT( "--debug-port", "-p" ) ) {
2835+ PARSE_ARG( "--debug-port" );
2836+ SET_ZCPROP( debug_port_ );
2837+ }
2838+#endif /* ZORBA_WITH_DEBUGGER */
2839+ else if ( IS_LONG_OPT( "--default-collation" ) ) {
2840+ PARSE_ARG( "--default-collation" );
2841+ zc_props.default_collation_ = ARG_VAL;
2842+ }
2843+ else if ( IS_LONG_OPT( "--disable-http-resolution" ) ) {
2844+ sctx_opt opt;
2845+ opt.clark_qname = "{http://zorba.io/options/features}disable";
2846+ opt.value = "http-uri-resolution";
2847+ zc_props.sctx_opts_.push_back( opt );
2848+ }
2849+ else if ( IS_LONG_OPT( "--dump-lib" ) )
2850+ z_props.setDumpLib( true );
2851+
2852+ ////////// e //////////////////////////////////////////////////////////////
2853+
2854+ else if ( IS_LONG_OPT( "--execute-plan" ) )
2855+ zc_props.load_plan_ = true;
2856+ else if ( IS_OPT( "--external-variable", "-e" ) ) {
2857+ PARSE_ARG( "--external-variable" );
2858+ string key, value;
2859+ if ( !split_key_value( ARG_VAL, "=", &key, &value ) ) {
2860+ error = "--external-variable argument must be of the form name=file or name:=value\n";
2861+ break;
2862+ }
2863+ external_var ev;
2864+ ev.var_value = value;
2865+
2866+ if ( key[0] == ':' ) {
2867+ error = "--external-variable argument must be of the form name=file or name:=value\n";
2868+ break;
2869+ }
2870+ if ( key[ key.size() - 1 ] == ':' )
2871+ key.erase( key.size() - 1 );
2872+ else
2873+ ev.inline_file = true;
2874+ ev.var_name = key;
2875+
2876+ zc_props.external_vars_.push_back( ev );
2877+ }
2878+
2879+ ////////// f //////////////////////////////////////////////////////////////
2880+
2881+ else if ( IS_LONG_OPT( "--force-gflwor" ) )
2882+ z_props.setForceGFLWOR( true );
2883+
2884+ ////////// h //////////////////////////////////////////////////////////////
2885+
2886+ else if ( IS_OPT( "--help", "-h" ) ) {
2887+ cout << "Zorba NoSQL Query Processor, Version: "
2888+ << Zorba::version() << '\n'
2889+ << "Available options:\n\n"
2890+ << get_help_msg();
2891+ exit( 0 );
2892+ }
2893+
2894+ ////////// i //////////////////////////////////////////////////////////////
2895+
2896+ else if ( IS_OPT( "--indent", "-i" ) )
2897+ zc_props.indent_ = true;
2898+ else if ( IS_LONG_OPT( "--infer-joins" ) ) {
2899+ PARSE_ARG( "--infer-joins" );
2900+ z_props.setInferJoins( bool_of( ARG_VAL ) );
2901+ }
2902+ else if ( IS_LONG_OPT( "--inline-udf" ) ) {
2903+ PARSE_ARG( "--inline-udf" );
2904+ z_props.setInlineUDF( bool_of( ARG_VAL ) );
2905+ }
2906+
2907+ ////////// j //////////////////////////////////////////////////////////////
2908+
2909+ else if ( IS_OPT( "--jsoniq", "-j" ) )
2910+ zc_props.jsoniq_ = true;
2911+
2912+ ////////// l //////////////////////////////////////////////////////////////
2913+
2914+ else if ( IS_OPT( "--lib-module", "-l" ) )
2915+ zc_props.lib_module_ = true;
2916+ else if ( IS_LONG_OPT( "--lib-path" ) ) {
2917+ PARSE_ARG( "--lib-path" );
2918+ zc_props.lib_path_ = ARG_VAL;
2919+ }
2920+ else if ( IS_LONG_OPT( "--loop-hoisting" ) ) {
2921+ PARSE_ARG( "--loop-hoisting" );
2922+ z_props.setLoopHoisting( bool_of( ARG_VAL ) );
2923+ }
2924+
2925+ ////////// m //////////////////////////////////////////////////////////////
2926+
2927+ else if ( IS_LONG_OPT( "--max-udf-call-depth" ) ) {
2928+ PARSE_ARG( "--max-udf-call-depth" );
2929+ SET_ZPROP( MaxUDFCallDepth );
2930+ }
2931+ else if ( IS_LONG_OPT( "--module-path" ) ) {
2932+ PARSE_ARG( "--module-path" );
2933+ zc_props.module_path_ = ARG_VAL;
2934+ }
2935+ else if ( IS_OPT( "--multiple", "-m" ) ) {
2936+ PARSE_ARG( "--multiple" );
2937+ SET_ZCPROP( multiple_ );
2938+ }
2939+
2940+ ////////// n //////////////////////////////////////////////////////////////
2941+
2942+ else if ( IS_LONG_OPT( "--no-copy-optim" ) ) {
2943+ PARSE_ARG( "--no-copy-optim" );
2944+ z_props.setNoCopyOptim( bool_of( ARG_VAL ) );
2945+ }
2946+ else if ( IS_LONG_OPT( "--no-logo" ) )
2947+ zc_props.no_logo_ = true;
2948+ else if ( IS_LONG_OPT( "--no-serializer" ) )
2949+ zc_props.no_serializer_ = true;
2950+ else if ( IS_LONG_OPT( "--no-tree-ids" ) )
2951+ z_props.setNoTreeIDs( true );
2952+
2953+ ////////// o //////////////////////////////////////////////////////////////
2954+
2955+ else if ( IS_OPT( "--omit-xml-declaration", "-r" ) )
2956+ zc_props.omit_xml_declaration_ = true;
2957+ else if ( IS_OPT( "--optimization-level", "-O" ) ) {
2958+ PARSE_ARG( "--optimization-level" );
2959+ unsigned opt_level;
2960+ atoi( ARG_VAL, &opt_level );
2961+ if ( opt_level > 2 ) {
2962+ error = "Only 0, 1 and 2 are allowed as values for --optimization-level";
2963+ break;
2964+ }
2965+ z_props.setOptimizationLevel( opt_level );
2966+ }
2967+ else if ( IS_LONG_OPT( "--option" ) ) {
2968+ PARSE_ARG( "--option" );
2969+ string key, value;
2970+ if ( !split_key_value( ARG_VAL, "=", &key, &value ) ) {
2971+ error = "--option argument must be of the form {namespace}localname=value\n";
2972+ break;
2973+ }
2974+ // TODO: check key is of the form {ns}local
2975+ sctx_opt opt;
2976+ opt.clark_qname = key;
2977+ opt.value = value;
2978+ zc_props.sctx_opts_.push_back( opt );
2979+ }
2980+ else if ( IS_LONG_OPT( "--ordering-mode" ) ) {
2981+ PARSE_ARG( "--ordering-mode" );
2982+ zc_props.ordering_mode_ = ARG_VAL;
2983+ }
2984+#ifdef ZORBA_WITH_FILE_ACCESS
2985+ else if ( IS_OPT( "--output-file", "-o" ) ) {
2986+ PARSE_ARG( "--output-file" );
2987+ zc_props.output_file_ = ARG_VAL;
2988+ }
2989+#endif /* ZORBA_WITH_FILE_ACCESS */
2990+
2991+ ////////// p //////////////////////////////////////////////////////////////
2992+
2993+ else if ( IS_LONG_OPT( "--parse-only" ) )
2994+ zc_props.parse_only_ = true;
2995+ else if ( IS_OPT( "--print-ast", "-a" ) )
2996+ z_props.setPrintAST( true );
2997+ else if ( IS_OPT( "--print-errors-as-xml", "-x" ) )
2998+ zc_props.print_errors_as_xml_ = true;
2999+ else if ( IS_LONG_OPT( "--print-intermediate-opt" ) )
3000+ z_props.setPrintIntermediateOpt( true );
3001+ else if ( IS_LONG_OPT( "--print-item-flow" ) )
3002+ z_props.setPrintItemFlow( true );
3003+ else if ( IS_LONG_OPT( "--print-iterator-tree" ) )
3004+ z_props.setPrintIteratorTree( true );
3005+ else if ( IS_LONG_OPT( "--print-locations" ) )
3006+ z_props.setPrintLocations( true );
3007+ else if ( IS_OPT( "--print-optimized", "-P" ) )
3008+ z_props.setPrintOptimized( true );
3009+ else if ( IS_LONG_OPT( "--print-query" ) )
3010+ zc_props.print_query_ = true;
3011+ else if ( IS_LONG_OPT( "--print-static-types" ) )
3012+ z_props.setPrintStaticTypes( true );
3013+ else if ( IS_LONG_OPT( "--print-translated" ) )
3014+ z_props.setPrintTranslated( true );
3015+
3016+ ////////// q //////////////////////////////////////////////////////////////
3017+
3018+ else if ( IS_OPT( "--query", "-q" ) ) {
3019+ if ( !got_as_files )
3020+ zc_props.as_files_ = false;
3021+ if ( *(argv+1) && !strncmp( *(argv+1), "-f", 2 ) )
3022+ break; // is it "-q -f <filename>" perhaps?
3023+ PARSE_ARG( "--query" );
3024+ zc_props.queries_or_files_.push_back( ARG_VAL );
3025+ }
3026+
3027+ ////////// s //////////////////////////////////////////////////////////////
3028+
3029+ else if ( IS_OPT( "--serialization-parameter", "-z" ) ) {
3030+ PARSE_ARG( "--serialization-parameter" );
3031+ string key, value;
3032+ serialization_param sp;
3033+ if ( split_key_value( ARG_VAL, "=", &key, &value ) ) {
3034+ sp.first = key;
3035+ sp.second = value;
3036+ } else
3037+ sp.first = ARG_VAL;
3038+ zc_props.serialization_params_.push_back( sp );
3039+ }
3040+ else if ( IS_LONG_OPT( "--serialize-html" ) )
3041+ zc_props.serialize_html_ = true;
3042+ else if ( IS_LONG_OPT( "--serialize-only-query" ) ) {
3043+ PARSE_ARG( "--serialize-only-query" );
3044+ zc_props.serialize_only_query_ = bool_of( ARG_VAL );
3045+ }
3046+ else if ( IS_OPT( "--serialize-plan", "-s" ) )
3047+ zc_props.serialize_plan_ = true;
3048+ else if ( IS_LONG_OPT( "--serialize-text" ) )
3049+ zc_props.serialize_text_ = true;
3050+ else if ( IS_LONG_OPT( "--stable-iterator-ids" ) )
3051+ z_props.setStableIteratorIDs( true );
3052+#ifndef ZORBA_NO_FULL_TEXT
3053+ else if ( IS_LONG_OPT( "--stop-words" ) ) {
3054+ PARSE_ARG( "--stop-words" );
3055+ string uri, value;
3056+ if ( !split_key_value( ARG_VAL, ":=", &uri, &value ) ) {
3057+ error = "--stop-words argument must be of the form URI:=value\n";
3058+ break;
3059+ }
3060+ ft_mapping ft;
3061+ ft.uri = uri;
3062+ ft.value = value;
3063+ zc_props.stop_words_mapping_.push_back( ft );
3064+ }
3065+
3066+ ////////// t //////////////////////////////////////////////////////////////
3067+
3068+ else if ( IS_LONG_OPT( "--thesaurus" ) ) {
3069+ PARSE_ARG( "--thesaurus" );
3070+ string uri, value;
3071+ if ( !split_key_value( ARG_VAL, ":=", &uri, &value ) ) {
3072+ error = "--thesaurus argument must be of the form URI:=value\n";
3073+ break;
3074+ }
3075+ if ( uri == "default" )
3076+ uri = "##default";
3077+ ft_mapping ft;
3078+ ft.uri = uri;
3079+ ft.value = value;
3080+ zc_props.thesaurus_mapping_.push_back( ft );
3081+ }
3082+#endif /* ZORBA_NO_FULL_TEXT */
3083+ else if ( IS_OPT( "--timing", "-t" ) )
3084+ zc_props.timing_ = true;
3085+ else if ( IS_LONG_OPT( "--timeout" ) ) {
3086+ PARSE_ARG( "--timeout" );
3087+ SET_ZCPROP( timeout_ );
3088+ }
3089+ else if ( IS_LONG_OPT( "--trace-parsing" ) )
3090+ z_props.setTraceParsing( true );
3091+ else if ( IS_LONG_OPT( "--trace-scanning" ) )
3092+ z_props.setTraceScanning( true );
3093+#ifndef NDEBUG
3094+ else if ( IS_LONG_OPT( "--trace-codegen" ) )
3095+ z_props.setTraceCodegen( true );
3096+ else if ( IS_LONG_OPT( "--trace-fulltext" ) )
3097+ z_props.setTraceFulltext( true );
3098+ else if ( IS_LONG_OPT( "--trace-translator" ) )
3099+ z_props.setTraceTranslator( true );
3100+#endif /* NDEBUG */
3101+ else if ( IS_LONG_OPT( "--trailing-nl" ) )
3102+ zc_props.trailing_nl_ = true;
3103+
3104+ ////////// u //////////////////////////////////////////////////////////////
3105+
3106+ else if ( IS_LONG_OPT( "--uri-path" ) ) {
3107+ PARSE_ARG( "--uri-path" );
3108+ zc_props.uri_path_ = ARG_VAL;
3109+ }
3110+ else if ( IS_LONG_OPT( "--use-indexes" ) ) {
3111+ PARSE_ARG( "--use-indexes" );
3112+ z_props.setUseIndexes( true );
3113+ }
3114+
3115+ ////////// v //////////////////////////////////////////////////////////////
3116+
3117+ else if ( IS_OPT( "--version", "-v" ) ) {
3118+ cout << "Zorba NoSQL Query Processor, Version: "
3119+ << zorba::Zorba::version() << endl;
3120+ exit( 1 ); // should be 0, but the old code returned 1
3121+ }
3122+
3123+ ////////// END ////////////////////////////////////////////////////////////
3124+
3125+ else if ( IS_LONG_OPT( "--" ) )
3126+ break;
3127+ else if ( (*argv)[0] == '-' ) {
3128+ cerr << "unknown command line option " << *argv << endl;
3129+ exit( 1 );
3130+ } else {
3131+ zc_props.queries_or_files_.push_back( *argv );
3132+ }
3133+ } // for
3134+
3135+ if ( !error )
3136+ error = check_args();
3137+ if ( error ) {
3138+ cout << "Error: " << error << "\nUse -h for help." << endl;
3139+ exit( 1 );
3140+ }
3141+ return argv - argv_orig;
3142+}
3143+
3144+///////////////////////////////////////////////////////////////////////////////
3145+
3146+/* vim:set et sw=2 ts=2: */
3147
3148=== renamed file 'bin/zorbacmdproperties.cpp' => 'bin/zorbacmd_props.cpp'
3149--- bin/zorbacmdproperties.cpp 2013-06-16 00:37:21 +0000
3150+++ bin/zorbacmd_props.cpp 2014-02-11 00:42:47 +0000
3151@@ -13,202 +13,48 @@
3152 * See the License for the specific language governing permissions and
3153 * limitations under the License.
3154 */
3155-#include "zorbacmdproperties.h"
3156-
3157-#include <fstream>
3158-#include <iostream>
3159-#include <cstdlib>
3160-
3161-#include <zorba/zorba.h>
3162-
3163-std::string ZorbaCMDProperties::check_args () {
3164-
3165- if(queriesOrFilesBegin() == queriesOrFilesEnd())
3166- {
3167- return "No queries submitted \nUsage: zorba -q '1 + 1' execute an inline query \n zorba file.xq execute a query from a file \n Use -h for help.";
3168- }
3169-
3170- if(unknownOption())
3171- {
3172- return "Extra arguments found on command line. Use -h for help.";
3173- }
3174-
3175- if(queriesOrFilesBegin() == queriesOrFilesEnd())
3176- {
3177- return "No queries submitted \nUsage: zorba -q '1 + 1' execute an inline query \n zorba file.xq execute a query from a file \n Use -h for help.";
3178- }
3179-
3180- if ( theBoundarySpace.size() != 0 )
3181- {
3182- if ( ! (theBoundarySpace.compare("strip") == 0 || theBoundarySpace.compare("preserve") == 0 ))
3183- return "Only strip and preserve are allowed as values for the option boundary-space";
3184- }
3185-
3186- if ( theConstructionMode.size() != 0 )
3187- {
3188- if ( ! (theConstructionMode.compare("strip") == 0 || theConstructionMode.compare("preserve") == 0 ))
3189- return "Only strip and preserve are allowed as values for the option construction-mode";
3190- }
3191-
3192- if ( theOrderingMode.size() != 0 ) {
3193- if ( ! (theOrderingMode.compare("ordered") == 0 || theOrderingMode.compare("unordered") == 0 ))
3194- return "Only ordered and unordered are allowed as values for the option ordering-mode";
3195- }
3196-
3197- if ( ! (theOptimizationLevel.compare("O0") == 0 || theOptimizationLevel.compare("O1") == 0
3198- || theOptimizationLevel.compare("O2") == 0 ) )
3199- return "only O0, O1 and O2 are allowed as values for the option opt-level";
3200-
3201- for (std::vector<std::string>::const_iterator lIter = theExternalVariable.begin();
3202- lIter != theExternalVariable.end(); ++lIter)
3203- {
3204- std::string lStr = *lIter;
3205- std::string::size_type lPos = lStr.find_first_of("=");
3206- std::string lVarName = lStr.substr(0, lPos);
3207- std::string lValue = lStr.substr(lPos + 1);
3208- bool lInlineFile = true;
3209- if (lVarName.at(lVarName.size()-1) == ':')
3210- {
3211- lInlineFile = false;
3212- lVarName.resize(lVarName.size()-1); // remove the :
3213- }
3214- ExternalVariable lExternalVariable;
3215- lExternalVariable.var_name = lVarName;
3216- lExternalVariable.var_value = lValue;
3217- lExternalVariable.inline_file = lInlineFile;
3218- theExternalVars.push_back(lExternalVariable);
3219- }
3220-
3221- for (std::vector<std::string>::const_iterator lIter = theOption.begin();
3222- lIter != theOption.end(); ++lIter)
3223- {
3224- size_t lEQual = lIter->find_last_of("=");
3225- if (lEQual == std::string::npos)
3226- return "option must be of the form {namespace}localname=value";
3227-
3228- std::string lClarkQName = lIter->substr(0, lEQual);
3229- std::string lValue = lIter->substr(lEQual + 1);
3230-
3231- StaticContextOption lOption;
3232- lOption.clark_qname = lClarkQName;
3233- lOption.value = lValue;
3234- theStaticContextOptions.push_back(lOption);
3235- }
3236-
3237- for (std::vector<std::string>::const_iterator lIter = theStopWords.begin();
3238- lIter != theStopWords.end(); ++lIter)
3239- {
3240- size_t lEQual = lIter->find(":=");
3241- if (lEQual == std::string::npos)
3242- return "Stop-words mapping must be of the form URI:=value";
3243-
3244- std::string lURI = lIter->substr(0, lEQual);
3245- std::string lValue = lIter->substr(lEQual + 2);
3246-
3247- FullTextMapping lMapping;
3248- lMapping.uri = lURI;
3249- lMapping.value = lValue;
3250- theStopWordsMapping.push_back(lMapping);
3251- }
3252-
3253- for (std::vector<std::string>::const_iterator lIter = theThesaurus.begin();
3254- lIter != theThesaurus.end(); ++lIter)
3255- {
3256- size_t lEQual = lIter->find(":=");
3257- if (lEQual == std::string::npos)
3258- return "Thesaurus mapping must be of the form URI:=value";
3259-
3260- std::string lURI = lIter->substr(0, lEQual);
3261- std::string lValue = lIter->substr(lEQual + 2);
3262-
3263- if ( lURI == "default" )
3264- lURI = "##default";
3265-
3266- FullTextMapping lMapping;
3267- lMapping.uri = lURI;
3268- lMapping.value = lValue;
3269- theThesaurusMapping.push_back(lMapping);
3270- }
3271-
3272- return "";
3273-}
3274-
3275-
3276-bool ZorbaCMDProperties::loadProperties(int argc, char* argv[])
3277-{
3278- std::string result = load_argv(argc, (const char **) argv);
3279-
3280- if (result.empty())
3281- result = check_args();
3282-
3283- if (result == "!HELP")
3284- {
3285- std::cout << "Zorba NoSQL Query Processor, Version: "
3286- << zorba::Zorba::version() << std::endl;
3287- std::cout << "Available options:\n\n";
3288- std::cout << get_help_msg ();
3289- return false;
3290- }
3291- else if (result == "!VER")
3292- {
3293- std::cout << "Zorba NoSQL Query Processor, Version: "
3294- << zorba::Zorba::version() << std::endl;
3295- return false;
3296- }
3297- else if (result.empty ())
3298- {
3299- return true;
3300- }
3301- else if (result [0] != '!')
3302- {
3303- std::cout << "Error: " << result << std::endl;
3304- return false;
3305- }
3306- else
3307- {
3308- return false;
3309- }
3310-}
3311-
3312-
3313-void ZorbaCMDProperties::getModulePath(std::string& aPath) const
3314-{
3315- aPath = theModulePath;
3316-}
3317-
3318-void ZorbaCMDProperties::getURIPath(std::string& aPath) const
3319-{
3320- aPath = theUriPath;
3321-}
3322-
3323-void ZorbaCMDProperties::getLibPath(std::string& aPath) const
3324-{
3325- aPath = theLibPath;
3326-}
3327-
3328-void ZorbaCMDProperties::getJVMClassPath(std::string& aPath) const
3329-{
3330- aPath = theClasspath;
3331-}
3332-
3333-std::vector<std::pair<std::string,std::string> > ZorbaCMDProperties::getSerializerParameters() const
3334-{
3335- std::vector<std::pair<std::string,std::string> > lResult;
3336- std::vector<std::string>::const_iterator lEnd = theSerializationParameter.end();
3337- for (
3338- std::vector<std::string>::const_iterator lIter = theSerializationParameter.begin();
3339- lIter != lEnd;
3340- ++lIter
3341- )
3342- {
3343- std::string lStr = *lIter;
3344- std::string::size_type lPos = lStr.find_first_of("=");
3345- std::string lVarName = lStr.substr(0, lPos);
3346- std::string lValue;
3347- if (lPos != std::string::npos)
3348- lValue = lStr.substr(lPos + 1);
3349-
3350- lResult.push_back(std::pair<std::string,std::string>(lVarName, lValue));
3351- }
3352- return lResult;
3353-}
3354+
3355+// local
3356+#include "zorbacmd_props.h"
3357+
3358+///////////////////////////////////////////////////////////////////////////////
3359+
3360+ZorbaCmdProperties::ZorbaCmdProperties() {
3361+ as_files_ = true;
3362+ byte_order_mark_ = false;
3363+ compile_only_ = false;
3364+#ifdef ZORBA_WITH_DEBUGGER
3365+ debug_ = false;
3366+ debug_host_ = "127.0.0.1";
3367+ debug_port_ = 28028;
3368+#endif /* ZORBA_WITH_DEBUGGER */
3369+ indent_ = false;
3370+ jsoniq_ = false;
3371+ lib_module_ = false;
3372+ load_plan_ = false;
3373+ multiple_ = 1;
3374+ no_logo_ = false;
3375+ no_serializer_ = false;
3376+ omit_xml_declaration_ = false;
3377+ optimization_level_ = 1;
3378+ parse_only_ = false;
3379+ print_errors_as_xml_ = false;
3380+ print_query_ = false;
3381+ save_plan_ = false;
3382+ serialize_html_ = false;
3383+ serialize_only_query_ = false;
3384+ serialize_plan_ = false;
3385+ serialize_text_ = false;
3386+ timeout_ = -1;
3387+ timing_ = false;
3388+ trailing_nl_ = false;
3389+}
3390+
3391+ZorbaCmdProperties& ZorbaCmdProperties::instance() {
3392+ static ZorbaCmdProperties instance;
3393+ return instance;
3394+}
3395+
3396+///////////////////////////////////////////////////////////////////////////////
3397+
3398+/* vim:set et sw=2 ts=2: */
3399
3400=== renamed file 'bin/zorbacmdproperties.h' => 'bin/zorbacmd_props.h'
3401--- bin/zorbacmdproperties.h 2014-01-31 23:27:47 +0000
3402+++ bin/zorbacmd_props.h 2014-02-11 00:42:47 +0000
3403@@ -1,10 +1,10 @@
3404 /*
3405- * Copyright 2006-2008 The FLWOR Foundation.
3406+ * Copyright 2006-2014 The FLWOR Foundation.
3407 *
3408 * Licensed under the Apache License, Version 2.0 (the "License");
3409 * you may not use this file except in compliance with the License.
3410 * You may obtain a copy of the License at
3411- *
3412+ *
3413 * http://www.apache.org/licenses/LICENSE-2.0
3414 *
3415 * Unless required by applicable law or agreed to in writing, software
3416@@ -13,114 +13,108 @@
3417 * See the License for the specific language governing permissions and
3418 * limitations under the License.
3419 */
3420+
3421 #ifndef ZORBA_CMD_PROPERTIES_H
3422 #define ZORBA_CMD_PROPERTIES_H
3423
3424+// standard
3425+#include <string>
3426+#include <vector>
3427+#include <utility> /* for pair */
3428+
3429+// Zorba
3430 #include <zorba/config.h>
3431-#include <zorba/item.h>
3432-
3433-#include "zorbacmdproperties_base.h"
3434-
3435-class ZorbaCMDProperties : public zorbacmd::ZorbaCMDPropertiesBase
3436-{
3437-public:
3438- struct ExternalVariable
3439- {
3440- std::string var_name;
3441- std::string var_value;
3442- bool inline_file;
3443- };
3444-
3445- typedef std::vector<ExternalVariable> ExternalVars_t;
3446-
3447-
3448- struct StaticContextOption
3449- {
3450- std::string clark_qname;
3451- std::string value;
3452- };
3453-
3454- typedef std::vector<StaticContextOption> Options_t;
3455-
3456- struct FullTextMapping
3457- {
3458- std::string uri;
3459- std::string value;
3460- };
3461-
3462- typedef std::vector<FullTextMapping> FullText_t;
3463-
3464- typedef std::vector<std::string> QueriesOrFiles_t;
3465-
3466-protected:
3467- ExternalVars_t theExternalVars;
3468- Options_t theStaticContextOptions;
3469- FullText_t theStopWordsMapping;
3470- FullText_t theThesaurusMapping;
3471-
3472-public:
3473- ExternalVars_t::const_iterator
3474- externalVarsBegin() const { return theExternalVars.begin(); }
3475-
3476- ExternalVars_t::const_iterator
3477- externalVarsEnd() const { return theExternalVars.end(); }
3478-
3479- Options_t::const_iterator
3480- optionsBegin() const { return theStaticContextOptions.begin(); }
3481-
3482- Options_t::const_iterator
3483- optionsEnd() const { return theStaticContextOptions.end(); }
3484-
3485- FullText_t::const_iterator
3486- stopWordsBegin() const { return theStopWordsMapping.begin(); }
3487-
3488- FullText_t::const_iterator
3489- stopWordsEnd() const { return theStopWordsMapping.end(); }
3490-
3491- FullText_t::const_iterator
3492- thesaurusBegin() const { return theThesaurusMapping.begin(); }
3493-
3494- FullText_t::const_iterator
3495- thesaurusEnd() const { return theThesaurusMapping.end(); }
3496-
3497- QueriesOrFiles_t::const_iterator
3498- queriesOrFilesBegin() const { return theQueriesOrFiles.begin(); }
3499-
3500- QueriesOrFiles_t::const_iterator
3501- queriesOrFilesEnd() const { return theQueriesOrFiles.end(); }
3502-
3503- std::vector<std::pair<std::string,std::string> >
3504- getSerializerParameters() const;
3505-
3506- void
3507- getModulePath(std::string&) const;
3508-
3509- void
3510- getURIPath(std::string&) const;
3511-
3512- void
3513- getLibPath(std::string&) const;
3514-
3515- void
3516- getJVMClassPath(std::string&) const;
3517-
3518- bool isDebug(){ return theDebug; }
3519-
3520- bool hasNoLogo(){ return theNoLogo; }
3521-
3522- std::string getDebugHost(){ return theDebugHost; }
3523-
3524- unsigned int getDebugPort(){ return theDebugPort; }
3525-
3526- std::string check_args ();
3527-
3528- void printHelp(std::ostream& os) const {
3529- os << "Zorba NoSQL Query Processor\n";
3530- os << "Available options:\n";
3531- os << get_help_msg ();
3532- }
3533-
3534- bool loadProperties(int argc, char* argv[]);
3535-};
3536+
3537+///////////////////////////////////////////////////////////////////////////////
3538+
3539+struct external_var {
3540+ std::string var_name;
3541+ std::string var_value;
3542+ bool inline_file;
3543+
3544+ external_var() : inline_file( false ) { }
3545+};
3546+
3547+typedef std::vector<external_var> external_vars;
3548+
3549+typedef std::pair<std::string,std::string> serialization_param;
3550+typedef std::vector<serialization_param> serialization_params;
3551+
3552+struct sctx_opt {
3553+ std::string clark_qname;
3554+ std::string value;
3555+};
3556+
3557+typedef std::vector<sctx_opt> sctx_opts;
3558+
3559+#ifndef ZORBA_NO_FULL_TEXT
3560+struct ft_mapping {
3561+ std::string uri;
3562+ std::string value;
3563+};
3564+
3565+typedef std::vector<ft_mapping> ft_mappings;
3566+#endif /* ZORBA_NO_FULL_TEXT */
3567+
3568+struct ZorbaCmdProperties {
3569+ static ZorbaCmdProperties& instance();
3570+
3571+ bool as_files_;
3572+ std::string base_uri_;
3573+ std::string boundary_space_;
3574+ bool byte_order_mark_;
3575+ std::string classpath_;
3576+ bool compile_only_;
3577+ std::string construction_mode_;
3578+ std::string ctx_item_;
3579+#ifdef ZORBA_WITH_DEBUGGER
3580+ bool debug_;
3581+ std::string debug_host_;
3582+ unsigned debug_port_;
3583+#endif /* ZORBA_WITH_DEBUGGER */
3584+ std::string default_collation_;
3585+ external_vars external_vars_;
3586+ bool indent_;
3587+ bool jsoniq_;
3588+ bool lib_module_;
3589+ std::string lib_path_;
3590+ bool load_plan_;
3591+ std::string module_path_;
3592+ unsigned long multiple_;
3593+ bool no_logo_;
3594+ bool no_serializer_;
3595+ bool omit_xml_declaration_;
3596+ unsigned optimization_level_;
3597+ std::string ordering_mode_;
3598+#ifdef ZORBA_WITH_FILE_ACCESS
3599+ std::string output_file_;
3600+#endif /* ZORBA_WITH_FILE_ACCESS */
3601+ bool parse_only_;
3602+ bool print_errors_as_xml_;
3603+ bool print_query_;
3604+ bool save_plan_;
3605+ sctx_opts sctx_opts_;
3606+ bool serialize_html_;
3607+ bool serialize_only_query_;
3608+ bool serialize_plan_;
3609+ bool serialize_text_;
3610+#ifndef ZORBA_NO_FULL_TEXT
3611+ ft_mappings stop_words_mapping_;
3612+ ft_mappings thesaurus_mapping_;
3613+#endif /* ZORBA_NO_FULL_TEXT */
3614+ long timeout_; // unused
3615+ bool timing_;
3616+ bool trailing_nl_;
3617+ std::string uri_path_;
3618+
3619+ serialization_params serialization_params_;
3620+ std::vector<std::string> queries_or_files_;
3621+
3622+private:
3623+ ZorbaCmdProperties();
3624+};
3625+
3626+///////////////////////////////////////////////////////////////////////////////
3627+
3628 #endif /* ZORBA_CMD_PROPERTIES_H */
3629 /* vim:set et sw=2 ts=2: */
3630
3631=== removed file 'bin/zorbacmdproperties.txt'
3632--- bin/zorbacmdproperties.txt 2014-01-31 23:27:47 +0000
3633+++ bin/zorbacmdproperties.txt 1970-01-01 00:00:00 +0000
3634@@ -1,40 +0,0 @@
3635-("as-files,f", "Treat all -q arguments as file paths instead of URIs or inline queries.")
3636-("base-uri", po::value<std::string>(), "Set the base URI property of the static context.")
3637-("boundary-space", po::value<std::string>(), "Set the boundary-space policy ('strip' or 'preserve') in the static context.")
3638-("byte-order-mark", "Set the byte-order-mark for the serializer.")
3639-("classpath", po::value<std::string>(), "JVM classpath to be used by modules using Java implementations")
3640-("compile-only", "Only compile (don't execute)")
3641-("compile-plan,c", "Output the query plan as binary.")
3642-("construction-mode", po::value<std::string>(), "Set the construction mode ('strip' or 'preserve') in the static context.")
3643-("context-item", po::value<std::string> (), "Set the context item to the XML document in a given file.")
3644-("debug,d", "Launch the Zorba debugger server and connect to a DBGP-enabled debugger client.")
3645-("debug-host,h", po::value<std::string>()->default_value("127.0.0.1"), "The host where the DBGP-enabled debugger client listens for connections. Defaults to: 127.0.0.1")
3646-("debug-port,p", po::value<unsigned int>()->default_value (28028), "The port on which the DBGP-enabled debugger client listens for connections. Defaults to: 28028")
3647-("default-collation", po::value<std::string>(), "Add the given collation and set the value of the default collation in the static context to the given collation.")
3648-("execute-plan", "Take a query plan as binary and execute it. Binary query plans can be generated using the --compile-plan option.")
3649-("external-variable,e", po::value<std::vector<std::string> >(), "Provide the value for a variable given a file (name=file) or a value (name:=value)")
3650-("indent,i", "Indent output.")
3651-("lib-module,l", "Query compiler option to treat the query as a library module. If this is set --compile-only option is also set to true.")
3652-("lib-path", po::value<std::string>(), "Library path (list of directories) where Zorba will look for dynamic libraries (e.g., module external function implementations.")
3653-("module-path", po::value<std::string>(), "Path (list of directories) to add to both the URI and Library paths.")
3654-("multiple,m", po::value<unsigned long>()->default_value (1), "Execute the given queries multiple times.")
3655-("no-logo", "Print no logo when starting.")
3656-("no-serializer", "Do not serialize (discard) result.")
3657-("omit-xml-declaration,r", "Omit the XML declaration from the result.")
3658-("optimization-level", po::value<std::string>()->default_value("O1"), "Optimization level for the query compiler (O0, O1 or O2 - default: O1)")
3659-("option", po::value<std::vector<std::string> >(), "Set an XQuery option in the static context. The QName of the option is passed as a string in the notation by James Clark (i.e. {namespace}localname). For example, --option {http://zorba.io/}option=value").
3660-("ordering-mode", po::value<std::string>(), "Set the ordering mode ('ordered' or 'unordered') in the static context.")
3661-("output-file,o", po::value<std::string>(), "Write the result to the given file.")
3662-("parse-only", "Stop after parsing the query.")
3663-("print-errors-as-xml,x", "Print the errors as XML.")
3664-("print-query", "Print the queries.")
3665-("query,q", po::value<std::vector<std::string> >(&theQueriesOrFiles), "Query test or file URI (file://...)")
3666-("serialization-parameter,z", po::value<std::vector<std::string> >(), "Set serialization parameter in the form of a parameter=value pair (see http://www.w3.org/TR/xslt-xquery-serialization/#serparam, e.g.: -z method=xhtml -z doctype-system=DTD/xhtml1-strict.dtd -z indent=yes).")
3667-("serialize-html", "Serialize the result as HTML.")
3668-("serialize-text", "Serialize the result as Text.")
3669-("stop-words", po::value<std::vector<std::string> >(), "Mapping specifying a stop-words URI to another.")
3670-("thesaurus", po::value<std::vector<std::string> >(), "Mapping specifying a thesaurus URI to another.")
3671-("timeout", po::value<long>()->default_value(-1), "Specify a timeout in seconds. After the specified time, the execution of the query will be aborted.")
3672-("timing,t", "Print timing information. In case of multiple queries the timing information is provided per each query. Both wallclock time and user time (which excludes I/O, network delays and other kernel waits) are shown.")
3673-("trailing-nl", "Output a trailing newline after the result of the query.")
3674-("uri-path", po::value<std::string>(), "URI path (list of directories) added to the built-in URI resolver, i.e. where to find modules/schemas to import.")
3675
3676=== removed file 'bin/zorbacmdproperties_base.cpp'
3677--- bin/zorbacmdproperties_base.cpp 2014-01-31 23:33:01 +0000
3678+++ bin/zorbacmdproperties_base.cpp 1970-01-01 00:00:00 +0000
3679@@ -1,374 +0,0 @@
3680-/*
3681- * Copyright 2006-2008 The FLWOR Foundation.
3682- *
3683- * Licensed under the Apache License, Version 2.0 (the "License");
3684- * you may not use this file except in compliance with the License.
3685- * You may obtain a copy of the License at
3686- *
3687- * http://www.apache.org/licenses/LICENSE-2.0
3688- *
3689- * Unless required by applicable law or agreed to in writing, software
3690- * distributed under the License is distributed on an "AS IS" BASIS,
3691- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3692- * See the License for the specific language governing permissions and
3693- * limitations under the License.
3694- */
3695-
3696-#include "zorbacmdproperties_base.h"
3697-
3698-namespace zorbacmd {
3699-
3700-///////////////////////////////////////////////////////////////////////////////
3701-
3702-ZorbaCMDPropertiesBase::ZorbaCMDPropertiesBase() {
3703- theAsFiles = true;
3704- theByteOrderMark = false;
3705- theCompileOnly = false;
3706- theDebug = false;
3707- theDebugHost = "127.0.0.1";
3708- theDebugPort = 28028;
3709- theFparm = false;
3710- theIndent = false;
3711- theLibModule = false;
3712- theLoadPlan = false;
3713- theMultiple = 1;
3714- theNoLogo = false;
3715- theNoSerializer = false;
3716- theOmitXmlDeclaration = false;
3717- theOptimizationLevel = "O1";
3718- theParseOnly = false;
3719- thePrintErrorsAsXml = false;
3720- thePrintQuery = false;
3721- theQBeforeF = false;
3722- theSavePlan = false;
3723- theSerializeHtml = false;
3724- theSerializePlan = false;
3725- theSerializeText = false;
3726- theTimeout = -1;
3727- theTiming = false;
3728- theTrailingNl = false;
3729- theUnknownOption = false;
3730-}
3731-
3732-char const** ZorbaCMDPropertiesBase::get_all_options() const {
3733- static const char* result [] = {
3734- "--as-files",
3735- "--base-uri",
3736- "--boundary-space",
3737- "--byte-order-mark",
3738- "--classpath",
3739- "--compile-only",
3740- "--compile-plan",
3741- "--construction-mode",
3742- "--context-item",
3743- "--debug",
3744- "--debug-host",
3745- "--debug-port",
3746- "--default-collation",
3747- "--disable-http-resolution",
3748- "--execute-plan",
3749- "--external-variable",
3750- "--indent",
3751- "--lib-module",
3752- "--lib-path",
3753- "--module-path",
3754- "--multiple",
3755- "--no-logo",
3756- "--no-serializer",
3757- "--omit-xml-declaration",
3758- "--optimization-level",
3759- "--option",
3760- "--ordering-mode",
3761-#ifdef ZORBA_WITH_FILE_ACCESS
3762- "--output-file",
3763-#endif /* ZORBA_WITH_FILE_ACCESS */
3764- "--parse-only",
3765- "--print-errors-as-xml",
3766- "--print-query",
3767- "--query",
3768- "--serialization-parameter",
3769- "--serialize-html",
3770- "--serialize-plan",
3771- "--serialize-text",
3772- "--stop-words",
3773- "--thesaurus",
3774- "--timeout",
3775- "--timing",
3776- "--trailing-nl",
3777- "--uri-path",
3778- NULL
3779- };
3780- return result;
3781-}
3782-
3783-#define IS_LONG_OPT(OPT) (strcmp( *argv, (OPT) ) == 0)
3784-#define IS_SHORT_OPT(OPT) (strncmp( *argv, (OPT), 2 ) == 0)
3785-#define IS_OPT(LOPT,SOPT) (IS_LONG_OPT(LOPT) || IS_SHORT_OPT(SOPT))
3786-
3787-std::string ZorbaCMDPropertiesBase::load_argv(int argc, const char **argv) {
3788- if ( !argv )
3789- return "";
3790-
3791- std::string result;
3792- for ( ++argv; *argv; ++argv ) {
3793- if ( IS_OPT( "--help", "-h" ) )
3794- return "!HELP";
3795- if ( IS_OPT( "--version", "-v" ) )
3796- return "!VER";
3797-
3798- if ( IS_OPT( "--as-files", "-f" ) ) {
3799- theFparm = true;
3800- theAsFiles = true;
3801- }
3802- else if ( IS_LONG_OPT( "--base-uri" ) ) {
3803- int d = 2;
3804- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3805- if (!*argv) { result = "No value given for --base-uri option"; break; }
3806- init_val(*argv, theBaseUri, d);
3807- }
3808- else if ( IS_LONG_OPT( "--boundary-space" ) ) {
3809- int d = 2;
3810- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3811- if (!*argv) { result = "No value given for --boundary-space option"; break; }
3812- init_val(*argv, theBoundarySpace, d);
3813- }
3814- else if ( IS_LONG_OPT( "--byte-order-mark" ) )
3815- theByteOrderMark = true;
3816- else if ( IS_LONG_OPT( "--classpath" ) ) {
3817- int d = 2;
3818- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3819- if (!*argv) { result = "No value given for --classpath option"; break; }
3820- init_val(*argv, theClasspath, d);
3821- }
3822- else if ( IS_LONG_OPT( "--compile-only" ) )
3823- theCompileOnly = true;
3824- else if ( IS_LONG_OPT( "--compile-plan" ) )
3825- theSavePlan = true;
3826- else if ( IS_LONG_OPT( "--construction-mode" ) ) {
3827- int d = 2;
3828- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3829- if (!*argv) { result = "No value given for --construction-mode option"; break; }
3830- init_val(*argv, theConstructionMode, d);
3831- }
3832- else if ( IS_LONG_OPT( "--context-item" ) ) {
3833- int d = 2;
3834- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3835- if (!*argv) { result = "No value given for --context-item option"; break; }
3836- init_val(*argv, theContextItem, d);
3837- }
3838- else if ( IS_OPT( "--debug", "-d" ) )
3839- theDebug = true;
3840- else if ( IS_OPT( "--debug-host", "-h" ) ) {
3841- int d = 2;
3842- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3843- if (!*argv) { result = "No value given for --debug-host option"; break; }
3844- init_val(*argv, theDebugHost, d);
3845- }
3846- else if ( IS_OPT( "--debug-port", "-p" ) ) {
3847- int d = 2;
3848- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3849- if (!*argv) { result = "No value given for --debug-port option"; break; }
3850- init_val(*argv, theDebugPort, d);
3851- }
3852- else if ( IS_LONG_OPT( "--default-collation" ) ) {
3853- int d = 2;
3854- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3855- if (!*argv) { result = "No value given for --default-collation option"; break; }
3856- init_val(*argv, theDefaultCollation, d);
3857- }
3858- else if ( IS_LONG_OPT( "--execute-plan" ) )
3859- theLoadPlan = true;
3860- else if ( IS_OPT( "--external-variable", "-e" ) ) {
3861- int d = 2;
3862- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3863- if (!*argv) { result = "No value given for --external-variable option"; break; }
3864- init_val(*argv, theExternalVariable, d);
3865- }
3866- else if ( IS_OPT( "--indent", "-i" ) )
3867- theIndent = true;
3868- else if ( IS_OPT( "--lib-module", "-l" ) )
3869- theLibModule = true;
3870- else if ( IS_LONG_OPT( "--lib-path" ) ) {
3871- int d = 2;
3872- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3873- if (!*argv) { result = "No value given for --lib-path option"; break; }
3874- init_val(*argv, theLibPath, d);
3875- }
3876- else if ( IS_LONG_OPT( "--module-path" ) ) {
3877- int d = 2;
3878- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3879- if (!*argv) { result = "No value given for --module-path option"; break; }
3880- init_val(*argv, theModulePath, d);
3881- }
3882- else if ( IS_LONG_OPT( "--no-logo" ) )
3883- theNoLogo = true;
3884- else if ( IS_LONG_OPT( "--no-serializer" ) )
3885- theNoSerializer = true;
3886- else if ( IS_OPT( "--multiple", "-m" ) ) {
3887- int d = 2;
3888- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3889- if (!*argv) { result = "No value given for --multiple option"; break; }
3890- init_val(*argv, theMultiple, d);
3891- }
3892- else if ( IS_OPT( "--omit-xml-declaration", "-r" ) )
3893- theOmitXmlDeclaration = true;
3894- else if ( IS_LONG_OPT( "--optimization-level" ) ) {
3895- int d = 2;
3896- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3897- if (!*argv) { result = "No value given for --optimization-level option"; break; }
3898- init_val(*argv, theOptimizationLevel, d);
3899- }
3900- else if ( IS_LONG_OPT( "--option" ) ) {
3901- int d = 2;
3902- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3903- if (!*argv) { result = "No value given for --option option"; break; }
3904- init_val(*argv, theOption, d);
3905- }
3906- else if ( IS_LONG_OPT( "--ordering-mode" ) ) {
3907- int d = 2;
3908- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3909- if (!*argv) { result = "No value given for --ordering-mode option"; break; }
3910- init_val(*argv, theOrderingMode, d);
3911- }
3912-#ifdef ZORBA_WITH_FILE_ACCESS
3913- else if ( IS_OPT( "--output-file", "-o" ) ) {
3914- int d = 2;
3915- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3916- if (!*argv) { result = "No value given for --output-file option"; break; }
3917- init_val(*argv, theOutputFile, d);
3918- }
3919-#endif /* ZORBA_WITH_FILE_ACCESS */
3920- else if ( IS_LONG_OPT( "--parse-only" ) )
3921- theParseOnly = true;
3922- else if ( IS_OPT( "--print-errors-as-xml", "-x" ) )
3923- thePrintErrorsAsXml = true;
3924- else if ( IS_LONG_OPT( "--print-query" ) )
3925- thePrintQuery = true;
3926- else if ( IS_OPT( "--query", "-q" ) ) {
3927- int d = 2;
3928- if(theFparm == false)
3929- theAsFiles = false;
3930- if(*(argv+1) && !strncmp(*(argv+1), "-f", 2))
3931- {
3932- theQBeforeF = true; // is it "-q -f <filename>" perhaps?
3933- break; // stop functionality here
3934- }
3935- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3936- if (!*argv) { result = "No value given for --query option"; break; }
3937- init_val(*argv, theQueriesOrFiles, d);
3938- }
3939- else if ( IS_LONG_OPT( "--serialize-html" ) )
3940- theSerializeHtml = true;
3941- else if ( IS_LONG_OPT( "--serialize-text" ) )
3942- theSerializeText = true;
3943- else if ( IS_OPT( "--serialization-parameter", "-z" ) ) {
3944- int d = 2;
3945- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3946- if (!*argv) { result = "No value given for --serialization-parameter option"; break; }
3947- init_val(*argv, theSerializationParameter, d);
3948- }
3949- else if ( IS_LONG_OPT( "--stop-words" ) ) {
3950- int d = 2;
3951- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3952- if (!*argv) { result = "No value given for --stop-words option"; break; }
3953- init_val(*argv, theStopWords, d);
3954- }
3955- else if ( IS_OPT( "--timing", "-t" ) )
3956- theTiming = true;
3957- else if ( IS_LONG_OPT( "--timeout" ) ) {
3958- int d = 2;
3959- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3960- if (!*argv) { result = "No value given for --timeout option"; break; }
3961- init_val(*argv, theTimeout, d);
3962- }
3963- else if ( IS_LONG_OPT( "--trailing-nl" ) )
3964- theTrailingNl = true;
3965- else if ( IS_LONG_OPT( "--uri-path" ) ) {
3966- int d = 2;
3967- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3968- if (!*argv) { result = "No value given for --uri-path option"; break; }
3969- init_val(*argv, theUriPath, d);
3970- }
3971- else if ( IS_OPT( "--serialize-plan", "-s" ) )
3972- theSerializePlan = true;
3973- else if ( IS_LONG_OPT( "--disable-http-resolution" ) ) {
3974- init_val("{http://zorba.io/options/features}disable=http-uri-resolution",
3975- theOption, 0);
3976- }
3977- else if ( IS_LONG_OPT( "--thesaurus" ) ) {
3978- int d = 2;
3979- if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
3980- if (!*argv) { result = "No value given for --thesaurus option"; break; }
3981- init_val(*argv, theThesaurus, d);
3982- }
3983-
3984- else if ( IS_LONG_OPT( "--" ) ) {
3985- copy_args (++argv);
3986- break;
3987- } else if ( (*argv)[0] == '-' ) {
3988- result = "unknown command line option "; result += *argv;
3989- theUnknownOption = true; break;
3990- } else {
3991- init_val(*argv, theQueriesOrFiles, 0);
3992- copy_args( argv );
3993- }
3994- } // for
3995- return result;
3996-}
3997-
3998-char const* ZorbaCMDPropertiesBase::get_help_msg() const {
3999- return
4000- "--as-files, -f\nTreat all -q arguments as file paths instead of URIs or inline queries. This option is deprecated and will be defaulted to true in the future, so any entry in the command line is going to be treated as files.\n\n"
4001- "--base-uri\nSet the base URI property of the static context.\n\n"
4002- "--boundary-space\nSet the boundary-space policy ('strip' or 'preserve') in the static context.\n\n"
4003- "--byte-order-mark\nSet the byte-order-mark for the serializer.\n\n"
4004- "--classpath\nJVM classpath to be used by modules using Java implementations\n\n"
4005- "--compile-only\nOnly compile (don't execute)\n\n"
4006- "--compile-plan,\nDo not execute the query; just compile it and save the execution plan in the file specified with the -o option.\n\n"
4007- "--construction-mode\nSet the construction mode ('strip' or 'preserve') in the static context.\n\n"
4008- "--context-item\nSet the context item to the XML document in a given file.\n\n"
4009- "--debug, -d\nLaunch the Zorba debugger server and connect to a DBGP-enabled debugger client.\n\n"
4010- "--debug-host, -h\nThe host where the DBGP-enabled debugger client listens for connections. Defaults to: 127.0.0.1\n\n"
4011- "--debug-port, -p\nThe port on which the DBGP-enabled debugger client listens for connections. Defaults to: 28028\n\n"
4012- "--default-collation\nAdd the given collation and set the value of the default collation in the static context to the given collation.\n\n"
4013- "--disable-http-resolution\nDo not use HTTP to resolve URIs\n\n"
4014- "--execute-plan\nDo not compile the query; instead load the execution plan from the file specified by the -f -q options (or by any file specified without any other argument), and execute the loaded plan.\n\n"
4015- "--external-variable, -e\nProvide the value for a variable given a file (name=file) or a value (name:=value)\n\n"
4016- "--indent, -i\nIndent output.\n\n"
4017- "--lib-module, -l\nQuery compiler option to treat the query as a library module. If this is set --compile-only option is also set to true.\n\n"
4018- "--lib-path\nLibrary path (list of directories) where Zorba will look for dynamic libraries (e.g., module external function implementations.\n\n"
4019- "--module-path\nPath (list of directories) to add to both the URI and Library paths.\n\n"
4020- "--multiple, -m\nExecute the given queries multiple times.\n\n"
4021- "--no-logo\nPrint no logo when starting.\n\n"
4022- "--no-serializer\nDo not serialize (discard) result.\n\n"
4023- "--omit-xml-declaration, -r\nOmit the XML declaration from the result.\n\n"
4024- "--optimization-level\nOptimization level for the query compiler (O0, O1 or O2 - default: O1)\n\n"
4025- "--option\nSet an XQuery option in the static context. The QName of the option is passed as a string in the notation by James Clark (i.e. {namespace}localname). For example, --option {http://zorba.io/}option=value\n\n"
4026- "--ordering-mode\nSet the ordering mode ('ordered' or 'unordered') in the static context.\n\n"
4027- "--output-file, -o\nWrite the result to the given file.\n\n"
4028- "--parse-only\nStop after parsing the query.\n\n"
4029- "--print-errors-as-xml, -x\nPrint the errors as XML.\n\n"
4030- "--print-query\nPrint the queries.\n\n"
4031- "--query, -q\nQuery test or file URI (file://...)\n\n"
4032- "--serialization-parameter, -z\nSet serialization parameter in the form of a parameter=value pair (see http://www.w3.org/TR/xslt-xquery-serialization/#serparam, e.g.: -z method=xhtml -z doctype-system=DTD/xhtml1-strict.dtd -z indent=yes).\n\n"
4033- "--serialize-html\nSerialize the result as HTML.\n\n"
4034- "--serialize-plan, -s\nSerialize and then load the query execution plan.\n\n"
4035- "--serialize-text\nSerialize the result as Text.\n\n"
4036- "--stop-words\nMapping specifying a stop-words URI to another.\n\n"
4037- "--thesaurus\nMapping specifying a thesaurus URI to another.\n\n"
4038- "--timeout\nSpecify a timeout in seconds. After the specified time, the execution of the query will be aborted.\n\n"
4039- "--timing, -t\nPrint timing information. In case of multiple queries the timing information is provided per each query. Both wallclock time and user time (which excludes I/O, network delays and other kernel waits) are shown.\n\n"
4040- "--trailing-nl\nOutput a trailing newline after the result of the query.\n\n"
4041- "--uri-path\nURI path (list of directories) added to the built-in URI resolver, i.e. where to find modules/schemas to import.\n\n"
4042- ;
4043-}
4044-
4045-ZorbaCMDPropertiesBase const* ZorbaCMDPropertiesBase::instance() {
4046- static ZorbaCMDPropertiesBase result;
4047- return &result;
4048-}
4049-
4050-///////////////////////////////////////////////////////////////////////////////
4051-
4052-} // namespace zorbacmd
4053-/* vim:set et sw=2 ts=2: */
4054
4055=== removed file 'bin/zorbacmdproperties_base.h'
4056--- bin/zorbacmdproperties_base.h 2014-01-31 23:27:47 +0000
4057+++ bin/zorbacmdproperties_base.h 1970-01-01 00:00:00 +0000
4058@@ -1,142 +0,0 @@
4059-/*
4060- * Copyright 2006-2008 The FLWOR Foundation.
4061- *
4062- * Licensed under the Apache License, Version 2.0 (the "License");
4063- * you may not use this file except in compliance with the License.
4064- * You may obtain a copy of the License at
4065- *
4066- * http://www.apache.org/licenses/LICENSE-2.0
4067- *
4068- * Unless required by applicable law or agreed to in writing, software
4069- * distributed under the License is distributed on an "AS IS" BASIS,
4070- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4071- * See the License for the specific language governing permissions and
4072- * limitations under the License.
4073- */
4074-
4075-#include <string>
4076-#include <sstream>
4077-#include <zorba/config.h>
4078-#include <zorba/properties_base.h>
4079-#include <cstring>
4080-
4081-#ifndef ZORBACMD_ZORBACMDPROPERTIESBASE
4082-#define ZORBACMD_ZORBACMDPROPERTIESBASE
4083-namespace zorbacmd {
4084-
4085-///////////////////////////////////////////////////////////////////////////////
4086-
4087-class ZorbaCMDPropertiesBase : public ::zorba::PropertiesBase {
4088-protected:
4089- bool theTiming;
4090-#ifdef ZORBA_WITH_FILE_ACCESS
4091- std::string theOutputFile;
4092-#endif /* ZORBA_WITH_FILE_ACCESS */
4093- std::vector<std::string> theSerializationParameter;
4094- bool theSerializeHtml;
4095- bool theSerializeText;
4096- bool theIndent;
4097- bool thePrintQuery;
4098- bool thePrintErrorsAsXml;
4099- bool theByteOrderMark;
4100- bool theOmitXmlDeclaration;
4101- std::string theBaseUri;
4102- std::string theBoundarySpace;
4103- std::string theDefaultCollation;
4104- std::string theConstructionMode;
4105- std::string theOrderingMode;
4106- unsigned long theMultiple;
4107- std::vector<std::string> theQueriesOrFiles;
4108- bool theAsFiles;
4109- std::vector<std::string> theExternalVariable;
4110- std::string theContextItem;
4111- std::string theOptimizationLevel;
4112- bool theLibModule;
4113- bool theParseOnly;
4114- bool theCompileOnly;
4115- bool theNoSerializer;
4116- bool theDebug;
4117- std::string theDebugHost;
4118- unsigned int theDebugPort;
4119- bool theNoLogo;
4120- long theTimeout;
4121- std::string theUriPath;
4122- std::string theLibPath;
4123- std::string theModulePath;
4124- std::string theClasspath;
4125- std::vector<std::string> theOption;
4126- bool theTrailingNl;
4127- std::vector<std::string> theStopWords;
4128- std::vector<std::string> theThesaurus;
4129- bool theSerializePlan;
4130- bool theSavePlan;
4131- bool theLoadPlan;
4132- bool theFparm;
4133- bool theQBeforeF;
4134- bool theUnknownOption;
4135-
4136- // inherited
4137- const char** get_all_options() const;
4138-
4139-public:
4140- ZorbaCMDPropertiesBase();
4141-
4142- bool timing () const { return theTiming; }
4143-#ifdef ZORBA_WITH_FILE_ACCESS
4144- const std::string &outputFile () const { return theOutputFile; }
4145-#endif /* ZORBA_WITH_FILE_ACCESS */
4146- const std::vector<std::string> &serializationParameter () const { return theSerializationParameter; }
4147- bool serializeHtml () const { return theSerializeHtml; }
4148- bool serializeText () const { return theSerializeText; }
4149- bool indent () const { return theIndent; }
4150- bool printQuery () const { return thePrintQuery; }
4151- bool printErrorsAsXml () const { return thePrintErrorsAsXml; }
4152- bool byteOrderMark () const { return theByteOrderMark; }
4153- bool omitXmlDeclaration () const { return theOmitXmlDeclaration; }
4154- const std::string &baseUri () const { return theBaseUri; }
4155- const std::string &boundarySpace () const { return theBoundarySpace; }
4156- const std::string &defaultCollation () const { return theDefaultCollation; }
4157- const std::string &constructionMode () const { return theConstructionMode; }
4158- const std::string &orderingMode () const { return theOrderingMode; }
4159- unsigned long multiple () const { return theMultiple; }
4160- const std::vector<std::string> &query () const { return theQueriesOrFiles; }
4161- bool asFiles () const { return theAsFiles; }
4162- const std::vector<std::string> &externalVariable () const { return theExternalVariable; }
4163- const std::string &contextItem () const { return theContextItem; }
4164- const std::string &optimizationLevel () const { return theOptimizationLevel; }
4165- bool libModule () const { return theLibModule; }
4166- bool parseOnly () const { return theParseOnly; }
4167- bool compileOnly () const { return theCompileOnly; }
4168- bool noSerializer () const { return theNoSerializer; }
4169- bool debug () const { return theDebug; }
4170- const std::string &debugHost () const { return theDebugHost; }
4171- unsigned debugPort () const { return theDebugPort; }
4172- bool noLogo () const { return theNoLogo; }
4173- const long &timeout () const { return theTimeout; }
4174- const std::string &uriPath () const { return theUriPath; }
4175- const std::string &libPath () const { return theLibPath; }
4176- const std::string &modulePath () const { return theModulePath; }
4177- const std::string &classpath () const { return theClasspath; }
4178- const std::vector<std::string> &option () const { return theOption; }
4179- bool trailingNl () const { return theTrailingNl; }
4180- const std::vector<std::string> &stopWords () const { return theStopWords; }
4181- const std::vector<std::string> &thesaurus () const { return theThesaurus; }
4182- bool serializePlan () const { return theSerializePlan; }
4183- bool loadPlan () const { return theLoadPlan; }
4184- bool savePlan () const { return theSavePlan; }
4185- bool qBeforeF () const { return theQBeforeF; }
4186- bool unknownOption() const { return theUnknownOption; }
4187-
4188- std::string load_argv(int argc, const char **argv);
4189-
4190- const char* get_help_msg() const;
4191-
4192- static const ZorbaCMDPropertiesBase* instance();
4193-};
4194-
4195-///////////////////////////////////////////////////////////////////////////////
4196-
4197-} // namespace zorbacmd
4198-
4199-#endif /* ZORBACMD_ZORBACMDPROPERTIESBASE */
4200-/* vim:set et sw=2 ts=2: */
4201
4202=== added file 'include/zorba/properties.h'
4203--- include/zorba/properties.h 1970-01-01 00:00:00 +0000
4204+++ include/zorba/properties.h 2014-02-11 00:42:47 +0000
4205@@ -0,0 +1,400 @@
4206+/*
4207+ * Copyright 2006-2008 The FLWOR Foundation.
4208+ *
4209+ * Licensed under the Apache License, Version 2.0 (the "License");
4210+ * you may not use this file except in compliance with the License.
4211+ * You may obtain a copy of the License at
4212+ *
4213+ * http://www.apache.org/licenses/LICENSE-2.0
4214+ *
4215+ * Unless required by applicable law or agreed to in writing, software
4216+ * distributed under the License is distributed on an "AS IS" BASIS,
4217+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4218+ * See the License for the specific language governing permissions and
4219+ * limitations under the License.
4220+ */
4221+#ifndef ZORBA_PROPERTIES_BASE_H
4222+#define ZORBA_PROPERTIES_BASE_H
4223+
4224+// standard
4225+#include <iostream>
4226+#include <sstream>
4227+#include <string>
4228+#include <vector>
4229+
4230+// Zorba
4231+#include <zorba/config.h>
4232+#include <zorba/internal/ztd.h>
4233+#include <zorba/internal/type_traits.h>
4234+#include <zorba/internal/unique_ptr.h>
4235+
4236+namespace zorba {
4237+
4238+///////////////////////////////////////////////////////////////////////////////
4239+
4240+/**
4241+ * \brief This class provides access to global properties.
4242+ *
4243+ * This class provides access to global properties set for Zorba in environment
4244+ * and configuration file.
4245+ */
4246+class ZORBA_DLL_PUBLIC Properties {
4247+public:
4248+ /**
4249+ * Gets the singleton instance.
4250+ *
4251+ * @return Returns said instance.
4252+ */
4253+ static Properties& instance();
4254+
4255+#ifndef NDEBUG
4256+ /**
4257+ * Gets whether abort(3) will be called when a ZorbaException is thrown.
4258+ * (This is a developer debugging aid.)
4259+ */
4260+ bool getAbort() const {
4261+ return abort_;
4262+ }
4263+
4264+ /**
4265+ * Sets whether abort(3) will be called when a ZorbaException is thrown.
4266+ * (This is a developer debugging aid.)
4267+ *
4268+ * @param abort If \c true, call abort(3) when a ZorbaException is thrown.
4269+ */
4270+ void setAbort( bool abort ) {
4271+ abort_ = abort;
4272+ }
4273+#endif /* NDEBUG */
4274+
4275+ /**
4276+ * Gets the stream used for additional developer debugging output.
4277+ * (This has nothing to do with the Zorba debugger.)
4278+ *
4279+ * @return Returns said stream; default: standard output.
4280+ */
4281+ std::ostream& getDebugStream() const {
4282+ return *debug_stream_.get();
4283+ }
4284+
4285+ /**
4286+ * Sets the file to use for additional developer debugging output.
4287+ * (This has nothing to do with the Zorba debugger.)
4288+ *
4289+ * @param file The path to the file to use.
4290+ */
4291+ void setDebugFile( char const *file );
4292+
4293+ /**
4294+ * Sets the file to use for additional developer debugging output.
4295+ * (This has nothing to do with the Zorba debugger.)
4296+ *
4297+ * @tparam StringType The string type.
4298+ * @param file The path to the file to use.
4299+ */
4300+ template<class StringType>
4301+ typename std::enable_if<ZORBA_HAS_C_STR(StringType),void>::type
4302+ setDebugFile( StringType const &file ) {
4303+ setDebugFile( file.c_str() );
4304+ }
4305+
4306+ /**
4307+ * Sets the stream to use for additional developer debugging output.
4308+ * (This has nothing to do with the Zorba debugger.)
4309+ *
4310+ * @param stream The stream to use.
4311+ * @param take_ownership If \c true, \a stream will be deleted when Zorba
4312+ * shuts down.
4313+ */
4314+ void setDebugStream( std::ostream &os, bool take_ownership = false );
4315+
4316+ bool getDumpLib() const {
4317+ return dump_lib_;
4318+ }
4319+
4320+ void setDumpLib( bool b ) {
4321+ dump_lib_ = b;
4322+ }
4323+
4324+ bool getForceGFLWOR() const {
4325+ return force_gflwor_;
4326+ }
4327+
4328+ void setForceGFLWOR( bool b ) {
4329+ force_gflwor_ = b;
4330+ }
4331+
4332+ bool getInferJoins() const {
4333+ return infer_joins_;
4334+ }
4335+
4336+ void setInferJoins( bool b ) {
4337+ infer_joins_ = b;
4338+ }
4339+
4340+ bool getInlineUDF() const {
4341+ return inline_udf_;
4342+ }
4343+
4344+ void setInlineUDF( bool b ) {
4345+ inline_udf_ = b;
4346+ }
4347+
4348+ std::string const& getClassPath() const {
4349+ return classpath_;
4350+ }
4351+
4352+ void setClassPath( char const *classpath ) {
4353+ classpath_ = classpath;
4354+ }
4355+
4356+ template<class StringType>
4357+ typename std::enable_if<ZORBA_HAS_C_STR(StringType),void>::type
4358+ setClassPath( StringType const &classpath ) {
4359+ setClassPath( classpath.c_str() );
4360+ }
4361+
4362+ /**
4363+ * \brief Get global JVM classpath property.
4364+ *
4365+ * Before the JVM is started this will return the classpath set by
4366+ * command line option, the CLASSPATH environment variable and in Zorba
4367+ * config file.
4368+ *
4369+ * After the JVM is started this will contain in addition the paths to jars
4370+ * used by modules that make use of the JVM.
4371+ *
4372+ * @deprecated Use getClassPath().
4373+ */
4374+ void getJVMClassPath( std::string &jvmClasspath ) const {
4375+ jvmClasspath = getClassPath();
4376+ }
4377+
4378+ /**
4379+ * \brief Set global JVM classpath property.
4380+ *
4381+ * This method should be used to set additional JVM classpath for modules
4382+ * that make use of JVM. This will overide the classpath set by CLASSPATH
4383+ * environment variable or Zorba config file.
4384+ *
4385+ * Once the JVM is started this method doesn't have any effect.
4386+ *
4387+ * @deprecated Use setClassPath().
4388+ */
4389+ void setJVMClassPath( std::string const &jvmClasspath ) {
4390+ setClassPath( jvmClasspath );
4391+ }
4392+
4393+ bool getLoopHoisting() const {
4394+ return loop_hoisting_;
4395+ }
4396+
4397+ void setLoopHoisting( bool b ) {
4398+ loop_hoisting_ = b;
4399+ }
4400+
4401+ uint32_t getMaxUDFCallDepth() const {
4402+ return max_udf_call_depth_;
4403+ }
4404+
4405+ void setMaxUDFCallDepth( uint32_t u ) {
4406+ max_udf_call_depth_ = u;
4407+ }
4408+
4409+ bool getNoCopyOptim() const {
4410+ return no_copy_optim_;
4411+ }
4412+
4413+ void setNoCopyOptim( bool b ) {
4414+ no_copy_optim_ = b;
4415+ }
4416+
4417+ bool getNoTreeIDs() const {
4418+ return no_tree_ids_;
4419+ }
4420+
4421+ void setNoTreeIDs( bool b ) {
4422+ no_tree_ids_ = b;
4423+ }
4424+
4425+ unsigned getOptimizationLevel() const {
4426+ return optimization_level_;
4427+ }
4428+
4429+ void setOptimizationLevel( unsigned optimization_level );
4430+
4431+ bool getPrintAST() const {
4432+ return print_ast_;
4433+ }
4434+
4435+ void setPrintAST( bool b ) {
4436+ print_ast_ = b;
4437+ }
4438+
4439+ bool getPrintIntermediateOpt() const {
4440+ return print_intermediate_opt_;
4441+ }
4442+
4443+ void setPrintIntermediateOpt( bool b ) {
4444+ print_intermediate_opt_ = b;
4445+ }
4446+
4447+ bool getPrintItemFlow() const {
4448+ return print_item_flow_;
4449+ }
4450+
4451+ void setPrintItemFlow( bool b ) {
4452+ print_item_flow_ = b ;
4453+ }
4454+
4455+ bool getPrintIteratorTree() const {
4456+ return print_iterator_locations_;
4457+ }
4458+
4459+ void setPrintIteratorTree( bool b ) {
4460+ print_iterator_locations_ = b;
4461+ }
4462+
4463+ bool getPrintLocations() const {
4464+ return print_locations_;
4465+ }
4466+
4467+ void setPrintLocations( bool b ) {
4468+ print_locations_ = b;
4469+ }
4470+
4471+ bool getPrintOptimized() const {
4472+ return print_optimized_;
4473+ }
4474+
4475+ void setPrintOptimized( bool b ) {
4476+ print_optimized_ = b;
4477+ }
4478+
4479+ bool getPrintStaticTypes() const {
4480+ return print_static_types_;
4481+ }
4482+
4483+ void setPrintStaticTypes( bool b ) {
4484+ print_static_types_ = b;
4485+ }
4486+
4487+ bool getPrintTranslated() const {
4488+ return print_translated_;
4489+ }
4490+
4491+ void setPrintTranslated( bool b ) {
4492+ print_translated_ = b;
4493+ }
4494+
4495+ bool getStableIteratorIDs() const {
4496+ return stable_iterator_ids_;
4497+ }
4498+
4499+ void setStableIteratorIDs( bool b ) {
4500+ stable_iterator_ids_ = b;
4501+ }
4502+
4503+ bool getTraceCodegen() const {
4504+ return trace_codegen_;
4505+ }
4506+
4507+ void setTraceCodegen( bool b ) {
4508+ trace_codegen_ = b;
4509+ }
4510+
4511+#ifndef ZORBA_NO_FULL_TEXT
4512+ bool getTraceFulltext() const {
4513+ return trace_fulltext_;
4514+ }
4515+
4516+ void setTraceFulltext( bool b ) {
4517+ trace_fulltext_ = b;
4518+ }
4519+#endif /* ZORBA_NO_FULL_TEXT */
4520+
4521+ bool getTraceParsing() const {
4522+ return trace_parsing_;
4523+ }
4524+
4525+ void setTraceParsing( bool b ) {
4526+ trace_parsing_ = b;
4527+ }
4528+
4529+ bool getTraceScanning() const {
4530+ return trace_scanning_;
4531+ }
4532+
4533+ void setTraceScanning( bool b ) {
4534+ trace_scanning_ = b;
4535+ }
4536+
4537+ bool getTraceTranslator() const {
4538+ return trace_translator_;
4539+ }
4540+
4541+ void setTraceTranslator( bool b ) {
4542+ trace_translator_ = b;
4543+ }
4544+
4545+ bool getUseIndexes() const {
4546+ return use_indexes_;
4547+ }
4548+
4549+ void setUseIndexes( bool b ) {
4550+ use_indexes_ = b;
4551+ }
4552+
4553+private:
4554+ typedef std::unique_ptr<std::ostream> stream_ptr;
4555+
4556+ Properties();
4557+ ~Properties();
4558+
4559+#ifndef NDEBUG
4560+ bool abort_;
4561+#endif /* NDEBUG */
4562+ std::string classpath_;
4563+ stream_ptr debug_stream_;
4564+ bool owns_debug_stream_;
4565+ bool dump_lib_;
4566+ bool force_gflwor_;
4567+ bool infer_joins_;
4568+ bool inline_udf_;
4569+ bool loop_hoisting_;
4570+ uint32_t max_udf_call_depth_;
4571+ bool no_copy_optim_;
4572+ bool no_tree_ids_;
4573+ unsigned optimization_level_;
4574+ bool print_ast_;
4575+ bool print_intermediate_opt_;
4576+ bool print_item_flow_;
4577+ bool print_iterator_locations_;
4578+ bool print_locations_;
4579+ bool print_optimized_;
4580+ bool print_static_types_;
4581+ bool print_translated_;
4582+ bool stable_iterator_ids_;
4583+ bool trace_codegen_;
4584+#ifndef ZORBA_NO_FULL_TEXT
4585+ bool trace_fulltext_;
4586+#endif /* ZORBA_NO_FULL_TEXT */
4587+ bool trace_parsing_;
4588+ bool trace_scanning_;
4589+ bool trace_translator_;
4590+ bool use_indexes_;
4591+};
4592+
4593+// deprecated name
4594+typedef Properties PropertiesGlobal;
4595+
4596+///////////////////////////////////////////////////////////////////////////////
4597+
4598+} // namespace zorba
4599+#endif // ZORBA_PROPERTIES_BASE_H
4600+/*
4601+ * Local variables:
4602+ * mode: c++
4603+ * End:
4604+ */
4605+/* vim:set et sw=2 ts=2: */
4606
4607=== modified file 'include/zorba/properties_base.h'
4608--- include/zorba/properties_base.h 2013-02-07 17:24:36 +0000
4609+++ include/zorba/properties_base.h 2014-02-11 00:42:47 +0000
4610@@ -1,5 +1,5 @@
4611 /*
4612- * Copyright 2006-2008 The FLWOR Foundation.
4613+ * Copyright 2006-2014 The FLWOR Foundation.
4614 *
4615 * Licensed under the Apache License, Version 2.0 (the "License");
4616 * you may not use this file except in compliance with the License.
4617@@ -13,136 +13,13 @@
4618 * See the License for the specific language governing permissions and
4619 * limitations under the License.
4620 */
4621+
4622 #ifndef ZORBA_PROPERTIES_BASE_H
4623 #define ZORBA_PROPERTIES_BASE_H
4624
4625-#include <string>
4626-#include <sstream>
4627-#include <iostream>
4628-#include <vector>
4629-#include <cctype>
4630-#include <zorba/config.h>
4631-
4632-namespace zorba {
4633-
4634-/***************************************************************************//**
4635-
4636-********************************************************************************/
4637-class ZORBA_DLL_PUBLIC PropertiesBase
4638-{
4639-protected:
4640- std::vector<std::string> thePositionalArgs;
4641-
4642-public:
4643- virtual ~PropertiesBase() {}
4644-
4645- std::string load_all(
4646- const char* cfgFilename,
4647- const std::string& env_pfx,
4648- int argc,
4649- const char **argv)
4650- {
4651- std::string result;
4652-
4653- if (! (result = load_env(env_pfx)).empty())
4654- return result;
4655-
4656- if (! (result = load_file(cfgFilename)).empty())
4657- return result;
4658-
4659- return load_argv(argc, argv);
4660- }
4661-
4662- std::string load_env(const std::string& env_pfx)
4663- {
4664- return load_env(env_pfx, get_all_options());
4665- }
4666-
4667- std::string load_env(const std::string& env_pfx, const char** options);
4668-
4669- std::string load_file(const char* fname);
4670-
4671- virtual std::string load_argv(int argc, const char **argv) = 0;
4672-
4673- virtual const char** get_all_options() const = 0;
4674-
4675- virtual std::string check_args() { return ""; }
4676-
4677- const std::vector<std::string>& getPositionalArgs() const
4678- {
4679- return thePositionalArgs;
4680- }
4681-
4682- void copy_args (const char** argv)
4683- {
4684- for (; *argv != NULL; ++argv)
4685- {
4686- thePositionalArgs.push_back(*argv);
4687- }
4688- }
4689-
4690- template<class T> void init_val(const char* str, T& val, unsigned delta = 0)
4691- {
4692- std::istringstream is(str + delta);
4693- is >> val;
4694- }
4695-
4696-};
4697-
4698-
4699-template<> ZORBA_DLL_PUBLIC void PropertiesBase::init_val(
4700- const char* str,
4701- std::string& val,
4702- unsigned delta);
4703-
4704-
4705-template<> ZORBA_DLL_PUBLIC void PropertiesBase::init_val(
4706- const char* str,
4707- std::vector<std::string>& val,
4708- unsigned delta);
4709-
4710-/**
4711- * \brief This class provides access to global properties.
4712- *
4713- * This class provides access to global properties set for Zorba in environment
4714- * and configuration file.
4715- * It is available using Zorba.getProperties() method.
4716- * \see { Zorba::getProperties() }
4717- */
4718-class ZORBA_DLL_PUBLIC PropertiesGlobal : public PropertiesBase
4719-{
4720-public:
4721- virtual ~PropertiesGlobal() {}
4722-
4723- /**
4724- * \brief Get global JVM classpath property.
4725- *
4726- * Before the JVM is started this will return the classpath set by
4727- * command line option, the CLASSPATH environment variable and in Zorba
4728- * config file.
4729- *
4730- * After the JVM is started this will contain in addition the paths to jars
4731- * used by modules that make use of the JVM.
4732- */
4733- virtual void getJVMClassPath(std::string & jvmClasspath) {}
4734-
4735- /**
4736- * \brief Set global JVM classpath property.
4737- *
4738- * This method should be used to set additional JVM classpath for modules
4739- * that make use of JVM. This will overide the classpath set by CLASSPATH
4740- * environment variable or Zorba config file.
4741- *
4742- * Once the JVM is started this method doesn't have any effect.
4743- */
4744- virtual void setJVMClassPath(const std::string & jvmClasspath) {}
4745-};
4746-
4747-}
4748-#endif // ZORBA_PROPERTIES_BASE_H
4749-/*
4750- * Local variables:
4751- * mode: c++
4752- * End:
4753- */
4754+// This is a deprecated header; #include <zorba/properties.h> instead.
4755+
4756+#include <zorba/properties.h>
4757+
4758+#endif /* ZORBA_PROPERTIES_BASE_H */
4759 /* vim:set et sw=2 ts=2: */
4760
4761=== modified file 'include/zorba/util/fs_util.h'
4762--- include/zorba/util/fs_util.h 2013-08-05 22:12:13 +0000
4763+++ include/zorba/util/fs_util.h 2014-02-11 00:42:47 +0000
4764@@ -90,6 +90,16 @@
4765 ////////// Directory //////////////////////////////////////////////////////////
4766
4767 /**
4768+ * Gets the directory where per-user configuration files are stored.
4769+ *
4770+ * @return Returns said directory.
4771+ * @throws ZorbaException with a diagnostic of zerr::ZOSE0004_IO_ERROR if it
4772+ * fails.
4773+ */
4774+ZORBA_DLL_PUBLIC
4775+std::string configdir();
4776+
4777+/**
4778 * Gets the current directory.
4779 *
4780 * @return Returns said directory.
4781@@ -269,6 +279,37 @@
4782 return path.substr( 0, pos );
4783 }
4784
4785+/**
4786+ * Gets the extension (the part of the name after the last '.') of the last
4787+ * path component of the given path name.
4788+ *
4789+ * @param path The path to get the extension of.
4790+ * @return Returns the extension (without the '.') or the empty string if
4791+ * \a path does not have an extension.
4792+ */
4793+inline std::string extension( char const *path ) {
4794+ char const *const name = base_name( path );
4795+ char const *const dot = std::strrchr( name, '.' );
4796+ return dot ? dot + 1 : "";
4797+}
4798+
4799+/**
4800+ * Gets the extension (the part of the name after the last '.') of the last
4801+ * path component of the given path name.
4802+ *
4803+ * @tparam PathStringType The \a path string type.
4804+ * @param path The path to get the extension of.
4805+ * @return Returns the extension (without the '.') or the empty string if
4806+ * \a path does not have an extension.
4807+ */
4808+template<class PathStringType> inline
4809+typename std::enable_if<ZORBA_IS_STRING(PathStringType),PathStringType>::type
4810+extension( PathStringType const &path ) {
4811+ PathStringType const name( base_name( path ) );
4812+ typename PathStringType::size_type const pos = name.rfind( '.' );
4813+ return pos != PathStringType::npos ? name.substr( pos + 1 ) : "";
4814+}
4815+
4816 #ifdef ZORBA_WITH_FILE_ACCESS
4817
4818 /**
4819
4820=== modified file 'include/zorba/util/smart_ptr.h'
4821--- include/zorba/util/smart_ptr.h 2013-06-12 04:55:14 +0000
4822+++ include/zorba/util/smart_ptr.h 2014-02-11 00:42:47 +0000
4823@@ -107,6 +107,12 @@
4824 return assign (rhs);
4825 }
4826
4827+ T* release() {
4828+ T *const temp = p;
4829+ p = 0;
4830+ return temp;
4831+ }
4832+
4833 }; // SmartPtr
4834
4835 } // namespace zorba
4836
4837=== modified file 'include/zorba/zorba.h'
4838--- include/zorba/zorba.h 2013-08-06 08:41:26 +0000
4839+++ include/zorba/zorba.h 2014-02-11 00:42:47 +0000
4840@@ -34,7 +34,7 @@
4841 #include <zorba/xquery.h>
4842 #include <zorba/zorba_string.h>
4843 #include <zorba/iterator.h>
4844-#include <zorba/properties_base.h>
4845+#include <zorba/properties.h>
4846
4847 namespace zorba {
4848
4849@@ -45,7 +45,7 @@
4850 * (2) create static contexts,
4851 * (3) provides access to the XmlDataManager,
4852 * (4) provides access to the ItemFactory, and
4853- * (5) provides access to the PropertiesGlobal.
4854+ * (5) provides access to the Properties.
4855 */
4856 class ZORBA_DLL_PUBLIC Zorba
4857 {
4858@@ -319,9 +319,18 @@
4859
4860 /** \brief Gets the singleton instance of Zorba's properties object.
4861 *
4862- * @return zorba::Properties the singleton instance of Zorba's properties object.
4863- */
4864- virtual PropertiesGlobal* getPropertiesGlobal() = 0;
4865+ * @return zorba::Properties the singleton instance of Zorba's properties
4866+ * object.
4867+ * @deprecated Use Properties::instance() instead.
4868+ */
4869+ virtual Properties* getProperties() = 0;
4870+
4871+ /**
4872+ * @deprecated Use Properties::instance() instead.
4873+ */
4874+ Properties* getPropertiesGlobal() {
4875+ return getProperties();
4876+ }
4877
4878 }; /* class Zorba */
4879
4880
4881=== modified file 'src/api/CMakeLists.txt'
4882--- src/api/CMakeLists.txt 2014-01-15 02:07:22 +0000
4883+++ src/api/CMakeLists.txt 2014-02-11 00:42:47 +0000
4884@@ -62,6 +62,7 @@
4885 store_consts.cpp
4886 streambuf.cpp
4887 mem_streambuf.cpp
4888+ properties.cpp
4889 transcode_streambuf.cpp
4890 uuid.cpp
4891 module_info_impl.cpp
4892
4893=== renamed file 'src/system/zorba_properties.cpp' => 'src/api/properties.cpp'
4894--- src/system/zorba_properties.cpp 2014-01-27 23:42:57 +0000
4895+++ src/api/properties.cpp 2014-02-11 00:42:47 +0000
4896@@ -14,377 +14,90 @@
4897 * limitations under the License.
4898 */
4899
4900-#include <cstring>
4901-
4902-#include "zorba_properties.h"
4903+// standard
4904+#include <exception>
4905+#include <fstream>
4906+#include <iostream>
4907+
4908+// Zorba
4909+#include <zorba/config.h>
4910+#include <zorba/internal/cxx_util.h>
4911+#include <zorba/properties.h>
4912+
4913+#include "util/string_util.h"
4914+
4915+using namespace std;
4916
4917 namespace zorba {
4918
4919 ///////////////////////////////////////////////////////////////////////////////
4920
4921-ZorbaProperties::ZorbaProperties() {
4922- theAbort = false;
4923- theCompileOnly = false;
4924- theDebug = false;
4925- theDumpLib = false;
4926- theForceGflwor = false;
4927- theInferJoins = true;
4928- theInlineUdf = true;
4929- theIterPlanTest = false;
4930- theJsoniqParser = false;
4931- theLibModule = false;
4932- theLoopHoisting = true;
4933- theMaxUdfCallDepth = 1024;
4934- theNoCopyOptim = true;
4935- theNoTreeIds = false;
4936- theOptimizer = 1;
4937- thePrintAst = false;
4938- thePrintIntermediateOpt = false;
4939- thePrintItemFlow = false;
4940- thePrintIteratorTree = false;
4941- thePrintLocations = false;
4942- thePrintNormalized = false;
4943- thePrintOptimized = false;
4944- thePrintQuery = false;
4945- thePrintStaticTypes = true;
4946- thePrintTime = false;
4947- thePrintTranslated = false;
4948- thePrintXqdoc = false;
4949- theReorderGlobals = true;
4950- theSerializeOnlyQuery = -1;
4951- theSpecializeCmp = true;
4952- theSpecializeNum = true;
4953- theStableIteratorIds = false;
4954- theTestPlanSerialization = false;
4955- theTraceCodegen = false;
4956- theTraceFulltext = false;
4957- theTraceParsing = false;
4958- theTraceScanning = false;
4959- theTraceTranslator = false;
4960- theUseIndexes = true;
4961- theUseSerializer = false;
4962-}
4963-
4964-char const** ZorbaProperties::get_all_options() const {
4965- static char const *result[] = {
4966- "--abort",
4967- "--CLASSPATH",
4968- "--compile-only",
4969- "--debug",
4970- "--debug-file",
4971- "--dot-plan-file",
4972- "--dump-lib",
4973- "--external-var",
4974- "--force-gflwor",
4975- "--infer-joins",
4976- "--inline-udf",
4977- "--iter-plan-test",
4978- "--jsoniq",
4979- "--lib-module",
4980- "--loop-hoisting",
4981- "--max-udf-call-depth",
4982- "--no-copy-optim",
4983- "--no-tree-ids",
4984- "--optimizer",
4985- "--plan",
4986- "--print-ast",
4987- "--print-intermediate-opt",
4988- "--print-item-flow",
4989- "--print-iterator-tree",
4990- "--print-locations",
4991- "--print-normalized",
4992- "--print-optimized",
4993- "--print-query",
4994- "--print-static-types",
4995- "--print-time",
4996- "--print-translated",
4997- "--print-xqdoc",
4998- "--query",
4999- "--reorder-globals",
5000- "--result-file",
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches