# HG changeset patch # User ib # Date 1328276322 0 # Node ID abcf26dcec6bb64a53ca7a091967865f8ce6a5a6 # Parent f3f93a410882e013cd90c328291cbd899049b6ba Add fgetstr() to read from files without end-of-line characters. Use it where fgets'ed lines are cleared of EOLs. Remove gfgets() and replace these calls by fgetstr(). diff -r f3f93a410882 -r abcf26dcec6b gui/cfg.c --- a/gui/cfg.c Thu Feb 02 18:26:17 2012 +0000 +++ b/gui/cfg.c Fri Feb 03 13:38:42 2012 +0000 @@ -223,27 +223,6 @@ { NULL, NULL, 0, 0, 0, 0, NULL } }; -static char *gfgets(char *str, int size, FILE *f) -{ - char *s, c; - - s = fgets(str, size, f); - - if (s) { - c = s[strlen(s) - 1]; - - if (c == '\n' || c == '\r') - s[strlen(s) - 1] = 0; - - c = s[strlen(s) - 1]; - - if (c == '\n' || c == '\r') - s[strlen(s) - 1] = 0; - } - - return s; -} - int cfg_gui_include(m_option_t *conf, const char *filename) { (void)conf; @@ -290,12 +269,12 @@ char tmp[512]; plItem *item; - if (gfgets(tmp, 512, f) == NULL) + if (fgetstr(tmp, 512, f) == NULL) continue; item = calloc(1, sizeof(plItem)); item->path = strdup(tmp); - gfgets(tmp, 512, f); + fgetstr(tmp, 512, f); item->name = strdup(tmp); listSet(gtkAddPlItem, item); } @@ -315,7 +294,7 @@ char tmp[512]; urlItem *item; - if (gfgets(tmp, 512, f) == NULL) + if (fgetstr(tmp, 512, f) == NULL) continue; item = calloc(1, sizeof(urlItem)); @@ -339,7 +318,7 @@ while (!feof(f)) { char tmp[512]; - if (gfgets(tmp, 512, f) == NULL) + if (fgetstr(tmp, 512, f) == NULL) continue; fsHistory[i++] = gstrdup(tmp); diff -r f3f93a410882 -r abcf26dcec6b gui/skin/font.c --- a/gui/skin/font.c Thu Feb 02 18:26:17 2012 +0000 +++ b/gui/skin/font.c Fri Feb 03 13:38:42 2012 +0000 @@ -125,8 +125,7 @@ return -3; } - while (fgets(buf, sizeof(buf), f)) { - buf[strcspn(buf, "\n\r")] = 0; // remove any kind of newline, if any + while (fgetstr(buf, sizeof(buf), f)) { strswap(buf, '\t', ' '); trim(buf); decomment(buf); diff -r f3f93a410882 -r abcf26dcec6b gui/skin/skin.c --- a/gui/skin/skin.c Thu Feb 02 18:26:17 2012 +0000 +++ b/gui/skin/skin.c Fri Feb 03 13:38:42 2012 +0000 @@ -1055,10 +1055,9 @@ currWinName[0] = 0; linenumber = 0; - while (fgets(line, sizeof(line), skinFile)) { + while (fgetstr(line, sizeof(line), skinFile)) { linenumber++; - line[strcspn(line, "\n\r")] = 0; // remove any kind of newline, if any strswap(line, '\t', ' '); trim(line); decomment(line); diff -r f3f93a410882 -r abcf26dcec6b gui/util/string.c --- a/gui/util/string.c Thu Feb 02 18:26:17 2012 +0000 +++ b/gui/util/string.c Fri Feb 03 13:38:42 2012 +0000 @@ -16,7 +16,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include #include #include @@ -321,3 +320,26 @@ return fname; } + +/** + * @brief Read characters from @a file. + * + * @note Reading stops with '\\r', '\\n' or EOF. + * + * @param str pointer to a buffer to receive the read characters + * @param size number of characters read at the most (including a terminating null-character) + * @param file file to read from + * + * @return str (success) or NULL (error) + */ +char *fgetstr(char *str, int size, FILE *file) +{ + char *s; + + s = fgets(str, size, file); + + if (s) + s[strcspn(s, "\n\r")] = 0; + + return s; +} diff -r f3f93a410882 -r abcf26dcec6b gui/util/string.h --- a/gui/util/string.h Thu Feb 02 18:26:17 2012 +0000 +++ b/gui/util/string.h Fri Feb 03 13:38:42 2012 +0000 @@ -19,7 +19,10 @@ #ifndef MPLAYER_GUI_STRING_H #define MPLAYER_GUI_STRING_H +#include + char *decomment(char *in); +char *fgetstr(char *str, int size, FILE *file); int gstrcasecmp(const char *a, const char *b); char *gstrchr(const char *str, int c); int gstrcmp(const char *a, const char *b);