annotate modules/sample/external/sample.c @ 3147:971e3c687f18

[xemacs-hg @ 2005-12-18 12:21:49 by malcolmp] Improvements to configure's complex option processing.
author malcolmp
date Sun, 18 Dec 2005 12:22:03 +0000
parents 25e260cb7994
children dce479915b74
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
996
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
1 /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
2 * Very simple sample module. Illustrates most of the salient features
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
3 * of Emacs dynamic modules.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
4 * (C) Copyright 1998, 1999 J. Kean Johnston. All rights reserved.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
5 * (C) Copyright 2002 Jerry James.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
6 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
7
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
8 #include <config.h>
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
9 #include "lisp.h"
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
10
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
11 /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
12 * This sample introduces three new Lisp objects to the Lisp reader.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
13 * The first, a simple boolean value, and the second a string. The
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
14 * Third is a sample function that simply prints a message.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
15 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
16 int sample_bool;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
17 Lisp_Object Vsample_string;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
18
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
19 DEFUN ("sample-function", Fsample_function, 0, 0, "", /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
20 This is a sample function loaded dynamically.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
21
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
22 You will notice in the source code for this module that the
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
23 declaration is identical to internal Emacs functions. This
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
24 makes it possible to use the exact same code in a dumped
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
25 version of Emacs.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
26 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
27 ())
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
28 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
29 message ("Eureka! It worked");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
30 return Qt;
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
31 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
32
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
33 /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
34 * Each dynamically loaded Emacs module is given a name at compile
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
35 * time. This is a short name, and must be a valid part of a C
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
36 * identifier. This name is used to construct the name of several
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
37 * functions which must appear in the module source code.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
38 * The first such function, modules_of_XXXX, should load in any dependent
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
39 * modules. This function is optional, and the module will still load if
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
40 * it is not present in the module.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
41 *
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
42 * The second function, which is NOT optional, is syms_of_XXXX, in which
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
43 * all functions that the module will be provided are declared. This
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
44 * function will contain calls to DEFSUBR().
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
45 *
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
46 * The third function, which is also NOT optional, is vars_of_XXXX, in
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
47 * which you declare all variables that the module provides. This
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
48 * function will contain calls to DEFVAR_LISP(), DEFVAR_BOOL() etc.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
49 *
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
50 * When declaring functions and variables in the syms_of_XXXX and
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
51 * vars_of_XXXX functions, you use the exact same syntax that you
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
52 * would as if this module were being compiled into the pure Emacs.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
53 *
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
54 * The fourth function, which is optional, is unload_XXXX, in which actions
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
55 * that must be taken to unload the module are listed. XEmacs will unbind
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
56 * functions and variables for you. Anything else that must be done should
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
57 * appear in this function.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
58 *
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
59 * All four of these functions are declared as void functions,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
60 * taking no parameters. Since this sample module is called 'sample',
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
61 * the functions will be named 'modules_of_sample', 'syms_of_sample',
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
62 * 'vars_of_sample', and 'unload_sample'.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
63 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
64
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
65 void
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
66 modules_of_sample()
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
67 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
68 /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
69 * This function isn't actually required as we will not be loading
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
70 * in any dependent modules, but if we were, we would do something like:
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
71 * emodules_load ("dependent.ell", "sample2", "1.0.0");
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
72 */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
73 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
74
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
75 void
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
76 syms_of_sample()
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
77 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
78 DEFSUBR(Fsample_function);
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
79 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
80
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
81 void
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
82 vars_of_sample()
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
83 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
84 DEFVAR_LISP ("sample-string", &Vsample_string /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
85 This is a sample string, declared in a dynamic module.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
86
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
87 The syntax and conventions used for all normal Emacs variables
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
88 apply equally to modules, using an identical syntax.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
89 */ );
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
90
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
91 DEFVAR_BOOL ("sample-boolean", &sample_bool /*
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
92 *Sample boolean value, in a dynamic module.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
93
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
94 This is a user-settable variable, as indicated by the *
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
95 as the first character of the description. Declared in
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
96 a module exactly as it would be internally in Emacs.
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
97 */ );
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
98 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
99
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
100 #ifdef HAVE_SHLIB
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
101 void
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
102 unload_sample()
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
103 {
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
104 /* We don't need to do anything here in the sample case. However, if you
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
105 create any new types with INIT_LRECORD_IMPLEMENTATION (sample_type), then
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
106 UNDEF_LRECORD_IMPLEMENTATION (sample_type) must appear here. Also, any
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
107 symbols declared with DEFSYMBOL (Qsample_var), or one of its variants,
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
108 must have a corresponding unstaticpro_nodump (&Qsample_var) here. */
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
109 }
25e260cb7994 [xemacs-hg @ 2002-09-10 15:27:02 by james]
james
parents:
diff changeset
110 #endif