#! /bin/sh

# Copyright (C) 2010, 2014 EPITA Research and Development Laboratory (LRDE).
#
# This file is part of Olena.
#
# Olena 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, version 2 of the License.
#
# Olena 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 Olena.  If not, see <http://www.gnu.org/licenses/>.

bdir="/home/roland/src/olena/_build/_inst/libexec/scribo"
bin=`basename $0`
version="2.1"

version()
{
    cat <<EOF
Olena Scribo Module Command-Line Interface (CLI) tool, version $version
Copyright (C) 2010, 2014 EPITA Research and Development Laboratory (LRDE)
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
EOF
}

usage()
{
    cat <<EOF
Usage: $bin [version] [help] COMMAND [ARGS]

List of available COMMAND argument:

  Full Toolchains
  ---------------


   * On documents

     doc-ppc	       Common preprocessing before looking for text.

     doc-ocr           Find and recognize text. Output: the actual text
     		       and its location.

     doc-dia           Analyse the document structure and extract the
     		       text. Output: an XML file with region and text
     		       information.



   * On pictures

     pic-loc           Try to localize text if there's any.

     pic-ocr           Localize and try to recognize text.



  Tools
  -----


     * xml2doc	       Convert the XML results of document toolchains
       		       into user documents (HTML, PDF...).


  Algorithms
  ----------


   * Binarization

     sauvola           Sauvola's algorithm.

     sauvola-ms        Multi-scale Sauvola's algorithm.

     sauvola-ms-fg     Extract foreground objects and run multi-scale
                       Sauvola's algorithm.

     sauvola-ms-split  Run multi-scale Sauvola's algorithm on each color
                       component and merge results.

---------------------------------------------------------------------------
See '$bin COMMAND --help' for more information on a specific command.
EOF
}


run_cmd()
{
    cmd="$1";
    if [ -z "$cmd" ]; then
        usage
	exit 0
    fi
    shift;

    case $cmd in

	doc-ppc)
	    $bdir/text_in_doc_preprocess $@
	    ;;

	doc-ocr)
	    $bdir/pbm_text_in_doc $@
	    ;;

	doc-dia)
	    $bdir/content_in_doc $@
	    ;;

	pic-loc)
	    $bdir/text_in_picture $@
	    ;;

	pic-ocr)
	    $bdir/text_recognition_in_picture $@
	    ;;

	xml2doc)
	    $bdir/scribo-xml2doc $@
	    ;;

	sauvola)
	    $bdir/sauvola $@
	    ;;

	sauvola-ms)
	    $bdir/sauvola_ms $@
	    ;;

    	sauvola-ms-fg)
	    $bdir/sauvola_ms_fg $@
	    ;;

    	sauvola-ms-split)
	    $bdir/sauvola_ms_split $@
	    ;;

	*)
	    cmd_bin=`echo $cmd | sed -e 's/-/_/g'`
	    if test -f $bdir/$cmd_bin; then
		$bdir/$cmd_bin $@
	    else
		echo "Error: Invalid command!"
		usage
	    fi
    esac
}


case $1 in

    version | --version)
	version
	;;


    help | --help)

	usage
	;;

    help)

	;;

    *)
	run_cmd $@
	;;

esac
