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

  1. /*
  2.  * finder.ged -- Find and load class under cursor.
  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: finder.ged 2.0 (15.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=6'                    /* 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.  
  27. CALL ADDLIB('rexxsupport.library', 0, -30, 2)
  28.  
  29. 'QUERY WORD VAR=class_name'
  30.  
  31. legal_letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890'
  32. IF (Strip(Upper(class_name), 'B', legal_letters) = '') ,
  33.    & (class_name ~= '') THEN ,
  34. DO
  35.    temporary_file = 't:finder.tmp'
  36.    class_found = 0
  37.  
  38.    finder_command = d2c(39) || 'finder >' || temporary_file || ' ' || class_name || d2c(39)
  39.    ADDRESS COMMAND 'rx "address command ' || finder_command  || '"'
  40.  
  41.    IF RC = 0 THEN DO
  42.       IF OPEN('full_path', temporary_file, 'read') THEN DO
  43.          class_found = 1
  44.          class_path = READLN('full_path')
  45.          'WINDOW FORCE USE="' || class_path || '"'
  46.          CALL CLOSE('full_path')
  47.          CALL DELETE(temporary_file)
  48.       END
  49.    END
  50.  
  51.    IF ~class_found THEN DO
  52.       'REQUEST STATUS=""'
  53.       'REQUEST TITLE="Find Class Error" PROBLEM="Class ''' || class_name || ''' not found."'
  54.    END
  55.  
  56. END
  57. ELSE DO
  58.    'REQUEST TITLE="Find Class Error" PROBLEM="Cursor must be placed over a proper class name."'
  59. END
  60.  
  61.  
  62. /* ---------------------------- END OF YOUR CODE --------------------- */
  63.  
  64. 'UNLOCK' /* VERY important: unlock GUI */
  65.  
  66. exit
  67.  
  68. SYNTAX:
  69.  
  70.    SAY "Syntax error line" SIGL ":" ERRORTEXT(RC)
  71.    'UNLOCK'
  72.  
  73.    exit
  74.  
  75. /***** ugly/convert_amiga_path_to_uri **************************************
  76.  * NAME
  77.  *   convert_amiga_path_to_uri -- Convert path from Amiga to URI style
  78.  * FUNCTION
  79.  *   Convert path from Amiga to URI style. The following conversion rules
  80.  *   are applied:
  81.  *
  82.  *   - Device names are transformed from e.g. "ram:" to "/ram/"
  83.  *   - Leading "/"'s replaced by "../"
  84.  *   - All "//"'s are replaced by "/../"
  85.  * INPUTS
  86.  *   amiga_path - Amiga style path
  87.  * RESULT
  88.  *   Path in URI style
  89.  * BUGS
  90.  *   The input path is not validated for correctness. In such a case the
  91.  *   result will also be invalid.
  92.  * EXAMPLES
  93.  *   "ram:"           -> "/ram/"
  94.  *   "ram:sepp"       -> "/ram/sepp"
  95.  *   "sepp//resi"     -> "sepp/../resi"
  96.  *   "ram:sepp//resi" -> "/ram/sepp/../resi"
  97.  *   "//resi/hugo"    -> "../../resi/hugo"
  98.  *   "//resi//hugo"   -> "../../resi/../hugo
  99.  **************************************************************************/
  100. convert_amiga_path_to_uri : PROCEDURE
  101.     PARSE ARG amiga_path
  102.  
  103.     uri = ''
  104.  
  105.     /* Extract device name from Amigapath (if there is any) */
  106.     device = ''
  107.     IF (POS(':', amiga_path) > 0) THEN DO
  108.         PARSE VAR amiga_path device ':' path_part
  109.         amiga_path = path_part
  110.     END
  111.  
  112.     /* Convert leading "/" to "../" */
  113.     DO WHILE (LEFT(amiga_path, 1) = '/')
  114.         amiga_path = DELSTR(amiga_path, 1, 1)
  115.         uri = uri || '../'
  116.     END
  117.  
  118.     uri = uri || amiga_path
  119.  
  120.     /* Convert '//' inside string to '/../' */
  121.     DO WHILE (POS('//', uri) > 0)
  122.         PARSE VAR uri before '//' after
  123.         uri = before || '/../' || after
  124.     END
  125.  
  126.     /* Add device name in Unix-style;
  127.      * 'ram:' becomes '/ram/' */
  128.     IF (device ~= '') THEN DO
  129.         uri = '/' || device || '/' || uri
  130.     END
  131.  
  132.     RETURN uri
  133.  
  134. /***** ugly/convert_uri_to_amiga_path **************************************
  135.  * NAME
  136.  *   convert_uri_to_amiga_path -- Convert path from URI to Amiga style
  137.  * SYNOPSIS
  138.  *   amiga_path = convert_uri_to_amiga_path( uri )
  139.  * FUNCTION
  140.  *   Convert path from URI to Amiga style. The following conversion rules
  141.  *   are applied:
  142.  *
  143.  *   - Remove leading './'
  144.  *   - Replace every leading '../' by '/'
  145.  *   - Replace every '/../' by '//'
  146.  *   - Replace every '~' by '%7E'
  147.  * INPUTS
  148.  *   uri - URI style path
  149.  * RESULT
  150.  *   amiga_path - Amiga style path
  151.  * BUGS
  152.  *   The input path is not validated for correctness. In such a case the
  153.  *   result will also be invalid.
  154.  *
  155.  *   Devices in URI style are not handled.
  156.  **************************************************************************/
  157. convert_uri_to_amiga_path : PROCEDURE
  158.     PARSE ARG uri
  159.  
  160.     amiga_path = ''
  161.  
  162.     /* Remove leading "./" */
  163.     IF (LEFT(uri, 2) = './')
  164.         uri = DELSTR(uri, 1, 2)
  165.     END
  166.  
  167.     /* Replace leading "../" by "/" */
  168.     DO WHILE (LEFT(uri, 3) = '../')
  169.         uri = DELSTR(uri, 1, 3)
  170.         amiga_path = amiga_path || '/'
  171.     END
  172.  
  173.     amiga_path = amiga_path || uri
  174.  
  175.     /* Replace '/../' inside string by '//' */
  176.     DO WHILE (POS('//', uri) > 0)
  177.         PARSE VAR uri before '/../' after
  178.         amiga_path = before || '//' || after
  179.     END
  180.  
  181.     /* Replace '~' by '%7E' */
  182.     DO WHILE (POS('~', uri) > 0)
  183.         PARSE VAR uri before '~' after
  184.         amiga_path = before || '%7E' || after
  185.     END
  186.  
  187.     RETURN amiga_path
  188.  
  189.  
  190.