forgotten commit. disabled until egl is adapted.
[AROS-Contrib.git] / dopus / Program / custom.c
blob4b64965c84848241579f3a4f7209ee1f38f1e6ed
1 /*
3 Directory Opus 4
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.
31 #include "dopus.h"
32 #include <dos/dostags.h>
34 #define MAXCOMMANDLEN 510
36 void defaultpar(par)
37 struct dopusfuncpar *par;
39 #ifdef _USE_SMALL_Q
40 if (status_flags&STATUS_IANSCRAP) {
41 par->which=FLAG_OUTWIND;
42 par->delay=-1;
44 else
45 #endif
47 par->which=FLAG_OUTWIND|FLAG_WB2F|FLAG_DOPUSF|FLAG_CDSOURCE;
48 par->delay=2;
50 par->key=par->qual=par->type=0;
51 par->pri=config->priority; par->stack=8000;
54 void dofunctionstring(func,name,title,pars)
55 char *func,*name,*title;
56 struct dopusfuncpar *pars;
58 char fbuf[256],*ptr;
59 int a,b,c,lb,ls,run=1,noloop=0,norm=1;
60 struct Directory *curcf;
61 struct function_data *funcdata;
63 D(bug("dofunctionstring(%s,%s,%s,%lx)\n",func?func:"<NULL>",name?name:"<NULL>",title?title:"<NULL>",pars));
64 if (!func || !func[0] ||
65 !(funcdata=LAllocRemember(&general_key,sizeof(struct function_data),MEMF_CLEAR))) return;
67 a=strlen(func);
68 status_flags&=~STATUS_VERIFYFAIL;
69 if (Window && !(status_flags&STATUS_FROMHOTKEY)) busy();
71 funcdata->activewin=data_active_window;
72 funcdata->inactivewin=1-data_active_window;
74 funcdata->file_request.window=Window;
75 funcdata->file_request.lines=15;
77 if (func_external_file[0]) {
78 D(bug("file: %s\n",func_external_file));
79 noloop=1;
80 if ((ptr=BaseName(func_external_file)))
81 strcpy(func_single_file,ptr);
82 strcpy(funcdata->source_path,func_external_file);
83 if ((ptr=BaseName(funcdata->source_path))) *ptr=0;
84 norm=0;
85 if (!status_iconified)
86 strcpy(funcdata->dest_path,str_pathbuffer[data_active_window]);
87 funcdata->activewin=1-data_active_window;
88 funcdata->inactivewin=data_active_window;
90 else if (func_single_file[0]) noloop=1;
91 else if (status_iconified) norm=0;
92 else funcdata->entry_first=checkalltot(dopus_curwin[funcdata->activewin]);
94 if (norm) {
95 strcpy(funcdata->source_path,str_arcorgname[0]?"T:":str_pathbuffer[funcdata->activewin]);
96 strcpy(funcdata->dest_path,str_pathbuffer[funcdata->inactivewin]);
99 status_justabort=status_haveaborted=0;
101 FOREVER {
102 c=lb=0; ls=-1;
104 curcf=funcdata->entry_first;
106 for (b=0;b<a;b++) {
107 if (c>0 && func[b]=='|' && lb) {
108 fbuf[c-1]=0; if (ls>-1) fbuf[ls]=0;
109 c=lb=0;
110 if (handlefunctionss(fbuf,name,title,pars,funcdata) ||
111 status_flags&STATUS_VERIFYFAIL) {
112 run=0;
113 break;
116 else {
117 if (c>0 || !(_isspace(func[b]))) {
118 if (func[b]=='|' && func[b+1]=='|') lb=1;
119 else if (_isspace(func[b])) {
120 if (ls==-1) ls=c;
122 else ls=-1;
123 fbuf[c++]=func[b];
127 if (c>0) {
128 fbuf[c]=0; if (ls>-1) fbuf[ls]=0;
129 if (handlefunctionss(fbuf,name,title,pars,funcdata) ||
130 status_flags&STATUS_VERIFYFAIL) run=0;
132 if (!pars || !(pars->which&FLAG_DOALL) || status_justabort || status_haveaborted ||
133 status_flags&STATUS_VERIFYFAIL || !run || func_single_file[0] || noloop ||
134 !funcdata->external_flag) break;
136 if (curcf && curcf==funcdata->entry_first)
137 funcdata->entry_first=funcdata->entry_first->next;
139 while (funcdata->entry_first) {
140 if (funcdata->entry_first->selected) break;
141 funcdata->entry_first=funcdata->entry_first->next;
144 if (!funcdata->entry_first) break;
145 funcdata->arg_use=funcdata->arg_first;
146 ++funcdata->function_count;
148 closescriptfile(pars,run,funcdata);
149 func_single_file[0]=0;
150 func_external_file[0]=0;
151 LFreeRemEntry(&general_key,(char *)funcdata);
153 if (norm && Window) {
154 for (a=0;a<2;a++) check_old_buffer(a);
158 int handlefunctionss(funcbuf,name,title,pars,funcdata)
159 char *funcbuf,*name,*title;
160 struct dopusfuncpar *pars;
161 struct function_data *funcdata;
163 int function,abort=0,a,b;
164 char *funcptr;
165 struct dopusfuncpar par;
166 struct Directory *didselect=NULL;
168 func_single_entry=NULL;
170 if (funcbuf[0]==FC_INTERNAL) {
171 b=strlen(funcbuf);
172 for (a=0;a<b;a++) if (funcbuf[a]=='{') break;
173 if (a<b) {
174 char buf2[256],newfunc[MAXCOMMANDLEN];
176 parserunline(funcbuf,buf2);
177 if (!(buildcustfunc(buf2,strlen(funcbuf),newfunc,NULL,0,0,0,funcdata)))
178 return(1);
179 funcbuf=newfunc;
181 if ((function=getfunction(funcbuf,&funcptr))!=-1) {
182 if (function!=FUNC_HELP && status_flags&STATUS_HELP) {
183 dohelp(name,funcbuf,pars?pars->key:0,pars?pars->qual:0,NULL);
184 abort=1;
186 else if (function==FUNC_ENDFUNCTION) closescriptfile(pars,1,funcdata);
187 else {
188 func_entry_deleted=0;
189 if (func_single_file[0]) {
190 if (func_external_file[0]) {
191 if (filloutdummy(func_external_file,&funcdata->entry_external)) {
192 funcdata->entry_external.selected=0;
193 func_single_entry=&funcdata->entry_external;
196 else if ((func_single_entry=
197 findfile(dopus_curwin[funcdata->activewin],func_single_file,NULL))) {
198 func_single_entry->selected=1;
199 updateselectinfo(func_single_entry,funcdata->activewin,0);
200 didselect=func_single_entry;
204 global_swap_window=FALSE;
206 D(bug("handlefunctionss():funcbuf:\t%s\n\tname:\t%s\n\ttitle:\t%s\n\tfuncptr:\t%s\n",funcbuf?funcbuf:"<NULL>",name?name:"<NULL>",title?title:"<NULL>",funcptr?funcptr:"<NULL>"));
207 if (funcptr) {
208 func_global_function=function;
209 rexxdisp(NULL,NULL,funcptr);
210 if (func_global_function)
211 abort=internal_function(func_global_function,rexx_global_flag,
212 funcdata->source_path,funcdata->dest_path);
213 func_global_function=0;
215 else abort=internal_function(function,0,funcdata->source_path,funcdata->dest_path);
217 if (global_swap_window) {
218 funcdata->activewin=data_active_window;
219 funcdata->inactivewin=1-data_active_window;
221 strcpy(funcdata->source_path,str_pathbuffer[funcdata->activewin]);
222 strcpy(funcdata->dest_path,str_pathbuffer[funcdata->inactivewin]);
224 funcdata->entry_first=checkalltot(dopus_curwin[funcdata->activewin]);
227 if (didselect && !func_entry_deleted && didselect->selected) {
228 didselect->selected=0;
229 updateselectinfo(didselect,funcdata->activewin,0);
231 func_single_entry=NULL; func_entry_deleted=0;
235 else {
236 funcdata->external_flag=1;
237 if (status_flags&STATUS_HELP) {
238 dohelp(name,funcbuf,pars?pars->key:0,pars?pars->qual:0,NULL);
239 abort=1;
241 else {
242 if (pars) CopyMem((char *)pars,(char *)&par,sizeof(struct dopusfuncpar));
243 else defaultpar(&par);
244 switch (funcbuf[0]) {
245 case FC_WORKBENCH: par.type=FT_WORKBENCH; ++funcbuf; break;
246 case FC_BATCH: par.type=FT_BATCH; ++funcbuf; break;
247 case FC_AREXX: par.type=FT_AREXX; ++funcbuf; break;
248 case FC_CHDIR: par.type=FT_CHDIR; ++funcbuf; break;
249 default: par.type=FT_EXECUTABLE; break;
251 if (!(customthing(name,title,funcbuf,&par,funcdata))) abort=1;
254 return(abort);
257 int getfunction(func,funcptr)
258 char *func,**funcptr;
260 int a,b;
262 if (funcptr) *funcptr=NULL;
263 if (!func) return(-1);
264 if (func[0]==FC_INTERNAL) {
265 b=0;
266 FOREVER {
267 if (commandlist[b].name==NULL) break;
268 a=strlen(commandlist[b].name);
269 if (Strnicmp(commandlist[b].name,&func[1],a)==0 &&
270 (_isspace(func[a+1]) || func[a+1]==0)) {
271 if (funcptr && func[a+1]) *funcptr=&func[a+1];
272 return((int)commandlist[b].function);
274 ++b;
277 return(-1);
280 int customthing(name,title,function,par,funcdata)
281 char *name,*title,*function;
282 struct dopusfuncpar *par;
283 struct function_data *funcdata;
285 int moretodo,a,b,len,retval,type,count;
286 unsigned char buf[256],*ptr;
287 char buf2[MAXCOMMANDLEN],tbuf[512];
288 struct args *usearg,*endarg;
290 if ((!name || !name[0]) && (!function || !function[0])) return(1);
291 if (Window && !status_iconified && !(status_flags&STATUS_FROMHOTKEY)) {
292 if (title) dostatustext(title);
293 else if (name) dostatustext(name);
296 type = par->type;
298 if (type==FT_AREXX) {
299 rexx_command(function,NULL);
300 return(1);
303 if (type != FT_AREXX)
305 if (!(openscriptfile(par,funcdata))) return(0);
306 if (type==FT_CHDIR) {
307 b=strlen(function);
308 for (a=1;a<b;a++) if (function[a]=='!') break;
309 LStrnCpy(buf2,&function[1],a-1);
310 lsprintf(tbuf,"CD %s\n",buf2);
311 Write(funcdata->output_file,tbuf,strlen(tbuf));
312 return(1);
315 retval=1;
317 if (!function[0]) {
318 if (type != FT_AREXX)
320 ptr=(unsigned char *)name;
321 while (*ptr) {
322 if (*ptr==';') *ptr='\n';
323 ++ptr;
325 lsprintf(tbuf,"%s\n",name);
326 Write(funcdata->output_file,tbuf,strlen(tbuf));
329 else {
330 parserunline(function,buf);
331 ptr=buf;
332 while (*ptr) {
333 if (*ptr==';') *ptr='\n';
334 ++ptr;
336 len=strlen((char *)buf);
337 count=funcdata->function_count;
338 endarg=usearg=funcdata->arg_use;
340 FOREVER {
341 if (status_haveaborted) {
342 if (type != FT_AREXX) closescriptfile(NULL,0,funcdata);
343 myabort();
344 retval=0;
345 break;
347 moretodo=0;
348 if (!(buildcustfunc(buf,len,buf2,&moretodo,par->which&FLAG_RECURSE,par->which&FLAG_RELOAD,
349 ((par->which&FLAG_NOQUOTE)?0:1),funcdata))) {
350 if (type != FT_AREXX) closescriptfile(NULL,0,funcdata);
351 retval=0;
352 break;
354 D(bug("customthing(): buf2 = %s\n",buf2));
355 if (type == FT_AREXX) rexx_command(buf2,NULL);
356 else
358 if (type==FT_BATCH) strcpy(tbuf,"Execute ");
359 else if (type==FT_WORKBENCH) lsprintf(tbuf,"\"%s\" -r ",str_dopusrt_path);
360 else tbuf[0]=0;
361 Write(funcdata->output_file,tbuf,strlen(tbuf));
363 lsprintf(tbuf,"%s\n",buf2);
364 Write(funcdata->output_file,tbuf,strlen(tbuf));
366 //D(bug("customthing: moretodo=%ld, funcdata: entry_first=%lx, file_request.filearray=%lx\n",moretodo,funcdata->entry_first,funcdata->file_request.filearray));
367 if (moretodo &&
368 (funcdata->entry_first || funcdata->file_request.filearray)) goto domorestuff;
369 if (!funcdata->recursive_path) break;
370 domorestuff:
371 //D(bug("customthing: domorestuff\n"));
372 funcdata->function_count=-1;
373 endarg=funcdata->arg_use;
374 if (usearg) funcdata->arg_use=usearg->next;
375 if (!funcdata->arg_use) funcdata->arg_use = usearg ? usearg : funcdata->arg_first;
377 //D(bug("customthing: end loop\n"));
378 funcdata->function_count=count;
379 funcdata->arg_use=endarg;
380 if (funcdata->activewin>-1)
381 funcdata->entry_first=checkalltot(dopus_curwin[funcdata->activewin]);
383 if (funcdata->file_request.filearray) {
384 LFreeRemember(&funcdata->file_request.filearraykey);
385 funcdata->file_request.filearray=NULL;
387 return(retval);
390 int buildcustfunc(function,line_len,buffer,moretodo,star,reload,quote,funcdata)
391 unsigned char *function;
392 int line_len;
393 char *buffer;
394 int *moretodo,star,reload,quote;
395 struct function_data *funcdata;
397 char buf3[256],*ptr,filebuf[FILEBUF_SIZE],dirbuf[256],*spath,defbuf[256],titlebuf[80];
398 int a,pos,bufpos,d,f,sblen,buftitpos,h,qad,def,tit;
399 struct Directory *cust=NULL,dummy;
400 struct args *arg;
402 /*buffer[0]=buf3[0]=*/dirbuf[0]=0;
403 qad=quote*2;
405 bzero(buffer,MAXCOMMANDLEN);
406 bzero(buf3,256);
407 // for (bufpos=0;bufpos<500;bufpos++) buffer[bufpos]=buf3[bufpos]=0;
408 bufpos=0;
410 sblen=strlen(funcdata->source_path);
412 //D(bug("buildcustfunc: function = %s\n",function));
413 for (pos=0;pos<line_len;pos++) {
414 switch (function[pos]) {
415 case FUNC_ONEFILE:
416 case FUNC_ONEFILE_NO:
417 if (!func_single_file[0]) {
418 if (status_iconified || status_flags&STATUS_FROMHOTKEY) {
419 if (getdummyfile(&dummy,dirbuf,&funcdata->file_request)) cust=&dummy;
420 else return(0);
422 else /*if (!funcdata->recursive_path)*/ cust=custgetfirst(funcdata);
423 if (cust) {
424 strcpy(funcdata->last_file,funcdata->source_path);
425 TackOn(funcdata->last_file,cust->name,256);
426 if (!funcdata->recursive_path && cust->type>0) {
427 if (star) {
428 LFreeRemember(&rec_pathkey);
429 funcdata->entry_current=cust;
430 StrCombine(buf3,funcdata->source_path,cust->name,256);
431 if (recursedir(buf3,NULL,R_STARDIR,strlen(funcdata->source_path)))
432 return(0);
433 setdirsize(cust,dos_global_bytecount,funcdata->activewin);
434 funcdata->recursive_path=rec_firstpath;
435 goto addfile1;
437 else {
438 bufpos+=addfilename(buffer,cust->name,NULL,quote);
439 if (function[pos]!=FUNC_ONEFILE_NO) {
440 custunselect(cust,reload,funcdata);
441 custnextsel(&funcdata->entry_first);
445 else {
446 addfile1:
447 if (funcdata->recursive_path) {
448 bufpos+=addfilename(buffer,funcdata->recursive_path->path,NULL,quote);
449 if (!(funcdata->recursive_path=funcdata->recursive_path->next) &&
450 function[pos]!=FUNC_ONEFILE_NO)
451 custunselect(funcdata->entry_current,reload,funcdata);
453 else {
454 bufpos+=addfilename(buffer,cust->name,NULL,quote);
455 if (function[pos]!=FUNC_ONEFILE_NO) {
456 custunselect(cust,reload,funcdata);
457 custnextsel(&funcdata->entry_first);
463 else {
464 strcpy(funcdata->last_file,func_single_file);
465 bufpos+=addfilename(buffer,func_single_file,NULL,quote);
467 break;
469 case FUNC_ALLFILES:
470 case FUNC_ALLFILES_NO:
471 if (!func_single_file[0]) {
472 a=d=strlen(buffer);
473 if (status_iconified || status_flags&STATUS_FROMHOTKEY) {
474 if (getdummyfile(&dummy,dirbuf,&funcdata->file_request)) cust=&dummy;
475 else return(0);
477 else cust=custgetfirst(funcdata);
478 while (a<(MAXCOMMANDLEN-1) && (cust || funcdata->recursive_path)) {
479 //if (cust) D(bug("cust->name: %s\n",cust->name));
480 if (funcdata->recursive_path || (cust->selected && cust->type!=0)) {
481 if (!funcdata->recursive_path && cust->type>0) {
482 if (star) {
483 LFreeRemember(&rec_pathkey);
484 funcdata->entry_current=cust;
485 StrCombine(buf3,funcdata->source_path,cust->name,256);
486 if (recursedir(buf3,NULL,R_STARDIR,strlen(funcdata->source_path)))
487 return(0);
488 setdirsize(cust,dos_global_bytecount,funcdata->activewin);
489 funcdata->recursive_path=rec_firstpath;
490 goto addfile2;
492 else {
493 if ((a+strlen(cust->name)+qad)>(MAXCOMMANDLEN-1)) break;
494 addfilename(buffer,cust->name,NULL,quote);
495 if (function[pos]!=FUNC_ALLFILES_NO)
496 custunselect(cust,reload,funcdata);
499 else {
500 addfile2:
501 if (funcdata->recursive_path) {
502 if ((a+strlen(funcdata->recursive_path->path)+qad)>(MAXCOMMANDLEN-1)) break;
503 addfilename(buffer,funcdata->recursive_path->path,NULL,quote);
504 if (!(funcdata->recursive_path=funcdata->recursive_path->next)) {
505 if (function[pos]!=FUNC_ALLFILES_NO)
506 custunselect(funcdata->entry_current,reload,funcdata);
509 else {
510 if ((a+strlen(cust->name)+qad)>(MAXCOMMANDLEN-1)) break;
511 addfilename(buffer,cust->name,NULL,quote);
512 if (function[pos]!=FUNC_ALLFILES_NO)
513 custunselect(cust,reload,funcdata);
516 StrConcat(buffer," ",MAXCOMMANDLEN);
517 a=strlen(buffer);
519 if (!funcdata->recursive_path) {
520 if (cust) cust=cust->next;
522 //D(bug("buffer: %s\n",buffer));
524 if (!funcdata->recursive_path) {
525 //D(bug("funcdata->entry_first: %s\t",funcdata->entry_first->name));
526 custnextsel(&funcdata->entry_first);
527 //D(bug("->\tfuncdata->entry_first: %s\n",funcdata->entry_first->name));
529 bufpos+=a-d;
530 if (moretodo) *moretodo=1;
532 else {
533 bufpos+=addfilename(buffer,func_single_file,NULL,quote);
534 StrConcat(buffer," ",MAXCOMMANDLEN);
535 ++bufpos;
537 break;
539 case FUNC_ONEPATH:
540 case FUNC_ONEPATH_NO:
541 //D(bug("buildcustfunc(): func_single_file=\"%s\"\n",func_single_file));
542 if (!func_single_file[0]) {
543 if (status_iconified || status_flags&STATUS_FROMHOTKEY) {
544 if (getdummyfile(&dummy,dirbuf,&funcdata->file_request)) cust=&dummy;
545 else return(0);
546 TackOn(dirbuf,NULL,256);
547 spath=dirbuf;
549 else {
550 /*if (!funcdata->recursive_path)*/ cust=custgetfirst(funcdata);
551 spath=funcdata->source_path;
553 //D(bug("cust = %lx\n",cust));
554 if (cust) {
555 strcpy(funcdata->last_file,spath);
556 TackOn(funcdata->last_file,cust->name,256);
557 //D(bug("funcdata->last_file = %s\n",funcdata->last_file));
558 if (!funcdata->recursive_path && cust->type>0) {
559 if (star) {
560 LFreeRemember(&rec_pathkey);
561 funcdata->entry_current=cust;
562 StrCombine(buf3,spath,cust->name,256);
563 //D(bug("recurse -> calling recursedir(%s)\n",buf3));
564 if (recursedir(buf3,NULL,R_STARDIR,0)) return(0);
565 setdirsize(cust,dos_global_bytecount,funcdata->activewin);
566 funcdata->recursive_path=rec_firstpath;
567 //D(bug("recursive_path = %s,%lx\n",funcdata->recursive_path->path,funcdata->recursive_path->next));
568 goto addfile3;
570 else {
571 //D(bug("no recurse\n"));
572 bufpos+=addfilename(buffer,spath,cust->name,quote);
573 if (function[pos]!=FUNC_ONEPATH_NO) {
574 custunselect(cust,reload,funcdata);
575 custnextsel(&funcdata->entry_first);
579 else {
580 addfile3:
581 if (funcdata->recursive_path) {
582 bufpos+=addfilename(buffer,funcdata->recursive_path->path,NULL,quote);
583 funcdata->recursive_path=funcdata->recursive_path->next;
584 if ((funcdata->recursive_path==NULL) && (function[pos]!=FUNC_ONEPATH_NO))
585 custunselect(funcdata->entry_current,reload,funcdata);
587 else {
588 bufpos+=addfilename(buffer,spath,cust->name,quote);
589 if (function[pos]!=FUNC_ONEPATH_NO) {
590 custunselect(cust,reload,funcdata);
591 custnextsel(&funcdata->entry_first);
597 else {
598 bufpos+=addfilename(buffer,funcdata->source_path,func_single_file,quote);
599 strcpy(funcdata->last_file,funcdata->source_path);
600 TackOn(funcdata->last_file,func_single_file,256);
602 break;
604 case FUNC_ALLPATHS:
605 case FUNC_ALLPATHS_NO:
606 if (!func_single_file[0]) {
607 a=d=strlen(buffer);
608 if (status_iconified || status_flags&STATUS_FROMHOTKEY) {
609 if (getdummyfile(&dummy,dirbuf,&funcdata->file_request)) cust=&dummy;
610 else return(0);
611 TackOn(dirbuf,NULL,256);
612 spath=dirbuf;
614 else {
615 cust=custgetfirst(funcdata);
616 spath=funcdata->source_path;
618 while (a<MAXCOMMANDLEN && (cust || funcdata->recursive_path)) {
619 if (funcdata->recursive_path || (cust->selected && cust->type!=0)) {
620 if (!funcdata->recursive_path && cust->type>0) {
621 if (star) {
622 LFreeRemember(&rec_pathkey);
623 funcdata->entry_current=cust;
624 StrCombine(buf3,spath,cust->name,256);
625 if (recursedir(buf3,NULL,R_STARDIR,0)) return(0);
626 setdirsize(cust,dos_global_bytecount,funcdata->activewin);
627 funcdata->recursive_path=rec_firstpath;
628 goto addfile4;
630 else {
631 if ((a+strlen(cust->name)+strlen(spath)+qad)>(MAXCOMMANDLEN-1)) break;
632 addfilename(buffer,spath,cust->name,quote);
633 if (function[pos]!=FUNC_ALLPATHS_NO)
634 custunselect(cust,reload,funcdata);
637 else {
638 addfile4:
639 if (funcdata->recursive_path) {
640 if ((a+strlen(funcdata->recursive_path->path)+qad)>(MAXCOMMANDLEN-1)) break;
641 addfilename(buffer,funcdata->recursive_path->path,NULL,quote);
642 if (!(funcdata->recursive_path=funcdata->recursive_path->next)) {
643 if (function[pos]!=FUNC_ALLPATHS_NO)
644 custunselect(funcdata->entry_current,reload,funcdata);
647 else {
648 if ((a+strlen(cust->name)+strlen(spath)+qad)>(MAXCOMMANDLEN-1)) break;
649 addfilename(buffer,spath,cust->name,quote);
650 if (function[pos]!=FUNC_ALLPATHS_NO)
651 custunselect(cust,reload,funcdata);
654 StrConcat(buffer," ",MAXCOMMANDLEN);
655 a=strlen(buffer);
657 if (!funcdata->recursive_path) {
658 if (cust) cust=cust->next;
659 // custnextsel(&funcdata->entry_first);
662 if (!funcdata->recursive_path) {
663 //D(bug("funcdata->entry_first: %s\t",funcdata->entry_first->name));
664 custnextsel(&funcdata->entry_first);
665 //D(bug("->\tfuncdata->entry_first: %s\n",funcdata->entry_first->name));
667 bufpos+=a-d;
668 if (moretodo) *moretodo=1;
670 else {
671 bufpos+=addfilename(buffer,funcdata->source_path,func_single_file,quote);
672 StrConcat(buffer," ",MAXCOMMANDLEN);
673 ++bufpos;
675 break;
677 case FUNC_SOURCE:
678 case FUNC_SOURCE_RR:
679 strcpy(buf3,funcdata->source_path);
680 if ((status_iconified || status_flags&STATUS_FROMHOTKEY)) {
681 if (dirrequester(&funcdata->file_request,buf3,
682 globstring[STR_SELECT_SOURCE_DIR])) {
683 myabort();
684 return(0);
686 StrConcat(buffer,buf3,MAXCOMMANDLEN);
687 bufpos=strlen(buffer);
689 else {
690 StrConcat(buffer,funcdata->source_path,MAXCOMMANDLEN);
691 bufpos+=sblen;
693 case FUNC_NOSOURCE_RR:
694 if (function[pos]!=FUNC_SOURCE) funcdata->rereadsource=1;
695 break;
697 case FUNC_DEST:
698 case FUNC_DEST_RR:
699 if (!(check_dest_path(funcdata))) return(0);
700 StrConcat(buffer,funcdata->dest_path,MAXCOMMANDLEN);
701 bufpos+=strlen(funcdata->dest_path);
702 case FUNC_NODEST_RR:
703 if (function[pos]!=FUNC_DEST) funcdata->rereaddest=1;
704 break;
706 case FUNC_SCREENNAME:
707 StrConcat(buffer,str_arexx_portname,MAXCOMMANDLEN);
708 bufpos+=strlen(str_arexx_portname);
709 break;
711 case FUNC_QUERYINFO:
712 ++pos;
714 char *data=NULL;
716 switch (function[pos]) {
718 /* Public screen name */
719 case 's':
720 data=get_our_pubscreen();
721 break;
723 /* ARexx port name */
724 case 'p':
725 data=str_arexx_portname;
726 break;
728 /* Last result */
729 case 'r':
730 data=str_last_rexx_result;
731 break;
734 if (data && data[0]) {
735 StrConcat(buffer,data,MAXCOMMANDLEN);
736 bufpos+=strlen(data);
739 break;
741 case FUNC_VARIABLE:
742 tit=0;
744 for (pos++;pos<line_len;pos++) {
745 if (function[pos]==FUNC_ENDARG) break;
746 if (tit<79) titlebuf[tit++]=function[pos];
748 titlebuf[tit]=0;
750 // if (system_version2) {
751 if ((a=GetVar(titlebuf,buf3,256,0))>0) {
752 StrConcat(buffer,buf3,MAXCOMMANDLEN);
753 bufpos+=a;
755 // }
756 break;
758 case FUNC_GETARG:
759 if (funcdata->function_count && funcdata->arg_use) {
760 use_old_arg:
761 StrConcat(buffer,funcdata->arg_use->argstring,MAXCOMMANDLEN);
762 bufpos+=strlen(funcdata->arg_use->argstring);
763 funcdata->arg_use=funcdata->arg_use->next;
764 for (f=pos+1;f<line_len && function[f]!=FUNC_ENDARG;f++);
765 pos=f;
766 break;
768 case FUNC_STDARG:
769 if (funcdata->function_count==-1 && funcdata->arg_use) goto use_old_arg;
770 buftitpos=-1;
771 def=0;
772 tit=0;
774 for (f=pos+1;f<line_len;f++) {
775 if (function[f]==FUNC_ENDARG) break;
776 else if (buftitpos==-1) {
777 if (function[f]==':') buftitpos=f+1;
778 else if (tit<79) titlebuf[tit++]=function[f];
780 else if (def<255) defbuf[def++]=function[f];
782 titlebuf[tit]=0;
783 defbuf[def]=0;
785 if (!titlebuf[0]) ptr=globstring[STR_ENTER_ARGUMENTS];
786 else ptr=titlebuf;
788 buf3[0]=0;
789 if (buftitpos>-1)
790 build_default_string(defbuf,buf3,funcdata->last_file,funcdata->source_path,funcdata->dest_path);
792 if (!(whatsit(ptr,256,buf3,NULL))) {
793 myabort();
794 return(0);
797 if (function[pos]==FUNC_GETARG) {
798 if (!(arg=LAllocRemember(&funcdata->arg_memkey,sizeof(struct args),MEMF_CLEAR)))
799 return(0);
800 if (!funcdata->arg_first) funcdata->arg_first=arg;
801 else funcdata->arg_current->next=arg;
802 funcdata->arg_current=arg;
803 strcpy(funcdata->arg_current->argstring,buf3);
805 StrConcat(buffer,buf3,MAXCOMMANDLEN);
806 bufpos+=strlen(buf3);
807 pos=f;
808 break;
810 case FUNC_REQUESTER:
811 if (funcdata->file_request.filearray) {
812 domultifiles:
813 while (bufpos<MAXCOMMANDLEN) {
814 if (funcdata->file_request.filearray[funcdata->fileargpos][0]) {
815 if ((bufpos+strlen(funcdata->file_request.filearray[funcdata->fileargpos])+qad)<MAXCOMMANDLEN) {
816 bufpos+=addfilename(buffer,
817 funcdata->file_request.filearray[funcdata->fileargpos],NULL,quote);
818 StrConcat(buffer," ",MAXCOMMANDLEN); ++bufpos;
819 ++funcdata->fileargpos;
821 else {
822 if (moretodo) *moretodo=1;
823 break;
826 if (!funcdata->file_request.filearray[funcdata->fileargpos][0]) {
827 LFreeRemember(&funcdata->file_request.filearraykey);
828 funcdata->file_request.filearray=NULL;
829 break;
832 for (f=pos+1;f<line_len;f++)
833 if (function[f]==FUNC_ENDARG || function[f]==0) break;
834 pos=f;
835 break;
837 h=-1;
838 switch (function[pos+1]) {
839 case 'f': h=0; break;
840 case 'F': h=DFRF_MULTI; break;
841 case 'd': h=DFRF_DIRREQ; break;
842 case 'o': h=DFRF_FONT; break;
844 if (h==-1) break;
845 ++pos;
846 buftitpos=-1;
847 for (f=pos+1;f<line_len;f++) {
848 if (function[f]==':' && buftitpos==-1) {
849 function[f]=0;
850 buftitpos=f+1;
852 if (function[f]==FUNC_ENDARG) {
853 function[f]=0;
854 break;
857 if (!function[(pos+1)]) funcdata->file_request.title=globstring[STR_FILE_REQUEST];
858 else funcdata->file_request.title=(char *)function+pos+1;
859 buf3[0]=0;
860 if (buftitpos>-1)
861 build_default_string(&function[buftitpos],buf3,funcdata->last_file,funcdata->source_path,funcdata->dest_path);
862 else if (h&DFRF_FONT) strcpy(buf3,"FONTS:");
863 funcdata->file_request.dirbuf=buf3;
864 funcdata->file_request.filebuf=filebuf; filebuf[0]=0;
865 if (!(h&DFRF_DIRREQ)) {
866 ptr=BaseName(buf3);
867 if (ptr>buf3) {
868 if (ptr[(strlen(ptr)-1)]!='/') {
869 strcpy(filebuf,ptr);
870 *ptr=0;
874 funcdata->file_request.flags=h;
875 if (FileRequest(&funcdata->file_request)) {
876 if (h&DFRF_MULTI) {
877 funcdata->fileargpos=0;
878 goto domultifiles;
880 if (!funcdata->file_request.dirbuf[0])
881 expand_path("",funcdata->file_request.dirbuf);
882 if (!(h&DFRF_DIRREQ)) {
883 if (quote) StrConcat(buffer,"\"",MAXCOMMANDLEN);
884 StrConcat(buffer,funcdata->file_request.dirbuf,MAXCOMMANDLEN);
885 TackOn(buffer,filebuf,MAXCOMMANDLEN);
886 if (quote) StrConcat(buffer,"\"",MAXCOMMANDLEN);
888 else StrConcat(buffer,funcdata->file_request.dirbuf,MAXCOMMANDLEN);
889 bufpos=strlen(buffer);
891 else {
892 myabort();
893 return(0);
895 pos=f;
896 break;
897 default:
898 buffer[bufpos++]=function[pos];
899 break;
901 if (bufpos==MAXCOMMANDLEN) break;
903 buffer[MAXCOMMANDLEN-1]=0;
904 return(1);
907 int addfilename(buf,part1,part2,quote)
908 char *buf,*part1,*part2;
909 int quote;
911 int c=0,d;
913 //D(bug("addfilename(%s,%s,%s,%ld\n",buf,part1,part2,quote));
914 d=strlen(buf);
915 if (d>0 && !(_isspace(buf[d-1]))) quote=0;
917 if (quote) {
918 StrConcat(buf,"\"",MAXCOMMANDLEN);
919 ++c;
921 if (part1) {
922 StrConcat(buf,part1,MAXCOMMANDLEN);
923 c+=strlen(part1);
925 if (part2) {
926 StrConcat(buf,part2,MAXCOMMANDLEN);
927 c+=strlen(part2);
929 if (quote) {
930 StrConcat(buf,"\"",MAXCOMMANDLEN);
931 ++c;
933 //D(bug("buf(%ld): %s\n",strlen(buf),buf));
934 return(c);
937 void parserunline(buf,buf1)
938 char *buf;
939 unsigned char *buf1;
941 int a,b,c,d;
943 a=strlen(buf);
944 bzero(buf1,256);//for (c=0;c<256;c++) buf1[c]=0;
945 c=0;
946 for (b=0;b<a;b++) {
947 if (c==256) break;
948 if (buf[b]=='{') {
949 if ((b+2)>=a) {
950 buf1[c]=buf[b];
951 ++c;
952 continue;
954 if (buf[(b+1)]=='{') {
955 buf1[c]=buf[b];
956 ++b; ++c;
957 continue;
960 switch (buf[(b+1)]) {
961 case 'a':
962 buf1[c]=FUNC_GETARG;
963 case 'A':
964 if (buf[(b+1)]=='A') buf1[c]=FUNC_STDARG;
965 case 'v':
966 if (buf[(b+1)]=='v') buf1[c]=FUNC_VARIABLE;
967 case 'R':
968 if (buf[(b+1)]=='R') {
969 if (buf[(b+2)]=='s') {
970 buf1[c]=FUNC_GETARG;
971 ++b;
973 else if (buf[(b+2)]=='S') {
974 buf1[c]=FUNC_STDARG;
975 ++b;
977 else buf1[c]=FUNC_REQUESTER;
979 ++c;
980 for (d=(b+2);d<a;d++) {
981 if (buf[d]=='}') break;
982 buf1[c]=buf[d];
983 ++c;
984 if (c==255) break;
986 buf1[c++]=FUNC_ENDARG;
987 b=d;
988 continue;
990 case 'Q':
991 buf1[c++]=FUNC_QUERYINFO;
992 buf1[c++]=buf[b+2];
993 b+=3;
994 continue;
997 switch (buf[(b+2)]) {
998 case 'r':
999 if (buf[(b+1)]=='d') buf1[c]=FUNC_DEST_RR;
1000 else if (buf[(b+1)]=='s') buf1[c]=FUNC_SOURCE_RR;
1001 else if (buf[(b+1)]=='S') buf1[c]=FUNC_NOSOURCE_RR;
1002 else if (buf[(b+1)]=='D') buf1[c]=FUNC_NODEST_RR;
1003 b+=3; ++c;
1004 continue;
1006 case 'u':
1007 if (buf[(b+1)]=='o') buf1[c]=FUNC_ONEFILE_NO;
1008 else if (buf[(b+1)]=='O') buf1[c]=FUNC_ALLFILES_NO;
1009 else if (buf[(b+1)]=='f') buf1[c]=FUNC_ONEPATH_NO;
1010 else if (buf[(b+1)]=='F') buf1[c]=FUNC_ALLPATHS_NO;
1011 b+=3; ++c;
1012 continue;
1014 case '}':
1015 switch (buf[(b+1)]) {
1016 case 'o': buf1[c]=FUNC_ONEFILE; break;
1017 case 'O': buf1[c]=FUNC_ALLFILES; break;
1018 case 's': buf1[c]=FUNC_SOURCE; break;
1019 case 'd': buf1[c]=FUNC_DEST; break;
1020 case 'f': buf1[c]=FUNC_ONEPATH; break;
1021 case 'F': buf1[c]=FUNC_ALLPATHS; break;
1022 case 'p': buf1[c]=FUNC_SCREENNAME; break;
1024 b+=2; ++c;
1025 continue;
1028 buf1[c]=buf[b];
1029 ++c;
1030 if (c==256) break;
1034 void custunselect(dir,rel,funcdata)
1035 struct Directory *dir;
1036 int rel;
1037 struct function_data *funcdata;
1039 struct recpath *temp;
1040 int win;
1042 win=funcdata->activewin;
1044 if (!status_iconified && !(status_flags&STATUS_FROMHOTKEY) && !func_external_file[0]) {
1045 if (rel && dir->name[0]) {
1046 if ((temp=LAllocRemember(&funcdata->reload_memkey,sizeof(struct recpath),MEMF_CLEAR)) &&
1047 (temp->path=LAllocRemember(&funcdata->reload_memkey,FILEBUF_SIZE,MEMF_CLEAR))) {
1048 strcpy(temp->path,dir->name);
1049 if (funcdata->reload_current) funcdata->reload_current->next=temp;
1050 funcdata->reload_current=temp;
1051 if (!funcdata->reload_first) funcdata->reload_first=temp;
1052 temp->next=NULL;
1055 unselect(win,dir);
1059 void doreloadfiles(funcdata)
1060 struct function_data *funcdata;
1062 char buf[256];
1063 struct recpath *rel;
1064 int off;
1066 rel=funcdata->reload_first;
1067 off=dopus_curwin[funcdata->activewin]->offset;
1068 while (rel) {
1069 StrCombine(buf,funcdata->source_path,rel->path,256);
1070 reload_file(funcdata->activewin,buf);
1071 rel=rel->next;
1073 dopus_curwin[funcdata->activewin]->offset=off;
1074 refreshwindow(funcdata->activewin,0);
1077 struct Directory *reload_file(win,name)
1078 int win;
1079 char *name;
1081 struct FileInfoBlock __aligned fileinfo;
1082 struct Directory *cust,*ret=NULL;
1084 if ((lockandexamine(name,&fileinfo))) {
1085 if ((cust=findfile(dopus_curwin[win],fileinfo.fib_FileName,NULL)))
1086 removefile(cust,dopus_curwin[win],win,FALSE);
1087 ret=(struct Directory *)addfile(dopus_curwin[win],
1088 win,fileinfo.fib_FileName,fileinfo.fib_Size,
1089 fileinfo.fib_DirEntryType,&(fileinfo.fib_Date),fileinfo.fib_Comment,
1090 fileinfo.fib_Protection,0,FALSE,NULL,NULL,fileinfo.fib_OwnerUID,fileinfo.fib_OwnerGID);
1092 else {
1093 if ((cust=findfile(dopus_curwin[win],BaseName(name),NULL)))
1094 removefile(cust,dopus_curwin[win],win,FALSE);
1096 return(ret);
1099 int openscriptfile(par,funcdata)
1100 struct dopusfuncpar *par;
1101 struct function_data *funcdata;
1103 struct FileInfoBlock __aligned fileinfo;
1104 char buf[256],buf2[256];
1105 BPTR lock;
1106 int a;
1108 if (funcdata->output_file) return(1);
1110 if (par->which&FLAG_CDSOURCE && !funcdata->source_path[0]) {
1111 if (!(simplerequest(globstring[STR_NO_SOURCE_SELECTED],
1112 globstring[STR_CONTINUE],str_cancelstring,NULL))) {
1113 myabort();
1114 return(0);
1117 else if (par->which&FLAG_CDDEST && !funcdata->dest_path[0]) {
1118 if (!(simplerequest(globstring[STR_NO_DESTINATION_SELECTED],
1119 globstring[STR_CONTINUE],str_cancelstring,NULL))) {
1120 myabort();
1121 return(0);
1125 makereselect(&func_reselection,funcdata->activewin);
1127 main_proc->pr_WindowPtr=(APTR)-1;
1128 if (CheckExist("T:",NULL)) strcpy(buf,"T:");
1129 else strcpy(buf,"RAM:");
1131 if ((lock=Lock(buf,ACCESS_READ))) {
1132 Examine(lock,&fileinfo);
1133 if (ExNext(lock,&fileinfo)) {
1134 FOREVER {
1135 if (LStrnCmp(fileinfo.fib_FileName,"dopustemp",9)==0)
1136 lsprintf(funcdata->scriptname,"%s%s",buf,fileinfo.fib_FileName);
1137 else funcdata->scriptname[0]=0;
1138 a=ExNext(lock,&fileinfo);
1139 if (funcdata->scriptname[0]) DeleteFile(funcdata->scriptname);
1140 if (!a) break;
1143 UnLock(lock);
1145 if (config->errorflags&ERROR_ENABLE_DOS) main_proc->pr_WindowPtr=(APTR)Window;
1147 for (a=0;a<100;a++) {
1148 lsprintf(funcdata->scriptname,"%sdopustemp.tmp%ld",buf,(long int)a);
1149 if ((funcdata->output_file=Open(funcdata->scriptname,MODE_NEWFILE))) break;
1151 if (!funcdata->output_file) {
1152 doerror(-1);
1153 return(0);
1156 lsprintf(funcdata->tempfile,"%sdopusout.tmp%ld",buf,(long int)a);
1158 rec_pathkey=NULL;
1160 lsprintf(buf,"\"%s\" -s\n",str_dopusrt_path);
1161 Write(funcdata->output_file,buf,strlen(buf));
1163 if (par->which&FLAG_SHELLUP) {
1164 if (config->shellstartup[0]) StrCombine(buf,"S:",config->shellstartup,40);
1165 else strcpy(buf,"S:Shell-Startup");
1166 if (CheckExist(buf,NULL)) {
1167 lsprintf(buf2,"Execute %s\n",buf);
1168 Write(funcdata->output_file,buf2,strlen(buf2));
1171 if (par->which&FLAG_DOPUSUP) {
1172 if (CheckExist("S:DOpus-Startup",NULL))
1173 Write(funcdata->output_file,"Execute S:DOpus-Startup\n",24);
1174 else if (CheckExist("S:DOpusShell-Startup",NULL))
1175 Write(funcdata->output_file,"Execute S:DOpusShell-Startup\n",29);
1177 Write(funcdata->output_file,"FailAt 999999\n",14);
1179 buf[0]=0;
1180 if (status_flags&STATUS_FROMHOTKEY) {
1181 expand_path("",buf2);
1182 lsprintf(buf,"CD \"%s\"\n",buf2);
1184 else {
1185 if (par->which&FLAG_CDSOURCE && funcdata->source_path[0])
1186 lsprintf(buf,"CD \"%s\"\n",funcdata->source_path);
1187 else if (par->which&FLAG_CDDEST) {
1188 if (!(check_dest_path(funcdata))) return(0);
1189 lsprintf(buf,"CD \"%s\"\n",funcdata->dest_path);
1192 if (buf[0]) Write(funcdata->output_file,buf,strlen(buf));
1194 lsprintf(buf,"Stack %ld\n",(long int)((par->stack<4000)?4000:par->stack));
1195 Write(funcdata->output_file,buf,strlen(buf));
1197 if (par->pri!=0) {
1198 lsprintf(buf,"ChangeTaskPri %ld\n",(long int)par->pri);
1199 Write(funcdata->output_file,buf,strlen(buf));
1202 return(1);
1205 int closescriptfile(par,run,funcdata)
1206 struct dopusfuncpar *par;
1207 int run;
1208 struct function_data *funcdata;
1210 struct MsgPort *msgport;
1211 struct Message *msg;
1212 char buf[256],buf2[512],portname[50],pubname[140];
1213 int wb2f,setcust=0,otemp=0,oldmodes,okayflag=0,bit,flags=0;
1214 BPTR tnil=NULL;
1216 if (run>0 && par && funcdata->output_file) {
1217 flags=par->which;
1218 if (flags&FLAG_OUTFILE && status_flags&STATUS_FROMHOTKEY) {
1219 flags&=~FLAG_OUTFILE;
1220 flags|=FLAG_OUTWIND;
1223 okayflag=1;
1224 wb2f=flags&FLAG_WB2F;
1225 msgport=NULL;
1226 endnotifies();
1228 if (flags&FLAG_OUTWIND) {
1229 lsprintf(buf2,"%s \"%s\" from %s",config->outputcmd,config->output,funcdata->scriptname);
1230 if (!(flags&FLAG_ASYNC)) {
1231 lsprintf(portname,"dopus_run%ld",(long int)system_dopus_runcount);
1232 if (!(msgport=LCreatePort(portname,0))) goto freeargs;
1234 else wb2f=1;
1236 else lsprintf(buf2,"%sExecute %s",(flags&FLAG_ASYNC)?"Run ":"",funcdata->scriptname);
1238 if (flags&FLAG_OUTWIND) {
1239 if (par->delay!=0) {
1240 lsprintf(buf,"\"%s\" -w %ld \"%s\"\n",
1241 str_dopusrt_path,
1242 (long int)par->delay,
1243 globstring[STR_PRESS_MOUSE_BUTTON]);
1244 Write(funcdata->output_file,buf,strlen(buf));
1246 if (msgport) {
1247 lsprintf(buf,"\"%s\" -p %s\n",str_dopusrt_path,portname);
1248 Write(funcdata->output_file,buf,strlen(buf));
1250 Write(funcdata->output_file,"EndCLI >NIL:\n",13);
1253 if (str_arcorgname[0])
1255 lsprintf(buf,"Delete \"%s\"\n",funcdata->last_file);
1257 Write(funcdata->output_file,buf,strlen(buf));
1258 str_arcorgname[0] = 0;
1261 Close(funcdata->output_file); funcdata->output_file=0;
1263 if (wb2f && (!(flags&FLAG_ASYNC) || !(flags&FLAG_DOPUSF)))
1264 WBenchToFront();
1265 if (flags&FLAG_OUTWIND && !wb2f && MainScreen) {
1266 // if (system_version2) {
1267 oldmodes=SetPubScreenModes(SHANGHAI);
1268 GetDefaultPubScreen(pubname);
1269 SetDefaultPubScreen((UBYTE *)str_arexx_portname);
1270 /* }
1271 else {
1272 Forbid();
1273 MainScreen->Flags&=~CUSTOMSCREEN;
1274 MainScreen->Flags|=WBENCHSCREEN;
1275 Permit();
1276 } */
1277 setcust=1;
1280 if (flags&FLAG_OUTFILE && (tnil=Open(funcdata->tempfile,MODE_NEWFILE))) otemp=1;
1281 if (!tnil) tnil=Open("NIL:",MODE_NEWFILE);
1283 // Execute(buf2,0,(BPTR)tnil);
1284 SystemTags(buf2,SYS_Input,Open("NIL:",MODE_OLDFILE),SYS_Output,tnil,SYS_Asynch,flags&FLAG_ASYNC,TAG_END);
1286 if (flags&FLAG_OUTWIND && !wb2f &&
1287 #ifdef _USE_SMALL_Q
1288 !(status_flags&STATUS_IANSCRAP) &&
1289 #endif
1290 MainScreen) {
1291 // if (system_version2) {
1292 SetDefaultPubScreen(pubname);
1293 SetPubScreenModes(oldmodes);
1294 /* }
1295 else {
1296 Forbid();
1297 MainScreen->Flags&=~WBENCHSCREEN;
1298 MainScreen->Flags|=CUSTOMSCREEN;
1299 Permit();
1300 } */
1301 setcust=0;
1304 if (msgport && Window) {
1305 SetSignal(0,INPUTSIG_ABORT);
1306 FOREVER {
1307 if ((bit=Wait(1<<msgport->mp_SigBit|rexx_signalbit|INPUTSIG_ABORT))
1308 &INPUTSIG_ABORT) {
1309 status_justabort=status_haveaborted=0;
1310 break;
1312 if (bit&rexx_signalbit) {
1313 rexx_dispatch(0);
1314 continue;
1316 if ((msg=GetMsg(msgport))) {
1317 ReplyMsg(msg);
1318 break;
1321 LDeletePort(msgport);
1324 if (!(flags&FLAG_ASYNC) && tnil) Close(tnil);
1326 if (setcust) {
1327 // if (system_version2) {
1328 SetDefaultPubScreen(pubname);
1329 SetPubScreenModes(oldmodes);
1330 /* }
1331 else {
1332 Forbid();
1333 MainScreen->Flags&=~WBENCHSCREEN;
1334 MainScreen->Flags|=CUSTOMSCREEN;
1335 Permit();
1336 } */
1339 if (flags&FLAG_DOPUSF) {
1340 if (MainScreen) ScreenToFront(MainScreen);
1341 if (Window && !Window->Flags&WFLG_BACKDROP) WindowToFront(Window);
1344 if (!status_iconified && !(status_flags&STATUS_FROMHOTKEY)) {
1345 if (funcdata->rereadsource || flags&FLAG_SCANSRCE) {
1346 startgetdir(funcdata->activewin,0);
1347 funcdata->reload_first=NULL;
1349 if (funcdata->rereaddest || flags&FLAG_SCANDEST)
1350 startgetdir(funcdata->inactivewin,0);
1351 if (flags&FLAG_RELOAD && funcdata->reload_first) doreloadfiles(funcdata);
1355 freeargs:
1356 if (funcdata->output_file) Close(funcdata->output_file);
1357 if ((funcdata->output_file || okayflag) && funcdata->scriptname[0] &&
1358 (!par || !(flags&FLAG_ASYNC)))
1359 DeleteFile(funcdata->scriptname);
1360 funcdata->output_file=NULL;
1361 funcdata->scriptname[0]=0;
1362 funcdata->rereaddest=funcdata->rereadsource=0;
1364 LFreeRemember(&funcdata->arg_memkey);
1365 if (otemp) {
1366 viewfile(funcdata->tempfile,globstring[STR_TEMPORARY_OUTPUT_FILE],FUNC_SMARTREAD,NULL,NULL,1,0);
1367 DeleteFile(funcdata->tempfile);
1369 LFreeRemember(&rec_pathkey);
1370 LFreeRemember(&funcdata->reload_memkey);
1372 if (Window && !(status_flags&STATUS_FROMHOTKEY)) unbusy();
1373 if (status_flags&STATUS_VERIFYFAIL) myabort();
1374 else if (okayflag) {
1375 if (Window && !status_iconified && !(status_flags&STATUS_FROMHOTKEY)) okay();
1376 if (flags&FLAG_ICONIFY && checkwindowquit()) iconify(2,0,0);
1377 else startnotifies();
1379 return(run);
1382 int getdummyfile(fbuf,dirbuf,freq)
1383 struct Directory *fbuf;
1384 char *dirbuf;
1385 struct DOpusFileReq *freq;
1387 char file[FILEBUF_SIZE],buf[300];
1389 freq->x=freq->y=-2;
1390 freq->title=globstring[STR_SELECT_A_FILE]; file[0]=0;
1391 freq->dirbuf=dirbuf; freq->filebuf=file;
1392 freq->window=Window;
1393 freq->lines=15; freq->flags=0;
1394 if (!dirbuf[0]) expand_path("",dirbuf);
1395 if (!(FileRequest(freq))) {
1396 myabort();
1397 return(0);
1399 if (!dirbuf[0]) expand_path("",dirbuf);
1400 if (fbuf) {
1401 strcpy(buf,dirbuf); TackOn(buf,file,256);
1402 return(filloutdummy(buf,fbuf));
1404 strcpy(func_single_file,file);
1405 return(1);
1408 int filloutdummy(name,fbuf)
1409 char *name;
1410 struct Directory *fbuf;
1412 struct FileInfoBlock __aligned fib;
1414 if (!(lockandexamine(name,&fib))) return(0);
1415 fbuf->last=fbuf->next=NULL;
1416 strcpy(fbuf->name,fib.fib_FileName);
1417 fbuf->type=fib.fib_DirEntryType;
1418 if (fbuf->type>=0) fbuf->size=-1;
1419 else fbuf->size=fib.fib_Size;
1420 fbuf->subtype=0;
1421 fbuf->protection=fib.fib_Protection;
1422 fbuf->comment=fbuf->dispstr=NULL;
1423 getprot(fbuf->protection,fbuf->protbuf);
1424 seedate(&fib.fib_Date,fbuf->datebuf,1);
1425 CopyMem((char *)&fib.fib_Date,&fbuf->date,sizeof(struct DateStamp));
1426 fbuf->selected=1;
1427 return(1);
1430 int dirrequester(freq,buf,title)
1431 struct DOpusFileReq *freq;
1432 char *buf,*title;
1434 if (title) freq->title=title;
1435 else freq->title=globstring[STR_SELECT_A_DIRECTORY];
1436 freq->dirbuf=buf;
1437 freq->flags=DFRF_DIRREQ;
1438 if (!buf[0]) expand_path("",buf);
1439 if (FileRequest(freq)) {
1440 if (!buf[0]) expand_path("",buf);
1441 return(1);
1443 return(0);
1446 void do_title_string(string,buf,ml,name)
1447 char *string,*buf;
1448 int ml;
1449 char *name;
1451 int a,b,c;
1453 a=strlen(string); c=0;
1454 for (b=0;b<a;b++) {
1455 if (string[b]=='%') {
1456 buf[c]=0;
1457 if (name) strcat(buf,name);
1458 else addreqfilename(buf,data_active_window);
1459 c=strlen(buf);
1461 else {
1462 if (ml && string[b]=='\\') buf[c]='\n';
1463 else buf[c]=string[b];
1464 ++c;
1466 if (c==(256+(ml*262))) break;
1468 buf[c]=0;
1471 void addreqfilename(buf,win)
1472 char *buf;
1473 int win;
1475 struct Directory *dir;
1477 if (func_single_file[0]) strcat(buf,func_single_file);
1478 else {
1479 dir=dopus_curwin[win]->firstentry;
1480 while (dir) {
1481 if (dir->selected && dir->type<0) break;
1482 dir=dir->next;
1484 if (dir && dir->selected && dir->type<0) strcat(buf,dir->name);
1488 struct Directory *custgetfirst(funcdata)
1489 struct function_data *funcdata;
1491 struct Directory *file;
1493 file=funcdata->entry_first;
1494 while (file) {
1495 if ((file->type!=0) && (file->selected) && (file->type!=ENTRY_CUSTOM)) return(file);
1496 file=file->next;
1498 return(NULL);
1501 void custnextsel(dir)
1502 struct Directory **dir;
1504 while (*dir) {
1505 if (!(*dir=(*dir)->next)) break;
1506 if ((*dir)->selected) break;
1510 int check_dest_path(funcdata)
1511 struct function_data *funcdata;
1513 if (funcdata->dest_path[0]) return(1);
1514 if ((status_iconified || status_flags&STATUS_FROMHOTKEY) &&
1515 ((dirrequester(&funcdata->file_request,
1516 funcdata->dest_path,globstring[STR_SELECT_DESTINATION_DIR])) ||
1517 !funcdata->dest_path[0])) {
1518 myabort();
1519 return(0);
1521 if (!funcdata->dest_path[0]) {
1522 dostatustext(globstring[STR_NO_DESTINATION_SELECTED]);
1523 simplerequest(globstring[STR_NO_DESTINATION_SELECTED],
1524 globstring[STR_CONTINUE],NULL);
1525 return(0);
1527 return(1);
1530 int getdummypath(dir,title)
1531 char *dir;
1532 int title;
1534 struct DOpusFileReq freq;
1535 int a;
1537 freq.window=Window;
1538 freq.lines=15;
1539 freq.x=freq.y=-2;
1540 if ((a=dirrequester(&freq,dir,globstring[title])))
1541 if (!dir[0]) expand_path("",dir);
1542 return(a);
1545 void build_default_string(string,buffer,filename,sourcepath,destpath)
1546 char *string,*buffer,*filename,*sourcepath,*destpath;
1548 int len,a,pos,flag;
1549 char *ptr;
1551 len=strlen(string);
1552 pos=0;
1553 for (a=0;a<len && pos<255;a++) {
1554 if (string[a]=='[' && string[a+2]==']') {
1555 flag=1;
1556 switch (string[a+1]) {
1557 case 'f':
1558 LStrnCpy(&buffer[pos],filename,255-pos);
1559 break;
1560 case 'o':
1561 if ((ptr=BaseName(filename))) LStrnCpy(&buffer[pos],ptr,255-pos);
1562 break;
1563 case 's':
1564 LStrnCpy(&buffer[pos],sourcepath,255-pos);
1565 break;
1566 case 'd':
1567 LStrnCpy(&buffer[pos],destpath,255-pos);
1568 break;
1569 default:
1570 flag=0;
1571 break;
1573 if (flag) {
1574 pos=strlen(buffer);
1575 a+=2;
1576 continue;
1579 buffer[pos++]=string[a];