Index: configure.ac =================================================================== RCS file: /cvsroot/hello/hello/configure.ac,v retrieving revision 1.5 diff -b -B -u -p -r1.5 configure.ac --- configure.ac 28 May 2005 22:19:27 -0000 1.5 +++ configure.ac 10 Jul 2005 03:36:46 -0000 @@ -44,10 +44,25 @@ AM_MISSING_PROG(HELP2MAN, help2man) dnl Checks for header files. AC_HEADER_STDC([]) -AC_CHECK_HEADERS([string.h fcntl.h sys/file.h sys/param.h]) +AC_CHECK_HEADERS([string.h fcntl.h sys/file.h sys/param.h autoopts/options.h]) dnl Checks for functions. AC_FUNC_ALLOCA + +[if test "X${ac_cv_header_autoopts_options_h}" == Xno +then + : +else + f=`autoopts-config cflags` 2>/dev/null + if test X"${f}" = X + then + : + else] + AC_DEFINE([HAVE_LIBOPTS],[1],[define if we can find libopts]) + [CFLAGS="${CFLAGS} ${f}" + LIBS="${LIBS} `autoopts-config ldflags`" + fi +fi] # i18n support from GNU gettext. AM_GNU_GETTEXT_VERSION([0.14.5]) Index: src/hello.c =================================================================== RCS file: /cvsroot/hello/hello/src/hello.c,v retrieving revision 1.7 diff -b -B -u -p -r1.7 hello.c --- src/hello.c 9 Jul 2005 23:23:23 -0000 1.7 +++ src/hello.c 10 Jul 2005 03:36:47 -0000 @@ -79,6 +79,10 @@ extern char *alloca (); #endif #include "system.h" +#ifdef HAVE_LIBOPTS +# include +#endif + struct option longopts[] = { { "greeting", required_argument, NULL, 'g' }, @@ -102,6 +106,7 @@ main (argc, argv) int optc; int h = 0, v = 0, t = 0, m = 0, n = 0, lose = 0, z = 0; char *greeting = NULL; + char *greeted = NULL; progname = argv[0]; @@ -116,6 +121,43 @@ main (argc, argv) textdomain (PACKAGE); #endif +#ifdef HAVE_LIBOPTS + { + const tOptionValue *ov_p = configFileLoad("hello.conf"); + + if (ov_p != NULL) { + struct option* lo_p = longopts; + while (lo_p->name != NULL) { + tOptionValue *opt_p = optionGetValue(ov_p, lo_p->name); + if (opt_p != NULL) switch (lo_p->val) { + { + case 'v': + case 'h': + break; + case 'g': + if (opt_p->valType != OPARG_TYPE_STRING) + continue; + greeting = strdup(opt_p->v.strVal); + break; + case 'm': + m = 2; + break; + case 'n': + n = 2; + break; + case 't': + t = 2; + break; + } + } + lo_p++; + } + + optionUnloadNested(ov_p); + } + } +#endif + while ((optc = getopt_long (argc, argv, "g:hmntv", longopts, (int *) 0)) != EOF) switch (optc) @@ -130,12 +172,14 @@ main (argc, argv) h = 1; break; case 'm': + if (t == 2) t = 0; m = 1; break; case 'n': n = 1; break; case 't': + if (m == 2) m = 0; t = 1; break; default: @@ -212,11 +256,29 @@ For more information about these matters "2005", PACKAGE); exit (0); } - if (m && t) + if (m && t) do + { +#ifdef HAVE_LIBOPTS + /* If the conflict is due to presetting, then override the preset + * by the command line setting. */ + if (m == 2) + { + if (t != 2) + { + m = 0; + break; + } + } + else if (t == 2) { + t = 0; + break; + } +#endif fprintf (stderr, _("%s: Incompatible flags: -m and -t\n"), progname); exit (1); } + while (0); if (m) { @@ -333,9 +395,10 @@ For more information about these matters ")); else { + char* fmt = _("%s, world!\n"); if (!greeting) - greeting = _("Hello, world!"); - puts (greeting); + greeting = _("Hello"); + printf (fmt, greeting); } }