int printescaped(const char *src) { int n = 0; mbstate_t src_state, stdout_state; /* The following +1 is to pass '\0' at the end of src to mbrtowc(). */ const char *endptr = src + strlen(src) + 1; /* * We have to reset src_state each time in this function, because * the codeset of src pathname may not match with current locale. * Note that if we pass NULL instead of src_state to mbrtowc(), * there is no way to reset the state. */ memset(&src_state, 0, sizeof(src_state)); memset(&stdout_state, 0, sizeof(stdout_state)); while (src < endptr) { wchar_t wc; size_t rv, span = endptr - src; #if 0 /* * XXX - we should fix libc instead. * Theoretically this should work, but our current * implementation of iso2022 module doesn't actually work * as expected, if there are redundant escape sequences * which exceed 32 bytes. */ if (span > MB_CUR_MAX) span = MB_CUR_MAX; #endif rv = mbrtowc(&wc, src, span, &src_state); if (rv == 0) { /* assert(wc == L'\0'); */ /* The following may output a shift sequence. */ n += printwc(wc, &stdout_state); break; } if (rv == (size_t)-1) { /* probably errno == EILSEQ */ n += printwc(L'?', &stdout_state); /* try to skip 1byte, because there is no better way */ src++; memset(&src_state, 0, sizeof(src_state)); } else if (rv == (size_t)-2) { if (span < MB_CUR_MAX) { /* incomplete char */ n += printwc(L'?', &stdout_state); break; } src += span; /* a redundant shift sequence? */ } else { n += printwc(iswprint(wc) ? wc : L'?', &stdout_state); src += rv; } } return n; }
int main (int argc, char** argv) { const char* flags[4] = { NULL }; const char* flagstr = "lwmc"; (void) input_flags(argc, argv, flagstr, flags); if (flags[FLAG_CHARACTER] != NULL) { flags[FLAG_BYTE] = NULL; } if ((flags[FLAG_LINE] == NULL) && (flags[FLAG_WORD] == NULL) && (flags[FLAG_CHARACTER] == NULL) && (flags[FLAG_BYTE] == NULL)) { flags[FLAG_LINE] = wc_flag_set; flags[FLAG_WORD] = wc_flag_set; flags[FLAG_BYTE] = wc_flag_set; } input_files(argc, argv, wc, flags); if ((optind + 1) < argc) { printwc("total", flags, &pvals_total); } return EXIT_SUCCESS; }
static void wc (char* filename, FILE* strm, void* data) { const char** flags = (const char**) data; printvals pvals; calcwc(strm, &pvals); printwc(filename, flags, &pvals); }
void LiquidCrystal_1602_RUS::print(const char *c_str) { wchar_t _str; int current_char = 0; int size = strlen(c_str); while (current_char < size) { current_char += mbtowc(&_str, (char *)c_str + current_char, 2); printwc(_str); cursor_col++; } }
void LiquidCrystal_1602_RUS::print(const wchar_t *_str) { int current_char = 0; int size = 0; //Определяем длину строки (количество символов) while (_str[size] != 0) { size++; } while (current_char < size) { printwc(_str[current_char]); current_char++; cursor_col++; } }