This repository has been archived by the owner on Jul 4, 2024. It is now read-only.
forked from adamjimenez/ChaosGroove
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.cpp
99 lines (73 loc) · 1.78 KB
/
log.cpp
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
// Log (.Cpp)
// --------
#include <stdio.h>
#include <stdarg.h>
#include "log.hpp"
#include "Game.hpp"
// Logging functions:
// ------------------
FILE *log_file;
int open_log(char *filename)
{
if ((log_file = fopen(filename, "w")) != NULL) return 0; /* Opened succesfully. */
return -1; /* Failed. */
}
int log(char *format, ...)
{
va_list ptr; /* get an arg pointer */
int status = -1;
if (log_file != NULL)
{
/* initialize ptr to point to the first argument after the format string */
va_start(ptr, format);
/* Write to logfile. */
status = vfprintf(log_file, format, ptr); // Write passed text.
fprintf(log_file, "\n"); // New line..
va_end(ptr);
/* Flush file. */
fflush(log_file);
}
return status;
}
// Same as log, except it doesn't write a Carriage Return character at the
// end of the line.
int log_no_cr(char *format, ...)
{
va_list ptr; /* get an arg pointer */
int status = -1;
if (log_file != NULL)
{
/* initialize ptr to point to the first argument after the format string */
va_start(ptr, format);
/* Write to logfile. */
status = vfprintf(log_file, format, ptr); // Write passed text.
va_end(ptr);
/* Flush file. */
fflush(log_file);
}
return status;
}
int close_log(void)
{
int status = -1;
if (log_file != NULL)
{
fflush(log_file);
fclose(log_file);
return 0;
}
return status;
}
// Support functions.
int log_header(void)
{
// Write the log header file with the details of the game name, author etc.
// These are all defines listed in "game.h"
log(GAME_NAME);
log("----------------------------------------------------");
log("Version : %s, Started : %s", GAME_VERSION, GAME_DATE);
log("Author : %s", GAME_AUTHOR);
log("----------------------------------------------------");
log("");
return 0;
}