X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=compress.c;h=f4b8b6749066f9d705a692bfebe50aefaa9a963e;hp=18972548195566840360d601dfdbcd10e025c726;hb=250e22d7ca2420a08b34711713839780fd042ba9;hpb=ee1d4d931ca3ebec494694b74a1868a7a2e631e3 diff --git a/compress.c b/compress.c index 1897254..f4b8b67 100644 --- a/compress.c +++ b/compress.c @@ -7,21 +7,18 @@ * please see the file GPL in the top level source directory. */ -#include "mutt.h" +#include -#ifdef USE_COMPRESSED +#include +#include -#include "mx.h" -#include "mutt_curses.h" +#include -#include "lib/mem.h" -#include "lib/intl.h" -#include "lib/str.h" +#include "mutt.h" -#include -#include -#include -#include +#include "mx.h" +#include "mbox.h" +#include "compress.h" typedef struct { const char *close; /* close-hook command */ @@ -37,7 +34,7 @@ char echo_cmd[HUGE_STRING]; * excl - exclusive lock? * retry - should retry if unable to lock? */ -int mbox_lock_compressed (CONTEXT * ctx, FILE * fp, int excl, int retry) +static int mbox_lock_compressed (CONTEXT * ctx, FILE * fp, int excl, int retry) { int r; @@ -51,7 +48,7 @@ int mbox_lock_compressed (CONTEXT * ctx, FILE * fp, int excl, int retry) return (r); } -void mbox_unlock_compressed (CONTEXT * ctx, FILE * fp) +static void mbox_unlock_compressed (CONTEXT * ctx, FILE * fp) { if (ctx->locked) { fflush (fp); @@ -111,7 +108,7 @@ static COMPRESS_INFO *set_compress_info (CONTEXT * ctx) COMPRESS_INFO *ci; /* Now lets uncompress this thing */ - ci = safe_malloc (sizeof (COMPRESS_INFO)); + ci = p_new(COMPRESS_INFO, 1); ctx->compressinfo = (void *) ci; ci->append = find_compress_hook (M_APPENDHOOK, ctx->path); ci->open = find_compress_hook (M_OPENHOOK, ctx->path); @@ -128,8 +125,7 @@ static void set_path (CONTEXT * ctx) /* Uncompress to /tmp */ mutt_mktemp (tmppath); - ctx->path = safe_malloc (safe_strlen (tmppath) + 1); - strcpy (ctx->path, tmppath); + ctx->path = p_dupstr(tmppath, m_strlen(tmppath)); } static int get_size (const char *path) @@ -148,13 +144,13 @@ static void store_size (CONTEXT * ctx) ci->size = get_size (ctx->realpath); } -static const char *compresshook_format_str (char *dest, size_t destlen, +static const char *compresshook_format_str (char *dest, ssize_t destlen, char op, const char *src, const char *fmt, - const char *ifstring, - const char *elsestring, + const char *ifstring __attribute__ ((unused)), + const char *elsestring __attribute__ ((unused)), unsigned long data, - format_flag flags) + format_flag flags __attribute__ ((unused))) { char tmp[SHORT_STRING]; @@ -187,7 +183,7 @@ static char *get_compression_cmd (const char *cmd, const CONTEXT * ctx) mutt_FormatString (expanded, sizeof (expanded), cmd, compresshook_format_str, (unsigned long) ctx, 0); - return safe_strdup (expanded); + return m_strdup(expanded); } int mutt_check_mailbox_compressed (CONTEXT * ctx) @@ -195,8 +191,8 @@ int mutt_check_mailbox_compressed (CONTEXT * ctx) COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo; if (ci->size != get_size (ctx->realpath)) { - FREE (&ctx->compressinfo); - FREE (&ctx->realpath); + p_delete(&ctx->compressinfo); + p_delete(&ctx->realpath); mutt_error _("Mailbox was corrupted!"); return (-1); @@ -214,7 +210,7 @@ int mutt_open_read_compressed (CONTEXT * ctx) if (!ci->open) { ctx->magic = 0; - FREE (ctx->compressinfo); + p_delete(&ctx->compressinfo); return (-1); } if (!ci->close || access (ctx->path, W_OK) != 0) @@ -229,11 +225,10 @@ int mutt_open_read_compressed (CONTEXT * ctx) cmd = get_compression_cmd (ci->open, ctx); if (cmd == NULL) return (-1); - dprint (2, (debugfile, "DecompressCmd: '%s'\n", cmd)); if ((fp = fopen (ctx->realpath, "r")) == NULL) { mutt_perror (ctx->realpath); - FREE (&cmd); + p_delete(&cmd); return (-1); } mutt_block_signals (); @@ -242,7 +237,7 @@ int mutt_open_read_compressed (CONTEXT * ctx) mutt_unblock_signals (); mutt_error _("Unable to lock mailbox!"); - FREE (&cmd); + p_delete(&cmd); return (-1); } @@ -258,11 +253,11 @@ int mutt_open_read_compressed (CONTEXT * ctx) if (rc) { mutt_any_key_to_continue (NULL); ctx->magic = 0; - FREE (ctx->compressinfo); + p_delete(&ctx->compressinfo); mutt_error (_("Error executing: %s : unable to open the mailbox!\n"), cmd); } - FREE (&cmd); + p_delete(&cmd); if (rc) return (-1); @@ -274,14 +269,14 @@ int mutt_open_read_compressed (CONTEXT * ctx) return (0); } -void restore_path (CONTEXT * ctx) +static void restore_path (CONTEXT * ctx) { - FREE (&ctx->path); + p_delete(&ctx->path); ctx->path = ctx->realpath; } /* remove the temporary mailbox */ -void remove_file (CONTEXT * ctx) +static void remove_file (CONTEXT * ctx) { if (ctx->magic == M_MBOX || ctx->magic == M_MMDF) remove (ctx->path); @@ -297,7 +292,7 @@ int mutt_open_append_compressed (CONTEXT * ctx) return (mutt_open_read_compressed (ctx)); ctx->magic = 0; - FREE (&ctx->compressinfo); + p_delete(&ctx->compressinfo); return (-1); } @@ -317,9 +312,6 @@ int mutt_open_append_compressed (CONTEXT * ctx) /* close a compressed mailbox */ void mutt_fast_close_compressed (CONTEXT * ctx) { - dprint (2, (debugfile, "mutt_fast_close_compressed called on '%s'\n", - ctx->path)); - if (ctx->compressinfo) { if (ctx->fp) fclose (ctx->fp); @@ -331,7 +323,7 @@ void mutt_fast_close_compressed (CONTEXT * ctx) remove_file (ctx); restore_path (ctx); - FREE (&ctx->compressinfo); + p_delete(&ctx->compressinfo); } } @@ -352,7 +344,7 @@ int mutt_sync_compressed (CONTEXT * ctx) if ((fp = fopen (ctx->realpath, "a")) == NULL) { mutt_perror (ctx->realpath); - FREE (&cmd); + p_delete(&cmd); return (-1); } mutt_block_signals (); @@ -363,12 +355,10 @@ int mutt_sync_compressed (CONTEXT * ctx) store_size (ctx); - FREE (&cmd); + p_delete(&cmd); return (-1); } - dprint (2, (debugfile, "CompressCommand: '%s'\n", cmd)); - endwin (); fflush (stdout); sprintf (echo_cmd, _("echo Compressing %s..."), ctx->realpath); @@ -385,7 +375,7 @@ int mutt_sync_compressed (CONTEXT * ctx) mutt_unblock_signals (); fclose (fp); - FREE (&cmd); + p_delete(&cmd); store_size (ctx); @@ -399,9 +389,6 @@ int mutt_slow_close_compressed (CONTEXT * ctx) char *cmd; COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo; - dprint (2, (debugfile, "mutt_slow_close_compressed called on '%s'\n", - ctx->path)); - if (!(ctx->append && ((append = get_append_command (ctx->realpath, ctx)) || (append = ci->close)))) { /* if we can not or should not append, * we only have to remove the compressed info, because sync was already @@ -428,7 +415,7 @@ int mutt_slow_close_compressed (CONTEXT * ctx) if ((fp = fopen (ctx->realpath, "a")) == NULL) { mutt_perror (ctx->realpath); - FREE (&cmd); + p_delete(&cmd); return (-1); } mutt_block_signals (); @@ -437,12 +424,10 @@ int mutt_slow_close_compressed (CONTEXT * ctx) mutt_unblock_signals (); mutt_error _("Unable to lock mailbox!"); - FREE (&cmd); + p_delete(&cmd); return (-1); } - dprint (2, (debugfile, "CompressCmd: '%s'\n", cmd)); - endwin (); fflush (stdout); @@ -458,7 +443,7 @@ int mutt_slow_close_compressed (CONTEXT * ctx) mutt_error (_ (" %s: Error compressing mailbox! Uncompressed one kept!\n"), ctx->path); - FREE (&cmd); + p_delete(&cmd); mbox_unlock_compressed (ctx, fp); mutt_unblock_signals (); fclose (fp); @@ -470,10 +455,23 @@ int mutt_slow_close_compressed (CONTEXT * ctx) fclose (fp); remove_file (ctx); restore_path (ctx); - FREE (&cmd); - FREE (&ctx->compressinfo); + p_delete(&cmd); + p_delete(&ctx->compressinfo); return (0); } -#endif /* USE_COMPRESSED */ +mx_t const compress_mx = { + M_COMPRESSED, + 1, + mbox_is_magic, + mbox_check_empty, + access, + mutt_open_read_compressed, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, +};