Initial import of Scalos. To decrease size I have
[AROS-Contrib.git] / scalos / main / CLIStart.c
blobc724b3120b6b4de52f0b135c8aad6b579dd79fd8
1 // CLIStart.c
2 // $Date$
3 // $Revision$
5 #include <exec/types.h>
6 #include <graphics/gels.h>
7 #include <graphics/rastport.h>
8 #include <intuition/classes.h>
9 #include <intuition/classusr.h>
10 #include <workbench/workbench.h>
11 #include <workbench/startup.h>
12 #include <dos/dostags.h>
14 #define __USE_SYSBASE
16 #include <proto/dos.h>
17 #include <proto/exec.h>
18 #include <proto/intuition.h>
19 #include "debug.h"
20 #include <proto/scalos.h>
22 #include <clib/alib_protos.h>
24 #include <datatypes/iconobject.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
30 #include <DefIcons.h>
32 #include "scalos_structures.h"
33 #include <defs.h>
34 #include "functions.h"
35 #include "Variables.h"
37 //----------------------------------------------------------------------------
39 // local data structures
41 //----------------------------------------------------------------------------
43 // local functions
45 //----------------------------------------------------------------------------
48 BOOL CLIStart(BPTR dirLock, CONST_STRPTR PrgName, Object *iconObject, ULONG def_StackSize)
50 BPTR oldCurrentDir;
51 STRPTR defTool;
52 STRPTR cmd;
53 ULONG StackSize = def_StackSize;
54 size_t CmdLen;
55 ULONG IconType;
56 BOOL Success = FALSE;
57 const struct DiskObject *icon = NULL;
59 oldCurrentDir = CurrentDir(dirLock);
61 GetAttr(IDTA_DefaultTool, iconObject, (APTR) &defTool);
62 GetAttr(IDTA_Stacksize, iconObject, &StackSize);
63 GetAttr(AIDTA_Icon, iconObject, (APTR) &icon);
65 if (NULL == defTool)
66 defTool = (STRPTR) "";
68 if (StackSize < def_StackSize)
69 StackSize = def_StackSize;
71 d1(kprintf("%s/%s/%ld: PrgName=<%s> deftool=<%s>\n", __FILE__, __FUNC__, __LINE__, PrgName, defTool));
73 GetAttr(IDTA_Type, iconObject, (ULONG *) &IconType);
74 switch ((ULONG) IconType)
76 case WBTOOL:
77 case WB_TEXTICON_TOOL:
78 CmdLen = strlen(PrgName) + 10;
79 break;
81 case WBPROJECT:
82 GetAttr(DTA_Name, iconObject, (APTR) &PrgName);
83 if (NULL == PrgName)
84 PrgName = (STRPTR) "";
86 CmdLen = strlen(PrgName) + strlen(defTool) + 10;
87 break;
88 default:
89 return FALSE;
90 break;
93 d1(kprintf("%s/%s/%ld: PrgName=<%s> deftool=<%s>\n", __FILE__, __FUNC__, __LINE__, PrgName, defTool));
95 cmd = AllocVec(CmdLen, MEMF_PUBLIC);
96 if (cmd)
98 BPTR inputFH, outputFH;
99 LONG Error;
100 STRPTR CliName;
102 switch ((ULONG) IconType)
104 case WBTOOL:
105 case WB_TEXTICON_TOOL:
106 ScaFormatStringMaxLength(cmd, CmdLen, "\"%s\"", (ULONG) PrgName);
107 break;
108 case WBPROJECT:
109 ScaFormatStringMaxLength(cmd, CmdLen, "\"%s\" \"%s\"", (ULONG) defTool, (ULONG) PrgName);
110 break;
111 default:
112 return FALSE;
113 break;
116 if (icon && icon->do_ToolWindow && strlen(icon->do_ToolWindow))
117 CliName = (STRPTR) icon->do_ToolWindow;
118 else
119 CliName = (STRPTR) CurrentPrefs.pref_ConsoleName; // was: "CON:////Scalos CLI/AUTO"
121 outputFH = (BPTR)NULL; // ... see SystemTagList() AutoDoc
122 inputFH = Open(CliName, MODE_NEWFILE);
124 d1(kprintf("%s/%s/%ld: inputFH=%08lx outputFH=%08lx\n", __FILE__, __FUNC__, __LINE__, inputFH, outputFH));
126 // SystemTagList()
127 Error = SystemTags(cmd,
128 SYS_Input, inputFH,
129 SYS_Output, outputFH,
130 SYS_Asynch, TRUE,
131 SYS_UserShell, TRUE,
132 NP_StackSize, StackSize,
133 NP_Path, DupWBPathList(),
134 TAG_END);
136 d1(kprintf("%s/%s/%ld: SystemTags returned %ld\n", __FILE__, __FUNC__, __LINE__, Error));
138 if (RETURN_OK == Error)
139 Success = TRUE;
141 FreeVec(cmd);
144 CurrentDir(oldCurrentDir);
146 return Success;
150 BPTR DupWBPathList(void)
152 struct Process *wbProc = ScalosMainTask;
153 struct CommandLineInterface *cli;
154 struct AssignList *aList, *StartList = NULL, **nList = NULL;
156 d1(KPrintF("%s/%s/%ld: wbProc=%08lx\n", __FILE__, __FUNC__, __LINE__, wbProc));
157 if (NULL == wbProc)
158 return (BPTR)NULL;
159 if (NT_PROCESS != wbProc->pr_Task.tc_Node.ln_Type)
160 return (BPTR)NULL;
162 cli = BADDR(wbProc->pr_CLI);
163 if (NULL == cli)
164 return (BPTR)NULL;
166 aList = BADDR(cli->cli_CommandDir);
167 if (NULL == aList)
168 return (BPTR)NULL;
170 while (aList)
172 struct AssignList *nNode = AllocVec(sizeof(struct AssignList), MEMF_PUBLIC);
174 if (NULL == nNode)
175 break;
176 if (NULL == nList)
177 StartList = nNode;
178 else
179 *nList = (struct AssignList *) MKBADDR(nNode);
181 nNode->al_Next = NULL;
182 nNode->al_Lock = DupLock(aList->al_Lock);
183 nList = &nNode->al_Next;
185 d1(kprintf("%s/%s/%ld: aList=%08lx Next=%08lx Lock=%08lx\n", __FILE__, __FUNC__, __LINE__, \
186 aList, aList->al_Next, aList->al_Lock));
188 aList = BADDR(aList->al_Next);
191 return MKBADDR(StartList);