;parse irrlicht-structs.....

;#IRR_DIR = "t:\dev\libraries\irrlicht-1.4\include"


Procedure.s doScanEnum(txt.s, file.s)
  startp.l=0
  pos=0
  
  out_text.s = ";From File:"+file+Chr(13)
  
  Repeat 
    pos = FindString(txt,"enum ",startp)
    If pos <> #Null
      ;Debug(Str(pos))
;      CallDebugger
      
      p2 = FindString(txt,"{",pos)
      
      e_name.s = Trim(Mid(txt,pos+4,p2-(pos+4)))
            
      
      If p2 = 0 Or Left(e_name,1) <> "E"
        startp = pos+4;
        Continue
      EndIf
      
      
      
      
      p3 = FindString(txt,"}",p2)

      If p3 = 0 
        startp = pos+4;
        Continue
      EndIf
      
  
;      Debug(Str(pos) +","+Str(p2)+","+Str(p3))
; 
      content.s = Mid(txt, p2, p3-p2)
  
  
    
      
      
;      Debug e_name
      
      
      comment_flag.l = #False
      out_text + "Enumeration  ;"+ e_name + Chr(13)
      count = CountString(content,Chr(13))
      For i = 1 To Count
        line.s = Trim(ReplaceString(StringField(content,i,Chr(13)),Chr(9),"")  )
        

        com_pos = FindString(line,"*/",0)
        If com_pos
          line = Right(line, Len(line)-com_pos-2)
          comment_flag = #False
        EndIf


        com_pos = FindString(line,"/*",0)
        If com_pos
          line = Left(line, Len(line)-com_pos)
          comment_flag = #True
        EndIf

        If comment_flag = #True
          Continue
        EndIf

        
        
        
        
        
        If Left(line,3) = "//!"
          out_text + ";"+Right(line,Len(line)-3) + Chr(13)
          Continue
        EndIf

        If Left(line,2) = "//"
          Continue
        EndIf

  
        If Left(line,1) = "{"
          Continue
        EndIf
  
        If Len(Trim(line)) = 0 
          Continue
        EndIf
        

        comment.s = ""
        ;comments behind the line 
        If CountString(line,"//") > 0
          comment = ";" + StringField(line, 2, "//")
          line = Trim(StringField(line, 1, "//"))
        
        EndIf
        
        
        If Right(line,1) = ","
          line = Left(line,Len(line)-1)
        EndIf
        
        line = ReplaceString(line, "0x", "$")
        line = ReplaceString(line, "video::", "#IRR_")
        
        
               
        
        
        out_text + "#IRR_"+line+ comment+ Chr(13)
         
        
;      Debug("#IRR_"+line)            
        
        
      Next
      out_text + "EndEnumeration"+ Chr(13)
      
      
      
;       Debug out_text;content
;       Debug ""
      
      startp=p3
    Else  
      Break
    EndIf      
  Until pos=0
  ProcedureReturn out_text;
EndProcedure 


inlinemacro.s = "Macro MAKE_IRR_ID(c0, c1, c2, c3) : c0 | (c1<<8) | (c2<<16) | (c3 << 24) : EndMacro"

out.s = ";Generated with IrrlichtEnumScanner"+Chr(13)
out + ";Time = " + FormatDate("dd.mm.yyyy - hh::ii:ss",Date()) + Chr(13)
out + ";" + Chr(13)
out + inlinemacro + Chr(13)
out + ";" + Chr(13)

If CountProgramParameters() = 2
  
  irr_dir.s = ProgramParameter()


  If ExamineDirectory(0,irr_dir,"*.h")
      While NextDirectoryEntry(0)
        If DirectoryEntryType(0) = #PB_DirectoryEntry_File
          Type$ = " [File] "
          ts.s = ""
          ito = ReadFile(#PB_Any,irr_dir + "\"+DirectoryEntryName(0))    
          If ito 
            Repeat
              ts + ReadString(ito) + Chr(13);
            Until Eof(ito) 
            CloseFile(ito)
            out + doScanEnum(ts,DirectoryEntryName(0)) 
          EndIf
          
        Else
          Type$ = " [Sub-Dir] "
        EndIf
        
  ;      Debug DirectoryEntryName(0) + Type$ + "- Größe in Bytes: " + Str(DirectoryEntrySize(0))
      Wend
      FinishDirectory(0)  
    
  EndIf
  
  of.l = CreateFile(#PB_Any, ProgramParameter())
  If of
    WriteString(of, out)
    CloseFile(of)
  EndIf
  
EndIf

  
  
  
  



;Debug(out)

; IDE Options = PureBasic 4.10 Beta 3 (Windows - x86)
; CursorPosition = 2
; Folding = -
; Executable = ..\IrrlichtEnumScanner.exe