- Update stm32f7_discovery target description
[AROS.git] / workbench / system / CLI.c
blobebe5d6d6b0d4283ab379115f81a31e7a23acfda6
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: CLI Command
6 Lang: English
7 */
9 /******************************************************************************
12 NAME
14 CLI
16 SYNOPSIS
18 WINDOW,FROM,STACK
20 LOCATION
22 SYS:System/
24 FUNCTION
26 Create a new shell in a new console window. This window will become
27 the active one.
29 The window belonging to the new shell may be specified by
30 using the WINDOW tooltype.
32 INPUTS
34 The attributes are read as tooltypes from the Shell icon.
36 WINDOW -- Specification of the shell window. It must be in the form
37 con:[X]/[Y]/[WIDTH]/[HEIGHT]...
39 X -- number of pixels from the left edge of
40 the screen
41 Y -- number of pixels from the top edge of
42 the screen
43 WIDTH -- width of the shell window in pixels
44 HEIGHT -- height of the shell window in pixels
45 TITLE -- text to appear in the shell window's
46 title bar
47 AUTO -- the window automatically appears when the
48 program needs input or output
49 ALT -- the window appears in the specified size
50 and position when the zoom gadget is clicked
51 BACKDROP -- the window is a backdrop window
52 CLOSE -- include a close gadget
53 INACTIVE -- the window is not made active when opened
54 NOBORDER -- the window is borderless, only the size,
55 depth and zoom gadgets are available
56 NOCLOSE -- the window has no close gadget
57 NODEPTH -- the window has no depth gadget
58 NODRAG -- the window cannot be drag; implies NOCLOSE
59 NOSIZE -- the window has no size gadget
60 SCREEN -- name of a public screen to open the window on
61 SIMPLE -- if the window is enlarged the text expands to
62 fill the available space
63 SMART -- if the window is enlarged the text will not
64 expand
65 WAIT -- the window can only be closed by selecting
66 the close gadget or entering CTRL-\.
69 FROM -- File to execute before resorting to normal shell
70 operations. If nothing is specified S:Shell-Startup
71 is used.
73 STACK -- Stack size in Bytes.
75 RESULT
77 NOTES
78 As opposed to C:NewShell, this is a Workbench Tool.
80 EXAMPLE
82 BUGS
84 SEE ALSO
86 INTERNALS
88 HISTORY
90 ******************************************************************************/
92 #include <proto/dos.h>
93 #include <proto/icon.h>
94 #include <workbench/startup.h>
96 //#define DEBUG 1
97 #include <aros/debug.h>
99 const TEXT ver[] = "$VER:CLI 1.2 (07.02.2017) © AROS Dev Team";
100 static BPTR olddir = (BPTR)-1;
102 int main(int argc, char **argv)
104 struct DiskObject *dobj = NULL;
105 LONG rc = RETURN_OK;
107 STRPTR winspec = NULL;
108 STRPTR fromspec = NULL;
109 ULONG stack = 0;
111 BPTR win, from;
112 BPTR iconlock = BNULL;
113 STRPTR iconname = NULL;
115 // CLI is a special case, because it is
116 // a default tool of an icon with a different name,
117 // usually SYS:System/Shell.info.
119 // check the wbmessage for the icon name
120 // from which we were called
121 if (argc == 0)
123 struct WBStartup *wbmsg = (struct WBStartup *)argv;
124 if (wbmsg->sm_NumArgs == 2)
126 iconlock = wbmsg->sm_ArgList[1].wa_Lock;
127 iconname = wbmsg->sm_ArgList[1].wa_Name;
128 olddir = CurrentDir(iconlock);
132 // if we don't have a valid name we try the standard name
133 if ((iconname == NULL) || (*iconname == '\0'))
135 iconname = "SYS:System/Shell";
138 // read the diskobject for the tooltypes
139 if ((dobj = GetDiskObject(iconname)) != NULL)
141 STRPTR result;
142 STRPTR *toolarray = dobj->do_ToolTypes;
144 result = FindToolType(toolarray, "STACK");
145 if (result)
146 StrToLong(result, &stack);
148 result = FindToolType(toolarray, "FROM");
149 if (result)
150 fromspec = result;
152 result = FindToolType(toolarray, "WINDOW");
153 if (result)
154 winspec = result;
156 D(bug("[CLI] iconname %s diskobject %p\n", iconname, dobj));
158 // sanity checks; set default values
159 if (stack < AROS_STACKSIZE)
160 stack = AROS_STACKSIZE;
162 if (fromspec == NULL)
163 fromspec = "S:Shell-Startup";
165 if (winspec == NULL)
166 winspec = "CON:0/50//130/AROS-Shell/CLOSE";
168 D(bug("[CLI] stack %d from %s window %s\n", stack, fromspec, winspec));
170 // open the streams for SystemTagList
171 from = Open(fromspec, MODE_OLDFILE);
172 win = Open(winspec, MODE_NEWFILE);
174 // launch the Shell
175 if (win)
177 struct TagItem tags[] =
179 { SYS_Asynch, TRUE },
180 { SYS_Background, FALSE },
181 { SYS_Input, (IPTR)win },
182 { SYS_Output, (IPTR)NULL },
183 { SYS_Error, (IPTR)NULL },
184 { SYS_ScriptInput, (IPTR)from },
185 { SYS_UserShell, TRUE },
186 { NP_StackSize, stack },
187 { TAG_DONE, 0 }
189 rc = SystemTagList("", tags);
190 if (rc != -1)
192 // SystemTagList closes the streams for us
193 // when run successfully asynch
194 win = BNULL;
195 from = BNULL;
197 else
198 rc = RETURN_FAIL;
200 Close(win);
201 Close(from);
202 FreeDiskObject(dobj);
204 if (olddir != (BPTR)-1)
206 CurrentDir(olddir);
207 olddir = (BPTR)-1;
210 return rc;