File: runtests.sh

package info (click to toggle)
cppcheck 2.20.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,924 kB
  • sloc: cpp: 274,396; python: 22,429; ansic: 8,103; sh: 1,094; makefile: 1,041; xml: 987; cs: 291
file content (662 lines) | stat: -rwxr-xr-x 21,025 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
#!/bin/bash
set -e # abort on error
#set -x # be verbose

# TODO: do not bail out on first error - always run all tests and return error instead

function exit_if_strict {
    if [ -n "${STRICT}" ] && [ "${STRICT}" -eq 1 ]; then
      exit 1
    fi
}

echo "Checking for pkg-config..."
if pkg-config --version; then
  HAS_PKG_CONFIG=1
  echo "pkg-config found."
else
  HAS_PKG_CONFIG=0
  echo "pkg-config is not available, skipping all syntax checks."
  exit_if_strict
fi

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/
CPPCHECK="$DIR"../../cppcheck
CFG="$DIR"../../cfg/

# TODO: remove missingInclude disabling when it no longer is implied by --enable=information
# Cppcheck options
# need to suppress unmatchedSuppression in case valueFlowBailout is not reported
CPPCHECK_OPT=(
    "--check-library"
    "--platform=unix64"
    "--enable=style,information"
    "--inconclusive"
    "--force"
    "--check-level=exhaustive"
    "--error-exitcode=-1"
    "--inline-suppr"
    "--template=\"{file}:{line}:{severity}:{id}:{message}\""
    "--debug-warnings"
    "--suppress=checkersReport")

# Compiler settings
CXX=g++
CXX_OPT=("-fsyntax-only" "-w" "-std=c++2a")
CC=gcc
CC_OPT=("-fsyntax-only" "-w" "-std=c11")

IWYU_OPTS=("-Xiwyu" "--no_fwd_decls" "-Xiwyu" "--update_comments")

function get_pkg_config_cflags {
    # TODO: get rid of the error enabling/disabling?
    set +e
    PKGCONFIG=$(pkg-config --cflags "$@")
    PKGCONFIG_RETURNCODE=$?
    set -e
    if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then
        PKGCONFIG=
    else
        # make sure the config is not empty when no flags were found - happens with e.g. libssl and sqlite3
        if [ -z "$PKGCONFIG" ]; then
            PKGCONFIG=" "
        fi
    fi
    echo "$PKGCONFIG"
}

function iwyu_run {
    # TODO: convert -I includes provided by pkg-config to -isystem so IWYU does not produce warnings for system headers
    ${IWYU} "${IWYU_OPTS[@]}" "${IWYU_CLANG_INC}" "$@"
}

function cc_syntax {
    if [ -z "$IWYU" ]; then
        ${CC} "${CC_OPT[@]}" "$@"
    else
        iwyu_run "${CC_OPT[@]}" "$@"
    fi
}

function cxx_syntax {
    if [ -z "$IWYU" ]; then
        ${CXX} "${CXX_OPT[@]}" "$@"
    else
        iwyu_run "${CXX_OPT[@]}" "$@"
    fi
}

function cppcheck_run {
    if [ -z "$IWYU" ]; then
        "${CPPCHECK}" "${CPPCHECK_OPT[@]}" "$@"
    fi
}

# posix.c
function posix_fn {
    echo "POSIX assumed to be present, checking syntax with ${CC} now."
    cc_syntax ${DIR}posix.c
}

# gnu.c
function gnu_fn {
    echo "GNU assumed to be present, checking syntax with ${CC} now."
    cc_syntax ${DIR}gnu.c
}

