diff options
Diffstat (limited to 'examples')
48 files changed, 0 insertions, 2121 deletions
diff --git a/examples/.cvsignore b/examples/.cvsignore deleted file mode 100644 index 282522db0..000000000 --- a/examples/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -Makefile -Makefile.in diff --git a/examples/ChangeLog b/examples/ChangeLog deleted file mode 100644 index f70742449..000000000 --- a/examples/ChangeLog +++ /dev/null @@ -1,144 +0,0 @@ -2001-07-24 Martin Grabmueller <mgrabmue@cs.tu-berlin.de> - - All examples are now built and tested on `make installcheck' - rather than `make check'. - -2001-07-19 Martin Grabmueller <mgrabmue@cs.tu-berlin.de> - - * box-dynamic-module/Makefile.am, box-dynamic/Makefile.am, - box-module/Makefile.am, box/Makefile.am: Use $(top_srcdir) to get - at GUILE_LOAD_PATH, and $(top_builddir) for the guile and - guile-config programs and for the link paths. Add check.test to - EXTRA_DIST. - - * box-dynamic-module/Makefile.am, box-dynamic/Makefile.am, - box-module/Makefile.am, box/Makefile.am: Add -L../../qt to LIBS. - -2001-07-19 Rob Browning <rlb@defaultvalue.org> - - * box-module/.cvsignore: add .deps - - * box/.cvsignore: add .deps. - -2001-07-17 Martin Grabmueller <mgrabmue@cs.tu-berlin.de> - - * box-module/Makefile.am (TESTS): New variable. - Create `box' on `make all'. - - * box-module/check.test, box-dynamic-module/check.test, - * box-dynamic/check.test: New files. - - * box-dynamic/Makefile.am (libbox): Create box library on `make - all'. - (TESTS): New variable. - - * box/Makefile.am (TESTS): New variable. - Create `box' program on `make all', use freshly built Guile for - building. - - * box/check.test: New file. - - * modules/check.test, safe/check.test, scripts/check.test: Set - GUILE_LOAD_PATH to make the tests run without installed Guile. - -2001-07-16 Thien-Thi Nguyen <ttn@revel.glug.org> - - * scripts/check.test: Add check for guile interpreter. - Fix bug: Use `$guile' everywhere. Thanks to Martin Grabmueller. - -2001-07-16 Martin Grabmueller <mgrabmue@cs.tu-berlin.de> - - * modules/check.test, safe/check.test: New files. - - * modules/Makefile.am (TESTS), safe/Makefile.am (TESTS): New - variables. - -2001-07-14 Thien-Thi Nguyen <ttn@revel.glug.org> - - * scripts/check.test: New file. - - * Makefile.am (TESTS): New var. - -2001-07-14 Martin Grabmueller <mgrabmue@cs.tu-berlin.de> - - * modules/main: Use :renamer for specifying renaming procedure. - -2001-07-10 Thien-Thi Nguyen <ttn@revel.glug.org> - - * scripts/hello (display-version, display-help): Fix comment; nfc. - -2001-07-09 Martin Grabmueller <mgrabmue@cs.tu-berlin.de> - - * box-dynamic/README: Corrected sample session. - - * box-module/box.c, box-dynamic-module/box.c, box-dynamic/box.c - * box/box.c: scm_bits_t -> scm_t_bits. - -2001-06-18 Martin Grabmueller <mgrabmue@cs.tu-berlin.de> - - * box-dynamic-module/README: Use a better example for box-map, as - suggested by Thomas Wawrzinek. - -2001-06-14 Martin Grabmueller <mgrabmue@cs.tu-berlin.de> - - * scripts/README, scripts/hello.scm, safe/untrusted.scm, - safe/evil.scm, safe/README, modules/README, modules/main, - modules/module-0.scm, modules/module-1.scm, modules/module-2.scm: - Minor cleanup. - - * README: Added intro stuff, restructured a bit. - - * box-dynamic/README, box-module/README, box/README: Cleanup and - restructuring. - - * box-dynamic-module/box-mixed.scm: New file, demonstrating usage - of extension library functionality, but without exporting - procedures from the library. - - Thanks to Thomas Wawrzinek for the idea and example code! - - * box-dynamic-module/box-module.scm: Add comments, export - make-box, box-ref, box-set!. - - * box-dynamic-module/README: Integrate new module (box-mixed), - restructure and cleanup a bit. - -2001-06-06 Martin Grabmueller <mgrabmue@cs.tu-berlin.de> - - * box-dynamic-module/box-module.scm: New file. - -2001-06-05 Martin Grabmueller <mgrabmue@cs.tu-berlin.de> - - * box-dynamic-module: New directory, implements the box type in a - shared library and places the definitions in a C-only module. - - Thanks to Thomas Wawrzinek for this, too! - - * box-dynamic/box.c, box/box.c, box-dynamic-module/box.c, - box-module/box.c (mark_box): Fixed typo in comment. - -2001-06-01 Rob Browning <rlb@cs.utexas.edu> - - * .cvsignore: here and in all subdirectories listing Makefile and - Makefile.in. - -2001-05-31 Martin Grabmueller <mgrabmue@cs.tu-berlin.de> - - * box-dynamic: New directory, implements the box type in a shared - library (aka extension) - - Thanks to Thomas Wawrzinek for patching box.c into an extension! - -2001-05-30 Martin Grabmueller <mgrabmue@cs.tu-berlin.de> - - * box-module: New directory, similar to box, but defines the - primitives in a module (box-module) instead of defining them - globally. - - * safe: New directory, explaining some aspects of using safe - environments for evaluation. - -2001-05-29 Martin Grabmueller <mgrabmue@cs.tu-berlin.de> - - * New directory for Guile example code. - diff --git a/examples/Makefile.am b/examples/Makefile.am deleted file mode 100644 index 504ba06ff..000000000 --- a/examples/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -## Process this file with Automake to create Makefile.in -## -## Copyright (C) 2001 Free Software Foundation, Inc. -## -## This file is part of GUILE. -## -## GUILE 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 2, or -## (at your option) any later version. -## -## GUILE 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 GUILE; see the file COPYING. If not, write -## to the Free Software Foundation, Inc., 59 Temple Place, Suite -## 330, Boston, MA 02111-1307 USA - -SUBDIRS = scripts box box-module box-dynamic box-dynamic-module\ - modules safe - -EXTRA_DIST = README diff --git a/examples/README b/examples/README deleted file mode 100644 index 793d131c8..000000000 --- a/examples/README +++ /dev/null @@ -1,36 +0,0 @@ - -*- outline -*- - -* Overview - -This directory contains examples illustrating various aspects of Guile -programming. - -If you plan writing Scheme programs, have a look at the `scripts' -directory. To learn more about Guile modules, check out the `modules' -directory, and maybe the `box-module' and `box-dynamic-module' -directories, if you are into C programming or shared libraries, -respectively. The `safe' directory contains examples for evaluation -Scheme code in controlled environments (sandboxing). The directories -`box', `box-module', `box-dynamic' and `box-dynamic-module' are -interesting if you plan writing Guile extensions. - -See the README files in the subdirectories for details. - - -* Included Examples - -scripts Examples for writing simple scripts in Guile Scheme. - -box Example for extending Guile with a new data type. - -box-module Similar to `box', but defines new procedures in a - named module. -box-dynamic Implements the box type in a dynamically loadable - library. -box-dynamic-module Combination of `box-module' and `box-dynamic': - Implements the `box' type in a shared library and - defines the procedures in a Guile module. - -modules Examples for writing and using Guile modules. - -safe Examples for creating and using safe environments. diff --git a/examples/box-dynamic-module/.cvsignore b/examples/box-dynamic-module/.cvsignore deleted file mode 100644 index 282522db0..000000000 --- a/examples/box-dynamic-module/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -Makefile -Makefile.in diff --git a/examples/box-dynamic-module/Makefile.am b/examples/box-dynamic-module/Makefile.am deleted file mode 100644 index 665a7de54..000000000 --- a/examples/box-dynamic-module/Makefile.am +++ /dev/null @@ -1,36 +0,0 @@ -## Process this file with Automake to create Makefile.in -## -## Copyright (C) 2001 Free Software Foundation, Inc. -## -## This file is part of GUILE. -## -## GUILE 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 2, or -## (at your option) any later version. -## -## GUILE 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 GUILE; see the file COPYING. If not, write -## to the Free Software Foundation, Inc., 59 Temple Place, Suite -## 330, Boston, MA 02111-1307 USA - -EXTRA_DIST = README box.c box-module.scm box-mixed.scm check.test - -CFLAGS=`$(bindir)/guile-config compile` -LIBS=`$(bindir)/guile-config link` - -libbox-module: box.lo - sh ../../libtool --mode=link $(CC) $< $(LIBS) -rpath $(libdir) -o libbox-module.la - -box.lo: box.c - sh ../../libtool --mode=compile $(CC) $(CFLAGS) -c $< - -installcheck: libbox-module - LTDL_LIBRARY_PATH=.libs GUILE_LOAD_PATH=$(top_srcdir):$(srcdir) $(srcdir)/check.test - -CLEANFILES=libbox-module.la box.lo box.o diff --git a/examples/box-dynamic-module/README b/examples/box-dynamic-module/README deleted file mode 100644 index 9f285c6ca..000000000 --- a/examples/box-dynamic-module/README +++ /dev/null @@ -1,77 +0,0 @@ - -*- outline -*- - -* Overview - -This directory includes an example program for extending Guile with a -new (and even useful) data type, putting it into a shared library, so it -can be called from an unmodified guile interpreter. Further, the shared -library defines a new guile module. - - -* Build Instructions - -To build the example, simply type - - make libbox-module - -in this directory. - - -* The Box Data Type - -A box is simply an object for storing one other object in. It can be -used for passing parameters by reference, for example. You simply -store an object into a box, pass it to another procedure which can -store a new object into it and thus return a value via the box. - - -** Usage - -Box objects are created with `make-box', set with `box-set!' and -examined with `box-ref'. Note that these procedures are placed in a -module called (box-module) and can thus only be accessed after using -this module. See the following example session for usage details. - - -** The Module (box-module) - -Extend your LD_LIBRARY_PATH variable (or equivalent) to include . and -.libs and make sure that your current working directory is the one -this file is contained in. - -$ guile -guile> (use-modules (box-module)) -guile> (define b (make-box)) -guile> b -#<box #f> -guile> (box-set! b '(list of values)) -guile> b -#<box (list of values)> -guile> (box-ref b) -(list of values) -guile> (quit) -$ - - -** The Module (box-mixed) - -The following example uses the module (box-mixed), also included in -this directory. It uses the shared library libbox-module like the -module (box-module) above, but does not export the procedures from -that module. It only implements some procedures for dealing with box -objects. - -$ guile -guile> (use-modules (box-mixed)) -guile> (define bl (make-box-list 1 2 3)) -guile> bl -(#<box 1> #<box 2> #<box 3>) -guile> (box-map 1+ bl) -(#<box 2> #<box 3> #<box 4>) -guile> (quit) -$ - -If you like this example so much that you want to have it available -for normal usage, install the dynamic libraries in the .libs directory -to the directory $(prefix)/lib and the scheme file `box-module.scm' in -a directory in your GUILE_LOAD_PATH. diff --git a/examples/box-dynamic-module/box-mixed.scm b/examples/box-dynamic-module/box-mixed.scm deleted file mode 100644 index 9e6135291..000000000 --- a/examples/box-dynamic-module/box-mixed.scm +++ /dev/null @@ -1,44 +0,0 @@ -;;; examples/box-dynamic-module/box-mixed.scm -- Scheme module using some -;;; functionality from the shared library libbox-module, but do not -;;; export procedures from the module. - -;;; Commentary: - -;;; This is the Scheme module box-mixed. It uses some functionality -;;; from the shared library libbox-module, but does not export it. - -;;; Code: - -;;; Author: Thomas Wawrzinek -;;; Date: 2001-06-08 -;;; Changed: 2001-06-14 by martin, some commenting, cleanup and integration. - -(define-module (box-mixed)) - -;; First, load the library. -;; -(load-extension "libbox-module" "scm_init_box") - -;; Create a list of boxes, each containing one element from ARGS. -;; -(define (make-box-list . args) - (map (lambda (el) - (let ((b (make-box))) - (box-set! b el) b)) - args)) - -;; Map the procedure FUNC over all elements of LST, which must be a -;; list of boxes. The result is a list of freshly allocated boxes, -;; each containing the result of an application of FUNC. -(define (box-map func lst) - (map (lambda (el) - (let ((b (make-box))) - (box-set! b (func (box-ref el))) - b)) - lst)) - -;; Export the procedures, so that they can be used by others. -;; -(export make-box-list box-map) - -;;; End of file. diff --git a/examples/box-dynamic-module/box-module.scm b/examples/box-dynamic-module/box-module.scm deleted file mode 100644 index ab589ba1b..000000000 --- a/examples/box-dynamic-module/box-module.scm +++ /dev/null @@ -1,25 +0,0 @@ -;;; examples/box-dynamic-module/box-module.scm -- Scheme module exporting -;;; some functionality from the shared library libbox-module. - -;;; Commentary: - -;;; This is the Scheme part of the dynamic library module (box-module). -;;; When you do a (use-modules (box-module)) in this directory, -;;; this file gets loaded and will load the compiled extension. - -;;; Code: - -;;; Author: Martin Grabmueller -;;; Date: 2001-06-06 - -(define-module (box-module)) - -;; First, load the library. -;; -(load-extension "libbox-module" "scm_init_box") - -;; Then export the procedures which should be visible to module users. -;; -(export make-box box-ref box-set!) - -;;; End of file. diff --git a/examples/box-dynamic-module/box.c b/examples/box-dynamic-module/box.c deleted file mode 100644 index 180190e9e..000000000 --- a/examples/box-dynamic-module/box.c +++ /dev/null @@ -1,127 +0,0 @@ -/* examples/box-dynamic-module/box.c - * - * Copyright (C) 1998,2001 Free Software Foundation, Inc. - * - * This program 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 2, or (at your option) - * any later version. - * - * This program 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 this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA - */ - -/* Include all needed declarations. */ -#include <libguile.h> - - -/* The type code for the newly created smob type will be stored into - this variable. It has the prefix `scm_tc16_' to make it usable - with the SCM_VALIDATE_SMOB macro below. */ -static scm_t_bits scm_tc16_box; - - -/* This function is responsible for marking all SCM objects included - in the smob. */ -static SCM -mark_box (SCM b) -{ - /* Since we have only one SCM object to protect, we simply return it - and the caller will mark it. */ - return SCM_CELL_OBJECT_1 (b); -} - - -/* Print a textual represenation of the smob to a given port. */ -static int -print_box (SCM b, SCM port, scm_print_state *pstate) -{ - SCM value = SCM_CELL_OBJECT_1 (b); - - scm_puts ("#<box ", port); - scm_write (value, port); - scm_puts (">", port); - - /* Non-zero means success. */ - return 1; -} - - -/* This defines the primitve `make-box', which returns a new smob of - type `box', initialized to `#f'. */ -static SCM -#define FUNC_NAME "make-box" -make_box (void) -{ - /* This macro creates the new objects, stores the value `#f' into it - and returns it to the caller. */ - SCM_RETURN_NEWSMOB (scm_tc16_box, SCM_BOOL_F); -} -#undef FUNC_NAME - - -/* This is the primitive `box-ref' which returns the object stored in - the box. */ -static SCM -box_ref (SCM b) -#define FUNC_NAME "box-ref" -{ - /* First, we have to ensure that the user really gave us a box - objects. The macro SCM_VALIDATE_SMOB will do all what is needed. - The parameters are interpreted as follows: - - 1: The position of the checked variable in the parameter list. - b: The passed parameter. - box: Concatenated with the fixed prefix scm_tc16_, names the type - code for the expected smob type. */ - SCM_VALIDATE_SMOB (1, b, box); - - /* Fetch the object from the box and return it. */ - return SCM_CELL_OBJECT_1 (b); -} -#undef FUNC_NAME - - -/* Primitive which stores an arbitrary value into a box. */ -static SCM -box_set_x (SCM b, SCM value) -#define FUNC_NAME "box-set!" -{ - SCM_VALIDATE_SMOB (1, b, box); - - /* Set the cell number 1 of the smob to the given value. */ - SCM_SET_CELL_OBJECT_1 (b, value); - - /* When this constant is returned, the REPL will not print the - returned value. All procedures in Guile which are documented as - returning `and unspecified value' actually return this value. */ - return SCM_UNSPECIFIED; -} -#undef FUNC_NAME - - -/* This is the function which must be given to `load-extension' as the - second argument. In this example, the Scheme file box-module.scm - (or box-mixed.scm) is responsible for doing the load-extension - call. The Scheme modules are also responsible for placing the - procedure definitions in the correct module. */ -void -scm_init_box () -{ - scm_tc16_box = scm_make_smob_type ("box", 0); - scm_set_smob_mark (scm_tc16_box, mark_box); - scm_set_smob_print (scm_tc16_box, print_box); - - scm_c_define_gsubr ("make-box", 0, 0, 0, make_box); - scm_c_define_gsubr ("box-set!", 2, 0, 0, box_set_x); - scm_c_define_gsubr ("box-ref", 1, 0, 0, box_ref); -} - -/* End of file. */ diff --git a/examples/box-dynamic-module/check.test b/examples/box-dynamic-module/check.test deleted file mode 100755 index 935176d20..000000000 --- a/examples/box-dynamic-module/check.test +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh - -# must be run from this directory -guile=${GUILE-../../libguile/guile} - -set -e - -# -# ./box test #1 -# -$guile -c '(begin (use-modules (box-module)) (let ((b (make-box))) (display b) (newline)))' > TMP -cat <<EOF | diff -u - TMP -#<box #f> -EOF -rm -f TMP - -# -# ./box test #2 -# -$guile -c '(begin (use-modules (box-module)) (let ((b (make-box))) (display b) (newline) (box-set! b 1) (display b) (newline)))' > TMP -cat <<EOF | diff -u - TMP -#<box #f> -#<box 1> -EOF -rm -f TMP - -# -# ./box test #3 -# -$guile -c '(begin (use-modules (box-module)) (let ((b (make-box))) (display b) (newline) (box-set! b 1) (display b) (newline) (display (box-ref b)) (newline)))' > TMP -cat <<EOF | diff -u - TMP -#<box #f> -#<box 1> -1 -EOF -rm -f TMP - -# -# ./box test #4 -# -$guile -c '(begin (use-modules (box-mixed)) (let ((b (make-box-list 1 2 3))) (display b) (newline) (display (box-map 1+ b)) (newline)))' > TMP -cat <<EOF | diff -u - TMP -(#<box 1> #<box 2> #<box 3>) -(#<box 2> #<box 3> #<box 4>) -EOF -rm -f TMP - -# check.test ends here diff --git a/examples/box-dynamic/.cvsignore b/examples/box-dynamic/.cvsignore deleted file mode 100644 index 282522db0..000000000 --- a/examples/box-dynamic/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -Makefile -Makefile.in diff --git a/examples/box-dynamic/Makefile.am b/examples/box-dynamic/Makefile.am deleted file mode 100644 index 574eadb85..000000000 --- a/examples/box-dynamic/Makefile.am +++ /dev/null @@ -1,36 +0,0 @@ -## Process this file with Automake to create Makefile.in -## -## Copyright (C) 2001 Free Software Foundation, Inc. -## -## This file is part of GUILE. -## -## GUILE 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 2, or -## (at your option) any later version. -## -## GUILE 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 GUILE; see the file COPYING. If not, write -## to the Free Software Foundation, Inc., 59 Temple Place, Suite -## 330, Boston, MA 02111-1307 USA - -EXTRA_DIST = README box.c check.test - -CFLAGS=`$(bindir)/guile-config compile` -LIBS=`$(bindir)/guile-config link` - -libbox: box.lo - sh ../../libtool --mode=link $(CC) $< $(LIBS) -rpath $(libdir) -o libbox.la - -box.lo: box.c - sh ../../libtool --mode=compile $(CC) $(CFLAGS) -c $< - -installcheck: libbox - LTDL_LIBRARY_PATH=.libs GUILE_LOAD_PATH=$(top_srcdir):$(srcdir) $(srcdir)/check.test - -CLEANFILES=libbox.la box.lo box.o diff --git a/examples/box-dynamic/README b/examples/box-dynamic/README deleted file mode 100644 index 7acc9f432..000000000 --- a/examples/box-dynamic/README +++ /dev/null @@ -1,58 +0,0 @@ - -*- outline -*- - -* Overview - -This directory includes an example program for extending Guile with a -new (and even useful) data type, putting it into a shared library, so it -can be called from an unmodified guile interpreter. - - -* Build Instructions - -To build the example, simply type - - make libbox - -in this directory. - - -* The Box Data Type - -A box is simply an object for storing one other object in. It can be -used for passing parameters by reference, for example. You simply -store an object into a box, pass it to another procedure which can -store a new object into it and thus return a value via the box. - - -** Usage - -Box objects are created with `make-box', set with `box-set!' and -examined with `box-ref'. Note that these procedures are placed in a -module called (box-module) and can thus only be accessed after using -this module. See the following example session for usage details: - -Extend your LD_LIBRARY_PATH variable (or equivalent) to include . and -.libs - - -** Example Session - -$ guile -guile> (load-extension "libbox" "scm_init_box") -guile> (define b (make-box)) -guile> b -#<box #f> -guile> (box-set! b '(list of values)) -guile> b -#<box (list of values)> -guile> (box-ref b) -(list of values) -guile> (quit) -$ - - -* Module Installation - -If you like this example so much that you want to have it available -for normal usage, install the dynamic libraries in the .libs directory -to the directory $(prefix)/lib diff --git a/examples/box-dynamic/box.c b/examples/box-dynamic/box.c deleted file mode 100644 index 9379b86a5..000000000 --- a/examples/box-dynamic/box.c +++ /dev/null @@ -1,128 +0,0 @@ -/* examples/box-dynamic/box.c - * - * Copyright (C) 1998,2001 Free Software Foundation, Inc. - * - * This program 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 2, or (at your option) - * any later version. - * - * This program 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 this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA - */ - -/* Include all needed declarations. */ -#include <libguile.h> - - -/* The type code for the newly created smob type will be stored into - this variable. It has the prefix `scm_tc16_' to make it usable - with the SCM_VALIDATE_SMOB macro below. */ -static scm_t_bits scm_tc16_box; - - -/* This function is responsible for marking all SCM objects included - in the smob. */ -static SCM -mark_box (SCM b) -{ - /* Since we have only one SCM object to protect, we simply return it - and the caller will mark it. */ - return SCM_CELL_OBJECT_1 (b); -} - - -/* Print a textual represenation of the smob to a given port. */ -static int -print_box (SCM b, SCM port, scm_print_state *pstate) -{ - SCM value = SCM_CELL_OBJECT_1 (b); - - scm_puts ("#<box ", port); - scm_write (value, port); - scm_puts (">", port); - - /* Non-zero means success. */ - return 1; -} - - -/* This defines the primitve `make-box', which returns a new smob of - type `box', initialized to `#f'. */ -static SCM -#define FUNC_NAME "make-box" -make_box (void) -{ - /* This macro creates the new objects, stores the value `#f' into it - and returns it to the caller. */ - SCM_RETURN_NEWSMOB (scm_tc16_box, SCM_BOOL_F); -} -#undef FUNC_NAME - - -/* This is the primitive `box-ref' which returns the object stored in - the box. */ -static SCM -box_ref (SCM b) -#define FUNC_NAME "box-ref" -{ - /* First, we have to ensure that the user really gave us a box - objects. The macro SCM_VALIDATE_SMOB will do all what is needed. - The parameters are interpreted as follows: - - 1: The position of the checked variable in the parameter list. - b: The passed parameter. - box: Concatenated with the fixed prefix scm_tc16_, names the type - code for the expected smob type. */ - SCM_VALIDATE_SMOB (1, b, box); - - /* Fetch the object from the box and return it. */ - return SCM_CELL_OBJECT_1 (b); -} -#undef FUNC_NAME - - -/* Primitive which stores an arbitrary value into a box. */ -static SCM -box_set_x (SCM b, SCM value) -#define FUNC_NAME "box-set!" -{ - SCM_VALIDATE_SMOB (1, b, box); - - /* Set the cell number 1 of the smob to the given value. */ - SCM_SET_CELL_OBJECT_1 (b, value); - - /* When this constant is returned, the REPL will not print the - returned value. All procedures in Guile which are documented as - returning `and unspecified value' actually return this value. */ - return SCM_UNSPECIFIED; -} -#undef FUNC_NAME - - -/* Create and initialize the new smob type, and register the - primitives with the interpreter library. - - To be called with (load-extension "libbox" "scm_init_box") - from a script. -*/ -void -scm_init_box () -{ - scm_tc16_box = scm_make_smob_type ("box", 0); - scm_set_smob_mark (scm_tc16_box, mark_box); - scm_set_smob_print (scm_tc16_box, print_box); - - scm_c_define_gsubr ("make-box", 0, 0, 0, make_box); - scm_c_define_gsubr ("box-set!", 2, 0, 0, box_set_x); - scm_c_define_gsubr ("box-ref", 1, 0, 0, box_ref); -} - -/* End of file. */ diff --git a/examples/box-dynamic/check.test b/examples/box-dynamic/check.test deleted file mode 100755 index c0923365c..000000000 --- a/examples/box-dynamic/check.test +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh - -# must be run from this directory -guile=${GUILE-../../libguile/guile} - -set -e - -# -# ./box test #1 -# -$guile -c '(begin (load-extension "libbox" "scm_init_box") (let ((b (make-box))) (display b) (newline)))' > TMP -cat <<EOF | diff -u - TMP -#<box #f> -EOF -rm -f TMP - -# -# ./box test #2 -# -$guile -c '(begin (load-extension "libbox" "scm_init_box") (let ((b (make-box))) (display b) (newline) (box-set! b 1) (display b) (newline)))' > TMP -cat <<EOF | diff -u - TMP -#<box #f> -#<box 1> -EOF -rm -f TMP - -# -# ./box test #3 -# -$guile -c '(begin (load-extension "libbox" "scm_init_box") (let ((b (make-box))) (display b) (newline) (box-set! b 1) (display b) (newline) (display (box-ref b)) (newline)))' > TMP -cat <<EOF | diff -u - TMP -#<box #f> -#<box 1> -1 -EOF -rm -f TMP - -# check.test ends here diff --git a/examples/box-module/.cvsignore b/examples/box-module/.cvsignore deleted file mode 100644 index 051d1bd50..000000000 --- a/examples/box-module/.cvsignore +++ /dev/null @@ -1,3 +0,0 @@ -Makefile -Makefile.in -.deps diff --git a/examples/box-module/Makefile.am b/examples/box-module/Makefile.am deleted file mode 100644 index 3fe82e7cd..000000000 --- a/examples/box-module/Makefile.am +++ /dev/null @@ -1,36 +0,0 @@ -## Process this file with Automake to create Makefile.in -## -## Copyright (C) 2001 Free Software Foundation, Inc. -## -## This file is part of GUILE. -## -## GUILE 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 2, or -## (at your option) any later version. -## -## GUILE 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 GUILE; see the file COPYING. If not, write -## to the Free Software Foundation, Inc., 59 Temple Place, Suite -## 330, Boston, MA 02111-1307 USA - -EXTRA_DIST = README box.c check.test - -CFLAGS=`$(bindir)/guile-config compile` -LIBS=`$(bindir)/guile-config link` - -box: box.o - $(CC) $< $(LIBS) -o box - -box.o: box.c - $(CC) $(CFLAGS) -c $< - -installcheck: box - LD_LIBRARY_PATH=$(libdir) GUILE_LOAD_PATH=$(top_srcdir) $(srcdir)/check.test - -CLEANFILES=box box.o diff --git a/examples/box-module/README b/examples/box-module/README deleted file mode 100644 index e1f1cd7af..000000000 --- a/examples/box-module/README +++ /dev/null @@ -1,56 +0,0 @@ - -*- outline -*- - -* Overview - -This directory includes an example program for extending Guile with a -new (and even useful) data type. - -The `box' program created by this example is nearly identical to the -one produced in directory ../box, with one (important) difference: The -interpreter in this directory will place all defined primitive -procedures in a module called (box-module). That means that this -module must be used before the primitives can be accessed. - - -* Build Instructions - -To build the example, simply type - - make box - -in this directory. - -The resulting `box' program is a Guile interpreter which has one -additional data type called `box'. - - -* The Box Data Type - -A box is simply an object for storing one other object in. It can be -used for passing parameters by reference, for example. You simply -store an object into a box, pass it to another procedure which can -store a new object into it and thus return a value via the box. - - -** Usage - -Box objects are created with `make-box', set with `box-set!' and -examined with `box-ref'. Note that these procedures are placed in a -module called (box-module) and can thus only be accessed after using -this module. See the following example session for usage details: - - -** Example Session - -$ ./box -guile> (use-modules (box-module)) -guile> (define b (make-box)) -guile> b -#<box #f> -guile> (box-set! b '(list of values)) -guile> b -#<box (list of values)> -guile> (box-ref b) -(list of values) -guile> (quit) -$ diff --git a/examples/box-module/box.c b/examples/box-module/box.c deleted file mode 100644 index 90f6881dd..000000000 --- a/examples/box-module/box.c +++ /dev/null @@ -1,160 +0,0 @@ -/* examples/box-module/box.c - * - * Copyright (C) 1998,2001 Free Software Foundation, Inc. - * - * This program 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 2, or (at your option) - * any later version. - * - * This program 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 this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA - */ - -/* Include all needed declarations. */ -#include <libguile.h> - - -/* The type code for the newly created smob type will be stored into - this variable. It has the prefix `scm_tc16_' to make it usable - with the SCM_VALIDATE_SMOB macro below. */ -static scm_t_bits scm_tc16_box; - - -/* This function is responsible for marking all SCM objects included - in the smob. */ -static SCM -mark_box (SCM b) -{ - /* Since we have only one SCM object to protect, we simply return it - and the caller will mark it. */ - return SCM_CELL_OBJECT_1 (b); -} - - -/* Print a textual represenation of the smob to a given port. */ -static int -print_box (SCM b, SCM port, scm_print_state *pstate) -{ - SCM value = SCM_CELL_OBJECT_1 (b); - - scm_puts ("#<box ", port); - scm_write (value, port); - scm_puts (">", port); - - /* Non-zero means success. */ - return 1; -} - - -/* This defines the primitve `make-box', which returns a new smob of - type `box', initialized to `#f'. */ -static SCM -#define FUNC_NAME "make-box" -make_box (void) -{ - /* This macro creates the new objects, stores the value `#f' into it - and returns it to the caller. */ - SCM_RETURN_NEWSMOB (scm_tc16_box, SCM_BOOL_F); -} -#undef FUNC_NAME - - -/* This is the primitive `box-ref' which returns the object stored in - the box. */ -static SCM -box_ref (SCM b) -#define FUNC_NAME "box-ref" -{ - /* First, we have to ensure that the user really gave us a box - objects. The macro SCM_VALIDATE_SMOB will do all what is needed. - The parameters are interpreted as follows: - - 1: The position of the checked variable in the parameter list. - b: The passed parameter. - box: Concatenated with the fixed prefix scm_tc16_, names the type - code for the expected smob type. */ - SCM_VALIDATE_SMOB (1, b, box); - - /* Fetch the object from the box and return it. */ - return SCM_CELL_OBJECT_1 (b); -} -#undef FUNC_NAME - - -/* Primitive which stores an arbitrary value into a box. */ -static SCM -box_set_x (SCM b, SCM value) -#define FUNC_NAME "box-set!" -{ - SCM_VALIDATE_SMOB (1, b, box); - - /* Set the cell number 1 of the smob to the given value. */ - SCM_SET_CELL_OBJECT_1 (b, value); - - /* When this constant is returned, the REPL will not print the - returned value. All procedures in Guile which are documented as - returning `and unspecified value' actually return this value. */ - return SCM_UNSPECIFIED; -} -#undef FUNC_NAME - - -/* Create and initialize the new smob type, and register the - primitives withe the interpreter library. - - This function must be declared a bit different from the example in - the ../box directory, because it will be called by - `scm_c_define_module', called from below. */ -static void -init_box_type (void * unused) -{ - scm_tc16_box = scm_make_smob_type ("box", 0); - scm_set_smob_mark (scm_tc16_box, mark_box); - scm_set_smob_print (scm_tc16_box, print_box); - - scm_c_define_gsubr ("make-box", 0, 0, 0, make_box); - scm_c_define_gsubr ("box-set!", 2, 0, 0, box_set_x); - scm_c_define_gsubr ("box-ref", 1, 0, 0, box_ref); - - /* This is new too: Since the procedures are now in a module, we - have to explicitly export them before they can be used. */ - scm_c_export ("make-box", "box-set!", "box-ref", NULL); -} - - -/* This is the function which gets called by scm_boot_guile after the - Guile library is completely initialized. */ -static void -inner_main (void *closure, int argc, char **argv) -{ - /* Unlike the example in ../box, init_box_type is not called - directly, but by scm_c_define_module, which will create a module - named (box-module) and make this module current while called - init_box_type, thus placing the definitions into that module. */ - scm_c_define_module ("box-module", init_box_type, NULL); - - /* ... then we start a shell, in which the box data type can be - used (after using the module (box-module)). */ - scm_shell (argc, argv); -} - - -/* Main program. */ -int -main (int argc, char **argv) -{ - /* Initialize Guile, then call `inner_main' with the arguments 0, - argc and argv. */ - scm_boot_guile (argc, argv, inner_main, 0); - return 0; /* Never reached. */ -} - -/* End of file. */ diff --git a/examples/box-module/check.test b/examples/box-module/check.test deleted file mode 100755 index 28a79d45b..000000000 --- a/examples/box-module/check.test +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh - -# must be run from this directory -guile=${GUILE-../../libguile/guile} - -set -e - -# -# ./box test #1 -# -./box -c '(begin (use-modules (box-module)) (let ((b (make-box))) (display b) (newline)))' > TMP -cat <<EOF | diff -u - TMP -#<box #f> -EOF -rm -f TMP - -# -# ./box test #2 -# -./box -c '(begin (use-modules (box-module)) (let ((b (make-box))) (display b) (newline) (box-set! b 1) (display b) (newline)))' > TMP -cat <<EOF | diff -u - TMP -#<box #f> -#<box 1> -EOF -rm -f TMP - -# -# ./box test #3 -# -./box -c '(begin (use-modules (box-module)) (let ((b (make-box))) (display b) (newline) (box-set! b 1) (display b) (newline) (display (box-ref b)) (newline)))' > TMP -cat <<EOF | diff -u - TMP -#<box #f> -#<box 1> -1 -EOF -rm -f TMP - -# check.test ends here diff --git a/examples/box/.cvsignore b/examples/box/.cvsignore deleted file mode 100644 index 051d1bd50..000000000 --- a/examples/box/.cvsignore +++ /dev/null @@ -1,3 +0,0 @@ -Makefile -Makefile.in -.deps diff --git a/examples/box/Makefile.am b/examples/box/Makefile.am deleted file mode 100644 index 3fe82e7cd..000000000 --- a/examples/box/Makefile.am +++ /dev/null @@ -1,36 +0,0 @@ -## Process this file with Automake to create Makefile.in -## -## Copyright (C) 2001 Free Software Foundation, Inc. -## -## This file is part of GUILE. -## -## GUILE 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 2, or -## (at your option) any later version. -## -## GUILE 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 GUILE; see the file COPYING. If not, write -## to the Free Software Foundation, Inc., 59 Temple Place, Suite -## 330, Boston, MA 02111-1307 USA - -EXTRA_DIST = README box.c check.test - -CFLAGS=`$(bindir)/guile-config compile` -LIBS=`$(bindir)/guile-config link` - -box: box.o - $(CC) $< $(LIBS) -o box - -box.o: box.c - $(CC) $(CFLAGS) -c $< - -installcheck: box - LD_LIBRARY_PATH=$(libdir) GUILE_LOAD_PATH=$(top_srcdir) $(srcdir)/check.test - -CLEANFILES=box box.o diff --git a/examples/box/README b/examples/box/README deleted file mode 100644 index fb0ef1305..000000000 --- a/examples/box/README +++ /dev/null @@ -1,48 +0,0 @@ - -*- outline -*- - -* Overview - -This directory includes an example program for extending Guile with a -new (and even useful) data type. - - -* Build Instructions - -To build the example, simply type - - make box - -in this directory. - -The resulting `box' program is a Guile interpreter which has one -additional data type called `box'. - - -* The Box Data Type - -A box is simply an object for storing one other object in. It can be -used for passing parameters by reference, for example. You simply -store an object into a box, pass it to another procedure which can -store a new object into it and thus return a value via the box. - - -** Usage - -Box objects are created with `make-box', set with `box-set!' and -examined with `box-ref'. See the following example session for usage -details: - - -** Example Session - -$ ./box -guile> (define b (make-box)) -guile> b -#<box #f> -guile> (box-set! b '(list of values)) -guile> b -#<box (list of values)> -guile> (box-ref b) -(list of values) -guile> (quit) -$ diff --git a/examples/box/box.c b/examples/box/box.c deleted file mode 100644 index e526fa880..000000000 --- a/examples/box/box.c +++ /dev/null @@ -1,148 +0,0 @@ -/* examples/box/box.c - * - * Copyright (C) 1998,2001 Free Software Foundation, Inc. - * - * This program 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 2, or (at your option) - * any later version. - * - * This program 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 this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA - */ - -/* Include all needed declarations. */ -#include <libguile.h> - - -/* The type code for the newly created smob type will be stored into - this variable. It has the prefix `scm_tc16_' to make it usable - with the SCM_VALIDATE_SMOB macro below. */ -static scm_t_bits scm_tc16_box; - - -/* This function is responsible for marking all SCM objects included - in the smob. */ -static SCM -mark_box (SCM b) -{ - /* Since we have only one SCM object to protect, we simply return it - and the caller will mark it. */ - return SCM_CELL_OBJECT_1 (b); -} - - -/* Print a textual represenation of the smob to a given port. */ -static int -print_box (SCM b, SCM port, scm_print_state *pstate) -{ - SCM value = SCM_CELL_OBJECT_1 (b); - - scm_puts ("#<box ", port); - scm_write (value, port); - scm_puts (">", port); - - /* Non-zero means success. */ - return 1; -} - - -/* This defines the primitve `make-box', which returns a new smob of - type `box', initialized to `#f'. */ -static SCM -#define FUNC_NAME "make-box" -make_box (void) -{ - /* This macro creates the new objects, stores the value `#f' into it - and returns it to the caller. */ - SCM_RETURN_NEWSMOB (scm_tc16_box, SCM_BOOL_F); -} -#undef FUNC_NAME - - -/* This is the primitive `box-ref' which returns the object stored in - the box. */ -static SCM -box_ref (SCM b) -#define FUNC_NAME "box-ref" -{ - /* First, we have to ensure that the user really gave us a box - objects. The macro SCM_VALIDATE_SMOB will do all what is needed. - The parameters are interpreted as follows: - - 1: The position of the checked variable in the parameter list. - b: The passed parameter. - box: Concatenated with the fixed prefix scm_tc16_, names the type - code for the expected smob type. */ - SCM_VALIDATE_SMOB (1, b, box); - - /* Fetch the object from the box and return it. */ - return SCM_CELL_OBJECT_1 (b); -} -#undef FUNC_NAME - - -/* Primitive which stores an arbitrary value into a box. */ -static SCM -box_set_x (SCM b, SCM value) -#define FUNC_NAME "box-set!" -{ - SCM_VALIDATE_SMOB (1, b, box); - - /* Set the cell number 1 of the smob to the given value. */ - SCM_SET_CELL_OBJECT_1 (b, value); - - /* When this constant is returned, the REPL will not print the - returned value. All procedures in Guile which are documented as - returning `and unspecified value' actually return this value. */ - return SCM_UNSPECIFIED; -} -#undef FUNC_NAME - - -/* Create and initialize the new smob type, and register the - primitives withe the interpreter library. */ -static void -init_box_type (void) -{ - scm_tc16_box = scm_make_smob_type ("box", 0); - scm_set_smob_mark (scm_tc16_box, mark_box); - scm_set_smob_print (scm_tc16_box, print_box); - - scm_c_define_gsubr ("make-box", 0, 0, 0, make_box); - scm_c_define_gsubr ("box-set!", 2, 0, 0, box_set_x); - scm_c_define_gsubr ("box-ref", 1, 0, 0, box_ref); -} - - -/* This is the function which gets called by scm_boot_guile after the - Guile library is completely initialized. */ -static void -inner_main (void *closure, int argc, char **argv) -{ - /* First, we create our data type... */ - init_box_type (); - /* ... then we start a shell, in which the box data type can be - used. */ - scm_shell (argc, argv); -} - - -/* Main program. */ -int -main (int argc, char **argv) -{ - /* Initialize Guile, then call `inner_main' with the arguments 0, - argc and argv. */ - scm_boot_guile (argc, argv, inner_main, 0); - return 0; /* Never reached. */ -} - -/* End of file. */ diff --git a/examples/box/check.test b/examples/box/check.test deleted file mode 100755 index 1909ffb7e..000000000 --- a/examples/box/check.test +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh - -# must be run from this directory -guile=${GUILE-../../libguile/guile} - -set -e - -# -# ./box test #1 -# -./box -c '(let ((b (make-box))) (display b) (newline))' > TMP -cat <<EOF | diff -u - TMP -#<box #f> -EOF -rm -f TMP - -# -# ./box test #2 -# -./box -c '(let ((b (make-box))) (display b) (newline) (box-set! b 1) (display b) (newline))' > TMP -cat <<EOF | diff -u - TMP -#<box #f> -#<box 1> -EOF -rm -f TMP - -# -# ./box test #3 -# -./box -c '(let ((b (make-box))) (display b) (newline) (box-set! b 1) (display b) (newline) (display (box-ref b)) (newline))' > TMP -cat <<EOF | diff -u - TMP -#<box #f> -#<box 1> -1 -EOF -rm -f TMP - -# check.test ends here diff --git a/examples/modules/.cvsignore b/examples/modules/.cvsignore deleted file mode 100644 index 282522db0..000000000 --- a/examples/modules/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -Makefile -Makefile.in diff --git a/examples/modules/Makefile.am b/examples/modules/Makefile.am deleted file mode 100644 index a6a9e0e03..000000000 --- a/examples/modules/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -## Process this file with Automake to create Makefile.in -## -## Copyright (C) 2001 Free Software Foundation, Inc. -## -## This file is part of GUILE. -## -## GUILE 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 2, or -## (at your option) any later version. -## -## GUILE 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 GUILE; see the file COPYING. If not, write -## to the Free Software Foundation, Inc., 59 Temple Place, Suite -## 330, Boston, MA 02111-1307 USA - -EXTRA_DIST = README module-0.scm module-1.scm module-2.scm main check.test - -installcheck: - srcdir=$(srcdir) GUILE_LOAD_PATH=$(top_srcdir):$(srcdir) $(srcdir)/check.test diff --git a/examples/modules/README b/examples/modules/README deleted file mode 100644 index ddad881cc..000000000 --- a/examples/modules/README +++ /dev/null @@ -1,32 +0,0 @@ - -*- outline -*- - -* Overview - -This directory includes examples which show how to write and use Guile -modules in Scheme programs. - -The descriptions below assume that you have a working copy of Guile -installed and available with the standard installation prefix -`/usr/local'. - - -* Included Examples - - -** main - - The main program, which uses the modules described below to perform - some actions. Module usage and selective importing as well as - renaming is demonstrated here.n - - $ ./main - - or - - guile -s main - -** module-0.scm, module-1.scm, module-2.scm - - Two modules which export several procedure, some of which have the - same names (so that renaming/selection is required for proper - importing). diff --git a/examples/modules/check.test b/examples/modules/check.test deleted file mode 100755 index f7a789b69..000000000 --- a/examples/modules/check.test +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -# must be run from this directory -guile=${GUILE-../../libguile/guile} - -if test "X$srcdir" = X; then - srcdir=. -fi - -set -e - -# -# ./main test -# -$guile -s $srcdir/main > TMP -cat <<EOF | diff -u - TMP -module-0 foo -module-0 bar -module-1 foo -module-1 bar -module-2 braz -module-2 braz -module-2 foo -EOF -rm -f TMP - -# check.test ends here diff --git a/examples/modules/main b/examples/modules/main deleted file mode 100644 index e4cc71dc7..000000000 --- a/examples/modules/main +++ /dev/null @@ -1,52 +0,0 @@ -#! /usr/local/bin/guile -s -!# -;;; examples/modules/main -- Module system demo. - -;;; Commentary: - -;;; The main demo program for the modules subdirectory. -;;; -;;; This program shows how all the new fancy module import features -;;; are to be used. - -;;; Author: Martin Grabmueller -;;; Date: 2001-05-29 - -;;; Code: - -(define-module (main) - ;; The module 0 is imported completely. - ;; - :use-module (module-0) - - ;; Module 1 is imported completely, too, but the procedure names are - ;; prefixed with the module name. - ;; - :use-module ((module-1) :renamer (symbol-prefix-proc 'module-1:)) - - ;; From module 2, only the procedure `braz' is imported, so that the - ;; procedures `foo' and `bar' also exported by that module don't - ;; clash with the definitions of module 0. - ;; - :use-module ((module-2) :select (braz)) - - ;; Import the bindings from module 2 again, now renaming them by - ;; explicitly mentioning the original and new names. - ;; - :use-module ((module-2) :select ((braz . m-2:braz) (foo . m-2:foo)))) - -;; -;; Now call the various imported procedures. -;; - -(foo) -(bar) -(module-1:foo) -(module-1:bar) -(braz) -(m-2:braz) -(m-2:foo) - -;; Local variables: -;; mode: scheme -;; End: diff --git a/examples/modules/module-0.scm b/examples/modules/module-0.scm deleted file mode 100644 index a5a001b64..000000000 --- a/examples/modules/module-0.scm +++ /dev/null @@ -1,24 +0,0 @@ -;;; examples/modules/module-0.scm -- Module system demo. - -;;; Commentary: - -;;; Module 0 of the module demo program. - -;;; Author: Martin Grabmueller -;;; Date: 2001-05-29 - -;;; Code: - -(define-module (module-0)) - -(export foo bar) - -(define (foo) - (display "module-0 foo") - (newline)) - -(define (bar) - (display "module-0 bar") - (newline)) - -;;; End of file. diff --git a/examples/modules/module-1.scm b/examples/modules/module-1.scm deleted file mode 100644 index 6a7bb43e0..000000000 --- a/examples/modules/module-1.scm +++ /dev/null @@ -1,24 +0,0 @@ -;;; examples/modules/module-1.scm -- Module system demo. - -;;; Commentary: - -;;; Module 1 of the module demo program. - -;;; Author: Martin Grabmueller -;;; Date: 2001-05-29 - -;;; Code: - -(define-module (module-1)) - -(export foo bar) - -(define (foo) - (display "module-1 foo") - (newline)) - -(define (bar) - (display "module-1 bar") - (newline)) - -;;; End of file. diff --git a/examples/modules/module-2.scm b/examples/modules/module-2.scm deleted file mode 100644 index 3147b2cab..000000000 --- a/examples/modules/module-2.scm +++ /dev/null @@ -1,28 +0,0 @@ -;;; examples/modules/module-2.scm -- Module system demo. - -;;; Commentary: - -;;; Module 2 of the module demo program. - -;;; Author: Martin Grabmueller -;;; Date: 2001-05-29 - -;;; Code: - -(define-module (module-2)) - -(export foo bar braz) - -(define (foo) - (display "module-2 foo") - (newline)) - -(define (bar) - (display "module-2 bar") - (newline)) - -(define (braz) - (display "module-2 braz") - (newline)) - -;;; End of file. diff --git a/examples/safe/.cvsignore b/examples/safe/.cvsignore deleted file mode 100644 index 282522db0..000000000 --- a/examples/safe/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -Makefile -Makefile.in diff --git a/examples/safe/Makefile.am b/examples/safe/Makefile.am deleted file mode 100644 index 16c2f1687..000000000 --- a/examples/safe/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -## Process this file with Automake to create Makefile.in -## -## Copyright (C) 2001 Free Software Foundation, Inc. -## -## This file is part of GUILE. -## -## GUILE 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 2, or -## (at your option) any later version. -## -## GUILE 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 GUILE; see the file COPYING. If not, write -## to the Free Software Foundation, Inc., 59 Temple Place, Suite -## 330, Boston, MA 02111-1307 USA - -EXTRA_DIST = README safe untrusted.scm evil.scm check.test - -installcheck: - srcdir=$(srcdir) GUILE_LOAD_PATH=$(top_srcdir) $(srcdir)/check.test diff --git a/examples/safe/README b/examples/safe/README deleted file mode 100644 index 47abcbf9f..000000000 --- a/examples/safe/README +++ /dev/null @@ -1,41 +0,0 @@ - -*- outline -*- - -* Overview - -This directory includes examples which show how to create and use safe -environments for safe (sand-boxed) execution of Scheme programs. - -*Note* that the files in this directory are only suitable for - demonstration purposes, if you have to implement safe evaluation - mechanisms in important environments, you will have to do more than - shown here -- for example disabling input/output operations. - -The descriptions below assume that you have a working copy of Guile -installed and available with the standard installation prefix -`/usr/local'. - -* Included Examples - - -** safe - - The main program, which executes the Scheme code in a file given on - the command line in a safe environment. The following command will - do that with the file `untrusted.scm' (see below.) - - $ ./safe untrusted.scm - - or - - guile -s safe untrusted.scm - -** untrusted.scm - - This file contains some Scheme code, which will be executed in a - safe environment by the `safe' script. - -** evil.scm - - This file also contains Scheme code, but it tries to do evil things. - Evaluating this with the `safe' script will abort on those evil - actions. diff --git a/examples/safe/check.test b/examples/safe/check.test deleted file mode 100755 index 9e5f192d8..000000000 --- a/examples/safe/check.test +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh - -# must be run from this directory -guile=${GUILE-../../libguile/guile} - -if test "X$srcdir" = X; then - srcdir=. -fi - -set -e - -# -# ./safe untrusted.scm -# -$guile -s $srcdir/safe $srcdir/untrusted.scm > TMP -cat <<EOF | diff -u - TMP -1 -1 -2 -6 -24 -120 -720 -5040 -40320 -362880 -3628800 -EOF -rm -f TMP - -# -# ./safe evil.scm -# -$guile -s $srcdir/safe $srcdir/evil.scm > TMP -cat <<EOF | diff -u - TMP -** Exception: (unbound-variable #f "Unbound variable: ~S" (open-input-file) #f) -EOF -rm -f TMP - -# check.test ends here diff --git a/examples/safe/evil.scm b/examples/safe/evil.scm deleted file mode 100644 index f9ee9082f..000000000 --- a/examples/safe/evil.scm +++ /dev/null @@ -1,27 +0,0 @@ -;;; examples/safe/evil.scm -- Evil Scheme file to be run in a safe -;;; environment. - -;;; Commentary: - -;;; This is an example file to be evaluated by the `safe' program in -;;; this directory. This program, unlike the `untrusted.scm' (which -;;; is untrusted, but a really nice fellow though), tries to do evil -;;; things and will thus break in a safe environment. -;;; -;;; *Note* that the files in this directory are only suitable for -;;; demonstration purposes, if you have to implement safe evaluation -;;; mechanisms in important environments, you will have to do more -;;; than shown here -- for example disabling input/output operations. - -;;; Author: Martin Grabmueller -;;; Date: 2001-05-30 - -;;; Code: - -(define passwd (open-input-file "/etc/passwd")) - -(let lp ((ch (read-char passwd))) - (if (not (eof-object? ch)) - (lp (read-char passwd)))) - -;;; End of file. diff --git a/examples/safe/safe b/examples/safe/safe deleted file mode 100755 index 7653dc2b8..000000000 --- a/examples/safe/safe +++ /dev/null @@ -1,85 +0,0 @@ -#! /usr/local/bin/guile -s -!# -;;; examples/safe/safe -- Example for safe (sand-boxed) evaluation. - -;;; Commentary: - -;;; This is a demo program for evaluating arbitrary (untrusted) Scheme -;;; code in a controlled, safe environment. Evaluation in safe -;;; environments restricts the evaluated code's access to some given -;;; primitives, which are considered `safe', that means which cannot -;;; do any harm to the world outside of Guile (creating/deleting files -;;; etc.) -;;; -;;; *Note* that the files in this directory are only suitable for -;;; demonstration purposes, if you have to implement safe evaluation -;;; mechanisms in important environments, you will have to do more -;;; than shown here -- for example disabling input/output operations. - -;;; Author: Martin Grabmueller -;;; Date: 2001-05-30 - -;;; Code: - -;; Safe module creation is implemented in this module: -;; -(use-modules (ice-9 safe)) - -;; This is the main program. It expects one parameter in the format -;; returned by (command-line) and expects that exactly one file name -;; is passed in this list (after the script name, which is passed as -;; the 0th parameter.) -;; -;; The given file is opened for reading, one expression after the -;; other is read and evaluated in a safe environment. All exceptions -;; caused by this evaluation are caught and printed out. -;; -(define (main cmd-line) - - ;; Internal definition of the procedure which prints usage - ;; information. - ;; - (define (display-help) - (display "Usage: safe FILENAME") - (newline) - (quit 1)) - - ;; Check that we received exactly one command line argument after - ;; the script name - ;; - (if (not (= (length cmd-line) 2)) - (display-help) - (let ((port (open-input-file (cadr cmd-line))) - - ;; Create the safe module. - (safe-module (make-safe-module))) - - ;; Read one expression a time. - (let lp ((expr (read port))) - ;; End of file? -> Return. - (if (eof-object? expr) - #t - (catch #t - (lambda () - ;; Evaluate the expression in the safe environment. - (eval expr safe-module) - ;; ... and read the next expression if no error occured. - (lp (read port))) - - ;; Handle exceptions. This procedure will be called when an - ;; error occurs while evaluating the expression. It just - ;; prints out a message telling so and returns from the - ;; evaluation loop, thus terminating the program. - ;; - (lambda args - (display "** Exception: ") - (write args) - (newline)))))))) - -;; Start the main program. -;; -(main (command-line)) - -;; Local variables: -;; mode: scheme -;; End: diff --git a/examples/safe/untrusted.scm b/examples/safe/untrusted.scm deleted file mode 100644 index f3ae5fe97..000000000 --- a/examples/safe/untrusted.scm +++ /dev/null @@ -1,33 +0,0 @@ -;;; examples/safe/untrusted.scm -- Scheme file to be run in a safe -;;; environment. - -;;; Commentary: - -;;; This is an example file to be evaluated by the `safe' program in -;;; this directory. -;;; -;;; *Note* that the files in this directory are only suitable for -;;; demonstration purposes, if you have to implement safe evaluation -;;; mechanisms in important environments, you will have to do more -;;; than shown here -- for example disabling input/output operations. - -;;; Author: Martin Grabmueller -;;; Date: 2001-05-30 - -;;; Code: - -;; fact -- the everlasting factorial function... -;; -(define (fact n) - (if (< n 2) - 1 - (* n (fact (- n 1))))) - -;; Display the factorial of 0..9 to the terminal. -;; -(do ((x 0 (+ x 1))) - ((= x 11)) - (display (fact x)) - (newline)) - -;;; End of file. diff --git a/examples/scripts/.cvsignore b/examples/scripts/.cvsignore deleted file mode 100644 index 282522db0..000000000 --- a/examples/scripts/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -Makefile -Makefile.in diff --git a/examples/scripts/Makefile.am b/examples/scripts/Makefile.am deleted file mode 100644 index 3a82dad77..000000000 --- a/examples/scripts/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -## Process this file with Automake to create Makefile.in -## -## Copyright (C) 2001 Free Software Foundation, Inc. -## -## This file is part of GUILE. -## -## GUILE 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 2, or -## (at your option) any later version. -## -## GUILE 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 GUILE; see the file COPYING. If not, write -## to the Free Software Foundation, Inc., 59 Temple Place, Suite -## 330, Boston, MA 02111-1307 USA - -EXTRA_DIST = README simple-hello.scm hello fact check.test - -installcheck: - srcdir=$(srcdir) GUILE_LOAD_PATH=$(top_srcdir) $(srcdir)/check.test diff --git a/examples/scripts/README b/examples/scripts/README deleted file mode 100644 index f3e965b5a..000000000 --- a/examples/scripts/README +++ /dev/null @@ -1,38 +0,0 @@ - -*- outline -*- - -* Overview - -This directory includes examples which show how to write scripts using -Guile. - -The descriptions below assume that you have a working copy of Guile -installed and available with the standard installation prefix -`/usr/local'. - -* Included Examples - - -** simple-hello.scm - - The simplest "Hello World!" program for Guile. Run it like this: - - $ guile -s simple-hello.scm - -** hello - - An advanced version of the script above, with command line handling - for the important options --help and --version. Run it like this: - - ./hello - - or - - guile -s hello - -** fact - - Command-line factorial calculator. Run it like this: - - ./fact 5 - - to calculate the factorial of 5. diff --git a/examples/scripts/check.test b/examples/scripts/check.test deleted file mode 100755 index 2a3e753d6..000000000 --- a/examples/scripts/check.test +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh - -# must be run from this directory -guile=${GUILE-../../libguile/guile} -if [ -x $guile ] ; then - : -else - echo could not find guile interpreter. - echo '(are you running this script from' `dirname $0` '?)' - echo GUILE env var: ${GUILE-not set} - exit 1 -fi - -if test "X$srcdir" = X; then - srcdir=. -fi - -set -e - -# -# simple-hello.scm -# -$guile -s $srcdir/simple-hello.scm > TMP -cat <<EOF | diff -u - TMP -Hello, World! -EOF -rm -f TMP - -# -# hello -# -$guile -s $srcdir/hello > TMP -echo "Hello, World!" | diff -u - TMP -rm -f TMP - -$guile -s $srcdir/hello --version > TMP -echo "hello 0.0.1" | diff -u - TMP -rm -f TMP - -$guile -s $srcdir/hello --help > TMP -cat <<EOF | diff -u - TMP -Usage: hello [options...] - --help, -h Show this usage information - --version, -v Show version information -EOF -rm -f TMP - -# -# fact -# -case `$guile -s $srcdir/fact 5` in 120) ;; *) echo $0: error: fact 5 ;; esac - -# check.test ends here diff --git a/examples/scripts/fact b/examples/scripts/fact deleted file mode 100755 index 05bcc9ffe..000000000 --- a/examples/scripts/fact +++ /dev/null @@ -1,69 +0,0 @@ -#! /usr/local/bin/guile -s -!# -;;; Commentary: - -;;; This is a command-line factorial calculator. Run like this: -;;; -;;; ./fact 5 -;;; -;;; to calculate the factorial of 5 - -;;; Author: Martin Grabmueller -;;; Date: 2001-05-29 - -;;; Code: - -(use-modules (ice-9 getopt-long)) - -;; This is the grammar for the command line synopsis we expect. -;; -(define command-synopsis - '((version (single-char #\v) (value #f)) - (help (single-char #\h) (value #f)))) - -;; Display version information and exit. -;; -(define (display-version) - (display "fact 0.0.1\n")) - -;; Display the usage help message and exit. -;; -(define (display-help) - (display "Usage: fact [options...] number\n") - (display " --help, -h Show this usage information\n") - (display " --version, -v Show version information\n")) - -;; Interpret options, if --help or --version was given, print out the -;; requested information and exit. Otherwise, calculate the factorial -;; of the argument. -;; -(define (main options) - (let ((help-wanted (option-ref options 'help #f)) - (version-wanted (option-ref options 'version #f)) - (args (option-ref options '() '()))) - (cond - ((or version-wanted help-wanted) - (if version-wanted - (display-version)) - (if help-wanted - (display-help))) - ((not (= (length args) 1)) - (display-help)) - (else - (display (fact (string->number (car args)))) - (newline))))) - -;; Calculate the factorial of n. -;; -(define (fact n) - (if (< n 2) - 1 - (* n (fact (- n 1))))) - -;; Call the main program with parsed command line options. -;; -(main (getopt-long (command-line) command-synopsis)) - -;; Local variables: -;; mode: scheme -;; End: diff --git a/examples/scripts/hello b/examples/scripts/hello deleted file mode 100755 index 01f9a6c3b..000000000 --- a/examples/scripts/hello +++ /dev/null @@ -1,57 +0,0 @@ -#! /usr/local/bin/guile -s -!# -;;; Commentary: - -;;; This is the famous Hello-World-program, written for Guile. It is a -;;; little bit enhanced in that it understands the command line options -;;; `--help' (-h) and `--version' (-v), which print a short usage -;;; decription or version information, respectively. - -;;; Author: Martin Grabmueller -;;; Date: 2001-05-29 - -;;; Code: - -(use-modules (ice-9 getopt-long)) - -;; This is the grammar for the command line synopsis we expect. -;; -(define command-synopsis - '((version (single-char #\v) (value #f)) - (help (single-char #\h) (value #f)))) - -;; Display version information. -;; -(define (display-version) - (display "hello 0.0.1\n")) - -;; Display the usage help message. -;; -(define (display-help) - (display "Usage: hello [options...]\n") - (display " --help, -h Show this usage information\n") - (display " --version, -v Show version information\n")) - -;; Interpret options, if --help or --version was given, print out the -;; requested information and exit. Otherwise, print the famous -;; message. -;; -(define (main options) - (let ((help-wanted (option-ref options 'help #f)) - (version-wanted (option-ref options 'version #f))) - (if (or version-wanted help-wanted) - (begin - (if version-wanted - (display-version)) - (if help-wanted - (display-help))) - (begin - (display "Hello, World!") (newline))))) - -;; Call the main program with parsed command line options. -;; -(main (getopt-long (command-line) command-synopsis)) - -;; Local variables: -;; mode: scheme -;; End: diff --git a/examples/scripts/simple-hello.scm b/examples/scripts/simple-hello.scm deleted file mode 100644 index b46bc36ff..000000000 --- a/examples/scripts/simple-hello.scm +++ /dev/null @@ -1,16 +0,0 @@ -;;; Commentary: - -;;; This is the famous Hello-World-program, written for Guile. -;;; -;;; For an advanced version, see the script `hello' in the same -;;; directory. - -;;; Author: Martin Grabmueller -;;; Date: 2001-05-29 - -;;; Code: - -(display "Hello, World!") -(newline) - -;;; End of file. |