~ubuntu-branches/ubuntu/quantal/numdiff/quantal

« back to all changes in this revision

Viewing changes to side.c

  • Committer: Package Import Robot
  • Author(s): Yaroslav Halchenko
  • Date: 2012-02-18 22:46:31 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120218224631-nxdvpq36o05v6sx7
Tags: 5.6.0-1
* New upstream release:
  - provides manpages -- dropped fix-missing-manpages.patch
  - the other patches updated
* Added patches:
  - up-mkdir-manpages.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
296
296
      next0 = i;
297
297
    }
298
298
}
 
299
 
 
300
/*
 
301
 * This function does the same actions as print_half_line(),
 
302
 * but takes as first argument a simple pointer to
 
303
 * const char
 
304
 */
 
305
static unsigned int
 
306
display_half_line (const char* line, unsigned int indent,
 
307
                   unsigned int out_bound)
 
308
{
 
309
  FILE *out = outfile;
 
310
  register unsigned int in_position = 0;
 
311
  register unsigned int out_position = 0;
 
312
  register const char *text_pointer = line;
 
313
  register const char *text_limit = line;
 
314
 
 
315
  for (; *text_limit != '\0'; text_limit++);
 
316
  while (text_pointer < text_limit)
 
317
    {
 
318
      register unsigned char c = *text_pointer++;
 
319
 
 
320
      switch (c)
 
321
        {
 
322
        case '\t':
 
323
          {
 
324
            unsigned int spaces = TAB_WIDTH - in_position % TAB_WIDTH;
 
325
            if (in_position == out_position)
 
326
              {
 
327
                unsigned int tabstop = out_position + spaces;
 
328
                if ((expand_tabs))
 
329
                  {
 
330
                    if (out_bound < tabstop)
 
331
                      tabstop = out_bound;
 
332
                    for (;  out_position < tabstop;  out_position++)
 
333
                      putc (' ', out);
 
334
                  }
 
335
                else
 
336
                  if (tabstop < out_bound)
 
337
                    {
 
338
                      out_position = tabstop;
 
339
                      putc (c, out);
 
340
                    }
 
341
              }
 
342
            in_position += spaces;
 
343
          }
 
344
          break;
 
345
 
 
346
        case '\r':
 
347
          {
 
348
            putc (c, out);
 
349
            tab_from_to (0, indent);
 
350
            in_position = out_position = 0;
 
351
          }
 
352
          break;
 
353
 
 
354
        case '\b':
 
355
          if (in_position != 0 && --in_position < out_bound)
 
356
            {
 
357
              if (out_position <= in_position)
 
358
                /* Add spaces to make up for suppressed tab past out_bound.  */
 
359
                for (;  out_position < in_position;  out_position++)
 
360
                  putc (' ', out);
 
361
              else
 
362
                {
 
363
                  out_position = in_position;
 
364
                  putc (c, out);
 
365
                }
 
366
            }
 
367
          break;
 
368
 
 
369
        case '\f':
 
370
        case '\v':
 
371
        control_character:
 
372
          if (in_position < out_bound)
 
373
            putc (c, out);
 
374
          break;
 
375
 
 
376
        default:
 
377
          if (! ISPRINT (c))
 
378
            goto control_character;
 
379
          /* falls through */
 
380
        case ' ':
 
381
          if (in_position++ < out_bound)
 
382
            {
 
383
              out_position = in_position;
 
384
              putc (c, out);
 
385
            }
 
386
          break;
 
387
 
 
388
        case '\n':
 
389
          return out_position;
 
390
        }
 
391
    }
 
392
 
 
393
  return out_position;
 
394
}
 
395
 
 
396
/*
 
397
 * Print side by side lines with a separator in the middle.
 
398
 * 0 parameters are taken to indicate white space text.
 
399
 * Blank lines that can easily be caught are reduced to a single newline.
 
400
 * This function works almost like  print_1sdiff_line() (see above),
 
401
 * but the parameter list is slightly different.
 
402
 * In addition, different separators are used
 
403
 */
 
404
 
 
405
void
 
406
print_1overview_line (const char *left, int are_different,
 
407
                      const char *right)
 
408
{
 
409
  FILE *out = outfile;
 
410
  unsigned int hw = sdiff_half_width, c2o = sdiff_column2_offset;
 
411
  unsigned int col = 0;
 
412
  bool put_newline = 0; 
 
413
  register const char *end_of_left = left;
 
414
  register const char *end_of_right = right;
 
415
  const char *sep = ":!:";
 
416
 
 
417
  if (left)
 
418
    {
 
419
      for (; *end_of_left != '\0'; end_of_left++);
 
420
      if (end_of_left != left)
 
421
        end_of_left--;
 
422
      put_newline |= *end_of_left == '\n';
 
423
      col = display_half_line (left, 0, hw);
 
424
    }
 
425
  else
 
426
    sep = ":>:";
 
427
 
 
428
  if (!right)
 
429
    sep = ":<:";
 
430
 
 
431
  if ((are_different))
 
432
    {
 
433
      col = tab_from_to (col, (hw + c2o - 3) / 2) + 3;
 
434
      fputs (sep, out);
 
435
    }
 
436
 
 
437
  if (right)
 
438
    {
 
439
      for (; *end_of_right != '\0'; end_of_right++);
 
440
      if (end_of_right != right)
 
441
        end_of_right--;
 
442
      put_newline |= (*end_of_right == '\n');
 
443
      if (*right != '\n')
 
444
        {
 
445
          col = tab_from_to (col, c2o);
 
446
          display_half_line (right, col, hw);
 
447
        }
 
448
    }
 
449
 
 
450
  if (put_newline)
 
451
    putc ('\n', out);
 
452
}