]> granicus.if.org Git - neomutt/commitdiff
Add (and use) a function mutt_str_replace, which essentially
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 10 Jan 2000 10:35:48 +0000 (10:35 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 10 Jan 2000 10:35:48 +0000 (10:35 +0000)
replaces the sequence:

safe_free (&s);
s = safe_strdup (t);

21 files changed:
attach.c
browser.c
compose.c
curs_main.c
edit.c
history.c
init.c
lib.c
main.c
menu.c
mh.c
muttlib.c
parse.c
pgpkey.c
postpone.c
protos.h
recvattach.c
rfc1524.c
rfc2047.c
send.c
sendlib.c

index 93658e440c034201c5eb01ecf2da7a0d22650b8e..57c3bde9038b8b01e75b62b0fc50c3aad15daf38 100644 (file)
--- a/attach.c
+++ b/attach.c
@@ -65,8 +65,7 @@ int mutt_get_tmp_attachment (BODY *a)
   if((fpin = fopen(a->filename, "r")) && (fpout = safe_fopen(tempfile, "w")))
   {
     mutt_copy_stream (fpin, fpout);
-    FREE(&a->filename);
-    a->filename = safe_strdup(tempfile);
+    mutt_str_replace (&a->filename, tempfile);
     a->unlink = 1;
 
     if(a->stamp >= st.st_mtime)
index bb538160c1abccff1fabea1b330b69d445060eda..d1ae8decb6d6e45945a7ebf1a472fe9bfb7e1e4c 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -932,10 +932,9 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
          }
          else
          {
-           safe_free ((void **) &Mask.pattern);
+           mutt_str_replace (&Mask.pattern, buf);
            regfree (Mask.rx);
            safe_free ((void **) &Mask.rx);
-           Mask.pattern = safe_strdup (buf);
            Mask.rx = rx;
            Mask.not = not;
 
index d49a22d7c2ee2134ced94bfe8baea93d7a5db092..9b55143afbcb0d15027f7815e59e76ad20683940 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -152,8 +152,8 @@ static int pgp_send_menu (int bits, int *redraw)
     if ((p = pgp_ask_for_key (_("Sign as: "), NULL, KEYFLAG_CANSIGN, PGP_PUBRING)))
     {
       snprintf (input_signas, sizeof (input_signas), "0x%s", pgp_keyid (p));
-      safe_free((void **) &PgpSignAs);             PgpSignAs = safe_strdup (input_signas);
-      safe_free((void **) &PgpSignMicalg);  PgpSignMicalg = safe_strdup (pgp_pkalg_to_mic (p->algorithm));
+      mutt_str_replace (&PgpSignAs, input_signas);
+      mutt_str_replace (&PgpSignMicalg, pgp_pkalg_to_mic (p->algorithm));
       pgp_free_key (&p);
       
       bits |= PGPSIGN;
@@ -188,10 +188,7 @@ static int pgp_send_menu (int bits, int *redraw)
          mutt_error _("Unknown MIC algorithm, valid ones are: pgp-md5, pgp-sha1, pgp-rmd160");
        }
        else 
-       {
-         safe_free ((void **) &PgpSignMicalg);
-         PgpSignMicalg = safe_strdup (input_micalg);
-       }
+         mutt_str_replace (&PgpSignMicalg, input_micalg);
       }
     }
     break;
@@ -487,8 +484,7 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
          buf[0] = 0;
        if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
        {
-         safe_free ((void **) &msg->env->subject);
-         msg->env->subject = safe_strdup (buf);
+         mutt_str_replace (&msg->env->subject, buf);
          move (HDR_SUBJECT, HDR_XOFFSET);
          clrtoeol ();
          if (msg->env->subject)
@@ -825,8 +821,7 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
        /* header names should not be translated */
        if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0)
        {
-         safe_free ((void **) &idx[menu->current]->content->description);
-         idx[menu->current]->content->description = safe_strdup (buf);
+         mutt_str_replace (&idx[menu->current]->content->description, buf);
          menu->redraw = REDRAW_CURRENT;
        }
        break;
@@ -964,8 +959,7 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
          if(mutt_rename_file (idx[menu->current]->content->filename, fname))
            break;
          
-         safe_free ((void **) &idx[menu->current]->content->filename);
-         idx[menu->current]->content->filename = safe_strdup (fname);
+         mutt_str_replace (&idx[menu->current]->content->filename, fname);
          menu->redraw = REDRAW_CURRENT;
 
          if(idx[menu->current]->content->stamp >= st.st_mtime)
