~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to src/od.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* od -- dump files in octal and other formats
2
 
   Copyright (C) 1992, 1995-2011 Free Software Foundation, Inc.
 
2
   Copyright (C) 1992-2012 Free Software Foundation, Inc.
3
3
 
4
4
   This program is free software: you can redistribute it and/or modify
5
5
   it under the terms of the GNU General Public License as published by
30
30
#include "xprintf.h"
31
31
#include "xstrtol.h"
32
32
 
33
 
/* The official name of this program (e.g., no `g' prefix).  */
 
33
/* The official name of this program (e.g., no 'g' prefix).  */
34
34
#define PROGRAM_NAME "od"
35
35
 
36
36
#define AUTHORS proper_name ("Jim Meyering")
41
41
#if HAVE_UNSIGNED_LONG_LONG_INT
42
42
typedef unsigned long long int unsigned_long_long_int;
43
43
#else
44
 
/* This is just a place-holder to avoid a few `#if' directives.
 
44
/* This is just a place-holder to avoid a few '#if' directives.
45
45
   In this case, the type isn't actually used.  */
46
46
typedef unsigned long int unsigned_long_long_int;
47
47
#endif
92
92
/* Ensure that our choice for FMT_BYTES_ALLOCATED is reasonable.  */
93
93
verify (MAX_INTEGRAL_TYPE_SIZE * CHAR_BIT / 3 <= 99);
94
94
 
95
 
/* Each output format specification (from `-t spec' or from
 
95
/* Each output format specification (from '-t spec' or from
96
96
   old-style options) is represented by one of these structures.  */
97
97
struct tspec
98
98
  {
156
156
  sizeof (long double)
157
157
};
158
158
 
159
 
/* Ensure that for each member of `enum size_spec' there is an
 
159
/* Ensure that for each member of 'enum size_spec' there is an
160
160
   initializer in the width_bytes array.  */
161
161
verify (ARRAY_CARDINALITY (width_bytes) == N_SIZE_SPECS);
162
162
 
192
192
   offset and pseudo-start address.  */
193
193
static bool traditional;
194
194
 
195
 
/* True if an old-style `pseudo-address' was specified.  */
 
195
/* True if an old-style 'pseudo-address' was specified.  */
196
196
static bool flag_pseudo_start;
197
197
 
