; Simple remake of robodoc
; This while Robodoc ist not able to generate a 'nice' HTML-Help or PDF
;
; Vorteile vom Wrapperdoc gegenüber dem Robodoc ist die höhere flexibilität beim Scannen.
; Wrapperdoc kann mehrere Verzeichnisse Scannen (Verzeichnisbäume), und auch die
; HTML-Ausgabe parametrisieren mit eigenen Templates !
;
; CodeSnippets : CompareWithWildcards() - Author: NicTheQuick
;
;TODOs 
;
;offen:
; definition variabler 'Text'-Files
; one-file ermöglichen (hmm, andere Templates....)
; PDF-Ausgabe
; Text-Ausgabe
; XML-Ausgabe ?

;
;erledigt:
; Simulation des SOURCE-Tags, um auch die Examples in die Doku einbauen zu können ->OK 18.04.2007
;
; einlesen und zusammenführung von Sourcen unterschiedlicher Quelle (z.B. c++ und PB), wobei hier
; tricky wäre, pro 'extention' ein unterschiedliches Set an markern zu definieren. -> vorbereitet 18.04.2007 ->OK 18.04.2007

; inline-tabellen (nur key/value) -> OK 18.04.2007
; sortieren -> ok 18.04.2007
; erstellen einer TOC -> OK 18.04.2007
; variablere Templates (Tag-Templates) -> OK 18.04.2007
; übernehmen von 'extra-daten" wie z.b. CSS, Images für HTMLHelp -> OK 18.04.2007
; Erstellen eines 'master-index-files- erstmal okay 17.4.2007
; Erstellen der 'Section-header' - erstmal okay 17.4.2007
; eigene Replacer im Settingsfile - erstmal okay 17.4.2007
;


;- Enums
Enumeration 
#WRAPPDOC_FORMAT_HTMLHELP
EndEnumeration

Enumeration 
#WRAPPDOC_TAG_KNOW
#WRAPPDOC_TAG_IGNORE
EndEnumeration

Enumeration 
  #WRAPPDOC_TAGFORMAT_NONE
  #WRAPPDOC_TAGFORMAT_SOURCE
  #WRAPPDOC_TAGFORMAT_LINE
  #WRAPPDOC_TAGFORMAT_TAB
  
EndEnumeration

;- Structs
Structure sTagInfo
  name.s
  type.l 
  Format.l 
  count.l
EndStructure

Structure sBlockDef
  blockstart.s
  blockend.s
  linestart.s 
EndStructure

Structure sPatternBlockDef
  pattern.s
  blockdef.sBlockDef
EndStructure

Structure sWrapperDocSettings
  defaultblock.sBlockDef
  output_format.l
  page_template.s
  tag_template.s
  output_path.s 
EndStructure

Structure sTag  
  name.s
  content.s
EndStructure

Structure sContent
  name.s
  RealName.s
  parent.s
  group.s
  File.s
  type.s
  Tags.sTag[256]
EndStructure

Structure sReplacer 
  key.s
  Value.s
EndStructure

Structure sGroup
  name.s
  parent.s
EndStructure

Structure sImportInfo
  File.s
  importtext.s 
  documented.l
EndStructure

Structure sJaPBeInfo
  text.s 
EndStructure

Structure sConstants
  text.s 
EndStructure



;- Global (Linked Lists ect.)
;Sorry, aber so ist es 'simpler' zu code, nicht gerade strukturierter.....
Global NewList content.sContent()
Global NewList Tags.sTagInfo()
Global NewList accept_files.s()
Global NewList ignore_files.s()
Global NewList source_paths.s()
Global NewList source_files.s()
Global NewList templates.sReplacer()
Global NewList user_replacers.sReplacer()
Global NewList groups.sGroup()
Global NewList patternblock.sPatternBlockDef()

Global NewList importinfo.sImportInfo()

Global settings.sWrapperDocSettings

; settings\blockstart = "/****"
; settings\blockend = "****"
; settings\linestart = "*"



default_page.s = "<html><head><title>@@NAME@@</title></head><body bgcolor=#FFFFDF link=#009999 vlink=#006666 alink=#006666>@@TAGS@@</body></html>"
; ;Template for 
default_tag.s = "<div width=600><h2>@@TAG@@</h2><br />@@VALUE@@</div>"


;entfernt den ersten Buchstaben
Macro chop(__text__)
  __text__ = Right(__text__,Len(__text__)-1)
EndMacro
;
;Holt sich einen Text der zwischen zwei 'markern' steht aus einem String.
;
Procedure.s  strBetween(String.s,startTag.s, endTag.s,startpos.l=1)
  start_pos_tmp.l = FindString(String,startTag,startpos)
  If start_pos_tmp> 0
    start_pos_tmp + Len(startTag)
    end_pos_tmp.l = FindString(String,endTag,start_pos_tmp)
    If end_pos_tmp> 0
      ProcedureReturn Mid(String, start_pos_tmp,  end_pos_tmp-start_pos_tmp) 
    EndIf
  EndIf 
  ProcedureReturn ""
EndProcedure      

;Author: NicTheQuick
;Forum: http://www.purebasic.fr/german/viewtopic.php?t=9625&start=0&postdays=0&postorder=asc&highlight=
;Date: 23 Okt 2006
Procedure CompareWithWildcards(String.s, StringToFind.s = "")
  Static oldStringToFind.s, max.l
  Static NewList vPart.s()
  Protected *c.Character, p.s = "", a.l, fr.l = #False, *c2.Character, *tmp
 
  Macro Add(zstring)
    If AddElement(vPart()) : vPart() = zstring : max + 1 : EndIf
  EndMacro
 
  If StringToFind = ""
    If oldStringToFind = "" : ProcedureReturn #False : EndIf
    StringToFind = oldStringToFind
  Else
    oldStringToFind = StringToFind
    ClearList(vPart())
    *c = @StringToFind : a = 0 : max = 0
    While *c\c
      If *c\c = '*'
        If a
          If ((Not PeekC(*c - SizeOf(Character)) = '*') And fr) Or max = 0
            If max Or fr : Add(p) : EndIf
            Add("*") : p = ""
            fr = #False
          Else
            p = ""
          EndIf
        Else
          Add("*")
        EndIf
      ElseIf *c\c = '?'
        If fr Or a = 0 : p + Chr(*c\c) : EndIf
      Else
        p + Chr(*c\c)
        fr = #True
      EndIf
      *c + SizeOf(Character) : a + 1
    Wend
   
    If p <> "" : Add(p) : EndIf
    max - 1
  EndIf
 
  a = 0
  *c = @String
  FirstElement(vPart())
  Repeat
    If vPart() = "*"
      If a = max
        ProcedureReturn #True
      EndIf
      *tmp = *c
      NextElement(vPart())
      Repeat
        *c = *tmp
        *c2 = PeekL(@vPart()) ;anders als bei Arrays
        While *c2\c
          If *c\c = 0 : ProcedureReturn #False : EndIf
          If *c2\c <> *c\c And *c2\c <> '?' : Break : EndIf
          *c + SizeOf(Character) : *c2 + SizeOf(Character)
        Wend
        If *c2\c = 0 : Break : EndIf
        *tmp + SizeOf(Character)
      ForEver
      *c = *tmp
    Else
      *c2 = PeekL(@vPart()) ;anders als bei Arrays
      While *c2\c
        If *c\c = 0 : ProcedureReturn #False : EndIf
        If *c2\c <> *c\c And *c2\c <> '?' : ProcedureReturn #False : EndIf
        *c + SizeOf(Character) : *c2 + SizeOf(Character)
      Wend
      If a = max And *c\c : ProcedureReturn #False : EndIf
      NextElement(vPart())
    EndIf
    a + 1
  Until a = max + 1
 
  ProcedureReturn #True
