Chapter 14. Format

Table of Contents
File loading
File saving

You need two things to handle a file format : loading and saving. One day you won't even have to provide a way to save informations because it will be possible to load a file in a format and save it in another one (this might even work in the other way (saving but no loading but I tend to prefer the first one)).

Gaby is really simple since the two functions you will have to define are load_file and save_file. It's even so simple that I'd like to say you "read the source, Luke" (vcard.c is around 6k long and is a good example).

Alternatively the functions can be named <plugin name>_load_file and <plugin name>_save_file. This alternative may become the standard way so you'd better use it.

File loading

gboolean load_file(struct location* loc);

is what you will have to define in your plug-in to load a file.

struct location is defined in gaby.h as :
struct location {
        gchar *filename;
        gchar *type;
        int max_index;
        int offset;
        int reread;
        int timeout_tag;
        gboolean readonly;
        gboolean disabled;
        table *table;
};
You may ignore everything except filename and table.

Another thing you have to know is (logically) the record structure.

As soon as you know that the process is really simple :

  1. Read a record from loc->filename

  2. Store this record in a record structure.

  3. Call record_add