' Gambas module file

Private $cComp As New Collection
Private $aComp As New String[]

Public Sub Main()

  Dim hFile As File
  Dim sLine As String
  Dim sComp As String
  Dim hComp As CComponent
  Dim bDescription As Boolean

  hFile = Open "template/debian/control" For Input 
  
  For Each sLine In hFile.Lines
    
    If sLine Begins "Package: " Then
      
      sComp = Mid$(sLine, InStr(sLine, " ") + 1)
      If sComp Begins "gambas3-" Then
        'sComp = Mid$(sLine, 18)
        'If sComp Begins "gb-" Then sComp = Replace(sComp, "-", ".")
        hComp = New CComponent
        hComp.Name = sComp
        $cComp[sComp] = hComp
        $aComp.Add(sComp)
      Else 
        sComp = ""
        hComp = Null
      Endif
      bDescription = False
      
    Else If hComp Then
    
      If sLine Begins "Description: " Then
        
        hComp.Summary = Mid$(sLine, InStr(sLine, " ") + 1)
        bDescription = True
        
      Else If bDescription Then
        
        If sLine Begins " " Then
          sLine = LTrim(sLine)
          If sLine = "." Then 
            hComp.Description &= "\n"
          Else
            hComp.Description &= sLine & " "
          Endif
        Else 
          hComp.Description = Trim(hComp.Description)
          bDescription = False
        Endif
        
      Endif
      
    Endif
    
  Next
  
  Close #hFile

  For Each sComp In $aComp
    
    hComp = $cComp[sComp]
    
    hFile = Open Application.Path &/ "conf" &/ sComp For Create
    Print #hFile, "Summary="; Quote(hComp.Summary)
    Print #hFile, "Description="; Quote(hComp.Description)
    Close #hFile
    
  Next

End