# qt.cpp
function qt_fn {
    if [ $HAS_PKG_CONFIG -eq 1 ]; then
        # TODO: check syntax with Qt5 and Qt6?
        QTCONFIG=$(get_pkg_config_cflags Qt6Core Qt6Test Qt6Gui)
        if [ -z "$QTCONFIG" ]; then
          QTCONFIG=$(get_pkg_config_cflags Qt5Core Qt5Test Qt5Gui)
          if [ -n "$QTCONFIG" ]; then
            QTBUILDCONFIG=$(pkg-config --variable=qt_config Qt5Core Qt5Test Qt5Gui)
            [[ $QTBUILDCONFIG =~ (^|[[:space:]])reduce_relocations($|[[:space:]]) ]] && QTCONFIG="${QTCONFIG} -fPIC"
          fi
        else
          QTBUILDCONFIG=$(pkg-config --variable=qt_config Qt6Core Qt6Test Qt6Gui)
          QTCONFIG="${QTCONFIG} -fPIC"
        fi
        if [ -n "$QTCONFIG" ]; then
            # TODO: get rid of the error enabling/disabling?
            set +e
            echo -e "#include <QString>" | ${CXX} "${CXX_OPT[@]}" ${QTCONFIG} -x c++ -
            QTCHECK_RETURNCODE=$?
            set -e
            if [ $QTCHECK_RETURNCODE -ne 0 ]; then
                echo "Qt not completely present or not working, skipping syntax check with ${CXX}."
                exit_if_strict
            else
                echo "Qt found and working, checking syntax with ${CXX} now."
                cxx_syntax ${QTCONFIG} ${DIR}qt.cpp
            fi
        else
            echo "Qt not present, skipping syntax check with ${CXX}."
            exit_if_strict
        fi
    fi
}

# bsd.c
function bsd_fn {
    # TODO: add syntax check
    true
}

# std.c
function std_c_fn {
    echo "C standard library assumed to be present, checking syntax with ${CC} now."
    cc_syntax "${DIR}"std.c
}

# std.cpp
function std_cpp_fn {
    echo "C++ standard library assumed to be present, checking syntax with ${CXX} now."
    cxx_syntax "${DIR}"std.cpp
}

# windows.cpp
function windows_fn {
    # TODO: Syntax check via g++ does not work because it can not find a valid windows.h
    #cxx_syntax ${DIR}windows.cpp
    true
}

# mfc.cpp
function mfc_fn {
    # TODO: Add syntax check
    true
}

# wxwidgets.cpp
function wxwidgets_fn {
    # TODO: get rid of the error enabling/disabling?
    set +e
    WXCONFIG=$(wx-config --cxxflags)
    WXCONFIG_RETURNCODE=$?
    set -e
    if [ $WXCONFIG_RETURNCODE -ne 0 ]; then
        echo "wx-config does not work, skipping syntax check for wxWidgets tests."
        exit_if_strict
    else
        # TODO: get rid of the error enabling/disabling?
        set +e
        echo -e "#include <wx/filefn.h>\n#include <wx/app.h>\n#include <wx/artprov.h>\n#include <wx/version.h>\n#if wxVERSION_NUMBER<2950\n#error \"Old version\"\n#endif" | ${CXX} "${CXX_OPT[@]}"  ${WXCONFIG} -x c++ -
        WXCHECK_RETURNCODE=$?
        set -e
        if [ $WXCHECK_RETURNCODE -ne 0 ]; then
            echo "wxWidgets not completely present (with GUI classes) or not working, skipping syntax check with ${CXX}."
            exit_if_strict
        else
            echo "wxWidgets found, checking syntax with ${CXX} now."
            cxx_syntax ${WXCONFIG} -Wno-deprecated-declarations "${DIR}"wxwidgets.cpp
        fi
    fi
}

