Re: on the awk(1)/nawk(1) usage synopsis
On Mon, Jan 29, 2007 at 07:37:04PM +0100, Igor Sobrado wrote: As a second change, I would suggest changing the usage message in the binary to fit on a standard 80 columns display. In short, I propose: - synchronizing the usage message returned by awk(1) and the synopsis in the manual page. done - splitting the usage message in two lines to fit on standard displays. done - put the options that do not require arguments before the options that require arguments. hmm, this was done anyway. the usage for awk is not totally lovely, so there is some mess, but it's more or less the form of all usage(). - optionally, remove the code that announces that -mr and -mf are obsolete options and, as a consequence, ignored. The standard message returned by awk(1) for non-existent options provides ALL information required. For example: $ awk -g awk: unknown option -g ignored awk: no program given From this message it is clear that -g is ignored because it is an unknown option. feel free to send a diff for this. jmc
Re: on the awk(1)/nawk(1) usage synopsis
Looking carefully at the switch () {...} structure in main.c it seems that the option -f requires an argument: iff the argument to -f is optional I would write: awk [-sae] [-V] [-d[n]] [-F fs] [-v var=value] [prog | -f [progfile]] file ... But it does not look as an optional argument, the case block for -f decrements the argument counter and increments the argument vector. I think that the synopsis for awk(1) should be awk [-sae] [-V] [-d[n]] [-F fs] [-v var=value] [prog | -f progfile] file ... instead. Am I wrong? I will be glad to provide a patch for this small bug. Just awaiting for some feedback. Igor.
Re: on the awk(1)/nawk(1) usage synopsis
Jason, you are very fast! I will download the new main.c as soon as I arrive at home and remove the case for the -m option. I will remove the f option in [-safe] as it seems that the argument to it is not optional. I will submit the patch, based on the updated code, later. Two changes: - remove the f option in -safe as it cannot be used without an argument. (it cannot be used without an argument, am I wrong?) - remove the case for -m as it is nicely handled by the default case. If you agree I will send a patch to Brian Kernighan, but it is perhaps better sending it by official channels (i.e. by you). Cheers, Igor.
Re: on the awk(1)/nawk(1) usage synopsis
On Mon, Jan 29, 2007 at 09:11:26PM +0100, Igor Sobrado wrote: Looking carefully at the switch () {...} structure in main.c it seems that the option -f requires an argument: iff the argument to -f is optional I would write: awk [-sae] [-V] [-d[n]] [-F fs] [-v var=value] [prog | -f [progfile]] file ... But it does not look as an optional argument, the case block for -f decrements the argument counter and increments the argument vector. I think that the synopsis for awk(1) should be awk [-sae] [-V] [-d[n]] [-F fs] [-v var=value] [prog | -f progfile] file ... instead. Am I wrong? I will be glad to provide a patch for this small bug. Just awaiting for some feedback. currently we have: awk [-safe] [-V] [-d[n]] [-F fs] [-v var=value] [prog | -f progfile] file ... nawk ... which seems to be what you are requesting. am i missing something here? jmc
Re: on the awk(1)/nawk(1) usage synopsis
Hi Jason. Thank you very much for managing these small bugs so fast. The first patch is for main.c: --- main.c Mon Jan 29 15:01:20 2007 +++ main.c Mon Jan 29 15:04:28 2007 @@ -63,8 +63,8 @@ setlocale(LC_NUMERIC, C); /* for parsing cmdline prog */ cmdname = __progname; if (argc == 1) { - fprintf(stderr, usage: %s [-safe] [-V] [-d[n]] [-F fs] - [-v var=value] [prog | -f progfile]\n\tfile ...\n, + fprintf(stderr, usage: %s [-sae] [-V] [-d[n]] [-F fs] + [-v var=value] [prog | -f progfile]\n\t file ...\n, cmdname); exit(1); } @@ -110,10 +110,6 @@ case 'v': /* -v a=1 to be done NOW. one -v for each */ if (argv[1][2] == '\0' --argc 1 isclvar((++argv)[1])) setclvar(argv[1]); - break; - case 'm': /* more memory: -mr=record, -mf=fields */ - /* no longer supported */ - WARNING(obsolete option %s ignored, argv[1]); break; case 'd': dbg = atoi(argv[1][2]); Changes introduced by this patch: - adds three spaces after the tab character to improve readability of the usage message. - removes the f option in -safe, it seems that the argument to -f is not optional. - removes the case for m, that is now managed by the default case: # awk -mr awk: unknown option -mr ignored awk: no program given The second one fixes the man page for awk.1: --- awk.1 Mon Jan 29 15:01:15 2007 +++ awk.1 Mon Jan 29 15:01:30 2007 @@ -31,7 +31,7 @@ .Nd pattern-directed scanning and processing language .Sh SYNOPSIS .Nm awk -.Op Fl safe +.Op Fl sae .Op Fl V .Op Fl d Ns Op Ar n .Op Fl F Ar fs By the way, thank you very much for changing the filename argument of -f to progfile. A good change! Igor.
Re: on the awk(1)/nawk(1) usage synopsis
Hi Jason. Sorry for sending the patches before answering to your email. As I am not subscribed to this mailing list I have not read your answer before working on the patches. I think that the -f option requires an argument. The argument is not optional, though. It seems that the case block that manages this option requires an argument. If the argument to -f is optional it can be written as [prog | -f [progfile]] but I believe that it is not optional, but required. In any case, the f option in -safe seems superfluous. The patches submitted remove the f option in the block of options without argument -s, -a, -f, -e in both main.c and the manual page for awk(1). Hope you will like this change too. Feel free to change the patch if you do not like it; I believe that removing the f option on -safe is good, but I can be wrong. Best wishes, Igor.
Re: on the awk(1)/nawk(1) usage synopsis
On Mon, Jan 29, 2007 at 10:16:55PM +0100, Igor Sobrado wrote: I think that the -f option requires an argument. The argument is not optional, though. It seems that the case block that manages this option requires an argument. If the argument to -f is optional it can be written as [prog | -f [progfile]] but I believe that it is not optional, but required. In any case, the f option in -safe seems superfluous. The patches submitted remove the f option in the block of options without argument -s, -a, -f, -e in both main.c and the manual page for awk(1). Hope you will like this change too. Feel free to change the patch if you do not like it; I believe that removing the f option on -safe is good, but I can be wrong. Best wishes, Igor. ah, ok. it is not 4 options (-s, -a, -f, and -e), but one (-safe, as in not in danger). that's why it is described as a ...first (and not very reliable) approximation to a ``safe'' version of awk. you are confusing that with the -f option, which does require an argument: [prog | -f progfile] hence: [-safe] [-V] and not the more usual: [-safeV] hope that's clear ;) jmc
Re: on the awk(1)/nawk(1) usage synopsis
On Mon, Jan 29, 2007 at 10:00:51PM +0100, Igor Sobrado wrote: Changes introduced by this patch: - adds three spaces after the tab character to improve readability of the usage message. i prefer just to use a single tab to start a new line. otherwise we end up with lots of usage() functions containing mad amounts of tabs and spaces, potentially in need of adjustment when things change. - removes the f option in -safe, it seems that the argument to -f is not optional. see my last mail about that. - removes the case for m, that is now managed by the default case: # awk -mr awk: unknown option -mr ignored awk: no program given hmm, i don;t see the harm of flagging these as obsoleted...the output is very similar whatever way you do it, and at least this way people used to the old behaviour get a little more warning. additionally i confess to a little mix up ;) i totally forgot that awk is maintained 3rd party when i made my changes. tut tut. in general it is better if we send fixes upstream and later import them. sometimes we keep local changes, but generally it is desirable to minimise those. jmc
Re: on the awk(1)/nawk(1) usage synopsis
In a private email, Philip Guenther has observed that awk does not completely folow the POSIX option guidelines. [-safe] is not [-s,-a,-f,-e] but a single option! The right patch is then: --- main.c.orig Mon Jan 29 15:01:20 2007 +++ main.c Mon Jan 29 15:52:47 2007 @@ -64,7 +64,7 @@ cmdname = __progname; if (argc == 1) { fprintf(stderr, usage: %s [-safe] [-V] [-d[n]] [-F fs] - [-v var=value] [prog | -f progfile]\n\tfile ...\n, + [-v var=value] [prog | -f progfile]\n\t file ...\n, cmdname); exit(1); } @@ -110,10 +110,6 @@ case 'v': /* -v a=1 to be done NOW. one -v for each */ if (argv[1][2] == '\0' --argc 1 isclvar((++argv)[1])) setclvar(argv[1]); - break; - case 'm': /* more memory: -mr=record, -mf=fields */ - /* no longer supported */ - WARNING(obsolete option %s ignored, argv[1]); break; case 'd': dbg = atoi(argv[1][2]); The patch for awk.1 is obviously not required then. I really appreciate the feedback of Philip Guenther. I was obviously wrong. Jason: can you, please, apply the right patch? I am sorry for the mistake, I should have read the man page carefully... I am just not accustomed to multicharacter options in Unix. Igor.
Re: on the awk(1)/nawk(1) usage synopsis
On Mon, Jan 29, 2007, Jason McIntyre wrote: ah, ok. it is not 4 options (-s, -a, -f, and -e), but one (-safe, as in not in danger). that's why it is described as a ...first (and not very reliable) approximation to a ``safe'' version of awk. you are confusing that with the -f option, which does require an argument: [prog | -f progfile] hence: [-safe] [-V] and not the more usual: [-safeV] hope that's clear ;) Hi again, Jason. Indeed, both Philip and you are right. I was expecting -safe to be four options instead of one. Indeed, the fifth one -V should then be added to the other options, but it is on a different block. A very good point! I am accustomed to single character options in Unix (perhaps this four character option is the reason main.c is not using getopt(3)). As the loop that manages the options passed to awk(1) has cases for both s and f I supposed -safe were four options, as POSIX guidelines recommend. But the s case includes a string comparison of the argument vector with -safe, it is just the first character of -safe... ...after ten years using awk(1) I never observed that -safe was a single option! :-) ...I have received your last email right now. Ok, manage the patch as you want. If you prefer dropping these spaces I will understand. Same about the case for the -m options, if you feel it is not required do not apply this patch. I really trust on the way OpenBSD developers manage the changes for this operating system, it is one of the few operating systems I like, and I have not found a single change that I dislike on it. If you want these changes not to be applied, I am sure it will be the right decision. Indeed, awk(1) is maintained by Brian Kernighan. That is the reason I asked who should manage this issue. I agree with you, it is better sending the fixes upstream and importing them with a software version upgrade. Local changes are a nightmare, as these changes need to be applied each time the software is upgraded (and sometimes reimplemented, as the source code changes!). I can send the patches to Brian Kernighan, asking him to apply these changes to the awk(1) source code. Do you agree? If you prefer sending the patches yourself, let me know. Thank you very much to you and to Philip Guenther for the feedback on my mistake about the -safe option. Best regards, Igor.
Re: on the awk(1)/nawk(1) usage synopsis
On Mon, Jan 29, 2007 at 11:19:11PM +0100, Igor Sobrado wrote: I can send the patches to Brian Kernighan, asking him to apply these changes to the awk(1) source code. Do you agree? If you prefer sending the patches yourself, let me know. the changes will be sent upstream next time we update. jmc