-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFNAME.c.template
116 lines (97 loc) · 2.91 KB
/
FNAME.c.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// -*- mode:c -*-
/***
* Todo:
* - Update `FNAME()` function, delete or fill out as needed
* - Add detailed instructions to desc_FNAME string array.
* - Compose more helpful .short_doc string
* - Finally, replace-string <FNAME> with your builtin function's name.
***/
#include <builtins.h>
// Prevent multiple inclusion of shell.h:
#ifndef EXECUTION_FAILURE
#include <shell.h>
#endif
#include <builtins/bashgetopt.h> // for internal_getopt(), etc
#include <builtins/common.h> // for no_options()
static int <FNAME>_builtin(WORD_LIST *list)
{
/************************************
* Start of OPTIONS section
*
* Delete if not needed:
* Remove until code until
* 'End of OPTIONS section'
* below
***********************************/
// Show usage if no options are set
if (no_options(list))
return EX_USAGE;
reset_internal_getopt();
// Process options, pick off, as options, arguments
// formed -X where x is any single letter, and "abc"
// second parameter of `internal_getopt` is the list
// of available option letters:
int opt;
while (-1 != (opt = internal_getopt(list, "abc:")))
{
switch(opt)
{
case 'a': break;
case 'b': break;
case 'c':
// The option value, when the letter is followed by a ':'
// as in 'c:' in call to `internal_getopt` above, is
// found in the the `list_optarg` variable when the
// letter is matched.
break;
default: do_stuff(); break;
}
}
// ONLY IF USING `internal_getopt`, reset the list
// to process any remaining non-option arguments:
list = loptend;
/************************************
* End of OPTIONS section
***********************************/
/************************************
* Start of ARGUMENTS section
***********************************/
WORD_LIST *ptr = list;
while (ptr)
{
// Process the option
ptr = ptr->next;
}
/************************************
* End of ARGUMENTS section
***********************************/
return EXECUTION_SUCCESS;
}
static char *desc_<FNAME>[] = {
"First of several lines providing comprehensive help.",
(char*)NULL // end of array marker
};
struct builtin <FNAME>_struct = {
.name = "<FNAME>",
.function = <FNAME>_builtin,
.flags = BUILTIN_ENABLED,
.long_doc = desc_<FNAME>,
.short_doc = "<FNAME> is cool",
.handle = 0
};
// Opportunity to modfy <FNAME>_struct members (or any other
// global variable or setting) before releasing
// the builtin for use.
//
// In particular, this has been used to generate a .long_doc
// array from code in the builtin executable.
int <FNAME>_builtin_load(char *name)
{
return 1;
}
// If <FBNAME>_builtin_load() allocated heap memory, this is
// the opportunity to free it.
void <FNAME>_builtin_unload(char *name)
{
;
}