# gtk.c
function gtk_fn {
    if [ $HAS_PKG_CONFIG -eq 1 ]; then
        GTKCONFIG=$(get_pkg_config_cflags gtk+-3.0)
        if [ -z "$GTKCONFIG" ]; then
            GTKCONFIG=$(get_pkg_config_cflags gtk+-2.0)
        fi
        if [ -n "$GTKCONFIG" ]; then
            # TODO: get rid of the error enabling/disabling?
            set +e
            echo -e "#include <gtk/gtk.h>" | ${CC} "${CC_OPT[@]}" ${GTKCONFIG} -x c -
            GTKCHECK_RETURNCODE=$?
            set -e
            if [ $GTKCHECK_RETURNCODE -ne 0 ]; then
                echo "GTK+ not completely present or not working, skipping syntax check with ${CC}."
                exit_if_strict
            else
                echo "GTK+ found and working, checking syntax with ${CC} now."
                cc_syntax ${GTKCONFIG} "${DIR}"gtk.c
            fi
        else
            echo "GTK+ not present, skipping syntax check with ${CC}."
            exit_if_strict
        fi
    fi
}

# boost.cpp
function boost_fn {
    # TODO: get rid of the error enabling/disabling?
    set +e
    echo -e "#include <boost/config.hpp>" | ${CXX} "${CXX_OPT[@]}" -x c++ -
    BOOSTCHECK_RETURNCODE=$?
    set -e
    if [ ${BOOSTCHECK_RETURNCODE} -ne 0 ]; then
        echo "Boost not completely present or not working, skipping syntax check with ${CXX}."
        exit_if_strict
    else
        echo "Boost found and working, checking syntax with ${CXX} now."
        cxx_syntax "${DIR}"boost.cpp
    fi
}

# sqlite3.c
function sqlite3_fn {
    if [ $HAS_PKG_CONFIG -eq 1 ]; then
        SQLITE3CONFIG=$(get_pkg_config_cflags sqlite3)
        if [ -n "$SQLITE3CONFIG" ]; then
            # TODO: get rid of the error enabling/disabling?
            set +e
            echo -e "#include <sqlite3.h>" | ${CC} "${CC_OPT[@]}" ${SQLITE3CONFIG} -x c -
            SQLITE3CHECK_RETURNCODE=$?
            set -e
            if [ $SQLITE3CHECK_RETURNCODE -ne 0 ]; then
                echo "SQLite3 not completely present or not working, skipping syntax check with ${CC}."
                exit_if_strict
            else
                echo "SQLite3 found and working, checking syntax with ${CC} now."
                cc_syntax ${SQLITE3CONFIG} "${DIR}"sqlite3.c
            fi
        else
            echo "SQLite3 not present, skipping syntax check with ${CC}."
            exit_if_strict
        fi
    fi
}

# openmp.c
function openmp_fn {
    # TODO: omp.h not found with IWYU
    # MacOS compiler has no OpenMP by default
    if ! command -v sw_vers; then
      echo "OpenMP assumed to be present, checking syntax with ${CC} now."
      cc_syntax -fopenmp ${DIR}openmp.c
    fi
}

# python.c
function python_fn {
    if [ $HAS_PKG_CONFIG -eq 1 ]; then
        PYTHON3CONFIG=$(get_pkg_config_cflags python3)
        if [ -n "$PYTHON3CONFIG" ]; then
            # TODO: get rid of the error enabling/disabling?
            set +e
            echo -e "#include <Python.h>" | ${CC} "${CC_OPT[@]}" ${PYTHON3CONFIG} -x c -
            PYTHON3CONFIG_RETURNCODE=$?
            set -e
            if [ $PYTHON3CONFIG_RETURNCODE -ne 0 ]; then
                echo "Python 3 not completely present or not working, skipping syntax check with ${CC}."
                exit_if_strict
            else
                echo "Python 3 found and working, checking syntax with ${CC} now."
                cc_syntax ${PYTHON3CONFIG} "${DIR}"python.c
            fi
        else
            echo "Python 3 not present, skipping syntax check with ${CC}."
            exit_if_strict
        fi
    fi
}

