nis-util
1.0.D108
|
00001 // 00002 // nis-util - NIS Administration Utilities 00003 // Copyright (C) 2001, 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-ethers/arglex/ethers.h> 00023 #include <nis-util-ethers/check.h> 00024 #include <nis-util-ethers/map.h> 00025 00026 00027 int 00028 main(int argc, char **argv) 00029 { 00030 arglex_ethers cmdline(argc, argv); 00031 rcstring ethers; 00032 rcstring hosts; 00033 rcstring by_name; 00034 rcstring by_addr; 00035 rcstring output; 00036 cmdline.token_first(); 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_ethers::token_hosts: 00046 if (!hosts.empty()) 00047 { 00048 explain_output_error("too many hosts files specified"); 00049 cmdline.usage(); 00050 } 00051 hosts = cmdline.get_filename_or_stdin(); 00052 break; 00053 00054 case arglex_ethers::token_ethers: 00055 if (!ethers.empty()) 00056 { 00057 explain_output_error("too many ethers files specified"); 00058 cmdline.usage(); 00059 } 00060 ethers = cmdline.get_filename_or_stdin(); 00061 break; 00062 00063 case arglex_ethers::token_by_name: 00064 if (!by_name.empty()) 00065 { 00066 explain_output_error("too many by_name files specified"); 00067 cmdline.usage(); 00068 } 00069 by_name = cmdline.get_filename_or_stdin(); 00070 break; 00071 00072 case arglex_ethers::token_by_address: 00073 if (!by_addr.empty()) 00074 { 00075 explain_output_error("too many by_addr files specified"); 00076 cmdline.usage(); 00077 } 00078 by_addr = cmdline.get_filename_or_stdin(); 00079 break; 00080 00081 case arglex_ethers::token_output: 00082 if (!output.empty()) 00083 { 00084 explain_output_error("too many output files specified"); 00085 cmdline.usage(); 00086 } 00087 output = cmdline.get_filename_or_stdout(); 00088 break; 00089 } 00090 cmdline.token_next(); 00091 } 00092 if (!by_name.empty()) 00093 map_by_name(by_name, output); 00094 else if (!by_addr.empty()) 00095 map_by_address(by_addr, output); 00096 else 00097 { 00098 if (ethers.empty()) 00099 explain_output_error_and_die("no ethers file specified"); 00100 if (hosts.empty()) 00101 explain_output_error_and_die("no hosts file specified"); 00102 check(ethers, hosts); 00103 } 00104 return 0; 00105 } 00106 00107 00108 // vim: set ts=8 sw=4 et :