[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 01/03: doc: Move examples to the 'doc/examples' directory.
From: |
Mathieu Lirzin |
Subject: |
[shepherd] 01/03: doc: Move examples to the 'doc/examples' directory. |
Date: |
Wed, 27 Jan 2016 23:47:47 +0000 |
mthl pushed a commit to branch master
in repository shepherd.
commit 55a6d8122d3aed8a0af28f2d65ab4a84fd96ad47
Author: Mathieu Lirzin <address@hidden>
Date: Wed Jan 27 18:45:37 2016 +0100
doc: Move examples to the 'doc/examples' directory.
* doc/examples/README: moved from 'examples' directory.
* doc/examples/_unknown.scm: Likewise.
* doc/examples/wolfgangj.scm: Likewise.
* shepherd.texi (Jump Start): Adapt a reference to those examples.
* examples/Makefile.am: Delete file.
* configure.ac (AC_CONFIG_FILES): Adapt to it.
* Makefile.am (EXTRA_DIST): Add files from "doc/examples" directory.
(SUBDIRS): Delete variable.
---
Makefile.am | 10 ++-
configure.ac | 3 +-
{examples => doc/examples}/README | 0
doc/examples/_unknown.scm | 153 ++++++++++++++++++++++++++++++
{examples => doc/examples}/wolfgangj.scm | 52 +++++-----
examples/Makefile.am | 3 -
examples/_unknown.scm | 153 ------------------------------
shepherd.texi | 2 +-
8 files changed, 189 insertions(+), 187 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index cf9a691..a7c73c1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -63,7 +63,6 @@ CLEANFILES = \
# Documentation.
info_TEXINFOS = shepherd.texi
-SUBDIRS = examples
AM_V_HELP2MAN = $(AM_V_HELP2MAN_$(V))
AM_V_HELP2MAN_ = $(AM_V_HELP2MAN_$(AM_DEFAULT_VERBOSITY))
@@ -93,7 +92,14 @@ dist_man1_MANS = shepherd.1 herd.1
dist_man8_MANS = halt.8 reboot.8
# Things not automatically included in the distribution.
-EXTRA_DIST = $(templates) QUESTIONS fdl-1.3.texi ChangeLog-2003
+EXTRA_DIST = \
+ ChangeLog-2003 \
+ fdl-1.3.texi \
+ QUESTIONS \
+ $(templates) \
+ doc/examples/README \
+ doc/examples/_unknown.scm \
+ doc/examples/wolfgangj.scm
# Create the socket directory (aka. 'default-socket-dir'.) Make it
# accessible only by its owner since otherwise 'shepherd' suggests using
diff --git a/configure.ac b/configure.ac
index 339167c..abab3fa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -94,7 +94,6 @@ AM_MISSING_PROG([HELP2MAN], [help2man])
dnl Finish.
AC_CONFIG_FILES([Makefile
- examples/Makefile
- modules/shepherd/system.scm])
+ modules/shepherd/system.scm])
AC_OUTPUT
diff --git a/examples/README b/doc/examples/README
similarity index 100%
rename from examples/README
rename to doc/examples/README
diff --git a/doc/examples/_unknown.scm b/doc/examples/_unknown.scm
new file mode 100644
index 0000000..fb639ab
--- /dev/null
+++ b/doc/examples/_unknown.scm
@@ -0,0 +1,153 @@
+;; _unknown.scm -- An example for an `unknown' service.
+;; Copyright (C) 2003 Wolfgang J�hrling <address@hidden>
+;;
+;; This file is part of the GNU Shepherd.
+;;
+;; The GNU Shepherd 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.
+;;
+;; The GNU Shepherd 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 the GNU Shepherd. If not, see <http://www.gnu.org/licenses/>.
+
+;; Return true if STR1 lacks a character that exists in STR2, but
+;; otherwise both are identical.
+(define (lacks-char-from? str1 str2)
+ (and (= (string-length str1)
+ (+ (string-length str2) 1))
+ (letrec ((next
+ (lambda (pos)
+ (and (not (= pos (string-length str1)))
+ (or (string=? str2
+ (string-append
+ (substring str1 0 pos)
+ (substring str1
+ (+ pos 1)
+ (string-length str1))))
+ (next (+ pos 1)))))))
+ (next 0))))
+
+;; Return true if either of STR1 and STR2 lacks a character found in
+;; the other one, but otherwise both are identical (e.g. as is the
+;; case for "blah" and "bla").
+(define (differs-by-missing-char? str1 str2)
+ (or (lacks-char-from? str1 str2)
+ (lacks-char-from? str2 str1)))
+
+;; Return true if the only difference between STR1 and STR2 is that a
+;; successive pair of characters is switched in one of them.
+(define (differs-by-switched-chars? str1 str2)
+ (and (= (string-length str1)
+ (string-length str2))
+ (> (string-length str1) 1)
+ (letrec ((next
+ (lambda (pos)
+ (and (not (= pos (string-length str1)))
+ (or (string=? str2
+ (string-append
+ (substring str1 0 (- pos 1))
+ (string (string-ref str1 pos)
+ (string-ref str1 (- pos 1)))
+ (substring str1
+ (+ pos 1)
+ (string-length str1))))
+ (next (+ pos 1)))))))
+ (next 1))))
+
+;; Return true if they differ by exactly one character (e.g. as is the
+;; case for "blah" and "bleh"), if it isn't the only one.
+(define (differs-by-one-char? str1 str2)
+ (and (= (string-length str1)
+ (string-length str2))
+ (> (string-length str1) 1)
+ (letrec ((next
+ (lambda (pos found-difference)
+ (if (= pos (string-length str1))
+ found-difference
+ (if (char=? (string-ref str1 pos)
+ (string-ref str2 pos))
+ (next (+ pos 1) found-difference)
+ (and (not found-difference)
+ (next (+ pos 1) #t)))))))
+ (next 0 #f))))
+
+;; Return true if STR1 and STR2 are identical, except for case
+;; (e.g. this gives true for "foobar" and "FooBAR").
+(define (differs-only-in-case? str1 str2)
+ (and (not (string=? str1 str2))
+ (string-ci=? str1 str2)))
+
+;; Return true if STR1 and STR2 are `similar' strings, meaning that
+;; they only differ in a minor way.
+(define (similar? str1 str2)
+ (any (lambda (pred?)
+ (pred? str1 str2))
+ (list differs-by-missing-char?
+ differs-by-switched-chars?
+ differs-by-one-char?
+ differs-only-in-case?)))
+
+
+
+;; TODO
+;; - We could look for non-running services first on `start' etc.
+;; - We also should do `unknown-action' (if service is known)
+;; - If doing this, we should enable the service to handle it
+;; - Make this the `default unknown service'
+;; - Messages if nothing found.
+
+;; Suggest a service that satisfies PRED?, if given, and has a name
+;; similar to SERVICE-SYMBOL.
+(define look-for-service
+ (case-lambda
+ ((service-symbol) (look-for-service service-symbol (lambda (x) #t)))
+ ((service-symbol pred?)
+ (call/ec
+ (lambda (return)
+ (for-each-service
+ (lambda (s)
+ (and (pred? s)
+ (similar? (symbol->string service-symbol)
+ (symbol->string (canonical-name s)))
+ (begin
+ (format #t "Did you mean ~a maybe?" (canonical-name s))
+ (newline)
+ (return #t)))))
+ #f)))))
+
+;; The classical compose.
+(define (compose f g)
+ (lambda (x)
+ (f (g x)))
+
+ (define unknown-service
+ (make <service>
+ #:provides '(unknown)
+ #:actions (make-actions
+ (start
+ "Called if user wants to start an unknown service."
+ (lambda (running service-sym . args)
+ (or (look-for-service service-sym (compose not running?))
+ (look-for-service service-sym))
+ running))
+ (stop
+ "Called if user wants to stop an unknown service."
+ (lambda (running service-sym . args)
+ (or (look-for-service service-sym running?)
+ (look-for-service service-sym))
+ running))
+ (action
+ "Called if user frobs an unknown service."
+ (lambda (running service-sym the-action . args)
+ (or (look-for-service service-sym running?)
+ (look-for-service service-sym))
+ running)))))
+
+ (register-services unknown-service)
+ (start unknown-service)
diff --git a/examples/wolfgangj.scm b/doc/examples/wolfgangj.scm
similarity index 74%
rename from examples/wolfgangj.scm
rename to doc/examples/wolfgangj.scm
index b01ddd0..0c16108 100644
--- a/examples/wolfgangj.scm
+++ b/doc/examples/wolfgangj.scm
@@ -75,16 +75,16 @@
(make <service>
#:provides '(term)
#:actions (make-actions
- (create "Create a new terminal."
- (lambda (running)
- (add-new-term)))
- (counter-set "Set the terminal creation counter."
- (lambda (running num)
- (set! term-counter (string->number num))))
- (status "Display the terminal creation counter."
- (lambda (running)
- (local-output "Terminal counter is at ~a."
- term-counter)))))
+ (create "Create a new terminal."
+ (lambda (running)
+ (add-new-term)))
+ (counter-set "Set the terminal creation counter."
+ (lambda (running num)
+ (set! term-counter (string->number num))))
+ (status "Display the terminal creation counter."
+ (lambda (running)
+ (local-output "Terminal counter is at ~a."
+ term-counter)))))
(make <service>
#:provides '(apache insecurity)
#:requires '(local-net)
@@ -95,14 +95,14 @@
#:start (make-system-constructor inet " start")
#:stop (make-system-destructor inet " stop")
#:actions (make-actions
- (dial "Connect to the big, evil internet."
- (lambda (running)
- (system inet-dial)
- #t))
- (hangup "Cut the internet connection."
- (lambda (running)
- (system inet-hangup)
- #t))))
+ (dial "Connect to the big, evil internet."
+ (lambda (running)
+ (system inet-dial)
+ #t))
+ (hangup "Cut the internet connection."
+ (lambda (running)
+ (system inet-hangup)
+ #t))))
(make <service>
#:provides '(local-net)
#:start (make-system-constructor ifconfig " " local-interface " " local-ip)
@@ -115,10 +115,10 @@
;; Create a few terminals.
(letrec ((loop (lambda (i)
- (and (not (zero? i))
- (begin
- (add-new-term)
- (loop (- i 1)))))))
+ (and (not (zero? i))
+ (begin
+ (add-new-term)
+ (loop (- i 1)))))))
(loop default-terms))
;; Go into background.
@@ -126,7 +126,7 @@
;; Setup internet, a mailer and a few terms.
(for-each start
- (append '(term inet mailer-daemon)
- (map (lambda (x)
- (symbol-append 'term- (number->symbol x)))
- (iota default-terms 1))))
+ (append '(term inet mailer-daemon)
+ (map (lambda (x)
+ (symbol-append 'term- (number->symbol x)))
+ (iota default-terms 1))))
diff --git a/examples/Makefile.am b/examples/Makefile.am
deleted file mode 100644
index 648b244..0000000
--- a/examples/Makefile.am
+++ /dev/null
@@ -1,3 +0,0 @@
-# examples/Makefile.am -- Add a few examples to the distribution.
-
-EXTRA_DIST = README _unknown.scm wolfgangj.scm
diff --git a/examples/_unknown.scm b/examples/_unknown.scm
deleted file mode 100644
index 9e425df..0000000
--- a/examples/_unknown.scm
+++ /dev/null
@@ -1,153 +0,0 @@
-;; _unknown.scm -- An example for an `unknown' service.
-;; Copyright (C) 2003 Wolfgang J�hrling <address@hidden>
-;;
-;; This file is part of the GNU Shepherd.
-;;
-;; The GNU Shepherd 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.
-;;
-;; The GNU Shepherd 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 the GNU Shepherd. If not, see <http://www.gnu.org/licenses/>.
-
-;; Return true if STR1 lacks a character that exists in STR2, but
-;; otherwise both are identical.
-(define (lacks-char-from? str1 str2)
- (and (= (string-length str1)
- (+ (string-length str2) 1))
- (letrec ((next
- (lambda (pos)
- (and (not (= pos (string-length str1)))
- (or (string=? str2
- (string-append
- (substring str1 0 pos)
- (substring str1
- (+ pos 1)
- (string-length str1))))
- (next (+ pos 1)))))))
- (next 0))))
-
-;; Return true if either of STR1 and STR2 lacks a character found in
-;; the other one, but otherwise both are identical (e.g. as is the
-;; case for "blah" and "bla").
-(define (differs-by-missing-char? str1 str2)
- (or (lacks-char-from? str1 str2)
- (lacks-char-from? str2 str1)))
-
-;; Return true if the only difference between STR1 and STR2 is that a
-;; successive pair of characters is switched in one of them.
-(define (differs-by-switched-chars? str1 str2)
- (and (= (string-length str1)
- (string-length str2))
- (> (string-length str1) 1)
- (letrec ((next
- (lambda (pos)
- (and (not (= pos (string-length str1)))
- (or (string=? str2
- (string-append
- (substring str1 0 (- pos 1))
- (string (string-ref str1 pos)
- (string-ref str1 (- pos 1)))
- (substring str1
- (+ pos 1)
- (string-length str1))))
- (next (+ pos 1)))))))
- (next 1))))
-
-;; Return true if they differ by exactly one character (e.g. as is the
-;; case for "blah" and "bleh"), if it isn't the only one.
-(define (differs-by-one-char? str1 str2)
- (and (= (string-length str1)
- (string-length str2))
- (> (string-length str1) 1)
- (letrec ((next
- (lambda (pos found-difference)
- (if (= pos (string-length str1))
- found-difference
- (if (char=? (string-ref str1 pos)
- (string-ref str2 pos))
- (next (+ pos 1) found-difference)
- (and (not found-difference)
- (next (+ pos 1) #t)))))))
- (next 0 #f))))
-
-;; Return true if STR1 and STR2 are identical, except for case
-;; (e.g. this gives true for "foobar" and "FooBAR").
-(define (differs-only-in-case? str1 str2)
- (and (not (string=? str1 str2))
- (string-ci=? str1 str2)))
-
-;; Return true if STR1 and STR2 are `similar' strings, meaning that
-;; they only differ in a minor way.
-(define (similar? str1 str2)
- (any (lambda (pred?)
- (pred? str1 str2))
- (list differs-by-missing-char?
- differs-by-switched-chars?
- differs-by-one-char?
- differs-only-in-case?)))
-
-
-
-;; TODO
-;; - We could look for non-running services first on `start' etc.
-;; - We also should do `unknown-action' (if service is known)
-;; - If doing this, we should enable the service to handle it
-;; - Make this the `default unknown service'
-;; - Messages if nothing found.
-
-;; Suggest a service that satisfies PRED?, if given, and has a name
-;; similar to SERVICE-SYMBOL.
-(define look-for-service
- (case-lambda
- ((service-symbol) (look-for-service service-symbol (lambda (x) #t)))
- ((service-symbol pred?)
- (call/ec
- (lambda (return)
- (for-each-service
- (lambda (s)
- (and (pred? s)
- (similar? (symbol->string service-symbol)
- (symbol->string (canonical-name s)))
- (begin
- (format #t "Did you mean ~a maybe?" (canonical-name s))
- (newline)
- (return #t)))))
- #f)))))
-
-;; The classical compose.
-(define (compose f g)
- (lambda (x)
- (f (g x)))
-
-(define unknown-service
- (make <service>
- #:provides '(unknown)
- #:actions (make-actions
- (start
- "Called if user wants to start an unknown service."
- (lambda (running service-sym . args)
- (or (look-for-service service-sym (compose not running?))
- (look-for-service service-sym))
- running))
- (stop
- "Called if user wants to stop an unknown service."
- (lambda (running service-sym . args)
- (or (look-for-service service-sym running?)
- (look-for-service service-sym))
- running))
- (action
- "Called if user frobs an unknown service."
- (lambda (running service-sym the-action . args)
- (or (look-for-service service-sym running?)
- (look-for-service service-sym))
- running)))))
-
-(register-services unknown-service)
-(start unknown-service)
diff --git a/shepherd.texi b/shepherd.texi
index 5203af1..edb2039 100644
--- a/shepherd.texi
+++ b/shepherd.texi
@@ -299,7 +299,7 @@ will now take a look at how to configure the Shepherd. In
the configuration
file, we need mainly the definition of services. We can also do
various other things there, like starting a few services already.
-FIXME: Finish. For now, look at the @code{examples/} subdirectory.
+FIXME: Finish. For now, look at the @code{doc/examples/} subdirectory.
@example
...