# lua.c
function lua_fn {
    if [ $HAS_PKG_CONFIG -eq 1 ]; then
        LUACONFIG=$(get_pkg_config_cflags lua)
        if [ -z "$LUACONFIG" ]; then
            LUACONFIG=$(get_pkg_config_cflags lua-5.3)
        fi
        if [ -n "$LUACONFIG" ]; then
            # TODO: get rid of the error enabling/disabling?
            set +e
            echo -e "#include <lua.h>" | ${CC} "${CC_OPT[@]}" ${LUACONFIG} -x c -
            LUACONFIG_RETURNCODE=$?
            set -e
            if [ $LUACONFIG_RETURNCODE -ne 0 ]; then
                echo "Lua not completely present or not working, skipping syntax check with ${CC}."
                exit_if_strict
            else
                echo "Lua found and working, checking syntax with ${CC} now."
                cc_syntax ${LUACONFIG} "${DIR}"lua.c
            fi
        else
            echo "Lua not present, skipping syntax check with ${CC}."
            exit_if_strict
        fi
    fi
}

# libcurl.c
function libcurl_fn {
    if [ $HAS_PKG_CONFIG -eq 1 ]; then
        LIBCURLCONFIG=$(get_pkg_config_cflags libcurl)
        if [ -n "$LIBCURLCONFIG" ]; then
            # TODO: get rid of the error enabling/disabling?
            set +e
            echo -e "#include <curl/curl.h>" | ${CC} "${CC_OPT[@]}" ${LIBCURLCONFIG} -x c -
            LIBCURLCONFIG_RETURNCODE=$?
            set -e
            if [ $LIBCURLCONFIG_RETURNCODE -ne 0 ]; then
                echo "libcurl not completely present or not working, skipping syntax check with ${CC}."
                exit_if_strict
            else
                echo "libcurl found and working, checking syntax with ${CC} now."
                cc_syntax ${LIBCURLCONFIG} "${DIR}"libcurl.c
            fi
        else
            echo "libcurl not present, skipping syntax check with ${CC}."
            exit_if_strict
        fi
    fi
}

# cairo.c
function cairo_fn {
    if [ $HAS_PKG_CONFIG -eq 1 ]; then
        CAIROCONFIG=$(get_pkg_config_cflags cairo)
        if [ -n "$CAIROCONFIG" ]; then
            # TODO: get rid of the error enabling/disabling?
            set +e
            echo -e "#include <cairo.h>" | ${CC} "${CC_OPT[@]}" ${CAIROCONFIG} -x c -
            CAIROCONFIG_RETURNCODE=$?
            set -e
            if [ $CAIROCONFIG_RETURNCODE -ne 0 ]; then
                echo "cairo not completely present or not working, skipping syntax check with ${CC}."
                exit_if_strict
            else
                echo "cairo found and working, checking syntax with ${CC} now."
                cc_syntax ${CAIROCONFIG} "${DIR}"cairo.c
            fi
        else
            echo "cairo not present, skipping syntax check with ${CC}."
            exit_if_strict
        fi
    fi
}

# googletest.cpp
function googletest_fn {
    # TODO: add syntax check
    true
}

# kde.cpp
function kde_fn {
    # TODO: get rid of the error enabling/disabling?
    set +e
    KDECONFIG=$(kde4-config --path include)
    KDECONFIG_RETURNCODE=$?
    set -e
    if [ $KDECONFIG_RETURNCODE -ne 0 ]; then
        echo "kde4-config does not work, skipping syntax check."
        exit_if_strict
    else
        KDEQTCONFIG=$(get_pkg_config_cflags QtCore)
        if [ -n "$KDEQTCONFIG" ]; then
            echo "Suitable Qt not present, Qt is necessary for KDE. Skipping syntax check."
            exit_if_strict
        else
            # TODO: get rid of the error enabling/disabling?
            set +e
            echo -e "#include <KDE/KGlobal>\n" | ${CXX} "${CXX_OPT[@]}" -isystem${KDECONFIG} ${KDEQTCONFIG} -x c++ -
            KDECHECK_RETURNCODE=$?
            set -e
            if [ $KDECHECK_RETURNCODE -ne 0 ]; then
                echo "KDE headers not completely present or not working, skipping syntax check with ${CXX}."
                exit_if_strict
            else
                echo "KDE found, checking syntax with ${CXX} now."
                cxx_syntax -isystem${KDECONFIG} ${KDEQTCONFIG} "${DIR}"kde.cpp
            fi
        fi
    fi
}

