~ubuntu-branches/ubuntu/natty/diffutils/natty

« back to all changes in this revision

Viewing changes to src/ifdef.c

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2010-05-04 20:38:00 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100504203800-f67xd9rsa9xl9qqj
Tags: 1:3.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* #ifdef-format output routines for GNU DIFF.
2
2
 
3
 
   Copyright (C) 1989, 1991, 1992, 1993, 1994, 2001, 2002 Free
 
3
   Copyright (C) 1989, 1991-1994, 2001-2002, 2004, 2006, 2009-2010 Free
4
4
   Software Foundation, Inc.
5
5
 
6
6
   This file is part of GNU DIFF.
9
9
   but WITHOUT ANY WARRANTY.  No author or distributor
10
10
   accepts responsibility to anyone for the consequences of using it
11
11
   or for whether it serves any particular purpose or works at all,
12
 
   unless he says so in writing.  Refer to the GNU DIFF General Public
 
12
   unless he says so in writing.  Refer to the GNU General Public
13
13
   License for full details.
14
14
 
15
15
   Everyone is granted permission to copy, modify and redistribute
16
16
   GNU DIFF, but only under the conditions described in the
17
 
   GNU DIFF General Public License.   A copy of this license is
 
17
   GNU General Public License.   A copy of this license is
18
18
   supposed to have been given to you along with GNU DIFF so you
19
19
   can know your rights and responsibilities.  It should be in a
20
20
   file named COPYING.  Among other things, the copyright notice
41
41
static void print_ifdef_hunk (struct change *);
42
42
static void print_ifdef_lines (FILE *, char const *, struct group const *);
43
43
 
44
 
static lin next_line;
 
44
static lin next_line0;
 
45
static lin next_line1;
45
46
 
46
47
/* Print the edit-script SCRIPT as a merged #ifdef file.  */
47
48
 
48
49
void
49
50
print_ifdef_script (struct change *script)
50
51
{
51
 
  next_line = - files[0].prefix_lines;
 
52
  next_line0 = next_line1 = - files[0].prefix_lines;
52
53
  print_script (script, find_change, print_ifdef_hunk);
53
 
  if (next_line < files[0].valid_lines)
 
54
  if (next_line0 < files[0].valid_lines
 
55
      || next_line1 < files[1].valid_lines)
54
56
    {
55
57
      begin_output ();
56
 
      format_ifdef (group_format[UNCHANGED], next_line, files[0].valid_lines,
57
 
                    next_line - files[0].valid_lines + files[1].valid_lines,
58
 
                    files[1].valid_lines);
 
58
      format_ifdef (group_format[UNCHANGED],
 
59
                    next_line0, files[0].valid_lines,
 
60
                    next_line1, files[1].valid_lines);
59
61
    }
60
62
}
61
63
 
76
78
  begin_output ();
77
79
 
78
80
  /* Print lines up to this change.  */
79
 
  if (next_line < first0)
80
 
    format_ifdef (group_format[UNCHANGED], next_line, first0,
81
 
                  next_line - first0 + first1, first1);
 
81
  if (next_line0 < first0 || next_line1 < first1)
 
82
    format_ifdef (group_format[UNCHANGED],
 
83
                  next_line0, first0,
 
84
                  next_line1, first1);
82
85
 
83
86
  /* Print this change.  */
84
 
  next_line = last0 + 1;
85
 
  format_ifdef (group_format[changes], first0, next_line, first1, last1 + 1);
 
87
  next_line0 = last0 + 1;
 
88
  next_line1 = last1 + 1;
 
89
  format_ifdef (group_format[changes],
 
90
                first0, next_line0,
 
91
                first1, next_line1);
86
92
}
87
93
 
88
94
/* Print a set of lines according to FORMAT.
323
329
        return 0;
324
330
      else
325
331
        {
326
 
          char value;
 
332
          char value IF_LINT (= 0);
327
333
          f = scan_char_literal (f, &value);
328
334
          if (!f)
329
335
            return 0;
353
359
          {
354
360
            /* For example, if the spec is "%3xn", use the printf
355
361
               format spec "%3lx".  Here the spec prefix is "%3".  */
356
 
            long long_value = value;
 
362
            long int long_value = value;
357
363
            size_t spec_prefix_len = f - spec - 2;
358
364
#if HAVE_C_VARARRAYS
359
365
            char format[spec_prefix_len + 3];
383
389
/* Scan the character literal represented in the string LIT; LIT points just
384
390
   after the initial apostrophe.  Put the literal's value into *VALPTR.
385
391
   Yield the address of the first character after the closing apostrophe,
386
 
   or zero if the literal is ill-formed.  */
 
392
   or a null pointer if the literal is ill-formed.  */
387
393
static char const *
388
394
scan_char_literal (char const *lit, char *valptr)
389
395
{
396
402
    {
397
403
      case 0:
398
404
      case '\'':
399
 
        return 0;
 
405
        return NULL;
400
406
 
401
407
      case '\\':
402
408
        value = 0;
404
410
          {
405
411
            unsigned int digit = c - '0';
406
412
            if (8 <= digit)
407
 
              return 0;
 
413
              return NULL;
408
414
            value = 8 * value + digit;
409
415
          }
410
416
        digits = p - lit - 2;
411
417
        if (! (1 <= digits && digits <= 3))
412
 
          return 0;
 
418
          return NULL;
413
419
        break;
414
420
 
415
421
      default:
416
422
        value = c;
417
423
        if (*p++ != '\'')
418
 
          return 0;
 
424
          return NULL;
419
425
        break;
420
426
    }
421
427