--- libaitcfg/src/parse.c 2009/09/09 09:29:37 1.2.2.1 +++ libaitcfg/src/parse.c 2009/09/09 20:42:07 1.2.2.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: parse.c,v 1.2.2.1 2009/09/09 09:29:37 misho Exp $ +* $Id: parse.c,v 1.2.2.2 2009/09/09 20:42:07 misho Exp $ * *************************************************************************/ #include "global.h" @@ -24,6 +24,22 @@ static inline int cfgDbg(FILE *f, char *fmt, ...) return ret; } +/* + * InvertQueue() InvertQueue order //{cfg} list of elements for revert + * @cfg = Head list element for revert +*/ +static inline void InvertQueue(sl_config * __restrict cfg) +{ + struct tagPair *item, *next, *prev = NULL; + + for (item = cfg->slh_first; item; item = next) { + next = item->sle_next; + item->sle_next = prev; + prev = item; + } + cfg->slh_first = prev; +} + // cfgWrite() Write to file from config list static inline int cfgWrite(FILE *f, sl_config * __restrict cfg, int whitespace) { @@ -42,6 +58,7 @@ static inline int cfgWrite(FILE *f, sl_config * __rest return -1; } + InvertQueue(cfg); for (av = cfg->slh_first; av; av = av->sle_next) { if (av->psSection && strcmp((char*) av->psSection, (char*) szSection)) { strlcpy((char*) szSection, (char*) av->psSection, MAX_STR + 1); @@ -70,6 +87,7 @@ static inline int cfgWrite(FILE *f, sl_config * __rest } } } + InvertQueue(cfg); bzero(szTime, MAX_STR + 1); time(&tim); @@ -82,7 +100,7 @@ static inline int cfgWrite(FILE *f, sl_config * __rest return 0; } -// ----------------------------------------- +// --------------------------------------------------- /* * ReadConfig() Read from file and add new item to config list