home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 4 / AACD04.ISO / AACD / Programming / envsof20 / eiffel / rexx / reformat.ged < prev    next >
Encoding:
Text File  |  1999-08-29  |  2.4 KB  |  102 lines

  1. /*
  2.  * reformat.ged -- Reformat Eiffel source using SmallEiffel's `pretty'.
  3.  *
  4.  * Copyright (C) 1999 Thomas Aglassiner <agi@sbox.tu-graz.ac.at>
  5.  * Freeware. Use at your own risk.
  6.  */
  7. version_info = "$VER: reformat.ged 1.4 (29.8.99)"
  8.  
  9. OPTIONS RESULTS                             /* enable return codes     */
  10.  
  11. if (LEFT(ADDRESS(), 6) ~= "GOLDED") then    /* not started by GoldEd ? */
  12.     address 'GOLDED.1'
  13.  
  14. 'LOCK CURRENT RELEASE=4'                    /* lock GUI, gain access   */
  15.  
  16. if (RC ~= 0) then
  17.     exit
  18.  
  19. OPTIONS FAILAT 21
  20.  
  21. SIGNAL ON SYNTAX                            /* ensure clean exit       */
  22.  
  23. /* ------------------------ INSERT YOUR CODE HERE: ------------------- */
  24.  
  25. rexx_path = 'GoldEd:add-ons/eiffel/rexx/'
  26. execute_command = rexx_path || 'execute.rexx'
  27.  
  28. pretty_options = '-default'
  29.  
  30. CALL ADDLIB('rexxdossupport.library', 0, -30, 2)
  31.  
  32. /* Obtain current filename */
  33. 'QUERY DOC VAR=filename'
  34.  
  35. IF RIGHT(filename,2) = '.e' THEN DO
  36.  
  37.    'REQUEST STATUS="Reformatting..."'
  38.  
  39.    /* Save file, remember current position */
  40.    'SAVE ALL'
  41.    'QUERY ABSLINE VAR=old_line'
  42.    'QUERY COLUMN VAR=old_column'
  43.  
  44.    /* Split filename to path and plain name */
  45.    delimiter_index = MAX(LASTPOS(':', filename), LASTPOS('/', filename))
  46.    directory = LEFT(filename, delimiter_index)
  47.    filename = SUBSTR(filename, delimiter_index + 1)
  48.  
  49.    /* Change to directory where file is located to avoid problems
  50.     * with non-ixemul paths */
  51.    CALL PRAGMA('Directory', directory)
  52.  
  53.    /* Delete possible backup */
  54.    backup_name = LEFT(filename, LENGTH(filename) - 1) || 'bak'
  55.    CALL Delete(backup_name)
  56.  
  57.    ADDRESS COMMAND 'pretty ' || pretty_options || ' "' || filename || '"'
  58.  
  59.    'REQUEST STATUS=""'
  60.    IF RC = 0 THEN DO
  61.       'OPEN AGAIN FORCE'
  62.       CALL Delete(backup_name)
  63.    END
  64.    ELSE DO
  65.       'REQUEST PROBLEM="Cannot reformat document.*NFix errors in source code and try again."'
  66.    END
  67.  
  68.    /* Restore position in editor */
  69.    'QUERY ABSLINES VAR=lines'
  70.    if old_line > lines then do
  71.       'GOTO BOTTOM'
  72.    end
  73.    else do
  74.       'GOTO LINE=' || old_line
  75.    end
  76.    'QUERY COLUMNS VAR=columns'
  77.    if old_column > columns then do
  78.       'GOTO EOL'
  79.    end
  80.    else do
  81.       'GOTO COLUMN=' || old_column
  82.    end
  83.  
  84. END
  85. ELSE DO
  86.    'REQUEST PROBLEM="Filename suffix for ''pretty'' must be ''.e''"'
  87. END
  88.  
  89.  
  90. /* ---------------------------- END OF YOUR CODE --------------------- */
  91.  
  92. 'UNLOCK' /* VERY important: unlock GUI */
  93.  
  94. exit
  95.  
  96. SYNTAX:
  97.  
  98.    SAY "Syntax error line" SIGL ":" ERRORTEXT(RC)
  99.    'UNLOCK'
  100.  
  101.    exit
  102.