Upgraded the build system for KDE2.
[kdbg.git] / kdbg / main.cpp
blob36cf7bbb1b38370a44fceb0e7842bd0fd4672a97
1 // $Id$
3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
7 #include <kapp.h>
8 #if QT_VERSION >= 200
9 #include <klocale.h> /* i18n */
10 #include <kmessagebox.h>
11 #include <kglobal.h>
12 #include <kstddirs.h>
13 #include <kcmdlineargs.h>
14 #include <kaboutdata.h>
15 #include <khelpmenu.h>
16 #else // QT_VERSION < 200
17 #include <kmsgbox.h>
18 #endif
19 #include <kstdaccel.h>
20 #include <kmenubar.h>
21 #include "dbgmainwnd.h"
22 #include "typetable.h"
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 #ifndef VERSION
27 #define VERSION ""
28 #endif
29 #ifdef HAVE_FCNTL_H
30 #include <fcntl.h> /* open(2) */
31 #endif
32 #ifdef HAVE_UNISTD_H
33 #include <unistd.h> /* getopt(3) */
34 #endif
35 #include <stdlib.h> /* getenv(3) */
36 #include "mydebug.h"
39 int main(int argc, char** argv)
41 #if QT_VERSION < 200
42 KApplication app(argc, argv, "kdbg");
44 QString about = "KDbg " VERSION " - ";
45 about += i18n("A Debugger\n"
46 "by Johannes Sixt <Johannes.Sixt@telecom.at>\n"
47 "with the help of many others");
48 #else
49 static const char* description =
50 i18n("A Debugger");
52 KAboutData aboutData("kdbg", "KDbg",
53 VERSION,
54 description,
55 KAboutData::License_GPL,
56 "(c) 1998-2001 Johannes Sixt",
57 0, /* any text */
58 "http://members.nextra.at/johsixt/kdbg.html",
59 "Johannes.Sixt@telecom.at");
60 aboutData.addAuthor("Johannes Sixt", 0, "Johannes.Sixt@telecom.at");
61 aboutData.addCredit("Max Judin",
62 I18N_NOOP("Docking windows"),
63 "novaprint@mtu-net.ru");
64 KCmdLineArgs::init( argc, argv, &aboutData );
66 static KCmdLineOptions options[] = {
67 { "t <file>", I18N_NOOP("transcript of conversation with the debugger"), 0 },
68 { "r <device>", I18N_NOOP("remote debugging via <device>"), 0 },
69 { "+[program]", I18N_NOOP("path of executable to debug"), 0 },
70 { "+[core]", I18N_NOOP("a core file to use"), 0}
72 KCmdLineArgs::addCmdLineOptions(options);
74 KApplication app;
76 KGlobal::dirs()->addResourceType("types", "share/apps/kdbg/types");
77 #endif
79 keys = new KStdAccel();
81 DebuggerMainWnd debugger("kdbg_main");
83 // insert help menu
84 QPopupMenu* helpMenu;
85 #if QT_VERSION < 200
86 helpMenu = kapp->getHelpMenu(false, about);
87 #else
88 KHelpMenu* khm = new KHelpMenu(&debugger, &aboutData, false);
89 helpMenu = khm->menu();
90 #endif
91 debugger.menuBar()->insertSeparator();
92 debugger.menuBar()->insertItem(i18n("&Help"), helpMenu);
94 /* type libraries */
95 TypeTable::initTypeLibraries();
97 // session management
98 bool restored = false;
99 if (app.isRestored()) {
100 if (KTMainWindow::canBeRestored(1)) {
101 debugger.restore(1);
102 restored = true;
106 app.setMainWidget(&debugger);
108 debugger.show();
110 // handle options
112 #if QT_VERSION < 200
113 extern char *optarg;
114 extern int optind;
115 int ch;
117 const char* transcript = 0;
118 while ((ch = getopt(argc, argv, "r:t:")) != -1) {
119 switch (ch) {
120 case 'r':
121 debugger.setRemoteDevice(optarg);
122 break;
123 case 't':
124 transcript = optarg;
125 break;
126 default:
127 TRACE(QString().sprintf("ignoring option -%c", ch));
130 argc -= optind - 1;
131 argv += optind - 1;
132 #else
133 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
134 QCString t = args->getOption("t");
135 const char* transcript = t.data();
136 QString remote = args->getOption("r");
137 if (!remote.isEmpty())
138 debugger.setRemoteDevice(remote);
139 #endif
140 // check environment variable for transcript file name
141 if (transcript == 0) {
142 transcript = getenv("KDBG_TRANSCRIPT");
144 debugger.setTranscript(transcript);
146 #if QT_VERSION < 200
147 if (!restored && argc > 1) {
148 // check for core file
149 if (argc > 2) {
150 debugger.setCoreFile(argv[2]);
152 if (!debugger.debugProgram(argv[1])) {
153 // failed
154 TRACE("cannot start debugger");
155 KMsgBox::message(&debugger, kapp->appName(),
156 i18n("Cannot start debugger."),
157 KMsgBox::STOP,
158 i18n("OK"));
159 debugger.setCoreFile("");
162 #else
163 if (!restored && args->count() > 0) {
164 // check for core file
165 if (args->count() > 1) {
166 debugger.setCoreFile(args->arg(1));
168 if (!debugger.debugProgram(args->arg(0))) {
169 // failed
170 TRACE("cannot start debugger");
171 KMessageBox::error(&debugger, i18n("Cannot start debugger."));
172 debugger.setCoreFile("");
175 #endif
177 int rc = app.exec();
178 return rc;