From ad6dec055f951c8571439fdfd2a30a4c3250001a Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Thu, 19 Aug 2004 17:28:53 +0000 Subject: [PATCH] Avoid the use of discouraged or deprecated things. --- guile-readline/readline.c | 49 ++++++++++++++----------- test-suite/standalone/test-conversion.c | 6 +-- test-suite/standalone/test-gh.c | 8 ++-- test-suite/standalone/test-unwind.c | 8 ++-- 4 files changed, 39 insertions(+), 32 deletions(-) diff --git a/guile-readline/readline.c b/guile-readline/readline.c index 9f7b39df0..c0fe8ec6e 100644 --- a/guile-readline/readline.c +++ b/guile-readline/readline.c @@ -165,7 +165,7 @@ SCM_DEFINE (scm_readline, "%readline", 0, 4, 0, if (!SCM_UNBNDP (text)) { - if (!SCM_STRINGP (text)) + if (!scm_is_string (text)) { --in_readline; scm_wrong_type_arg (s_scm_readline, SCM_ARG1, text); @@ -253,15 +253,17 @@ internal_readline (SCM text) { SCM ret; char *s; - char *prompt = SCM_UNBNDP (text) ? "" : SCM_STRING_CHARS (text); + char *prompt = SCM_UNBNDP (text) ? "" : scm_to_locale_string (text); promptp = 1; s = readline (prompt); if (s) - ret = scm_makfrom0str (s); + ret = scm_from_locale_string (s); else ret = SCM_EOF_VAL; + if (!SCM_UNBNDP (text)) + free (prompt); free (s); return ret; @@ -326,10 +328,9 @@ SCM_DEFINE (scm_add_history, "add-history", 1, 0, 0, #define FUNC_NAME s_scm_add_history { char* s; - SCM_VALIDATE_STRING (1,text); - s = SCM_STRING_CHARS (text); - add_history (strdup (s)); + s = scm_to_locale_string (text); + add_history (s); return SCM_UNSPECIFIED; } @@ -341,8 +342,13 @@ SCM_DEFINE (scm_read_history, "read-history", 1, 0, 0, "") #define FUNC_NAME s_scm_read_history { - SCM_VALIDATE_STRING (1,file); - return scm_from_bool (!read_history (SCM_STRING_CHARS (file))); + char *filename; + SCM ret; + + filename = scm_to_locale_string (file); + ret = scm_from_bool (!read_history (filename)); + free (filename); + return ret; } #undef FUNC_NAME @@ -352,8 +358,13 @@ SCM_DEFINE (scm_write_history, "write-history", 1, 0, 0, "") #define FUNC_NAME s_scm_write_history { - SCM_VALIDATE_STRING (1,file); - return scm_from_bool (!write_history (SCM_STRING_CHARS (file))); + char *filename; + SCM ret; + + filename = scm_to_locale_string (file); + ret = scm_from_bool (!write_history (filename)); + free (filename); + return ret; } #undef FUNC_NAME @@ -375,14 +386,14 @@ SCM_DEFINE (scm_filename_completion_function, "filename-completion-function", 2, { char *s; SCM ans; - SCM_VALIDATE_STRING (1,text); + char *c_text = scm_to_locale_string (text); #ifdef HAVE_RL_FILENAME_COMPLETION_FUNCTION - s = rl_filename_completion_function (SCM_STRING_CHARS (text), scm_is_true (continuep)); + s = rl_filename_completion_function (c_text, scm_is_true (continuep)); #else - s = filename_completion_function (SCM_STRING_CHARS (text), scm_is_true (continuep)); + s = filename_completion_function (c_text, scm_is_true (continuep)); #endif - ans = scm_makfrom0str (s); - free (s); + ans = scm_take_locale_string (s); + free (c_text); return ans; } #undef FUNC_NAME @@ -404,18 +415,14 @@ completion_function (char *text, int continuep) return NULL; /* #f => completion disabled */ else { - SCM t = scm_makfrom0str (text); + SCM t = scm_from_locale_string (text); SCM c = scm_from_bool (continuep); res = scm_apply (compfunc, scm_list_2 (t, c), SCM_EOL); if (scm_is_false (res)) return NULL; - if (!SCM_STRINGP (res)) - scm_misc_error (s_scm_readline, - "Completion function returned bogus value: %S", - scm_list_1 (res)); - return strdup (SCM_STRING_CHARS (res)); + return scm_to_locale_string (res); } } diff --git a/test-suite/standalone/test-conversion.c b/test-suite/standalone/test-conversion.c index ff246325f..fcadde981 100644 --- a/test-suite/standalone/test-conversion.c +++ b/test-suite/standalone/test-conversion.c @@ -188,19 +188,19 @@ typedef struct { static SCM out_of_range_handler (void *data, SCM key, SCM args) { - return scm_equal_p (key, scm_str2symbol ("out-of-range")); + return scm_equal_p (key, scm_from_locale_symbol ("out-of-range")); } static SCM wrong_type_handler (void *data, SCM key, SCM args) { - return scm_equal_p (key, scm_str2symbol ("wrong-type-arg")); + return scm_equal_p (key, scm_from_locale_symbol ("wrong-type-arg")); } static SCM misc_error_handler (void *data, SCM key, SCM args) { - return scm_equal_p (key, scm_str2symbol ("misc-error")); + return scm_equal_p (key, scm_from_locale_symbol ("misc-error")); } static SCM diff --git a/test-suite/standalone/test-gh.c b/test-suite/standalone/test-gh.c index 99527376a..a00cea3d5 100644 --- a/test-suite/standalone/test-gh.c +++ b/test-suite/standalone/test-gh.c @@ -29,8 +29,8 @@ string_equal (SCM str, char *lit) int len = strlen (lit); int result; - result = ((SCM_STRING_LENGTH (str) == len) - && (!memcmp (SCM_STRING_CHARS (str), lit, len))); + result = ((scm_i_string_length (str) == len) + && (!memcmp (scm_i_string_chars (str), lit, len))); scm_remember_upto_here_1 (str); return result; } @@ -54,14 +54,14 @@ test_gh_set_substr () code if you have to copy the string just to look at it. */ /* Copy a substring to an overlapping region to its right. */ - gh_set_substr (SCM_STRING_CHARS (string), string, 4, 6); + gh_set_substr (scm_i_string_chars (string), string, 4, 6); assert (string_equal (string, "FreeFree, it!")); string = gh_str02scm ("Free, darnit!"); assert (gh_string_p (string)); /* Copy a substring to an overlapping region to its left. */ - gh_set_substr (SCM_STRING_CHARS (string) + 6, string, 2, 6); + gh_set_substr (scm_i_string_chars (string) + 6, string, 2, 6); assert (string_equal (string, "Frdarnitrnit!")); } diff --git a/test-suite/standalone/test-unwind.c b/test-suite/standalone/test-unwind.c index ca04df344..460f07ba2 100644 --- a/test-suite/standalone/test-unwind.c +++ b/test-suite/standalone/test-unwind.c @@ -177,8 +177,8 @@ check_ports () scm_frame_begin (0); { - SCM port = scm_open_file (scm_str2string (filename), - scm_str2string ("w")); + SCM port = scm_open_file (scm_from_locale_string (filename), + scm_from_locale_string ("w")); scm_frame_unwind_handler_with_scm (close_port, port, SCM_F_WIND_EXPLICITLY); @@ -189,8 +189,8 @@ check_ports () scm_frame_begin (0); { - SCM port = scm_open_file (scm_str2string (filename), - scm_str2string ("r")); + SCM port = scm_open_file (scm_from_locale_string (filename), + scm_from_locale_string ("r")); SCM res; scm_frame_unwind_handler_with_scm (close_port, port, SCM_F_WIND_EXPLICITLY); -- 2.20.1