198
198
/* The difference between the old-style pseudo starting address and
288
288
usage (int status)
289
289
{
290
290
  if (status != EXIT_SUCCESS)
291
 
    fprintf (stderr, _("Try `%s --help' for more information.\n"),
292
 
             program_name);
 
291
    emit_try_help ();
293
292
  else
294
293
    {
295
294
      printf (_("\
314
313
"), stdout);
315
314
      fputs (_("\
316
315
  -N, --read-bytes=BYTES      limit dump to BYTES input bytes\n\
317
 
  -S, --strings[=BYTES]       output strings of at least BYTES graphic chars\n\
 
316
  -S BYTES, --strings[=BYTES]  output strings of at least BYTES graphic chars\n\
318
317
  -t, --format=TYPE           select output format or formats\n\
319
318
  -v, --output-duplicates     do not use * to mark line suppression\n\
320
 
  -w, --width[=BYTES]         output BYTES bytes per output line\n\
 
319
  -w[BYTES], --width[=BYTES]  output BYTES bytes per output line\n\
321
320
      --traditional           accept arguments in traditional form\n\
322
321
"), stdout);
323
322
      fputs (HELP_OPTION_DESCRIPTION, stdout);
641
640
              if (MAX_INTEGRAL_TYPE_SIZE < size
642
641
                  || integral_type_size[size] == NO_SIZE)
643
642
                {
644
 
                  error (0, 0, _("invalid type string %s;\n\
645
 
this system doesn't provide a %lu-byte integral type"), quote (s_orig), size);
 
643
                  error (0, 0, _("invalid type string %s;\nthis system"
 
644
                                 " doesn't provide a %lu-byte integral type"),
 
645
                         quote (s_orig), size);
646
646
                  return false;
647
647
                }
648
648
              s = p;
760
760
              if (size > MAX_FP_TYPE_SIZE
761
761
                  || fp_type_size[size] == NO_SIZE)
762
762
                {
763
 
                  error (0, 0, _("invalid type string %s;\n\
764
 
this system doesn't provide a %lu-byte floating point type"),
 
763
                  error (0, 0,
 
764
                         _("invalid type string %s;\n"
 
765
                           "this system doesn't provide a %lu-byte"
 
766
                           " floating point type"),
765
767
                         quote (s_orig), size);
766
768
                  return false;
767
769
                }
771
773
        }
772
774
      size_spec = fp_type_size[size];
773
775
 
774
 
      struct lconv const *locale = localeconv ();
775
 
      size_t decimal_point_len =
776
 
        (locale->decimal_point[0] ? strlen (locale->decimal_point) : 1);
777
 
 
778
 
      switch (size_spec)
779
 
        {
780
 
        case FLOAT_SINGLE:
781
 
          print_function = print_float;
782
 
          field_width = FLT_STRLEN_BOUND_L (decimal_point_len);
783
 
          break;
784
 
 
785
 
        case FLOAT_DOUBLE:
786
 
          print_function = print_double;
787
 
          field_width = DBL_STRLEN_BOUND_L (decimal_point_len);
788
 
          break;
789
 
 
790
 
        case FLOAT_LONG_DOUBLE:
791
 
          print_function = print_long_double;
792
 
          field_width = LDBL_STRLEN_BOUND_L (decimal_point_len);
793
 
          break;
794
 
 
795
 
        default:
796
 
          abort ();
797
 
        }
798
 
 
799
 
      break;
 
776
      {
 
777
        struct lconv const *locale = localeconv ();
 
778
        size_t decimal_point_len =
 
779
          (locale->decimal_point[0] ? strlen (locale->decimal_point) : 1);
 
780
 
 
781
        switch (size_spec)
 
782
          {
 
783
          case FLOAT_SINGLE:
 
784
            print_function = print_float;
 
785
            field_width = FLT_STRLEN_BOUND_L (decimal_point_len);
 
786
            break;
 
787
 
 
788
          case FLOAT_DOUBLE:
 
789
            print_function = print_double;
 
790
            field_width = DBL_STRLEN_BOUND_L (decimal_point_len);
 
791
            break;
 
792
 
 
793
          case FLOAT_LONG_DOUBLE:
 
794
            print_function = print_long_double;
 
795
            field_width = LDBL_STRLEN_BOUND_L (decimal_point_len);
 
796
            break;
 
797
 
 
798
          default:
 
799
            abort ();
 
800
          }
 
801
 
 
802
        break;
 
803
      }
800
804
 
801
805
    case 'a':
802
806
      ++s;
815
819
      break;
816
820
 
817
821
    default:
818
 
      error (0, 0, _("invalid character `%c' in type string %s"),
 
822
      error (0, 0, _("invalid character '%c' in type string %s"),
819
823
             *s, quote (s_orig));
820
824
      return false;
821
825
    }
979
983
 
980
984
      if (fstat (fileno (in_stream), &file_stats) == 0)
981
985
        {
982
 
          /* The st_size field is valid only for regular files
983
 
             (and for symbolic links, which cannot occur here).
 
986
          /* The st_size field is valid for regular files.
984
987
             If the number of bytes left to skip is larger than
985
988
             the size of the current file, we can decrement n_skip
986
989
             and go on to the next file.  Skip this optimization also
1283
1286
  if (s[0] == '+')
1284
1287
    ++s;
1285
1288
 
1286
 
  /* Determine the radix we'll use to interpret S.  If there is a `.',
1287
 
     it's decimal, otherwise, if the string begins with `0X'or `0x',
 
1289
  /* Determine the radix we'll use to interpret S.  If there is a '.',
 
1290
     it's decimal, otherwise, if the string begins with '0X'or '0x',
1288
1291
     it's hexadecimal, else octal.  */
