From owner-freebsd-hackers Fri Sep 20 11:38:55 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id LAA01009 for hackers-outgoing; Fri, 20 Sep 1996 11:38:55 -0700 (PDT) Received: from csla.csl.sri.com (csla.csl.sri.com [192.12.33.2]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id LAA00935 for ; Fri, 20 Sep 1996 11:38:48 -0700 (PDT) Received: from impulse.csl.sri.com (impulse.csl.sri.com [130.107.15.11]) by csla.csl.sri.com (8.7.3/8.7.3) with ESMTP id LAA07553 for ; Fri, 20 Sep 1996 11:38:14 -0700 (PDT) Received: from impulse.csl.sri.com (localhost [127.0.0.1]) by impulse.csl.sri.com (8.7.3/8.7.3) with ESMTP id LAA01472 for ; Fri, 20 Sep 1996 11:35:45 -0700 (PDT) Message-Id: <199609201835.LAA01472@impulse.csl.sri.com> To: hackers@freebsd.org Subject: rpcgen / fgets Date: Fri, 20 Sep 1996 11:35:45 -0700 From: Fred Gilham Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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,", ' ' , "%\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