home *** CD-ROM | disk | FTP | other *** search
- \******************************************************************************
- \*
- \* WSCON.BAS CBASIC (CB-80) (C) David Chazin 10/85
- \* Last update: 10/11/85 ver 1.0 Roosevelt, NJ 08555-0364
- \*
- \* The main purpose of this program is to read in a WordStar document
- \* from a disk file and write straight printable ASCII to another disk
- \* file or the printer at the user's choice. The original text file is
- \* not altered in any way. If an output file which already exists is
- \* specified, user is given the option to overwrite or append to the file.
- \*
- \* WSCON can be invoked from a command line. If just WSCON in entered,
- \* the user is presented with helpful information and is prompted for the
- \* command line.
- \*
- \* There are other fine programs already available which do
- \* approximately the same job. I undertook to write this one so I would
- \* have a program which properly handled the "soft" hyphen and one which
- \* didn't print a bunch of blank lines at the end of each page when
- \* printing to a disk file.
- \*
- \* When set to give hyphen help, WordStar will insert a "soft" or
- \* conditional hyphen in the middle of a long word at the end of a line.
- \* If the paragraph in which that word occurs is subsequently reformatted,
- \* that word may not remain at the end of the line. The "soft" hyphen
- \* will, therefore, wind up in the middle of the line. Then, when the
- \* other de-WordStar-izers that I've seen handle this situation, we
- \* either wind up with a hyphen somewhere in the middle of a line where it
- \* does not belong, or without a hyphen at the end of the line where is does
- \* belong. WSCON deletes all "soft" hyphens not occurring at the end of a
- \* line.
- \*
- \* The other special need addressed by WSCON concerns page formatting,
- \* specifically the numerous blank lines sometimes printed to get from
- \* one page to the next. As editor and publisher of the newsletter/journal
- \* of the Kaypro Users Group of New Jersey, I regularly have need to change
- \* an article from a WordStar document intended for printing into a
- \* straight ASCII file appropriate for viewing on a CRT. Accordingly,
- \* WSCON will not print more than one blank line in a row to a disk file,
- \* thereby negating the effects of this page formatting.
- \*
- \* WSCON also deletes all control characters (except CR, LF and Tab),
- \* strips any set high-order bits, truncates spaces and tabs occurring
- \* at the end of a line, ignores lines beginning with a period, and
- \* changes ^O's into spaces.
- \*
- \**************************** GLOBAL DECLARATIONS *****************************
- \*
- STRING Cmd$, InputFile$, OutputFile$, Bell$, Response$, Dummy$, Buffer$, \
- Truncate$, SoftHyphen$
-
- INTEGER Ptr%, Char%, PreviousLineWasBlank%, HardCopy%, L%
- \*
- \******************** INITIALIZATION OF GLOBAL VARIABLES **********************
- \*
- Bell$ = CHR$(7)
- Truncate$ = CHR$(9) + CHR$(32) + CHR$ (160) rem tab and space
- SoftHyphen$ = CHR$(30) + CHR$(31)
- HardCopy% = 0
- \*
- \******************************* MAIN PROGRAM *********************************
- \*
- \Error Handling:
- ON ERROR GOTO 0.0
- GOTO 1.3
- 0.0 PRINT Bell$; "Error "; ERR; " at line "; ERRL
- STOP
-
-
- \Get Command Tail:
- 1.3 IF MATCH (LEFT$(COMMAND$,1), "?*/", 1) > 0 OR LEN (COMMAND$) = 0 \
- THEN \
- GOTO 1.0 \
- ELSE \
- Cmd$ = COMMAND$: \
- GOTO 2.0
- 1.0 PRINT "WSCON ver 1.0 (c) 1985 David Chazin, Roosevelt, NJ 08555-0364":\
- PRINT " De-WordStar-izes a text file. If you enter LST: as" :\
- PRINT " the OutputFile.Typ, then output goes to printer. Other-" :\
- PRINT " wise, output goes to the specified disk file.": GOTO 1.1
- 1.2 PRINT Bell$; "What the heck is "; InputFile$; "?"
- 1.1 PRINT
- PRINT " Syntax: WSCON InputFile.Typ, OutputFile.Typ"
- PRINT
- PRINT " Enter command line or press <CR> to quit:"
- PRINT
- PRINT " WSCON";
- INPUT ""; LINE Cmd$
- IF Cmd$ = "" \
- THEN \
- STOP \
- ELSE \
- Cmd$ = UCASE$ (Cmd$)
-
-
- \Parse Command Tail:
- 2.0 Ptr% = MATCH (" ", Cmd$, 1) rem remove all spaces
- IF Ptr% > 0 THEN \
- Cmd$ = MID$ (Cmd$, 1, Ptr%-1) + MID$ (Cmd$, Ptr%+1, 255): \
- GOTO 2.0
- Ptr% = MATCH (",", Cmd$, 1) rem get file names
- IF Ptr% = 0 THEN \
- PRINT Bell$; "Invalid command line": \
- GOTO 1.1
- InputFile$ = MID$ (Cmd$, 1, Ptr%-1)
- IF SIZE (InputFile$) = 0 THEN \
- GOTO 1.2
- OutputFile$ = MID$ (Cmd$, Ptr%+1, 255)
- IF OutputFile$ = "LST:" THEN \
- HardCopy% = -1: \
- GOTO 3.3
- IF SIZE (OutputFile$) <> 0 THEN \
- PRINT Bell$; OutputFile$; " already exists:";: \
- PRINT " Q = Quit O = Overwrite A = Append ";: \
- Response$ = UCASE$ (CHR$ (CONCHAR%)): PRINT: \
- ON MATCH (Response$, "QOA", 1) GOTO 1.1, 3.0, 3.1
-
-
- \Open Files:
- 3.0 CREATE OutputFile$ AS 2: GOTO 3.3 rem overwrite
- 3.1 OPEN OutputFile$ AS 2 rem append
- IF END #2 THEN 3.3
- 3.2 READ #2; LINE Dummy$: GOTO 3.2
- 3.3 IF END #1 THEN 1.2
- OPEN InputFile$ AS 1
-
-
- \Main Loop:
-
-
- \Initialize Main Loop:
- IF END #1 THEN 8.0
- IF HardCopy% THEN LPRINTER
- PreviousLineWasBlank% = 0
-
-
- \Read Line from Input File:
- 4.0 READ #1; LINE Buffer$
-
-
- \Ignore Lines Beginning with Dot Commands:
- IF LEFT$ (Buffer$, 1) <> "." THEN GOTO 12.0
- Ptr% = MATCH (CHR$(13) + CHR$(138), Buffer$, 1)
- IF Ptr% = 0 THEN GOTO 4.0
- Buffer$ = MID$ (Buffer$, Ptr% + 2, 255)
-
-
- \Remove CR with bit 7 set, if present:
- 12.0 IF RIGHT$ (Buffer$, 1) = CHR$ (141) THEN \
- Buffer$ = LEFT$ (Buffer$, LEN (Buffer$) - 1)
-
-
- \Change ^O's into spaces:
- 11.0 Ptr% = MATCH (CHR$(15), Buffer$, 1)
- IF Ptr% > 0 THEN \
- Buffer$ = LEFT$ (Buffer$, Ptr%-1) + " " + MID$ (Buffer$, Ptr%+1, 255):\
- GOTO 11.0
-
-
- \Truncate Trailing Blanks and Tabs:
- Ptr% = LEN (Buffer$)
- IF Ptr% = 0 THEN GOTO 10.0
- 5.0 IF MATCH (MID$ (Buffer$, Ptr%, 1), Truncate$, 1) <> 0 THEN \
- Ptr% = Ptr% - 1: \
- IF Ptr% > 0 THEN GOTO 5.0
- Buffer$ = LEFT$ (Buffer$, Ptr%)
-
-
- \Treat a Line Containing Only Control Characters as a Blank Line:
- L% = LEN (Buffer$)
- FOR Ptr% = 1 TO L%
- IF MID$ (Buffer$, Ptr%, 1) > CHR$(31) THEN Ptr% = L% + 5
- NEXT Ptr%
- IF Ptr% = L% + 1 THEN Buffer$ = ""
-
-
- \Do Not Print 2 Blank Lines in a Row to File:
- 10.0 IF HardCopy% THEN GOTO 9.0
- Ptr% = LEN (Buffer$)
- IF Ptr% = 0 \
- THEN \
- IF PreviousLineWasBlank% \
- THEN \
- GOTO 4.0 \
- ELSE \
- PreviousLineWasBlank% = -1: \
- GOTO 7.0 \
- ELSE \
- PreviousLineWasBlank% = 0
-
-
- \Change a Soft Hyphen Occurrring at End of Line into Hard Hyphen:
- 9.0 IF MATCH (RIGHT$ (Buffer$, 1), SoftHyphen$, 1) <> 0 THEN \
- Buffer$ = LEFT$ (Buffer$, LEN (Buffer$) -1) + "-"
-
-
- \Strip High Order Bits:
- FOR Ptr% = 1 TO LEN (Buffer$)
- Char% = ASC (MID$ (Buffer$, Ptr%, 1))
- IF Char% > 127 THEN Buffer$ = LEFT$ (Buffer$, Ptr%-1) + \
- CHR$ (Char% - 128) + MID$ (Buffer$, Ptr%+1, 255)
- NEXT Ptr%
-
-
- \Delete All Control Characters Except CR, LF and Tab:
- Ptr% = 0
- 6.0 Ptr% = Ptr% + 1
- 6.1 IF Ptr% > LEN (Buffer$) THEN GOTO 7.0
- Char% = ASC (MID$ (Buffer$, Ptr%, 1))
- IF Char% < 32 AND Char% <> 9 AND Char% <> 10 AND Char% <> 13 \
- THEN \
- Buffer$ = LEFT$ (Buffer$, Ptr%-1) + MID$ (Buffer$, Ptr%+1, 255): \
- GOTO 6.1 \
- ELSE \
- GOTO 6.0
-
-
- \Print Formatted Line to Output File
- 7.0 IF HardCopy% \
- THEN \
- PRINT Buffer$ \
- ELSE \
- PRINT USING "&"; #2; Buffer$
-
-
- \Go to Top of Loop:
- GOTO 4.0
-
-
- \End Routine:
- 8.0 IF NOT HardCopy% THEN CLOSE 2
- CLOSE 1
- END