From MAILER-DAEMON Sat Jul 02 14:33:34 2005 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Domo2-0002Bz-6z for mharc-bug-hello@gnu.org; Sat, 02 Jul 2005 14:33:34 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Domo1-0002Be-2U for bug-hello@gnu.org; Sat, 02 Jul 2005 14:33:33 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Domnz-0002BE-Ir for bug-hello@gnu.org; Sat, 02 Jul 2005 14:33:32 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Domjh-0001H2-BL for bug-hello@gnu.org; Sat, 02 Jul 2005 14:29:05 -0400 Received: from [216.17.153.58] (helo=joseki.proulx.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DomPn-0007Rq-Uk for bug-hello@gnu.org; Sat, 02 Jul 2005 14:08:32 -0400 Received: from dementia.proulx.com (dementia.proulx.com [192.168.1.115]) by joseki.proulx.com (Postfix) with ESMTP id 44F4E4B2ED for ; Sat, 2 Jul 2005 12:02:57 -0600 (MDT) Received: by dementia.proulx.com (Postfix, from userid 1000) id 3BBF3141E95; Sat, 2 Jul 2005 12:02:57 -0600 (MDT) Date: Sat, 2 Jul 2005 12:02:57 -0600 To: bug-hello@gnu.org Message-ID: <20050702180257.GA25389@dementia.proulx.com> Mail-Followup-To: bug-hello@gnu.org References: <200506292000.19746.bkorb@veritas.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200506292000.19746.bkorb@veritas.com> User-Agent: Mutt/1.5.9i From: bob@proulx.com (Bob Proulx) Subject: Re: [bug-hello] Does "Hello, world!" need a configuration file? X-BeenThere: bug-hello@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "GNU Hello bugs and discussion." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Jul 2005 18:33:33 -0000 Bruce Korb wrote: > The package that "works for me" can be found here: > > ftp://ftp.gnu.org/gnu/autogen/rel-5.7.1/libopts-25.1.0.tar.gz A minor typo: s/rel-5.7.1/rel5.7.1/ This one works: ftp://ftp.gnu.org/gnu/autogen/rel5.7.1/libopts-25.1.0.tar.gz ftp://ftp.gnu.org/gnu/autogen/rel5.7.1/libopts-25.1.0.tar.gz.sig Bob From MAILER-DAEMON Sat Jul 09 20:27:50 2005 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1DrPfi-0000qy-M4 for mharc-bug-hello@gnu.org; Sat, 09 Jul 2005 20:27:50 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DrPfM-0000fh-Ln for bug-hello@gnu.org; Sat, 09 Jul 2005 20:27:29 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DrPfH-0000c6-Mv for bug-hello@gnu.org; Sat, 09 Jul 2005 20:27:24 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DrPfF-0000TJ-0v for bug-hello@gnu.org; Sat, 09 Jul 2005 20:27:21 -0400 Received: from [209.61.216.22] (helo=f7.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DrPS8-00041F-Rv for bug-hello@gnu.org; Sat, 09 Jul 2005 20:13:49 -0400 X-Envelope-From: karl@freefriends.org X-Envelope-To: bug-hello@gnu.org Received: (from karl@localhost) by f7.net (8.11.7-20030920/8.11.7) id j6A06WR10246; Sat, 9 Jul 2005 20:06:32 -0400 Date: Sat, 9 Jul 2005 20:06:32 -0400 Message-Id: <200507100006.j6A06WR10246@f7.net> From: karl@freefriends.org (Karl Berry) To: bkorb@veritas.com In-Reply-To: <200506292000.19746.bkorb@veritas.com> Cc: bug-hello@gnu.org Subject: Re: [bug-hello] Does "Hello, world!" need a configuration file? X-BeenThere: bug-hello@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "GNU Hello bugs and discussion." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Jul 2005 00:27:48 -0000 Hi Bruce, configury magic needed to actually make it work. (details....;) It would be very helpful if you could make a stab at defining that configury magic :). At least, it's not immediately obvious to me where to start. Also, I'd like to request a simpler change. I don't see any purpose in allowing the options like --version and --help to be set in the configuration file. All that really needs to be allowed is a single setting in the config file, say "greeting", which overrides the "hello, world" text. Ok? On the other hand, I guess that might actually make it worse, since part of the point here is to reuse the longopts structure, right? I don't like duplicating that switch statement to handle all the options when they are not really useful. Hmm. I'm not sure what is best. I've added a --greeting (-g) option to allow it from the command line. Thanks, k From MAILER-DAEMON Sun Jul 10 08:51:23 2005 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1DrbHH-00080V-GL for mharc-bug-hello@gnu.org; Sun, 10 Jul 2005 08:51:23 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DrSta-00042I-NW for bug-hello@gnu.org; Sat, 09 Jul 2005 23:54:22 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DrStT-0003xA-O8 for bug-hello@gnu.org; Sat, 09 Jul 2005 23:54:19 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DrStO-0003k2-EG for bug-hello@gnu.org; Sat, 09 Jul 2005 23:54:10 -0400 Received: from [64.233.162.200] (helo=zproxy.gmail.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DrSyt-0004bd-Ti for bug-hello@gnu.org; Sat, 09 Jul 2005 23:59:52 -0400 Received: by zproxy.gmail.com with SMTP id x3so305394nzd for ; Sat, 09 Jul 2005 20:52:33 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:organization:to:subject:date:user-agent:cc:references:in-reply-to:mime-version:content-type:message-id:from; b=BrjSfDjLNQOzdPsp+menoxaZn364yUEO3h9RQaR8rgK1aeCzLZbtg8L2NIwEaJ9Rscz9UYwiiL4Jvhd2itI/V7tO1LT4JASXo3FEBl4Y/NQBqfmoXwcNZ8py1AIDIqjKQQZ2GoVE59+R6HQrbfises/cNqyF50qHvNo2xkJgpF8= Received: by 10.36.222.28 with SMTP id u28mr963800nzg; Sat, 09 Jul 2005 20:52:33 -0700 (PDT) Received: from mendocino.ejasent.com ([69.226.239.180]) by mx.gmail.com with ESMTP id 8sm1552102nzn.2005.07.09.20.52.32; Sat, 09 Jul 2005 20:52:33 -0700 (PDT) Organization: GNU To: Karl Berry Date: Sat, 9 Jul 2005 20:52:31 -0700 User-Agent: KMail/1.7.1 References: <200507100006.j6A06WR10246@f7.net> In-Reply-To: <200507100006.j6A06WR10246@f7.net> MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_/tJ0Cn5xh54oKJC" Message-Id: <200507092052.31518.bkorb@gnu.org> From: Bruce Korb X-Mailman-Approved-At: Sun, 10 Jul 2005 08:51:22 -0400 Cc: bug-hello@gnu.org, bkorb@veritas.com Subject: Re: [bug-hello] Does "Hello, world!" need a configuration file? X-BeenThere: bug-hello@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "GNU Hello bugs and discussion." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Jul 2005 03:54:44 -0000 --Boundary-00=_/tJ0Cn5xh54oKJC Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi Karl, On Saturday 09 July 2005 05:06 pm, Karl Berry wrote: > Hi Bruce, > > configury magic needed to actually make it work. (details....;) > > It would be very helpful if you could make a stab at defining that > configury magic :). At least, it's not immediately obvious to me where > to start. But I _hate_ autoconf. :-) Attached anyway. > Also, I'd like to request a simpler change. I don't see any purpose in > allowing the options like --version and --help to be set in the > configuration file. I don't either, but it was easier than worrying about it. The attached patch simply ignores them. With a little effort, it could not look for them, too, but I leave that as an exercise for the reader. :) > All that really needs to be allowed is a single > setting in the config file, say "greeting", which overrides the "hello, > world" text. Ok? How about, "greeting" overrides just the "hello" and not the "greeted" (world) part? > On the other hand, I guess that might actually make it worse, since part > of the point here is to reuse the longopts structure, right? Naw. I just needed to fix the loop-over-the-longopts thing to ignore -h and -v. > I don't > like duplicating that switch statement to handle all the options when > they are not really useful. Hmm. I'm not sure what is best. Two things: 1) this is only an example showing how it works. It is not meant to be saying, "you have to use your longopts list." You could, of course, set a counter to the value: (sizeof(longopts)/sizeof(longopts[0]))-2 and stop when it reaches zero. Do you want to bother? 2) You otta be using AutoOpts anyway. "help" and "version" are automatically supported and marked as not "presettable" viz. export AUTOGEN_HELP=yes will have no effect, though: export AUTOGEN_TIMEOUT=180 will work as expected. hello.c does not do environment variables (yet? ;) > I've added a --greeting (-g) option to allow it from the command line. I've tweaked it to only fiddle with the "hello" part and leave "world" alone. Cheers - Bruce --Boundary-00=_/tJ0Cn5xh54oKJC Content-Type: text/x-diff; charset="us-ascii"; name="hello.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="hello.diff" 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); } } --Boundary-00=_/tJ0Cn5xh54oKJC-- From MAILER-DAEMON Sun Jul 10 20:02:13 2005 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1DrlkS-0003FE-AO for mharc-bug-hello@gnu.org; Sun, 10 Jul 2005 20:02:12 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DrlkQ-0003E7-Dd for bug-hello@gnu.org; Sun, 10 Jul 2005 20:02:10 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DrlkN-0003Ci-TD for bug-hello@gnu.org; Sun, 10 Jul 2005 20:02:08 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Drlgu-00022Q-N6 for bug-hello@gnu.org; Sun, 10 Jul 2005 19:58:32 -0400 Received: from [209.61.216.22] (helo=f7.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DrlSy-0001L9-Ah for bug-hello@gnu.org; Sun, 10 Jul 2005 19:44:08 -0400 X-Envelope-From: karl@freefriends.org X-Envelope-To: bug-hello@gnu.org Received: (from karl@localhost) by f7.net (8.11.7-20030920/8.11.7) id j6ANacC07185; Sun, 10 Jul 2005 19:36:38 -0400 Date: Sun, 10 Jul 2005 19:36:38 -0400 Message-Id: <200507102336.j6ANacC07185@f7.net> From: karl@freefriends.org (Karl Berry) To: bruce.korb@gmail.com In-Reply-To: <200507092052.31518.bkorb@gnu.org> Cc: bug-hello@gnu.org, bkorb@veritas.com Subject: Re: [bug-hello] Does "Hello, world!" need a configuration file? X-BeenThere: bug-hello@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "GNU Hello bugs and discussion." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Jul 2005 00:02:11 -0000 not meant to be saying, "you have to use your longopts list." Ah. Yes, now I think I understand betterwhat's going on. But tell me again, just so I'm sure -- configFileLoad just parses whatever is there? You don't have to give it a description in advance? So if all we wanted to do was look for one option, we could just say tOptionValue *opt_p = optionGetValue(ov_p, "greeting"); and that's it? Thi But I _hate_ autoconf. :-) Attached anyway. Thanks. The test per se looks more or less ok, but we really need to encapsulate this in a macro. The point here is not that anyone cares about a config file for hello per se, but to provide an example of handling config files. We don't want to recommend that everyone dump 10 lines of shell code into their configure.ac's, that makes updating painful. I guess this means we should throw something about this into gnulib. But before I write that group, I see one problem: + LIBS="${LIBS} `autoopts-config ldflags`" Unfortunately, it's necessary to separate the loader flags (like -L/whatever, which get added to LDFLAGS) from the actual library calls (like -lautoopt, which get added to LIBS). I don't remember specifically why any more, but I know it's the case :(. I fear this means autoopts-config has to change ... (Also, CPPFLAGS should be used instead of CFLAGS, but that doesn't seem like a problem. CFLAGS is reserved for the user and should not contain any definitions which are required for building ... see the coding standards and autoconf.) What sorts of things do autoopts-config cflags and ldflags output? It's always the overhead stuff that's the killer ... Thanks, karl