source: mainline/uspace/app/bdsh/scli.c@ 3f932a7e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3f932a7e 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.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/* Globals that are modified during start-up that modules/builtins
46 * should be aware of. */
47volatile unsigned int cli_quit = 0;
48volatile unsigned int cli_verbocity = 1;
49
50/* The official name of this program
51 * (change to your liking in configure.ac and re-run autoconf) */
52const char *progname = PACKAGE_NAME;
53
54/* These are not exposed, even to builtins */
55static int cli_init(cliuser_t *);
56static void cli_finit(cliuser_t *);
57
58/* Constructor */
59static int cli_init(cliuser_t *usr)
60{
61 usr->line = (char *) NULL;
62 usr->name = "root";
63 usr->cwd = (char *) NULL;
64 usr->prompt = (char *) NULL;
65 usr->lasterr = 0;
66
67 if (input_init() != 0)
68 return 1;
69
70 return (int) cli_set_prompt(usr);
71}
72
73/* Destructor */
74static void cli_finit(cliuser_t *usr)
75{
76 if (NULL != usr->line)
77 free(usr->line);
78 if (NULL != usr->prompt)
79 free(usr->prompt);
80 if (NULL != usr->cwd)
81 free(usr->cwd);
82}
83
84iostate_t *get_iostate(void)
85{
86 return iostate;
87}
88
89
90void set_iostate(iostate_t *ios)
91{
92 iostate = ios;
93 stdin = ios->stdin;
94 stdout = ios->stdout;
95 stderr = ios->stderr;
96}
97
98int main(int argc, char *argv[])
99{
100 errno_t ret = 0;
101
102 stdiostate.stdin = stdin;
103 stdiostate.stdout = stdout;
104 stdiostate.stderr = stderr;
105 iostate = &stdiostate;
106
107 if (cli_init(&usr))
108 exit(EXIT_FAILURE);
109
110 while (!cli_quit) {
111 get_input(&usr);
112 if (NULL != usr.line) {
113 ret = process_input(&usr);
114 cli_set_prompt(&usr);
115 usr.lasterr = ret;
116 }
117 }
118
119 printf("Leaving %s.\n", progname);
120
121 cli_finit(&usr);
122 return ret;
123}
Note: See TracBrowser for help on using the repository browser.