File: sf-admin.cc

package info (click to toggle)
cssc 1.0.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,612 kB
  • ctags: 1,424
  • sloc: cpp: 13,502; sh: 4,759; ansic: 2,971; perl: 342; makefile: 339; awk: 11
file content (444 lines) | stat: -rw-r--r-- 9,141 bytes parent folder | download | duplicates (2)
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
/*
 * sf-admin.cc: Part of GNU CSSC.
 * 
 * 
 *    Copyright (C) 1997,1998,1999,2001,2004 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.
 * 
 * CSSC was originally Based on MySC, by Ross Ridge, which was 
 * placed in the Public Domain.
 *
 *
 * Members of the class sccs_file for performing creation and
 * adminstration operations on the SCCS file.
 *
 */

#include "cssc.h"
#include "sccsfile.h"
#include "sl-merge.h"
#include "delta.h"
#include "linebuf.h"
#include "bodyio.h"


#ifdef CONFIG_SCCS_IDS
static const char rcs_id[] = "CSSC $Id: sf-admin.cc,v 1.34 2004/10/10 12:19:16 james_youngman Exp $";
#endif



/* #define ADMIN_MERGE_LOCKED_RELEASES if you want
 * admin -fl1 s.foo ;  admin -fl2 s.foo 
 * to result in both releases 1 and 2 being locked; 
 * if you do not deifne this, the -fl option will 
 * implicitly clear any previous list of locked releases. 
 */
#undef ADMIN_MERGE_LOCKED_RELEASES



/* Changes the file comment, flags, and/or the user authorization list
   of the SCCS file. */

bool
sccs_file::admin(const char *file_comment,
		 bool force_binary,
		 mylist<mystring> set_flags, mylist<mystring> unset_flags,
		 mylist<mystring> add_users, mylist<mystring> erase_users)
{
	
  if (force_binary)
    flags.encoded = 1;

  if (file_comment != NULL)
    {
      comments = NULL;
      if (file_comment[0] != '\0')
	{
	  FILE *fc = fopen(file_comment, "r");
	  if (NULL == fc)
	    {
	      errormsg_with_errno("%s: Can't open comment file", file_comment);
	      return false;
	    }

	  while (!read_line_param(fc))
	    {
	      comments.add(plinebuf->c_str());
	    }

	  if (ferror(fc))
	    {
	      errormsg_with_errno("%s: Read error", file_comment);
	      fclose(fc);
	      return false;
	    }
	  else
	    {
	      fclose(fc);
	    }
	}
    }

  int i;

  int len;
  len = set_flags.length();
  for(i = 0; i < len; i++)
    {
      const char *s = set_flags[i].c_str();
      
      switch (*s++)
	{
	case 'b':
	  flags.branch = 1;
	  break;
	  
	case 'c':
	  flags.ceiling = release(s);
	  if (!flags.ceiling.valid())
	    {
	      errormsg("Invalid release ceiling: '%s'", s);
	      return false;
	    }
	  break;

	case 'f':
	  flags.floor = release(s);
	  if (!flags.floor.valid())
	    {
	      errormsg("Invalid release floor: '%s'", s);
	      return false;
	    }
	  break;


	case 'd':
	  flags.default_sid = sid(s);
	  if (!flags.default_sid.valid())
	    {
	      errormsg("Invalid default SID: '%s'", s);
	      return false;
	    }
	  break;

	case 'i':
	  if (strlen(s))
	    {
	      errormsg("Flag 'i' does not take an argument.");
	      return false;
	    }
	  else
	    {
	      flags.no_id_keywords_is_fatal = 1;
	    }
	  break;


	case 'j':
	  flags.joint_edit = 1;
	  break;

	case 'l':
	  if (strcmp(s, "a") == 0)
	    {
	      flags.all_locked = 1;
	      flags.locked = release_list(); // empty list
	    }
	  else
	    {
#ifdef ADMIN_MERGE_LOCKED_RELEASES
	      flags.locked.merge(release_list(s));
#else
	      /* "admin -fl" clears any previously locked releases. 
	       */
	      flags.locked = release_list(); // empty list
	      flags.locked.merge(release_list(s));
#endif
	    }
	  break;

	case 'm':
	  set_module_flag(s);
	  break;
	  
	case 'n':
	  flags.null_deltas = 1;
	  break;


	case 'q':
	  set_user_flag(s);
	  break;
	  
	case 'e':
	  errormsg("The encoding flag must be set with the -b option");
	  return false;


	case 't':
	  set_type_flag(s);
	  break;

	case 'v':
	  set_mr_checker_flag(s);
	  break;

	case 'x':
	  warning("The 'x' (executable) flag is a SCO extension and is not supported by other versions of SCCS.");
	  flags.executable = 1;
	  break;
	  
	case 'y':
	  // Argument is a comma-separated list of keyword letters to expand.
	  warning("The 'y' (expanded keywords) flag is a Sun extension present only in Solaris 8 and later, and is not supported by other versions of SCCS.");
	  set_expanded_keyword_flag(""); // delete any existing ones.
	  while (*s)
	    {
	      char c = *s++;
	      if (',' != c)
		{
		  if (isalpha((unsigned char)c))
		    {
		      if (!is_known_keyword_char(c))
			{
			  warning("'%%%c%%' is not a recognised SCCS keyword, "
				  "but remembering that we want to expand it "
				  "anyway, for the future.", c);
			}
	  
		      flags.substitued_flag_letters.add(c);
		    }
		  else
		    {
		      errormsg("Unexpected character '%c' in argument to option '-fy'.", c);
		      return false;
		    }
		}
	    }
	  break;
	  
	default:
	  // TODO: this will fail for every file, so should probably
	  // be a "hard" error.
	  errormsg("Unrecognized flag '%c'", s[-1]);
	  return false;
	}
    }
	      
	
  len = unset_flags.length();
  for(i = 0; i < len; i++)
    {
      const char *s = unset_flags[i].c_str();

      switch (*s++)
	{
	case 'b':
	  flags.branch = 0;
	  break;
	  
	case 'c':
	  flags.ceiling = 0;
	  break;
	  
	case 'f':
	  flags.floor = 0;
	  break;
	  
	  
	case 'd':
	  flags.default_sid = NULL; // (XXX: correct use of NULL?) 
	  break;
	  
	case 'i':
	  flags.no_id_keywords_is_fatal = 0;
	  break;
	  
	case 'j':
	  flags.joint_edit = 0;
	  break;
	  
	case 'l':
	  if (strcmp(s, "a") == 0)
	    {
	      flags.all_locked = 0;
	      flags.locked = release_list();
	    }
	  else
	    {
	      flags.locked.remove(release_list(s));
	    }
	  break;
	  
	case 'm':
	  delete flags.module;
	  flags.module = 0;
	  break;
	  
	case 'n':
	  flags.null_deltas = 0;
	  break;
	  
	  
	case 'q':
	  delete flags.user_def;
	  flags.user_def = 0;
	  break;
	  
	case 'e':
	  errormsg("Deletion of the binary-encoding flag is not supported.");
	  return false;
			
	case 't':
	  delete flags.type;
	  flags.type = 0;
	  break;
	  
	case 'v':
	  delete flags.mr_checker;
	  flags.mr_checker = 0;
	  break;
	  
	case 'x':
	  flags.executable = 0;
	  break;
	  
	case 'y':
	  // Set the expanded-keyword flag to the empty string, which 
	  // means 'all' rather than none.
	  set_expanded_keyword_flag("");
	  break;
	  
	default:
	  // TODO: this will fail for every file, so should probably
	  // be a "hard" error.
	  errormsg("Unrecognized flag '%c'", s[-1]);
	  return false;
	}
    }

  // Erase any required users from the list.
  users -= erase_users;
	
  // Add the specified users to the beginning of the user list.
  mylist<mystring> newusers = add_users;
  newusers += users;
  users = newusers;

  return true;
}


