Skip to content

Commit

Permalink
add 0.7.0 version files
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoine committed Sep 9, 2022
1 parent 1b77141 commit 63936d5
Show file tree
Hide file tree
Showing 25 changed files with 2,186 additions and 0 deletions.
674 changes: 674 additions & 0 deletions COPYING

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
INTRODUCTION

Obnc-libext extends the basic library in OBNC with modules for accessing command line arguments and environment variables, printing to the standard error stream, converting numbers to strings and vice versa, and for customizing the trap handler.


INSTALLATION

1. Compile the library with the command

./build

2. Optionally, test the library with the command

./test

3. Install the library with the command

./install

The default destination is /usr/local. If you want to use a different location, run `./install PATH'. To undo the installation, run `./install u' or `./install u PATH'. For other installation options, run `./install -h'.


DOCUMENTATION

share/doc/obnc/obncdoc/ext/


LICENSE

The library source code of obnc-libext is released under the Mozilla Public License, see file ext/LICENSE. All other files are released under the GNU General Public License, see file COPYING.


AUTHOR

Karl Landstrom <[email protected]>
84 changes: 84 additions & 0 deletions build
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/sh

# Copyright (C) 2017, 2018, 2019 Karl Landstrom <[email protected]>
#
# This file is part of obnc-libext.
#
# obnc-libext is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# obnc-libext is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with obnc-libext. If not, see <http://www.gnu.org/licenses/>.

set -o errexit -o nounset

readonly selfDirPath="$(cd "$(dirname "$0")"; pwd -P)"
readonly packageName="$(basename "$selfDirPath")"
readonly packageNameSansVersion="${packageName%%-[0-9]*}"
readonly libName="${packageNameSansVersion#obnc-lib}"

EchoAndRun()
{
echo "$@"
eval "$@"
}


Build()
{
EchoAndRun cd "$selfDirPath/$libName"
for test in ?*Test.obn; do
EchoAndRun obnc "$test"
done
EchoAndRun obncdoc
cd "$selfDirPath"
}


Clean()
{
rm -rf "$selfDirPath/$libName"/.obnc
local file=
for file in "$selfDirPath/$libName"/*Test; do
rm -f "$file"
done
rm -rf "$selfDirPath/$libName/obncdoc"
}


Help()
{
echo "usage: "
printf "\tbuild [clean]\n"
printf "\tbuild -h\n"
echo
printf "\tclean\tdelete all generated files\n"
printf "\t-h\tdisplay help and exit\n"
}

clean=false
for arg in "$@"; do
case "$arg" in
clean)
clean=true;;
-h)
Help
exit;;
*)
{ echo "invalid command"; Help; } >&2
exit 1
esac
done

if "$clean"; then
Clean
else
Build
fi
41 changes: 41 additions & 0 deletions ext/ArgsTest.obn
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(*Copyright (C) 2017, 2018, 2019 Karl Landstrom <[email protected]>

This file is part of obnc-libext.

obnc-libext is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

obnc-libext is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with obnc-libext. If not, see <http://www.gnu.org/licenses/>.*)

MODULE ArgsTest;

IMPORT Args := extArgs;

VAR
arg: ARRAY 8 OF CHAR;
shortArg: ARRAY 2 OF CHAR;
res: INTEGER;

BEGIN
ASSERT(Args.count = 2);

Args.Get(0, arg, res);
ASSERT(arg = "foo");
ASSERT(res = 0);

Args.Get(1, arg, res);
ASSERT(arg = "bar");
ASSERT(res = 0);

Args.Get(0, shortArg, res);
ASSERT(shortArg = "f");
ASSERT(res = 2)
END ArgsTest.
20 changes: 20 additions & 0 deletions ext/ArgsTest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

# Copyright (C) 2017, 2018, 2019 Karl Landstrom <[email protected]>
#
# This file is part of obnc-libext.
#
# obnc-libext is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# obnc-libext is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with obnc-libext. If not, see <http://www.gnu.org/licenses/>.

./ArgsTest foo bar
88 changes: 88 additions & 0 deletions ext/ConvertTest.obn
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
(*Copyright (C) 2017, 2018, 2019 Karl Landstrom <[email protected]>

This file is part of obnc-libext.

obnc-libext is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

obnc-libext is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with obnc-libext. If not, see <http://www.gnu.org/licenses/>.*)

MODULE ConvertTest;

IMPORT Convert := extConvert;

VAR
s: ARRAY 32 OF CHAR;
shortStr: ARRAY 2 OF CHAR;
i: INTEGER;
x: REAL;
done: BOOLEAN;

PROCEDURE ApproxEqual(x, y: REAL): BOOLEAN;
RETURN ABS(x - y) < 0.001
END ApproxEqual;

BEGIN
(*test IntToString*)
Convert.IntToString(-123, s, done);
ASSERT(done);
ASSERT(s = "-123");
Convert.IntToString(0, s, done);
ASSERT(done);
ASSERT(s = "0");
Convert.IntToString(123, s, done);
ASSERT(done);
ASSERT(s = "123");
Convert.IntToString(123, shortStr, done);
ASSERT(~done);

(*test RealToString*)
Convert.RealToString(-123.0, s, done);
ASSERT(done);
ASSERT((s = "-1.230000E+02") OR (s = "-1.230000E+002"));
Convert.RealToString(0.0, s, done);
ASSERT(done);
ASSERT((s = "0.000000E+00") OR (s = "0.000000E+000"));
Convert.RealToString(123.0, s, done);
ASSERT(done);
ASSERT((s = "1.230000E+02") OR (s = "1.230000E+002"));
Convert.RealToString(123.0, shortStr, done);
ASSERT(~done);

(*test StringToInt*)
Convert.StringToInt("-123", i, done);
ASSERT(done);
ASSERT(i = -123);
Convert.StringToInt("0", i, done);
ASSERT(done);
ASSERT(i = 0);
Convert.StringToInt("123", i, done);
ASSERT(done);
ASSERT(i = 123);
Convert.StringToInt("0FFH", i, done);
ASSERT(done);
ASSERT(i = 0FFH);
Convert.StringToInt("foo123", i, done);
ASSERT(~done);

(*test StringToReal*)
Convert.StringToReal("-12.3", x, done);
ASSERT(done);
ASSERT(ApproxEqual(x, -12.3));
Convert.StringToReal("0.0", x, done);
ASSERT(done);
ASSERT(ApproxEqual(x, 0.0));
Convert.StringToReal("1.23E+01", x, done);
ASSERT(done);
ASSERT(ApproxEqual(x, 12.3));
Convert.StringToReal("foo12.3", x, done);
ASSERT(~done)
END ConvertTest.
41 changes: 41 additions & 0 deletions ext/EnvTest.obn
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(*Copyright (C) 2017, 2018, 2019 Karl Landstrom <[email protected]>

This file is part of obnc-libext.

obnc-libext is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

obnc-libext is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with obnc-libext. If not, see <http://www.gnu.org/licenses/>.*)

MODULE EnvTest;

IMPORT Env := extEnv;

PROCEDURE Test;
VAR foo: ARRAY 8 OF CHAR;
foo1: ARRAY 4 OF CHAR;
res: INTEGER;
BEGIN
Env.Get("FOO", foo, res);
ASSERT(res = 0);
ASSERT(foo = "bar baz");

Env.Get("FOO", foo1, res);
ASSERT(res = 4);
ASSERT(foo1 = "bar");

Env.Get("ENVTESTFOO", foo, res);
ASSERT(res = -1)
END Test;

BEGIN
Test
END EnvTest.
20 changes: 20 additions & 0 deletions ext/EnvTest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

# Copyright (C) 2017, 2018, 2019 Karl Landstrom <[email protected]>
#
# This file is part of obnc-libext.
#
# obnc-libext is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# obnc-libext is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with obnc-libext. If not, see <http://www.gnu.org/licenses/>.

env FOO="bar baz" ./EnvTest
41 changes: 41 additions & 0 deletions ext/ErrTest.obn
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(*Copyright (C) 2017, 2018, 2019 Karl Landstrom <[email protected]>

This file is part of obnc-libext.

obnc-libext is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

obnc-libext is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with obnc-libext. If not, see <http://www.gnu.org/licenses/>.*)

MODULE ErrTest;

IMPORT Err := extErr;

BEGIN
Err.Char("a"); Err.Ln;
Err.String("abc"); Err.Ln;
Err.Int(-07FFFFFFFH - 1, 0); Err.Ln; (*minimum 32-bit integer*)
Err.Int(-1, 0); Err.Ln;
Err.Int(-1, 3); Err.Ln;
Err.Int(0, 0); Err.Ln;
Err.Int(1, 0); Err.Ln;
Err.Int(37, 0); Err.Ln;
Err.Int(07FFFFFFFH, 0); Err.Ln; (*maximum 32-bit integer*)
Err.Hex(0); Err.Ln;
Err.Hex(1); Err.Ln;
Err.Hex(0DEADBEEFH); Err.Ln;
Err.Real(-1.0, 0); Err.Ln;
Err.Real(0.0, 0); Err.Ln;
Err.Real(0.0, 14); Err.Ln;
Err.Real(1.0, 0); Err.Ln;
Err.Real(37.0, 0); Err.Ln;
Err.Real(0.37, 0); Err.Ln
END ErrTest.
Loading

0 comments on commit 63936d5

Please sign in to comment.