nis-util  1.0.D108
nis-util-services/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/ac/assert.h>
00020 #include <libexplain/output.h>
00021 
00022 #include <nis-util-services/arglex/services.h>
00023 #include <nis-util-services/check.h>
00024 #include <nis-util-services/map.h>
00025 
00026 
00027 int
00028 main(int argc, char **argv)
00029 {
00030     arglex_services cmdline(argc, argv);
00031     cmdline.token_first();
00032     rcstring etc_protocols;
00033     rcstring by_name;
00034     rcstring by_servicename;
00035     rcstring by_check;
00036     rcstring output;
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_services::token_check:
00046             cmdline.get_filename_or_stdin(by_check);
00047             break;
00048 
00049         case arglex_services::token_by_name:
00050             cmdline.get_filename_or_stdin(by_name);
00051             break;
00052 
00053         case arglex_services::token_by_servicename:
00054             cmdline.get_filename_or_stdin(by_servicename);
00055             break;
00056 
00057         case arglex_services::token_output:
00058             if (!output.empty())
00059             {
00060                 explain_output_error("too many output files specified");
00061                 cmdline.usage();
00062             }
00063             output = cmdline.get_filename_or_stdout();
00064             break;
00065 
00066         case arglex_services::token_protocols:
00067             cmdline.get_filename_or_stdin(etc_protocols);
00068             break;
00069         }
00070         cmdline.token_next();
00071     }
00072     if (!by_name.empty() + !by_servicename.empty() + !by_check.empty() != 1)
00073     {
00074         explain_output_error
00075         (
00076             "exactly one of %s or %s or %s must be specified",
00077             cmdline.token_name(arglex_services::token_check),
00078             cmdline.token_name(arglex_services::token_by_name),
00079             cmdline.token_name(arglex_services::token_by_servicename)
00080         );
00081         cmdline.usage();
00082     }
00083     if (!by_name.empty())
00084         map_by_name(by_name, output);
00085     else if (!by_servicename.empty())
00086         map_by_servicename(by_servicename, output);
00087     else
00088     {
00089         assert(!by_check.empty());
00090         if (etc_protocols.empty())
00091             explain_output_error_and_die("no protocols file specified");
00092         check(by_check, etc_protocols);
00093     }
00094     return 0;
00095 }
00096 
00097 
00098 // vim: set ts=8 sw=4 et :