int main() { char file_in[ ] = "local_in.txt", file_out[ ] = "local_out.txt"; FILE *fp_in_wide, *fp_out_wide; wint_t wc; if ( setlocale( LC_CTYPE, "" ) == NULL) fwprintf( stderr, L"Sorry, couldn't change to the system's native locale.\n"), exit(1); if (( fp_in_wide = fopen( file_in, "r" )) == NULL ) fprintf( stderr, "Error opening the file %s\n", file_in), exit(2); if (( fp_out_wide = fopen( file_out, "w" )) == NULL ) fprintf( stderr, "Error opening the file %s\n", file_out), exit(3); fwide( fp_in_wide, 1); // Not strictly necessary, since first fwide( fp_out_wide, 1); // file access also sets wide or byte mode. while (( wc = fgetwc( fp_in_wide )) != WEOF ) { // ... process each wide character read ... if ( fputwc( (wchar_t)wc, fp_out_wide) == WEOF) break; } if ( ferror( fp_in_wide)) fprintf( stderr, "Error reading the file %s\n", file_in); if ( ferror( fp_out_wide)) fprintf( stderr, "Error writing to the file %s\n", file_out); return 0; }
int main() { int c,i; wchar_t s[100]; FILE *fil = fopen("hi.txt","w+"); printf("%d\n",fwide(fil,0)); fputwc(L'c',fil); fputws(L"hi dave\n",fil); fwprintf(fil,L"%ls\n",L"geez"); printf("%d\n",fwide(fil,0)); printf("%d\n",fputc('z',fil)); printf("%d\n",fwide(fil,-1)); printf("%d\n",fputc('y',fil)); printf("%d\n",fputc('y',fil)); rewind(fil); printf("%d\n",fwide(fil,1)); printf("%04x\n",fgetwc(fil)); printf("%04x\n",fgetwc(fil)); printf(":%x: ",fgetws(s,100,fil)); for (i=0; i <wcslen(s); i++) printf("%04x ",s[i]); printf("\n"); fwscanf(fil,L"%ls ",s); for (i=0; i <wcslen(s); i++) printf("%04x ",s[i]); printf("\n"); printf("%d\n",fwide(fil,-1)); printf("%02x\n",fgetc(fil)); fclose(fil); }
static int do_test (void) { /* The test-in-container framework sets these environment variables. The presence of GCONV_PATH invalidates this test. */ unsetenv ("GCONV_PATH"); unsetenv ("LOCPATH"); /* Create the gconv module cache. iconvconfig is in /sbin, which is not on PATH. */ { char *iconvconfig = xasprintf ("%s/iconvconfig", support_sbindir_prefix); TEST_COMPARE (system (iconvconfig), 0); } /* Use built-in ASCII gconv module, without triggering cache initialization. */ FILE *fp1 = xfopen ("/dev/zero", "r"); TEST_COMPARE (fwide (fp1, 1), 1); /* Use non-ASCII gconv module and trigger gconv cache initialization. */ FILE *fp2 = xfopen ("/dev/zero", "r,ccs=UTF-8"); TEST_COMPARE (fwide (fp2, 0), 1); xfclose (fp1); xfclose (fp2); return 0; }
int main() { FILE *fp_in_wide; wchar_t buffer[4096]; wchar_t *line = buffer; if ( setlocale( LC_CTYPE, "" ) == NULL) { fwprintf( stderr, L"Sorry, couldn't change to the system's native locale.\n"); return -1; } if (( fp_in_wide = fopen( "local_in.txt", "r" )) == NULL ) { perror( "Opening input file"); return -1; } fwide( fp_in_wide, 1); line = fgetws( buffer, sizeof(buffer), fp_in_wide ); if ( line == NULL ) perror( "Reading from input file" ); else if( fputws( line, stdout) < 0) perror( "Writing to stdout" ); return 0; }
int main(void) { int i; setlocale(LC_ALL, ""); const char *narrow = "Test Unicode (narrow): ïà ý ÐÐ¾Ñ ã‘ãŸã„ã¨é¡˜ã†!\n"; fprintf(stdout, "%s\n", narrow); fprintf(stdout, "Narrow bytes:\n"); for (i = 0; i< strlen(narrow); ++i) fprintf(stdout, "%3d: %02X\n", i, (unsigned int) *((unsigned char *)narrow+i)); if (fwide (stderr, 1) <= 0) fprintf(stdout, "Failed to set stderr to wide orientation\n"); const wchar_t *wide = L"Test Unicode (wide): ïà ý ÐÐ¾Ñ ã‘ãŸã„ã¨é¡˜ã†!\n"; fwprintf(stderr, L"\n%ls\n", wide); fwprintf(stderr, L"\nNarrow-to-wide: %s\n", narrow); fprintf(stdout, "\nWide-to-narrow: %ls\n", wide); fprintf(stdout, "Wide bytes:\n"); for (i = 0; i< (wcslen(wide) * sizeof(wchar_t)); ++i) fprintf(stdout, "%3d: %02X\n", i, (unsigned int) *((unsigned char *)wide+i)); return 0; }
wint_t ungetwc(wint_t c, FILE* f) { unsigned char mbc[MB_LEN_MAX]; int l = 1; locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; FLOCK(f); if (f->mode <= 0) fwide(f, 1); *ploc = f->locale; if (!f->rpos) __toread(f); if (!f->rpos || f->rpos < f->buf - UNGET + l || c == WEOF || (!isascii(c) && (l = wctomb((void*)mbc, c)) < 0)) { FUNLOCK(f); *ploc = loc; return WEOF; } if (isascii(c)) *--f->rpos = c; else memcpy(f->rpos -= l, mbc, l); f->flags &= ~F_EOF; FUNLOCK(f); *ploc = loc; return c; }
static wchar_t * fwreadFile( FILE ** file, const char * fileName, char * fileMode ) { wchar_t * result ; long oldOffset; int resultLen; int i ; if ( * file == NULL || fileName == NULL || fileMode == NULL ) { return NULL; } // save old file state oldOffset = ftell( * file ); fclose( * file ); // read file contents if ( ( * file = fopen( fileName, "r" ) ) == NULL ) { return NULL; } //fwide( * file, 1 ); resultLen = 0; while ( fgetwc( * file ) != WEOF ) { resultLen++; } // ta_debug_printf( "fwreadFile : resultLen is %d\n", resultLen ); fseek( * file, 0, SEEK_SET ); if ( ( result = (wchar_t *)ta_alloc_memory( ( resultLen + 1 ) * sizeof( wchar_t ) ) ) != NULL ) { // + 1 - for final 0 // fread( result, resultLen, sizeof( wchar_t ), * file ); int i; for ( i = 0; i < resultLen; i++ ) { result[ i ] = fgetwc( * file ); } result[ resultLen ] = 0; } fclose( * file ); // ta_debug_printf( "fwreadFile : result is [%s|%ls]\n", result, result ); // restore old file state // fileMode = [analog replace_CString for char *]( fileMode, 'w', 'a' ); for ( i = 0; i < strlen( fileMode ); i++ ) { if ( fileMode[ i ] == 'w' ) { fileMode[ i ] = 'a'; } } * file = fopen( fileName, fileMode ); fwide( * file, 1 ); fseek( * file, oldOffset, SEEK_SET ); return result; }
wint_t __fputwc_unlocked(wchar_t c, FILE* f) { char mbc[MB_LEN_MAX]; int l; locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; if (f->mode <= 0) fwide(f, 1); *ploc = f->locale; if (isascii(c)) { c = putc_unlocked(c, f); } else if (f->wpos + MB_LEN_MAX < f->wend) { l = wctomb((void*)f->wpos, c); if (l < 0) c = WEOF; else f->wpos += l; } else { l = wctomb(mbc, c); if (l < 0 || __fwritex((void*)mbc, l, f) < l) c = WEOF; } if (c == WEOF) f->flags |= F_ERR; *ploc = loc; return c; }
int __fxprintf (FILE *fp, const char *fmt, ...) { if (fp == NULL) fp = stderr; va_list ap; va_start (ap, fmt); int res; if (fwide (fp, 0) > 0) { size_t len = strlen (fmt) + 1; wchar_t wfmt[len]; for (size_t i = 0; i < len; ++i) { assert (isascii (fmt[i])); wfmt[i] = fmt[i]; } res = vfwprintf (fp, wfmt, ap); } else res = INTUSE(vfprintf) (fp, fmt, ap); va_end (ap); return res; }
int main(int argc, char** argv) { int result = 0; fprintf(stdout, "stdout should now be set to non-wide mode ...\n"); result = fwide(stdout, 0); if (result != -1) { printf("PROBLEM: fwide(stdout, 0) = %d (expected -1)\n", result); } fwprintf(stderr, L"stderr should now be set to wide mode ...\n"); result = fwide(stderr, 0); if (result != 1) { printf("PROBLEM: fwide(stderr, 0) = %d (expected -1)\n", result); } fprintf(stderr, "%s", "this should *not* be visible!\n"); fwprintf(stdout, L"%ls", L"this should *not* be visible!\n"); fprintf(stderr, "%ls", L"this should *not* be visible!\n"); fwprintf(stdout, L"%s", "this should *not* be visible!\n"); fprintf(stdout, "%ls", L"this *should* be visible!\n"); fwprintf(stderr, L"%s", "this *should* be visible!\n"); fprintf(stdout, "%s", "this *should* be visible!\n"); fwprintf(stderr, L"%ls", L"this *should* be visible!\n"); setlocale(LC_ALL, ""); fprintf(stderr, "%s", "this should *not* be visible!\n"); fwprintf(stdout, L"%ls", L"this should *not* be visible!\n"); fprintf(stderr, "%ls", L"this should *not* be visible!\n"); fwprintf(stdout, L"%s", "this should *not* be visible!\n"); fprintf(stdout, "%ls", L"this *should* be visible! (äöúß)\n"); fwprintf(stderr, L"%s", "this *should* be visible! (äöúß)\n"); fprintf(stdout, "%s", "this *should* be visible! (äöúß)\n"); fwprintf(stderr, L"%ls", L"this *should* be visible! (äöúß)\n"); return 0; }
PrintContext_t Print_Create(BOOL bPrintConsole, UINT32 u32InitBufferSize, UINT32 u32BufferBlockSize) { PrintContext_t hPrint; if ((hPrint = WcmMalloc(sizeof(stPrintContext_t))) == NULL) return NULL; if ((hPrint->bszTextBuffer = WcmMalloc(BCHARS2BYTES(u32InitBufferSize))) == NULL) return NULL; // Initialize the text buffer hPrint->u32TextBufferSize = u32InitBufferSize; hPrint->u32NextBufferChar = 0; b_memset(hPrint->bszTextBuffer, 0, u32InitBufferSize); hPrint->u32BufferBlockSize = u32BufferBlockSize; // Initialize the rest hPrint->hLogFile = NULL; hPrint->bszLogFileName = NULL; hPrint->bEnabled = TRUE; hPrint->bBuffered = FALSE; hPrint->bPrintConsole = bPrintConsole; if (bPrintConsole) #ifdef WIN32 hPrint->fPrintConsole = stdout; #else #ifdef ENABLE_WIDE_CHAR { if (fwide(stdout,0) > 0) hPrint->fPrintConsole = stdout; else { hPrint->fPrintConsole = fopen("/dev/tty", "w"); if (hPrint->fPrintConsole != NULL) fwide(hPrint->fPrintConsole, 1); } } #else { hPrint->fPrintConsole = stdout; } #endif #endif else
bool CpuProfileInputStream::open(const gtString& path) { if (path.isEmpty()) { return false; } // Check if file is already open if (m_fileStream.isOpened()) { if (path != m_path) { // Close and open a new file close(); } else { return true; } } // Windows Note: // The profile files are opened with UTF-8 encoding. // if (!m_fileStream.open(path.asCharArray(), WINDOWS_SWITCH(FMODE_TEXT("r, ccs=UTF-8"), FMODE_TEXT("rb")))) { return false; } // Set path name m_path = path; #if AMDT_BUILD_TARGET == AMDT_LINUX_OS if (fwide(m_fileStream.getHandler(), 1) <= 0) { close(); return false; } // Note: For Linux // Due to a bug in some version of gcc, // we add this to make sure that we are // starting from the beginning of the file. m_fileStream.seekCurrentPosition(CrtFile::ORIGIN_BEGIN, 0); #endif getCurrentPosition(&m_bof); // Get length of file m_fileStream.seekCurrentPosition(CrtFile::ORIGIN_END, 0); getCurrentPosition(&m_eof); // Back to the beginning of file setCurrentPosition(&m_bof); return true; }
FILE * setup_std(FILE *std, int line) { int r; if (freopen(filename, "r+", std) == NULL) err(2, "freopen"); if ((r = fwide(std, 0)) != 0) fail(line, r, "==", "freopen"); return (std); }
inline void FatalErrorL(const wchar_t* pStr, ...) { fwide(stderr, 1); va_list a; va_start(a, pStr); wchar_t msg[1024] = {0}; vswprintf(msg, countof(msg), pStr, a); fputws(msg, stderr); exit(1); }
FILE * setup(int line) { FILE *f; int r; if ((f = fopen(filename, "r+")) == NULL) err(2, "fopen"); if ((r = fwide(f, 0)) != 0) fail(line, r, "==", "fopen"); return (f); }
void Win32RCFormatter::startOutput( const XMLCh* const locale , const XMLCh* const outPath) { // // Ok, lets try to open the the output file. All of the messages for all // the domains are put into a single message tabble in a single RC file, // which can be linked into the program. // // CppErrMsgs_xxxx.RC // // where xxx is the locale suffix passed in. // const unsigned int bufSize = 4095; XMLCh tmpBuf[bufSize + 1]; // make sure the append will work tmpBuf[0] = 0; XMLCh *tmpXMLStr = XMLString::transcode("CppErrMsgs_"); XMLCh *tmpXMLStr2 = XMLString::transcode(".RC"); XMLString::catString(tmpBuf, outPath); XMLString::catString(tmpBuf, tmpXMLStr ); XMLString::catString(tmpBuf, locale); XMLString::catString(tmpBuf, tmpXMLStr2 ); XMLString::release(&tmpXMLStr); XMLString::release(&tmpXMLStr2); char *tmpStr = XMLString::transcode(tmpBuf); fOutFl = fopen(tmpStr, "wt"); XMLString::release(&tmpStr); if ((!fOutFl) || (fwide(fOutFl,1) < 0)) { wprintf(L"Could not open the output file: %s\n\n", xmlStrToPrintable(tmpBuf) ); releasePrintableStr throw ErrReturn_OutFileOpenFailed; } // // Ok, lets output the grunt data at the start of the file. We put out a // comment that indicates its a generated file, and the title string. // fwprintf ( fOutFl , L"// ----------------------------------------------------------------\n" L"// This file was generated from the XML error message source.\n" L"// so do not edit this file directly!!\n" L"// ----------------------------------------------------------------\n\n" ); }
static int do_test (void) { FILE *f = popen ("echo test", "r"); int result = 0, ret; char *line = NULL; size_t len = 0; if (f == NULL) { printf ("popen failed %m"); return 1; } #if __OPTION_POSIX_WIDE_CHAR_DEVICE_IO /* POSIX says that pipe streams are byte-oriented. */ if (fwide (f, 0) >= 0) { puts ("popen did not return byte-oriented stream"); result = 1; } #endif if (getline (&line, &len, f) != 5) { puts ("could not read line from popen"); result = 1; } else if (strcmp (line, "test\n") != 0) { printf ("read \"%s\"\n", line); result = 1; } if (getline (&line, &len, f) != -1) { puts ("second getline did not return -1"); result = 1; } ret = pclose (f); if (ret != 0) { printf ("pclose returned %d\n", ret); result = 1; } return result; }
void CppSrcFormatter::startOutput( const XMLCh* const locale , const XMLCh* const outPath) { // // Ok, lets try to open the the output file. All of the messages // for all the domains are put into a single Cpp file, which can be // compiled into the program. // // CppErrMsgs_xxxx.cpp // // where xxx is the locale suffix passed in. // const unsigned int bufSize = 4095; XMLCh tmpBuf[bufSize + 1]; tmpBuf[0] = 0; XMLCh *tmpXMLStr = XMLString::transcode("XercesMessages_"); XMLCh *tmpXMLStr2 = XMLString::transcode(".hpp"); XMLString::catString(tmpBuf, outPath); XMLString::catString(tmpBuf, tmpXMLStr ); XMLString::catString(tmpBuf, locale); XMLString::catString(tmpBuf, tmpXMLStr2 ); XMLString::release(&tmpXMLStr); XMLString::release(&tmpXMLStr2); char *tmpStr = XMLString::transcode(tmpBuf); fOutFl = fopen(tmpStr, "wt"); XMLString::release(&tmpStr); if ((!fOutFl) || (fwide(fOutFl, 1) < 0)) { wprintf(L"Could not open the output file: %s\n\n", tmpBuf); throw ErrReturn_OutFileOpenFailed; } // // Ok, lets output the grunt data at the start of the file. We put out a // comment that indicates its a generated file, and the title string. // fwprintf ( fOutFl , L"// ----------------------------------------------------------------\n" L"// This file was generated from the XML error message source.\n" L"// so do not edit this file directly!!\n" L"// ----------------------------------------------------------------\n\n" L"#include <xercesc/util/XercesDefs.hpp>\n\n" L"XERCES_CPP_NAMESPACE_BEGIN\n\n" ); }
wchar_t _EWL_CDECL __getwchar(void) { wchar_t wch = (wchar_t)0; /* wide char to hold the final result */ char_t mbbuffer[MB_LEN_MAX]; char_t * mbbufptr = mbbuffer; int_t mbresult = -1; int_t mbstlen = 1; int_t i; for (i = 0; i < MB_LEN_MAX; i++) { mbbuffer[i] = 0x00; } if (fwide(stdin, 1) <= 0) { MISRA_EXCEPTION_RULE_14_7() return(WEOF); }
errno_t vfscanf_m(FILE *file, const string_m format, int *count, va_list args){ int orientation; errno_t rv; if(!format){ ErrorHandler("vfscanf_m: 2nd Argument NULL Pointer", format, EINVAL); ERROR(EINVAL); } orientation = fwide(file, 0); if(orientation > 0) rv = wvfscanf_m(file, format, count, args); else rv = cvfscanf_m(file, format, count, args); if (rv) ERROR(rv); return rv; }
FILE * open_wmemstream(wchar_t **bufp, size_t *sizep) { struct wmemstream *ms; int save_errno; FILE *fp; if (bufp == NULL || sizep == NULL) { errno = EINVAL; return (NULL); } *bufp = calloc(1, sizeof(wchar_t)); if (*bufp == NULL) return (NULL); ms = malloc(sizeof(*ms)); if (ms == NULL) { save_errno = errno; free(*bufp); *bufp = NULL; errno = save_errno; return (NULL); } ms->bufp = bufp; ms->sizep = sizep; ms->len = 0; ms->offset = 0; memset(&ms->mbstate, 0, sizeof(mbstate_t)); wmemstream_update(ms); fp = funopen(ms, NULL, wmemstream_write, wmemstream_seek, wmemstream_close); if (fp == NULL) { save_errno = errno; free(ms); free(*bufp); *bufp = NULL; errno = save_errno; return (NULL); } fwide(fp, 1); return (fp); }
int main(int argc, char *argv[]) { wchar_t pw[MAX_PASS_LEN*2+1]; char *locale; locale = setlocale(LC_ALL, ""); fwide(stdout, 1); if (argc != 2) { printf("\n Usage: aim_decode <base64 blob>"); printf("\n Example: aim_decode zo+VVoi9LWCtc0B8z9ZnfojNdjVuv08DXid8yK++LYI=\n"); return 0; } if (strlen(argv[1]) % 2 != 0) { printf("\n %s doesn't appear to be valid base64 string!\n", argv[1]); return 0; } AIM_Decrypt(argv[1], pw); wprintf(L"\n Password = \"%s\"\n", pw); return 0; }
void ICUResBundFormatter::startOutput(const XMLCh* const msgLocale , const XMLCh* const outPath) { // // Ok, lets try to open the the output file. All of the messages // for all the domains are put into a single Msg file, which can be // compiled into the program. // // CppErrMsgs_xxxx.Msg // // where xxx is the locale suffix passed in. // const unsigned int bufSize = 4095; XMLCh tmpBuf[bufSize + 1]; tmpBuf[0] = 0; XMLCh *tmpXMLStr = XMLString::transcode(".txt"); // ICU Resource Bundles now uses "root" as locale XMLCh* locale = XMLString::transcode ("root"); XMLString::catString(tmpBuf, outPath); XMLString::catString(tmpBuf, locale); XMLString::catString(tmpBuf, tmpXMLStr ); XMLString::release(&tmpXMLStr); char *tmpStr = XMLString::transcode(tmpBuf); fOutFl = fopen(tmpStr, "wt"); XMLString::release(&tmpStr); if ((!fOutFl) || (fwide(fOutFl, 1) < 0)) { wprintf(L"Could not open the output file: %s\n\n", xmlStrToPrintable(tmpBuf) ); releasePrintableStr throw ErrReturn_OutFileOpenFailed; } // Set the message delimiter fwprintf(fOutFl, L"%s { \n", xmlStrToPrintable(locale) ); releasePrintableStr XMLString::release(&locale); }
int zmain (void) { int fd; char fname[] = "/tmp/tst-perror.XXXXXX"; int result = 0; char buf[200]; ssize_t n; fd = mkstemp (fname); if (fd == -1) error (EXIT_FAILURE, errno, "cannot create temporary file"); /* Make sure the file gets removed. */ unlink (fname); fclose (stderr); if (dup2 (fd, 2) == -1) { printf ("cannot create file descriptor 2: %m\n"); exit (EXIT_FAILURE); } stderr = fdopen (2, "w"); if (stderr == NULL) { printf ("fdopen failed: %m\n"); exit (EXIT_FAILURE); } if (fwide (stderr, 0) != 0) { printf ("stderr not initially in mode 0\n"); exit (EXIT_FAILURE); } errno = EILSEQ; perror ("null mode test 1"); if (fwide (stderr, 0) != 0) { puts ("perror changed the mode from 0"); result = 1; } fputs ("multibyte string\n", stderr); if (fwide (stderr, 0) >= 0) { puts ("fputs didn't set orientation to narrow"); result = 1; } errno = EINVAL; perror ("<0 mode test"); fclose (stderr); lseek (fd, 0, SEEK_SET); n = read (fd, buf, sizeof (buf)); if (n != MB_EXP_LEN || memcmp (buf, MB_EXP, MB_EXP_LEN) != 0) { printf ("multibyte test failed. Expected:\n%s\nGot:\n%.*s\n", MB_EXP, (int) n, buf); result = 1; } else puts ("multibyte test succeeded"); lseek (fd, 0, SEEK_SET); ftruncate (fd, 0); if (dup2 (fd, 2) == -1) { printf ("cannot create file descriptor 2: %m\n"); exit (EXIT_FAILURE); } stderr = fdopen (2, "w"); if (stderr == NULL) { printf ("fdopen failed: %m\n"); exit (EXIT_FAILURE); } if (fwide (stderr, 0) != 0) { printf ("stderr not initially in mode 0\n"); exit (EXIT_FAILURE); } errno = EILSEQ; perror ("null mode test 2"); if (fwide (stderr, 0) != 0) { puts ("perror changed the mode from 0"); result = 1; } fputws (L"wide string\n", stderr); if (fwide (stderr, 0) <= 0) { puts ("fputws didn't set orientation to wide"); result = 1; } errno = EINVAL; perror (">0 mode test"); fclose (stderr); lseek (fd, 0, SEEK_SET); n = read (fd, buf, sizeof (buf)); if (n != WC_EXP_LEN || memcmp (buf, WC_EXP, WC_EXP_LEN) != 0) { printf ("wide test failed. Expected:\n%s\nGot:\n%.*s\n", WC_EXP, (int) n, buf); result = 1; } else puts ("wide test succeeded"); close (fd); return result; }
int main() { mbstate_t mb = {0}; size_t s = 0; tm tm = {0}; wint_t w = 0; ::FILE* fp = 0; __darwin_va_list va; char* ns = 0; wchar_t* ws = 0; static_assert((std::is_same<decltype(fwprintf(fp, L"")), int>::value), ""); static_assert((std::is_same<decltype(fwscanf(fp, L"")), int>::value), ""); static_assert((std::is_same<decltype(swprintf(ws, s, L"")), int>::value), ""); static_assert((std::is_same<decltype(swscanf(L"", L"")), int>::value), ""); static_assert((std::is_same<decltype(vfwprintf(fp, L"", va)), int>::value), ""); static_assert((std::is_same<decltype(vfwscanf(fp, L"", va)), int>::value), ""); static_assert((std::is_same<decltype(vswprintf(ws, s, L"", va)), int>::value), ""); static_assert((std::is_same<decltype(vswscanf(L"", L"", va)), int>::value), ""); static_assert((std::is_same<decltype(vwprintf(L"", va)), int>::value), ""); static_assert((std::is_same<decltype(vwscanf(L"", va)), int>::value), ""); static_assert((std::is_same<decltype(wprintf(L"")), int>::value), ""); static_assert((std::is_same<decltype(wscanf(L"")), int>::value), ""); static_assert((std::is_same<decltype(fgetwc(fp)), wint_t>::value), ""); static_assert((std::is_same<decltype(fgetws(ws, 0, fp)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(fputwc(L' ', fp)), wint_t>::value), ""); static_assert((std::is_same<decltype(fputws(L"", fp)), int>::value), ""); static_assert((std::is_same<decltype(fwide(fp, 0)), int>::value), ""); static_assert((std::is_same<decltype(getwc(fp)), wint_t>::value), ""); static_assert((std::is_same<decltype(getwchar()), wint_t>::value), ""); static_assert((std::is_same<decltype(putwc(L' ', fp)), wint_t>::value), ""); static_assert((std::is_same<decltype(putwchar(L' ')), wint_t>::value), ""); static_assert((std::is_same<decltype(ungetwc(L' ', fp)), wint_t>::value), ""); static_assert((std::is_same<decltype(wcstod(L"", (wchar_t**)0)), double>::value), ""); static_assert((std::is_same<decltype(wcstof(L"", (wchar_t**)0)), float>::value), ""); static_assert((std::is_same<decltype(wcstold(L"", (wchar_t**)0)), long double>::value), ""); static_assert((std::is_same<decltype(wcstol(L"", (wchar_t**)0, 0)), long>::value), ""); static_assert((std::is_same<decltype(wcstoll(L"", (wchar_t**)0, 0)), long long>::value), ""); static_assert((std::is_same<decltype(wcstoul(L"", (wchar_t**)0, 0)), unsigned long>::value), ""); static_assert((std::is_same<decltype(wcstoull(L"", (wchar_t**)0, 0)), unsigned long long>::value), ""); static_assert((std::is_same<decltype(wcscpy(ws, L"")), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcsncpy(ws, L"", s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcscat(ws, L"")), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcsncat(ws, L"", s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcscmp(L"", L"")), int>::value), ""); static_assert((std::is_same<decltype(wcscoll(L"", L"")), int>::value), ""); static_assert((std::is_same<decltype(wcsncmp(L"", L"", s)), int>::value), ""); static_assert((std::is_same<decltype(wcsxfrm(ws, L"", s)), size_t>::value), ""); static_assert((std::is_same<decltype(wcschr((wchar_t*)0, L' ')), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcscspn(L"", L"")), size_t>::value), ""); static_assert((std::is_same<decltype(wcslen(L"")), size_t>::value), ""); static_assert((std::is_same<decltype(wcspbrk((wchar_t*)0, L"")), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcsrchr((wchar_t*)0, L' ')), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcsspn(L"", L"")), size_t>::value), ""); static_assert((std::is_same<decltype(wcsstr((wchar_t*)0, L"")), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcstok(ws, L"", (wchar_t**)0)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wmemchr((wchar_t*)0, L' ', s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wmemcmp(L"", L"", s)), int>::value), ""); static_assert((std::is_same<decltype(wmemcpy(ws, L"", s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wmemmove(ws, L"", s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wmemset(ws, L' ', s)), wchar_t*>::value), ""); static_assert((std::is_same<decltype(wcsftime(ws, s, L"", &tm)), size_t>::value), ""); static_assert((std::is_same<decltype(btowc(0)), wint_t>::value), ""); static_assert((std::is_same<decltype(wctob(w)), int>::value), ""); static_assert((std::is_same<decltype(mbsinit(&mb)), int>::value), ""); static_assert((std::is_same<decltype(mbrlen("", s, &mb)), size_t>::value), ""); static_assert((std::is_same<decltype(mbrtowc(ws, "", s, &mb)), size_t>::value), ""); static_assert((std::is_same<decltype(wcrtomb(ns, L' ', &mb)), size_t>::value), ""); static_assert((std::is_same<decltype(mbsrtowcs(ws, (const char**)0, s, &mb)), size_t>::value), ""); static_assert((std::is_same<decltype(wcsrtombs(ns, (const wchar_t**)0, s, &mb)), size_t>::value), ""); }
static void simple_tests(void) { static const char zerobuf[] = { 'f', 'o', 'o', 0, 0, 0, 0, 'b', 'a', 'r', 0 }; char c; FILE *fp; fp = open_memstream(&buf, NULL); if (fp != NULL) errx(1, "did not fail to open stream"); else if (errno != EINVAL) err(1, "incorrect error for bad length pointer"); fp = open_memstream(NULL, &len); if (fp != NULL) errx(1, "did not fail to open stream"); else if (errno != EINVAL) err(1, "incorrect error for bad buffer pointer"); fp = open_memstream(&buf, &len); if (fp == NULL) err(1, "failed to open stream"); fflush(fp); assert_stream(""); if (fwide(fp, 0) >= 0) printf("stream is not byte-oriented\n"); fprintf(fp, "fo"); fflush(fp); assert_stream("fo"); fputc('o', fp); fflush(fp); assert_stream("foo"); rewind(fp); fflush(fp); assert_stream(""); fseek(fp, 0, SEEK_END); fflush(fp); assert_stream("foo"); /* * Test seeking out past the current end. Should zero-fill the * intermediate area. */ fseek(fp, 4, SEEK_END); fprintf(fp, "bar"); fflush(fp); /* * Can't use assert_stream() here since this should contain * embedded null characters. */ if (len != 10) printf("bad length %zd for zero-fill test\n", len); else if (memcmp(buf, zerobuf, sizeof(zerobuf)) != 0) printf("bad buffer for zero-fill test\n"); fseek(fp, 3, SEEK_SET); fprintf(fp, " in "); fflush(fp); assert_stream("foo in "); fseek(fp, 0, SEEK_END); fflush(fp); assert_stream("foo in bar"); rewind(fp); if (fread(&c, sizeof(c), 1, fp) != 0) printf("fread did not fail\n"); else if (!ferror(fp)) printf("error indicator not set after fread\n"); else clearerr(fp); fseek(fp, 4, SEEK_SET); fprintf(fp, "bar baz"); fclose(fp); assert_stream("foo bar baz"); free(buf); }
/** * Tests the wide character output function "fwprintf". * * CAUTION! Some wide characters are not recognised by the gnu/linux console yet, * so that only question marks appear on the place of the corresponding character, e.g.: * - U+70BA CJK UNIFIED IDEOGRAPH-70BA 為 * - U+256D BOX DRAWINGS LIGHT ARC DOWN AND RIGHT ╭ * * The ASCII characters and the following wide characters are recognised properly: * - U+2500 BOX DRAWINGS LIGHT HORIZONTAL ─ * * Results: * - if defining wide character array elements as symbol: * use L before EACH single character to convert it into a wide character, * since otherwise, it is interpreted as "normal" character and not displayed properly * - if defining wide character array elements as number/ code: * use the UTF-16 encoding and NOT UTF-8, since UTF-8 may offer more than one number to be written * and writing them one after the other into the array, separated by commata or not, brings wrong results * - a termination is NOT necessary for array definition, as the array count is given as usual in CYBOI * - the %s placeholder is not enough, since the wide character strings are not printed; * a letter "l" HAS TO BE added to make output work, e.g.: %ls * - a cast to (wchar_t*) is NOT necessary, since the L before a string already does that * and self-defined constants are of type wchar_t anyway */ void test_wide_character_wprintf() { /** The test wide character string. */ // The following does NOT work and will bring the compilation warning: // "cast to pointer from integer of different size" // The reason is that an "L" is needed before EACH character, to make it a wide character! // Therefore, the following three lines are commented out. // static wchar_t TEST_WIDE_CHARACTER_STRING_ARRAY[] = {'r', 'e', 'c', 't', 'a', 'n', 0xE7, 0x82, 0xBA, 'l', 'e'}; // static wchar_t TEST_WIDE_CHARACTER_STRING_ARRAY[] = {'r', 'e', 'c', 't', 'a', 'n', 0xE2, 0x94, 0x80, 'l', 'e'}; // static wchar_t* TEST_WIDE_CHARACTER_STRING = TEST_WIDE_CHARACTER_STRING_ARRAY; //?? static wchar_t TEST_WIDE_CHARACTER_STRING_WITH_TERMINATION_ARRAY[] = {'r', 'e', 'c', 't', 'a', 'n', '為', 'l', 'e', '\0'}; static wchar_t TEST_WIDE_CHARACTER_STRING_WITH_TERMINATION_ARRAY[] = {'r', 'e', 'c', 't', 'a', 'n', '─', 'l', 'e', '\0'}; static wchar_t* TEST_WIDE_CHARACTER_STRING_WITH_TERMINATION = TEST_WIDE_CHARACTER_STRING_WITH_TERMINATION_ARRAY; //?? static wchar_t TEST_WIDE_CHARACTER_STRING_WITH_L_ARRAY[] = {L'r', L'e', L'c', L't', L'a', L'n', L'為', L'l', L'e'}; static wchar_t TEST_WIDE_CHARACTER_STRING_WITH_L_ARRAY[] = {L'r', L'e', L'c', L't', L'a', L'n', L'─', L'l', L'e'}; static wchar_t* TEST_WIDE_CHARACTER_STRING_WITH_L = TEST_WIDE_CHARACTER_STRING_WITH_L_ARRAY; //?? static wchar_t TEST_WIDE_CHARACTER_STRING_WITH_L_AND_TERMINATION_ARRAY[] = {L'r', L'e', L'c', L't', L'a', L'n', L'為', L'l', L'e', 0x0000}; static wchar_t TEST_WIDE_CHARACTER_STRING_WITH_L_AND_TERMINATION_ARRAY[] = {L'r', L'e', L'c', L't', L'a', L'n', L'─', L'l', L'e', 0x0000}; static wchar_t* TEST_WIDE_CHARACTER_STRING_WITH_L_AND_TERMINATION = TEST_WIDE_CHARACTER_STRING_WITH_L_AND_TERMINATION_ARRAY; //?? static wchar_t TEST_WIDE_CHARACTER_STRING_WITH_UTF_8_CODES_AND_TERMINATION_ARRAY[] = {0x0072, 0x0065, 0x0063, 0x0074, 0x0061, 0x006E, 0xE7, 0x82, 0xBA, 0x006C, 0x0065, 0x0000}; static wchar_t TEST_WIDE_CHARACTER_STRING_WITH_UTF_8_CODES_AND_TERMINATION_ARRAY[] = {0x0072, 0x0065, 0x0063, 0x0074, 0x0061, 0x006E, 0xE2, 0x94, 0x80, 0x006C, 0x0065, 0x0000}; static wchar_t* TEST_WIDE_CHARACTER_STRING_WITH_UTF_8_CODES_AND_TERMINATION = TEST_WIDE_CHARACTER_STRING_WITH_UTF_8_CODES_AND_TERMINATION_ARRAY; //?? static wchar_t TEST_WIDE_CHARACTER_STRING_WITH_UTF_16_CODES_AND_TERMINATION_ARRAY[] = {0x0072, 0x0065, 0x0063, 0x0074, 0x0061, 0x006E, 0x70BA, 0x006C, 0x0065, 0x0000}; static wchar_t TEST_WIDE_CHARACTER_STRING_WITH_UTF_16_CODES_AND_TERMINATION_ARRAY[] = {0x0072, 0x0065, 0x0063, 0x0074, 0x0061, 0x006E, 0x2500, 0x006C, 0x0065, 0x0000}; static wchar_t* TEST_WIDE_CHARACTER_STRING_WITH_UTF_16_CODES_AND_TERMINATION = TEST_WIDE_CHARACTER_STRING_WITH_UTF_16_CODES_AND_TERMINATION_ARRAY; // Set stream orientation to wide character mode. // The second function argument has the following meaning: // - positive value: wide character mode // - negative value: (narrow) character mode fwide(stdout, *NUMBER_1_INTEGER_MEMORY_MODEL); log_write_terminated_message((void*) stdout, L"Test fputws.\n"); //?? log_write_terminated_message((void*) stdout, (wchar_t*) TEST_WIDE_CHARACTER_STRING); wprintf(L"Test wprintf without stream argument.\n"); // Test wide character constants. fwprintf(stdout, L"Test hello world ls: %10ls \n", "hello world"); fwprintf(stdout, L"Test hello world s: %10s \n", "hello world"); fwprintf(stdout, L"Test hello world L ls with cast: %10ls \n", (wchar_t*) L"hello world"); fwprintf(stdout, L"Test hello world L s with cast: %10s \n", (wchar_t*) L"hello world"); fwprintf(stdout, L"Test hello world L ls without cast: %10ls\n", L"hello world"); fwprintf(stdout, L"Test hello world L s without cast: %10s\n", L"hello world"); //?? fwprintf(stdout, L"Test wide character string ls: %5ls \n", TEST_WIDE_CHARACTER_STRING); //?? fwprintf(stdout, L"Test wide character string s: %5s \n", TEST_WIDE_CHARACTER_STRING); fwprintf(stdout, L"Test wide character string with termination: %5ls \n", TEST_WIDE_CHARACTER_STRING_WITH_TERMINATION); fwprintf(stdout, L"Test wide character string L ls: %5ls \n", TEST_WIDE_CHARACTER_STRING_WITH_L); fwprintf(stdout, L"Test wide character string L s: %5s \n", TEST_WIDE_CHARACTER_STRING_WITH_L); fwprintf(stdout, L"Test wide character string L and termination: %5ls \n", TEST_WIDE_CHARACTER_STRING_WITH_L_AND_TERMINATION); fwprintf(stdout, L"Test wide character string with UTF-8 codes and termination ls: %5ls \n", TEST_WIDE_CHARACTER_STRING_WITH_UTF_8_CODES_AND_TERMINATION); fwprintf(stdout, L"Test wide character string with UTF-8 codes and termination s: %5s \n", TEST_WIDE_CHARACTER_STRING_WITH_UTF_8_CODES_AND_TERMINATION); fwprintf(stdout, L"Test wide character string with UTF-16 codes and termination ls: %5ls \n", TEST_WIDE_CHARACTER_STRING_WITH_UTF_16_CODES_AND_TERMINATION); fwprintf(stdout, L"Test wide character string with UTF-16 codes and termination s: %5s \n", TEST_WIDE_CHARACTER_STRING_WITH_UTF_16_CODES_AND_TERMINATION); //?? fwprintf(stdout, L"Test wide character string fourth letter with cast: %lc \n", (wchar_t*) TEST_WIDE_CHARACTER_STRING[3]); //?? fwprintf(stdout, L"Test wide character string fourth letter without cast: %lc \n", TEST_WIDE_CHARACTER_STRING[3]); log_write_terminated_message((void*) stdout, L"Test END.\n"); }
/* threadsafety protection is in fwrite */ wchar_t _EWL_CDECL putwc(wchar_t c, FILE * file) { if (fwide(file, 1) <= 0) { MISRA_EXCEPTION_RULE_14_7() return WEOF; }
int main(int argc, const char **argv) { srand((unsigned int)time(NULL)); #if _MSC_VER setlocale(LC_ALL, ""); #else std::setlocale(LC_ALL, ""); fwide(stdout,1); fwide(stderr,1); #endif //デバッグビルドだと毎回テストを実行します. 慈悲はない. SEXYTEST_RUNNER(); //オプションを配列にマップ if (! Option::m()->Create(argc,argv) ) { wprintf(L"\n"); usage(); return 0; } if (argc <= 2) { // wiki2yomiConvert("jawiki-latest-pages.xml"); // wiki2ruigiConvert("jawiki-latest-pages.xml"); // wiki2engConvert("jawiki-latest-pages.xml"); // cmudic2yomiConvert("cmudict.0.7a"); // wiki2charaConvert("jawiki-latest-pages.xml"); // wiki2categoryConvert("jawiki-latest-pages.xml"); usage(); return 0; } //モードによって振り分け if ( strcmp(argv[1],"yomi") == 0) { wiki2yomiConvert(argv[2] ); } else if ( strcmp(argv[1],"ruigi") == 0) { wiki2ruigiConvert(argv[2] ); } else if ( strcmp(argv[1],"eng") == 0) { wiki2engConvert(argv[2] ); } else if ( strcmp(argv[1],"chara") == 0) { wiki2charaConvert(argv[2] ); } else if ( strcmp(argv[1],"category") == 0) { wiki2categoryConvert(argv[2] ); } else if ( strcmp(argv[1],"cmudict") == 0) { cmudic2yomiConvert(argv[2] ); } else { wprintf(L"パラメタ(%ls)は存在しません。死んで詫びよ。\n",_A2W(argv[1]).c_str() ); wprintf(L"\n"); usage(); return 0; } return 0; }
void MsgCatFormatter::startOutput( const XMLCh* const locale , const XMLCh* const outPath) { // // Ok, lets try to open the the output file. All of the messages // for all the domains are put into a single Msg file, which can be // compiled into the program. // // CppErrMsgs_xxxx.Msg // // where xxx is the locale suffix passed in. // const unsigned int bufSize = 4095; XMLCh *tmpBuf = new XMLCh[bufSize + 1]; tmpBuf[0] = 0; XMLCh *tmpXMLStr = XMLString::transcode("XercesMessages_"); XMLCh *tmpXMLStr2 = XMLString::transcode(".Msg"); XMLString::catString(tmpBuf, outPath); XMLString::catString(tmpBuf, tmpXMLStr ); XMLString::catString(tmpBuf, locale); XMLString::catString(tmpBuf, tmpXMLStr2 ); XMLString::release(&tmpXMLStr); XMLString::release(&tmpXMLStr2); char *tmpStr = XMLString::transcode(tmpBuf); fOutFl = fopen(tmpStr, "wt"); XMLString::release(&tmpStr); if ((!fOutFl) ||(fwide(fOutFl, 1) < 0)) { wprintf(L"Could not open the output file: %s\n\n", xmlStrToPrintable(tmpBuf) ); releasePrintableStr XMLString::release(&tmpBuf); throw ErrReturn_OutFileOpenFailed; } // Set the message delimiter fwprintf(fOutFl, L"$quote \"\n"); delete tmpBuf; tmpBuf = new XMLCh[bufSize + 1]; tmpBuf[0] = 0; tmpXMLStr = XMLString::transcode("XMLMsgCat_Ids.hpp"); XMLString::catString(tmpBuf, outPath); XMLString::catString(tmpBuf, tmpXMLStr ); XMLString::release(&tmpXMLStr); tmpStr = XMLString::transcode(tmpBuf); fOutHpp = fopen(tmpStr, "wt"); XMLString::release(&tmpStr); if ((!fOutHpp) || (fwide(fOutHpp,1) < 0)) { wprintf(L"Could not open the output file: %s\n\n", xmlStrToPrintable(tmpBuf) ); releasePrintableStr XMLString::release(&tmpBuf); throw ErrReturn_OutFileOpenFailed; } fwprintf ( fOutHpp , L"// ----------------------------------------------------------------\n" L"// This file was generated from the XML error message source.\n" L"// so do not edit this file directly!!\n" L"// ----------------------------------------------------------------\n\n" L"#include <xercesc/util/XercesDefs.hpp>\n\n" L"XERCES_CPP_NAMESPACE_BEGIN\n\n" ); // Reset the sequence id fSeqId = 1; delete tmpBuf; }