diff options
author | Marco Peereboom <marco@conformal.com> | 2010-08-10 19:21:44 +0000 |
---|---|---|
committer | Marco Peereboom <marco@conformal.com> | 2010-08-10 19:21:44 +0000 |
commit | 7e83a798850e96c52c0974a06d7876f95a39ce00 (patch) | |
tree | fd9796e410537e99f1fcc6519fd38873cc11c693 | |
parent | 0ac7921a8a2e5fb1615bed82f99daf20b84f12a2 (diff) | |
download | xombrero-7e83a798850e96c52c0974a06d7876f95a39ce00.tar.gz |
don't add duplicate links
from Jean-Philippe Ouellet <jean-philippe@ouellet.biz>
-rw-r--r-- | xxxterm.c | 16 |
1 files 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); |