File: prs.cc

package info (click to toggle)
cssc 1.0.1-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 3,620 kB
  • ctags: 1,424
  • sloc: cpp: 13,500; sh: 4,759; ansic: 2,971; perl: 342; makefile: 342; awk: 11
file content (201 lines) | stat: -rw-r--r-- 4,292 bytes parent folder | download | duplicates (3)
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
/*
 * prs.cc: Part of GNU CSSC.
 * 
 *    Copyright (C) 1997,1998,1999,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.
 * 
 * CSSC was originally Based on MySC, by Ross Ridge, which was 
 * placed in the Public Domain.
 *
 *
 * Prints selected parts of an SCCS file.
 *
 */

#include "cssc.h"
#include "fileiter.h"
#include "sccsfile.h"
#include "my-getopt.h"
#include "version.h"
#include "delta.h"
#include "except.h"


const char main_rcs_id[] = "CSSC $Id: prs.cc,v 1.23 2001/09/29 19:39:41 james_youngman Exp $";

void
usage() {
	fprintf(stderr,
"usage: %s [-aelDRV] [-c cutoff] [-d format] [-r SID] file ...\n",
		prg_name);
}

int
main(int argc, char **argv)
{
  Cleaner arbitrary_name;
  int c;
  mystring format = ":Dt:\t:DL:\nMRs:\n:MR:COMMENTS:\n:C:";
  sid rid = NULL;		// (XXX: correct use of NULL?) 
  /* enum */ sccs_file::when selected = sccs_file::SIDONLY;
  int all_deltas = 0;
  sccs_date cutoff_date;
  int default_processing = 1;

  if (argc > 0)
    set_prg_name(argv[0]);
  else
    set_prg_name("prs");

  CSSC_Options opts(argc, argv, "d!Dr!Relc!aV");
  for(c = opts.next();
      c != CSSC_Options::END_OF_ARGUMENTS;
      c = opts.next())
    {
      switch (c)
	{
	default:
	  errormsg("Unsupported option: '%c'", c);
	  return 2;
	  
	case 'd':
	  format = opts.getarg();
	  default_processing = 0;
	  break;
	  
	case 'D':	// obsolete MySC-ism.
	  default_processing = 0;
	  break;
	  
	case 'r':
	  if (strlen(opts.getarg()))
	    {
	      rid = sid(opts.getarg());
	      if (!rid.valid() || rid.partial_sid())
		{
		  errormsg("Invaild SID: '%s'", opts.getarg());
		  return 2;
		}
	    }
	  else
	    {
	      // default: get the most recent delta.
	    }
	  default_processing = 0;
	  break;
	  
	case 'R':	// obsolete MySC-ism.
	  rid = NULL;		// (XXX: correct use of NULL?) 
	  default_processing = 0;
	  break;
	  
	case 'c':
	  cutoff_date = sccs_date(opts.getarg());
	  if (!cutoff_date.valid())
	    {
	      errormsg("Invalid cutoff date: '%s'",
		       opts.getarg());
	      return 2;
	    }
	  break;
	  
	case 'e':
	  selected = sccs_file::EARLIER;
	  default_processing = 0;
	  break;
	  
	case 'l':
	  selected = sccs_file::LATER;
	  default_processing = 0;
	  break;
	  
	case 'a':
	  all_deltas = 1;
	  break;
	  
	case 'V':
	  version();
	  break;
	}
      
    }
  
  if (selected == sccs_file::SIDONLY && cutoff_date.valid())
    {
      errormsg("Either the -e or -l switch must used with a"
	       " cutoff date.");
      return 2;
    }
  
  if (default_processing)
    {
      selected = sccs_file::EARLIER;
    }

  sccs_file_iterator iter(opts);
  if (! iter.using_source())
    {
      errormsg("No SCCS file specified.");
      return 1;
    }

  int retval = 0;
  
  while (iter.next())
    {
#ifdef HAVE_EXCEPTIONS
      try 
	{
#endif	  
	  sccs_name &name = iter.get_name();
	  sccs_file file(name, sccs_file::READ);
	  
	  if (default_processing)
	    {
	      printf("%s:\n\n", name.c_str());
	    }
	  if (!file.prs(stdout, format, rid, cutoff_date, selected,
			all_deltas))
	    {
	      retval = 1;
	    }
#ifdef HAVE_EXCEPTIONS
	} // end of try block.
      catch (CsscExitvalException e)
	{
	  if (e.exitval > retval)
	    retval = e.exitval;
	}
#endif
    }
  return retval;
}


// Explicit template instantiations.
template class range_list<sid>;
template class mylist<mystring>;
template class mylist<seq_no>;
template class mylist<delta>;
template class range_list<release>;


#include "stack.h"
template class stack<seq_no>;

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