Genie strings page expanded

It is still very much a work-in-progress, but I have added to my introductory page on string handling in Genie:

http://puppylinux.com/genie/strings.htm

This came about because I wanted to write a little program that involved some string manipulations, and I realised that my web page was inadequate. There are many more string functions than those I had documented -- well, I have now added some to the page but it is still far from complete.

The '0setup' script in Woof downloads a compatible-distro's package database files and converts them to the Woof standardised format. However, in the case of Ubuntu this process takes a couple of hours. I have also placed the '0setup' script into a running Puppy so that the user can update the database, and a wait of two hours is unacceptable. Hence I resolved to rewrite the conversion code in Genie, and that was when I realised that I needed more information on string functions, particularly how to handle regular expressions.

I came across a bug:

init

var f = FileStream.open("/tmp/0setup-raw-db","r")
var a = new array of char[2048]
while f.eof() != true
f.gets(a) /*read one line from file*/
a[a.length - 1] = 0 /*make it null-terminated*/
var ONELINE = (string)a /*caste array-of-char to a string*/
print "%s", ONELINE


...this prints the last line of the file twice. Or, is that a feature? Only get the "bug" if last line has a carriage-return. I'll ask on the Vala mail-list first, before reporting to bugzilla.


Posted on 21 Mar 2009, 7:26


Comments:

Posted on 21 Mar 2009, 15:17 by BarryK
re: prints line twice
I got a prompt response from the Vala mail-list. Nicolas Joseph posted this:

Attention, the function feof (in C) should not be used to check the end of a file: http://c-faq.com/stdio/feof.html


The correct code:

[indent=2]
init
var f = FileStream.open("./main.gs","r")
var a = new array of char[2048]
while (f.gets(a) != null)
a[a.length - 1] = 0 /*make it null-terminated*/
var ONELINE = (string)a /*caste array-of-char to a string*/
print "%s", ONELINE


And Jamie McCracken tidied it up a bit:

[indent=2]


init

var f = FileStream.open("./main.gs","r")

var a = new array of char[2048]

while f.gets(a) is not null
a[a.length - 1] = 0 /*make it null-terminated*/
var ONELINE = (string)a /*cast array-of-char to a string*/
print ONELINE


Ok, I've got an example in my Genie web pages that I will fix.