Guidance
指路人
g.yi.org
software / rapidq / Examples / File & Directory / QIniFile / QLibrary.Inc

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

  
'******************************************************
'*     QLibrary.Inc - Common Routines & Functions     *
'******************************************************


'******************************************************
'*       String Functions & Subroutines               *
'******************************************************
     FUNCTION Trim$ (Datum AS STRING) AS STRING
      Result = LTRIM$(RTRIM$(Datum))
     END FUNCTION

     FUNCTIONI CatStr$ (...) AS STRING
      DIM I AS BYTE

      Result = PARAMSTR$(1)
      FOR I = 2 TO PARAMSTRCOUNT
       Result = Result + PARAMSTR$(I)
      NEXT I
     END FUNCTIONI

     FUNCTION Equ$(String1 AS STRING, String2 AS STRING, Exact AS BYTE) AS INTEGER
      IF Exact = True THEN
       IF Trim$(String1) = Trim$(String2) THEN
        Result = True
       ELSE
        Result = False
       END IF
      ELSE
       IF Trim$(UCASE$(String1)) = Trim$(UCASE$(String2)) THEN
        Result = True
       ELSE
        Result = False
       END IF
      END IF
     END FUNCTION

'******************************************************
'*         File Functions & Subroutines               *
'******************************************************
     FUNCTION AddPath$ (Path AS STRING, File AS STRING) AS STRING
      AddPath$ = Path + "\" + File
     END FUNCTION

'****************************
'* RapidQ Keyword Extension *
'****************************

     TYPE RQConst EXTENDS QSTRINGLIST
      FileId      AS STRING
      Initialized AS BYTE

      SUB Initialize
       DIM RQ_Idx          AS INTEGER
       DIM Buffer          AS QSTRINGLIST
       DIM StrLength       AS INTEGER
       DIM Point           AS BYTE
       DIM StrLine         AS STRING
       DIM StrWord         AS STRING
       DIM StrValue        AS STRING
       DIM Entry           AS STRING
       DIM Tmp             AS STRING
       DIM R AS INTEGER, G AS INTEGER, B AS INTEGER

       WITH RQConst
        .Initialized = True
        .Clear
        Buffer.LoadFromFile(.FileId)
        RQ_Idx = 0
        WHILE RQ_Idx < Buffer.ItemCount-1
         StrLine = Trim$(Buffer.Item(RQ_Idx))
         IF INSTR(StrLine,"CONST") > 0 AND LEFT$(StrLine,1) <> "'" THEN
          StrLine   = Trim$(REPLACESUBSTR$(StrLine,"CONST",""))
          StrLength = LEN(StrLine)
          Point     = INSTR(StrLine,"=") + 1
          StrWord   = Trim$(LEFT$(StrLine,Point - 2))
          StrValue  = Trim$(MID$(StrLine,Point,StrLength - Point + 1))
          IF INSTR(StrValue,"'") > 0 THEN
           StrLength = LEN(StrValue)
           Point     = INSTR(StrValue,"'")
           StrValue  = Trim$(LEFT$(StrValue,Point-1))
          END IF
          IF INSTR(StrValue,"&H") > 0 THEN
           StrLine  = StrValue
           StrValue = Trim$(REPLACESUBSTR$(StrValue,"&H",""))
           StrValue = CONVBASE$(StrValue,16,10)
          END IF
          IF INSTR(StrValue,"RGB") > 0 THEN
           StrValue = REPLACESUBSTR$(StrValue,"RGB(","")
           StrValue = REPLACESUBSTR$(StrValue,")",",")
           StrValue = Trim$(StrValue)
           R        = VAL(Trim$(FIELD$(StrValue,",",1)))
           G        = VAL(Trim$(FIELD$(StrValue,",",2)))
           B        = VAL(Trim$(FIELD$(StrValue,",",3)))
           StrValue = Trim$(STR$(RGB(R,G,B)))
          END IF
          Entry = StrWord + ";" + StrValue
          .AddItems Entry
         END IF
         INC RQ_Idx
        WEND
       END WITH
      END SUB

      FUNCTION ValueOf(Entry AS STRING) AS LONG
       DIM Idx AS INTEGER
       DIM StrWord AS STRING
       DIM StrValue AS LONG

       Entry = Trim$(Entry)
       WITH RQConst
        IF .Initialized = False THEN
         .Initialize
        END IF
        Idx = 0
        WHILE Idx < .ItemCount
         StrWord  = FIELD$(.Item(Idx),";",1)
         StrValue = VAL(FIELD$(.Item(Idx),";",2))
         IF Equ$(StrWord,Entry,False) = True THEN
          Result = StrValue
          Idx    = .ItemCount
         END IF
         INC Idx
        WEND
       END WITH
      END FUNCTION

Constructor:
      Initialized = False
      FileId      = "RapidQ.Inc"
     END CONSTRUCTOR
     END TYPE

'************
'* QIniFile *
'************
     TYPE QIniFile EXTENDS QOBJECT
