X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=doc%2Fusage.html;h=225470e6c4f56daf6ef2d4a947abfe05a1eebb7c;hb=560a739640bb8ab266e1335afb9a8cef9eb4f1aa;hp=ee3e248bae1331b1f9d175c2320c416ef024881d;hpb=7372fd1bb10934271adbb12fe27f45df8ea225d2;p=gedcom-parse.git diff --git a/doc/usage.html b/doc/usage.html index ee3e248..225470e 100644 --- a/doc/usage.html +++ b/doc/usage.html @@ -17,15 +17,14 @@
$PREFIX/share/gedcom-parse
+There is a separate script to help with library and compilation flags, see the development support.$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.-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
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).gom_parse_file()
. For this, an entire model based on C structs is used. These structs are documented here,
-and follow the GEDCOM syntax quite closely. Each of the records in
-a GEDCOM file are modelled by a separate struct, and some common sub-structures
-have their own struct definition.
+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.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.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.width
parameter takes one of the following values:struct header* gom_get_header();
-struct submission* gom_get_submission();
-
- -struct XXX* gom_get_first_XXX();
-struct XXX* gom_get_XXX_by_xref(char* xref);
-
The XXX stands for one of the following:-family,
individual, multimedia, note, repository, source, submitter, user_rec
.
-
ONE_BYTE
: This should be used for all character sets except UNICODE.TWO_BYTE_HILO
: High-low encoding for UNICODE (i.e. big-endian)TWO_BYTE_LOHI
: Low-high encoding for UNICODE (i.e. little-endian)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:WITHOUT_BOM
WITH_BOM
gedcom_write_open
):int gedcom_write_set_line_terminator (Enc_line_end end);
+The end
parameter takes one of the following values:END_CR
: only carriage return ("/r") (cf. Macintosh)END_LF
: only line feed ("/n") (cf. Unix, Mac OS X)END_CR_LF
: first carriage return, then line feed ("/r/n") (cf. DOS, Windows)END_LF_CR
: first line feed, then carriage return ("/n/r")next
member of the structs. This means that e.g. the following piece of code will traverse the linked list of family records:-Thestruct family* fam;
-
-for (fam = gom_get_first_family() ; fam ; fam = fam->next) {
- ...
-}
-
next
member of the last element in the list is guaranteed to have the NULL
value.previous
member. But for implementation reasons the behaviour of this previous
member on the edges of the linked list will not be guaranteed, i.e. it can be circular or terminated with NULL
, no assumptions can be made in the application code.next
and previous
-member following the above conventions. This means that the following
-piece of code traverses all children of a family (see the details of the
-different structs here):struct family* fam = ...;
-
-struct xref_list* xrl;
-for (xrl = fam->children ; xrl ; xrl = xrl->next) {
- ...
-}
+Note that for examples of using these functions you can look at the sources for the Gedcom object model (e.g. the functionwrite_header
ingom/header.c
).
+Records
+For writing lines corresponding to records (i.e. on level 0), the following function is available: ++Theint gedcom_write_record_str (Gedcom_write_hndl hndl, Gedcom_rec rec, char* xrefstr, char* value);
hndl
parameter is the write handle that was returned bygedcom_write_open
. Therec
parameter is one of the identifiers given in the first column in this table (exceptREC_USER
: see below). Thexrefstr
andval
parameters are respectively the cross-reference key of the record (something like '@FAM01@
'), and the value of the record line, which should beNULL
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: +-Note that all character strings in the object model are encoded in UTF-8 (Why UTF-8?).int gedcom_write_element_str (Gedcom_write_hndl hndl, Gedcom_elt elt, int parsed_tag,
+ + int parent_rec_or_elt, char* value);
+int 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);
+i
nt gedcom_write_element_age (Gedcom_write_hndl hndl, Gedcom_elt elt, int parsed_tag,
+ + int parent_rec_or_elt, struct age_value* +value);
-User data
-Each of the structs has an extra member calledextra
(of typestruct user_data*
). - This gathers all non-standard GEDCOM tags within the scope of the struct -in a flat linked list, no matter what the internal structure of the non-standard -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.- a level: the level number in the GEDCOM file
-- a tag: the tag given in the GEDCOM file
-- a value: the value, which can be a string value or a cross-reference value (one of the two will be non-NULL)
-
-
++These functions only differ in the type of the last argument, which is the value of the element.
+
+Thehndl
parameter is again the write handle returned bygedcom_write_open
. Theelt
parameter is one of the identifiers given in the first column in this table (exceptELT_USER
: see below). Theparent_rec_or_elt
is the correspondingrec
orelt
+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, theparsed_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 formTAG_name
. This parameter is needed whenever the second column in this table shows several possible tags (this is e.g. the case forELT_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 callinggedcom_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:+
+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.int gedcom_write_user_str (Gedcom_write_hndl hndl, int level, char* tag, char* xrefstr,
+ char* value);
+int gedcom_write_user_xref (Gedcom_write_hndl hndl,
int level, char* tag, char* xrefstr,
++ struct xref_value* value);
+
Other API functions
@@ -585,207 +647,52 @@ default)
thelocale
mechanism (i.e. via theLANG
,LC_ALL
orLC_CTYPE
environment variables), which also controls thegettext
mechanism in the application.
-
-
- - The source distribution of-gedcom-parse
contains an example implementation (utf8-locale.c
- andutf8-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:
- --- 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-char *convert_utf8_to_locale (char *input, int *conv_failures);
char *convert_locale_to_utf8 (char *input);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 passNULL
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):
- --
- -- inclusion of some headers:
- --- ----#include <locale.h> /* for setlocale */
#include <langinfo.h> /* for nl_langinfo */
#include <iconv.h> /* for iconv_* functions */-
- -- set the program's current locale to what -the user configured in the environment:
- --- ----setlocale(LC_ALL, "");
-
- -- open a conversion handle for conversion - from UTF-8 to the character set of the current locale (once for the entire - program):
- --- ----iconv_t iconv_handle;
...
iconv_handle = iconv_open(nl_langinfo(CODESET), "UTF-8");
if (iconv_handle == (iconv_t) -1)
/* signal an error */-
- -- then, every string can be converted - using the following:
- --- ----/* 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 seterrno
toE2BIG
. Also, -thein_ptr
andout_ptr
will point just after -the last successfully converted character in the respective buffers, and -thein_len
andout_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 -- 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).iconv
function will then also return -1 and seterrno
- toEILSEQ
; thein_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 - :- -
--
- -- if the first byte is in -binary 0xxxxxxx, then the character is only one byte long, just skip over -that byte
-
-
-- if the first byte is in -binary 11xxxxxx, then skip over that byte and all bytes 10xxxxxx that follow.
- -
--
- -- eventually, the conversion -handle needs to be closed (when the program exits):
- -
--- The example implementation - mentioned above grows the output buffer dynamically and outputs "?" for characters - that can't be converted.---iconv_close(iconv_handle);
+
With+gedcom-parse
comes a library implementing help functions for UTF-8 encoding (see +the documentation for this library).
-Support for configure.in
- Programs using the GEDCOM parser library and using autoconf to configure - their sources can use the following statements in configure.in (the example - is checking for gedcom-parse, version 1.34):
- -- There are three preprocessor symbols defined for version checks in the - header:AC_CHECK_LIB(gedcom, gedcom_parse_file,,
- AC_MSG_ERROR(Cannot - find libgedcom: Please install gedcom-parse))
- AC_MSG_CHECKING(for libgedcom version)
- AC_TRY_RUN([
- #include <stdio.h>
- #include <stdlib.h>
- #include <gedcom.h>
- int
- main()
- {
- if (GEDCOM_PARSE_VERSION >= 1034) exit(0);
- exit(1);
- }],
- ac_gedcom_version_ok='yes',
- ac_gedcom_version_ok='no',
- ac_gedcom_version_ok='no')
- if test "$ac_gedcom_version_ok" = 'yes' ; then
- AC_MSG_RESULT(ok)
- else
- AC_MSG_RESULT(not ok)
- AC_MSG_ERROR(You need at least version 1.34 of gedcom-parse)
- fi
-
+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:
+
++All the arguments are optional and default to 0. E.g. to check for +version 1.34.2, you would put in configure.in the following statement:AM_PATH_GEDCOM_PARSER([min_version,[action_if_found,[action_if_not_found,[modules]]]])
+
+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).AM_PATH_GEDCOM_PARSER(1.34.2)
+
+
+The macro also sets the variablesGEDCOM_CFLAGS
andGEDCOM_LIBS
for use in Makefiles. Typically, this would be done as follows in a Makefile.am:
++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 isbin_programs = myprg
+myprg_SOURCES = myprg.c foo.c bar.c
+INCLUDES = @GEDCOM_CFLAGS@
+LDADD = @GEDCOM_LIBS@gom
(the Gedcom object model). For example:
++To be able to use this macro in the sources of your application, you have three options:AM_PATH_GEDCOM_PARSER(0.21.2, , ,gom)
+
++
+- Put the file
+m4/gedcom.m4
in your autoconf data directory (i.e. the path given by 'aclocal --print-ac-dir
', usually/usr/share/aclocal
). You can do this automatically by going into the m4 subdirectory and typing 'make install-m4
'.
+
+- If you're using autoconf, but not automake, copy the contents of
+m4/gedcom.m4
in theaclocal.m4
file in your sources.
+
+- If you're using automake, copy the contents of
+m4/gedcom.m4
in theacinclude.m4
file in your sources.
+
+There are three preprocessor symbols defined for version checks in the + header (but their direct use is deprecated: please use the macro above):
- The last one is equal to
- @@ -794,7 +701,22 @@ handle needs to be closed (when the program exits):
GEDCOM_PARSE_VERSION_MAJOR
(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 scriptgedcom-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): ++Similarly, to get linking flags, use one of the following: +gedcom-config --cflags
+gedcom-config --cflags gom
++ +gedcom-config --libs
+gedcom-config --libs gom
+
@@ -804,6 +726,13 @@ handle needs to be closed (when the program exits):
+
+
+
+
+
+
+