get rid of str_array
This commit is contained in:
parent
5e66f5d007
commit
74bae9ee0b
2
Makefile
2
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
|
||||
|
43
container.c
43
container.c
@ -1,43 +0,0 @@
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
#include <string.h>
|
||||
|
||||
#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: */
|
17
container.h
17
container.h
@ -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: */
|
27
dunst.c
27
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");
|
||||
}
|
||||
|
2
dunst.h
2
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 {
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
#include "dunst.h"
|
||||
#include "container.h"
|
||||
|
||||
#include "dunst_dbus.h"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user