# libsigc++.cpp
function libsigcpp_fn {
    if [ $HAS_PKG_CONFIG -eq 1 ]; then
        LIBSIGCPPCONFIG=$(get_pkg_config_cflags sigc++-2.0)
        if [ -n "$LIBSIGCPPCONFIG" ]; then
            # TODO: get rid of the error enabling/disabling?
            set +e
            echo -e "#include <sigc++/sigc++.h>\n" | ${CXX} "${CXX_OPT[@]}" ${LIBSIGCPPCONFIG} -x c++ -
            LIBSIGCPPCONFIG_RETURNCODE=$?
            set -e
            if [ $LIBSIGCPPCONFIG_RETURNCODE -ne 0 ]; then
                echo "libsigc++ not completely present or not working, skipping syntax check with ${CXX}."
                exit_if_strict
            else
                echo "libsigc++ found and working, checking syntax with ${CXX} now."
                cxx_syntax ${LIBSIGCPPCONFIG} "${DIR}"libsigc++.cpp
            fi
        else
            echo "libsigc++ not present, skipping syntax check with ${CXX}."
            exit_if_strict
        fi
    fi
}

# openssl.c
function openssl_fn {
    if [ $HAS_PKG_CONFIG -eq 1 ]; then
        OPENSSLCONFIG=$(get_pkg_config_cflags libssl)
        if [ -n "$OPENSSLCONFIG" ]; then
            # TODO: get rid of the error enabling/disabling?
            set +e
            echo -e "#include <openssl/ssl.h>" | ${CC} "${CC_OPT[@]}" ${OPENSSLCONFIG} -x c -
            OPENSSLCONFIG_RETURNCODE=$?
            set -e
            if [ $OPENSSLCONFIG_RETURNCODE -ne 0 ]; then
                echo "OpenSSL not completely present or not working, skipping syntax check with ${CC}."
                exit_if_strict
            else
                echo "OpenSSL found and working, checking syntax with ${CC} now."
                cc_syntax ${OPENSSLCONFIG} "${DIR}"openssl.c
            fi
        else
            echo "OpenSSL not present, skipping syntax check with ${CC}."
            exit_if_strict
        fi
    fi
}

# opencv2.cpp
function opencv2_fn {
    if [ $HAS_PKG_CONFIG -eq 1 ]; then
        OPENCVCONFIG=$(get_pkg_config_cflags opencv)
        if [ -n "$OPENCVCONFIG" ]; then
            # TODO: get rid of the error enabling/disabling?
            set +e
            echo -e "#include <opencv2/opencv.hpp>\n" | ${CXX} "${CXX_OPT[@]}"  ${OPENCVCONFIG} -x c++ -
            OPENCVCONFIG_RETURNCODE=$?
            set -e
            if [ $OPENCVCONFIG_RETURNCODE -ne 0 ]; then
                echo "OpenCV not completely present or not working, skipping syntax check with ${CXX}."
                exit_if_strict
            else
                echo "OpenCV found and working, checking syntax with ${CXX} now."
                cxx_syntax ${OPENCVCONFIG} "${DIR}"opencv2.cpp
            fi
        else
            echo "OpenCV not present, skipping syntax check with ${CXX}."
            exit_if_strict
        fi
    fi
}

