Added some functions and fixed.

This commit is contained in:
Saturneic 2018-08-03 18:32:20 +08:00
parent 5a96a5ab9e
commit 498d988a5e
17 changed files with 638 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 = "554985107.001519"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "64"
@ -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 = "554985107.0016969"
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 = "554985107.001803"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "81"
endingLineNumber = "81"
landmarkName = "s_idToASCIIString"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554985107.001882"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "84"
endingLineNumber = "84"
landmarkName = "s_idToASCIIString"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554985107.001967"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "101"
endingLineNumber = "101"
landmarkName = "s_idToASCIIString"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554985107.002043"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "115"
endingLineNumber = "115"
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 = "554985107.002121"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "107"
endingLineNumber = "107"
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 = "554985107.002201"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "170"
endingLineNumber = "170"
landmarkName = "asciiStringToS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554985107.002274"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "112"
endingLineNumber = "112"
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 = "554985107.002347"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "118"
endingLineNumber = "118"
landmarkName = "s_idToASCIIString"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554985107.002418"
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 = "554985107.0024869"
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 = "554985107.002557"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "174"
endingLineNumber = "174"
landmarkName = "asciiStringToS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554985107.002624"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "218"
endingLineNumber = "218"
landmarkName = "freeS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554985107.002689"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "163"
endingLineNumber = "163"
landmarkName = "asciiStringToS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554985107.002749"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "20"
endingLineNumber = "20"
landmarkName = "initS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554985107.002807"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "172"
endingLineNumber = "172"
landmarkName = "asciiStringToS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554985107.002861"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "182"
endingLineNumber = "182"
landmarkName = "asciiStringToS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554985107.002926"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "105"
endingLineNumber = "105"
landmarkName = "s_idToASCIIString"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554985107.002979"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "184"
endingLineNumber = "184"
landmarkName = "asciiStringToS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554985107.003031"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "217"
endingLineNumber = "217"
landmarkName = "freeS_id"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "id/id.c"
timestampString = "554985107.003078"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "195"
endingLineNumber = "195"
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

88
id/id.c
View File

@ -16,36 +16,25 @@ 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));
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 (deep_level > 1) p_sid->value_deeper = (unsigned int *)malloc(sizeof(unsigned int)*DEEPB_LEN);
if (deep_level > 2) p_sid->value_deepest = (unsigned int *)malloc(sizeof(unsigned int)*DEEPA_LEN);
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 +45,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,17 +84,17 @@ 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;
}
@ -121,7 +110,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 +124,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 +139,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 +151,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 +161,52 @@ 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));
for(int i = 0; i < string_len; i++){
buff[i] = (unsigned int)string[i] - 48;
}
printf("%s\n",string);
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);

18
id/id.h
View File

@ -1,11 +1,3 @@
//
// id.h
// ZE-Standard-Libraries
//
// Created by 胡一兵 on 2018/7/25.
// Copyright © 2018年 ZE. All rights reserved.
//
#ifndef id_h
#define id_h
@ -15,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

@ -83,6 +83,7 @@ Node *initNode(void) {
Node *p_node = (Node *)malloc(sizeof(Node));
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;
@ -101,6 +102,7 @@ List *initList(void) {
Node *p_node;
List *p_list = (List *)malloc(sizeof(List));
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 +299,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 +331,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 +458,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

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

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

@ -32,6 +32,7 @@ TNode *initTNode(void) {
Node *s_node;
TNode *p_tnode = (TNode *)malloc(sizeof(TNode));
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;
@ -61,6 +62,7 @@ Tree *initTree(void) {
Node *s_node;
Tree *p_tree = (Tree *)malloc(sizeof(Tree));
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

@ -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
@ -13,16 +18,89 @@
#define TREE_NODE 9
#define STACK_NODE 10
#define TYPE_LEN 5
#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 */