File: sf-get.cc

package info (click to toggle)
cssc 1.2.0-2
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 3,564 kB
  • ctags: 1,387
  • sloc: cpp: 13,240; sh: 4,771; ansic: 2,992; perl: 342; makefile: 338; awk: 11
file content (482 lines) | stat: -rw-r--r-- 11,934 bytes parent folder | download
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
/*
 * sf-get.cc: Part of GNU CSSC.
 * 
 * 
 *    Copyright (C) 1997,1998,1999,2001,2002,2003,
 *                  2004,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.
 *
 *
 * Members of class sccs_file used in getting deltas. 
 * 
 */

#ifdef __GNUC__
#pragma implementation "seqstate.h"
#endif

#include "cssc.h"
#include "sccsfile.h"
#include "pfile.h"
#include "seqstate.h"
#include "delta.h"
#include "delta-table.h"
#include "linebuf.h"
#include "bodyio.h"

// We use @LIBOBJS@ instead now...
// #ifndef HAVE_STRSTR
// #include "strstr.cc"
// #endif

#ifdef CONFIG_SCCS_IDS
static const char rcs_id[] = "CSSC $Id: sf-get.cc,v 1.43 2008/01/06 19:42:23 jay Exp $";
#endif

bool
sccs_file::prepare_seqstate_1(seq_state &state, seq_no seq)
{
  bool bDebug = getenv("CSSC_SHOW_SEQSTATE") ? true : false;

  /* new code */
#if 1
  seq_no y;
  int i, len;

  // deltas descended from the version we want are wanted (unless excluded)
  y = seq;
  do
    {
      ASSERT(y <= seq);
      const delta &d = delta_table->delta_at_seq(y);
      ASSERT(d.prev_seq < y);
      state.set_included(d.prev_seq, y, false);
      y = d.prev_seq;
    } while (y > 0);
  state.set_included(seq, (seq_no) seq_state::BY_DEFAULT, false);

  // Apply any inclusions 
  for (y=seq; y>0; --y)
    {
      if (state.is_included(y))
	{
	  const delta &d = delta_table->delta_at_seq(y);

	  len = d.included.length();
	  if (bDebug)
	    {
	      fprintf(stderr,
		      "seq %d includes %d other deltas...\n",
		      y, len);
	    }
	  
	  for(i = 0; i < len; i++)
	    {
	      const seq_no s = d.included[i];
	      if (s == y)
		continue;
	      
	      // A particular delta cannot have a LATER delta in 
	      // its include list.
	      ASSERT(s <= y);
	      state.set_included(s, y, true); 
	      ASSERT(state.is_included(s));
	    }
	}
    }
  
  // Apply any exclusions
  for (y=1; y<=seq; ++y)
    {
      if (state.is_included(y))
      {
	const delta &d = delta_table->delta_at_seq(y);
	
	len = d.excluded.length();
	if (bDebug)
	  {
	    fprintf(stderr,
		    "seq %d excludes %d other deltas...\n",
		    y, len);
	  }
	
	for(i = 0; i < len; i++)
	  {
	    const seq_no s = d.excluded[i];
	    if (s == y)
	      continue;
	    
	    // A particular delta cannot have a LATER delta in 
	    // its exclude list.
	    ASSERT(s <= y);
	    state.set_excluded(s, y);
	    ASSERT(state.is_excluded(s));
	  }
      }
    }
    

  // Apply any ignores
  // These are not recursive, so for example if version 1.6 ignored
  // version 1.2, the body lines for 1.1 will still be included.
  // (but what about any includes or excludes?)
  for (y=seq; y>0; --y)
    {
      if (state.is_included(y))
	{
	  const delta &d = delta_table->delta_at_seq(y);
	  len = d.ignored.length();
	  if (bDebug)
	    {
	      fprintf(stderr,
		      "seq %d ignores %d other deltas...\n",
		      y, len);
	    }
	
	  
	  for(i = 0; i < len; i++)
	    {
	      const seq_no s = d.ignored[i];
	      if (s == y)
		continue;
	      ASSERT(s <= y);
	      state.set_ignored(s, y);
	      
	      ASSERT(state.is_ignored(s));
	      ASSERT(!state.is_included(s));
	      ASSERT(!state.is_excluded(s));
	    }
	}
    }
  

  if (bDebug)
    {
      for (y=1; y<=seq; ++y)
	{
	  const char *msg;
	  if (state.is_ignored(y))
	    msg = "ignored";
	  else if (state.is_included(y))
	    msg = "included";
	  else
	    msg = "excluded";
	      
	  fprintf(stderr, "seq_no %d: %s\n", y, msg);
	}
    }
  
#else

  // We must include the version we are trying to get.
  state.set_included(seq, (seq_no) seq_state::BY_DEFAULT, false);
  
  while (seq != 0)
    {
      int len;
      int i;

      bool bExcluded = state.is_excluded(seq);
      bool bIncluded = state.is_included(seq);

      bool bVisible = true;
      if (bExcluded)
        bVisible = false;
      else if (!bIncluded)
        bVisible = false;

      if (bDebug)
        {
          if (bExcluded)
            {
              fprintf(stderr, "seq %lu: is excluded\n", (unsigned long)seq);
            }
          if (bVisible)
            {
              fprintf(stderr, "seq %lu: is visible\n", (unsigned long)seq);
            }
          else
            {
              fprintf(stderr, "seq %lu: is not visible\n", (unsigned long)seq);
            }
        }

      
      if (bVisible)
        {
          // OK, this delta is visible in the final result.  Apply its
          // include and exclude list.  We are travelling from newest to
          // oldest deltas.  Hence deltas which are ALREADY excluded or
          // included are left alone.  Only deltas which have not yet been
          // either included or excluded are messed with.
          
          const delta &d = delta_table->delta_at_seq(seq);
          
          len = d.included.length();
          for(i = 0; i < len; i++)
            {
	      if (bDebug)
		{
		  fprintf(stderr,
			  "seq %d includes %d other deltas...\n",
			  seq, len);
		}
		      
              const seq_no s = d.included[i];
              if (s == seq)
                continue;
              
              // A particular delta cannot have a LATER delta in 
              // its include list.
              ASSERT(s <= seq);
              
              if (!state.is_excluded(s))
                {
                  if (bDebug)
                    {
                      fprintf(stderr, "seq %lu includes seq %lu\n",
                              (unsigned long) seq,
                              (unsigned long) s);
                    }
                  state.set_included(s, seq, true); 
                  ASSERT(state.is_included(s));
                }
            }           

          len = d.excluded.length();
          for(i = 0; i < len; i++)
            {
	      if (bDebug)
		{
		  fprintf(stderr,
			  "se %d excludes %d other deltas...\n",
			  seq, len);
		}
		      
              const seq_no s = d.excluded[i];
              if (s == seq)
                continue;
              
              // A particular delta cannot have a LATER delta in 
              // its exclude list.
              ASSERT(s <= seq);
              
	      if (bDebug)
		{
		  fprintf(stderr, "seq %lu excludes seq %lu\n",
			  (unsigned long)seq,
			  (unsigned long)s);
		}
	      state.set_explicitly_excluded(s, seq);
	      ASSERT(state.is_excluded(s));
            }

          // If this seq was explicitly included, don't recurse for it 
          // (this fixes SourceForge bug number 111140).
          if (state.is_recursive(seq))
            {
	      fprintf(stderr, "seq %lu is recursive; including seq %lu\n",
		      (unsigned long)seq,
		      (unsigned long)d.prev_seq);
	      state.set_included(d.prev_seq, seq, false);
	    }
	}
      
      --seq;
    }

#endif

  
  if (bDebug)
    {
      fprintf(stderr,
              "sccs_file::prepare_seqstate_1(seq_state &state, seq_no seq)"
              " done\n");
    }
  return true;
}

