Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

tdisp.c

Go to the documentation of this file.
00001 #include <windows.h> 00002 #include <stdio.h> 00003 #include <stdlib.h> 00004 #include <io.h> 00005 #include <fcntl.h> 00006 00007 BOOL gfNotepad = FALSE; 00008 00009 VOID ErrorExit(VOID) { 00010 fprintf(stderr, "Usage: \"tdisp [-n] hex1 [hex2] [width]\"\n"); 00011 fprintf(stderr, " \"tdisp hex\"\n"); 00012 fprintf(stderr, " Displays single Unicode char <hex>\n"); 00013 fprintf(stderr, " \"tdisp hex1 hex2\"\n"); 00014 fprintf(stderr, " Displays Unicode char <hex1> through <hex2>\n"); 00015 fprintf(stderr, " \"tdisp hex1 hex2 n\"\n"); 00016 fprintf(stderr, " Displays <hex1> thru <hex2> in lines of <width> chars\n"); 00017 fprintf(stderr, " -n generates a Notepad Unicode text file on stdout\n"); 00018 exit(2); 00019 } 00020 00021 VOID NotepadPrint(LPWSTR pwsz) { 00022 while (*pwsz) { 00023 if (*pwsz == 0x000a) { 00024 printf("%c%c", 0x0d, 0x00); 00025 } 00026 printf("%c%c", LOBYTE(*pwsz), HIBYTE(*pwsz)); 00027 pwsz++; 00028 } 00029 } 00030 00031 int _cdecl main(int argc, char *argv[]) { 00032 WCHAR wch1, wch2; 00033 int n = 1; 00034 int i; 00035 LPWSTR p; 00036 WCHAR awch[100]; 00037 DWORD cchWritten; 00038 00039 if (argc < 2) { 00040 ErrorExit(); 00041 } 00042 00043 if ((*argv[1] == '/') || (*argv[1] == '-')) { 00044 switch (argv[1][1]) { 00045 case 'n': 00046 gfNotepad = TRUE; 00047 /* Set "stdin" to have binary mode: */ 00048 _setmode( _fileno( stdout ), _O_BINARY ); 00049 printf("%c%c", 0xff, 0xfe); // Unicode BOM 00050 argv++; 00051 break; 00052 default: 00053 ErrorExit(); 00054 } 00055 } 00056 00057 wch1 = (WCHAR)strtol(argv[1], NULL, 16); 00058 if (argc > 2) { 00059 wch2 = (WCHAR)strtol(argv[2], NULL, 16); 00060 if (argc > 3) { 00061 n = atoi(argv[3]); 00062 } 00063 } else { 00064 wch2 = wch1; 00065 } 00066 00067 if (gfNotepad) { 00068 NotepadPrint(L"=======(begin)=======\n"); 00069 } else { 00070 printf("=======(begin)=======\n"); 00071 } 00072 00073 while (wch1 <= wch2) { 00074 i = swprintf(awch, L"0x%04x : --->", wch1); 00075 p = &awch[i]; 00076 for (i = 0; i < n; i++) { 00077 *p++ = wch1++; 00078 } 00079 *p = L'\0'; 00080 wcscat(awch, L"<---\n"); 00081 if (gfNotepad) { 00082 NotepadPrint(awch); 00083 } else { 00084 WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), awch, 00085 wcslen(awch), &cchWritten, NULL); 00086 } 00087 } 00088 00089 if (gfNotepad) { 00090 NotepadPrint(L"========(end)========\n"); 00091 } else { 00092 printf("========(end)========\n"); 00093 } 00094 00095 return 0; 00096 }

Generated on Sat May 15 19:41:57 2004 for test by doxygen 1.3.7