You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
elseCOG_RETURN_ERROR(cog_sprintf("Expected one of \\start, \\end, \\current but got %O", how));
178
+
longnf=n;
179
+
if (nf!=n) COG_RETURN_ERROR(cog_sprintf("can't seek to a non-integer offset: %O", where));
180
+
interr=fseek(f, n, w);
181
+
if (err) COG_RETURN_ERROR(cog_sprintf("failed to seek to %O for %O", where, how));
182
+
returnNULL;
183
+
}
184
+
cog_modfuncfne_seek= {"Seek", COG_FUNC, fn_seek, "Seeks a file to a particular offset,"};
185
+
186
+
cog_object*fn_readline() {
187
+
COG_ENSURE_N_ITEMS(1);
188
+
cog_object*file=cog_pop();
189
+
COG_ENSURE_TYPE(file, &ot_file);
190
+
FILE*f= (FILE*)file->as_ptr;
191
+
if (!f) COG_RETURN_ERROR(cog_string("Tried to read a closed file"));
192
+
cog_object*str=cog_emptystring();
193
+
cog_object*tail=str;
194
+
intch;
195
+
do {
196
+
ch=fgetc(f);
197
+
cog_string_append_byte(&tail, ch);
198
+
} while (ch!='\n');
199
+
cog_push(str);
200
+
returnNULL;
201
+
}
202
+
cog_modfuncfne_readline= {"Read-Line", COG_FUNC, fn_readline, "Read a line of text from the file, until and including the next newline (ASCII 0x0A) character."};
203
+
204
+
cog_object*fn_close() {
205
+
COG_ENSURE_N_ITEMS(1);
206
+
cog_object*file=cog_pop();
207
+
COG_ENSURE_TYPE(file, &ot_file);
208
+
FILE*f= (FILE*)file->as_ptr;
209
+
if (!f) COG_RETURN_ERROR(cog_string("File is already closed"));
210
+
fclose(f);
211
+
file->as_ptr=NULL;
212
+
returnNULL;
213
+
}
214
+
cog_modfuncfne_close= {"Close", COG_FUNC, fn_close, "Close an opened file."};
0 commit comments