nis-util  1.0.D108
nis-util-afpvol-gen/main.cc
Go to the documentation of this file.
00001 //
00002 // nis-util - NIS Administration Utilities
00003 // Copyright (C) 2012 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or (at
00008 // your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License along
00016 // with this program. If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 
00019 #include <libexplain/output.h>
00020 
00021 #include <lib/space/automap.h>
00022 #include <lib/space/hosts/slurp.h>
00023 #include <lib/space/automap/functor/afpvol_generator.h>
00024 #include <lib/space/automap/functor/direct.h>
00025 #include <lib/space/automap/functor/indirect.h>
00026 
00027 #include <nis-util-afpvol-gen/arglex/afpvol.h>
00028 
00029 
00030 static void
00031 both_whine(void)
00032 {
00033     explain_output_error_and_die
00034     (
00035         "you must use exactly one -Director or -Indirect option"
00036     );
00037 }
00038 
00039 
00040 int
00041 main(int argc, char **argv)
00042 {
00043     arglex_afpvol cmdline(argc, argv);
00044     cmdline.token_next();
00045     space_automap::pointer stp;
00046     rcstring outfile;
00047     space_hosts_slurp::pointer hosts;
00048     while (cmdline.token_cur() != arglex::token_eoln)
00049     {
00050         switch (cmdline.token_cur())
00051         {
00052         default:
00053             cmdline.generic_argument();
00054             break;
00055 
00056         case arglex_afpvol::token_direct:
00057             {
00058                 rcstring filename = cmdline.get_filename_or_stdin();
00059                 if (stp)
00060                     both_whine();
00061                 stp = space_automap::create(filename);
00062                 space_automap_functor_direct checker(stp.get());
00063                 stp->read_and_process(checker, hosts.get());
00064             }
00065             break;
00066 
00067         case arglex_afpvol::token_indirect:
00068             {
00069                 rcstring filename = cmdline.get_filename_or_stdin();
00070                 if (stp)
00071                     both_whine();
00072                 stp = space_automap::create(cmdline.get_string_value());
00073                 space_automap_functor_indirect checker(stp.get());
00074                 stp->read_and_process(checker, hosts.get());
00075             }
00076             break;
00077 
00078         case arglex_afpvol::token_output:
00079             if (!outfile.empty())
00080                 explain_output_error_and_die("too many output files specified");
00081             outfile = cmdline.get_filename_or_stdout();
00082             break;
00083 
00084         case arglex_afpvol::token_debug:
00085             space_automap::grammar_debug();
00086             break;
00087 
00088         case arglex_afpvol::token_hosts:
00089             if (hosts)
00090                 explain_output_error_and_die("too many --hosts maps specified");
00091             hosts = space_hosts_slurp::create(cmdline.get_filename_or_stdin());
00092             hosts->read_and_process();
00093             break;
00094         }
00095         cmdline.token_next();
00096     }
00097     if (!stp)
00098         both_whine();
00099     space_automap_functor_afpvol_generator generator(outfile);
00100     stp->walk(generator);
00101     return 0;
00102 }
00103 
00104 
00105 // vim: set ts=8 sw=4 et :