4 Original GPL release version 4.12
5 Copyright 1993-2000 Jonathan Potter
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 All users of Directory Opus 4 (including versions distributed
22 under the GPL) are entitled to upgrade to the latest version of
23 Directory Opus version 5 at a reduced price. Please see
24 http://www.gpsoft.com.au for more information.
26 The release of Directory Opus 4 under the GPL in NO WAY affects
27 the existing commercial status of Directory Opus 5.
35 //#include <exec/types.h>
36 //#include <exec/memory.h>
37 //#include <exec/execbase.h>
38 //#include <dos/dos.h>
39 //#include <dos/dosextens.h>
40 //#include <dos/exall.h>
41 #include <intuition/intuitionbase.h>
42 #include <graphics/gfxbase.h>
43 #include <devices/input.h>
44 #include <workbench/startup.h>
45 #include <dopus/dopusbase.h>
47 #include <proto/dos.h>
48 #include <proto/exec.h>
49 #include <proto/graphics.h>
50 #include <proto/icon.h>
51 #include <proto/dopus.h>
57 #if defined(__PPC__) || defined(__AROS__)
61 #define __aligned __attribute__((__aligned__(4)))
62 #define lsprintf sprintf
66 //extern struct ExecBase *SysBase;
67 //extern struct DosLibrary *DOSBase;
68 struct DOpusBase
*DOpusBase
= NULL
;
70 void WBRun(int,char **);
71 int setarg(struct WBArg
*,char *,BPTR
);
72 BPTR
CloneCommandDir(const char *);
74 static const char *version
="$VER: DOpusRT 4.8 (" __DATE__
") by Jacek Rzeuski";
76 static const char *pathlists
[7]={
85 struct InputEvent
*InputHandler(register struct InputEvent
*ie
__asm("a0"),register struct Task
*task
__asm("a1"))
87 if (ie
->ie_Class
== IECLASS_RAWMOUSE
)
89 if (ie
->ie_Code
& IECODE_LBUTTON
)
91 #if !defined(__AROS__)
92 register struct ExecBase
*SysBase
__asm("a6") = *(struct ExecBase
**)4L;
95 Signal(task
,(ie
->ie_Code
& IECODE_UP_PREFIX
)?2:1);
101 static inline LONG
atoi(char *str
)
105 StrToLong((STRPTR
)str
,&i
);
115 struct MsgPort
*port
,*port1
,*cont
;
116 struct Process
*myproc
;
118 struct Window
*win
=NULL
;
119 struct CommandLineInterface
*cli
;
120 struct IntuitionBase
*IntuitionBase
;
121 struct GfxBase
*GfxBase
;
122 struct Interrupt
*interrupt
;
123 struct IOStdReq
*inputreq
;
125 if (argc
<2 || !(DOpusBase
=(struct DOpusBase
*)OpenLibrary("dopus.library",0))) return 1000000/*_exit(0)*/;
126 IntuitionBase
=DOpusBase
->IntuitionBase
;
127 GfxBase
=DOpusBase
->GfxBase
;
129 myproc
=(struct Process
*)FindTask(NULL
);
130 cli
=BADDR(myproc
->pr_CLI
);
131 if (cont
=GetConsoleTask()) {
132 struct InfoData __aligned ind
;
133 ULONG arg
=MKBADDR(&ind
);
135 if (SendPacket(cont
,ACTION_DISK_INFO
,&arg
,1))
136 win
=(struct Window
*)ind
.id_VolumeNode
;
140 if (argv
[1][0]=='-') switch(LToLower(argv
[1][1]))
144 if ((win
->WScreen
->Flags
&SCREENTYPE
)!=WBENCHSCREEN
) {
145 myproc
->pr_WindowPtr
=(APTR
)win
;
146 SetFont(win
->RPort
,GfxBase
->DefaultFont
);
147 Write(out
,"\x1b\x63",2);
150 if (cli
&& !cli
->cli_CommandDir
) {
153 for (a
=0;a
<7;a
++) if ((path
=CloneCommandDir(pathlists
[a
]))) break;
154 cli
->cli_CommandDir
=path
;
158 if ((a
=atoi(argv
[2]))>60) a
=60;
159 if (a
>0) Delay(a
*50);
162 if (port
=LCreatePort(NULL
,0)) {
163 if (inputreq
=(struct IOStdReq
*)LCreateExtIO(port
,sizeof(struct IOStdReq
))) {
164 if (!(OpenDevice("input.device",NULL
,(struct IORequest
*)inputreq
,NULL
))) {
165 if (interrupt
=AllocMem(sizeof(struct Interrupt
),MEMF_CLEAR
|MEMF_PUBLIC
)) {
166 interrupt
->is_Code
=(APTR
)InputHandler
;
167 interrupt
->is_Node
.ln_Pri
=51;
168 interrupt
->is_Node
.ln_Name
="DOpusRT";
169 interrupt
->is_Data
=myproc
;
172 Write(out
,argv
[3],strlen(argv
[3]));
174 else Write(out
,"\nPress left mouse button to continue...",39);
175 inputreq
->io_Data
=(APTR
)interrupt
;
176 inputreq
->io_Command
=IND_ADDHANDLER
;
177 DoIO((struct IORequest
*)inputreq
);
182 if (IntuitionBase
->ActiveWindow
==win
) {
183 x
=win
->MouseX
; y
=win
->MouseY
;
185 if ((x
<=win
->BorderLeft
) || (x
>=win
->Width
-win
->BorderRight
) ||
186 (y
<=win
->BorderTop
) || (y
>=win
->Height
-win
->BorderBottom
)) flag
=0;
189 else if (a
&2 && flag
) {
191 if (x
>win
->BorderLeft
&& x
<win
->Width
-win
->BorderRight
&&
192 y
>win
->BorderTop
&& y
<win
->Height
-win
->BorderBottom
) break;
196 // inputreq->io_Data=(APTR)interrupt;
197 inputreq
->io_Command
=IND_REMHANDLER
;
198 DoIO((struct IORequest
*)inputreq
);
199 FreeMem(interrupt
,sizeof(struct Interrupt
));
201 CloseDevice((struct IORequest
*)inputreq
);
203 LDeleteExtIO((struct IORequest
*)inputreq
);
212 if ((port
=FindPort(argv
[2]))) {
214 port1
=LCreatePort(0,0);
215 msg
.mn_Node
.ln_Type
=NT_MESSAGE
;
216 msg
.mn_ReplyPort
=port1
;
217 msg
.mn_Length
=sizeof(struct Message
);
225 WBRun(argc
-2,&argv
[2]);
228 CloseLibrary((struct Library
*)DOpusBase
);
239 BPTR
CloneCommandDir(const char *taskname
)
241 struct Process
*teacher
;
242 struct CommandLineInterface
*teachcli
;
243 struct PathList
*wext
,*mext
,*lastmext
=NULL
;
247 if (teacher
=(struct Process
*)FindTask(taskname
))
249 if (teachcli
=(struct CommandLineInterface
*)BADDR(teacher
->pr_CLI
))
251 for (wext
=BADDR(teachcli
->cli_CommandDir
); wext
; wext
=BADDR(wext
->nextPath
))
253 if (!(mext
= AllocVec(sizeof(struct PathList
),MEMF_PUBLIC
))) break;
256 mext
->pathLock
=DupLock(wext
->pathLock
);
257 if (!newpath
) newpath
=MKBADDR(mext
);
259 if (lastmext
) lastmext
->nextPath
=MKBADDR(mext
);
268 void WBRun(argc
,argv
)
272 struct WBStartup
*WBStartup
;
273 struct DiskObject
*diskobj
=NULL
;
275 int stacksize
,i
,ok
=1;
276 struct Process
*ourtask
;
277 struct MsgPort
*replyport
=NULL
;
279 struct IconBase
*IconBase
;
280 struct DOpusRemember
*key
=NULL
;
281 struct CommandLineInterface
*cli
;
283 if (argc
<1 || !(IconBase
=(struct IconBase
*)OpenLibrary("icon.library",0))) return;
285 ourtask
=(struct Process
*)FindTask(NULL
);
287 if ((WBStartup
=LAllocRemember(&key
,sizeof(struct WBStartup
),MEMF_CLEAR
)) &&
288 (WBStartup
->sm_ArgList
=LAllocRemember(&key
,sizeof(struct WBArg
)*(argc
+1),MEMF_CLEAR
)) &&
289 (replyport
=LCreatePort(NULL
,0)))
291 WBStartup
->sm_Message
.mn_ReplyPort
=replyport
;
292 WBStartup
->sm_NumArgs
=argc
;
295 if (setarg(&WBStartup
->sm_ArgList
[i
],argv
[i
],ourtask
->pr_CurrentDir
))
300 olddir
=CurrentDir(WBStartup
->sm_ArgList
[0].wa_Lock
);
302 if (!(diskobj
=GetDiskObject(WBStartup
->sm_ArgList
[0].wa_Name
)))
304 if (!(SearchPathList(argv
[0],namebuf
,256)))
307 else if (diskobj
->do_Type
==WBTOOL
) LStrCpy(namebuf
,argv
[0]);
308 else if (diskobj
->do_Type
==WBPROJECT
)
310 if (SearchPathList(diskobj
->do_DefaultTool
,namebuf
,256))
312 for (i
= argc
- 1; i
>= 0; i
--)
313 CopyMem(&WBStartup
->sm_ArgList
[i
],&WBStartup
->sm_ArgList
[i
+1],sizeof(struct WBArg
));
314 if (setarg(&WBStartup
->sm_ArgList
[0],namebuf
,WBStartup
->sm_ArgList
[0].wa_Lock
))
316 else ++WBStartup
->sm_NumArgs
;
324 if (diskobj
) stacksize
=diskobj
->do_StackSize
;
327 if (cli
= BADDR(ourtask
->pr_CLI
))
328 stacksize
= cli
->cli_DefaultStack
*4;
329 else stacksize
= 4096;
332 stacksize
= (stacksize
+3)&(~3);
333 if (stacksize
< 4096) stacksize
= 4096;
335 WBStartup
->sm_ToolWindow
=(diskobj
)?diskobj
->do_ToolWindow
:NULL
;
337 if (WBStartup
->sm_Segment
= LoadSeg(namebuf
))
339 char *ptr
= BaseName(namebuf
);
342 if (WBStartup
->sm_Process
=CreateProc(ptr
,
343 ourtask
->pr_Task
.tc_Node
.ln_Pri
,WBStartup
->sm_Segment
,stacksize
))
346 ((struct Process
*)(WBStartup
->sm_Process
->mp_SigTask
))->pr_HomeDir
=Lock(ptr
,ACCESS_READ
);
348 PutMsg(WBStartup
->sm_Process
,(struct Message
*)WBStartup
);
358 if (replyport
) LDeletePort(replyport
);
359 if (diskobj
) FreeDiskObject(diskobj
);
360 if (olddir
!=-1) CurrentDir(olddir
);
362 /*if (WBStartup->sm_Segment)*/ UnLoadSeg(WBStartup
->sm_Segment
);
363 if (WBStartup
->sm_ArgList
) {
364 for (i
=0;i
<WBStartup
->sm_NumArgs
;i
++) {
365 // if (WBStartup->sm_ArgList[i].wa_Lock)
366 UnLock(WBStartup
->sm_ArgList
[i
].wa_Lock
);
371 /*if (IconBase)*/ CloseLibrary((struct Library
*)IconBase
);
374 int setarg(WBArg
,name
,curdir
)
382 if (!name
|| !name
[0]) return(1);
386 if (*p
==':' || *p
=='/') lastc
=p
+1;
389 WBArg
->wa_Lock
=DupLock(curdir
);
393 if (!lastc
[0]) return(1);
394 WBArg
->wa_Name
=lastc
;
397 if (!(WBArg
->wa_Lock
=Lock(name
,ACCESS_READ
))) return(1);