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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8d2dd7f2 was 582a0b8, checked in by Jakub Jermar <jakub@…>, 8 years ago

Remove unistd.h

  • Rename usleep() and sleep() to thread_usleep() and thread_sleep() and move to thread.[hc].
  • Include stddef.h in order to provide NULL.
  • Move getpagesize() to libposix.
  • Sync uspace/dist/src/c/demos with originals.
  • Property mode set to 100644
File size: 3.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/* 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>
34#include <stddef.h>
35#include <str.h>
36#include "errors.h"
37#include "cmds.h"
38#include "builtin_aliases.h"
39#include "scli.h"
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++) {
52 if (!str_cmp(cmd->name, command))
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) {
67 if (!str_cmp(builtin_aliases[i], command))
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
81 for(i=0; builtin_aliases[i] != NULL; i++) {
82 if (!str_cmp(builtin_aliases[i], command))
83 return (char *)builtin_aliases[++i];
84 i++;
85 }
86
87 return (char *)NULL;
88}
89
90int help_builtin(int builtin, unsigned int extended)
91{
92 builtin_t *cmd = builtins;
93
94 cmd += builtin;
95
96 if (NULL != cmd->help) {
97 cmd->help(extended);
98 return CL_EOK;
99 } else {
100 return CL_ENOENT;
101 }
102}
103
104int run_builtin(int builtin, char *argv[], cliuser_t *usr, iostate_t *new_iostate)
105{
106 int rc;
107 builtin_t *cmd = builtins;
108
109 cmd += builtin;
110
111 iostate_t *old_iostate = get_iostate();
112 set_iostate(new_iostate);
113
114 if (NULL != cmd->entry) {
115 rc = ((int)cmd->entry(argv, usr));
116 } else {
117 rc = CL_ENOENT;
118 }
119
120 set_iostate(old_iostate);
121
122 return rc;
123}
Note: See TracBrowser for help on using the repository browser.