Re: flaw found [in my own program]
On Jun 8, 2009, at 7:15 PM, Gary Kline wrote: not surprisingly, i found a fla w in my getc(fp) program that tried to read past ? and ? ... the example i added to my test file was simply the 2 bytes and ?. so if you have a stray ? with a matching close case, the binary hangs on a read. so, again, can anybody suggest a better example, in C, to get past two delimiters? Back in the days when I taught introductory C programming, one the the early homework assignments was to write a filter that would strip C- style comments. As a follow-up they had to do this allowing for nested comments. I don't think I can recover things from the back-up tapes that I have for that corse material, but the approach I directed people toward was to have a variable, let's call it status that records one of four states OUTSIDE /* just reading normally, not in the material to be striped */ AFTER_LT /* You've read in a '' and are looking for a '?' */ INSIDE /* You are in the material to be stripped */ AFTER_Q /* You are in the material to be stripped and have just read a '?' */ then use a switch statement on the character you are reading in. switch(c) { case '': ... case '?': ... case '': ... case EOF: ... default: ... } In each case, you look at the current state, decide whether the write 'c' to output and what state to change to. The most common mistake students would make would be to forget the EOF case. I suspect that you may have done the same. -j ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: flaw found [in my own program]
On Tue, Jun 09, 2009 at 06:19:21PM -0500, Jeffrey Goldberg wrote: On Jun 8, 2009, at 7:15 PM, Gary Kline wrote: not surprisingly, i found a fla w in my getc(fp) program that tried to read past ? and ? ... the example i added to my test file was simply the 2 bytes and ?. so if you have a stray ? with a matching close case, the binary hangs on a read. so, again, can anybody suggest a better example, in C, to get past two delimiters? Back in the days when I taught introductory C programming, one the the early homework assignments was to write a filter that would strip C- style comments. As a follow-up they had to do this allowing for nested comments. I don't think I can recover things from the back-up tapes that I have for that corse material, but the approach I directed people toward was to have a variable, let's call it status that records one of four states OUTSIDE /* just reading normally, not in the material to be striped */ AFTER_LT /* You've read in a '' and are looking for a '?' */ INSIDE /* You are in the material to be stripped */ AFTER_Q /* You are in the material to be stripped and have just read a '?' */ then use a switch statement on the character you are reading in. switch(c) { case '': ... case '?': ... case '': ... case EOF: ... default: ... } In each case, you look at the current state, decide whether the write 'c' to output and what state to change to. The most common mistake students would make would be to forget the EOF case. I suspect that you may have done the same. -j :-) yup, this is definitely better that initial approach. i have improved my function to return a 1 after ?, 2 after a ? and a 3 if both are found. i still think my function hangs in an loop if only the opening php token is found. thanks for the idea! gary -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org For FBSD list: http://transfinite.thought.org/slicejourney.php The 4.91a release of Jottings: http://jottings.thought.org/index.php ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: flaw found....
Gary, On Mon, Jun 8, 2009 at 8:15 PM, Gary Klinekl...@thought.org wrote: not surprisingly, i found a fla w in my getc(fp) program that tried to read past ? and ? ... the example i added to my test file was simply the 2 bytes and ?. so if you have a stray ? with a matching close case, the binary hangs on a read. so, again, can anybody suggest a better example, in C, to get past two delimiters? one thought is how gcc parses the /* and */ comment delimiters. any compiler gurus out there who know where this code is? gary ? What about having it check a char array, similar to how programs like ls(1) does checking for command line arguments? http://svn.freebsd.org/base/stable/7/bin/ls/ls.c - line 181 and on. -- Glen Barber http://www.dev-urandom.com http://www.linkedin.com/in/glenjbarber ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: flaw found....
On Mon, Jun 08, 2009 at 08:20:22PM -0400, Glen Barber wrote: Gary, On Mon, Jun 8, 2009 at 8:15 PM, Gary Klinekl...@thought.org wrote: not surprisingly, i found a fla w in my getc(fp) program that tried to read past ? and ? ... the example i added to my test file was simply the 2 bytes and ?. so if you have a stray ? with a matching close case, the binary hangs on a read. so, again, can anybody suggest a better example, in C, to get past two delimiters? one thought is how gcc parses the /* and */ comment delimiters. any compiler gurus out there who know where this code is? gary ? What about having it check a char array, similar to how programs like ls(1) does checking for command line arguments? http://svn.freebsd.org/base/stable/7/bin/ls/ls.c - line 181 and on. yes, this is one thing i was thinking about at around 04:30! having a pointer to both the beginning and ending of the delimiter pair. if no ending was found, issue a warning and error exit. FWIW, Google just pointed me at a snippet that showed how to get past things like // comments thankee! -- Glen Barber http://www.dev-urandom.com http://www.linkedin.com/in/glenjbarber -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org For FBSD list: http://transfinite.thought.org/slicejourney.php The 4.91a release of Jottings: http://jottings.thought.org/index.php ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org