/* * Copyright (C) 2017 Pietro Cerutti * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef TAILQ_H #define TAILQ_H #include #include #include #include "queue.h" #define NONULL(x) ((!(x) || !*(x)) ? "" : x) #define FREE(x) free(*x) #define safe_malloc malloc #define safe_strdup strdup #define ascii_strcasecmp strcasecmp TAILQ_HEAD(TailQHead, TailQNode); struct TailQNode { TAILQ_ENTRY(TailQNode) entries; char *data; }; static inline struct TailQNode * mutt_tailq_new_node(const char *s) { const char *ns = NONULL(s); struct TailQNode *node = safe_malloc(sizeof (struct TailQNode)); node->data = safe_strdup(ns); return node; } static inline void mutt_tailq_add(struct TailQHead *dst, const char *s) { TAILQ_INSERT_TAIL(dst, mutt_tailq_new_node(s), entries); } static inline void mutt_tailq_remove(struct TailQHead *h, const char *s) { struct TailQNode *node, *tmp; TAILQ_FOREACH_SAFE(node, h, entries, tmp) { if (ascii_strcasecmp(node->data, s) == 0) { TAILQ_REMOVE(h, node, entries); FREE(&node->data); FREE(&node); return; } } } struct TailQHead AliasFiles = TAILQ_HEAD_INITIALIZER(AliasFiles); int main() { mutt_tailq_add(&AliasFiles, "./muttrc"); mutt_tailq_remove(&AliasFiles, "./muttrc"); return 0; } #endif /* TAILQ_H */