1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
/*
* val.cc: Part of GNU CSSC.
*
* Copyright (C) 1997,1998,2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*
*
* Validate a SCCS file.
*
*/
#include "cssc.h"
#include "fileiter.h"
#include "sccsfile.h"
#include "my-getopt.h"
#include "version.h"
#include "except.h"
#include "valcodes.h"
const char main_rcs_id[] = "$Id: val.cc,v 1.8 2002/03/25 00:07:56 james_youngman Exp $";
/* Prints a list of included or excluded SIDs. */
void
usage()
{
fprintf(stderr,
"usage: %s [-sV] [-m module] [-rSID] [-y type]\n",
prg_name);
}
static void problem(int &retval, const int &newprob)
{
if (newprob > retval)
retval = newprob;
}
int
main(int argc, char **argv)
{
Cleaner arbitrary_name;
int retval = 0;
bool silent = false;
mystring mstring;
bool had_m_option = false;
mystring ystring;
bool had_y_option = false;
bool had_r_option = false;
int c;
const char *req_sid_str = NULL;
sid rid = NULL; // (XXX: correct use of NULL?)
if (argc > 0)
set_prg_name(argv[0]);
else
set_prg_name("val");
class CSSC_Options opts(argc, argv, "sV!m!r!y!", 0);
for(c = opts.next();
c != CSSC_Options::END_OF_ARGUMENTS;
c = opts.next())
{
switch (c)
{
case CSSC_Options::UNRECOGNIZED_OPTION:
case CSSC_Options::MISSING_ARGUMENT:
problem(retval, Val_InvalidOption);
return retval;
default:
errormsg("Unsupported option: '%c'", c);
problem(retval, Val_InvalidOption);
return retval;
case 'r':
if (had_r_option)
{
errormsg("Duplicate -r option\n");
problem(retval, Val_InvalidOption);
}
had_r_option = true;
req_sid_str = opts.getarg();
rid = sid(req_sid_str);
if (!rid.valid())
{
errormsg("Invaild SID: '%s'", opts.getarg());
problem(retval, Val_InvalidSID);
}
break;
case 's':
silent = true;
break;
case 'm':
if (had_m_option)
{
errormsg("Duplicate -m option\n");
problem(retval, Val_InvalidOption);
}
had_m_option = true;
mstring = mystring(opts.getarg());
break;
case 'y':
if (had_y_option)
{
errormsg("Duplicate -y option\n");
problem(retval, Val_InvalidOption);
}
had_y_option = true;
ystring = mystring(opts.getarg());
break;
case 'V':
version();
break;
}
}
if (silent)
{
if (!stdout_to_null())
return 1; // fatal error.
}
sccs_file_iterator iter(opts);
if (sccs_file_iterator::NONE == iter.using_source())
{
errormsg("No SCCS file specified");
problem(retval, Val_MissingFile);
return retval;
}
while (iter.next())
{
#ifdef HAVE_EXCEPTIONS
try
{
#endif
sccs_name &name = iter.get_name();
// BUG when HAVE_EXCEPTIONS is false...
// If we cannot open the SCCS file, we would normally
// call ctor_fail(), with an argument of -1. This
// makes the program exit with an exit status of -1.
//
// TODO: use atexit() and _exit() to kludge it.
sccs_file file(name, sccs_file::READ);
if (had_r_option)
{
if (rid.valid() && NULL == file.find_delta(rid))
{
if (!silent)
{
errormsg("%s: Requested SID %s not found.",
name.c_str(), req_sid_str);
}
problem(retval, Val_NoSuchSID);
}
}
if (had_m_option)
{
const mystring &module_flag = file.get_module_name();
if (module_flag != mstring)
{
if (!silent)
{
errormsg("%s: mismatch for %%"
"M%%: wanted \"%s\", got \"%s\"\n",
name.c_str(),
mstring.c_str(),
module_flag.c_str());
}
problem(retval, Val_MismatchedM);
}
}
if (had_y_option)
{
const mystring &type_flag = file.get_module_type_flag();
if (type_flag != ystring)
{
if (!silent)
{
errormsg("%s: mismatch for %%"
"Y%%: wanted \"%s\", got \"%s\"\n",
name.c_str(),
mstring.c_str(),
type_flag.c_str());
}
problem(retval, Val_MismatchedY);
}
}
if (!file.validate())
{
problem(retval, Val_CorruptFile);
}
#ifdef HAVE_EXCEPTIONS
}
catch (CsscSfileMissingException e)
{
problem(retval, Val_CannotOpenOrWrongFormat);
}
catch (CsscContstructorFailedException e)
{
problem(retval, Val_CorruptFile);
}
catch (CsscSfileCorruptException ce)
{
problem(retval, Val_CorruptFile);
}
catch (CsscExitvalException e)
{
if (e.exitval > retval)
retval = e.exitval;
}
#endif
}
return retval;
}
/* Local variables: */
/* mode: c++ */
/* End: */
|