fixed a bug that the ini-format reader of xli handles a comment on the same line as the key-value pair.
did a preparatory work for writing qse_xli_writeini()
This commit is contained in:
parent
9532597507
commit
9cf7a9af9d
@ -139,6 +139,11 @@ QSE_EXPORT int qse_xli_writestd (
|
|||||||
qse_xli_iostd_t* out
|
qse_xli_iostd_t* out
|
||||||
);
|
);
|
||||||
|
|
||||||
|
QSE_EXPORT int qse_xli_writeinistd (
|
||||||
|
qse_xli_t* xli,
|
||||||
|
qse_xli_iostd_t* out
|
||||||
|
);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -739,6 +739,11 @@ QSE_EXPORT int qse_xli_write (
|
|||||||
qse_xli_io_impl_t io
|
qse_xli_io_impl_t io
|
||||||
);
|
);
|
||||||
|
|
||||||
|
QSE_EXPORT int qse_xli_writeini (
|
||||||
|
qse_xli_t* xli,
|
||||||
|
qse_xli_io_impl_t io
|
||||||
|
);
|
||||||
|
|
||||||
QSE_EXPORT void* qse_getxlipairxtn (
|
QSE_EXPORT void* qse_getxlipairxtn (
|
||||||
qse_xli_pair_t* pair
|
qse_xli_pair_t* pair
|
||||||
);
|
);
|
||||||
|
@ -5,7 +5,7 @@ AM_CPPFLAGS = \
|
|||||||
-I$(top_srcdir)/include
|
-I$(top_srcdir)/include
|
||||||
|
|
||||||
lib_LTLIBRARIES = libqsexli.la
|
lib_LTLIBRARIES = libqsexli.la
|
||||||
libqsexli_la_SOURCES = xli.h xli.c err.c read.c read-ini.c write.c std.c
|
libqsexli_la_SOURCES = xli.h xli.c err.c read.c read-ini.c write.c write-ini.c std.c
|
||||||
libqsexli_la_LDFLAGS = -L../cmn -version-info 1:0:0 -no-undefined
|
libqsexli_la_LDFLAGS = -L../cmn -version-info 1:0:0 -no-undefined
|
||||||
libqsexli_la_LIBADD = -lqsecmn
|
libqsexli_la_LIBADD = -lqsecmn
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ am__uninstall_files_from_dir = { \
|
|||||||
am__installdirs = "$(DESTDIR)$(libdir)"
|
am__installdirs = "$(DESTDIR)$(libdir)"
|
||||||
LTLIBRARIES = $(lib_LTLIBRARIES)
|
LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||||
libqsexli_la_DEPENDENCIES =
|
libqsexli_la_DEPENDENCIES =
|
||||||
am_libqsexli_la_OBJECTS = xli.lo err.lo read.lo read-ini.lo write.lo \
|
am_libqsexli_la_OBJECTS = xli.lo err.lo read.lo read-ini.lo write.lo write-ini.lo \
|
||||||
std.lo
|
std.lo
|
||||||
libqsexli_la_OBJECTS = $(am_libqsexli_la_OBJECTS)
|
libqsexli_la_OBJECTS = $(am_libqsexli_la_OBJECTS)
|
||||||
AM_V_lt = $(am__v_lt_@AM_V@)
|
AM_V_lt = $(am__v_lt_@AM_V@)
|
||||||
@ -378,7 +378,7 @@ AM_CPPFLAGS = \
|
|||||||
-I$(top_srcdir)/include
|
-I$(top_srcdir)/include
|
||||||
|
|
||||||
lib_LTLIBRARIES = libqsexli.la
|
lib_LTLIBRARIES = libqsexli.la
|
||||||
libqsexli_la_SOURCES = xli.h xli.c err.c read.c read-ini.c write.c std.c
|
libqsexli_la_SOURCES = xli.h xli.c err.c read.c read-ini.c write.c write-ini.c std.c
|
||||||
libqsexli_la_LDFLAGS = -L../cmn -version-info 1:0:0 -no-undefined
|
libqsexli_la_LDFLAGS = -L../cmn -version-info 1:0:0 -no-undefined
|
||||||
libqsexli_la_LIBADD = -lqsecmn
|
libqsexli_la_LIBADD = -lqsecmn
|
||||||
all: all-am
|
all: all-am
|
||||||
@ -465,6 +465,7 @@ distclean-compile:
|
|||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/read.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/read.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/std.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/std.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/write.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/write.Plo@am__quote@
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/write-ini.Plo@am__quote@
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xli.Plo@am__quote@
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xli.Plo@am__quote@
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
|
@ -112,12 +112,16 @@ static int skip_comment (qse_xli_t* xli, qse_xli_tok_t* tok)
|
|||||||
GET_CHAR_TO (xli, c);
|
GET_CHAR_TO (xli, c);
|
||||||
if (c == QSE_T('\n') || c == QSE_CHAR_EOF) break;
|
if (c == QSE_T('\n') || c == QSE_CHAR_EOF) break;
|
||||||
|
|
||||||
|
/* i don't honor QSE_XLI_KEEPTEXT in the ini-format reader...
|
||||||
if (xli->opt.trait & QSE_XLI_KEEPTEXT) ADD_TOKEN_CHAR (xli, tok, c);
|
if (xli->opt.trait & QSE_XLI_KEEPTEXT) ADD_TOKEN_CHAR (xli, tok, c);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
while (1);
|
while (1);
|
||||||
|
|
||||||
|
/* i don't honor QSE_XLI_KEEPTEXT in the ini-format reader...
|
||||||
if ((xli->opt.trait & QSE_XLI_KEEPTEXT) &&
|
if ((xli->opt.trait & QSE_XLI_KEEPTEXT) &&
|
||||||
qse_xli_inserttext (xli, xli->parlink->list, QSE_NULL, QSE_STR_PTR(tok->name)) == QSE_NULL) return -1;
|
qse_xli_inserttext (xli, &xli->root->list, QSE_NULL, QSE_STR_PTR(tok->name)) == QSE_NULL) return -1;
|
||||||
|
*/
|
||||||
|
|
||||||
GET_CHAR (xli); /* eat the new line letter */
|
GET_CHAR (xli); /* eat the new line letter */
|
||||||
return 1; /* comment by ; */
|
return 1; /* comment by ; */
|
||||||
@ -135,8 +139,12 @@ static int get_token_into (qse_xli_t* xli, qse_xli_tok_t* tok)
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (skip_spaces (xli) <= -1) return -1;
|
if (skip_spaces (xli) <= -1) return -1;
|
||||||
|
if (!(xli->tok_status & TOK_STATUS_UPTO_EOL))
|
||||||
|
{
|
||||||
if ((n = skip_comment (xli, tok)) <= -1) return -1;
|
if ((n = skip_comment (xli, tok)) <= -1) return -1;
|
||||||
}
|
}
|
||||||
|
else n = 0;
|
||||||
|
}
|
||||||
while (n >= 1);
|
while (n >= 1);
|
||||||
|
|
||||||
qse_str_clear (tok->name);
|
qse_str_clear (tok->name);
|
||||||
@ -297,6 +305,9 @@ static int read_list (qse_xli_t* xli)
|
|||||||
qse_cstr_t key;
|
qse_cstr_t key;
|
||||||
qse_xli_list_t* curlist;
|
qse_xli_list_t* curlist;
|
||||||
|
|
||||||
|
key.ptr = QSE_NULL;
|
||||||
|
key.len = 0;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if (MATCH(xli, QSE_XLI_TOK_EOF)) break;
|
if (MATCH(xli, QSE_XLI_TOK_EOF)) break;
|
||||||
@ -305,19 +316,19 @@ static int read_list (qse_xli_t* xli)
|
|||||||
{
|
{
|
||||||
/* insert a pair with an empty list */
|
/* insert a pair with an empty list */
|
||||||
pair = qse_xli_insertpairwithemptylist (xli, &xli->root->list, QSE_NULL, QSE_STR_PTR(xli->tok.name), QSE_NULL, QSE_NULL);
|
pair = qse_xli_insertpairwithemptylist (xli, &xli->root->list, QSE_NULL, QSE_STR_PTR(xli->tok.name), QSE_NULL, QSE_NULL);
|
||||||
if (pair == QSE_NULL) return -1;
|
if (pair == QSE_NULL) goto oops;
|
||||||
curlist = (qse_xli_list_t*)pair->val;
|
curlist = (qse_xli_list_t*)pair->val;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if (get_token(xli) <= -1) return -1;
|
if (get_token(xli) <= -1) goto oops;
|
||||||
|
|
||||||
if (MATCH(xli, QSE_XLI_TOK_EOF)) break;
|
if (MATCH(xli, QSE_XLI_TOK_EOF)) break;
|
||||||
if (MATCH(xli, QSE_XLI_TOK_TAG))
|
if (MATCH(xli, QSE_XLI_TOK_TAG))
|
||||||
{
|
{
|
||||||
/* switch to a new tag */
|
/* switch to a new tag */
|
||||||
pair = qse_xli_insertpairwithemptylist (xli, &xli->root->list, QSE_NULL, QSE_STR_PTR(xli->tok.name), QSE_NULL, QSE_NULL);
|
pair = qse_xli_insertpairwithemptylist (xli, &xli->root->list, QSE_NULL, QSE_STR_PTR(xli->tok.name), QSE_NULL, QSE_NULL);
|
||||||
if (pair == QSE_NULL) return -1;
|
if (pair == QSE_NULL) goto oops;
|
||||||
curlist = (qse_xli_list_t*)pair->val;
|
curlist = (qse_xli_list_t*)pair->val;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -325,7 +336,7 @@ static int read_list (qse_xli_t* xli)
|
|||||||
if (!MATCH(xli, QSE_XLI_TOK_IDENT))
|
if (!MATCH(xli, QSE_XLI_TOK_IDENT))
|
||||||
{
|
{
|
||||||
qse_xli_seterror (xli, QSE_XLI_EKEY, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
qse_xli_seterror (xli, QSE_XLI_EKEY, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
||||||
return -1;
|
goto oops;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xli->opt.trait & QSE_XLI_KEYNODUP)
|
if (xli->opt.trait & QSE_XLI_KEYNODUP)
|
||||||
@ -341,41 +352,35 @@ static int read_list (qse_xli_t* xli)
|
|||||||
qse_strcmp (((qse_xli_pair_t*)atom)->key, QSE_STR_PTR(xli->tok.name)) == 0)
|
qse_strcmp (((qse_xli_pair_t*)atom)->key, QSE_STR_PTR(xli->tok.name)) == 0)
|
||||||
{
|
{
|
||||||
qse_xli_seterror (xli, QSE_XLI_EEXIST, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
qse_xli_seterror (xli, QSE_XLI_EEXIST, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
||||||
return -1;
|
goto oops;
|
||||||
}
|
}
|
||||||
|
|
||||||
atom = atom->prev;
|
atom = atom->prev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSE_ASSERT (key.ptr == QSE_NULL);
|
||||||
key.len = QSE_STR_LEN(xli->tok.name);
|
key.len = QSE_STR_LEN(xli->tok.name);
|
||||||
key.ptr = qse_strdup (QSE_STR_PTR(xli->tok.name), xli->mmgr);
|
key.ptr = qse_strdup (QSE_STR_PTR(xli->tok.name), xli->mmgr);
|
||||||
if (key.ptr == QSE_NULL)
|
if (key.ptr == QSE_NULL)
|
||||||
{
|
{
|
||||||
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
|
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
|
||||||
return -1;
|
goto oops;
|
||||||
}
|
}
|
||||||
|
|
||||||
xli->tok_status |= TOK_STATUS_SAME_LINE;
|
xli->tok_status |= TOK_STATUS_SAME_LINE;
|
||||||
if (get_token (xli) <= -1)
|
if (get_token (xli) <= -1) goto oops;
|
||||||
{
|
|
||||||
QSE_MMGR_FREE (xli->mmgr, key.ptr);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (!MATCH(xli, QSE_XLI_TOK_EQ))
|
if (!MATCH(xli, QSE_XLI_TOK_EQ))
|
||||||
{
|
{
|
||||||
QSE_MMGR_FREE (xli->mmgr, key.ptr);
|
|
||||||
qse_xli_seterror (xli, QSE_XLI_EEQ, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
qse_xli_seterror (xli, QSE_XLI_EEQ, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
||||||
return -1;
|
goto oops;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read the value */
|
/* read the value */
|
||||||
xli->tok_status |= TOK_STATUS_UPTO_EOL;
|
xli->tok_status |= TOK_STATUS_UPTO_EOL;
|
||||||
if (get_token (xli) <= -1)
|
if (get_token (xli) <= -1) goto oops;
|
||||||
{
|
|
||||||
QSE_MMGR_FREE (xli->mmgr, key.ptr);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
xli->tok_status &= ~(TOK_STATUS_SAME_LINE | TOK_STATUS_UPTO_EOL);
|
xli->tok_status &= ~(TOK_STATUS_SAME_LINE | TOK_STATUS_UPTO_EOL);
|
||||||
|
|
||||||
if (MATCH(xli, QSE_XLI_TOK_EOF))
|
if (MATCH(xli, QSE_XLI_TOK_EOF))
|
||||||
@ -387,8 +392,11 @@ static int read_list (qse_xli_t* xli)
|
|||||||
empty.len = 0;
|
empty.len = 0;
|
||||||
|
|
||||||
pair = qse_xli_insertpairwithstr (xli, curlist, QSE_NULL, key.ptr, QSE_NULL, QSE_NULL, &empty, QSE_NULL);
|
pair = qse_xli_insertpairwithstr (xli, curlist, QSE_NULL, key.ptr, QSE_NULL, QSE_NULL, &empty, QSE_NULL);
|
||||||
|
|
||||||
QSE_MMGR_FREE (xli->mmgr, key.ptr);
|
QSE_MMGR_FREE (xli->mmgr, key.ptr);
|
||||||
if (pair == QSE_NULL) return -1;
|
key.ptr = QSE_NULL;
|
||||||
|
|
||||||
|
if (pair == QSE_NULL) goto oops;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,24 +404,31 @@ static int read_list (qse_xli_t* xli)
|
|||||||
{
|
{
|
||||||
/* add a new pair with the initial string segment */
|
/* add a new pair with the initial string segment */
|
||||||
pair = qse_xli_insertpairwithstr (xli, curlist, QSE_NULL, key.ptr, QSE_NULL, QSE_NULL, QSE_STR_XSTR(xli->tok.name), QSE_NULL);
|
pair = qse_xli_insertpairwithstr (xli, curlist, QSE_NULL, key.ptr, QSE_NULL, QSE_NULL, QSE_STR_XSTR(xli->tok.name), QSE_NULL);
|
||||||
|
|
||||||
QSE_MMGR_FREE (xli->mmgr, key.ptr);
|
QSE_MMGR_FREE (xli->mmgr, key.ptr);
|
||||||
if (pair == QSE_NULL) return -1;
|
key.ptr = QSE_NULL;
|
||||||
|
|
||||||
|
if (pair == QSE_NULL) goto oops;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qse_xli_seterror (xli, QSE_XLI_EVAL, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
qse_xli_seterror (xli, QSE_XLI_EVAL, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
||||||
return -1;
|
goto oops;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qse_xli_seterror (xli, QSE_XLI_ESECTAG, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
qse_xli_seterror (xli, QSE_XLI_ESECTAG, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
||||||
return -1;
|
goto oops;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
oops:
|
||||||
|
if (key.ptr) QSE_MMGR_FREE (xli->mmgr, key.ptr);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_root_list (qse_xli_t* xli)
|
static int read_root_list (qse_xli_t* xli)
|
||||||
@ -461,8 +476,6 @@ int qse_xli_readini (qse_xli_t* xli, qse_xli_io_impl_t io)
|
|||||||
|
|
||||||
if (read_root_list (xli) <= -1) goto oops;
|
if (read_root_list (xli) <= -1) goto oops;
|
||||||
|
|
||||||
QSE_ASSERT (xli->parlink == QSE_NULL);
|
|
||||||
|
|
||||||
if (!MATCH (xli, QSE_XLI_TOK_EOF))
|
if (!MATCH (xli, QSE_XLI_TOK_EOF))
|
||||||
{
|
{
|
||||||
qse_xli_seterror (xli, QSE_XLI_ESYNTAX, QSE_NULL, &xli->tok.loc);
|
qse_xli_seterror (xli, QSE_XLI_ESYNTAX, QSE_NULL, &xli->tok.loc);
|
||||||
|
@ -662,3 +662,33 @@ int qse_xli_writestd (qse_xli_t* xli, qse_xli_iostd_t* out)
|
|||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int qse_xli_writeinistd (qse_xli_t* xli, qse_xli_iostd_t* out)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
xtn_t* xtn = (xtn_t*) QSE_XTN (xli);
|
||||||
|
|
||||||
|
if (out == QSE_NULL || (out->type != QSE_XLI_IOSTD_FILE &&
|
||||||
|
out->type != QSE_XLI_IOSTD_STR))
|
||||||
|
{
|
||||||
|
/* the input is a must. at least 1 file or 1 string
|
||||||
|
* must be specified */
|
||||||
|
qse_xli_seterrnum (xli, QSE_XLI_EINVAL, QSE_NULL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
xtn->s.out.x = out;
|
||||||
|
n = qse_xli_writeini (xli, sf_out);
|
||||||
|
|
||||||
|
if (out->type == QSE_XLI_IOSTD_STR)
|
||||||
|
{
|
||||||
|
if (n >= 0)
|
||||||
|
{
|
||||||
|
QSE_ASSERT (xtn->s.out.u.str.buf != QSE_NULL);
|
||||||
|
qse_str_yield (xtn->s.out.u.str.buf, &out->u.str, 0);
|
||||||
|
}
|
||||||
|
if (xtn->s.out.u.str.buf) qse_str_close (xtn->s.out.u.str.buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
32
qse/lib/xli/write-ini.c
Normal file
32
qse/lib/xli/write-ini.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "xli.h"
|
||||||
|
|
||||||
|
int qse_xli_writeini (qse_xli_t* xli, qse_xli_io_impl_t io)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user