Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Bypassing DATA's restrictions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bypassing DATA's restrictions

    DATA statements generate the array of ASCIIZ strings.
    Main idea to bypass DATA's restrictions (32K ? inside function/sub) is to include an array of ASCIIZ into resource file.

    I begin from the end. This sample demonstrates, how to use an array, crated by special utility.

    Code:
       #Compile Exe
       #Register None
       #Dim All
       #Include "Data.Inc"
       #Resource "DataTest.Pbr"
    
       Function PbMain
          '---- Initialization --------
          DataAddr = LoadResource (ByVal 0, _
             ByVal FindResource(ByVal 0&, "Data", ByVal %RT_RCDATA))
    
          '----------------------- Test ------------------
          Dim i As Long
          For i = 1 To %DataCount
             ' Replacement for Read$(i) 
             DataItem = @DataAddr[i - 1] + DataAddr: MsgBox @DataItem
          Next
          ' Replacement for "Restore Lbl2: Read "
          DataItem = @DataAddr[%Lbl2 - 1] + DataAddr: MsgBox "Lbl2 = " + @DataItem
       End Function
    Now about utility.
    Before starting it's necessary to prepare
    1) ordinary text file with "DATA" values. Delimiters - according Input's rules.

    For sample: file Data.Txt
    Code:
    January, February, March, April, May, June, July
    August, September, October, November, December
    "Ivan Ivanow",  165, " 270 "
    $%Lbl1
       250, 420, "Moskwa "
    $%Lbl2
      St.-Peterburg,  -2150.25
    2) Rc file with RCDATA statement.

    In sample - file Data.Rc with line
    Data RCDATA Data.Dat

    3) Bat file, which converts RC to PBR

    In sample - file _Rc.Bat with lines
    rc DataTest
    pbres DataTest

    Then you can start following utility
    Code:
       #Compile Exe
       #Dim All
       #Register None
       #Include "win32api.inc"
       $Data_Src_File = "Data.Txt"
       $Data_Dst_File = "Data.Dat"
       $Inc_File      = "Data.Inc"
       $CompileRc     = "_Rc.Bat"
       %mlBuffer = 100000
    
       Function PbMain
          Dim Buffer As String * %mlBuffer, lBuffer As Long, OffSetDataItem As Long Ptr
          Dim DataItem As String, lDataItem As Long, nDataItem As Long, maxDataItem As Long
          Dim Cross As Long,  i As Long
          maxDataItem = Fix(%mlBuffer / 4)
          Open $Inc_File For Output As #2
          Open $Data_Dst_File For Output As #3
          OffSetDataItem = VarPtr(Buffer)
          For Cross = 1 To 2
             nDataItem = 0: lBuffer = 0: Open $Data_Src_File For Input Shared As #1
             If Err <> 0 Then MsgBox "Can't open " + $Data_Src_File: Exit Function
             While Not Eof(1)
                Input #1, DataItem
                If Len(DataItem) >= 32767 Then MsgBox "Error 1": Exit Function
                If Left$(DataItem, 2) = "$%" Then
                   If Cross = 2 Then Print #2, "   %" + _
                      Trim$(Mid$(DataItem, 3)) + " =" + Str$(nDataItem + 1)
                Else
                   If nDataItem >= maxDataItem Then MsgBox "Error 2": Exit Function
                   lDataItem = Len(DataItem) + 1
                   If Cross = 1 Then
                      @OffSetDataItem[nDataItem] = lBuffer: lBuffer = lBuffer + lDataItem
                   Else
                      If lBuffer + lDataItem > %mlBuffer Then _
                         Print #3, Left$(Buffer, lBuffer);: lBuffer = 0
                      Mid$(Buffer, lBuffer + 1, lDataItem - 1) = DataItem
                      lBuffer = lBuffer + lDataItem: Mid$(Buffer, lBuffer, 1) = Chr$(0)
                   End If
                   Incr nDataItem
                End If
             Wend
             If Cross = 1 Then
                lBuffer = 4 * nDataItem
                For i = 0 To nDataItem - 1
                   @OffSetDataItem[i] = @OffSetDataItem[i] + lBuffer
                Next
                Print #3, Left$(Buffer, lBuffer);
             End If
             Close #1
          Next
          
          Print #2, "   %DataCount =" + Str$(nDataItem)
          Print #2, "   Global DataItem As Asciiz Ptr, DataAddr As Long Ptr": Close #2
          Print #3, Left$(Buffer, lBuffer);: Close #3
          Shell $CompileRc
          MsgBox "Ok"
    End Function
Working...
X