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.
33 #define MAXRXOUTSTANDING 300
34 #define RXERRORIMGONE 100
35 #define RXERRORNOCMD 30
37 static struct RexxMsg
*oldrxmsg
;
38 static int rexx_closing
;
39 static long replies_pending
;
41 void rexx_dispatch(allfuncs
)
48 while (msg
=(struct RexxMsg
*)GetMsg(arexx_port
)) {
49 if ((!RexxSysBase
|| !(IsRexxMsg(msg
))) &&
50 msg
->rm_Node
.mn_Node
.ln_Type
!=NT_REPLYMSG
) {
52 struct DOpusMessage
*dopusmsg
;
53 struct DOpusArgsList
*arglist
;
55 //D(bug("0.%s\t%ld\n",msg->rm_Args[0],IsRexxMsg(msg)));
56 dopusmsg
=(struct DOpusMessage
*)msg
;
58 switch (dopusmsg
->command
) {
60 fill_out_visinfo((struct VisInfo
*)dopusmsg
->data
,NULL
);
62 case DOPUSMSG_GETNEXTFILE
:
63 arglist
=(struct DOpusArgsList
*)dopusmsg
->data
;
64 if (arglist
->single_file
) {
65 strcpy(arglist
->file_data
,arglist
->single_file
);
66 arglist
->single_file
=NULL
;
68 else if (arglist
->file_list
) {
69 struct Directory
*entry
;
71 entry
=(struct Directory
*)arglist
->file_list
;
72 strcpy(arglist
->file_data
,dopus_curwin
[arglist
->file_window
]->directory
);
73 TackOn(arglist
->file_data
,entry
->name
,256);
74 arglist
->last_select
=arglist
->file_list
;
78 if (entry
->type
<0 && entry
->selected
) break;
82 arglist
->file_list
=(APTR
)entry
;
84 else arglist
->file_data
[0]=0;
86 case DOPUSMSG_UNSELECTFILE
:
87 arglist
=(struct DOpusArgsList
*)dopusmsg
->data
;
88 if (arglist
->last_select
) {
89 unselect(arglist
->file_window
,arglist
->last_select
);
90 arglist
->last_select
=NULL
;
93 case DOPUSMSG_GETPRINTDIR
:
94 get_printdir_data((struct PrintDirData
*)dopusmsg
->data
);
97 ReplyMsg((struct Message
*)dopusmsg
);
99 else if (RexxSysBase
) {
100 if (msg
->rm_Node
.mn_Node
.ln_Type
==NT_REPLYMSG
) {
101 if (msg
->rm_Args
[1]) rexx_msg_reply(msg
);
102 DeleteArgstring(msg
->rm_Args
[0]);
107 command
=(char *)msg
->rm_Args
[0];
108 D(bug("rexx.1.%s\n",command
));
109 while (*command
>0 && *command
<=' ') ++command
;
113 if (rexx_closing
) msg
->rm_Result1
=RXERRORIMGONE
;
116 for (cmd
=0;commandlist
[cmd
].name
;cmd
++) {
117 a
=strlen(commandlist
[cmd
].name
);
118 if ((Strnicmp(commandlist
[cmd
].name
,command
,a
))==0 &&
119 (command
[a
]==0 || (_isspace(command
[a
])))) {
120 D(bug("rexx.2.%s\n",commandlist
[cmd
].name
));
121 func_global_function
=0;
122 rexxdisp(msg
,&commandlist
[cmd
],command
+a
);
123 if (!allfuncs
|| func_global_function
==FUNC_ICONIFY
||
124 func_global_function
==FUNC_QUIT
) break;
125 if (func_global_function
) {
130 internal_function(func_global_function
,rexx_global_flag
,NULL
,NULL
);
131 func_global_function
=0;
132 lsprintf(buf
,"%ld",(long int)rexx_return_value
);
133 rexx_set_return(msg
,rexx_result_code
,buf
);
138 if (!commandlist
[cmd
].name
) {
139 rexx_command(msg
->rm_Args
[0],msg
);
144 if (!dontreply
) ReplyMsg((struct Message
*)msg
);
147 else if (msg
->rm_Node
.mn_Node
.ln_Type
!=NT_REPLYMSG
)
148 ReplyMsg((struct Message
*)msg
);
152 struct RexxMsg
*send_rexx_command(command
,replyfunc
,msg
)
157 struct MsgPort
*rxport
;
158 struct RexxMsg
*RexxMsg
;
160 D(bug("send_rexx_command(%s)\n",command
?command
:"NULL"));
161 if (!RexxSysBase
|| replies_pending
>MAXRXOUTSTANDING
-1 ||
162 !command
|| !command
[0]) return(NULL
);
164 if ((RexxMsg
=(struct RexxMsg
*)
165 CreateRexxMsg(arexx_port
,"dopus",str_arexx_portname
)) &&
166 (RexxMsg
->rm_Args
[0]=(STRPTR
)CreateArgstring(command
,(long)strlen(command
)))) {
168 RexxMsg
->rm_Action
=RXCOMM
;
169 RexxMsg
->rm_Args
[1]=(STRPTR
)replyfunc
;
170 RexxMsg
->rm_Args
[2]=(STRPTR
)msg
;
171 RexxMsg
->rm_Node
.mn_Node
.ln_Name
="REXX";
174 if (rxport
=FindPort("REXX"))
175 PutMsg(rxport
,(struct Message
*)RexxMsg
);
181 else DeleteArgstring(RexxMsg
->rm_Args
[0]);
183 if (RexxMsg
) DeleteRexxMsg(RexxMsg
);
187 void rexx_msg_reply(msg
)
190 struct RexxMsg
*oldmsg
;
192 if ((oldmsg
=(struct RexxMsg
*)(msg
->rm_Args
[2]))) {
193 rexx_set_return(oldmsg
,msg
->rm_Result1
,(char *)msg
->rm_Result2
);
194 ReplyMsg((struct Message
*)oldmsg
);
198 struct RexxMsg
*rexx_command(command
,syncmsg
)
200 struct RexxMsg
*syncmsg
;
204 if (!command
|| !command
[0]) msg
=NULL
;
205 else if (syncmsg
) msg
=send_rexx_command(command
,(APTR
)&rexx_msg_reply
,syncmsg
);
206 else msg
=send_rexx_command(command
,NULL
,NULL
);
210 void rexx_copyresult(char *result
)
214 if (result
) if (new_lrr
= AllocVec(strlen(result
)+1,MEMF_ANY
))
216 strcpy(new_lrr
,result
);
217 FreeVec(str_last_rexx_result
);
218 str_last_rexx_result
= new_lrr
;
222 void rexx_set_return(msg
,rc
,result
)
227 str_last_rexx_result
[0]=0;
229 if (msg
&& RexxSysBase
) {
230 if (rc
|| !result
|| !(msg
->rm_Action
&(1<<RXFB_RESULT
))) {
236 msg
->rm_Result2
=(long)CreateArgstring(result
,strlen(result
));
237 rexx_copyresult(result
);
240 else rexx_copyresult(result
);
243 void close_rexx_port()
248 oldrxmsg
->rm_Result1
=RXERRORIMGONE
;
249 ReplyMsg((struct Message
*)oldrxmsg
);
252 while (replies_pending
) {
253 if (!FindPort("REXX")) break;
254 WaitPort(arexx_port
);