/* Creates a new SCCS file. */

bool
sccs_file::create(const sid &id,
		  const char *iname,
		  mylist<mystring> mrs, mylist<mystring> comments,
		  int suppress_comments, bool force_binary)
{

  sccs_date now = sccs_date::now();
  if (!suppress_comments && comments.length() == 0)
    {
      comments.add(mystring("date and time created ")
		   + now.as_string()
		   + mystring(" by ")
		   + get_user_name());
    }


  delta new_delta('D', id, now, get_user_name(), 1, 0,
		  mrs, comments);
  new_delta.inserted = 0;
  new_delta.deleted = 0;
  new_delta.unchanged = 0;

  FILE *out = start_update(new_delta);
  if (NULL == out)
    return false;
  
  if (fprintf_failed(fprintf(out, "\001I 1\n")))
    return false;

  bool ret = true;
  if (iname != NULL)
    {
    FILE *in;

    if (strcmp(iname, "-") == 0)
      {
	in = stdin;
      }
    else
      {
      in = fopen(iname, "r");
      if (NULL == in)
	{
	  errormsg_with_errno("%s: Can't open file for reading", iname);
	  // TODO: delete output file?
	  fclose(out);
	  return false;
	}
      }

    bool found_id = false;
    unsigned long int lines = 0uL;

    // Insert the body...
    if (body_insert(&force_binary,
		     iname,		// input file name
		     name.xfile().c_str(), // output file name
		     in, out,
		     &lines, &found_id))
      {
	new_delta.inserted = lines;
	
	if (force_binary)
	  flags.encoded = true;	// fixup file in sccs_file::end_update()
      }
    else
      {
	ret = false;
      }
    
    if (in != stdin)
      fclose(in);

    // TODO: what if no id keywords is fatal?  Delete current s-file?
    // If so, do we continue with the next?
    if (!found_id)
      {
	no_id_keywords(name.c_str()); // this function normally returns. 
      }
  }
	
  if (fprintf_failed(fprintf(out, "\001E 1\n")))
    return false;

  // if the "encoded" flag needs to be changed,
  // end_update() will change it.
  if (!end_update(&out, new_delta))
    return false;

  return ret;
}

/* Local variables: */
/* mode: c++ */
/* End: */