@@ -1036,8 +1030,7 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
          menu->max = idxlen;
 
          idx[menu->current]->content->type = itype;
-         safe_free ((void **) &idx[menu->current]->content->subtype);
-         idx[menu->current]->content->subtype = safe_strdup (p);
+         mutt_str_replace (&idx[menu->current]->content->subtype, p);
          idx[menu->current]->content->unlink = 1;
          menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
 
index af352027449ed87404984d9749750d6b19aa98fd..f8e2b5371c2a2a34073fe4e484af23bd37774a9d 100644 (file)
@@ -918,12 +918,8 @@ int mutt_index_menu (void)
 
         if (Context)
         {
-         FREE (&LastFolder);
-         LastFolder = safe_strdup (Context->path);
-       }
+         mutt_str_replace (&LastFolder, Context->path);
 
-       if (Context)
-       {
          if (mx_close_mailbox (Context) != 0)
          {
            menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
diff --git a/edit.c b/edit.c
index 92f21dfe9bc69f8e178c70f3455921d65627b127..73be6b85c9e72c130adecfd117a2b84b6178779a 100644 (file)
--- a/edit.c
+++ b/edit.c
@@ -253,10 +253,7 @@ static void be_edit_header (ENVELOPE *e, int force)
     addstr ("Subject: ");
     strfcpy (tmp, e->subject ? e->subject: "", sizeof (tmp));
     if (mutt_enter_string ((unsigned char *) tmp, sizeof (tmp), LINES-1, 9, 0) == 0)
-    {
-      safe_free ((void **) &e->subject);
-      e->subject = safe_strdup (tmp);
-    }
+      mutt_str_replace (&e->subject, tmp);
     addch ('\n');
   }
 
@@ -391,8 +388,7 @@ int mutt_builtin_editor (const char *path, HEADER *msg, HEADER *cur)
            addstr (_("missing filename.\n"));
          break;
        case 's':
-         safe_free ((void **) &msg->env->subject);
-         msg->env->subject = safe_strdup (p);
+         mutt_str_replace (&msg->env->subject, p);
          break;
        case 't':
          msg->env->to = rfc822_parse_adrlist (msg->env->to, p);
index dfd2234e4fadf037857c49f2c0916cc29925a85a..f38b4969994a6dd3364867c44f97634b65afc1eb 100644 (file)
--- a/history.c
+++ b/history.c
@@ -79,8 +79,7 @@ void mutt_history_add (history_class_t hclass, const char *s)
     if (prev < 0) prev = HistSize - 1;
     if (!h->hist[prev] || mutt_strcmp (h->hist[prev], s) != 0)
     {
-      safe_free ((void **) &h->hist[h->last]);
-      h->hist[h->last++] = safe_strdup (s);
+      mutt_str_replace (&h->hist[h->last++], s);
       if (h->last > HistSize - 1)
        h->last = 0;
     }
diff --git a/init.c b/init.c
index c824c047bd301ac02063b44e99377cc3207be3f9..56e6510597898c1c9b66f2fc9a8147862b89c482 100644 (file)
--- a/init.c
+++ b/init.c
@@ -653,20 +653,16 @@ static void mutt_restore_default (struct option_t *p)
   {
     case DT_STR:
       if (p->init)
-      {
-       FREE (p->data);
-       *((char **) p->data) = safe_strdup ((char *) p->init);
-      }
+       mutt_str_replace ((char **) p->data, (char *) p->init); 
       break;
     case DT_PATH:
       if (p->init)
       {
        char path[_POSIX_PATH_MAX];
 
-       FREE (p->data);
        strfcpy (path, (char *) p->init, sizeof (path));
        mutt_expand_path (path, sizeof (path));
-       *((char **) p->data) = safe_strdup (path);
+       mutt_str_replace ((char **) p->data, path);
       }
       break;
     case DT_ADDR:
diff --git a/lib.c b/lib.c
index dff66a2f46ae9a352d1aa08f493157e252c2b2dd..d16a5e1484048ff2f5b416e243ef8fffe58414c5 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -143,6 +143,13 @@ char *safe_strdup (const char *s)
   return (p);
 }
 
+void mutt_str_replace (char **p, const char *s)
+{
+  if (*p)
+    free (*p);
+  *p = safe_strdup (s);
+}
+
 /* convert all characters in the string to lowercase */
 char *mutt_strlower (char *s)
 {
diff --git a/main.c b/main.c
index 477190c1090521247aa70acae50cc78c70c2e906..46a70af4502701c938ed8480d7bdd55b6434fae1 100644 (file)
--- a/main.c
+++ b/main.c
@@ -396,8 +396,7 @@ int main (int argc, char **argv)
        break;
 
       case 'F':
-       FREE (&Muttrc);
-       Muttrc = safe_strdup (optarg);
+       mutt_str_replace (&Muttrc, optarg);
        break;
 
       case 'f':
diff --git a/menu.c b/menu.c
index 809a941e20bde300dc9da759a8217b248bcd91ed..759bdcdd3d94c8c7c1a5e667c3c3cb6d21b78dc8 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -658,8 +658,7 @@ static int menu_search (MUTTMENU *menu, int op)
                                             _("Reverse search for: "),
                         buf, sizeof (buf), M_CLEAR) != 0 || !buf[0])
       return (-1);
