home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progbas / qconvert.arj / QCONVERT.BAS next >
BASIC Source File  |  1991-11-19  |  4KB  |  142 lines

  1.      dim shared subnum(300):dim shared subname$(300)
  2. TOP:
  3.      com$=command$
  4.      length=len(com$)
  5.      max=(length/2)+1
  6.      dim arg$(max)
  7.      true=-1:false=0:i=1:num=0:inword=true
  8.      while i <= length
  9.           ch$=mid$(com$,i,1)
  10.           if ch$ <> " " then
  11.                if not inword then inword = true
  12.                arg$(num) = arg$(num) + ch$
  13.           elseif inword then
  14.                num =num+1
  15.                inword=false
  16.           end if
  17.           i = i+1
  18.      wend
  19.      y=1
  20.      if not arg$(0)="" then goto BEGINNING
  21. HELP:
  22.      print" "
  23.      print"QCONVERT converts QuickBASIC programs to BASIC.  (C) 1986 David A. Wesson"
  24.      print" "
  25.      print"Syntax: QCONVERT  [d:]filename  [d:]newfile "
  26.      print" where  filename = original file  [drive optional]      "
  27.      print"        newfile  = new file to be created  [drive optional]"
  28.      print"
  29.      print"        NOTE: The original file must be in ASCII.
  30.      print"        QuickBasic is a trademark owned by MicroSoft.
  31.      print"        Incompatabilities in commands are not handled.
  32.      system
  33. BEGINNING:
  34.      infile$=arg$(0)
  35.      on error goto NOFIND
  36.           open infile$ for input as #1
  37.      outfile$=arg$(1)
  38.           if outfile$="" then goto BADFILE
  39.           if outfile$=infile$ then goto BADFILE
  40.           open outfile$ for output as #2
  41. ROUTINE:
  42.      color 15:print"QCONVERT:";:color 7:print"QuickBASIC to BASIC converter"
  43.      print"Converting ";infile$;" to ";outfile$
  44.      print"Hit [Ctrl]+[Break] to terminate."
  45.      print"  Starting time: ";time$
  46.      print"  Program lines: "
  47.      print"Processing line: "
  48.     z=0
  49. CYCLE:
  50.      if eof(1) then goto REPLACENAMES
  51.     line input #1,l$
  52.      z=z+1
  53.     locate 5,17:print z
  54. SUBNAME:
  55.     if left$(l$,1)=chr$(39)_
  56.         or left$(l$,3)="REM"_
  57.         or left$(l$,3)="rem"_
  58.         or left$(l$,1)=chr$(9)_
  59.         or left$(l$,1)>chr$(122)_
  60.         or left$(l$,1)<chr$(65)_
  61.         or left$(l$,1)=chr$(32) then goto CYCLE
  62.     colonpos=instr(1,l$,chr$(58))
  63.                  s=s+1
  64.               subname$(s)=left$(l$,colonpos-1)
  65.               subnum(s)=z*10
  66.     goto CYCLE
  67. REPLACENAMES:
  68.      close #1
  69.      open infile$ for input as #1
  70.      z=0
  71. SEARCH:
  72.      if eof(1) then goto FINISH
  73.      line input #1,l$
  74.     z=z+1
  75.     locate 6,17:print z
  76.      if left$(l$,1)=chr$(39) or left$(l$,3)="REM"_
  77.          or left$(l$,3)="rem" then
  78.         goto DUMP
  79.      end if
  80.     n=0
  81. NEXTNAME:
  82.      for n = 1 to s
  83.          replace$=subname$(n)
  84.            new$=str$(subnum(n))
  85.     NEXTSEARCH:
  86.          lfpos=instr(1,l$,replace$)
  87.              if lfpos<1 then goto NEXTN
  88.              if lfpos=1 then l$=chr$(39)+l$:goto DUMP
  89.              if lfpos>1 and lfpos<7 then goto NEXTN
  90.              if mid$(l$,lfpos-5,4)="GOTO"_
  91.                  or mid$(l$,lfpos-5,4)="goto"_
  92.                  or mid$(l$,lfpos-6,5)="GOSUB"_
  93.                  or mid$(l$,lfpos-6,5)="gosub" then
  94.                  gosub SPLIT
  95.      n=0
  96.                  goto NEXTN
  97.              end if
  98. NEXTN:
  99.         next n
  100.      goto DUMP
  101. SPLIT:
  102.     lpart$=left$(l$,lfpos-2)
  103.     rpos=lfpos+len(replace$)-1
  104.     rpart$=right$(l$,len(l$)-rpos)
  105.     l$=lpart$+new$+rpart$
  106.     return
  107. DUMP:
  108.     l$=str$(z*10)+chr$(32)+l$
  109.     print #2,l$
  110.     goto SEARCH
  111. NOFIND:
  112.      print"ERROR: No file by that name found."
  113.      goto HELP
  114. BADFILE:
  115.      print"ERROR: Duplicate or missing filename."
  116.      goto HELP
  117. FINISH:
  118.      print "    Finish time: ";time$
  119.      close
  120.      print"Would you like a list of replaced labels"
  121.      print"sent to your printer? ( Y or N ) "
  122. IN:      w$=inkey$:if w$="" then goto IN:
  123.          if w$="y" or w$="Y" then goto PRINTOUT
  124.          if w$="n" or w$="N" then end else goto IN
  125. PRINTOUT:
  126.      print"Turn on your printer, please, and hit a key"
  127. WAITING:     w$=inkey$:if w$="" then goto WAITING
  128.      lprint"LINE","LABEL"
  129.      lprint""
  130.      for n = 1 to s
  131.         lprint subnum(n),subname$(n)
  132.      next n   
  133.      lprint""
  134.      lprint s;"labels found in ";z;" program lines"
  135.      end
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.