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

  1. /* new_class.ged -- Create new Eiffel class using template.
  2.  *
  3.  * $VER: new_class.ged 1.0 (29.8.99)
  4.  */
  5.  
  6. template_file = 'GoldEd:add-ons/eiffel/template/new_class.e'
  7.  
  8. OPTIONS RESULTS
  9.  
  10. if (LEFT(ADDRESS(), 6) ~= 'GOLDED') then
  11.  
  12.     address 'GOLDED.1'
  13.  
  14. 'LOCK CURRENT RELEASE=6'
  15.  
  16. if (RC ~= 0) then
  17.     exit
  18.  
  19. OPTIONS FAILAT 6
  20.  
  21. SIGNAL ON SYNTAX
  22.  
  23. 'REQUEST VAR=class_name STRING TITLE="New class..." BODY="Type name of new class*N(Without path or .e suffix)"'
  24. if RC = 0 then do
  25.    digits_and_underscore =  '_1234567890'
  26.    lower_letters = 'abcdefghijklmnopqrstuvwxyz'
  27.    upper_letters = Upper(lower_letters)
  28.  
  29.    /* Validate class name */
  30.    error_message = ''
  31.    if Verify(class_name, lower_letters || upper_letters || digits_and_underscore) ~= 0 then do
  32.       error_message = 'Class name must only contain letters, numbers and underscores (_)'
  33.    end
  34.    else if Pos(Left(class_name, 1), digits_and_underscore) > 0 then do
  35.       error_message = 'Numbers and underscore (_) must occur after the first letter'
  36.    end
  37.  
  38.    if error_message = '' then do
  39.       class_name = Upper(class_name)
  40.       class_file = Translate(class_name, lower_letters, upper_letters) || '.e'
  41.  
  42.       /* Remember state of search requester */
  43.       'QUERY NAME=FIND VAR=old_find'
  44.       'QUERY NAME=RPLC VAR=old_replace'
  45.  
  46.       'OPEN NEW QUIET SMART NAME="' || class_file || '"'
  47.       'WINDOW FORCE USE="' || class_file || '"'
  48.  
  49.       'OPEN INSERT NAME="' || template_file || '"'
  50.  
  51.       /* Replace all occurrences of "%/CLASS/" by `class_name' */
  52.       'REPLACE ALL QUIET STRING="%/CLASS/" BY="' || class_name || '"'
  53.  
  54.       /* Remove all lines with the word "%/DELETE/" in it. */
  55.       'GOTO TOP COLUMN=1'
  56.       found = 1
  57.       do while found
  58.          'FIND FIRST QUIET STRING="%/DELETE/"'
  59.          found = RC = 0
  60.          if found then do
  61.             'DELETE LINE'
  62.          end
  63.       end
  64.  
  65.       /* Goto position marked with "%/CURSOR/ and remove keyword */
  66.       'REPLACE ALL QUIET STRING="%/CURSOR/" BY=""'
  67.  
  68.       /* Restore state of search requester */
  69.       'FIX VAR=old_find'
  70.       'FIX VAR=old_replace'
  71.       'SET NAME=FIND VALUE="' || old_find || '"'
  72.       'SET NAME=RPLC VALUE="' || old_replace || '"'
  73.    end
  74.    else do
  75.       /* Class name contains invalid character */
  76.       'REQUEST PROBLEM="' || error_message || '."'
  77.    end
  78. end
  79.  
  80. 'UNLOCK'
  81.  
  82. exit
  83.  
  84. SYNTAX:
  85.  
  86. SAY 'Error in line' SIGL ':' ERRORTEXT(RC)
  87.  
  88. 'UNLOCK'
  89.  
  90.