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