readline.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int LineRead (FILE *fd, char buf[], int n, int *cnt, int *nr)
void C2F() readnextline (integer *fd, char buf[], integer *n, integer *count, integer *nr, integer *ierr)


Function Documentation

int LineRead ( FILE *  fd,
char  buf[],
int  n,
int cnt,
int nr 
)

Definition at line 23 of file readline.c.

References count, CR, info, LF, offset, and SEEK_CUR.

00024 {
00025   int c,count,info;
00026   long int offset;
00027 
00028   count=0;
00029   *nr=0;
00030   
00031   while (1) {
00032     c=fgetc(fd);
00033     *nr=*nr+1;
00034     if (c==LF) { /* LF reached first: unix file */
00035       buf[count++]=(char)0;
00036       info=1; /* EOL reached */
00037       break;
00038     }
00039     else if (c==CR) { /* CR reached first: Dos or Mac file */
00040       c=fgetc(fd);
00041       *nr=*nr+1;
00042       if (c==EOF) {
00043         buf[count++]=(char)0;
00044         info=0;/* EOF reached after an EOL */
00045         break;
00046       }
00047     else if (c==LF) { /* LF after CR : Dos file */
00048         buf[count++]=(char)0;
00049         info=1; /* EOL reached */
00050         break;
00051       }
00052       else if (c!=LF) { /* Mac file */
00053         offset=-1;
00054         fseek(fd,offset,SEEK_CUR);
00055         *nr=*nr-1;
00056         buf[count++]=(char)0;
00057         info=1;  /* EOL reached */
00058         break;
00059       }
00060     }
00061     else if (c==EOF) { /* EOF reached before any EOL*/
00062       buf[count++]=(char)0;
00063       if (count==1) 
00064         info=-1; /* EOF reached */
00065       else
00066         info=3;
00067       break;
00068     }
00069     else {
00070       buf[count++]=(char)c;
00071       if (count==n-1) {
00072         buf[count++]=(char)0;
00073         info=2; /* buffer full */
00074         break;
00075       }
00076     }
00077   }
00078   *cnt=count;
00079   return(info);
00080 }

void C2F() readnextline ( integer fd,
char  buf[],
integer n,
integer count,
integer nr,
integer ierr 
)

Definition at line 82 of file readline.c.

References buf, count, fd, GetFile(), ierr, LineRead(), n, and nr.

00083 {
00084 
00085 FILE *fa= GetFile(fd);
00086 
00087 *ierr=LineRead(fa,buf,*n,count,nr);
00088 
00089 }

Here is the call graph for this function:


Generated on Sun Mar 4 15:16:22 2007 for Scilab [trunk] by  doxygen 1.5.1