~ubuntu-branches/ubuntu/vivid/diffutils/vivid

« back to all changes in this revision

Viewing changes to src/side.c

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2010-02-13 11:49:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100213114900-09lz8jx6wct52qp8
Tags: 1:2.9-1
* New upstream release, now under GPL version 3 or later.
* There is now a --tab-size option. Closes: #82923.
* Manpage for cmp describes exit status. Closes: #200614.
* Manpage for diff describes exit status. Closes: #228441, #473233.
* The file de.po is now more recent. Closes: #313686.
* Fixed bad sdiff behaviour. Closes: #320222.
* Added wdiff to Suggests. Closes: #324627.
* Fixed cmp behaviour regarding stdout and stderr. Closes: #356083.
* The file ru.po is now more recent. Closes: #409274.
* The file es.po is now more recent. Closes: #418005, #481708.
* The file nl.po is now more recent. Closes: #427370.
* Modified watch file to use http instead of ftp.
* Removed .comment section from executables.
* Added Homepage field to control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* sdiff-format output routines for GNU DIFF.
2
2
 
3
 
   Copyright (C) 1991, 1992, 1993, 1998, 2001, 2002 Free Software
 
3
   Copyright (C) 1991-1993, 1998, 2001-2002, 2004, 2009-2010 Free Software
4
4
   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
22
22
 
23
23
#include "diff.h"
24
24
 
 
25
#include <wchar.h>
 
26
 
25
27
static void print_sdiff_common_lines (lin, lin);
26
28
static void print_sdiff_hunk (struct change *);
27
29
 
43
45
 
44
46
/* Tab from column FROM to column TO, where FROM <= TO.  Yield TO.  */
45
47
 
46
 
static unsigned int
47
 
tab_from_to (unsigned int from, unsigned int to)
 
48
static size_t
 
