日期:2014-05-16  浏览次数:20646 次

看看大家linux的能力!
/*下面给出的代码是GNU写的hello的小程序!看看那位高手能把它编译并运行!
当然最好给出详细的过程!能把hello写到如此份上,真是学到了很多!
*/
/* hello.c -- print a greeting message and exit.

  Copyright (C) 1992, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
  2005, 2006 Free Software Foundation, Inc.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2, or (at your option)
  any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software Foundation,
  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */

#include <config.h>
#include "system.h"

/* String containing name the program is called with. */
const char *program_name;

static const struct option longopts[] =
{
  { "greeting", required_argument, NULL, 'g' },
  { "help", no_argument, NULL, 'h' },
  { "next-generation", no_argument, NULL, 'n' },
  { "traditional", no_argument, NULL, 't' },
  { "version", no_argument, NULL, 'v' },
  { NULL, 0, NULL, 0 }
};

static void print_help (void);
static void print_version (void);

int
main (int argc, char *argv[])
{
  int optc;
  int t = 0, n = 0, lose = 0;
  const char *greeting = NULL;

  program_name = argv[0];

  /* Set locale via LC_ALL. */
  setlocale (LC_ALL, "";

#if ENABLE_NLS
  /* Set the text message domain. */
  bindtextdomain (PACKAGE, LOCALEDIR);
  textdomain (PACKAGE);
#endif

  /* Even exiting has subtleties. The /dev/full device on GNU/Linux
  can be used for testing whether writes are checked properly. For
  instance, hello >/dev/null should exit unsuccessfully. On exit,
  if any writes failed, change the exit status. This is
  implemented in the Gnulib module "closeout". */
  atexit (close_stdout);

  while ((optc = getopt_long (argc, argv, "g:hntv", longopts, NULL)) != -1)
  switch (optc)
  {
  /* One goal here is having --help and --version exit immediately,
  per GNU coding standards. */
  case 'v':
  print_version ();
  exit (EXIT_SUCCESS);
  break;
  case 'g':
  greeting = optarg;
  break;
  case 'h':
  print_help ();
  exit (EXIT_SUCCESS);
  break;
  case 'n':
  n = 1;
  break;
  case 't':
  t = 1;
  break;
  default:
  lose = 1;
  break;
  }

  if (lose || optind < argc)
  {
  /* Print error message and exit. */
  if (optind < argc)
  fprintf (stderr, _("%s: extra operand: %s\n",
  program_name, argv[optind]);
  fprintf (stderr, _("Try `%s --help' for more information.\n",