aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--makefile27
-rw-r--r--src/ini_read.c11
-rw-r--r--src/main.c114
-rw-r--r--tests/bom.ini4
4 files changed, 131 insertions, 25 deletions
diff --git a/makefile b/makefile
index b3e0097..5369f24 100644
--- a/makefile
+++ b/makefile
@@ -1,4 +1,4 @@
-.PHONY: all clean main test testlib testlibd install copylib ldconf lib debug distclean
+.PHONY: all clean mkdir main test testlib testlibd install copylib ldconf lib debug distclean
# buid & link with gcc
CC = gcc
@@ -45,24 +45,26 @@ test: clean $(PROG)
lib: $(PROG) ldconf
debug: clean $(PROG)
install: lib copylib
-testlib: lib ldconf clean main
-testlibd: lib ldconf clean main
+#testlib: lib ldconf clean main
+#testlibd: lib ldconf clean main
+testlib: clean mkdir main
+testlibd: clean mkdir main
# debug-hoz felüldefiniálva
-debug: CFLAGS = -Wall -c -g -g3 -ggdb -std=c89 -Wpedantic -Wmissing-prototypes -D"GIT_LAST=$(LASTVER)" -D"GIT_LASTT=$(LASTVERT)" -D"GIT_MAINT=$(LASTMAINT)"
+debug: CFLAGS = -Wall -c -O0 -g -g3 -ggdb -std=c89 -Wpedantic -Wmissing-prototypes -D"GIT_LAST=$(LASTVER)" -D"GIT_LASTT=$(LASTVERT)" -D"GIT_MAINT=$(LASTMAINT)"
debug: LDLIBS = -lefence
# make lib FLAGS: not link: -c, relative addresses: -fPIC
lib: CFLAGS = -fPIC -c -Wall -D"GIT_LAST=$(LASTVER)" -D"GIT_LASTT=$(LASTVERT)" -D"GIT_MAINT=$(LASTMAINT)"
lib: LDFLAGS = -shared -Wl,-soname,liblightconfini.so.$(LASTMAINT)
lib: LDLIBS = -lc
# nem mindegy, hogy mellette van, vagy alatta egy sorral!
-testlib: LDFLAGS = -L $(PWD)/$(LIBDIR)/
+#testlib: LDFLAGS = -L $(PWD)/$(LIBDIR)/
testlib: LDLIBS = -llightconfini
-testlib: PREP = TESTLIB
#Dinamikus betöltés tesztelése
testlibd: LDFLAGS = -rdynamic
testlibd: LDLIBS = -ldl
-testlibd: PREP = TESTLIBD
+testlibd: PREP = -D"TESTLIBD"
+#testlibd: PREP = -D"TESTLIBD" -D"LIBINSTALLED"
# Ha még nem létezik az obj könyvtár, létrehozza
@@ -81,7 +83,7 @@ $(OBJS): $(OBJDIR)/%.o: $(SRCDIR)/%.c
# A main újrafordítása
main:
- $(CC) $(CFLAGS) -D"$(PREP)" -o $(OBJDIR)/main.o $(SRCDIR)/main.c
+ $(CC) $(CFLAGS) $(PREP) -o $(OBJDIR)/main.o $(SRCDIR)/main.c
$(LD) $(LDFLAGS) $(OBJDIR)/main.o -o $(PROG) $(LDLIBS)
# OBJ létrehozáshoz
@@ -95,13 +97,18 @@ $(LIBDIR):
rebuild: clean all
copylib:
- $(CP) -r $(LIBDIR)/* /usr/local/lib/
+ $(CP) -f $(SRCDIR)/lightconfini.h /usr/local/include/
+ $(CP) -f $(LIBDIR)/* /usr/local/lib/
ln -sf /usr/local/lib/liblightconfini.so.$(LASTVERT) /usr/local/lib/liblightconfini.so
ldconfig
ldconf:
ln -sf $(PWD)/$(LIBDIR)/liblightconfini.so.$(LASTVERT) $(PWD)/$(LIBDIR)/liblightconfini.so
- ldconfig -n $(PWD)/$(LIBDIR)/
+ #ldconfig -n $(PWD)/$(LIBDIR)/
+
+mkdir:
+ $(MKD) $(BINDIR)
+ $(MKD) $(OBJDIR)
clean:
$(RM) $(OBJS)
diff --git a/src/ini_read.c b/src/ini_read.c
index 66799a1..e58bc80 100644
--- a/src/ini_read.c
+++ b/src/ini_read.c
@@ -588,7 +588,7 @@ struct lcini_data *iniFSM(struct lcini_data *data, const uint8_t *in, int32_t le
lcini_data *lciniCreateNode( lcini_data *head, int lineLen ){ /* Creates one Node */
lcini_data *curr;
- curr = (lcini_data *) malloc(1*sizeof(lcini_data));
+ curr = (lcini_data *) calloc(1, sizeof(lcini_data));
curr->nodeState = lcini_EMPTY;
curr->lineNum = 0;
curr->lineLen = lineLen;
@@ -600,6 +600,11 @@ lcini_data *lciniCreateNode( lcini_data *head, int lineLen ){ /* Creates one Nod
curr->comment = (uint8_t *) calloc(lineLen, sizeof(uint8_t));
curr->errorMsg = (uint8_t *) calloc(lineLen, sizeof(uint8_t));
} else {
+ curr->section = NULL;
+ curr->param = NULL;
+ curr->value = NULL;
+ curr->comment = NULL;
+ curr->errorMsg = NULL;
lineLen = 0;
}
curr->sectionLen = lineLen;
@@ -641,7 +646,7 @@ lcini_data *lciniDestroyNodes( lcini_data *head){ /* Destroys Nodes from HEAD to
lcini_shortret *lciniMKShortRet(int bufflen){
lcini_shortret *dt=NULL;
- dt = (lcini_shortret *) malloc(1*sizeof(lcini_shortret));
+ dt = (lcini_shortret *) calloc(1, sizeof(lcini_shortret));
if(dt){
dt->ret = (char *) calloc(bufflen, sizeof(char));
dt->retlen = bufflen;
@@ -747,7 +752,7 @@ struct lcini_data *lciniReadOut(const char *filename){ /* Reads the entire
}
return list;
}
-
+
int lciniReadOutOwn(const char *filename){ /* Reads the entire file to a linked-list */
diff --git a/src/main.c b/src/main.c
index a0f342a..ff84fd4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3,26 +3,35 @@
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
-
-/* #include "inirw_internal.h" */
+/*#define TESTLIBD*/
+/*#define LIBINSTALLED*/
+#ifdef TESTLIBD
+#include <dlfcn.h>
+#endif
+#ifdef LIBINSTALLED
+#include <lightconfini.h>
+#else
#include "lightconfini.h"
+#endif
#include "main.h"
#define main_c
+#ifdef LIBINSTALLED
+const char* linkpath = "liblightconfini.so.1";
+#else
+const char* linkpath = "./libdir/liblightconfini.so.1";
+#endif
+
/* int lens=46, lenp=36, lenv=56, lenc=74, elen=65; */
int lens=16, lenp=16, lenv=16, lenc=24, elen=55;
lcinimyReadFunc mylciniReadOutFunct=myfunct;
-/*lcinimyReadFunc mylciniReadOutFunct=NULL;*/
-
-
-
+/*lcinimyReadFunc *mylciniReadOutFunct=NULL;*/
char *search_sec = "bom_section";
char *search_par = "mmm";
-
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 ){
printf("LN: %d,\tLL: %d, \tSC: %*s,%2d P: %*s,%2d V: %*s,%2d C: %*s,%2d ER: %*s,%2d\n", line, linelen, lens, section,sectionlen,
@@ -37,12 +46,92 @@ int main(int argc, char* argv[]){
lcini_data *ini=NULL, *tmp=NULL;
FILE *fp;
lcini_shortret *sret=NULL, *sret2=NULL;
-
+#ifdef TESTLIBD
+ void *hl;
+ size_t (*lciniFileMaxLineLen)(FILE *tfd);
+ struct lcini_data *(*lciniReadOut)(const char *filename);
+ int (*lciniReadOutOwn)(const char *filename);
+ lcini_data *(*lciniGet)(lcini_data *head, const char *section, const char *parameter);
+ int (*lciniGetStr)(lcini_data *head, const char *section, const char *parameter, char *dst, int dstlen);
+ lcini_shortret *(*lciniGetShort)(lcini_data *head, const char *section, const char *parameter, lcini_shortret *ret);
+ lcini_shortret *(*lciniGetFromFileShort)(const char *filename, const char *section, const char *parameter, lcini_shortret *ret);
+ int (*lciniGetFromFileStr)(const char *filename, const char *section, const char *parameter, char *dst, int dstlen);
+ lcini_data *(*lciniDestroyNodes)( lcini_data *head);
+ /*lcini_data *(*lciniCreateNode)( lcini_data *head, int lineLen ); */
+ /*lcini_shortret *(*lciniMKShortRet)(int bufflen); */
+ void (*lciniDestroyShortRet)(lcini_shortret *dt);
+#endif
if(argc > 1){
memset(filename, 0, 4096);
/* snprintf(filename, 4096, "%s", argv[1]); */
sprintf(filename, "%s", argv[1]);
}
+ if(argc > 2){
+ search_sec = argv[2];
+ }
+ if(argc > 3){
+ search_par = argv[3];
+ }
+
+#ifdef TESTLIBD
+ hl = dlopen(linkpath, RTLD_LAZY);
+ if(!hl){
+ printf("\nDynamic Library load error - %s \nexit\n",dlerror());
+ exit(1);
+ }
+ lciniFileMaxLineLen = dlsym(hl, "lciniFileMaxLineLen");
+ if((buff1 = dlerror()) != NULL){
+ printf("\nsym err - %s\n", buff1);
+ }
+ lciniReadOut = dlsym(hl, "lciniReadOut");
+ if((buff1 = dlerror()) != NULL){
+ printf("\nsym err - %s\n", buff1);
+ }
+ lciniReadOutOwn = dlsym(hl, "lciniReadOutOwn");
+ if((buff1 = dlerror()) != NULL){
+ printf("\nsym err - %s\n", buff1);
+ }
+ lciniGet = dlsym(hl,"lciniGet");
+ if((buff1 = dlerror()) != NULL){
+ printf("\nsym err - %s\n", buff1);
+ }
+ lciniGetStr = dlsym(hl,"lciniGetStr");
+ if((buff1 = dlerror()) != NULL){
+ printf("\nsym err - %s\n", buff1);
+ }
+ lciniGetShort = dlsym(hl,"lciniGetShort");
+ if((buff1 = dlerror()) != NULL){
+ printf("\nsym err - %s\n", buff1);
+ }
+ lciniGetFromFileShort = dlsym(hl, "lciniGetFromFileShort");
+ if((buff1 = dlerror()) != NULL){
+ printf("\nsym err - %s\n", buff1);
+ }
+ lciniGetFromFileStr = dlsym(hl,"lciniGetFromFileStr");
+ if((buff1 = dlerror()) != NULL){
+ printf("\nsym err - %s\n", buff1);
+ }
+ lciniDestroyNodes = dlsym(hl,"lciniDestroyNodes");
+ if((buff1 = dlerror()) != NULL){
+ printf("\nsym err - %s\n", buff1);
+ }
+ /*lciniCreateNode = dlsym(hl,"lciniCreateNode");
+ if((buff1 = dlerror()) != NULL){
+ printf("\nsym err - %s\n", buff1);
+ }*/
+ /*lciniMKShortRet = dlsym(hl,"lciniMKShortRet");
+ if((buff1 = dlerror()) != NULL){
+ printf("\nsym err - %s\n", buff1);
+ }*/
+ lciniDestroyShortRet = dlsym(hl,"lciniDestroyShortRet");
+ if((buff1 = dlerror()) != NULL){
+ printf("\nsym err - %s\n", buff1);
+ }
+
+
+#endif
+
+
fp = fopen(filename, "rb");
len = lciniFileMaxLineLen(fp)+1;
if(fp != NULL) { fclose(fp);}
@@ -85,7 +174,7 @@ int main(int argc, char* argv[]){
printf("\n\nFUNC: lciniReadOutOwn():\n\n");
- /* lciniReadOutOwn(filename); */
+ lciniReadOutOwn(filename);
@@ -117,7 +206,7 @@ int main(int argc, char* argv[]){
printf("\n\nFUNC: lciniGetFromFileShort():\n\n");
- sret2 = lciniGetFromFileShort(filename, search_sec, search_par, NULL);
+ sret2 = lciniGetFromFileShort(filename, search_sec, search_par, sret2);
printf("---\n");
if(sret2){
printf("SR: '%s', %d, t: ",sret2->ret,sret2->retlen);
@@ -131,7 +220,7 @@ int main(int argc, char* argv[]){
}
printf("\n\nFUNC: lciniGetFromFileStr():\n\n");
- /* r=lciniGetFromFileStr(filename, search_sec, search_par, buff6, 100); */
+ r=lciniGetFromFileStr(filename, search_sec, search_par, buff6, 100);
printf("r: %d, R: '%s' \n",r,buff6);
@@ -145,5 +234,8 @@ int main(int argc, char* argv[]){
free(buff5);
free(buff6);
printf("\n -- end --\n");
+#ifdef TESTLIBD
+ dlclose(hl);
+#endif
return 0;
}
diff --git a/tests/bom.ini b/tests/bom.ini
index e1bacff..7a57d38 100644
--- a/tests/bom.ini
+++ b/tests/bom.ini
@@ -3,6 +3,8 @@
bom_name=bom_value ;OK
key “= value“ ;ER
key="value" ;OK
-10= 10
+key="val-val" ;OK #Former will be replaced with this.
+10= 10 ;OK
+;ERROR (No closing quotation mark sign!)
mmm="1234567890\
123456789asdfgh\ \ No newline at end of file