Skip to content

Commit

Permalink
move extract_token to libparse
Browse files Browse the repository at this point in the history
- Move `extract_token()` to libparse
- Drop dummy copy in the test code
  • Loading branch information
flatcap committed Mar 13, 2023
1 parent d44e665 commit b2c1625
Show file tree
Hide file tree
Showing 24 changed files with 180 additions and 392 deletions.
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@
2019-11-11 Richard Russon \<rich@flatcap.org\>
* Bug Fixes
- browser: fix directory view
- fix crash in mutt_extract_token()
- fix crash in parse_extract_token()
- force a screen refresh
- fix crash sending message from command line
- notmuch: use nm_default_url if no mailbox data
Expand Down
2 changes: 1 addition & 1 deletion Makefile.autosetup
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ $(PWD)/pager:
###############################################################################
# libparse
LIBPARSE= libparse.a
LIBPARSEOBJS=
LIBPARSEOBJS= parse/extract.o
CLEANFILES+= $(LIBPARSE) $(LIBPARSEOBJS)
ALLOBJS+= $(LIBPARSEOBJS)

Expand Down
9 changes: 4 additions & 5 deletions alias/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
#include "address/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "mutt.h"
#include "commands.h"
#include "lib.h"
#include "parse/lib.h"
#include "alias.h"
#include "init.h"
#include "reverse.h"

