diff --git a/src/main.c b/src/main.c index 169ffff..762bcd2 100644 --- a/src/main.c +++ b/src/main.c @@ -833,10 +833,7 @@ int args_from_file( dstring* utfile_str, char* file_str ){ - char* line; - unsigned int len=256; - unsigned int pos=0; - char* line_realloc; + dstring line; char c; // open file @@ -847,7 +844,7 @@ int args_from_file( } // allocate line buffer - line=calloc(sizeof(char), len); + dstring_init(&line,64); while(1){ c=fgetc(file); @@ -861,11 +858,11 @@ int args_from_file( if(c=='\n' || c=='\r'){ // read entry // ignore lines with fewer than three characters - if(pos>=3){ + if(line.length>=3){ // find line starting with "#!" - if(line[0]=='#' && line[1]=='!'){ + if(line.string[0]=='#' && line.string[1]=='!'){ wordexp_t pwordexp; - wordexp(line+2,&pwordexp,0); + wordexp(line.string+2,&pwordexp,0); // read arguments read_args(pwordexp.we_wordc, (const char **)pwordexp.we_wordv, params, command, nthreads, savefile_str, utfile_str, NULL); wordfree(&pwordexp); @@ -873,32 +870,15 @@ int args_from_file( break; } } - // reset buffer - pos=0; - line[pos]='\0'; + line.length=0; } // add to buffer else { - // check that there is room in buffer - if(pos==len){ - // too short: reallocate - line_realloc=calloc(sizeof(char), 2*len); - for(pos=0;pos