1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
/*
\funcref{fun\_fgets}{void fun\_fgets ()}
{}
{}
{}
{fun\_gets(), fun\_printf(), fun\_fprintf()}
{funfgets.c}
{
This function reads in a string from a file and returns it in the {\em
reg} return register as an {\em e\_str} value. The arguments on the
stack are: the filename and an {\em int offset}, where the read
operation should start.
The return value is a list, holding as the first list element the read
string and as the second element the offset where the reading operation
ended. The offset and the string are empty (offset 0, string "") when
the reading operation failed.
}
*/
#include "icm-exec.h"
void fun_fgets ()
{
char
buffer [255];
register char
*filename;
register int
offset;
register FILE
*inf;
reg = newvar (e_list);
filename = stack [sp].vu.i->ls.str;
offset = stack [sp - 1].vu.intval;
if ( (inf = fopen (filename, "r")) &&
! fseek (inf, (long) offset, SEEK_SET) &&
fgets (buffer, 254, inf)
)
{
reg = addtolist (reg, buffer);
sprintf (buffer, "%d", (int) ftell (inf));
reg = addtolist (reg, buffer);
fclose (inf);
}
}
|