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 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
|
/*
* delta.cc: Part of GNU CSSC.
*
* Copyright (C) 1997,1998,1999,2001,2007,2008 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 3 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, see <http://www.gnu.org/licenses/>.
*
* CSSC was originally Based on MySC, by Ross Ridge, which was
* placed in the Public Domain.
*
*
* Adds new deltas to SCCS files.
*
*/
#include "cssc.h"
#include "my-getopt.h"
#include "fileiter.h"
#include "pfile.h"
#include "sccsfile.h"
#include "sf-chkmr.h"
#include "version.h"
#include "delta.h"
#include "except.h"
const char main_rcs_id[] = "CSSC $Id: delta.cc,v 1.37 2008/01/06 19:42:23 jay Exp $";
void
usage() {
fprintf(stderr,
"usage: %s [-nsVp] [-m MRs] [-r SID] [-y comments] file ...\n",
prg_name);
}
#define EXITVAL_INVALID_OPTION (1)
int
delta_main(int argc, char **argv)
{
Cleaner arbitrary_name;
int c;
sid rid(sid::null_sid());
int silent = 0; /* -s */
int keep_gfile = 0; /* -n */
#if 0
sid_list ignore; /* -g */
#endif
mystring mrs; /* -m -M */
mystring comments; /* -y -Y */
int suppress_mrs = 0; // if -m given with no arg.
int got_mrs = 0; // if no need to prompt for MRs.
int suppress_comments = 0; // if -y given with no arg.
int got_comments = 0;
bool display_diff_output = false; // -p
if (argc > 0) {
set_prg_name(argv[0]);
} else {
set_prg_name("delta");
}
ASSERT(!rid.valid());
class CSSC_Options opts(argc, argv, "r!sng!m!y!pV", EXITVAL_INVALID_OPTION);
for(c = opts.next();
c != CSSC_Options::END_OF_ARGUMENTS;
c = opts.next()) {
switch (c) {
default:
errormsg("Unsupported option: '%c'", c);
return EXITVAL_INVALID_OPTION;
case 'r':
rid = sid(opts.getarg());
if (!rid.valid()) {
errormsg("Invaild SID: '%s'", opts.getarg());
return EXITVAL_INVALID_OPTION;
}
break;
case 's':
silent = 1;
break;
case 'n':
keep_gfile = 1;
break;
case 'p':
display_diff_output = true;
break;
case 'm':
mrs = opts.getarg();
suppress_mrs = (mrs == "");
got_mrs = 1;
break;
#if 0
/* not a standard option */
case 'M':
mrs = "";
suppress_mrs = 1;
got_mrs = 1;
break;
#endif
case 'y':
comments = opts.getarg();
suppress_comments = (comments == "");
got_comments = 1;
break;
#if 0
/* not a standard option */
case 'Y':
comments = "";
suppress_comments = 1;
got_comments = 1;
break;
#endif
case 'V':
version();
break;
}
}
sccs_file_iterator iter(opts);
if (! iter.using_source())
{
errormsg("No SCCS file specified.");
return EXITVAL_INVALID_OPTION;
}
if (silent)
{
if (!stdout_to_null())
{
return 1; // fatal error. Process no files.
}
}
mylist<mystring> mr_list, comment_list;
int first = 1;
int retval = 0;
while (iter.next())
{
#ifdef HAVE_EXCEPTIONS
try
{
#endif
bool failed = false;
sccs_name &name = iter.get_name();
sccs_file file(name, sccs_file::UPDATE);
sccs_pfile pfile(name, sccs_pfile::UPDATE);
if (first)
{
if (!suppress_mrs && !got_mrs && file.mr_required())
{
mrs = prompt_user("MRs? ");
got_mrs = 1;
}
if (!suppress_comments && !got_comments)
{
comments = prompt_user("comments? ");
got_comments = 1;
}
mr_list = split_mrs(mrs);
comment_list = split_comments(comments);
first = 0;
}
switch (pfile.find_sid(rid)) {
case sccs_pfile::FOUND:
break;
case sccs_pfile::NOT_FOUND:
if (!rid.valid())
{
errormsg("%s: You have no edits outstanding.",
name.c_str());
}
else
{
errormsg("%s: Specified SID hasn't been locked for"
" editing by you.",
name.c_str());
}
failed = true;
retval = EXITVAL_INVALID_OPTION;
break;
case sccs_pfile::AMBIGUOUS:
if (rid.valid())
{
errormsg("%s: Specified SID is ambiguous.",
name.c_str());
}
else
{
errormsg("%s: You must specify a SID on the"
" command line.", name.c_str());
}
failed = true;
retval = EXITVAL_INVALID_OPTION;
break;
default:
abort();
}
if (!failed)
{
if (!suppress_mrs && file.mr_required())
{
if (mr_list.length() == 0)
{
errormsg("%s: MR number(s) must be supplied.",
name.c_str());
retval = 1;
continue;
}
if (file.check_mrs(mr_list))
{
/* In this case, _real_ SCCS prints the ID anyway.
*/
pfile->delta.print(stdout);
putchar('\n');
errormsg("%s: Invalid MR number(s).",
name.c_str());
retval = 1;
continue;
}
}
else if (mr_list.length())
{
// MRs were specified and the MR flag is turned off.
pfile->delta.print(stdout);
putchar('\n');
errormsg("%s: MR verification ('v') flag not set, MRs"
" are not allowed.\n",
name.c_str());
retval = 1;
continue;
}
mystring gname = name.gfile();
if (!file.add_delta(gname, pfile, mr_list, comment_list,
display_diff_output))
{
retval = 1;
// if delta failed, don't delete the g-file.
}
else
{
if (!keep_gfile)
{
/* SourceForge bug 489005: remove the g-file
* as the real user if we are running setuid.
*/
if (!unlink_file_as_real_user(gname.c_str()))
{
errormsg_with_errno("Failed to remove file %s",
gname.c_str());
retval = 1;
}
}
}
}
#ifdef HAVE_EXCEPTIONS
}
catch (CsscReallyFatalException e)
{
exit(e.exitval);
}
catch (CsscExitvalException e)
{
if (e.exitval > retval)
retval = e.exitval; // continue with next file.
}
#endif
}
return retval;
}
int
main(int argc, char **argv)
{
int ret;
ret = delta_main(argc, argv);
return ret;
}
// Explicit template instantiations.
template class range_list<sid>;
template class mylist<mystring>;
template class mylist<delta>;
template class mylist<seq_no>;
template class mylist<sccs_pfile::edit_lock>;
template class mylist<char const*>;
//template mylist<char const*>& operator+=(mylist<char const *> &, mylist<mystring> const &);
template class range_list<release>;
#include "stack.h"
template class stack<unsigned short>;
/* Local variables: */
/* mode: c++ */
/* End: */
|