Add string array, have the pdfio_file_t object manage allocated data.

This commit is contained in:
Michael R Sweet
2021-04-25 11:28:56 -04:00
parent 899feb15c7
commit 98c48e66c2
5 changed files with 268 additions and 29 deletions

View File

@@ -15,11 +15,40 @@
//
// '()' - .
// Array structure
//
bool pdfioArrayAppendArray(pdfio_array_t *a, pdfio_array_t *value)
struct _pdfio_array_s
{
size_t num_values, // Number of values in use
alloc_values; // Number of allocated values
_pdfio_value_t *values; // Array of values
};
//
// Local functions...
//
static bool append_value(pdfio_array_t *a, _pdfio_value_t *v);
//
// 'pdfioArrayAppendArray()' - Add an array value to an array.
//
bool // O - `true` on success, `false` on failure
pdfioArrayAppendArray(
pdfio_array_t *a, // I - Array
pdfio_array_t *value) // I - Value
{
_pdfio_value_t v; // Value for array
v.type = PDFIO_VALTYPE_ARRAY;
v.value.array = value;
return (append_value(a, &v));
}
@@ -176,3 +205,39 @@ pdfio_valtype_t pdfioArrayGetType(pdfio_array_t *a, int n)
}
//
// '()' - .
//
_pdfio_value_t *
_pdfioArrayGetValue(pdfio_array_t *a, int n)
{
}
//
// 'append_value()' - Append a value.
//
static bool // O - `true` on success, `false` otherwise
append_value(pdfio_array_t *a, // I - Array
_pdfio_value_t *v) // I - Value
{
if (!a)
return (false);
if (a->num_values >= a->alloc_values)
{
_pdfio_value_t *temp = (_pdfio_value_t *)realloc(a->values, (a->alloc_values + 16) * sizeof(_pdfio_value_t));
if (!temp)
return (false);
a->values = temp;
a->alloc_values += 16;
}
a->values[a->num_values ++] = *v;
return (true);
}