>Miscellaneous macros and functions

Miscellaneous macros and functions

Name

Miscellaneous macros and functions -- Various utilities.

Synopsis


#include <gts.h>


#define     GTS_COMMENTS

struct      GtsFile;
enum        GtsTokenType;
struct      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);
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.


struct GtsFile

struct GtsFile {
  FILE * fp;
  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;
};


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;


struct GtsFileVariable

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


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_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.