Miles Bader wrote: > On Wed, Sep 10, 2003 at 03:45:34PM +0200, Andreas B?sching wrote: > + while ((str = fgets (string, BUFSIZ, stdin))) > + { > + fprintf (out, "%s ", quote_file_name (str)); > + } > > I think that there shouldn't be a space after the %s -- that will cause each > line of input to be evaluated independantly, which is probably not what you > want, as well as being the wrong thing if a line is longer than BUFSIZ. > Also, you don't free the result from quote_file_name (it's only only going to > matter for extremely long input -- but that's probably more likely for stuff > being fed from stdin). > > Hmmm, this isn't really your fault, but I notice that _every_ call to > quote_file_name immediately just prints the result, like: > > fprintf (out, "-display %s ", quote_file_name (display)); > > where quote_file_name mallocs a new string. > > It would be nicer to just change quote_file_name to something like > `output_quoted_string (char *str, FILE *stream)', which just copies STR to > STREAM with appropriate quoting (doing away with all the mallocing). > > Then expressions like the above could be changed to: > > { > fputs ("-display ", out); > output_quoted_string (display, out); > } > > and your loop would be: > > while ((str = fgets (string, BUFSIZ, stdin))) > output_quoted_string (str, out); Okay, Here is another version of the patch, with a new version of quote_file_name and the bug fix suggested by Sfefan and Miles. and again RFC crunchy