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 ;
00024 *buf = 0;
00025
00026 return 1;
00027 }
00028
00029
00030
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 ) {
00059 c = fgetc(fd);
00060
00061 if ( c == EOF ) {
00062 if ( i == 0 ) {
00063 ret = 0;
00064 }
00065 break;
00066 }
00067
00068 if ( c == '\012' ) break;
00069
00070 if ( c == '\015' ) {
00071 if ( (c = fgetc(fd) ) != EOF ) {
00072 if ( c != '\012' ) {
00073 ungetc ( c, fd );
00074 }
00075 }
00076 break;
00077 }
00078
00079 buf[i] = c;
00080
00081 i++;
00082 }
00083 buf[i] = '\0';
00084
00085 G_debug ( 4, "G_getl2: ->%s<-", buf );
00086
00087 return ret;
00088 }