home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / p / wscon10.lbr / WSCON.BZS / WSCON.BAS
Encoding:
BASIC Source File  |  1993-10-25  |  8.0 KB  |  234 lines

  1. \******************************************************************************
  2. \*
  3. \* WSCON.BAS                   CBASIC (CB-80)            (C) David Chazin 10/85
  4. \* Last update: 10/11/85 ver 1.0                       Roosevelt, NJ 08555-0364
  5. \*
  6. \*       The main purpose of this program is to read in a WordStar document
  7. \*    from a disk file and write straight printable ASCII to another disk
  8. \*    file or the printer at the user's choice.  The original text file is
  9. \*    not altered in any way.  If an output file which already exists is
  10. \*    specified, user is given the option to overwrite or append to the file.
  11. \*
  12. \*       WSCON can be invoked from a command line.  If just WSCON in entered,
  13. \*    the user is presented with helpful information and is prompted for the
  14. \*    command line.
  15. \*
  16. \*       There are other fine programs already available which do
  17. \*    approximately the same job.  I undertook to write this one so I would
  18. \*    have a program which properly handled the "soft" hyphen and one which
  19. \*    didn't print a bunch of blank lines at the end of each page when
  20. \*    printing to a disk file.
  21. \*
  22. \*       When set to give hyphen help, WordStar will insert a "soft" or
  23. \*    conditional hyphen in the middle of a long word at the end of a line.
  24. \*    If the paragraph in which that word occurs is subsequently reformatted,
  25. \*    that word may not remain at the end of the line.  The "soft" hyphen
  26. \*    will, therefore, wind up in the middle of the line.  Then, when the
  27. \*    other  de-WordStar-izers  that I've seen handle this situation, we
  28. \*    either wind up with a hyphen somewhere in the middle of a line where it
  29. \*    does not belong, or without a hyphen at the end of the line where is does
  30. \*    belong.  WSCON deletes all "soft" hyphens not occurring at the end of a
  31. \*    line.
  32. \*
  33. \*       The other special need addressed by WSCON concerns page formatting,
  34. \*    specifically the numerous blank lines sometimes printed to get from
  35. \*    one page to the next.  As editor and publisher of the newsletter/journal
  36. \*    of the Kaypro Users Group of New Jersey, I regularly have need to change
  37. \*    an article from a WordStar document intended for printing into a
  38. \*    straight ASCII file appropriate for viewing on a CRT.  Accordingly,
  39. \*    WSCON will not print more than one blank line in a row to a disk file,
  40. \*    thereby negating the effects of this page formatting.
  41. \*
  42. \*       WSCON also deletes all control characters (except CR, LF and Tab),
  43. \*    strips any set high-order bits, truncates spaces and tabs occurring
  44. \*    at the end of a line, ignores lines beginning with a period, and
  45. \*    changes ^O's into spaces.
  46. \*
  47. \**************************** GLOBAL DECLARATIONS *****************************
  48. \*
  49.     STRING  Cmd$, InputFile$, OutputFile$, Bell$, Response$, Dummy$, Buffer$,    \
  50.         Truncate$, SoftHyphen$
  51.  
  52.     INTEGER Ptr%, Char%, PreviousLineWasBlank%, HardCopy%, L%
  53. \*
  54. \******************** INITIALIZATION OF GLOBAL VARIABLES **********************
  55. \*
  56.     Bell$ = CHR$(7)
  57.     Truncate$ = CHR$(9) + CHR$(32) + CHR$ (160)        rem tab and space
  58.     SoftHyphen$ = CHR$(30) + CHR$(31)
  59.     HardCopy% = 0
  60. \*
  61. \******************************* MAIN PROGRAM *********************************
  62. \*
  63. \Error Handling:
  64.     ON ERROR GOTO 0.0
  65.     GOTO 1.3
  66.     0.0 PRINT Bell$; "Error "; ERR; " at line "; ERRL
  67.     STOP
  68.  
  69.  
  70. \Get Command Tail:
  71.     1.3 IF MATCH (LEFT$(COMMAND$,1), "?*/", 1) > 0 OR LEN (COMMAND$) = 0    \
  72.       THEN                                    \
  73.         GOTO 1.0                                \
  74.       ELSE                                    \
  75.         Cmd$ = COMMAND$:                            \
  76.         GOTO 2.0
  77.     1.0 PRINT "WSCON ver 1.0    (c) 1985 David Chazin, Roosevelt, NJ 08555-0364":\
  78.     PRINT "    De-WordStar-izes  a  text  file.    If you enter LST: as"   :\
  79.     PRINT "    the OutputFile.Typ, then output goes to printer.  Other-"   :\ 
  80.     PRINT "    wise, output goes to the specified disk file.": GOTO 1.1
  81.     1.2 PRINT Bell$; "What the heck is "; InputFile$; "?"
  82.     1.1 PRINT
  83.     PRINT "   Syntax:  WSCON InputFile.Typ, OutputFile.Typ"
  84.     PRINT
  85.     PRINT "   Enter command line or press <CR> to quit:"
  86.     PRINT
  87.     PRINT "            WSCON";
  88.     INPUT ""; LINE Cmd$
  89.     IF Cmd$ = ""                                \
  90.       THEN                                    \
  91.         STOP                                \
  92.       ELSE                                    \
  93.         Cmd$ = UCASE$ (Cmd$)
  94.  
  95.  
  96. \Parse Command Tail:
  97.     2.0 Ptr% = MATCH (" ", Cmd$, 1)            rem remove all spaces
  98.     IF Ptr% > 0 THEN                            \
  99.         Cmd$ = MID$ (Cmd$, 1, Ptr%-1) + MID$ (Cmd$, Ptr%+1, 255):        \
  100.         GOTO 2.0
  101.     Ptr% = MATCH (",", Cmd$, 1)            rem get file names
  102.     IF Ptr% = 0 THEN                            \
  103.         PRINT Bell$; "Invalid command line":                \
  104.         GOTO 1.1
  105.         InputFile$  = MID$ (Cmd$, 1, Ptr%-1)
  106.         IF SIZE (InputFile$) = 0 THEN                        \
  107.         GOTO 1.2
  108.         OutputFile$ = MID$ (Cmd$, Ptr%+1, 255)
  109.     IF OutputFile$ = "LST:" THEN                        \
  110.         HardCopy% = -1:                            \
  111.         GOTO 3.3
  112.     IF SIZE (OutputFile$) <> 0 THEN                        \
  113.         PRINT Bell$; OutputFile$; " already exists:";:            \
  114.         PRINT "   Q = Quit   O = Overwrite   A = Append  ";:        \
  115.         Response$ = UCASE$ (CHR$ (CONCHAR%)): PRINT:            \
  116.         ON MATCH (Response$, "QOA", 1) GOTO 1.1, 3.0, 3.1
  117.  
  118.  
  119. \Open Files:
  120.     3.0 CREATE OutputFile$ AS 2: GOTO 3.3    rem overwrite
  121.     3.1 OPEN   OutputFile$ AS 2            rem append
  122.     IF END #2 THEN 3.3
  123.     3.2 READ #2; LINE Dummy$: GOTO 3.2
  124.     3.3 IF END #1 THEN 1.2
  125.     OPEN   InputFile$  AS 1
  126.  
  127.  
  128. \Main Loop:
  129.  
  130.  
  131.     \Initialize Main Loop:
  132.     IF END #1 THEN 8.0
  133.     IF HardCopy% THEN LPRINTER
  134.     PreviousLineWasBlank% = 0
  135.  
  136.  
  137.     \Read Line from Input File:
  138.     4.0 READ #1; LINE Buffer$
  139.  
  140.  
  141.     \Ignore Lines Beginning with Dot Commands:
  142.     IF LEFT$ (Buffer$, 1) <> "." THEN GOTO 12.0
  143.     Ptr% = MATCH (CHR$(13) + CHR$(138), Buffer$, 1)
  144.     IF Ptr% = 0 THEN GOTO 4.0
  145.     Buffer$ = MID$ (Buffer$, Ptr% + 2, 255)
  146.  
  147.  
  148.     \Remove CR with bit 7 set, if present:
  149.    12.0 IF RIGHT$ (Buffer$, 1) = CHR$ (141) THEN                \
  150.         Buffer$ = LEFT$ (Buffer$, LEN (Buffer$) - 1)
  151.  
  152.  
  153.     \Change ^O's into spaces:
  154.    11.0 Ptr% = MATCH (CHR$(15), Buffer$, 1)
  155.     IF Ptr% > 0 THEN                            \
  156.         Buffer$ = LEFT$ (Buffer$, Ptr%-1) + " " + MID$ (Buffer$, Ptr%+1, 255):\
  157.         GOTO 11.0
  158.  
  159.  
  160.     \Truncate Trailing Blanks and Tabs:
  161.     Ptr% = LEN (Buffer$)
  162.     IF Ptr% = 0 THEN GOTO 10.0
  163.     5.0 IF MATCH (MID$ (Buffer$, Ptr%, 1), Truncate$, 1) <> 0 THEN        \
  164.         Ptr% = Ptr% - 1:                            \
  165.         IF Ptr% > 0 THEN GOTO 5.0
  166.     Buffer$ = LEFT$ (Buffer$, Ptr%)
  167.  
  168.  
  169.     \Treat a Line Containing Only Control Characters as a Blank Line:
  170.         L% = LEN (Buffer$)
  171.     FOR Ptr% = 1 TO L%
  172.         IF MID$ (Buffer$, Ptr%, 1) > CHR$(31) THEN Ptr% = L% + 5
  173.     NEXT Ptr%
  174.     IF Ptr% = L% + 1 THEN Buffer$ = ""
  175.  
  176.  
  177.     \Do Not Print 2 Blank Lines in a Row to File:
  178.    10.0 IF HardCopy% THEN GOTO 9.0
  179.     Ptr% = LEN (Buffer$)
  180.     IF Ptr% = 0                                \
  181.       THEN                                    \
  182.         IF PreviousLineWasBlank%                        \
  183.           THEN                                \
  184.         GOTO 4.0                            \
  185.           ELSE                                \
  186.         PreviousLineWasBlank% = -1:                    \
  187.         GOTO 7.0                            \
  188.       ELSE                                    \
  189.         PreviousLineWasBlank% = 0
  190.  
  191.  
  192.     \Change a Soft Hyphen Occurrring at End of Line into Hard Hyphen:
  193.     9.0 IF MATCH (RIGHT$ (Buffer$, 1), SoftHyphen$, 1) <> 0 THEN        \
  194.         Buffer$ = LEFT$ (Buffer$, LEN (Buffer$) -1) + "-"
  195.  
  196.  
  197.     \Strip High Order Bits:
  198.     FOR Ptr% = 1 TO LEN (Buffer$)
  199.         Char% = ASC (MID$ (Buffer$, Ptr%, 1))
  200.         IF Char% > 127 THEN Buffer$ = LEFT$ (Buffer$, Ptr%-1) +        \
  201.         CHR$ (Char% - 128) + MID$ (Buffer$, Ptr%+1, 255)
  202.     NEXT Ptr%
  203.  
  204.  
  205.     \Delete All Control Characters Except CR, LF and Tab:
  206.     Ptr% = 0
  207.     6.0 Ptr% = Ptr% + 1
  208.     6.1 IF Ptr% > LEN (Buffer$) THEN GOTO 7.0
  209.     Char% = ASC (MID$ (Buffer$, Ptr%, 1))
  210.     IF Char% < 32 AND Char% <> 9 AND Char% <> 10 AND Char% <> 13        \
  211.       THEN                                    \
  212.         Buffer$ = LEFT$ (Buffer$, Ptr%-1) + MID$ (Buffer$, Ptr%+1, 255):    \
  213.         GOTO 6.1                                \
  214.       ELSE                                    \
  215.         GOTO 6.0        
  216.  
  217.  
  218.     \Print Formatted Line to Output File
  219.     7.0 IF HardCopy%                                \
  220.       THEN                                    \
  221.         PRINT Buffer$                            \
  222.       ELSE                                    \
  223.         PRINT USING "&"; #2; Buffer$
  224.  
  225.  
  226.     \Go to Top of Loop:
  227.     GOTO 4.0
  228.  
  229.  
  230. \End Routine:
  231. 8.0 IF NOT HardCopy% THEN CLOSE 2
  232.     CLOSE 1
  233.     END
  234.