source: mainline/uspace/app/bdsh/cmds/builtin_cmds.c@ a35b458

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a35b458 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 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: 3.0 KB
RevLine 
[36ab7c7]1/*
2 * Copyright (c) 2008 Tim Post
[216d6fc]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
[36ab7c7]6 * modification, are permitted provided that the following conditions
7 * are met:
[216d6fc]8 *
[36ab7c7]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.
[216d6fc]16 *
[36ab7c7]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.
[216d6fc]27 */
28
29/* Almost identical (for now) to mod_cmds.c , however this will not be the case
30 * soon as builtin_t is going to grow way beyond module_t */
31
32#include <stdio.h>
33#include <stdlib.h>
[582a0b8]34#include <stddef.h>
[19f857a]35#include <str.h>
[216d6fc]36#include "errors.h"
37#include "cmds.h"
38#include "builtin_aliases.h"
[6ea9a1d]39#include "scli.h"
[216d6fc]40
41extern volatile unsigned int cli_interactive;
42
43int is_builtin(const char *command)
44{
45 builtin_t *cmd;
46 unsigned int i = 0;
47
48 if (NULL == command)
49 return -2;
50
51 for (cmd = builtins; cmd->name != NULL; cmd++, i++) {
[92fd52d7]52 if (!str_cmp(cmd->name, command))
[216d6fc]53 return i;
54 }
55
56 return -1;
57}
58
59int is_builtin_alias(const char *command)
60{
61 unsigned int i = 0;
62
63 if (NULL == command)
64 return -1;
65
66 for(i=0; builtin_aliases[i] != NULL; i+=2) {
[92fd52d7]67 if (!str_cmp(builtin_aliases[i], command))
[216d6fc]68 return 1;
69 }
70
71 return 0;
72}
73
74char *alias_for_builtin(const char *command)
75{
76 unsigned int i = 0;
77
78 if (NULL == command)
79 return (char *)NULL;
80
[05b59393]81 for(i=0; builtin_aliases[i] != NULL; i+=2) {
[92fd52d7]82 if (!str_cmp(builtin_aliases[i], command))
[05b59393]83 return (char *)builtin_aliases[i+1];
[216d6fc]84 }
85
86 return (char *)NULL;
87}
88
89int help_builtin(int builtin, unsigned int extended)
90{
91 builtin_t *cmd = builtins;
92
93 cmd += builtin;
94
95 if (NULL != cmd->help) {
96 cmd->help(extended);
97 return CL_EOK;
[b0889d05]98 } else {
[216d6fc]99 return CL_ENOENT;
[b0889d05]100 }
[216d6fc]101}
102
[6ea9a1d]103int run_builtin(int builtin, char *argv[], cliuser_t *usr, iostate_t *new_iostate)
[216d6fc]104{
[6ea9a1d]105 int rc;
[216d6fc]106 builtin_t *cmd = builtins;
107
108 cmd += builtin;
[a35b458]109
[6ea9a1d]110 iostate_t *old_iostate = get_iostate();
111 set_iostate(new_iostate);
[a35b458]112
[6ea9a1d]113 if (NULL != cmd->entry) {
114 rc = ((int)cmd->entry(argv, usr));
[b0889d05]115 } else {
[6ea9a1d]116 rc = CL_ENOENT;
117 }
[a35b458]118
[6ea9a1d]119 set_iostate(old_iostate);
[216d6fc]120
[6ea9a1d]121 return rc;
[216d6fc]122}
Note: See TracBrowser for help on using the repository browser.