Commands using UNIX or Linux often use the man to find some commands or the use of functions. A few days ago, I Down had a CGYWIN, I would like to learn the development below the Linux environment. When cGywin uses Man to see help, I always feel that I have not used some text editor, such as UltraEdit, I don't feel, I don't feel very straight ( I believe this feeling is just for those who just contact * NIX), so I will redirect the help file to a file, and use UltraEdit under Window, but I found that redirect output The file contains some control characters (underscore, color), which is difficult to read directly below Window. So I wrote a small program, transform the contents of the help file that redirected output, and converted to the text file below Window.
The program is relatively simple, mainly to find control characters and convert it. The program code is as follows:
INT Main (int Argc, char * argv []) {char * pname = argv [0]; PNAME = Strlen (Argv [0]); while (PNAME> Argv [0] && PName [-1]! = ' // ') {PNAME -;} if (argc! = 2) {Printf ("USAGE:% s filename / R / N EG .:% s vingo.txt / r / n", PNAME, PNAME; RETURN 0;} Handle Hfile = CreateFile (argv [1], generic_read, file_share_read, 0, open_existing, file_attribute_normal, null); if (hfile == invalid_handle_value) {Printf ("Can not open file:% s / r / n", argv [1]); DWORD dwError = GetLastError (); return 0;} char szNewFileName [MAX_PATH]; sprintf (szNewFileName, "% s.vingo.txt", argv [1]); HANDLE hFileNew = CreateFile (szNewFileName, GENERIC_WRITE , FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFileNew == INVALID_HANDLE_VALUE) {CloseHandle (hFile); printf ( "Can not Create File / r / n"); return 0;} char chTemp; DWORD cbRead; DWORD Cbwrite; while ILE (HFile, & ChTemp, Null) {if (cbread == 0) {Break;} //printf("[%.2x]" ,chtemp); if (chTemp == 0x08) {Readfile (Hfile, & ChTemp, Null); Continue;} if (chTEMP == 0x5f) {ReadFile (HFile, & ChTemp, Sizeof (Char), & Cbread, NULL); if (chTemp == 0x08 ) {Continue;} else {if (chTEMP == 0x5f) {setfilepointer (hfile, -1, 0, file_current);
}}}}} {Writefile (Hfilenew, "/ R / N", 2, & cbWrite, NULL);} IF ((chTEMP <= 0x7e) && (chTEMP> = 0x20)) {Writefile (HFileNew) , & chTemp, SizeOf (CHAR), & CBWRITE, NULL; IF (CBWrite! = Sizeof (Char)) {Printf ("While Writing% C, Maybe Happen Some Errors", ChTemp);}}} CloseHandle (HFILE); CloseHandle (HFileNew); Printf ("OK ... Translate SuccessFully / R / NPLEase READ File:% S / R / N", SzneWFileName); Return 0;}