1 | /*************************************************************************** |
---|
2 | TmDmCreator |
---|
3 | Create SQL code for ToolMap project |
---|
4 | ------------------- |
---|
5 | copyright : (C) 2013 CREALP Lucien Schreiber |
---|
6 | email : lucien.schreiber at crealp dot vs dot ch |
---|
7 | ***************************************************************************/ |
---|
8 | |
---|
9 | /*************************************************************************** |
---|
10 | * * |
---|
11 | * This program is free software; you can redistribute it and/or modify * |
---|
12 | * it under the terms of the GNU General Public License as published by * |
---|
13 | * the Free Software Foundation; either version 2 of the License, or * |
---|
14 | * (at your option) any later version. * |
---|
15 | * * |
---|
16 | ***************************************************************************/ |
---|
17 | #include "wx/wxprec.h" |
---|
18 | #ifdef __BORLANDC__ |
---|
19 | #pragma hdrstop |
---|
20 | #endif |
---|
21 | #ifndef WX_PRECOMP |
---|
22 | #include "wx/wx.h" |
---|
23 | #endif |
---|
24 | |
---|
25 | #include <wx/app.h> |
---|
26 | #include <wx/cmdline.h> |
---|
27 | #include <wx/dir.h> |
---|
28 | #include <wx/filename.h> |
---|
29 | #include "tmdmcreator.h" |
---|
30 | |
---|
31 | |
---|
32 | static const wxCmdLineEntryDesc cmdLineDesc[] = |
---|
33 | { |
---|
34 | { wxCMD_LINE_SWITCH, "h", "help", "show this help message", |
---|
35 | wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, |
---|
36 | { wxCMD_LINE_SWITCH, "v", "verbose", "Be more verbose" }, |
---|
37 | { wxCMD_LINE_SWITCH, "t", "toolmap", "toolmap output" }, |
---|
38 | { wxCMD_LINE_SWITCH, "o", "overwrite", "overwrite output" }, |
---|
39 | { wxCMD_LINE_PARAM, NULL, NULL, "[base structure sql file]"}, |
---|
40 | { wxCMD_LINE_PARAM, NULL, NULL, "[user structure sql file]"}, |
---|
41 | { wxCMD_LINE_PARAM, NULL, NULL, "[user content txt file]"}, |
---|
42 | { wxCMD_LINE_PARAM, NULL, NULL, "[result file]"}, |
---|
43 | { wxCMD_LINE_NONE } |
---|
44 | }; |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | void PrintArray(const wxArrayString & array, const wxString & msg = wxEmptyString){ |
---|
49 | if (msg != wxEmptyString) { |
---|
50 | wxPrintf(msg + _T("\n")); |
---|
51 | } |
---|
52 | for (unsigned int i = 0; i< array.GetCount(); i++) { |
---|
53 | wxPrintf(array[i] + _T("\n")); |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | int main(int argc, char **argv){ |
---|
60 | // debugging string for OSX |
---|
61 | // this is needed for viewing string content with Xcode !! |
---|
62 | wxString myTest = _T("Test debugging"); |
---|
63 | myTest.ToUTF8().data(); |
---|
64 | myTest.Len(); |
---|
65 | |
---|
66 | wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program"); |
---|
67 | wxInitializer initializer; |
---|
68 | if ( !initializer ){ |
---|
69 | fprintf(stderr, "Failed to initialize the wxWidgets library, aborting."); |
---|
70 | return -1; |
---|
71 | } |
---|
72 | |
---|
73 | wxString myLogoTxt = _T("*\n* TmDmCreator \n* Create SQL file for ToolMap projects \n* (c) Copyright 2013 Lucien Schreiber - CREALP . All Rights Reserved. \n*\n"); |
---|
74 | wxCmdLineParser parser(cmdLineDesc, argc, argv); |
---|
75 | parser.SetLogo(myLogoTxt); |
---|
76 | if (parser.Parse() != 0) { |
---|
77 | return 0; |
---|
78 | } |
---|
79 | |
---|
80 | // cmd line is correct !! |
---|
81 | wxPrintf(myLogoTxt); |
---|
82 | |
---|
83 | bool bVerbose = parser.Found("verbose"); |
---|
84 | bool bToolMap = parser.Found("toolmap"); |
---|
85 | if (parser.Found("overwrite")) { |
---|
86 | wxRemoveFile(parser.GetParam(3)); |
---|
87 | } |
---|
88 | |
---|
89 | if (bToolMap == true) { |
---|
90 | wxPrintf(_("Exporting to ToolMap project not supported for now!\n")); |
---|
91 | return 0; |
---|
92 | } |
---|
93 | |
---|
94 | wxASSERT(parser.GetParamCount() == 4); |
---|
95 | TmDmCreator myCreator; |
---|
96 | myCreator.SetBaseSQL(wxFileName(parser.GetParam(0))); |
---|
97 | myCreator.SetUserSQL(wxFileName(parser.GetParam(1))); |
---|
98 | myCreator.SetUserContent(wxFileName(parser.GetParam(2))); |
---|
99 | myCreator.SetOutSQL(wxFileName(parser.GetParam(3))); |
---|
100 | |
---|
101 | wxArrayString myErrors; |
---|
102 | if (myCreator.CheckFiles(myErrors) == false) { |
---|
103 | if (bVerbose == true) { |
---|
104 | PrintArray(myErrors); |
---|
105 | } |
---|
106 | wxPrintf(_("Error while checking files, aborting!\n")); |
---|
107 | return 0; |
---|
108 | } |
---|
109 | |
---|
110 | if (myCreator.ProcessFiles(myErrors) == false) { |
---|
111 | if (bVerbose == true) { |
---|
112 | PrintArray(myErrors); |
---|
113 | } |
---|
114 | wxPrintf(_("Error processing files, aborting\n")); |
---|
115 | return 0; |
---|
116 | } |
---|
117 | |
---|
118 | wxPrintf(_("Processing succeed!\n")); |
---|
119 | return 0; |
---|
120 | } |
---|