X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=doc%2Fusage.html;h=00003be0d0b4484dd762b1c4b4e7c0b174d1065f;hb=b1a87b467d9c6b38aa4a2b2e4537b0deff9a251e;hp=786cf1f1694714bb02dfe73eaf6bf5ec7e564767;hpb=440a08f883e410cb0c714ccdc3bf95d23be3d805;p=gedcom-parse.git diff --git a/doc/usage.html b/doc/usage.html index 786cf1f..00003be 100644 --- a/doc/usage.html +++ b/doc/usage.html @@ -1,9 +1,7 @@
my_message_handler
is the callback
- that will be called for errors (type=ERROR
), warnings (
- type=WARNING
) and messages (type=MESSAGE
). The
+ that will be called for errors (type=ERROR
), warnings (type=WARNING
) and messages (type=MESSAGE
). The
callback must have the signature as in the example. For errors, the
msg
passed to the callback will have the format:Note that the entire string will be properly internationalized, and -encoded in UTF-8 (see "Why UTF-8?" LINK TBD). Also, +encoded in UTF-8 (Why UTF-8?). Also, no newline is appended, so that the application program can use it in any way it wants. Warnings are similar, but use "Warning" instead of "Error". Messages are plain text, without any prefix.Error on line
<lineno>: <actual_message>
gedcom-tags.h
yourself).struct
that will contain the information for the
+ e.g. pass a struct
(or an object in a C++ application) that will contain the information for the
header. In the end callback, the application could then e.g. do some
finalizing operations on the struct
to put it in its database.struct
that
+ that the context of the parent line (here e.g. the struct
that
describes the header) is passed to this start callback. The callback
-itself returns here the same context, but this can be its own context object
+itself returns here in this example the same context, but this can be its own context object
of course. The end callback is called with both the context of the
-parent and the context of itself, which will be the same in the example.
+parent and the context of itself, which in this example will be the same.
Again, the list of identifiers to use as a first argument for the
subscription function are detailed in the
interface details .Gedcom_val
type is meant to be an opaque type. The
only thing that needs to be known about it is that it can contain specific
@@ -291,9 +290,8 @@ level number (the initial number of the line in the GEDCOM file), the tag
Gedcom_val
argument of the end callback
is currently not used. It is there for future enhancements.Gedcom_val
argument in
-the start callback for records. This argument is currently a string
-value giving the pointer in string form.Gedcom_val
arguments in
+the start callback for records. The first one (xref
) contains the xref_value
corresponding to the cross-reference (or NULL
if there isn't one), the second one (parsed_value
) contains the value that is parsed from the raw_value
. See the interface details.parent
could be of different
types, depending on the context).NULL
. This is e.g. the case if none of the "upper" tags has been subscribed upon.locale
mechanism (i.e. via the LANG
, LC_ALL
or LC_CTYPE
environment variables), which also controls the gettext
+ mechanism in the application. For this, 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 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.
+
+
++ -+++iconv_close(iconv_handle);
gedcom-parse
contains an example implementation (utf8-locale.c
and utf8-locale.h
+ in the top directory) that grows the output buffer dynamically and outputs
+"?" for characters that can't be converted. 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).
+ ++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);
char *convert_locale_to_utf8 (char *input);
setlocale
function (the second step above).
+ All other steps, including setting up and closing down the conversion
+handles, are transparantly handled by the two functions.+++void convert_set_unknown (const char *unknown);
$Id$
$Name$