RTF2TXT.BAT - RTF to Text file converter

A program born out of a simple need, to read a Rich Text Format document. This batch creates and runs a QBasic program that converts the RTF file to plain text. Changes "\par" to newline, "\tab" to tab, all other words beginning with "\" are ignored. Newlines in the source file are ignored. To get rid of the header junk, "{" turns off the output stream until a "}" comes along.

Usage: RTF2TXT infile.rtf outfile.txt

:: (updated) Cheezy RTF-to-Text converter batch 
:: by Terry Newton. Needs QBASIC "on the path"
@echo off
if .%2==. echo Usage: Usage: RTF2TXT infile.rtf outfile.txt
if .%2==. goto end
if not exist %1 echo File not found
if not exist %1 goto end
echo Converting RTF to text...
echo> rtf2-.bas :on error goto x
echo>>rtf2-.bas open "%1" for input as #1:open "rtf2-" for output as #2
echo>>rtf2-.bas f:a$=input$(1,1):c$=""
echo>>rtf2-.bas if a$=chr$(13) or a$=chr$(10) then goto f
echo>>rtf2-.bas if a$="{" then skip=1:goto f
echo>>rtf2-.bas if a$="}" then skip=0:goto f
echo>>rtf2-.bas if skip then goto f
echo>>rtf2-.bas if (a$="\")=0 then goto o
echo>>rtf2-.bas g:a$=input$(1,1):if (a$=" ")=0 then c$=c$+a$:goto g
echo>>rtf2-.bas if c$="par" then print #2,""
echo>>rtf2-.bas if c$="tab" then print #2,chr$(9);
echo>>rtf2-.bas goto f
echo>>rtf2-.bas o:print #2,a$;:goto f
echo>>rtf2-.bas x:close #1:close #2:resume ww
echo>>rtf2-.bas ww:on error goto done
echo>>rtf2-.bas open "rtf2-" for input as #1:open "%2" for output as #2
echo>>rtf2-.bas lm:line input #1, a$:if a$="" then print #2,"":goto lm
echo>>rtf2-.bas l0:t=0:p=instr(a$,chr$(9)):if sgn(77-p)-(p=0)=1 then t=8
echo>>rtf2-.bas p=77-t:if sgn(p-len(a$)+1)=1 then print #2,a$:goto lm
echo>>rtf2-.bas l1:if mid$(a$,p,1)=" " then goto c
echo>>rtf2-.bas p=p-1:if p=0 then print #2,a$:goto lm else goto l1
echo>>rtf2-.bas c:print #2,left$(a$,p-1):a$=right$(a$,len(a$)-p):goto l0
echo>>rtf2-.bas done:close #1:close #2:system
qbasic /run rtf2-.bas
del rtf2-.bas
del rtf2-