## modules/up/src/rpslcheck/rpslcheck.cc

/* [<][>][^][v][top][bottom][index][help] */

## FUNCTIONS

This source file includes following functions.

1. start_tracing
2. start_debugging
3. init_and_set_options
4. main

       1 //  $Id: rpslcheck.cc,v 1.1.1.1 2000/03/10 16:32:17 engin Exp $
       2 //
       3 //  Copyright (c) 1994 by the University of Southern California
       4 //  All rights reserved.
       5 //
       6 //  Permission to use, copy, modify, and distribute this software and its
       7 //  documentation in source and binary forms for lawful non-commercial
       8 //  purposes and without fee is hereby granted, provided that the above
       9 //  copyright notice appear in all copies and that both the copyright
      10 //  notice and this permission notice appear in supporting documentation,
      11 //  and that any documentation, advertising materials, and other materials
      12 //  related to such distribution and use acknowledge that the software was
      13 //  developed by the University of Southern California, Information
      14 //  Sciences Institute. The name of the USC may not be used to endorse or
      15 //  promote products derived from this software without specific prior
      16 //  written permission.
      17 //
      18 //  THE UNIVERSITY OF SOUTHERN CALIFORNIA DOES NOT MAKE ANY
      19 //  REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY
      20 //  PURPOSE.  THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
      21 //  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
      22 //  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
      23 //  TITLE, AND NON-INFRINGEMENT.
      24 //
      25 //  IN NO EVENT SHALL USC, OR ANY OTHER CONTRIBUTOR BE LIABLE FOR ANY
      26 //  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, WHETHER IN CONTRACT, TORT,
      27 //  OR OTHER FORM OF ACTION, ARISING OUT OF OR IN CONNECTION WITH, THE USE
      28 //  OR PERFORMANCE OF THIS SOFTWARE.
      29 //
      30 //  Questions concerning this software should be directed to
      31 //  ratoolset@isi.edu.
      32 //
      33 //  Author(s): Cengiz Alaettinoglu <cengiz@ISI.EDU>
      34
      35 #include <config.h>
      36 #include <istream.h>
      37 #include "rpsl/object.hh"
      38 #include "util/rusage.hh"
      39 #include "util/debug.hh"
      40 #include "util/trace.hh"
      41 #include "util/Argv.hh"
      42 #include "util/version.hh"
      43 #ifdef IRR_NEEDED
      44 #include "irr/irr.hh"
      45 #include "irr/rawhoisc.hh"
      46 #endif // IRR_NEEDED
      47 #include "rpsl/schema.hh"
      48
      49 Rusage ru;
      50 bool opt_stats                   = false;
      51 bool opt_rusage                  = false;
      52 char *opt_prompt                 = "RtConfig> ";
      53 bool opt_echo                    = false;
      54 #ifdef DEBUG
      55 bool opt_debug_rpsl              = false;
      56 #endif // DEBUG
      57
      58 int start_tracing(char *dst, char *key, char *nextArg) {
         /* [<][>][^][v][top][bottom][index][help] */
      59    if (nextArg) {
      60       trace.enable(nextArg);
      61       return 1; // return 1 to signify nextArg is used by us
      62    }
      63    return 0;
      64 }
      65
      66 int start_debugging(char *dst, char *key, char *nextArg) {
         /* [<][>][^][v][top][bottom][index][help] */
      67    if (nextArg) {
      68       Debug(dbg.enable(atoi(nextArg)));
      69       return 1; // return 1 to signify nextArg is used by us
      70    }
      71    return 0;
      72 }
      73
      74 void init_and_set_options (int argc, char **argv, char **envp) {
         /* [<][>][^][v][top][bottom][index][help] */
      75    ArgvInfo argTable[] = {
      76      // RAToolSet common arguments
      77      // key, type, src, dst, help
      78      {"-T", ARGV_FUNC, (char *) &start_tracing,      (char *) NULL,
      79       "Start tracing the next argument"},
      80      {"-D", ARGV_FUNC, (char *) &start_debugging,    (char *) NULL,
      81       "Start debugging the next argument"},
      82      {"-version", ARGV_FUNC, (char *) &version,      (char *) NULL,
      83       "Show version"},
      84 #ifdef IRR_NEEDED
      85      {"-h", ARGV_FUNC, (char *) &IRR::ArgvHost,      (char *) NULL,
      86       "Host name of the RAWhoisd server"},
      87      {"-p", ARGV_FUNC, (char *) &IRR::ArgvPort,      (char *) NULL,
      88       "Port number of the RAWhoisd server"},
      89      {"-s", ARGV_FUNC, (char *) &IRR::ArgvSources,   (char *) NULL,
      90       "Order of databases"},
      91      {"-ignore_errors", ARGV_FUNC, (char *)&IRR::IgnoreErrors, (char *)NULL,
      92       "Ignore IRR error and warning messages"},
      93      {"-report_errors", ARGV_FUNC, (char *)&IRR::ReportErrors, (char *)NULL,
      94       "Print IRR error and warning messages"},
      95 #endif // IRR_NEEDED
      96      {"-rusage", ARGV_BOOL, (char *) NULL,           (char *) &opt_rusage,
      97       "On termination print resource usage"},
      98      {"-stats", ARGV_BOOL, (char *) NULL,            (char *) &opt_stats,
      99       "On termination print class statistics"},
     100      {"-prompt", ARGV_STRING,  (char *) NULL,        (char *) &opt_prompt,
     101       "Prompt"},
     102
     103      {"-echo", ARGV_BOOL, (char *) NULL,           (char *) &opt_echo,
     104       "Echo each object parsed"},
     105 #ifdef DEBUG
     106      {"-debug_rpsl", ARGV_BOOL, (char *) NULL,     (char *) &opt_debug_rpsl,
     107       "Turn on bison debugging. Intended for developers."},
     108 #endif // DEBUG
     109      {(char *) NULL, ARGV_END, (char *) NULL, (char *) NULL,
     110       (char *) NULL}
     111    };
     112
     113 #ifdef IRR_NEEDED
     114    IRR::handleEnvironmentVariables(envp);
     115 #endif // IRR_NEEDED
     116
     117    if (ParseArgv(&argc, argv, argTable, ARGV_NO_LEFTOVERS) != ARGV_OK) {
     118       cerr << endl;
     119       exit(1);
     120    }
     121
     122 #ifdef IRR_NEEDED
     123    irr = IRR::newClient();
     124 #endif // IRR_NEEDED
     125
     126    // have a prompt only if the input is coming from a tty
     127    if (!isatty(fileno(stdin)) || !isatty(fileno(stdout)))
     128       opt_prompt = NULL;
     129 }
     130
     131
     132 main(int argc, char **argv, char **envp) {
         /* [<][>][^][v][top][bottom][index][help] */
     133    schema.initialize();
     134    init_and_set_options(argc, argv, envp);
     135
     136    // opt_echo = 1;
     137
     138 #ifdef DEBUG
     139    extern int rpsldebug;
     140    if (opt_debug_rpsl)
     141       rpsldebug = 1;
     142 #endif // DEBUG
     143
     144    Object *o;
     145    bool code = true;
     146    int count = 0;
     147    while (cin) {
     148       o = new Object;
     149       code = o->read();
     150       if (code)
     151          code = o->scan();
     152
     153       if (opt_echo && code)
     154          cout << *o;
     155
     156       delete o;
     157    }
     158
     159    if (opt_stats)
     160       schema.printClassStats();
     161
     162    if (opt_prompt)
     163       cout << endl;
     164
     165    if (opt_rusage)
     166       clog << ru;
     167 }

/* [<][>][^][v][top][bottom][index][help] */