Changeset b7ee89b for functions.c


Ignore:
Timestamp:
Oct 17, 2009, 6:08:15 PM (15 years ago)
Author:
Karl Ramm <kcr@1ts.org>
Branches:
master, release-1.10, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
6ea3890
Parents:
435001d
git-author:
Karl Ramm <kcr@1ts.org> (09/24/09 11:05:55)
git-committer:
Karl Ramm <kcr@1ts.org> (10/17/09 18:08:15)
Message:
Cleanup and use owl_getline{,_chomp} and owl_slurp
File:
1 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r08e414a rb7ee89b  
    13631363  owl_fmtext fm;
    13641364  FILE *file;
    1365   char buff[1024];
     1365  char *s = NULL;
    13661366
    13671367  file=fopen(filename, "r");
     
    13721372
    13731373  owl_fmtext_init_null(&fm);
    1374   while (fgets(buff, 1024, file)) {
    1375     owl_fmtext_append_normal(&fm, buff);
    1376     /*    owl_fmtext_append_normal(&fm, "\n"); */
    1377   }
     1374  while (owl_getline(&s, file))
     1375    owl_fmtext_append_normal(&fm, s);
     1376  owl_free(s);
    13781377
    13791378  owl_function_popless_fmtext(&fm);
     
    20222021  const char *redirect = " 2>&1 < /dev/null";
    20232022  char *newbuff;
    2024   char *out, buff2[1024];
    2025   int size;
     2023  char *out;
    20262024  FILE *p;
    20272025
     
    20412039    owl_popexec_new(newbuff);
    20422040  } else {
    2043     p=popen(newbuff, "r");
    2044     out=owl_malloc(1024);
    2045     size=1024;
    2046     strcpy(out, "");
    2047     while (fgets(buff2, 1024, p)!=NULL) {
    2048       size+=1024;
    2049       out=owl_realloc(out, size);
    2050       strcat(out, buff2);
    2051     }
     2041    p = popen(newbuff, "r");
     2042    out = owl_slurp(p);
    20522043    pclose(p);
    20532044   
     
    33383329  char *path;
    33393330  FILE *file;
    3340   char buff[LINE];
     3331  char *s = NULL;
    33413332  int fail_silent = 0;
    33423333
     
    33473338    path = owl_util_makepath(filename);
    33483339  }
    3349   file=fopen(path, "r");
     3340  file = fopen(path, "r");
    33503341  owl_free(path);
    33513342  if (!file) {
     
    33553346    return;
    33563347  }
    3357   while (fgets(buff, LINE, file)!=NULL) {
    3358     if (buff[0] == '\0' || buff[0] == '#') continue;
    3359     if (buff[strlen(buff) - 1] == '\n')
    3360       buff[strlen(buff) - 1] = '\0';
    3361     owl_function_command(buff);
    3362   }
     3348  while (owl_getline_chomp(&s, file)) {
     3349    if (s[0] == '\0' || s[0] == '#')
     3350      continue;
     3351    owl_function_command(s);
     3352  }
     3353
     3354  owl_free(s);
    33633355  fclose(file);
    33643356}
Note: See TracChangeset for help on using the changeset viewer.