nis-util
1.0.D108
|
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-netmasks/arglex/netmasks.h> 00023 #include <nis-util-netmasks/check.h> 00024 #include <nis-util-netmasks/map.h> 00025 00026 00027 int 00028 main(int argc, char **argv) 00029 { 00030 arglex_netmasks cmdline(argc, argv); 00031 cmdline.token_first(); 00032 rcstring etc_netmasks; 00033 rcstring etc_networks; 00034 rcstring output; 00035 bool by_address = false; 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_netmasks::token_by_address: 00046 if (by_address) 00047 { 00048 explain_output_error("too many by_address files specified"); 00049 cmdline.usage(); 00050 } 00051 etc_netmasks = cmdline.get_filename_or_stdin(); 00052 by_address = true; 00053 break; 00054 00055 case arglex_netmasks::token_check: 00056 if (check_flag) 00057 { 00058 explain_output_error("too many check files specified"); 00059 cmdline.usage(); 00060 } 00061 etc_netmasks = cmdline.get_filename_or_stdin(); 00062 check_flag = true; 00063 break; 00064 00065 case arglex_netmasks::token_networks: 00066 if (!etc_networks.empty()) 00067 { 00068 explain_output_error("too many networks files specified"); 00069 cmdline.usage(); 00070 } 00071 etc_networks = cmdline.get_filename_or_stdin(); 00072 break; 00073 00074 case arglex_netmasks::token_output: 00075 if (!output.empty()) 00076 { 00077 explain_output_error("too many output files specified"); 00078 cmdline.usage(); 00079 } 00080 output = cmdline.get_filename_or_stdout(); 00081 break; 00082 } 00083 cmdline.token_next(); 00084 } 00085 if (by_address) 00086 map_by_address(etc_netmasks, output); 00087 else 00088 { 00089 if (etc_netmasks.empty()) 00090 explain_output_error_and_die("no netmasks file specified"); 00091 if (etc_networks.empty()) 00092 explain_output_error_and_die("no networks file specified"); 00093 check(etc_netmasks, etc_networks); 00094 } 00095 return 0; 00096 } 00097 00098 00099 // vim: set ts=8 sw=4 et :