mirror of
https://github.com/michaelrsweet/pdfio.git
synced 2025-08-29 15:22:06 +02:00
Implement value/array/dict reading, refactor indirect references.
This commit is contained in:
@@ -23,6 +23,22 @@ static ssize_t read_buffer(pdfio_file_t *pdf, char *buffer, size_t bytes);
|
||||
static bool write_buffer(pdfio_file_t *pdf, const void *buffer, size_t bytes);
|
||||
|
||||
|
||||
//
|
||||
// '_pdfioFileClearTokens()' - Clear the token stack.
|
||||
//
|
||||
|
||||
void
|
||||
_pdfioFileClearTokens(pdfio_file_t *pdf)// I - PDF file
|
||||
{
|
||||
while (pdf->num_tokens > 0)
|
||||
{
|
||||
pdf->num_tokens --;
|
||||
free(pdf->tokens[pdf->num_tokens]);
|
||||
pdf->tokens[pdf->num_tokens] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// '_pdfioFileConsume()' - Consume bytes from the file.
|
||||
//
|
||||
@@ -131,6 +147,20 @@ _pdfioFileGetToken(pdfio_file_t *pdf, // I - PDF file
|
||||
char *buffer,// I - String buffer
|
||||
size_t bufsize)// I - Size of string buffer
|
||||
{
|
||||
// See if we have a token waiting on the stack...
|
||||
if (pdf->num_tokens > 0)
|
||||
{
|
||||
// Yes, return it...
|
||||
pdf->num_tokens --;
|
||||
strncpy(buffer, pdf->tokens[pdf->num_tokens], bufsize - 1);
|
||||
buffer[bufsize - 1] = '\0';
|
||||
|
||||
free(pdf->tokens[pdf->num_tokens]);
|
||||
pdf->tokens[pdf->num_tokens] = NULL;
|
||||
return (true);
|
||||
}
|
||||
|
||||
// No, read a new one...
|
||||
return (_pdfioTokenRead(pdf, buffer, bufsize, (_pdfio_tpeek_cb_t)_pdfioFilePeek, (_pdfio_tconsume_cb_t)_pdfioFileConsume, pdf));
|
||||
}
|
||||
|
||||
@@ -268,6 +298,22 @@ _pdfioFilePrintf(pdfio_file_t *pdf, // I - PDF file
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// '()' - Push a token on the token stack.
|
||||
//
|
||||
|
||||
void
|
||||
_pdfioFilePushToken(pdfio_file_t *pdf, // I - PDF file
|
||||
const char *token)// I - Token
|
||||
{
|
||||
if (pdf->num_tokens < (sizeof(pdf->tokens) / sizeof(pdf->tokens[0])))
|
||||
{
|
||||
if ((pdf->tokens[pdf->num_tokens ++] = strdup(token)) == NULL)
|
||||
pdf->num_tokens --;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// '_pdfioFilePuts()' - Write a literal string to a PDF file.
|
||||
//
|
||||
|
Reference in New Issue
Block a user