home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 12 / CD_ASCQ_12_0294.iso / vrac / epmgcc10.zip / GCCPROC.E < prev    next >
Text File  |  1994-01-29  |  13KB  |  383 lines

  1. /*
  2. ╔══════════════════════════════════════════════════════════════════════════════╗
  3. ║ What's it called: EPMGCC  V1.00                                              ║
  4. ║                                                                              ║
  5. ║ What does it do:  The E source code for the GCC-Interface for EPM.           ║
  6. ║                   This file contains the command and procedure definitions   ║
  7. ║                   and is linked separately because of the size limitation    ║
  8. ║                   of epm.ex (64K).                                           ║
  9. ║                                                                              ║
  10. ║ Who and When:     B. Bablok 12/93 - 01/94                                    ║
  11. ║                                                                              ║
  12. ╚══════════════════════════════════════════════════════════════════════════════╝
  13.  
  14. ┌──────────────────────────────────────────────────────────────────────────────┐
  15. │  Definitions of external commands, if not defined in gccenv.e                │
  16. └──────────────────────────────────────────────────────────────────────────────┘
  17. */
  18. TRYINCLUDE 'gccenv.e'
  19.  
  20. COMPILE IF not defined(GCC_EDIT_COMMAND)
  21.    CONST   GCC_EDIT_COMMAND = 'start /c /win epro'
  22. COMPILE ENDIF
  23.  
  24. COMPILE IF not defined(GCC_COMP_COMMAND)
  25.    CONST   GCC_COMP_COMMAND = 'start /n /win gcc'
  26. COMPILE ENDIF
  27.  
  28. COMPILE IF not defined(GCC_BUILD_COMMAND)
  29.    CONST   GCC_BUILD_COMMAND = 'start /n /win make'
  30. COMPILE ENDIF
  31.  
  32. COMPILE IF not defined(GCC_DEBUG_COMMAND)
  33.    CONST   GCC_DEBUG_COMMAND = 'start /n /win gdb'
  34. COMPILE ENDIF
  35. /*
  36. ┌──────────────────────────────────────────────────────────────────────────────┐
  37. │  Command definitions (menu commands)                                         │
  38. └──────────────────────────────────────────────────────────────────────────────┘
  39. */
  40. DEFC open_project =
  41.   UNIVERSAL gcc_project_file, gcc_project, gcc_error_file, gcc_error_file_id
  42.  
  43.   gcc_project_file = ENTRYBOX('Make-file name:','/Ok/Cancel/',
  44.                                                          gcc_project_file,20,40)
  45.   gcc_project = SUBSTR(gcc_project_file,1,LASTPOS('.',gcc_project_file)-1)
  46.   gcc_error_file    = ''
  47.   gcc_error_file_id = ''
  48.  
  49. DEFC edit_project =
  50.   UNIVERSAL gcc_project_file
  51.   GCC_EDIT_COMMAND gcc_project_file
  52.  
  53. DEFC close_project =
  54.   UNIVERSAL gcc_project, gcc_project_file, gcc_error_file, gcc_error_file_id
  55.   gcc_project       = ''
  56.   gcc_project_file  = ''
  57.   gcc_error_file    = ''
  58.   gcc_error_file_id = ''
  59.  
  60. DEFC set_comp_options =
  61.   UNIVERSAL gcc_d_comp_options, gcc_p_comp_options, gcc_debug
  62.  
  63.   IF gcc_debug THEN
  64.     buf = ENTRYBOX('Compile parameters (debug):','/Ok/CANCEL/',
  65.                                               gcc_d_comp_options,30,100,atoi(1))
  66.   ELSE
  67.     buf = ENTRYBOX('Compile parameters (prod):','/Ok/CANCEL/',
  68.                                               gcc_p_comp_options,30,100,atoi(1))
  69.   ENDIF
  70.   button = ASC(SUBSTR(buf,1,1))
  71.   IF button <> 1 THEN
  72.      SAYERROR 'Cancelled'
  73.   ELSE
  74.      eos = POS(\0,buf,2)
  75.      IF gcc_debug THEN
  76.         gcc_d_comp_options = SUBSTR(buf,2,eos-2)
  77.      ELSE
  78.         gcc_p_comp_options = SUBSTR(buf,2,eos-2)
  79.      ENDIF
  80.   ENDIF
  81.  
  82. DEFC compile_file =
  83.   UNIVERSAL gcc_error_file, gcc_error_file_id, gcc_autosave, gcc_verbose,
  84.             gcc_debug, gcc_d_comp_options, gcc_p_comp_options
  85.  
  86.   IF .modify THEN
  87.      IF gcc_autosave THEN
  88.         'Save'
  89.          SAYERROR 'Saving file before invoking gcc!'
  90.      ELSE
  91.          SAYERROR 'Warning: File not saved! Compiling old version!'
  92.      ENDIF
  93.   ENDIF
  94.  
  95.   gcc_error_file = SUBSTR(.filename,1,LASTPOS('.',.filename)) || 'err'
  96.  
  97.   IF gcc_debug THEN
  98.      command = gcc_resolve_template(gcc_d_comp_options,'C') '> ' ||
  99.                                                            gcc_error_file '2>&1'
  100.   ELSE
  101.      command = gcc_resolve_template(gcc_p_comp_options,'C') '> ' ||
  102.                                                            gcc_error_file '2>&1'
  103.   ENDIF
  104.  
  105.   IF gcc_verbose THEN
  106.      SAYERROR GCC_COMP_COMMAND command
  107.   ENDIF
  108.   GCC_COMP_COMMAND command
  109.   IF rc <> 0 THEN
  110.      SAYERROR 'Error invoking GCC, RC =' rc
  111.   ELSE
  112.      gcc_error_file_id = ''                   -- reset error_file_id
  113.   ENDIF
  114.  
  115. DEFC set_make_options =
  116.   UNIVERSAL gcc_d_make_options, gcc_p_make_options, gcc_debug
  117.  
  118.   IF gcc_debug THEN
  119.     buf = ENTRYBOX('Build parameters (debug):','/Ok/CANCEL/',
  120.                                               gcc_d_make_options,30,100,atoi(1))
  121.   ELSE
  122.     buf = ENTRYBOX('Build parameters (prod):','/Ok/CANCEL/',
  123.                                               gcc_p_make_options,30,100,atoi(1))
  124.   ENDIF
  125.   button = ASC(SUBSTR(buf,1,1))
  126.   IF button <> 1 THEN
  127.      SAYERROR 'Cancelled'
  128.   ELSE
  129.      eos = POS(\0,buf,2)
  130.      IF gcc_debug THEN
  131.         gcc_d_make_options = SUBSTR(buf,2,eos-2)
  132.      ELSE
  133.         gcc_p_make_options = SUBSTR(buf,2,eos-2)
  134.      ENDIF
  135.   ENDIF
  136.  
  137. DEFC build_project =
  138.   UNIVERSAL gcc_error_file, gcc_project_file, gcc_project, gcc_verbose,
  139.             gcc_debug, gcc_error_file_id, gcc_d_make_options,
  140.             gcc_p_make_options, gcc_autosave
  141.  
  142.   IF gcc_autosave THEN
  143.      SAYERROR 'Saving files before invoking make!'
  144.      GETFILEID StartFileID
  145.      LOOP
  146.         IF .modify THEN
  147.            'Save'
  148.         ENDIF
  149.         NEXTFILE
  150.         GETFILEID NextFileID
  151.         IF NextFileID = StartFileID THEN
  152.            LEAVE
  153.         ENDIF
  154.         ACTIVATEFILE NextFileID
  155.      ENDLOOP
  156.      ACTIVATEFILE StartFileID
  157.   ENDIF
  158.  
  159.   gcc_error_file = gcc_project || '.err' -- intervening compile_file is possible
  160.   IF gcc_debug THEN
  161.      command = gcc_resolve_template(gcc_d_make_options,'M') '> ' ||
  162.                                                            gcc_error_file '2>&1'
  163.   ELSE
  164.      command = gcc_resolve_template(gcc_p_make_options,'M') '> ' ||
  165.                                                            gcc_error_file '2>&1'
  166.   ENDIF
  167.  
  168.   IF gcc_verbose THEN
  169.      SAYERROR GCC_BUILD_COMMAND command
  170.   ENDIF
  171.   GCC_BUILD_COMMAND command
  172.   IF rc <> 0 THEN
  173.      SAYERROR 'Error invoking MAKE, RC =' rc
  174.   ELSE
  175.      gcc_error_file_id = ''                   -- reset error_file_id
  176.   ENDIF
  177.  
  178. DEFC view_results =
  179.   UNIVERSAL gcc_project, gcc_error_file, gcc_error_file_id
  180.   IF gcc_error_file <> '' THEN
  181.      'EDIT /d' gcc_error_file
  182.   ELSEIF EXIST(gcc_project'.err') THEN
  183.      gcc_error_file = gcc_project'.err'
  184.      'EDIT /d' gcc_error_file
  185.   ELSEIF EXIST(SUBSTR(.filename,1,LASTPOS('.',.filename)) || 'err') THEN
  186.      gcc_error_file = SUBSTR(.filename,1,LASTPOS('.',.filename)) || 'err'
  187.      'EDIT /d' gcc_error_file
  188.   ENDIF
  189.   GETFILEID gcc_error_file_id
  190.  
  191. DEFC run_exe =
  192.   UNIVERSAL gcc_project, gcc_runtime_arguments
  193.   buf = ENTRYBOX('Programm parameters:','/Ok/CANCEL/',gcc_runtime_arguments,
  194.                                                                   30,60,atoi(1))
  195.   button = ASC(SUBSTR(buf,1,1))
  196.   IF button <> 1 THEN
  197.      SAYERROR 'Cancelled'
  198.   ELSE
  199.      eos = POS(\0,buf,2)
  200.      gcc_runtime_arguments = SUBSTR(buf,2,eos-2)
  201.      IF EXIST(gcc_project'.exe') THEN
  202.         'start /n /win' gcc_project gcc_runtime_arguments
  203.      ELSE
  204.         'start /n /win' SUBSTR(.filename,1,LASTPOS('.',.filename)) || 'exe ' ||
  205.                                                            gcc_runtime_arguments
  206.      ENDIF
  207.   ENDIF
  208.  
  209. DEFC debug_exe =
  210.   UNIVERSAL gcc_project
  211.  
  212.   IF EXIST(gcc_project'.exe') THEN
  213.      GCC_DEBUG_COMMAND gcc_project || '.exe'
  214.   ELSE
  215.      GCC_DEBUG_COMMAND SUBSTR(.filename,1,LASTPOS('.',.filename)) || 'exe'
  216.   ENDIF
  217.  
  218. DEFC toggle_debug_mode =
  219.   UNIVERSAL gcc_debug, gcc_verbose
  220.   gcc_debug = NOT gcc_debug
  221.   IF gcc_verbose THEN
  222.       SAYERROR 'gcc_debug = 'gcc_debug
  223.   ENDIF
  224.  
  225. DEFC toggle_autosave_mode =
  226.   UNIVERSAL gcc_autosave, gcc_verbose
  227.   gcc_autosave = NOT gcc_autosave
  228.   IF gcc_verbose THEN
  229.       SAYERROR 'gcc_autosave = 'gcc_autosave
  230.   ENDIF
  231.  
  232. DEFC toggle_verbose_mode =
  233.   UNIVERSAL gcc_verbose
  234.   gcc_verbose = NOT gcc_verbose
  235.   IF gcc_verbose THEN
  236.       SAYERROR 'gcc_verbose = 'gcc_verbose
  237.   ENDIF
  238. /*
  239. ┌──────────────────────────────────────────────────────────────────────────────┐
  240. │  Procedure definitions                                                       │
  241. └──────────────────────────────────────────────────────────────────────────────┘
  242. */
  243.  
  244. DEFPROC get_gcc_debug_mode =
  245.   UNIVERSAL gcc_debug
  246.   RETURN gcc_debug
  247.  
  248. DEFPROC get_gcc_autosave_mode =
  249.   UNIVERSAL gcc_autosave
  250.   RETURN gcc_autosave
  251.  
  252. DEFPROC get_gcc_verbose_mode =
  253.   UNIVERSAL gcc_verbose
  254.   RETURN gcc_verbose
  255.  
  256. DEFPROC gcc_project_open =
  257.   UNIVERSAL gcc_project
  258.   RETURN gcc_project <> ''
  259.  
  260. DEFPROC gcc_project_file_exists =
  261.   UNIVERSAL gcc_project_file
  262.   RETURN EXIST(gcc_project_file)
  263.  
  264. DEFPROC gcc_exe_exists =
  265.   UNIVERSAL gcc_project
  266.   RETURN EXIST(gcc_project || '.exe') OR
  267.          EXIST(SUBSTR(.filename,1,LASTPOS('.',.filename)) || 'exe')
  268.  
  269. DEFPROC gcc_error_file_exists =
  270.   UNIVERSAL gcc_project, gcc_error_file
  271.   RETURN gcc_error_file <> '' OR  EXIST(gcc_project || '.err') OR
  272.          EXIST(SUBSTR(.filename,1,LASTPOS('.',.filename)) || 'err')
  273.  
  274. DEFPROC gcc_is_cc_file =
  275.   ext = FILETYPE()
  276.   RETURN WORDPOS(ext,'CC C CXX CPP') > 0
  277.  
  278. DEFPROC gcc_next_error =
  279.    UNIVERSAL gcc_error_file_id, gcc_other_file_id, gcc_error_file
  280.  
  281.    IF gcc_error_file_id = '' THEN
  282.       IF gcc_error_file_exists() THEN
  283.          'view_results'
  284.       ELSE
  285.          SAYERROR 'No compile/build-results available. Use Compile/Build first.'
  286.       ENDIF
  287.       RETURN
  288.    ENDIF
  289.  
  290.    GETFILEID gcc_other_file_id
  291.    IF gcc_other_file_id <> gcc_error_file_id THEN      -- not in error-file
  292.      ACTIVATEFILE gcc_error_file_id                    -- switch to error-file
  293.      IF .line = .last THEN                             -- no more errors
  294.        ACTIVATEFILE gcc_other_file_id                  -- go back
  295.        SAYERROR "No more errors!"
  296.        RETURN
  297.      ELSE
  298.        "+1"                                            -- next line
  299.      ENDIF
  300.    ENDIF
  301.  
  302.    WHILE (.line <= .last) DO           -- iterate until a "true" error is found
  303.      GETLINE  line                     -- errors look like file.c:12: message
  304.      IF SUBSTR(line,2,1) = ":" THEN
  305.         PARSE VALUE line WITH drive ":" filename ":" lineno ":" gcc_message
  306.         filename = drive":"filename
  307.      ELSE
  308.         PARSE VALUE line WITH filename ":" lineno ":" gcc_message
  309.      ENDIF
  310.      IF NOT ISNUM(lineno) OR POS(":",WORD(line,1)) = 0 THEN
  311.        IF .line = .last THEN
  312.           SAYERROR "No more errors!"
  313.           RETURN
  314.        ELSE                           -- try the next line
  315.          "+1"
  316.        ENDIF
  317.      ELSE                             -- found an error
  318.        "EDIT" TRANSLATE(filename,'\','/') "'"lineno"'"
  319.        SAYERROR gcc_message
  320.        RETURN
  321.      ENDIF
  322.    ENDWHILE
  323.  
  324. DEFPROC gcc_resolve_template =
  325.    UNIVERSAL gcc_project_file
  326.  
  327.    template = ARG(1)
  328.    option   = ARG(2)    -- C for compile and M for make
  329.  
  330.    IF option = 'C' THEN
  331.       file = .filename
  332.    ELSE
  333.       file = gcc_project_file
  334.    ENDIF
  335.    path = SUBSTR(file,1,LASTPOS('\',file))
  336.    IF SUBSTR(file,2,1) = ':' THEN
  337.        drive = SUBSTR(file,1,2)
  338.    ELSE
  339.        drive = ''
  340.    ENDIF
  341.    fname = DELSTR(file,1,LENGTH(path))
  342.    name  = SUBSTR(fname,1,LASTPOS('.',fname)-1)
  343.    ext   = DELSTR(fname,1,LENGTH(name)+1)
  344.  
  345.    col = POS('%**E',template)
  346.    WHILE col > 0 DO
  347.       template = DELSTR(template,col,4)
  348.       template = SUBSTR(template,1,col-1) || ext || SUBSTR(template,col)
  349.       col = POS('%**E',template)
  350.    ENDWHILE
  351.    col = POS('%**N',template)
  352.    WHILE col > 0 DO
  353.       template = DELSTR(template,col,4)
  354.       template = SUBSTR(template,1,col-1) || name || SUBSTR(template,col)
  355.       col = POS('%**N',template)
  356.    ENDWHILE
  357.    col = POS('%**F',template)
  358.    WHILE col > 0 DO
  359.       template = DELSTR(template,col,4)
  360.       template = SUBSTR(template,1,col-1) || fname || SUBSTR(template,col)
  361.       col = POS('%**F',template)
  362.    ENDWHILE
  363.    col = POS('%**P',template)
  364.    WHILE col > 0 DO
  365.       template = DELSTR(template,col,4)
  366.       template = SUBSTR(template,1,col-1) || path || SUBSTR(template,col)
  367.       col = POS('%**P',template)
  368.    ENDWHILE
  369.    col = POS('%**D',template)
  370.    WHILE col > 0 DO
  371.       template = DELSTR(template,col,4)
  372.       template = SUBSTR(template,1,col-1) || drive || SUBSTR(template,col)
  373.       col = POS('%**D',template)
  374.    ENDWHILE
  375.    col = POS('%*',template)
  376.    WHILE col > 0 DO
  377.       template = DELSTR(template,col,2)
  378.       template = SUBSTR(template,1,col-1) || file || SUBSTR(template,col)
  379.       col = POS('%*',template)
  380.    ENDWHILE
  381.  
  382.    RETURN TRANSLATE(template,'/','\')
  383.