Public:
      Name      AS STRING
      Lines     AS QSTRINGLIST
      LineCount AS INTEGER

      SUB ClearEnding
       DIM LinesIdx AS INTEGER
       DIM StrWord AS STRING

       IF (QIniFile.Lines.ItemCount-1) => 0 THEN
        LinesIdx = QIniFile.Lines.ItemCount-1
        StrWord  = QIniFile.Lines.Item(LinesIdx)
        WHILE Empty$(StrWord) = True
         QIniFile.Lines.DelItems LinesIdx
         IF LinesIdx > 0 THEN
          DEC LinesIdx
          StrWord = QIniFile.Lines.Item(LinesIdx)
         ELSE
          StrWord = "*"
         END IF
        WEND
       END IF
      END SUB

      FUNCTION AddBrackets$(Datum AS STRING) AS STRING
       Datum = Trim$(Datum)
       IF INSTR(Datum,"[") = 0 THEN
        Result = "[" + Datum
       END IF
       IF INSTR(Datum,"]") <> LEN(Datum) THEN
        Result = Result + "]"
       END IF
      END FUNCTION

      FUNCTION ReadEntry (Section AS STRING, KeyWord AS STRING) AS STRING
       DIM StrLength AS INTEGER
       DIM Point     AS BYTE
       DIM StrLine   AS STRING
       DIM StrWord   AS STRING
       DIM Bracket   AS STRING
       DIM LinesIdx  AS INTEGER

       Section  = QIniFile.AddBrackets$(Section)
       QIniFile.Lines.Clear
       IF FILEEXISTS(QIniFile.Name) = True THEN
        KeyWord = Trim$(KeyWord)
        QIniFile.Lines.LoadFromFile(QIniFile.Name)
        QIniFile.Lines.AddItems " "
        LinesIdx = 0
        WHILE LinesIdx < QIniFile.Lines.ItemCount-1
         StrWord = Trim$(QIniFile.Lines.Item(LinesIdx))
         IF Equ$(StrWord,Section,False) THEN
          INC LinesIdx
          StrLine = Trim$(QIniFile.Lines.Item(LinesIdx))
          Bracket = LEFT$(StrLine,1)
          WHILE Bracket <> "[" AND LinesIdx < QIniFile.Lines.ItemCount-1
           StrWord    = Trim$(FIELD$(StrLine,"=",1))
           StrLength  = LEN(StrLine)
           IF Equ$(StrWord,KeyWord,False) THEN
            Point    = INSTR(StrLine,"=") + 1
            Result   = MID$(StrLine,Point,StrLength - Point + 1)
            LinesIdx = QIniFile.Lines.ItemCount
           ELSE
            INC LinesIdx
            StrLine = Trim$(QIniFile.Lines.Item(LinesIdx))
            Bracket = LEFT$(StrLine,1)
           END IF
          WEND
         ELSE
          INC LinesIdx
         END IF
        WEND
       END IF
       QIniFile.ClearEnding
       QIniFile.LineCount = QIniFile.Lines.ItemCount
      END FUNCTION

      SUB ReadSection (Section AS STRING)
       DIM StrLength AS INTEGER
       DIM Point     AS BYTE
       DIM StrLine   AS STRING
       DIM StrWord   AS STRING
       DIM Bracket   AS STRING
       DIM LinesIdx  AS INTEGER
       DIM Buffer    AS QSTRINGLIST

       Section = QIniFile.AddBrackets$(Section)
       QIniFile.Lines.Clear
       IF FILEEXISTS(QIniFile.Name) THEN
        Buffer.LoadFromFile(QIniFile.Name)
        Buffer.AddItems " "
        LinesIdx = 0
        WHILE LinesIdx < Buffer.ItemCount-1
         StrWord = LEFT$(Trim$(Buffer.Item(LinesIdx)),LEN(Section))
         IF Equ$(StrWord,Section,False) THEN
          INC LinesIdx
          StrLine = Buffer.Item(LinesIdx)
          Bracket = LEFT$(StrLine,1)
          WHILE Bracket <> "[" AND LinesIdx < Buffer.ItemCount-1
           QIniFile.Lines.AddItems StrLine
           INC LinesIdx
           StrLine = Buffer.Item(LinesIdx)
           Bracket = LEFT$(StrLine,1)
          WEND
          LinesIdx = Buffer.ItemCount
         ELSE
          INC LinesIdx
         END IF
        WEND
       END IF
       QIniFile.LineCount = QIniFile.Lines.ItemCount
      END SUB

      SUB WriteEntry (Section AS STRING, KeyWord AS STRING, KeyEntry AS STRING)
       DIM StrLength AS INTEGER
       DIM StrLine   AS STRING
       DIM StrWord   AS STRING
       DIM Point     AS BYTE
       DIM Bracket   AS STRING
       DIM LinesIdx  AS INTEGER
       DIM Fin       AS BYTE

       KeyWord  = Trim$(KeyWord)
       KeyEntry = Trim$(KeyEntry)
       Section  = QIniFile.AddBrackets$(Section)
       QIniFile.Lines.Clear
       IF FILEEXISTS(QIniFile.Name) THEN
        QIniFile.Lines.LoadFromFile(QIniFile.Name)
        QIniFile.Lines.AddItems " "
        LinesIdx = 0
        WHILE LinesIdx < QIniFile.Lines.ItemCount-1
         StrWord = LEFT$(Trim$(QIniFile.Lines.Item(LinesIdx)),LEN(Section))
         IF Equ$(StrWord,Section,False) THEN
          INC LinesIdx
          StrLine = Trim$(QIniFile.Lines.Item(LinesIdx))
          Bracket = LEFT$(StrLine,1)
          WHILE Bracket <> "[" AND LinesIdx < QIniFile.Lines.ItemCount-1
           StrLength = LEN(StrLine)
           StrWord   = Trim$(FIELD$(StrLine,"=",1))
           IF Equ$(StrWord,KeyWord,False) THEN
            Point   = INSTR(StrLine,"=") + 1
            StrWord = MID$(StrLine,Point,StrLength - Point + 1)
            StrLine = CatStr$(KeyWord," = ",KeyEntry)
            QIniFile.Lines.DelItems(LinesIdx)
            QIniFile.Lines.InsertItem(LinesIdx,StrLine)
            Fin      = True
            LinesIdx = QIniFile.Lines.ItemCount
           ELSE
            INC LinesIdx
            StrLine = QIniFile.Lines.Item(LinesIdx)
            Bracket = LEFT$(Trim$(StrLine),1)
           END IF
          WEND
          IF Fin <> True THEN
           QIniFile.ClearEnding
           QIniFile.Lines.AddItems CatStr$(KeyWord,"=",KeyEntry)
           Fin = True
          END IF
         ELSE
          INC LinesIdx
         END IF
        WEND
       END IF
       IF Fin <> True THEN
        QIniFile.ClearEnding
        QIniFile.Lines.AddItems " "
        QIniFile.Lines.AddItems Section
        QIniFile.Lines.AddItems CatStr$(KeyWord,"=",KeyEntry)
       END IF
       QIniFile.Lines.SaveToFile(QIniFile.Name)
       QIniFile.LineCount = QIniFile.Lines.ItemCount
      END SUB

      SUB WriteSection (Section AS STRING,SectionList AS QSTRINGLIST)
       DIM StrLength AS INTEGER
       DIM Point     AS BYTE
       DIM StrLine   AS STRING
       DIM StrWord   AS STRING
       DIM Bracket   AS STRING
       DIM LinesIdx  AS INTEGER
       DIM Buffer    AS QSTRINGLIST

       QIniFile.Lines.Clear
       Point   = False
       Section = QIniFile.AddBrackets$(Section)
       IF FILEEXISTS(QIniFile.Name) THEN
        Buffer.LoadFromFile(QIniFile.Name)
        Buffer.AddItems " "
        LinesIdx = 0
        WHILE LinesIdx < Buffer.ItemCount -1
         StrLine = Buffer.Item(LinesIdx)
         StrWord = LEFT$(Trim$(Buffer.Item(LinesIdx)),LEN(Section))
         IF Equ$(StrWord,Section,False) THEN
          Point   = LinesIdx
          INC LinesIdx
          StrLine = Buffer.Item(LinesIdx)
          Bracket = LEFT$(StrLine,1)
          WHILE Bracket <> "[" AND LinesIdx < Buffer.ItemCount-1
           INC LinesIdx
           StrLine = Buffer.Item(LinesIdx)
           Bracket = LEFT$(StrLine,1)
          WEND
         ELSE
          QIniFile.Lines.AddItems StrLine
          INC LinesIdx
         END IF
        WEND
       END IF
       SectionList.InsertItem(0,Section)
       IF Point > False THEN
        FOR LinesIdx = 0 TO SectionList.Itemcount-1
         StrLine = SectionList.Item(LinesIdx)
         QIniFile.Lines.InsertItem(Point,StrLine)
         INC Point
        NEXT LinesIdx
       ELSE
        QIniFile.Lines.AddItems " "
        Point = QIniFile.Lines.ItemCount
        QIniFile.Lines.AddList SectionList
       END IF
       QIniFile.ClearEnding
       QIniFile.Lines.SaveToFile(QIniFile.Name)
       QIniFile.LineCount = QIniFile.Lines.ItemCount
      END SUB

      SUB Edit
       DIM CurName AS STRING
       DIM Editor  AS STRING

       CurName        = QIniFile.Name
       QIniFile.Name  = "QLibrary.Ini"
       Editor         = QIniFile.ReadEntry("QIniFile","TextEditor")
       QIniFile.Name  = CurName
       Editor         = CatStr$(Editor," ",QIniFile.Name)
       SHELL Editor
       QIniFile.LineCount = 0
      END SUB
     END TYPE

'------------------------------------------------------
'$EndIf '<---- End QLibrary definition check
'------------------------------------------------------
掌柜推荐
 
 
¥477.00 ·
 
 
¥918.00 ·
 
 
¥370.00 ·
 
 
¥271.00 ·
 
 
¥995.00 ·
 
 
¥1,580.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2003-01-15 20:35:40