source: mainline/uspace/app/bdsh/scli.c@ 59cce22

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 59cce22 was 09ab0a9a, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Fix vertical spacing with new Ccheck revision.

  • Property mode set to 100644
File size: 3.2 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#include <stdio.h>
30#include <stdlib.h>
31#include <stddef.h>
32#include <str.h>
33#include "config.h"
34#include "scli.h"
35#include "input.h"
36#include "util.h"
37#include "errors.h"
38#include "cmds/cmds.h"
39
40/* See scli.h */
41static cliuser_t usr;
42static iostate_t *iostate;
43static iostate_t stdiostate;
44
45/*
46 * Globals that are modified during start-up that modules/builtins
47 * should be aware of.
48 */
49volatile unsigned int cli_quit = 0;
50volatile unsigned int cli_verbocity = 1;
51
52/*
53 * The official name of this program
54 * (change to your liking in configure.ac and re-run autoconf)
55 */
56const char *progname = PACKAGE_NAME;
57
58/* These are not exposed, even to builtins */
59static int cli_init(cliuser_t *);
60static void cli_finit(cliuser_t *);
61
62/* Constructor */
63static int cli_init(cliuser_t *usr)
64{
65 usr->line = (char *) NULL;
66 usr->name = "root";
67 usr->cwd = (char *) NULL;
68 usr->prompt = (char *) NULL;
69 usr->lasterr = 0;
70
71 if (input_init() != 0)
72 return 1;
73
74 return (int) cli_set_prompt(usr);
75}
76
77/* Destructor */
78static void cli_finit(cliuser_t *usr)
79{
80 if (NULL != usr->line)
81 free(usr->line);
82 if (NULL != usr->prompt)
83 free(usr->prompt);
84 if (NULL != usr->cwd)
85 free(usr->cwd);
86}
87
88iostate_t *get_iostate(void)
89{
90 return iostate;
91}
92
93void set_iostate(iostate_t *ios)
94{
95 iostate = ios;
96 stdin = ios->stdin;
97 stdout = ios->stdout;
98 stderr = ios->stderr;
99}
100
101int main(int argc, char *argv[])
102{
103 errno_t ret = 0;
104
105 stdiostate.stdin = stdin;
106 stdiostate.stdout = stdout;
107 stdiostate.stderr = stderr;
108 iostate = &stdiostate;
109
110 if (cli_init(&usr))
111 exit(EXIT_FAILURE);
112
113 while (!cli_quit) {
114 get_input(&usr);
115 if (NULL != usr.line) {
116 ret = process_input(&usr);
117 cli_set_prompt(&usr);
118 usr.lasterr = ret;
119 }
120 }
121
122 printf("Leaving %s.\n", progname);
123
124 cli_finit(&usr);
125 return ret;
126}
Note: See TracBrowser for help on using the repository browser.