home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 3 / CD_Magazyn_EXEC_nr_3.iso / Internet / Strony_WWW / Opus4.x / DOpus414JRsrc.lha / DirectoryOpus4 / Program / custom.c < prev    next >
C/C++ Source or Header  |  2000-03-27  |  55KB  |  1,530 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  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.
  11.  
  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.
  16.  
  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.
  20.  
  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.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "dopus.h"
  32.  
  33. void defaultpar(par)
  34. struct dopusfuncpar *par;
  35. {
  36.     if (status_flags&STATUS_IANSCRAP) {
  37.         par->which=FLAG_OUTWIND;
  38.         par->delay=-1;
  39.     }
  40.     else {
  41.         par->which=FLAG_OUTWIND|FLAG_WB2F|FLAG_DOPUSF|FLAG_CDSOURCE;
  42.         par->delay=2;
  43.     }
  44.     par->key=par->qual=par->type=0;
  45.     par->pri=config->priority; par->stack=8000;
  46. }
  47.  
  48. void dofunctionstring(func,name,title,pars)
  49. char *func,*name,*title;
  50. struct dopusfuncpar *pars;
  51. {
  52.     char fbuf[256],*ptr;
  53.     int a,b,c,lb,ls,run=1,noloop=0,norm=1;
  54.     struct Directory *curcf;
  55.     struct function_data *funcdata;
  56.  
  57.     if (!func || !func[0] ||
  58.         !(funcdata=LAllocRemember(&general_key,sizeof(struct function_data),MEMF_CLEAR))) return;
  59.  
  60.     a=strlen(func);
  61.     status_flags&=~STATUS_VERIFYFAIL;
  62.     if (Window && !(status_flags&STATUS_FROMHOTKEY)) busy();
  63.  
  64.     funcdata->activewin=data_active_window;
  65.     funcdata->inactivewin=1-data_active_window;
  66.  
  67.     funcdata->file_request.window=Window;
  68.     funcdata->file_request.lines=15;
  69.  
  70.     if (func_external_file[0]) {
  71.         noloop=1;
  72.         if (ptr=BaseName(func_external_file))
  73.             strcpy(func_single_file,ptr);
  74.         strcpy(funcdata->source_path,func_external_file);
  75.         if (ptr=BaseName(funcdata->source_path)) *ptr=0;
  76.         norm=0;
  77.         if (!status_iconified)
  78.             strcpy(funcdata->dest_path,str_pathbuffer[data_active_window]);
  79.         funcdata->activewin=1-data_active_window;
  80.         funcdata->inactivewin=data_active_window;
  81.     }
  82.     else if (func_single_file[0]) noloop=1;
  83.     else if (status_iconified) norm=0;
  84.     else funcdata->entry_first=checkalltot(dopus_curwin[funcdata->activewin]);
  85.  
  86.     if (norm) {
  87.         strcpy(funcdata->source_path,str_pathbuffer[funcdata->activewin]);
  88.         strcpy(funcdata->dest_path,str_pathbuffer[funcdata->inactivewin]);
  89.     }
  90.  
  91.     status_justabort=status_haveaborted=0;
  92.  
  93.     FOREVER {
  94.         c=lb=0; ls=-1;
  95.  
  96.         curcf=funcdata->entry_first;
  97.  
  98.         for (b=0;b<a;b++) {
  99.             if (c>0 && func[b]=='|' && lb) {
  100.                 fbuf[c-1]=0; if (ls>-1) fbuf[ls]=0;
  101.                 c=lb=0;
  102.                 if (handlefunctionss(fbuf,name,title,pars,funcdata) ||
  103.                     status_flags&STATUS_VERIFYFAIL) {
  104.                     run=0;
  105.                     break;
  106.                 }
  107.             }
  108.             else {
  109.                 if (c>0 || !isspace(func[b])) {
  110.                     if (func[b]=='|' && func[b+1]=='|') lb=1;
  111.                     else if (isspace(func[b])) {
  112.                         if (ls==-1) ls=c;
  113.                     }
  114.                     else ls=-1;
  115.                     fbuf[c++]=func[b];
  116.                 }
  117.             }
  118.         }
  119.         if (c>0) {
  120.             fbuf[c]=0; if (ls>-1) fbuf[ls]=0;
  121.             if (handlefunctionss(fbuf,name,title,pars,funcdata) ||
  122.                 status_flags&STATUS_VERIFYFAIL) run=0;
  123.         }
  124.         if (!pars || !(pars->which&FLAG_DOALL) || status_justabort || status_haveaborted ||
  125.             status_flags&STATUS_VERIFYFAIL || !run || func_single_file[0] || noloop ||
  126.             !funcdata->external_flag) break;
  127.  
  128.         if (curcf && curcf==funcdata->entry_first)
  129.             funcdata->entry_first=funcdata->entry_first->next;
  130.  
  131.         while (funcdata->entry_first) {
  132.             if (funcdata->entry_first->selected) break;
  133.             funcdata->entry_first=funcdata->entry_first->next;
  134.         }
  135.  
  136.         if (!funcdata->entry_first) break;
  137.         funcdata->arg_use=funcdata->arg_first;
  138.         ++funcdata->function_count;
  139.     }
  140.     closescriptfile(pars,run,funcdata);
  141.     func_single_file[0]=0;
  142.     func_external_file[0]=0;
  143.     LFreeRemEntry(&general_key,(char *)funcdata);
  144.  
  145.     if (norm && Window) {
  146.         for (a=0;a<2;a++) check_old_buffer(a);
  147.     }
  148. }
  149.  
  150. handlefunctionss(funcbuf,name,title,pars,funcdata)
  151. char *funcbuf,*name,*title;
  152. struct dopusfuncpar *pars;
  153. struct function_data *funcdata;
  154. {
  155.     int function,abort=0,a,b;
  156.     char *funcptr,buf2[500],newfunc[500];
  157.     struct dopusfuncpar par;
  158.     struct Directory *didselect=NULL;
  159.  
  160.     func_single_entry=NULL;
  161.  
  162.     if (funcbuf[0]==FC_INTERNAL) {
  163.         b=strlen(funcbuf);
  164.         for (a=0;a<b;a++) if (funcbuf[a]=='{') break;
  165.         if (a<b) {
  166.             parserunline(funcbuf,buf2);
  167.             if (!(buildcustfunc(buf2,strlen(funcbuf),newfunc,NULL,0,0,0,funcdata)))
  168.                 return(1);
  169.             funcbuf=newfunc;
  170.         }
  171.         if ((function=getfunction(funcbuf,&funcptr))!=-1) {
  172.             if (function!=FUNC_HELP && status_flags&STATUS_HELP) {
  173.                 dohelp(name,funcbuf,pars?pars->key:0,pars?pars->qual:0,NULL);
  174.                 abort=1;
  175.             }
  176.             else if (function==FUNC_ENDFUNCTION) closescriptfile(pars,1,funcdata);
  177.             else {
  178.                 func_entry_deleted=0;
  179.                 if (func_single_file[0]) {
  180.                     if (func_external_file[0]) {
  181.                         if (filloutdummy(func_external_file,&funcdata->entry_external)) {
  182.                             funcdata->entry_external.selected=0;
  183.                             func_single_entry=&funcdata->entry_external;
  184.                         }
  185.                     }
  186.                     else if ((func_single_entry=
  187.                         findfile(dopus_curwin[funcdata->activewin],func_single_file,NULL))) {
  188.                         func_single_entry->selected=1;
  189.                         updateselectinfo(func_single_entry,funcdata->activewin,0);
  190.                         didselect=func_single_entry;
  191.                     }
  192.                 }
  193.  
  194.                 global_swap_window=FALSE;
  195.  
  196. #ifdef DEBUG
  197. kprintf("funcbuf:\t%s\n",funcbuf);
  198. kprintf("name:\t%s\n",name);
  199. kprintf("title:\t%s\n",title);
  200. kprintf("funcptr:\t%s\n",funcptr);
  201. kprintf("buf2:\t%s\n",buf2);
  202. #endif
  203.                 if (funcptr) {
  204.                     func_global_function=function;
  205.                     rexxdisp(NULL,NULL,funcptr);
  206.                     if (func_global_function)
  207.                         abort=internal_function(func_global_function,rexx_global_flag,
  208.                             funcdata->source_path,funcdata->dest_path);
  209.                     func_global_function=0;
  210.                 }
  211.                 else abort=internal_function(function,0,funcdata->source_path,funcdata->dest_path);
  212.  
  213.                 if (global_swap_window) {
  214.                     funcdata->activewin=data_active_window;
  215.                     funcdata->inactivewin=1-data_active_window;
  216.  
  217.                     strcpy(funcdata->source_path,str_pathbuffer[funcdata->activewin]);
  218.                     strcpy(funcdata->dest_path,str_pathbuffer[funcdata->inactivewin]);
  219.  
  220.                     funcdata->entry_first=checkalltot(dopus_curwin[funcdata->activewin]);
  221.                 }
  222.  
  223.                 if (didselect && !func_entry_deleted && didselect->selected) {
  224.                     didselect->selected=0;
  225.                     updateselectinfo(didselect,funcdata->activewin,0);
  226.                 }
  227.                 func_single_entry=NULL; func_entry_deleted=0;
  228.             }
  229.         }
  230.     }
  231.     else {
  232.         funcdata->external_flag=1;
  233.         if (status_flags&STATUS_HELP) {
  234.             dohelp(name,funcbuf,pars?pars->key:0,pars?pars->qual:0,NULL);
  235.             abort=1;
  236.         }
  237.         else {
  238.             if (pars) CopyMem((char *)pars,(char *)&par,sizeof(struct dopusfuncpar));
  239.             else defaultpar(&par);
  240.             switch (funcbuf[0]) {
  241.                 case FC_WORKBENCH: par.type=FT_WORKBENCH; ++funcbuf; break;
  242.                 case FC_BATCH: par.type=FT_BATCH; ++funcbuf; break;
  243.                 case FC_AREXX: par.type=FT_AREXX; ++funcbuf; break;
  244.                 case FC_CHDIR: par.type=FT_CHDIR; ++funcbuf; break;
  245.                 default: par.type=FT_EXECUTABLE; break;
  246.             }
  247.             if (!(customthing(name,title,funcbuf,&par,funcdata))) abort=1;
  248.         }
  249.     }
  250.     return(abort);
  251. }
  252.  
  253. getfunction(func,funcptr)
  254. char *func,**funcptr;
  255. {
  256.     int a,b;
  257.  
  258.     if (funcptr) *funcptr=NULL;
  259.     if (!func) return(-1);
  260.     if (func[0]==FC_INTERNAL) {
  261.         b=0;
  262.         FOREVER {
  263.             if (commandlist[b].name==NULL) break;
  264.             a=strlen(commandlist[b].name);
  265.             if (LStrnCmpI(commandlist[b].name,&func[1],a)==0 &&
  266.                 (isspace(func[a+1]) || func[a+1]==0)) {
  267.                 if (funcptr && func[a+1]) *funcptr=&func[a+1];
  268.                 return((int)commandlist[b].function);
  269.             }
  270.             ++b;
  271.         }
  272.     }
  273.     return(-1);
  274. }
  275.  
  276. customthing(name,title,function,par,funcdata)
  277. char *name,*title,*function;
  278. struct dopusfuncpar *par;
  279. struct function_data *funcdata;
  280. {
  281.     int moretodo,a,b,len,tot,type,count;
  282.     unsigned char buf[500],*ptr;
  283.     char buf2[500],tbuf[512];
  284.     struct args *usearg,*endarg;
  285.  
  286.     if ((!name || !name[0]) && (!function || !function[0])) return(1);
  287.     if (Window && !status_iconified && !(status_flags&STATUS_FROMHOTKEY)) {
  288.         if (title) dostatustext(title);
  289.         else if (name) dostatustext(name);
  290.     }
  291.  
  292.     if ((type=par->type)==FT_AREXX) {
  293.         rexx_command(function,NULL);
  294.         return(1);
  295.     }
  296.  
  297.     if (!(openscriptfile(par,funcdata))) return(0);
  298.     if (type==FT_CHDIR) {
  299.         b=strlen(function);
  300.         for (a=1;a<b;a++) if (function[a]=='!') break;
  301.         LStrnCpy(buf2,&function[1],a-1);
  302.         lsprintf(tbuf,"CD %s\n",buf2);
  303.         Write(funcdata->output_file,tbuf,strlen(tbuf));
  304.         return(1);
  305.     }
  306.  
  307.     tot=1;
  308.  
  309.     if (!function[0]) {
  310.         ptr=(unsigned char *)name;
  311.         while (*ptr) {
  312.             if (*ptr==';') *ptr='\n';
  313.             ++ptr;
  314.         }
  315.         lsprintf(tbuf,"%s\n",name);
  316.         Write(funcdata->output_file,tbuf,strlen(tbuf));
  317.     }
  318.     else {
  319.         parserunline(function,buf);
  320.         ptr=buf;
  321.         while (*ptr) {
  322.             if (*ptr==';') *ptr='\n';
  323.             ++ptr;
  324.         }
  325.         len=strlen((char *)buf);
  326.  
  327.         count=funcdata->function_count;
  328.         endarg=usearg=funcdata->arg_use;
  329.  
  330.         FOREVER {
  331.             if (status_haveaborted) {
  332.                 closescriptfile(NULL,0,funcdata);
  333.                 myabort();
  334.                 tot=0;
  335.                 break;
  336.             }
  337.             moretodo=0;
  338.             if (!(buildcustfunc(buf,len,buf2,&moretodo,par->which&FLAG_RECURSE,par->which&FLAG_RELOAD,
  339.                 ((par->which&FLAG_NOQUOTE)?0:1),funcdata))) {
  340.                 closescriptfile(NULL,0,funcdata);
  341.                 tot=0;
  342.                 break;
  343.             }
  344.             if (type==FT_BATCH) Write(funcdata->output_file,"Execute ",8);
  345.             else if (type==FT_WORKBENCH) {
  346.                 lsprintf(tbuf,"%s -r ",str_dopusrt_path);
  347.                 Write(funcdata->output_file,tbuf,strlen(tbuf));
  348.             }
  349.             lsprintf(tbuf,"%s\n",buf2);
  350.             Write(funcdata->output_file,tbuf,strlen(tbuf));
  351.             if (moretodo &&
  352.                 (funcdata->entry_first || funcdata->file_request.filearray)) goto domorestuff;
  353.             if (!funcdata->recursive_path) break;
  354. domorestuff:
  355.             funcdata->function_count=-1;
  356.             endarg=funcdata->arg_use;
  357.             if (usearg) funcdata->arg_use=usearg->next;
  358.             if (!funcdata->arg_use) {
  359.                 if (usearg) funcdata->arg_use=usearg;
  360.                 else funcdata->arg_use=funcdata->arg_first;
  361.             }
  362.         }
  363.         funcdata->function_count=count;
  364.         funcdata->arg_use=endarg;
  365.         if (funcdata->activewin>-1)
  366.             funcdata->entry_first=checkalltot(dopus_curwin[funcdata->activewin]);
  367.     }
  368.     if (funcdata->file_request.filearray) {
  369.         LFreeRemember(&funcdata->file_request.filearraykey);
  370.         funcdata->file_request.filearray=NULL;
  371.     }
  372.     return(tot);
  373. }
  374.  
  375. buildcustfunc(function,line_len,buffer,moretodo,star,reload,quote,funcdata)
  376. unsigned char *function;
  377. int line_len;
  378. char *buffer;
  379. int *moretodo,star,reload,quote;
  380. struct function_data *funcdata;
  381. {
  382.     char buf3[500],*ptr,filebuf[FILEBUF_SIZE],dirbuf[256],*spath,defbuf[256],titlebuf[80];
  383.     int a,pos,bufpos,d,f,sblen,buftitpos,h,qad,def,tit;
  384.     struct Directory *cust,dummy;
  385.     struct args *arg;
  386.  
  387.     buffer[0]=buf3[0]=dirbuf[0]=0;
  388.     qad=quote*2;
  389.  
  390.     for (bufpos=0;bufpos<500;bufpos++) buffer[bufpos]=buf3[bufpos]=0;
  391.     bufpos=0;
  392.  
  393.     sblen=strlen(funcdata->source_path);
  394.  
  395.     for (pos=0;pos<line_len;pos++) {
  396.         switch (function[pos]) {
  397.             case FUNC_ONEFILE:
  398.             case FUNC_ONEFILE_NO:
  399.                 if (!func_single_file[0]) {
  400.                     if (status_iconified || status_flags&STATUS_FROMHOTKEY) {
  401.                         if (getdummyfile(&dummy,dirbuf,&funcdata->file_request)) cust=&dummy;
  402.                         else return(0);
  403.                     }
  404.                     else if (!funcdata->recursive_path) cust=custgetfirst(funcdata);
  405.                     if (cust) {
  406.                         strcpy(funcdata->last_file,funcdata->source_path);
  407.                         TackOn(funcdata->last_file,cust->name,256);
  408.                         if (!funcdata->recursive_path && cust->type>0) {
  409.                             if (star) {
  410.                                 LFreeRemember(&rec_pathkey);
  411.                                 funcdata->entry_current=cust;
  412.                                 StrCombine(buf3,funcdata->source_path,cust->name,256);
  413.                                 if (recursedir(buf3,NULL,R_STARDIR,strlen(funcdata->source_path)))
  414.                                     return(0);
  415.                                 setdirsize(cust,dos_global_bytecount,funcdata->activewin);
  416.                                 funcdata->recursive_path=rec_firstpath;
  417.                                 goto addfile1;
  418.                             }
  419.                             else {
  420.                                 bufpos+=addfilename(buffer,cust->name,NULL,quote);
  421.                                 if (function[pos]!=FUNC_ONEFILE_NO) {
  422.                                     custunselect(cust,reload,funcdata);
  423.                                     custnextsel(&funcdata->entry_first);
  424.                                 }
  425.                             }
  426.                         }
  427.                         else {
  428. addfile1:
  429.                             if (funcdata->recursive_path) {
  430.                                 bufpos+=addfilename(buffer,funcdata->recursive_path->path,NULL,quote);
  431.                                 if (!(funcdata->recursive_path=funcdata->recursive_path->next) &&
  432.                                     function[pos]!=FUNC_ONEFILE_NO)
  433.                                     custunselect(funcdata->entry_current,reload,funcdata);
  434.                             }
  435.                             else {
  436.                                 bufpos+=addfilename(buffer,cust->name,NULL,quote);
  437.                                 if (function[pos]!=FUNC_ONEFILE_NO) {
  438.                                     custunselect(cust,reload,funcdata);
  439.                                     custnextsel(&funcdata->entry_first);
  440.                                 }
  441.                             }
  442.                         }
  443.                     }
  444.                 }
  445.                 else {
  446.                     strcpy(funcdata->last_file,func_single_file);
  447.                     bufpos+=addfilename(buffer,func_single_file,NULL,quote);
  448.                 }
  449.                 break;
  450.  
  451.             case FUNC_ALLFILES:
  452.             case FUNC_ALLFILES_NO:
  453.                 if (!func_single_file[0]) {
  454.                     a=d=strlen(buffer);
  455.                     if (status_iconified || status_flags&STATUS_FROMHOTKEY) {
  456.                         if (getdummyfile(&dummy,dirbuf,&funcdata->file_request)) cust=&dummy;
  457.                         else return(0);
  458.                     }
  459.                     else cust=custgetfirst(funcdata);
  460.                     while (a<256 && (cust || funcdata->recursive_path)) {
  461.                         if (funcdata->recursive_path || (cust->selected && cust->type!=0)) {
  462.                             if (!funcdata->recursive_path && cust->type>0) {
  463.                                 if (star) {
  464.                                     LFreeRemember(&rec_pathkey);
  465.                                     funcdata->entry_current=cust;
  466.                                     StrCombine(buf3,funcdata->source_path,cust->name,256);
  467.                                     if (recursedir(buf3,NULL,R_STARDIR,strlen(funcdata->source_path)))
  468.                                         return(0);
  469.                                     setdirsize(cust,dos_global_bytecount,funcdata->activewin);
  470.                                     funcdata->recursive_path=rec_firstpath;
  471.                                     goto addfile2;
  472.                                 }
  473.                                 else {
  474.                                     if ((a+strlen(cust->name)+qad)>255) break;
  475.                                     addfilename(buffer,cust->name,NULL,quote);
  476.                                     if (function[pos]!=FUNC_ALLFILES_NO)
  477.                                         custunselect(cust,reload,funcdata);
  478.                                 }
  479.                             }
  480.                             else {
  481. addfile2:
  482.                                 if (funcdata->recursive_path) {
  483.                                     if ((a+strlen(funcdata->recursive_path->path)+qad)>255) break;
  484.                                     addfilename(buffer,funcdata->recursive_path->path,NULL,quote);
  485.                                     if (!(funcdata->recursive_path=funcdata->recursive_path->next)) {
  486.                                         if (function[pos]!=FUNC_ALLFILES_NO)
  487.                                             custunselect(funcdata->entry_current,reload,funcdata);
  488.                                     }
  489.                                 }
  490.                                 else {
  491.                                     if ((a+strlen(cust->name)+qad)>255) break;
  492.                                     addfilename(buffer,cust->name,NULL,quote);
  493.                                     if (function[pos]!=FUNC_ALLFILES_NO)
  494.                                         custunselect(cust,reload,funcdata);
  495.                                 }
  496.                             }
  497.                             StrConcat(buffer," ",256);
  498.                             a=strlen(buffer);
  499.                         }
  500.                         if (!funcdata->recursive_path) {
  501.                             if (cust) cust=cust->next;
  502.                             custnextsel(&funcdata->entry_first);
  503.                         }
  504.                     }
  505.                     bufpos+=a-d;
  506.                     if (moretodo) *moretodo=1;
  507.                 }
  508.                 else {
  509.                     bufpos+=addfilename(buffer,func_single_file,NULL,quote);
  510.                     StrConcat(buffer," ",256);
  511.                     ++bufpos;
  512.                 }
  513.                 break;
  514.  
  515.             case FUNC_ONEPATH:
  516.             case FUNC_ONEPATH_NO:
  517.                 if (!func_single_file[0]) {
  518.                     if (status_iconified || status_flags&STATUS_FROMHOTKEY) {
  519.                         if (getdummyfile(&dummy,dirbuf,&funcdata->file_request)) cust=&dummy;
  520.                         else return(0);
  521.                         TackOn(dirbuf,NULL,256);
  522.                         spath=dirbuf;
  523.                     }
  524.                     else {
  525.                         if (!funcdata->recursive_path) cust=custgetfirst(funcdata);
  526.                         spath=funcdata->source_path;
  527.                     }
  528.                     if (cust) {
  529.                         strcpy(funcdata->last_file,spath);
  530.                         TackOn(funcdata->last_file,cust->name,256);
  531.                         if (!funcdata->recursive_path && cust->type>0) {
  532.                             if (star) {
  533.                                 LFreeRemember(&rec_pathkey);
  534.                                 funcdata->entry_current=cust;
  535.                                 StrCombine(buf3,spath,cust->name,256);
  536.                                 if (recursedir(buf3,NULL,R_STARDIR,0)) return(0);
  537.                                 setdirsize(cust,dos_global_bytecount,funcdata->activewin);
  538.                                 funcdata->recursive_path=rec_firstpath;
  539.                                 goto addfile3;
  540.                             }
  541.                             else {
  542.                                 bufpos+=addfilename(buffer,spath,cust->name,quote);
  543.                                 if (function[pos]!=FUNC_ONEPATH_NO) {
  544.                                     custunselect(cust,reload,funcdata);
  545.                                     custnextsel(&funcdata->entry_first);
  546.                                 }
  547.                             }                   
  548.                         }
  549.                         else {
  550. addfile3:
  551.                             if (funcdata->recursive_path) {
  552.                                 bufpos+=addfilename(buffer,funcdata->recursive_path->path,NULL,quote);
  553.                                 if (!(funcdata->recursive_path=funcdata->recursive_path->next) && function[pos]!=FUNC_ONEPATH_NO)
  554.                                     custunselect(funcdata->entry_current,reload,funcdata);
  555.                             }
  556.                             else {
  557.                                 bufpos+=addfilename(buffer,spath,cust->name,quote);
  558.                                 if (function[pos]!=FUNC_ONEPATH_NO) {
  559.                                     custunselect(cust,reload,funcdata);
  560.                                     custnextsel(&funcdata->entry_first);
  561.                                 }
  562.                             }
  563.                         }
  564.                     }
  565.                 }
  566.                 else {
  567.                     bufpos+=addfilename(buffer,funcdata->source_path,func_single_file,quote);
  568.                     strcpy(funcdata->last_file,funcdata->source_path);
  569.                     TackOn(funcdata->last_file,func_single_file,256);
  570.                 }
  571.                 break;
  572.  
  573.             case FUNC_ALLPATHS:
  574.             case FUNC_ALLPATHS_NO:
  575.                 if (!func_single_file[0]) {
  576.                     a=d=strlen(buffer);
  577.                     if (status_iconified || status_flags&STATUS_FROMHOTKEY) {
  578.                         if (getdummyfile(&dummy,dirbuf,&funcdata->file_request)) cust=&dummy;
  579.                         else return(0);
  580.                         TackOn(dirbuf,NULL,256);
  581.                         spath=dirbuf;
  582.                     }
  583.                     else {
  584.                         cust=custgetfirst(funcdata);
  585.                         spath=funcdata->source_path;
  586.                     }
  587.                     while (a<256 && (cust || funcdata->recursive_path)) {
  588.                         if (funcdata->recursive_path || (cust->selected && cust->type!=0)) {
  589.                             if (!funcdata->recursive_path && cust->type>0) {
  590.                                 if (star) {
  591.                                     LFreeRemember(&rec_pathkey);
  592.                                     funcdata->entry_current=cust;
  593.                                     StrCombine(buf3,spath,cust->name,256);
  594.                                     if (recursedir(buf3,NULL,R_STARDIR,0)) return(0);
  595.                                     setdirsize(cust,dos_global_bytecount,funcdata->activewin);
  596.                                     funcdata->recursive_path=rec_firstpath;
  597.                                     goto addfile4;
  598.                                 }
  599.                                 else {
  600.                                     if ((a+strlen(cust->name)+strlen(spath)+qad)>255) break;
  601.                                     addfilename(buffer,spath,cust->name,quote);
  602.                                     if (function[pos]!=FUNC_ALLPATHS_NO)
  603.                                         custunselect(cust,reload,funcdata);
  604.                                 }   
  605.                             }
  606.                             else {
  607. addfile4:
  608.                                 if (funcdata->recursive_path) {
  609.                                     if ((a+strlen(funcdata->recursive_path->path)+qad)>255) break;
  610.                                     addfilename(buffer,funcdata->recursive_path->path,NULL,quote);
  611.                                     if (!(funcdata->recursive_path=funcdata->recursive_path->next)) {
  612.                                         if (function[pos]!=FUNC_ALLPATHS_NO)
  613.                                             custunselect(funcdata->entry_current,reload,funcdata);
  614.                                     }
  615.                                 }
  616.                                 else {
  617.                                     if ((a+strlen(cust->name)+strlen(spath)+qad)>255) break;
  618.                                     addfilename(buffer,spath,cust->name,quote);
  619.                                     if (function[pos]!=FUNC_ALLPATHS_NO)
  620.                                         custunselect(cust,reload,funcdata);
  621.                                 }
  622.                             }
  623.                             StrConcat(buffer," ",256);
  624.                             a=strlen(buffer);
  625.                         }
  626.                         if (!funcdata->recursive_path) {
  627.                             if (cust) cust=cust->next;
  628.                             custnextsel(&funcdata->entry_first);
  629.                         }
  630.                     }
  631.                     bufpos+=a-d;
  632.                     if (moretodo) *moretodo=1;
  633.                 }
  634.                 else {
  635.                     bufpos+=addfilename(buffer,funcdata->source_path,func_single_file,quote);
  636.                     StrConcat(buffer," ",256);
  637.                     ++bufpos;
  638.                 }
  639.                 break;
  640.  
  641.             case FUNC_SOURCE:
  642.             case FUNC_SOURCE_RR:
  643.                 strcpy(buf3,funcdata->source_path);
  644.                 if ((status_iconified || status_flags&STATUS_FROMHOTKEY)) {
  645.                     if (dirrequester(&funcdata->file_request,buf3,
  646.                         globstring[STR_SELECT_SOURCE_DIR])) {
  647.                         myabort();
  648.                         return(0);
  649.                     }
  650.                     StrConcat(buffer,buf3,256);
  651.                     bufpos=strlen(buffer);
  652.                 }
  653.                 else {
  654.                     StrConcat(buffer,funcdata->source_path,256);
  655.                     bufpos+=sblen;
  656.                 }
  657.             case FUNC_NOSOURCE_RR:
  658.                 if (function[pos]!=FUNC_SOURCE) funcdata->rereadsource=1;
  659.                 break;
  660.  
  661.             case FUNC_DEST:
  662.             case FUNC_DEST_RR:
  663.                 if (!(check_dest_path(funcdata))) return(0);
  664.                 StrConcat(buffer,funcdata->dest_path,256);
  665.                 bufpos+=strlen(funcdata->dest_path);
  666.             case FUNC_NODEST_RR:
  667.                 if (function[pos]!=FUNC_DEST) funcdata->rereaddest=1;
  668.                 break;
  669.  
  670.             case FUNC_SCREENNAME:
  671.                 StrConcat(buffer,str_arexx_portname,256);
  672.                 bufpos+=strlen(str_arexx_portname);
  673.                 break;
  674.  
  675.             case FUNC_QUERYINFO:
  676.                 ++pos;
  677.                 {
  678.                     char *data=NULL;
  679.  
  680.                     switch (function[pos]) {
  681.  
  682.                         /* Public screen name */
  683.                         case 's':
  684.                             data=get_our_pubscreen();
  685.                             break;
  686.  
  687.                         /* ARexx port name */
  688.                         case 'p':
  689.                             data=str_arexx_portname;
  690.                             break;
  691.  
  692.                         /* Last result */
  693.                         case 'r':
  694.                             data=str_last_rexx_result;
  695.                             break;
  696.                     }
  697.  
  698.                     if (data && data[0]) {
  699.                         StrConcat(buffer,data,256);
  700.                         bufpos+=strlen(data);
  701.                     }
  702.                 }
  703.                 break;
  704.  
  705.             case FUNC_VARIABLE:
  706.                 tit=0;
  707.  
  708.                 for (pos++;pos<line_len;pos++) {
  709.                     if (function[pos]==FUNC_ENDARG) break;
  710.                     if (tit<79) titlebuf[tit++]=function[pos];
  711.                 }
  712.                 titlebuf[tit]=0;
  713.  
  714.                 if (system_version2) {
  715.                     if ((a=GetVar(titlebuf,buf3,500,0))>0) {
  716.                         StrConcat(buffer,buf3,256);
  717.                         bufpos+=a;
  718.                     }
  719.                 }
  720.                 break;
  721.  
  722.             case FUNC_GETARG:
  723.                 if (funcdata->function_count && funcdata->arg_use) {
  724. use_old_arg:
  725.                     StrConcat(buffer,funcdata->arg_use->argstring,256);
  726.                     bufpos+=strlen(funcdata->arg_use->argstring);
  727.                     funcdata->arg_use=funcdata->arg_use->next;
  728.                     for (f=pos+1;f<line_len && function[f]!=FUNC_ENDARG;f++);
  729.                     pos=f;
  730.                     break;
  731.                 }
  732.             case FUNC_STDARG:
  733.                 if (funcdata->function_count==-1 && funcdata->arg_use) goto use_old_arg;
  734.                 buftitpos=-1;
  735.                 def=0;
  736.                 tit=0;
  737.  
  738.                 for (f=pos+1;f<line_len;f++) {
  739.                     if (function[f]==FUNC_ENDARG) break;
  740.                     else if (buftitpos==-1) {
  741.                         if (function[f]==':') buftitpos=f+1;
  742.                         else if (tit<79) titlebuf[tit++]=function[f];
  743.                     }
  744.                     else if (def<255) defbuf[def++]=function[f];
  745.                 }
  746.                 titlebuf[tit]=0;
  747.                 defbuf[def]=0;
  748.  
  749.                 if (!titlebuf[0]) ptr=globstring[STR_ENTER_ARGUMENTS];
  750.                 else ptr=titlebuf;
  751.  
  752.                 buf3[0]=0;
  753.                 if (buftitpos>-1)
  754.                     build_default_string(defbuf,buf3,funcdata->last_file,funcdata->source_path,funcdata->dest_path);
  755.  
  756.                 if (!(whatsit(ptr,256,buf3,NULL))) {
  757.                     myabort();
  758.                     return(0);
  759.                 }
  760.  
  761.                 if (function[pos]==FUNC_GETARG) {
  762.                     if (!(arg=LAllocRemember(&funcdata->arg_memkey,sizeof(struct args),MEMF_CLEAR)))
  763.                         return(0);
  764.                     if (!funcdata->arg_first) funcdata->arg_first=arg;
  765.                     else funcdata->arg_current->next=arg;
  766.                     funcdata->arg_current=arg;
  767.                     strcpy(funcdata->arg_current->argstring,buf3);
  768.                 }
  769.                 StrConcat(buffer,buf3,256);
  770.                 bufpos+=strlen(buf3);
  771.                 pos=f;
  772.                 break;
  773.  
  774.             case FUNC_REQUESTER:
  775.                 if (funcdata->file_request.filearray) {
  776. domultifiles:
  777.                     while (bufpos<256) {
  778.                         if (funcdata->file_request.filearray[funcdata->fileargpos][0]) {
  779.                             if ((bufpos+strlen(funcdata->file_request.filearray[funcdata->fileargpos])+qad)<256) {
  780.                                 bufpos+=addfilename(buffer,
  781.                                     funcdata->file_request.filearray[funcdata->fileargpos],NULL,quote);
  782.                                 StrConcat(buffer," ",256); ++bufpos;
  783.                                 ++funcdata->fileargpos;
  784.                             }
  785.                             else {
  786.                                 if (moretodo) *moretodo=1;
  787.                                 break;
  788.                             }
  789.                         }
  790.                         if (!funcdata->file_request.filearray[funcdata->fileargpos][0]) {
  791.                             LFreeRemember(&funcdata->file_request.filearraykey);
  792.                             funcdata->file_request.filearray=NULL;
  793.                             break;
  794.                         }
  795.                     }
  796.                     for (f=pos+1;f<line_len;f++)
  797.                         if (function[f]==FUNC_ENDARG || function[f]==0) break;
  798.                     pos=f;
  799.                     break;
  800.                 }
  801.                 h=-1;
  802.                 switch (function[pos+1]) {
  803.                     case 'f': h=0; break;
  804.                     case 'F': h=DFRF_MULTI; break;
  805.                     case 'd': h=DFRF_DIRREQ; break;
  806.                     case 'o': h=DFRF_FONT; break;
  807.                 }
  808.                 if (h==-1) break;
  809.                 ++pos;
  810.                 buftitpos=-1;
  811.                 for (f=pos+1;f<line_len;f++) {
  812.                     if (function[f]==':' && buftitpos==-1) {
  813.                         function[f]=0;
  814.                         buftitpos=f+1;
  815.                     }
  816.                     if (function[f]==FUNC_ENDARG) {
  817.                         function[f]=0;
  818.                         break;
  819.                     }
  820.                 }
  821.                 if (!function[(pos+1)]) funcdata->file_request.title=globstring[STR_FILE_REQUEST];
  822.                 else funcdata->file_request.title=(char *)function+pos+1;
  823.                 buf3[0]=0;
  824.                 if (buftitpos>-1)
  825.                     build_default_string(&function[buftitpos],buf3,funcdata->last_file,funcdata->source_path,funcdata->dest_path);
  826.                 else if (h&DFRF_FONT) strcpy(buf3,"FONTS:");
  827.                 funcdata->file_request.dirbuf=buf3;
  828.                 funcdata->file_request.filebuf=filebuf; filebuf[0]=0;
  829.                 if (!(h&DFRF_DIRREQ)) {
  830.                     ptr=BaseName(buf3);
  831.                     if (ptr>buf3) {
  832.                         if (ptr[(strlen(ptr)-1)]!='/') {
  833.                             strcpy(filebuf,ptr);
  834.                             *ptr=0;
  835.                         }
  836.                     }
  837.                 }
  838.                 funcdata->file_request.flags=h;
  839.                 if (FileRequest(&funcdata->file_request)) {
  840.                     if (h&DFRF_MULTI) {
  841.                         funcdata->fileargpos=0;
  842.                         goto domultifiles;
  843.                     }
  844.                     if (!funcdata->file_request.dirbuf[0])
  845.                         expand_path("",funcdata->file_request.dirbuf);
  846.                     if (!(h&DFRF_DIRREQ)) {
  847.                         if (quote) StrConcat(buffer,"\"",256);
  848.                         StrConcat(buffer,funcdata->file_request.dirbuf,256);
  849.                         TackOn(buffer,filebuf,256);
  850.                         if (quote) StrConcat(buffer,"\"",256);
  851.                     }
  852.                     else StrConcat(buffer,funcdata->file_request.dirbuf,256);
  853.                     bufpos=strlen(buffer);
  854.                 }
  855.                 else {
  856.                     myabort();
  857.                     return(0);
  858.                 }
  859.                 pos=f;
  860.                 break;
  861.             default:
  862.                 buffer[bufpos++]=function[pos];
  863.                 break;
  864.         }
  865.         if (bufpos==256) break;
  866.     }
  867.     buffer[255]=0;
  868.     return(1);
  869. }
  870.  
  871. addfilename(buf,part1,part2,quote)
  872. char *buf,*part1,*part2;
  873. int quote;
  874. {
  875.     int c=0,d;
  876.  
  877.     d=strlen(buf);
  878.     if (d>0 && !(isspace(buf[d-1]))) quote=0;
  879.  
  880.     if (quote) {
  881.         StrConcat(buf,"\"",256);
  882.         ++c;
  883.     }
  884.     if (part1) {
  885.         StrConcat(buf,part1,256);
  886.         c+=strlen(part1);
  887.     }
  888.     if (part2) {
  889.         StrConcat(buf,part2,256);
  890.         c+=strlen(part2);
  891.     }
  892.     if (quote) {
  893.         StrConcat(buf,"\"",256);
  894.         ++c;
  895.     }
  896.     return(c);
  897. }
  898.  
  899. void parserunline(buf,buf1)
  900. char *buf;
  901. unsigned char *buf1;
  902. {
  903.     int a,b,c,d;
  904.  
  905.     a=strlen(buf);
  906.     for (c=0;c<256;c++) buf1[c]=0;
  907.     c=0;
  908.     for (b=0;b<a;b++) {
  909.         if (c==256) break;
  910.         if (buf[b]=='{') {
  911.             if ((b+2)>=a) {
  912.                 buf1[c]=buf[b];
  913.                 ++c;
  914.                 continue;
  915.             }
  916.             if (buf[(b+1)]=='{') {
  917.                 buf1[c]=buf[b];
  918.                 ++b; ++c;
  919.                 continue;
  920.             }
  921.  
  922.             switch (buf[(b+1)]) {
  923.                 case 'a':
  924.                     buf1[c]=FUNC_GETARG;
  925.                 case 'A':
  926.                     if (buf[(b+1)]=='A') buf1[c]=FUNC_STDARG;
  927.                 case 'v':
  928.                     if (buf[(b+1)]=='v') buf1[c]=FUNC_VARIABLE;
  929.                 case 'R':
  930.                     if (buf[(b+1)]=='R') {
  931.                         if (buf[(b+2)]=='s') {
  932.                             buf1[c]=FUNC_GETARG;
  933.                             ++b;
  934.                         }
  935.                         else if (buf[(b+2)]=='S') {
  936.                             buf1[c]=FUNC_STDARG;
  937.                             ++b;
  938.                         }
  939.                         else buf1[c]=FUNC_REQUESTER;
  940.                     }
  941.                     ++c;
  942.                     for (d=(b+2);d<a;d++) {
  943.                         if (buf[d]=='}') break;
  944.                         buf1[c]=buf[d];
  945.                         ++c;
  946.                         if (c==255) break;
  947.                     }
  948.                     buf1[c++]=FUNC_ENDARG;
  949.                     b=d;
  950.                     continue;
  951.  
  952.                 case 'Q':
  953.                     buf1[c++]=FUNC_QUERYINFO;
  954.                     buf1[c++]=buf[b+2];
  955.                     b+=3;
  956.                     continue;
  957.             }
  958.  
  959.             switch (buf[(b+2)]) {
  960.                 case 'r':
  961.                     if (buf[(b+1)]=='d') buf1[c]=FUNC_DEST_RR;
  962.                     else if (buf[(b+1)]=='s') buf1[c]=FUNC_SOURCE_RR;
  963.                     else if (buf[(b+1)]=='S') buf1[c]=FUNC_NOSOURCE_RR;
  964.                     else if (buf[(b+1)]=='D') buf1[c]=FUNC_NODEST_RR;
  965.                     b+=3; ++c;
  966.                     continue;
  967.  
  968.                 case 'u':
  969.                     if (buf[(b+1)]=='o') buf1[c]=FUNC_ONEFILE_NO;
  970.                     else if (buf[(b+1)]=='O') buf1[c]=FUNC_ALLFILES_NO;
  971.                     else if (buf[(b+1)]=='f') buf1[c]=FUNC_ONEPATH_NO;
  972.                     else if (buf[(b+1)]=='F') buf1[c]=FUNC_ALLPATHS_NO;
  973.                     b+=3; ++c;
  974.                     continue;
  975.  
  976.                 case '}':
  977.                     switch (buf[(b+1)]) {
  978.                         case 'o': buf1[c]=FUNC_ONEFILE; break;
  979.                         case 'O': buf1[c]=FUNC_ALLFILES; break;
  980.                         case 's': buf1[c]=FUNC_SOURCE; break;
  981.                         case 'd': buf1[c]=FUNC_DEST; break;
  982.                         case 'f': buf1[c]=FUNC_ONEPATH; break;
  983.                         case 'F': buf1[c]=FUNC_ALLPATHS; break;
  984.                         case 'p': buf1[c]=FUNC_SCREENNAME; break;
  985.                     }
  986.                     b+=2; ++c;
  987.                     continue;
  988.             }
  989.         }
  990.         buf1[c]=buf[b];
  991.         ++c;
  992.         if (c==256) break;
  993.     }
  994. }
  995.  
  996. void custunselect(dir,rel,funcdata)
  997. struct Directory *dir;
  998. int rel;
  999. struct function_data *funcdata;
  1000. {
  1001.     struct recpath *temp;
  1002.     int win;
  1003.  
  1004.     win=funcdata->activewin;
  1005.  
  1006.     if (!status_iconified && !(status_flags&STATUS_FROMHOTKEY) && !func_external_file[0]) {
  1007.         if (rel && dir->name[0]) {
  1008.             if ((temp=LAllocRemember(&funcdata->reload_memkey,sizeof(struct recpath),MEMF_CLEAR)) &&
  1009.                 (temp->path=LAllocRemember(&funcdata->reload_memkey,33,MEMF_CLEAR))) {
  1010.                 strcpy(temp->path,dir->name);
  1011.                 if (funcdata->reload_current) funcdata->reload_current->next=temp;
  1012.                 funcdata->reload_current=temp;
  1013.                 if (!funcdata->reload_first) funcdata->reload_first=temp;
  1014.                 temp->next=NULL;
  1015.             }
  1016.         }
  1017.         unselect(win,dir);
  1018.     }
  1019. }
  1020.  
  1021. void doreloadfiles(funcdata)
  1022. struct function_data *funcdata;
  1023. {
  1024.     char buf[256];
  1025.     struct recpath *rel;
  1026.     int off;
  1027.  
  1028.     rel=funcdata->reload_first;
  1029.     off=dopus_curwin[funcdata->activewin]->offset;
  1030.     while (rel) {
  1031.         StrCombine(buf,funcdata->source_path,rel->path,256);
  1032.         reload_file(funcdata->activewin,buf);
  1033.         rel=rel->next;
  1034.     }
  1035.     dopus_curwin[funcdata->activewin]->offset=off;
  1036.     refreshwindow(funcdata->activewin,0);
  1037. }
  1038.  
  1039. struct Directory *reload_file(win,name)
  1040. int win;
  1041. char *name;
  1042. {
  1043.     struct FileInfoBlock __aligned fileinfo;
  1044.     struct Directory *cust,*ret=NULL;
  1045.  
  1046.     if ((lockandexamine(name,&fileinfo))) {
  1047.         if ((cust=findfile(dopus_curwin[win],fileinfo.fib_FileName,NULL)))
  1048.             removefile(cust,dopus_curwin[win],win,FALSE);
  1049.         ret=(struct Directory *)addfile(dopus_curwin[win],
  1050.             win,fileinfo.fib_FileName,fileinfo.fib_Size,
  1051.             fileinfo.fib_DirEntryType,&(fileinfo.fib_Date),fileinfo.fib_Comment,
  1052.             fileinfo.fib_Protection,0,FALSE,NULL,NULL,fileinfo.fib_OwnerUID,fileinfo.fib_OwnerGID);
  1053.     }
  1054.     else {
  1055.         if ((cust=findfile(dopus_curwin[win],BaseName(name),NULL)))
  1056.             removefile(cust,dopus_curwin[win],win,FALSE);
  1057.     }
  1058.     return(ret);
  1059. }
  1060.  
  1061. openscriptfile(par,funcdata)
  1062. struct dopusfuncpar *par;
  1063. struct function_data *funcdata;
  1064. {
  1065.     char buf[512],buf2[512];
  1066.     struct FileInfoBlock __aligned fileinfo;
  1067.     BPTR lock;
  1068.     int a;
  1069.  
  1070.     if (funcdata->output_file) return(1);
  1071.  
  1072.     if (par->which&FLAG_CDSOURCE && !funcdata->source_path[0]) {
  1073.         if (!(simplerequest(globstring[STR_NO_SOURCE_SELECTED],
  1074.             globstring[STR_CONTINUE],str_cancelstring,NULL))) {
  1075.             myabort();
  1076.             return(0);
  1077.         }
  1078.     }
  1079.     else if (par->which&FLAG_CDDEST && !funcdata->dest_path[0]) {
  1080.         if (!(simplerequest(globstring[STR_NO_DESTINATION_SELECTED],
  1081.             globstring[STR_CONTINUE],str_cancelstring,NULL))) {
  1082.             myabort();
  1083.             return(0);
  1084.         }
  1085.     }
  1086.  
  1087.     makereselect(&func_reselection,funcdata->activewin);
  1088.  
  1089.     main_proc->pr_WindowPtr=(APTR)-1;
  1090.     if (CheckExist("T:",NULL)) strcpy(buf,"T:");
  1091.     else strcpy(buf,"RAM:");
  1092.  
  1093.     if (lock=Lock(buf,ACCESS_READ)) {
  1094.         Examine(lock,&fileinfo);
  1095.         if (ExNext(lock,&fileinfo)) {
  1096.             FOREVER {
  1097.                 if (LStrnCmp(fileinfo.fib_FileName,"dopustemp",9)==0)
  1098.                     lsprintf(funcdata->scriptname,"%s%s",buf,fileinfo.fib_FileName);
  1099.                 else funcdata->scriptname[0]=0;
  1100.                 a=ExNext(lock,&fileinfo);
  1101.                 if (funcdata->scriptname[0]) DeleteFile(funcdata->scriptname);
  1102.                 if (!a) break;
  1103.             }
  1104.         }
  1105.         UnLock(lock);
  1106.     }
  1107.     if (config->errorflags&ERROR_ENABLE_DOS) main_proc->pr_WindowPtr=(APTR)Window;
  1108.  
  1109.     for (a=0;a<100;a++) {
  1110.         lsprintf(funcdata->scriptname,"%sdopustemp.tmp%ld",buf,a);
  1111.         if (funcdata->output_file=Open(funcdata->scriptname,MODE_NEWFILE)) break;
  1112.     }
  1113.     if (!funcdata->output_file) {
  1114.         doerror(IoErr());
  1115.         return(0);
  1116.     }
  1117.  
  1118.     lsprintf(funcdata->tempfile,"%sdopusout.tmp%ld",buf,a);
  1119.  
  1120.     rec_pathkey=NULL;
  1121.  
  1122.     lsprintf(buf,"%s -s\n",str_dopusrt_path);
  1123.     Write(funcdata->output_file,buf,strlen(buf));
  1124.  
  1125.     if (par->which&FLAG_SHELLUP) {
  1126.         if (config->shellstartup[0]) StrCombine(buf,"S:",config->shellstartup,40);
  1127.         else strcpy(buf,"S:Shell-Startup");
  1128.         if (CheckExist(buf,NULL)) {
  1129.             lsprintf(buf2,"Execute %s\n",buf);
  1130.             Write(funcdata->output_file,buf2,strlen(buf2));
  1131.         }
  1132.     }
  1133.     if (par->which&FLAG_DOPUSUP) {
  1134.         if (CheckExist("S:DOpus-Startup",NULL))
  1135.             Write(funcdata->output_file,"Execute S:DOpus-Startup\n",24);
  1136.         else if (CheckExist("S:DOpusShell-Startup",NULL))
  1137.             Write(funcdata->output_file,"Execute S:DOpusShell-Startup\n",29);
  1138.     }
  1139.     Write(funcdata->output_file,"FailAt 999999\n",14);
  1140.  
  1141.     buf[0]=0;
  1142.     if (status_flags&STATUS_FROMHOTKEY) {
  1143.         expand_path("",buf2);
  1144.         lsprintf(buf,"CD \"%s\"\n",buf2);
  1145.     }
  1146.     else {
  1147.         if (par->which&FLAG_CDSOURCE && funcdata->source_path[0])
  1148.             lsprintf(buf,"CD \"%s\"\n",funcdata->source_path);
  1149.         else if (par->which&FLAG_CDDEST) {
  1150.             if (!(check_dest_path(funcdata))) return(0);
  1151.             lsprintf(buf,"CD \"%s\"\n",funcdata->dest_path);
  1152.         }
  1153.     }
  1154.     if (buf[0]) Write(funcdata->output_file,buf,strlen(buf));
  1155.  
  1156.     lsprintf(buf,"Stack %ld\n",(par->stack<4000)?4000:par->stack);
  1157.     Write(funcdata->output_file,buf,strlen(buf));
  1158.  
  1159.     if (par->pri!=0) {
  1160.         lsprintf(buf,"ChangeTaskPri %ld\n",par->pri);
  1161.         Write(funcdata->output_file,buf,strlen(buf));
  1162.     }
  1163.  
  1164.     return(1);
  1165. }
  1166.  
  1167. closescriptfile(par,run,funcdata)
  1168. struct dopusfuncpar *par;
  1169. int run;
  1170. struct function_data *funcdata;
  1171. {
  1172.     struct MsgPort *msgport;
  1173.     struct Message *msg;
  1174.     char buf[256],buf2[512],portname[50],pubname[140];
  1175.     int wb2f,setcust=0,tnil=0,otemp=0,oldmodes,okayflag=0,bit,flags=0;
  1176.  
  1177.     if (run>0 && par && funcdata->output_file) {
  1178.         flags=par->which;
  1179.         if (flags&FLAG_OUTFILE && status_flags&STATUS_FROMHOTKEY) {
  1180.             flags&=~FLAG_OUTFILE;
  1181.             flags|=FLAG_OUTWIND;
  1182.         }
  1183.  
  1184.         okayflag=1;
  1185.         wb2f=flags&FLAG_WB2F;
  1186.         msgport=NULL;
  1187.         endnotifies();
  1188.  
  1189.         if (flags&FLAG_OUTWIND) {
  1190.             lsprintf(buf2,"%s \"%s\" from %s",config->outputcmd,config->output,funcdata->scriptname);
  1191.             if (!(flags&FLAG_ASYNC)) {
  1192.                 lsprintf(portname,"dopus_run%ld",system_dopus_runcount);
  1193.                 if (!(msgport=LCreatePort(portname,0))) goto freeargs;
  1194.             }
  1195.             else wb2f=1;
  1196.         }
  1197.         else if (flags&FLAG_ASYNC) lsprintf(buf2,"run execute %s",funcdata->scriptname);
  1198.         else lsprintf(buf2,"execute %s",funcdata->scriptname);
  1199.  
  1200.         if (flags&FLAG_OUTWIND) {
  1201.             if (par->delay!=0) {
  1202.                 lsprintf(buf,"%s -w %ld \"%s\"\n",
  1203.                     str_dopusrt_path,
  1204.                     par->delay,
  1205.                     globstring[STR_PRESS_MOUSE_BUTTON]);
  1206.                 Write(funcdata->output_file,buf,strlen(buf));
  1207.             }
  1208.             if (msgport) {
  1209.                 lsprintf(buf,"%s -p %s\n",str_dopusrt_path,portname);
  1210.                 Write(funcdata->output_file,buf,strlen(buf));
  1211.             }
  1212.             Write(funcdata->output_file,"EndCLI >NIL:\n",13);
  1213.         }
  1214.  
  1215.         Close(funcdata->output_file); funcdata->output_file=0;
  1216.  
  1217.         if (wb2f && (!(flags&FLAG_ASYNC) || !(flags&FLAG_DOPUSF)))
  1218.             WBenchToFront();    
  1219.         if (flags&FLAG_OUTWIND && !wb2f && MainScreen) {
  1220.             if (system_version2) {
  1221.                 oldmodes=SetPubScreenModes(SHANGHAI);
  1222.                 GetDefaultPubScreen(pubname);
  1223.                 SetDefaultPubScreen((UBYTE *)str_arexx_portname);
  1224.             }
  1225.             else {
  1226.                 Forbid();   
  1227.                 MainScreen->Flags&=~CUSTOMSCREEN;
  1228.                 MainScreen->Flags|=WBENCHSCREEN;
  1229.                 Permit();
  1230.             }
  1231.             setcust=1;
  1232.         }
  1233.  
  1234.         if (flags&FLAG_OUTFILE && (tnil=Open(funcdata->tempfile,MODE_NEWFILE))) otemp=1;
  1235.         if (!tnil) tnil=Open("NIL:",MODE_OLDFILE);
  1236.  
  1237.         Execute(buf2,0,(BPTR)tnil);
  1238.  
  1239.         if (flags&FLAG_OUTWIND && !wb2f && !(status_flags&STATUS_IANSCRAP) && MainScreen) {
  1240.             if (system_version2) {
  1241.                 SetDefaultPubScreen(pubname);
  1242.                 SetPubScreenModes(oldmodes);
  1243.             }
  1244.             else {
  1245.                 Forbid();   
  1246.                 MainScreen->Flags&=~WBENCHSCREEN;
  1247.                 MainScreen->Flags|=CUSTOMSCREEN;
  1248.                 Permit();
  1249.             }
  1250.             setcust=0;
  1251.         }
  1252.  
  1253.         if (msgport && Window) {
  1254.             SetSignal(0,INPUTSIG_ABORT);
  1255.             FOREVER {
  1256.                 if ((bit=Wait(1<<msgport->mp_SigBit|rexx_signalbit|INPUTSIG_ABORT))
  1257.                     &INPUTSIG_ABORT) {
  1258.                     status_justabort=status_haveaborted=0;
  1259.                     break;
  1260.                 }
  1261.                 if (bit&rexx_signalbit) {
  1262.                     rexx_dispatch(0);
  1263.                     continue;
  1264.                 }
  1265.                 if ((msg=GetMsg(msgport))) {
  1266.                     ReplyMsg(msg);
  1267.                     break;
  1268.                 }
  1269.             }
  1270.             LDeletePort(msgport);
  1271.         }
  1272.  
  1273.         if (!(flags&FLAG_ASYNC) && tnil) Close(tnil);
  1274.  
  1275.         if (setcust) {
  1276.             if (system_version2) {
  1277.                 SetDefaultPubScreen(pubname);
  1278.                 SetPubScreenModes(oldmodes);
  1279.             }
  1280.             else {
  1281.                 Forbid();   
  1282.                 MainScreen->Flags&=~WBENCHSCREEN;
  1283.                 MainScreen->Flags|=CUSTOMSCREEN;
  1284.                 Permit();
  1285.             }
  1286.         }
  1287.  
  1288.         if (flags&FLAG_DOPUSF) {
  1289.             if (MainScreen) ScreenToFront(MainScreen);
  1290.             if (Window && !Window->Flags&WFLG_BACKDROP) WindowToFront(Window);
  1291.         }
  1292.  
  1293.         if (!status_iconified && !(status_flags&STATUS_FROMHOTKEY)) {
  1294.             if (funcdata->rereadsource || flags&FLAG_SCANSRCE) {
  1295.                 startgetdir(funcdata->activewin,0);
  1296.                 funcdata->reload_first=NULL;
  1297.             }
  1298.             if (funcdata->rereaddest || flags&FLAG_SCANDEST)
  1299.                 startgetdir(funcdata->inactivewin,0);
  1300.             if (flags&FLAG_RELOAD && funcdata->reload_first) doreloadfiles(funcdata);
  1301.         }
  1302.     }
  1303.  
  1304. freeargs:
  1305.     if (funcdata->output_file) Close(funcdata->output_file);
  1306.     if ((funcdata->output_file || okayflag) && funcdata->scriptname[0] &&
  1307.         (!par || !(flags&FLAG_ASYNC)))
  1308.         DeleteFile(funcdata->scriptname);
  1309.     funcdata->output_file=funcdata->scriptname[0]=0;
  1310.     funcdata->rereaddest=funcdata->rereadsource=0;
  1311.  
  1312.     LFreeRemember(&funcdata->arg_memkey);
  1313.     if (otemp) {
  1314.         viewfile(funcdata->tempfile,globstring[STR_TEMPORARY_OUTPUT_FILE],FUNC_READ,NULL,NULL,1,0);
  1315.         DeleteFile(funcdata->tempfile);
  1316.     }
  1317.     LFreeRemember(&rec_pathkey);
  1318.     LFreeRemember(&funcdata->reload_memkey);
  1319.  
  1320.     if (Window && !(status_flags&STATUS_FROMHOTKEY)) unbusy();
  1321.     if (status_flags&STATUS_VERIFYFAIL) myabort();
  1322.     else if (okayflag) {
  1323.         if (Window && !status_iconified && !(status_flags&STATUS_FROMHOTKEY)) okay();
  1324.         if (flags&FLAG_ICONIFY && checkwindowquit()) iconify(2,0,0);
  1325.         else startnotifies();
  1326.     }
  1327.     return(run);
  1328. }
  1329.  
  1330. getdummyfile(fbuf,dirbuf,freq)
  1331. struct Directory *fbuf;
  1332. char *dirbuf;
  1333. struct DOpusFileReq *freq;
  1334. {
  1335.     char file[FILEBUF_SIZE],buf[300];
  1336.  
  1337.     freq->x=freq->y=-2;
  1338.     freq->title=globstring[STR_SELECT_A_FILE]; file[0]=0;
  1339.     freq->dirbuf=dirbuf; freq->filebuf=file;
  1340.     freq->window=Window;
  1341.     freq->lines=15; freq->flags=0;
  1342.     if (!dirbuf[0]) expand_path("",dirbuf);
  1343.     if (!(FileRequest(freq))) {
  1344.         myabort();
  1345.         return(0);
  1346.     }
  1347.     if (!dirbuf[0]) expand_path("",dirbuf);
  1348.     if (fbuf) {
  1349.         strcpy(buf,dirbuf); TackOn(buf,file,256);
  1350.         return(filloutdummy(buf,fbuf));
  1351.     }
  1352.     strcpy(func_single_file,file);
  1353.     return(1);
  1354. }
  1355.  
  1356. filloutdummy(name,fbuf)
  1357. char *name;
  1358. struct Directory *fbuf;
  1359. {
  1360.     struct FileInfoBlock __aligned fib;
  1361.  
  1362.     if (!(lockandexamine(name,&fib))) return(0);
  1363.     fbuf->last=fbuf->next=NULL;
  1364.     strcpy(fbuf->name,fib.fib_FileName);
  1365.     fbuf->type=fib.fib_DirEntryType;
  1366.     if (fbuf->type>=0) fbuf->size=-1;
  1367.     else fbuf->size=fib.fib_Size;
  1368.     fbuf->subtype=0;
  1369.     fbuf->protection=fib.fib_Protection;
  1370.     fbuf->comment=fbuf->dispstr=NULL;
  1371.     getprot(fbuf->protection,fbuf->protbuf);
  1372.     seedate(&fib.fib_Date,fbuf->datebuf,1);
  1373.     CopyMem((char *)&fib.fib_Date,&fbuf->date,sizeof(struct DateStamp));
  1374.     fbuf->selected=1;
  1375.     return(1);
  1376. }
  1377.  
  1378. dirrequester(freq,buf,title)
  1379. struct DOpusFileReq *freq;
  1380. char *buf,*title;
  1381. {
  1382.     if (title) freq->title=title;
  1383.     else freq->title=globstring[STR_SELECT_A_DIRECTORY];
  1384.     freq->dirbuf=buf;
  1385.     freq->flags=DFRF_DIRREQ;
  1386.     if (!buf[0]) expand_path("",buf);
  1387.     if (FileRequest(freq)) {
  1388.         if (!buf[0]) expand_path("",buf);
  1389.         return(1);
  1390.     }
  1391.     return(0);
  1392. }
  1393.  
  1394. void do_title_string(string,buf,ml,name)
  1395. char *string,*buf;
  1396. int ml;
  1397. char *name;
  1398. {
  1399.     int a,b,c;
  1400.  
  1401.     a=strlen(string); c=0;
  1402.     for (b=0;b<a;b++) {
  1403.         if (string[b]=='%') {
  1404.             buf[c]=0;
  1405.             if (name) strcat(buf,name);
  1406.             else addreqfilename(buf,data_active_window);
  1407.             c=strlen(buf);
  1408.         }
  1409.         else {
  1410.             if (ml && string[b]=='\\') buf[c]='\n';
  1411.             else buf[c]=string[b];
  1412.             ++c;
  1413.         }
  1414.         if (c==(256+(ml*262))) break;
  1415.     }
  1416.     buf[c]=0;
  1417. }
  1418.  
  1419. void addreqfilename(buf,win)
  1420. char *buf;
  1421. int win;
  1422. {
  1423.     struct Directory *dir;
  1424.  
  1425.     if (func_single_file[0]) strcat(buf,func_single_file);
  1426.     else {
  1427.         dir=dopus_curwin[win]->firstentry;
  1428.         while (dir) {
  1429.             if (dir->selected && dir->type<0) break;
  1430.             dir=dir->next;
  1431.         }
  1432.         if (dir && dir->selected && dir->type<0) strcat(buf,dir->name);
  1433.     }
  1434. }
  1435.  
  1436. struct Directory *custgetfirst(funcdata)
  1437. struct function_data *funcdata;
  1438. {
  1439.     struct Directory *file;
  1440.  
  1441.     file=funcdata->entry_first;
  1442.     while (file) {
  1443.         if (file->type!=0 && file->selected && file->type!=ENTRY_CUSTOM) return(file);
  1444.         file=file->next;
  1445.     }
  1446.     return(NULL);
  1447. }
  1448.  
  1449. void custnextsel(dir)
  1450. struct Directory **dir;
  1451. {
  1452.     while (*dir) {
  1453.         if (!(*dir=(*dir)->next)) break;
  1454.         if ((*dir)->selected) break;
  1455.     }
  1456. }
  1457.  
  1458. check_dest_path(funcdata)
  1459. struct function_data *funcdata;
  1460. {
  1461.     if (funcdata->dest_path[0]) return(1);
  1462.     if ((status_iconified || status_flags&STATUS_FROMHOTKEY) &&
  1463.         ((dirrequester(&funcdata->file_request,
  1464.         funcdata->dest_path,globstring[STR_SELECT_DESTINATION_DIR])) ||
  1465.         !funcdata->dest_path[0])) {
  1466.         myabort();
  1467.         return(0);
  1468.     }
  1469.     if (!funcdata->dest_path[0]) {
  1470.         dostatustext(globstring[STR_NO_DESTINATION_SELECTED]);
  1471.         simplerequest(globstring[STR_NO_DESTINATION_SELECTED],
  1472.             globstring[STR_CONTINUE],NULL);
  1473.         return(0);
  1474.     }
  1475.     return(1);
  1476. }
  1477.  
  1478. getdummypath(dir,title)
  1479. char *dir;
  1480. int title;
  1481. {
  1482.     struct DOpusFileReq freq;
  1483.     int a;
  1484.  
  1485.     freq.window=Window;
  1486.     freq.lines=15;
  1487.     freq.x=freq.y=-2;
  1488.     if ((a=dirrequester(&freq,dir,globstring[title])))
  1489.         if (!dir[0]) expand_path("",dir);
  1490.     return(a);
  1491. }
  1492.  
  1493. void build_default_string(string,buffer,filename,sourcepath,destpath)
  1494. char *string,*buffer,*filename,*sourcepath,*destpath;
  1495. {
  1496.     int len,a,pos,flag;
  1497.     char *ptr;
  1498.  
  1499.     len=strlen(string);
  1500.     pos=0;
  1501.     for (a=0;a<len && pos<499;a++) {
  1502.         if (string[a]=='[' && string[a+2]==']') {
  1503.             flag=1;
  1504.             switch (string[a+1]) {
  1505.                 case 'f':
  1506.                     LStrnCpy(&buffer[pos],filename,499-pos);
  1507.                     break;
  1508.                 case 'o':
  1509.                     if (ptr=BaseName(filename)) LStrnCpy(&buffer[pos],ptr,499-pos);
  1510.                     break;
  1511.                 case 's':
  1512.                     LStrnCpy(&buffer[pos],sourcepath,499-pos);
  1513.                     break;
  1514.                 case 'd':
  1515.                     LStrnCpy(&buffer[pos],destpath,499-pos);
  1516.                     break;
  1517.                 default:
  1518.                     flag=0;
  1519.                     break;
  1520.             }
  1521.             if (flag) {
  1522.                 pos=strlen(buffer);
  1523.                 a+=2;
  1524.                 continue;
  1525.             }
  1526.         }
  1527.         buffer[pos++]=string[a];
  1528.     }
  1529. }
  1530.