2018-02-18 06:32:58 +00:00
|
|
|
#include "error.h"
|
|
|
|
|
2018-08-02 12:59:06 +00:00
|
|
|
int initErrorSystem(void) {
|
2018-08-21 08:26:31 +00:00
|
|
|
error_list = initList(0);
|
|
|
|
notice_list = initList(0);
|
2018-08-02 12:59:06 +00:00
|
|
|
if_error = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int setLogDirectory(const char *path) {
|
|
|
|
logfile.id = getId();
|
2018-08-03 03:38:19 +00:00
|
|
|
unsigned long memory_space = strlen(path) + 256;
|
2018-08-02 12:59:06 +00:00
|
|
|
char *file_path = (char *)malloc(sizeof(char)*memory_space);
|
|
|
|
|
|
|
|
strcat(file_path, path);
|
|
|
|
strcat(file_path, "log");
|
2018-08-03 03:38:19 +00:00
|
|
|
sprintf(file_path, "%lu", logfile.id);
|
2018-08-02 12:59:06 +00:00
|
|
|
|
|
|
|
if ((logfile.fp = fopen(file_path, "w")) == NULL) {
|
|
|
|
printf("Cannot set logfile!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
logfile.if_enable = 1;
|
|
|
|
|
|
|
|
free(file_path);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int closeLogDirectory(void) {
|
|
|
|
Node *p = error_list->head;
|
|
|
|
while (p != NULL) {
|
|
|
|
saveError(p->value);
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = notice_list->head;
|
|
|
|
while (p != NULL) {
|
|
|
|
saveNotice(p->value);
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
releaseList(error_list);
|
|
|
|
releaseList(notice_list);
|
|
|
|
if_error = 0;
|
|
|
|
fclose(logfile.fp);
|
|
|
|
logfile.if_enable = 0;
|
2018-08-03 03:38:19 +00:00
|
|
|
return 0;
|
2018-08-02 12:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int loadFromFile(FILE *fp,char* number) {
|
2018-02-18 06:32:58 +00:00
|
|
|
|
2018-08-02 12:59:06 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-08-03 10:32:20 +00:00
|
|
|
int saveError(Error *p_error) {
|
2018-08-02 12:59:06 +00:00
|
|
|
fprintf(logfile.fp,
|
|
|
|
"--------------------\n\
|
|
|
|
ERROR\n\
|
|
|
|
Type : %ud\n\
|
|
|
|
Priority : %d\n\
|
|
|
|
Time : %s\n\
|
|
|
|
Info : \n\
|
|
|
|
%s\n\
|
|
|
|
%s\n\
|
|
|
|
---------------------\n",
|
2018-08-03 10:32:20 +00:00
|
|
|
p_error->type, p_error->priority, ctime( &(p_error->time) ), p_error->info.head, p_error->info.body);
|
2018-08-03 03:38:19 +00:00
|
|
|
return 0;
|
2018-02-18 06:32:58 +00:00
|
|
|
}
|
2018-08-03 10:32:20 +00:00
|
|
|
int saveNotice(Notice *p_notice) {
|
2018-08-02 12:59:06 +00:00
|
|
|
fprintf(logfile.fp,
|
|
|
|
"--------------------\n\
|
|
|
|
NOTICE\n\
|
|
|
|
Type : %ud\n\
|
|
|
|
Time : %s\n\
|
|
|
|
Info : \n\
|
|
|
|
%s\n\
|
|
|
|
%s\n\
|
|
|
|
----------------------\n",
|
2018-08-03 10:32:20 +00:00
|
|
|
p_notice->type, ctime( &(p_notice->time) ), p_notice->info.head, p_notice->info.body);
|
2018-08-03 03:38:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|