3 MPDM - Minimum Profit Data Manager
4 Copyright (C) 2003/2010 Angel Ortega <angel@triptico.com>
6 mpdm_s.c - String management
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 http://www.triptico.com
35 #ifdef CONFOPT_GETTEXT
48 void *mpdm_poke_o(void *dst
, int *dsize
, int *offset
, const void *org
,
51 if (org
!= NULL
&& osize
) {
53 if (*offset
+ osize
> *dsize
) {
57 dst
= realloc(dst
, *dsize
* esize
);
60 memcpy((char *) dst
+ (*offset
* esize
), org
, osize
* esize
);
68 void *mpdm_poke(void *dst
, int *dsize
, const void *org
, int osize
,
70 /* pokes (adds) org into dst, which is a dynamic string, making it grow */
74 return mpdm_poke_o(dst
, dsize
, &offset
, org
, osize
, esize
);
78 wchar_t *mpdm_pokewsn(wchar_t * dst
, int *dsize
, const wchar_t * str
,
80 /* adds a wide string to dst using mpdm_poke() with size */
83 dst
= mpdm_poke(dst
, dsize
, str
, slen
, sizeof(wchar_t));
89 wchar_t *mpdm_pokews(wchar_t * dst
, int *dsize
, const wchar_t * str
)
90 /* adds a wide string to dst using mpdm_poke() */
93 dst
= mpdm_pokewsn(dst
, dsize
, str
, wcslen(str
));
99 wchar_t *mpdm_pokev(wchar_t * dst
, int *dsize
, const mpdm_t v
)
100 /* adds the string in v to dst using mpdm_poke() */
103 const wchar_t *ptr
= mpdm_string(v
);
106 dst
= mpdm_pokews(dst
, dsize
, ptr
);
114 wchar_t *mpdm_mbstowcs(const char *str
, int *s
, int l
)
115 /* converts an mbs to a wcs, but filling invalid chars
116 with question marks instead of just failing */
119 char tmp
[64]; /* really MB_CUR_MAX + 1 */
124 /* allow NULL values for s */
128 /* if there is a limit, duplicate and break the string */
136 /* try first a direct conversion with mbstowcs */
137 if ((*s
= mbstowcs(NULL
, cstr
, 0)) != -1) {
138 /* direct conversion is possible; do it */
139 if ((ptr
= malloc((*s
+ 1) * sizeof(wchar_t))) != NULL
) {
140 mbstowcs(ptr
, cstr
, *s
);
145 /* zero everything */
149 /* no more characters to process? */
150 if ((c
= cstr
[n
+ i
]) == '\0' && i
== 0)
157 if (mbstowcs(&wc
, tmp
, 1) == (size_t) - 1) {
158 /* can still be an incomplete multibyte char? */
159 if (c
!= '\0' && i
<= (int) MB_CUR_MAX
)
162 /* too many failing bytes; skip 1 byte */
168 /* skip used bytes and back again */
173 if ((ptr
= mpdm_poke(ptr
, s
, &wc
, 1, sizeof(wchar_t))) == NULL
)
177 /* null terminate and count one less */
179 ptr
= mpdm_poke(ptr
, s
, L
"", 1, sizeof(wchar_t));
184 /* free the duplicate */
192 char *mpdm_wcstombs(const wchar_t * str
, int *s
)
193 /* converts a wcs to an mbs, but filling invalid chars
194 with question marks instead of just failing */
197 char tmp
[64]; /* really MB_CUR_MAX + 1 */
200 /* allow NULL values for s */
204 /* try first a direct conversion with wcstombs */
205 if ((*s
= wcstombs(NULL
, str
, 0)) != -1) {
206 /* direct conversion is possible; do it and return */
207 if ((ptr
= malloc(*s
+ 1)) != NULL
) {
208 wcstombs(ptr
, str
, *s
);
215 /* invalid encoding? convert characters one by one */
219 if ((l
= wctomb(tmp
, *str
)) <= 0) {
220 /* if char couldn't be converted,
221 write a question mark instead */
222 l
= wctomb(tmp
, L
'?');
226 if ((ptr
= mpdm_poke(ptr
, s
, tmp
, l
, 1)) == NULL
)
232 /* null terminate and count one less */
234 ptr
= mpdm_poke(ptr
, s
, "", 1, 1);
242 mpdm_t
mpdm_new_wcs(int flags
, const wchar_t * str
, int size
, int cpy
)
243 /* creates a new string value from a wcs */
247 /* a size of -1 means 'calculate it' */
248 if (size
== -1 && str
!= NULL
)
253 /* free() on destruction */
257 if ((ptr
= malloc((size
+ 1) * sizeof(wchar_t))) == NULL
)
260 /* if no source, reset to zeroes; otherwise, copy */
262 memset(ptr
, '\0', size
* sizeof(wchar_t));
264 wcsncpy(ptr
, str
, size
);
269 ptr
= (wchar_t *) str
;
272 flags
|= MPDM_STRING
;
274 return mpdm_new(flags
, ptr
, size
);
278 mpdm_t
mpdm_new_mbstowcs(int flags
, const char *str
, int l
)
279 /* creates a new string value from an mbs */
284 if ((ptr
= mpdm_mbstowcs(str
, &size
, l
)) == NULL
)
288 flags
|= (MPDM_STRING
| MPDM_FREE
);
290 return mpdm_new(flags
, ptr
, size
);
294 mpdm_t
mpdm_new_wcstombs(int flags
, const wchar_t * str
)
295 /* creates a new mbs value from a wbs */
300 ptr
= mpdm_wcstombs(str
, &size
);
304 /* unset the string flag; mbs,s are not 'strings' */
305 flags
&= ~MPDM_STRING
;
307 return mpdm_new(flags
, ptr
, size
);
311 mpdm_t
mpdm_new_i(int ival
)
312 /* creates a new string value from an integer */
317 /* creates the visual representation */
318 snprintf(tmp
, sizeof(tmp
), "%d", ival
);
322 return mpdm_set_ival(v
, ival
);
326 mpdm_t
mpdm_new_r(double rval
)
327 /* creates a new string value from a real number */
332 /* creates the visual representation */
333 snprintf(tmp
, sizeof(tmp
), "%lf", rval
);
335 /* manually strip useless zeroes */
336 if (strchr(tmp
, '.') != NULL
) {
339 for (ptr
= tmp
+ strlen(tmp
) - 1; *ptr
== '0'; ptr
--);
341 /* if it's over the ., strip it also */
350 return mpdm_set_rval(v
, rval
);
357 * mpdm_string2 - Returns a printable representation of a value (with buffer).
359 * @wtmp: the external buffer
361 * Returns a printable representation of a value. For strings, it's
362 * the value data itself; for any other type, a conversion to string
363 * is returned instead. If @v is not a string, the @wtmp buffer
364 * can be used as a placeholder for the string representation.
366 * The reference count value in @v is not touched.
369 wchar_t *mpdm_string2(const mpdm_t v
, wchar_t *wtmp
)
374 /* if it's NULL, return a constant */
378 /* if it's a string, return it */
379 if (v
->flags
& MPDM_STRING
)
380 ret
= (wchar_t *) v
->data
;
382 /* otherwise, return a visual representation */
383 snprintf(tmp
, sizeof(tmp
), "%p", v
);
384 mbstowcs(wtmp
, tmp
, sizeof(tmp
) * sizeof(wchar_t));
394 * mpdm_string - Returns a printable representation of a value.
397 * Returns a printable representation of a value. For strings, it's
398 * the value data itself; for any other type, a conversion to string
399 * is returned instead. This value should be used immediately, as it
400 * can be a pointer to a static buffer.
402 * The reference count value in @v is not touched.
405 wchar_t *mpdm_string(const mpdm_t v
)
407 static wchar_t tmp
[32];
409 return mpdm_string2(v
, tmp
);
414 * mpdm_cmp - Compares two values.
415 * @v1: the first value
416 * @v2: the second value
418 * Compares two values. If both has the MPDM_STRING flag set,
419 * a comparison using wcscoll() is returned; if both are arrays,
420 * the size is compared first and, if they have the same number
421 * elements, each one is compared; otherwise, a simple visual
422 * representation comparison is done.
425 int mpdm_cmp(const mpdm_t v1
, const mpdm_t v2
)
436 /* is any value NULL? */
443 /* different values, but same content? (unlikely) */
444 if (v1
->data
== v2
->data
)
447 if (MPDM_IS_STRING(v1
) && MPDM_IS_STRING(v2
))
448 r
= wcscoll((wchar_t *) v1
->data
, (wchar_t *) v2
->data
);
450 if (MPDM_IS_ARRAY(v1
) && MPDM_IS_ARRAY(v2
)) {
451 /* compare first the sizes */
452 if ((r
= mpdm_size(v1
) - mpdm_size(v2
)) == 0) {
455 /* they have the same size;
456 compare each pair of elements */
457 for (n
= 0; n
< mpdm_size(v1
); n
++) {
458 if ((r
= mpdm_cmp(mpdm_aget(v1
, n
),
459 mpdm_aget(v2
, n
))) != 0)
467 r
= wcscoll(mpdm_string(v1
), mpdm_string2(v2
, tmp
));
478 * mpdm_cmp_s - Compares two values (string version).
479 * @v1: the first value
480 * @v2: the second value
482 * Compares two values. If both has the MPDM_STRING flag set,
483 * a comparison using wcscoll() is returned; if both are arrays,
484 * the size is compared first and, if they have the same number
485 * elements, each one is compared; otherwise, a simple visual
486 * representation comparison is done.
488 int mpdm_cmp_s(const mpdm_t v1
, const wchar_t * v2
)
490 return mpdm_cmp(v1
, MPDM_S(v2
));
495 * mpdm_splice - Creates a new string value from another.
496 * @v: the original value
497 * @i: the value to be inserted
498 * @offset: offset where the substring is to be inserted
499 * @del: number of characters to delete
501 * Creates a new string value from @v, deleting @del chars at @offset
502 * and substituting them by @i. If @del is 0, no deletion is done.
503 * both @offset and @del can be negative; if this is the case, it's
504 * assumed as counting from the end of @v. If @v is NULL, @i will become
505 * the new string, and both @offset and @del will be ignored. If @v is
506 * not NULL and @i is, no insertion process is done (only deletion, if
509 * Returns a two element array, with the new string in the first
510 * element and the deleted string in the second (with a NULL value
514 mpdm_t
mpdm_splice(const mpdm_t v
, const mpdm_t i
, int offset
, int del
)
529 /* negative offsets start from the end */
531 offset
= os
+ 1 - offset
;
533 /* never add further the end */
537 /* negative del counts as 'characters left' */
539 del
= os
+ 1 - offset
+ del
;
541 /* something to delete? */
543 /* never delete further the end */
544 if (offset
+ del
> os
)
548 d
= MPDM_NS(((wchar_t *) v
->data
) + offset
, del
);
553 /* something to insert? */
556 /* new size and remainder */
560 n
= MPDM_NS(NULL
, ns
);
562 ptr
= (wchar_t *) n
->data
;
564 /* copy the beginning */
566 wcsncpy(ptr
, v
->data
, offset
);
570 /* copy the text to be inserted */
572 wcsncpy(ptr
, i
->data
, ins
);
576 /* copy the remaining */
579 wcsncpy(ptr
, ((wchar_t *) v
->data
) + r
, os
);
589 /* creates the output array */
605 * mpdm_strcat_sn - Concatenates two strings (string with size version).
606 * @s1: the first string
607 * @s2: the second string
608 * @size: the size of the second string
610 * Returns a new string formed by the concatenation of @s1 and @s2.
613 mpdm_t
mpdm_strcat_sn(const mpdm_t s1
, const wchar_t * s2
, int size
)
619 if (s1
== NULL
&& s2
== NULL
)
622 ptr
= mpdm_pokev(ptr
, &s
, s1
);
623 ptr
= mpdm_pokewsn(ptr
, &s
, s2
, size
);
625 ptr
= mpdm_poke(ptr
, &s
, L
"", 1, sizeof(wchar_t));
626 r
= MPDM_ENS(ptr
, s
- 1);
634 * mpdm_strcat_s - Concatenates two strings (string version).
635 * @s1: the first string
636 * @s2: the second string
638 * Returns a new string formed by the concatenation of @s1 and @s2.
641 mpdm_t
mpdm_strcat_s(const mpdm_t s1
, const wchar_t * s2
)
643 return mpdm_strcat_sn(s1
, s2
, s2
? wcslen(s2
) : 0);
648 * mpdm_strcat - Concatenates two strings.
649 * @s1: the first string
650 * @s2: the second string
652 * Returns a new string formed by the concatenation of @s1 and @s2.
655 mpdm_t
mpdm_strcat(const mpdm_t s1
, const mpdm_t s2
)
660 r
= mpdm_strcat_s(s1
, s2
? mpdm_string(s2
) : NULL
);
668 * mpdm_ival - Returns a value's data as an integer.
671 * Returns a value's data as an integer. If the value is a string,
672 * it's converted via sscanf and returned; non-string values have all
673 * an ival of 0. The converted integer is cached, so costly string
674 * conversions are only done once. Values created with the MPDM_IVAL
675 * flag set have its ival cached from the beginning.
679 int mpdm_ival(mpdm_t v
)
686 /* if there is no cached integer, calculate it */
687 if (!(v
->flags
& MPDM_IVAL
)) {
688 /* if it's a string, calculate it; other
689 values will have an ival of 0 */
690 if (v
->flags
& MPDM_STRING
) {
694 wcstombs(tmp
, (wchar_t *) v
->data
, sizeof(tmp
));
695 tmp
[sizeof(tmp
) - 1] = '\0';
697 /* workaround for mingw32: as it doesn't
698 correctly parse octal and hexadecimal
699 numbers, they are tried as special cases */
701 if (tmp
[1] == 'b' || tmp
[1] == 'B') {
706 while (*ptr
== '0' || *ptr
== '1') {
716 if (tmp
[1] == 'x' || tmp
[1] == 'X')
723 sscanf(tmp
, fmt
, &i
);
739 * mpdm_rval - Returns a value's data as a real number (double).
742 * Returns a value's data as a real number (double float). If the value
743 * is a string, it's converted via sscanf and returned; non-string values
744 * have all an rval of 0. The converted double is cached, so costly string
745 * conversions are only done once. Values created with the MPDM_RVAL
746 * flag set have its rval cached from the beginning.
750 double mpdm_rval(mpdm_t v
)
757 /* if there is no cached double, calculate it */
758 if (!(v
->flags
& MPDM_RVAL
)) {
759 /* if it's a string, calculate it; other
760 values will have an rval of 0.0 */
761 if (v
->flags
& MPDM_STRING
) {
765 wcstombs(tmp
, (wchar_t *) v
->data
, sizeof(tmp
));
766 tmp
[sizeof(tmp
) - 1] = '\0';
768 /* if the number starts with 0, it's
769 an octal or hexadecimal number; just
770 take the integer value and cast it */
771 if (tmp
[0] == '0' && tmp
[1] != '.')
772 r
= (double) mpdm_ival(v
);
774 /* set locale to C for non locale-dependent
775 floating point conversion */
776 prev_locale
= setlocale(LC_NUMERIC
, "C");
779 sscanf(tmp
, "%lf", &r
);
781 /* set previous locale */
782 setlocale(LC_NUMERIC
, prev_locale
);
799 * mpdm_gettext - Translates a string to the current language.
802 * Translates the @str string to the current language.
804 * This function can still be used even if there is no real gettext
805 * support() by manually filling the __I18N__ hash.
807 * If the string is found in the current table, the translation is
808 * returned; otherwise, the same @str value is returned.
812 mpdm_t
mpdm_gettext(const mpdm_t str
)
818 if ((i18n
= mpdm_hget_s(mpdm_root(), L
"__I18N__")) == NULL
)
819 i18n
= mpdm_hset_s(mpdm_root(), L
"__I18N__", MPDM_H(0));
823 /* try first the cache */
824 if ((v
= mpdm_hget(i18n
, str
)) == NULL
) {
825 #ifdef CONFOPT_GETTEXT
830 t
= mpdm_ref(MPDM_2MBS(str
->data
));
832 /* ask gettext for it */
833 s
= gettext((char *) t
->data
);
842 #else /* CONFOPT_GETTEXT */
846 #endif /* CONFOPT_GETTEXT */
848 /* store in the cache */
849 mpdm_hset(i18n
, str
, v
);
859 * mpdm_gettext_domain - Sets domain and data directory for translations.
860 * @dom: the domain (application name)
861 * @data: directory contaning the .mo files
863 * Sets the domain (application name) and translation data for translating
864 * strings that will be returned by mpdm_gettext().@data must point to a
865 * directory containing the .mo (compiled .po) files.
867 * If there is no gettext support, returns 0, or 1 otherwise.
871 int mpdm_gettext_domain(const mpdm_t dom
, const mpdm_t data
)
878 #ifdef CONFOPT_GETTEXT
883 /* convert both to mbs,s */
884 dm
= mpdm_ref(MPDM_2MBS(dom
->data
));
885 dt
= mpdm_ref(MPDM_2MBS(data
->data
));
887 /* bind and set domain */
888 bindtextdomain((char *) dm
->data
, (char *) dt
->data
);
889 textdomain((char *) dm
->data
);
891 mpdm_hset_s(mpdm_root(), L
"__I18N__", MPDM_H(0));
898 #endif /* CONFOPT_GETTEXT */
904 if ((v
= mpdm_hget_s(mpdm_root(), L
"ENV")) != NULL
&&
905 mpdm_hget_s(v
, L
"LANG") == NULL
) {
906 wchar_t *wptr
= L
"en";
908 /* MS Windows crappy language constants... */
910 switch ((GetSystemDefaultLangID() & 0x00ff)) {
916 break; /* bulgarian */
952 break; /* hungarian */
955 break; /* icelandic */
961 break; /* japanese */
970 break; /* norwegian */
976 break; /* portuguese */
979 break; /* romansh (switzerland) */
982 break; /* romanian */
994 break; /* albanian */
1000 mpdm_hset_s(v
, L
"LANG", MPDM_S(wptr
));
1003 #endif /* CONFOPT_WIN32 */
1012 #ifdef CONFOPT_WCWIDTH
1014 int wcwidth(wchar_t);
1016 int mpdm_wcwidth(wchar_t c
)
1021 #else /* CONFOPT_WCWIDTH */
1023 #include "wcwidth.c"
1025 int mpdm_wcwidth(wchar_t c
)
1027 return mk_wcwidth(c
);
1030 #endif /* CONFOPT_WCWIDTH */
1034 * mpdm_sprintf - Formats a sprintf()-like string.
1035 * @fmt: the string format
1036 * @args: an array of values
1038 * Formats a string using the sprintf() format taking the values from @args.
1041 mpdm_t
mpdm_sprintf(const mpdm_t fmt
, const mpdm_t args
)
1043 const wchar_t *i
= fmt
->data
;
1051 /* loop all characters */
1052 while ((c
= *i
++) != L
'\0') {
1054 wchar_t *tptr
= NULL
;
1055 wchar_t *wptr
= NULL
;
1058 /* format directive */
1064 /* transfer the % */
1067 /* transform the format to mbs */
1068 while (*i
!= L
'\0' &&
1069 m
< (int) (sizeof(t_fmt
) - MB_CUR_MAX
- 1) &&
1070 wcschr(L
"-.0123456789", *i
) != NULL
)
1071 m
+= wctomb(&t_fmt
[m
], *i
++);
1073 /* transfer the directive */
1074 m
+= wctomb(&t_fmt
[m
], *i
++);
1078 /* by default, copies the format */
1081 /* pick next value */
1082 v
= mpdm_aget(args
, n
++);
1084 switch (t_fmt
[m
- 1]) {
1093 snprintf(tmp
, sizeof(tmp
) - 1, t_fmt
, mpdm_ival(v
));
1098 /* float (real) value */
1099 snprintf(tmp
, sizeof(tmp
) - 1, t_fmt
, mpdm_rval(v
));
1105 ptr
= mpdm_wcstombs(mpdm_string(v
), NULL
);
1106 snprintf(tmp
, sizeof(tmp
) - 1, t_fmt
, ptr
);
1125 mask
= 1 << ((sizeof(int) * 8) - 1);
1127 if (mask
& (unsigned int) mpdm_ival(v
)) {
1154 wptr
= tptr
= mpdm_mbstowcs(tmp
, &m
, -1);
1163 o
= mpdm_poke(o
, &l
, wptr
, m
, sizeof(wchar_t));
1165 /* free the temporary buffer, if any */
1173 /* null-terminate */
1174 o
= mpdm_poke(o
, &l
, L
"", 1, sizeof(wchar_t));
1179 return MPDM_ENS(o
, l
- 1);
1184 * mpdm_ulc - Converts a string to uppercase or lowecase.
1186 * @u: convert to uppercase (1) or to lowercase (0).
1188 * Converts @s to uppercase (for @u == 1) or to lowercase (@u == 0).
1191 mpdm_t
mpdm_ulc(const mpdm_t s
, int u
)
1201 if ((optr
= malloc((i
+ 1) * sizeof(wchar_t))) != NULL
) {
1202 wchar_t *iptr
= mpdm_string(s
);
1205 for (n
= 0; n
< i
; n
++)
1206 optr
[n
] = u
? towupper(iptr
[n
]) : towlower(iptr
[n
]);
1209 r
= MPDM_ENS(optr
, i
);
1218 /* scanf working buffers */
1219 #define SCANF_BUF_SIZE 1024
1220 static wchar_t scanf_yset
[SCANF_BUF_SIZE
];
1221 static wchar_t scanf_nset
[SCANF_BUF_SIZE
];
1222 static wchar_t scanf_mark
[SCANF_BUF_SIZE
];
1229 { L
's', L
"", L
" \t"},
1230 { L
'u', L
"0123456789", L
""},
1231 { L
'd', L
"-0123456789", L
""},
1232 { L
'i', L
"-0123456789", L
""},
1233 { L
'f', L
"-0123456789.", L
""},
1234 { L
'x', L
"-0123456789xabcdefABCDEF", L
""},
1235 { L
'\0', NULL
, NULL
},
1239 * mpdm_sscanf - Extracts data like sscanf().
1240 * @fmt: the string format
1241 * @str: the string to be parsed
1242 * @offset: the character offset to start scanning
1244 * Extracts data from a string using a special format pattern, very
1245 * much like the scanf() series of functions in the C library. Apart
1246 * from the standard percent-sign-commands (s, u, d, i, f, x,
1247 * n, [, with optional size and * to ignore), it implements S,
1248 * to match a string of characters upto what follows in the format
1249 * string. Also, the [ set of characters can include other % formats.
1251 * Returns an array with the extracted values. If %n is used, the
1252 * position in the scanned string is returned as the value.
1255 mpdm_t
mpdm_sscanf(const mpdm_t fmt
, const mpdm_t str
, int offset
)
1257 wchar_t *i
= (wchar_t *) str
->data
;
1258 wchar_t *f
= (wchar_t *) fmt
->data
;
1270 wchar_t *ptr
= NULL
;
1277 /* empty all buffers */
1278 scanf_yset
[0] = scanf_nset
[0] = scanf_mark
[0] = L
'\0';
1282 /* an asterisk? don't return next value */
1288 /* does it have a size? */
1289 while (wcschr(L
"0123456789", *f
)) {
1295 /* if no size, set it to an arbitrary big limit */
1299 /* now *f should contain a command */
1303 /* is it a verbatim percent sign? */
1307 wcscpy(scanf_yset
, L
"%");
1314 mpdm_push(r
, MPDM_I(i
- (wchar_t *) str
->data
));
1317 /* string upto a mark */
1321 /* fill the mark upto another command */
1326 /* is it an 'n'? ignore and go on */
1333 scanf_mark
[msize
++] = *tmp
;
1338 scanf_mark
[msize
++] = *tmp
;
1343 scanf_mark
[msize
] = L
'\0';
1349 wchar_t *set
= scanf_yset
;
1351 /* is it an inverse set? */
1357 /* first one is a ]? add it */
1363 /* now build the set */
1364 for (; n
< SCANF_BUF_SIZE
- 1 && *f
&& *f
!= L
']'; f
++) {
1365 /* is it a range? */
1369 /* start or end? hyphen itself */
1370 if (n
== 0 || *f
== L
']')
1373 /* pick previous char */
1374 wchar_t c
= set
[n
- 1];
1377 while (n
< SCANF_BUF_SIZE
- 1 && c
< *f
)
1382 /* is it another command? */
1387 for (i
= 0; scanf_sets
[i
].cmd
; i
++) {
1388 if (*f
== scanf_sets
[i
].cmd
) {
1390 wcscat(set
, scanf_sets
[i
].yset
);
1391 n
+= wcslen(scanf_sets
[i
].yset
);
1406 /* a standard set? */
1410 for (n
= 0; scanf_sets
[n
].cmd
!= L
'\0'; n
++) {
1411 if (cmd
== scanf_sets
[n
].cmd
) {
1412 wcscpy(scanf_yset
, scanf_sets
[n
].yset
);
1413 wcscpy(scanf_nset
, scanf_sets
[n
].nset
);
1419 /* now fill the dynamic string */
1421 !wcschr(scanf_nset
, *i
) &&
1422 (scanf_yset
[0] == L
'\0' || wcschr(scanf_yset
, *i
)) &&
1423 (msize
== 0 || wcsncmp(i
, scanf_mark
, msize
) != 0)) {
1425 /* only add if not being ignored */
1427 ptr
= mpdm_poke(ptr
, &size
, i
, 1, sizeof(wchar_t));
1433 if (!ignore
&& size
) {
1434 /* null terminate and push */
1435 ptr
= mpdm_poke(ptr
, &size
, L
"", 1, sizeof(wchar_t));
1436 mpdm_push(r
, MPDM_ENS(ptr
, size
- 1));
1440 if (*f
== L
' ' || *f
== L
'\t') {
1441 /* if it's a blank, sync to next non-blank */
1444 while (*i
== L
' ' || *i
== L
'\t')
1448 /* test for literals in the format string */