From 3452af77070e93e43e76294e298373102be108e5 Mon Sep 17 00:00:00 2001 From: Pietro Cerutti Date: Wed, 26 Jul 2017 07:06:01 +0000 Subject: [PATCH] Convert remaining List structures to STailQ in main.c Issue #374 --- init.c | 18 +++++++-------- main.c | 67 +++++++++++++++++++++++++++++--------------------------- mutt.h | 2 +- protos.h | 3 +-- 4 files changed, 46 insertions(+), 44 deletions(-) diff --git a/init.c b/init.c index 9fbcff918..f571e491c 100644 --- a/init.c +++ b/init.c @@ -3936,10 +3936,8 @@ int var_to_string(int idx, char *val, size_t len) /** * mutt_query_variables - Implement the -Q command line flag */ -int mutt_query_variables(struct List *queries) +int mutt_query_variables(struct STailQHead *queries) { - struct List *p = NULL; - char command[STRING]; struct Buffer err, token; @@ -3950,9 +3948,10 @@ int mutt_query_variables(struct List *queries) err.dsize = STRING; err.data = safe_malloc(err.dsize); - for (p = queries; p; p = p->next) + struct STailQNode *np; + STAILQ_FOREACH(np, queries, entries) { - snprintf(command, sizeof(command), "set ?%s\n", p->data); + snprintf(command, sizeof(command), "set ?%s\n", np->data); if (mutt_parse_rc_line(command, &token, &err) == -1) { fprintf(stderr, "%s\n", err.data); @@ -4029,7 +4028,7 @@ int mutt_getvaluebyname(const char *name, const struct Mapping *map) return -1; } -static int execute_commands(struct List *p) +static int execute_commands(struct STailQHead *p) { struct Buffer err, token; @@ -4037,9 +4036,10 @@ static int execute_commands(struct List *p) err.dsize = STRING; err.data = safe_malloc(err.dsize); mutt_buffer_init(&token); - for (; p; p = p->next) + struct STailQNode *np; + STAILQ_FOREACH(np, p, entries) { - if (mutt_parse_rc_line(p->data, &token, &err) == -1) + if (mutt_parse_rc_line(np->data, &token, &err) == -1) { fprintf(stderr, _("Error in command line: %s\n"), err.data); FREE(&token.data); @@ -4091,7 +4091,7 @@ static char *find_cfg(const char *home, const char *xdg_cfg_home) return NULL; } -void mutt_init(int skip_sys_rc, struct List *commands) +void mutt_init(int skip_sys_rc, struct STailQHead *commands) { struct passwd *pw = NULL; struct utsname utsname; diff --git a/main.c b/main.c index 642b91901..74cdb3c4f 100644 --- a/main.c +++ b/main.c @@ -195,10 +195,10 @@ int main(int argc, char **argv, char **env) char *draftFile = NULL; char *newMagic = NULL; struct Header *msg = NULL; - struct List *attach = NULL; - struct List *commands = NULL; - struct List *queries = NULL; - struct List *alias_queries = NULL; + struct STailQHead attach = STAILQ_HEAD_INITIALIZER(attach); + struct STailQHead commands = STAILQ_HEAD_INITIALIZER(commands); + struct STailQHead queries = STAILQ_HEAD_INITIALIZER(queries); + struct STailQHead alias_queries = STAILQ_HEAD_INITIALIZER(alias_queries); int sendflags = 0; int flags = 0; int version = 0; @@ -270,8 +270,8 @@ int main(int argc, char **argv, char **env) } /* non-option, either an attachment or address */ - if (attach) - attach = mutt_add_list(attach, argv[optind]); + if (!STAILQ_EMPTY(&attach)) + mutt_stailq_insert_tail(&attach, safe_strdup(argv[optind])); else argv[nargc++] = argv[optind]; } @@ -282,10 +282,10 @@ int main(int argc, char **argv, char **env) switch (i) { case 'A': - alias_queries = mutt_add_list(alias_queries, optarg); + mutt_stailq_insert_tail(&alias_queries, safe_strdup(optarg)); break; case 'a': - attach = mutt_add_list(attach, optarg); + mutt_stailq_insert_tail(&attach, safe_strdup(optarg)); break; case 'F': @@ -337,7 +337,7 @@ int main(int argc, char **argv, char **env) break; case 'e': - commands = mutt_add_list(commands, optarg); + mutt_stailq_insert_tail(&commands, safe_strdup(optarg)); break; case 'H': @@ -371,7 +371,7 @@ int main(int argc, char **argv, char **env) break; case 'Q': - queries = mutt_add_list(queries, optarg); + mutt_stailq_insert_tail(&queries, safe_strdup(optarg)); break; case 'R': @@ -404,7 +404,7 @@ int main(int argc, char **argv, char **env) char buf[LONG_STRING]; snprintf(buf, sizeof(buf), "set news_server=%s", optarg); - commands = mutt_add_list(commands, buf); + mutt_stailq_insert_tail(&commands, safe_strdup(buf)); } case 'G': /* List of newsgroups */ @@ -444,7 +444,8 @@ int main(int argc, char **argv, char **env) } /* Check for a batch send. */ - if (!isatty(0) || queries || alias_queries || dump_variables || batch_mode) + if (!isatty(0) || !STAILQ_EMPTY(&queries) || !STAILQ_EMPTY(&alias_queries) || + dump_variables || batch_mode) { set_option(OPT_NO_CURSES); sendflags = SENDBATCH; @@ -465,8 +466,8 @@ int main(int argc, char **argv, char **env) } /* set defaults and read init files */ - mutt_init(flags & MUTT_NOSYSRC, commands); - mutt_free_list(&commands); + mutt_init(flags & MUTT_NOSYSRC, &commands); + mutt_stailq_free(&commands); /* Initialize crypto backends. */ crypt_init(); @@ -474,24 +475,25 @@ int main(int argc, char **argv, char **env) if (newMagic) mx_set_magic(newMagic); - if (queries) + if (!STAILQ_EMPTY(&queries)) { for (; optind < argc; optind++) - queries = mutt_add_list(queries, argv[optind]); - return mutt_query_variables(queries); + mutt_stailq_insert_tail(&queries, safe_strdup(argv[optind])); + return mutt_query_variables(&queries); } if (dump_variables) return mutt_dump_variables(hide_sensitive); - if (alias_queries) + if (!STAILQ_EMPTY(&alias_queries)) { int rv = 0; struct Address *a = NULL; for (; optind < argc; optind++) - alias_queries = mutt_add_list(alias_queries, argv[optind]); - for (; alias_queries; alias_queries = alias_queries->next) + mutt_stailq_insert_tail(&alias_queries, safe_strdup(argv[optind])); + struct STailQNode *np; + STAILQ_FOREACH(np, &alias_queries, entries) { - if ((a = mutt_lookup_alias(alias_queries->data))) + if ((a = mutt_lookup_alias(np->data))) { /* output in machine-readable form */ mutt_addrlist_to_intl(a, NULL); @@ -500,9 +502,10 @@ int main(int argc, char **argv, char **env) else { rv = 1; - printf("%s\n", alias_queries->data); + printf("%s\n", np->data); } } + mutt_stailq_free(&alias_queries); return rv; } @@ -553,7 +556,8 @@ int main(int argc, char **argv, char **env) mutt_free_windows(); mutt_endwin(NULL); } - else if (subject || msg || sendflags || draftFile || includeFile || attach || optind < argc) + else if (subject || msg || sendflags || draftFile || includeFile || + !STAILQ_EMPTY(&attach) || optind < argc) { FILE *fin = NULL; FILE *fout = NULL; @@ -746,34 +750,33 @@ int main(int argc, char **argv, char **env) FREE(&bodytext); - if (attach) + if (!STAILQ_EMPTY(&attach)) { - struct List *t = attach; struct Body *a = msg->content; while (a && a->next) a = a->next; - while (t) + struct STailQNode *np; + STAILQ_FOREACH(np, &attach, entries) { if (a) { - a->next = mutt_make_file_attach(t->data); + a->next = mutt_make_file_attach(np->data); a = a->next; } else - msg->content = a = mutt_make_file_attach(t->data); + msg->content = a = mutt_make_file_attach(np->data); if (!a) { if (!option(OPT_NO_CURSES)) mutt_endwin(NULL); - fprintf(stderr, _("%s: unable to attach file.\n"), t->data); - mutt_free_list(&attach); + fprintf(stderr, _("%s: unable to attach file.\n"), np->data); + mutt_stailq_free(&attach); exit(1); } - t = t->next; } - mutt_free_list(&attach); + mutt_stailq_free(&attach); } rv = ci_send_message(sendflags, msg, bodyfile, NULL, NULL); diff --git a/mutt.h b/mutt.h index a0104608a..5a61f5843 100644 --- a/mutt.h +++ b/mutt.h @@ -324,7 +324,7 @@ struct List *mutt_add_list_n(struct List *head, const void *data, size_t len); struct List *mutt_find_list(struct List *l, const char *data); int mutt_remove_from_rx_list(struct RxList **l, const char *str); -void mutt_init(int skip_sys_rc, struct List *commands); +void mutt_init(int skip_sys_rc, struct STailQHead *commands); /* flag to mutt_pattern_comp() */ #define MUTT_FULL_MSG (1 << 0) /* enable body and header matching */ diff --git a/protos.h b/protos.h index 8530e502c..90ee580da 100644 --- a/protos.h +++ b/protos.h @@ -43,7 +43,6 @@ struct Context; struct EnterState; struct Envelope; struct Header; -struct List; struct Parameter; struct Regex; struct ReplaceList; @@ -343,7 +342,7 @@ int mutt_parse_unhook(struct Buffer *buf, struct Buffer *s, unsigned long data, int mutt_pipe_attachment(FILE *fp, struct Body *b, const char *path, char *outfile); int mutt_print_attachment(FILE *fp, struct Body *a); int mutt_query_complete(char *buf, size_t buflen); -int mutt_query_variables(struct List *queries); +int mutt_query_variables(struct STailQHead *queries); int mutt_save_attachment(FILE *fp, struct Body *m, char *path, int flags, struct Header *hdr); int _mutt_save_message(struct Header *h, struct Context *ctx, int delete, int decode, int decrypt); int mutt_save_message(struct Header *h, int delete, int decode, int decrypt); -- 2.40.0