Guidance
指路人
g.yi.org
software / rapidq / Examples / Tools - IDE, Designer, Builder / FreeQ IDE src / tools / AutoDeclare.inc

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'
' **************************************************************
' **  Parse a basic file for subs/functions/API/constants so you can paste them
' **  into a file for auto DECLARE statements
' **  Program will detect continuation to the next line
' **  if the '_' code is separated by a space from other text
' **
' ** Auto Declare generator modified from  RQdecl2.bas by JohnK
' ** and by lots of help from RQ community
' **
' **************************************************************



'generate declare sub / functions from a StringList

     SUB IDE_GenDeclares(ListIn AS QSTRINGLIST, SortIt AS INTEGER)
      DIM TheLine         AS STRING
      DIM APIname         AS STRING        'actual name of api function/sub name
      DIM UpLine          AS STRING        'upper case of the line
      DIM ListOut         AS QSTRINGLIST

      IF ListIn.ItemCount < 1 THEN EXIT SUB           'what happened?

      DEFINT  i = 0, ApiN = 0, ConstN = 0, LimitEnder = 0, JmpLoop

      WHILE (i < ListIn.ItemCount)
       TheLine = TRIM$(ListIn.Item(i))                                     'get whole line w/o spaces
       LimitEnder = INSTR(TheLine, sQuot)                                  'find comment start
       IF LimitEnder THEN TheLine = RTRIM$(LEFT$(TheLine, LimitEnder-1))   'remove comment
       TheLine = StripTabs(TheLine)                                        'remove tabs, replace with space
       UpLine = UCASE$(TheLine)                                             'upper case for matches
       DO                                                                  'combine multilines into one line
        JmpLoop = False
        IF RIGHT$(TheLine, 1) = CHR$(95) THEN                           'the _ char messes up parse!
         LimitEnder = LEN(TheLine) - 1
        ELSE
         LimitEnder = INSTR(TheLine, (CHR$(32)+CHR$(95)))            'continuation delimiter
        END IF

        IF LimitEnder THEN
         TheLine = RTRIM$(LEFT$(TheLine, LimitEnder))                'get good part
         IF i <ListIn.ItemCount THEN i++ :TheLine = TheLine + " " + StripTabs(TRIM$(ListIn.Item(i)))        'append it
         UpLine = UCASE$(TheLine)
        ELSE
         JmpLoop = True                                             'single line
        END IF
       LOOP UNTIL JmpLoop

       IF (LEFT$(UpLine, 5) = "TYPE " AND INSTR(7, UpLine," EXTENDS ")) THEN   'skip class/object declarations
        JmpLoop = 0
        DO
         IF i <ListIn.ItemCount THEN                                     'check EOF
          i++
          TheLine = TRIM$(StripTabs(ListIn.Item(i)))                  'read next line
          IF  UCASE$(LEFT$(TheLine, 9)) = "END TYPE" THEN JmpLoop = 1 'found the end of type declare
         ELSE
          JmpLoop = True
         END IF
        LOOP UNTIL JmpLoop
       END IF

'         IF LEFT$(UpLine, 17) = "DECLARE FUNCTION " AND INSTR(19, UpLine," LIB ") THEN    'got us an API
'             ApiN++
'             LimitEnder = INSTR(19, UpLine," LIB ")
'             APIname = TRIM$(MID$(TheLine, 18, LimitEnder-18))
'             IF MakeSubAlias THEN
' '                LimitEnder = INSTR(19, UpLine," LIB ")
'                 LimitEnder = INSTR(LimitEnder, UpLine, CHR$(34))
'                 LimitEnder = INSTR(LimitEnder, UpLine, CHR$(34) + CHR$(32))    'get the second quote after LIB
'                 APIFuncLines(ApiN) = LEFT$(TheLine, LimitEnder) + " ALIAS " + _
'                     CHR$(34) + APIname + CHR$(34) + _
'                     RIGHT$(TheLine, LEN(TheLine) - LimitEnder)
'             ELSE
' '                LimitEnder = INSTR(19, UpLine," LIB ")                'or just up to the Alias part
' '                APIFuncLines(ApiN) = TRIM$(MID$(TheLine, 18, LimitEnder-18))
'                 LimitEnder = INSTR(TheLine,"(")                    'now get parameters
' '                APIFuncLines(ApiN) = APIFuncLines(ApiN) + " " + TRIM$(MID$(TheLine, LimitEnder, LEN(TheLine) - LimitEnder +1))
'                 APIFuncLines(ApiN) = APIname + " " + TRIM$(MID$(TheLine, LimitEnder, LEN(TheLine) - LimitEnder +1))
'             END IF
'         END IF

'
'         IF LEFT$(UpLine, 12) = "DECLARE SUB " AND INSTR(13, UpLine," LIB ") THEN    'got us an API
'             ApiN++
'             LimitEnder = INSTR(13, UpLine," LIB ")                'up to the  Alias part
'             APIname = TRIM$(MID$(TheLine, 12, LimitEnder-12))
'             IF MakeSubAlias THEN
'                 LimitEnder = INSTR(LimitEnder, UpLine, CHR$(34))
'                 LimitEnder = INSTR(LimitEnder, UpLine, CHR$(34) + CHR$(32))    'get the second quote after LIB
'                 APIFuncLines(ApiN) = LEFT$(TheLine, LimitEnder) + " ALIAS " + _
'                     CHR$(34) + APIname + CHR$(34) + _
'                     RIGHT$(TheLine, LEN(TheLine) - LimitEnder)
'             ELSE
' '                APIFuncLines(ApiN) = TRIM$(MID$(TheLine, 12, LimitEnder-12))
'                 LimitEnder = INSTR(TheLine,"(")                    'now get parameters
' '                APIFuncLines(ApiN) = APIFuncLines(ApiN) + " " + TRIM$(MID$(TheLine, LimitEnder, LEN(TheLine) - LimitEnder +1))
'                 APIFuncLines(ApiN) = APIname + " " + TRIM$(MID$(TheLine, LimitEnder, LEN(TheLine) - LimitEnder +1))
'             END IF
'         END IF

       IF LEFT$(UpLine, 4) = "SUB "        THEN ListOut.AddItems "DECLARE " + TheLine
       IF LEFT$(UpLine, 9) = "FUNCTION "   THEN ListOut.AddItems  "DECLARE " + TheLine
       IF LEFT$(UpLine, 5) = "SUBI "       THEN ListOut.AddItems  "DECLARE " + TheLine 'don't use!!
       IF LEFT$(UpLine, 10) = "FUNCTIONI " THEN ListOut.AddItems  "DECLARE " + TheLine
       i++
      WEND
      IF SortIt THEN ListOut.Sort
      ListIn.Clear
      ListIn.Text = ListOut.Text
      ListOut.Clear
     END SUB



掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2024-4-27  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2010-12-07 21:18:03