nis-util  1.0.D108
nis-util-protocols/main.cc
Go to the documentation of this file.
00001 //
00002 // nis-util - NIS Administration Utilities
00003 // Copyright (C) 2002, 2008, 2009, 2011, 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
00016 // along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 
00019 #include <lib/config.h>
00020 #include <libexplain/output.h>
00021 
00022 #include <nis-util-protocols/arglex/protocols.h>
00023 #include <nis-util-protocols/check.h>
00024 #include <nis-util-protocols/map.h>
00025 
00026 
00027 int
00028 main(int argc, char **argv)
00029 {
00030     arglex_protocols cmdline(argc, argv);
00031     cmdline.token_first();
00032     rcstring etc_protocols;
00033     bool by_name = false;
00034     bool by_number = false;
00035     rcstring output;
00036     bool check_flag = false;
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_protocols::token_check:
00046             if (check_flag)
00047             {
00048                 explain_output_error("too many check files specified");
00049                 cmdline.usage();
00050             }
00051             etc_protocols = cmdline.get_filename_or_stdin();
00052             check_flag = true;
00053             break;
00054 
00055         case arglex_protocols::token_by_name:
00056             if (by_name)
00057             {
00058                 explain_output_error("too many by_name files specified");
00059                 cmdline.usage();
00060             }
00061             etc_protocols = cmdline.get_filename_or_stdin();
00062             by_name = true;
00063             break;
00064 
00065         case arglex_protocols::token_by_number:
00066             if (by_number)
00067             {
00068                 explain_output_error("too many by_number files specified");
00069                 cmdline.usage();
00070             }
00071             etc_protocols = cmdline.get_filename_or_stdin();
00072             by_number = true;
00073             break;
00074 
00075         case arglex_protocols::token_output:
00076             if (!output.empty())
00077             {
00078                 explain_output_error("too many output files specified");
00079                 cmdline.usage();
00080             }
00081             output = cmdline.get_filename_or_stdout();
00082             break;
00083         }
00084         cmdline.token_next();
00085     }
00086     if (etc_protocols.empty())
00087         explain_output_error_and_die("no protocols file specified");
00088     if (by_name)
00089         map_by_name(etc_protocols, output);
00090     else if (by_number)
00091         map_by_number(etc_protocols, output);
00092     else
00093         check(etc_protocols);
00094     return 0;
00095 }
00096 
00097 
00098 // vim: set ts=8 sw=4 et :