init version.
[bush.git] / examples / loadables / hello.c
blobb0d595ebc27a58b1ce022dd8eb05720eaf86304d
1 /* Sample builtin to be dynamically loaded with enable -f and create a new
2 builtin. */
4 /* See Makefile for compilation details. */
6 /*
7 Copyright (C) 1999-2009 Free Software Foundation, Inc.
9 This file is part of GNU Bush.
10 Bush is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
15 Bush is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with Bush. If not, see <http://www.gnu.org/licenses/>.
24 #include <config.h>
26 #if defined (HAVE_UNISTD_H)
27 # include <unistd.h>
28 #endif
30 #include <stdio.h>
32 #include "loadables.h"
34 /* A builtin `xxx' is normally implemented with an `xxx_builtin' function.
35 If you're converting a command that uses the normal Unix argc/argv
36 calling convention, use argv = make_builtin_argv (list, &argc) and call
37 the original `main' something like `xxx_main'. Look at cat.c for an
38 example.
40 Builtins should use internal_getopt to parse options. It is the same as
41 getopt(3), but it takes a WORD_LIST *. Look at print.c for an example
42 of its use.
44 If the builtin takes no options, call no_options(list) before doing
45 anything else. If it returns a non-zero value, your builtin should
46 immediately return EX_USAGE. Look at logname.c for an example.
48 A builtin command returns EXECUTION_SUCCESS for success and
49 EXECUTION_FAILURE to indicate failure. */
50 int
51 hello_builtin (list)
52 WORD_LIST *list;
54 printf("hello world\n");
55 fflush (stdout);
56 return (EXECUTION_SUCCESS);
59 int
60 hello_builtin_load (s)
61 char *s;
63 printf ("hello builtin loaded\n");
64 fflush (stdout);
65 return (1);
68 void
69 hello_builtin_unload (s)
70 char *s;
72 printf ("hello builtin unloaded\n");
73 fflush (stdout);
76 /* An array of strings forming the `long' documentation for a builtin xxx,
77 which is printed by `help xxx'. It must end with a NULL. By convention,
78 the first line is a short description. */
79 char *hello_doc[] = {
80 "Sample builtin.",
81 "",
82 "this is the long doc for the sample hello builtin",
83 (char *)NULL
86 /* The standard structure describing a builtin command. bush keeps an array
87 of these structures. The flags must include BUILTIN_ENABLED so the
88 builtin can be used. */
89 struct builtin hello_struct = {
90 "hello", /* builtin name */
91 hello_builtin, /* function implementing the builtin */
92 BUILTIN_ENABLED, /* initial flags for builtin */
93 hello_doc, /* array of long documentation strings. */
94 "hello", /* usage synopsis; becomes short_doc */
95 0 /* reserved for internal use */