Commit graph

83 commits

Author SHA1 Message Date
Bill Currie
e3762d8f38 [util] Make plist mostly null-safe
The main purpose is to allow fluent-style:
    const char *targetname = PL_String (PL_ObjectForKey (entity, "targetname"));
    if (targetname && !PL_ObjectForKey (targets, targetname)) {
        PL_D_AddObject (targets, targetname, entity);
    }

[note: the above is iffy due to ownership of entity, but the code from
which the above comes works around the issue]
2021-03-03 18:01:35 +09:00
Bill Currie
4eb07220cd [util] Make plists more const-correct 2021-02-25 11:55:25 +09:00
Bill Currie
5535d1f8e6 [util] Keep track of plist dictionary key order
The order in which keys are added to the dictionary object is
maintained. Adding a key after removing an old key adds the new key to
the end of the list rather than reusing the old key's spot.
2021-02-09 17:03:33 +09:00
Bill Currie
0dcd946063 [util] Add plist parser for dictionary -> array
PL_ParseLabeledArray works the same way as PL_ParseArray, but instead
takes a dictionary object. The keys of the items are ignored, and the
order is not preserved (at this stage), but this is a cleaner solution
to getting an array of objects when the definitions of those objects
need to be accessible by name as well.
2021-02-09 15:24:28 +09:00
Bill Currie
14e4fd9f6a [util] Pass context to the plist array/symtab parser allocator 2021-02-09 15:01:55 +09:00
Bill Currie
a408fd40da [util] Make plist more const-correct 2021-02-09 14:56:48 +09:00
Bill Currie
dfa7af03c6 [util] Plug a thread-safety hole in plists 2021-02-09 09:57:07 +09:00
Bill Currie
7970525ef4 [util] Make va thread-safe
It now takes a context pointer (opaque data) that holds the buffers it
uses for the temporary strings. If the context pointer is null, a static
context is used (making those uses of va NOT thread-safe). Most calls to
va use the static context, but all such calls have been formatted
consistently so they are easy to find when it comes time to do a full
audit.
2021-01-31 16:05:48 +09:00
Bill Currie
12ec6c5c29 [util] Add eol to plist parse errors
I suspect it got lost when I made the error message a string item.
2021-01-26 20:45:07 +09:00
Bill Currie
8224169394 [util] Make plist parse errors a little more useful
Particularly the "unexpected character" ones.
2021-01-23 18:56:15 +09:00
Bill Currie
b493e6ac32 [util] Expose plist type check support functions 2021-01-05 23:39:52 +09:00
Bill Currie
81300f89f8 [util] Allow multiple types for pl fields
I want to be able to use name references, but that requires string
items, so anything that would normally be dictionary or array (or
binary, even) would also need to accept string. This seemed to be the
cleanest solution. Any custom parser would then need to check the type
and act appropriately, but any inappropriate types have already been
pre-filtered by the standard parsers.
2021-01-02 14:02:33 +09:00
Bill Currie
d824db68a5 [util] Zero plist symtabl object memory 2020-12-25 00:28:26 +09:00
Bill Currie
fefb32bf13 [util] Add a PL dictionary to hash table parser 2020-12-24 16:06:34 +09:00
Bill Currie
cb2bdb0224 [util] Rename PL_ParseDictionary to PL_ParseStruct
Struct is far more appropriate for its function, and I need to parse a
dictionary into a hash table.
2020-12-24 13:33:37 +09:00
Bill Currie
5864b553ef [util] Add accessors for binary plist objects 2020-12-23 14:07:30 +09:00
Bill Currie
591667c36d [util] Add a context parameter to the plist parsers
Not used by the dict/array parsers themselves, but is passed on to any
value parser callbacks for their own use.
2020-12-21 14:22:42 +09:00
Bill Currie
9f4f63796b [util] Fix some unitialized vars
Not sure how they got past gcc. Maybe a bug in 9.3.0?
2020-07-17 00:23:09 +09:00
Bill Currie
2b23e01d9a [util] Make PL_Type and PL_Line const-correct 2020-07-17 00:22:47 +09:00
Bill Currie
16c6818612 [util] Set parsed array size correctly
The array has to be allocated using byte elements and thus the size of
the array is the number of bytes, but it needs to be the actual number
of elements in the array. Problem caused by not knowing the actual type
(and C not having type variables anyway).
2020-07-16 22:14:19 +09:00
Bill Currie
26cd93f788 [util] Expose PL_Message
It's far to useful elsewhere.
2020-07-16 22:14:19 +09:00
Bill Currie
ef33adac56 [util] Make PL_String const correct 2020-07-16 22:14:19 +09:00
Bill Currie
72f583f16f [util] Fix some plist object parsing errors
Forgot to break after finding the field when parsing a dictionary
object, and use the correct parser for array objects.
2020-07-16 22:14:19 +09:00
Bill Currie
c6a8829a52 [util] Add code to parse a plist array to an array 2020-07-14 12:05:34 +09:00
Bill Currie
8bd5f4f201 [util] Add code to parse a dictionary to a struct
PL_ParseDictionary itself does only one level, but it takes care of the
key-field mappings and property list item type checking leaving the
actual parsing to a helper specified by the field. That helper is free
to call PL_ParseDictionary recursively.
2020-07-05 16:53:35 +09:00
Bill Currie
f6ea9e4d87 [util] Store source line in plist items
The first line of the parsed item is stored and can be retrieved using
PL_Line. Line numbers not stored for dictionary keys yet. Will be 0 for
any items generated by code rather than parsed from a file or string.
2020-07-01 21:47:09 +09:00
Bill Currie
4cef9792f4 [util] Make hash-tables semi-thread-safe
They take a pointer to a free-list used for hashlinks so the hashlink
pools can be per-thread. However, hash tables that are not updated are
always thread-safe, so this affects only updates. progs_t has been set
up such that it is easy for multiple progs within one thread can share
hashlinks.
2020-03-25 15:43:16 +09:00
Bill Currie
e27d7cbd2d Handle alloca "correctly".
Use AC_FUNC_ALLOCA and the #ifdef mess suggested by the autoconf docs
(hidden in qfalloca.h).
2013-01-22 21:02:50 +09:00
Bill Currie
d6bb5bec86 Use the already calculated string length.
No point doing it twice.
2013-01-08 18:10:27 +09:00
Bill Currie
a4714ac9b5 Correctly parse octal escapes for plist strings.
It seems the code expected octal escapes to always start with 0. This is
not the case. Also, octal escapes are limited to 3 digits (and hex to 2).