/**
Expand All @@ -59,7 +58,7 @@ enum CommandResult parse_alias(struct Buffer *buf, struct Buffer *s,
}

/* name */
mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);
mutt_debug(LL_DEBUG5, "First token is '%s'\n", buf->data);
if (parse_grouplist(&gl, buf, s, err) == -1)
{
Expand All @@ -68,7 +67,7 @@ enum CommandResult parse_alias(struct Buffer *buf, struct Buffer *s,
char *name = mutt_str_dup(buf->data);

/* address list */
mutt_extract_token(buf, s, TOKEN_QUOTE | TOKEN_SPACE | TOKEN_SEMICOLON);
parse_extract_token(buf, s, TOKEN_QUOTE | TOKEN_SPACE | TOKEN_SEMICOLON);
mutt_debug(LL_DEBUG5, "Second token is '%s'\n", buf->data);
struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
int parsed = mutt_addrlist_parse2(&al, buf->data);
Expand Down Expand Up @@ -163,7 +162,7 @@ enum CommandResult parse_unalias(struct Buffer *buf, struct Buffer *s,
{
do
{
mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);

struct Alias *np = NULL;
if (mutt_str_equal("*", buf->data))
Expand Down
7 changes: 3 additions & 4 deletions alternates.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@
#include "address/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "mutt.h"
#include "alternates.h"
#include "parse/lib.h"
#include "commands.h"
#include "init.h"

struct RegexList Alternates = STAILQ_HEAD_INITIALIZER(Alternates); ///< List of regexes to match the user's alternate email addresses
struct RegexList UnAlternates = STAILQ_HEAD_INITIALIZER(UnAlternates); ///< List of regexes to exclude false matches in Alternates
Expand Down Expand Up @@ -93,7 +92,7 @@ enum CommandResult parse_alternates(struct Buffer *buf, struct Buffer *s,

do
{
mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);

if (parse_grouplist(&gl, buf, s, err) == -1)
goto bail;
Expand Down Expand Up @@ -127,7 +126,7 @@ enum CommandResult parse_unalternates(struct Buffer *buf, struct Buffer *s,
{
do
{
mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);
mutt_regexlist_remove(&Alternates, buf->data);

if (!mutt_str_equal(buf->data, "*") &&
Expand Down
11 changes: 5 additions & 6 deletions attach/attachments.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
#include "email/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "attachments.h"
#include "ncrypt/lib.h"
#include "init.h"
#include "parse/lib.h"

/**
* struct AttachMatch - An attachment matching a regex for attachment counter
Expand Down Expand Up @@ -316,7 +315,7 @@ static enum CommandResult parse_attach_list(struct Buffer *buf, struct Buffer *s

do
{
mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);

if (!buf->data || (*buf->data == '\0'))
continue;
Expand Down Expand Up @@ -394,7 +393,7 @@ static enum CommandResult parse_unattach_list(struct Buffer *buf, struct Buffer

do
{
mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);
FREE(&tmp);

if (mutt_istr_equal(buf->data, "any"))
Expand Down Expand Up @@ -470,7 +469,7 @@ static int print_attach_list(struct ListHead *h, const char op, const char *name
enum CommandResult parse_attachments(struct Buffer *buf, struct Buffer *s,
intptr_t data, struct Buffer *err)
{
mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);
if (!buf->data || (*buf->data == '\0'))
{
mutt_buffer_strcpy(err, _("attachments: no disposition"));
Expand Down Expand Up @@ -533,7 +532,7 @@ enum CommandResult parse_unattachments(struct Buffer *buf, struct Buffer *s,
char *p = NULL;
struct ListHead *head = NULL;

mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);
if (!buf->data || (*buf->data == '\0'))
{
mutt_buffer_strcpy(err, _("unattachments: no disposition"));
Expand Down
25 changes: 12 additions & 13 deletions color/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@
#include "mutt/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "lib.h"
#include "pager/lib.h"
#include "init.h"
#include "parse/lib.h"
#include "options.h"
#ifdef USE_DEBUG_COLOR
#include <stdio.h>
Expand Down Expand Up @@ -231,7 +230,7 @@ static enum CommandResult parse_attr_spec(struct Buffer *buf, struct Buffer *s,
return MUTT_CMD_WARNING;
}

mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);

if (mutt_istr_equal("bold", buf->data))
*attrs |= A_BOLD;
Expand Down Expand Up @@ -273,7 +272,7 @@ static enum CommandResult parse_color_pair(struct Buffer *buf, struct Buffer *s,
return MUTT_CMD_WARNING;
}

mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);

if (mutt_istr_equal("bold", buf->data))
{
Expand Down Expand Up @@ -325,7 +324,7 @@ static enum CommandResult parse_color_pair(struct Buffer *buf, struct Buffer *s,
return MUTT_CMD_WARNING;
}

mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);

return parse_color_name(buf->data, bg, attrs, false, err);
}
Expand Down Expand Up @@ -397,7 +396,7 @@ static enum CommandResult parse_object(struct Buffer *buf, struct Buffer *s,
return MUTT_CMD_WARNING;
}

mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);

rc = mutt_map_get_value(buf->data, ComposeColorFields);
if (rc == -1)
Expand Down Expand Up @@ -440,7 +439,7 @@ static enum CommandResult parse_object(struct Buffer *buf, struct Buffer *s,
static enum CommandResult parse_uncolor(struct Buffer *buf, struct Buffer *s,
struct Buffer *err, bool uncolor)
{
mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);

if (mutt_str_equal(buf->data, "*"))
{
Expand Down Expand Up @@ -487,7 +486,7 @@ static enum CommandResult parse_uncolor(struct Buffer *buf, struct Buffer *s,
{
color_debug(LL_DEBUG5, "do nothing\n");
/* just eat the command, but don't do anything real about it */
mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);
} while (MoreArgs(s));

return MUTT_CMD_SUCCESS;
Expand All @@ -504,7 +503,7 @@ static enum CommandResult parse_uncolor(struct Buffer *buf, struct Buffer *s,

do
{
mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);
if (mutt_str_equal("*", buf->data))
{
if (regex_colors_parse_uncolor(cid, NULL, uncolor))
Expand Down Expand Up @@ -742,7 +741,7 @@ static enum CommandResult parse_color(struct Buffer *buf, struct Buffer *s,
return MUTT_CMD_WARNING;
}

mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);
color_debug(LL_DEBUG5, "color: %s\n", mutt_buffer_string(buf));

rc = parse_object(buf, s, &cid, &q_level, err);
Expand All @@ -760,7 +759,7 @@ static enum CommandResult parse_color(struct Buffer *buf, struct Buffer *s,
color_debug(LL_DEBUG5, "regex needed\n");
if (MoreArgs(s))
{
mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);
}
else
{
Expand Down Expand Up @@ -811,12 +810,12 @@ static enum CommandResult parse_color(struct Buffer *buf, struct Buffer *s,
* 0 arguments: sets the default status color (handled below by else part)
* 1 argument : colorize pattern on match
* 2 arguments: colorize nth submatch of pattern */
mutt_extract_token(buf, s, TOKEN_NO_FLAGS);
parse_extract_token(buf, s, TOKEN_NO_FLAGS);

if (MoreArgs(s))
{
struct Buffer tmp = mutt_buffer_make(0);
mutt_extract_token(&tmp, s, TOKEN_NO_FLAGS);
parse_extract_token(&tmp, s, TOKEN_NO_FLAGS);
if (!mutt_str_atoui_full(tmp.data, &match))
{
mutt_buffer_printf(err, _("%s: invalid number: %s"),
Expand Down
Loading

0 comments on commit b2c1625

Please sign in to comment.