-    safe_free ((void **) &menu->searchBuf);
-    menu->searchBuf = safe_strdup (buf);
+    mutt_str_replace (&menu->searchBuf, buf);
     menu->searchDir = (op == OP_SEARCH) ? M_SEARCH_DOWN : M_SEARCH_UP;
   }
   else 
diff --git a/mh.c b/mh.c
index a4d6678709ebafa8069bbc13b5426ff5392bbb58..a4805978f1a8a14c4a486b529ead45532df6789b 100644 (file)
--- a/mh.c
+++ b/mh.c
@@ -500,10 +500,7 @@ int maildir_commit_message (CONTEXT *ctx, MESSAGE *msg, HEADER *hdr)
     if (safe_rename (msg->path, full) == 0)
     {
       if (hdr) 
-      {
-       FREE (&hdr->path);
-       hdr->path = safe_strdup (path);
-      }
+       mutt_str_replace (&hdr->path, path);
       FREE (&msg->path);
       return 0;
     }
@@ -575,10 +572,7 @@ int mh_commit_message (CONTEXT *ctx, MESSAGE *msg, HEADER *hdr)
     if (safe_rename (msg->path, path) == 0)
     {
       if (hdr)
-      {
-       FREE (&hdr->path);
-       hdr->path = safe_strdup (tmp);
-      }
+       mutt_str_replace (&hdr->path, tmp);
       FREE (&msg->path);
       return 0;
     }
@@ -648,10 +642,7 @@ static int mh_sync_message (CONTEXT *ctx, int msgno)
     {
       snprintf (newpath, _POSIX_PATH_MAX, "%s/%s", ctx->path, h->path);
       if ((rc = safe_rename (newpath, oldpath)) == 0)
-      {
-       FREE (&h->path);
-       h->path = safe_strdup (partpath);
-      }
+       mutt_str_replace (&h->path, partpath);
     }
   }
   else mx_close_message (&dest);
@@ -719,8 +710,7 @@ static int maildir_sync_message (CONTEXT *ctx, int msgno)
       mutt_perror ("rename");
       return (-1);
     }
-    safe_free ((void **) &h->path);
-    h->path = safe_strdup (partpath);
+    mutt_str_replace (&h->path, partpath);
   }
   return (0);
 }
@@ -928,10 +918,7 @@ int mh_check_mailbox(CONTEXT *ctx, int *index_hint)
                 ctx->hdrs[i]->read    ? "R" : ""));
 
       if(mutt_strcmp(ctx->hdrs[i]->path, p->h->path))
-      {
-       safe_free((void **) &ctx->hdrs[i]->path);
-       ctx->hdrs[i]->path = safe_strdup(p->h->path);
-      }
+       mutt_str_replace (&ctx->hdrs[i]->path, p->h->path);
 
       if(modified)
       {
index ae7d7eb688d6ca42c3b21d13c9dcb3bcc0a11664..8d7ed9e90ad9a27e6f3b6827e9856dd609d67f48 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -403,8 +403,7 @@ void mutt_set_parameter (const char *attribute, const char *value, PARAMETER **p
   {
     if (mutt_strcasecmp (attribute, q->attribute) == 0)
     {
-      safe_free((void **) &q->value);
-      q->value = safe_strdup(value);
+      mutt_str_replace (&q->value, value);
       return;
     }
   }
diff --git a/parse.c b/parse.c
index 93b3854c2c6f4c14c23d2d56c949123992d23d8b..0f6a82c827a3b9286ce56c30034b51fe229a9cdf 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -348,8 +348,7 @@ static void parse_content_disposition (char *s, BODY *ct)
        * have allocated space if a "name=filename" parameter was
        * specified.
        */
-      safe_free ((void **) &ct->filename);
-      ct->filename = safe_strdup (s); 
+      mutt_str_replace (&ct->filename, s);
     }
     if ((s = mutt_get_parameter ("name", parms)) != 0)
       ct->form_name = safe_strdup (s);
@@ -406,8 +405,7 @@ BODY *mutt_read_mime_header (FILE *fp, int digest)
        parse_content_disposition (c, p);
       else if (!mutt_strcasecmp ("description", line + 8))
       {
-       safe_free ((void **) &p->description);
-       p->description = safe_strdup (c);
+       mutt_str_replace (&p->description, c);
        rfc2047_decode (p->description, p->description, mutt_strlen (p->description) + 1);
       }
     }
@@ -455,8 +453,7 @@ void mutt_parse_part (FILE *fp, BODY *b)
   if (!b->parts)
   {
     b->type = TYPETEXT;
-    safe_free ((void **) &b->subtype);
-    b->subtype = safe_strdup ("plain");
+    mutt_str_replace (&b->subtype, "plain");
   }
 }
 
