First commit.
This commit is contained in:
parent
c22cb61054
commit
3b49e7e05f
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -7,7 +7,11 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
077B60801F066901001D40C4 /* Db.c in Sources */ = {isa = PBXBuildFile; fileRef = 077B607E1F066901001D40C4 /* Db.c */; };
|
||||
07DD47AF1EFE3B0500E42AD7 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 07DD47AE1EFE3B0500E42AD7 /* main.c */; };
|
||||
07FA738B1EFF3D9B001A0F2C /* List.c in Sources */ = {isa = PBXBuildFile; fileRef = 07FA73891EFF3D9B001A0F2C /* List.c */; };
|
||||
07FA738E1EFF3DE4001A0F2C /* Debug.c in Sources */ = {isa = PBXBuildFile; fileRef = 07FA738C1EFF3DE4001A0F2C /* Debug.c */; };
|
||||
07FA73911EFF3E36001A0F2C /* ID.c in Sources */ = {isa = PBXBuildFile; fileRef = 07FA738F1EFF3E36001A0F2C /* ID.c */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
@ -23,8 +27,17 @@
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
077B607E1F066901001D40C4 /* Db.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Db.c; sourceTree = "<group>"; };
|
||||
077B607F1F066901001D40C4 /* Db.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Db.h; sourceTree = "<group>"; };
|
||||
077B60811F066A49001D40C4 /* Support.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Support.h; sourceTree = "<group>"; };
|
||||
07DD47AB1EFE3B0500E42AD7 /* filesys */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = filesys; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
07DD47AE1EFE3B0500E42AD7 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
|
||||
07FA73891EFF3D9B001A0F2C /* List.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = List.c; sourceTree = "<group>"; };
|
||||
07FA738A1EFF3D9B001A0F2C /* List.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = List.h; sourceTree = "<group>"; };
|
||||
07FA738C1EFF3DE4001A0F2C /* Debug.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Debug.c; sourceTree = "<group>"; };
|
||||
07FA738D1EFF3DE4001A0F2C /* Debug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Debug.h; sourceTree = "<group>"; };
|
||||
07FA738F1EFF3E36001A0F2C /* ID.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ID.c; sourceTree = "<group>"; };
|
||||
07FA73901EFF3E36001A0F2C /* ID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ID.h; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@ -58,6 +71,15 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
07DD47AE1EFE3B0500E42AD7 /* main.c */,
|
||||
077B607E1F066901001D40C4 /* Db.c */,
|
||||
077B607F1F066901001D40C4 /* Db.h */,
|
||||
07FA738F1EFF3E36001A0F2C /* ID.c */,
|
||||
07FA73901EFF3E36001A0F2C /* ID.h */,
|
||||
07FA738C1EFF3DE4001A0F2C /* Debug.c */,
|
||||
07FA738D1EFF3DE4001A0F2C /* Debug.h */,
|
||||
07FA73891EFF3D9B001A0F2C /* List.c */,
|
||||
07FA738A1EFF3D9B001A0F2C /* List.h */,
|
||||
077B60811F066A49001D40C4 /* Support.h */,
|
||||
);
|
||||
path = filesys;
|
||||
sourceTree = "<group>";
|
||||
@ -119,7 +141,11 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
07FA738E1EFF3DE4001A0F2C /* Debug.c in Sources */,
|
||||
077B60801F066901001D40C4 /* Db.c in Sources */,
|
||||
07DD47AF1EFE3B0500E42AD7 /* main.c in Sources */,
|
||||
07FA73911EFF3E36001A0F2C /* ID.c in Sources */,
|
||||
07FA738B1EFF3D9B001A0F2C /* List.c in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -248,6 +274,7 @@
|
||||
07DD47B41EFE3B0500E42AD7 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
|
20
filesys/Db.c
Normal file
20
filesys/Db.c
Normal file
@ -0,0 +1,20 @@
|
||||
//
|
||||
// db.c
|
||||
// filesys
|
||||
//
|
||||
// Created by Saturneric on 2017/6/30.
|
||||
// Copyright © 2017年 Bakantu Eric. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Db.h"
|
||||
#include "List.h"
|
||||
|
||||
int build_database(DB_CREATE_INFO * p_db_cte_ifo){
|
||||
char db_path[64];
|
||||
int mk_return = -1;
|
||||
sprintf(db_path,"%s%s/",path,p_db_cte_ifo->name);
|
||||
printf("DEBUG: db_path = %s\n",db_path);
|
||||
|
||||
mk_return = mkdir(db_path,S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH);
|
||||
return mk_return;
|
||||
}
|
24
filesys/Db.h
Normal file
24
filesys/Db.h
Normal file
@ -0,0 +1,24 @@
|
||||
//
|
||||
// Db.h
|
||||
// filesys
|
||||
//
|
||||
// Created by Saturneric on 2017/6/30.
|
||||
// Copyright © 2017年 Bakantu Eric. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Db_h
|
||||
#define Db_h
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
char *path = "data/";
|
||||
|
||||
typedef struct db_info{
|
||||
char name[16];
|
||||
} DB_CREATE_INFO;
|
||||
|
||||
extern int build_database(DB_CREATE_INFO *);
|
||||
|
||||
#endif /* Db_h */
|
84
filesys/Debug.c
Normal file
84
filesys/Debug.c
Normal file
@ -0,0 +1,84 @@
|
||||
//
|
||||
// Debug.c
|
||||
// filesys
|
||||
//
|
||||
// Created by Saturneric on 2017/6/25.
|
||||
// Copyright © 2017年 Bakantu Eric. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Debug.h"
|
||||
#include "ID.h"
|
||||
|
||||
int debug_printf(DEBUG_CREATE_INFO *p_deg_ifo){
|
||||
if (p_deg_ifo->avaliable == 0) return -1;
|
||||
if (p_deg_ifo->safe == 0) return -1;
|
||||
if(p_deg_ifo->type == -2){
|
||||
printf("!!");
|
||||
}
|
||||
if(p_deg_ifo->type == 0){
|
||||
printf("?");
|
||||
}
|
||||
if(p_deg_ifo->type == -1){
|
||||
printf("!");
|
||||
}
|
||||
printf("Debug Message{ \n");
|
||||
printf(" message: %s\n",p_deg_ifo->message);
|
||||
if(p_deg_ifo->type > 0){
|
||||
p_deg_ifo->showvar = 1;
|
||||
}
|
||||
if(p_deg_ifo->showvar){
|
||||
if(p_deg_ifo->variable == NULL){
|
||||
printf("DEBUG_PRINTF Error : unable to get the variable\n}\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if(p_deg_ifo->type == STRING){
|
||||
printf(" ------------\n type: variable info(string)");
|
||||
if (p_deg_ifo->showvar)
|
||||
printf("%s",(char *)(p_deg_ifo->variable));
|
||||
}
|
||||
else if(p_deg_ifo->type == INT){
|
||||
printf(" ------------\n type: variable info(integer)");
|
||||
if (p_deg_ifo->showvar)
|
||||
printf("%d",*(int *)(p_deg_ifo->variable));
|
||||
}
|
||||
else if(p_deg_ifo->type == FLOAT){
|
||||
printf(" ------------\n type: variable info(float)");
|
||||
if (p_deg_ifo->showvar)
|
||||
printf("%f",*(double *)(p_deg_ifo->variable));
|
||||
}
|
||||
else if (p_deg_ifo->type == WARNING){
|
||||
printf(" ------------\n type: warning");
|
||||
if (p_deg_ifo->showvar)
|
||||
printf("\n location: %p",p_deg_ifo->variable);
|
||||
}
|
||||
else if (p_deg_ifo->type == ERROR){
|
||||
printf(" ------------\n type: error");
|
||||
if (p_deg_ifo->showvar)
|
||||
printf("\n location: %p",p_deg_ifo->variable);
|
||||
}
|
||||
else if (p_deg_ifo->type == IMPORTANT_ERROR){
|
||||
printf(" ------------\n type: improtant error");
|
||||
if (p_deg_ifo->showvar)
|
||||
printf("\n location: %p",p_deg_ifo->variable);
|
||||
}
|
||||
else printf("DEBUG_PRINTF Error : unable to get the type of the variable");
|
||||
printf("\n}\n");
|
||||
free(p_deg_ifo);
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEBUG_CREATE_INFO *get_degcrtifo(void){
|
||||
DEBUG_CREATE_INFO *p_deg_crt_ifo = NULL;
|
||||
p_deg_crt_ifo = (DEBUG_CREATE_INFO *) malloc(sizeof(DEBUG_CREATE_INFO));
|
||||
if (p_deg_crt_ifo == NULL) return NULL;
|
||||
p_deg_crt_ifo->type = 0;
|
||||
p_deg_crt_ifo->avaliable = 1;
|
||||
p_deg_crt_ifo->showvar = 0;
|
||||
p_deg_crt_ifo->variable = NULL;
|
||||
p_deg_crt_ifo->safe = 1;
|
||||
p_deg_crt_ifo->id = get_id();
|
||||
|
||||
return p_deg_crt_ifo;
|
||||
}
|
||||
|
35
filesys/Debug.h
Normal file
35
filesys/Debug.h
Normal file
@ -0,0 +1,35 @@
|
||||
//
|
||||
// Debug.h
|
||||
// filesys
|
||||
//
|
||||
// Created by Saturneric on 2017/6/25.
|
||||
// Copyright © 2017年 Bakantu Eric. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Debug_h
|
||||
#define Debug_h
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define STRING 1
|
||||
#define INT 2
|
||||
#define FLOAT 3
|
||||
#define ERROR -1
|
||||
#define IMPORTANT_ERROR -2
|
||||
#define WARNING 0
|
||||
|
||||
typedef struct debug_info{
|
||||
long id;
|
||||
int type;
|
||||
int safe;
|
||||
int showvar;
|
||||
int avaliable;
|
||||
void *variable;
|
||||
char *message;
|
||||
} DEBUG_CREATE_INFO;
|
||||
|
||||
extern int debug_printf(DEBUG_CREATE_INFO *);
|
||||
extern DEBUG_CREATE_INFO *get_degcrtifo(void);
|
||||
|
||||
#endif /* Debug_h */
|
14
filesys/ID.c
Normal file
14
filesys/ID.c
Normal file
@ -0,0 +1,14 @@
|
||||
//
|
||||
// ID.c
|
||||
// filesys
|
||||
//
|
||||
// Created by Saturneric on 2017/6/25.
|
||||
// Copyright © 2017年 Bakantu Eric. All rights reserved.
|
||||
//
|
||||
|
||||
#include "ID.h"
|
||||
|
||||
long get_id(void){
|
||||
srand((unsigned int)time(NULL));
|
||||
return (long)(rand()+rand()%1000);
|
||||
}
|
18
filesys/ID.h
Normal file
18
filesys/ID.h
Normal file
@ -0,0 +1,18 @@
|
||||
//
|
||||
// ID.h
|
||||
// filesys
|
||||
//
|
||||
// Created by Saturneric on 2017/6/25.
|
||||
// Copyright © 2017年 Bakantu Eric. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef ID_h
|
||||
#define ID_h
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
extern long get_id(void);
|
||||
|
||||
#endif /* ID_h */
|
262
filesys/List.c
Normal file
262
filesys/List.c
Normal file
@ -0,0 +1,262 @@
|
||||
//
|
||||
// List.c
|
||||
// filesys
|
||||
//
|
||||
// Created by Saturneric on 2017/6/25.
|
||||
// Copyright © 2017年 Bakantu Eric. All rights reserved.
|
||||
//
|
||||
|
||||
#include "List.h"
|
||||
#include "Debug.h"
|
||||
#include "ID.h"
|
||||
|
||||
List *build_list(void){
|
||||
List *p_list = (List *) malloc(sizeof(List));
|
||||
p_list->avaliable = 1;
|
||||
p_list->id = get_id();
|
||||
p_list->h_node = NULL;
|
||||
p_list->l_node = NULL;
|
||||
p_list->num = 0;
|
||||
p_list->safe = 1;
|
||||
return p_list;
|
||||
}
|
||||
|
||||
Node *build_node(void){
|
||||
Node *p_node = (Node *) malloc(sizeof(Node));
|
||||
p_node->avaliable = 1;
|
||||
p_node->id = get_id();
|
||||
p_node->l_node = NULL;
|
||||
p_node->n_node = NULL;
|
||||
p_node->value = NULL;
|
||||
p_node->safe = 1;
|
||||
return p_node;
|
||||
}
|
||||
|
||||
int add_node(List *p_list, Node *p_node){
|
||||
int pass = 1;
|
||||
if(check_list(p_list) == -1) pass = -1;
|
||||
if(check_node(p_node) == -1) pass = -1;
|
||||
if (pass == -1) return -1;
|
||||
if(p_list->h_node == NULL){
|
||||
p_list->h_node = p_node;
|
||||
p_list->l_node = p_node;
|
||||
}
|
||||
else{
|
||||
p_list->l_node->n_node = p_node;
|
||||
p_node->l_node = p_list->l_node;
|
||||
p_list->l_node = p_node;
|
||||
}
|
||||
p_list->num++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int del_node(List *p_list, Node *p_node){
|
||||
int pass = 1;
|
||||
if(check_list(p_list) == -1) pass = -1;
|
||||
if(check_node(p_node) == -1) pass = -1;
|
||||
if (pass == -1) return -1;
|
||||
if (p_list->num <= 0) return -1;
|
||||
p_node->l_node->l_node->n_node = NULL;
|
||||
Node *pl_node = p_node->l_node->l_node;
|
||||
free_node(p_node->l_node);
|
||||
p_node->l_node = pl_node;
|
||||
p_list->num--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int free_node(Node *p_node){
|
||||
free(p_node ->value);
|
||||
free(p_node);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int check_list(List *p_list){
|
||||
if(p_list == NULL){
|
||||
DEBUG_CREATE_INFO *t_deg_crt_ifo = get_degcrtifo();;
|
||||
t_deg_crt_ifo->type = ERROR;
|
||||
t_deg_crt_ifo->showvar = 1;
|
||||
t_deg_crt_ifo->variable = &p_list;
|
||||
t_deg_crt_ifo->message = "the list is no eist.";
|
||||
debug_printf(t_deg_crt_ifo);
|
||||
return -1;
|
||||
}
|
||||
if (!p_list->avaliable){
|
||||
DEBUG_CREATE_INFO *t_deg_crt_ifo = get_degcrtifo();;
|
||||
t_deg_crt_ifo->type = WARNING;
|
||||
t_deg_crt_ifo->showvar = 1;
|
||||
t_deg_crt_ifo->variable = &p_list;
|
||||
t_deg_crt_ifo->message = "the list is no avaliable.";
|
||||
debug_printf(t_deg_crt_ifo);
|
||||
return -1;
|
||||
}
|
||||
if (!p_list->safe){
|
||||
DEBUG_CREATE_INFO *t_deg_crt_ifo = get_degcrtifo();;
|
||||
t_deg_crt_ifo->type = ERROR;
|
||||
t_deg_crt_ifo->showvar = 1;
|
||||
t_deg_crt_ifo->variable = &p_list;
|
||||
t_deg_crt_ifo->message = "the list is no safe.";
|
||||
debug_printf(t_deg_crt_ifo);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int check_node(Node *p_node){
|
||||
if(p_node == NULL){
|
||||
DEBUG_CREATE_INFO *t_deg_crt_ifo = get_degcrtifo();;
|
||||
t_deg_crt_ifo->type = ERROR;
|
||||
t_deg_crt_ifo->showvar = 1;
|
||||
t_deg_crt_ifo->variable = &p_node;
|
||||
t_deg_crt_ifo->message = "the node is no eist.";
|
||||
debug_printf(t_deg_crt_ifo);
|
||||
return -1;
|
||||
|
||||
}
|
||||
if (!p_node->avaliable){
|
||||
DEBUG_CREATE_INFO *t_deg_crt_ifo = get_degcrtifo();;
|
||||
t_deg_crt_ifo->type = WARNING;
|
||||
t_deg_crt_ifo->showvar = 1;
|
||||
t_deg_crt_ifo->variable = &p_node;
|
||||
t_deg_crt_ifo->message = "the node is no avaliable.";
|
||||
debug_printf(t_deg_crt_ifo);
|
||||
return -1;
|
||||
}
|
||||
if (!p_node->safe){
|
||||
DEBUG_CREATE_INFO *t_deg_crt_ifo = get_degcrtifo();;
|
||||
t_deg_crt_ifo->type = ERROR;
|
||||
t_deg_crt_ifo->showvar = 1;
|
||||
t_deg_crt_ifo->variable = &p_node;
|
||||
t_deg_crt_ifo->message = "the node is no safe.";
|
||||
debug_printf(t_deg_crt_ifo);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int free_list(List *p_list){
|
||||
if (p_list == NULL){
|
||||
DEBUG_CREATE_INFO *t_deg_crt_ifo = get_degcrtifo();;
|
||||
t_deg_crt_ifo->type = WARNING;
|
||||
t_deg_crt_ifo->showvar = 1;
|
||||
t_deg_crt_ifo->variable = &p_list;
|
||||
t_deg_crt_ifo->message = "the list is no exist.";
|
||||
debug_printf(t_deg_crt_ifo);
|
||||
}
|
||||
Node *p_node, *pl_node;
|
||||
p_node = p_list->h_node;
|
||||
while (p_node != NULL){
|
||||
pl_node = p_node;
|
||||
p_node = p_node->n_node;
|
||||
pl_node->avaliable = 0;
|
||||
pl_node->safe = 0;
|
||||
free_node(pl_node);
|
||||
}
|
||||
p_list->avaliable = 0;
|
||||
p_list->safe = 0;
|
||||
free(p_list);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Node * get_locationByindex(List *p_list,int index){
|
||||
check_list(p_list);
|
||||
if (index > p_list->num-1){
|
||||
DEBUG_CREATE_INFO *t_deg_crt_ifo = get_degcrtifo();;
|
||||
t_deg_crt_ifo->type = ERROR;
|
||||
t_deg_crt_ifo->showvar = 1;
|
||||
t_deg_crt_ifo->variable = &p_list;
|
||||
t_deg_crt_ifo->message = "the nodes in the list is not enough.";
|
||||
debug_printf(t_deg_crt_ifo);
|
||||
return NULL;
|
||||
}
|
||||
Node *p_node = p_list->h_node;
|
||||
while(--index > 0){
|
||||
p_node = p_node->n_node;
|
||||
}
|
||||
return p_node;
|
||||
}
|
||||
|
||||
Node *get_locationByid(List *p_list,long id){
|
||||
check_list(p_list);
|
||||
Node *p_node = p_list->h_node;
|
||||
Node *s_node = NULL;
|
||||
while(s_node == NULL){
|
||||
if (p_node->id == id) s_node = p_node;
|
||||
p_node = p_node->n_node;
|
||||
}
|
||||
return s_node;
|
||||
}
|
||||
|
||||
Node *get_locationBystring(List *p_list, char *string){
|
||||
check_list(p_list);
|
||||
Node *p_node = p_list->h_node;
|
||||
Node *s_node = NULL;
|
||||
while(s_node == NULL){
|
||||
if (!strcmp(p_node->value, string)) s_node = p_node;
|
||||
p_node = p_node->n_node;
|
||||
}
|
||||
return s_node;
|
||||
}
|
||||
|
||||
int *set_valueint(int integer){
|
||||
int *p_integer = (int *) malloc(sizeof(int));
|
||||
*p_integer = integer;
|
||||
return p_integer;
|
||||
}
|
||||
|
||||
double *set_valuefloat(double fnum){
|
||||
double *p_fnum = (double *)malloc(sizeof(double));
|
||||
*p_fnum = fnum;
|
||||
return p_fnum;
|
||||
}
|
||||
|
||||
char *set_valuestring(char *string){
|
||||
char *p_string = (char *) malloc(sizeof(char) * 256);
|
||||
strcpy(p_string, string);
|
||||
return p_string;
|
||||
}
|
||||
|
||||
int list_tofile(FILE *p_file, List *p_list){
|
||||
//fprintf(p_file, "%d,%d,");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Item *build_item(void){
|
||||
Item *p_item = (Item *)malloc(sizeof(Item));
|
||||
p_item->id = get_id();
|
||||
p_item->data_list = build_list();
|
||||
p_item->data_num = 0;
|
||||
p_item->type_list = build_list();
|
||||
p_item->define_list = build_list();
|
||||
p_item->define_num = 0;
|
||||
p_item->avaliable = 1;
|
||||
p_item->safe = 1;
|
||||
return p_item;
|
||||
}
|
||||
|
||||
int add_define(Item *p_item, char *define, char *type){
|
||||
Node *pd_node = build_node();
|
||||
pd_node->value = set_valuestring(define);
|
||||
|
||||
Node *pt_node = build_node();
|
||||
pt_node->value = set_valuestring(type);
|
||||
|
||||
add_node(p_item->define_list, pd_node);
|
||||
add_node(p_item->type_list, pt_node);
|
||||
p_item->define_num++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int add_data(Item *p_item, void *value){
|
||||
if (p_item->data_num >= p_item->define_num){
|
||||
DEBUG_CREATE_INFO *t_deg_crt_ifo = get_degcrtifo();;
|
||||
t_deg_crt_ifo->type = ERROR;
|
||||
t_deg_crt_ifo->showvar = 1;
|
||||
t_deg_crt_ifo->variable = &p_item;
|
||||
t_deg_crt_ifo->message = "data is more than define.";
|
||||
debug_printf(t_deg_crt_ifo);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
102
filesys/List.h
Normal file
102
filesys/List.h
Normal file
@ -0,0 +1,102 @@
|
||||
//
|
||||
// List.h
|
||||
// filesys
|
||||
//
|
||||
// Created by Saturneric on 2017/6/25.
|
||||
// Copyright © 2017年 Bakantu Eric. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef List_h
|
||||
#define List_h
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
typedef struct node{
|
||||
long id;
|
||||
int avaliable;
|
||||
int safe;
|
||||
void *value;
|
||||
struct node *n_node;
|
||||
struct node *l_node;
|
||||
} Node;
|
||||
|
||||
typedef struct list{
|
||||
long id;
|
||||
int avaliable;
|
||||
int safe;
|
||||
long num;
|
||||
Node *h_node;
|
||||
Node *l_node;
|
||||
} List;
|
||||
|
||||
typedef struct define{
|
||||
long id;
|
||||
int avaliable;
|
||||
int safe;
|
||||
int num;
|
||||
List *define_list;
|
||||
List *type_list;
|
||||
} Define;
|
||||
|
||||
typedef struct item{
|
||||
long id;
|
||||
int avaliable;
|
||||
int safe;
|
||||
Define *p_define;
|
||||
List *define_list;
|
||||
List *type_list;
|
||||
List *data_list;
|
||||
int data_num;
|
||||
int define_num;
|
||||
} Item;
|
||||
|
||||
typedef struct table{
|
||||
long id;
|
||||
int avaliable;
|
||||
int safe;
|
||||
Define *p_define;
|
||||
List *item_list;
|
||||
int num;
|
||||
}Table;
|
||||
|
||||
typedef struct bin{
|
||||
long id;
|
||||
int avaliable;
|
||||
int safe;
|
||||
List *item_list;
|
||||
} Bin;
|
||||
|
||||
extern List *build_list(void);
|
||||
extern Node *build_node(void);
|
||||
extern int free_list(List *);
|
||||
extern int free_node(Node *);
|
||||
extern int add_node(List *, Node *);
|
||||
extern int del_node(List *, Node *);
|
||||
extern int check_list(List *);
|
||||
extern int check_node(Node *);
|
||||
extern Node *get_locationByindex(List *,int);
|
||||
extern Node *get_locationByid(List *,long);
|
||||
|
||||
extern Node *get_locationBystring(List *, char *);
|
||||
|
||||
extern int list_tofile(FILE *, List *);
|
||||
extern int file_tolist(FILE *, List *);
|
||||
|
||||
extern int *set_valueint(int);
|
||||
extern double *set_valuefloat(double);
|
||||
extern char *set_valuestring(char *);
|
||||
|
||||
extern Item *build_item(Define *);
|
||||
extern int add_data(Item *, void *);
|
||||
extern int free_item(Item *);
|
||||
|
||||
extern Define *build_define(void);
|
||||
extern int add_define(Define *, char *, char *);
|
||||
extern int free_define(Define *);
|
||||
|
||||
|
||||
#endif /* List_h */
|
14
filesys/Support.h
Normal file
14
filesys/Support.h
Normal file
@ -0,0 +1,14 @@
|
||||
//
|
||||
// Support.h
|
||||
// filesys
|
||||
//
|
||||
// Created by Saturneric on 2017/6/30.
|
||||
// Copyright © 2017年 Bakantu Eric. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef Support_h
|
||||
#define Support_h
|
||||
|
||||
#include "List.h"
|
||||
|
||||
#endif /* Support_h */
|
@ -1,15 +1,19 @@
|
||||
//
|
||||
// main.c
|
||||
// filesys
|
||||
//
|
||||
// Created by Saturneric on 2017/6/24.
|
||||
// Copyright © 2017年 Bakantu Eric. All rights reserved.
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include "Support.h"
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
// insert code here...
|
||||
printf("Hello, World!\n");
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
Node *nl[50];
|
||||
List *pl = build_list();
|
||||
for(int i = 0; i < 50; i++){
|
||||
nl[i] = build_node();
|
||||
nl[i]->value = (void *)set_valueint(i);
|
||||
add_node(pl, nl[i]);
|
||||
}
|
||||
|
||||
Node *p_node = get_locationByindex(pl, 5);
|
||||
free_list(pl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user