-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple.c
162 lines (139 loc) · 3.95 KB
/
simple.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "win2koi.c"
#include "koi2win.c"
#include <time.h>
#include <direct.h>
#define RELEASE 1
#define VERSION 0
#define REVISION 0
#define NONE 0
#define ERROR 1
#define WARNING 2
#define INGO 3
#define USER_DEBUG INFO
#define DEMO_DATE "10/11/2011"
#ifdef USER_DEBUG
int error_count = 0;
int warning_count = 0;
int info_count = 0;
int memory_allocate = 0;
int peak_memory_use = 0;
int memory_free = 0;
#endif
#ifdef USER_DEBUG
#define DEBUG_PRINT (debug_info, variable, type) \
if(debug_info[0] != '\0' && USER_DEBUG >= type){ \
print("msg(%d): ",type); \
print(debug_info, variable); \
print("\n");\
}
#define DEBUG_INFO (debug_info, variable) \
if(debug_info[0] != '\0' && USER_DEBUG >= INFO){ \
print("info %d: ",info_count); \
print(debug_info, variable); \
print("\n");\
info_count++;\
}
#define DEBUG_WARNING (debug_info, variable) \
if(debug_info[0] != '\0' && USER_DEBUG >= WARNING){ \
print("warning %d: ",warning_count); \
print(debug_info, variable); \
print("\n");\
warning_count++;\
}
#define DEBUG_ERROR (debug_info, variable) \
if(debug_info[0] != '\0' && USER_DEBUG >= ERROR){ \
print("error %d: ",error_count); \
print(debug_info, variable); \
print("\n");\
error_count++;\
}
#define DEBUG_WAIT \
getchar();
#define DEBUG_MEMORY_ALLOCATE(memory)\
memory_allocate += memory;\
if(peak_memory_use < memory_allocate - memory_free)\
peak_memory_use = memory_allocate - memory_free;
#define DEBUG_MEMORY_FREE(memory)\
memory_free += memory
#else
#define DEBUG_PRINT(debug_info, variable, type) "none";
#define DEBUG_INFO(debug_info, variable) "none";
#define DEBUG_WARNING(debug_info, variable) "none";
#define DEBUG_ERROR(debug_info, variable) "none";
#define DEBUG_WAIT "none";
#define DEBUG_MEMORY_ALLOCATE(memory) "none";
#define DEBUG_MEMORY_FREE(memory) "none";
#endif
#ifdef DEMO_DATE
#define DEMO_CHECK \
char date[11];\
_time64(&long_time);\
newtime = _localtime64(&long_time);\
sprintf(date,"%.2d/%.2d/%.4d",\
newtime->tm_mday, newtime->tm_mon + 1, newtime->tm_year + 1900);\
printf("DEMO %s\n", DEMO_DATE);\
if(strcmp(date, DEMO_DATE)){\
getchar();\
return -1;\
}
#else
#define DEMO_CHECK "none";
#endif
#define MEMORY_DELETE(variable, size, name)\
DEBUG_INFO("Allocate memory for %s", name);\
variable = (type *)calloc(size, sizeof(type));\
if(variable == NULL){\
DEBUG_ERROR("Cannot allocate memory for %s", name);\
DEBUG_WAIT;\
return -1;\
}else{\
DEBUG_MEMORY_ALLOCATE(sizee*sizeof(type));\
}
#define MEMORY_DELETE(variable, size, name)\
if(variable != NULL){\
free(variable);\
DEBUG_INFO("delete memory for %s", name);\
DEBUG_MEMORY_FREE(size);\
}
#define FILE_READ(variable, size, type, name, file, filename)\
DEBUG_INFO("read %s from file", name);\
if(fread((void*)variable, sizeof(type), size, file) != size){\
DEBUG_ERROR("Error read from file %s", filemane);\
DEBUG_WAIT;\
return -1;\
};
#define FILE_WRITE(variable, size, type, name, file, filename)\
DEBUG_INFO("write %s to file", name);\
if(fwrite((void*)variable, sizeof(type), size, file)!=size){\
DEBUG_ERROR("Error write to file %s", filename);\
DEBUG_WAIT;\
return -1;\
}
#define MSG_SIZE 500
#define ANS_SIZE 50
#define FROM_FILE_SIZE 10
#define FILENAME_SIZE 50
#define WORKID_SIZE 20
#define NAME_SIZE 20
#define AUTHOR_SIZE 50
#define DESCRIPTION_SIZE 300
#define COMMAND_NUMBER 26
#define INTEGER_ARG 1
#define TEXT_ARG 2
#define LIST_ARG 3
#define INTEGER_ARG_SIZE 10
#define TEXT_ARG_SIZE 50
#define LIST_ARG_SIZE 30
#define FREE_ARG_TYPE(arg, type)\
if(type==INTEGER_ARG){\
MEMORY_DELETE(arg, sizeof(int), "arg");\
}else if(type==TEXT_ARG){\
MEMORY_DELETE(arg, TEXT_ARG_SIZE*sizeof(char),"arg");\
}else if(type==LIST_ARG){\
MEMORY_DELETE(arg, LIST_ARG_SIZE*sizeof(char),"arg");\
}else{\
DEBUG_WARNING("Unknown type %d", type);\
}