Debian Codegraph @

ddebug/debug.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 * Copyright (C) 2024 Descent Developers
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <cstdio>
21 #include <cstdlib>
22 #include <cstring>
23
24 #include "debug.h"
25
26 void Debug_LogClose();
27
28 FILE *Debug_logfile = nullptr;
29
30 bool Debug_Logfile(const char *filename) {
31 if (Debug_logfile == nullptr) {
32 Debug_logfile = fopen(filename, "w");
33 if (Debug_logfile == nullptr) {
34 Debug_MessageBox(OSMBOX_OK, "Debug", "FYI Logfile couldn't be created.");
35 return false;
36 }
37 atexit(Debug_LogClose);
38 }
39 Debug_LogWrite("BEGINNING LOG\n\n");
40
41 return true;
42 }
43
44 void Debug_LogWrite(const char *str) {
45 if (Debug_logfile)
46 fwrite(str, strlen(str), 1, Debug_logfile);
47 }
48
49 void Debug_LogClose() {
50 if (Debug_logfile) {
51 Debug_LogWrite("\nEND LOG");
52 fclose(Debug_logfile);
53 Debug_logfile = nullptr;
54 }
55 }