1 /* 2 This file is part of CDO. CDO is a collection of Operators to manipulate and analyse Climate model Data. 3 4 Author: Uwe Schulzweida 5 6 */ 7 8 #include "readline.h" 9 10 namespace cdo 11 { 12 13 int readline(FILE * fp,char * line,int len)14readline(FILE *fp, char *line, int len) 15 { 16 int ichar, ipos = 0; 17 18 while ((ichar = fgetc(fp)) != EOF) 19 { 20 if (ichar == '\r') 21 { 22 if ((ichar = fgetc(fp)) != EOF) 23 if (ichar != '\n') ungetc(ichar, fp); 24 break; 25 } 26 if (ichar == '\n') break; 27 line[ipos++] = ichar; 28 if (ipos >= len) 29 { 30 fprintf(stderr, "readline Warning: end of line not found (maxlen = %d)!\n", len); 31 break; 32 } 33 } 34 line[ipos] = 0; 35 36 if (feof(fp) && ipos == 0) return 0; 37 38 return 1; 39 } 40 41 } // namespace cdo 42