nis-util  1.0.D108
nis-util-networks/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-networks/arglex/networks.h>
00023 #include <nis-util-networks/check.h>
00024 #include <nis-util-networks/map.h>
00025 
00026 
00027 int
00028 main(int argc, char **argv)
00029 {
00030     arglex_networks cmdline(argc, argv);
00031     cmdline.token_first();
00032     rcstring etc_networks;
00033     rcstring etc_netmasks;
00034     rcstring output;
00035     bool by_name = false;
00036     bool by_address = false;
00037     bool check_flag = false;
00038     while (cmdline.token_cur() != arglex::token_eoln)
00039     {
00040         switch (cmdline.token_cur())
00041         {
00042         default:
00043             cmdline.generic_argument();
00044             break;
00045 
00046         case arglex_networks::token_by_address:
00047             if (by_address)
00048             {
00049                 explain_output_error("too many by_address files specified");
00050                 cmdline.usage();
00051             }
00052             etc_networks = cmdline.get_filename_or_stdin();
00053             by_address = true;
00054             break;
00055 
00056         case arglex_networks::token_by_name:
00057             if (by_name)
00058             {
00059                 explain_output_error("too many by_name files specified");
00060                 cmdline.usage();
00061             }
00062             etc_networks = cmdline.get_filename_or_stdin();
00063             by_name = true;
00064             break;
00065 
00066         case arglex_networks::token_check:
00067             if (check_flag)
00068             {
00069                 explain_output_error("too many check files specified");
00070                 cmdline.usage();
00071             }
00072             etc_networks = cmdline.get_filename_or_stdin();
00073             check_flag = true;
00074             break;
00075 
00076         case arglex_networks::token_netmasks:
00077             if (!etc_netmasks.empty())
00078             {
00079                 explain_output_error("too many netmasks files specified");
00080                 cmdline.usage();
00081             }
00082             etc_netmasks = cmdline.get_filename_or_stdin();
00083             break;
00084 
00085         case arglex_networks::token_output:
00086             if (!output.empty())
00087             {
00088                 explain_output_error("too many output files specified");
00089                 cmdline.usage();
00090             }
00091             output = cmdline.get_filename_or_stdout();
00092             break;
00093         }
00094         cmdline.token_next();
00095     }
00096     if (by_address)
00097         map_by_address(etc_networks, output);
00098     else if (by_name)
00099         map_by_name(etc_networks, output);
00100     else
00101     {
00102         if (etc_networks.empty())
00103             explain_output_error_and_die("no networks file specified");
00104         if (etc_netmasks.empty())
00105             explain_output_error_and_die("no netmasks file specified");
00106         check(etc_networks, etc_netmasks);
00107     }
00108     return 0;
00109 }
00110 
00111 
00112 // vim: set ts=8 sw=4 et :