// read_line.cc // Kevin Karplus // 20 Oct 1995 separated from Input.cc #include "Input.h" #include // Read a line (skipping comments and blank lines) // and strip leading white space. // Allocate new storage for it, and return the char* string. // Return 0 if no more data. char *read_line(istream &in) { int buf_len=8188; char *buf=new char[buf_len]; buf[0]=0; get_word(in, buf); if (buf[0]==0) { delete [] buf; return 0; } int end=strlen(buf); char c; while(in.get(c) && c!='\n') { if (end >=buf_len-1) { // reallocate the buffer int new_len = buf_len*2; char *new_buf=new char[new_len]; for(int i=buf_len-1; i>=0; i--) new_buf[i] = buf[i]; delete [] buf; buf=new_buf; buf_len = new_len; } buf[end++] = c; } buf[end] = 0; char *ret = new char[end+1]; strcpy(ret, buf); delete [] buf; return ret; }