O Plameras was once rumoured to have said:
> 
> This is a different code.
> 
> I'd do it differently. But for another time.

So would I.  If I was trying to implement the original arrangement
properly, I'd probably do it something like this...

---BEGIN---
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <libintl.h>

#define _(x) gettext(x)
#define VERSION "0.1"

void
somefunction(char *strout, int n)
{
        strncpy(strout, _("some words"), n);
        strout[n-1]='\0';
}

void
usage(int argc, char *argv[])
{
        fprintf(stderr,_("%s: do stuff\n\n"), argv[0]);
        fprintf(stderr,_("usage:\n  %s [<flags>]\n\n"), argv[0]);
        fprintf(stderr,_("valid flags:\n"));
        fprintf(stderr,_("  -h, --help      display this message\n"));
        fprintf(stderr,_("  -v, --version   display the version number\n"));
        exit(1);
}

void
version(int argc, char *argv[])
{
        fprintf(stderr, _("%s: version %s\n"), argv[0], VERSION);
        exit(1);
}

static struct option opts[] = {
        {"help", no_argument, NULL, 'h'},
        {"version", no_argument, NULL, 'v'},
        {NULL, 0, NULL, 0}
};

#ifndef BUF
#define BUF     256
#endif

int
main (int argc, char *argv[])
{
        char    string[BUF];
        int     c;

        while (-1 != (c = getopt_long(argc, argv, "hv", opts, NULL))) {
                switch (c) {
                case 'v':
                        version (argc, argv);
                        break;
                case 'h':
                        usage (argc, argv);
                        break;
                default:
                        break;
                }
        }

        somefunction(string, BUF);

        printf (_("\n\nString is: %s\n\n"), string);

        return 0;
}
---END---

Thus keeping the i18n and GNU people happy too!

C.
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to