diff --git a/Makefile b/Makefile index a901aed..ee4bacb 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ include config.mk -SRC = draw.c dunst.c container.c dunst_dbus.c utils.c options.c +SRC = draw.c dunst.c dunst_dbus.c utils.c options.c OBJ = ${SRC:.c=.o} all: doc options dunst service diff --git a/container.c b/container.c deleted file mode 100644 index 3afbfdc..0000000 --- a/container.c +++ /dev/null @@ -1,43 +0,0 @@ -#include "stdlib.h" -#include "stdio.h" -#include - -#include "container.h" - - -str_array *str_array_malloc(void) -{ - str_array *a = malloc(sizeof(str_array)); - a->count = 0; - a->strs = NULL; - return a; -} - -void str_array_append(str_array *a, char *str) -{ - if (!a) - return; - a->count++; - a->strs = realloc(a->strs, a->count * sizeof(char *)); - (a->strs)[a->count-1] = str; -} - -void str_array_dup_append(str_array *a, const char *str) -{ - if (!a) - return; - char *dup = g_strdup(str); - str_array_append(a, dup); -} - -void str_array_deep_free(str_array *a) -{ - if (!a) - return; - for (int i = 0; i < a->count; i++) { - free((a->strs)[i]); - } - free(a); -} - -/* vim: set ts=8 sw=8 tw=0: */ diff --git a/container.h b/container.h deleted file mode 100644 index 265b8dc..0000000 --- a/container.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _LIST_H -#define _LIST_H - -#include "dunst.h" - -typedef struct _str_array { - int count; - char **strs; -} str_array; - -str_array *str_array_malloc(void); -void str_array_dup_append(str_array *a, const char *str); -void str_array_append(str_array *a, char *str); -void str_array_deep_free(str_array *a); - -#endif -/* vim: set ts=8 sw=8 tw=0: */ diff --git a/dunst.c b/dunst.c index e009c21..f25e4c7 100644 --- a/dunst.c +++ b/dunst.c @@ -31,7 +31,6 @@ #include "dunst.h" #include "draw.h" #include "dunst_dbus.h" -#include "container.h" #include "utils.h" #include "options.h" @@ -108,7 +107,7 @@ void draw_win(void); void hide_win(void); void move_all_to_history(void); void print_version(void); -str_array *extract_urls(const char *str); +char *extract_urls(const char *str); void context_menu(void); void run_script(notification *n); @@ -135,7 +134,7 @@ int cmp_notification_data(const void *va, const void *vb, void *data) } -str_array *extract_urls( const char * to_match) +char *extract_urls( const char * to_match) { static bool is_initialized = false; static regex_t cregex; @@ -151,7 +150,7 @@ str_array *extract_urls( const char * to_match) } } - str_array *urls = str_array_malloc(); + char *urls = NULL; const char * p = to_match; regmatch_t m; @@ -171,12 +170,10 @@ str_array *extract_urls( const char * to_match) char *match = strndup(to_match+start, finish-start); - str_array_append(urls, match); + urls = string_append(urls, match, "\n"); p += m.rm_eo; } - return 0; - return urls; } @@ -184,10 +181,8 @@ void context_menu(void) { char *dmenu_input = NULL; for (GList *iter = g_queue_peek_head_link(displayed); iter; iter = iter->next) { - for (int i = 0; i < ((notification*)iter->data)->urls->count; i++) { - dmenu_input = string_append(dmenu_input, - (((notification*)iter->data)->urls->strs)[i], "\n"); - } + notification *n = iter->data; + dmenu_input = string_append(dmenu_input, n->urls, "\n"); } @@ -332,12 +327,12 @@ static void print_notification(notification * n) printf("\turgency: %d\n", n->urgency); printf("\tformatted: '%s'\n", n->msg); printf("\tid: %d\n", n->id); - printf("urls\n"); - printf("\t{\n"); - for (int i = 0; i < n->urls->count; i++) { - printf("\t\t%s\n", (n->urls->strs)[i]); + if (n->urls) { + printf("\turls\n"); + printf("\t{\n"); + printf("%s\n", n->urls); + printf("\t}\n"); } - printf("\t}\n"); printf("\tscript: %s\n", n->script); printf("}\n"); } diff --git a/dunst.h b/dunst.h index d0bfe87..73ea36e 100644 --- a/dunst.h +++ b/dunst.h @@ -57,7 +57,7 @@ typedef struct _notification { int progress; /* percentage + 1, 0 to hide */ int line_count; const char *script; - struct { int count; char **strs; } *urls; + char *urls; } notification; typedef struct _rule_t { diff --git a/dunst_dbus.c b/dunst_dbus.c index ff61855..1de276d 100644 --- a/dunst_dbus.c +++ b/dunst_dbus.c @@ -4,7 +4,6 @@ #include #include "dunst.h" -#include "container.h" #include "dunst_dbus.h"