Subversion Repositories HelenOS

Rev

Rev 3397 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3397 Rev 3492
Line 55... Line 55...
55
return a value. Help entry points are void *, no return value is expected.
55
return a value. Help entry points are void *, no return value is expected.
56
 
56
 
57
They are typed as such (from cmds.h):
57
They are typed as such (from cmds.h):
58
 
58
 
59
/* Types for module command entry and help */
59
/* Types for module command entry and help */
60
typedef int * (* mod_entry_t)(char **);
60
typedef int (* mod_entry_t)(char **);
61
typedef void * (* mod_help_t)(unsigned int);
61
typedef void (* mod_help_t)(unsigned int);
62
 
62
 
63
/* Built-in commands need to be able to modify cliuser_t */
63
/* Built-in commands need to be able to modify cliuser_t */
64
typedef int * (* builtin_entry_t)(char **, cliuser_t *);
64
typedef int (* builtin_entry_t)(char **, cliuser_t *);
65
typedef void * (* builtin_help_t)(unsigned int);
65
typedef void (* builtin_help_t)(unsigned int);
66
 
66
 
67
As you can see, both modular and builtin commands expect an array of
67
As you can see, both modular and builtin commands expect an array of
68
arguments, however bulitins also expect to be pointed to cliuser_t.
68
arguments, however bulitins also expect to be pointed to cliuser_t.
69
 
69
 
70
Both are defined with the same simple structure:
70
Both are defined with the same simple structure:
Line 151... Line 151...
151
 
151
 
152
1: Use mknewcmd to generate the skeletal files.
152
1: Use mknewcmd to generate the skeletal files.
153
 
153
 
154
2: Change your "usage()" command as shown:
154
2: Change your "usage()" command as shown:
155
     -- void usage(...)
155
     -- void usage(...)
156
     ++ void * help_cmd_foo(unsigned int level)
156
     ++ void help_cmd_foo(unsigned int level)
157
     -- return;
-
 
158
     ++ retrn CMD_VOID;
-
 
159
 
157
 
160
     'level' is either 0 or 1, indicating the level of help requested.
158
     'level' is either 0 or 1, indicating the level of help requested.
161
     If the help / usage function currently exits based on how it is
159
     If the help / usage function currently exits based on how it is
162
     called, you'll need to change it.
160
     called, you'll need to change it.
163
 
161
 
164
3: Change the programs "main()" as shown:
162
3: Change the programs "main()" as shown:
165
     -- int main(int argc, char **argv)
163
     -- int main(int argc, char **argv)
166
     ++ int * cmd_foo(char **argv)
164
     ++ int cmd_foo(char **argv)
167
     -- return 1;
165
     -- return 1;
168
     ++ return CMD_FAILURE;
166
     ++ return CMD_FAILURE;
169
     -- return 0;
167
     -- return 0;
170
     ++ return CMD_SUCCESS;
168
     ++ return CMD_SUCCESS;
171
 
169
 
172
     If main() returns an int that is not 1 or 0 (e.g. 127), cast it as
-
 
173
     such:
-
 
174
 
-
 
175
     -- return 127;
-
 
176
     ++ return (int *) 127;
-
 
177
 
-
 
178
     NOTE: _ONLY_ the main and help entry points need to return int * or
-
 
179
     void *, respectively. Also take note that argc has changed. The type
-
 
180
     for entry points may soon change.
-
 
181
 
-
 
182
     NOTE: If main is void, you'll need to change it and ensure that its
170
     NOTE: If main is void, you'll need to change it and ensure that its
183
     expecting an array of arguments, even if they'll never be read or
171
     expecting an array of arguments, even if they'll never be read or
184
     used. I.e.:
172
     used. I.e.:
185
 
173
 
186
     -- void main(void)
174
     -- void main(void)
187
     ++ int * cmd_foo(char **argv)
175
     ++ int cmd_foo(char **argv)
188
 
-
 
189
     Similararly, do not try to return CMD_VOID within the modules main
-
 
190
     entry point. If somehow you escape the compiler yelling at you, you
-
 
191
     will surely see pretty blue and yellow fireworks once its reached.
-
 
192
 
176
 
193
4: Don't expose more than the entry and help points:
177
4: Don't expose more than the entry and help points:
194
     -- void my_function(int n)
178
     -- void my_function(int n)
195
     ++ static void my_function(int n)
179
     ++ static void my_function(int n)
196
 
180