nis-util  1.0.D108
nis-util-auto-master-check/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/auto_master/functor/check.h>
00023 #include <lib/space/auto_master/functor/depends.h>
00024 #include <lib/space/hosts/slurp.h>
00025 
00026 #include <nis-util-auto-master-check/arglex/auto-master.h>
00027 
00028 
00029 int
00030 main(int argc, char **argv)
00031 {
00032     arglex_auto_master cmdline(argc, argv);
00033     cmdline.token_first();
00034     rcstring filename;
00035     bool depends = false;
00036     space_hosts_slurp::pointer hosts_map;
00037     while (cmdline.token_cur() != arglex::token_eoln)
00038     {
00039         switch (cmdline.token_cur())
00040         {
00041         default:
00042             cmdline.generic_argument();
00043             break;
00044 
00045         case arglex::token_string:
00046             if (!filename.empty())
00047             {
00048                 explain_output_error("too many file names specified");
00049                 cmdline.usage();
00050             }
00051             filename = cmdline.get_string_value();
00052             break;
00053 
00054         case arglex::token_stdio:
00055             if (!filename.empty())
00056             {
00057                 explain_output_error("too many file names specified");
00058                 cmdline.usage();
00059             }
00060             filename = "-";
00061             cmdline.check_stdin_references();
00062             break;
00063 
00064         case arglex_auto_master::token_include:
00065             if (cmdline.token_next() != arglex::token_string)
00066             {
00067                 explain_output_error
00068                 (
00069                     "the -include option requires a pathname as argument"
00070                 );
00071                 cmdline.usage();
00072             }
00073             space_auto_master_functor::add_include_search_path
00074             (
00075                 cmdline.get_string_value()
00076             );
00077             break;
00078 
00079         case arglex_auto_master::token_suffix:
00080             if (cmdline.token_next() != arglex::token_string)
00081             {
00082                 explain_output_error
00083                 (
00084                     "the -suffix option requires a string as argument"
00085                 );
00086                 cmdline.usage();
00087             }
00088             space_auto_master_functor::add_suffix(cmdline.get_string_value());
00089             break;
00090 
00091         case arglex_auto_master::token_depends:
00092             depends = true;
00093             break;
00094 
00095         case arglex_auto_master::token_debug:
00096             space_auto_master::grammar_debug();
00097             space_automap::grammar_debug();
00098             break;
00099 
00100         case arglex_auto_master::token_hosts:
00101             if (hosts_map)
00102                 explain_output_error_and_die("too many host maps specified");
00103             hosts_map =
00104                 space_hosts_slurp::create(cmdline.get_filename_or_stdin());
00105             hosts_map->read_and_process();
00106             break;
00107         }
00108         cmdline.token_next();
00109     }
00110     if (filename.empty())
00111     {
00112         explain_output_error("no file name specified");
00113         cmdline.usage();
00114     }
00115 
00116     // read in the file.
00117     space_auto_master::pointer p = space_auto_master::create(filename);
00118     p->read_and_process();
00119 
00120     if (depends)
00121     {
00122         space_auto_master_functor_depends func;
00123         p->walk(func);
00124     }
00125     else
00126     {
00127         space_auto_master_functor_check inspector(p, hosts_map);
00128         p->walk(inspector);
00129     }
00130     return 0;
00131 }
00132 
00133 
00134 // vim: set ts=8 sw=4 et :