From 7e83a798850e96c52c0974a06d7876f95a39ce00 Mon Sep 17 00:00:00 2001 From: Marco Peereboom Date: Tue, 10 Aug 2010 19:21:44 +0000 Subject: don't add duplicate links from Jean-Philippe Ouellet --- xxxterm.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/xxxterm.c b/xxxterm.c index 11030ae..e0af932 100644 --- a/xxxterm.c +++ b/xxxterm.c @@ -542,6 +542,8 @@ favadd(struct tab *t, struct karg *args) { char file[PATH_MAX]; FILE *f; + char *line = NULL; + size_t urilen, linelen; WebKitWebFrame *frame; const gchar *uri, *title; @@ -554,8 +556,6 @@ favadd(struct tab *t, struct karg *args) warn("favorites"); return (1); } - if (fseeko(f, 0, SEEK_END) == -1) - err(1, "fseeko"); title = webkit_web_view_get_title(t->wv); frame = webkit_web_view_get_main_frame(t->wv); @@ -572,8 +572,20 @@ favadd(struct tab *t, struct karg *args) goto done; } + urilen = strlen(uri); + + while (!feof(f)) { + line = fparseln(f, &linelen, NULL, NULL, 0); + if (linelen == urilen && !strcmp(line, uri)) + goto done; + free(line); + line = NULL; + } + fprintf(f, "\n%s\n%s", title, uri); done: + if (line) + free(line); fclose(f); return (0); -- cgit 1.4.1-2-gfad0