source: mainline/uspace/app/bdsh/cmds/mod_cmds.c@ 47b2d7e3

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 47b2d7e3 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * Copyright (c) 2008 Tim Post
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/* NOTES:
30 * module_* functions are pretty much identical to builtin_* functions at this
31 * point. On the surface, it would appear that making each function dual purpose
32 * would be economical.
33 *
34 * These are kept separate because the structures (module_t and builtin_t) may
35 * grow apart and become rather different, even though they're identical at this
36 * point.
37 *
38 * To keep things easy to hack, everything is separated. In reality this only adds
39 * 6 - 8 extra functions, but keeps each function very easy to read and modify. */
40
41/* TODO:
42 * Many of these could be unsigned, provided the modules and builtins themselves
43 * can follow suit. Long term goal. */
44
45#include <stdio.h>
46#include <stdlib.h>
47#include <stddef.h>
48#include <str.h>
49#include "errors.h"
50#include "cmds.h"
51#include "module_aliases.h"
52
53extern volatile unsigned int cli_interactive;
54
55/* Checks if an entry function matching command exists in modules[], if so
56 * its position in the array is returned */
57int is_module(const char *command)
58{
59 module_t *mod;
60 unsigned int i = 0;
61
62 if (NULL == command)
63 return -2;
64
65 for (mod = modules; mod->name != NULL; mod++, i++) {
66 if (!str_cmp(mod->name, command))
67 return i;
68 }
69
70 return -1;
71}
72
73/* Checks if a module is an alias (sharing an entry point with another
74 * module). Returns 1 if so */
75int is_module_alias(const char *command)
76{
77 unsigned int i = 0;
78
79 if (NULL == command)
80 return -1;
81
82 for(i=0; mod_aliases[i] != NULL; i+=2) {
83 if (!str_cmp(mod_aliases[i], command))
84 return 1;
85 }
86
87 return 0;
88}
89
90/* Returns the name of the module that an alias points to */
91char *alias_for_module(const char *command)
92{
93 unsigned int i = 0;
94
95 if (NULL == command)
96 return (char *)NULL;
97
98 for(i=0; mod_aliases[i] != NULL; i+=2) {
99 if (!str_cmp(mod_aliases[i], command))
100 return (char *)mod_aliases[i+1];
101 }
102
103 return (char *)NULL;
104}
105
106
107/* Invokes the 'help' entry function for the module at position (int) module,
108 * which wants an unsigned int to determine brief or extended display. */
109int help_module(int module, unsigned int extended)
110{
111 module_t *mod = modules;
112
113 mod += module;
114
115 if (NULL != mod->help) {
116 mod->help(extended);
117 return CL_EOK;
118 } else {
119 return CL_ENOENT;
120 }
121}
122
123/* Invokes the module entry point modules[module], passing argv[] as an argument
124 * stack. */
125int run_module(int module, char *argv[], iostate_t *new_iostate)
126{
127 int rc;
128 module_t *mod = modules;
129
130 mod += module;
131
132 iostate_t *old_iostate = get_iostate();
133 set_iostate(new_iostate);
134
135 if (NULL != mod->entry) {
136 rc = ((int)mod->entry(argv));
137 } else {
138 rc = CL_ENOENT;
139 }
140
141 set_iostate(old_iostate);
142
143 return rc;
144}
Note: See TracBrowser for help on using the repository browser.