aboutsummaryrefslogtreecommitdiffhomepage
path: root/libslang/slsh/lib/require.sl
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2011-10-14 04:55:05 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2011-10-14 04:55:05 +0200
commit6aa0e0017d7d0cddc006da885946934b06949a91 (patch)
tree66b688ec32e2f91266db760b1762f2a50cc52036 /libslang/slsh/lib/require.sl
parenta966db5b71328f6adf9dd767e64b322a3bd7ed9c (diff)
downloaderlang-slang-fork-6aa0e0017d7d0cddc006da885946934b06949a91.tar.gz
include libslang-1.4.9 and automatically build it and link erlang-slang against it
few (erlang) people will still have libslang-1.4.9 installed or spend time to get it to link against the driver
Diffstat (limited to 'libslang/slsh/lib/require.sl')
-rw-r--r--libslang/slsh/lib/require.sl82
1 files changed, 82 insertions, 0 deletions
diff --git a/libslang/slsh/lib/require.sl b/libslang/slsh/lib/require.sl
new file mode 100644
index 0000000..eec1e0d
--- /dev/null
+++ b/libslang/slsh/lib/require.sl
@@ -0,0 +1,82 @@
+% These functions were taken from the jed editor
+
+static variable Features = Assoc_Type [Int_Type,0];
+
+%!%+
+%\function{_featurep}
+%\synopsis{Test whether or not a feature is present}
+%\usage{Int_Type _featurep (String_Type feature)}
+%\description
+% The \sfun{_featurep} function returns a non-zero value if the specified
+% feature is present. Otherwise, it returns 0 to indicate that the feature
+% has not been loaded.
+%\seealso{require, provide}
+%!%-
+public define _featurep (f)
+{
+ Features[f];
+}
+
+
+%!%+
+%\function{provide}
+%\synopsis{Declare that a specified feature is available}
+%\usage{provide (String_Type feature)}
+%\description
+% The \sfun{provide} function may be used to declare that a "feature" has
+% been loaded. See the documentation for \sfun{require} for more information.
+%\seealso{require, _featurep}
+%!%-
+public define provide (f)
+{
+ Features[f] = 1;
+}
+
+%!%+
+%\function{require}
+%\synopsis{Make sure a feature is present, and load it if not}
+%\usage{require (String_Type feature [,String_Type file]}
+%\description
+% The \sfun{require} function ensures that a specified "feature" is present.
+% If the feature is not present, the \sfun{require} function will attempt to
+% load the feature from a file. If called with two arguments, the feature
+% will be loaded from the file specified by the second argument. Otherwise,
+% the feature will be loaded from a file given by the name of the feature,
+% with ".sl" appended.
+%
+% If after loading the file, if the feature is not present,
+% a warning message will be issued.
+%\notes
+% "feature" is an abstract quantity that is undefined here.
+%
+% A popular use of the \sfun{require} function is to ensure that a specified
+% file has already been loaded. In this case, the feature is the
+% filename itself. The advantage of using this mechanism over using
+% \ifun{evalfile} is that if the file has already been loaded, \sfun{require}
+% will not re-load it. For this to work, the file must indicate that it
+% provides the feature via the \sfun{provide} function.
+%\seealso{provide, _featurep, evalfile}
+%!%-
+public define require ()
+{
+ variable f, file;
+
+ if (_NARGS == 2)
+ {
+ (f, file) = ();
+ }
+ else
+ {
+ f = ();
+ file = f;
+ }
+
+ if (_featurep (f))
+ return;
+
+ () = evalfile (file);
+ !if (_featurep (f))
+ vmessage ("***Warning: feature %s not found in %s", f, file);
+}
+
+