From: Peter Verthez Date: Sat, 28 Dec 2002 17:00:35 +0000 (+0000) Subject: Updated documentation. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=c80fb171c952d002191509a343bb4c3747dffc35;p=gedcom-parse.git Updated documentation. --- diff --git a/doc/gom.html b/doc/gom.html index a0829bc..7358ad1 100644 --- a/doc/gom.html +++ b/doc/gom.html @@ -22,12 +22,13 @@ -
  • Other functions
  • +
  • Modifying the object model
  • Writing the object model to file
    +
  • - + @@ -125,7 +126,7 @@ tags is.  Each element of the linked list has:
    This way, none of the information in the GEDCOM file is lost, even the non-standard information.


    -

    Other functions

    +

    Modifying the object model

    Manipulating strings

    There are some functions available to retrieve and change strings in the @@ -170,6 +171,15 @@ want to know this.  You can pass NULL if you're not interested if an error occurred (e.g. if the given string is not a valid string for the current locale); in that case the target data variable is not modified.

    +

    Writing the object model to file
    +

    +Writing the current object model to a file is simply done using the following function:
    +
    int gom_write_file (const char* filename, int* total_conv_fails);
    +This writes the model to the file filename.  The second parameter can return the total number of conversion failures (pass NULL if you're not interested).
    +
    +The functions in this section can be used before gom_write_file to control some settings.
    +

    +
    $Id$
    $Name$

    @@ -183,4 +193,6 @@ the current locale); in that case the target data variable is not modified.



    +
    +
    \ No newline at end of file diff --git a/doc/interface.html b/doc/interface.html index d41fe7f..906aeea 100644 --- a/doc/interface.html +++ b/doc/interface.html @@ -2312,6 +2312,9 @@ the value that is returned by GEDCOM_STRING(val) is always the s
    +The following function creates a new date_value struct and initializes it properly, or copies an existing date value: +
    struct date_value* gedcom_new_date_value (struct date_value* copy_from);
    +If the parameter copy_from is NULL, a new value is created and given initial values.  If it is non-NULL, the value is copied into a new date value.

    struct date

    @@ -2415,10 +2418,85 @@ to DATE_BOUNDED.
    day numbers for "1 MAR 1990" and "31 MAR 1990", and the Gregorian date "1990" is represented by the serial day numbers for "1 JAN 1990" and "31 DEC 1990".  Similarly for the other calendar types.
    + +
    + +
    +To ensure that an updated date value is consistent, i.e. all +its struct fields are consistent with each other, the following function +can be used:
    +
    int gedcom_normalize_date (Date_input compute_from, struct date_value* value);
    + +The compute_from parameter determines which fields +will be taken as input to compute the other fields.  The following table +gives an overview of the input and output parameters (the calendar type cal is always an input parameter, and should not be CAL_UNKNOWN):
    +
    + + + + + + + + + + + + + + + + + + + + + + + +
    compute_from
    +
    input parameters
    +
    output parameters
    +
    DI_FROM_STRINGS
    +
    day_str, month_str, year_str
    +
    day, month, year, year_type
    +type, sdn1, sdn2

    +
    DI_FROM_NUMBERS
    +
    day, month, year, year_type
    +
    day_str, month_str, year_str
    + +type, sdn1, sdn2

    +
    DI_FROM_SDN
    +
    type, sdn1, sdn2
    +
    day, month, year
    +day_str, month_str, year_str

    +
    +
    +If the type in the date value is DV_PHRASE, no conversions take +place, otherwise one or both of the date structs are processed according +to the table above, depending on the type.  The function returns 0 in case of success, non-zero in case of an error.
    +
    +This function could also be used to convert a date from one calendar to another, +because the serial day number is calendar independent (error handling is +ignored in this example):
    +
    struct date_value* dv = gedcom_new_date_value(NULL);
    +dv->date1.cal = CAL_GREGORIAN;
    +dv->date1.day   = 4
    ;
    + dv->date1.month = 2;
    +dv->date1.year  = 1799;
    +dv->date1.year_type = YEAR_SINGLE;
    +gedcom_normalize_date(DI_FROM_NUMBERS, dv);
    +
    +dv->date1.cal = CAL_FRENCH_REV;
    +gedcom_normalize_date(DI_FROM_SDN, dv);
    +/* the day, month and year are now filled in according to the French Revolution calendar */

    +
    + +
    +
    + -
    -

    struct age_value

    This struct describes an age as given in the GEDCOM file, and has the @@ -2497,7 +2575,10 @@ The modifier can be one of the following:
    -
    +The following function creates a new age_value struct and initializes it properly, or copies an existing age value: +
    struct age_value* gedcom_new_age_value (struct age_value* copy_from);
    + +If the parameter copy_from is NULL, a new value is created and given initial values.  If it is non-NULL, the value is copied into a new age value.

    struct xref_value

    This struct represents a cross-reference in the GEDCOM file (but note that @@ -2609,4 +2690,5 @@ An example would thus be: "@This is an xref_val@".



    +
    \ No newline at end of file diff --git a/doc/usage.html b/doc/usage.html index 0a8c7e8..1c59ae9 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.
    @@ -412,6 +419,134 @@ raw_value, int parsed_tag)
    of the "upper" tags has been subscribed upon.
    +

    +

    Support for writing GEDCOM files

    +The Gedcom parser library also contains functions to writing GEDCOM files. + Similar as for the parsing itself, there are two interfaces: an interface +which is very basic, and requires you to call a function for each line in +the GEDCOM file, and an interface which just dumps the Gedcom object model +to a file in one shot (if you use the Gedcom object model).
    +
    +Again, this section focuses on the basic interface, the Gedcom object model interface is described here.
    +
    +

    Opening and closing files

    +The basic functions for opening and closing Gedcom files for writing are the following:
    + +
    Gedcom_write_hndl gedcom_write_open (const char* filename);
    +int               gedcom_write_close (Gedcom_write_hndl hndl, int* total_conv_fails);
    +The function gedcom_write_open takes a parameter the name of +the file to write, and returns a write handle, which needs to be used in +subsequent functions.  It returns NULL in case of errors.
    +
    +The function gedcom_write_close takes, next to the write handle, +an integer pointer as parameter.  If you pass an actual pointer for +this, the function will write in it the total number of conversion failures; +you can pass NULL if you're not interested.  The function returns 0 in case of success, non-zero in case of failure.
    +
    +

    Controlling some settings
    +

    +Note that by default the file is written in ASCII encoding (and hence e.g. +accented characters will cause a conversion failure).  You can change +this by calling the following function before calling gedcom_write_open, i.e. it affects all files that are opened after it is being called:
    +
    +
    int gedcom_write_set_encoding (const char* charset, Encoding width, Enc_bom bom);
    +The valid charset values are given in the first column in the file gedcom.enc in the data directory of gedcom-parse ($PREFIX/share/gedcom-parse). + The character sets UNICODE, ASCII and ANSEL are always supported (these +are standard for GEDCOM), as well as ANSI (not standard), but there may be +others.
    +
    +The width parameter takes one of the following values:
    + + +The bom parameter determines whether a byte-order-mark should +be written in the file in case of UNICODE encoding (usually preferred because +it then clearly indicates the byte ordering).  It takes one of the following +values:
    + +For both these parameters you can pass 0 for non-UNICODE encodings, since +that corresponds to the correct values (and is ignored anyway).  The +function returns 0 in case of success, non-zero in case of error.
    +
    +Further, it is possible to control the kind of line terminator that is used, via the following function (also to be used before gedcom_write_open):
    +
    int gedcom_write_set_line_terminator (Enc_line_end end);
    +The end parameter takes one of the following values:
    + +By default, this is set to the appropriate line terminator on the current +platform, so it only needs to be changed if there is some special reason +for it.
    +

    Writing data
    +

    +For actually writing the data, the principle is that every line in the GEDCOM +file to write corresponds to a call to one of the following functions, except +that CONT/CONC lines can be automatically taken care of.  Note that +the resulting GEDCOM file should conform to the GEDCOM standard.  Several +checks are built in already, and more will follow, to force this.  There +is (currently) no compatibility mode for writing GEDCOM files.
    +
    +In general, each of the following functions expect their input in UTF-8 encoding (see also here).  If this is not the case, errors will be returned.
    +
    +Note that for examples of using these functions you can look at the sources for the Gedcom object model (e.g. the function write_header in gom/header.c).
    +

    Records

    +For writing lines corresponding to records (i.e. on level 0), the following function is available: +
    int gedcom_write_record_str (Gedcom_write_hndl hndl, Gedcom_rec rec, char* xrefstr, char* value);
    +The hndl parameter is the write handle that was returned by gedcom_write_open.  The rec parameter is one of the identifiers given in the first column in this table (except REC_USER: see below).  The xrefstr and val parameters are respectively the cross-reference key of the record (something like '@FAM01@'), and the value of the record line, which should be NULL for some record types, according to the same table.
    +

    Elements

    +For writing lines corresponding to elements (inside records, i.e. on a level +bigger than 0), the following functions are available, depending on the data +type: +
    int gedcom_write_element_str  (Gedcom_write_hndl hndl, Gedcom_elt elt, int parsed_tag,
    +                      +         int parent_rec_or_elt, char* value);
    +i
    nt gedcom_write_element_xref (Gedcom_write_hndl hndl, Gedcom_elt elt, int parsed_tag,
    +                      +         int parent_rec_or_elt, struct xref_value* +value);

    + int gedcom_write_element_date (Gedcom_write_hndl hndl, Gedcom_elt elt, int parsed_tag,
    +                      +         int parent_rec_or_elt, struct date_value* +value);

    + int gedcom_write_element_age  (Gedcom_write_hndl hndl, Gedcom_elt elt, int parsed_tag,
    +                      +         int parent_rec_or_elt, struct age_value* +value);

    +
    +
    +These functions only differ in the type of the last argument, which is the value of the element.
    +
    +The hndl parameter is again the write handle returned by gedcom_write_open.  The elt parameter is one of the identifiers given in the first column in this table (except ELT_USER: see below).  The parent_rec_or_elt is the corresponding rec or elt +identifier of the logically enclosing statement: this will determine the +level number written on the line, as the level number of the parent + 1.
    +
    +Some of the identifiers can actually stand for different tags.  For this reason, the parsed_tag has to be passed for some of them.  This parsed tag is the same as was returned by the callback functions defined above, and is an identifier of the form TAG_name.  This parameter is needed whenever the second column in this table shows several possible tags (this is e.g. the case for ELT_SUB_FAM_EVT).
    +
    +Note that for writing a date value, the given value should be valid, i.e. +all its struct fields filled in properly and consistent.  This can be +done by calling gedcom_normalize_date (see here).
    +

    User-defined tags

    +For user-defined tags (tags starting with an underscore), there are separate functions, again depending on the data type: +
    int gedcom_write_user_str  (Gedcom_write_hndl hndl, int level, char* tag, char* xrefstr,
    +                            char* value);
    +i
    nt gedcom_write_user_xref (Gedcom_write_hndl hndl, int level, char* tag, char* xrefstr,
    + +                            struct xref_value* value);
    +
    +In the case of user-defined tags, the level and tag string are passed verbatim +(not controlled by the library).  This allows to write any extra data +that doesn't use a standard tag, but is only allowed for tags starting with +an underscore.

    Other API functions
    @@ -512,189 +647,17 @@ 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 a library implementing help functions for UTF-8 encoding (see -the "utf8" subdirectory of the top directory).   Feel free to use - it in your source code.  It isn't installed anywhere, so you need -to take over the source and header files in your application. Note that on -some systems it uses libcharset, which is also included in this subdirectory. -  
    -
    - Its interface contains first of all the following two help functions:
    - -
    -
    int   is_utf8_string (char *input);
    int utf8_strlen (char *input);
    The -first one returns 1 if the given input is a valid UTF-8 string, it returns -0 otherwise, the second gives the number of UTF-8 characters in the given -input.  Note that the second function assumes that the input is valid -UTF-8, and gives unpredictable results if it isn't.
    -
    -For conversion, the following functions are available:
    -
    -
    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:
    - -
      -
    • Make sure from the beginning - that the output buffer is big enough.  However, it's difficult to find - an absolute maximum length in advance, even given the length of the input - string.
      -
      -
    • -
    • Do the conversion in several - steps, growing the output buffer each time to make more space, and calling - iconv consecutively until the conversion is complete. -  This is the preferred way (a function could be written to encapsulate - all this).
    • - -
    - 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:
    - -
      -
    • Just fail the conversion, -and show an error.  This is not very user friendly, of course.
      -
      -
    • -
    • Skip over the character that - can't be converted and append a "?" to the output buffer, then call - iconv again.  Skipping over a UTF-8 character is fairly simple, - as follows from the encoding rules - :
    • - -
    - -
      - -
        -
      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:
    @@ -727,6 +690,20 @@ There are three preprocessor symbols defined for version checks in the The last one is equal to (GEDCOM_PARSE_VERSION_MAJOR * 1000) + GEDCOM_PARSE_VERSION_MINOR.
    +
    +

    Compilation and linking flags

    +Similar to other libraries, the GEDCOM parse library installs a script gedcom-config to help with compilation and linking flags.
    +
    +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

    +
    +
    @@ -743,4 +720,6 @@ There are three preprocessor symbols defined for version checks in the


    +
    +
    \ No newline at end of file