Dear Gretl Team,
As a part of my job in function package maintenance, I'm trying to make a
Hansl script to (1) create a list of functions available in the Gretl
internet server, (2) download them using the new "install" command and, (3)
execute the examples.
I really appreciate your help to build a list with the names of the
functions. I'm using the following code to retrieve the names:
<hansl>
string functions_page = readfile("
http://ricardo.ecn.wfu.edu/gretl/cgi-bin/gretldata.cgi?opt=SHOW_FUNCS")
string line = ""
scalar i = 1
loop while getline(functions_page, line) --quiet
string line_name = sprintf("line_%d", i++)
string @line_name = strstr(line, "current_fnfiles/")
string @line_name = strstr(@line_name, "<tt>")
string @line_name = strsub(@line_name, "</td><td>", "
")
string @line_name = strsub(@line_name, "</a>", "")
string @line_name = strsub(@line_name, "</td></tr>",
"")
string @line_name = strsub(@line_name, "<p>", "'")
string @line_name = strsub(@line_name, "<tt>", "'")
string @line_name = strsub(@line_name, "</tt>", "'")
string @line_name = strsub(@line_name, "</p>", "'")
string @line_name = strstrip(@line_name)
if @line_name = ""
delete @line_name
else
print @line_name
endif
endloop
</hansl>
It gives me something like this:
(...)
'addlist.gfn' 'Allin Cottrell' '1.2' '2010-12-17'
'Sequential addition
of variables to a model'
(...)
Now I need to use just the first piece of the string ("addlist") to combine
it with the install command. Something like this:
<hansl>
install addlist.gfn
</hansl>
Now my question: How could I extract the first "element" of my string?
string line
string fname
loop while getline(page, line) --quiet
string s = strstr(line, "current_fnfiles/")
if strlen(s) > 0 && sscanf(s + 16, "%[^\"]", fname)
printf "got '%s'\n", fname
endif
endloop
</hansl>
The sscanf format '%[^\"]' says: read a string until you encounter
'"'
then stop (the leading '^' represents negation in this context).
Allin