This commit is contained in:
MapleSign 2018-08-03 19:48:51 +08:00
commit 61110f5af9
20 changed files with 707 additions and 203 deletions

View File

@ -120,6 +120,7 @@
927993B420CB87D6008CE3A9 = {
isa = PBXGroup;
children = (
92A15CFC211442C700826FB8 /* graph */,
9286EB7C2114021E00752977 /* communicate */,
9286EB78211400BD00752977 /* error */,
9269D4F1210F1B9E00161557 /* id */,
@ -159,6 +160,13 @@
name = communicate;
sourceTree = "<group>";
};
92A15CFC211442C700826FB8 /* graph */ = {
isa = PBXGroup;
children = (
);
name = graph;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */

View File

@ -3,10 +3,33 @@
version = "1.0">
<ContextStates>
<ContextState
contextName = "init_node:list.h">
contextName = "freeS_id:id.c">
</ContextState>
<ContextState
contextName = "asciiStringToS_id:id.c">
<PersistentStrings>
<PersistentString
value = "list_list">
value = "buff[string_len-1]">
</PersistentString>
<PersistentString
value = "5 + i * 5 + j">
</PersistentString>
<PersistentString
value = "s_id-&gt;value[i]">
</PersistentString>
<PersistentString
value = "strlen(string)">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "s_idToASCIIString:id.c">
<PersistentStrings>
<PersistentString
value = "sizeof(char)">
</PersistentString>
<PersistentString
value = "buff[buff_count]">
</PersistentString>
</PersistentStrings>
</ContextState>
@ -27,8 +50,27 @@
<ContextState
contextName = "releaseMalloc:list.h">
</ContextState>
<ContextState
contextName = "init_node:list.h">
<PersistentStrings>
<PersistentString
value = "list_list">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState
contextName = "initS_id:id.c">
</ContextState>
<ContextState
contextName = "init_list:list.h">
</ContextState>
<ContextState
contextName = "main:test.c">
<PersistentStrings>
<PersistentString
value = "strlen(string)">
</PersistentString>
</PersistentStrings>
</ContextState>
</ContextStates>
</VariablesViewState>

View File

@ -154,7 +154,7 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "test.c"
timestampString = "554959944.593868"
timestampString = "554986718.90595"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "64"
@ -170,7 +170,7 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "tree/tree_expand.c"
timestampString = "554638722.806551"
timestampString = "554986718.906049"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "60"
@ -179,5 +179,344 @@
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.906109"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "19"
endingLineNumber = "19"
landmarkName = "initS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.906213"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "99"
endingLineNumber = "99"
landmarkName = "simFitS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.906307"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "102"
endingLineNumber = "102"
landmarkName = "unknown"
landmarkType = "0">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.906399"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "122"
endingLineNumber = "122"
landmarkName = "s_idToASCIIString"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.90649"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "136"
endingLineNumber = "136"
landmarkName = "s_idToASCIIString"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
condition = "buff_count == 26"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.906581"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "128"
endingLineNumber = "128"
landmarkName = "s_idToASCIIString"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
condition = "string_len != 25"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.90667"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "191"
endingLineNumber = "191"
landmarkName = "asciiStringToS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.906878"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "133"
endingLineNumber = "133"
landmarkName = "s_idToASCIIString"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
condition = "buff_count == 26"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.906978"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "139"
endingLineNumber = "139"
landmarkName = "s_idToASCIIString"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.907084"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "143"
endingLineNumber = "143"
landmarkName = "s_idToASCIIString"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.907181"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "147"
endingLineNumber = "147"
landmarkName = "s_idToASCIIString"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.9072779"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "197"
endingLineNumber = "197"
landmarkName = "asciiStringToS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.90737"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "240"
endingLineNumber = "240"
landmarkName = "asciiStringToS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.90746"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "184"
endingLineNumber = "184"
landmarkName = "s_idToASCIIString"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.907542"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "23"
endingLineNumber = "23"
landmarkName = "initS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.9076231"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "196"
endingLineNumber = "196"
landmarkName = "asciiStringToS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.907701"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "204"
endingLineNumber = "204"
landmarkName = "asciiStringToS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.907778"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "126"
endingLineNumber = "126"
landmarkName = "s_idToASCIIString"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.9078521"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "206"
endingLineNumber = "206"
landmarkName = "asciiStringToS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.9079241"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "239"
endingLineNumber = "239"
landmarkName = "asciiStringToS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554986718.908048"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "217"
endingLineNumber = "217"
landmarkName = "asciiStringToS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>

View File

@ -52,32 +52,7 @@ int loadFromFile(FILE *fp,char* number) {
return 1;
}
int pushInfo(Info *p_info, const char *head, const char *body) {
p_info->head = (char *)malloc(sizeof(char) * strlen(head));
p_info->body = (char *)malloc(sizeof(char) * strlen(body));
strcpy(p_info->head, head);
strcpy(p_info->body, body);
return 0;
}
int pushError(unsigned int type, int pri, Info *p_info) {
Error error;
error.type = type;
error.priority = pri;
error.p_info = p_info;
error.time = time(NULL);
return 0;
}
int pushNotice(unsigned int type, Info *p_info) {
Notice notice;
notice.type = type;
notice.p_info = p_info;
notice.time = time(NULL);
return 0;
}
static int saveError(Error *p_error) {
int saveError(Error *p_error) {
fprintf(logfile.fp,
"--------------------\n\
ERROR\n\
@ -88,10 +63,10 @@ static int saveError(Error *p_error) {
%s\n\
%s\n\
---------------------\n",
p_error->type, p_error->priority, ctime( &(p_error->time) ), p_error->p_info->head, p_error->p_info->body);
p_error->type, p_error->priority, ctime( &(p_error->time) ), p_error->info.head, p_error->info.body);
return 0;
}
static int saveNotice(Notice *p_notice) {
int saveNotice(Notice *p_notice) {
fprintf(logfile.fp,
"--------------------\n\
NOTICE\n\
@ -101,6 +76,6 @@ static int saveNotice(Notice *p_notice) {
%s\n\
%s\n\
----------------------\n",
p_notice->type, ctime( &(p_notice->time) ), p_notice->p_info->head, p_notice->p_info->body);
p_notice->type, ctime( &(p_notice->time) ), p_notice->info.head, p_notice->info.body);
return 0;
}

View File

@ -1,37 +1,8 @@
#include "../list/list_expand.h"
#include <string.h>
#include <time.h>
#ifndef ERROR_H
#define ERROR_H
#define HIGH 0x3
#define STANDARD 0x2
#define LOW 0x1
typedef struct Info{
char *head;
char *body;
}Info;
typedef struct Error{
unsigned int type;
int priority;
Info *p_info;
time_t time;
}Error;
typedef struct Notice{
unsigned int type;
Info *p_info;
time_t time;
}Notice;
typedef struct Log{
FILE *fp;
int if_enable;
unsigned long int id;
}Log;
#include "../type/type.h"
#include "../list/list_expand.h"
Log logfile;
List *error_list = NULL;
@ -42,14 +13,10 @@ int initErrorSystem(void);
int setLogDirectory(const char *path);
int closeLogDirectory(void);
int loadFromFile(FILE *fp,char* number);
int pushInfo(Info *p_info, const char *head,const char *body);
int pushError(unsigned int type, int pri, Info *p_info);
int pushNotice(unsigned int type, Info *p_info);
//为保证处理效果,不允许外调下列函数
static int saveError(Error *p_error);
static int saveNotice(Notice *p_notice);
int saveError(Error *p_error);
int saveNotice(Notice *p_notice);
#endif

112
id/id.c
View File

@ -16,36 +16,43 @@ unsigned long long getId(void) {
}
SID *initS_id(unsigned int deep_level){
SID *p_sid = (SID *)malloc(sizeof(SID));
SID *p_sid = (SID *) malloc(sizeof(SID));
if(p_sid == NULL){
printf("\ninitS_id(): Error in getting the memory of sid.\n");
}
p_sid->type = VOID;
p_sid->deep = deep_level;
p_sid->value = NULL;
p_sid->value_deeper = NULL;
p_sid->value_deepest = NULL;
if (deep_level > 0) p_sid->value = (unsigned int (*)[DEEPC_LEN])malloc(sizeof(unsigned int)*DEEPC_LEN);
if (deep_level > 1) p_sid->value_deeper = (unsigned int (*)[DEEPB_LEN])malloc(sizeof(unsigned int)*DEEPB_LEN);
if (deep_level > 2) p_sid->value_deepest = (unsigned int (*)[DEEPA_LEN])malloc(sizeof(unsigned int)*DEEPA_LEN);
if (deep_level > 0) {
p_sid->value = (unsigned int *)malloc(sizeof(unsigned int)*DEEPC_LEN);
if(p_sid->value == NULL){
printf("\ninitS_id(): Error in getting the memory of sid.value.\n");
}
}
if (deep_level > 1){
p_sid->value_deeper = (unsigned int *)malloc(sizeof(unsigned int)*DEEPB_LEN);
if(p_sid->value_deeper == NULL){
printf("\ninitS_id(): Error in getting the memory of sid.value_deeper.\n");
}
}
if (deep_level > 2){
p_sid->value_deepest = (unsigned int *)malloc(sizeof(unsigned int)*DEEPA_LEN);
if(p_sid->value_deepest == NULL){
printf("\ninitS_id(): Error in getting the memory of sid.value_deepest.\n");
}
}
return p_sid;
}
SID *getS_id(unsigned int type, unsigned int deep_level){
SID *p_sid = (SID *)malloc(sizeof(SID));
SID *p_sid = initS_id(deep_level);
p_sid->type = type;
p_sid->deep = deep_level;
p_sid->value = NULL;
p_sid->value_deeper = NULL;
p_sid->value_deepest = NULL;
if(deep_level > 0){
p_sid->value = (unsigned int (*)[DEEPC_LEN])malloc(sizeof(unsigned int)*DEEPC_LEN);
for(int i = 0; i < DEEPC_LEN; i++) (*p_sid->value)[i] = rand()%65535;
if(deep_level > 1){
p_sid->value_deeper = (unsigned int (*)[DEEPB_LEN])malloc(sizeof(unsigned int)*DEEPB_LEN);
for(int i = 0; i < DEEPB_LEN; i++) (*p_sid->value_deeper)[i] = rand()%65535;
}
if (deep_level > 2) {
p_sid->value_deepest = (unsigned int (*)[DEEPA_LEN])malloc(sizeof(unsigned int)*DEEPA_LEN);
for(int i = 0; i < DEEPA_LEN; i++) (*p_sid->value_deepest)[i] = rand()%65535;
}
for(int i = 0; i < DEEPC_LEN; i++) p_sid->value[i] = rand()%65535;
if(deep_level > 1) for(int i = 0; i < DEEPB_LEN; i++) p_sid->value_deeper[i] = rand()%65535;
if (deep_level > 2) for(int i = 0; i < DEEPA_LEN; i++) p_sid->value_deepest[i] = rand()%65535;
}
return p_sid;
@ -56,20 +63,20 @@ int fitS_id(const SID *fs_id, const SID *ss_id){
if(fs_id->deep == ss_id->deep){
if (fs_id->deep > 0)
for(int i = 0; i < DEEPC_LEN; i++){
if((*fs_id->value)[i] == (*ss_id->value)[i]) continue;
else if((*fs_id->value)[i] > (*ss_id->value)[i]) return 1;
if(fs_id->value[i] == ss_id->value[i]) continue;
else if(fs_id->value[i] > ss_id->value[i]) return 1;
else return -1;
}
if (fs_id->deep > 1)
for(int i = 0; i < DEEPB_LEN; i++){
if((*fs_id->value_deeper)[i] == (*ss_id->value_deeper)[i]) continue;
else if((*fs_id->value_deeper)[i] > (*ss_id->value_deeper)[i]) return 1;
if(fs_id->value_deeper[i] == ss_id->value_deeper[i]) continue;
else if(fs_id->value_deeper[i] > ss_id->value_deeper[i]) return 1;
else return -1;
}
if (fs_id->deep > 2)
for(int i = 0; i < DEEPA_LEN; i++){
if((*fs_id->value_deepest)[i] == (*ss_id->value_deepest)[i]) continue;
else if((*fs_id->value_deepest)[i] > (*ss_id->value_deepest)[i]) return 1;
if(fs_id->value_deepest[i] == ss_id->value_deepest[i]) continue;
else if(fs_id->value_deepest[i] > ss_id->value_deepest[i]) return 1;
else return -1;
}
}
@ -95,20 +102,23 @@ char *s_idToASCIIString(const SID *s_id){
unsigned int buff[DATA_BIT];
if(s_id->deep > 0){
if (s_id->deep == DEEPC){
string = (char *) malloc(sizeof(char) * (DEEPC_LEN + 1) * DATA_BIT + 1);
string = (char *) malloc(sizeof(char) * (DEEPC_LEN + 1) * DATA_BIT);
deep_len = DEEPC_LEN + 1;
deep_len *= DATA_BIT;
}
else if (s_id->deep == DEEPB){
string = (char *) malloc(sizeof(char) * (DEEPC_LEN + DEEPB_LEN + 1) * DATA_BIT + 1);
string = (char *) malloc(sizeof(char) * (DEEPC_LEN + DEEPB_LEN + 1) * DATA_BIT);
deep_len = DEEPC_LEN + DEEPB_LEN + 1;
deep_len *= DATA_BIT;
}
else{
string = (char *)malloc(sizeof(char) * (DEEPC_LEN + DEEPB_LEN + DEEPA_LEN + 1) * DATA_BIT + 1);
string = (char *)malloc(sizeof(char) * (DEEPC_LEN + DEEPB_LEN + DEEPA_LEN + 1) * DATA_BIT);
deep_len = DEEPC_LEN + DEEPB_LEN + DEEPA_LEN + 1;
deep_len *= DATA_BIT;
}
if(string == NULL){
printf("\ns_idToASCIIString(): Error in getting the memory of string.\n");
}
string[deep_len] = '\0';
temp = s_id->type;
buff_count = DATA_BIT - 1;
@ -121,7 +131,7 @@ char *s_idToASCIIString(const SID *s_id){
}
deep_len -= DATA_BIT;
for(int i = 0; i < DEEPC_LEN; i++){
temp = (*s_id->value)[i];
temp = s_id->value[i];
for (int i = 0; i < DATA_BIT; i++) buff[i] = 0;
string_count = TYPE_LEN + (i) * 5;
buff_count = DATA_BIT - 1;
@ -135,7 +145,7 @@ char *s_idToASCIIString(const SID *s_id){
deep_len -= DEEPC_LEN * DATA_BIT;
if(deep_len > 0)
for(int i = 0; i < DEEPB_LEN; i++){
temp = (*s_id->value_deeper)[i];
temp = s_id->value_deeper[i];
for (int i = 0; i < DATA_BIT; i++) buff[i] = 0;
string_count = TYPE_LEN + DEEPC_LEN * DATA_BIT + (i) * DATA_BIT;
buff_count = DATA_BIT - 1;
@ -150,7 +160,7 @@ char *s_idToASCIIString(const SID *s_id){
deep_len -= DEEPB_LEN * DATA_BIT;
if(deep_len > 0)
for(int i = 0; i < DEEPA_LEN; i++){
temp = (*s_id->value_deepest)[i];
temp = s_id->value_deepest[i];
for (int i = 0; i < DATA_BIT; i++) buff[i] = 0;
string_count = TYPE_LEN + (DEEPC_LEN + DEEPB_LEN) * DATA_BIT + (i) * DATA_BIT;
buff_count = DATA_BIT - 1;
@ -162,7 +172,6 @@ char *s_idToASCIIString(const SID *s_id){
}
for(int i = DATA_BIT - 1; i >= 0; i--) string[string_count + i] = buff[i] + 48;
}
printf("%s",string);
return string;
}
else{
@ -173,52 +182,53 @@ char *s_idToASCIIString(const SID *s_id){
SID *asciiStringToS_id(const char *string){
SID *s_id = NULL;
unsigned long long string_len = strlen(string);
unsigned int *buff = (unsigned int *) malloc(sizeof(string_len - 1));
for(int i = 0; i < string_len; i++){
buff[i] = string[i] - 48;
}
if (string_len == 25) s_id = initS_id(1);
else if (string_len == 65) s_id = initS_id(2);
else if (string_len == 225) s_id = initS_id(3);
else return NULL;
unsigned int *buff = (unsigned int *) malloc(sizeof(unsigned int) * (string_len));
if(buff == NULL){
printf("\ns_idToASCIIString(): Error in getting the memory of string.\n");
}
for(int i = 0; i < string_len; i++){
buff[i] = (unsigned int)string[i] - 48;
}
s_id->type = 0;
for (int i = 0; i < 5; i++){
s_id->type += buff[i] ;
s_id->type *= 10;
s_id->type *= 10u;
}
s_id->type /= 10;
s_id->type /= 10u;
if (string_len >= 25){
for(int i = 0; i < DEEPC_LEN; i++){
(*s_id->value)[i] = 0;
s_id->value[i] = 0;
for (int j = 0; j < 5; j++){
(*s_id->value)[i] += (int)buff[5 + i * 5 + j];
(*s_id->value)[i] *= 10;
s_id->value[i] += (unsigned int)buff[5 + i * 5 + j];
if(j < 4) s_id->value[i] *= 10;
}
(*s_id->value)[i] /= 10;
}
}
if (string_len >= 65){
for(int i = 0; i < DEEPB_LEN; i++){
(*s_id->value_deeper)[i] = 0;
s_id->value_deeper[i] = 0;
for (int j = 0; j < 5; j++){
(*s_id->value_deeper)[i] += buff[25 + i * 5 + j];
(*s_id->value_deeper)[i] *= 10;
s_id->value_deeper[i] += buff[25 + i * 5 + j];
if(j < 4) s_id->value_deeper[i] *= 10;
}
(*s_id->value_deeper)[i] /= 10;
}
}
if (string_len >= 225){
for(int i = 0; i < DEEPA_LEN; i++){
(*s_id->value_deepest)[i] = 0;
s_id->value_deepest[i] = 0;
for (int j = 0; j < 5; j++){
(*s_id->value_deepest)[i] += buff[65 + i * 5 + j];
(*s_id->value_deepest)[i] *= 10;
s_id->value_deepest[i] += buff[65 + i * 5 + j];
if(j < 4) s_id->value_deepest[i] *= 10;
}
(*s_id->value_deepest)[i] /= 10;
}
}
free(buff);

10
id/id.h
View File

@ -7,18 +7,10 @@
#include <time.h>
#include "../type/type.h"
typedef struct s_id{
unsigned int type;
unsigned int (*value)[DEEPC_LEN];//4
unsigned int (*value_deeper)[DEEPB_LEN];//8
unsigned int (*value_deepest)[DEEPA_LEN];//32
unsigned int deep;
}SID;
void init_rand(void);
unsigned long long getId(void);
SID *getS_id(unsigned int type ,unsigned int deep_level);
SID *getS_id(unsigned int type, unsigned int deep_level);
int fitS_id(const SID *fs_id, const SID *ss_id);
int simFitS_id(const SID *fs_id, const SID *ss_id);

View File

@ -8,8 +8,15 @@ int safeModeForNode(int ifon) {
if (ifon == 1) {
if (node_list == NULL && list_list == NULL) {
node_list = (List *)malloc(sizeof(List));
if(node_list == NULL){
showError(pushError(LIST, HIGH, initInfo("safeModeForNode()", "Error in get the memory of node_list.")));
return -1;
}
list_list = (List *)malloc(sizeof(List));
if(list_list == NULL){
showError(pushError(LIST, HIGH, initInfo("safeModeForNode()", "Error in get the memory of list_list.")));
return -1;
}
list_list->head = NULL;
list_list->length = 0;
list_list->tail = NULL;
@ -81,8 +88,13 @@ int releaseAllForNode(void) {
Node *initNode(void) {
Node *p_node = (Node *)malloc(sizeof(Node));
if(p_node == NULL){
showError(pushError(LIST_NODE, STANDARD, initInfo("initNode()", "Error in get the memory of node.")));
return NULL;
}
Node *prec_node = NULL;
p_node->s_id = getS_id(LIST_NODE, 2);
p_node->if_sid = 1;
p_node->if_malloc = 0;
p_node->next = NULL;
p_node->last = NULL;
@ -98,9 +110,14 @@ Node *initNode(void) {
}
List *initList(void) {
Node *p_node;
Node *p_node = NULL;
List *p_list = (List *)malloc(sizeof(List));
if(p_list == NULL){
showError(pushError(LIST_NODE, STANDARD, initInfo("initList()", "Error in get the memory of list.")));
return NULL;
}
p_list->s_id = getS_id(LIST, 1);
p_list->if_sid = 1;
p_list->head = NULL;
p_list->tail = NULL;
p_list->length = 0;
@ -297,7 +314,6 @@ int popFromTail(List *p_list) {
return 0;
}
/*该函数算法需要改进*/
Node *findByIdForNode(List *p_list, const SID *s_id) {
Node *ph_node = p_list->head;
Node *pt_node = p_list->tail;
@ -330,7 +346,7 @@ Node *findByValue(List *p_list, unsigned int type, const void *value) {
while (p_node != NULL) {
if (p_node->type != type) {
p_node = p_node->next;
continue;//跳过不合类型的节点
continue;
}
if (type == INT) {
if (*((int *)p_node->value) == *((int *)value)) {
@ -457,3 +473,95 @@ int releaseOnlyNode(Node *p_node) {
free(p_node);
return 0;
}
int releaseNodeForCustom(Node *p_node, int (*func)(void *)){
if (if_safeModeForNode == 1) {
removeByNode(node_list, p_node);
}
if (p_node->if_malloc == 1) {
if (!func(p_node->value))
showError(pushError(LIST_NODE, STANDARD, initInfo("releaseNodeForCustom()", "Error in using custom freeing value function.")));
p_node->value = NULL;
}
p_node->last = NULL;
p_node->next = NULL;
p_node->type = VOID;
p_node->value = NULL;
freeS_id(p_node->s_id);
p_node->if_malloc = 0;
free(p_node);
return 0;
}
int releaseListForCustom(List *p_list, int (*func)(void *)){
Node *p_node, *pl_node;
p_node = p_list->head;
if (if_safeModeForNode == 1) {
Node *tar_list = findByValue(list_list, POINTER, (void *)p_list);
removeByNode(list_list, tar_list);
}
while (p_node != NULL) {
pl_node = p_node;
p_node = p_node->next;
pl_node->next = NULL;
pl_node->last = NULL;
releaseNodeForCustom(pl_node,func);
}
p_list->head = NULL;
p_list->tail = NULL;
p_list->length = 0;
freeS_id(p_list->s_id);
free(p_list);
return 0;
}
int pushInfo(Info *p_info, const char *head, const char *body) {
strcpy(p_info->head, head);
strcpy(p_info->body, body);
return 0;
}
Error *pushError(unsigned int type, int pri, Info *p_info) {
Error *p_error = (Error *)malloc(sizeof(Error));
p_error->type = type;
p_error->priority = pri;
p_error->info = *p_info;
p_error->time = time(NULL);
free(p_info);
return p_error;
}
Notice *pushNotice(unsigned int type, Info *p_info) {
Notice *p_notice = (Notice *)malloc(sizeof(Notice));
p_notice->type = type;
p_notice->info = *p_info;
p_notice->time = time(NULL);
free(p_info);
return p_notice;
}
Info *initInfo(const char *head, const char *body){
Info *p_info = (Info *)malloc(sizeof(Info));
pushInfo(p_info, head, body);
return p_info;
}
int showError(Error *p_error){
printf("\n");
for (int i = 0; i < p_error->priority; i++) {
printf("!");
}
printf("(Error) %s\n",asctime(localtime(&p_error->time)));
printf("%s: %s.\n",p_error->info.head,p_error->info.body);
free(p_error);
return 0;
}
int showWarning(Notice *p_notice){
printf("\n@");
printf("(Warning) %s\n",asctime(localtime(&p_notice->time)));
printf("%s: %s.\n",p_notice->info.head,p_notice->info.body);
free(p_notice);
return 0;
}

View File

@ -1,31 +1,8 @@
#ifndef LIST_H
#define LIST_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "../type/type.h"
#include "../id/id.h"
typedef struct Node{
SID *s_id;
void *value;
_Bool if_malloc;
_Bool if_sid;
unsigned int type;
struct Node *next;
struct Node *last;
} Node;
typedef struct List{
SID *s_id;
Node *head;
Node *tail;
unsigned long long length;
} List;
int safeModeForNode(int ifon);
int releaseSingleListForsafeModeForNode(List *p_list);
int releaseSingleNodeForsafeModeForNode(List *p_list);
@ -55,13 +32,25 @@ Node *findByValue(List *p_list, unsigned int type, const void *value);
List *mply_findByValue(List *p_list, unsigned int type, const void *value);
int releaseList(List *p_list);
int releaseListForCustom(List *p_list, int (*func)(void *));
int releaseListForSingle(List *p_list);
int releaseNode(Node *p_node);
int releaseNodeForCustom(Node *p_node, int (*func)(void *));
int releaseOnlyNode(Node *p_node);
int isListEmpty(List *p_list);
List *copyList(List *p_list);
int pushInfo(Info *p_info, const char *head,const char *body);
Error *pushError(unsigned int type, int pri, Info *p_info);
Notice *pushNotice(unsigned int type, Info *p_info);
Info *initInfo(const char *head, const char *body);
Error *createError(Info *info,unsigned int type,int pri);
Notice *createWarning(Info *info, unsigned int type, int pri);
int showError(Error *);
int showWarning(Notice *);
static int if_safeModeForNode;
static List *node_list;
static List *list_list;

View File

@ -355,7 +355,7 @@ unsigned long long calListMemory(List * p_list){
unsigned long long nodes_size = 0LL;
unsigned long long list_size = sizeof(p_list);
while(p_node != NULL){
nodes_size += sizeof(p_node) + sizeof(*p_node->value);
nodes_size += sizeof(p_node);
p_node = p_node->next;
}
return list_size + nodes_size;

View File

@ -1,5 +1,6 @@
#ifndef LIST_EXPAND_H
#define LIST_EXPAND_H
#include "list.h"
Node *nodeWithInt(int);

View File

@ -2,6 +2,10 @@
Stack *initStack(void) {
Stack *p_stack = (Stack *)malloc(sizeof(Stack));
if(p_stack == NULL){
showError(pushError(STACK, STANDARD, initInfo("initStack()", "Error in get the memory of stack.")));
return NULL;
}
p_stack->s_id = getS_id(STACK, 1);
p_stack->length = 0;
p_stack->top = NULL;
@ -10,6 +14,10 @@ Stack *initStack(void) {
SNode *initSNode(void) {
SNode *p_snode = (SNode *)malloc(sizeof(SNode));
if(p_snode == NULL){
showError(pushError(STACK_NODE, STANDARD, initInfo("initSNode()", "Error in get the memory of snode.")));
return NULL;
}
p_snode->s_id = getS_id(STACK_NODE, 2);
p_snode->if_malloc = 0;
p_snode->next = NULL;

View File

@ -1,5 +1,3 @@
#include <stdlib.h>
#ifndef STACK_H
#define STACK_H
#include "../list/list_expand.h"

View File

@ -1,7 +1,6 @@
#ifndef STACK_EXPAND_H
#define STACK_EXPAND_H
#include <string.h>
#include "stack.h"
SNode *snodeWithInt(int);

5
test.c
View File

@ -84,10 +84,5 @@ int stack(void) {
int main(int argc, char **argv) {
//tree();
init_rand();
SID *p_sid = getS_id(LIST_NODE, 1);
char *string = s_idToASCIIString(p_sid);
SID *t_sid = asciiStringToS_id(string);
int if_same = simFitS_id(p_sid, t_sid);
getchar();
return 0;
}

4
test.h
View File

@ -1,11 +1,9 @@
#ifndef TEST_H
#define TEST_H
#include<stdio.h>
#include "type/type.h"
#include "list/list_expand.h"
#include "stack/stack_expand.h"
#include "tree/tree.h"
#include "tree/tree_expand.h"
int stack(void);

View File

@ -8,8 +8,15 @@ int safeModeForTree(int ifon) {
if (ifon == 1) {
if (tnode_list == NULL && tree_list == NULL) {
tnode_list = (List *)malloc(sizeof(List));
if(tnode_list == NULL){
showError(pushError(TREE_NODE, HIGH, initInfo("safeModeForTree()", "Error in get the memory of tnode_list.")));
return -1;
}
tree_list = (List *)malloc(sizeof(List));
if(tree_list == NULL){
showError(pushError(TREE_NODE, HIGH, initInfo("safeModeForTree()", "Error in get the memory of tree_list.")));
return -1;
}
tree_list->head = NULL;
tree_list->length = 0;
tree_list->tail = NULL;
@ -31,7 +38,12 @@ int safeModeForTree(int ifon) {
TNode *initTNode(void) {
Node *s_node;
TNode *p_tnode = (TNode *)malloc(sizeof(TNode));
if(p_tnode == NULL){
showError(pushError(TREE_NODE, STANDARD, initInfo("initTNode()", "Error in get the memory of tnode.")));
return NULL;
}
p_tnode->s_id = getS_id(TREE_NODE, 2);
p_tnode->if_sid = 1;
p_tnode->child_num = 0;
p_tnode->father = NULL;
p_tnode->if_malloc = 0;
@ -60,7 +72,12 @@ TNode *initTNode(void) {
Tree *initTree(void) {
Node *s_node;
Tree *p_tree = (Tree *)malloc(sizeof(Tree));
if(p_tree == NULL){
showError(pushError(TREE, STANDARD, initInfo("initTree()", "Error in get the memory of tree.")));
return NULL;
}
p_tree->s_id = getS_id(TREE, 1);
p_tree->if_sid = 1;
p_tree->root = NULL;
if (if_safeModeForTree) {
if (if_safeModeForNode) {

View File

@ -4,27 +4,6 @@
#include <stdio.h>
#include "../list/list_expand.h"
typedef struct tree_node
{
SID *s_id;
List *home;
struct tree_node *father;
Node *room;
unsigned long long child_num;
unsigned int type;
void *value;
_Bool if_malloc;
_Bool if_sid;
}TNode;
typedef struct tree
{
SID *s_id;
_Bool if_sid;
TNode *root;
}Tree;
int safeModeForTree(int ifon);
int releaseAllForTree(void);

View File

@ -222,6 +222,6 @@ unsigned long long calTreeMemory(Tree *p_tree){
}
int _doCalTreeMemory(TNode *p_tnode, unsigned long long height){
tnodes_size += sizeof(p_tnode) + sizeof(*p_tnode->value);
tnodes_size += sizeof(p_tnode);
return 0;
}

View File

@ -1,6 +1,11 @@
#ifndef type_h
#define type_h
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#define VOID 0
#define INT 1
#define DOUBLE 2
@ -12,17 +17,91 @@
#define LIST_NODE 8
#define TREE_NODE 9
#define STACK_NODE 10
#define TYPE_LEN 5
#define T_SID 11
#define DEEPC 1
#define DEEPB 2
#define DEEPA 3
#define TYPE_LEN 5
#define DEEPC_LEN 4
#define DEEPB_LEN 8
#define DEEPA_LEN 32
#define DATA_BIT 5
#define HIGH 0x3
#define STANDARD 0x2
#define LOW 0x1
typedef struct s_id{
unsigned int type;
unsigned int *value;//4
unsigned int *value_deeper;//8
unsigned int *value_deepest;//32
unsigned int deep;
}SID;
typedef struct Node{
SID *s_id;
void *value;
_Bool if_malloc;
_Bool if_sid;
unsigned int type;
struct Node *next;
struct Node *last;
} Node;
typedef struct List{
SID *s_id;
Node *head;
Node *tail;
_Bool if_sid;
unsigned long long length;
} List;
typedef struct Info{
char head[64];
char body[256];
}Info;
typedef struct Error{
unsigned int type;
int priority;
Info info;
time_t time;
}Error;
typedef struct Notice{
unsigned int type;
Info info;
time_t time;
}Notice;
typedef struct Log{
FILE *fp;
int if_enable;
unsigned long int id;
}Log;
typedef struct tree_node
{
SID *s_id;
List *home;
struct tree_node *father;
Node *room;
unsigned long long child_num;
unsigned int type;
void *value;
_Bool if_malloc;
_Bool if_sid;
}TNode;
typedef struct tree
{
SID *s_id;
_Bool if_sid;
TNode *root;
}Tree;
#endif /* type_h */