diff options
author | M.Gergő | 2020-05-14 02:04:04 +0200 |
---|---|---|
committer | M.Gergő | 2020-05-14 02:04:04 +0200 |
commit | 0026bdb684cd610be6a7f8499db8920ee1579c1b (patch) | |
tree | 2050392e850d780ae419de7bc7183d0af550bfec /src/main.c | |
parent | 3a62d45767dca76f109425fb8e641741a87ee4b4 (diff) | |
download | lightconfini-0026bdb684cd610be6a7f8499db8920ee1579c1b.tar.gz lightconfini-0026bdb684cd610be6a7f8499db8920ee1579c1b.zip |
little tests & repair
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 68 |
1 files changed, 34 insertions, 34 deletions
@@ -4,48 +4,47 @@ #include <ctype.h> #include <stdbool.h> -#include <linux/limits.h> /* PATH_MAX*/ #include "ini_rw.h" #define main_c - + -int main() -{ - char filename[] = "tests/test.ini", *buff1, *buff2, *buff3, *buff4, *buff5; +int main(int argc, char* argv[]){ + + + char filename[4096] = "tests/test.ini", *buff1, *buff2, *buff3, *buff4, *buff5; lci_data *ini=NULL, *tmp=NULL; - int len=0, elen=64, lens=0, lenp=0, lenv=0, lenc=0; + int len=0, elen=54, lens=0, lenp=0, lenv=0, lenc=0; FILE *fp; + if(argc > 1){ + memset(filename, 0, 4096); + snprintf(filename, 4096, "%s", argv[1]); + } + + fp = fopen(filename, "rb"); - len = getFileMaxLineLen(fp); - fclose(fp); + len = getFileMaxLineLen(fp)+0; + if(fp != NULL) { fclose(fp);} -//len = 24000; + len = 24000; //Debug + lens=16; + lenp=16; + lenv=16; + lenc=44; - buff1 = malloc((len+3)*sizeof(char)); - buff2 = malloc((len+3)*sizeof(char)); - buff3 = malloc((len+3)*sizeof(char)); - buff4 = malloc((len+3)*sizeof(char)); - buff5 = malloc((elen+3)*sizeof(char)); -memset(buff1, 0, (len+3)*sizeof(char)); -memset(buff2, 0, (len+3)*sizeof(char)); -memset(buff3, 0, (len+3)*sizeof(char)); -memset(buff4, 0, (len+3)*sizeof(char)); -memset(buff5, 0, (elen+3)*sizeof(char)); + buff1 = calloc((len+3), sizeof(char)); + buff2 = calloc((len+3), sizeof(char)); + buff3 = calloc((len+3), sizeof(char)); + buff4 = calloc((len+3), sizeof(char)); + buff5 = calloc((elen+3),sizeof(char)); - printf("\nLineMax: %d\n\n",len); ini = iniReadOut(filename); - lens=16; - lenp=16; - lenv=16; - lenc=44; - tmp = ini; while(tmp != NULL){ @@ -54,21 +53,22 @@ memset(buff5, 0, (elen+3)*sizeof(char)); snprintf(buff2, len+3, "'%s' %3ld",tmp->param, tmp->paramLen); snprintf(buff3, len+3, "'%s' %3ld",tmp->value, tmp->valueLen); snprintf(buff4, len+3, "'%s' %3ld",tmp->comment, tmp->commentLen); - snprintf(buff5, elen, "'%s' %3ld",tmp->errorMsg, tmp->errorMsgLen); + snprintf(buff5, elen+3, "'%s' %3ld",tmp->errorMsg, tmp->errorMsgLen); - //printf("LN: %ld,\tLL: %ld,\tSE: %*s,%2ld P: %*s,%2ld V: %*s,%2ld C: %*s,%2ld ER: %*s \n", tmp->lineNum, tmp->lineLen, lens, buff1,tmp->sectionStartPos, - // lenp, buff2, tmp->paramStartPos, lenv, buff3, tmp->valueStartPos, lenc, buff4, tmp->commentStartPos, elen, buff5); + printf("LN: %ld,\tLL: %ld,\tSE: %*s,%2ld P: %*s,%2ld V: %*s,%2ld C: %*s,%2ld ER: %*s \n", tmp->lineNum, tmp->lineLen, lens, buff1,tmp->sectionStartPos, + lenp, buff2, tmp->paramStartPos, lenv, buff3, tmp->valueStartPos, lenc, buff4, tmp->commentStartPos, elen, buff5); tmp=tmp->next; } -free(buff1); -free(buff2); -free(buff3); -free(buff4); -free(buff5); - destroyNodes( ini); + free(buff1); + free(buff2); + free(buff3); + free(buff4); + free(buff5); + + destroyNodes( ini); return 0; |