[barcode] Patch to get output in strings

Cloyce D. Spradling cloyce@headgear.org
Fri, 9 Nov 2001 18:18:25 -0600


--EuxKj2iCbKjpUGkD
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi guys.

I'm thinking about writing a Perl module to interface with the barcode
library, and I thought it'd be nice to be able to have output returned
in a string instead of just output to a file.  I don't know how useful
this would be for PCL, since I'm only using the library to generate PostScript,
but I also patched the PCL output for completeness.

This would add one new function to the API:

/*
 * Encode and return the output as a string
 */
extern unsigned char *Barcode_String(struct Barcode_Item *bc, int flags);

The caller is responsible for freeing the string after use.  I've not
patched any of the documents, since I don't like writing docs and didn't
want to waste the time if this idea is rejected. :)  If you guys find it
acceptable, I'll gladly patch the docs, too.

In the implementation I've tried to avoid potiential buffer overruns, and
no static buffers are used at all.  This leads to a construction that I'm
not entirely happy with;  the old

 fprintf(f, "...");

turns into the fairly clunky

 do
     i = snprintf(currpos, currlen, "...");
 while(_check_strbuf(&retval, &curpos, &currlen, i));

This of course introduces a dependency on snprintf and also on realloc.  I
don't know how that'll affect portability or even how much you guys care
about that.  I *think* it'll work on any POSIX system.  Currently I've
tested on Solaris 8 and Linux (glibc 2.1).  Next week I'll test it on
some other platforms (IRIX, AIX, MacOS X, maybe others; I don't know yet).

Well, sirs, what do you think?  I'm open to suggestions about how to make
it better.  In any case, I do think this is pretty valuable functionality.

The patch is a little large (~15.5kB), so I've compressed it with bzip2. If
I should deliver it in some other way, please let me know.
--
Cloyce

--EuxKj2iCbKjpUGkD
Content-Type: application/x-bzip2
Content-Disposition: attachment; filename="barcode-0.97-string.diff.bz2"
Content-Transfer-Encoding: base64

QlpoOTFBWSZTWVG4kUUAEvD/gHrySAB7///////fDr//3/9gE3wOnyCpWnu226VbSC7tXVS2
ZK5MQDkGVFAqpClVUqBVASKpeOZNNDIAGIyDIAaYIGIBo00AGQNAAlT1QBtREA0AAAAAAAAA
AAABKCaI1BqanqaabamoNDQDNQaDIaAaAABoACTUSEAgBGkzSZMjFNGmnqbE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