Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!rpi!uupsi!kepler1!fcaggian From: fcaggian@kepler.com (Frank Caggiano) Newsgroups: comp.lang.eiffel Subject: Re: formated string objects Summary: It doesn't devalue it Keywords: sprintf like routine Message-ID: <463@kepler1.kepler.com> Date: 12 Jan 91 02:45:25 GMT References: <457@kepler1.kepler.com> <1071@tetrauk.UUCP> Organization: Kepler Financial Mgmt., Setuket, NY Lines: 84 In article <1071@tetrauk.UUCP>, rick@tetrauk.UUCP (Rick Jones) writes: > In article <457@kepler1.kepler.com> fcaggian@kepler.com (Frank Caggiano) writes: > >The following c routine is something I've wanted to write for > >a while now. It makes creating formatted string objects > >easier. > > I hate to devalue your work, but if your system has the vprintf() set of > functions, you can do this extremely simply. It would look like: [ revised code deleted ] I don't feel that your posting devalues my work in anyway. It's a valid solution to the problem. My code was stripped out of another routine I wrote some years ago which is called eprintf. It acts just like the starndard printf routines but had added % parameter recognition for error reporting. I appreciate it when someone tales the time to look at and comment on code I have written. How else is one to learn in this buisiness? > You might want to make BUFSIZ something really big to make the probability of > buffer overrun very low. The double check in the for loop prevents buffer overrun. If the format string and expanded values are to large the returned string will be incomplete. > I'm not sure of the extent to which vsprintf() is supported. A real problem with the growth of UNIX. Just what is truely portable code these days ? If anyone knows how universial the vsprintf() functions are prehaps they could let us know. By the way according to the man page for varargs on the sun my spliting of the format string from the rest of the varargs isn't right. It should be something like: was: OBJPTR format_obj(fmt,va_alist) char *fmt; should be: OBJPTR format_obj(va_alist) /* removed fmt as arg */ va_dcl /* the missing ; IS RIGHT see varargs */ { va_list ap; register int n; register char *cp, c, *buf_end; char buf[BUFSIZ], f[20], *fmt; /* added fmt as local var */ ^^^^^^^^^^^ OBJPTR strobj; ROUT_PTR from_c; cp = buf; f[0] = '%'; buf_end = buf+BUFSIZ; va_start (ap); /* add */ fmt = va_arg(ap, char *); /* set fmt from var arg list */ while((c = *fmt++) != '\0' && cp < buf_end) { [ THE REST is the same ] The code as I orignally posted it works but may have problems with really long arg lists. > -- > Rick Jones > Tetra Ltd. Maidenhead, Was it something important? Maybe not > Berks, UK What was it you wanted? Tell me again I forgot > rick@tetrauk.uucp -- Bob Dylan I like the Dylan quotes in your signature. How come I've never seen the one: 'You know something is happening but you don't know what it is, do you Mr. ........ ' [ It may be a bit off my Dylan is rusty ] :-) Regards PS. Did you do work for an American Law firm in London about 5 years ago? -- Frank Caggiano INTERNET: fcaggian@kepler.com Kepler Financial Management, Ltd. UUCP: ..!uunet!kepler1!fcaggian 100 North Country Rd. fax: (516) 751-8678 Sekauket, NY 11733 voice: (516) 689-6300