modules/up/src/rpslcheck/rpslcheck.cc
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- start_tracing
- start_debugging
- init_and_set_options
- main
1 // $Id: rpslcheck.cc,v 1.2 2000/08/31 12:36:15 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 char *countries[400];
132 char *sources[100];
133
134 main(int argc, char **argv, char **envp) {
/* [<][>][^][v][top][bottom][index][help] */
135 schema.initialize();
136 init_and_set_options(argc, argv, envp);
137
138 // opt_echo = 1;
139
140 #ifdef DEBUG
141 extern int rpsldebug;
142 if (opt_debug_rpsl)
143 rpsldebug = 1;
144 #endif // DEBUG
145
146 /*initialize countries , added EG 20000807*/
147 countries[0] = strdup("AZ");
148 countries[1] = strdup("AT");
149 countries[2] = strdup("AU");
150 countries[3] = strdup("DE");
151 countries[4] = strdup("DK");
152 countries[5] = strdup("EU");
153 countries[6] = strdup("GB");
154 countries[7] = strdup("IE");
155 countries[8] = strdup("IT");
156 countries[9] = strdup("JP");
157 countries[10]= strdup("NL");
158 countries[11]= strdup("PL");
159 countries[12]= strdup("PT");
160 countries[13]= strdup("RU");
161 countries[14]= strdup("TR");
162 countries[15]= strdup("UK");
163 countries[16]= NULL;
164
165 /*initialize sources, added EG 20000831*/
166 sources[0] = strdup("RIPE");
167 sources[1] = NULL;
168
169 Object *o;
170 bool code = true;
171 int count = 0;
172 while (cin) {
173 o = new Object;
174 code = o->read();
175 if (code)
176 code = o->scan();
177
178 if (opt_echo && code)
179 cout << *o;
180
181 delete o;
182 }
183
184 if (opt_stats)
185 schema.printClassStats();
186
187 if (opt_prompt)
188 cout << endl;
189
190 if (opt_rusage)
191 clog << ru;
192 }