Problem with wchar in Linux

Gustavo Felisberto <[email protected]> Fri, 24 Apr 2009 15:06:08 +0100
Newsgroups gmane.text.xml.expat.general
Message-ID <[email protected]>
Hello, I'm having problems with wchar in Linux. I've built expat with:

./configure --prefix=/home/humpback/bin/expat CFLAGS="-g -O2
-fshort-wchar" CPPFLAGS="-DXML_LARGE_SIZE -DXML_UNICODE_WCHAR_T"
--disable-shared --enable-static
make buildlib LIBRARY=libexpatwf.la
make installlib LIBRARY=libexpatwf.la

I then modified one of the samples provided in expat and built (source is attached):


g++ -DXML_LARGE_SIZE -DXML_UNICODE_WCHAR_T -O0 -g3 -Wall -c
-fmessage-length=0 -MMD -MP -MF"expattests.d" -MT"CPPTestes.d"
-o"expattests.o" "expattests.cpp"

g++  -L/home/humpback/bin/expat/lib -o"expattests"  expattests.o -lexpatwf

When i run the resulting code I get errors in printf because the data is
not valid. Can someone help me?

-- 
Gustavo Felisberto.
WIT-Software, Lda
Coimbra (Portugal), San Jose (California)
Phone: +351239801030
Web: http://www.wit-software.com

_______________________________________________
Expat-discuss mailing list
[email protected]
http://mail.libexpat.org/mailman/listinfo/expat-discuss
expattests.cpp (text/x-c++src, 1.3 KB)
#include <stdio.h>
#include <expat.h>

#if defined(__amigaos__) && defined(__USE_INLINE__)
#include <proto/expat.h>
#endif

#ifdef XML_LARGE_SIZE
#if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400
#define XML_FMT_INT_MOD "I64"
#else
#define XML_FMT_INT_MOD "ll"
#endif
#else
#define XML_FMT_INT_MOD "l"
#endif

#define BUFFSIZE        8192

static char Buff[1024] = "<xml>\n<name>\nGustavo\n</name>\n<crap>\n</crap>";

int Depth;

static void XMLCALL
start(void *data, const wchar_t *el, const wchar_t **attr) {
	int i;

	for (i = 0; i < Depth; i++) {
		printf("  ");
	}

	if (printf("%ls", el) < 0) {
		printf("error printing");
	}

	for (i = 0; attr[i]; i += 2) {
		printf(" %ls='%ls'", attr[i], attr[i + 1]);
	}

	printf("\n");
	Depth++;
}

static void XMLCALL
end(void *data, const wchar_t *el) {
	Depth--;
}

int main(int argc, char *argv[]) {
	XML_Parser p = XML_ParserCreate(NULL);
	if (!p) {
		printf("Couldn't allocate memory for parser\n");
		exit(-1);
	}

	XML_SetElementHandler(p, start, end);

	int len;

	len = sizeof(Buff);

	if (XML_Parse(p, Buff, len, 1) == XML_STATUS_ERROR) {
		printf("Parse error at line %" XML_FMT_INT_MOD "u:\n%ls\n",
				XML_GetCurrentLineNumber(p), XML_ErrorString(
						XML_GetErrorCode(p)));
		exit(-1);
	}

	XML_ParserFree(p);
	return 0;
}
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAknxx1cACgkQHcteKKZlrPqwlgCgym/0NFtpOIqnkusui8pF//Bf
CiQAn1ytLvADswLiCGnPqSSmNmAIKIjt
=y6VP
-----END PGP SIGNATURE-----