Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Sep 1996 11:35:45 -0700
From:      Fred Gilham <gilham@csl.sri.com>
To:        hackers@freebsd.org
Subject:   rpcgen / fgets
Message-ID:  <199609201835.LAA01472@impulse.csl.sri.com>

next in thread | raw e-mail | index | archive | help


I'm having trouble with rpcgen.  It seems to happen in both 2.1.5R and
2.2-960801-SNAP.

The symptom is that directives (lines in the .x file beginning with %)
that have continuation indicators ("\" as the last character of the
line) get garbled.

Here's what I see:

%#define PRINTRECORD(fp,r,t) {      \
%  fprintf(fp,RECFORMAT,            \
%        UID_LEN,   r->userid,      \
%        COUNT_LEN, r->count,       \
%        SEED_LEN,  r->seed,        \
%        VAL_LEN,   r->val,         \
%        TIME_LEN,  t);             \
%}


gets turned into

#define PRINTRECORD(fp,r,t) {      %  fprintf(fp,RECFORMAT,            %         UID_LEN, 
  r->userid,      %      COUNT_LEN, r->count,       %    SEED_LEN,  r->seed,        %    V
AL_LEN,   r->val,         %        TIME_LEN,  t);             %}


This obviously won't compile.  On the other hand, sunos and solaris
rpcgen both handle this correctly.

I've run rpcgen through the debugger.  The code that writes directives
is

                          .
                          .
                          .
                 } else if (directive(curline)) {
                         printdirective(curline);




Setting the breakpoint at printdirective(), I see:

(gdb) where
#0  printdirective (
    line=0x13d24 "%#define PRINTRECORD(fp,r,t) {      %  fprintf(fp,RECFORMAT,", ' ' <repeats 12 times>, "%\t UID_LEN,   r->userid,      %\t COUNT_LEN, r->count,       %\t SEED_LEN,  r->seed,        %\t VAL_LEN,   r->val,         %       "...) at rpc_scan.c:475
#1  0xb321 in get_token (tokp=0xefbfda18) at rpc_scan.c:192
#2  0x8b88 in get_definition () at rpc_parse.c:76
#3  0x2023 in c_output (infile=0xefbfdb60 "otpdb.x", define=0x15af "-DRPC_XDR", extend=1, 
    outfile=0x15fc "_xdr.c") at rpc_main.c:465
#4  0x17e9 in main (argc=2, argv=0xefbfdaac) at rpc_main.c:206

which means that the line fed to printdirective() is already mangled.

It almost looks like fgets() is somehow processing the continuation
characters but I don't see anything in the code for fgets() that would
do that.

Another indication that this problem is caused by the continuation
characters is that if I put a space after the continuation characters,
the line is handled properly, i.e.



%#define PRINTRECORD(fp,r,t) {      \ 
%  fprintf(fp,RECFORMAT,            \ 
%	 UID_LEN,   r->userid,      \ 
%	 COUNT_LEN, r->count,       \ 
%	 SEED_LEN,  r->seed,        \ 
%	 VAL_LEN,   r->val,         \ 
%        TIME_LEN,  t);             \ 
%}

(with spaces after the `\' character)

becomes

#define PRINTRECORD(fp,r,t) {      \ 
  fprintf(fp,RECFORMAT,            \ 
         UID_LEN,   r->userid,      \ 
         COUNT_LEN, r->count,       \ 
         SEED_LEN,  r->seed,        \ 
         VAL_LEN,   r->val,         \ 
        TIME_LEN,  t);             \ 
}

(also with spaces after the `\' character---still no good)

but in the same file

%#define PRINTHEADER(fp) {          \
%  fprintf(fp,RECFORMAT,            \
%	 UID_LEN,   "user",         \
%	 COUNT_LEN, "count",        \
%	 SEED_LEN,  "seed",         \
%	 VAL_LEN,   "value",        \
%	 TIME_LEN,  "timestamp");   \
%}

(without spaces after the `\' character)

remains

#define PRINTHEADER(fp) {          %  fprintf(fp,RECFORMAT,            %         UID_LEN, 
  "user",         %      COUNT_LEN, "count",        %    SEED_LEN,  "seed",         %    V
AL_LEN,   "value",        %      TIME_LEN,  "timestamp");   %}


Does anyone have any comments about this?  Is this a bug or what?

Obviously I can work around it, but the behavior seems incorrect.

-Fred Gilham   gilham@csl.sri.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199609201835.LAA01472>