File: main.cpp

package info (click to toggle)
swi-prolog 9.2.9%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 84,456 kB
  • sloc: ansic: 401,705; perl: 374,799; lisp: 9,080; cpp: 8,920; java: 5,525; sh: 3,282; javascript: 2,690; python: 2,655; ruby: 1,594; yacc: 845; makefile: 440; xml: 317; sed: 12; sql: 6
file content (162 lines) | stat: -rw-r--r-- 4,671 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*  Part of SWI-Prolog interface to Qt

    Author:        Carlo Capelli
    E-mail:        cc.carlo.cap@gmail.com
    Copyright (c)  2013-2015, Carlo Capelli
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:

    1. Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in
       the documentation and/or other materials provided with the
       distribution.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.
*/

#include <QApplication>
#include "pqMainWindow.h"
#include <QFile>
#include <QDebug>
#include <QTextStream>
#include "swipl_win.h"

#undef _SWI_CPP2_CPP_SEPARATE
#undef _SWI_CPP2_CPP_inline
#define _SWI_CPP2_CPP_SEPARATE
#define _SWI_CPP2_CPP_inline
#include <SWI-cpp2.cpp>

static FILE *logfile;
static bool  nolog = true;

#if QT_VERSION < 0x050000

static QtMsgHandler previous;

static void logger(QtMsgType type, const char *msg)
{
    if (!logfile) {
        if (previous)
            previous(type, msg);
        return;
    }

    switch (type) {
    case QtDebugMsg:
        fprintf(logfile, "Debug: %s\n", msg);
        break;
    case QtWarningMsg:
        fprintf(logfile, "Warning: %s\n", msg);
        break;
    case QtCriticalMsg:
        fprintf(logfile, "Critical: %s\n", msg);
        break;
    case QtFatalMsg:
        fprintf(logfile, "Fatal: %s\n", msg);
        abort();
    }

    fflush(logfile);
}

#else

static QtMessageHandler previous;
static void
logger(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
    if ( nolog )
        return;

    if (!logfile) {
        if (previous)
            previous(type, context, msg);
        return;
    }

    QByteArray localMsg = msg.toLocal8Bit();
    switch (type) {
    case QtDebugMsg:
        fprintf(logfile, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
        break;
    case QtWarningMsg:
        fprintf(logfile, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
        break;
    case QtCriticalMsg:
        fprintf(logfile, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
        break;
    case QtFatalMsg:
        fprintf(logfile, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
        abort();
        break;
#if QT_VERSION >= 0x050500
    case QtInfoMsg:
        fprintf(logfile, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
        break;
#endif
    }

    fflush(logfile);
}

#endif

/* Note that QApplication is created using new to avoid destruction
   on program shutdown.  Destroying causes a crash in XCloseDisplay()
   if xpce was started.
*/

int main(int argc, char *argv[]) {
    const char *logname;

    if ( (logname = getenv("QDEBUG")) ) {
        nolog = false;
        if ( strcmp(logname, "stderr") != 0 )
            logfile = fopen(logname, "w");
    }

#if QT_VERSION < 0x050000
    previous = qInstallMsgHandler(logger);
#else
    previous = qInstallMessageHandler(logger);
#endif

    auto a = new swipl_win(argc, argv);
    int rc = a->exec();
    qDebug() << "main loop finished" << rc;
delete a;
    return rc;
}


/* JW: Hack to compile swipl-win on MacOs 10.7 using g++ 4.8 while
   avoiding linking to a new C++ shared object.
*/

#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1070
namespace std {
void __throw_bad_function_call()
{ fprintf(stderr, "Bad function call\n");
  exit(1);
}
}
#endif