[Vala] EOF problems
- From: Stefan Risberg <steffenomak gmail com>
- To: vala-list gnome org
- Subject: [Vala] EOF problems
- Date: Fri, 15 Jul 2011 22:57:21 +0200
I am trying to read a file char by char but I can't find where or how I
can check if end of line (EOF) was found. I'm writing a simple parser
for a project but I can't seem to find in the online api doc of gio or
glib how to check for it. I saw that I can do it using posix, but I
would rather use gio.
The code I'm working with
////////////////////////////////////////
////// CODE ///////////////////////
////////////////////////////////////////
namespace FsXml
{
public class Main
{
public static int main(string[] args)
{
stdout.printf("trying to find file %s\n", args[1]);
var f = File.new_for_path(args[1]);
if(!f.query_exists())
{
stderr.printf("File does not exist\n");
return 1;
}
try
{
var dis = new GLib.DataInputStream(f.read());
uchar p;
while(true)
{
p = dis.read_byte();
stdout.printf("%c %d\n", p, p);
}
stdout.printf("End of file\n");
}
catch(IOError e)
{
stderr.printf("IOError: %s\n", e.message);
return 2;
}
catch(Error e)
{
stderr.printf("Error: %s\n", e.message);
return 2;
}
return 0;
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]