~ubuntu-branches/ubuntu/maverick/hello/maverick

« back to all changes in this revision

Viewing changes to src/hello.c

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2009-08-03 23:34:18 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090803233418-e1zshrjd3oqhmrrb
Tags: 2.4-1
* New upstream release. License is now GPLv3 or later.
* Manual is included again, as it's now GFDL without invariant sections.
* Clarified manual: If more than one of the greeting options is specified
  (`-g', `-n', `-t', and their long-named equivalents), whichever comes
  last takes precedence. Closes: #457941.
* Don't pass -isp to dpkg-gencontrol, as it's deprecated. Closes: #508833.
* Changed source URL in copyright file to use http, not ftp.
* Standards-Version: 3.8.2 (no changes for this).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* hello.c -- print a greeting message and exit.
2
2
 
3
 
   Copyright (C) 1992, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
4
 
   2005, 2006 Free Software Foundation, Inc.
 
3
   Copyright 1992, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2005,
 
4
   2006, 2007, 2008 Free Software Foundation, Inc.
5
5
 
6
 
   This program is free software; you can redistribute it and/or modify
 
6
   This program is free software: you can redistribute it and/or modify
7
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.
 
8
   the Free Software Foundation, either version 3 of the License, or
 
9
   (at your option) any later version.
10
10
 
11
11
   This program is distributed in the hope that it will be useful,
12
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
14
   GNU General Public License for more details.
15
15
 
16
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.  */
 
17
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
18
 
20
19
#include <config.h>
21
20
#include "system.h"
33
32
  { NULL, 0, NULL, 0 }
34
33
};
35
34
 
 
35
/* Different types of greetings; only one per invocation.  */
 
36
typedef enum {
 
37
  greet_gnu, greet_new, greet_traditional, greet_user
 
38
} greeting_type;
 
39
 
 
40
/* Forward declarations.  */
36
41
static void print_help (void);
37
42
static void print_version (void);
38
43
 
40
45
main (int argc, char *argv[])
41
46
{
42
47
  int optc;
43
 
  int t = 0, n = 0, lose = 0;
44
 
  const char *greeting = NULL;
 
48
  int lose = 0;
 
49
  const char *greeting_msg = NULL;
 
50
  greeting_type g = greet_gnu;
45
51
 
46
52
  program_name = argv[0];
47
53
 
54
60
  textdomain (PACKAGE);
55
61
#endif
56
62
 
57
 
  /* Even exiting has subtleties.  The /dev/full device on GNU/Linux
58
 
     can be used for testing whether writes are checked properly.  For
59
 
     instance, hello >/dev/null should exit unsuccessfully.  On exit,
60
 
     if any writes failed, change the exit status.  This is
61
 
     implemented in the Gnulib module "closeout".  */
 
63
  /* Even exiting has subtleties.  On exit, if any writes failed, change
 
64
     the exit status.  The /dev/full device on GNU/Linux can be used for
 
65
     testing; for instance, hello >/dev/full should exit unsuccessfully.
 
66
     This is implemented in the Gnulib module "closeout".  */
62
67
  atexit (close_stdout);
63
68
 
64
69
  while ((optc = getopt_long (argc, argv, "g:hntv", longopts, NULL)) != -1)
65
70
    switch (optc)
66
71
      {
67
 
      /* One goal here is having --help and --version exit immediately,
68
 
         per GNU coding standards.  */
 
72
      /* --help and --version exit immediately, per GNU coding standards.  */
69
73
      case 'v':
70
74
        print_version ();
71
75
        exit (EXIT_SUCCESS);
72
76
        break;
73
77
      case 'g':
74
 
        greeting = optarg;
 
78
        greeting_msg = optarg;
 
79
        g = greet_user;
75
80
        break;
76
81
      case 'h':
77
82
        print_help ();
78
83
        exit (EXIT_SUCCESS);
79
84
        break;
80
85
      case 'n':
81
 
        n = 1;
 
86
        g = greet_new;
82
87
        break;
83
88
      case 't':
84
 
        t = 1;
 
89
        g = greet_traditional;
85
90
        break;
86
91
      default:
87
92
        lose = 1;
100
105
    }
101
106
 
102
107
  /* Print greeting message and exit. */
103
 
  if (t)
 
108
  if (g == greet_traditional)
104
109
    printf (_("hello, world\n"));
105
110
 
106
 
  else if (n)
 
111
  else if (g == greet_new)
107
112
    /* TRANSLATORS: Use box drawing characters or other fancy stuff
108
113
       if your encoding (e.g., UTF-8) allows it.  If done so add the
109
114
       following note, please:
116
121
+---------------+\n\
117
122
"));
118
123
 
119
 
  else
120
 
    {
121
 
      if (!greeting)
122
 
        greeting = _("Hello, world!");
123
 
      puts (greeting);
124
 
    }
 
124
  else if (g == greet_user)
 
125
    puts (greeting_msg);
 
126
 
 
127
  else if (g == greet_gnu)
 
128
    puts (_("Hello, world!"));
125
129
  
 
130
  else {
 
131
    /* No need for this impossible message to be translated.  */
 
132
    fprintf (stderr, "Impossible hello value %d\n", g);
 
133
    exit (EXIT_FAILURE);
 
134
  }
 
135
 
126
136
  exit (EXIT_SUCCESS);
127
137
}
128
138
 
186
196
     year comes around.  */
187
197
  printf (_("\
188
198
Copyright (C) %s Free Software Foundation, Inc.\n\
189
 
License: GNU GPL v2+ <http://www.gnu.org/licenses/gpl.html>\n\
190
 
This is free software.  There is NO WARRANTY, to the extent permitted by law.\n"),
191
 
              "2006");
 
199
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n\
 
200
This is free software: you are free to change and redistribute it.\n\
 
201
There is NO WARRANTY, to the extent permitted by law.\n"),
 
202
              "2008");
192
203
}