home *** CD-ROM | disk | FTP | other *** search
- //
- // Copyright (c) 2000
- // Pasquale J. Villani
- // All Rights reserved
- //
- // This is our child process. It reads data from standard input,
- // flips characters in the buffer from upper case to lower case and vice versa,
- // then write the buffer out.
- //
-
- #include <windows.h>
- #include <ctype.h>
-
- #define BUFSIZE 4096
-
-
- int main(int argc, char *argv[])
- {
- CHAR chBuf[BUFSIZE];
- DWORD dwRead, dwWritten, dwIdx;
- HANDLE hStdin, hStdout; BOOL fSuccess;
-
- // First, get handles to standard input and standard output so we
- // can use them later.
- hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
- hStdin = GetStdHandle(STD_INPUT_HANDLE);
- if ((hStdout == INVALID_HANDLE_VALUE) ||
- (hStdin == INVALID_HANDLE_VALUE))
- {
- ExitProcess(1);
- }
-
- // Loop until either there's no input or a failure on the output,
- // converting characters in between.
- for (;;)
- {
- // Read from standard input.
- fSuccess = ReadFile(hStdin, chBuf, BUFSIZE, &dwRead, NULL);
- if (!fSuccess || dwRead == 0)
- {
- break;
- }
-
- // Flip upper case to lower case and vice versa
- for( dwIdx = 0; dwIdx < dwRead; dwIdx++ )
- {
- if(islower(chBuf[dwIdx]))
- chBuf[dwIdx] = _toupper(chBuf[dwIdx]);
- else if(isupper(chBuf[dwIdx]))
- chBuf[dwIdx] = _tolower(chBuf[dwIdx]);
- }
-
- fSuccess = WriteFile(hStdout, chBuf, dwRead, &dwWritten, NULL);
- if (!fSuccess)
- {
- break;
- }
- }
- }
-
-
-
-