bool
sccs_file::get(mystring gname, class seq_state &state,
               struct subst_parms &parms,
               bool do_kw_subst,
               int show_sid, int show_module, int debug,
               bool no_decode /* = false */,
	       bool for_edit /* = false */)
{
  ASSERT(mode != CREATE);
  ASSERT(mode != FIX_CHECKSUM);

  if (!edit_mode_ok(for_edit))	// "get -e" on BK files is not allowed
    return false;
  
  int (*outputfn)(FILE*,const cssc_linebuf*);
  if (flags.encoded && false == no_decode)
    outputfn = output_body_line_binary;
  else
    outputfn = output_body_line_text;
        

  if (!seek_to_body())
    return false;
  

  /* The following statement is not correct. */
  /* "@I 1" should start the body of the SCCS file */

  if (read_line() != 'I')
    {
      corrupt("Expected '@I'");
      return false;
    }
  check_arg();

  /* The check on the following line is certainly wrong, since
   * the first body line need not refer to the first delta.  For
   * example, SunOS 4.1.1's SCCS implementation doesn't always
   * start with ^AI 1.
   */
  unsigned short first_delta = strict_atous( plinebuf->c_str() + 3);
  state.start(first_delta, 'I'); /* 'I' means "insert". */

  FILE *out = parms.out;

  while (1) {
    int c = read_line();

    if (c == -1) { 
      /* EOF */
      break;
    }

    if (c == 0) {
      /* A non-control line */

      if (debug) {
        if (state.include_line()) {
          putc('I', f);
        } else {
          putc('D', f);
        }
        putc(' ', f);
      } else if (!state.include_line()) {
        continue;
      }

      parms.out_lineno++;

      if (show_module)
        fprintf(out, "%s\t", get_module_name().c_str());

      if (show_sid)
        {
          seq_to_sid(state.active_seq()).print(out);
          putc('\t', out);
        }

      int err;
      if (do_kw_subst)
        {
          // If there is a cutoff date,
          // prepare_seqstate() will take account of
          // it.  We need the keyword substitution to
          // take account of this and substitute the
          // correct stuff.... so we figure out what
          // delta has actually been selected here...


          if (flags.encoded)
            {
              /*
               * We ignore the possiblity of keyword substitution.
               * I don't think "real" SCCS does keyword substitution
               * for this case either -- James Youngman <jay@gnu.org>
               */
              err = outputfn(out, plinebuf);
            }
          else
            {
                // Mark Reynolds <mark@aoainc.com>: GCC 2.8.1 on VAX
                // Ultrix 4.2 doesn't seem to get this call right.
                // Since subst_fn is always write_subst anyway, we 
                // work around it by using the function pointer just as a 
                // boolean variable.   Yeuch.
                // 
                // 2001-07-30: get rid of all the cruft by using a boolean
                //             flag instead of a function pointer, for all
                //             systems. 
                err = write_subst(plinebuf->c_str(), &parms, parms.delta, false);
              
              if (fputc_failed(fputc('\n', out)))
                err = 1;
            }
        }
      else
        {
          if (!parms.found_id && plinebuf->check_id_keywords())
            parms.found_id = 1;
          err = outputfn(out, plinebuf);
        } 

      if (err)
        {
          errormsg_with_errno("%s: Write error.", gname.c_str());
          return false;
        }
      
      continue;
    }

    /* A control line */

    check_arg();
    seq_no seq = strict_atous(plinebuf->c_str() + 3);
    if (seq < 1 || seq > highest_delta_seqno()) {
      corrupt("Invalid serial number");
    }

    const char *msg = NULL;

    switch (c) {
    case 'E':
      msg = state.end(seq);
      break;

    case 'D':
    case 'I':
      msg = state.start(seq, c);
      break;
      
    default:
      corrupt("Unexpected control line");
      break;
    }

    if (msg != NULL) {
      corrupt(msg);
    }
  }

  fflush(out);
  return true;
}

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