libannodex  0.7.3
Reading from memory buffers

Sometimes it is not possible to provide a file descriptor for a data source; for example, if the data is extracted from a high level library. In this case, you must directly input the data to libannodex using memory buffers as follows:

This procedure is illustrated in src/examples/print-title-memory.c:

/*
Copyright (C) 2003 Commonwealth Scientific and Industrial Research
Organisation (CSIRO) Australia
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of CSIRO Australia nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
static int
read_head (ANNODEX * anx, const AnxHead * head, void * user_data)
{
puts (head->title);
return ANX_CONTINUE;
}
int
main (int argc, char *argv[])
{
ANNODEX * anx = NULL;
unsigned char buf[1024];
long n = 1024;
anx = anx_new (ANX_READ);
anx_set_read_head_callback (anx, read_head, NULL);
while (n > 0) {
/* Fill a memory buffer */
n = fread (buf, 1, 1024, stdin);
/* Input that memory buffer into the annodex */
n = anx_read_input (anx, buf, n);
}
anx_close (anx);
exit (0);
}
annodex.h
_AnxHead
Definition: anx_types.h:87
anx_set_read_head_callback
int anx_set_read_head_callback(ANNODEX *annodex, AnxReadHead read_head, void *user_data)
Set the function to call when the head element is read.
ANNODEX
void ANNODEX
An ANNODEX handle.
Definition: anx_types.h:55
_AnxHead::title
const char * title
title element of header
Definition: anx_types.h:92
anx_new
ANNODEX * anx_new(int mode)
Create a managed Annodex handle This is an alternative interface for non-file annodexes.
anx_close
ANNODEX * anx_close(ANNODEX *annodex)
Close an annodex.
anx_read_input
long anx_read_input(ANNODEX *annodex, unsigned char *buf, long n)
Input data from a memory buffer into an annodex.