[BACK]Return to cfg.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/cfg.c between version 1.31 and 1.32

version 1.31, 2014/04/17 11:38:35 version 1.32, 2014/06/25 19:17:27
Line 23 
Line 23 
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   #include <util.h>
   
 #include "tmux.h"  #include "tmux.h"
   
Line 36 
Line 37 
 load_cfg(const char *path, struct cmd_q *cmdq, char **cause)  load_cfg(const char *path, struct cmd_q *cmdq, char **cause)
 {  {
         FILE            *f;          FILE            *f;
         u_int            n, found;          char             delim[3] = { '\\', '\\', '\0' };
         char            *buf, *copy, *line, *cause1, *msg;          u_int            found;
         size_t           len, oldlen;          size_t           line = 0;
           char            *buf, *cause1, *msg, *p;
         struct cmd_list *cmdlist;          struct cmd_list *cmdlist;
   
         log_debug("loading %s", path);          log_debug("loading %s", path);
Line 47 
Line 49 
                 return (-1);                  return (-1);
         }          }
   
         n = found = 0;          found = 0;
         line = NULL;          while ((buf = fparseln(f, NULL, &line, delim, 0))) {
         while ((buf = fgetln(f, &len))) {                  log_debug("%s: %s", path, buf);
                 /* Trim \n. */  
                 if (buf[len - 1] == '\n')  
                         len--;  
                 log_debug("%s: %.*s", path, (int)len, buf);  
   
                 /* Current line is the continuation of the previous one. */  
                 if (line != NULL) {  
                         oldlen = strlen(line);  
                         line = xrealloc(line, 1, oldlen + len + 1);  
                 } else {  
                         oldlen = 0;  
                         line = xmalloc(len + 1);  
                 }  
   
                 /* Append current line to the previous. */  
                 memcpy(line + oldlen, buf, len);  
                 line[oldlen + len] = '\0';  
                 n++;  
   
                 /* Continuation: get next line? */  
                 len = strlen(line);  
                 if (len > 0 && line[len - 1] == '\\') {  
                         line[len - 1] = '\0';  
   
                         /* Ignore escaped backslash at EOL. */  
                         if (len > 1 && line[len - 2] != '\\')  
                                 continue;  
                 }  
                 copy = line;  
                 line = NULL;  
   
                 /* Skip empty lines. */                  /* Skip empty lines. */
                 buf = copy;                  p = buf;
                 while (isspace((u_char)*buf))                  while (isspace((u_char) *p))
                         buf++;                          p++;
                 if (*buf == '\0') {                  if (*p == '\0') {
                         free(copy);                          free(buf);
                         continue;                          continue;
                 }                  }
   
                 /* Parse and run the command. */                  /* Parse and run the command. */
                 if (cmd_string_parse(buf, &cmdlist, path, n, &cause1) != 0) {                  if (cmd_string_parse(p, &cmdlist, path, line, &cause1) != 0) {
                         free(copy);                          free(buf);
                         if (cause1 == NULL)                          if (cause1 == NULL)
                                 continue;                                  continue;
                         xasprintf(&msg, "%s:%u: %s", path, n, cause1);                          xasprintf(&msg, "%s:%zu: %s", path, line, cause1);
                         ARRAY_ADD(&cfg_causes, msg);                          ARRAY_ADD(&cfg_causes, msg);
                         free(cause1);                          free(cause1);
                         continue;                          continue;
                 }                  }
                 free(copy);                  free(buf);
   
                 if (cmdlist == NULL)                  if (cmdlist == NULL)
                         continue;                          continue;
Line 108 
Line 80 
                 cmd_list_free(cmdlist);                  cmd_list_free(cmdlist);
                 found++;                  found++;
         }          }
         if (line != NULL)  
                 free(line);  
         fclose(f);          fclose(f);
   
         return (found);          return (found);

Legend:
Removed from v.1.31  
changed lines
  Added in v.1.32