Skip to content

Commit

Permalink
add 0.4.0 version files
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoine committed Sep 9, 2022
1 parent 3f47e01 commit 0f6c317
Show file tree
Hide file tree
Showing 21 changed files with 1,726 additions and 0 deletions.
674 changes: 674 additions & 0 deletions COPYING

Large diffs are not rendered by default.

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

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


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'.


LICENSE

OBNC is released under the GNU General Public License, see file COPYING.


AUTHOR

Karl Landstrom <karl@miasap.se>
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obnc-libstd version 0.4.0
84 changes: 84 additions & 0 deletions build
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/sh

# Copyright 2017 Karl Landstrom <karl@miasap.se>
#
# This file is part of obnc-libstd.
#
# obnc-libstd 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-libstd 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-libstd. 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
152 changes: 152 additions & 0 deletions install
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/bin/sh

# Copyright (C) 2017 Karl Landstrom <karl@miasap.se>
#
# This file is part of obnc-libstd.
#
# obnc-libstd 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-libstd 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-libstd. 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%-*}"
readonly libName="${packageNameSansVersion#obnc-lib}"

readonly modules="$(ls "$selfDirPath/$libName"/*.obn | grep -v 'Test\.obn$' | while read file; do basename "${file%.obn}"; done)"
prefix="/usr/local"
libdir="lib"
destdir=
destIncludeDir=
destLibDir=
destObncdocDir=
EchoAndRun()
{
echo "$@"
eval "$@"
}
UpdateObncdocIndex()
{
EchoAndRun cd "$destObncdocDir/.."
if obncdoc-index >/dev/null 2>&1; then
EchoAndRun obncdoc-index \> index.html
fi
cd - >/dev/null
}
Install()
{
local srcDir="$selfDirPath/$libName"
#install library
EchoAndRun mkdir -p "$destIncludeDir"
EchoAndRun mkdir -p "$destLibDir"
local module=
for module in $modules; do
EchoAndRun cp "$srcDir/.obnc/$module.h" "$destIncludeDir"
EchoAndRun cp "$srcDir/.obnc/$module.o" "$destLibDir"
EchoAndRun cp "$srcDir/.obnc/$module.sym" "$destLibDir"
if [ -e "$srcDir/.obnc/$module.imp" ]; then
EchoAndRun cp "$srcDir/.obnc/$module.imp" "$destLibDir"
fi
if [ -e "$srcDir/$module.env" ]; then
EchoAndRun cp "$srcDir/$module.env" "$destLibDir"
fi
done
#install documentation
EchoAndRun mkdir -p "$destObncdocDir"
EchoAndRun cp "$srcDir/obncdoc/$libName"* "$destObncdocDir"
for file in "$srcDir/obncdoc/"*; do
if [ "$file" = "${file%Test.*}" ]; then
EchoAndRun cp "$file" "$destObncdocDir"
fi
done
UpdateObncdocIndex
}
Uninstall()
{
#delete library files
local module=
for module in $modules; do
EchoAndRun rm -f "$destIncludeDir/$module.h"
EchoAndRun rm -f "$destLibDir/$module.o"
EchoAndRun rm -f "$destLibDir/$module.sym"
EchoAndRun rm -f "$destLibDir/$module.imp"
EchoAndRun rm -f "$destLibDir/$module.env"
done
#delete documentation
EchoAndRun rm -f "$destObncdocDir"/*
UpdateObncdocIndex
}
Help()
{
echo "usage: "
printf "\tinstall [u] [--prefix=PREFIX] [--libdir=LIBDIR] [--destdir=DESTDIR]\n"
printf "\tinstall -h\n"
echo
printf "\tu\t\tuninstall\n"
printf "\t--prefix\ttoplevel installation directory instead of /usr/local\n"
printf "\t--libdir\tlibrary installation directory instead of lib\n"
printf "\t--destdir\tspecify directory for staged installation\n"
printf "\t-h\t\tdisplay help and exit\n"
}
uninstall=false
for arg in "$@"; do
case "$arg" in
u)
uninstall=true;;
--prefix=*)
prefix="${arg#--prefix=}"
if [ "${prefix#/}" = "$prefix" ]; then
echo "prefix must be an absolute path: $prefix" >&2
exit 1
fi;;
--libdir=*)
libdir="${arg#--libdir=}"
if [ "${libdir#*/}" != "$libdir" ]; then
echo "libdir must be a prefix relative path, not an absolute path: $prefix" >&2
exit 1
fi;;
--destdir=*)
destdir="${arg#--destdir=}";;
-h)
Help
exit;;
*) { echo "invalid command"; Help; } >&2
exit 1
esac
done
destIncludeDir="$destdir$prefix/include/obnc/$libName"
destLibDir="$destdir$prefix/$libdir/obnc/$libName"
destObncdocDir="$destdir$prefix/share/doc/obnc/obncdoc/$libName"
if "$uninstall"; then
Uninstall
else
Install
fi
41 changes: 41 additions & 0 deletions std/ArgsTest.obn
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(*Copyright 2017 Karl Landstrom <karl@miasap.se>

This file is part of obnc-libstd.

obnc-libstd 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-libstd 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-libstd. If not, see <http://www.gnu.org/licenses/>.*)

MODULE ArgsTest;

IMPORT Args := stdArgs;

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 std/ArgsTest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

# Copyright 2017 Karl Landstrom <karl@miasap.se>
#
# This file is part of obnc-libstd.
#
# obnc-libstd 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-libstd 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-libstd. If not, see <http://www.gnu.org/licenses/>.

./ArgsTest foo bar
Loading

0 comments on commit 0f6c317

Please sign in to comment.