GOLF(2gg)
π GOLF(2gg) β the read-line glow-up π
okay bestie, we're in the 2gg section of the manual, aka the GOLF docs, and today's episode is all about read-line. pull up a chair, grab a strawberry π, and let's get into it.
β¨ NAME β¨
read-line β reads stuff from files, one line at a time
π― PURPOSE π―
Read a text file line by line, in a loop. that's the whole vibe. no cap. π
π§ SYNTAX π§
read-line <file> to <line content> [ status <status> ] [ delimiter <delimiter> ]
<any code>
end-read-line
like, you open the loop with read-line, you put whatever code you want in the middle, and you close it with end-read-line. iconic structure, honestly. π
π DESCRIPTION π
so read-line is what starts the loop, and inside that loop a text <file> gets read line by line into the string <line content>. end-read-line is the closer β it ends the loop. once you've hit the end of <file>, or an error pops off, the loop dips out. bye bestie π
<file> can be a full path name, or a path relative to the application home directory (check the directories page for that one, iykyk).
now the <status> number β pay attention, this is important fr fr:
- it's
GG_ERR_READif something goes wrong reading the file - it's
GG_ERR_OPENif the file literally cannot be opened - it's
GG_OKAYif end-of-file has been reached
check for errors after the end-read-line statement, not before, okay? and if a line was read successfully? then <status> is its length. slay. π
<line content> gets allocated when a line is read, and it gets freed just before the next line is read β or if there are no more lines left to read at all. so if you wanna use <line content> outside of this scope, you gotta save it or stash it somewhere first. it will NOT wait for you. π
the string <delimiter> is what separates the lines in the file, and by default it's a new line β but honestly it can be any character (just know it's the first character of the string <delimiter> that counts).
and a new line (or a <delimiter>) stays in <line content> if it was present in the file. note that the very last line may not have it. π
want to bounce out of the loop early or skip ahead? use the break-loop and continue-loop statements. main character energy, honestly.
π EXAMPLES π
exhibit a: reading a text file line by line, then displaying it as a web page with line breaks:
read-line "/home/bear/tmp/ll/filexx" to one_line status st
string-length one_line to line_len
@Line length is <<print-out line_len>>, line is <<p-web one_line>> status <<print-out st>><br/>
end-read-line
if-true st lesser-than 0
get-req error to err
@Error in reading, error [<<print-out err>>]
end-if
exhibit b: reading a text file that's delimited by the "|" character:
read-line "/home/user/dir/file" to one_line status len delimiter '|'
...
π SEE ALSO π
Files
change-mode close-file copy-file delete-file file-position file-storage file-uploading lock-file open-file read-file read-line rename-file stat-file temporary-file uniq-file unlock-file write-file
See all documentation
quick reminder bestie: this page is from $VERSION, dated $DATE, and yes, it still lives under the GOLF(2gg) banner. that's the whole page. go read some files. mwah π
π¦ where this page comes from
- ubuntu questing: golf 601.4.41-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms