Don't use for each loops

The hare compiler on OpenBSD doesn't support them :(
This commit is contained in:
Sasha Koshka 2024-10-11 17:08:16 -04:00
parent d921a2b144
commit ea527a2065

View File

@ -116,14 +116,16 @@ export fn post(input: io::handle, board: str, user_name: (str | void)) (void | e
}; };
export fn list(output: io::handle) (void | error) = { export fn list(output: io::handle) (void | error) = {
for (let directory .. bulb_path) list_boards_in(output, directory)?; for (let index = 0z; index < len(bulb_path); index += 1) {
list_boards_in(output, bulb_path[index])?;
};
}; };
export fn look_up_board(board: str) (str | no_such_board | invalid_board) = { export fn look_up_board(board: str) (str | no_such_board | invalid_board) = {
validate_board_name(board)?; validate_board_name(board)?;
static let buf = path::buffer { ... }; static let buf = path::buffer { ... };
for (let directory .. bulb_path) { for (let index = 0z; index < len(bulb_path); index += 1) {
let location = path::set(&buf, directory, board)!; let location = path::set(&buf, bulb_path[index], board)!;
match (os::stat(location)) { match (os::stat(location)) {
case fs::filestat => return location; case fs::filestat => return location;
case => void; case => void;
@ -150,8 +152,8 @@ export fn validate_board_name(board: str) (void | invalid_board) = {
fn list_boards_in(output: io:: handle, directory: str) (void | error) = { fn list_boards_in(output: io:: handle, directory: str) (void | error) = {
let entries = os::readdir(directory)?; let entries = os::readdir(directory)?;
defer fs::dirents_free(entries); defer fs::dirents_free(entries);
for (let entry .. entries) { for (let index = 0z; index < len(entries); index += 1) {
fmt::fprintln(output, entry.name)?; fmt::fprintln(output, entries[index].name)?;
}; };
}; };