Skip to content

Commit

Permalink
rename mutt_buffer_*() functinos
Browse files Browse the repository at this point in the history
Give the most commonly used functions shorter names.

mutt_buffer_* -> buf_*
  • Loading branch information
flatcap committed Apr 14, 2023
1 parent 15cf0eb commit d679706
Show file tree
Hide file tree
Showing 253 changed files with 5,777 additions and 5,913 deletions.
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,7 @@
- refactor: create a generic base64 encode/decode
- debug: remove dprint in favor of mutt_debug (#375)
- Fix dubious use macro for _() / gettext() (#376)
- Use mutt_buffer_init instead of memset
- Use buf_init instead of memset
- Make the heap method and datatype a plain list
- Reverts making AliasFile into a list_t (#379)
- Turn mutt_new_* macros into inline functions
Expand Down
50 changes: 25 additions & 25 deletions address/address.c
Original file line number Diff line number Diff line change
Expand Up @@ -1066,60 +1066,60 @@ size_t mutt_addr_write(struct Buffer *buf, struct Address *addr, bool display)
return 0;
}

const size_t initial_len = mutt_buffer_len(buf);
const size_t initial_len = buf_len(buf);

if (addr->personal)
{
if (strpbrk(addr->personal, AddressSpecials))
{
mutt_buffer_addch(buf, '"');
buf_addch(buf, '"');
for (const char *pc = addr->personal; *pc; pc++)
{
if ((*pc == '"') || (*pc == '\\'))
{
mutt_buffer_addch(buf, '\\');
buf_addch(buf, '\\');
}
mutt_buffer_addch(buf, *pc);
buf_addch(buf, *pc);
}
mutt_buffer_addch(buf, '"');
buf_addch(buf, '"');
}
else
{
mutt_buffer_addstr(buf, addr->personal);
buf_addstr(buf, addr->personal);
}

mutt_buffer_addch(buf, ' ');
buf_addch(buf, ' ');
}

if (addr->personal || (addr->mailbox && (*addr->mailbox == '@')))
{
mutt_buffer_addch(buf, '<');
buf_addch(buf, '<');
}

if (addr->mailbox)
{
if (!mutt_str_equal(addr->mailbox, "@"))
{
const char *a = display ? mutt_addr_for_display(addr) : addr->mailbox;
mutt_buffer_addstr(buf, a);
buf_addstr(buf, a);
}

if (addr->personal || (addr->mailbox && (*addr->mailbox == '@')))
{
mutt_buffer_addch(buf, '>');
buf_addch(buf, '>');
}

if (addr->group)
{
mutt_buffer_addstr(buf, ": ");
buf_addstr(buf, ": ");
}
}
else
{
mutt_buffer_addch(buf, ';');
buf_addch(buf, ';');
}

return mutt_buffer_len(buf) - initial_len;
return buf_len(buf) - initial_len;
}

/**
Expand All @@ -1143,10 +1143,10 @@ static size_t addrlist_write(const struct AddressList *al, struct Buffer *buf,

if (header)
{
mutt_buffer_printf(buf, "%s: ", header);
buf_printf(buf, "%s: ", header);
}

size_t cur_col = mutt_buffer_len(buf);
size_t cur_col = buf_len(buf);
bool in_group = false;
struct Address *a = NULL;
TAILQ_FOREACH(a, al, entries)
Expand All @@ -1159,11 +1159,11 @@ static size_t addrlist_write(const struct AddressList *al, struct Buffer *buf,
}

// wrap if needed
const size_t cur_len = mutt_buffer_len(buf);
const size_t cur_len = buf_len(buf);
cur_col += mutt_addr_write(buf, a, display);
if (cur_col > cols)
{
mutt_buffer_insert(buf, cur_len, "\n\t");
buf_insert(buf, cur_len, "\n\t");
cur_col = 8;
}

Expand All @@ -1172,13 +1172,13 @@ static size_t addrlist_write(const struct AddressList *al, struct Buffer *buf,
// group terminator
if (in_group && !a->mailbox && !a->personal)
{
mutt_buffer_addch(buf, ';');
buf_addch(buf, ';');
++cur_col;
in_group = false;
}
if (next && (next->mailbox || next->personal))
{
mutt_buffer_addstr(buf, ", ");
buf_addstr(buf, ", ");
cur_col += 2;
}
if (!next)
Expand All @@ -1188,7 +1188,7 @@ static size_t addrlist_write(const struct AddressList *al, struct Buffer *buf,
}
}

return mutt_buffer_len(buf);
return buf_len(buf);
}

/**
Expand Down Expand Up @@ -1241,10 +1241,10 @@ size_t mutt_addrlist_write_list(const struct AddressList *al, struct ListHead *l
{
struct Buffer buf = { 0 };
mutt_addr_write(&buf, a, true);
if (!mutt_buffer_is_empty(&buf))
if (!buf_is_empty(&buf))
{
/* We're taking the ownership of the buffer string here */
mutt_list_insert_tail(list, (char *) mutt_buffer_string(&buf));
mutt_list_insert_tail(list, (char *) buf_string(&buf));
count++;
}
}
Expand All @@ -1263,10 +1263,10 @@ size_t mutt_addrlist_write_list(const struct AddressList *al, struct ListHead *l
*/
void mutt_addrlist_write_file(const struct AddressList *al, FILE *fp, const char *header)
{
struct Buffer *buf = mutt_buffer_pool_get();
struct Buffer *buf = buf_pool_get();
mutt_addrlist_write_wrap(al, buf, header);
fputs(mutt_buffer_string(buf), fp);
mutt_buffer_pool_release(&buf);
fputs(buf_string(buf), fp);
buf_pool_release(&buf);
fputc('\n', fp);
}

Expand Down
92 changes: 44 additions & 48 deletions alias/alias.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,10 @@ struct AddressList *mutt_get_address(struct Envelope *env, const char **prefix)
*/
void alias_create(struct AddressList *al, const struct ConfigSubset *sub)
{
struct Buffer *buf = mutt_buffer_pool_get();
struct Buffer *fixed = mutt_buffer_pool_get();
struct Buffer *buf = buf_pool_get();
struct Buffer *fixed = buf_pool_get();
struct Buffer *prompt = NULL;
struct Buffer *tmp = mutt_buffer_pool_get();
struct Buffer *tmp = buf_pool_get();

struct Address *addr = NULL;
char *pc = NULL;
Expand All @@ -384,38 +384,37 @@ void alias_create(struct AddressList *al, const struct ConfigSubset *sub)
addr = TAILQ_FIRST(al);
if (addr && addr->mailbox)
{
mutt_buffer_strcpy(tmp, addr->mailbox);
pc = strchr(mutt_buffer_string(tmp), '@');
buf_strcpy(tmp, addr->mailbox);
pc = strchr(buf_string(tmp), '@');
if (pc)
*pc = '\0';
}
}

/* Don't suggest a bad alias name in the event of a strange local part. */
check_alias_name(mutt_buffer_string(tmp), buf->data, buf->dsize);
check_alias_name(buf_string(tmp), buf->data, buf->dsize);

retry_name:
/* L10N: prompt to add a new alias */
if ((mutt_buffer_get_field(_("Alias as: "), buf, MUTT_COMP_NO_FLAGS, false,
NULL, NULL, NULL) != 0) ||
mutt_buffer_is_empty(buf))
if ((buf_get_field(_("Alias as: "), buf, MUTT_COMP_NO_FLAGS, false, NULL, NULL, NULL) != 0) ||
buf_is_empty(buf))
{
goto done;
}

/* check to see if the user already has an alias defined */
if (alias_lookup(mutt_buffer_string(buf)))
if (alias_lookup(buf_string(buf)))
{
mutt_error(_("You already have an alias defined with that name"));
goto done;
}

if (check_alias_name(mutt_buffer_string(buf), fixed->data, fixed->dsize))
if (check_alias_name(buf_string(buf), fixed->data, fixed->dsize))
{
switch (mutt_yesorno(_("Warning: This alias name may not work. Fix it?"), MUTT_YES))
{
case MUTT_YES:
mutt_buffer_copy(buf, fixed);
buf_copy(buf, fixed);
goto retry_name;
case MUTT_ABORT:
goto done;
Expand All @@ -424,28 +423,27 @@ void alias_create(struct AddressList *al, const struct ConfigSubset *sub)
}

struct Alias *alias = alias_new();
alias->name = mutt_buffer_strdup(buf);
alias->name = buf_strdup(buf);

mutt_addrlist_to_local(al);

if (addr && addr->mailbox)
mutt_buffer_strcpy(buf, addr->mailbox);
buf_strcpy(buf, addr->mailbox);
else
mutt_buffer_reset(buf);
buf_reset(buf);

mutt_addrlist_to_intl(al, NULL);

do
{
if ((mutt_buffer_get_field(_("Address: "), buf, MUTT_COMP_NO_FLAGS, false,
NULL, NULL, NULL) != 0) ||
mutt_buffer_is_empty(buf))
if ((buf_get_field(_("Address: "), buf, MUTT_COMP_NO_FLAGS, false, NULL, NULL, NULL) != 0) ||
buf_is_empty(buf))
{
alias_free(&alias);
goto done;
}

mutt_addrlist_parse(&alias->addr, mutt_buffer_string(buf));
mutt_addrlist_parse(&alias->addr, buf_string(buf));
if (TAILQ_EMPTY(&alias->addr))
mutt_beep(false);
if (mutt_addrlist_to_intl(&alias->addr, &err))
Expand All @@ -457,39 +455,37 @@ void alias_create(struct AddressList *al, const struct ConfigSubset *sub)
} while (TAILQ_EMPTY(&alias->addr));

if (addr && addr->personal && !mutt_is_mail_list(addr))
mutt_buffer_strcpy(buf, addr->personal);
buf_strcpy(buf, addr->personal);
else
mutt_buffer_reset(buf);
buf_reset(buf);

if (mutt_buffer_get_field(_("Personal name: "), buf, MUTT_COMP_NO_FLAGS,
false, NULL, NULL, NULL) != 0)
if (buf_get_field(_("Personal name: "), buf, MUTT_COMP_NO_FLAGS, false, NULL,
NULL, NULL) != 0)
{
alias_free(&alias);
goto done;
}
mutt_str_replace(&TAILQ_FIRST(&alias->addr)->personal, mutt_buffer_string(buf));
mutt_str_replace(&TAILQ_FIRST(&alias->addr)->personal, buf_string(buf));

mutt_buffer_reset(buf);
if (mutt_buffer_get_field(_("Comment: "), buf, MUTT_COMP_NO_FLAGS, false,
NULL, NULL, NULL) == 0)
buf_reset(buf);
if (buf_get_field(_("Comment: "), buf, MUTT_COMP_NO_FLAGS, false, NULL, NULL, NULL) == 0)
{
mutt_str_replace(&alias->comment, mutt_buffer_string(buf));
mutt_str_replace(&alias->comment, buf_string(buf));
}

mutt_buffer_reset(buf);
buf_reset(buf);
mutt_addrlist_write(&alias->addr, buf, true);
prompt = mutt_buffer_pool_get();
prompt = buf_pool_get();
if (alias->comment)
{
mutt_buffer_printf(prompt, "[%s = %s # %s] %s", alias->name,
mutt_buffer_string(buf), alias->comment, _("Accept?"));
buf_printf(prompt, "[%s = %s # %s] %s", alias->name, buf_string(buf),
alias->comment, _("Accept?"));
}
else
{
mutt_buffer_printf(prompt, "[%s = %s] %s", alias->name,
mutt_buffer_string(buf), _("Accept?"));
buf_printf(prompt, "[%s = %s] %s", alias->name, buf_string(buf), _("Accept?"));
}
if (mutt_yesorno(mutt_buffer_string(prompt), MUTT_YES) != MUTT_YES)
if (mutt_yesorno(buf_string(prompt), MUTT_YES) != MUTT_YES)
{
alias_free(&alias);
goto done;
Expand All @@ -499,18 +495,18 @@ void alias_create(struct AddressList *al, const struct ConfigSubset *sub)
TAILQ_INSERT_TAIL(&Aliases, alias, entries);

const char *const c_alias_file = cs_subset_path(sub, "alias_file");
mutt_buffer_strcpy(buf, c_alias_file);
buf_strcpy(buf, c_alias_file);

if (mutt_buffer_get_field(_("Save to file: "), buf, MUTT_COMP_FILE | MUTT_COMP_CLEAR,
false, NULL, NULL, NULL) != 0)
if (buf_get_field(_("Save to file: "), buf, MUTT_COMP_FILE | MUTT_COMP_CLEAR,
false, NULL, NULL, NULL) != 0)
{
goto done;
}
mutt_expand_path(buf->data, buf->dsize);
fp_alias = fopen(mutt_buffer_string(buf), "a+");
fp_alias = fopen(buf_string(buf), "a+");
if (!fp_alias)
{
mutt_perror(mutt_buffer_string(buf));
mutt_perror(buf_string(buf));
goto done;
}

Expand Down Expand Up @@ -541,15 +537,15 @@ void alias_create(struct AddressList *al, const struct ConfigSubset *sub)
if (check_alias_name(alias->name, NULL, 0))
mutt_file_quote_filename(alias->name, buf->data, buf->dsize);
else
mutt_buffer_strcpy(buf, alias->name);
buf_strcpy(buf, alias->name);

recode_buf(buf->data, buf->dsize);
fprintf(fp_alias, "alias %s ", mutt_buffer_string(buf));
mutt_buffer_reset(buf);
fprintf(fp_alias, "alias %s ", buf_string(buf));
buf_reset(buf);

mutt_addrlist_write(&alias->addr, buf, false);
recode_buf(buf->data, buf->dsize);
write_safe_address(fp_alias, mutt_buffer_string(buf));
write_safe_address(fp_alias, buf_string(buf));
if (alias->comment)
fprintf(fp_alias, " # %s", alias->comment);
fputc('\n', fp_alias);
Expand All @@ -560,10 +556,10 @@ void alias_create(struct AddressList *al, const struct ConfigSubset *sub)

done:
mutt_file_fclose(&fp_alias);
mutt_buffer_pool_release(&buf);
mutt_buffer_pool_release(&fixed);
mutt_buffer_pool_release(&prompt);
mutt_buffer_pool_release(&tmp);
buf_pool_release(&buf);
buf_pool_release(&fixed);
buf_pool_release(&prompt);
buf_pool_release(&tmp);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions alias/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ enum CommandResult parse_alias(struct Buffer *buf, struct Buffer *s,

if (!MoreArgs(s))
{
mutt_buffer_strcpy(err, _("alias: no address"));
buf_strcpy(err, _("alias: no address"));
return MUTT_CMD_WARNING;
}

Expand All @@ -73,7 +73,7 @@ enum CommandResult parse_alias(struct Buffer *buf, struct Buffer *s,
int parsed = mutt_addrlist_parse2(&al, buf->data);
if (parsed == 0)
{
mutt_buffer_printf(err, _("Warning: Bad address '%s' in alias '%s'"), buf->data, name);
buf_printf(err, _("Warning: Bad address '%s' in alias '%s'"), buf->data, name);
FREE(&name);
goto bail;
}
Expand All @@ -82,7 +82,7 @@ enum CommandResult parse_alias(struct Buffer *buf, struct Buffer *s,
char *estr = NULL;
if (mutt_addrlist_to_intl(&al, &estr))
{
mutt_buffer_printf(err, _("Warning: Bad IDN '%s' in alias '%s'"), estr, name);
buf_printf(err, _("Warning: Bad IDN '%s' in alias '%s'"), estr, name);
FREE(&name);
FREE(&estr);
goto bail;
Expand Down
Loading

0 comments on commit d679706

Please sign in to comment.