29 #define DISABLE_DEBUGLOG
51 #include <gwenhywfar/gwenhywfarapi.h>
52 #include <gwenhywfar/debug.h>
53 #include <gwenhywfar/stringlist.h>
89 while(*src && (
unsigned char)(*src)<33)
106 while(*src && size<(maxsize-1)) {
121 if (!insideQuotes && strchr(delims, *src)!=0)
131 "Found a closing \" without an opening one "
132 "(consider using a backslash to escape)");
149 if (isspace((
int)((
unsigned char)*src)) && !lastWasEscape) {
173 if (strchr(delims, *src)==0) {
188 if (lastBlankPos!=-1)
189 buffer[lastBlankPos]=0;
203 const char *savedSrc=src;
211 while(*src && (
unsigned char)(*src)<33) {
212 if (strchr(delims, *src)) {
246 if (!insideQuotes && strchr(delims, *src)!=0)
256 "Found a closing \" without an opening one "
257 "(consider using a backslash to escape)");
274 if (!lastWasEscape && *((
unsigned char*)src)<33) {
295 if (strchr(delims, *src)==0) {
310 if (lastBlankPos!=-1)
322 unsigned int maxsize) {
329 x=(
unsigned char)*src;
331 (x>=
'A' && x<=
'Z') ||
332 (x>=
'a' && x<=
'z') ||
333 (x>=
'0' && x<=
'9'))) {
336 if ((maxsize-1)<size+3) {
341 c=(((
unsigned char)(*src))>>4)&0xf;
346 c=((
unsigned char)(*src))&0xf;
353 if (size<(maxsize-1))
372 unsigned int maxsize) {
379 x=(
unsigned char)*src;
381 (x>=
'A' && x<=
'Z') ||
382 (x>=
'a' && x<=
'z') ||
383 (x>=
'0' && x<=
'9') ||
393 if ((maxsize-1)<size+3) {
398 c=(((
unsigned char)(*src))>>4)&0xf;
403 c=((
unsigned char)(*src))&0xf;
410 if (size<(maxsize-1))
430 unsigned int maxsize){
435 while(*src && srclen>0) {
438 x=(
unsigned char)*src;
440 (x>=
'A' && x<=
'Z') ||
441 (x>=
'a' && x<=
'z') ||
442 (x>=
'0' && x<=
'9')) {
443 if (size<(maxsize-1))
452 unsigned char d1, d2;
461 if (!(*src) || !isxdigit((
int)*src)) {
466 d1=(
unsigned char)(toupper(*src));
470 if (!(*src) || !isxdigit((
int)*src)) {
474 d2=(
unsigned char)(toupper(*src));
485 if (size<(maxsize-1))
486 buffer[size++]=(
char)c;
495 "characters in escaped string (\"%s\")",
512 unsigned int maxsize){
524 unsigned int maxsize){
529 while(*src && srclen>0) {
532 x=(
unsigned char)*src;
534 (x>=
'A' && x<=
'Z') ||
535 (x>=
'a' && x<=
'z') ||
536 (x>=
'0' && x<=
'9') ||
544 if (size<(maxsize-1))
553 unsigned char d1, d2;
562 if (!(*src) || !isxdigit((
int)*src)) {
567 d1=(
unsigned char)(toupper(*src));
571 if (!(*src) || !isxdigit((
int)*src)) {
575 d2=(
unsigned char)(toupper(*src));
586 if (size<(maxsize-1))
587 buffer[size++]=(
char)c;
596 "characters in escaped string (\"%s\")",
613 unsigned int maxsize){
623 char *buffer,
unsigned int maxsize) {
627 if ((l*2)+1 > maxsize) {
637 c=(((
unsigned char)(src[pos]))>>4)&0xf;
642 c=((
unsigned char)(src[pos]))&0xf;
659 unsigned int groupsize,
661 int skipLeadingZeroes) {
676 c=(((
unsigned char)(src[pos]))>>4)&0xf;
677 if (skipLeadingZeroes) {
687 if (size+1>=maxsize) {
694 if (size+1>=maxsize) {
698 buffer[size++]=delimiter;
704 c=((
unsigned char)(src[pos]))&0xf;
705 if (skipLeadingZeroes) {
714 if (size+1>=maxsize) {
723 if (size+1>=maxsize) {
727 buffer[size++]=delimiter;
742 unsigned int groupsize,
744 int skipLeadingZeroes){
759 c=(((
unsigned char)(src[pos]))>>4)&0xf;
760 if (skipLeadingZeroes) {
775 if (groupsize && j==groupsize) {
785 c=((
unsigned char)(src[pos]))&0xf;
786 if (skipLeadingZeroes) {
801 if (groupsize && j==groupsize) {
825 unsigned char d1, d2;
829 if (!isxdigit((
int)*src)) {
833 d1=(
unsigned char)(toupper(*src));
837 if (!(*src) || !isxdigit((
int)*src)) {
841 d2=(
unsigned char)(toupper(*src));
855 buffer[size++]=(
char)c;
869 unsigned char d1, d2;
873 if (isspace((
int)*src)) {
877 if (!isxdigit((
int)*src)) {
881 d1=(
unsigned char)(toupper(*src));
885 if (!(*src) || !isxdigit((
int)*src)) {
889 d2=(
unsigned char)(toupper(*src));
918 unsigned char d1, d2;
927 if (!isdigit((
int)*src)) {
931 d1=(
unsigned char)(*src);
935 if (!(*src) || !isxdigit((
int)*src)) {
939 d2=(
unsigned char)(*src);
958 unsigned int groupsize,
960 int skipLeadingZeroes){
975 c=(((
unsigned char)(src[pos]))>>4)&0xf;
976 if (skipLeadingZeroes) {
989 if (groupsize && j==groupsize) {
999 c=((
unsigned char)(src[pos]))&0xf;
1000 if (skipLeadingZeroes) {
1001 if (c==0 && pos+1<l)
1004 skipLeadingZeroes=0;
1013 if (groupsize && j==groupsize) {
1044 return strcasecmp(s1, s2);
1046 return strcmp(s1, s2);
1053 while(*haystack && tolower(*haystack)!=tolower(*needle))
1064 while(*t && *s && (tolower(*t)==tolower(*s))) {
1086 const char *p,
unsigned int *ppos,
1088 unsigned int *matches) {
1094 unsigned int _wpos = *wpos, _ppos = *ppos, _matches = *matches;
1101 while (_wpos<wlength && _ppos<plength) {
1107 *matches = _matches;
1117 if (a!=b && b!=
'?') {
1120 *matches = _matches;
1127 if (_wpos==wlength && _ppos==plength) {
1130 *matches = _matches;
1134 if (_wpos>=wlength && _ppos<plength)
1135 if (p[_ppos]==
'*') {
1138 *matches = _matches;
1144 *matches = _matches;
1151 const char *p,
unsigned int *ppos,
1153 unsigned int *matches) {
1154 unsigned int lwpos, lppos, lmatches;
1161 while(lwpos<wlength) {
1176 unsigned int matches;
1177 unsigned int plength;
1179 ppos=wpos=matches=0;
1212 sprintf(lbuffer,
"%d", num);
1220 strcpy(buffer, lbuffer);
1222 buffer[i++]=fillchar;
1226 else if (fillchar<0) {
1234 strcat(buffer, lbuffer);
1239 strcpy(buffer, lbuffer);
1247 unsigned int insert) {
1254 for (k=0; k<insert; k++)
1255 fprintf(stderr,
" ");
1256 fprintf(stderr,
"String size is %d:\n",l);
1258 for (k=0; k<insert; k++)
1259 fprintf(stderr,
" ");
1260 fprintf(stderr,
"%04x: ",pos);
1266 for (i=pos; i<j; i++) {
1267 fprintf(stderr,
"%02x ",(
unsigned char)s[i]);
1270 for (i=0; i<16-(j-pos); i++)
1271 fprintf(stderr,
" ");
1273 for (i=pos; i<j; i++) {
1275 fprintf(stderr,
".");
1277 fprintf(stderr,
"%c",s[i]);
1279 fprintf(stderr,
"\n");
1288 unsigned int insert) {
1296 for (k=0; k<insert; k++)
1299 snprintf(numbuf,
sizeof(numbuf),
"%d", l);
1303 for (k=0; k<insert; k++)
1305 snprintf(numbuf,
sizeof(numbuf),
"%04x: ",pos);
1312 for (i=pos; i<j; i++) {
1313 snprintf(numbuf,
sizeof(numbuf),
"%02x ", (
unsigned char)s[i]);
1317 for (i=0; i<16-(j-pos); i++)
1320 for (i=pos; i<j; i++) {
1341 x=(
unsigned char)*src;
1343 (x>=
'A' && x<=
'Z') ||
1344 (x>=
'a' && x<=
'z') ||
1345 (x>=
'0' && x<=
'9'))) {
1349 c=(((
unsigned char)(*src))>>4)&0xf;
1354 c=((
unsigned char)(*src))&0xf;
1375 x=(
unsigned char)*src;
1377 (x>=
'A' && x<=
'Z') ||
1378 (x>=
'a' && x<=
'z') ||
1379 (x>=
'0' && x<=
'9')) {
1384 unsigned char d1, d2;
1389 if (!(*src) || !isxdigit((
int)*src)) {
1394 d1=(
unsigned char)(toupper(*src));
1398 if (!(*src) || !isxdigit((
int)*src)) {
1402 d2=(
unsigned char)(toupper(*src));
1417 "characters in escaped string (\"%s\")",
1434 x=(
unsigned char)*src;
1436 (x>=
'A' && x<=
'Z') ||
1437 (x>=
'a' && x<=
'z') ||
1438 (x>=
'0' && x<=
'9') ||
1451 c=(((
unsigned char)(*src))>>4)&0xf;
1456 c=((
unsigned char)(*src))&0xf;
1481 if (strlen(src)>2) {
1482 unsigned char d1, d2;
1485 if (isxdigit((
int)src[1]) && isxdigit((
int)src[2])) {
1489 d1=(
unsigned char)(toupper(*src));
1493 d2=(
unsigned char)(toupper(*src));
1531 (x>=
'A' && x<=
'Z') ||
1532 (x>=
'a' && x<=
'z') ||
1533 (x>=
'0' && x<=
'9') ||
1544 c=(((
unsigned char)x)>>4)&0xf;
1549 c=((
unsigned char)x)&0xf;
1565 const char *logDomain,
1591 for (i=0; i<size; i++) {
1593 if (isspace((
int)*p)) {
1594 if (!lastWasBlank) {
1610 if (lastBlankPos!=0)
1622 #ifdef HAVE_SETLOCALE
1623 const char *orig_locale = setlocale(LC_NUMERIC,
NULL);
1624 char *currentLocale = strdup(orig_locale ? orig_locale :
"C");
1625 setlocale(LC_NUMERIC,
"C");
1628 rv=snprintf(numbuf,
sizeof(numbuf),
"%f", num);
1630 #ifdef HAVE_SETLOCALE
1631 setlocale(LC_NUMERIC, currentLocale);
1632 free(currentLocale);
1635 if (rv<1 || rv>=
sizeof(numbuf))
1645 #ifdef HAVE_SETLOCALE
1646 const char *orig_locale = setlocale(LC_NUMERIC,
NULL);
1647 char *currentLocale = strdup(orig_locale ? orig_locale :
"C");
1648 setlocale(LC_NUMERIC,
"C");
1651 rv=sscanf(s,
"%lf", num);
1653 #ifdef HAVE_SETLOCALE
1654 setlocale(LC_NUMERIC, currentLocale);
1655 free(currentLocale);
1670 nboth=strlen(s1)+strlen(s2);
1681 if (toupper(*s1)==toupper(*t)) {
1685 if (isalnum((
int)*s1) && isalnum((
int)*t)) {
1713 if (toupper(*s1)==toupper(*t)) {
1717 if (isalnum((
int)*s1) && isalnum((
int)*t)) {
1733 pc=(nmatch*100)/nboth;
1759 while(handled<len) {
1763 c=(
unsigned char)*s;
1764 if ((c & 0xfe)==0xfc)
1766 else if ((c & 0xfc)==0xf8)
1768 else if ((c & 0xf8)==0xf0)
1770 else if ((c & 0xf0)==0xe0)
1772 else if ((c & 0xe0)==0xc0)
1774 else if (c & 0x80) {
1780 if (handled+i+1>len) {
1782 "Incomplete UTF8 sequence at pos %d", handled);
1789 for (j=0; j<i; j++) {
1790 if ((((
unsigned char)*s) & 0xc0)!=0xc0) {
1792 "Invalid UTF8 sequence at pos %d (rel %d of %d)",
1810 uint32_t bytesAdded;
1812 #define GWEN_TEXT__APPENDCHAR(chr) \
1815 GWEN_Buffer_IncrementPos(buf, bytesAdded); \
1816 GWEN_Buffer_AdjustUsedBytes(buf); \
1818 GWEN_Buffer_AllocRoom(buf, 2); \
1819 pdst=GWEN_Buffer_GetPosPointer(buf); \
1820 roomLeft=GWEN_Buffer_GetMaxUnsegmentedWrite(buf); \
1823 *(pdst++)=(unsigned char)chr; \
1837 x=(
unsigned char)*src;
1840 unsigned char num=0;
1844 while(*src && isdigit((
int)*src)) {
1852 else if (strncmp(src+1,
"szlig;", 6)==0) {
1858 else if (strncmp(src+1,
"Auml;", 5)==0) {
1864 else if (strncmp(src+1,
"Ouml;", 5)==0) {
1870 else if (strncmp(src+1,
"Uuml;", 5)==0) {
1876 else if (strncmp(src+1,
"auml;", 5)==0) {
1882 else if (strncmp(src+1,
"ouml;", 5)==0) {
1888 else if (strncmp(src+1,
"uuml;", 5)==0) {
1901 if (strncasecmp(src, e->
replace, l)==0) {
1923 #undef GWEN_TEXT__APPENDCHAR
1935 x=(
unsigned char)*src;
1950 snprintf(numbuf,
sizeof(numbuf),
"&#%d;", x);
1965 const char *toCharset,
1966 const char *text,
int len,
1969 if (fromCharset && *fromCharset && toCharset && *toCharset &&
1970 strcasecmp(fromCharset, toCharset)!=0) {
1973 "iconv not available, can not convert from \"%s\" to \"%s\"",
1974 fromCharset, toCharset);
1978 ic=iconv_open(toCharset, fromCharset);
1979 if (ic==((iconv_t)-1)) {
1981 fromCharset, toCharset);
2001 outbuf=(
char*)malloc(outLeft);
2007 done=iconv(ic, &pInbuf, &inLeft, &pOutbuf, &outLeft);
2008 if (done==(
size_t)-1) {
2010 strerror(errno), errno);