/[coreutils]/coreutils/src/head.c
ViewVC logotype

Diff of /coreutils/src/head.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.68 by meyering, Sat Dec 1 17:41:25 2001 UTC revision 1.69 by meyering, Sat Feb 2 08:10:04 2002 UTC
# Line 1  Line 1 
1  /* head -- output first part of file(s)  /* head -- output first part of file(s)
2     Copyright (C) 89, 90, 91, 1995-2001 Free Software Foundation, Inc.     Copyright (C) 89, 90, 91, 1995-2002 Free Software Foundation, Inc.
3    
4     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# Line 55  enum header_mode Line 55  enum header_mode
55    multiple_files, always, never    multiple_files, always, never
56  };  };
57    
58    /* Options corresponding to header_mode values.  */
59    static char const header_mode_option[][4] = { "", " -v", " -q" };
60    
61  /* The name this program was run with. */  /* The name this program was run with. */
62  char *program_name;  char *program_name;
63    
# Line 107  Mandatory arguments to long options are Line 110  Mandatory arguments to long options are
110        fputs (_("\        fputs (_("\
111  \n\  \n\
112  SIZE may have a multiplier suffix: b for 512, k for 1K, m for 1 Meg.\n\  SIZE may have a multiplier suffix: b for 512, k for 1K, m for 1 Meg.\n\
113  If -VALUE is used as first OPTION, read -c VALUE when one of\n\  "), stdout);
114  multipliers bkm follows concatenated, else read -n VALUE.\n\        if (POSIX2_VERSION < 200112)
115            fputs (_("\
116    \n\
117    (obsolete)  If -VALUE is used as first OPTION, same as -c VALUE when one of\n\
118    multipliers bkm follows concatenated, else same as -n VALUE.\n\
119  "), stdout);  "), stdout);
120        puts (_("\nReport bugs to <bug-textutils@gnu.org>."));        puts (_("\nReport bugs to <bug-textutils@gnu.org>."));
121      }      }
# Line 257  main (int argc, char **argv) Line 264  main (int argc, char **argv)
264  {  {
265    enum header_mode header_mode = multiple_files;    enum header_mode header_mode = multiple_files;
266    int exit_status = 0;    int exit_status = 0;
   char *n_string;  
267    int c;    int c;
268    
269    /* Number of items to print. */    /* Number of items to print. */
# Line 278  main (int argc, char **argv) Line 284  main (int argc, char **argv)
284    
285    print_headers = 0;    print_headers = 0;
286    
287    if (argc > 1 && argv[1][0] == '-' && ISDIGIT (argv[1][1]))    if (POSIX2_VERSION < 200112
288          && 1 < argc && argv[1][0] == '-' && ISDIGIT (argv[1][1]))
289      {      {
290          char *a = argv[1];
291          char *n_string = ++a;
292        char *end_n_string;        char *end_n_string;
293        char multiplier_char = 0;        char multiplier_char = 0;
294    
       n_string = &argv[1][1];  
   
295        /* Old option syntax; a dash, one or more digits, and one or        /* Old option syntax; a dash, one or more digits, and one or
296           more option letters.  Move past the number. */           more option letters.  Move past the number. */
297        for (++argv[1]; ISDIGIT (*argv[1]); ++argv[1])        do ++a;
298          {        while (ISDIGIT (*a));
           /* empty */  
         }  
299    
300        /* Pointer to the byte after the last digit.  */        /* Pointer to the byte after the last digit.  */
301        end_n_string = argv[1];        end_n_string = a;
302    
303        /* Parse any appended option letters. */        /* Parse any appended option letters. */
304        while (*argv[1])        for (; *a; a++)
305          {          {
306            switch (*argv[1])            switch (*a)
307              {              {
308              case 'c':              case 'c':
309                count_lines = 0;                count_lines = 0;
# Line 309  main (int argc, char **argv) Line 314  main (int argc, char **argv)
314              case 'k':              case 'k':
315              case 'm':              case 'm':
316                count_lines = 0;                count_lines = 0;
317                multiplier_char = *argv[1];                multiplier_char = *a;
318                break;                break;
319    
320              case 'l':              case 'l':
# Line 325  main (int argc, char **argv) Line 330  main (int argc, char **argv)
330                break;                break;
331    
332              default:              default:
333                error (0, 0, _("unrecognized option `-%c'"), *argv[1]);                error (0, 0, _("unrecognized option `-%c'"), *a);
334                usage (1);                usage (1);
335              }              }
           ++argv[1];  
336          }          }
337    
338          if (OBSOLETE_OPTION_WARNINGS && ! getenv ("POSIXLY_CORRECT"))
339            error (0, 0,
340                   _("warning: `head -%s' is obsolete; use `head -%c %.*s%.*s%s'"),
341                   n_string, count_lines ? 'n' : 'c',
342                   (int) (end_n_string - n_string), n_string,
343                   multiplier_char != 0, &multiplier_char,
344                   header_mode_option[header_mode]);
345    
346        /* Append the multiplier character (if any) onto the end of        /* Append the multiplier character (if any) onto the end of
347           the digit string.  Then add NUL byte if necessary.  */           the digit string.  Then add NUL byte if necessary.  */
348        *end_n_string = multiplier_char;        *end_n_string = multiplier_char;

Legend:
Removed from v.1.68  
changed lines
  Added in v.1.69

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26