Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!sunybcs!bingvaxu!leah!rds95 From: rds95@leah.Albany.Edu ( Robert Seals) Newsgroups: comp.sources.d Subject: File access problem using ptc -- Message-ID: <490@leah.Albany.Edu> Date: Thu, 27-Aug-87 12:45:28 EDT Article-I.D.: leah.490 Posted: Thu Aug 27 12:45:28 1987 Date-Received: Sat, 29-Aug-87 09:47:47 EDT Organization: The University at Albany, Computer Services Center Lines: 71 Keywords: reset, pascal, ptc, um Yo, There is a problem - I'm sure you've heard about it already - in the otherwise wonderful ptc program posted to comp.sources.unix recently. It doesn't handle files correctly. Both the C and Pascal versions do the same thing. Perhaps I can illustrate... program ptcbug(input, output, f); var f: text; c: char; begin reset(f, 'ptcbug.p'); while not eof(f) do begin while not eoln(f) do begin read(f, c); write(c) end; readln(f); writeln end end. This is a reasonable program for 4.2 pc (did I say Ultrix?). It works, and even produces the correct result. But when the translated program is cc'ed, here is what happens... % ptc ptcbug.c % cc ptcbug.c "ptcbug.c", line 66: operands of : have incompatible types "ptcbug.c", line 120: redeclaration of rewind So, I tracked down the problem, and it is in the `reset' - but the whole thing is done with macros, and upon expansion by cpp, here is what you get { ..... stuff ..... } main() { (f).init = (f).init ? ( ((f).out && !(f).eoln) ? ( ( f).buf = ('\n'), ( f).eoln = (( f).buf == '\n'), (void)fputc(( f).buf, ( f).fp), 0) : 0, rewind((f).fp)) : (((f).fp = Fopen( "ptcbug.p", Rmode)), 1), (f).eof = (f).out = 0, (f).init = 1, (f).eoln = (((f).buf = fgetc((f).fp)) == '\n') ? (((f).buf = ' '), 1) : 0; while (! ((((f).init == 0) ? ( fread((char *)&(f).buf, sizeof((f).buf), 1, (f).fp)) : 0, ((f).eof ? 1 : ((((f).fp)->_flag& 00020)!=0))) ? (boolean)1 : (boolean)0)) { while (! ((f).eoln ? (boolean)1 : (boolean)0)) { c = (f).buf, (f).init = 1, (f).eoln = (((f).buf = fgetc((f).fp)) == '\n') ? (((f).buf = ' '), 1) : 0; ( output).buf = (c), ( output).eoln = (( output).buf == '\n'), (void)fputc(( output).buf, ( output).fp); } Getl(&f); ( output).buf = ('\n'), ( output).eoln = (( output).buf == '\n'), (void)fputc(( output).buf, ( output).fp); } exit(0); { ....... more stuff ........} It's like, wow man, like I can't handle this action at all, ya no? So, somewhere up in the first line, there is an error in : . As far as the redefinition of rewind(), I am puzzled, because it puts the definition at the very end of the new C program. Hmm. Has anybody come up with anything that will make it work? Programs that use stdin and out all work fine, and this is a real bummer drag, because very few of my programs don't use files. HELP rob Robert Seals Atmospheric Sciences Research Center Try this one: rob@asrcmv.albany.edu It might work... This is more likely: ...leah.albany.edu!asrcmv!rob Or just use "r"! Or follow the From: path. I WANT TO MARRY LIZ FRASER AND I'VE NEVER EVEN MET HER --------------