list.h \
plog.c \
plog.h \
+ pstr.c \
+ pstr.h \
ptime.c \
ptime.h \
ttrss.c \
am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"
PROGRAMS = $(bin_PROGRAMS)
am_prss_OBJECTS = main.$(OBJEXT) http.$(OBJEXT) io.$(OBJEXT) \
- list.$(OBJEXT) plog.$(OBJEXT) ptime.$(OBJEXT) ttrss.$(OBJEXT) \
- ttrss_cache.$(OBJEXT) ttrss_model.$(OBJEXT) ttrss_ws.$(OBJEXT) \
- ttrss_wsasync.$(OBJEXT) url.$(OBJEXT) webbrowser.$(OBJEXT)
+ list.$(OBJEXT) plog.$(OBJEXT) pstr.$(OBJEXT) ptime.$(OBJEXT) \
+ ttrss.$(OBJEXT) ttrss_cache.$(OBJEXT) ttrss_model.$(OBJEXT) \
+ ttrss_ws.$(OBJEXT) ttrss_wsasync.$(OBJEXT) url.$(OBJEXT) \
+ webbrowser.$(OBJEXT)
prss_OBJECTS = $(am_prss_OBJECTS)
prss_LDADD = $(LDADD)
AM_V_P = $(am__v_P_@AM_V@)
list.h \
plog.c \
plog.h \
+ pstr.c \
+ pstr.h \
ptime.c \
ptime.h \
ttrss.c \
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/list.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plog.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pstr.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ptime.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ttrss.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ttrss_cache.Po@am__quote@
#include <config.h>
#include "http.h"
#include <plog.h>
+#include <pstr.h>
#include "ttrss.h"
#include "ttrss_ws.h"
#include "webbrowser.h"
return NULL;
}
+static char *headline_to_markup(struct headline *h)
+{
+ return strrepg(h->title, "&", "&");
+}
+
static char *headline_get_formated_headline(struct headline *h)
{
+ char *tmp, *res;
+
+ tmp = headline_to_markup(h);
+
if (h->unread)
- return g_strdup_printf("<b>%s</b>", h->title);
+ res = g_strdup_printf("<b>%s</b>", tmp);
else
- return strdup(h->title);
+ res = strdup(tmp);
+
+ free(tmp);
+
+ return res;
}
static char *headline_get_date(struct headline *h)
GtkTreeIter iter;
GtkTreeModel *model;
struct headline *headline;
- char *str, *date;
+ char *str, *date, *title;
log_debug("headline_cursor_changed_cbk()");
headline = get_selected_headline(&iter);
if (headline) {
- gtk_label_set_text(w_headline_title, headline->title);
+ title = headline_to_markup(headline);
+ gtk_label_set_markup(w_headline_title, title);
+
gtk_label_set_text(w_headline_date, ctime(&headline->date));
str = ttrss_get_headline_content(headline);
date = headline_get_date(headline);
gtk_list_store_set(GTK_LIST_STORE(model),
&iter,
- COL_HEADLINE_TITLE, headline->title,
+ COL_HEADLINE_TITLE, title,
COL_HEADLINE_DATE, date,
COL_HEADLINE_EPOCH_TIME, headline->date,
-1);
free(date);
+ free(title);
} else {
log_debug("headline not found");
}
--- /dev/null
+/*
+ Copyright (C) 2011-2014 jeanfi@gmail.com
+
+ 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
+ */
+
+#include <string.h>
+
+#include <pstr.h>
+
+char *strrep(char *str, const char *old, const char *new)
+{
+ char *p, *res;
+ int pos;
+
+ if (!str)
+ return NULL;
+
+ if (!*str || !old || !*old || !new || !strcmp(old, new))
+ return str;
+
+ p = strstr(str, old);
+
+ if (!p)
+ return str;
+
+ res = malloc(strlen(str) + (new ? strlen(new) : 0) - strlen(old) + 1);
+
+ pos = p - str;
+
+ strncpy(res, str, pos);
+ res[pos] = '\0';
+
+ if (new)
+ strcat(res + pos, new);
+
+ strcat(res, str + pos + strlen(old));
+
+ return res;
+}
+
+/*
+ Derivated from http://stackoverflow.com/questions/779875/what-is-the-function-to-replace-string-in-c
+*/
+char *strrepg(char *orig, const char *rep, const char *with) {
+ char *result; // the return string
+ char *ins; // the next insert point
+ char *tmp; // varies
+ int len_rep; // length of rep
+ int len_with; // length of with
+ int len_front; // distance between rep and end of last rep
+ int count; // number of replacements
+
+ if (!orig)
+ return NULL;
+ if (!rep)
+ rep = "";
+ len_rep = strlen(rep);
+ if (!with)
+ with = "";
+ len_with = strlen(with);
+
+ ins = orig;
+ for(count = 0; (tmp = strstr(ins, rep)); count++) {
+ ins = tmp + len_rep;
+ }
+
+ // first time through the loop, all the variable are set correctly
+ // from here on,
+ // tmp points to the end of the result string
+ // ins points to the next occurrence of rep in orig
+ // orig points to the remainder of orig after "end of rep"
+ tmp = result = malloc(strlen(orig) + (len_with - len_rep) * count + 1);
+
+ if (!result)
+ return NULL;
+
+ while (count--) {
+ ins = strstr(orig, rep);
+ len_front = ins - orig;
+ tmp = strncpy(tmp, orig, len_front) + len_front;
+ tmp = strcpy(tmp, with) + len_with;
+ orig += len_front + len_rep; // move to next "end of rep"
+ }
+ strcpy(tmp, orig);
+ return result;
+}
--- /dev/null
+/*
+ Copyright (C) 2011-2014 jeanfi@gmail.com
+
+ 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 _P_STR_H_
+#define _P_STR_H_
+
+#define _P_STR_VER 2
+
+/*
+ Replaces the first occurence of the substring 'old' by 'new' in the
+ string 'str'.
+
+ Returns a new allocated string only if an occurence is found.
+ */
+char *strrep(char *str, const char *old, const char *new);
+
+char *strrepg(char *str, const char *old, const char *new);
+
+#endif