From afad5f6ac5ba0e4b92158c35f23f41688f92b048 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 18 Oct 2018 08:54:14 +0200 Subject: Set slide size from stylesheet --- src/utils.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index 9033466..bafbb99 100644 --- a/src/utils.c +++ b/src/utils.c @@ -109,6 +109,34 @@ static char *fgets_long(FILE *fh, size_t *lp) } +int parse_double(const char *a, float v[2]) +{ + int nn; + + nn = sscanf(a, "%fx%f", &v[0], &v[1]); + if ( nn != 2 ) { + fprintf(stderr, _("Invalid size '%s'\n"), a); + return 1; + } + + return 0; +} + + +int parse_tuple(const char *a, float v[4]) +{ + int nn; + + nn = sscanf(a, "%f,%f,%f,%f", &v[0], &v[1], &v[2], &v[3]); + if ( nn != 4 ) { + fprintf(stderr, _("Invalid tuple '%s'\n"), a); + return 1; + } + + return 0; +} + + char *load_everything(const char *filename) { FILE *fh; -- cgit v1.2.3 From 73433f7ee0ca0d86edacbe8544e95911a9856ddd Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 20 Oct 2018 10:09:38 +0200 Subject: Remove legacy API cruft --- src/utils.c | 88 ------------------------------------------------------------- 1 file changed, 88 deletions(-) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index bafbb99..277b3f1 100644 --- a/src/utils.c +++ b/src/utils.c @@ -54,61 +54,6 @@ int safe_strcmp(const char *a, const char *b) } -static char *fgets_long(FILE *fh, size_t *lp) -{ - char *line; - size_t la; - size_t l = 0; - - la = 1024; - line = malloc(la); - if ( line == NULL ) return NULL; - - do { - - int r; - - r = fgetc(fh); - if ( r == EOF ) { - if ( l == 0 ) { - free(line); - *lp = 0; - return NULL; - } else { - line[l++] = '\0'; - *lp = l; - return line; - } - } - - line[l++] = r; - - if ( r == '\n' ) { - line[l++] = '\0'; - *lp = l; - return line; - } - - if ( l == la ) { - - char *ln; - - la += 1024; - ln = realloc(line, la); - if ( ln == NULL ) { - free(line); - *lp = 0; - return NULL; - } - - line = ln; - - } - - } while ( 1 ); -} - - int parse_double(const char *a, float v[2]) { int nn; @@ -136,36 +81,3 @@ int parse_tuple(const char *a, float v[4]) return 0; } - -char *load_everything(const char *filename) -{ - FILE *fh; - size_t el = 1; - char *everything = strdup(""); - - fh = fopen(filename, "r"); - if ( fh == NULL ) return NULL; - - while ( !feof(fh) ) { - - size_t len = 0; - char *line = fgets_long(fh, &len); - - if ( line != NULL ) { - - everything = realloc(everything, el+len); - if ( everything == NULL ) { - fprintf(stderr, _("Failed to allocate memory\n")); - return NULL; - } - el += len; - - strcat(everything, line); - } - - } - - fclose(fh); - - return everything; -} -- cgit v1.2.3