This fixes the garbled bold text in ITS.
2013-01-08 16:54:23 +09:00
Bill Currie
ec42bde527 Make hash tables more const correct.
And clean up the resulting mess :/
2012-10-27 11:44:31 +09:00
Bill Currie
62face768f Fix some char index issues. 2012-08-18 11:02:52 +09:00
Bill Currie
23a38738fc Massive whitespace cleanup.
Lots of trailing whitespace and otherwise blank lines.
2012-05-22 08:23:22 +09:00
Bill Currie
bc1b483525 Nuke the rcsid stuff.
It's pretty useless in git.
2012-04-22 10:56:32 +09:00
Bill Currie
561484842c Fix some snafus in PL_ParseData
Found them by inspection while writing a python version of qfplist.
2012-04-17 21:26:33 +09:00
Bill Currie
f75b0a611b Some compile fixes for OpenBSD 2011-08-25 22:35:20 +09:00
Bill Currie
1402feafd2 Kill some magic numbers and clean up some whitespace. 2011-08-20 16:30:43 +09:00
Bill Currie
bc2174d92b Remove some dead variables reported by Spirit. 2011-05-04 09:30:38 +09:00
Bill Currie
fd24170b32 get the behavior or PL_NewData correct
It taking ownership of the data was the correct behavior, so go back to that.
2010-08-20 13:21:22 +09:00
Bill Currie
a744caa421 The public api of qfplist is now fully documented.
Evertyhing that can or should be private now is, and all public functions
are documented.
2010-08-20 13:10:37 +09:00
Bill Currie
5c73d81e00 Python style long strings ("""...""") now supported for parsing. Any such strings will be written out as standard strings with escaped quotes when writing the plist. 2007-10-13 07:55:58 +00:00
Bill Currie
5294a97d6a make sure the \ gets written for all escapes, not just octals 2007-10-13 07:14:47 +00:00
Bill Currie
ece4df298e make that a factor of ~400. 2007-05-13 03:27:54 +00:00
Bill Currie
a72f2046f5 speed up PL_WritePropertyList by ~3x. 2007-05-13 03:13:01 +00:00
Bill Currie
81a57bb3fa patch from phrosty for vc2005 support. includes fixes for a bunch of gcc-isms that crept in over the years. 2007-03-22 23:20:57 +00:00
Bill Currie
99c0954b47 the big dso visibility patch :). Sure, we have to have unique names for static builds, but with controlled visibitly we should get faster program loads (although this isn't C++, so it's not as bad) and complex plugins are cleaner. 2007-03-10 12:00:59 +00:00
Bill Currie
70ec9848e7 add PL_RemoveObjectForKey and make PL_D_AddObject take a normal C string for key instead of a pl string. 2006-12-09 06:00:36 +00:00
Bill Currie
9cbac0bbc1 add array item removal 2006-12-09 02:33:08 +00:00
Bill Currie
3fb03fc2be hah, should have been using __attribute__((used)) all that time (rather
than __attribute__((unused))). fixes the missing console in -x11
2005-08-04 15:27:09 +00:00
Bill Currie
501180aaac gcc-4.0 fixes. even found some bugs :) (names /not/ mangled this time) 2005-06-08 06:35:48 +00:00