diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ini_read.c | 35 | ||||
-rw-r--r-- | src/lightconfini.h | 2 | ||||
-rw-r--r-- | src/main.c | 9 | ||||
-rw-r--r-- | src/main.h | 9 |
4 files changed, 30 insertions, 25 deletions
diff --git a/src/ini_read.c b/src/ini_read.c index 9ac834c..8f57650 100644 --- a/src/ini_read.c +++ b/src/ini_read.c @@ -11,10 +11,6 @@ #include "inirw_internal.h" #include "lightconfini.h" - -/* -extern void (mylciniReadOutFunct)(int line, int linelen, char *section, int sectionlen, char *param, int paramlen, char *value, int valuelen, char *comment, int commentlen, char *error, int errorlen ); -*/ size_t strNullLen(const char *str){ @@ -710,22 +706,19 @@ int lciniReadOutOwn(const char *filename){ /* Reads the entire file to a li char *buff=NULL; FILE *fp=NULL; int64_t linemax, line=0, pos=0; - struct lcini_data curr; + struct lcini_data *curr; /* char cc;*/ - curr.section = NULL; - curr.param = NULL; - curr.value = NULL; - curr.comment = NULL; - curr.errorMsg = NULL; + curr = lciniCreateNode(NULL,256); buff = (char *) malloc(256*sizeof(char)); memset(buff, 0, 256*sizeof(char)); fp = fopen(filename, "rb"); - if(!fp && mylciniReadOutFunct != NULL){ /* fp == NULL */ - - sprintf(buff, "File opening error. Errno: %d (%s)", errno, strerror(errno) ); - mylciniReadOutFunct(0,0, NULL,0, NULL,0, NULL,0, NULL,0, buff, 256); + if(!fp){ /* fp == NULL */ + if( mylciniReadOutFunct != NULL){ + sprintf(buff, "File opening error. Errno: %d (%s)", errno, strerror(errno) ); + (*mylciniReadOutFunct)(0,0, NULL,0, NULL,0, NULL,0, NULL,0, buff, 256); + } } else { linemax = lciniFileMaxLineLen(fp) +1; @@ -741,13 +734,12 @@ int lciniReadOutOwn(const char *filename){ /* Reads the entire file to a li if(1){ /* Call the Finite-State-Machine processor */ - curr.lineNum = line; - curr.lineLen = pos + 1; - iniFSM(&curr, buff, linemax); - } - if(curr.nodeState != lcini_EMPTY && mylciniReadOutFunct != NULL ){ /* Dropping empty lines */ - /* mylciniReadOutFunct(line, pos+1, curr.section, curr.sectionLen, curr.param, curr.paramLen, curr.value, curr.valueLen, curr.comment, curr.commentLen, curr.errorMsg, curr.errorMsgLen);*/ - (*mylciniReadOutFunct)(line, pos+1, curr.section, curr.sectionLen, curr.param, curr.paramLen, curr.value, curr.valueLen, curr.comment, curr.commentLen, curr.errorMsg, curr.errorMsgLen); + curr->lineNum = line; + curr->lineLen = pos + 1; + iniFSM(curr, buff, linemax); + } + if(curr->nodeState != lcini_EMPTY && mylciniReadOutFunct != NULL ){ /* Call with function ptr */ + (*mylciniReadOutFunct)(line, pos+1, curr->section, curr->sectionLen, curr->param, curr->paramLen, curr->value, curr->valueLen, curr->comment, curr->commentLen, curr->errorMsg, curr->errorMsgLen); } pos = 0; @@ -762,6 +754,7 @@ int lciniReadOutOwn(const char *filename){ /* Reads the entire file to a li if(fp){ fclose(fp); } + lciniDestroyNodes(curr); free(buff); return line; } diff --git a/src/lightconfini.h b/src/lightconfini.h index ee5a7c3..7bbe918 100644 --- a/src/lightconfini.h +++ b/src/lightconfini.h @@ -38,7 +38,7 @@ typedef struct lcini_retdata{ /* Ha maga függvény van átpakolva, nevestül, testestül */ /* extern void (mylciniReadOutFunct)(int line, int linelen, char *section, int sectionlen, char *param, int paramlen, char *value, int valuelen, char *comment, int commentlen, char *error, int errorlen ) ; */ /* Ha csak egy fggvényre mutató ptr */ -typedef void (*lcinimyReadFunc)(int line, int linelen, char *section, int sectionlen, char *param, int paramlen, char *value, int valuelen, char *comment, int commentlen, char *error, int errorlen ) ; +typedef void (*lcinimyReadFunc)(int line, int linelen, char *section, int sectionlen, char *param, int paramlen, char *value, int valuelen, char *comment, int commentlen, char *error, int errorlen ); extern lcinimyReadFunc mylciniReadOutFunct; @@ -6,10 +6,15 @@ /* #include "inirw_internal.h" */ #include "lightconfini.h" +#include "main.h" #define main_c int lens=16, lenp=16, lenv=16, lenc=24, elen=55; +lcinimyReadFunc mylciniReadOutFunct=myfunct; +/*lcinimyReadFunc mylciniReadOutFunct=NULL;*/ + + void myfunct(int line, int linelen, char *section, int sectionlen, char *param, int paramlen, char *value, int valuelen, char *comment, int commentlen, char *error, int errorlen ){ @@ -17,10 +22,8 @@ void myfunct(int line, int linelen, char *section, int sectionlen, char *param, printf("LN: %d,\tLL: %d,\tSC: %*s,%2d P: %*s,%2d V: %*s,%2d C: %*s,%2d ER: %*s \n", line, linelen, lens, section,sectionlen, lenp, param, paramlen, lenv, value, valuelen, lenc, comment, commentlen, elen, error); } -/*lcinimyReadFunc mylciniReadOutFunct=myfunct;*/ -lcinimyReadFunc mylciniReadOutFunct=NULL; - + int main(int argc, char* argv[]){ int len; diff --git a/src/main.h b/src/main.h new file mode 100644 index 0000000..6246787 --- /dev/null +++ b/src/main.h @@ -0,0 +1,9 @@ +#ifndef MAIN_H_INCLUDED +#define MAIN_H_INCLUDED +#include <stdint.h> /* int64_t*/ + + +void myfunct(int line, int linelen, char *section, int sectionlen, char *param, int paramlen, char *value, int valuelen, char *comment, int commentlen, char *error, int errorlen ); + +#endif /* MAIN_H_INCLUDED */ + |