@@ -988,8 +985,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE *f, HEADER *hdr, short user_hdrs,
          {
            if (hdr)
            {
-             safe_free ((void **) &hdr->content->description);
-             hdr->content->description = safe_strdup (p);
+             mutt_str_replace (&hdr->content->description, p);
              rfc2047_decode (hdr->content->description,
                              hdr->content->description,
                              mutt_strlen (hdr->content->description) + 1);
@@ -1008,8 +1004,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE *f, HEADER *hdr, short user_hdrs,
       case 'd':
        if (!mutt_strcasecmp ("ate", line + 1))
        {
-         safe_free((void **)&e->date);
-         e->date = safe_strdup(p);
+         mutt_str_replace (&e->date, p);
          if (hdr)
            hdr->date_sent = mutt_parse_date (p, hdr);
          matched = 1;
index d2fd5503b22d010663b53f624f2b1b28f70de590..c9b28df5ab4f93a86bd4ccd7218b75c69f6cde7c 100644 (file)
--- a/pgpkey.c
+++ b/pgpkey.c
@@ -618,10 +618,7 @@ pgp_key_t *pgp_ask_for_key (char *tag, char *whatfor,
     if (whatfor)
     {
       if (l)
-      {
-       safe_free ((void **) &l->dflt);
-       l->dflt = safe_strdup (resp);
-      }
+       mutt_str_replace (&l->dflt, resp);
       else
       {
        l = safe_malloc (sizeof (struct pgp_cache));
index d386bcc630480c311fdf8f5f6d005c593d5e24ac..743aa0ab0ce48f574f078a90fcaa03953f12ad1f 100644 (file)
@@ -482,17 +482,11 @@ int mutt_parse_pgp_hdr (char *p, int set_signas)
   }
  
   if (set_signas || *pgp_sign_as)
-  {
-    safe_free((void **) &PgpSignAs);
-    PgpSignAs = safe_strdup(pgp_sign_as);
-  }
+    mutt_str_replace (&PgpSignAs, pgp_sign_as);
 
   /* the micalg field must not be empty */
   if (set_signas && *pgp_sign_micalg)
-  {
-    safe_free((void **) &PgpSignMicalg);
-    PgpSignMicalg = safe_strdup(pgp_sign_micalg);
-  }
+    mutt_str_replace (&PgpSignMicalg, pgp_sign_micalg);
 
   return pgp;
 }
@@ -624,8 +618,7 @@ int mutt_prepare_template (FILE *fp, CONTEXT *ctx, HEADER *newhdr, HEADER *hdr,
       return -1;
     }
     
-    safe_free ((void *) &b->filename);
-    b->filename = safe_strdup (file);
+    mutt_str_replace (&b->filename, file);
     b->unlink = 1;
 
     if (mutt_is_text_type (b->type, b->subtype))
index 7efd31245cc27357e332e144c90e5df1dd462984..cc6727469e469b0b9af157f791c787c9b0503184 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -194,6 +194,7 @@ void mutt_shell_escape (void);
 void mutt_show_error (void);
 void mutt_signal_init (void);
 void mutt_stamp_attachment (BODY *a);
+void mutt_str_replace (char **p, const char *s);
 void mutt_tabs_to_spaces (char *);
 void mutt_tag_set_flag (int, int);
 void mutt_unblock_signals (void);
index 09b034c859b82feead1d6261b80a3c69d901921b..81acec92b4cd4cdcd0c222bd853ef013ac713f58 100644 (file)
@@ -88,10 +88,7 @@ void mutt_update_tree (ATTACHPTR **idx, short idxlen)
     if (idx[x]->tree)
     {
       if (mutt_strcmp (idx[x]->tree, buf) != 0)
-      {
-       safe_free ((void **) &idx[x]->tree);
-       idx[x]->tree = safe_strdup (buf);
-      }
+       mutt_str_replace (&idx[x]->tree, buf);
     }
     else
       idx[x]->tree = safe_strdup (buf);
index cc727aab5d72ef2631b7ba8603ff246d7131091e..4e20b4a80e06af6d2afb45f1b76a7c9c5af2a02a 100644 (file)
--- a/rfc1524.c
+++ b/rfc1524.c
@@ -150,8 +150,7 @@ static int get_field_text (char *field, char **entry,
     {
       field++;
       field = mutt_skip_whitespace (field);
-      safe_free ((void **) entry);
-      *entry = safe_strdup (field);
+      mutt_str_replace (entry, field);
     }
     return 1;
   }
index e8a3e6ed01df152bc56a3eba88089404386ff1f4..89cd09ae0ac7f08d47cc8f972d89aa27948f1863 100644 (file)
--- a/rfc2047.c
+++ b/rfc2047.c
@@ -259,15 +259,13 @@ void rfc2047_encode_adrlist (ADDRESS *addr)
     if (ptr->personal)
     {
       rfc2047_encode_string (buffer, sizeof (buffer), (const unsigned char *)ptr->personal);
-      safe_free ((void **) &ptr->personal);
-      ptr->personal = safe_strdup (buffer);
+      mutt_str_replace (&ptr->personal, buffer);
     }
 #ifdef EXACT_ADDRESS
     if (ptr->val)
     {
       rfc2047_encode_string (buffer, sizeof (buffer), (const unsigned char *)ptr->val);
-      safe_free ((void **) &ptr->val);
-      ptr->val = safe_strdup (buffer);
+      mutt_str_replace (&ptr->val, buffer);
     }
 #endif
     ptr = ptr->next;
diff --git a/send.c b/send.c
index 65a977d217fdb2cd6de91d12c96e3464dc172a55..c631fc57eb360660d12ea27129e2ef75ffa95b02 100644 (file)
--- a/send.c
+++ b/send.c
@@ -234,8 +234,7 @@ static int edit_envelope (ENVELOPE *en)
     mutt_message _("No subject, aborting.");
     return (-1);
   }
-  safe_free ((void **) &en->subject);
-  en->subject = safe_strdup (buf);
+  mutt_str_replace (&en->subject, buf);
 
   return 0;
 }
@@ -914,8 +913,7 @@ static void encode_descriptions (BODY *b)
     if (t->description)
     {
       rfc2047_encode_string (tmp, sizeof (tmp), (unsigned char *) t->description);
-      safe_free ((void **) &t->description);
-      t->description = safe_strdup (tmp);
+      mutt_str_replace (&t->description, tmp);
     }
     if (t->parts)
       encode_descriptions (t->parts);
index 255f38ccee908251f2ab50dd836ada15b5a4fe3c..4ce2d873d83d7f1b93807c4252d6aa85e3b33eeb 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -1381,8 +1381,7 @@ static void encode_headers (LIST *h)
       snprintf (tmp, sizeof (tmp), "%s: ", h->data);
       len = mutt_strlen (tmp);
       rfc2047_encode_string (tmp + len, sizeof (tmp) - len, (unsigned char *) p);
-      safe_free ((void **) &h->data);
-      h->data = safe_strdup (tmp);
+      mutt_str_replace (&h->data, tmp);
     }
   }
 }
@@ -1811,8 +1810,7 @@ void mutt_prepare_envelope (ENVELOPE *env)
   {
     rfc2047_encode_string (buffer, sizeof (buffer) - 1,
                           (unsigned char *) env->subject);
-    safe_free ((void **) &env->subject);
-    env->subject = safe_strdup (buffer);
+    mutt_str_replace (&env->subject, buffer);
   }
   encode_headers (env->userhdrs);