Subversion Repositories Tewi

Rev

Rev 191 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 191 Rev 212
Line 1... Line 1...
1
/* $Id: log.c 191 2024-09-29 05:11:20Z nishi $ */
1
/* $Id: log.c 212 2024-10-02 17:44:55Z nishi $ */
2
 
2
 
3
#include "cm_log.h"
3
#include "cm_log.h"
4
 
4
 
5
#include "cm_string.h"
5
#include "cm_string.h"
6
 
6
 
Line 39... Line 39...
39
#endif
39
#endif
40
	fflush(logfile);
40
	fflush(logfile);
41
}
41
}
42
 
42
 
43
void cm_log(const char* name, const char* log, ...) {
43
void cm_log(const char* name, const char* log, ...) {
44
	if(!cm_do_log) return;
-
 
45
	va_list args;
44
	va_list args;
46
	va_start(args, log);
-
 
47
	char namebuf[LOGNAME_LENGTH + 1];
45
	char namebuf[LOGNAME_LENGTH + 1];
-
 
46
	int i;
-
 
47
	char* result;
-
 
48
	char cbuf[2];
-
 
49
	if(!cm_do_log) return;
-
 
50
	va_start(args, log);
48
	memset(namebuf, '.', LOGNAME_LENGTH);
51
	memset(namebuf, '.', LOGNAME_LENGTH);
49
	namebuf[LOGNAME_LENGTH] = 0;
52
	namebuf[LOGNAME_LENGTH] = 0;
50
	int i;
-
 
51
	for(i = 0; name[i] != 0 && i < LOGNAME_LENGTH; i++) {
53
	for(i = 0; name[i] != 0 && i < LOGNAME_LENGTH; i++) {
52
		namebuf[i] = name[i];
54
		namebuf[i] = name[i];
53
	}
55
	}
54
 
56
 
55
	char* result = malloc(1);
57
	result = malloc(1);
56
	result[0] = 0;
58
	result[0] = 0;
57
 
59
 
58
	char cbuf[2];
-
 
59
	cbuf[1] = 0;
60
	cbuf[1] = 0;
60
 
61
 
61
	for(i = 0; log[i] != 0; i++) {
62
	for(i = 0; log[i] != 0; i++) {
62
		if(log[i] == '%') {
63
		if(log[i] == '%') {
63
			i++;
64
			i++;
Line 67... Line 68...
67
				result = cm_strcat(tmp, c == NULL ? "(null)" : c);
68
				result = cm_strcat(tmp, c == NULL ? "(null)" : c);
68
				free(tmp);
69
				free(tmp);
69
			} else if(log[i] == 'd') {
70
			} else if(log[i] == 'd') {
70
				int a = va_arg(args, int);
71
				int a = va_arg(args, int);
71
				char buf[128];
72
				char buf[128];
72
				sprintf(buf, "%d", a);
-
 
73
				char* tmp = result;
73
				char* tmp = result;
-
 
74
				sprintf(buf, "%d", a);
74
				result = cm_strcat(tmp, buf);
75
				result = cm_strcat(tmp, buf);
75
				free(tmp);
76
				free(tmp);
76
			}
77
			}
77
		} else {
78
		} else {
78
			cbuf[0] = log[i];
-
 
79
			char* tmp = result;
79
			char* tmp = result;
-
 
80
			cbuf[0] = log[i];
80
			result = cm_strcat(tmp, cbuf);
81
			result = cm_strcat(tmp, cbuf);
81
			free(tmp);
82
			free(tmp);
82
		}
83
		}
83
	}
84
	}
84
 
85