- Main Page
- Modules
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

# guththila_reader.h

    00001
    00002 /*
    00003  * Licensed to the Apache Software Foundation (ASF) under one or more
    00004  * contributor license agreements.  See the NOTICE file distributed with
    00005  * this work for additional information regarding copyright ownership.
    00006  * The ASF licenses this file to You under the Apache License, Version 2.0
    00007  * (the "License"); you may not use this file except in compliance with
    00008  * the License.  You may obtain a copy of the License at
    00009  *
    00010  *      http://www.apache.org/licenses/LICENSE-2.0
    00011  *
    00012  * Unless required by applicable law or agreed to in writing, software
    00013  * distributed under the License is distributed on an "AS IS" BASIS,
    00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    00015  * See the License for the specific language governing permissions and
    00016  * limitations under the License.
    00017  */
    00018 #ifndef GUTHTHILA_READER_H
    00019 #define GUTHTHILA_READER_H
    00020
    00021 #include <stdio.h>
    00022 #include <guththila_defines.h>
    00023 #include <axutil_utils.h>
    00024
    00025 EXTERN_C_START()
    00026
    00027 typedef int(GUTHTHILA_CALL * GUTHTHILA_READ_INPUT_CALLBACK)(
    00028         guththila_char_t *buffer,
    00029         int size,
    00030         void *ctx);
    00031
    00032 enum guththila_reader_type
    00033 {
    00034     GUTHTHILA_FILE_READER = 1,
    00035         GUTHTHILA_IO_READER,
    00036         GUTHTHILA_MEMORY_READER
    00037 };
    00038
    00039 typedef struct guththila_reader_s
    00040 {
    00041     int type;                           /* Type of reader */
    00042     FILE *fp;                           /* File pointer */
    00043     guththila_char_t *buff;     /* Buffer */
    00044     int buff_size;                      /* Buff size */
    00045         GUTHTHILA_READ_INPUT_CALLBACK input_read_callback;      /* Call back */
    00046     void *context;                      /* Context */
    00047 } guththila_reader_t;
    00048
    00049 #ifndef GUTHTHILA_READER_SET_LAST_START
    00050 #define GUTHTHILA_READER_SET_LAST_START(_reader, _start) ((_reader)->start = _start)
    00051 #endif
    00052
    00053 #ifndef GUTHTHILA_READER_STEP_BACK
    00054 #define GUTHTHILA_READER_STEP_BACK(_reader) ((_reader->next--))
    00055 #endif
    00056
    00057 /*
    00058  * Reading a file.
    00059  * @param filename      name of the file
    00060  * @param env environment
    00061  */
    00062 GUTHTHILA_EXPORT guththila_reader_t * GUTHTHILA_CALL
    00063 guththila_reader_create_for_file(guththila_char_t *filename,
    00064         const axutil_env_t * env);
    00065
    00066 /*
    00067  * Reading from a call back function.
    00068  * @param input_read_callback function pointer to read data
    00069  * @param ctx context
    00070  * @param env environment
    00071  */
    00072 GUTHTHILA_EXPORT guththila_reader_t * GUTHTHILA_CALL
    00073 guththila_reader_create_for_io(GUTHTHILA_READ_INPUT_CALLBACK
    00074         input_read_callback, void *ctx,
    00075         const axutil_env_t * env);
    00076
    00077 /*
    00078  * Reading from memory buffer.
    00079  * @param buffer buffer
    00080  * @param size  size of the buffer
    00081  * @param env environment
    00082  */
    00083 GUTHTHILA_EXPORT guththila_reader_t * GUTHTHILA_CALL
    00084 guththila_reader_create_for_memory(void *buffer,
    00085         int size,
    00086         const axutil_env_t * env);
    00087
    00088 /*
    00089  * Read the specified number of character to the given buffer.
    00090  * @param r reader
    00091  * @param buffer buffer to place the read data
    00092  * @param offset position to place the data on the given buffer
    00093  * @param length number of bytes to read
    00094  * @param env environment
    00095  * @return number of bytes put in to the buffer. -1 if end of the read.
    00096  */
    00097 GUTHTHILA_EXPORT int GUTHTHILA_CALL  guththila_reader_read(
    00098     guththila_reader_t * r,
    00099     guththila_char_t * buffer,
    00100     int offset,
    00101     int length,
    00102     const axutil_env_t * env);
    00103
    00104 /*
    00105  * Free the reader.
    00106  * @param r reader
    00107  * @param env environment
    00108  */
    00109 GUTHTHILA_EXPORT void GUTHTHILA_CALL  guththila_reader_free(
    00110     guththila_reader_t * r,
    00111     const axutil_env_t * env);
    00112
    00113 EXTERN_C_END()
    00114 #endif  /*  */
    00115