# cppunit.cpp
function cppunit_fn {
    if [ $HAS_PKG_CONFIG -eq 1 ]; then
        if ! pkg-config cppunit; then
            echo "cppunit not found, skipping syntax check for cppunit"
            exit_if_strict
        else
            echo "cppunit found, checking syntax with ${CXX} now."
            cxx_syntax -Wno-deprecated-declarations "${DIR}"cppunit.cpp
        fi
    fi
}

# emscripten.cpp
function emscripten_fn {
    # TODO: Syntax check via g++ does not work because it can not find a valid emscripten.h
    # cxx_syntax ${DIR}emscripten.cpp
    true
}

# selinux.c
function selinux_fn {
    # TODO: add syntax check
    true
}

function check_file {
    f=$(basename "$1")
    lib="${f%%.*}"
    case $f in
        boost.cpp)
            boost_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        bsd.c)
            bsd_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        cairo.c)
            cairo_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        cppunit.cpp)
            cppunit_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        emscripten.cpp)
            emscripten_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        gnu.c)
            gnu_fn
            # TODO: posix needs to specified first or it has a different mmap() config
            # TODO: get rid of posix dependency
            cppcheck_run --library=posix,"$lib" "${DIR}"gnu.c
            ;;
        googletest.cpp)
            googletest_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        gtk.c)
            gtk_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        kde.cpp)
            # TODO: "kde-4config" is no longer commonly available in recent distros
            #kde_fn
           cppcheck_run --library="$lib" --library=qt "${DIR}""$f"
            ;;
        libcurl.c)
            libcurl_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        libsigc++.cpp)
            libsigcpp_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        lua.c)
            lua_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        mfc.cpp)
            mfc_fn
            cppcheck_run --platform=win64 --library="$lib" "${DIR}""$f"
            ;;
        opencv2.cpp)
            # TODO: "opencv.pc" is not commonly available in distros
            #opencv2_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        openmp.c)
            openmp_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        openssl.c)
            openssl_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        posix.c)
            posix_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        python.c)
            python_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        qt.cpp)
            qt_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        selinux.c)
            selinux_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        sqlite3.c)
            sqlite3_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        std.c)
            std_c_fn
            cppcheck_run "${DIR}""$f"
            ;;
        std.cpp)
            std_cpp_fn
            cppcheck_run "${DIR}""$f"
            ;;
        windows.cpp)
            windows_fn
            cppcheck_run --platform=win32A --library="$lib" "${DIR}""$f"
            cppcheck_run --platform=win32W --library="$lib" "${DIR}""$f"
            cppcheck_run --platform=win64  --library="$lib" "${DIR}""$f"
            ;;
        wxwidgets.cpp)
            wxwidgets_fn
            cppcheck_run --library="$lib" "${DIR}""$f"
            ;;
        *)
          echo "Unhandled file $f"
          exit_if_strict
    esac
}

function check_files
{
for f in "$@"
do
    check_file "$f"
done
}

# Check the syntax of the defines in the configuration files
function check_defines_syntax
{
    if ! xmlstarlet --version; then
        echo "xmlstarlet needed to extract defines, skipping defines check."
        exit_if_strict
    else
        for configfile in "${CFG}"*.cfg; do
            echo "Checking defines in $configfile"
            # Disable debugging output temporarily since there could be many defines
            set +x
            # XMLStarlet returns 1 if no elements were found which is no problem here
            EXTRACTED_DEFINES=$(xmlstarlet sel -t -m '//define' -c . -n <"$configfile" || true)
            EXTRACTED_DEFINES=$(echo "$EXTRACTED_DEFINES" | sed 's/<define name="/#define /g' | sed 's/" value="/ /g' | sed 's/"\/>//g')
            echo "$EXTRACTED_DEFINES" | gcc -fsyntax-only -xc -Werror -
        done
    fi
}

if [ $# -eq 0  ]
then
    check_files "${DIR}"*.{c,cpp}
    check_defines_syntax
else
    check_files "$@"
fi

echo SUCCESS