this is how to do it in C or C++
its just reading charters from stdin i think 1 at a time
while ((c = getchar()) != EOF) {
/* read single char until EOF */
//if (c == fromch) c = toch;
/* convert matching characters */
putchar (c);
/* copy character to stdout */
}
hears one for qbasic i found PS ther called "filter" not pipe's it touc me ages to find this out
'===========================================================================
' Subject: MD-DOS STANDARD OUTPUT FILTER Date: 01-08-97 (15:27)
' Author: Tyler Barnes Code: QB, PDS
' Origin: comp.lang.basic.misc Packet: DOS.ABC
'===========================================================================
'Hey everyone. Here's one last version of the filter program I made. (I
'hope I didn't post this version already)
'You will notice that I have two different filter "methods" ... The
'"EASY" method worked in my old version, but the "COMPLICATED" version
'did not because I didn't have any of the file handling SUBs created. I
'expected you could just use BASIC's file handling routines.
'Unfortunatly, BASIC's routines mess with the MSDOS cursor so I had to
'make my own custom file-handling routines to handle the second filter
'method. Here it is:
DECLARE FUNCTION REPLACE$ (T$, S$, R$)
DECLARE SUB StandardOutput (ST$)
DECLARE FUNCTION ReadFile$ (Bytes%)
DECLARE FUNCTION FileExist% (T$)
DECLARE FUNCTION StandardInput$ ()
DECLARE SUB OpenFile (File$, Mode$)
DECLARE SUB WriteFile (DTW$)
DECLARE SUB CloseFile ()
'$INCLUDE: '\basic\bc\qb.bi'
DIM SHARED InregX AS RegTypeX, OutregX AS RegTypeX
' __________________________________________________________________________
'| MS-DOS Standard Output Filter |
'| By D. Tyler Barnes |
'| |
'| This program allows you to create a standard output filter such |
'| as MORE.COM and SORT.EXE, two programs that come with MS-DOS. It allows |
'| you to pipe information to your program from the command line and modify |
'| the information before sending it to standard output. |
'| |
'| Note: This version of FILTER.BAS has custom file handling routines |
'| because BASIC's inbuilt file handling routines mess with the DOS |
'| cursor. That was messing things up pretty badly in the previous |
'| version. |
'| |
'| Example Usage: DIR /w |Filter |
'| Example #2: Filter <FILENAME.EXT |
'| |
'| Send comments to:
Tyler.Barnes@access.cn.camriv.bc.ca |
'| |
'| TWO WANNA-BE-HACKER FILTERS PROVIDED! |
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CONST RunMethod = "complicated"
SELECT CASE UCASE$(RunMethod)
CASE "COMPLICATED"
'----------------------------------------------------------------------------
'****************************************************************************
'Complicated method. Study this if you're wanting to make a filter that has
'to recieve data more than one byte at a time
'****************************************************************************
TempName% = 0
NewName:
TempName$ = LTRIM$(STR$(TempName%))
IF FileExist(TempName$) THEN TempName% = TempName% + 1: GOTO NewName
OpenFile TempName$, "O"
DO
in$ = StandardInput$
WriteFile in$
LOOP UNTIL in$ = CHR$(0)
CloseFile
OpenFile TempName$, "I"
DO
in$ = ""
DO
A$ = ReadFile$(1)
in$ = in$ + A$
LOOP UNTIL A$ = CHR$(0) OR A$ = CHR$(13)
'~~~~~~~~~~~~ Data is processed here ~~~~~~~~~~~~
in$ = REPLACE$(in$, "MORON", "LAMER")
in$ = REPLACE$(in$, "IDIOT", "LAMER")
in$ = REPLACE$(in$, "GEEK", "LAMER")
in$ = REPLACE$(in$, "JERK", "LAMER")
in$ = REPLACE$(in$, "NERD", "LAMER")
in$ = REPLACE$(in$, "LOSER", "LAMER")
in$ = REPLACE$(in$, "THAT", "DAT")
in$ = REPLACE$(in$, "THIS", "DIS")
in$ = REPLACE$(in$, "THING", "THANG")
in$ = REPLACE$(in$, "LOVE", "LUV")
in$ = REPLACE$(in$, "BITES", "BYTES")
in$ = REPLACE$(in$, "YOUR", "YER")
in$ = REPLACE$(in$, "YOU'RE", "YER")
in$ = REPLACE$(in$, "GREETING", "GREET")
in$ = REPLACE$(in$, "CONGRATULATIONS", "CONGRATZ")
in$ = REPLACE$(in$, "CKS", "X")
in$ = REPLACE$(in$, " C", " K")
in$ = REPLACE$(in$, " F", " PH")
in$ = REPLACE$(in$, "S ", "Z ")
in$ = REPLACE$(in$, "S" + CHR$(13), "Z" + CHR$(13))
in$ = REPLACE$(in$, "AU", "AW")
in$ = UCASE$(in$)
in$ = REPLACE$(in$, "A", "a")
in$ = REPLACE$(in$, "E", "e")
in$ = REPLACE$(in$, "I", "i")
in$ = REPLACE$(in$, "O", "o")
in$ = REPLACE$(in$, "O", "0")
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
StandardOutput in$
LOOP UNTIL A$ = CHR$(0)
CloseFile
KILL TempName$
'----------------------------------------------------------------------------
CASE "EASY"
'****************************************************************************
'Easy method. Use this if recieving data 1 byte at a time is A-ok!
'****************************************************************************
DO
in$ = StandardInput$
'~~~~~~~~~~~~ Data is processed here ~~~~~~~~~~~~
in$ = UCASE$(in$)
SELECT CASE in$
CASE "A", "E", "I", "U": in$ = LCASE$(in$)
CASE "S": in$ = "Z"
CASE "O": in$ = "0"
CASE "F": in$ = "PH"
END SELECT
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
StandardOutput in$
LOOP UNTIL in$ = CHR$(0)
'----------------------------------------------------------------------------
END SELECT
SUB CloseFile
SHARED FileNum%
CLOSE FileNum%
END SUB
FUNCTION FileExist% (T$)
'Just for the record, I didn't write this function. Not to say I COULDN'T.
DEFINT A-Z
DIM F AS STRING * 64
DIM Inx AS RegTypeX
DIM Outx AS RegTypeX
Inx.ax = &H2F00
CALL INTERRUPTX(&H21, Inx, Outx)
DTAAddr = Outx.bx
F$ = LTRIM$(RTRIM$(UCASE$(T$))) + CHR$(0)
Inx.ds = VARSEG(F$)
Inx.dx = VARPTR(F$)
Inx.ax = &H4E00
Inx.cx = -1
CALL INTERRUPTX(&H21, Inx, Outx)
IF Outx.flags AND 1 THEN
FileExist% = 0
ELSE
FileExist% = 1
END IF
END FUNCTION
DEFSNG A-Z
SUB OpenFile (File$, Mode$)
SHARED FileNum%, DOSFileNum%
Mode$ = UCASE$(Mode$)
FileNum% = FREEFILE
SELECT CASE Mode$
CASE "I": OPEN File$ FOR INPUT AS FileNum%
CASE "O": OPEN File$ FOR OUTPUT AS FileNum%
CASE ELSE: ERROR (5)
END SELECT
DOSFileNum% = FILEATTR(1, 2)
END SUB
FUNCTION ReadFile$ (Bytes%)
SHARED DOSFileNum%
RecieveBuffer$ = STRING$(Bytes%, 0)
InregX.ax = &H3F00 'Read from device/file subfunction
InregX.bx = DOSFileNum% 'File handle
InregX.cx = Bytes% 'Characters to read
InregX.dx = SADD(RecieveBuffer$) 'Point DX to offset of recieve buffer
InregX.ds = VARSEG(RecieveBuffer$) 'Point DS to segment of recieve buffer
CALL INTERRUPTX(&H21, InregX, OutregX) 'Read in to recieve buffer
IF OutregX.ax = 0 THEN RecieveBuffer$ = CHR$(0)'If EOF return a null!
ReadFile$ = RecieveBuffer$
END FUNCTION
FUNCTION REPLACE$ (T$, S$, R$)
DEFINT A-Z
W = 1
DO UNTIL INSTR(W, UCASE$(T$), UCASE$(S$)) = 0
Q = INSTR(W, UCASE$(T$), UCASE$(S$))
T$ = LEFT$(T$, Q - 1) + R$ + RIGHT$(T$, LEN(T$) - (Q + LEN(S$) - 1))
W = Q + LEN(R$)
LOOP
REPLACE$ = T$
END FUNCTION
DEFSNG A-Z
FUNCTION StandardInput$
SHARED DOSFileNum%
Temp% = DOSFileNum%
DOSFileNum% = 0
StandardInput$ = ReadFile$(1)
DOSFileNum% = Temp%
END FUNCTION
SUB StandardOutput (ST$)
SHARED DOSFileNum%
Temp% = DOSFileNum%
DOSFileNum% = 1
WriteFile ST$
DOSFileNum% = Temp%
END SUB
SUB WriteFile (DTW$)
SHARED DOSFileNum%
InregX.ax = &H4000 'Read from device/file subfunction
InregX.bx = DOSFileNum% 'File handle
InregX.cx = LEN(DTW$) 'Characters to write
InregX.dx = SADD(DTW$) 'Point DX to offset of string
InregX.ds = VARSEG(DTW$) 'Point DS to segment of string
CALL INTERRUPTX(&H21, InregX, InregX) 'Write chars
END SUB