~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/debug.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: debug.cpp 11979 2008-01-24 18:47:05Z rubidium $ */
 
1
/* $Id: debug.cpp 15299 2009-01-31 20:16:06Z smatz $ */
2
2
 
3
 
/** @file debug.cpp */
 
3
/** @file debug.cpp Handling of printing debug messages. */
4
4
 
5
5
#include "stdafx.h"
6
6
#include <stdio.h>
7
7
#include <stdarg.h>
8
 
#include "openttd.h"
9
 
#include "console.h"
 
8
#include "console_func.h"
10
9
#include "debug.h"
11
10
#include "string_func.h"
12
11
#include "network/core/core.h"
 
12
#include "fileio_func.h"
13
13
 
14
14
#if defined(ENABLE_NETWORK)
15
15
SOCKET _debug_socket = INVALID_SOCKET;
30
30
int _debug_freetype_level;
31
31
int _debug_sl_level;
32
32
int _debug_station_level;
 
33
int _debug_gamelog_level;
 
34
int _debug_desync_level;
33
35
 
34
36
 
35
37
struct DebugLevel {
54
56
        DEBUG_LEVEL(freetype),
55
57
        DEBUG_LEVEL(sl),
56
58
        DEBUG_LEVEL(station),
 
59
        DEBUG_LEVEL(gamelog),
 
60
        DEBUG_LEVEL(desync),
57
61
        };
58
62
#undef DEBUG_LEVEL
59
63
 
60
64
#if !defined(NO_DEBUG_MESSAGES)
61
65
 
62
 
void CDECL debug(const char *dbg, ...)
 
66
static void debug_print(const char *dbg, const char *buf)
63
67
{
64
 
        va_list va;
65
 
        va_start(va, dbg);
66
 
        const char *s;
67
 
        char buf[1024];
68
 
 
69
 
        s = va_arg(va, const char*);
70
 
        vsnprintf(buf, lengthof(buf), s, va);
71
 
        va_end(va);
72
68
#if defined(ENABLE_NETWORK)
73
69
        if (_debug_socket != INVALID_SOCKET) {
74
 
                char buf2[lengthof(buf) + 32];
 
70
                char buf2[1024 + 32];
75
71
 
76
72
                snprintf(buf2, lengthof(buf2), "dbg: [%s] %s\n", dbg, buf);
77
 
                send(_debug_socket, buf2, strlen(buf2), 0);
 
73
                send(_debug_socket, buf2, (int)strlen(buf2), 0);
78
74
        } else
79
75
#endif /* ENABLE_NETWORK */
80
 
        {
 
76
        if (strcmp(dbg, "desync") != 0) {
81
77
#if defined(WINCE)
82
78
                /* We need to do OTTD2FS twice, but as it uses a static buffer, we need to store one temporary */
83
79
                TCHAR tbuf[512];
87
83
                fprintf(stderr, "dbg: [%s] %s\n", dbg, buf);
88
84
#endif
89
85
                IConsoleDebug(dbg, buf);
 
86
        } else {
 
87
                static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
 
88
                if (f == NULL) return;
 
89
 
 
90
                fprintf(f, "%s", buf);
 
91
                fflush(f);
90
92
        }
91
93
}
 
94
 
 
95
void CDECL debug(const char *dbg, ...)
 
96
{
 
97
        va_list va;
 
98
        va_start(va, dbg);
 
99
        const char *s;
 
100
        char buf[1024];
 
101
 
 
102
        s = va_arg(va, const char*);
 
103
        vsnprintf(buf, lengthof(buf), s, va);
 
104
        va_end(va);
 
105
 
 
106
        debug_print(dbg, buf);
 
107
}
92
108
#endif /* NO_DEBUG_MESSAGES */
93
109
 
94
110
void SetDebugString(const char *s)
155
171
 
156
172
        for (i++; i != endof(debug_level); i++) {
157
173
                snprintf(dbgval, sizeof(dbgval), ", %s=%d", i->name, *i->level);
158
 
                ttd_strlcat(dbgstr, dbgval, sizeof(dbgstr));
 
174
                strecat(dbgstr, dbgval, lastof(dbgstr));
159
175
        }
160
176
 
161
177
        return dbgstr;
162
178
}
163
 
 
164
 
#ifdef DEBUG_DUMP_COMMANDS
165
 
#include "fileio.h"
166
 
 
167
 
void CDECL DebugDumpCommands(const char *s, ...)
168
 
{
169
 
        static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
170
 
        if (f == NULL) return;
171
 
 
172
 
        va_list va;
173
 
        va_start(va, s);
174
 
        vfprintf(f, s, va);
175
 
        va_end(va);
176
 
 
177
 
        fflush(f);
178
 
}
179
 
#endif /* DEBUG_DUMP_COMMANDS */