Fixed out-by-one error in previous commit.
[AROS.git] / workbench / c / shellcommands / NewShell.c
blob557f164c0f9908960d92e66e84e9d398698b514a
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: NewShell CLI Command
6 Lang: English
7 */
9 /******************************************************************************
12 NAME
14 NewShell
16 SYNOPSIS
18 WINDOW,FROM
20 LOCATION
24 FUNCTION
26 Create a new shell in a new console window. This window will become
27 the active one. The new shell inherits most attributes of the parent
28 shell like the current directory, stack size, prompt and so on.
29 However, it is completely independent of the parent shell.
30 The window belonging to the new shell may be specified by
31 using the WINDOW keyword.
33 INPUTS
35 WINDOW -- Specification of the shell window
37 X -- number of pixels from the left edge of
38 the screen
39 Y -- number of pixels from the top edge of
40 the screen
41 WIDTH -- width of the shell window in pixels
42 HEIGHT -- height of the shell window in pixels
43 TITLE -- text to appear in the shell window's
44 title bar
45 AUTO -- the window automatically appears when the
46 program needs input or output
47 ALT -- the window appears in the specified size
48 and position when the zoom gadget is clicked
49 BACKDROP -- the window is a backdrop window
50 CLOSE -- include a close gadget
51 INACTIVE -- the window is not made active when opened
52 NOBORDER -- the window is borderless, only the size,
53 depth and zoom gadgets are available
54 NOCLOSE -- the window has no close gadget
55 NODEPTH -- the window has no depth gadget
56 NODRAG -- the window cannot be drag; implies NOCLOSE
57 NOSIZE -- the window has no size gadget
58 SCREEN -- name of a public screen to open the window on
59 SIMPLE -- if the window is enlarged the text expands to
60 fill the available space
61 SMART -- if the window is enlarged the text will not
62 expand
63 WAIT -- the window can only be closed by selecting
64 the close gadget or entering CTRL-\.
67 FROM -- File to execute before resorting to normal shell
68 operations. If nothing is specified S:Shell-Startup
69 is used.
71 RESULT
73 NOTES
75 EXAMPLE
77 NewShell "CON:10/10/640/480/My own shell/CLOSE"
79 BUGS
81 SEE ALSO
83 INTERNALS
85 HISTORY
87 ******************************************************************************/
89 #include <exec/memory.h>
90 #include <proto/exec.h>
91 #include <proto/dos.h>
92 #include <dos/dosextens.h>
93 #include <dos/dostags.h>
94 #include <aros/asmcall.h>
95 #include <string.h>
97 #include <aros/shcommands.h>
99 AROS_SH3(NewShell, 41.2,
100 AROS_SHA(STRPTR, ,WINDOW, ,"CON:10/50/640/480/AROS-Shell/CLOSE"),
101 AROS_SHA(STRPTR, ,FROM, ,"S:Shell-Startup"),
102 AROS_SHA(ULONG, ,STACK, ,AROS_STACKSIZE))
104 AROS_SHCOMMAND_INIT
106 BPTR from = Open(SHArg(FROM), MODE_OLDFILE);
107 BPTR win = Open(SHArg(WINDOW), MODE_OLDFILE);
108 ULONG stack = SHArg(STACK);
110 LONG rc = RETURN_FAIL;
112 if (stack < AROS_STACKSIZE)
113 stack = AROS_STACKSIZE;
115 if (win)
117 struct TagItem tags[] =
119 { SYS_Asynch, TRUE },
120 { SYS_Background, FALSE },
121 { SYS_Input, (IPTR)win },
122 { SYS_Output, (IPTR)NULL },
123 { SYS_Error, (IPTR)NULL },
124 { SYS_ScriptInput, (IPTR)from },
125 { SYS_UserShell, TRUE },
126 { NP_StackSize, stack },
127 { TAG_DONE, 0 }
130 rc = SystemTagList("", tags);
131 if (rc != -1)
133 win = BNULL;
134 from = BNULL;
136 else
137 rc = RETURN_FAIL;
139 else
141 PrintFault(IoErr(), "NewShell");
144 Close(win);
145 Close(from);
147 return rc;
149 AROS_SHCOMMAND_EXIT