shishi-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

shishi/lib cfg.c


From: shishi-commit
Subject: shishi/lib cfg.c
Date: Tue, 23 Sep 2003 18:07:45 -0400

CVSROOT:        /cvsroot/shishi
Module name:    shishi
Branch:         
Changes by:     Simon Josefsson <address@hidden>        03/09/23 18:07:45

Modified files:
        lib            : cfg.c 

Log message:
        (shishi_cfg_from_file): Replace fgets with readlinebuffer, to support
        unrestricted line lengths.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/shishi/shishi/lib/cfg.c.diff?tr1=1.37&tr2=1.38&r1=text&r2=text

Patches:
Index: shishi/lib/cfg.c
diff -u shishi/lib/cfg.c:1.37 shishi/lib/cfg.c:1.38
--- shishi/lib/cfg.c:1.37       Sat Sep 20 07:06:10 2003
+++ shishi/lib/cfg.c    Tue Sep 23 18:07:45 2003
@@ -325,7 +325,7 @@
 int
 shishi_cfg_from_file (Shishi * handle, const char *cfg)
 {
-  char line[BUFSIZ];
+  struct linebuffer lb;
   FILE *fh;
 
   if (cfg == NULL)
@@ -338,30 +338,32 @@
       return SHISHI_FOPEN_ERROR;
     }
 
-  while (!feof (fh) && !ferror (fh))
+  initbuffer (&lb);
+
+  while (readlinebuffer (&lb, fh))
     {
-      if (!fgets (line, sizeof (line), fh))
-       continue;
+      char *p = lb.buffer;
+      char *q;
 
-      line[strlen (line) - 1] = '\0';
+      p[lb.length - 1] = '\0';
 
-      while (line[0] && strchr (" \t\r\n", line[0]))
-       memmove (line, line + 1, strlen (line));
+      while (*p && strchr (" \t\r\n", *p))
+       p++;
 
-      if (line[0] == '#' || line[0] == '\0')
+      if (*p == '\0' || *p == '#')
        continue;
 
-      if (strchr (line, ' ') && (strchr (line, '=') == NULL ||
-                                strchr (line, ' ') < strchr (line, '=')))
-       {
-         char *p = strchr (line, ' ');
-         while (*(p + 1) == ' ' || *(p + 1) == '=')
-           memmove (p, p + 1, strlen (p + 1) + 1);
-         *p = '=';
-       }
+      q = strchr (p, ' ');
+      if (q && (strchr (p, '=') == NULL || q < strchr (p, '=')))
+       *q = '=';
 
-      shishi_cfg (handle, line);
+      shishi_cfg (handle, p);
     }
+
+  if (ferror (fh))
+    shishi_error_printf (handle, "Error reading configuration file");
+
+  freebuffer (&lb);
 
   if (fclose (fh) != 0)
     return SHISHI_FCLOSE_ERROR;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]