Sophie

Sophie

distrib > Mandriva > 10.0-com > i586 > by-pkgid > 0453bcaf7bb5ad036996f9b24ca9fa16 > files > 100

gaby-2.0.2-4mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>Format</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Gaby's documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Gaby Developers' Guide"
HREF="p489.html"><LINK
REL="PREVIOUS"
TITLE="An action"
HREF="x822.html"><LINK
REL="NEXT"
TITLE="File saving"
HREF="x886.html"></HEAD
><BODY
CLASS="CHAPTER"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Gaby's documentation</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x822.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x886.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="PLUGIN-FORMAT"
></A
>Chapter 11. Format</H1
><P
>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)).</P
><P
>Gaby is really simple since the two functions you will have to define are
<CODE
CLASS="FUNCTION"
>load_file</CODE
> and <CODE
CLASS="FUNCTION"
>save_file</CODE
>. It's even so
simple that I'd like to say you "read the source, Luke"
(<TT
CLASS="FILENAME"
>vcard.c</TT
> is around 6k long and is a good example).</P
><P
>Alternatively the functions can be named 
<CODE
CLASS="FUNCTION"
>&lt;plugin name&gt;_load_file</CODE
> and
<CODE
CLASS="FUNCTION"
>&lt;plugin name&gt;_save_file</CODE
>. This alternative may become
the standard way so you'd better use it.</P
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="AEN852"
>11.1. File loading</A
></H1
><P
>&#13;<DIV
CLASS="FUNCSYNOPSIS"
><P
></P
><A
NAME="AEN855"
></A
><CODE
CLASS="FUNCDEF"
>gboolean load_file</CODE
>(struct location* loc);<P
></P
></DIV
>

is what you will have to define in your plug-in to load a file.&#13;</P
><P
>&#13;<CODE
CLASS="STRUCTNAME"
>struct location</CODE
> is defined in
<TT
CLASS="FILENAME"
>gaby.h</TT
> as :

<PRE
CLASS="PROGRAMLISTING"
>struct location {
        gchar *filename;
        gchar *type;
        int max_index;
        int offset;
        int reread;
        int timeout_tag;
        gboolean readonly;
        gboolean disabled;
        table *table;
};</PRE
>

You may ignore everything except <CODE
CLASS="STRUCTFIELD"
>filename</CODE
> and
<CODE
CLASS="STRUCTFIELD"
>table</CODE
>.

<P
></P
><UL
><LI
><P
><CODE
CLASS="STRUCTFIELD"
>filename</CODE
> hold the name of the file you have to read;</P
></LI
><LI
><P
><CODE
CLASS="STRUCTFIELD"
>table</CODE
> hold the table in which you'll put records you
read.</P
></LI
></UL
>&#13;</P
><P
>Another thing you have to know is (logically) the
<CODE
CLASS="STRUCTNAME"
>record</CODE
> structure. </P
><P
>As soon as you know that the process is really simple :

<P
></P
><OL
TYPE="1"
><LI
><P
>Read a record from <CODE
CLASS="STRUCTFIELD"
>loc-&#62;filename</CODE
></P
></LI
><LI
><P
>Store this record in a <CODE
CLASS="STRUCTNAME"
>record</CODE
> structure.</P
></LI
><LI
><P
>Call <CODE
CLASS="FUNCTION"
>record_add</CODE
></P
></LI
></OL
></P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x822.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x886.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>An action</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="p489.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>File saving</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>