libsent/src/util/readfile.c

説明を見る。
00001 
00026 /*
00027  * Copyright (c) 1991-2006 Kawahara Lab., Kyoto University
00028  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00029  * Copyright (c) 2005-2006 Julius project team, Nagoya Institute of Technology
00030  * All rights reserved
00031  */
00032 
00033 #include <sent/stddefs.h>
00034 #include <sent/tcpip.h>
00035 
00036 #ifdef HAVE_ZLIB
00037 #include <zlib.h>
00038 #endif
00039 
00040 
00051 char *
00052 getl(char *buf, int maxlen, FILE *fp)
00053 {
00054   int newline;
00055 
00056   while(
00057 #ifdef HAVE_ZLIB
00058         gzgets((gzFile)fp, buf, maxlen) != Z_NULL
00059 #else
00060         fgets(buf, maxlen, fp) != NULL
00061 #endif
00062         ) {
00063     newline = strlen(buf)-1;    /* chop newline */
00064     if (buf[newline] == '\n') {
00065       buf[newline] = '\0';
00066       newline--;
00067     }
00068     if (newline >= 0 && buf[newline] == '\r') buf[newline] = '\0';
00069     if (buf[0] == '\0') continue; /* if blank line, read next */
00070     return buf;
00071   }
00072   return NULL;
00073 }
00074 
00085 char *
00086 getl_fp(char *buf, int maxlen, FILE *fp)
00087 {
00088   int newline;
00089 
00090   while(fgets(buf, maxlen, fp) != NULL) {
00091     newline = strlen(buf)-1;    /* chop newline */
00092     if (buf[newline] == '\n') {
00093       buf[newline] = '\0';
00094       newline--;
00095     }
00096     if (newline >= 0 && buf[newline] == '\r') buf[newline] = '\0';
00097     if (buf[0] == '\0') continue; /* if blank line, read next */
00098     return buf;
00099   }
00100   return NULL;
00101 }
00102 
00113 char *
00114 getl_fd(char *buf, int maxlen, int fd)
00115 {
00116   int cnt;
00117   char *p;
00118   p = buf;
00119   while(1) {
00120     cnt = read(fd, p, 1);
00121     if (cnt <= 0) return NULL;          /* eof or error */
00122     if (*p == '\n') {
00123       *p = '\0';
00124       if (p - 1 >= buf && *(p-1) == '\r') *(p-1) = '\0';
00125       if (buf[0] == '\0') {
00126         p = buf;
00127         continue;
00128       } else {
00129         break;
00130       }
00131     } else {
00132       if (++p >= buf + maxlen) {
00133         j_error("Error: getl_fd: line too long (> %d)\n", maxlen);
00134       }
00135     }
00136   }
00137   return buf;
00138 }
00139 
00150 char *
00151 getl_sd(char *buf, int maxlen, int sd)
00152 {
00153   int cnt;
00154   char *p;
00155   p = buf;
00156   while(1) {
00157     cnt = recv(sd, p, 1, 0);
00158     if (cnt <= 0) return NULL;                /* eof or error */
00159     if (*p == '\n') {
00160       *p = '\0';
00161       if (p - 1 >= buf && *(p-1) == '\r') *(p-1) = '\0';
00162       if (buf[0] == '\0') {
00163       p = buf;
00164       continue;
00165       } else {
00166       break;
00167       }
00168     } else {
00169       if (++p >= buf + maxlen) {
00170       j_error("Error: getl_sd: line too long (> %d)\n", maxlen);
00171       }
00172     }
00173   }
00174   return buf;
00175 }
00176 
00185 char *
00186 first_token(char *buf)
00187 {
00188   char *p;
00189   if ((p=strtok(buf, DELM)) == NULL) {
00190     j_error("data format error: corrupted data?\n");
00191   }
00192   return p;
00193 }
00201 char *
00202 next_token() {
00203   char *p;
00204   if ((p=strtok(NULL,DELM)) == NULL) {
00205     j_error("data format error: corrupted data?\n");
00206   }
00207   return p;
00208 }
00215 char *
00216 next_token_if_any() {
00217   char *p;
00218 
00219   p=strtok(NULL,DELM);
00220 
00221   return p;
00222 }
00229 char *
00230 rest_token() {
00231   char *p;
00232   if ((p=strtok(NULL, "\n")) == NULL) {
00233     j_error("data format error: corrupted data?\n");
00234   }
00235   return p;
00236 }    

Juliusに対してTue Dec 26 16:19:28 2006に生成されました。  doxygen 1.5.0