1289
1292
  if (strchr (s, '.') != NULL)
1290
1293
    radix = 10;
1389
1392
}
1390
1393
 
1391
1394
/* STRINGS mode.  Find each "string constant" in the input.
1392
 
   A string constant is a run of at least `string_min' ASCII
 
1395
   A string constant is a run of at least 'string_min' ASCII
1393
1396
   graphic (or formatting) characters terminated by a null.
1394
1397
   Based on a function written by Richard Stallman for a
1395
1398
   traditional version of od.  Return true if successful.  */
1407
1410
      size_t i;
1408
1411
      int c;
1409
1412
 
1410
 
      /* See if the next `string_min' chars are all printing chars.  */
 
1413
      /* See if the next 'string_min' chars are all printing chars.  */
1411
1414
    tryline:
1412
1415
 
1413
1416
      if (limit_bytes_to_format
1429
1432
          buf[i] = c;
1430
1433
        }
1431
1434
 
1432
 
      /* We found a run of `string_min' printable characters.
 
1435
      /* We found a run of 'string_min' printable characters.
1433
1436
         Now see if it is terminated with a null byte.  */
1434
1437
      while (!limit_bytes_to_format || address < end_offset)
1435
1438
        {
1452
1455
        }
1453
1456
 
1454
1457
      /* If we get here, the string is all printable and null-terminated,
1455
 
         so print it.  It is all in `buf' and `i' is its length.  */
 
1458
         so print it.  It is all in 'buf' and 'i' is its length.  */
1456
1459
      buf[i] = 0;
1457
1460
      format_address (address - i - 1, ' ');
1458
1461
 
1517
1520
  size_t width_per_block = 0;
1518
1521
  static char const multipliers[] = "bEGKkMmPTYZ0";
1519
1522
 
1520
 
  /* The old-style `pseudo starting address' to be printed in parentheses
 
1523
  /* The old-style 'pseudo starting address' to be printed in parentheses
1521
1524
     after any true address.  */
1522
1525
  uintmax_t pseudo_start IF_LINT ( = 0);
1523
1526
 
1537
1540
  integral_type_size[sizeof (int)] = INT;
1538
1541
  integral_type_size[sizeof (long int)] = LONG;
1539
1542
#if HAVE_UNSIGNED_LONG_LONG_INT
1540
 
  /* If `long int' and `long long int' have the same size, it's fine
1541
 
     to overwrite the entry for `long' with this one.  */
 
1543
  /* If 'long int' and 'long long int' have the same size, it's fine
 
1544
     to overwrite the entry for 'long' with this one.  */
1542
1545
  integral_type_size[sizeof (unsigned_long_long_int)] = LONG_LONG;
1543
1546
#endif
1544
1547
 
1546
1549
    fp_type_size[i] = NO_SIZE;
1547
1550
 
1548
1551
  fp_type_size[sizeof (float)] = FLOAT_SINGLE;
1549
 
  /* The array entry for `double' is filled in after that for `long double'
 
1552
  /* The array entry for 'double' is filled in after that for 'long double'
1550
1553
     so that if they are the same size, we avoid any overhead of
1551
1554
     long double computation in libc.  */
1552
1555
  fp_type_size[sizeof (long double)] = FLOAT_LONG_DOUBLE;
1597
1600
              break;
1598
1601
            default:
1599
1602
              error (EXIT_FAILURE, 0,
1600
 
                     _("invalid output address radix `%c'; \
1601
 
it must be one character from [doxn]"),
 
1603
                     _("invalid output address radix '%c';\
 
1604
 it must be one character from [doxn]"),
1602
1605
                     optarg[0]);
1603
1606
              break;
1604
1607
            }