annotate src/main.cpp @ 754:4ec2ac09969d

Renamed the logger class and put it into a namespace for later universal tool reuse. git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@1031 59b1889a-e5ac-428c-b0c7-476e01d41282
author thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
date Tue, 21 Dec 2010 23:07:50 +0000
parents e64c04dc6f61
children 5a0ece4b81b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
60
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
1 /***************************************************************************
727
aae5a8d04f70 Updated comment copyright year.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 724
diff changeset
2 * Copyright (C) 2006-2010 by Thomas Schweitzer *
60
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
3 * thomas-schweitzer(at)arcor.de *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
4 * *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
5 * This program is free software; you can redistribute it and/or modify *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
6 * it under the terms of the GNU General Public License version 2.0 as *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
7 * published by the Free Software Foundation. *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
8 * *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
9 * This program is distributed in the hope that it will be useful, *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
12 * GNU General Public License for more details. *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
13 * *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
14 * You should have received a copy of the GNU General Public License *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
15 * along with this program in the file LICENSE.GPL; if not, write to the *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
16 * Free Software Foundation, Inc., *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
18 ***************************************************************************/
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
19
638
94734b9eb54f Renamed the source files and some classes to have consistent names. What a nice kind of work.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 635
diff changeset
20 #include "MainWindow.h"
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
21
638
94734b9eb54f Renamed the source files and some classes to have consistent names. What a nice kind of work.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 635
diff changeset
22 #include "UiGuiIndentServer.h"
754
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
23 #include "debugging/TSLogger.h"
638
94734b9eb54f Renamed the source files and some classes to have consistent names. What a nice kind of work.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 635
diff changeset
24 #include "UiGuiIniFileParser.h"
94734b9eb54f Renamed the source files and some classes to have consistent names. What a nice kind of work.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 635
diff changeset
25 #include "UiGuiSettings.h"
691
2af225b848bb Enhanced the logger by an info message type and until now use it at start to log the version.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 688
diff changeset
26 #include "UiGuiVersion.h"
692
e3ff3c85d271 Added a class for retrieving info about the operating system and use this for logging info.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 691
diff changeset
27 #include "UiGuiSystemInfo.h"
751
ac165b6ae67e Done some refactoring:
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 742
diff changeset
28 #include "IndentHandler.h"
ac165b6ae67e Done some refactoring:
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 742
diff changeset
29 #include "SettingsPaths.h"
ac165b6ae67e Done some refactoring:
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 742
diff changeset
30
ac165b6ae67e Done some refactoring:
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 742
diff changeset
31 #include <QApplication>
ac165b6ae67e Done some refactoring:
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 742
diff changeset
32 #include <QTextCodec>
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
33
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
34 #include <string>
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
35 #include <iostream>
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
36 #include <algorithm>
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
37 #include <tclap/CmdLine.h>
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
38
721
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
39 #ifdef WIN32
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
40
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
41 #include <windows.h>
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
42 #include <direct.h>
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
43 #include <stdlib.h>
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
44 #include <stdio.h>
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
45 #include <fcntl.h>
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
46 #include <io.h>
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
47 #include <iostream>
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
48 #include <fstream>
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
49
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
50 /**
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
51 \brief Calling this function tries to attach to the console of the parent process and
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
52 redirect all inputs and outputs from and to this console.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
53
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
54 The redirected streams are stdout, stdin, stderr, cout, wcout, cin, wcin, wcerr, cerr, wclog and clog.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
55
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
56 Code based on info from http://dslweb.nwnexus.com/~ast/dload/guicon.htm.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
57 */
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
58 bool attachToConsole(/*enum ATTACH_ONLY|TRY_ATTACH_ELSE_CREATE|CREATE_NEW*/)
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
59 {
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
60 int hConHandle;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
61 long lStdHandle;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
62 CONSOLE_SCREEN_BUFFER_INFO coninfo;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
63 FILE *fp;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
64
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
65 // Trying to attach to the console of the parent process.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
66 BOOL successful = AttachConsole(ATTACH_PARENT_PROCESS);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
67 // In case that the parent process has no console return false and do no input/output redirection.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
68 if ( !successful )
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
69 return false;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
70
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
71 // Set the screen buffer to be big enough to let us scroll text
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
72 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
73 // Set maximum console lines.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
74 coninfo.dwSize.Y = 500;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
75 SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
76
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
77 // Redirect unbuffered STDOUT to the console.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
78 lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
79 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
80 fp = _fdopen( hConHandle, "w" );
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
81 *stdout = *fp;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
82 setvbuf( stdout, NULL, _IONBF, 0 );
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
83
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
84 // Redirect unbuffered STDIN to the console.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
85 lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
86 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
87 fp = _fdopen( hConHandle, "r" );
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
88 *stdin = *fp;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
89 setvbuf( stdin, NULL, _IONBF, 0 );
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
90
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
91 // Redirect unbuffered STDERR to the console.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
92 lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
93 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
94 fp = _fdopen( hConHandle, "w" );
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
95 *stderr = *fp;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
96 setvbuf( stderr, NULL, _IONBF, 0 );
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
97
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
98 // Make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog point to console as well.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
99 std::ios::sync_with_stdio();
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
100
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
101 return true;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
102 }
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
103 #endif
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
104
754
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
105 using namespace tschweitzer::debugging;
721
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
106
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
107 /*!
500
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
108 /brief Entry point to UniversalIndentGUI application.
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
109
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
110 Evaluates the following parameters:
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
111 No parameters starts without server and full gui.
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
112 -f filename --file filename : Opens the by filename defined file on start.
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
113 -p --plugin : Run as plugin. Server will be started with a simplified gui.
500
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
114 -s --server : Run as server only without gui.
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
115 If -p and -s are set, -p will be used.
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
116 -v --verbose needs a following parameter defining the verbose level as a number from 0 to 3.
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
117 */
635
e1fdfb9adf92 According to the previous code formatting also made the function opening brace be consistently placed.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
118 int main(int argc, char *argv[]) {
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
119 QString file2OpenOnStart = "";
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
120 int verboseLevel = 1;
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
121 bool startAsPlugin = false;
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
122 bool startAsServer = false;
721
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
123 bool tclapExitExceptionThrown = false;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
124 int returnValue = 0;
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
125
721
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
126 #ifdef WIN32
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
127 bool attachedToConsole = false;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
128 attachedToConsole = attachToConsole();
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
129 #endif
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
130
734
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
131 #ifdef __APPLE__
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
132 // Filter out -psn_0_118813 and similar parameters.
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
133 std::vector<char*> argList;
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
134 for ( int i = 0; i < argc; i++ ) {
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
135 QString argString(argv[i]);
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
136
742
edde9cbb2ce4 Corrected filtering of faulty finder command line parameter.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 734
diff changeset
137 if ( argString.startsWith("-psn_") == false ) {
734
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
138 argList.push_back(argv[i]);
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
139 }
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
140 else {
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
141 // std::cerr << std::endl << "The parameter "<< i << " is an invalid finder parameter. Parameter was " << argv[i] << std::endl;
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
142 }
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
143 }
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
144 for ( size_t i = 0; i < argList.size(); i++ ) {
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
145 argv[i] = argList.at(i);
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
146 }
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
147 argc = argList.size();
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
148 #endif
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
149
742
edde9cbb2ce4 Corrected filtering of faulty finder command line parameter.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 734
diff changeset
150 // Wrap everything in a try block. Do this every time,
edde9cbb2ce4 Corrected filtering of faulty finder command line parameter.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 734
diff changeset
151 // because exceptions will be thrown for problems.
edde9cbb2ce4 Corrected filtering of faulty finder command line parameter.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 734
diff changeset
152 try {
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
153 // Define the command line object.
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
154 TCLAP::CmdLine cmd("If -p and -s are set, -p will be used.\nGiving no parameters starts full gui without server.", ' ', "UiGUI version " PROGRAM_VERSION_STRING " " PROGRAM_REVISION);
721
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
155 cmd.setExceptionHandling(false);
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
156
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
157 // Define a value argument and add it to the command line.
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
158 TCLAP::ValueArg<std::string> filenameArg("f", "file", "Opens the by filename defined file on start" , false, "", "string");
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
159 cmd.add( filenameArg );
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
160
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
161 // Define a switch and add it to the command line.
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
162 TCLAP::SwitchArg pluginSwitch("p", "plugin", "Run as plugin. Server will be started with a simplified gui", false);
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
163 cmd.add( pluginSwitch );
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
164
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
165 // Define a switch and add it to the command line.
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
166 TCLAP::SwitchArg serverSwitch("s", "server", "Run as server only without gui", false);
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
167 cmd.add( serverSwitch );
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
168
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
169 // Define a value argument and add it to the command line.
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
170 TCLAP::ValueArg<int> verboselevelArg("v", "verbose", "Sets how many info is written to the log. 0 means with debug info, 3 means critical messages only" , false, 1, "int");
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
171 cmd.add( verboselevelArg );
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
172
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
173 // Parse the args.
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
174 cmd.parse( argc, argv );
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
175
742
edde9cbb2ce4 Corrected filtering of faulty finder command line parameter.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 734
diff changeset
176 // Get the value parsed by each arg.
753
e64c04dc6f61 Made the code be compatible to the Qt compile variant with "-no-stl" being set.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 751
diff changeset
177 file2OpenOnStart = filenameArg.getValue().c_str();
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
178 startAsPlugin = pluginSwitch.getValue();
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
179 startAsServer = serverSwitch.getValue();
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
180 verboseLevel = verboselevelArg.getValue();
721
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
181 }
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
182 catch (TCLAP::ArgException &e) { // catch arg exceptions
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
183 std::cerr << std::endl << "error: " << e.error() << ". " << e.argId() << std::endl;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
184 returnValue = 1;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
185 }
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
186 catch (TCLAP::ExitException &e) { // catch exit exceptions
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
187 tclapExitExceptionThrown = true;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
188 returnValue = e.getExitStatus();
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
189 }
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
190 catch (...) { // catch any exceptions
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
191 std::cerr << std::endl << "There was an error! Maybe faulty command line arguments set. See --help." << std::endl;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
192 returnValue = 1;
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
193 }
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
194
721
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
195 if ( returnValue != 0 || tclapExitExceptionThrown ) {
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
196 #ifdef WIN32
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
197 if ( attachedToConsole ) {
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
198 // Workaround for skipped command line prompt: Get the current working directory and print it to console.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
199 char* buffer;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
200 if( (buffer = _getcwd( NULL, 0 )) != NULL ) {
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
201 std::cerr << std::endl << buffer << ">";
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
202 free(buffer);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
203 }
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
204 // Release the connection to the parents console.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
205 FreeConsole();
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
206 }
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
207 #endif
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
208 return returnValue;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
209 }
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
210
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
211 QApplication app(argc, argv);
638
94734b9eb54f Renamed the source files and some classes to have consistent names. What a nice kind of work.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 635
diff changeset
212 UiGuiIndentServer server;
500
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
213 MainWindow *mainWindow = NULL;
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
214 IndentHandler *indentHandler = NULL;
496
205b2f8adf4a In preparation for some kind of IPC added a server class. With this abstraction it will be easier to create plugins for other ides or editors which can communicate with UiGUI.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 479
diff changeset
215
709
718e2e543cd1 Start parsing the command line arguments before the logger is initialized. Otherwise the command line verbose level applies too late and some debug output might be missing.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 692
diff changeset
216 // Init and install the logger function.
718e2e543cd1 Start parsing the command line arguments before the logger is initialized. Otherwise the command line verbose level applies too late and some debug output might be missing.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 692
diff changeset
217 // Setting UTF-8 as default 8-Bit encoding to ensure that qDebug does no false string conversion.
718e2e543cd1 Start parsing the command line arguments before the logger is initialized. Otherwise the command line verbose level applies too late and some debug output might be missing.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 692
diff changeset
218 QTextCodec::setCodecForCStrings( QTextCodec::codecForName("UTF-8") );
718e2e543cd1 Start parsing the command line arguments before the logger is initialized. Otherwise the command line verbose level applies too late and some debug output might be missing.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 692
diff changeset
219 QTextCodec::setCodecForLocale( QTextCodec::codecForName("UTF-8") );
754
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
220 // Force creation of an TSLogger instance here, to avoid recursion with SettingsPaths init function.
687
b4aee13bc733 - Added a new class, that is responsible for logging of any kind and added some logging/debug output calls.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
221 #ifdef _DEBUG
754
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
222 TSLogger::getInstance(0);
688
b5b686bac866 Made it possible to set the verbose level via command line parameter.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 687
diff changeset
223 #else
754
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
224 TSLogger::getInstance(verboseLevel);
687
b4aee13bc733 - Added a new class, that is responsible for logging of any kind and added some logging/debug output calls.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
225 #endif
754
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
226 qInstallMsgHandler( TSLogger::messageHandler );
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
227 TSLogger::messageHandler( TSLoggerInfoMsg, QString("Starting UiGUI Version %1 %2").arg(PROGRAM_VERSION_STRING).arg(PROGRAM_REVISION).toAscii() );
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
228 TSLogger::messageHandler( TSLoggerInfoMsg, QString("Running on %1").arg(UiGuiSystemInfo::getOperatingSystem()).toAscii() );
634
82cd1efd6015 Talking about clean and well formatted code all the time and never run mine through a beautifier while still having a mix of tabs an spaces. So now Uncrustify has cleaned my code. Still two unsatisfying points are left. indenthandler.cpp line 467 a space between case label and colon has been removed and like on line 503 some code lines got indented without setting that explicitly.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 571
diff changeset
229
528
7a1b429fd4e7 - Removed any warnings.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 500
diff changeset
230 // Set default values for all by UniversalIndentGUI used settings objects.
7a1b429fd4e7 - Removed any warnings.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 500
diff changeset
231 QCoreApplication::setOrganizationName("UniversalIndentGUI");
7a1b429fd4e7 - Removed any warnings.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 500
diff changeset
232 QCoreApplication::setOrganizationDomain("universalindent.sf.net");
7a1b429fd4e7 - Removed any warnings.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 500
diff changeset
233 QCoreApplication::setApplicationName("UniversalIndentGUI");
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
234
500
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
235 // Start normal with full gui and without server.
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
236 if ( !startAsPlugin && !startAsServer ) {
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
237 mainWindow = new MainWindow(file2OpenOnStart);
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
238 mainWindow->show();
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
239 }
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
240 // Start as plugin with server.
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
241 else if ( startAsPlugin ) {
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
242 server.startServer();
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
243 indentHandler = new IndentHandler(0);
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
244 indentHandler->show();
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
245 }
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
246 // Start as server only without any gui.
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
247 else if ( startAsServer ) {
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
248 server.startServer();
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
249 }
63
aea5d4632a2f replaced tabs by spaces.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 60
diff changeset
250
721
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
251 returnValue = app.exec();
571
f401efb5080b Explicitly calling delete on the MainWindow and IndentHandler objects and now the (dependent) destructors are also correctly called.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 557
diff changeset
252
724
6cca48ee1557 Small correction and compiler warning avoid.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 721
diff changeset
253 if ( startAsPlugin || startAsServer )
571
f401efb5080b Explicitly calling delete on the MainWindow and IndentHandler objects and now the (dependent) destructors are also correctly called.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 557
diff changeset
254 server.stopServer();
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
255
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
256 delete indentHandler;
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
257 delete mainWindow;
634
82cd1efd6015 Talking about clean and well formatted code all the time and never run mine through a beautifier while still having a mix of tabs an spaces. So now Uncrustify has cleaned my code. Still two unsatisfying points are left. indenthandler.cpp line 467 a space between case label and colon has been removed and like on line 503 some code lines got indented without setting that explicitly.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 571
diff changeset
258
751
ac165b6ae67e Done some refactoring:
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 742
diff changeset
259 SettingsPaths::cleanAndRemoveTempDir();
754
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
260 TSLogger::deleteInstance();
571
f401efb5080b Explicitly calling delete on the MainWindow and IndentHandler objects and now the (dependent) destructors are also correctly called.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 557
diff changeset
261
f401efb5080b Explicitly calling delete on the MainWindow and IndentHandler objects and now the (dependent) destructors are also correctly called.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 557
diff changeset
262 return returnValue;
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
263 }