49
tab_from_to (size_t from, size_t to)
48
50
{
49
51
  FILE *out = outfile;
50
 
  unsigned int tab;
 
52
  size_t tab;
 
53
  size_t tab_size = tabsize;
51
54
 
52
55
  if (!expand_tabs)
53
 
    for (tab = from + TAB_WIDTH - from % TAB_WIDTH;  tab <= to;  tab += TAB_WIDTH)
 
56
    for (tab = from + tab_size - from % tab_size;  tab <= to;  tab += tab_size)
54
57
      {
55
58
        putc ('\t', out);
56
59
        from = tab;
60
63
  return to;
61
64
}
62
65
 
63
 
/*
64
 
 * Print the text for half an sdiff line.  This means truncate to width
65
 
 * observing tabs, and trim a trailing newline.  Returns the last column
66
 
 * written (not the number of chars).
67
 
 */
68
 
static unsigned int
69
 
print_half_line (char const *const *line, unsigned int indent,
70
 
                 unsigned int out_bound)
 
66
/* Print the text for half an sdiff line.  This means truncate to
 
67
   width observing tabs, and trim a trailing newline.  Return the
 
68
   last column written (not the number of chars).  */
 
69
 
 
70
static size_t
 
71
print_half_line (char const *const *line, size_t indent, size_t out_bound)
71
72
{
72
73
  FILE *out = outfile;
73
 
  register unsigned int in_position = 0;
74
 
  register unsigned int out_position = 0;
 
74
  register size_t in_position = 0;
 
75
  register size_t out_position = 0;
75
76
  register char const *text_pointer = line[0];
76
77
  register char const *text_limit = line[1];
 
78
  mbstate_t mbstate = { 0 };
77
79
 
78
80
  while (text_pointer < text_limit)
79
81
    {
80
 
      register unsigned char c = *text_pointer++;
 
82
      char const *tp0 = text_pointer;
 
83
      register char c = *text_pointer++;
81
84
 
82
85
      switch (c)
83
86
        {
84
87
        case '\t':
85
88
          {
86
 
            unsigned int spaces = TAB_WIDTH - in_position % TAB_WIDTH;
 
89
            size_t spaces = tabsize - in_position % tabsize;
87
90
            if (in_position == out_position)
88
91
              {
89
 
                unsigned int tabstop = out_position + spaces;
 
92
                size_t tabstop = out_position + spaces;
90
93
                if (expand_tabs)
91
94
                  {
92
95
                    if (out_bound < tabstop)
128
131
            }
129
132
          break;
130
133
 
 
134
        default:
 
135
          {
 
136
            wchar_t wc;
 
137
            size_t bytes = mbrtowc (&wc, tp0, text_limit - tp0, &mbstate);
 
138
 
 
139
            if (0 < bytes && bytes < (size_t) -2)
 
140
              {
 
141
                int width = wcwidth (wc);
 
142
                if (0 < width)
 
143
                  in_position += width;
 
144
                if (in_position <= out_bound)
 
145
                  {
 
146
                    out_position = in_position;
 
147
                    fwrite (tp0, 1, bytes, stdout);
 
148
                  }
 
149
                text_pointer = tp0 + bytes;
 
150
                break;
 
151
              }
 
152
          }
 
153
          /* Fall through.  */
131
154
        case '\f':
132
155
        case '\v':
133
 
        control_char:
134
156
          if (in_position < out_bound)
135
157
            putc (c, out);
136
158
          break;
137
159
 
138
 
        default:
139
 
          if (! ISPRINT (c))
140
 
            goto control_char;
141
 
          /* falls through */
142
 
        case ' ':
 
160
        case ' ': case '!': case '"': case '#': case '%':
 
161
        case '&': case '\'': case '(': case ')': case '*':
 
162
        case '+': case ',': case '-': case '.': case '/':
 
163
        case '0': case '1': case '2': case '3': case '4':
 
164
        case '5': case '6': case '7': case '8': case '9':
 
165
        case ':': case ';': case '<': case '=': case '>':
 
166
        case '?':
 
167
        case 'A': case 'B': case 'C': case 'D': case 'E':
 
168
        case 'F': case 'G': case 'H': case 'I': case 'J':
 
169
        case 'K': case 'L': case 'M': case 'N': case 'O':
 
170
        case 'P': case 'Q': case 'R': case 'S': case 'T':
 
171
        case 'U': case 'V': case 'W': case 'X': case 'Y':
 
172
        case 'Z':
 
173
        case '[': case '\\': case ']': case '^': case '_':
 
174
        case 'a': case 'b': case 'c': case 'd': case 'e':
 
175
        case 'f': case 'g': case 'h': case 'i': case 'j':
 
176
        case 'k': case 'l': case 'm': case 'n': case 'o':
 
177
        case 'p': case 'q': case 'r': case 's': case 't':
 
178
        case 'u': case 'v': case 'w': case 'x': case 'y':
 
179
        case 'z': case '{': case '|': case '}': case '~':
 
180
          /* These characters are printable ASCII characters.  */
143
181
          if (in_position++ < out_bound)
144
182
            {
145
183
              out_position = in_position;
155
193
  return out_position;
156
194
}
157
195
 
158
 
/*
159
 
 * Print side by side lines with a separator in the middle.
160
 
 * 0 parameters are taken to indicate white space text.
161
 
 * Blank lines that can easily be caught are reduced to a single newline.
162
 
 */
 
196
/* Print side by side lines with a separator in the middle.
 
197
   0 parameters are taken to indicate white space text.
 
198
   Blank lines that can easily be caught are reduced to a single newline.  */
163
199
 
164
200
static void
165
201
print_1sdiff_line (char const *const *left, char sep,
166
202
                   char const *const *right)
167
203
{
168
204
  FILE *out = outfile;
169
 
  unsigned int hw = sdiff_half_width, c2o = sdiff_column2_offset;
170
 
  unsigned int col = 0;
171
 
  bool put_newline = 0;
 
205
  size_t hw = sdiff_half_width;
 
206
  size_t c2o = sdiff_column2_offset;
 
207
  size_t col = 0;
 
208
  bool put_newline = false;
172
209
 
173
210
  if (left)
174
211
    {
208
245
    {
209
246
      if (sdiff_merge_assist)
210
247
        {
211
 
          long len0 = limit0 - i0;
212
 
          long len1 = limit1 - i1;
 
248
          long int len0 = limit0 - i0;
 
249
          long int len1 = limit1 - i1;
213
250
          fprintf (outfile, "i%ld,%ld\n", len0, len1);
214
251
        }
215
252
 
250
287
 
251
288
  if (sdiff_merge_assist)
252
289
    {
253
 
      long len0 = last0 - first0 + 1;
254
 
      long len1 = last1 - first1 + 1;
 
290
      long int len0 = last0 - first0 + 1;
 
291
      long int len1 = last1 - first1 + 1;
255
292
      fprintf (outfile, "c%ld,%ld\n", len0, len1);
256
293
    }
257
294