~ubuntu-branches/ubuntu/intrepid/parted/intrepid

« back to all changes in this revision

Viewing changes to gnulib/lib/long-options.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2008-06-24 14:31:05 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080624143105-rd7yw67a9qnvh51i
Tags: 1.8.8.git.2008.03.24-7ubuntu1
* Resynchronise with Debian (LP: #237568). Remaining changes:
  - swap-uuid.dpatch: Create UUIDs on new swap partitions.
  - gptsync.dpatch: On Intel Mac systems, write a synced MBR rather than a
    protective MBR.
  - Add -fno-stack-protector on sparc.
  - sparc-new-label.dpatch: Fix sparc disk label generation. This is
    required for LDOM and parallel installations with Solaris 10.
  - loop-partitions.dpatch: Loop devices can only have one partition, so
    don't generate device names such as "/dev/loop0p1".
  - unpartitioned-disks.dpatch: Don't try to call BLKPG ioctls on
    unpartitionable disks (only implemented for loop devices at the
    moment), as they will always fail.
  - When building with gcc-4.3, add -Wno-array-bounds to CFLAGS.
  - Cell partition tables are misdetected as pc98, so disable pc98 support
    on powerpc.
  - array-bounds.dpatch: Backport patch from git to allow building with
    gcc-4.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Utility to accept --help and --version options as unobtrusively as possible.
 
2
 
 
3
   Copyright (C) 1993, 1994, 1998, 1999, 2000, 2002, 2003, 2004, 2005,
 
4
   2006 Free Software Foundation, Inc.
 
5
 
 
6
   This program is free software; you can redistribute it and/or modify
 
7
   it under the terms of the GNU General Public License as published by
 
8
   the Free Software Foundation; either version 2, or (at your option)
 
9
   any later version.
 
10
 
 
11
   This program is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
   GNU General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU General Public License
 
17
   along with this program; if not, write to the Free Software Foundation,
 
18
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
19
 
 
20
/* Written by Jim Meyering.  */
 
21
 
 
22
#include <config.h>
 
23
 
 
24
/* Specification.  */
 
25
#include "long-options.h"
 
26
 
 
27
#include <stdarg.h>
 
28
#include <stdio.h>
 
29
#include <stdlib.h>
 
30
#include <getopt.h>
 
31
 
 
32
#include "version-etc.h"
 
33
 
 
34
static struct option const long_options[] =
 
35
{
 
36
  {"help", no_argument, NULL, 'h'},
 
37
  {"version", no_argument, NULL, 'v'},
 
38
  {NULL, 0, NULL, 0}
 
39
};
 
40
 
 
41
/* Process long options --help and --version, but only if argc == 2.
 
42
   Be careful not to gobble up `--'.  */
 
43
 
 
44
void
 
45
parse_long_options (int argc,
 
46
                    char **argv,
 
47
                    const char *command_name,
 
48
                    const char *package,
 
49
                    const char *version,
 
50
                    void (*usage_func) (int),
 
51
                    /* const char *author1, ...*/ ...)
 
52
{
 
53
  int c;
 
54
  int saved_opterr;
 
55
 
 
56
  saved_opterr = opterr;
 
57
 
 
58
  /* Don't print an error message for unrecognized options.  */
 
59
  opterr = 0;
 
60
 
 
61
  if (argc == 2
 
62
      && (c = getopt_long (argc, argv, "+", long_options, NULL)) != -1)
 
63
    {
 
64
      switch (c)
 
65
        {
 
66
        case 'h':
 
67
          (*usage_func) (EXIT_SUCCESS);
 
68
 
 
69
        case 'v':
 
70
          {
 
71
            va_list authors;
 
72
            va_start (authors, usage_func);
 
73
            version_etc_va (stdout, command_name, package, version, authors);
 
74
            exit (0);
 
75
          }
 
76
 
 
77
        default:
 
78
          /* Don't process any other long-named options.  */
 
79
          break;
 
80
        }
 
81
    }
 
82
 
 
83
  /* Restore previous value.  */
 
84
  opterr = saved_opterr;
 
85
 
 
86
  /* Reset this to zero so that getopt internals get initialized from
 
87
     the probably-new parameters when/if getopt is called later.  */
 
88
  optind = 0;
 
89
}