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

« back to all changes in this revision

Viewing changes to src/csplit.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
/* csplit - split a file into sections determined by context lines
2
 
   Copyright (C) 1991, 1995-2011 Free Software Foundation, Inc.
 
2
   Copyright (C) 1991-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
34
34
#include "stdio--.h"
35
35
#include "xstrtol.h"
36
36
 
37
 
/* The official name of this program (e.g., no `g' prefix).  */
 
37
/* The official name of this program (e.g., no 'g' prefix).  */
38
38
#define PROGRAM_NAME "csplit"
39
39
 
40
40
#define AUTHORS \
51
51
  uintmax_t lines_required;     /* Number of lines required. */
52
52
  uintmax_t repeat;             /* Repeat count. */
53
53
  int argnum;                   /* ARGV index. */
54
 
  bool repeat_forever;          /* True if `*' used as a repeat count. */
 
54
  bool repeat_forever;          /* True if '*' used as a repeat count. */
55
55
  bool ignore;                  /* If true, produce no output (for regexp). */
56
56
  bool regexpr;                 /* True if regular expression was used. */
57
57
  struct re_pattern_buffer re_compiled; /* Compiled regular expression. */
111
111
static void create_output_file (void);
112
112
static void delete_all_files (bool);
113
113
static void save_line_to_file (const struct cstring *line);
114
 
void usage (int status);
115
114
 
116
115
/* Start of buffer list. */
117
116
static struct buffer_record *head = NULL;
119
118
/* Partially read line. */
120
119
static char *hold_area = NULL;
121
120
 
122
 
/* Number of bytes in `hold_area'. */
 
121
/* Number of bytes in 'hold_area'. */
123
122
static size_t hold_count = 0;
124
123
 
125
124
/* Number of the last line in the buffers. */
171
170
   the input file. */
172
171
static struct control *controls;
173
172
 
174
 
/* Number of elements in `controls'. */
 
173
/* Number of elements in 'controls'. */
175
174
static size_t control_used;
176
175
 
177
176
/* The set of signals that are caught.  */
426
425
      free (l);
427
426
      l = n;
428
427
    }
 
428
  buf->line_start = NULL;
429
429
  free (buf->buffer);
430
430
  buf->buffer = NULL;
431
431
}
487
487
      bytes_avail = b->bytes_alloc; /* Size of buffer returned. */
488
488
      p = b->buffer;
489
489
 
490
 
      /* First check the `holding' area for a partial line. */
 
490
      /* First check the 'holding' area for a partial line. */
491
491
      if (hold_count)
492
492
        {
493
493
          memcpy (p, hold_area, hold_count);
500
500
      b->bytes_used += read_input (p, bytes_avail);
501
501
 
502
502
      lines_found = record_line_starts (b);
503
 
      if (!lines_found)
504
 
        free_buffer (b);
505
503
 
506
504
      if (lines_found || have_read_eof)
507
505
        break;
516
514
  if (lines_found)
517
515
    save_buffer (b);
518
516
  else
519
 
    free (b);
 
517
    {
 
518
      free_buffer (b);
 
519
      free (b);
 
520
    }
520
521
 
521
522
  return lines_found != 0;
522
523
}
1071
1072
 
1072
1073
  end = str + strlen (str) - 1;
1073
1074
  if (*end != '}')
1074
 
    error (EXIT_FAILURE, 0, _("%s: `}' is required in repeat count"), str);
 
1075
    error (EXIT_FAILURE, 0, _("%s: '}' is required in repeat count"), str);
1075
1076
  *end = '\0';
1076
1077
 
1077
1078
  if (str+1 == end-1 && *(str+1) == '*')
1081
1082
      if (xstrtoumax (str + 1, NULL, 10, &val, "") != LONGINT_OK)
1082
1083
        {
1083
1084
          error (EXIT_FAILURE, 0,
1084
 
                 _("%s}: integer required between `{' and `}'"),
 
1085
                 _("%s}: integer required between '{' and '}'"),
1085
1086
                 global_argv[argnum]);
1086
1087
        }
1087
1088
      p->repeat = val;
1108
1109
  closing_delim = strrchr (str + 1, delim);
1109
1110
  if (closing_delim == NULL)
1110
1111
    error (EXIT_FAILURE, 0,
1111
 
           _("%s: closing delimiter `%c' missing"), str, delim);
 
1112
           _("%s: closing delimiter '%c' missing"), str, delim);
1112
1113
 
1113
1114
  len = closing_delim - str - 1;
1114
1115
  p = new_control_record ();
1444
1445
usage (int status)
1445
1446
{
1446
1447
  if (status != EXIT_SUCCESS)
1447
 
    fprintf (stderr, _("Try `%s --help' for more information.\n"),
1448
 
             program_name);
 
1448
    emit_try_help ();
1449
1449
  else
1450
1450
    {
1451
1451
      printf (_("\
1453
1453
"),
1454
1454
              program_name);
1455
1455
      fputs (_("\
1456
 
Output pieces of FILE separated by PATTERN(s) to files `xx00', `xx01', ...,\n\
 
1456
Output pieces of FILE separated by PATTERN(s) to files 'xx00', 'xx01', ...,\n\
1457
1457
and output byte counts of each piece to standard output.\n\
1458
1458
\n\
1459
1459
"), stdout);
1462
1462
"), stdout);
1463
1463
      fputs (_("\
1464
1464
  -b, --suffix-format=FORMAT  use sprintf FORMAT instead of %02d\n\
1465
 
  -f, --prefix=PREFIX        use PREFIX instead of `xx'\n\
 
1465
  -f, --prefix=PREFIX        use PREFIX instead of 'xx'\n\
1466
1466
  -k, --keep-files           do not remove output files on errors\n\
1467
1467
"), stdout);
1468
1468
      fputs (_("\
1484
1484
  {INTEGER}          repeat the previous pattern specified number of times\n\
1485
1485
  {*}                repeat the previous pattern as many times as possible\n\
1486
1486
\n\
1487
 
A line OFFSET is a required `+' or `-' followed by a positive integer.\n\
 
1487
A line OFFSET is a required '+' or '-' followed by a positive integer.\n\
1488
1488
"), stdout);
1489
1489
      emit_ancillary_info ();
1490
1490
    }