From 610e5411c20c1dcf5c599067fe00585140e79841 Mon Sep 17 00:00:00 2001 From: rcyeske Date: Sun, 25 Feb 2001 00:21:34 +0000 Subject: removed dependancy on gnu extension: getline() --- src/main.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 1a85969..9dfc8a4 100644 --- a/src/main.c +++ b/src/main.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "ratpoison.h" @@ -181,30 +182,45 @@ load_rc_file (char *filename) { FILE *rcfile; - char *lineptr; - size_t n; - - n = 0; - lineptr = NULL; - if ((rcfile = fopen (filename, "r")) == NULL) { fprintf (stderr, "ratpoison: could not open %s\n", filename); } else { - size_t retval; - n = 256; - lineptr = (char*)malloc(n); - - while ((retval = getline (&lineptr, &n, rcfile)) != EOF) + size_t n = 256; + char *partial; + char *line; + int linesize = n; + + partial = (char*)malloc(n); + line = (char*)malloc(linesize); + + *line = '\0'; + while (fgets (partial, n, rcfile) != NULL) { - fprintf (stderr, "read command: %s\n", lineptr); + if ((strlen (line) + strlen (partial)) <= linesize) + { + linesize *= 2; + line = (char*) realloc (line, linesize); + } + + strcat (line, partial); - command (lineptr); + if (feof(rcfile) || (*(line + strlen(line) - 1) == '\n')) + { + fprintf (stderr, "read line: %s\n", line); + + /* do it */ + command (line); + + *line = '\0'; + } } - free (lineptr); + + free (line); + free (partial); } } -- cgit v1.2.3