home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / epmgcc32.zip / gcc.e < prev    next >
Text File  |  1996-12-08  |  36KB  |  999 lines

  1. /*
  2. ╔══════════════════════════════════════════════════════════════════════════════╗
  3. ║ What's it called: EPMGCC  V3.20                                              ║
  4. ║                                                                              ║
  5. ║ What does it do:  The E source code for the GCC-Interface for EPM.           ║
  6. ║                   This file contains the menu definitions and procedures.    ║
  7. ║                                                                              ║
  8. ║ Who and When:     B. Bablok 12/93 - 12/96                                    ║
  9. ║                                                                              ║
  10. ╚══════════════════════════════════════════════════════════════════════════════╝
  11. */
  12. TRYINCLUDE 'gccenv.e'
  13. TRYINCLUDE 'gccconst.e'
  14. /*
  15. ┌──────────────────────────────────────────────────────────────────────────────┐
  16. │  DEFINIT: Initialize EPMGCC variables and post menu build                    │
  17. └──────────────────────────────────────────────────────────────────────────────┘
  18. */
  19. DEFINIT
  20.     UNIVERSAL gcc_project,            -- project name
  21.               gcc_project_file,       -- make file name
  22.               gcc_sel_projects,       -- previously selected projects
  23.               gcc_d_comp_options,     -- compile options (debug)
  24.               gcc_p_comp_options,     -- compile options (production)
  25.               gcc_d_make_options,     -- make    options (debug)
  26.               gcc_p_make_options,     -- make    options (production)
  27.               gcc_error_file,         -- latest error-file
  28.               gcc_error_file_id,      -- ID of latest error-file
  29.               gcc_line2index,         -- ID of array
  30.               gcc_index2err,          -- ID of array
  31.               gcc_error_index,        -- index of current error
  32.               gcc_debug,              -- debug mode
  33.               gcc_autosave,           -- auto-save mode
  34.               gcc_verbose,            -- verbose mode
  35.               gcc_remove,             -- .err-remove mode
  36.               gcc_runtime_arguments,  -- runtime arguments
  37.               gcc_debug_arguments,    -- runtime arguments for debugger
  38.               gcc_edit_cmd,           -- command to start makefile edit
  39.               gcc_compile_cmd,        -- command to start compiler
  40.               gcc_build_cmd,          -- command to start make
  41.               gcc_debug_cmd,          -- command to start debug
  42.               gcc_translate,          -- translate \ to / in filenames
  43.               gcc_parser_mod,         -- current error-parser module
  44.               gcc_save_settings       -- save settings to epm.ini
  45.  
  46.     UNIVERSAL app_hini
  47.  
  48.     gcc_project           = ''
  49.     gcc_sel_projects      = QUERYPROFILE(app_hini,'GCC','GCC_SEL_PROJECTS')
  50.     gcc_project_file      = ''
  51.     gcc_error_file        = ''
  52.     gcc_error_file_id     = ''
  53.     gcc_line2index        = ''
  54.     gcc_index2err         = ''
  55.     gcc_error_index       = 0
  56.  
  57.     gcc_save_settings     = QUERYPROFILE(app_hini,'GCC','GCC_SETTINGS_MODE')
  58.     if gcc_save_settings = 1 then    -- settings were saved the last time
  59.  
  60.        gcc_debug             = QUERYPROFILE(app_hini,'GCC','GCC_DEBUG_MODE')
  61.        gcc_autosave          = QUERYPROFILE(app_hini,'GCC','GCC_AUTOSAVE_FILE')
  62.        gcc_verbose           = QUERYPROFILE(app_hini,'GCC','GCC_VERBOSE_MODE')
  63.        gcc_remove            = QUERYPROFILE(app_hini,'GCC','GCC_REMOVE_MODE')
  64.  
  65.        gcc_d_comp_options    = QUERYPROFILE(app_hini,'GCC','GCC_D_COMPILE_OPTIONS')
  66.        gcc_p_comp_options    = QUERYPROFILE(app_hini,'GCC','GCC_P_COMPILE_OPTIONS')
  67.        gcc_d_make_options    = QUERYPROFILE(app_hini,'GCC','GCC_D_BUILD_OPTIONS')
  68.        gcc_p_make_options    = QUERYPROFILE(app_hini,'GCC','GCC_P_BUILD_OPTIONS')
  69.  
  70.        gcc_edit_cmd          = QUERYPROFILE(app_hini,'GCC','GCC_EDIT_COMMAND')
  71.        gcc_compile_cmd       = QUERYPROFILE(app_hini,'GCC','GCC_COMP_COMMAND')
  72.        gcc_build_cmd         = QUERYPROFILE(app_hini,'GCC','GCC_BUILD_COMMAND')
  73.        gcc_debug_cmd         = QUERYPROFILE(app_hini,'GCC','GCC_DEBUG_COMMAND')
  74.        gcc_translate         = QUERYPROFILE(app_hini,'GCC','GCC_WANT_TRANSLATE')
  75.        gcc_parser_mod        = QUERYPROFILE(app_hini,'GCC','GCC_PARSER_MODULE')
  76.  
  77.        gcc_runtime_arguments = QUERYPROFILE(app_hini,'GCC','GCC_RT_ARGS')
  78.        gcc_debug_arguments   = QUERYPROFILE(app_hini,'GCC','GCC_DB_ARGS')
  79.  
  80.     else
  81.  
  82.        gcc_debug             = GCC_DEBUG_MODE
  83.        gcc_autosave          = GCC_AUTOSAVE_FILE
  84.        gcc_verbose           = GCC_VERBOSE_MODE
  85.        gcc_remove            = GCC_REMOVE_MODE
  86.        gcc_save_settings     = GCC_SETTINGS_MODE
  87.  
  88.        gcc_d_comp_options    = GCC_D_COMPILE_OPTIONS
  89.        gcc_p_comp_options    = GCC_P_COMPILE_OPTIONS
  90.        gcc_d_make_options    = GCC_D_BUILD_OPTIONS
  91.        gcc_p_make_options    = GCC_P_BUILD_OPTIONS
  92.  
  93.        gcc_edit_cmd          = GCC_EDIT_COMMAND
  94.        gcc_compile_cmd       = GCC_COMP_COMMAND
  95.        gcc_build_cmd         = GCC_BUILD_COMMAND
  96.        gcc_debug_cmd         = GCC_DEBUG_COMMAND
  97.        gcc_translate         = GCC_WANT_TRANSLATE
  98.        gcc_parser_mod        = GCC_PARSER_MODULE
  99.  
  100.        gcc_runtime_arguments = ''
  101.        gcc_debug_arguments   = ''
  102.     endif
  103.  
  104.     'PostMe BuildGCCMenu'
  105.     'PostMe LINK' gcc_parser_mod
  106.     'PostMe SAYERROR Current parser module:' gcc_parser_mod
  107. /*
  108. ┌──────────────────────────────────────────────────────────────────────────────┐
  109. │  DEFEXIT: Save EPMGCC variables if necessary                                 │
  110. └──────────────────────────────────────────────────────────────────────────────┘
  111. */
  112. DEFEXIT
  113.     UNIVERSAL gcc_sel_projects,       -- previously selected projects
  114.               gcc_d_comp_options,     -- compile options (debug)
  115.               gcc_p_comp_options,     -- compile options (production)
  116.               gcc_d_make_options,     -- make    options (debug)
  117.               gcc_p_make_options,     -- make    options (production)
  118.               gcc_debug,              -- debug mode
  119.               gcc_autosave,           -- auto-save mode
  120.               gcc_verbose,            -- verbose mode
  121.               gcc_remove,             -- .err-remove mode
  122.               gcc_runtime_arguments,  -- runtime arguments
  123.               gcc_debug_arguments,    -- runtime arguments for debugger
  124.               gcc_edit_cmd,           -- command to start makefile edit
  125.               gcc_compile_cmd,        -- command to start compiler
  126.               gcc_build_cmd,          -- command to start make
  127.               gcc_debug_cmd,          -- command to start debug
  128.               gcc_translate,          -- translate \ to / in filenames
  129.               gcc_parser_mod,         -- current error-parser module
  130.               gcc_save_settings       -- save settings to epm.ini
  131.  
  132.     UNIVERSAL app_hini
  133.  
  134.     CALL SETPROFILE(app_hini,'GCC','GCC_SEL_PROJECTS',gcc_sel_projects)
  135.     CALL SETPROFILE(app_hini,'GCC','GCC_SETTINGS_MODE',gcc_save_settings)
  136.  
  137.     if gcc_save_settings = 1 then
  138.  
  139.        CALL SETPROFILE(app_hini,'GCC','GCC_DEBUG_MODE',gcc_debug)
  140.        CALL SETPROFILE(app_hini,'GCC','GCC_AUTOSAVE_FILE',gcc_autosave)
  141.        CALL SETPROFILE(app_hini,'GCC','GCC_VERBOSE_MODE',gcc_verbose)
  142.        CALL SETPROFILE(app_hini,'GCC','GCC_REMOVE_MODE',gcc_remove)
  143.  
  144.        CALL SETPROFILE(app_hini,'GCC','GCC_D_COMPILE_OPTIONS',gcc_d_comp_options)
  145.        CALL SETPROFILE(app_hini,'GCC','GCC_P_COMPILE_OPTIONS',gcc_p_comp_options)
  146.        CALL SETPROFILE(app_hini,'GCC','GCC_D_BUILD_OPTIONS',gcc_d_make_options)
  147.        CALL SETPROFILE(app_hini,'GCC','GCC_P_BUILD_OPTIONS',gcc_p_make_options)
  148.  
  149.        CALL SETPROFILE(app_hini,'GCC','GCC_EDIT_COMMAND',gcc_edit_cmd)
  150.        CALL SETPROFILE(app_hini,'GCC','GCC_COMP_COMMAND',gcc_compile_cmd)
  151.        CALL SETPROFILE(app_hini,'GCC','GCC_BUILD_COMMAND',gcc_build_cmd)
  152.        CALL SETPROFILE(app_hini,'GCC','GCC_DEBUG_COMMAND',gcc_debug_cmd)
  153.        CALL SETPROFILE(app_hini,'GCC','GCC_WANT_TRANSLATE',gcc_translate)
  154.        CALL SETPROFILE(app_hini,'GCC','GCC_PARSER_MODULE',gcc_parser_mod)
  155.  
  156.        CALL SETPROFILE(app_hini,'GCC','GCC_RT_ARGS',gcc_runtime_arguments)
  157.        CALL SETPROFILE(app_hini,'GCC','GCC_DB_ARGS',gcc_debug_arguments)
  158.  
  159.     endif
  160. /*
  161. ┌──────────────────────────────────────────────────────────────────────────────┐
  162. │  GCC menu registering                                                        │
  163. └──────────────────────────────────────────────────────────────────────────────┘
  164. */
  165. DEFSELECT
  166.    'PostMe GCCMenuEnable'
  167.  
  168. DEFLOAD
  169.    'PostMe GCCMenuEnable'
  170. /*
  171. ┌───────────────────────────────────────────────────────────────────────────────┐
  172. │  Define GCC menu system                                                       │
  173. └───────────────────────────────────────────────────────────────────────────────┘
  174. */
  175. DEFC BuildGCCMenu =
  176.     UNIVERSAL defaultmenu, activemenu
  177.  
  178.     DELETEMENU defaultmenu, HELP_MENU_ID, 0, 0      -- delete help menu
  179.  
  180.     BUILDSUBMENU defaultmenu, 21, '~GCC', GCC_MENU__MSG, 0,0
  181.     BUILDMENUITEM defaultmenu, 21, 2101, '~Open Project',
  182.                                'gcc_open_project'GCC_OPEN__MSG, 0,0
  183.     BUILDMENUITEM defaultmenu, 21, 2118, '~Select Project',
  184.                                'gcc_select_project'GCC_SEL__MSG, 0,0
  185.     BUILDMENUITEM defaultmenu, 21, 2102, '~Edit Project',
  186.                                'gcc_edit_project'GCC_EDIT__MSG, 0,0
  187.     BUILDMENUITEM defaultmenu, 21, 2103, 'C~lose Project',
  188.                                'gcc_close_project'GCC_CLOSE__MSG, 0,0
  189.     BUILDMENUITEM defaultmenu, 21, 2104, \0, '', 4, 0
  190.     BUILDMENUITEM defaultmenu, 21, 2105, 'Set com~pile options  c-F11',
  191.                                'gcc_set_comp_options'GCC_COMP_OPT__MSG, 0,0
  192.     BUILDMENUITEM defaultmenu, 21, 2106, '~Compile current file  c-F12',
  193.                                'gcc_compile_file'GCC_COMP__MSG, 0,0
  194.     BUILDMENUITEM defaultmenu, 21, 2107, 'Set b~uild options     s-F11',
  195.                                'gcc_set_make_options'GCC_BUILD_OPT__MSG, 0,0
  196.     BUILDMENUITEM defaultmenu, 21, 2108, '~Build current project s-F12',
  197.                                'gcc_build_project'GCC_BUILD__MSG, 0,0
  198.     BUILDMENUITEM defaultmenu, 21, 2109, '~View results',
  199.                                'gcc_view_results'GCC_VIEW__MSG, 0,0
  200.     BUILDMENUITEM defaultmenu, 21, 2100, \0, '', 4, 0
  201.     BUILDMENUITEM defaultmenu, 21, 2111, '~Run Exe',
  202.                                'gcc_run_exe'GCC_RUN__MSG, 0,0
  203.     BUILDMENUITEM defaultmenu, 21, 2112, '~Debug Exe',
  204.                                'gcc_debug_exe'GCC_DEBUG__MSG, 0,0
  205.     BUILDMENUITEM defaultmenu, 21, 2113, \0, '', 4, 0
  206.     BUILDMENUITEM defaultmenu, 21, 2114, 'Debug ~Mode',
  207.                                'gcc_toggle_debug_mode'GCC_DEBUGMODE__MSG, 0,0
  208.     BUILDMENUITEM defaultmenu, 21, 2115, '~Auto Save',
  209.                                'gcc_toggle_autosave_mode'GCC_AUTOSAVE__MSG, 0,0
  210.     BUILDMENUITEM defaultmenu, 21, 2116, 'Verbose (~test) Mode',
  211.                                'gcc_toggle_verbose_mode'GCC_VERBOSE__MSG, 0,0
  212.     BUILDMENUITEM defaultmenu, 21, 2117, 'Remove ~.err-files automatically',
  213.                                'gcc_toggle_remove_mode'GCC_REMOVE__MSG, 0,0
  214.     BUILDMENUITEM defaultmenu, 21, 2119, 'Save settings',
  215.                                'gcc_toggle_settings_mode'GCC_SETTINGS__MSG, 0,0
  216.  
  217.     CALL READD_HELP_MENU()
  218.     -- SHOWMENU defaultmenu
  219.     call maybe_show_menu()
  220.     'PostMe  GCCMenuEnable'
  221.  
  222. -- enable the GCC menu only if a c/cc/h-, error- or make-file is loaded -
  223. -- or if GCC_MENU_ALWAYS_ON is set
  224.  
  225. DEFC GCCMenuEnable =
  226.  COMPILE IF GCC_MENU_ALWAYS_ON = 1
  227.     gcc_enabled = 1
  228.  COMPILE ELSE
  229.     ext = FILETYPE()
  230.     gcc_enabled = WORDPOS(ext,GCC_EXTENSIONS) > 0
  231.  COMPILE ENDIF
  232.  SetMenuAttribute(21, 16384, gcc_enabled)
  233.  RETURN
  234.  
  235. /*
  236. ┌──────────────────────────────────────────────────────────────────────────────┐
  237. │  Command definitions (menu commands)                                         │
  238. └──────────────────────────────────────────────────────────────────────────────┘
  239. */
  240. DEFC gcc_open_project =
  241.   UNIVERSAL gcc_project_file, gcc_project, gcc_error_file, gcc_error_file_id,
  242.             gcc_sel_projects
  243.  
  244.   IF ARG(1) <> '' THEN
  245.      gcc_project_file = ARG(1)     -- called from gcc_select_project
  246.   ELSE
  247.      gcc_project_file = ENTRYBOX('Make-file name:','/Ok/Cancel/',
  248.                                                          gcc_project_file,20,40)
  249.      IF gcc_project_file = '' THEN
  250.         RETURN
  251.      ELSE
  252.         CALL gcc_delete_arrays()
  253.      ENDIF
  254.   ENDIF
  255.  
  256.   IF POS('.',gcc_project_file) > 0 THEN
  257.      gcc_project = SUBSTR(gcc_project_file,1,LASTPOS('.',gcc_project_file)-1)
  258.   ELSE
  259.      gcc_project = gcc_project_file
  260.   ENDIF
  261.  
  262.   gcc_error_file    = ''
  263.   gcc_error_file_id = ''
  264.  
  265.   IF ARG(1) = '' THEN
  266.      IF POS(LOWCASE(gcc_project_file),LOWCASE(gcc_sel_projects)) = 0 THEN
  267.         IF gcc_sel_projects = '' THEN
  268.            gcc_sel_projects = '/' || gcc_project_file || '/'
  269.         ELSEIF COUNT('/',gcc_sel_projects) < 6 THEN
  270.               gcc_sel_projects = '/' || gcc_project_file || gcc_sel_projects
  271.         ELSE
  272.            gcc_sel_projects = STRIP(gcc_sel_projects,'T','/')
  273.            gcc_sel_projects = '/' || gcc_project_file ||
  274.                        SUBSTR(gcc_sel_projects,1, LASTPOS('/',gcc_sel_projects))
  275.         ENDIF
  276.      ELSE
  277.         CALL gcc_reorder_projects(gcc_project_file)
  278.      ENDIF
  279.   ENDIF
  280.  
  281. DEFC gcc_select_project =
  282.    UNIVERSAL gcc_sel_projects
  283.  
  284.    IF gcc_sel_projects = '' THEN
  285.       SAYERROR 'Selection list is empty. Use "Open project"'
  286.    ELSE
  287.       selected = LISTBOX('Select project',gcc_sel_projects,'/OK/Cancel',5,35)
  288.       IF selected <> '' THEN
  289.          'gcc_close_project'
  290.          'gcc_open_project' selected
  291.          CALL gcc_reorder_projects(selected)
  292.       ELSE
  293.          SAYERROR 'Select canceled'
  294.       ENDIF
  295.    ENDIF
  296.  
  297. DEFC gcc_edit_project =
  298.   UNIVERSAL gcc_project_file, gcc_edit_cmd
  299.   gcc_edit_cmd gcc_project_file
  300.  
  301. DEFC gcc_close_project =
  302.   UNIVERSAL gcc_project, gcc_project_file, gcc_error_file, gcc_error_file_id
  303.   gcc_project       = ''
  304.   gcc_project_file  = ''
  305.   gcc_error_file    = ''
  306.   gcc_error_file_id = ''
  307.   CALL gcc_delete_arrays()
  308.  
  309. DEFC gcc_set_comp_options =
  310.   UNIVERSAL gcc_d_comp_options, gcc_p_comp_options, gcc_debug
  311.  
  312.   IF gcc_debug THEN
  313.     buf = ENTRYBOX('Compile parameters (debug):','/Ok/CANCEL/',
  314.                                               gcc_d_comp_options,30,100,atoi(1))
  315.   ELSE
  316.     buf = ENTRYBOX('Compile parameters (prod):','/Ok/CANCEL/',
  317.                                               gcc_p_comp_options,30,100,atoi(1))
  318.   ENDIF
  319.   button = ASC(SUBSTR(buf,1,1))
  320.   IF button <> 1 THEN
  321.      SAYERROR 'Cancelled'
  322.   ELSE
  323.      eos = POS(\0,buf,2)
  324.      IF gcc_debug THEN
  325.         gcc_d_comp_options = SUBSTR(buf,2,eos-2)
  326.      ELSE
  327.         gcc_p_comp_options = SUBSTR(buf,2,eos-2)
  328.      ENDIF
  329.   ENDIF
  330.  
  331. DEFC gcc_compile_file =
  332.   UNIVERSAL gcc_error_file, gcc_error_file_id, gcc_autosave, gcc_verbose,
  333.             gcc_debug, gcc_d_comp_options, gcc_p_comp_options, gcc_remove,
  334.             gcc_compile_cmd, gcc_line2index, gcc_index2err, gcc_error_index
  335.  
  336.   IF .modify THEN
  337.      IF gcc_autosave THEN
  338.         'Save'
  339.          SAYERROR 'Saving file before invoking' WORD(gcc_compile_cmd,
  340.                                                      WORDS(gcc_compile_cmd))'!'
  341.      ELSE
  342.          SAYERROR 'Warning: File not saved! Compiling old version!'
  343.      ENDIF
  344.   ENDIF
  345.  
  346.   IF gcc_remove THEN
  347.      GETFILEID StartFileID
  348.      LOOP
  349.         IF gcc_remove AND FILETYPE() = 'ERR' THEN
  350.            IF .modify THEN
  351.               'FILE'
  352.            ELSE
  353.               'QUIT'
  354.            ENDIF
  355.         ENDIF
  356.         NEXTFILE
  357.         GETFILEID NextFileID
  358.         IF NextFileID = StartFileID THEN
  359.            LEAVE
  360.         ENDIF
  361.         ACTIVATEFILE NextFileID
  362.      ENDLOOP
  363.      ACTIVATEFILE StartFileID
  364.   ENDIF
  365.  
  366.   gcc_error_file = SUBSTR(.filename,1,LASTPOS('.',.filename)) || 'err'
  367.  
  368.   IF gcc_debug THEN
  369.      arguments = gcc_resolve_template(gcc_d_comp_options,'C')
  370.   ELSE
  371.      arguments = gcc_resolve_template(gcc_p_comp_options,'C')
  372.   ENDIF
  373.  
  374.   IF gcc_verbose THEN
  375.      SAYERROR '(' || gcc_compile_cmd arguments || ') > ' || gcc_error_file '2>&1'
  376.   ENDIF
  377.  
  378.   '(' || gcc_compile_cmd arguments || ') > ' || gcc_error_file '2>&1'
  379.   IF rc <> 0 THEN
  380.      SAYERROR 'Error invoking' WORD(gcc_compile_cmd,
  381.                                              WORDS(gcc_compile_cmd))', RC =' rc
  382.   ELSE
  383.      gcc_error_file_id = ''                   -- reset error_file_id
  384.      CALL gcc_delete_arrays()
  385.   ENDIF
  386.  
  387. DEFC gcc_set_make_options =
  388.   UNIVERSAL gcc_d_make_options, gcc_p_make_options, gcc_debug
  389.  
  390.   IF gcc_debug THEN
  391.     buf = ENTRYBOX('Build parameters (debug):','/Ok/CANCEL/',
  392.                                               gcc_d_make_options,30,100,atoi(1))
  393.   ELSE
  394.     buf = ENTRYBOX('Build parameters (prod):','/Ok/CANCEL/',
  395.                                               gcc_p_make_options,30,100,atoi(1))
  396.   ENDIF
  397.   button = ASC(SUBSTR(buf,1,1))
  398.   IF button <> 1 THEN
  399.      SAYERROR 'Cancelled'
  400.   ELSE
  401.      eos = POS(\0,buf,2)
  402.      IF gcc_debug THEN
  403.         gcc_d_make_options = SUBSTR(buf,2,eos-2)
  404.      ELSE
  405.         gcc_p_make_options = SUBSTR(buf,2,eos-2)
  406.      ENDIF
  407.   ENDIF
  408.  
  409. DEFC gcc_build_project =
  410.   UNIVERSAL gcc_error_file, gcc_project_file, gcc_project, gcc_verbose,
  411.             gcc_debug, gcc_error_file_id, gcc_d_make_options,
  412.             gcc_p_make_options, gcc_autosave, gcc_remove, gcc_build_cmd,
  413.             gcc_line2index, gcc_index2err, gcc_error_index
  414.  
  415.   IF gcc_autosave OR gcc_remove THEN
  416.      IF gcc_autosave THEN
  417.         SAYERROR 'Checking for modified files ...'
  418.      ENDIF
  419.      GETFILEID StartFileID
  420.      NextFileID = ''
  421.      LOOP
  422.         IF gcc_remove AND FILETYPE() = 'ERR' THEN
  423.            IF .modify THEN
  424.               'FILE'
  425.            ELSE
  426.               'QUIT'
  427.            ENDIF
  428.            IF NextFileID = '' THEN
  429.               GETFILEID StartFileID
  430.               ITERATE
  431.            ENDIF
  432.         ELSEIF gcc_autosave AND .modify THEN
  433.            'Save'
  434.         ENDIF
  435.         NEXTFILE
  436.         GETFILEID NextFileID
  437.         IF NextFileID = StartFileID THEN
  438.            LEAVE
  439.         ENDIF
  440.         ACTIVATEFILE NextFileID
  441.      ENDLOOP
  442.      ACTIVATEFILE StartFileID
  443.   ENDIF
  444.  
  445.   gcc_error_file = gcc_project || '.err' -- intervening compile_file is possible
  446.   IF gcc_debug THEN
  447.      arguments = gcc_resolve_template(gcc_d_make_options,'M')
  448.   ELSE
  449.      arguments = gcc_resolve_template(gcc_p_make_options,'M')
  450.   ENDIF
  451.  
  452.   IF gcc_verbose THEN
  453.      SAYERROR '(' || gcc_build_cmd arguments  || ') > ' || gcc_error_file '2>&1'
  454.   ENDIF
  455.  
  456.   '(' || gcc_build_cmd arguments || ') > ' || gcc_error_file '2>&1'
  457.   IF rc <> 0 THEN
  458.      SAYERROR 'Error invoking' WORD(gcc_build_cmd,
  459.                                              WORDS(gcc_build_cmd))', RC =' rc
  460.   ELSE
  461.      gcc_error_file_id = ''                   -- reset error_file_id
  462.      CALL gcc_delete_arrays()
  463.   ENDIF
  464.  
  465. DEFC gcc_view_results =
  466.   UNIVERSAL gcc_project, gcc_error_file, gcc_error_file_id,
  467.             gcc_line2index, gcc_index2err, gcc_error_index
  468.  
  469.  
  470.   IF gcc_error_file_id <> '' THEN
  471.      'EDIT' gcc_error_file
  472.   ELSE
  473.      IF gcc_error_file <> '' THEN
  474.         'EDIT /d' gcc_error_file
  475.      ELSEIF EXIST(gcc_project'.err') THEN
  476.         gcc_error_file = gcc_project'.err'
  477.         'EDIT /d' gcc_error_file
  478.      ELSEIF EXIST(SUBSTR(.filename,1,LASTPOS('.',.filename)) || 'err') THEN
  479.         gcc_error_file = SUBSTR(.filename,1,LASTPOS('.',.filename)) || 'err'
  480.         'EDIT /d' gcc_error_file
  481.      ENDIF
  482.      GETFILEID gcc_error_file_id
  483.   ENDIF
  484.   IF gcc_index2err <> '' THEN
  485.      DO_ARRAY 7, gcc_index2err, 'orig.'gcc_error_index, line
  486.      .line = line
  487.   ENDIF
  488.  
  489. DEFC gcc_run_exe =
  490.   UNIVERSAL gcc_project, gcc_runtime_arguments, gcc_compile_cmd, gcc_verbose
  491.  
  492.   IF POS(TRANSLATE(LASTWORD(gcc_compile_cmd)),'JAVAC NRC') > 0 THEN
  493.      gcc_javapgm = LISTBOX('Select program:','/java/javapm/applet','/OK/Cancel',5,35)
  494.      IF gcc_javapgm = '' THEN
  495.         SAYERROR 'Cancelled'
  496.         RETURN
  497.      ENDIF
  498.   ENDIF
  499.  
  500.   buf = ENTRYBOX('Programm parameters:','/Ok/CANCEL/',gcc_runtime_arguments,
  501.                                                                   30,60,atoi(1))
  502.   button = ASC(SUBSTR(buf,1,1))
  503.   IF button <> 1 THEN
  504.      SAYERROR 'Cancelled'
  505.      RETURN
  506.   ELSE
  507.      eos = POS(\0,buf,2)
  508.      gcc_runtime_arguments = SUBSTR(buf,2,eos-2)
  509.      IF POS(TRANSLATE(LASTWORD(gcc_compile_cmd)),'JAVAC NRC') = 0 THEN
  510.         IF EXIST(gcc_project'.exe') THEN
  511.            IF gcc_verbose THEN
  512.               SAYERROR 'start /n /f'  gcc_project gcc_runtime_arguments
  513.            ENDIF
  514.            'start /n /f'  gcc_project gcc_runtime_arguments
  515.         ELSE
  516.            IF gcc_verbose THEN
  517.               SAYERROR 'start /n /f'
  518.                          SUBSTR(.filename,1,LASTPOS('.',.filename)) || 'exe ' ||
  519.                                                            gcc_runtime_arguments
  520.            ENDIF
  521.            'start /n /f' SUBSTR(.filename,1,LASTPOS('.',.filename)) || 'exe ' ||
  522.                                                           gcc_runtime_arguments
  523.         ENDIF
  524.      ELSEIF gcc_javapgm = 'applet' THEN
  525.         IF EXIST(gcc_runtime_arguments) THEN
  526.            IF gcc_verbose THEN
  527.               SAYERROR 'start /n /f applet' gcc_runtime_arguments
  528.            ENDIF
  529.            'start /n /f applet' gcc_runtime_arguments
  530.         ELSE
  531.            SAYERROR gcc_runtime_arguments 'not found'
  532.            RETURN
  533.         ENDIF
  534.      ELSE
  535.         IF EXIST(gcc_project'.class') THEN
  536.            run_class = SUBSTR(gcc_project,LASTPOS('\',gcc_project)+1)
  537.         ELSEIF EXIST(SUBSTR(.filename,1,LASTPOS('.',.filename))'class') THEN
  538.            run_class = SUBSTR(.filename,LASTPOS('\',.filename)+1)
  539.            run_class = SUBSTR(run_class,1,LASTPOS('.',run_class)-1)
  540.         ELSE
  541.            SAYERROR 'Class not found'
  542.            RETURN
  543.         ENDIF
  544.         IF gcc_verbose THEN
  545.            SAYERROR 'start /n /f' gcc_javapgm  run_class gcc_runtime_arguments
  546.         ENDIF
  547.         'start /n /f' gcc_javapgm  run_class gcc_runtime_arguments
  548.      ENDIF
  549.   ENDIF
  550.  
  551. DEFC gcc_debug_exe =
  552.   UNIVERSAL gcc_project, gcc_debug_cmd, gcc_translate, gcc_debug_arguments
  553.  
  554.   buf = ENTRYBOX('Programm parameters:','/Ok/CANCEL/',gcc_debug_arguments,
  555.                                                                   30,60,atoi(1))
  556.   button = ASC(SUBSTR(buf,1,1))
  557.   IF button <> 1 THEN
  558.      SAYERROR 'Cancelled'
  559.   ELSE
  560.      eos = POS(\0,buf,2)
  561.      gcc_debug_arguments = SUBSTR(buf,2,eos-2)
  562.      IF EXIST(gcc_project'.exe') THEN
  563.         IF gcc_translate THEN
  564.            gcc_debug_cmd TRANSLATE(gcc_project||'.exe','/','\') ||
  565.                                                            gcc_debug_arguments
  566.         ELSE
  567.            gcc_debug_cmd gcc_project||'.exe' gcc_debug_arguments
  568.         ENDIF
  569.      ELSE
  570.         IF gcc_translate THEN
  571.            gcc_debug_cmd TRANSLATE(SUBSTR(.filename,1,LASTPOS('.',.filename))||
  572.                                             'exe','/','\') gcc_debug_arguments
  573.         ELSE
  574.            gcc_debug_cmd SUBSTR(.filename,1,LASTPOS('.',.filename))|| 'exe ' ||
  575.                                                            gcc_debug_arguments
  576.         ENDIF
  577.      ENDIF
  578.   ENDIF
  579.  
  580. DEFC gcc_toggle_debug_mode =
  581.   UNIVERSAL gcc_debug, gcc_verbose
  582.   gcc_debug = NOT gcc_debug
  583.   IF gcc_verbose THEN
  584.      IF gcc_debug THEN
  585.         SAYERROR 'Debug mode = ON'
  586.      ELSE
  587.         SAYERROR 'Debug mode = OFF'
  588.      ENDIF
  589.   ENDIF
  590.  
  591. DEFC gcc_toggle_autosave_mode =
  592.   UNIVERSAL gcc_autosave, gcc_verbose
  593.   gcc_autosave = NOT gcc_autosave
  594.   IF gcc_verbose THEN
  595.      IF gcc_autosave THEN
  596.         SAYERROR 'Autosave mode = ON'
  597.      ELSE
  598.         SAYERROR 'Autosave mode = OFF'
  599.      ENDIF
  600.   ENDIF
  601.  
  602. DEFC gcc_toggle_verbose_mode =
  603.   UNIVERSAL gcc_verbose
  604.   gcc_verbose = NOT gcc_verbose
  605.   IF gcc_verbose THEN
  606.      SAYERROR 'Verbose mode = ON'
  607.   ELSE
  608.      SAYERROR 'Verbose mode = OFF'
  609.   ENDIF
  610.  
  611. DEFC gcc_toggle_remove_mode =
  612.   UNIVERSAL gcc_remove, gcc_verbose
  613.   gcc_remove = NOT gcc_remove
  614.   IF gcc_verbose THEN
  615.      IF gcc_remove THEN
  616.         SAYERROR 'Remove mode = ON'
  617.      ELSE
  618.         SAYERROR 'Remove mode = OFF'
  619.      ENDIF
  620.   ENDIF
  621.  
  622. DEFC gcc_toggle_settings_mode =
  623.   UNIVERSAL gcc_save_settings, gcc_verbose
  624.   gcc_save_settings = NOT gcc_save_settings
  625.   IF gcc_verbose THEN
  626.      IF gcc_save_settings THEN
  627.         SAYERROR 'Save settings mode = ON'
  628.      ELSE
  629.         SAYERROR 'Save settings mode = OFF'
  630.      ENDIF
  631.   ENDIF
  632.  
  633. DEFC gcc_setpos =
  634.   .line = WORD(ARG(1),1)
  635.   .col  = WORD(ARG(1),2)
  636.   IF WORDS(ARG(1)) = 3 THEN
  637.      CIRCLEIT 3, .line, .col, .col-1+WORD(ARG(1),3), 16777220, 16777218
  638.   ENDIF
  639.  
  640. /*
  641. ┌──────────────────────────────────────────────────────────────────────────────┐
  642. │  Definition of commands used from menubar/commandline                        │
  643. └──────────────────────────────────────────────────────────────────────────────┘
  644. */
  645.  
  646. DEFC gcc_prev_err =
  647.    UNIVERSAL gcc_error_file_id, gcc_error_file,
  648.              gcc_line2index, gcc_index2err, gcc_error_index
  649.  
  650.    IF gcc_line2index = '' THEN                  -- arrays not initialized
  651.       IF gcc_error_file_exists() THEN
  652.          IF gcc_create_error_index() <> 0 THEN
  653.             RETURN
  654.          ENDIF
  655.       ELSE
  656.          SAYERROR 'No compile/build-results available. Use Compile/Build first.'
  657.          RETURN
  658.       ENDIF
  659.    ENDIF
  660.  
  661.    /* if in error-file, look for previous error-line */
  662.  
  663.    GETFILEID this_file_id
  664.    IF this_file_id = gcc_error_file_id THEN       -- in error-file
  665.       n = ''
  666.       is_error_line = 1
  667.       WHILE (.line > 0) DO
  668.          do_array 7, gcc_line2index, .line, n
  669.          IF n <> '' THEN
  670.             IF is_error_line THEN
  671.                gcc_error_index = n
  672.             ELSE
  673.                gcc_error_index = n + 1
  674.             ENDIF
  675.             LEAVE
  676.          ELSEIF .line = 1 THEN
  677.             SAYERROR "No previous error!"
  678.             RETURN
  679.          ELSE                           -- try previous line
  680.            .line = .line - 1
  681.          ENDIF
  682.       ENDWHILE
  683.    ENDIF
  684.  
  685.    /* decrement error-index and lookup error */
  686.  
  687.    IF gcc_error_index < 2 THEN
  688.       SAYERROR "No previous error!"
  689.    ELSE
  690.       gcc_error_index = gcc_error_index - 1
  691.       CALL gcc_display_error()
  692.    ENDIF
  693.  
  694.  
  695. DEFC gcc_curr_err =
  696.    UNIVERSAL gcc_error_file_id, gcc_error_file,
  697.              gcc_line2index, gcc_index2err, gcc_error_index
  698.  
  699.    IF gcc_line2index = '' THEN
  700.       IF gcc_error_file_exists() THEN
  701.          IF gcc_create_error_index() <> 0 THEN
  702.             RETURN
  703.          ENDIF
  704.       ELSE
  705.          SAYERROR 'No compile/build-results available. Use Compile/Build first.'
  706.          RETURN
  707.       ENDIF
  708.    ENDIF
  709.  
  710.    /* if in error-file, check for error-line */
  711.  
  712.    GETFILEID this_file_id
  713.    IF this_file_id = gcc_error_file_id THEN       -- in error-file
  714.       n = ''
  715.       do_array 7, gcc_line2index, .line, n
  716.       IF n <> '' THEN
  717.          gcc_error_index = n
  718.       ELSE
  719.          'gcc_next_err'
  720.          RETURN
  721.       ENDIF
  722.    ENDIF
  723.    CALL gcc_display_error()
  724.  
  725.  
  726. DEFC gcc_next_err =
  727.    UNIVERSAL gcc_error_file_id, gcc_error_file,
  728.              gcc_line2index, gcc_index2err, gcc_error_index
  729.  
  730.    IF gcc_line2index = '' THEN
  731.       IF gcc_error_file_exists() THEN
  732.          IF gcc_create_error_index() <> 0 THEN
  733.             RETURN
  734.          ELSE
  735.             gcc_error_index = 0    -- first time after compile/build:
  736.          ENDIF                     -- next_err == curr_err == first error
  737.       ELSE
  738.          SAYERROR 'No compile/build-results available. Use Compile/Build first.'
  739.          RETURN
  740.       ENDIF
  741.    ENDIF
  742.  
  743.    /* if in error-file, look for next error-line */
  744.  
  745.    GETFILEID this_file_id
  746.    IF this_file_id = gcc_error_file_id THEN       -- in error-file
  747.       n = ''
  748.       is_error_line = 1
  749.       WHILE (.line <= .last) DO
  750.          do_array 7, gcc_line2index, .line, n
  751.          IF n <> '' THEN
  752.             IF is_error_line THEN
  753.                gcc_error_index = n
  754.             ELSE
  755.                gcc_error_index = n - 1
  756.             ENDIF
  757.             LEAVE
  758.          ELSEIF .line = .last THEN
  759.             SAYERROR "No more errors!"
  760.             RETURN
  761.          ELSE                           -- try the next line
  762.            is_error_line = 0
  763.            "+1"
  764.          ENDIF
  765.       ENDWHILE
  766.    ENDIF
  767.  
  768.    /* increment error-index and lookup error */
  769.  
  770.    do_array 7, gcc_index2err, 0, limit
  771.    IF gcc_error_index = limit THEN
  772.       SAYERROR "No more errors!"
  773.    ELSE
  774.       gcc_error_index = gcc_error_index + 1
  775.       CALL gcc_display_error()
  776.    ENDIF
  777.  
  778. /*
  779. ┌──────────────────────────────────────────────────────────────────────────────┐
  780. │  Procedure definitions                                                       │
  781. └──────────────────────────────────────────────────────────────────────────────┘
  782. */
  783.  
  784. DEFPROC gcc_reorder_projects =
  785.   UNIVERSAL gcc_sel_projects
  786.  
  787.   file = ARG(1)
  788.   gcc_sel_projects = '/'file || DELSTR(gcc_sel_projects,
  789.                                 POS(LOWCASE(file'/'),LOWCASE(gcc_sel_projects)),
  790.                                                                 LENGTH(file'/'))
  791.  
  792. DEFPROC get_gcc_debug_mode =
  793.   UNIVERSAL gcc_debug
  794.   RETURN gcc_debug
  795.  
  796. DEFPROC get_gcc_autosave_mode =
  797.   UNIVERSAL gcc_autosave
  798.   RETURN gcc_autosave
  799.  
  800. DEFPROC get_gcc_verbose_mode =
  801.   UNIVERSAL gcc_verbose
  802.   RETURN gcc_verbose
  803.  
  804. DEFPROC get_gcc_remove_mode =
  805.   UNIVERSAL gcc_remove
  806.   RETURN gcc_remove
  807.  
  808. DEFPROC get_gcc_settings_mode =
  809.   UNIVERSAL gcc_save_settings
  810.   RETURN gcc_save_settings
  811.  
  812. DEFPROC gcc_project_open =
  813.   UNIVERSAL gcc_project
  814.   RETURN gcc_project <> ''
  815.  
  816. DEFPROC gcc_project_file_exists =
  817.   UNIVERSAL gcc_project_file
  818.   RETURN EXIST(gcc_project_file)
  819.  
  820. DEFPROC gcc_exe_exists =
  821.   UNIVERSAL gcc_project, gcc_compile_cmd
  822.   IF POS(TRANSLATE(LASTWORD(gcc_compile_cmd)),'JAVAC NRC') = 0 THEN
  823.      RETURN EXIST(gcc_project || '.exe') OR
  824.             EXIST(SUBSTR(.filename,1,LASTPOS('.',.filename)) || 'exe')
  825.   ELSE
  826.      RETURN EXIST(gcc_project || '.class') OR
  827.             EXIST(SUBSTR(.filename,1,LASTPOS('.',.filename)) || 'class')
  828.   ENDIF
  829.  
  830. DEFPROC gcc_error_file_exists =
  831.   UNIVERSAL gcc_project, gcc_error_file
  832.   RETURN gcc_error_file <> '' OR  EXIST(gcc_project || '.err') OR
  833.          EXIST(SUBSTR(.filename,1,LASTPOS('.',.filename)) || 'err')
  834.  
  835. DEFPROC gcc_is_cc_file =
  836.   ext = FILETYPE()
  837.   RETURN WORDPOS(ext,GCC_EXTENSIONS) > 0
  838.  
  839. DEFPROC gcc_next_error =
  840.    UNIVERSAL gcc_error_file_id, gcc_other_file_id, gcc_error_file
  841.  
  842.    IF gcc_error_file_id = '' THEN
  843.       IF gcc_error_file_exists() THEN
  844.          'gcc_view_results'
  845.       ELSE
  846.          SAYERROR 'No compile/build-results available. Use Compile/Build first.'
  847.       ENDIF
  848.       RETURN
  849.    ENDIF
  850.  
  851.    GETFILEID gcc_other_file_id
  852.    IF gcc_other_file_id <> gcc_error_file_id THEN      -- not in error-file
  853.      'gcc_next_err'
  854.    ELSE
  855.      'gcc_curr_err'
  856.    ENDIF
  857.  
  858. DEFPROC gcc_resolve_template =
  859.    UNIVERSAL gcc_project_file, gcc_translate
  860.  
  861.    template = ARG(1)
  862.    option   = ARG(2)    -- C for compile and M for make
  863.  
  864.    IF option = 'C' THEN
  865.       file = .filename
  866.    ELSE
  867.       file = gcc_project_file
  868.    ENDIF
  869.    path = SUBSTR(file,1,LASTPOS('\',file))
  870.    IF SUBSTR(file,2,1) = ':' THEN
  871.        drive = SUBSTR(file,1,2)
  872.    ELSE
  873.        drive = ''
  874.    ENDIF
  875.    fname = DELSTR(file,1,LENGTH(path))
  876.    name  = SUBSTR(fname,1,LASTPOS('.',fname)-1)
  877.    ext   = DELSTR(fname,1,LENGTH(name)+1)
  878.  
  879.    col = POS('%**E',template)
  880.    WHILE col > 0 DO
  881.       template = DELSTR(template,col,4)
  882.       template = SUBSTR(template,1,col-1) || ext || SUBSTR(template,col)
  883.       col = POS('%**E',template)
  884.    ENDWHILE
  885.    col = POS('%**N',template)
  886.    WHILE col > 0 DO
  887.       template = DELSTR(template,col,4)
  888.       template = SUBSTR(template,1,col-1) || name || SUBSTR(template,col)
  889.       col = POS('%**N',template)
  890.    ENDWHILE
  891.    col = POS('%**F',template)
  892.    WHILE col > 0 DO
  893.       template = DELSTR(template,col,4)
  894.       template = SUBSTR(template,1,col-1) || fname || SUBSTR(template,col)
  895.       col = POS('%**F',template)
  896.    ENDWHILE
  897.    col = POS('%**P',template)
  898.    WHILE col > 0 DO
  899.       template = DELSTR(template,col,4)
  900.       template = SUBSTR(template,1,col-1) || path || SUBSTR(template,col)
  901.       col = POS('%**P',template)
  902.    ENDWHILE
  903.    col = POS('%**D',template)
  904.    WHILE col > 0 DO
  905.       template = DELSTR(template,col,4)
  906.       template = SUBSTR(template,1,col-1) || drive || SUBSTR(template,col)
  907.       col = POS('%**D',template)
  908.    ENDWHILE
  909.    col = POS('%*',template)
  910.    WHILE col > 0 DO
  911.       template = DELSTR(template,col,2)
  912.       template = SUBSTR(template,1,col-1) || file || SUBSTR(template,col)
  913.       col = POS('%*',template)
  914.    ENDWHILE
  915.  
  916.    IF gcc_translate THEN
  917.       RETURN TRANSLATE(template,'/','\')
  918.    ELSE
  919.       RETURN template
  920.    ENDIF
  921.  
  922. DEFPROC gcc_create_error_index =
  923.    UNIVERSAL gcc_project, gcc_error_file, gcc_error_file_id,
  924.              gcc_line2index, gcc_index2err, gcc_error_index
  925.  
  926.    /* create arrays   ------------------------------------------------------- */
  927.  
  928.    DO_ARRAY 1, gcc_line2index, 'gcc_line2index'     -- line to error number
  929.    DO_ARRAY 1, gcc_index2err,  'gcc_index2err'      -- number to message
  930.  
  931.    current_line_this_file = .line
  932.    GETFILEID this_file_id
  933.    IF gcc_error_file = '' THEN                -- no compile/build, but maybe the
  934.       IF EXIST(gcc_project'.err') THEN        -- error-file is still on disk
  935.          gcc_error_file = gcc_project'.err'
  936.       ELSEIF EXIST(SUBSTR(.filename,1,LASTPOS('.',.filename)) || 'err') THEN
  937.          gcc_error_file = SUBSTR(.filename,1,LASTPOS('.',.filename)) || 'err'
  938.       ELSE
  939.          SAYERROR 'No compile/build-results available. Use Compile/Build first.'
  940.          RETURN 3
  941.       ENDIF
  942.    ENDIF
  943.    IF gcc_error_file_id = '' THEN
  944.       'EDIT /d' gcc_error_file
  945.       GETFILEID gcc_error_file_id
  946.    ELSEIF this_file_id <> gcc_error_file_id THEN
  947.       ACTIVATEFILE gcc_error_file_id
  948.    ENDIF
  949.  
  950.    /* parse whole file and fill arrays   ------------------------------------ */
  951.  
  952.    SAYERROR 'Parsing errors ...'
  953.    current_line_error_file = .line
  954.    .line = 1
  955.    .col  = 1
  956.    'gcc_parse_error all'
  957.    .line = current_line_error_file
  958.  
  959.    limit = ''
  960.    DO_ARRAY 7, gcc_index2err, 0, limit
  961.    IF limit <> '' THEN
  962.       gcc_error_index = 1
  963.       rc = 0
  964.    ELSE
  965.       SAYERROR 'No compile errors!'
  966.       rc = 2
  967.    ENDIF
  968.    ACTIVATEFILE this_file_id
  969.    .line = current_line_this_file
  970.    RETURN rc
  971.  
  972.  
  973. DEFPROC gcc_display_error =
  974.    UNIVERSAL gcc_index2err, gcc_error_index
  975.  
  976.    DO_ARRAY 7, gcc_index2err, 'line.'gcc_error_index, lineno
  977.    DO_ARRAY 7, gcc_index2err, 'col.'gcc_error_index, col
  978.    DO_ARRAY 7, gcc_index2err, 'len.'gcc_error_index, len
  979.    DO_ARRAY 7, gcc_index2err, 'file.'gcc_error_index, filename
  980.    DO_ARRAY 7, gcc_index2err, 'msg.'gcc_error_index, gcc_message
  981.  
  982.    "EDIT" TRANSLATE(filename,'\','/') "'gcc_setpos "lineno col len"'"
  983.    SAYERROR gcc_message
  984.  
  985. DEFPROC gcc_delete_arrays =
  986.    UNIVERSAL gcc_line2index, gcc_index2err, gcc_error_index
  987.  
  988.    IF gcc_line2index <> '' THEN
  989.       GETFILEID this_file_id
  990.       ACTIVATEFILE gcc_line2index
  991.       'XCOM QUIT'
  992.       ACTIVATEFILE gcc_index2err
  993.       'XCOM QUIT'
  994.       ACTIVATEFILE this_file_id
  995.       gcc_line2index  = ''
  996.       gcc_index2err   = ''
  997.       gcc_error_index = 0
  998.    ENDIF
  999.