Changeset 2062
- Timestamp:
- Jun 23, 2005, 8:01:58 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/src/lib/io/_output.c
-
Property cvs2svn:cvs-rev
changed from
1.7
to1.8
r2061 r2062 13 13 #include <emx/float.h> 14 14 #include <InnoTekLIBC/locale.h> 15 #include <wchar.h> 15 16 #include "getputc.h" 16 17 … … 175 176 OUT_PAD (v, ' ', v->width - str_len); 176 177 OUT_STR (v, str, str_len); 178 if (str_len < v->width && v->minus) 179 OUT_PAD (v, ' ', v->width - str_len); 180 return 0; 181 } 182 183 184 /* Perform formatting for the "%C" and "%S" formats. The meaning of 185 the '0' flag is not defined by ANSI for "%C" and "%S"; we always 186 use blanks for padding. */ 187 188 static int cvt_wstr (olocal *v, const wchar_t *str, int str_len) 189 { 190 if (str == NULL) 191 { 192 /* Print "(null)" for the NULL pointer if the precision is big 193 enough or not specified. */ 194 195 if (v->prec < 0 || v->prec >= 6) 196 str = L"(null)"; 197 else 198 str = L""; 199 } 200 201 /* The precision, if specified, limits the number of characters to 202 be printed. If the precision is specified, the array pointed to 203 by STR does not need to be null-terminated. */ 204 205 if (str_len == -1) 206 { 207 if (v->prec >= 0) 208 { 209 const wchar_t *end = (const wchar_t *)wmemchr (str, 0, v->prec); 210 if (end != NULL) 211 str_len = end - str; 212 else 213 str_len = v->prec; 214 } 215 else 216 str_len = wcslen (str); 217 } 218 else if (v->prec >= 0 && v->prec < str_len) 219 str_len = v->prec; 220 221 /* Print the string, using blanks for padding. */ 222 223 if (str_len < v->width && !v->minus) 224 OUT_PAD (v, ' ', v->width - str_len); 225 mbstate_t state = {{0}}; 226 for (int i = 0; i < str_len; i++) 227 { 228 char mb[MB_LEN_MAX + 1]; 229 size_t cb = wcrtomb(mb, *str, &state); 230 switch (cb) 231 { 232 /* 233 * Quit the loop. 234 */ 235 case -2: /* incomplete character - we ASSUME this cannot happen. */ 236 case -1: /* encoding error */ 237 case 0: /* end of string */ 238 i = str_len; 239 break; 240 241 default: 242 str++; 243 OUT_STR(v, mb, cb); 244 break; 245 } 246 } 177 247 if (str_len < v->width && v->minus) 178 248 OUT_PAD (v, ' ', v->width - str_len); … … 872 942 873 943 case 'c': 944 if (size != 'l' && size != 'L') 945 { 946 char c; 947 948 c = (char)va_arg (arg_ptr, int); 949 v.prec = 1; 950 CHECK (cvt_str (&v, &c, 1)); 951 break; 952 } 953 /* fall thru */ 954 case 'C': 874 955 { 875 charc;876 877 c = (char)va_arg (arg_ptr, int);956 wchar_t wc; 957 958 wc = (wchar_t)va_arg (arg_ptr, int); 878 959 v.prec = 1; 879 CHECK (cvt_ str (&v, &c, 1));960 CHECK (cvt_wstr (&v, &wc, 1)); 880 961 } 881 962 break; 882 963 883 964 case 's': 884 CHECK (cvt_str (&v, va_arg (arg_ptr, const char *), -1)); 965 if (size != 'l' && size != 'L') 966 { 967 CHECK (cvt_str (&v, va_arg (arg_ptr, const char *), -1)); 968 break; 969 } 970 /* fall thru */ 971 case 'S': 972 CHECK (cvt_wstr (&v, va_arg (arg_ptr, const wchar_t *), -1)); 885 973 break; 886 974 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.