' coding: UTF-8
' This is
CONST PROG_NAME = "fb-doc" '*< the name of the programm
CONST PROG_VERS = "0.2"    '*< the program version

/'* \file fb-doc.bas
\brief The main source file to compile

This main file includes all the submodules. Compile it by
fbc (the FreeBASIC compiler) to create your fb-doc binary.

'/


/'* \mainpage fb-doc

fb-doc is a tool for generating documentation from and for FreeBasic 
source code. Rather than creating the documentation output directly, 
fb-doc is designed to close the gap between FreeBasic (= FB) and C 
syntax to allow for using any C / C++ documentation tool-chain. Also 
it supports the creation of documentational comments in the source 
and it can get extended via external plugins.

Find more information in the Tutorial

- \subpage intro
- \subpage installation
- \subpage usage
- \subpage examples
- \subpage pagetables
- \subpage externfiles
- \subpage extend
- \subpage todo

or at the world wide web:

 - en: \ProjPage
 - de: http://www.freebasic-portal.de/downloads/ressourcencompiler/fb-doc-229.html


\section licence fb-doc licence (GPLv3):

Copyright &copy; 2012-2013 by \Email

This program is free software; you can redistribute it and/or modify 
it under the terms of the GNU General Public License as published by 
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but 
WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
General Public License for more details.

You should have received a copy of the GNU General Public License 
along with this program; if not, write to the Free Software 
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110- 
1301, USA. For further details please refer to: 
http://www.gnu.org/licenses/gpl-3.0.html


\section ackno Acknowledgements

Thanks go to:

 - Dimitri van Heesch (author of Doxygen)
 - Chris Lyttle, Dan Mueth, Stefan Kost (authors of gtk-doc)
 - the FreeBasic developers (a great modern programming language with fun-factor)
 - AGS for testing and bug reporting

'/

#INCLUDE ONCE "fb-doc.bi"

#INCLUDE ONCE "fb-doc_parser.bas"
#INCLUDE ONCE "fb-doc_emitters.bas"
#INCLUDE ONCE "fb-doc_options.bas"

' *** main ***

OPT = NEW Options()

WITH *.OPT
  SELECT CASE AS CONST .RunMode '                                execute
  CASE    .HELP_MESSAGE : ERROUT(MSG_HELP)
  CASE .VERSION_MESSAGE : ERROUT(MSG_VERSION)
  CASE .GEANYFILTER
    .Pars->Ocha = FREEFILE
    OPEN CONS FOR OUTPUT AS #.Pars->Ocha
    .Pars->StdIn()
    CLOSE #.Pars->Ocha
  CASE ELSE
    IF .RunMode = .SCAN_LIST THEN
      .Pars->Ocha = FREEFILE
      IF OPEN(CALLEES_FILE FOR OUTPUT AS #.Pars->Ocha) THEN _
        ERROUT(" --> Couldn't write " & CALLEES_FILE & ".") : EXIT SELECT
      .AllCallees = 1
    ELSEIF .AllCallees >= 0 THEN '             load CALLEES_FILE, if any
      VAR fnr = FREEFILE         '*< File number to read \em fb-doc.lfn
      IF 0 = OPEN(CALLEES_FILE FOR INPUT AS #fnr) THEN
        ERROUT("loading " & CALLEES_FILE & " for file " & .InFile)
        .Callees = STRING(LOF(fnr), 0)
        GET #fnr, , .Callees
        CLOSE #fnr
        .AllCallees = 1
      END IF
    END IF

    VAR a = 0, _                '*< Start character of next file name / pattern
        i = a, _                '*< Counter for characters
        l = LEN(.InFile) - 1, _ '*< Length of input queue (number of characters)
        inpat = 0               '*< Flag, set when name is a pattern
    DO
      SELECT CASE AS CONST .InFile[i]
      CASE 0 : EXIT DO
      CASE ASC("*"), ASC("?") : inpat = 1
      CASE ASC(";")
        .InPattern = MID(.InFile, a + 1, i - a)
        IF inpat THEN IF .InRecursiv < 0 THEN .InRecursiv *= -1
        .Pattern()
        inpat = 0
        a = i + 1
      END SELECT : i += 1
    LOOP

    IF .RunMode = .SCAN_LIST THEN
      MSG_LINE(CALLEES_FILE)
      CLOSE #.Pars->Ocha
      ERROUT(" --> written")
    END IF
  END SELECT
END WITH

DELETE OPT
FOR i AS INTEGER = 0 TO UBOUND(Emitters)
  DELETE Emitters(i)
NEXT

