mdcore  0.1.5
Defines | Functions | Variables
/home/pedro/work/mdcore/src/reader.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <alloca.h>
#include "../config.h"
#include "errs.h"
#include "reader.h"

Defines

#define error(r, id)   reader_error( r , id , __LINE__ , __FUNCTION__ )

Functions

int reader_error (struct reader *r, int id, int line, const char *function)
int reader_getc (struct reader *r)
 Read the next char.
int reader_getline (struct reader *r, char *buff, int buff_size)
 Read until a newline.
int reader_skipline (struct reader *r)
 Skip until a newline.
int reader_iscomm_stop (struct reader *r, int c)
 Check if a character is a comment stop.
int reader_iscomm_start (struct reader *r, int c)
 Check if a character is a comment start.
int reader_isws (struct reader *r, int c)
 Check if a character is whitespace.
int reader_getcomment (struct reader *r, char *buff, int buff_size)
 Read the next comment from the given reader.
int reader_skipcomment (struct reader *r)
 Skip the next comment from the given reader.
int reader_gettoken (struct reader *r, char *buff, int buff_size)
 Read a token from the given reader.
int reader_skiptoken (struct reader *r)
 Skip a token from the given reader.
int reader_init (struct reader *r, FILE *file, char *ws, char *comm_start, char *comm_stop)
 Initialize the reader.

Variables

int reader_err = reader_err_ok
char * reader_err_msg [6]
char reader_buff [100]

Define Documentation

#define error (   r,
  id 
)    reader_error( r , id , __LINE__ , __FUNCTION__ )

Function Documentation

int reader_error ( struct reader r,
int  id,
int  line,
const char *  function 
)
int reader_getc ( struct reader r)

Read the next char.

Parameters:
rThe reader.
Returns:
The next character or < 0 on error (see reader_err).
int reader_getcomment ( struct reader r,
char *  buff,
int  buff_size 
)

Read the next comment from the given reader.

Parameters:
rthe reader.
buffPointer to char at which to store the token.
buff_sizeSize of the buff.
Returns:
The number of read characters or < 0 on error (see reader_err).
int reader_getline ( struct reader r,
char *  buff,
int  buff_size 
)

Read until a newline.

Parameters:
rThe reader.
buffPointer to char at which to store the token.
buff_sizeSize of the buff.
Returns:
The number of read characters or < 0 on error (see reader_err).
int reader_gettoken ( struct reader r,
char *  buff,
int  buff_size 
)

Read a token from the given reader.

Parameters:
rThe reader.
buffPointer to char at which to store the token.
buff_sizeSize of the buff.
Returns:
The number of read characters or < 0 on error (see reader_err).
int reader_init ( struct reader r,
FILE *  file,
char *  ws,
char *  comm_start,
char *  comm_stop 
)

Initialize the reader.

Parameters:
rThe reader structure.
fileThe FILE with which the reader should be associated.
wsString containing the accepted whitespace characters.
comm_startString containing characters indicating the start of a comment.
comm_stopString containing characters indicating the end of a comment.

The FILE supplied should be open and will be read as of its current position.

Returns:
reader_err_ok or < 0 on error (see reader_err).
int reader_iscomm_start ( struct reader r,
int  c 
)

Check if a character is a comment start.

Parameters:
rThe reader.
cThe character to verify.
Returns:
1 if c is in the comm_start of the reader r or 0 otherwise.
int reader_iscomm_stop ( struct reader r,
int  c 
)

Check if a character is a comment stop.

Parameters:
rThe reader.
cThe character to verify.
Returns:
1 if c is in the comm_stop of the reader r or 0 otherwise.
int reader_isws ( struct reader r,
int  c 
)

Check if a character is whitespace.

Parameters:
rThe reader.
cThe character to verify.
Returns:
1 if c is in the comm_stop of the reader r or 0 otherwise.
int reader_skipcomment ( struct reader r)

Skip the next comment from the given reader.

Parameters:
rthe reader.
Returns:
The number of read characters or < 0 on error (see reader_err).
int reader_skipline ( struct reader r)

Skip until a newline.

Parameters:
rThe reader.
Returns:
The number of read characters or < 0 on error (see reader_err).
int reader_skiptoken ( struct reader r)

Skip a token from the given reader.

Parameters:
rThe reader.
Returns:
The number of read characters or < 0 on error (see reader_err).

Variable Documentation

char reader_buff[100]

ID of the last error

char* reader_err_msg[6]
Initial value:
 {
        "Nothing bad happened.",
    "An unexpected NULL pointer was encountered.",
    "A call to malloc failed, probably due to insufficient memory.",
    "An input-output error occurred.",
    "Maximum buffer size reached.",
    "End of file reached.",
        }
 All Data Structures Files Functions Variables Typedefs Enumerator Defines