EndProcedure


;Fügt ein Tag aus den Settings-File ein
Procedure addTag(name.s, Format.l, type.l) 
  ForEach Tags()
    If Tags()\name = name 
      Tags()\Format = Format 
      Tags()\type=type 
      ProcedureReturn
    EndIf
  Next
  AddElement(Tags())  
  Tags()\name = name 
  Tags()\Format = Format 
  Tags()\type=type 
EndProcedure 

;Parst die Tags aus einem String, der im SettingFile steht.
Procedure setTagsFromStrings(items.s, Format, type)
  If Len(items) > 0
    count.l = CountString(items,Chr(10))  
    For i = 1 To count+1
      name.s = StringField(items,i,Chr(10))
      addTag(name,Format,type)
      AddElement(Tags())
    Next
  EndIf 
EndProcedure 

;Einträge in den Settings, simple AssoziativeListe...
NewList entries.sTag()

;Hile einen Eintrag aus der Liste.
Procedure.s _getEntry(key.s)
  Shared entries()
  ForEach entries() 
    If entries() \name = key  
      ProcedureReturn entries()\content
    EndIf
  Next
  ProcedureReturn ""
EndProcedure

Procedure.s _getTemplate(key.s)
  ForEach templates() 
    If templates()\key = key  
      ProcedureReturn templates()\Value
    EndIf
  Next
  ProcedureReturn ""
EndProcedure


Procedure  addPatternBlock(pattern.s)
  new.l = #True
  ForEach patternblock()
    If patternblock()\pattern = pattern
      new = #False 
      Break
    EndIf
  Next
  If new 
    AddElement(patternblock())
    patternblock()\pattern = pattern
  EndIf
 EndProcedure 
  
