home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d9xx / d969 / ace.lha / ACE / ACE-2.0.lha / AIDE.lha / AIDE.b < prev    next >
Text File  |  1994-01-19  |  32KB  |  1,305 lines

  1. {*
  2. ** ACE Integrated Development Environment: AIDE.
  3. **
  4. ** Author: David J Benn
  5. **   Date: 23rd,24th,28th-31st December 1993,
  6. **       1st-3rd,5th,6th,8th,10th-12th,14th,15th,17th,19th January 1994
  7. *}
  8.  
  9. version$ = "$VER: AIDE 1.0 (19.01.94)"
  10.  
  11. DEFLNG a-z
  12.  
  13. {*
  14. ** Menu Constants (prefixes: c=command, m=menu, i=menu item)
  15. *}
  16.  
  17. '..basic values
  18. CONST TRUE    =-1&
  19. CONST FALSE    =0&
  20. CONST NULL    =0&
  21.  
  22. '..Object file types
  23. CONST ASM    =1
  24. CONST EXE    =2
  25.  
  26. '..Modes
  27. CONST cDisable    =0
  28. CONST cEnable     =1
  29. CONST cCheck    =2
  30.  
  31. '..Project Menu
  32. CONST mProject    =1
  33. CONST iNew    =1
  34. CONST iOpen    =2
  35. CONST iView    =3
  36. CONST iSep1.1    =4
  37. CONST iDelete    =5
  38. CONST iPrint    =6
  39. CONST iExecute    =7
  40. CONST iShell    =8
  41. CONST iSep1.2    =9
  42. CONST iAbout    =10
  43. CONST iQuit    =11
  44.  
  45. '..Program Menu
  46. CONST mProgram    =2
  47. CONST iSetSource=1
  48. CONST iEdit    =2
  49. CONST iSep2.1    =3
  50. CONST iRun    =4
  51. CONST iSep2.2    =5
  52. CONST iCompile    =6
  53. CONST iMake    =7
  54. CONST iBuild    =8
  55. CONST iSep2.3    =9
  56. CONST iViewAsm    =10
  57. CONST iViewPrep    =11
  58. CONST iShowErrs    =12
  59.  
  60. '..Compiler Menu
  61. CONST mCompiler    =3
  62. CONST iBreak    =1
  63. CONST iComments =2
  64. CONST iIcon    =3
  65. CONST iListLines=4
  66. CONST iOptimise =5
  67. CONST iWindow    =6
  68.  
  69. '..Linker
  70. CONST mLinker    =4
  71. CONST iAddModule=1
  72. CONST iRemModule=2
  73. CONST iRemAllMod=3
  74. CONST iSep4.1    =4
  75.  
  76. '..Help
  77. CONST mHelp    =5
  78. CONST iACEDoc    =1
  79. CONST iA68KDoc    =2
  80. CONST iBlinkDoc    =3
  81. CONST iSep5.1    =4
  82. CONST iACERef    =5
  83.  
  84. '..Other stuff
  85. CONST strSize    =80
  86. CONST maxModules=10
  87.  
  88.  
  89. {*
  90. ** Structure Definitions
  91. *}
  92.  
  93. STRUCT program_info
  94.   STRING   source_file SIZE strSize
  95.   STRING   source_dir  SIZE strSize
  96.   LONGINT  made
  97.   SHORTINT module_count
  98. END STRUCT
  99.  
  100. STRUCT config_info
  101.   STRING editor SIZE strSize
  102.   STRING viewer SIZE strSize
  103.   STRING tmpdir SIZE strSize
  104.   STRING docdir SIZE strSize
  105.   STRING bltdir SIZE strSize
  106.   STRING agddir SIZE strSize
  107. END STRUCT 
  108.  
  109. STRUCT options_info
  110.   LONGINT user_break
  111.   LONGINT asm_comments
  112.   LONGINT error_log
  113.   LONGINT create_icon
  114.   LONGINT list_lines
  115.   LONGINT optimise
  116.   LONGINT window_close
  117. END STRUCT
  118.  
  119. STRUCT DateStamp
  120.   LONGINT days
  121.   LONGINT mins
  122.   LONGINT ticks
  123. END STRUCT
  124.  
  125. STRUCT FileInfoBlock
  126.   longint fib_DiskKey
  127.   longint fib_DirEntryType
  128.   string  fib_FileName size 108
  129.   longint fib_Protection
  130.   longint fib_EntryType
  131.   longint fib_Size
  132.   longint fib_NumBlocks
  133.   string  fib_Date size 12
  134.   string  fib_Comment size 80
  135.   string  fib_Reserved size 36
  136. END STRUCT
  137.  
  138.  
  139. {*
  140. ** Global Variables
  141. *}
  142.  
  143. DECLARE STRUCT program_info prog
  144. DECLARE STRUCT config_info config
  145. DECLARE STRUCT options_info options
  146.  
  147. DIM module$(maxModules)
  148.  
  149. STRING default_command
  150.  
  151.  
  152. {*
  153. ** Subprogram declarations
  154. *}
  155.  
  156. SUB fexists(STRING fname)
  157.   OPEN "I",#255,fname
  158.   if HANDLE(255) then
  159.     fexists=TRUE
  160.   else
  161.     fexists=FALSE
  162.   end if
  163.   CLOSE #255
  164. END SUB
  165.  
  166. SUB get_file_datestamp(STRING fname,ADDRESS ds_addr)
  167. CONST   ACCESS_READ = -2&
  168. LONGINT mylock
  169. DECLARE STRUCT FileInfoBlock file_info
  170. DECLARE STRUCT DateStamp ds,Date
  171. DECLARE FUNCTION Lock&(filename$,accessmode&) LIBRARY
  172. DECLARE FUNCTION UnLock(filelock&) LIBRARY
  173. DECLARE FUNCTION Examine(filelock&,fib_ptr&) LIBRARY
  174.  
  175.   '..Return the datestamp of the file.
  176.   '..No checking beyond a test for NULL lock.
  177.  
  178.   ds = ds_addr
  179.   mylock = Lock(fname,ACCESS_READ) 
  180.  
  181.   if mylock <> NULL then
  182.     Examine(mylock,file_info)
  183.     Date = @file_info->fib_Date
  184.     ds->days  = Date->days
  185.     ds->mins  = Date->mins
  186.     ds->ticks = Date->ticks
  187.     UnLock(mylock)
  188.   end if
  189. END SUB
  190.  
  191. SUB SHORTINT datestamps_different(ADDRESS ds1_addr,ADDRESS ds2_addr)
  192. DECLARE STRUCT DateStamp ds1,ds2
  193.  
  194.   '..Return TRUE if the datestamps of 2 files 
  195.   '..are different.
  196.  
  197.   ds1 = ds1_addr
  198.   ds2 = ds2_addr
  199.  
  200.   '..If one file doesn't exist but the
  201.   '..other does, then the datestamps
  202.   '..are different.
  203.   IF (ds1 = NULL and ds2 <> NULL) or (ds1 <> NULL and ds2 = NULL) THEN 
  204.      datestamps_different = TRUE
  205.      EXIT SUB
  206.   END IF
  207.  
  208.   '..If neither file exists, then the
  209.   '..datestamps aren't different.
  210.   IF ds1 = NULL and ds2 = NULL THEN
  211.      datestamps_different = FALSE
  212.      EXIT SUB
  213.   END IF
  214.  
  215.   d1=ds1->days
  216.   d2=ds2->days    
  217.   m1=ds1->mins
  218.   m2=ds2->mins    
  219.   t1=ds1->ticks
  220.   t2=ds2->ticks    
  221.  
  222.   if (d1<>d2) or (m1<>m2) or (t1<>t2) then
  223.      datestamps_different=TRUE
  224.   else
  225.      datestamps_different=FALSE
  226.   end if
  227. END SUB
  228.  
  229. SUB SHORTINT older(ADDRESS ds1_addr,ADDRESS ds2_addr)
  230. DECLARE STRUCT DateStamp ds1,ds2
  231.  
  232.   '..Return TRUE if first datestamp is older than second.
  233.   ds1 = ds1_addr
  234.   ds2 = ds2_addr
  235.  
  236.   '..If first file doesn't exist it can't
  237.   '..be older than second.
  238.   IF ds1 = NULL THEN
  239.      older = FALSE
  240.      EXIT SUB
  241.   END IF
  242.  
  243.   '..If second file doesn't exist
  244.   '..but the the first file does, 
  245.   '..the first file must be older
  246.   '..than the second.
  247.   IF ds2 = NULL THEN 
  248.      older = TRUE
  249.      EXIT SUB
  250.   END IF
  251.   
  252.   d1=ds1->days
  253.   d2=ds2->days    
  254.   m1=ds1->mins
  255.   m2=ds2->mins    
  256.   t1=ds1->ticks
  257.   t2=ds2->ticks    
  258.  
  259.   IF (d1<d2) or (d1=d2 and m1<m2) or (d1=d2 and m1=m2 and t1<t2) THEN
  260.      older = TRUE
  261.   ELSE
  262.      older = FALSE
  263.   END IF  
  264. END SUB
  265.  
  266. SUB STRING quote(STRING x)
  267. '..enclose x in quotes
  268.   quote = CHR$(34)+x+CHR$(34)
  269. END SUB
  270.  
  271. {------------------------------------------------------}
  272.  
  273. SUB abort_prog(STRING fname)
  274. SINGLE  time0
  275.   BEEP
  276.   PRINT fname;" error!"
  277.   PRINT
  278.   PRINT "press 'q' key to quit."
  279.   WHILE UCASE$(INKEY$)<>"Q":WEND
  280.   WINDOW CLOSE 1
  281.   STOP
  282. END SUB
  283.  
  284. SUB STRING strip_whitespace(STRING X)
  285. SHORTINT i,j,length
  286. STRING   ch SIZE 2
  287.   '..remove leading whitespace from X.
  288.   length = LEN(X)
  289.  
  290.   i=1
  291.   repeat
  292.     ch = MID$(X,i,1)
  293.     if ch <= " " then ++i
  294.   until ch > " " or i > length
  295.  
  296.   '..return the stripped string.
  297.   strip_whitespace = MID$(X,i)
  298. END SUB
  299.  
  300. SUB append_slash(ADDRESS X_addr)
  301. STRING X ADDRESS X_addr
  302. STRING delimiter SIZE 2
  303.     delimiter = RIGHT$(X,1)
  304.     if delimiter <> "/" and delimiter <> ":" then 
  305.       X = X+"/" 
  306.     end if
  307. END SUB
  308.  
  309. SUB get_config
  310. SHARED   config
  311. CONST    words=6
  312. DIM      keyword$(words) SIZE 7
  313. SHORTINT i,posn
  314. LONGINT  abort
  315. STRING   config_file SIZE 12
  316. STRING   ln SIZE 81
  317. STRING   value SIZE strSize
  318.  
  319.   config_file = "AIDE.config"
  320.  
  321.   abort=FALSE
  322.  
  323.   '..read the config file keywords
  324.   for i=1 to words
  325.     read keyword$(i)
  326.   next
  327.   DATA EDITOR,VIEWER,TMPDIR,DOCDIR,BLTDIR,AGDDIR
  328.  
  329.   '..open the configuration file
  330.   OPEN "I",#1,config_file
  331.  
  332.   '..abort program if we can't open this!
  333.   if HANDLE(1)=NULL then CALL abort_prog(config_file)
  334.  
  335.   '..search for config keywords and set 
  336.   '..values in config structure (expects: <configvar>=<value>).
  337.   while not eof(1)
  338.     LINE INPUT #1,ln
  339.     ln = UCASE$(ln)
  340.     if LEFT$(ln,1) <> "#" then
  341.       i=1 : posn=0
  342.       while i<=words and posn=0
  343.         posn=INSTR(ln,keyword$(i))
  344.         if posn=0 then ++i
  345.       wend
  346.       if posn > 0 then     
  347.      value = strip_whitespace(MID$(ln,INSTR(ln,"=")+1))
  348.     case
  349.       i=1 : config->editor = value
  350.           i=2 : config->viewer = value
  351.           i=3 : config->tmpdir = value
  352.       i=4 : config->docdir = value
  353.       i=5 : config->bltdir = value
  354.       i=6 : config->agddir = value
  355.         end case
  356.       end if
  357.     end if
  358.   wend
  359.   CLOSE #1
  360.  
  361.   '..Check we've got all the non-optional values and 
  362.   '..make changes where necessary.
  363.  
  364.   if config->editor="" then abort=TRUE
  365.  
  366.   if config->viewer="" then abort=TRUE  
  367.  
  368.   if config->tmpdir="" then 
  369.     abort=TRUE
  370.   else
  371.     append_slash(@config->tmpdir)
  372.     '.."Ram Disk:" will cause Blink to choke
  373.     '..since it can't handle quoted args, and the 2.04
  374.     '..ASL file requester yields this name for "RAM:"
  375.     if LEFT$(config->tmpdir,9) = "RAM DISK:" then
  376.        config->tmpdir = "RAM:"+MID$(config->tmpdir,10)
  377.     end if    
  378.   end if
  379.  
  380.   if config->docdir="" then
  381.     abort=TRUE
  382.   else
  383.     append_slash(@config->docdir)  
  384.   end if
  385.  
  386.   if config->bltdir<>"" then 
  387.     append_slash(@config->bltdir)  
  388.   end if
  389.  
  390.   '..AmigaGuide is optional since no files are yet supplied for this.
  391.   if config->agddir<>"" then
  392.     append_slash(@config->agddir)  
  393.   end if
  394.  
  395.   if abort then CALL abort_prog(config_file)    
  396. END SUB
  397.  
  398. SUB initialise_config
  399. SHARED config
  400.   config->editor=""
  401.   config->viewer=""
  402.   config->tmpdir=""
  403.   config->agddir=""
  404. END SUB
  405.  
  406. SUB initialise_program_info
  407. SHARED prog
  408.   prog->source_file=""
  409.   prog->source_dir=""
  410.   prog->made=FALSE
  411.   prog->module_count=0
  412. END SUB
  413.  
  414. SUB initialise_options
  415. SHARED options
  416.   options->user_break=FALSE
  417.   options->asm_comments=FALSE
  418.   options->error_log=FALSE
  419.   options->create_icon=FALSE
  420.   options->list_lines=FALSE
  421.   options->optimise=TRUE
  422.   options->window_close=FALSE
  423. END SUB
  424.  
  425. SUB initialise_environment
  426. SHARED module$
  427.   PRINT "Initialising..."
  428.   initialise_config
  429.   get_config
  430.   initialise_options
  431.   initialise_program_info
  432.   '..clear link modules array
  433.   for i=1 to maxModules:module$(i)="":next
  434. END SUB
  435.  
  436. {------------------------------------------------------}
  437.  
  438. SUB setup_menus
  439.   '..Project Menu
  440.   MENU mProject,0,cEnable,           "Project"
  441.  
  442.   MENU mProject,iNew,cEnable,           "New","N"
  443.   MENU mProject,iOpen,cEnable,           "Open...","O"
  444.   MENU mProject,iView,cEnable,        "View...","V"
  445.   MENU mProject,iSep1.1,cDisable,      "-----------------"
  446.   MENU mProject,iDelete,cEnable,       "Delete...","D"
  447.   MENU mProject,iPrint,cEnable,           "Print...","P"
  448.   MENU mProject,iExecute,cEnable,      "Execute...","X"
  449.   MENU mProject,iShell,cEnable,        "Spawn Shell"
  450.   MENU mProject,iSep1.2,cDisable,      "-----------------"
  451.   MENU mProject,iAbout,cEnable,           "About..."
  452.   MENU mProject,iQuit,cEnable,           "Quit AIDE","Q"
  453.   
  454.   '..Program Menu
  455.   MENU mProgram,0,cEnable,           "Program"
  456.  
  457.   MENU mProgram,iSetSource,cEnable,      "Set Source...","S"
  458.   MENU mProgram,iEdit,cDisable,        "Edit Source","E"
  459.   MENU mProgram,iSep2.1,cDisable,       "------------------------"
  460.   MENU mProgram,iRun,cDisable,            "Run","R"
  461.   MENU mProgram,iSep2.2,cDisable,      "------------------------"
  462.   MENU mProgram,iCompile,cDisable,      "Compile","C"
  463.   MENU mProgram,iMake,cDisable,      "Make Executable","M"
  464.   MENU mProgram,iBuild,cDisable,       "Build Application","B"
  465.   MENU mProgram,iSep2.3,cDisable,      "------------------------"
  466.   MENU mProgram,iViewAsm,cDisable,    "View Assembly Source"
  467.   MENU mProgram,iViewPrep,cDisable,    "View Preprocessed Source"
  468.   MENU mProgram,iShowErrs,cDisable,      "Show Compiler Errors"
  469.  
  470.   '..Compiler Menu
  471.   MENU mCompiler,0,cEnable,        "Compiler"
  472.   MENU mCompiler,iBreak,cEnable,    "    Break Trapping"
  473.   MENU mCompiler,iComments,cEnable,    "    Assembly Comments"
  474.   MENU mCompiler,iIcon,cEnable,        "    Create Icon"
  475.   MENU mCompiler,iListLines,cEnable,    "    List Source Lines"
  476.   MENU mCompiler,iOptimise,cCheck,    "    Optimise Assembly"
  477.   MENU mCompiler,iWindow,cEnable,    "    Window Trapping"
  478.  
  479.   '..Linker Menu
  480.   MENU mLinker,0,cEnable,        "Linker"
  481.   MENU mLinker,iAddModule,cEnable,    "Add Module..."
  482.   MENU mLinker,iRemModule,cDisable,    "Remove Module..."
  483.   MENU mLinker,iRemAllMod,cDisable,     "Remove All Modules"
  484.   MENU mLinker,iSep4.1,cDisable,    "------------------"
  485.  
  486.   '..Help Menu
  487.   MENU mHelp,0,cEnable,            "Help"
  488.   MENU mHelp,iACEDoc,cEnable,        "Compiler"
  489.   MENU mHelp,iA68KDoc,cEnable,        "Assembler"
  490.   MENU mHelp,iBlinkDoc,cEnable,        "Linker"
  491.   MENU mHelp,iSep5.1,cDisable,        "------------"
  492.   MENU mHelp,iACERef,cEnable,        "ACE Language"
  493. END SUB
  494.  
  495. {------------------------------------------------------}
  496.  
  497. SUB new_file
  498. SHARED config
  499.   SYSTEM config->editor
  500. END SUB
  501.  
  502. SUB open_file
  503. SHARED config
  504. STRING file_name SIZE strSize
  505.   file_name = FileBox$("Open")  
  506.   SYSTEM config->editor+" "+quote(file_name)
  507. END SUB
  508.  
  509. SUB view_file
  510. SHARED config
  511. STRING file_name SIZE strSize
  512.   file_name = FileBox$("View") 
  513.   SYSTEM config->viewer+" "+quote(file_name)
  514. END SUB
  515.  
  516. SUB execute_command
  517. SHARED default_command
  518. SHARED config
  519. STRING command, script_call
  520. STRING title SIZE strSize
  521. STRING prompt SIZE strSize
  522.  
  523.   prompt = "Enter Command and Arguments:"
  524.   title  = "Execute Command"
  525.  
  526.   command = InputBox$(prompt,title,default_command)
  527.  
  528.   if command <> "" then 
  529.     '..construct a shell script.
  530.     OPEN "O",254,config->tmpdir+"command-script"
  531.     PRINT #254,"failat 11"
  532.     PRINT #254,"echo "+CHR$(34)+"*E[0;0H*E[J"+CHR$(34) '..cls
  533.     PRINT #254,"prompt "+CHR$(34)+CHR$(34)
  534.     PRINT #254,"stack 40000"
  535.     PRINT #254,"alias C EndCli"
  536.     PRINT #254,command
  537.     PRINT #254,"echo "+CHR$(34)+CHR$(34)
  538.     PRINT #254,"echo "+CHR$(34)+"Press C and <Enter> to continue..."+CHR$(34)
  539.     CLOSE #254
  540.  
  541.     '..Execute it!
  542.     script_call = "NewShell "+CHR$(34)+"CON:0/125/640/100/Command Window"
  543.     script_call = script_call+CHR$(34)+" FROM "
  544.     script_call = script_call+config->tmpdir+"command-script"
  545.     SYSTEM script_call
  546.  
  547.     '..Kill it.
  548.     KILL config->tmpdir+"command-script"
  549.  
  550.     '..Set new default command.
  551.     default_command = command
  552.   end if
  553. END SUB
  554.  
  555. SUB print_file
  556. STRING file_name SIZE strSize
  557. STRING text_line
  558.   file_name = FileBox$("Print")
  559.   OPEN "I",#1,file_name
  560.   if HANDLE(1) then
  561.     PRINT "Printing ";file_name;"..."
  562.     OPEN "O",#2,"PRT:"
  563.     while not eof(1)
  564.       LINE INPUT #1,text_line
  565.       PRINT #2,text_line
  566.     wend
  567.     CLOSE 1,2
  568.   else
  569.     if file_name<>"" then print "Unable to print ";file_name
  570.   end if 
  571. END SUB
  572.  
  573. SUB delete_file
  574. STRING file_name SIZE strSize
  575.   file_name = FileBox$("Delete")
  576.   if file_name<>"" then 
  577.     if NOT MsgBox("Really delete "+file_name+"?","Yes","No!") then 
  578.       PRINT file_name;" not deleted."
  579.       EXIT SUB
  580.     end if 
  581.     KILL file_name
  582.     if ERR then 
  583.       PRINT "Error while deleting!"
  584.     else
  585.       PRINT file_name;" deleted."
  586.     end if
  587.   else
  588.     PRINT "No file/directory specified."
  589.   end if
  590. END SUB
  591.  
  592. SUB spawn_shell
  593.   SYSTEM "NewShell CON:0/125/640/100/AIDEshell/CLOSE"
  594. END SUB
  595.  
  596. SUB about_box
  597.   x$="Written in ACE by David Benn "+CHR$(169)+" 1994"
  598.   dummy = MsgBox(x$,"OK")
  599. END SUB
  600.  
  601. SUB handle_project_menu(item)
  602. SHORTINT result
  603.   case 
  604.     item = iNew          : new_file
  605.     item = iOpen      : open_file
  606.     item = iView    : view_file
  607.     item = iPrint     : print_file
  608.     item = iExecute    : execute_command
  609.     item = iDelete    : delete_file
  610.     item = iShell    : spawn_shell
  611.     item = iAbout     : about_box
  612.   end case  
  613. END SUB
  614.  
  615. {------------------------------------------------------}
  616.  
  617. SUB set_source
  618. SHARED  prog
  619. STRING  file_name SIZE strSize
  620. STRING  tmp SIZE strSize
  621. STRING  delimiter SIZE 2
  622. STRING  extension SIZE 3
  623. LONGINT posn,ramdisk,dblslash,found
  624.  
  625.   '..get source file name
  626.   file_name = FileBox$("Select Source File")
  627.  
  628.   if file_name="" then 
  629.     PRINT "No source file specified."
  630.     EXIT SUB
  631.   end if
  632.  
  633.   '..extract directory path and file
  634.   posn=LEN(file_name)
  635.   found=FALSE
  636.   repeat
  637.     delimiter = MID$(file_name,posn,1)
  638.     if delimiter=":" or delimiter="/" then
  639.     found=TRUE
  640.     else
  641.          --posn
  642.     end if
  643.   until posn=0 or found
  644.  
  645.   if not found then 
  646.     prog->source_file = file_name
  647.     prog->source_dir = ""
  648.   else
  649.     '..source directory
  650.     prog->source_dir = LEFT$(file_name,posn)
  651.   
  652.     '..kludge for Wb 3.0 ASL requester when PARENT button
  653.     '..is selected. (??)
  654.     dblslash = INSTR(prog->source_dir,"//")
  655.     if dblslash then
  656.        tmp = prog->source_dir
  657.        prog->source_dir = MID$(tmp,1,dblslash) + MID$(tmp,dblslash+2)
  658.     end if   
  659.  
  660.     '..source file
  661.     prog->source_file = MID$(file_name,posn+1)
  662.   end if
  663.  
  664.   '..remove file extension
  665.   extension = RIGHT$(prog->source_file,2)
  666.   if ucase$(extension) <> ".B" then 
  667.     prog->source_file = ""
  668.   else
  669.     posn = INSTR(ucase$(prog->source_file),".B")
  670.      prog->source_file = LEFT$(prog->source_file,posn-1)
  671.   end if  
  672.  
  673.   '..enable inactive program menu items?
  674.   if prog->source_file <> "" then
  675.     prog->made=FALSE
  676.     MENU mProgram,iEdit,cEnable
  677.     MENU mProgram,iRun,cEnable
  678.     MENU mProgram,iArguments,cEnable
  679.     MENU mProgram,iCompile,cEnable
  680.     MENU mProgram,iMake,cEnable
  681.     MENU mProgram,iBuild,cEnable
  682.     MENU mProgram,iViewAsm,cEnable
  683.     MENU mProgram,iViewPrep,cEnable
  684.     MENU mProgram,iShowErrs,cEnable
  685.     PRINT "Source file is ";prog->source_dir;prog->source_file;".b"
  686.   else
  687.     PRINT "No source file specified!"
  688.   end if
  689. END SUB
  690.  
  691. SUB edit_source
  692. SHARED config,prog
  693. STRING command
  694. STRING orig_file SIZE strSize
  695. DECLARE STRUCT DateStamp ds1,ds2
  696.  
  697.   orig_file = prog->source_dir+prog->source_file+".b"
  698.  
  699.   IF NOT fexists(orig_file) THEN
  700.      PRINT "Unable to edit ";orig_file
  701.      EXIT SUB
  702.   END IF
  703.  
  704.   '..Get datestamp of original file before editing
  705.   get_file_datestamp(orig_file,ds1)
  706.   
  707.   '..Edit source file
  708.   SYSTEM config->editor+" "+quote(orig_file)
  709.  
  710.   '..Get datestamp of original file after editing
  711.   get_file_datestamp(orig_file,ds2)
  712.  
  713.   '..Flag file as "unmade" if it's changed;
  714.   '..delete any existing assembly source file
  715.   '..since it is now out of date.
  716.   IF datestamps_different(ds1,ds2) THEN
  717.      KILL config->tmpdir+prog->source_file+".s"
  718.      prog->made=FALSE
  719.   END IF
  720. END SUB
  721.  
  722. SUB invoke_make_script(STRING target_dir,SHORTINT object_type)
  723. SHARED  prog,config
  724. STRING  command
  725. STRING  msg SIZE strSize     
  726. STRING  target_file SIZE strSize     
  727. LONGINT target_ok
  728. DECLARE STRUCT DateStamp old_target,new_target
  729. CONST   BOLD=2&,NORMAL=0&,ALLBITS=255&
  730. DECLARE FUNCTION SetSoftStyle(Rp&,textstyle&,bitmask&) LIBRARY
  731.  
  732.   CLS
  733.   library "graphics.library"       
  734.   SetSoftStyle(WINDOW(8),BOLD,ALLBITS)
  735.   PRINT "Making ";CHR$(34);prog->source_file;CHR$(34)
  736.   SetSoftStyle(WINDOW(8),NORMAL,ALLBITS)
  737.   library close "graphics.library"
  738.  
  739.   target_file = target_dir+prog->source_file
  740.  
  741.   '..Delete the executable from previous compilations
  742.   '..(if there were any) so we know whether the make 
  743.   '..was successful or not.
  744.   KILL target_file
  745.  
  746.   '..Rename assembly source file (if it exists) with a ".old" extension.
  747.   '..This is used below to check whether a new target file has been created.
  748.   if fexists(target_file+".s") then
  749.      NAME target_file+".s" AS target_file+".old"
  750.   else
  751.      '..Create a dummy assembly source file so
  752.      '..there is something to compare the new
  753.      '..assembly source file (about to be created) to.
  754.      OPEN "O",#1,target_file+".old"
  755.      PRINT #1,"; dummy assembly source"
  756.      PRINT #1,"END"
  757.      CLOSE #1 
  758.   end if
  759.  
  760.   '..Delete old error file in case we don't generate one now
  761.   '..(ie: don't want old ace.err to be associated with current
  762.   '..compilation).
  763.   KILL "ace.err"
  764.  
  765.   '..start asynchronous process to Make the program. 
  766.   command = "NewShell "+CHR$(34)+"CON:0/125/640/100/Make program: "
  767.   command = command + prog->source_file+CHR$(34)
  768.   command = command + " FROM " + config->tmpdir+"AIDE-newshell-startup"
  769.   SYSTEM command  
  770.  
  771.   '..**********************************
  772.   '..Display messages from Make process 
  773.   '..while waiting for it to complete.
  774.   '..**********************************
  775.   OPEN "I",#1,"PIPE:"
  776.   repeat
  777.     LINE INPUT #1,msg
  778.     if msg<>"MakeDone" and msg<>"MakeAborted" and msg<>"" then PRINT msg 
  779.   until msg = "MakeDone" or msg = "MakeAborted"
  780.   CLOSE #1
  781.  
  782.   case 
  783.     object_type = ASM : PRINT "Assembly source file ";
  784.     object_type = EXE : PRINT "Executable file ";
  785.   end case
  786.  
  787.   '..***************
  788.   '..Successful Make
  789.   '..***************
  790.   if msg = "MakeDone" then 
  791.     if object_type=ASM then
  792.        '..assembly source is target
  793.        get_file_datestamp(target_file+".old",old_target)
  794.        get_file_datestamp(target_file+".s",new_target)
  795.        if fexists(target_file+".s") and older(old_target,new_target) then
  796.       target_ok=TRUE
  797.        else
  798.       target_ok=FALSE
  799.        end if
  800.     else
  801.        '..executable is target
  802.        if object_type=EXE then
  803.           target_ok=fexists(target_file)
  804.        else
  805.       '..unknown target type!
  806.       target_ok=FALSE
  807.        end if
  808.     end if
  809.  
  810.     if  target_ok then 
  811.       PRINT "created."
  812.       prog->made=TRUE
  813.     else
  814.       PRINT "not created."
  815.     end if
  816.   end if
  817.  
  818.   '..*****************
  819.   '..Unsuccessful Make
  820.   '..*****************
  821.   if msg = "MakeAborted" then
  822.     KILL target_dir+prog->source_file
  823.     KILL target_dir+prog->source_file+".s"
  824.     KILL target_dir+prog->source_file+".old"
  825.     PRINT "not created."
  826.     prog->made=FALSE
  827.   end if
  828. END SUB
  829.  
  830. SUB make_program(STRING target_dir,SHORTINT object_type)
  831. SHARED   config,prog,options,module$
  832. SHORTINT i
  833. STRING   command,opts
  834. STRING     ace_src_name SIZE strSize
  835. STRING     asm_src_name SIZE strSize
  836. DECLARE  STRUCT DateStamp ace_src,asm_src
  837.  
  838.   '..Generate a shell script to make the program.
  839.   OPEN "O",#1,config->tmpdir+"AIDE-newshell-startup"
  840.   
  841.   PRINT #1,"failat 11"
  842.   PRINT #1,"echo "+CHR$(34)+"*E[0;0H*E[J"+CHR$(34)
  843.   PRINT #1,"alias QuitMake echo >PIPE: MakeAborted"
  844.   PRINT #1,"stack 40000"
  845.  
  846.   ace_src_name = prog->source_dir+prog->source_file+".b"
  847.   asm_src_name = target_dir+prog->source_file+".s"
  848.  
  849.   '..Compare datestamps of ACE source and assembly source (if it exists!)
  850.   get_file_datestamp(ace_src_name, ace_src)
  851.   get_file_datestamp(asm_src_name, asm_src)
  852.   
  853.   '..We only want to compile the ACE source if it hasn't already been
  854.   '..compiled (by the user selecting "Compile Program" in the past).
  855.   IF NOT fexists(asm_src_name) OR NOT older(ace_src,asm_src) THEN
  856.     '*** APP ***  
  857.     PRINT #1,"echo >PIPE: Preprocessing"
  858.     command = "ACE:bin/app "+quote(ace_src_name)
  859.     command = command +" "+quote(target_dir+prog->source_file+".b")
  860.     PRINT #1,command
  861.  
  862.     '..preprocessor errors?
  863.     PRINT #1,"IF ERROR"
  864.     PRINT #1,"   echo >PIPE: Aborted!"
  865.     PRINT #1,"   echo >PIPE: MakeAborted"
  866.     PRINT #1,"   EndCLI"
  867.     PRINT #1,"ENDIF"
  868.  
  869.     '*** ACE ***
  870.     PRINT #1,"echo >PIPE: Compiling"
  871.     command = "ACE:bin/ace -E"
  872.  
  873.     '..Compiler switches? (the "i" switch is redundant here since
  874.     '..build_application copies the icon from ACE:icons/exe.info
  875.     '..but someone MAY expect the icon to also be in the working 
  876.     '..directory when compiling/making!)
  877.     opts=""
  878.     if options->user_break then opts = opts + "b"
  879.     if options->asm_comments then opts = opts + "c"
  880.     if options->create_icon then opts = opts + "i" 
  881.     if options->list_lines then opts = opts + "l"
  882.     if options->optimise then opts = opts + "O"
  883.     if options->window_close then opts = opts + "w"
  884.     if opts <> "" then command = command + opts+" "
  885.  
  886.     command = command + quote(target_dir+prog->source_file+".b")
  887.     PRINT #1,command
  888.  
  889.     '..compile-time errors?
  890.     PRINT #1,"IF ERROR"
  891.     PRINT #1,"   echo >PIPE: Aborted!"
  892.     PRINT #1,"   echo >PIPE: MakeAborted"
  893.     PRINT #1,"   EndCLI"
  894.     PRINT #1,"ENDIF"
  895.   END IF
  896.  
  897.   IF object_type = EXE THEN
  898.     '*** A68K ***
  899.     PRINT #1,"echo >PIPE: Assembling"
  900.     command = "ACE:bin/a68k "+quote(asm_src_name)
  901.     PRINT #1,command
  902.  
  903.     '*** BLINK ***
  904.     PRINT #1,"echo >PIPE: Linking"
  905.     command = "ACE:bin/blink "+target_dir+prog->source_file+".o"
  906.     command = command + " LIB "
  907.     '..add link modules
  908.     for i=1 to prog->module_count
  909.       if module$(i)<>"" then command = command + module$(i) + "+"
  910.     next
  911.     command = command + "ACElib:startup.lib+ACElib:db.lib+ACElib:ami.lib"
  912.     'command = command + "SMALLCODE SMALLDATA" 
  913.     PRINT #1,command
  914.   END IF
  915.  
  916.   '..OK -> we're finished
  917.   PRINT #1,"echo >PIPE: MakeDone"
  918.   PRINT #1,"EndCLI"
  919.  
  920.   CLOSE #1
  921.  
  922.   '..do it!
  923.   invoke_make_script(target_dir,object_type)
  924. END SUB
  925.  
  926. SUB compile_program
  927. SHARED config,prog
  928.   if not prog->made or not fexists(config->tmpdir+prog->source_file+".s") then
  929.      make_program(config->tmpdir,ASM)
  930.   else
  931.      PRINT prog->source_file;" is up to date."    
  932.   end if
  933. END SUB
  934.  
  935. SUB make_executable
  936. SHARED config,prog
  937.   if not prog->made or not fexists(config->tmpdir+prog->source_file) then
  938.      make_program(config->tmpdir,EXE)
  939.   else
  940.      PRINT prog->source_file;" is up to date."
  941.   end if
  942. END SUB
  943.  
  944. SUB run_program
  945. SHARED config,prog
  946.   make_executable
  947.   if prog->made then
  948.     PRINT "Running ";prog->source_file;"..."
  949.     SYSTEM quote(config->tmpdir+prog->source_file)
  950.     CLS
  951.     PRINT prog->source_file;" finished."
  952.   else
  953.     '..There (probably) was a compile error.
  954.     PRINT "Unable to run ";prog->source_file;"."
  955.   end if
  956. END SUB
  957.  
  958. SUB build_application
  959. SHARED config,prog,options
  960. STRING command,dest_dir
  961.   make_executable
  962.   '..where's the executable going?
  963.   if config->bltdir<>"" then 
  964.      dest_dir = config->bltdir
  965.   else
  966.      dest_dir = prog->source_dir
  967.   end if
  968.   '..copy executable
  969.   command = "sys:c/copy >NIL: "+config->tmpdir+prog->source_file+" "
  970.   command = command + quote(dest_dir+prog->source_file)
  971.   SYSTEM command
  972.   '..copy icon?
  973.   if options->create_icon then
  974.     command = "sys:c/copy >NIL: ACE:icons/exe.info "
  975.     command = command + quote(dest_dir+prog->source_file+".info")
  976.     SYSTEM command
  977.   end if
  978.   '..were we successful?
  979.   if prog->made then 
  980.     PRINT dest_dir+prog->source_file;" has been built."
  981.   end if
  982. END SUB
  983.  
  984. SUB view_assembly_source
  985. SHARED config,prog
  986. STRING fname SIZE strSize 
  987.   fname = config->tmpdir+prog->source_file+".s"
  988.   if fexists(fname) then 
  989.     SYSTEM config->viewer+" "+quote(fname)
  990.   else
  991.     PRINT "No assembly source present."
  992.   end if
  993. END SUB
  994.  
  995. SUB view_preprocessed_source
  996. SHARED config,prog
  997. STRING fname SIZE strSize 
  998.   fname = config->tmpdir+prog->source_file+".b"
  999.   if fexists(fname) then 
  1000.     SYSTEM config->viewer+" "+quote(fname)
  1001.   else
  1002.     PRINT "No preprocessed source present."
  1003.   end if
  1004. END SUB
  1005.  
  1006. SUB show_compiler_errors
  1007. SHARED config
  1008.   OPEN "I",#1,"ace.err"  
  1009.   if HANDLE(1) then 
  1010.     if LOF(1)<>0 then
  1011.       SYSTEM config->viewer+" ace.err"
  1012.     else
  1013.       PRINT "There were no compilation errors."
  1014.     end if
  1015.   else
  1016.     PRINT "No ACE error log."
  1017.   end if
  1018.   CLOSE #1
  1019. END SUB
  1020.  
  1021. SUB handle_program_menu(item)
  1022.   case
  1023.     item = iSetSource    : set_source
  1024.     item = iEdit    : edit_source
  1025.     item = iRun        : run_program
  1026.     item = iCompile      : compile_program
  1027.     item = iMake    : make_executable
  1028.     item = iBuild    : build_application
  1029.     item = iViewAsm    : view_assembly_source
  1030.     item = iViewPrep    : view_preprocessed_source
  1031.     item = iShowErrs    : show_compiler_errors
  1032.   end case
  1033. END SUB
  1034.  
  1035. {------------------------------------------------------}
  1036.  
  1037. SUB change_option_state(ADDRESS opt,SHORTINT item)
  1038.   if NOT *&opt then
  1039.     *&opt:=TRUE
  1040.     MENU mCompiler,item,cCheck
  1041.   else
  1042.     *&opt:=FALSE
  1043.     MENU mCompiler,item,cEnable
  1044.   end if
  1045. END SUB
  1046.  
  1047. SUB handle_compiler_menu(item)
  1048. SHARED  options
  1049. ADDRESS opt
  1050.   case
  1051.     item = iBreak    : opt = @options->user_break
  1052.     item = iComments    : opt = @options->asm_comments
  1053.     item = iIcon    : opt = @options->create_icon
  1054.     item = iListLines    : opt = @options->list_lines
  1055.     item = iOptimise    : opt = @options->optimise
  1056.     item = iWindow    : opt = @options->window_close
  1057.   end case
  1058.  
  1059.   change_option_state(opt,item)
  1060. END SUB
  1061.  
  1062. {------------------------------------------------------}
  1063.  
  1064. SUB add_link_module
  1065. SHARED   module$,prog 
  1066. SHORTINT maxMod,i
  1067. LONGINT  found
  1068. STRING   module SIZE strSize
  1069.  
  1070.   '..add a module to the list of object files to link.
  1071.  
  1072.   maxMod = prog->module_count + 1
  1073.  
  1074.   if maxMod <= maxModules then
  1075.     '..get name of module
  1076.     module = FileBox$("Add Module")
  1077.  
  1078.     if module <> "" then 
  1079.       '..is module already in the list?
  1080.       found=FALSE
  1081.       for i=1 to prog->module_count
  1082.     if module$(i) = module then found=TRUE
  1083.       next
  1084.  
  1085.       if not found then
  1086.     '..No -> add module to list 
  1087.         module$(maxMod) = module
  1088.         MENU mLinker,iSep4.1+maxMod,cEnable,module$(maxMod)
  1089.  
  1090.         '..increment module count
  1091.         prog->module_count = prog->module_count + 1
  1092.        
  1093.      '..program may need to be remade
  1094.     prog->made=FALSE
  1095.  
  1096.     PRINT module$(maxMod);" added to list."
  1097.  
  1098.         '..enable "remove" menu items when there is 1 module in the list.
  1099.         if prog->module_count = 1 then 
  1100.           MENU mLinker,iRemModule,cEnable
  1101.           MENU mLinker,iRemAllMod,cEnable
  1102.         end if
  1103.       else
  1104.         PRINT module;" already in list."
  1105.       end if
  1106.     else
  1107.       PRINT "No module specified."
  1108.     end if
  1109.   else
  1110.     PRINT "No more than";maxModules;"modules can be specified."
  1111.   end if
  1112. END SUB
  1113.  
  1114. SUB enable_menu_items
  1115.   '..enable menu items disabled by setup_menus
  1116.   MENU mProgram,iEdit,cEnable
  1117.   MENU mProgram,iRun,cEnable
  1118.   MENU mProgram,iArguments,cEnable
  1119.   MENU mProgram,iCompile,cEnable
  1120.   MENU mProgram,iMake,cEnable
  1121.   MENU mProgram,iBuild,cEnable
  1122.   MENU mProgram,iViewAsm,cEnable
  1123.   MENU mProgram,iViewPrep,cEnable
  1124.   MENU mProgram,iShowErrs,cEnable  
  1125. END SUB
  1126.  
  1127. SUB remove_link_module
  1128. SHARED   module$,prog 
  1129. SHORTINT maxMod,n,i
  1130. LONGINT  found
  1131. STRING   module SIZE strSize
  1132.  
  1133.   '..remove a module from the list of files to link.
  1134.   maxMod = prog->module_count
  1135.  
  1136.   if maxMod > 0 then
  1137.     '..get module name
  1138.     module = FileBox$("Remove Module")
  1139.  
  1140.     '..remove module from list if it exists.
  1141.     if module <> "" then
  1142.       found=FALSE
  1143.       for n=1 to maxMod
  1144.         if module$(n) = module and not found then 
  1145.        found=TRUE 
  1146.        module$(n)=""
  1147.         end if
  1148.       next
  1149.  
  1150.       if found then
  1151.       '..restore module list
  1152.       CLS
  1153.        PRINT "Updating..."
  1154.           '..shuffle module list entries
  1155.           for n=1 to MaxMod
  1156.             for i=maxMod to 2 step -1
  1157.           if module$(i-1) = "" then 
  1158.          module$(i-1) = module$(i)  
  1159.          module$(i) = ""
  1160.           end if
  1161.             next
  1162.           next
  1163.         '.fix menus
  1164.           menu clear
  1165.           setup_menus
  1166.       enable_menu_items
  1167.            MENU mLinker,iRemModule,cEnable
  1168.       MENU mLinker,iRemAllMod,cEnable
  1169.              for i=1 to maxMod
  1170.         if module$(i)<>"" then MENU mLinker,iSep4.1+i,cEnable,module$(i)
  1171.       next
  1172.       CLS
  1173.  
  1174.       '. decrement module count
  1175.           prog->module_count = prog->module_count - 1
  1176.  
  1177.        '..program may need to be remade
  1178.       prog->made=FALSE
  1179.  
  1180.       '..disable "remove" menu items if all have been removed.
  1181.       if prog->module_count = 0 then 
  1182.          MENU mLinker,iRemModule,cDisable
  1183.          MENU mLinker,iRemAllMod,cDisable
  1184.       end if
  1185.       else
  1186.           PRINT module;" not in list."
  1187.       end if
  1188.     else
  1189.       PRINT "No module specified."
  1190.     end if
  1191.   else
  1192.     PRINT "No modules to remove."
  1193.   end if
  1194. END SUB
  1195.  
  1196. SUB remove_all_modules
  1197. SHARED   prog,module$
  1198. SHORTINT i
  1199.   CLS  
  1200.   PRINT "Updating..."
  1201.   menu clear
  1202.   setup_menus
  1203.   enable_menu_items
  1204.   for i=1 to maxModules
  1205.     module$(i)=""
  1206.   next
  1207.   CLS
  1208.   '..no modules left
  1209.   prog->module_count = 0
  1210.   '..program may need to be remade
  1211.   prog->made=FALSE
  1212. END SUB
  1213.  
  1214. SUB handle_linker_menu(item)
  1215.   case
  1216.     item = iAddModule : add_link_module 
  1217.     item = iRemModule : remove_link_module
  1218.     item = iRemAllMod : remove_all_modules
  1219.   end case
  1220. END SUB
  1221.  
  1222. {------------------------------------------------------}
  1223.  
  1224. SUB ace_doc
  1225. SHARED config
  1226.   SYSTEM config->viewer+" "+quote(config->docdir+"ace.doc")
  1227. END SUB
  1228.  
  1229. SUB a68k_doc
  1230. SHARED config
  1231.   SYSTEM config->viewer+" "+quote(config->docdir+"a68k.doc")
  1232. END SUB
  1233.  
  1234. SUB blink_doc
  1235. SHARED config
  1236.   SYSTEM config->viewer+" "+quote(config->docdir+"blink.doc")
  1237. END SUB
  1238.  
  1239. SUB ace_ref
  1240. SHARED config
  1241.   if config->agddir="" then
  1242.     '..AmigaGuide not installed -> use ref.doc
  1243.       SYSTEM config->viewer+" "+quote(config->docdir+"ref.doc")
  1244.   else
  1245.     '..AmigaGuide installed -> use ref.guide
  1246.       SYSTEM config->agddir+"AmigaGuide "+quote(config->docdir+"ref.guide")
  1247.   end if    
  1248. END SUB
  1249.  
  1250. SUB handle_help_menu(item)
  1251.   case
  1252.     item = iACEDoc     : ace_doc
  1253.     item = iA68KDoc     : a68k_doc
  1254.     item = iBlinkDoc     : blink_doc
  1255.     item = iACERef     : ace_ref
  1256.   end case
  1257. END SUB
  1258.  
  1259. {------------------------------------------------------}
  1260.  
  1261. SUB event_loop(SHORTINT first_menu_selection)
  1262. SHORTINT menuNum,itemNum
  1263.   repeat
  1264.     menu wait
  1265.     if first_menu_selection then 
  1266.     cls   '..remove initial "Select a menu option" message.
  1267.     first_menu_selection = FALSE
  1268.     end if
  1269.     menuNum = MENU(0)
  1270.     itemNum = MENU(1)
  1271.     case 
  1272.       menuNum = mProject  : handle_project_menu(itemNum)
  1273.       menuNum = mProgram  : handle_program_menu(itemNum)
  1274.       menuNum = mCompiler : handle_compiler_menu(itemNum)
  1275.       menuNum = mLinker   : handle_linker_menu(itemNum)
  1276.       menuNum = mHelp     : handle_help_menu(itemNum)
  1277.     end case
  1278.   until menuNum = mProject and itemNum = iQuit
  1279. END SUB
  1280.  
  1281. SUB clean_up
  1282. SHARED config
  1283.   '..delete tmpdir files 
  1284.   SYSTEM "delete >NIL: "+quote(config->tmpdir+"#?")
  1285.   KILL "ace.err"
  1286. END SUB
  1287.  
  1288.  
  1289. {*
  1290. ** Main Program
  1291. *}
  1292.  
  1293. window 1,"AIDE version 1.0",(0,10)-(640,125),22
  1294. if SYSTEM >= 37 then
  1295.   initialise_environment
  1296.   setup_menus
  1297.   cls
  1298.   print "Select a menu option."
  1299.   event_loop(TRUE)
  1300.   clean_up
  1301. else
  1302.   reply=MsgBox("Need Wb 2.04 or higher. See AIDE.doc for more.","OK")
  1303. end if
  1304. window close 1
  1305.