X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=doc%2Fusage.html;h=44bdb95f340ff8f32f71773c645385d81054959f;hb=60282b9f2f1326231ea5019e239d00bdccd6608b;hp=dc2e70ad7d9f03ebde68f0f2b722ca9caf204076;hpb=cf04c144fa910f52d44ef33d2fa9a03f912efa2e;p=gedcom-parse.git diff --git a/doc/usage.html b/doc/usage.html index dc2e70a..44bdb95 100644 --- a/doc/usage.html +++ b/doc/usage.html @@ -17,7 +17,14 @@
  • Start and end callbacks
  • Default callbacks
  • -
  • Other API functions
  • +
  • Support for writing GEDCOM files
  • + +
  • Other API functions
  • Converting character sets
  • -
  • Support for configure.in
    +
  • Development support

  • Interface details of the callback parser
  • C object model
    @@ -57,9 +64,9 @@ application program, which implements the callback parser
  • - - - Next to these, there is also a data directory in $PREFIX/share/gedcom-parse +There is a separate script to help with library and compilation flags, see the development support.
    +
    +Next to these, there is also a data directory in $PREFIX/share/gedcom-parse that contains some additional stuff, but which is not immediately important at first.  I'll leave the description of the data directory for later.
    @@ -102,8 +109,9 @@ the -lgedcom option on the linking of the program as the last option, so that its initialization code is run first.  In the case of using the C object model, the linking options should be: -lgedcom_gom -lgedcom
    -
    - The next sections will refine this piece of code to be able to have +
    The function gedcom_init() also initializes locale handling by calling setlocale(LC_ALL, ""), in case the application would not do this (it doesn't hurt for the application to do the same).

    +The next sections will refine this piece of code to be able to have meaningful errors and the actual data that is in the file.

    @@ -155,7 +163,7 @@ out of the GEDCOM file.  This section focuses on the callback mechanism is called for that tag, and when all its subordinate lines with their tags have been processed, the "end element" callback is called for the original tag.  Since GEDCOM is hierarchical, this results in properly -nested calls to appropriate "start element" and "end element" callbacks.
    +nested calls to appropriate "start element" and "end element" callbacks (note: see compatibility handling).

    However, it would be typical for a genealogy program to support only a subset of the GEDCOM standard, certainly a program that is still under @@ -328,7 +336,9 @@ in the section for record callbacks above.
    - Currently, there is a beginning for compatibility for ftree and Lifelines (3.0.2).
    + Currently, there is (some) compatibility for:
    + +The following function allows to set some options for the compatibility handling:
    +
    void gedcom_set_compat_options (Gedcom_compat options)
    +
    +The parameter can be an OR'ed combination of the following options:
    + +
    +
    In some compatibility cases, tags are coming out-of-order, +i.e. their start element callback would have to come after the end element +callback of the parent tag.  E.g. instead of the standard GEDCOM
    +
    1 DATE ...
    +2 TIME ...

    +
    +the genealogy program has generated something like:
    +
    1 DATE ...
    +1 TIME ...

    +
    +This can give a problem if your end element callbacks free some resources.  
    +
    +If your program can handle elements out of context, you can enable this option. + By default it is disabled, and so the values of these out-of-context +tags are lost (the parser generates a warning if this is the case).  The Gedcom object model in C has this option enabled.
    +
    +
    +
    +

    Converting character sets

    @@ -511,185 +697,37 @@ default)
    the locale mechanism (i.e. via the LANG, LC_ALL or LC_CTYPE environment variables), which also controls the gettext mechanism in the application.  
    -
    -
    - - The source distribution of -gedcom-parse contains an example implementation (utf8-locale.c - and utf8-locale.h in the "t" subdirectory of the top directory).  - Feel free to use it in your source code (it is not part of the library, -and it isn't installed anywhere, so you need to take over the source and -header file in your application).  
    -
    - Its interface is:
    - -
    -
    char *convert_utf8_to_locale (char *input, int *conv_failures);
    char *convert_locale_to_utf8 (char *input);
    -
    - Both functions return a pointer to a static buffer that is overwritten - on each call.  To function properly, the application must first set -the locale using the setlocale function (the second step detailed - below).  All other steps given below, including setting up and closing - down the conversion handles, are transparantly handled by the two functions. -  
    -
    - If you pass a pointer to an integer to the first function, it will be -set to the number of conversion failures, i.e. characters that couldn't -be converted; you can also just pass NULL if you are not interested -(note that usually, the interesting information is just whether there -were conversion failures or not, which is then given by the integer -being bigger than zero or not).  The second function doesn't need this, -because any locale can be converted to UTF-8.
    -
    - You can change the "?" that is output for characters that can't be converted - to any string you want, using the following function before the conversion - calls:
    - -
    -
    void convert_set_unknown (const char *unknown);
    -
    -
    - If you want to have your own functions for it instead of this example -implementation, the following steps need to be taken by the application -(more detailed info can be found in the info file of the GNU libc library -in the "Generic Charset Conversion" section under "Character Set Handling" -or online - here):
    - - - -
    -
    -
    #include <locale.h>    /* for setlocale */
    #include <langinfo.h> /* for nl_langinfo */
    #include <iconv.h> /* for iconv_* functions */
    -
    -
    - - - -
    -
    -
    setlocale(LC_ALL, "");
    -
    -
    - - - -
    -
    -
    iconv_t iconv_handle;
    ...
    iconv_handle = iconv_open(nl_langinfo(CODESET), "UTF-8");

    if (iconv_handle == (iconv_t) -1)
    /* signal an error */
    -
    -
    - - - -
    -
    -
    /* char* in_buf is the input buffer,    size_t in_len is its length */
    /* char* out_buf is the output buffer, size_t out_len is its length */

    size_t nconv;
    char *in_ptr = in_buf;
    char *out_ptr = out_buf;
    nconv = iconv(iconv_handle, &in_ptr, &in_len, &out_ptr, &out_len);
    -
    -
    - -
    If the output buffer is not big enough, iconv will - return -1 and set errno to E2BIG.  Also, -the in_ptr and out_ptr will point just after -the last successfully converted character in the respective buffers, and -the in_len and out_len will be updated to show -the remaining lengths.  There can be two strategies here:
    - - - Another error case is when the conversion was unsuccessful (if one of -the characters can't be represented in the target character set).  The - iconv function will then also return -1 and set errno - to EILSEQ; the in_ptr will point to the character - that couldn't be converted.  In that case, again two strategies are -possible:
    - - - -
      - -
        -
      1. if the first byte is in -binary 0xxxxxxx, then the character is only one byte long, just skip over -that byte
        -
        -
      2. -
      3. if the first byte is in -binary 11xxxxxx, then skip over that byte and all bytes 10xxxxxx that follow.
        -
      4. - -
      - -
    -
    - - - -
    -
    -
    iconv_close(iconv_handle);
    -
    -
    - The example implementation - mentioned above grows the output buffer dynamically and outputs "?" for characters - that can't be converted.
    +
    With +gedcom-parse comes a library implementing help functions for UTF-8 encoding (see +the documentation for this library).

    -

    Support for configure.in

    There +

    Development support

    +

    Macro for configure.in
    +

    +There is a macro available for use in configure.in for applications that are using autoconf to configure their sources.  The following macro checks whether the Gedcom parser library is available and whether its version is high enough:
    -
    AM_LIB_GEDCOM_PARSER([major,[minor,[patch]]])
    +
    AM_PATH_GEDCOM_PARSER([min_version,[action_if_found,[action_if_not_found,[modules]]]])
    All the arguments are optional and default to 0.  E.g. to check for -version 1.34, you would put in configure.in the following statement:
    -
    AM_LIB_GEDCOM_PARSER(1,34)
    +version 1.34.2, you would put in configure.in the following statement:
    +
    AM_PATH_GEDCOM_PARSER(1.34.2)
    +
    Note that version numbers now contains three parts (since version +0.20.0: this is also the first version in which this macro is available).
    +
    +The macro also sets the variables GEDCOM_CFLAGS and GEDCOM_LIBS for use in Makefiles.  Typically, this would be done as follows in a Makefile.am:
    +
    bin_programs   = myprg
    + myprg_SOURCES  = myprg.c foo.c bar.c
    +INCLUDES       = @GEDCOM_CFLAGS@
    +LDADD          = @GEDCOM_LIBS@
    +If your program uses some extra modules, they can be passed as fourth argument +in the macro, so that the CFLAGS and LIBS are correctly filled in.  Currently, +the only available module is gom (the Gedcom object model).  For example:
    +
    AM_PATH_GEDCOM_PARSER(0.21.2, , ,gom)
    To be able to use this macro in the sources of your application, you have three options:
    - The last one is equal to (GEDCOM_PARSE_VERSION_MAJOR * 1000) + GEDCOM_PARSE_VERSION_MINOR.
    + The last one is equal to (GEDCOM_PARSE_VERSION_MAJOR * 1000) + GEDCOM_PARSE_VERSION_MINOR. As you see, this only checked the major and minor version, not the patch number, so this is obsolete.
    +
    +

    Compilation and linking flags

    +Similar to other libraries, the GEDCOM parse library installs a script gedcom-config to help with compilation and linking flags for programs that don't use autoconf/automake.
    +
    +To get compilation flags for your program, use (depending on whether you +only use the callback parser, or also the GEDCOM object model): +
    gedcom-config --cflags
    +gedcom-config --cflags gom

    +
    +Similarly, to get linking flags, use one of the following: +
    gedcom-config --libs
    +gedcom-config --libs gom

    +
    +
    @@ -724,6 +776,14 @@ There are three preprocessor symbols defined for version checks in the
                        
    +
    +
    +
    +
    +
    +
    +
    +