From 9e255b8e31b70c9695d81228f46850319fdb553c Mon Sep 17 00:00:00 2001 From: TudbuT Date: Wed, 4 May 2022 19:48:09 +0200 Subject: [PATCH] add startswith --- bootstrap/ISBPL.java | 3 +-- std.isbpl | 21 +++++++++++++++++++++ stream.isbpl | 4 ++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/bootstrap/ISBPL.java b/bootstrap/ISBPL.java index 0da71fb..2e29a72 100644 --- a/bootstrap/ISBPL.java +++ b/bootstrap/ISBPL.java @@ -446,8 +446,7 @@ public class ISBPL { break; case "getos": func = (Stack stack) -> { - // TODO: This is not done yet, and it's horrible so far. - stack.push(toISBPLString("linux")); + stack.push(toISBPLString(System.getProperty("os.name"))); }; break; case "mktype": diff --git a/std.isbpl b/std.isbpl index 4cdda6c..c022577 100644 --- a/std.isbpl +++ b/std.isbpl @@ -462,3 +462,24 @@ func ] { } pop array } + +func astartswith { + def match _array =match + def str _array =str + + str alen match alen lt if { + 0 2 stop + } + str alen match alen eq if { + str match eq 2 stop + } + def i 0 =i + while { i match alen lt } { + str i aget match i aget eq not if { + 0 3 stop + } + i inc + } + + 1 +} diff --git a/stream.isbpl b/stream.isbpl index a7779a9..b88dbd5 100644 --- a/stream.isbpl +++ b/stream.isbpl @@ -15,6 +15,10 @@ def STREAM.write iota =STREAM.write def STREAM.create.server iota =STREAM.create.server +func STREAM.stdin { + getos strlowercase "win" astartswith dup if { "conIN$" } not if { "/dev/stdin" } +} + func stream.readline { def id =id def byte 0 =byte