 GW2QB 0.65 - GWBasic to QBasic Source Code converter
 (C)2007 PeatSoft (10-01-2007)
 www.xs4all.nl/~hwiegman/qbasic.html
 gammon@xs4all.nl

 ----------------------------------------------------------------------------

 REQUIREMENTS
   - DOS
   - GWBasic ASCII Source Code files

 ----------------------------------------------------------------------------

 GW2QB converts GWBasic ASCII source code files into QBasic files.
 A record of modifications is saved in GW2QB.LOG
 Put GW2QB in a directory in your path, eg. C:\WINDOWS\COMMAND.
 
 Commandline parameters:
   GW2QB basfile [outputfile] [options]

   basfile     - valid GWBasic ASCII source code file
   outputfile  - file in which the output is saved. If outputfile is not
                 given, the output will be saved in basfile.QB
   OPTIONS:
   /s          - do not split lines with multiple statements
   /t          - do not make general IF THEN...END IF blocks
   /n          - do not split lines containing IF...NEXT
   /g          - do not make IF THEN...END IF blocks from lines starting
                 with IF...THEN GOTO
   /l          - do not make DO...LOOP blocks
   /d          - do not move DEF FN statements
   /m          - do not move DEFtype, DIM and OPTION BASE statements
   /e          - do not place line numbers on empty lines
   /b          - move blocks to replace GOTO statements
   /ix         - set number of spaces for indentation (x=0-8,n)
                 x=n keeps original indentation from basfile

   Options must be separated by a space: GW2QB test.bas /s /t

 ----------------------------------------------------------------------------

 WHAT DOES GW2QB?

   - Splits lines with multiple statements:

           A = 1: B = 2
             A = 1
             B = 2

           A = 1: B = 2 'initialize
             A = 1
             B = 2 'initialize

       You can disable this with the commandline option '/s'.

   - Makes IF THEN ... END IF blocks from IF statements:

           IF A = 1 THEN B = 2
             IF A =1 THEN
                 B = 2
             END IF

           IF A = 1 THEN B = 2 ELSE B = 3
             IF A =1 THEN
                 B = 2
             ELSE
                 B = 3
             END IF

       You can disable this with the commandline option '/t'.

   - Splits lines beginning with IF and containing a NEXT statement:

           IF A <> 1 THEN B = 2: NEXT I
             IF A = 1 THEN EXIT FOR
             B = 2: NEXT I

       You can disable this with the commandline option '/n'.
       Lines with multiple IF or ELSE statements are ignored.
       Supported are:
         a. IF X z Y THEN
         b. IF X z Y AND/OR X z Y THEN
       where X and Y are expressions
             z is a relational operator (=, <>, <, >, <=, >=)

   - Makes IF THEN ... END IF blocks from lines with IF THEN ... GOTO:

               IF A > 1 THEN GOTO 200
               B = 2
           200 GOSUB 300

               IF A <= 1 THEN
                   B = 2
               END IF
               GOSUB 300

       You can disable this with the commandline option '/g'.
       Supported are:
         a. IF X z Y THEN GOTO linenumber
         b. IF X z Y AND/OR X z Y THEN GOTO linenumber
       where X and Y are expressions
             z is a relational operator (=, <>, <, >, <=, >=)

   - Makes DO ... LOOP blocks from lines like:

               200 A$ = INKEY$
                   IF A$ = "" THEN GOTO 200

                   DO
                       A$ = INKEY$
                   LOOP WHILE A$ = ""

               200 A$ = INKEY$
                   GOTO 200

                   DO
                       A$ = INKEY$
                   LOOP

       You can disable this with the commandline option '/l'.

   - Moves blocks to replace GOTO statements:

               200 GOTO 300
               250 A(0) = 1: RETURN
               300 DIM A(10)
                   GOSUB 250
                   END
               
               200 DIM A(10)
                   GOSUB 250
                   END
               250 A(0) = 1: RETURN

       You can enable this with the commandline option '/b'.
       NOTE: the code can become difficult to survey.

   - Removes unused line numbers.
   - Checks for duplicate line numbers.
   - Places remaining line numbers on empty lines.
     Places empty lines before line numbers when they are the start of a
     GOSUB routine.

       You can disable this with the commandline option '/e'.

   - Checks line numbers in GOTO, GOSUB, RETURN, RESTORE, RESUME and RUN statements.
   - Indents lines between FOR ... NEXT, WHILE ... WEND, IF THEN ... END IF
     and DO ... LOOP statements.

       Set this with the commandline option '/ix' where x is a number between
       0 and 8, or x=n which keeps the original indentation from the input
       file. Default is x=4.
       Note: tab characters in the input file are replaced by a single space.

   - Moves COMMON statements at the top of the code.
     If there are no DIM statements, a new DIM statement is inserted before
     the COMMON statement.
   - Moves DEF FN statements at the top of the code when a DEF FN function is
     called before it is defined.

       You can disable this with the commandline option '/d'.

   - Moves DEFtype statements at the top of the code when there is only one
     DEFtype statement.
     Moves DIM statements at the top of the code when there are less than two
     DEFtype statements and the DIM dimensions are indexed by numbers, not by
     variables and if the code does not contain REDIM or ERASE statements.
     Moves OPTION BASE statements at the top of the code.

       You can disable this with the commandline option '/m'.

   - Remarks rubbish:
       statements beginning with illegal characters eg. '('
   - Remarks keywords used in other languages such as PLOT
   - Remarks abandoned keywords: NEW, SAVE, LOAD filespec, LIST, DEF USR
   - Remarks ELSE statements if they are not preceded by an IF keyword
   - Changes LOAD filespec,R to CHAIN filespec
   - Changes invalid TIME$ statements: TIME$="x" -> TIME$="0x:00"
   - Changes various typo errors: RIGHTS, SPC79)
   - Renames illegal variable names: ACCESS, BASE, CONST, EXIT, IS, etc.
   - Inserts spaces in invalid FIELD statements:
       FIELD#1,2asB$ -> FIELD#1,2 as B$
   - Changes the following commands in PLAY statements:
       Xstringvariable into "X"+VARPTR$(stringvariable)
       command=variable into "command="+VARPTR$(variable)
   - Changes CHAIN [MERGE] "cfile" [,[linenum][,ALL][,DELETE range]] to
       CHAIN "cfile"

       QBasic does not support the MERGE, ALL, DELETE and linenum commands.

 ----------------------------------------------------------------------------

 WHAT DOES GW2QB NOT?

   - checking for:
       incorrect code such as: CC = CCAND 15
                               CC = "string"
                               C$ = "123";
       missing : between keywords
   - convert CALL statements into CALL ABSOLUTE 
   - move DIM statements at the top of the code when they are indexed by
     variables
   
     NOTE: a 100% correct conversion is nearly impossible, so you'll have
           to modify the code yourself if QBasic reports an error.

 ----------------------------------------------------------------------------

 WHAT IS NEW?
   0.01 (06-07-2001) - Initial release.
   0.02 (06-10-2001) - Fixed some bugs.
   0.03 (06-17-2001) - Fixed bug in removing line numbers' routine.
   0.04 (06-29-2001) - Bigger files can be converted.
   0.05 (06-30-2001) - Fixed some bugs.
   0.06 (07-31-2001) - Added beautifying code and fixed some bugs.
   0.07 (08-04-2001) - Added support for RESUME statements.
                       Added splitting lines beginning with IF and
                       containing a NEXT statement.
                       Added remarking of NEW statements.
                       Fixed some bugs.
   0.08 (08-06-2001) - Fixed bug in ON ERROR GOTO handling.
                       Fixed bug in splitting lines' routine.
   0.09 (08-25-2001) - Added support for files with spaces before line
                       numbers.
                     - Added support for GO TO command.
                     - Fixed bug in counting removed line numbers.
   0.10 (10-03-2001) - Fixed bug in ON ... GOTO handling.
   0.11 (10-05-2001) - Fixed bug in GOTO handling.
   0.12 (10-12-2001) - Added renaming of illegal variable names.
                       Fixed bug in NEW handling.
   0.13 (10-18-2001) - Improved splitting lines' routine.
                       Added remarking of SAVE statements.
                       Fixed bug in ON KEY() GOSUB handling.
   0.14 (10-25-2001) - Added remarking of LOAD filespec statements.
                       Added changing of LOAD filespec,R to CHAIN filespec
                       Fixed bug in ON KEY() GOSUB handling.
   0.15 (11-02-2001) - Added removal of leading spaces if no line numbers
                       are present.
                       Added splitting lines with multiple statements.
   0.16 (11-05-2001) - Fixed bug in invalid keywords handling.
   0.17 (11-11-2001) - Fixed bug in CHAIN handling.
                       Fixed bug in splitting lines' routine.
   0.18 (11-19-2001) - Added moving DEF FN statements at the top of the code
                       if necessary.
                       Added making of IF THEN ... END IF blocks.
                       Improved and fixed splitting lines' routine.
   0.19 (11-20-2001) - Fixed bug in GOTO handling.
   0.20 (11-23-2001) - Fixed bug in GOTO handling.
   0.21 (11-30-2001) - Fixed bug in CHAIN handling.
                       Improved illegal variables' routine.
   0.22 (12-05-2001) - Added remarking of ELSE statements if they are not
                       preceded by an IF keyword.
                       Fixed bugs in invalid keywords handling.
   0.23 (12-11-2001) - Fixed bugs in DEF FN routine and added commandline
                       option to disable moving of DEF FN statements.
   0.24 (12-23-2001) - Fixed bug in GOTO handling.
                       Fixed bugs in moving statements.
                       Added moving of DEFtype, DIM and OPTION BASE
                       statements.
   0.25 (12-27-2001) - Fixed bug in GOTO handling.
                       Added making of DO ... LOOP blocks.
   0.26 (01-08-2002) - Improved DIM and DEFtype handling.
                       Improved illegal statements' routine.
                       Added changing of invalid TIME$ statements.
                       Added indentation of lines between FOR...NEXT and
                       WHILE...WEND statements.
                       Removed /V (Version) switch.
   0.27 (01-14-2002) - Added support for files that have no spaces after
                       linenumber 0 and for files starting with empty lines.
                       Improved illegal statements' routine.
                       Added making of general IF THEN ... END IF blocks.
   0.28 (01-17-2002) - Fixed bug in creating IF THEN ... END IF blocks.
                       Improved splitting lines' routine.
   0.29 (01-20-2002) - Added support for files with tabs.
                       Fixed bug in GOTO handling.
   0.30 (01-30-2002) - Added placing of line numbers on empty lines.
                       Improved illegal variables' routine.
                       Added placing of an empty line before a line number
                       when that line number is the start of a GOSUB routine.
   0.31 (01-31-2002) - Fixed bugs in ON...GOTO/GOSUB handling.
   0.32 (02-06-2002) - Improved illegal statements routine and GOTO/GOSUB
                       handling.
                       Fixed and improved splitting lines' routine.
   0.33 (02-09-2002) - Fixed CHAIN handling.
                       Improved making of DO...LOOP blocks.
                       Added indentation of lines between DO...LOOP
                       statements.
                       Fixed bug in making of IF THEN...END IF blocks.
   0.34 (02-18-2002) - Improved illegal variables' routine.
                       Fixed and improved GOTO/GOSUB handling.
                       Fixed bug in CHAIN handling.
   0.35 (03-02-2002) - Added moving of blocks to replace GOTO statements.
                       Fixed and improved GOTO/GOSUB handling.
   0.36 (03-06-2002) - Improved moving blocks' routine.
                       Fixed and improved illegal statements handling.
   0.37 (03-09-2002) - Fixed indentation routine.
                       Improved illegal variables' routine.
                       Fixed and improved moving blocks' routine.
   0.38 (03-16-2002) - Improved moving DEF FN statements' routine.
                       Improved illegal statements routine.
                       Fixed CHAIN and ELSE handling.
   0.39 (03-31-2002) - Added changing of X commands in PLAY statements.
                       Improved illegal variables' routine.
                       Fixed DIM handling.
   0.40 (04-08-2002) - Improved TIME$ handling.
                       Improved illegal variables' routine.
                       Fixed ON ERROR GOTO 0 handling.
   0.41 (04-21-2002) - Improved illegal variables' routine.
                       Improved moving blocks' routine.
                       Fixed splitting lines' routine.
   0.42 (04-29-2002) - Improved illegal variables' routine.
                       Improved illegal statements routine.
                       Improved indentation routine.
                       Fixed bug in moving blocks' routine.
   0.43 (05-02-2002) - Fixed moving blocks' routine.
   0.44 (05-06-2002) - Improved illegal variables' routine.
                       Fixed creating of IF THEN ... END IF blocks.
   0.45 (05-09-2002) - Fixed indentation routine.
                       Fixed splitting lines' routine.
   0.46 (05-26-2002) - Remarks at the end of a line with multiple statements
                       will not be split.
                       Improved making of DO...LOOP blocks.
                       Improved PLAY routine.
                       Fixed splitting lines' routine.
   0.47 (06-04-2002) - Fixed RESUME handling.
   0.48 (06-11-2002) - Fixed and improved relational operators' routine.
                       Improved illegal variables' routine.
   0.49 (06-21-2002) - Improved illegal variables' routine.
                       Removed ' character from GW2QB messages to avoid
                       confusing with the QBASIC meaning.
                       Fixed bug in linenumber 0 handling.
   0.50 (07-01-2002) - Fixed indentation' routine.
   0.51 (07-25-2002) - Improved illegal variables' routine.
                       Fixed IF...THEN handling.
   0.52 (08-26-2002) - Fixed error when handling large files.
                       Improved error handling.
                       Improved illegal statements' routine.
                       Improved illegal variables' routine.
                       Fixed LOAD handling.
   0.53 (09-24-2002) - Improved illegal variables' routine.
                       Fixed COMMON handling.
                       Fixed GOTO/GOSUB handling.
                       Fixed IF...THEN handling.
   0.54 (09-26-2002) - Fixed splitting lines' routine.
   0.55 (10-05-2002) - Improved illegal variables' routine.
                       Fixed IF...THEN handling.
   0.56 (10-28-2002) - Added linenumber handling of RUN statements.
                       Improved illegal variables' routine.
                       Fixed ON...ERROR handling.
   0.57 (11-03-2002) - Improved PLAY handling.
                       Fixed splitting' lines routine.
   0.58 (11-28-2002) - Improved illegal variables' routine.
                       Fixed IF...THEN handling.
   0.59 (01-18-2003) - Improved illegal variables' routine.
                       Fixed DO...LOOP handling.
   0.60 (09-21-2003) - Improved illegal variables' routine.
                       Fixed OPTION BASE handling.
                       Added insertion of spaces in invalid FIELD statements.
   0.61 (11-10-2003) - Improved illegal variables' routine.
                       Improved illegal statements' routine.
                       Added checking for duplicate line numbers.
   0.62 (12-29-2003) - Cosmetic changes.
                       Fixed handling of large files.
   0.63 (02-02-2004) - Improved DEF FN handling.
                       Fixed several bugs.
   0.64 (07-30-2006) - Improved moved lines routine.
                       Added placement of an empty line after RESUME
                       statements.
   0.65 (10-01-2007) - Fixed typo errors: RIGHTS, SPC
                       Improved COMMON handling.
                       Improved illegal variables' handling.

 ----------------------------------------------------------------------------

 BUG REPORTS
   If you have bug reports, comments, suggestions or questions
   please email me. Thanks.

   Email: gammon@xs4all.nl

 ----------------------------------------------------------------------------

 LEGAL
   
   You are using GW2QB at your own risk, no responsibility is taken for
   damages to your computer system.

   Feel free to distribute this program, as long as the files remain
   intact. You may not use it for personal or any other gain without my
   consent.

 ----------------------------------------------------------------------------
   Thanks for downloading. Have fun!
