Miscellaneous macros and functions

Name

Miscellaneous macros and functions -- Various utilities.

Synopsis


#include <gts.h>


#define     GTS_COMMENTS

            GtsFile;
enum        GtsTokenType;
            GtsFileVariable;

GtsFile*    gts_file_new                    (FILE *fp);
void        gts_file_next_token             (GtsFile *f);
void        gts_file_first_token_after      (GtsFile *f,
                                             GtsTokenType type);
void        gts_file_assign_start           (GtsFile *f,
                                             GtsFileVariable *vars);
GtsFileVariable* gts_file_assign_next       (GtsFile *f,
                                             GtsFileVariable *vars);
void        gts_file_assign_variables       (GtsFile *f,
                                             GtsFileVariable *vars);
gint        gts_file_getc                   (GtsFile *f);
gint        gts_file_getc_scope             (GtsFile *f);
guint       gts_file_read                   (GtsFile *f,
                                             gpointer ptr,
                                             guint size,
                                             guint nmemb);
void        gts_file_variable_error         (GtsFile *f,
                                             GtsFileVariable *vars,
                                             const gchar *name,
                                             const gchar *format,
                                             ...);
void        gts_file_verror                 (GtsFile *f,
                                             const gchar *format,
                                             va_list args);
void        gts_file_error                  (GtsFile *f,
                                             const gchar *format,
                                             ...);
void        gts_file_destroy                (GtsFile *f);

Description

The gts_get_token() and gts_get_newline() functions are used for parsing GTS geometric files.

Details

GTS_COMMENTS

#define GTS_COMMENTS  "#!"

Set of characters used as comments identifiers in GTS geometric files.


GtsFile

typedef struct {
  FILE * fp;
  gchar * s, * s1;
  guint line, pos;
  GString * token;
  GtsTokenType type;
  gchar * error;

  guint curline, curpos;
  guint scope, scope_max;
  gint next_token;
  gchar * delimiters;
  gchar * comments;
  gchar * tokens;
} GtsFile;


enum GtsTokenType

typedef enum {
  GTS_NONE   = 1 << 8,
  GTS_INT    = 1 << 9,
  GTS_UINT   = 1 << 10,
  GTS_FLOAT  = 1 << 11,
  GTS_DOUBLE = 1 << 12,
  GTS_STRING = 1 << 13,
  GTS_FILE   = 1 << 14,
  GTS_ERROR  = 1 << 15
} GtsTokenType;


GtsFileVariable

typedef struct {
  GtsTokenType type;
  gchar name[30];
  gboolean unique;
  gpointer data;
  gboolean set;
  guint line, pos;
} GtsFileVariable;


gts_file_new ()

GtsFile*    gts_file_new                    (FILE *fp);

fp :

a file pointer.

Returns :

a new GtsFile.


gts_file_next_token ()

void        gts_file_next_token             (GtsFile *f);

Reads next token from f and updates its token and delim fields.

f :

a GtsFile.


gts_file_first_token_after ()

void        gts_file_first_token_after      (GtsFile *f,
                                             GtsTokenType type);

Finds and sets the first token of a type different from type occuring after a token of type type.

f :

a GtsFile.

type :

a GtsTokenType.


gts_file_assign_start ()

void        gts_file_assign_start           (GtsFile *f,
                                             GtsFileVariable *vars);

Opens a block delimited by braces to read a list of optional arguments specified by vars.

If an error is encountered the error field of f is set.

f :

a GtsFile.

vars :

a GTS_NONE terminated array of GtsFileVariable.


gts_file_assign_next ()

GtsFileVariable* gts_file_assign_next       (GtsFile *f,
                                             GtsFileVariable *vars);

Assigns the next optional argument of vars read from f.

f :

a GtsFile.

vars :

a GTS_NONE terminated array of GtsFileVariable.

Returns :

the variable of vars which has been assigned or NULL if no variable has been assigned (if an error has been encountered the error field of f is set).


gts_file_assign_variables ()

void        gts_file_assign_variables       (GtsFile *f,
                                             GtsFileVariable *vars);

Assigns all the variables belonging to vars found in f.

If an error is encountered the error field of f is set.

f :

a GtsFile.

vars :

an array of GtsFileVariable.


gts_file_getc ()

gint        gts_file_getc                   (GtsFile *f);

f :

a GtsFile.

Returns :

the next character in f or EOF if the end of the file is reached or if an error occured.


gts_file_getc_scope ()

gint        gts_file_getc_scope             (GtsFile *f);

f :

a GtsFile.

Returns :

the next character in f in the scope defined by f->scope_max or EOF if the end of the file is reached or if an error occured.


gts_file_read ()

guint       gts_file_read                   (GtsFile *f,
                                             gpointer ptr,
                                             guint size,
                                             guint nmemb);

Reads nmemb elements of data, each size bytes long, from f, storing them at the location given by ptr.

f :

a GtsFile.

ptr :

a pointer.

size :

size of an element.

nmemb :

number of elements.

Returns :

the number of elements read.


gts_file_variable_error ()

void        gts_file_variable_error         (GtsFile *f,
                                             GtsFileVariable *vars,
                                             const gchar *name,
                                             const gchar *format,
                                             ...);

Sets the error field of f using gts_file_verror().

String name must match one of the variable names in vars.

If variable name has been assigned (using gts_file_assign_variables()) sets the line and pos fields of f to the line and position where it has been assigned.

f :

a GtsFile.

vars :

an array of GtsFileVariable.

name :

the name of a variable in vars.

format :

the standard sprintf() format string.

... :

the parameters to insert into the format string.


gts_file_verror ()

void        gts_file_verror                 (GtsFile *f,
                                             const gchar *format,
                                             va_list args);

Sets the error field of f using g_strdup_vprintf().

This function can be called only once and disables any other operation on f (gts_file_close() excepted).

f :

a GtsFile.

format :

the standard sprintf() format string.

args :

the list of parameters to insert into the format string.


gts_file_error ()

void        gts_file_error                  (GtsFile *f,
                                             const gchar *format,
                                             ...);

Sets the error field of f using gts_file_verror().

This function can be called only once and disables any other operation on f (gts_file_close() excepted).

f :

a GtsFile.

format :

the standard sprintf() format string.

... :

the parameters to insert into the format string.


gts_file_destroy ()

void        gts_file_destroy                (GtsFile *f);

Frees all the memory allocated for f.

f :

a GtsFile.