1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

Don't include libunistring headers in Guile public headers

This requres the creation of a new type
scm_t_string_failed_conversion_handler to replace libunistring's
enum iconveh_ilseq_handler.

* libguile/strings.h: don't include <uniconv.h>
(scm_t_string_failed_conversion_handler): new enum type
(SCM_FAILED_CONVERSION_ERROR, SCM_FAILED_CONVERSION_QUESTION_MARK):
(SCM_FAILED_CONVERSION_ESCAPE_SEQUENCE): new enum type values

* libguile/strings.c (scm_to_stringn): now takes type
scm_t_string_failed_conversion_handler.  All callers changed.

* libguile/print.c: include <uniconv.h>

* libguile/ports.c (scm_lfwrite_substr): use
scm_t_string_conversion_handler's constants

* libguile/gen-scmconfig.c (SCM_ICONVEH_ERROR):
(SCM_ICONVEH_QUESTION_MARK, SCM_ICONVEH_ESCAPE_SEQUENCE): store
iconveh_ilseq_hander constants as #define's
This commit is contained in:
Michael Gran 2009-08-12 08:30:59 -07:00
parent 3c7cf7f5c0
commit eca29b0202
5 changed files with 29 additions and 8 deletions

View file

@ -125,6 +125,7 @@
#include <stdio.h>
#include <string.h>
#include <uniconv.h>
#define pf printf
@ -424,6 +425,14 @@ main (int argc, char *argv[])
pf ("#define SCM_HAVE_ARRAYS 1 /* always true now */\n");
pf ("\n");
pf ("/* Constants from uniconv.h. */\n");
pf ("#define SCM_ICONVEH_ERROR %d\n", (int) iconveh_error);
pf ("#define SCM_ICONVEH_QUESTION_MARK %d\n",
(int) iconveh_question_mark);
pf ("#define SCM_ICONVEH_ESCAPE_SEQUENCE %d\n",
(int) iconveh_escape_sequence);
printf ("#endif\n");
return 0;

View file

@ -1024,7 +1024,7 @@ scm_lfwrite_substr (SCM str, size_t start, size_t end, SCM port)
size = end - start;
buf = scm_to_stringn (scm_c_substring (str, start, end), &len,
NULL, iconveh_escape_sequence);
NULL, SCM_FAILED_CONVERSION_ESCAPE_SEQUENCE);
ptob->write (port, buf, len);
free (buf);

View file

@ -23,6 +23,7 @@
#endif
#include <errno.h>
#include <uniconv.h>
#include <unictype.h>
#include "libguile/_scm.h"

View file

@ -26,6 +26,7 @@
#include <stdio.h>
#include <ctype.h>
#include <unistr.h>
#include <uniconv.h>
#include "libguile/_scm.h"
#include "libguile/chars.h"
@ -1473,13 +1474,14 @@ scm_to_locale_stringn (SCM str, size_t * lenp)
/* In the future, enc will hold the port's encoding. */
enc = NULL;
return scm_to_stringn (str, lenp, enc, iconveh_escape_sequence);
return scm_to_stringn (str, lenp, enc,
SCM_FAILED_CONVERSION_ESCAPE_SEQUENCE);
}
/* Low-level scheme to C string conversion function. */
char *
scm_to_stringn (SCM str, size_t * lenp, const char *encoding,
enum iconv_ilseq_handler handler)
scm_t_string_failed_conversion_handler handler)
{
static const char iso[11] = "ISO-8859-1";
char *buf;
@ -1527,14 +1529,14 @@ scm_to_stringn (SCM str, size_t * lenp, const char *encoding,
buf = NULL;
len = 0;
buf = u32_conv_to_encoding (iso,
handler,
(enum iconv_ilseq_handler) handler,
(scm_t_uint32 *) scm_i_string_wide_chars (str),
ilen, NULL, NULL, &len);
if (buf == NULL)
scm_misc_error (NULL, "cannot convert to output locale ~s: \"~s\"",
scm_list_2 (scm_from_locale_string (iso), str));
if (handler == iconveh_escape_sequence)
if (handler == SCM_FAILED_CONVERSION_ESCAPE_SEQUENCE)
unistring_escapes_to_guile_escapes (&buf, &len);
if (lenp)

View file

@ -3,7 +3,7 @@
#ifndef SCM_STRINGS_H
#define SCM_STRINGS_H
/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2004, 2005, 2006, 2008, 2009 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@ -23,7 +23,6 @@
#include <uniconv.h>
#include "libguile/__scm.h"
@ -90,6 +89,15 @@
no wide version of this interface.
*/
/* A type indicating what strategy to take when string locale
conversion is unsuccessful. */
typedef enum
{
SCM_FAILED_CONVERSION_ERROR = SCM_ICONVEH_ERROR,
SCM_FAILED_CONVERSION_QUESTION_MARK = SCM_ICONVEH_QUESTION_MARK,
SCM_FAILED_CONVERSION_ESCAPE_SEQUENCE = SCM_ICONVEH_ESCAPE_SEQUENCE
} scm_t_string_failed_conversion_handler;
SCM_API SCM scm_string_p (SCM x);
SCM_API SCM scm_string (SCM chrs);
SCM_API SCM scm_make_string (SCM k, SCM chr);
@ -122,7 +130,8 @@ SCM_API char *scm_to_locale_string (SCM str);
SCM_API char *scm_to_locale_stringn (SCM str, size_t *lenp);
SCM_INTERNAL char *scm_to_stringn (SCM str, size_t *lenp,
const char *encoding,
enum iconv_ilseq_handler handler);
scm_t_string_failed_conversion_handler
handler);
SCM_API size_t scm_to_locale_stringbuf (SCM str, char *buf, size_t max_len);
SCM_API SCM scm_makfromstrs (int argc, char **argv);