home *** CD-ROM | disk | FTP | other *** search
/ Sauce 'n' Code 1 / sauce-n-code-01.adf / ASCII_Source / De-Coloniser.asc < prev    next >
Text File  |  1995-05-07  |  5KB  |  278 lines

  1. ' *******************************************
  2. ' *** AMOS Professional De-Coloniser V1.3 ***
  3. ' ***          By John.A.Kinsella         ***
  4. ' *******************************************
  5.  
  6. ' *** This program seperates multi-statement lines into single statement 
  7. '     lines, as well as removing REMs, and also converts IF...THEN 
  8. '     commands into IF...END IF commands.  
  9.  
  10. Set Accessory 
  11.  
  12. INIT_SCREEN
  13.  
  14. ' *** Make sure we are an accessory
  15.  
  16. If Prg Under<>1
  17.    R=Dialog Box(AL$,2,"This program only work as an accessory!")
  18.    MN_QUIT
  19. End If 
  20.  
  21. ' *** Do buffer check
  22.  
  23. Ask Editor Equ("AEdAsk_Free")
  24. If Param<5000
  25.    R=Dialog Box(AL$,2,"Please increse program buffer to continue (Try 20k Extra)")
  26.    MN_QUIT
  27. End If 
  28.  
  29. ' *** Ask user to continue 
  30.  
  31. R=Dialog Box(AL$,2,"De-Colonise the current program, please confirm.")
  32. If R=1
  33.    MN_QUIT
  34. End If 
  35.  
  36. ' *** Question to remove REMs  
  37.  
  38. NOREM=Dialog Box(AL$,2,"Remove REM statements from program.")
  39.  
  40. ' *** Open all procedures  
  41.  
  42. Call Editor Equ("AEd_UnfoldAll")
  43.  
  44. ' *** Ask number of lines
  45.  
  46. Ask Editor Equ("AEdAsk_NumberOfLines")
  47. NLINES=Param
  48.  
  49. ' *** Goto top of text 
  50.  
  51. Call Editor Equ("AEd_TopOfText")
  52.  
  53. ' *** De-Colonise program  
  54.  
  55. R=Dialog Box(AL$,0,"De-Colonising program (ESC Quits) ["+Str$(NLINES)+" Lines ]")
  56.  
  57. Set Input 10,-1
  58. Open Out 2,"RAM:TEMP.ASC"
  59.  
  60. For N=1 To NLINES
  61.    
  62.    If Inkey$=Chr$(27)
  63.       E$="De-Colonisation aborted."
  64.       Exit 
  65.    End If 
  66.    
  67.    Ask Editor Equ("AEdAsk_CurrentLine"),N
  68.    LINE$=Param$
  69.    
  70.    L$=LINE$
  71.    Gosub NOCOLON
  72.    
  73.    Call Editor Equ("AEd_Down")
  74.    
  75. Next N
  76.  
  77. If E$<>""
  78.    R=Dialog Box(AL$,1,E$)
  79.    MN_QUIT
  80. End If 
  81.  
  82. Close 
  83.  
  84. ' *** Erase previous program & merge De-Colonised one. 
  85.  
  86. R=Dialog Box(AL$,0,"Merging De-Colonised program, please wait...")
  87.  
  88. Call Editor Equ("AEd_HighlightAll")
  89. Call Editor Equ("AEd_BlocCut")
  90. Call Editor Equ("AEd_Forget")
  91. Call Editor Equ("AEd_MergeAscii"),0,"RAM:TEMP.ASC"
  92.  
  93. ' *** Print message. 
  94.  
  95. R=Dialog Box(AL$,1,"Now Re-Tokenise the program...")
  96.  
  97. ' *** Quit !!! 
  98.  
  99. MN_QUIT
  100.  
  101. Procedure INIT_SCREEN
  102.    
  103.    Global AL$
  104.    Restore ALT
  105.    
  106.    Repeat 
  107.       Read A$
  108.       AL$=AL$+A$
  109.    Until A$=""
  110.    
  111.    Resource Screen Open 0,640,40,0
  112.    Curs Off 
  113.    Flash Off 
  114.    Cls 0
  115.    Screen Display 0,,80,,
  116.    Wait Vbl 
  117.    
  118.    Paper 0
  119.    Pen 1
  120.    Pop Proc
  121.    
  122.    ' *** QUICK RUN DIALOG BOXES 
  123.    
  124.    ALT:
  125.    Data " "
  126.    Data "SIze   SW,SH;"
  127.    Data "BAse   SWidth SX -2/,SHeight SY- 2/;"
  128.    Data "IF     0VA 0=;"
  129.    Data "["
  130.    Data "BOx    0,0,1,SX,SY;"
  131.    Data "POut   1VACX,16,1VA,0,7;"
  132.    Data "BU 0,0,0,SX,SY,0,0,0;[][SM;]"
  133.    Data "]"
  134.    Data "IF     0VA 1=;"
  135.    Data "["
  136.    Data "BOx    0,0,1,SX,SY;"
  137.    Data "POut   1VACX,8,1VA,0,7;"
  138.    Data "BU 1,SX112-,SY16-,96,16,0,0,1;[LI 0,0,41BP3*+,SX;PR 4MECXBP+,1,4ME,7;][BR0;BQ;]"
  139.    Data "KY 27,0;"
  140.    Data "BU 0,0,0,SX,SY,0,0,0;[][SM;]"
  141.    Data "RUn    0,3;"
  142.    Data "]"
  143.    Data "IF     0VA 2=;"
  144.    Data "["
  145.    Data "BOx    0,0,1,SX,SY;"
  146.    Data "POut   1VACX,8,1VA,0,7;"
  147.    Data "BU 1,16,SY16-,96,16,0,0,1;[LI 0,0,41BP3*+,SX;PR 4MECXBP+,1,4ME,7;][BR0;BQ;]"
  148.    Data "KY 13,0;"
  149.    Data "BU 2,SX112-,SY16-,96,16,0,0,1;[LI 0,0,41BP3*+,SX;PR 3MECXBP+,1,3ME,7;][BR0;BQ;]"
  150.    Data "KY 27,0;"
  151.    Data "BU 0,0,0,SX,SY,0,0,0;[][SM;]"
  152.    Data "RUn    0,3;"
  153.    Data "]"
  154.    Data "EXit;"
  155.    Data ""
  156.    
  157. End Proc
  158.  
  159. Procedure MN_QUIT
  160.    
  161.    Trap Dialog Close 
  162.    Trap Screen Close 0
  163.    
  164.    Erase All 
  165.    Close 
  166.    
  167.    Trap Kill "RAM:TEMP.ASC"
  168.    
  169.    End 
  170.    
  171. End Proc
  172.  
  173. NOCOLON:
  174.  
  175. ' *** Remove spaces  
  176.  
  177. TL=1
  178. TM$=" "
  179.  
  180. While TM$=" "
  181.    TM$=Mid$(L$,TL,1)
  182.    Inc TL
  183. Wend 
  184.  
  185. Dec TL
  186.  
  187. L$=Mid$(L$,TL,Len(L$)-TL+1)
  188.  
  189. ' *** This section seperates each command & converts IF...THENs  
  190. '     into IF...END IFs, and also removes REMs if required.  
  191.  
  192. If(((Left$(L$,3)<>"Rem") and(Left$(L$,1)<>"'") and(NOREM=2)) or(NOREM=1))
  193.    
  194.    QU=0
  195.    M$=""
  196.    P=1
  197.    SM=0
  198.    
  199.    While P<=Len(L$)
  200.       
  201.       If((Mid$(L$,P,2)=" :") or(Mid$(L$,P,4)="Then") or(Mid$(L$,P,4)="Else") or(Mid$(L$,P,7)="Else If")) and QU=0
  202.          
  203.          If Mid$(L$,P,4)="Then"
  204.             TH=1
  205.             P=P+2
  206.          End If 
  207.          
  208.          If Mid$(L$,P,7)="Else If"
  209.             Print #2,"Else ";
  210.             SM=1
  211.             P=P+2
  212.          End If 
  213.          
  214.          If Mid$(L$,P,4)="Else"
  215.             EL=1
  216.             P=P+2
  217.          End If 
  218.          
  219.          If SM=1
  220.             Print #2,M$;
  221.             SM=0
  222.          Else 
  223.             Print #2,M$
  224.          End If 
  225.          
  226.          Inc P
  227.          M$=""
  228.          
  229.          If EL=1
  230.             Print #2,"Else"
  231.             EL=0
  232.          End If 
  233.          
  234.       Else 
  235.          
  236.          If QU=0
  237.             
  238.             If Mid$(L$,P,3)="Rem"
  239.                M$=M$+Mid$(L$,P)
  240.                P=Len(L$)
  241.                Goto NXT
  242.             End If 
  243.             
  244.          End If 
  245.          
  246.          If Mid$(L$,P,1)=Chr$(34)
  247.             QU=1-QU
  248.          End If 
  249.          
  250.          M$=M$+Mid$(L$,P,1)
  251.          
  252.       End If 
  253.       
  254.       Inc P
  255.       
  256.    Wend 
  257.    
  258.    NXT:
  259.    
  260.    If M$<>""
  261.       Print #2,M$
  262.    End If 
  263.    
  264. End If 
  265.  
  266. If TH=1
  267.    Print #2,"End If"
  268.    TH=0
  269. End If 
  270.  
  271. Return 
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.