/*-----------------------------------------------------------------------------

Copyright (C) 2002, 2006, 2009, 2010, 2011, 2012.

A. Ronald Gallant
Post Office Box 659 
Chapel Hill NC 27514 
USA   

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 documentation, first read flagmap.h then read this file.

#include "flagmap.h"

namespace flagmap {

  void define_flag(std::map<std::string, flagmap::fval>& flag)
  {
    // The following three flags are special.

    flag["h"] = fval("-h           help message"); 
    flag["f"] = fval("-f           filter, reads from standard input");
    flag["filenames_expected"] = fval("");
    flag["filenames_expected"].set = true;

    // The only changes to the flags above that will not break the code  
    // are specific combinations of

    // 1. comment out the line flag["h"] 
    // 2. comment out the line flag["f"].
    // 3. change the line 
    //      flag["filenames_expected"].set = true;
    //    to
    //      flag["filenames_expected"].set = false;

    // Combinations determine program usage as follows:

    // 1. For the two usages "program -f [remaining options] < filename"
    // and "program [remaining options] filename(s)" to be correct, but
    // for "program [remaining options]" to be an error, leave as is.
    
    // 2. For the three usages "program [options] < filename", 
    // "program [options] filename(s)", and "program [options]" to
    // be correct, where the third usage means read from standard input, 
    // comment out the line flag["f"].

    // 3. For only the usage "program [options]" to be correct, where no 
    // filenames are expected on the command line (other than as 
    // arguments to user defined flags), comment out the line flag["f"] 
    // and assign false to the variable flag["filenames_expected"].set

    // Comment out the line optional_part_example below and add flags here 
    // using optional_part_example in flagmap.cpp as a guide. 

    optional_part_example(flag);
  }

  // For usage cases 1 and 2 above the following function would be coded 
  // to do the useful work.
  
  std::istream& process_filename(std::istream& fin,
    std::string progname,
    std::map<std::string,flagmap::fval> flag,
    std::vector<std::string> file)
  {
    return process_filename_example(fin, progname, flag, file);
  }
}

// For case 3, the line return flagmap::process_file in the following 
// main would be commented out and the remainder of main would be coded 
// to do the useful work.

int main(int argc, char** argp, char** envp)
{
  std::map<std::string, flagmap::fval> flag;
  std::vector<std::string> file;
  std::string progname;
  flagmap::define_flag(flag);
  if (flagmap::process_flag(argc, argp, progname, flag, file) != 0) return 1; 
  return flagmap::process_file(progname, flag, file);
}

