GRASS Programmer's Manual
6.4.2(2012)
|
00001 #include <stdio.h> 00002 #include <grass/gis.h> 00003 00017 int G_getl(char *buf, int n, FILE * fd) 00018 { 00019 if (!fgets(buf, n, fd)) 00020 return 0; 00021 00022 for (; *buf && *buf != '\n'; buf++) ; 00023 *buf = 0; 00024 00025 return 1; 00026 } 00027 00028 00029 00052 int G_getl2(char *buf, int n, FILE * fd) 00053 { 00054 int i = 0; 00055 int c; 00056 int ret = 1; 00057 00058 while (i < n - 1) { 00059 c = fgetc(fd); 00060 00061 if (c == EOF) { 00062 if (i == 0) { /* Read correctly (return 1) last line in file without '\n' */ 00063 ret = 0; 00064 } 00065 break; 00066 } 00067 00068 if (c == '\n') 00069 break; /* UNIX */ 00070 00071 if (c == '\r') { /* DOS or MacOS9 */ 00072 if ((c = fgetc(fd)) != EOF) { 00073 if (c != '\n') { /* MacOS9 - we have to return the char to stream */ 00074 ungetc(c, fd); 00075 } 00076 } 00077 break; 00078 } 00079 00080 buf[i] = c; 00081 00082 i++; 00083 } 00084 buf[i] = '\0'; 00085 00086 return ret; 00087 }