--- libaitcfg/src/Attic/tools.c 2010/03/22 14:53:49 1.3 +++ libaitcfg/src/Attic/tools.c 2010/03/22 15:15:48 1.4 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: tools.c,v 1.3 2010/03/22 14:53:49 misho Exp $ +* $Id: tools.c,v 1.4 2010/03/22 15:15:48 misho Exp $ * *************************************************************************/ #include "global.h" @@ -23,24 +23,25 @@ inline int ltrim(u_char *psLine) if (!pos) return 0; - memmove(psLine, psLine + pos, strlen((char*) psLine) - pos + 1); + memmove(psLine, psLine + pos, (strlen((char*) psLine) - pos) + 1); return pos; } // rtrim() Right trim whitespaces inline int rtrim(u_char *psLine) { - int i, pos = 0; + register int i; + int pos = 0; if (!psLine) return 0; - for (i = strlen((char*) psLine); i; i--) { - switch (psLine[i - 1]) { + for (i = strlen((char*) psLine) - 1; i; i--) { + switch (psLine[i]) { case ' ': case '\t': case '\r': case '\n': - psLine[i - 1] = 0; + psLine[i] = 0; pos++; continue; } @@ -61,4 +62,32 @@ inline int trim(u_char *psLine) ret += rtrim(psLine); return ret; +} + +// unquot() Unquoted string +inline int unquot(u_char *psLine) +{ + char *pos, *str = NULL; + int flg; + + if (!psLine) + return 0; + + switch (*psLine) { + case '`': + case '"': + case '\'': + str = strdup((char*) psLine + 1); + for (pos = str, flg = 0; *pos; flg = ('\\' == *pos), pos++) { + if (!flg && *pos == *psLine) { + *pos = 0; + strlcpy((char*) psLine, str, strlen((char*) psLine) + 1); + break; + } + } + free(str); + return 1; + } + + return 0; }