annotate src/main.cpp @ 769:431756c6e342

Made the attachToConsole call be compiler and not system dependent. git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@1046 59b1889a-e5ac-428c-b0c7-476e01d41282
author thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
date Thu, 21 Apr 2011 15:19:00 +0000
parents cc2ba63d6005
children fa7aa6f543f1
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 /***************************************************************************
769
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
2 * Copyright (C) 2006-2011 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>
756
5a0ece4b81b4 main.cpp: Added a try-catch around the application execution call.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 754
diff changeset
33 #include <QDebug>
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
34
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
35 #include <string>
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
36 #include <iostream>
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
37 #include <algorithm>
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
38 #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
39
769
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
40 #ifdef _MSC_VER
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
41
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 <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
43 #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
44 #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
45 #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
46 #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
47 #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
48 #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
49 #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
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 /**
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 \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
53 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
54
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 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
56
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 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
58 */
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 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
60 {
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 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
62 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
63 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
64 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
65
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 // 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
67 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
68 // 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
69 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
70 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
71
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 // 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
73 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
74 // 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
75 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
76 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
77
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 // 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
79 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
80 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
769
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
81 if ( hConHandle != -1 ) {
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
82 fp = _fdopen( hConHandle, "w" );
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
83 *stdout = *fp;
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
84 setvbuf( stdout, NULL, _IONBF, 0 );
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
85 }
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
86
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 // 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
88 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
89 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
769
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
90 if ( hConHandle != -1 ) {
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
91 fp = _fdopen( hConHandle, "r" );
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
92 *stdin = *fp;
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
93 setvbuf( stdin, NULL, _IONBF, 0 );
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
94 }
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
95
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 // 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
97 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
98 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
769
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
99 if ( hConHandle != -1 ) {
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
100 fp = _fdopen( hConHandle, "w" );
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
101 *stderr = *fp;
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
102 setvbuf( stderr, NULL, _IONBF, 0 );
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
103 }
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
104
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
105 // 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
106 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
107
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
108 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
109 }
769
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
110 #else
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
111 bool attachToConsole()
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
112 {
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
113 return false;
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
114 }
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
115
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
116 #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
117
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
118 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
119
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
120 /*!
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
121 /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
122
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
123 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
124 No parameters starts without server and full gui.
765
cc2ba63d6005 Opening a file via command line call is possible without any parameter prefix now.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 756
diff changeset
125 A string without any parameter prefix will be loaded as 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
126 -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
127 -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
128 If -p and -s are set, -p will be used.
765
cc2ba63d6005 Opening a file via command line call is possible without any parameter prefix now.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 756
diff changeset
129 -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
130 */
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
131 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
132 QString file2OpenOnStart = "";
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
133 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
134 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
135 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
136 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
137 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
138
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
139 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
140 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
141
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
142 #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
143 // 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
144 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
145 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
146 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
147
742
edde9cbb2ce4 Corrected filtering of faulty finder command line parameter.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 734
diff changeset
148 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
149 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
150 }
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
151 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
152 // 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
153 }
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
154 }
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
155 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
156 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
157 }
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
158 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
159 #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
160
742
edde9cbb2ce4 Corrected filtering of faulty finder command line parameter.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 734
diff changeset
161 // 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
162 // 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
163 try {
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
164 // 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
165 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
166 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
167
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
168 // Define a value argument and add it to the command line.
765
cc2ba63d6005 Opening a file via command line call is possible without any parameter prefix now.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 756
diff changeset
169 TCLAP::UnlabeledValueArg<std::string> filenameArg("file", "Opens the by filename defined file on start" , false, "", "filename");
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
170 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
171
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
172 // 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
173 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
174 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
175
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
176 // 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
177 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
178 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
179
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
180 // 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
181 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
182 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
183
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
184 // 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
185 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
186
742
edde9cbb2ce4 Corrected filtering of faulty finder command line parameter.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 734
diff changeset
187 // 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
188 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
189 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
190 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
191 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
192 }
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
193 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
194 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
195 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
196 }
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 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
198 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
199 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
200 }
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 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
202 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
203 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
204 }
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
205
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
206 if ( returnValue != 0 || tclapExitExceptionThrown ) {
769
431756c6e342 Made the attachToConsole call be compiler and not system dependent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 765
diff changeset
207 #ifdef _MSC_VER
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
208 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
209 // 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
210 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
211 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
212 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
213 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
214 }
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
215 // 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
216 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
217 }
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
218 #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
219 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
220 }
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
221
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
222 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
223 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
224 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
225 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
226
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
227 // 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
228 // 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
229 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
230 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
231 // 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
232 #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
233 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
234 #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
235 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
236 #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
237 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
238 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
239 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
240
528
7a1b429fd4e7 - Removed any warnings.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 500
diff changeset
241 // 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
242 QCoreApplication::setOrganizationName("UniversalIndentGUI");
7a1b429fd4e7 - Removed any warnings.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 500
diff changeset
243 QCoreApplication::setOrganizationDomain("universalindent.sf.net");
7a1b429fd4e7 - Removed any warnings.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 500
diff changeset
244 QCoreApplication::setApplicationName("UniversalIndentGUI");
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
245
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
246 // 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
247 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
248 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
249 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
250 }
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
251 // 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
252 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
253 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
254 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
255 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
256 }
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
257 // 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
258 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
259 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
260 }
63
aea5d4632a2f replaced tabs by spaces.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 60
diff changeset
261
756
5a0ece4b81b4 main.cpp: Added a try-catch around the application execution call.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 754
diff changeset
262 try {
5a0ece4b81b4 main.cpp: Added a try-catch around the application execution call.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 754
diff changeset
263 returnValue = app.exec();
5a0ece4b81b4 main.cpp: Added a try-catch around the application execution call.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 754
diff changeset
264 }
5a0ece4b81b4 main.cpp: Added a try-catch around the application execution call.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 754
diff changeset
265 catch (std::exception &ex) {
5a0ece4b81b4 main.cpp: Added a try-catch around the application execution call.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 754
diff changeset
266 qCritical() << __LINE__ << " " << __FUNCTION__ << ": Something went terribly wrong:" << ex.what();
5a0ece4b81b4 main.cpp: Added a try-catch around the application execution call.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 754
diff changeset
267 }
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
268
724
6cca48ee1557 Small correction and compiler warning avoid.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 721
diff changeset
269 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
270 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
271
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
272 delete indentHandler;
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
273 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
274
751
ac165b6ae67e Done some refactoring:
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 742
diff changeset
275 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
276 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
277
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
278 return returnValue;
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
279 }