-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdebug.c
executable file
·70 lines (57 loc) · 1.26 KB
/
debug.c
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
/*
* WSPR Toolkit for Linux
* ======================
* by DJ0ABR
*
* debug.c
*
* this program formats nice console messages
* and is used to print information of the program flow
* into the console
*
* */
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <pthread.h>
#include "debug.h"
#include "wsprtk.h"
int makeprot = 0;
void current_time(char *text)
{
struct timeval tv;
struct tm *tm;
gettimeofday(&tv, NULL);
tm = gmtime(&tv.tv_sec);
strftime(text,255,"%Y.%m.%d %H.%M.%S ",tm);
}
void deb_printf(char const *src, char *fmt, ...)
{
char s[10000];
char text[10000] = { "" };
va_list ap;
va_start(ap, fmt);
current_time(text);
sprintf(text+strlen(text),"[%9.9s] ", src);
vsprintf(s,fmt,ap);
sprintf(text+strlen(text),"%s\n",s);
va_end(ap);
// drucke in Konsole
for(int i=0; i<strlen(text); i++)
if(text[i] == '\n') text[i] = ' ';
printf("%s\n", text);
if(makeprot)
{
// und schreibe in Protokolldatei
FILE *fw=fopen("protokoll.txt","a");
if(fw)
{
fprintf(fw,"%s\n", text);
fclose(fw);
}
else
printf("kann Protokolldatei nicht öffnen\n");
}
}