Mercurial > mplayer.hg
changeset 34560:abcf26dcec6b
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().
author | ib |
---|---|
date | Fri, 03 Feb 2012 13:38:42 +0000 |
parents | f3f93a410882 |
children | f744357e94bd |
files | gui/cfg.c gui/skin/font.c gui/skin/skin.c gui/util/string.c gui/util/string.h |
diffstat | 5 files changed, 32 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- 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);
--- 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);
--- 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);
--- 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 <stdio.h> #include <stdlib.h> #include <string.h> @@ -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; +}
--- 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 <stdio.h> + 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);