diff options
author | M.Gergő | 2020-05-08 21:10:20 +0200 |
---|---|---|
committer | M.Gergő | 2020-05-08 21:10:20 +0200 |
commit | 1ed4114bb3b9e701dcf6b2d8f1c6da2b47979d4d (patch) | |
tree | 5527f11faed55f5eb5e5f27ac24207cb36435a73 /src/ini_read.c | |
parent | 8b42a04bf6df46fa06e2333a0b41b3c92e7ef4f1 (diff) | |
download | lightconfini-1ed4114bb3b9e701dcf6b2d8f1c6da2b47979d4d.tar.gz lightconfini-1ed4114bb3b9e701dcf6b2d8f1c6da2b47979d4d.zip |
escaping
Diffstat (limited to 'src/ini_read.c')
-rw-r--r-- | src/ini_read.c | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/src/ini_read.c b/src/ini_read.c index d4d535d..ac23548 100644 --- a/src/ini_read.c +++ b/src/ini_read.c @@ -19,12 +19,13 @@ struct lci_data fsmdata; size_t strNullLen(const char *str){ if(str == NULL){ return 0; - } else { + } else { return strlen(str); } } char *strResize(char *ptr, size_t oldsize, size_t newsize){ + //return ptr; char *tmp; if(newsize == 0){ //pucol @@ -33,23 +34,22 @@ char *strResize(char *ptr, size_t oldsize, size_t newsize){ } else if(newsize != oldsize){ //Változtat tmp = (char *) malloc(newsize*sizeof(char)); + memset(tmp, 0, newsize); + if(tmp == NULL){ //Hiba esetén nem nyúl hozzá return ptr; } else if(ptr == NULL) { - memset(tmp, 0, newsize); - ptr = tmp; + //memset(tmp, 0, newsize); return tmp; } else if(newsize > oldsize) { // FEL - memset(tmp, 0, newsize); + //memset(tmp, 0, newsize); strncpy(tmp, ptr, oldsize); // old < new - free(ptr); - ptr = tmp; + free(ptr); return tmp; } else if(newsize < oldsize){ //LE - memset(tmp, 0, newsize); + //memset(tmp, 0, newsize); strncpy(tmp, ptr, newsize); // new < old free(ptr); - ptr = tmp; return tmp; } else { //Ide sosem jutunk return ptr; @@ -76,17 +76,8 @@ char unescape(char c){ return '\v'; } else if(c == 'e'){ return 0x1B; - /* } else if(c == '\\'){ //Backslash - return '\\'; - } else if(c == '\''){ //Apostrophe - return '\''; - } else if(c == '\"'){ //Double quotation mark - return '\"'; - } else if(c == '?'){ //Question mark - return '?'; - */ - } else if(c < 0x20){ - return '~'; +/* } else if(c < 0x20){ + return '~'; */ } else { // jó az eredeti return c; } @@ -148,7 +139,7 @@ int64_t getFileMaxLineLen(FILE *tfd){ struct lci_data *iniFSM(struct lci_data *data, const char *in, int64_t len){ - int64_t i,j; + int64_t i,j; enum ini_states pstate=Start, state=Start; char cc; @@ -161,10 +152,12 @@ struct lci_data *iniFSM(struct lci_data *data, const char *in, int64_t len){ switch (state) { case Start: + if(data->nodeState == MULTILINE){ //Elküldjük gyűjteni state = DqmW; // Vagy ValW ?? j = data->valueLen-2; //(x-1) => \0; (x-2) => j--; data->value = strResize(data->value, data->valueLen, data->valueLen+len); // strResize(ptr, oldsize, newsize) + data->valueLen += len; i--; } else if(in[i] == '\n' || in[i] == '\r' || in[i] == '\0'){ //sorvége state = Stop; // Sorvége @@ -175,6 +168,7 @@ struct lci_data *iniFSM(struct lci_data *data, const char *in, int64_t len){ j = -1; state = CommEndW; data->comment = strResize(data->comment, data->commentLen, len); + data->commentLen = len; memset(data->comment, 0, len); data->commentStartPos = i; data->sectionStartPos = -1; //Hogy pucoljon @@ -182,12 +176,14 @@ struct lci_data *iniFSM(struct lci_data *data, const char *in, int64_t len){ j = -1; state = SectEndW; data->section = strResize(data->section, data->sectionLen, len); + data->sectionLen = len; memset(data->section, 0, len); data->sectionStartPos = i; //zárójeleket is veszi! } else if(isalnum(in[i]) ){ //Változó jön j = -1; state = EqW1; data->param = strResize(data->param, data->paramLen, len); + data->paramLen = len; memset(data->param, 0, len); data->paramStartPos = i; i--; @@ -208,6 +204,7 @@ struct lci_data *iniFSM(struct lci_data *data, const char *in, int64_t len){ j = -1; state = CommEndW; data->comment = strResize(data->comment, data->commentLen, len); + data->commentLen = len; memset(data->comment, 0, len); data->commentStartPos = i; data->sectionStartPos = -1; //Hogy pucoljon @@ -215,12 +212,14 @@ struct lci_data *iniFSM(struct lci_data *data, const char *in, int64_t len){ j = -1; state = SectEndW; data->section = strResize(data->section, data->sectionLen, len); + data->sectionLen = len; memset(data->section, 0, len); data->sectionStartPos = i; } else if (isalnum(in[i])){ //Változó lesz belőle j = -1; state = EqW1; data->param = strResize(data->param, data->paramLen, len); + data->paramLen = len; memset(data->param, 0, len); data->paramStartPos = i; i--; @@ -281,6 +280,7 @@ struct lci_data *iniFSM(struct lci_data *data, const char *in, int64_t len){ j = -1; state = CommEndW; data->comment = strResize(data->comment, data->commentLen, len); + data->commentLen = len; memset(data->comment, 0, len); data->commentStartPos = i; data->nodeState = CONTINUE; @@ -334,6 +334,7 @@ struct lci_data *iniFSM(struct lci_data *data, const char *in, int64_t len){ j = -1; state = CommEndW; data->comment = strResize(data->comment, data->commentLen, len); + data->commentLen = len; memset(data->comment, 0, len); data->commentStartPos = i; data->nodeState = CONTINUE; @@ -342,6 +343,7 @@ struct lci_data *iniFSM(struct lci_data *data, const char *in, int64_t len){ j = -1; state = DqmW; data->value = strResize(data->value, data->valueLen, len); + data->valueLen = len; memset(data->value, 0, len); data->valueStartPos = i; data->nodeState = CONTINUE; @@ -351,6 +353,7 @@ struct lci_data *iniFSM(struct lci_data *data, const char *in, int64_t len){ j = -1; state = ValW; data->value = strResize(data->value, data->valueLen, len); + data->valueLen = len; memset(data->value, 0, len); data->valueStartPos = i; data->nodeState = CONTINUE; @@ -377,6 +380,7 @@ struct lci_data *iniFSM(struct lci_data *data, const char *in, int64_t len){ state = CommEndW; j = -1; data->comment = strResize(data->comment, data->commentLen, len); + data->commentLen = len; memset(data->comment, 0, len); data->commentStartPos = i; data->nodeState = CONTINUE; @@ -431,6 +435,7 @@ struct lci_data *iniFSM(struct lci_data *data, const char *in, int64_t len){ j = -1; state = CommEndW; data->comment = strResize(data->comment, data->commentLen, len); + data->commentLen = len; memset(data->comment, 0, len); data->commentStartPos = i; data->nodeState = CONTINUE; @@ -445,7 +450,7 @@ struct lci_data *iniFSM(struct lci_data *data, const char *in, int64_t len){ case DqmW: //dupla idézőjelben az érték - if(pstate != Bslsh && in[i] == '\"'){ //újabb idézőjel -> string vége + if(/*pstate != Bslsh &&*/ in[i] == '\"'){ //újabb idézőjel -> string vége data->value[j] = '\0'; data->valueLen = j+1; data->nodeState = READY; @@ -478,6 +483,7 @@ struct lci_data *iniFSM(struct lci_data *data, const char *in, int64_t len){ case Error: data->errorMsg = strResize(data->errorMsg, data->errorMsgLen, 256); + data->errorMsgLen = 256; memset(data->errorMsg, 0, 256) ; if(pstate == SectEndW || pstate == SectEndD){ @@ -502,7 +508,7 @@ struct lci_data *iniFSM(struct lci_data *data, const char *in, int64_t len){ if(in[i] == '\n' || in[i] == '\r' || in[i] == '\0' || pstate == Error){ //Sorvége, maradunk state = Stop; if(strNullLen(data->section) == 0){data->sectionLen = 0;} - if(strNullLen(data->param) == 0){data->paramLen = 0;} + if(/*data->nodeState != MULTILINE &&*/ strNullLen(data->param) == 0){data->paramLen = 0;} if(strNullLen(data->value) == 0){data->valueLen = 0;} if(strNullLen(data->comment) == 0){data->commentLen = 0;} if(strNullLen(data->errorMsg) == 0){data->errorMsgLen = 0;} @@ -622,8 +628,8 @@ struct lci_data *iniReadOut(const char *filename){ if(list == NULL){ list = curr; } - if(prev != NULL && prev->section != NULL && curr != NULL && curr->section != NULL){ - strncpy(curr->section, prev->section, curr->lineLen); + if(prev != NULL && prev != curr && prev->section != NULL && curr != NULL && curr->section != NULL){ + strncpy(curr->section, prev->section, curr->sectionLen); curr->sectionLen = prev->sectionLen; } if(curr != NULL){ @@ -650,11 +656,14 @@ struct lci_data *iniReadOut(const char *filename){ prev = curr; } else { //Az előzőhöz hozzávesszük a mostanit prev->next = curr; - if(prev->next != NULL){ //Csak, ha lett új felvéve + if(prev->next != NULL && curr->nodeState != MULTILINE){ //Csak, ha lett új felvéve prev = prev->next; } } + if(curr != NULL && curr->nodeState == ERROR){ + return list; + } pos = 0; memset(buff, 0, linemax); } else { |