有没有“你好,世界”?类似于 GNU 的库示例项目?

发布于 2024-10-02 09:55:53 字数 1539 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月下凄凉 2024-10-09 09:55:53

创建了一个名为 libabc: 共享库骨架 的项目作者:伦纳特·珀特林:

为了让事情变得简单,我们整理了一个名为 libabc 的示例框架库,其自述文件以简洁的形式包含了我们的所有要点。

http://0pointer.de/blog/projects/libabc.html

There is a project called libabc: shared library skeleton created by Lennart Poettering:

To make things easy we have put together an example skeleton library we dubbed libabc, whose README file includes all our points in terse form.

http://0pointer.de/blog/projects/libabc.html

海之角 2024-10-09 09:55:53

以下是我经常提出的一些准则。我不完全确定它们会有多大帮助:

http://en.wikipedia.org/wiki/ Indent_style

http://www.python.org/dev/peps/pep -0007/

否则,我只是尝试匹配我所看到的。查看上面的样式指南应该可以让您很好地了解在代码中要寻找并尝试匹配的一致性。

编辑:

我应该澄清一下,上述指南并非特定于 GNU,但可能会帮助您找到一致性,例如命名方案或制表符/间距指南。

The following are some guidelines that I regularly bring up. I'm not entirely sure how helpful they'll be:

http://en.wikipedia.org/wiki/Indent_style

http://www.python.org/dev/peps/pep-0007/

Otherwise, I just try to match what I see. Looking at the above style guides should give you a good indication of what consistencies to look for and attempt to match in your code.

Edit:

I should clarify, the above guides are not specific to GNU, but might help you find consistencies such as naming schemes or tab/spacing guides.

冷…雨湿花 2024-10-09 09:55:53

我通读了 GNU 手册,找到了一个简短的示例,我认为它可以让您有一个良好的开端:

直接来自手册:

/* hello.c -- print a greeting message and exit.

    Copyright (C) 1992, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
    2005, 2006, 2007 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 3, 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/full 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"),
                program_name);
       exit (EXIT_FAILURE);
     }

   /* Print greeting message and exit. */
   if (t)
     printf (_("hello, world\n"));

   else if (n)
     /* TRANSLATORS: Use box drawing characters or other fancy stuff
        if your encoding (e.g., UTF-8) allows it.  If done so add the
        following note, please:

        [Note: For best viewing results use a UTF-8 locale, please.]
     */
    printf (_("\
 +---------------+\n\
 | Hello, world! |\n\
 +---------------+\n\
 "));

   else
     {
       if (!greeting)
         greeting = _("Hello, world!");
       puts (greeting);
     }

   exit (EXIT_SUCCESS);
 }


 
 /* Print help info.  This long message is split into
    several pieces to help translators be able to align different
    blocks and identify the various pieces.  */

 static void
 print_help (void)
 {
   /* TRANSLATORS: --help output 1 (synopsis)
      no-wrap */
         printf (_("\
 Usage: %s [OPTION]...\n"), program_name);

   /* TRANSLATORS: --help output 2 (brief description)
      no-wrap */
   fputs (_("\
 Print a friendly, customizable greeting.\n"), stdout);

   puts ("");
   /* TRANSLATORS: --help output 3: options 1/2
      no-wrap */
   fputs (_("\
   -h, --help          display this help and exit\n\
   -v, --version       display version information and exit\n"), stdout);

   puts ("");
   /* TRANSLATORS: --help output 4: options 2/2
      no-wrap */
   fputs (_("\
   -t, --traditional       use traditional greeting format\n\
   -n, --next-generation   use next-generation greeting format\n\
   -g, --greeting=TEXT     use TEXT as the greeting message\n"), stdout);

   printf ("\n");
   /* TRANSLATORS: --help output 5 (end)
      TRANSLATORS: the placeholder indicates the bug-reporting address
      for this application.  Please add _another line_ with the
      address for translation bugs.
      no-wrap */
   printf (_("\
 Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
 }


 
 /* Print version and copyright information.  */

 static void
 print_version (void)
 {
   printf ("hello (GNU %s) %s\n", PACKAGE, VERSION);
   /* xgettext: no-wrap */
   puts ("");

   /* It is important to separate the year from the rest of the message,
      as done here, to avoid having to retranslate the message when a new
      year comes around.  */
   printf (_("\
 Copyright (C) %s Free Software Foundation, Inc.\n\
 License GPLv3+: GNU GPL version 3 or later\
 <http://gnu.org/licenses/gpl.html>\n\
 This is free software: you are free to change and redistribute it.\n\
 There is NO WARRANTY, to the extent permitted by law.\n"),
               "2007");
 }

I read through the GNU manual and found a short example that I think would get you to a good start:

Straight from the manual:

/* hello.c -- print a greeting message and exit.

    Copyright (C) 1992, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
    2005, 2006, 2007 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 3, 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/full 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"),
                program_name);
       exit (EXIT_FAILURE);
     }

   /* Print greeting message and exit. */
   if (t)
     printf (_("hello, world\n"));

   else if (n)
     /* TRANSLATORS: Use box drawing characters or other fancy stuff
        if your encoding (e.g., UTF-8) allows it.  If done so add the
        following note, please:

        [Note: For best viewing results use a UTF-8 locale, please.]
     */
    printf (_("\
 +---------------+\n\
 | Hello, world! |\n\
 +---------------+\n\
 "));

   else
     {
       if (!greeting)
         greeting = _("Hello, world!");
       puts (greeting);
     }

   exit (EXIT_SUCCESS);
 }


 
 /* Print help info.  This long message is split into
    several pieces to help translators be able to align different
    blocks and identify the various pieces.  */

 static void
 print_help (void)
 {
   /* TRANSLATORS: --help output 1 (synopsis)
      no-wrap */
         printf (_("\
 Usage: %s [OPTION]...\n"), program_name);

   /* TRANSLATORS: --help output 2 (brief description)
      no-wrap */
   fputs (_("\
 Print a friendly, customizable greeting.\n"), stdout);

   puts ("");
   /* TRANSLATORS: --help output 3: options 1/2
      no-wrap */
   fputs (_("\
   -h, --help          display this help and exit\n\
   -v, --version       display version information and exit\n"), stdout);

   puts ("");
   /* TRANSLATORS: --help output 4: options 2/2
      no-wrap */
   fputs (_("\
   -t, --traditional       use traditional greeting format\n\
   -n, --next-generation   use next-generation greeting format\n\
   -g, --greeting=TEXT     use TEXT as the greeting message\n"), stdout);

   printf ("\n");
   /* TRANSLATORS: --help output 5 (end)
      TRANSLATORS: the placeholder indicates the bug-reporting address
      for this application.  Please add _another line_ with the
      address for translation bugs.
      no-wrap */
   printf (_("\
 Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
 }


 
 /* Print version and copyright information.  */

 static void
 print_version (void)
 {
   printf ("hello (GNU %s) %s\n", PACKAGE, VERSION);
   /* xgettext: no-wrap */
   puts ("");

   /* It is important to separate the year from the rest of the message,
      as done here, to avoid having to retranslate the message when a new
      year comes around.  */
   printf (_("\
 Copyright (C) %s Free Software Foundation, Inc.\n\
 License GPLv3+: GNU GPL version 3 or later\
 <http://gnu.org/licenses/gpl.html>\n\
 This is free software: you are free to change and redistribute it.\n\
 There is NO WARRANTY, to the extent permitted by law.\n"),
               "2007");
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文