~ubuntu-branches/debian/sid/librecad/sid

« back to all changes in this revision

Viewing changes to librecad/src/main/main.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2013-12-30 12:17:45 UTC
  • mfrom: (0.2.10)
  • Revision ID: package-import@ubuntu.com-20131230121745-nfji56gc8mv8y6ve
Tags: 2.0.0+nolibs-1
* New upstream release
* Debian S-V 3.9.5, no changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
#include "main.h"
28
28
 
29
 
#include <qapplication.h>
 
29
#include <QApplication>
 
30
#include <QDebug>
30
31
 
31
32
#include <QSplashScreen>
32
33
QSplashScreen *splash;
94
95
//      qInitImages_librecad();
95
96
#endif
96
97
 
97
 
        const char *lpDebugSwitch = "--debug";
98
 
        size_t      iDebugSwitchLen = strlen(lpDebugSwitch);
 
98
        const QString lpDebugSwitch0("-d"),lpDebugSwitch1("--debug") ;
 
99
        const QString help0("-h"), help1("--help");
 
100
        bool allowOptions=true;
 
101
        QList<int> argClean;
99
102
        for (int i=0; i<argc; i++) {
100
 
            if ( ! strncmp( lpDebugSwitch, argv[i], iDebugSwitchLen)) {
 
103
            QString argstr(argv[i]);
 
104
            if(allowOptions&&QString::compare("--", argstr)==0){
 
105
                allowOptions=false;
 
106
                continue;
 
107
            }
 
108
 
 
109
            if (allowOptions&&(
 
110
                        help0.compare(argstr, Qt::CaseInsensitive)==0 ||
 
111
                        help1.compare(argstr, Qt::CaseInsensitive)==0
 
112
                        )
 
113
                    ){//hep information
 
114
                qDebug()<<"librecad::usage: <options> <dxf file>";
 
115
                qDebug()<<"-h, --help\tdisplay this message";
 
116
                qDebug()<<"";
 
117
                qDebug()<<" --help\tdisplay this message";
 
118
                qDebug()<<"-d, --debug <level>";
 
119
                RS_DEBUG->print( RS_Debug::D_NOTHING, "possible debug levels:");
 
120
                RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Nothing", RS_Debug::D_NOTHING);
 
121
                RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Critical", RS_Debug::D_CRITICAL);
 
122
                RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Error", RS_Debug::D_ERROR);
 
123
                RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Warning", RS_Debug::D_WARNING);
 
124
                RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Notice", RS_Debug::D_NOTICE);
 
125
                RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Informational", RS_Debug::D_INFORMATIONAL);
 
126
                RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Debugging", RS_Debug::D_DEBUGGING);
 
127
                exit(0);
 
128
 
 
129
            }
 
130
            if ( allowOptions&& (
 
131
                     argstr.startsWith(lpDebugSwitch0, Qt::CaseInsensitive)||
 
132
                     argstr.startsWith(lpDebugSwitch1, Qt::CaseInsensitive)
 
133
                     )
 
134
                 ){
101
135
                // to control the level of debugging output use --debug with level 0-6, e.g. --debug3
102
136
                // for a list of debug levels use --debug?
103
137
                // if no level follows, the debugging level is set
104
 
                if( strlen( argv[i]) > iDebugSwitchLen) {
105
 
                    switch( argv[i][iDebugSwitchLen]) {
106
 
                    case '?' :
107
 
                        RS_DEBUG->print( RS_Debug::D_NOTHING, "possible debug levels:");
108
 
                        RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Nothing", RS_Debug::D_NOTHING);
109
 
                        RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Critical", RS_Debug::D_CRITICAL);
110
 
                        RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Error", RS_Debug::D_ERROR);
111
 
                        RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Warning", RS_Debug::D_WARNING);
112
 
                        RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Notice", RS_Debug::D_NOTICE);
113
 
                        RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Informational", RS_Debug::D_INFORMATIONAL);
114
 
                        RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Debugging", RS_Debug::D_DEBUGGING);
115
 
                        return 0;
116
 
 
117
 
                    case '0' + RS_Debug::D_NOTHING :
118
 
                        RS_DEBUG->setLevel( RS_Debug::D_NOTHING);
119
 
                        ++i;
120
 
                        break;
121
 
 
122
 
                    case '0' + RS_Debug::D_CRITICAL :
123
 
                        RS_DEBUG->setLevel( RS_Debug::D_CRITICAL);
124
 
                        ++i;
125
 
                        break;
126
 
 
127
 
                    case '0' + RS_Debug::D_ERROR :
128
 
                        RS_DEBUG->setLevel( RS_Debug::D_ERROR);
129
 
                        ++i;
130
 
                        break;
131
 
 
132
 
                    case '0' + RS_Debug::D_WARNING :
133
 
                        RS_DEBUG->setLevel( RS_Debug::D_WARNING);
134
 
                        ++i;
135
 
                        break;
136
 
 
137
 
                    case '0' + RS_Debug::D_NOTICE :
138
 
                        RS_DEBUG->setLevel( RS_Debug::D_NOTICE);
139
 
                        ++i;
140
 
                        break;
141
 
 
142
 
                    case '0' + RS_Debug::D_INFORMATIONAL :
143
 
                        RS_DEBUG->setLevel( RS_Debug::D_INFORMATIONAL);
144
 
                        ++i;
145
 
                        break;
146
 
 
147
 
                    case '0' + RS_Debug::D_DEBUGGING :
148
 
                        RS_DEBUG->setLevel( RS_Debug::D_DEBUGGING);
149
 
                        ++i;
150
 
                        break;
151
 
 
152
 
                    default :
153
 
                        RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING);
154
 
                        break;
155
 
                    }
156
 
                }
157
 
                else {
 
138
                argstr.remove(QRegExp("^"+lpDebugSwitch0));
 
139
                argstr.remove(QRegExp("^"+lpDebugSwitch1));
 
140
                char level;
 
141
                if(argstr.size()==0){
 
142
                    if(i+1<argc) {
 
143
                        ++i;
 
144
                        level=argv[i][0];
 
145
                        argClean<<i;
 
146
                    }else
 
147
                        level='3'; //default to D_WARNING
 
148
                }else
 
149
                    level=argstr.toStdString()[0];
 
150
                //                if( strlen( argv[i]) > iDebugSwitchLen) {
 
151
                switch(level) {
 
152
                case '?' :
 
153
                    RS_DEBUG->print( RS_Debug::D_NOTHING, "possible debug levels:");
 
154
                    RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Nothing", RS_Debug::D_NOTHING);
 
155
                    RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Critical", RS_Debug::D_CRITICAL);
 
156
                    RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Error", RS_Debug::D_ERROR);
 
157
                    RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Warning", RS_Debug::D_WARNING);
 
158
                    RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Notice", RS_Debug::D_NOTICE);
 
159
                    RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Informational", RS_Debug::D_INFORMATIONAL);
 
160
                    RS_DEBUG->print( RS_Debug::D_NOTHING, "    %d Debugging", RS_Debug::D_DEBUGGING);
 
161
                    return 0;
 
162
 
 
163
                case '0' + RS_Debug::D_NOTHING :
 
164
                    RS_DEBUG->setLevel( RS_Debug::D_NOTHING);
 
165
                    ++i;
 
166
                    break;
 
167
 
 
168
                case '0' + RS_Debug::D_CRITICAL :
 
169
                    RS_DEBUG->setLevel( RS_Debug::D_CRITICAL);
 
170
                    ++i;
 
171
                    break;
 
172
 
 
173
                case '0' + RS_Debug::D_ERROR :
 
174
                    RS_DEBUG->setLevel( RS_Debug::D_ERROR);
 
175
                    ++i;
 
176
                    break;
 
177
 
 
178
                case '0' + RS_Debug::D_WARNING :
 
179
                    RS_DEBUG->setLevel( RS_Debug::D_WARNING);
 
180
                    ++i;
 
181
                    break;
 
182
 
 
183
                case '0' + RS_Debug::D_NOTICE :
 
184
                    RS_DEBUG->setLevel( RS_Debug::D_NOTICE);
 
185
                    ++i;
 
186
                    break;
 
187
 
 
188
                case '0' + RS_Debug::D_INFORMATIONAL :
 
189
                    RS_DEBUG->setLevel( RS_Debug::D_INFORMATIONAL);
 
190
                    ++i;
 
191
                    break;
 
192
 
 
193
                case '0' + RS_Debug::D_DEBUGGING :
 
194
                    RS_DEBUG->setLevel( RS_Debug::D_DEBUGGING);
 
195
                    ++i;
 
196
                    break;
 
197
 
 
198
                default :
158
199
                    RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING);
 
200
                    break;
159
201
                }
 
202
                //                }
 
203
//                else {
 
204
//                    RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING);
 
205
//                }
160
206
            }
161
207
        }
162
208
        RS_DEBUG->print("param 0: %s", argv[0]);
173
219
        RS_FileIO::instance()->registerFilter( &(RS_FilterDXF1::createFilter));
174
220
 
175
221
        // parse command line arguments that might not need a launched program:
176
 
        QStringList fileList = handleArgs(argc, argv);
 
222
        QStringList fileList = handleArgs(argc, argv, argClean);
177
223
 
178
224
        QString lang;
179
225
        QString langCmd;
343
389
 *
344
390
 * @return list of files to load on startup.
345
391
 */
346
 
QStringList handleArgs(int argc, char** argv) {
 
392
QStringList handleArgs(int argc, char** argv, const QList<int>& argClean) {
347
393
        RS_DEBUG->print("main: handling args..");
348
394
        QStringList ret;
349
395
 
353
399
        QString output;
354
400
 
355
401
        for (int i=1; i<argc; i++) {
 
402
            if(argClean.indexOf(i)>=0) continue;
356
403
                if (QString(argv[i]).startsWith("-")==false) {
357
404
                        QString fname = QDir::toNativeSeparators(
358
405
                                QFileInfo(QFile::decodeName(argv[i])).absoluteFilePath() );