1 | /* $Id: kShellMain.c 18 2002-10-17 21:25:33Z bird $
|
---|
2 | *
|
---|
3 | * kShell - Mainprogram (intented for testing)
|
---|
4 | *
|
---|
5 | * Copyright (c) 2002 knut st. osmundsen <[email protected]>
|
---|
6 | *
|
---|
7 | *
|
---|
8 | * This file is part of kBuild.
|
---|
9 | *
|
---|
10 | * kBuild is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU Lesser General Public License as published
|
---|
12 | * by the Free Software Foundation; either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * kBuild is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU Lesser General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU Lesser General Public License
|
---|
21 | * along with kBuild; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
23 | *
|
---|
24 | */
|
---|
25 |
|
---|
26 |
|
---|
27 | /*******************************************************************************
|
---|
28 | * Header Files *
|
---|
29 | *******************************************************************************/
|
---|
30 | #include "kShell.h"
|
---|
31 | #include <string.h>
|
---|
32 | #include <stdio.h>
|
---|
33 |
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Simple main program which will execute any arguments or
|
---|
37 | * start in interactive mode if no parameters.
|
---|
38 | */
|
---|
39 | int main(int argc, char **argv)
|
---|
40 | {
|
---|
41 | static char szCmd[4096];
|
---|
42 | int argi;
|
---|
43 | int rc;
|
---|
44 |
|
---|
45 | /*
|
---|
46 | * init the shell.
|
---|
47 | */
|
---|
48 | rc = kshellInit(1);
|
---|
49 | if (rc)
|
---|
50 | return rc;
|
---|
51 |
|
---|
52 |
|
---|
53 | /*
|
---|
54 | * If any arguments we'll execute them as a command.
|
---|
55 | */
|
---|
56 | if (argc > 1)
|
---|
57 | {
|
---|
58 | for (argi = 2, strcpy(&szCmd[0], argv[1]); argi < argc; argi++)
|
---|
59 | strcat(strcat(&szCmd[0], " "), argv[argi]);
|
---|
60 | rc = kshellExecute(szCmd);
|
---|
61 | }
|
---|
62 |
|
---|
63 | /*
|
---|
64 | * Interactive mode.
|
---|
65 | */
|
---|
66 | else
|
---|
67 | {
|
---|
68 | while (fgets(&szCmd[0], sizeof(szCmd), stdin))
|
---|
69 | {
|
---|
70 | char *pszEnd = &szCmd[strlen(&szCmd[0]) - 1];
|
---|
71 | while (pszEnd >= &szCmd[0] && (*pszEnd == '\n' || *pszEnd == '\r'))
|
---|
72 | *pszEnd-- = '\0';
|
---|
73 |
|
---|
74 | if (!strcmp(&szCmd[0], "exit"))
|
---|
75 | break;
|
---|
76 |
|
---|
77 | rc = kshellExecute(&szCmd[0]);
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|
82 | /*
|
---|
83 | * Terminate the shell and exit.
|
---|
84 | */
|
---|
85 | kshellTerm();
|
---|
86 |
|
---|
87 | return rc;
|
---|
88 | }
|
---|