home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / arexx / include2ged1.1.lha / Include2GEDDict.rexx < prev   
Encoding:
OS/2 REXX Batch file  |  1992-09-02  |  23.6 KB  |  536 lines

  1. /*     Include2GEDDict.rexx - macro for developers using GoldED
  2.  
  3. VERSION
  4.     $VER: Include2GEDDict.rexx 1.1 06.03.95
  5.  
  6. COPYRIGHT
  7.     ©1995 Jan Skypala, Better Software
  8.  
  9. DISTRIBUTION
  10.     This file is freeware, but also copyrighted to its author.
  11.     You can distribute it in unchaged form for no or nominal fee, upload it to
  12.     BBS, include on public domain CD-ROMs (like Aminet or Fred Fish), in
  13.     magazines.
  14.     It is permitted to include this macro within GoldED archive.
  15.     It is permitted to include this macro in GoldED macro collections (like
  16.     ESEE).
  17.     I would not mind if you send a copy of magazine or free CD if you decided to
  18.     publish it in the magazine or on the CD-ROM.
  19.     It is permitted to include this macro in language packages (I would not mind
  20.     if you send me a copy of package)
  21.     I would not mind if you send at least postcard.
  22.  
  23. DESCRIPTION
  24.     This is Arexx macro to make life more comfortable. If you like using GoldED
  25.     dictionary for autocompletition and autocasing you maybe hate manual
  26.     inserting every word you want. That's why this Arexx script comes. Running
  27.     it on standard files it will grab the words for them and insert them into
  28.     dictionary automaticaly. Currently recognized files:
  29.  
  30.     .fd    files with list of libraries functions
  31.     .h     C include files
  32.     .i     assembler include files
  33.     .m     AmigaE include files
  34.  
  35. USAGE
  36.     rx Include2GEDDict.rexx FILES/M
  37.  
  38.     FILES - list of files (including paths). If not specified and rexxreqtools
  39.             library available then file requester opens and lets you select
  40.             files.
  41.  
  42. REQUIREMENTS
  43.     GoldED running
  44.     rexxreqtools.library for file requester if no files specified
  45.     ec:ShowModule for AmigaE modules processing
  46.  
  47. BUGS
  48.     The program doesn't process two level nested C structures. It's built in,
  49.     but GoldED crashes sometimes when I insert the words into dictionary (maybe
  50.     they are too long), so I made the program to ignore them i.e. it will not
  51.     produce any mischmasch in dictionary. If you want to see the place it is
  52.     lines 381-384. It is the case of following include files and structures:
  53.     devices/inputevent.h
  54.         InputEvent.ie_position.ie_xy.ie_x
  55.         InputEvent.ie_position.ie_xy.ie_y
  56.         InputEvent.ie_position.ie_dead.ie_prev1DownCode
  57.         InputEvent.ie_position.ie_dead.ie_prev1DownQual
  58.         InputEvent.ie_position.ie_dead.ie_prev2DownCode
  59.         InputEvent.ie_position.ie_dead.ie_prev2DownQual
  60.     dos/dosextens.h
  61.         DosList.dol_misc.dol_handler.dol_Handler
  62.         DosList.dol_misc.dol_handler.dol_StackSize
  63.         DosList.dol_misc.dol_handler.dol_Priority
  64.         DosList.dol_misc.dol_handler.dol_Startup
  65.         DosList.dol_misc.dol_handler.dol_SegList
  66.         DosList.dol_misc.dol_handler.dol_GlobVec
  67.         DosList.dol_misc.dol_volume.dol_VolumeDate
  68.         DosList.dol_misc.dol_volume.dol_LockList
  69.         DosList.dol_misc.dol_volume.dol_DiskType
  70.         DosList.dol_misc.dol_assign.dol_AssignName
  71.         DosList.dol_misc.dol_assign.dol_List
  72.     dos/notify.h
  73.         NotifyRequest.nr_stuff.nr_Msg.nr_Port
  74.         NotifyRequest.nr_stuff.nr_Signal.nr_Task
  75.         NotifyRequest.nr_stuff.nr_Signal.nr_SignalNum
  76.         NotifyRequest.nr_stuff.nr_Signal.nr_pad
  77.     You can insert them manually, of course.
  78.     There are no three level nested structures in include files so I didn't care
  79.     about them at all.
  80.  
  81. HISTORY
  82.     1.0 - first public release
  83.     1.1 - error messages showing in shell eliminated
  84.         - now also understands macro definitions in AmigaE .m modules
  85.         - one level nested C structures are now processed alright
  86.         - typedef struct { ... } name (used in intuition/classusr.h) corrected
  87.         - two level nested C structures processed, just because of GoldED
  88.           crashing the words are not inserted into dictionary yet.
  89.         - arrays in C structures now processed alright
  90.  
  91. FUTURE
  92.     If you send me files e.g. for pascal I can do the work for them too. Just in
  93.     the case they are pre-compiled (like AmigaE modules) I need some utility to
  94.     convert them into text files.
  95.  
  96. AUTHOR'S ADDRESSES
  97.     e-mail:     one@risc.upol.cz
  98.     snail mail: Jan Skypala
  99.                 Zasovska 730
  100.                 Valasske Mezirici
  101.                 757 01
  102.                 Czech Republic
  103. */
  104.  
  105. OPTIONS RESULTS                             /* enable return codes     */
  106.  
  107. address 'GOLDED.1' 'LOCK CURRENT QUIET'     /* lock GUI, gain access   */
  108. address command
  109. OPTIONS FAILAT 6                            /* ignore warnings         */
  110. SIGNAL ON SYNTAX                            /* ensure clean exit       */
  111.  
  112. if arg() = 1 then do
  113.     args = upper( arg( 1 ) )
  114.     do i = 1 to words( args )
  115.         onearg = subword( args, i )
  116.         if index( onearg, ' ' ) ~= 0 then onearg = substr( onearg, 1, index( onearg, ' ' ) - 1 )
  117.         call processonefile( onearg )
  118.         end
  119.     end
  120. else do
  121.     if addlib( "rexxreqtools.library", 0, -30, 0 ) then do
  122.         call rtfilerequest( , , "Select files", , "rtfi_flags=freqf_multiselect", files )
  123.         if files == 1 then
  124.             do i=1 to files.count
  125.                 call processonefile( upper( files.i ) )
  126.             end
  127.         end
  128.     end
  129.  
  130. address 'GOLDED.1'
  131. 'UNLOCK'                                /* VERY important: unlock GUI */
  132. EXIT
  133.  
  134. SYNTAX:
  135.  
  136. SAY "Sorry, error line" SIGL ":" ERRORTEXT(RC) ":-("
  137. address 'GOLDED.1'
  138. 'UNLOCK'
  139. EXIT
  140.  
  141. /* This procedure is called for every argument provided or every file selected
  142.    in file requester */
  143. processonefile: procedure
  144. if index( arg(1), '.FD' ) ~= 0 then
  145.     if substr( arg(1), index( arg(1), '.FD' ) ) = '.FD' then call fd( arg(1) )
  146. if index( arg(1), '.M' ) ~= 0 then
  147.     if substr( arg(1), index( arg(1), '.M' ) ) = '.M' then call m( arg(1) )
  148. if index( arg(1), '.H' ) ~= 0 then
  149.     if substr( arg(1), index( arg(1), '.H' ) ) = '.H' then call h( arg(1) )
  150. if index( arg(1), '.I' ) ~= 0 then
  151.     if substr( arg(1), index( arg(1), '.I' ) ) = '.I' then call i( arg(1) )
  152. return 0
  153.  
  154. /* This procedure processes .fd files */
  155. fd: procedure
  156. if open( file, arg(1), read ) = 0 then do
  157.                                        say 'File' arg(1) 'not found.'
  158.                                        return 0
  159.                                        end
  160. fini = 0
  161. process = 1
  162. do until fini
  163.     line = readln( file )
  164.     uline = upper( line )
  165.     fini = eof( file )
  166.     select
  167.         when uline = '##END' then fini = 1
  168.         when uline = '##PUBLIC' then process = 1
  169.         when uline = '##PRIVATE' then process = 0
  170.         when process = 1 then
  171.             select
  172.                 when index( line, '*' ) = 1 then nop
  173.                 when index( line, '##' ) = 1 then nop
  174.                 otherwise address 'GOLDED.1' 'PHRASE ADD' substr( line, 1, index( line, '(' ))
  175.                 end
  176.         otherwise nop
  177.         end
  178.     end
  179. call close(file)
  180. return 0
  181.  
  182. /* This procedure processes AmigaE modules */
  183. m: procedure
  184. address command 'ec:showmodule' arg(1) '>t:module.$'
  185. if open( file, 't:module.$', read ) = 0 then do
  186.                                              say 'Error processing file' arg(1)
  187.                                              return 0
  188.                                              end
  189. state = 0
  190. do until eof( file )
  191.     line = readln( file )
  192.     select
  193.         when index( line, 'CONST' ) = 1 then do
  194.             address 'GOLDED.1' 'PHRASE ADD' substr( line, 7, index( line, '=' ) - 7 )
  195.             status = 1
  196.             end
  197.         when index( line, '(---) OBJECT' ) = 1 then do
  198.             object = substr( line, 14 )
  199.             address 'GOLDED.1' 'PHRASE ADD' object
  200.             status = 2
  201.             end
  202.         when index( line, '(---) ENDOBJECT' ) = 1 then status = 0
  203.         when index( line, 'LIBRARY' ) = 1 then do
  204.             address 'GOLDED.1' 'PHRASE ADD' substr( line, 9, index( line, ' ', 9 ) - 9 )
  205.             status = 3
  206.             end
  207.         when index( line, 'ENDLIBRARY' ) = 1 then status = 0
  208.         when index( line, 'PROC' ) = 1 then do
  209.             address 'GOLDED.1' 'PHRASE ADD' substr( line, 6, index( line, '(' ) - 5 )
  210.             status = 0
  211.             end
  212.         when index( line, '#define' ) = 1 then do
  213.             if index( line, '/', 9 ) = 0 then address 'GOLDED.1' 'PHRASE ADD' substr( line, 9 )
  214.                                          else address 'GOLDED.1' 'PHRASE ADD' substr( line, 9, index( line, '/' ) - 9 ) || '('
  215.             status = 0
  216.             end
  217.         when line = '' then status = 0
  218.         when status = 1 then address 'GOLDED.1' 'PHRASE ADD' substr( line, 7, index( line, '=' ) - 7 )
  219.         when status = 2 then address 'GOLDED.1' 'PHRASE ADD' object || '.' || substr( line, 9, index( line, ':' ) - 9 )
  220.         when status = 3 then address 'GOLDED.1' 'PHRASE ADD' substr( line, 3, index( line, '(' ) - 2 )
  221.         otherwise nop
  222.         end
  223.     end
  224. call close( file )
  225. address command 'delete >NIL: t:module.$'
  226. return 0
  227.  
  228. /* This procedure processes C headers (.h include files) */
  229. h: procedure
  230. if open( file, arg(1), read ) = 0 then do
  231.                                        say 'File' arg(1) 'not found.'
  232.                                        return 0
  233.                                        end
  234. note = 0
  235. status = 0
  236. substruct = 0
  237. parth = 0
  238. do until eof( file )
  239.     line = readln( file )
  240.     if note = 0 then
  241.         if index( line, '/*' ) ~= 0 then
  242.             do while index( line, '/*' ) ~= 0
  243.                 if index( line, '*/' ) ~= 0 then line = substr( line, 1, index( line, '/*' ) - 1 ) || substr( line, index( line, '*/' ) + 2 )
  244.                                             else do
  245.                                                  if index( line, '/*' ) = 1 then line = ''
  246.                                                                             else line = substr( line, 1, index( line, '/*' ) - 1 )
  247.                                                  note = 1
  248.                                                  end
  249.                 end
  250.         else nop
  251.     else
  252.         if index( line, '*/' ) = 0 then line = ''
  253.                                    else do
  254.                                        line = substr( line, index( line, '*/' ) + 2 )
  255.                                        note = 0
  256.                                        if index( line, '/*' ) ~= 0 then
  257.                                            do while index( line, '/*' ) ~= 0
  258.                                                if index( line, '*/' ) ~= 0 then line = substr( line, 1, index( line, '/*' ) - 1 ) || substr( line, index( line, '*/' ) + 2 )
  259.                                                                            else do
  260.                                                                                 if index( line, '/*' ) = 1 then line = ''
  261.                                                                                                            else line = substr( line, 1, index( line, '/*' ) - 1 )
  262.                                                                                 note = 1
  263.                                                                                 end
  264.                                                if index( line, '/*' ) = 0 then strip = 0
  265.                                                end
  266.                                        else nop
  267.                                        end
  268.     do while index( line, ';' ) ~= 0
  269.         line = substr( line, 1, index( line, ';' ) - 1 ) ' 1 ' substr( line, index( line, ';' ) + 1 )
  270.         end
  271.     do while index( line, ',' ) ~= 0
  272.         line = substr( line, 1, index( line, ',' ) - 1 ) ' 2 ' substr( line, index( line, ',' ) + 1 )
  273.         end
  274.     do while index( line, '    ' ) ~= 0
  275.         line = substr( line, 1, index( line, '    ' ) - 1 ) substr( line, index( line, '    ' ) + 1 )
  276.         end
  277.     if words( line ) > 0 then
  278.         do i = 1 to words( line )
  279.             word = subword( line, i )
  280.             if index( word, ' ' ) ~= 0 then word = substr( word, 1, index( word, ' ' ) - 1 )
  281.             output = 0
  282.             array = 0
  283.             select
  284.                 when status = 0 then
  285.                     select
  286.                         when word = 'struct' then status = 1
  287.                         when word = '#define' then status = 5
  288.                         when word = 'typedef' then status = 6
  289.                         otherwise nop
  290.                         end
  291.                 when status = 1 then do
  292.                     struct = word
  293.                     status = 2
  294.                     output = 1
  295.                     end
  296.                 when status = 2 then if word = '{' then status = 3
  297.                                                    else status = 0
  298.                 when status = 3 then
  299.                     select
  300.                         when word = '}' then if substruct = 0 then status = 0
  301.                                                               else status = 8
  302.                         when word = 'struct' then status = 7
  303.                         when word = 'union' then status = 7
  304.                         when word = '1' then nop
  305.                         otherwise status = 4
  306.                         end
  307.                 when status = 4 then
  308.                     if word = '*' then nop
  309.                     else do
  310.                          if index( word, '*' ) = 1 then word = substr( word, 2 )
  311.                          if index( word, '[' ) ~= 0 then do
  312.                             word = substr( word, 1, index( word, '[' ) - 1 )
  313.                             array = 1
  314.                             end
  315.                          select
  316.                             when substruct = 0 then do
  317.                                 word = struct || '.' || word
  318.                                 output = 1
  319.                                 end
  320.                             otherwise attrs = attrs word
  321.                             end
  322.                          status = 3
  323.                          end
  324.                 when status = 5 then do
  325.                     if index( word, '(' ) ~= 0 then word = substr( word, 1, index( word, '(' ) )
  326.                     output = 1
  327.                     status = 0
  328.                     end
  329.                 when status = 6 then do
  330.                     if word = 'struct' then status = 9
  331.                                        else do
  332.                                            output = 1
  333.                                            status = 0
  334.                                        end
  335.                     end
  336.                 when status = 7 then if word ~= '{' then status = 4
  337.                                                     else do
  338.                                                         substruct = substruct + 1
  339.                                                         select
  340.                                                             when substruct = 1 then attrs = ''
  341.                                                             when substruct = 2 then attrs = attrs '|'
  342.                                                             otherwise nop
  343.                                                             end
  344.                                                         status = 3
  345.                                                         end
  346.                 when status = 8 then do
  347.                     select
  348.                         when substruct = 1 then do
  349.                             if index( word, '[' ) ~= 0 then do
  350.                                 attr = substr( word, 1, index( word, '[' ) - 1 )
  351.                                 array = 1
  352.                                 end
  353.                             word = struct || '.' || word
  354.                             subsub = 0
  355.                             firstsub = 0
  356.                             do i = 1 to words( attrs )
  357.                                 attr = subword( attrs, i )
  358.                                 if index( attr, ' ' ) ~= 0 then attr = substr( attr, 1, index( attr, ' ' ) - 1 )
  359.                                 subarray = 0
  360.                                 if index( attr, '[' ) ~= 0 then do
  361.                                     attr = substr( attr, 1, index( attr, '[' ) - 1 )
  362.                                     subarray = 1
  363.                                     end
  364.                                 select
  365.                                     when attr = '{' then do
  366.                                         subsub = subsub + 1
  367.                                         firstsub = 1
  368.                                         end
  369.                                     when firstsub = 1 then do
  370.                                         firstsub = 0
  371.                                         subsubstruct = attr
  372.                                         address 'GOLDED.1' 'PHRASE ADD' word || '.' || attr
  373.                                         if subarray then address 'GOLDED.1' 'PHRASE ADD' word || '.' || attr || '['
  374.                                         end
  375.                                     when attr = '}' then
  376.                                         subsub = subsub - 1
  377.                                     when subsub = 0 then do
  378.                                         address 'GOLDED.1' 'PHRASE ADD' word || '.' || attr
  379.                                         if subarray then address 'GOLDED.1' 'PHRASE ADD' word || '.' || attr || '['
  380.                                         end
  381.                                     /* when subsub = 1 then do
  382.                                         address 'GOLDED.1' 'PHRASE ADD' word || '.' || subsubstruct || '.' || attr
  383.                                         if subarray then address 'GOLDED.1' 'PHRASE ADD' word || '.' || subsubstruct || '.' || attr || '['
  384.                                         end */
  385.                                     otherwise nop
  386.                                     end
  387.                                 end
  388.                             output = 1
  389.                             attrs = ''
  390.                             end
  391.                         when substruct = 2 then attrs = substr( attrs, 1, index( attrs, '|' ) - 2 ) '{' word substr( attrs, index( attrs, '|' ) + 2 ) '}'
  392.                         otherwise nop
  393.                         end
  394.                     status = 3
  395.                     substruct = substruct - 1
  396.                     end
  397.                 when status = 9 then
  398.                     select
  399.                         when word = '{' then parth = parth + 1
  400.                         when word = '}' then do
  401.                             parth = parth - 1
  402.                             if parth = 0 then status = 10
  403.                             end
  404.                         otherwise nop
  405.                         end
  406.                 when status = 10 then
  407.                     if word = '*' then nop
  408.                     else do
  409.                          if index( word, '*' ) = 1 then word = substr( word, 2 )
  410.                          status = 0
  411.                          output = 1
  412.                          end
  413.                 otherwise nop
  414.                 end
  415.             if output then address 'GOLDED.1' 'PHRASE ADD' word
  416.             if output & array then address 'GOLDED.1' 'PHRASE ADD' word || '['
  417.             end
  418.     end
  419. call close( file )
  420. return 0
  421.  
  422. /* This procedure processes assembler include files (.i) */
  423. i: procedure
  424. if open( file, arg(1), read ) = 0 then do
  425.                                        say 'File' arg(1) 'not found.'
  426.                                        return 0
  427.                                        end
  428. do until eof( file )
  429.     line = readln( file )
  430.     do while index( line, ',' ) ~= 0
  431.         line = substr( line, 1, index( line, ',' ) - 1 ) ' 2 ' substr( line, index( line, ',' ) + 1 )
  432.         end
  433.     do while index( line, '    ' ) ~= 0
  434.         line = substr( line, 1, index( line, '    ' ) - 1 ) substr( line, index( line, '    ' ) + 1 )
  435.         end
  436.     fini = 0
  437.     nth = 1
  438.     status = 0
  439.     do until fini
  440.         if nth > words( line ) then fini = 1
  441.         else do
  442.             word = subword( line, nth )
  443.             if index( word, ' ' ) ~= 0 then word = substr( word, 1, index( word, ' ' ) - 1 )
  444.             nth = nth + 1
  445.             output = 0
  446.             select
  447.                 when index( word, ';' ) = 1 then fini = 1
  448.                 when index( word, '*' ) = 1 then fini = 1
  449.                 when nth = 2 then
  450.                     select
  451.                         when index( line, ' ' ) ~= 1 then do
  452.                             if index( word, '=' ) = 0 then do
  453.                                 const = word
  454.                                 status = 0
  455.                                 end
  456.                             else do
  457.                                 word = substr( word, 1, index( word, '=' ) - 1 )
  458.                                 output = 1
  459.                                 status = 0
  460.                                 end
  461.                             end
  462.                         when upper( word ) = 'STRUCTURE' then status = 1
  463.                         when upper( word ) = 'STRUCT' then status = 1
  464.                         when upper( word ) = 'APTR' then status = 1
  465.                         when upper( word ) = 'BPTR' then status = 1
  466.                         when upper( word ) = 'CPTR' then status = 1
  467.                         when upper( word ) = 'FPTR' then status = 1
  468.                         when upper( word ) = 'RPTR' then status = 1
  469.                         when upper( word ) = 'LONG' then status = 1
  470.                         when upper( word ) = 'ULONG' then status = 1
  471.                         when upper( word ) = 'WORD' then status = 1
  472.                         when upper( word ) = 'UWORD' then status = 1
  473.                         when upper( word ) = 'BYTE' then status = 1
  474.                         when upper( word ) = 'UBYTE' then status = 1
  475.                         when upper( word ) = 'SHORT' then status = 1
  476.                         when upper( word ) = 'USHORT' then status = 1
  477.                         when upper( word ) = 'FLOAT' then status = 1
  478.                         when upper( word ) = 'DOUBLE' then status = 1
  479.                         when upper( word ) = 'BOOL' then status = 1
  480.                         when upper( word ) = 'LABEL' then status = 1
  481.                         when upper( word ) = 'ENUM' then status = 1
  482.                         when upper( word ) = 'EITEM' then status = 1
  483.                         when upper( word ) = 'LIBENT' then status = 1
  484.                         when upper( word ) = 'LIBDEF' then status = 1
  485.                         when upper( word ) = 'BITDEF' then status = 2
  486.                         otherwise nop
  487.                         end
  488.                 when nth = 3 then
  489.                     select
  490.                         when upper( word ) = 'EQU' then do
  491.                             output = 1
  492.                             word = const
  493.                             const = ''
  494.                             end
  495.                         when upper( word ) = 'MACRO' then do
  496.                             output = 1
  497.                             word = const
  498.                             const = ''
  499.                             end
  500.                         when word = '=' then do
  501.                             output = 1
  502.                             word = const
  503.                             const = ''
  504.                             end
  505.                         when status = 1 then do
  506.                             output = 1
  507.                             status = 0
  508.                             end
  509.                         when status = 2 then do
  510.                             prefix = word
  511.                             status = 3
  512.                             end
  513.                         otherwise nop
  514.                         end
  515.                 when nth = 4 then
  516.                     if status = 3 & word = '2' then status = 4
  517.                 when nth = 5 then
  518.                     select
  519.                         when status = 4 then do
  520.                             status = 0
  521.                             address 'GOLDED.1' 'PHRASE ADD' prefix || 'B_' || word
  522.                             word = prefix || 'F_' || word
  523.                             output = 1
  524.                             end
  525.                         otherwise nop
  526.                         end
  527.                 otherwise nop
  528.                 end
  529.             if output then address 'GOLDED.1' 'PHRASE ADD' word
  530.             end
  531.         end
  532.     end
  533. call close( file )
  534. return 0
  535.  
  536.