;Scanne das 'Settings'-File
;Dabei ist das Format an das deds RoboDoc angelehnt, allerdings 
;entsprechend der geplanten Nutzung, ist diese etwas anders.
;
; Ein Settingfile ist in verschiedene Einträge 'gesplitted'
; Jeder Eintrag steht zwischen zwei 'square brackets' (Bsp: [items])
; Zudem muss ein Eintrag in einer eigenen Zeile stehen, und beim ersten
; Zeichen der Zeile beginnen.
; 
Procedure scanSettings(filename.s) 
  Shared entries(), default_page.s, default_tag.s
  ;templates initialisieren  
  ClearList(templates())
  
  ;Die Liste wird geleert
  ClearList(entries())
  
  
  ;Und es wird ein Dummy-Eintrag hinzugefügt, damit immer ein aktueller Eintrag vorhanden ist.
  ;Das erspart uns ein prüfung bei jedem hinzufügen.....
  AddElement(entries())
  entries()\name = "DUMMY"  ; To catch not tagged thingies...
  inF.l = ReadFile(#PB_Any , filename) 
  If inF 
    Repeat 
      line.s = ReplaceString(ReadString(inF),Chr(9)," ")
      ;Ist das erste Zeichen eine '[', dann beginnt hier ein neuer Eintrag
      If Left(line,1) = "["
        ;Wir fügen einen Eintrag zur Eintragsliste (entries)
        AddElement(entries())
        ;Dann scannen wir den Namen, und setzten ihn am Eintrag
        entries()\name = strBetween(line,"[","]")
        ;prüfen ob ein Template definiert wurde
        If StringField(entries()\name,1,":") = "template" 
          AddElement(templates())
          templates()\key = StringField(entries()\name,2,":")
;          Debug("Template="+templates()\key)
        EndIf
        
        ;prüfen ob ein Replacer definiert wurde
        If StringField(entries()\name,1,":") = "replacer" 
          AddElement(user_replacers())
          user_replacers()\key = StringField(entries()\name,2,":")
        EndIf
        If FindString(entries()\name,":",1) > 0
          If StringField(entries()\name,1,":") = "start block"  
            addPatternBlock(StringField(entries()\name,2,":"))
          EndIf
          If StringField(entries()\name,1,":") = "end block"  
            addPatternBlock(StringField(entries()\name,2,":"))
          EndIf
          If StringField(entries()\name,1,":") = "line start"  
            addPatternBlock(StringField(entries()\name,2,":"))
          EndIf
        EndIf
        
        
        
        ;Ist das erste Zeichen ein '#', dann ist dies eine kommentarzeile und wird ignoriert.
      ElseIf Left(line,1) = "#"
        ; Do nothing...
      Else  
        ;Die Zeile enthielt weder Kommentar noch einen neuen Eintrag, also wird sie 
        ;zum aktuelle Eintrag hinzugefügt
        If Len(entries()\content) > 0
          entries()\content = entries()\content + Chr(10)+ Trim(line)
        Else
          entries()\content = Trim(line)
        EndIf
      EndIf
    Until Eof(inF) 
    CloseFile(inF)  
  EndIf
  
  ;Dies ist nur ein simples Dumping, welches später entfernt werden kann
  ; ForEach entries()  
    ; Debug("TAG="+entries()\name) 
    ; Debug("CONTENT="+entries()\content) 
  ; Next
  ; 
  ;Jetzt werden die Einträge ausgewertet. 
  ;Zuerst die verschiedenen Items-typen
  items.s = _getEntry("items")
  setTagsFromStrings(items,#WRAPPDOC_TAGFORMAT_NONE, #WRAPPDOC_TAG_KNOW)
  items.s = _getEntry("ignore items")
  setTagsFromStrings(items,#WRAPPDOC_TAGFORMAT_NONE, #WRAPPDOC_TAG_IGNORE)
  items.s = _getEntry("line items")
  setTagsFromStrings(items,#WRAPPDOC_TAGFORMAT_LINE, #WRAPPDOC_TAG_KNOW)
  items.s = _getEntry("source items")
  setTagsFromStrings(items,#WRAPPDOC_TAGFORMAT_SOURCE, #WRAPPDOC_TAG_KNOW)
  items.s = _getEntry("tab items")
  setTagsFromStrings(items,#WRAPPDOC_TAGFORMAT_TAB, #WRAPPDOC_TAG_KNOW)
  
  ; jetzt holen wir die Pattern für die erlauben Files
  items.s = _getEntry("accept files")
  If Len(items) > 0
    count.l = CountString(items,Chr(10))  
    For i = 1 To count +1
      name.s = StringField(items,i,Chr(10))
      AddElement(accept_files()) : accept_files() = name : Debug("Accept-FILE="+name)
    Next
  EndIf 
  ; jetzt holen wir die Pattern für die zu ignorierenden Namen
  items.s = _getEntry("ignore files")
  If Len(items) > 0
    count.l = CountString(items,Chr(10))  
    For i = 1 To count +1
      name.s = StringField(items,i,Chr(10))
      AddElement(ignore_files()) : ignore_files() = name : Debug("IGNORE-FILE="+name)
    Next
  EndIf 
  ;Und nun benötigen wir noch die Source-Pfade
  items.s = _getEntry("source path")
  If Len(items) > 0
    count.l = CountString(items,Chr(10))  
    For i = 1 To count +1
      name.s = StringField(items,i,Chr(10))
      AddElement(source_paths()) : source_paths() = name : Debug("SOURCE-PATH="+name)
    Next
  EndIf 

  ;erst die Deafults
  
  settings\defaultblock\blockstart = "/****"
  settings\defaultblock\blockend = "****"
  settings\defaultblock\linestart = "*"
  
  
  settings\defaultblock\blockstart = _getEntry("block start")
  settings\defaultblock\blockend = _getEntry("block end")
  settings\defaultblock\linestart = _getEntry("line start")
  
  
  
  AddElement(templates()) : templates()\key = "page" : templates()\Value = default_page 
  AddElement(templates()) : templates()\key = "tag" : templates()\Value = default_tag
  
  ;jetzt suchen wir die 'values' der templates
  ForEach templates() 
    templates()\Value = _getEntry("template:"+templates()\key)
;    Debug("tempalte="+templates()\key + " / content=" +templates()\Value)
  Next
  
  ;jetzt suchen wir die 'values' der replacers
  ForEach user_replacers() 
    user_replacers()\Value = _getEntry("replacer:"+user_replacers()\key)
  Next
  
  
  ; pattern/filetype-basierte blockdefs 
  ForEach patternblock()
    patternblock()\blockdef\blockstart = _getEntry("block start:"+patternblock()\pattern)
    patternblock()\blockdef\blockend = _getEntry("block end:"+patternblock()\pattern)
    patternblock()\blockdef\linestart = _getEntry("line start:"+patternblock()\pattern)
  Next
  
  
  
  ; ;Prüfen ob die 'wichtigen' templates gesetzt sind !
  ; v.s = _getTemplate("page")
  ; If Len
  ; 
  ; page = _getEntry("page template")
  ; basic = _getEntry("tag template")

EndProcedure


Procedure ScanLineForImport(line.s,File.s,inBlock.l) 
  If Left(line, 10) = "#PBIMPORT:"
    AddElement (importinfo())
    importinfo()\File = File
    importinfo()\importtext = StringField(line,2,":")
    importinfo()\documented = inBlock
  EndIf
EndProcedure


;******************************************************************************
; This function scans a file against the 'doc'-Format and extracts
; all information out.
;
; Diese Function scant ein Source-File. wobei hier die entsprechenden 'Marker' genutzt
; werden.  Wichtig ist, das hier auch nur die Tags übernommen werden, die im Settings-File
; angegeben wurden.

Procedure scanFile(filename.s, *blockdef.sBlockDef) 
  Debug("Scan File:" + filename)
  Debug("BlockStart="+*blockdef\blockstart)
  Debug("BlockEnd="+*blockdef\blockend)
  Debug("")
  inF.l = ReadFile(#PB_Any , filename) 
  If inF 
    inBlock.l = #False
    inTag.l = #False
    TagNum.l = -1
    ZeilenAnzahl.l = 0 
    ignoreLineStart.l = #False
    Repeat 
      line.s = ReadString(inF)
      ScanLineForImport(line,filename, inBlock)
      If inBlock = #False
        ; prüfen ob Block startet
        If Left(line,Len(*blockdef\blockstart)) = *blockdef\blockstart 
          ;scan den header..... 
          AddElement(content())
          content()\File = filename
          content()\type = Mid(line,Len(*blockdef\blockstart )+1,1)
          content()\name = StringField(line,2," ") 
          If Left(content()\name,1) = "/" :  chop(content()\name) : EndIf
 ;         Debug("NEW BLOCK type= "+content()\type)
          
          inBlock = #True
          inTag.l = #False
          TagNum.l = -1
        EndIf
        
      Else
        If Left(line,Len(*blockdef\blockend)) = *blockdef\blockend 
          inBlock=#False
        Else
          ;Ist es eine 'gültige' Zeile ?
          If Left(line,Len(*blockdef\linestart)) = *blockdef\linestart  Or ignoreLineStart = #True
            If Left(line,Len(*blockdef\linestart)) = *blockdef\linestart
              line = Right(line,Len(line)-Len(*blockdef\linestart  ))
            EndIf 
            ; Wir sind im Block, un müssen nun auf 'Tags' achten
            tagname.s = UCase(StringField(line,2," ")) 
            inTag = #False
            ;nein, dann schauen, ob wir eines haben..... 
            ForEach Tags()
              If Len(Tags()\name) > 0 And Tags()\name = tagname
                ;Gotcha !
                inTag=#True 
                TagNum + 1 
  ;;              Debug("ADD-TAG="+tagname)
                content()\Tags[TagNum]\name = tagname 
                ; versuchen das SOURCE-Tag von ROBODOC zu simulieren (aber flexibler)
                If tagname = "SOURCE"
;                  Debug("FOUND SOURCE")
                  ignoreLineStart=#True
                Else
                  ignoreLineStart=#False 
                EndIf
                Break;
              EndIf 
            Next
            If inTag = #False
              ; wir sind bereits in einem Tag 
;;              Debug("ADD-CONTENT="+line)
              content()\Tags[TagNum]\content = content()\Tags[TagNum]\content + Chr(10) + line
            EndIf
          EndIf
        EndIf
      EndIf
    Until Eof(inF) 
    CloseFile(inF) 
  EndIf
EndProcedure


;Unter nutzung der Wildcards wird ermittelt, ob dieses File/Dir gescannt werden darf.
;bzw. es nicht als zu ignorierend eingestuft wird.
Procedure isReadAllowed(name.s)
  ForEach ignore_files()
    If CompareWithWildcards(name,ignore_files()) 
      ProcedureReturn #False 
  EndIf
  Next
  ProcedureReturn #True
EndProcedure

;Unter nutzung der Wildcards wird ermittelt, ob dieses File/ gescannt werden darf.
;bzw. es zu den accepte-file-pattern passt.
Procedure isScanFile(name.s)
  ForEach accept_files()
    If CompareWithWildcards(name,accept_files()) 
      ProcedureReturn #True 
  EndIf
  Next
  ProcedureReturn #False
EndProcedure
 

; Hier findet das eigentliche 'durchwühlen' der Verzeichhnisse statt. Unter nutzung der sourcepfade
; und der pattern (accct/ignore) werden die erlaubten Files gescannt (scanFile() )
Procedure ReadDirs(Path.s, Rek.l)  
  If Right(Path, 1) = "\" : Path = Left(Path, Len(Path) - 1) : EndIf  
  
  NextOK.l  
  name.s  
  ExamineDirectory(Rek, Path, "")  
   
  Repeat  
    NextOK = NextDirectoryEntry(Rek)  
    type.l = DirectoryEntryType(Rek)
    name = DirectoryEntryName(Rek)  
    
    If isReadAllowed(name)  And NextOK
      If type = #PB_DirectoryEntry_Directory And name <> "." And name <> ".."  
        ReadDirs(Path + "\" + name, Rek + 1)  
      ElseIf type = #PB_DirectoryEntry_File  And isScanFile(name)  
        AddElement(source_files()): source_files() = Path + "\" + name
      EndIf  
    EndIf 
  Until NextOK = #False  
  FinishDirectory(Rek)
EndProcedure  

;Durch alle Source-Pfadee suchen !
Procedure makeFileList() 
  ForEach source_paths()
    ReadDirs(source_paths(),0)
  Next
  ForEach source_files()
;;    Debug("Source-File:" + source_files())
  Next
EndProcedure

; Inlinetable sollen ermöglichen einfache tablellen einzubauen
; der Syntax soll folgender sein :
; [TAB]
; [/TAB]
; jede Zeile dazwischen wird beim ersten '-' getrennt und auf key/value gemappt.
Procedure.s inlineTables(content.s)
  Result.s = ""
  count_line.l = CountString(content,Chr(10))
  inTable.l = #False
  For v = 1 To  count_line+1 
    thisline.s = StringField(content,v,Chr(10))
    If inTable
      If FindString(thisline,"[/TAB]",1) > 0
        Result = Result+"</table>"+Chr(10)
        inTable=#False 
      Else 
        Result = Result + "<tr><td>"+StringField(thisline,1,"-")+"</td><td>"+StringField(thisline,2,"-")+"</td></tr>"+Chr(10)
      EndIf 
    Else 
      If FindString(thisline,"[TAB]",1) > 0 
        inTable=#True 
        Result = Result+"<table>"+Chr(10)
      Else
        If Len(Result) = 0
          Result = thisline 
        Else
          Result = Result + Chr(10) + thisline 
        EndIf
      EndIf
    EndIf
  Next
  
  ProcedureReturn Result
EndProcedure



;Ein Tag Formatieren entsprechnd seines 'Formates' 
Procedure.s formatTag(tag.s, content.s) 
  Result.s = ""
  Format.l = #WRAPPDOC_TAGFORMAT_NONE
  ForEach Tags()
    If Tags()\name = tag 
      Format = Tags()\Format
    EndIf
  Next
  
  content = inlineTables(content)
  
  Select Format 
    Case #WRAPPDOC_TAGFORMAT_SOURCE
      ;      Debug("TAGFORMAT:  #WRAPPDOC_TAGFORMAT_SOURCE ("+tag+")")
      Result = ReplaceString(content,Chr(10),"<br />")
    Case #WRAPPDOC_TAGFORMAT_LINE
;      Debug("TAGFORMAT:  #WRAPPDOC_TAGFORMAT_LINE ("+tag+")")
      Result = ReplaceString(content,Chr(10),"<br />")
    Case #WRAPPDOC_TAGFORMAT_TAB
;      Debug("TAGFORMAT:  #WRAPPDOC_TAGFORMAT_TAB ("+tag+")")
      Result.s = "<table border=0>"
      count_line.l = CountString(content,Chr(10))
      paraname.s = ""
      paravalue.s =""
      For v = 1 To  count_line+1 
        thisline.s = StringField(content,v,Chr(10))
        If CountString(thisline,"-") = 1
          If Len(paraname)  > 0
            Result = Result + "<tr><td valign="+Chr(34)+"top"+Chr(34)+"><b>"+paraname+"</b></td><td valign="+Chr(34)+"top"+Chr(34)+">&nbsp;-&nbsp;<td valign="+Chr(34)+"top"+Chr(34)+">"+paravalue+"</td></tr>" 
          EndIf
          paraname = Trim(StringField(thisline,1,"-"))
          paravalue = Trim(StringField(thisline,2,"-"))
        ElseIf CountString(thisline,"-") = 0
          paravalue = paravalue+"<br />"+Trim(thisline)
        EndIf
        ; If Len(Trim(thisline)) > 0
          ; result = result + "<tr><td><b>"+Trim(StringField(thisline,1,"-"))+"</b></td><td>&nbsp;-&nbsp;<td>"+Trim(StringField(thisline,2,"-"))+"</td></tr>"
        ; EndIf
      Next
      If Len(paraname)  > 0
        Result = Result + "<tr><td><b>"+paraname+"</b></td><td>&nbsp;-&nbsp;<td>"+paravalue+"</td></tr>" 
      EndIf
      Result = Result + "</table>"
    Default:
      Result = content
  EndSelect
  
  ProcedureReturn Result
EndProcedure

Procedure gatherConstants(tag.s, content.s) 
  Result.s = ""
  Format.l = #WRAPPDOC_TAGFORMAT_NONE
  ForEach Tags()
    If Tags()\name = tag 
      Format = Tags()\Format
    EndIf
  Next 
EndProcedure 

; Die Anzahl der Undokumentierten Funktionen ist vielleicht interessant.....
 ;im Lauf der Zeit sollte diese Zahl gen Null gehen!
; Diese Funkrin setzt hierbei auch das documented-Flag an dem Imports,
; damit man auch für z.B. jaPBe und Doku(HTML) eine übersicht machen kann.
Procedure determineUndocumented() 
  
  undocumented.l = 0
  ForEach(importinfo())
    stext.s = UCase(StringField(importinfo()\importtext,1,"("))
    found_doku.l = #False
    ForEach content()
      If UCase(content()\RealName) = stext
        found_doku.l = #True
        Break
      EndIf
    Next
    importinfo()\documented = found_doku
    If found_doku = #False
      undocumented + 1
    EndIf
  Next
  ProcedureReturn undocumented
EndProcedure


Procedure buildImportfile(outdir.s)
  Protected NewList mGroups.s()
  
  If Right(outdir,1) <> "/" And Right(outdir,1) <> "\" : outdir+"/" : EndIf
  outname.s = Trim(_getEntry("importfile"))
  outname = Trim(StringField(outname,1,Chr(10)))
  If Len(Trim(outname)) = 0 : outname =" _wrapperDoc_importfile_out.pbi": EndIf
  Debug("Importfilename:"+outdir +  outname +":")
  
  ForEach(importinfo())
    found.l = #False
    ForEach mGroups()
      If mGroups() = importinfo()\File
        found = #True
        Break
      EndIf
    Next
    If found = #False 
      AddElement(mGroups())
      mGroups() = importinfo()\File
    EndIf
  Next
  
  undocumented.l = determineUndocumented()
  
   
  outF.l =  CreateFile(#PB_Any,outdir +  outname)
  If outF 
    Debug("File created")
    WriteStringN(outF,";Importfile Generated by wrapperDoc")
    WriteStringN(outF,";Number of Scanned Files:"+Str(CountList(mGroups())) )
    WriteStringN(outF,";Number of Functions:"+Str(CountList(importinfo()))) 
    WriteStringN(outF,";Not Documented / only imported : "+Str(undocumented)) 
    WriteStringN(outF,"")
    WriteStringN(outF,"Import #PB_Compiler_Home + "+Chr(34)+"Includes\Libraries\win32\Newton.lib"+Chr(34))
    WriteStringN(outF,"EndImport")
    WriteStringN(outF,"") 
    WriteStringN(outF,"Import #PB_Compiler_Home + "+Chr(34)+"Includes\Libraries\win32\Irrklang.lib"+Chr(34))
    WriteStringN(outF,"EndImport")
    WriteStringN(outF,"") 
    
    WriteStringN(outF,"ImportC #PB_Compiler_Home + "+Chr(34)+"includes\Libraries\win32\IrrlichtWrapper.lib"+Chr(34))

    ForEach mGroups()
      WriteStringN(outF," ; ----------------------------------------------------------")
      WriteStringN(outF," ;from File : "+ mGroups())
      ForEach(importinfo())
        If  importinfo()\File = mGroups()
          WriteStringN(outF,"    "+importinfo()\importtext) 
        EndIf
      Next
  
      
      ForEach content()  
        If content()\File = mGroups()
        For I = 0 To 255
          If Len(content()\Tags[I]\name) > 0  
            If content()\Tags[I]\name = "PBINLINE"   ;fiddle in some Source-Fragments....
              outer.s = ReplaceString(content()\Tags[I]\content,Chr(10),Chr(13)+Chr(10)) 
              WriteStringN(outF,"    "+outer)  
            EndIf
          EndIf
        Next
      EndIf
      
      
      Next
      
        
    Next
    
    WriteStringN(outF,"EndImport")
    WriteStringN(outF,"") 
    CloseFile(outF)
  Else
    Debug("No File created !!")
    
  EndIf
  
    
  
EndProcedure



;Erstmal hardcodiert, später wäre ein Template auch denkbar....
Procedure build_jaPBe_file(outdir.s)
  Protected NewList mGroups.s()
  
  If Right(outdir,1) <> "/" And Right(outdir,1) <> "\" : outdir+"/" : EndIf
  outname.s = Trim(_getEntry("japbefile"))
  outname = Trim(StringField(outname,1,Chr(10)))
  If Len(Trim(outname)) = 0 : outname =" _wrapperDoc_japbefile_out.txt": EndIf
  Debug("Importfilename:"+outdir +  outname +":")
  
  outF.l =  CreateFile(#PB_Any,outdir +  outname)
  If outF 
    Debug("File created")
    WriteStringN(outF,";Reference Generated by wrapperDoc")
    WriteStringN(outF,"/Procedure")
    
    ForEach content()  
      synopsis.s=""
      info.s=""
      For I = 0 To 255
        If Len(content()\Tags[I]\name) > 0  
          If content()\Tags[I]\name = "NAME"  ;wir brauchen den Namen wg. der Info
            info = StringField(content()\Tags[I]\content,2,"-")
          EndIf
          If content()\Tags[I]\name = "SYNOPSIS"  ;wir brauchen den Namen wg. der Info
            pos_eq.l = FindString(content()\Tags[I]\content,"=",1)
            If pos_eq<> 0
              synopsis = Right(content()\Tags[I]\content,Len(content()\Tags[I]\content)-pos_eq-1) 
            Else
              synopsis= content()\Tags[I]\content
            EndIf
          EndIf
        EndIf
      Next
      out_text.s =  Trim(synopsis) + " - " + Trim(info)
      out_text = ReplaceString( out_text,Chr(10),"")
      out_text = ReplaceString( out_text,Chr(9),"")
      If Len(Trim(synopsis)) > 0
        WriteStringN(outF,Trim(out_text)) 
      EndIf
      
    Next
    
    ; now the undocumented ones...
    ForEach importinfo() 
      If importinfo()\documented = #False 
        WriteStringN(outF,Trim(importinfo()\importtext))  
      EndIf
    Next
    CloseFile(outF)
  Else
    Debug("No File created !!")
    
  EndIf
  
  
  
EndProcedure

Procedure build_desc_entry(outF.l, txt.s, info.s) 
  entries.s = strBetween(txt,"(",")")
  name.s = Trim(StringField(txt, 1, "(") )  
  count.l = CountString(entries,",")
  
  Debug("entries="+entries)
  Debug("name="+name)
  Debug("count="+Str(count))

  out.s = name + ","
  
  out2.s = "("
  
  For i = 1 To count+1
    entry.s = Trim(StringField(StringField(entries,i,","),1,"="))
    
    
    out2 + entry
           
    
    Debug("entry="+entry)
        
    format.s = StringField(entry,2,".") 

    Debug("format="+format)
    
    Select format 
      Case "b"
        out +"Byte"
      Case "l"
        out +"Long"
      Case "s"
        out +"String"
      Case "f"
        out +"Float"
      Case "d"
        out +"Double"
      Case "q"
        out +"Quad"
      Default
        out +"any"
    EndSelect        
       
       
    If i <> count+1
      out+","
      out2+","
    EndIf
    
    
    
  Next
      
      
      
;    PeekL, Long (Address) - Retrieve a long from the specified address
;    Long | DebuggerCheck      
    

  Debug(out + " "+out2+")" + " - "+info)          
  Debug("Long")          
    
    
  WriteStringN(outF, out + " "+out2+")" + " - "+info)          
  WriteStringN(outF, "Long")          
    
  
  
  
  

EndProcedure 
;Erstmal hardcodiert, später wäre ein Template auch denkbar....
Procedure build_userlib_file(outdir.s)
  
  If Right(outdir,1) <> "/" And Right(outdir,1) <> "\" : outdir+"/" : EndIf

  outname.s = Trim(_getEntry("userlibfile"))
  outname = Trim(StringField(outname,1,Chr(10)))

  If Len(Trim(outname)) = 0 : outname =" _wrapperDoc_userlib_out.desc": EndIf

  Debug("Importfilename:"+outdir +  outname +":")
  
  outF.l =  CreateFile(#PB_Any,outdir +  outname)
  If outF 
    Debug("File created")
    
    WriteStringN(outF,";File Generated by wrapperDoc")
    WriteStringN(outF,";")
    WriteStringN(outF,"C")
    WriteStringN(outF,"3")
    WriteStringN(outF,"irrlicht.dll")
    WriteStringN(outF,"newton.dll")
    WriteStringN(outF,"irrklang.dll")
    WriteStringN(outF,";")
    WriteStringN(outF,"LIB")
    WriteStringN(outF,";")
    WriteStringN(outF,"Misc")
    WriteStringN(outF,";")
    
    
    ForEach(importinfo())
      info.s = ""
      name.s = Trim(StringField(importinfo()\importtext, 1, "(") )  
      
      ForEach content()  
        If name = content()\RealName 
          For I = 0 To 255
            If Len(content()\Tags[I]\name) > 0  
              If content()\Tags[I]\name = "NAME"  ;wir brauchen den Namen wg. der Info
                info = StringField(content()\Tags[I]\content,2,"-")
              EndIf
            EndIf
          Next  
        EndIf  
      Next 
      build_desc_entry(outF, importinfo()\importtext, info)             
      
    Next
    CloseFile(outF)
  Else
    Debug("No File created !!")
    
  EndIf
  
   
EndProcedure

  
Procedure isOutputTag(tagname.s)
  ForEach Tags()
    If Tags()\name = tagname
      If Tags()\type = #WRAPPDOC_TAG_IGNORE
        ProcedureReturn #False
      EndIf
    EndIf
  Next  
  ProcedureReturn #True
EndProcedure


;Hier werden die eingescannten Daten zu HTML-Files verpackt. Dies unter nutzung der
;Templates und auch der verschiedenen Tag-Typen
;TODO: Das ersetzen der verscheidenen 'Platzhalter' sollte Dynamischer sein, so das evtl.
;           auch im Settings-File entsprechende Replacer definiert werden. z.B. Texte/Autoren/Links....
Procedure buildFiles(outdir.s) 
  ;  Shared basic.s,page.s
  If Right(outdir,1) <> "/" And Right(outdir,1) <> "\" : outdir+"/" : EndIf
  
    ; Baue Replacers, und suche den 'RealName....
  NewList replacers.sReplacer()  
  ForEach content() 
    sc.l = CountString(content()\name,"/") 
      content()\RealName = StringField(content()\name,sc+1,"/")
      content()\group = StringField(content()\name,sc,"/")
      If content()\type <> "h"
        AddElement(replacers())
        replacers()\key = " "+content()\RealName
        replacers()\Value = " <a href="+Chr(34)+content()\RealName+".html"+Chr(34)+">"+content()\RealName+"</a>"
      EndIf 
    Next
    SortStructuredList(replacers(),1,OffsetOf(sReplacer\key),#PB_Sort_String)
    
    templPage.s = _getTemplate("page")
    templTag.s   = _getTemplate("tag")
    ForEach content()
      Tags.s = ""
      
      For I = 0 To 255
        If Len(content()\Tags[I]\name) > 0  
          thisTempl.s = _getEntry("template:#"+content()\Tags[I]\name)
          If Len(thisTempl)=0 : thisTempl = templTag: EndIf
          If isOutputTag(content()\Tags[I]\name)
            tagvalue.s = formatTag(content()\Tags[I]\name,content()\Tags[I]\content)
            Tags  = Tags + ReplaceString(ReplaceString(thisTempl,"@@TAG@@",content()\Tags[I]\name),"@@VALUE@@",tagvalue)
            Tags  = ReplaceString(Tags,"@@TAG-LOWER@@",LCase(content()\Tags[I]\name))
           EndIf
        EndIf
      Next
      If content()\type = "h"
        groupname.s = content()\RealName
        ; Wenn es ein Header-File ist, dann bauen wir den 'kleinen' index noch dran !
        out.s ="Contents=<br /><ul>"
        altIndex.l = ListIndex(content())
        ForEach content()
          If content()\group = groupname
            out=out + "<li><a href="+Chr(34)+content()\RealName+".html"+Chr(34)+">"+content()\RealName+"</a></li>"
            EndIf
        Next
        out=out+"</ul>"
        SelectElement(content(),altIndex)
        Tags = Tags + out
        EndIf
      pagia.s = ReplaceString(ReplaceString(templPage,"@@NAME@@",content()\RealName),"@@TAGS@@",Tags)
      pagia  = ReplaceString(pagia,"@@SECTION@@",content()\group)
      
      ForEach replacers() 
        pagia = ReplaceString(pagia,replacers()\key,replacers()\Value)
      Next
      
      ForEach user_replacers() 
        pagia = ReplaceString(pagia,"@@"+user_replacers()\key+"@@",user_replacers()\Value)
      Next
      
      
      
      
      outname.s = content()\RealName
      If Left(outname,1) = "#"
        chop(outname)
      EndIf
     outF.l = CreateFile(#PB_Any,outdir+outname+".html")
     If outF 
        WriteString(outF,pagia)
        CloseFile(outF)
    EndIf
    
  ;  Debug(pagia)
  Next

EndProcedure 

;Sortiert die 'Entries' in Gruppen, und füllt die Gruppen-Liste
Procedure makeGroups() 
  ForEach content()
    sc.l = CountString(content()\name,"/") 
    If sc = 1
      ;wir habe eine Gruppe ! 
      groupname.s = StringField(content()\name,1,"/")
      found.l = #False
      ForEach groups() 
        If groups()\name = groupname 
          found = #True 
          Break 
        EndIf
      Next
      If found = #False
        AddElement(groups())
        groups()\name = groupname
      EndIf
      content()\parent = groupname
    EndIf 
  Next 
  SortStructuredList(groups(),2,OffsetOf(sGroup\name),#PB_Sort_String)
EndProcedure

Procedure makeRealName()
  ForEach content()
    sc.l = CountString(content()\name,"/") 
    content()\RealName = StringField(content()\name,sc+1,"/")
  Next
EndProcedure

;Diese Function übernimmt die 'tricky'-Aufgabe die HTMLHELP-Projektdateien zu erstellen !
Procedure buildHtmlHelp(outdir.s, help_file.s) 

  If Right(outdir,1) <> "/" And Right(outdir,1) <> "\" : outdir+"/" : EndIf
  help_file= outdir + help_file
    
    ;nun habe wir este eine flache Hierarchie, aber genug für den Anfang....
    
    ;schreibe hhc
    outF =  CreateFile(#PB_Any,help_file+".hhc") 
  If outF 
    WriteStringN(outF,"<!DOCTYPE HTML PUBLIC "+Chr(34)+"-//IETF//DTD HTML//EN"+Chr(34)+">")
      WriteStringN(outF,"<HTML>")
      WriteStringN(outF,"<HEAD>")
      WriteStringN(outF,"<meta name="+Chr(34)+"GENERATOR"+Chr(34)+" content="+Chr(34)+"libdesc"+Chr(34)+">")
      WriteStringN(outF,"<!-- Sitemap 1.0 -->")
      WriteStringN(outF,"</HEAD><BODY>")
      
      WriteStringN(outF,"<UL>")
      WriteStringN(outF,"<LI> <OBJECT type="+Chr(34)+"Text/sitemap"+Chr(34)+">")
      WriteStringN(outF,"<param name="+Chr(34)+"name"+Chr(34)+" Value="+Chr(34)+"index"+Chr(34)+">")
      WriteStringN(outF,"<param name="+Chr(34)+"Local"+Chr(34)+" Value="+Chr(34)+"masterindex.html"+Chr(34)+">")
      WriteStringN(outF,"</OBJECT>")
      WriteStringN(outF,"</UL>")
      
      WriteStringN(outF,"<OBJECT type="+Chr(34)+"text/site properties"+Chr(34)+">")
      WriteStringN(outF,"<param name="+Chr(34)+"ImageType"+Chr(34)+" value="+Chr(34)+"Folder"+Chr(34)+">")
      WriteStringN(outF,"</OBJECT>")
      WriteStringN(outF,"<UL>")
      
      ForEach(groups())
          If Len(groups()\name) = 0
            Continue
          EndIf
          WriteStringN(outF,"<LI> <OBJECT type="+Chr(34)+"text/sitemap"+Chr(34)+">")
          WriteStringN(outF,"<param name="+Chr(34)+"name"+Chr(34)+" value="+Chr(34)+groups()\name+Chr(34)+">");
          WriteStringN(outF,"<param name="+Chr(34)+"Local"+Chr(34)+" value="+Chr(34)+ groups()\name+".html"+Chr(34)+">")
;          WriteStringN(outF,"<param name="+Chr(34)+"Local"+Chr(34)+" value="+Chr(34)+outdir + groups()\name + ".html"+Chr(34)+">")
          WriteStringN(outF,"<param name="+Chr(34)+"ImageNumber"+Chr(34)+" value="+Chr(34)+"1"+Chr(34)+">")
        WriteStringN(outF,"</OBJECT>");                   
        WriteStringN(outF,"<UL>");
        ForEach(content())
          If Len(content()\name) = 0
            Continue
          EndIf
          If content()\parent <> groups()\name
            Continue
          EndIf
          file_out.s = content()\RealName +".html" ;outdir + content()\RealName + ".html" 
          WriteStringN(outF,"<LI> <OBJECT type="+Chr(34)+"text/sitemap"+Chr(34)+">")
          WriteStringN(outF,"<param name="+Chr(34)+"name"+Chr(34)+" value="+Chr(34)+content()\RealName+Chr(34)+">");
          WriteStringN(outF,"<param name="+Chr(34)+"Local"+Chr(34)+" value="+Chr(34)+file_out+Chr(34)+">")
          WriteStringN(outF,"</OBJECT>");
        Next
        WriteStringN(outF,"</UL>")        
      Next
  
        WriteStringN(outF,"</UL>")
      WriteStringN(outF,"</BODY></HTML>")
      CloseFile(outF)
      
    Else
      Debug("Can't create HHC" + help_file);
    EndIf

    outF =  CreateFile(#PB_Any,help_file+".hhp")   

    If outF 
      WriteStringN(outF,"[OPTIONS]")
      WriteStringN(outF,"Compatibility=1.1 Or later")
      WriteStringN(outF,"Compiled file="+help_file+".chm")
      WriteStringN(outF,"Contents file="+help_file+".hhc")
      WriteStringN(outF,"Default topic="+ "masterindex.html")
      WriteStringN(outF,"Display compile progress=No")
      WriteStringN(outF,"Title="+ _getEntry("document title") )
      WriteStringN(outF,";Index file="+help_file+".hhk")
      WriteStringN(outF,"Language=0x407 Deutsch (Deutschland)")
      WriteStringN(outF,"")
      WriteStringN(outF,"[FILES]")

      ForEach(content())
        If Len(content()\name) = 0
          Continue
        EndIf
        file_out.s = content()\RealName + ".html" 
        WriteStringN(outF,file_out )
      Next
      
      ;now the additional file
      add_files.s = _getEntry("additional files")
      If Len(Trim(add_files)) > 0
        count.l = CountString(add_files,Chr(10))  
        For I = 1 To count+1
          name.s = Trim(StringField(add_files,I,Chr(10)))
          WriteStringN(outF,name) 
        Next
      EndIf 
      
      
      WriteStringN(outF,"[INFOTYPES]");
      CloseFile(outF)
    Else
      
      
      
      Debug("Can't create HHP " + help_file);
    EndIf
EndProcedure


Procedure buildMasterIndex(filename.s)
  ;  If Right(filename,1) <> "/" And Right(filename,1) <> "\" : filename+"/" : EndIf

  out.s = "<ul>"
  
  ForEach(groups())
    If Len(groups()\name) = 0
      Continue
    EndIf
    out = out + "<li><a href="+Chr(34)+groups()\name+".html"+Chr(34)+">"+groups()\name+"</a></li>"
    out = out + "<ul>"
    ForEach(content())
      If Len(content()\name) = 0
        Continue
      EndIf
      If content()\parent <> groups()\name
        Continue
      EndIf
      usename.s = content()\RealName
      usetext.s=""
      For iz = 0 To 255 
        If content()\Tags[iz]\name = "NAME" 
          usetext = Trim(StringField(content()\Tags[iz]\content,2,"-"))
        EndIf
      Next
      
      out = out + "<li><a href="+Chr(34)+content()\RealName + ".html" +Chr(34)+">"+usename + "</a>&nbsp;&nbsp;-&nbsp;&nbsp;<i>"+usetext+"</i></li>"
    Next
    out = out +"</ul>"
  Next
  out = out +"</ul>"
  
  templPage.s = _getTemplate("masterindex")
  If Len(templPage) = 0 : _getTemplate("page") : EndIf
    
  pagia.s = ReplaceString(ReplaceString(templPage,"@@NAME@@","Index"),"@@INDEX@@",out)
  pagia = ReplaceString(pagia,"@@PROJECTNAME@@",_getEntry("document title"))
  ; ForEach replacers() 
  ; pagia = ReplaceString(pagia,replacers()\key,replacers()\Value)
  ; Next
  
  ForEach user_replacers() 
    pagia = ReplaceString(pagia,"@@"+user_replacers()\key+"@@",user_replacers()\Value)
  Next
  outF.l = CreateFile(#PB_Any,filename)
  If outF 
    WriteString(outF,pagia)
    CloseFile(outF)
  Else
    MessageRequester("oops","could not write "+ filename)
  EndIf
  
  ;Debug("MASTERINDEX="+pagia)
  
EndProcedure

Procedure buildTableOfContent(filename.s)
  NewList alphs.s()
  For I = 65 To 90 ; A-Z 
    AddElement(alphs()): alphs() = Chr(I)
  Next
  
  out.s = "<ul>"
  ForEach alphs()
    out = out + "<li><a name="+Chr(34)+alphs()+Chr(34)+"><b>"+alphs()+"</b></a></li>"
    out=out +"<ul>"
    ForEach content() 
      If UCase(Left(content()\RealName,1)) = alphs() 
        out = out + "<li><a href="+Chr(34)+content()\RealName+".html"+Chr(34)+">"+content()\RealName+"</a></li>"
      EndIf
    Next
    out=out +"</ul>" 
  Next
  out=out +"</ul>"
  
  templPage.s = _getTemplate("page")
  pagia.s = ReplaceString(ReplaceString(templPage,"@@NAME@@","TOC"),"@@TAGS@@",out)
   
  ForEach user_replacers() 
    pagia = ReplaceString(pagia,"@@"+user_replacers()\key+"@@",user_replacers()\Value)
  Next
  outF.l = CreateFile(#PB_Any,filename)
  If outF 
    WriteString(outF,pagia)
    CloseFile(outF)
  Else
    MessageRequester("oops","could not write "+ filename)
  EndIf
EndProcedure
  
  

;Hier ist eine Test-Area, die später durcxh das Parsen der Kommandozeile, und evtl durch
;eine jkleine GUI ersetzt wird.

parameters.l = CountProgramParameters()
If parameters <> 1 
  End 
EndIf


settingfile.s = ProgramParameter(); "t:\projects\IrrlichtWrapperSVN\IrrlichtWrapper_1_05\Dokumentation\wrapperDocIWPV.rc"

scanSettings(settingfile)
makeFileList()

ForEach patternblock()
  Debug("Patternblock:"+patternblock()\pattern )
  Debug("   blockstart:"+patternblock()\blockdef\blockstart )
  Debug("")
Next

  ;Test
;file.s = "t:\projects\IrrlichtWrapperSVN\IrrlichtWrapper_1_05\IrrlichtWrapper_source\wrapperscene.cpp"

outpath.s = Trim(_getEntry("output path"))
If Right(outpath,1) <> "/" And Right(outpath,1) <> "\" : outpath+"\" : EndIf
ForEach( source_files()) 
  
  *blockdef.sBlockDef = @settings\defaultblock
  ForEach patternblock()
    If CompareWithWildcards(source_files(),patternblock()\pattern )
      *blockdef = @patternblock()\blockdef
    EndIf
  Next
  
  scanFile(source_files(),*blockdef)
Next

outputformats.s = _getEntry("output format")


makeRealName()
SortStructuredList(content(), 2,OffsetOf(sContent\RealName), #PB_Sort_String)
makeGroups()
determineUndocumented()

Debug("Output-Formats: "+outputformats)
;If HTML or HTML-HELP, Wee need the Files !
If FindString(outputformats, "HTML",0) <> 0
  buildFiles(outpath) ;"t:\projects\pb4\libdesc\out") 
  buildMasterIndex(outpath+"masterindex.html")
  buildTableOfContent(outpath+"toc.html")
  If FindString(outputformats, "HTMLHELP",0) <> 0
    buildHtmlHelp(outpath, "IW")
  EndIf
EndIf

If FindString(outputformats, "IMPORTFILE",0) <> 0
  Debug("Go to Write the ImportFile")
  buildImportfile(outpath)
EndIf

If FindString(outputformats, "JAPBE",0) <> 0
  Debug("Go to Write the ImportFile")
  build_jaPBe_file(outpath)
EndIf

If FindString(outputformats, "USERLIB",0) <> 0
  Debug("Go to Write the UserlibFile")
  build_userlib_file(outpath)
EndIf
  

CallDebugger
End

ForEach content()
  Debug(content()\name)
  For I = 0 To 255
    If Len(content()\Tags[I]\name) > 0 
      Debug("TAG="+content()\Tags[I]\name)
      Debug("CONTENT="+content()\Tags[I]\content)
    EndIf
  Next
Next

; jaPBe Version=3.7.6.647
; FoldLines=00AC00FA
; Build=21
; Language=0x0000 Language Neutral
; FirstLine=792
; CursorPosition=883
; ExecutableFormat=Console
; Executable=T:\projects\IrrlichtWrapperSVN\IrrlichtWrapper_1_05\Dokumentation\wrapperDoc.exe
; CommandLine=t:\projects\IrrlichtWrapperSVN\IrrlichtWrapper_1_05\Dokumentation\wrapperDocIWPV.rc
; DontSaveDeclarec
; IDE Options = PureBasic 4.10 Beta 3 (Windows - x86)
; CursorPosition = 1013
; FirstLine = 976
; Folding = ------
; Executable = ..\..\Dokumentation\wrapperDoc.exe