Commit graph

10 commits

Author SHA1 Message Date
Linus Torvalds
3521cdcbd6 membuffer: add helper functions to return regular C strings
The whole "create a string using a printf-like interface" thing is
pretty common, and most users then don't necessarily want to deal with
the membuffer interfaces around it.

So this just creates trivial wrappers to do this, so that you can do

    s = format_string("%d: %s\n", i, str);

or similar things.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-15 06:02:24 -08:00
Dirk Hohndel
12f422a1a3 Add helper function to extend C strings
This is trivial to do with Qt, but when we want to be able to do this in C
code it takes a little more work. This creates a simple pattern to extend
an existing C string.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-14 17:50:03 -08:00
Gehad elrobey
464a611d8d HTML: Better quoting to the export strings
Move the quote function to membuffer.c and adding wrappers that call
it from both xml and html exporters to get rid of redundancy.

Quote the location, buddy, suit, tags and notes This
prevents js code from crashing.

[Miika Turkia: minor whitespace and code fix]

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-06 10:08:09 -07:00
Gehad
cb3436b42e Use helper function to write decimal numbers
Never ever use '%f' to write floating point data to a file. The stupid
locale handling creates useless comma-infested output in some locales.
Instead use one of our clever helper functions to do the right thing.

Original patch by Gehad, modified by Linus to be a little more generic.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-05 16:10:11 -07:00
Linus Torvalds
989c8f0110 Fix totally broken put_vformat() implementation
I'm ashamed.  put_vbuffer() worked perfectly fine for the normal case
when everything fit in our simple buffer on-stack, but the fallback case
was broken in so many ways that I'm just going to go sit in a corner and
cry myself to sleep.

And dammit, I _knew_ how to do it right.  I knew you had to do a
"va_copy()" and couldn't just keep re-using 'args'.  I've done this
before.  But I half-arsed it, and nobody ever noticed, because you
wouldn't do C style format strings for big strings.

"128 bytes is enough for everybody".

And as penance for this idiocy, I just spent too much time trying to
figure out what was wrong in my git loading code when my debug printouts
caused SIGSEGV's.

Sigh.

Anyway, now it should hopefully be correct, and the code is smarter
about things too, not having that extra buffer since we already *have* a
buffer in the "struct membuffer" we are working with.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-08 16:32:31 -08:00
Dirk Hohndel
37c1e8147a Don't have the put_something() functions return success
We didn't use the return value anywhere.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-07 20:33:22 -08:00
Linus Torvalds
0b8deb2a15 Add C string helper to membuffer interface
I don't know why I didn't do this from the beginning.  We often build up
a membuffer and then want to use it as a C string.  You could do it by
hand by adding the zero byte at the end, but that's just annoying.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-07 16:36:11 -08:00
Dirk Hohndel
76e6420f6b Massive automated whitespace cleanup
I know everyone will hate it.
Go ahead. Complain. Call me names.
At least now things are consistent and reproducible.
If you want changes, have your complaint come with a patch to
scripts/whitespace.pl so that we can automate it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-27 20:09:57 -08:00
Linus Torvalds
77da20196f Clean up membuffer internal structure names, add strip function
The "size" member was confusing - it's the size of the allocation, not
the size of the current string.  The size of the current string is the
member called "used".

This naming makes perfect sense for the internal implementation, but
it's confusing to users who actually do want to get the size of the
resulting string at the end.

So rename the fields to "alloc" and "len" - which is pretty clear.

This also adds a helper function to strip whitespace from the end:
"strip_mb()".

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-10 07:03:25 -08:00
Linus Torvalds
96a4fd1bb2 Save XML files into a memory buffer rather than directly into a file
This introduces a "struct membuffer" abstraction that you can write
things into, and makes the XML saving code write to the memory buffer
rather than a file.

The UDDF export already really wanted this: it used to write to a file,
only to then read that file back into memory, delete the file, and then
*rewrite* the file after doing the magic xslt transform.

But the longer-term reason for this is that I want to try to write other
formats, and I want to try to share most helpers.  And those other
formats will need this memory buffer model.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16 12:51:23 +07:00