Attribute VB_Name = "Module1"
Option Explicit
Option Base 0

Private Function IncludeFASM(ByVal Filename As String, Optional ByVal FileID As Long = 2&) As String
  Dim xLong1 As Long
  Dim xChar1 As String

  Open Filename For Input As FileID
  Do Until EOF(FileID)
    Line Input #FileID, xChar1
    xChar1 = Trim(Replace(xChar1, vbTab, " "))
    xLong1 = InStr(xChar1, ";")
    If Not xLong1 = 1& Then
      If Not xLong1 = 0& Then xChar1 = Trim(Left(xChar1, xLong1 - 1&))
      If Not Len(xChar1) = 0& Then
        xLong1 = InStr(xChar1, " ")
        If xLong1 = 0& Then
          If Not xChar1 = "endp" Then
            If Right(xChar1, 1&) = ":" Then
              Select Case xChar1
                Case "CritSection:"
                  Print #1, xChar1
                End Select
              xChar1 = "!" + xChar1
              End If
            Print #1, xChar1
            End If
          Else
          Select Case LCase(Left(xChar1, xLong1 - 1&))
            Case "include"
              GoTo NoDo
            Case "file"
              'Stop
              xChar1 = Trim(Mid(xChar1, xLong1 + 1&))
              xChar1 = "includebinary " + Chr(34&) + "D:\DEV\Software\Libraries\LineSpec\DllSource\" + Mid(xChar1, 2&, Len(xChar1) - 2&) + Chr(34&)
              'IncludeFASM xChar1
            Case "proc"
              xChar1 = "!" + Trim(Mid(xChar1, xLong1 + 1&)) + ":"
            Case "jmp", "call", _
                 "je", "ja", "jb", "jne", "jna", "jnb", _
                 "xor", "push", _
                 "db", "dd", "dw"
              xChar1 = "!" + xChar1
            End Select
          Print #1, xChar1
NoDo:
          End If
        End If
      End If
    Loop
  Close FileID
  End Function

Private Function IncludePB(ByVal Filename As String, Optional ByVal FileID As Long = 2&) As String
  Dim xChar1 As String

  Open Filename For Input As FileID
  Do Until EOF(FileID)
    Line Input #FileID, xChar1
    If Left(xChar1, 5&) = "FASM " Then
      Call IncludeFASM(Mid(xChar1, 6&), FileID + 1&)
      Else
      Print #1, xChar1
      End If
    Loop
  Close FileID
  End Function

Private Sub Main()
  Open "LineSpec_PB.pb" For Output As 1
  Call IncludePB("CreatePB.pb")
  Close 1
  End Sub
