Hi Marcel,

Ingo Schwarze wrote on Wed, Jul 24, 2019 at 03:27:05PM +0200:
> Marcel Logen wrote on Tue, Jul 23, 2019 at 11:16:33PM +0200:
>> Ingo Schwarze wrote:

>>> 1. What exactly are you doing? (minimal test case, if possible)

> [...]
>> | t20$ gencat foo1.cat foo1.msg
>> | gencat: can't specify a message when no set exists on line 3
>> | 1 "foo
>> 
>> | t20$ gencat foo2.cat foo2.msg
> [...]

> Thank you for the report.  I am able to reproduce the described
> behaviour.  I shall investigate further and come back to you.

Oh, it seems to me the issue is actually quite easy to fix,
see the patch below.

While here, note that the automatic variable "setid" is a state
variable and must persist from one iteration of the main parsing
loop to the next, while "msgid" is not a state variable.  It is
used only inside the "else" clause and assigned to before each use.
So delete the misleading initializations of msgid.

My impression is that no change is needed in the manual page.

OK?
  Ingo

P.S.
It appears this tool could use some auditing, KNF, and general
cleanup, but it is certainly not high priority...


Index: gencat.c
===================================================================
RCS file: /cvs/src/usr.bin/gencat/gencat.c,v
retrieving revision 1.19
diff -u -p -r1.19 gencat.c
--- gencat.c    28 Jun 2019 13:35:01 -0000      1.19
+++ gencat.c    24 Jul 2019 13:53:00 -0000
@@ -405,11 +405,12 @@ void
 MCParse(int fd)
 {
        char   *cptr, *str;
-       int     setid, msgid = 0;
+       int     setid, msgid;
        char    quote = 0;
 
        /* XXX: init sethead? */
 
+       setid = 0;
        while ((cptr = get_line(fd))) {
                if (*cptr == '$') {
                        ++cptr;
@@ -418,7 +419,6 @@ MCParse(int fd)
                                cptr = wskip(cptr);
                                setid = atoi(cptr);
                                MCAddSet(setid);
-                               msgid = 0;
                        } else if (strncmp(cptr, "delset", 6) == 0) {
                                cptr += 6;
                                cptr = wskip(cptr);
@@ -462,6 +462,10 @@ MCParse(int fd)
                        } else {
                                warning(cptr, "neither blank line nor start of 
a message id");
                                continue;
+                       }
+                       if (setid == 0) {
+                               setid = NL_SETD;
+                               MCAddSet(setid);
                        }
                        /*
                         * If we have a message ID, but no message,

Reply via email to