diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2006-04-20 15:52:01 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2006-04-20 15:52:01 +0000 |
commit | d2ef02c76377c03d1c62362623df1d8f9daa9c00 (patch) | |
tree | e91b5a022590b9670c57497917d04478ce127143 | |
parent | bac588a3ed958fd017aeb9006e311380bb0e3021 (diff) | |
download | mailutils-d2ef02c76377c03d1c62362623df1d8f9daa9c00.tar.gz mailutils-d2ef02c76377c03d1c62362623df1d8f9daa9c00.tar.bz2 |
Rewritten using Guile 1.8 API.
Throw 'mailutils-error instead of returning #f on error.
-rw-r--r-- | libmu_scm/mu_address.c | 66 | ||||
-rw-r--r-- | libmu_scm/mu_body.c | 45 | ||||
-rw-r--r-- | libmu_scm/mu_logger.c | 28 | ||||
-rw-r--r-- | libmu_scm/mu_mailbox.c | 112 | ||||
-rw-r--r-- | libmu_scm/mu_message.c | 81 | ||||
-rw-r--r-- | libmu_scm/mu_mime.c | 61 | ||||
-rw-r--r-- | libmu_scm/mu_port.c | 20 | ||||
-rw-r--r-- | libmu_scm/mu_scm.c | 39 | ||||
-rw-r--r-- | libmu_scm/mu_util.c | 31 |
9 files changed, 286 insertions, 197 deletions
diff --git a/libmu_scm/mu_address.c b/libmu_scm/mu_address.c index cb4c5000f..72ed64f8b 100644 --- a/libmu_scm/mu_address.c +++ b/libmu_scm/mu_address.c @@ -1,5 +1,5 @@ /* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 1999, 2000, 2001, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2005, 2006 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 @@ -29,39 +29,47 @@ _get_address_part (const char *func_name, address_get_fp fun, char *str; SCM ret; int num; + int status; - SCM_ASSERT (SCM_NIMP (ADDRESS) && SCM_STRINGP (ADDRESS), - ADDRESS, SCM_ARG1, func_name); + SCM_ASSERT (scm_is_string (ADDRESS), ADDRESS, SCM_ARG1, func_name); if (!SCM_UNBNDP (NUM)) { - SCM_ASSERT (SCM_IMP (NUM) && SCM_INUMP (NUM), - NUM, SCM_ARG1, func_name); - num = SCM_INUM (NUM); + SCM_ASSERT (scm_is_integer (NUM), NUM, SCM_ARG1, func_name); + num = scm_to_int (NUM); } else num = 1; - str = SCM_STRING_CHARS (ADDRESS); - length = strlen (str); + length = strlen (scm_i_string_chars (ADDRESS)); if (length == 0) - return scm_makfrom0str(""); + mu_scm_error (func_name, 0, + "Empty address", SCM_BOOL_F); - if (mu_address_create (&addr, SCM_STRING_CHARS (ADDRESS))) - return SCM_BOOL_F; + status = mu_address_create (&addr, scm_i_string_chars (ADDRESS)); + if (status) + mu_scm_error (func_name, status, "Cannot create address", SCM_BOOL_F); str = malloc (length + 1); if (!str) { mu_address_destroy (&addr); - return SCM_BOOL_F; + mu_scm_error (func_name, ENOMEM, + "Cannot allocate memory", SCM_BOOL_F); } - if ((*fun) (addr, num, str, length + 1, NULL) == 0) + status = (*fun) (addr, num, str, length + 1, NULL); + mu_address_destroy (&addr); + + if (status == 0) ret = scm_makfrom0str (str); else - ret = SCM_BOOL_F; - mu_address_destroy (&addr); + { + free (str); + mu_scm_error (func_name, status, + "Underlying function failed", SCM_BOOL_F); + } + free (str); return ret; } @@ -123,12 +131,15 @@ SCM_DEFINE (scm_mu_address_get_count, "mu-address-get-count", 1, 0, 0, { mu_address_t addr; size_t count = 0; + int status; - SCM_ASSERT (SCM_NIMP (ADDRESS) && SCM_STRINGP (ADDRESS), - ADDRESS, SCM_ARG1, FUNC_NAME); + SCM_ASSERT (scm_is_string (ADDRESS), ADDRESS, SCM_ARG1, FUNC_NAME); - if (mu_address_create (&addr, SCM_STRING_CHARS (ADDRESS))) - return SCM_MAKINUM(0); + status = mu_address_create (&addr, scm_i_string_chars (ADDRESS)); + if (status) + mu_scm_error (FUNC_NAME, status, + "Cannot create address for ~A", + scm_list_1 (ADDRESS)); mu_address_get_count (addr, &count); mu_address_destroy (&addr); @@ -142,21 +153,24 @@ SCM_DEFINE (scm_mu_username_to_email, "mu-username->email", 0, 1, 0, "is assumed\n") #define FUNC_NAME s_scm_mu_username_to_email { - char *name; + const char *name; char *email; SCM ret; if (SCM_UNBNDP (NAME)) name = NULL; - else { - SCM_ASSERT (SCM_NIMP (NAME) && SCM_STRINGP (NAME), - NAME, SCM_ARG1, FUNC_NAME); - name = SCM_STRING_CHARS (NAME); - } + else + { + SCM_ASSERT (scm_is_string (NAME), NAME, SCM_ARG1, FUNC_NAME); + name = scm_i_string_chars (NAME); + } email = mu_get_user_email (name); if (!email) - return SCM_BOOL_F; + mu_scm_error (FUNC_NAME, 0, + "Cannot get user email for ~A", + scm_list_1 (scm_makfrom0str (name))); + ret = scm_makfrom0str (email); free (email); return ret; diff --git a/libmu_scm/mu_body.c b/libmu_scm/mu_body.c index 43835ea6b..a019cc15d 100644 --- a/libmu_scm/mu_body.c +++ b/libmu_scm/mu_body.c @@ -1,5 +1,5 @@ /* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 1999, 2000, 2001, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2005, 2006 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 @@ -88,7 +88,7 @@ mu_scm_body_create (SCM msg, mu_body_t body) { struct mu_body *mbp; - mbp = scm_must_malloc (sizeof (struct mu_body), "body"); + mbp = scm_gc_malloc (sizeof (struct mu_body), "body"); mbp->msg = msg; mbp->body = body; mbp->stream = NULL; @@ -108,14 +108,18 @@ SCM_DEFINE (scm_mu_body_read_line, "mu-body-read-line", 1, 0, 0, { struct mu_body *mbp; int n, nread; - + int status; + SCM_ASSERT (mu_scm_is_body (BODY), BODY, SCM_ARG1, FUNC_NAME); mbp = (struct mu_body *) SCM_CDR (BODY); if (!mbp->stream) { - if (mu_body_get_stream (mbp->body, &mbp->stream)) - return SCM_BOOL_F; + status = mu_body_get_stream (mbp->body, &mbp->stream); + if (status) + mu_scm_error (FUNC_NAME, status, + "Cannot get body stream", + SCM_BOOL_F); } if (!mbp->buffer) @@ -123,16 +127,18 @@ SCM_DEFINE (scm_mu_body_read_line, "mu-body-read-line", 1, 0, 0, mbp->bufsize = BUF_SIZE; mbp->buffer = malloc (mbp->bufsize); if (!mbp->buffer) - return SCM_BOOL_F; + mu_scm_error (FUNC_NAME, ENOMEM, "Cannot allocate memory", SCM_BOOL_F); } nread = 0; while (1) { - if (mu_stream_readline (mbp->stream, mbp->buffer + nread, - mbp->bufsize - nread, - mbp->offset, &n)) - return SCM_BOOL_F; + status = mu_stream_readline (mbp->stream, mbp->buffer + nread, + mbp->bufsize - nread, + mbp->offset, &n); + if (status) + mu_scm_error (FUNC_NAME, status, + "Error reading from stream", SCM_BOOL_F); if (n == 0) break; nread += n; @@ -164,24 +170,25 @@ SCM_DEFINE (scm_mu_body_write, "mu-body-write", 2, 0, 0, char *ptr; size_t len, n; struct mu_body *mbp; - + int status; + SCM_ASSERT (mu_scm_is_body (BODY), BODY, SCM_ARG1, FUNC_NAME); mbp = (struct mu_body *) SCM_CDR (BODY); - SCM_ASSERT (SCM_NIMP (TEXT) && SCM_STRINGP (TEXT), - TEXT, SCM_ARG2, FUNC_NAME); + SCM_ASSERT (scm_is_string (TEXT), TEXT, SCM_ARG2, FUNC_NAME); if (!mbp->stream) { - if (mu_body_get_stream (mbp->body, &mbp->stream)) - return SCM_BOOL_F; + status = mu_body_get_stream (mbp->body, &mbp->stream); + if (status) + mu_scm_error (FUNC_NAME, status, + "Cannot get body stream", SCM_BOOL_F); } ptr = SCM_STRING_CHARS (TEXT); len = strlen (ptr); - if (mu_stream_write (mbp->stream, ptr, len, mbp->offset, &n)) - { - return SCM_BOOL_F; - } + status = mu_stream_write (mbp->stream, ptr, len, mbp->offset, &n); + mu_scm_error (FUNC_NAME, status, + "Error writing to stream", SCM_BOOL_F); mbp->offset += n; return SCM_BOOL_T; } diff --git a/libmu_scm/mu_logger.c b/libmu_scm/mu_logger.c index dadedf383..23604af52 100644 --- a/libmu_scm/mu_logger.c +++ b/libmu_scm/mu_logger.c @@ -1,5 +1,5 @@ /* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2006 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 @@ -25,27 +25,26 @@ SCM_DEFINE (scm_mu_openlog, "mu-openlog", 3, 0, 0, "Opens a connection to the system logger for Guile program.") #define FUNC_NAME s_scm_mu_openlog { - char *ident; + const char *ident; int option, facility; if (IDENT == SCM_BOOL_F) ident = "libmu_scm"; else { - SCM_ASSERT (SCM_NIMP (IDENT) && SCM_STRINGP (IDENT), - IDENT, SCM_ARG1, FUNC_NAME); - ident = SCM_STRING_CHARS (IDENT); + SCM_ASSERT (scm_is_string (IDENT), IDENT, SCM_ARG1, FUNC_NAME); + ident = scm_i_string_chars (IDENT); } - if (SCM_IMP (OPTION) && SCM_INUMP (OPTION)) - option = SCM_INUM (OPTION); + if (scm_is_integer (OPTION)) + option = scm_to_int32 (OPTION); else if (SCM_BIGP (OPTION)) option = (int) scm_i_big2dbl (OPTION); else SCM_ASSERT (0, OPTION, SCM_ARG2, FUNC_NAME); - if (SCM_IMP (FACILITY) && SCM_INUMP (FACILITY)) - facility = SCM_INUM (FACILITY); + if (scm_is_integer (FACILITY)) + facility = scm_to_int32 (FACILITY); else if (SCM_BIGP (FACILITY)) facility = (int) scm_i_big2dbl (FACILITY); else @@ -65,16 +64,15 @@ SCM_DEFINE (scm_mu_logger, "mu-logger", 2, 0, 0, if (PRIO == SCM_BOOL_F) prio = LOG_INFO; - else if (SCM_IMP (PRIO) && SCM_INUMP (PRIO)) - prio = SCM_INUM (PRIO); + else if (scm_is_integer (PRIO)) + prio = scm_to_int32 (PRIO); else if (SCM_BIGP (PRIO)) prio = (int) scm_i_big2dbl (PRIO); else SCM_ASSERT (0, PRIO, SCM_ARG1, FUNC_NAME); - SCM_ASSERT (SCM_NIMP (TEXT) && SCM_STRINGP (TEXT), - TEXT, SCM_ARG2, FUNC_NAME); - syslog (prio, "%s", SCM_STRING_CHARS (TEXT)); + SCM_ASSERT (scm_is_string (TEXT), TEXT, SCM_ARG2, FUNC_NAME); + syslog (prio, "%s", scm_i_string_chars (TEXT)); return SCM_UNSPECIFIED; } #undef FUNC_NAME @@ -127,6 +125,6 @@ mu_scm_logger_init () int i; for (i = 0; i < sizeof (syslog_kw)/sizeof (syslog_kw[0]); i++) - scm_c_define (syslog_kw[i].name, SCM_MAKINUM (syslog_kw[i].facility)); + scm_c_define (syslog_kw[i].name, scm_from_int (syslog_kw[i].facility)); #include <mu_logger.x> } diff --git a/libmu_scm/mu_mailbox.c b/libmu_scm/mu_mailbox.c index 698366abd..8e5a623a5 100644 --- a/libmu_scm/mu_mailbox.c +++ b/libmu_scm/mu_mailbox.c @@ -1,5 +1,5 @@ /* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2006 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 @@ -90,7 +90,7 @@ mu_scm_mailbox_create (mu_mailbox_t mbox) { struct mu_mailbox *mum; - mum = scm_must_malloc (sizeof (struct mu_mailbox), "mailbox"); + mum = scm_gc_malloc (sizeof (struct mu_mailbox), "mailbox"); mum->mbox = mbox; SCM_RETURN_NEWSMOB (mailbox_tag, mum); } @@ -111,9 +111,8 @@ SCM_DEFINE (scm_mu_mail_directory, "mu-mail-directory", 0, 1, 0, { if (!SCM_UNBNDP (URL)) { - SCM_ASSERT (SCM_NIMP (URL) && SCM_STRINGP (URL), - URL, SCM_ARG1, FUNC_NAME); - mu_set_mail_directory (SCM_STRING_CHARS (URL)); + SCM_ASSERT (scm_is_string (URL), URL, SCM_ARG1, FUNC_NAME); + mu_set_mail_directory (scm_i_string_chars (URL)); } return scm_makfrom0str (mu_mail_directory ()); } @@ -126,9 +125,8 @@ SCM_DEFINE (scm_mu_folder_directory, "mu-folder-directory", 0, 1, 0, { if (!SCM_UNBNDP (URL)) { - SCM_ASSERT (SCM_NIMP (URL) && SCM_STRINGP (URL), - URL, SCM_ARG1, FUNC_NAME); - mu_set_folder_directory (SCM_STRING_CHARS (URL)); + SCM_ASSERT (scm_is_string (URL), URL, SCM_ARG1, FUNC_NAME); + mu_set_folder_directory (scm_i_string_chars (URL)); } return scm_makfrom0str (mu_folder_directory ()); } @@ -140,14 +138,14 @@ SCM_DEFINE (scm_mu_mailbox_open, "mu-mailbox-open", 2, 0, 0, #define FUNC_NAME s_scm_mu_mailbox_open { mu_mailbox_t mbox = NULL; - char *mode_str; + const char *mode_str; int mode = 0; + int status; + + SCM_ASSERT (scm_is_string (URL), URL, SCM_ARG1, FUNC_NAME); + SCM_ASSERT (scm_is_string (MODE), MODE, SCM_ARG2, FUNC_NAME); - SCM_ASSERT (SCM_NIMP (URL) && SCM_STRINGP (URL), URL, SCM_ARG1, FUNC_NAME); - SCM_ASSERT (SCM_NIMP (MODE) && SCM_STRINGP (MODE), - MODE, SCM_ARG2, FUNC_NAME); - - for (mode_str = SCM_STRING_CHARS (MODE); *mode_str; mode_str++) + for (mode_str = scm_i_string_chars (MODE); *mode_str; mode_str++) switch (*mode_str) { case 'r': @@ -167,15 +165,22 @@ SCM_DEFINE (scm_mu_mailbox_open, "mu-mailbox-open", 2, 0, 0, if (mode & MU_STREAM_READ && mode & MU_STREAM_WRITE) mode = (mode & ~(MU_STREAM_READ | MU_STREAM_WRITE)) | MU_STREAM_RDWR; - if (mu_mailbox_create_default (&mbox, SCM_STRING_CHARS (URL)) != 0) - return SCM_BOOL_F; + status = mu_mailbox_create_default (&mbox, scm_i_string_chars (URL)); + if (status) + mu_scm_error (FUNC_NAME, status, + "Cannot create default mailbox ~A", + scm_list_1 (URL)); - if (mu_mailbox_open (mbox, mode) != 0) + + status = mu_mailbox_open (mbox, mode); + if (status) { mu_mailbox_destroy (&mbox); - return SCM_BOOL_F; + mu_scm_error (FUNC_NAME, status, + "Cannot open default mailbox ~A", + scm_list_1 (URL)); } - + return mu_scm_mailbox_create (mbox); } #undef FUNC_NAME @@ -219,15 +224,18 @@ SCM_DEFINE (scm_mu_mailbox_get_port, "mu-mailbox-get-port", 2, 0, 0, { struct mu_mailbox *mum; mu_stream_t stream; + int status; SCM_ASSERT (mu_scm_is_mailbox (MBOX), MBOX, SCM_ARG1, FUNC_NAME); - SCM_ASSERT (SCM_NIMP (MODE) && SCM_STRINGP (MODE), - MODE, SCM_ARG2, FUNC_NAME); + SCM_ASSERT (scm_is_string (MODE), MODE, SCM_ARG2, FUNC_NAME); mum = (struct mu_mailbox *) SCM_CDR (MBOX); - if (mu_mailbox_get_stream (mum->mbox, &stream)) - return SCM_BOOL_F; + status = mu_mailbox_get_stream (mum->mbox, &stream); + if (status) + mu_scm_error (FUNC_NAME, status, + "Cannot get mailbox stream", + scm_list_1 (MBOX)); return mu_port_make_from_stream (MBOX, stream, - scm_mode_bits (SCM_STRING_CHARS (MODE))); + scm_mode_bits ((char*)scm_i_string_chars (MODE))); } #undef FUNC_NAME @@ -238,17 +246,20 @@ SCM_DEFINE (scm_mu_mailbox_get_message, "mu-mailbox-get-message", 2, 0, 0, size_t msgno; struct mu_mailbox *mum; mu_message_t msg; - + int status; + SCM_ASSERT (mu_scm_is_mailbox (MBOX), MBOX, SCM_ARG1, FUNC_NAME); - SCM_ASSERT ((SCM_IMP (MSGNO) && SCM_INUMP (MSGNO)), - MSGNO, SCM_ARG2, FUNC_NAME); + SCM_ASSERT (scm_is_integer (MSGNO), MSGNO, SCM_ARG2, FUNC_NAME); mum = (struct mu_mailbox *) SCM_CDR (MBOX); - msgno = SCM_INUM (MSGNO); - - if (mu_mailbox_get_message (mum->mbox, msgno, &msg)) - return SCM_BOOL_F; - + msgno = scm_to_int32 (MSGNO); + + status = mu_mailbox_get_message (mum->mbox, msgno, &msg); + if (status) + mu_scm_error (FUNC_NAME, status, + "Cannot get message ~A from mailbox ~A", + scm_list_2 (MSGNO, MBOX)); + return mu_scm_message_create (MBOX, msg); } #undef FUNC_NAME @@ -259,12 +270,16 @@ SCM_DEFINE (scm_mu_mailbox_messages_count, "mu-mailbox-messages-count", 1, 0, 0, { struct mu_mailbox *mum; size_t nmesg; - + int status; + SCM_ASSERT (mu_scm_is_mailbox (MBOX), MBOX, SCM_ARG1, FUNC_NAME); mum = (struct mu_mailbox *) SCM_CDR (MBOX); - if (mu_mailbox_messages_count (mum->mbox, &nmesg)) - return SCM_BOOL_F; + status = mu_mailbox_messages_count (mum->mbox, &nmesg); + if (status) + mu_scm_error (FUNC_NAME, status, + "Cannot count messages in mailbox ~A", + scm_list_1 (MBOX)); return mu_scm_makenum (nmesg); } #undef FUNC_NAME @@ -274,11 +289,15 @@ SCM_DEFINE (scm_mu_mailbox_expunge, "mu-mailbox-expunge", 1, 0, 0, #define FUNC_NAME s_scm_mu_mailbox_expunge { struct mu_mailbox *mum; - + int status; + SCM_ASSERT (mu_scm_is_mailbox (MBOX), MBOX, SCM_ARG1, FUNC_NAME); mum = (struct mu_mailbox *) SCM_CDR (MBOX); - if (mu_mailbox_expunge (mum->mbox)) - return SCM_BOOL_F; + status = mu_mailbox_expunge (mum->mbox); + if (status) + mu_scm_error (FUNC_NAME, status, + "Cannot expunge messages in mailbox ~A", + scm_list_1 (MBOX)); return SCM_BOOL_T; } #undef FUNC_NAME @@ -289,10 +308,15 @@ SCM_DEFINE (scm_mu_mailbox_url, "mu-mailbox-url", 1, 0, 0, { struct mu_mailbox *mum; mu_url_t url; - + int status; + SCM_ASSERT (mu_scm_is_mailbox (MBOX), MBOX, SCM_ARG1, FUNC_NAME); mum = (struct mu_mailbox *) SCM_CDR (MBOX); mu_mailbox_get_url (mum->mbox, &url); + if (status) + mu_scm_error (FUNC_NAME, status, + "Cannot get mailbox URL", + SCM_BOOL_F); return scm_makfrom0str (mu_url_to_string (url)); } #undef FUNC_NAME @@ -303,13 +327,17 @@ SCM_DEFINE (scm_mu_mailbox_append_message, "mu-mailbox-append-message", 2, 0, 0, { struct mu_mailbox *mum; mu_message_t msg; - + int status; + SCM_ASSERT (mu_scm_is_mailbox (MBOX), MBOX, SCM_ARG1, FUNC_NAME); SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG2, FUNC_NAME); mum = (struct mu_mailbox *) SCM_CDR (MBOX); msg = mu_scm_message_get (MESG); - if (mu_mailbox_append_message (mum->mbox, msg)) - return SCM_BOOL_F; + status = mu_mailbox_append_message (mum->mbox, msg); + if (status) + mu_scm_error (FUNC_NAME, status, + "Cannot append message ~A to mailbox ~A", + scm_list_2 (MESG, MBOX)); return SCM_BOOL_T; } #undef FUNC_NAME diff --git a/libmu_scm/mu_message.c b/libmu_scm/mu_message.c index a3060b538..848037182 100644 --- a/libmu_scm/mu_message.c +++ b/libmu_scm/mu_message.c @@ -1,5 +1,5 @@ /* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2006 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 @@ -125,7 +125,7 @@ mu_scm_message_create (SCM owner, mu_message_t msg) { struct mu_message *mum; - mum = scm_must_malloc (sizeof (struct mu_message), "message"); + mum = scm_gc_malloc (sizeof (struct mu_message), "message"); mum->msg = msg; mum->mbox = owner; SCM_RETURN_NEWSMOB (message_tag, mum); @@ -258,21 +258,19 @@ SCM_DEFINE (scm_mu_message_set_header, "mu-message-set-header", 3, 1, 0, SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); msg = mu_scm_message_get (MESG); - SCM_ASSERT (SCM_NIMP (HEADER) && SCM_STRINGP (HEADER), - HEADER, SCM_ARG2, FUNC_NAME); + SCM_ASSERT (scm_is_string (HEADER), HEADER, SCM_ARG2, FUNC_NAME); if (SCM_IMP (VALUE) && SCM_BOOLP (VALUE)) return SCM_UNSPECIFIED; - SCM_ASSERT (SCM_NIMP (VALUE) && SCM_STRINGP (VALUE), - VALUE, SCM_ARG2, FUNC_NAME); + SCM_ASSERT (scm_is_string (VALUE), VALUE, SCM_ARG2, FUNC_NAME); if (!SCM_UNBNDP (REPLACE)) { replace = REPLACE == SCM_BOOL_T; } mu_message_get_header (msg, &hdr); - mu_header_set_value (hdr, SCM_STRING_CHARS (HEADER), SCM_STRING_CHARS (VALUE), + mu_header_set_value (hdr, scm_i_string_chars (HEADER), scm_i_string_chars (VALUE), replace); return SCM_UNSPECIFIED; } @@ -335,14 +333,13 @@ SCM_DEFINE (scm_mu_message_get_header, "mu-message-get-header", 2, 0, 0, mu_message_t msg; mu_header_t hdr; char *value = NULL; - char *header_string; + const char *header_string; SCM ret = SCM_BOOL_F; SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); msg = mu_scm_message_get (MESG); - SCM_ASSERT (SCM_NIMP (HEADER) && SCM_STRINGP (HEADER), - HEADER, SCM_ARG2, FUNC_NAME); - header_string = SCM_STRING_CHARS (HEADER); + SCM_ASSERT (scm_is_string (HEADER), HEADER, SCM_ARG2, FUNC_NAME); + header_string = scm_i_string_chars (HEADER); mu_message_get_header (msg, &hdr); if (mu_header_aget_value (hdr, header_string, &value) == 0) { @@ -359,8 +356,8 @@ string_sloppy_member (SCM lst, char *name) for(; SCM_CONSP (lst); lst = SCM_CDR(lst)) { SCM car = SCM_CAR (lst); - if ((SCM_NIMP (car) && SCM_STRINGP (car)) - && strcasecmp (SCM_STRING_CHARS (car), name) == 0) + if (scm_is_string (car) + && strcasecmp (scm_i_string_chars (car), name) == 0) return 1; } return 0; @@ -459,11 +456,9 @@ SCM_DEFINE (scm_mu_message_set_header_fields, "mu-message-set-header-fields", 2, cell, SCM_ARGn, FUNC_NAME); car = SCM_CAR (cell); cdr = SCM_CDR (cell); - SCM_ASSERT (SCM_NIMP (car) && SCM_STRINGP (car), - car, SCM_ARGn, FUNC_NAME); - SCM_ASSERT (SCM_NIMP (cdr) && SCM_STRINGP (cdr), - cdr, SCM_ARGn, FUNC_NAME); - mu_header_set_value (hdr, SCM_STRING_CHARS (car), SCM_STRING_CHARS (cdr), replace); + SCM_ASSERT (scm_is_string (car), car, SCM_ARGn, FUNC_NAME); + SCM_ASSERT (scm_is_string (cdr), cdr, SCM_ARGn, FUNC_NAME); + mu_header_set_value (hdr, scm_i_string_chars (car), scm_i_string_chars (cdr), replace); } return SCM_UNSPECIFIED; } @@ -507,10 +502,10 @@ SCM_DEFINE (scm_mu_message_get_flag, "mu-message-get-flag", 2, 0, 0, SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); msg = mu_scm_message_get (MESG); - SCM_ASSERT (SCM_IMP (FLAG) && SCM_INUMP (FLAG), FLAG, SCM_ARG2, FUNC_NAME); + SCM_ASSERT (scm_is_integer (FLAG), FLAG, SCM_ARG2, FUNC_NAME); mu_message_get_attribute (msg, &attr); - switch (SCM_INUM (FLAG)) + switch (scm_to_int32 (FLAG)) { case MU_ATTRIBUTE_ANSWERED: ret = mu_attribute_is_answered (attr); @@ -538,7 +533,7 @@ SCM_DEFINE (scm_mu_message_get_flag, "mu-message-get-flag", 2, 0, 0, break; default: mu_attribute_get_flags (attr, &ret); - ret &= SCM_INUM (FLAG); + ret &= scm_to_int32 (FLAG); } return ret ? SCM_BOOL_T : SCM_BOOL_F; } @@ -556,7 +551,7 @@ SCM_DEFINE (scm_mu_message_set_flag, "mu-message-set-flag", 2, 1, 0, SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); msg = mu_scm_message_get (MESG); - SCM_ASSERT (SCM_IMP (FLAG) && SCM_INUMP (FLAG), FLAG, SCM_ARG2, FUNC_NAME); + SCM_ASSERT (scm_is_integer (FLAG), FLAG, SCM_ARG2, FUNC_NAME); if (!SCM_UNBNDP (VALUE)) { @@ -566,7 +561,7 @@ SCM_DEFINE (scm_mu_message_set_flag, "mu-message-set-flag", 2, 1, 0, } mu_message_get_attribute (msg, &attr); - switch (SCM_INUM (FLAG)) + switch (scm_to_int32 (FLAG)) { case MU_ATTRIBUTE_ANSWERED: if (value) @@ -618,7 +613,7 @@ SCM_DEFINE (scm_mu_message_set_flag, "mu-message-set-flag", 2, 1, 0, break; default: if (value) - mu_attribute_set_flags (attr, SCM_INUM (FLAG)); + mu_attribute_set_flags (attr, scm_to_int32 (FLAG)); } return SCM_UNSPECIFIED; } @@ -634,9 +629,9 @@ SCM_DEFINE (scm_mu_message_get_user_flag, "mu-message-get-user-flag", 2, 0, 0, SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); msg = mu_scm_message_get (MESG); - SCM_ASSERT (SCM_IMP (FLAG) && SCM_INUMP (FLAG), FLAG, SCM_ARG2, FUNC_NAME); + SCM_ASSERT (scm_is_integer (FLAG), FLAG, SCM_ARG2, FUNC_NAME); mu_message_get_attribute (msg, &attr); - return mu_attribute_is_userflag (attr, SCM_INUM (FLAG)) ? + return mu_attribute_is_userflag (attr, scm_to_int32 (FLAG)) ? SCM_BOOL_T : SCM_BOOL_F; } #undef FUNC_NAME @@ -654,7 +649,7 @@ SCM_DEFINE (scm_mu_message_set_user_flag, "mu-message-set-user-flag", 2, 1, 0, SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); msg = mu_scm_message_get (MESG); - SCM_ASSERT (SCM_IMP (FLAG) && SCM_INUMP (FLAG), FLAG, SCM_ARG2, FUNC_NAME); + SCM_ASSERT (scm_is_integer (FLAG), FLAG, SCM_ARG2, FUNC_NAME); if (!SCM_UNBNDP (VALUE)) { @@ -665,9 +660,9 @@ SCM_DEFINE (scm_mu_message_set_user_flag, "mu-message-set-user-flag", 2, 1, 0, mu_message_get_attribute (msg, &attr); if (set) - mu_attribute_set_userflag (attr, SCM_INUM (FLAG)); + mu_attribute_set_userflag (attr, scm_to_int32 (FLAG)); else - mu_attribute_unset_userflag (attr, SCM_INUM (FLAG)); + mu_attribute_unset_userflag (attr, scm_to_int32 (FLAG)); return SCM_UNSPECIFIED; } #undef FUNC_NAME @@ -687,8 +682,7 @@ SCM_DEFINE (scm_mu_message_get_port, "mu-message-get-port", 2, 1, 0, mu_stream_t stream = NULL; SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); - SCM_ASSERT (SCM_NIMP (MODE) && SCM_STRINGP (MODE), - MODE, SCM_ARG2, FUNC_NAME); + SCM_ASSERT (scm_is_string (MODE), MODE, SCM_ARG2, FUNC_NAME); msg = mu_scm_message_get (MESG); @@ -710,7 +704,7 @@ SCM_DEFINE (scm_mu_message_get_port, "mu-message-get-port", 2, 1, 0, } return mu_port_make_from_stream (MESG, stream, - scm_mode_bits (SCM_STRING_CHARS (MODE))); + scm_mode_bits ((char*)scm_i_string_chars (MODE))); } #undef FUNC_NAME @@ -776,14 +770,14 @@ SCM_DEFINE (scm_mu_message_get_part, "mu-message-get-part", 2, 0, 0, int ismime = 0; SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); - SCM_ASSERT (SCM_IMP (PART) && SCM_INUMP (PART), PART, SCM_ARG2, FUNC_NAME); + SCM_ASSERT (scm_is_integer (PART), PART, SCM_ARG2, FUNC_NAME); msg = mu_scm_message_get (MESG); mu_message_is_multipart (msg, &ismime); if (!ismime) return SCM_BOOL_F; - if (mu_message_get_part (msg, SCM_INUM (PART), &submsg)) + if (mu_message_get_part (msg, scm_to_int32 (PART), &submsg)) return SCM_BOOL_F; return mu_scm_message_create (MESG, submsg); } @@ -796,7 +790,7 @@ SCM_DEFINE (scm_mu_message_send, "mu-message-send", 1, 3, 0, "Optional FROM and TO are sender and recever addresses\n") #define FUNC_NAME s_scm_mu_message_send { - char *mailer_name; + const char *mailer_name; mu_address_t from = NULL; mu_address_t to = NULL; mu_mailer_t mailer = NULL; @@ -808,27 +802,26 @@ SCM_DEFINE (scm_mu_message_send, "mu-message-send", 1, 3, 0, if (!SCM_UNBNDP (MAILER) && MAILER != SCM_BOOL_F) { - SCM_ASSERT (SCM_NIMP (MAILER) && SCM_STRINGP (MAILER), - MAILER, SCM_ARG2, FUNC_NAME); - mailer_name = SCM_STRING_CHARS (MAILER); + SCM_ASSERT (scm_is_string (MAILER), MAILER, SCM_ARG2, FUNC_NAME); + mailer_name = scm_i_string_chars (MAILER); } else { SCM val = MU_SCM_SYMBOL_VALUE("mu-mailer"); - mailer_name = SCM_STRING_CHARS(val); + mailer_name = scm_i_string_chars(val); } if (!SCM_UNBNDP (FROM) && FROM != SCM_BOOL_F) { - SCM_ASSERT (SCM_NIMP (FROM) && SCM_STRINGP (FROM) - && mu_address_create (&from, SCM_STRING_CHARS (FROM)) == 0, + SCM_ASSERT (scm_is_string (FROM) + && mu_address_create (&from, scm_i_string_chars (FROM)) == 0, FROM, SCM_ARG3, FUNC_NAME); } if (!SCM_UNBNDP (TO) && TO != SCM_BOOL_F) { - SCM_ASSERT (SCM_NIMP (TO) && SCM_STRINGP (TO) - && mu_address_create (&to, SCM_STRING_CHARS (TO)) == 0, + SCM_ASSERT (scm_is_string (TO) + && mu_address_create (&to, scm_i_string_chars (TO)) == 0, TO, SCM_ARG4, FUNC_NAME); } @@ -837,7 +830,7 @@ SCM_DEFINE (scm_mu_message_send, "mu-message-send", 1, 3, 0, return SCM_BOOL_F; } - if (SCM_INUM(MU_SCM_SYMBOL_VALUE("mu-debug"))) + if (scm_to_int32 (MU_SCM_SYMBOL_VALUE("mu-debug"))) { mu_debug_t debug = NULL; mu_mailer_get_debug (mailer, &debug); diff --git a/libmu_scm/mu_mime.c b/libmu_scm/mu_mime.c index 836ddc2df..84923face 100644 --- a/libmu_scm/mu_mime.c +++ b/libmu_scm/mu_mime.c @@ -1,5 +1,5 @@ /* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2006 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 @@ -66,7 +66,7 @@ mu_scm_mime_create (SCM owner, mu_mime_t mime) { struct mu_mime *mum; - mum = scm_must_malloc (sizeof (struct mu_mime), "mime"); + mum = scm_gc_malloc (sizeof (struct mu_mime), "mime"); mum->owner = owner; mum->mime = mime; SCM_RETURN_NEWSMOB (mime_tag, mum); @@ -96,7 +96,8 @@ SCM_DEFINE (scm_mu_mime_create, "mu-mime-create", 0, 2, 0, mu_message_t msg = NULL; mu_mime_t mime; int flags; - + int status; + if (SCM_IMP (FLAGS) && SCM_BOOLP (FLAGS)) { /*if (FLAGS == SCM_BOOL_F)*/ @@ -104,9 +105,8 @@ SCM_DEFINE (scm_mu_mime_create, "mu-mime-create", 0, 2, 0, } else { - SCM_ASSERT (SCM_IMP (FLAGS) && SCM_INUMP (FLAGS), - FLAGS, SCM_ARG1, FUNC_NAME); - flags = SCM_INUM (FLAGS); + SCM_ASSERT (scm_is_integer (FLAGS), FLAGS, SCM_ARG1, FUNC_NAME); + flags = scm_to_int32 (FLAGS); } if (!SCM_UNBNDP (MESG)) @@ -115,8 +115,10 @@ SCM_DEFINE (scm_mu_mime_create, "mu-mime-create", 0, 2, 0, msg = mu_scm_message_get (MESG); } - if (mu_mime_create (&mime, msg, flags)) - return SCM_BOOL_F; + status = mu_mime_create (&mime, msg, flags); + if (status) + mu_scm_error (FUNC_NAME, status, + "Cannot create MIME object", SCM_BOOL_F); return mu_scm_mime_create (MESG, mime); } @@ -139,11 +141,14 @@ SCM_DEFINE (scm_mu_mime_get_num_parts, "mu-mime-get-num-parts", 1, 0, 0, { mu_mime_t mime; size_t nparts; + int status; SCM_ASSERT (mu_scm_is_mime (MIME), MIME, SCM_ARG1, FUNC_NAME); mime = mu_scm_mime_get (MIME); - if (mu_mime_get_num_parts (mime, &nparts)) - return SCM_BOOL_F; + status = mu_mime_get_num_parts (mime, &nparts); + if (status) + mu_scm_error (FUNC_NAME, status, + "Cannot count MIME parts", SCM_BOOL_F); return mu_scm_makenum (nparts); } #undef FUNC_NAME @@ -154,13 +159,18 @@ SCM_DEFINE (scm_mu_mime_get_part, "mu-mime-get-part", 2, 0, 0, #define FUNC_NAME s_scm_mu_mime_get_part { mu_message_t msg = NULL; - + int status; + SCM_ASSERT (mu_scm_is_mime (MIME), MIME, SCM_ARG1, FUNC_NAME); - SCM_ASSERT (SCM_IMP (PART) && SCM_INUMP (PART), - PART, SCM_ARG2, FUNC_NAME); + SCM_ASSERT (scm_is_integer (PART), PART, SCM_ARG2, FUNC_NAME); + + status = mu_mime_get_part (mu_scm_mime_get (MIME), + scm_to_int32 (PART), &msg); + if (status) + mu_scm_error (FUNC_NAME, status, + "Cannot get part ~A from MIME object ~A", + scm_list_2 (PART, MIME)); - if (mu_mime_get_part (mu_scm_mime_get (MIME), SCM_INUM (PART), &msg)) - return SCM_BOOL_F; return mu_scm_message_create (MIME, msg); } #undef FUNC_NAME @@ -172,15 +182,19 @@ SCM_DEFINE (scm_mu_mime_add_part, "mu-mime-add-part", 2, 0, 0, { mu_mime_t mime; mu_message_t msg; - + int status; + SCM_ASSERT (mu_scm_is_mime (MIME), MIME, SCM_ARG1, FUNC_NAME); SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG2, FUNC_NAME); mime = mu_scm_mime_get (MIME); msg = mu_scm_message_get (MESG); - if (mu_mime_add_part (mime, msg)) - return SCM_BOOL_F; - + status = mu_mime_add_part (mime, msg); + if (status) + mu_scm_error (FUNC_NAME, status, + "Cannot add new part to MIME object ~A", + scm_list_1 (MIME)); + mu_scm_message_add_owner (MESG, MIME); return SCM_BOOL_T; @@ -194,11 +208,16 @@ SCM_DEFINE (scm_mu_mime_get_message, "mu-mime-get-message", 1, 0, 0, { mu_mime_t mime; mu_message_t msg; + int status; SCM_ASSERT (mu_scm_is_mime (MIME), MIME, SCM_ARG1, FUNC_NAME); mime = mu_scm_mime_get (MIME); - if (mu_mime_get_message (mime, &msg)) - return SCM_BOOL_F; + status = mu_mime_get_message (mime, &msg); + if (status) + mu_scm_error (FUNC_NAME, status, + "Cannot get message from MIME object ~A", + scm_list_1 (MIME)); + return mu_scm_message_create (MIME, msg); } #undef FUNC_NAME diff --git a/libmu_scm/mu_port.c b/libmu_scm/mu_port.c index 523fea711..0120a160b 100644 --- a/libmu_scm/mu_port.c +++ b/libmu_scm/mu_port.c @@ -1,5 +1,5 @@ /* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2006 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 @@ -81,7 +81,7 @@ mu_port_make_from_stream (SCM msg, mu_stream_t stream, long mode) SCM port; scm_port *pt; - mp = scm_must_malloc (sizeof (struct mu_port), "mu-port"); + mp = scm_gc_malloc (sizeof (struct mu_port), "mu-port"); mp->msg = msg; mp->stream = stream; mp->offset = 0; @@ -159,10 +159,13 @@ mu_port_fill_input (SCM port) struct mu_port *mp = MU_PORT (port); scm_port *pt = SCM_PTAB_ENTRY (port); size_t nread = 0; + int status; - if (mu_stream_read (mp->stream, pt->read_buf, pt->read_buf_size, - |