X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=doc%2Fusage.html;h=409ebbf308878bf17f0b2726ade6faf57a8eedb3;hb=4217fc0e76c6560a5ad43cffc314f0f28ad9deec;hp=cd050df414a0f2e707d0e8b9a71fd0999318046f;hpb=6d7fe09b0eab9dd8ea3c209d59589bea6514a48c;p=gedcom-parse.git diff --git a/doc/usage.html b/doc/usage.html index cd050df..409ebbf 100644 --- a/doc/usage.html +++ b/doc/usage.html @@ -25,7 +25,10 @@
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>
locale
mechanism (i.e. via the LANG
, LC_ALL
or LC_CTYPE
environment variables), which also controls the gettext
+ mechanism in the application. gedcom-parse
contains an example implementation (utf8-locale.c
and utf8-locale.h
+ in 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).
+ + +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 thechar *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. 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.+void convert_set_unknown (const char *unknown);
+++++#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.
+
+
++ The example implementation +mentioned above grows the output buffer dynamically and outputs "?" for characters +that can't be converted.+++iconv_close(iconv_handle);
+ +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
+
GEDCOM_PARSE_VERSION_MAJOR
GEDCOM_PARSE_VERSION_MINOR
GEDCOM_PARSE_VERSION
(GEDCOM_PARSE_VERSION_MAJOR * 1000) + GEDCOM_PARSE_VERSION_MINOR.
$Id$
$Name$