home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / disks / misc / afcopy_v4.4 / sourcecode / afcopy_file.c < prev    next >
C/C++ Source or Header  |  1981-06-29  |  19KB  |  768 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <dos.h>
  5. #include <time.h>
  6. #include <exec/types.h>
  7. #include <exec/memory.h>
  8. #include <exec/execbase.h>
  9. #include <exec/nodes.h>
  10. #include <dos/dos.h>
  11. #include <dos/dostags.h>
  12. #include <dos/filehandler.h>
  13. #include <libraries/dos.h>
  14. #include <intuition/intuition.h>
  15. #include <intuition/gadgetclass.h>
  16. #include <libraries/reqtools.h>
  17. #include <libraries/dos.h>
  18. #include <clib/exec_protos.h>
  19. #include <clib/dos_protos.h>
  20. #include <clib/intuition_protos.h>
  21. #include <clib/gadtools_protos.h>
  22. #include <clib/graphics_protos.h>
  23. #include <clib/reqtools_protos.h>
  24.  
  25. #include "afcopy_defines.h"
  26. #include "afcopy_protos.h"
  27. #include "afcopy_version.h"
  28. #include "afcopy_vars.h"
  29.  
  30.  
  31. void getfiles(short side, char *path)
  32. {
  33.   BPTR FL;
  34.   struct FileInfoBlock *FB;
  35.   long err;
  36.   char errormsg[600],iomsg[50];
  37.  
  38. #ifdef DEBUG
  39.   puts("getfiles()");
  40. #endif
  41.  
  42.   pathok[side]=FALSE;
  43.   clearside(side);
  44.  
  45.   SetAPen(W->RPort,2);
  46. /*  SetBPen(W->RPort,0);*/ /*assume backgroung is color 0 due to clearfiles()*/
  47.   OutTextXY(W,filexpos[side]+50,topborder+50,"Reading Directory...");
  48.   totalfiles[side]=0;
  49.   selectedfiles[side]=0;
  50.   selectedsize[side]=0;
  51.   if ((FL=Lock(path,(long)ACCESS_READ))==NULL)
  52.   {
  53.     err=IoErr();
  54.     if (!(err==226 && ignorenodisk))
  55.     {
  56.       IoErrMsg(iomsg,err);
  57.  
  58.       sprintf(errormsg,"Error Getting Directory!\n%s\n%s",path,iomsg);
  59.       rtEZRequest (errormsg,okmsg,NULL,(struct TagItem *)&reqtags,NULL);
  60.     }
  61.   }
  62.   else
  63.   {
  64.     NameFromLock(FL,cpath[side],MAX_PATH_LEN);
  65.     addterm(cpath[side]);
  66.     FB=malloc(sizeof(struct FileInfoBlock));
  67.     err= !Examine(FL,FB);
  68.     if (!err)
  69.     {
  70.       pathok[side]=TRUE;
  71.       do
  72.       {
  73.         err=!ExNext(FL,FB);
  74.         if (!err)
  75.         {
  76.           if (totalfiles[side] < MAX_FILES_IN_LIST)
  77.           {
  78.             if (FB->fib_DirEntryType!=0)
  79.             {
  80.               if (ignorehiddenbit || (!ignorehiddenbit && !(FB->fib_Protection & 1<<7)))
  81.               {
  82.                 if (allocmemforname(side))
  83.                 {
  84.                   strcpy(filename[side][totalfiles[side]],FB->fib_FileName);
  85.                   filesize[side][totalfiles[side]]=FB->fib_Size;
  86.                   filetype[side][totalfiles[side]]=FB->fib_DirEntryType<0 ? -1 : 1;
  87.                   filetags[side][totalfiles[side]]=FALSE;
  88. /*                  strcpy(errormsg,cpath[side]);
  89.                   strcat(errormsg,FB->fib_FileName);
  90.                   filedate[side][totalfiles[side]]=getft(errormsg);
  91. */
  92.                   filedate[side][totalfiles[side]]=FB->fib_Date;
  93.                   totalfiles[side]++;
  94.                   if ((totalfiles[side]%20)==0) updateslider(side,0);
  95.                 }
  96.                 else
  97.                 {
  98.                   rtEZRequest("no memory left!!","Bogus",NULL,(struct TagItem *)&reqtags,NULL);
  99.                 }
  100.               }
  101.             }
  102.             else
  103.             {
  104.               rtEZRequest ("Encountered A Strange File Entry!","Hmm, I'l check my disk",NULL,(struct TagItem *)&reqtags,NULL);
  105.             }
  106.           }
  107.         }
  108.       } while (!err);
  109.     }
  110.     free(FB);
  111.     UnLock(FL);
  112.   }
  113.   updateslider(side,0);
  114.   qsortfiles(side,0,totalfiles[side]-1);
  115.   clearside(side);
  116.   DoDiskInfo(side,cpath[side]);
  117. }
  118.  
  119. /*
  120.  * i'd just like to thank the author of format for the follow bit of
  121.  * code, some of which is nicked from his source.
  122.  */
  123.  
  124. void findvolumes(short side)
  125. {
  126.   struct DosList      *DosList;
  127.   struct DeviceNode   *DevNode;
  128.   UBYTE           *Pointer;
  129.   char string[32]="";
  130.   int loop;
  131.  
  132.   pathok[side]=FALSE;
  133.   totalfiles[side]=0;
  134.   selectedfiles[side]=0;
  135.   selectedsize[side]=0;
  136.  
  137.   clearside(side);
  138.   DosList = LockDosList(LDF_ALL|LDF_READ);
  139.   while(DosList = NextDosEntry(DosList,LDF_ALL|LDF_READ))
  140.   {
  141.     DevNode = (struct DeviceNode *)DosList;
  142.     if (DevNode->dn_Type==DLT_DIRECTORY || DevNode->dn_Type==DLT_VOLUME)
  143.     {
  144.       Pointer = (UBYTE *)BADDR(DevNode -> dn_Name);
  145.       if (Pointer[0])
  146.       {
  147.         for(loop = 0 ; loop < Pointer[0] ; loop++)
  148.                           string[loop] = Pointer[loop + 1];
  149.  
  150.         string[Pointer[0]]   = 0; /* terminate string */
  151.         strcat(string,":");
  152.         AddToFileList(side,string,0,1,FALSE);
  153.       }
  154.     }
  155.   }
  156.   UnLockDosList(LDF_ALL|LDF_READ);
  157.   qsortfiles(side,0,totalfiles[side]-1);
  158.   strcpy(cpath[side],"");
  159.   updatepath(side);
  160.   displayoffset[side]=0;
  161.   updateslider(side,0);
  162.   displayfilelist(side,0);
  163. }
  164.  
  165. LONG getfilesize(char *filename)
  166. {
  167.   BPTR FL;
  168.   struct FileInfoBlock *FB;
  169.   LONG retval=-1;
  170.  
  171. #ifdef DEBUG
  172.   puts("getfilesize()");
  173. #endif
  174.  
  175.   if (FL=Lock(filename,(long)ACCESS_READ))
  176.   {
  177.     if(FB=malloc(sizeof(struct FileInfoBlock)))
  178.     {
  179.       if (Examine(FL,FB))
  180.       {
  181.         retval=FB->fib_Size;
  182.       }
  183.       free(FB);
  184.     }
  185.     UnLock(FL);
  186.   }
  187.   return(retval);
  188. }
  189.  
  190. int ModifyComment(char *filename,BOOL usedefcomm)
  191. {
  192.  
  193.   /* return -1 if ALL was pressed */
  194.  
  195.   char comment[MAX_COMMENT_LEN+1];
  196.  
  197.   int errnum=0;
  198.   BPTR FL;
  199.   struct FileInfoBlock *FB;
  200.   int doit=1;
  201.  
  202. #ifdef DEBUG
  203.   puts("ModifyComment()");
  204. #endif
  205.  
  206.   if (!usedefcomm)
  207.   {
  208.     if ((FL=Lock(filename,(long)ACCESS_READ))==NULL)
  209.     {
  210.       errnum=IoErr();
  211.     }
  212.     else
  213.     {
  214.       if(FB=malloc(sizeof(struct FileInfoBlock)))
  215.       {
  216.         errnum= !Examine(FL,FB);
  217.         if (!errnum)
  218.         {
  219.           strcpy(comment,FB->fib_Comment);
  220.           free(FB);
  221.         }
  222.         UnLock(FL);
  223.       }
  224.       else
  225.       {
  226.         errnum=103; /* NO MEM! */
  227.       }
  228.     }
  229.   }
  230.   else
  231.   {
  232.     strcpy(comment,defaultcomment);
  233.   }
  234.   if (!errnum)
  235.   {
  236.     if (!usedefcomm)
  237.     {
  238.       switch(rtGetString (comment, MAX_COMMENT_LEN, "Modify Comment", NULL,
  239.                               RTGS_GadFmt, "Ok|ALL|Cancel",
  240.                               RT_Window,W,
  241.                               TAG_END))
  242.       {
  243.         case 2:
  244.           strcpy(defaultcomment,comment);
  245.           doit=2;
  246.           break;
  247.         case 0:
  248.           doit=0;
  249.           break;
  250.       }
  251.     }
  252.     if (doit)
  253.     {
  254.       SetComment(filename,comment);
  255.       errnum=IoErr();
  256.       if (!errnum && doit==2) errnum=-1;
  257.     }
  258.   }
  259.   return(errnum);
  260. }
  261.  
  262.  
  263. int filecopy(char *fromname,char *toname)
  264. {
  265.  
  266. /*
  267.  * Simple function to copy a file, return IoErr if it fails, else it returns 0
  268.  * (if it fails it *will* delete the destination file if it exists.)
  269.  */
  270.   LONG f1,f2;
  271.   ULONG *buf;
  272.   ULONG allocd,fromsize,nr,nw; /* ho ho ho, I forget to add the U to uword the first time..... */
  273.                /* makes life interesting when you can only copy files less than*/
  274.                /* 32768 bytes long......... hehehe!! */
  275.   BOOL cancel=FALSE,ChangedIt=FALSE,overwrite=FALSE;
  276.   int errnum=0;
  277.   BPTR FL;
  278.   struct FileInfoBlock *FB;
  279.   UWORD prot=240;
  280.   char reqstr[300]="\0";
  281.  
  282.  
  283. #ifdef DEBUG
  284.   puts("filecopy()");
  285. #endif
  286.  
  287.   actuallytransferred=AT_NO;
  288.  
  289.   if (FB=malloc(sizeof(struct FileInfoBlock)))
  290.   {
  291.  
  292.     if ((FL=Lock(fromname,(long)ACCESS_READ))==NULL)
  293.     {
  294.       errnum=IoErr();
  295.     }
  296.     else
  297.     {
  298.       errnum= !Examine(FL,FB);
  299.       if (!errnum)
  300.       {
  301.         prot=FB->fib_Protection;
  302.         fromsize=FB->fib_Size;
  303.       }
  304.       UnLock(FL);
  305.       if (prot & FIBF_READ)
  306.       {
  307.         if ((!setprotverify) || ((setprotverify) && (rtEZRequest("File Protected From Reading!\n"
  308.                                           "Shall I change the protection for a mo ?",
  309.                                           "_Ok|_Dont you dare!",NULL,(struct TagItem *)&reqtags,NULL))))
  310.         {
  311.           ChangedIt=TRUE;
  312.           SetProtection(fromname,240);
  313.         }
  314.       }
  315.     }
  316.  
  317.     if ((f1=Open(toname,MODE_OLDFILE))!=NULL)
  318.     {
  319.       IoErr(); // Clear IO Error..
  320.       ExamineFH(f1,FB);
  321.       if (autooverwrite)
  322.       {
  323.         overwrite=TRUE;
  324.       }
  325.       else
  326.       {
  327.         if (!skipall)
  328.         {
  329.           sprintf(reqstr,"Destination File Exists!\nNEW: %-32s %ld\nOLD: %-32s %ld\nOverwrite ?",fromname,fromsize,toname,FB->fib_Size);
  330.           switch (rtEZRequest(reqstr,"_Yes|_All|_Skip|Sk_ip All|_Rename|_Cancel",NULL,(struct TagItem *)&reqtags,NULL))
  331.           {
  332.             case 0: // Cancel
  333.               cancel=TRUE;
  334.               errnum=1;
  335.               break;
  336.             case 1: // YES
  337.               overwrite=TRUE;
  338.               break;
  339.             case 2: // ALL
  340.               tempautooverwrite=TRUE;
  341.               autooverwrite=TRUE;
  342.               overwrite=TRUE;
  343.               break;
  344.             case 3: // Skip
  345.               cancel=TRUE;
  346.               errnum=203; // object exists..
  347.               break;
  348.             case 4: // SkipAll
  349.               skipall=TRUE;
  350.               break;
  351.             case 5: // Rename
  352.               if (rtGetString(toname,MAX_PATH_LEN,"Enter New Name",NULL,RTGS_GadFmt, "Ok|Cancel",RT_Window,W,TAG_END)==0)
  353.               {
  354.                 cancel=TRUE;
  355.               }
  356.               break;
  357.           }
  358.         }
  359.         if (skipall) cancel=TRUE;
  360.       }
  361.       Close(f1);
  362.     }
  363.     free(FB);
  364.   }
  365.  
  366.   if (!cancel)
  367.   {
  368.     if ((f1=Open(fromname,MODE_OLDFILE))!=NULL)
  369.     {
  370.       if ((f2=Open(toname,MODE_NEWFILE))!=NULL)
  371.       {
  372.         allocd=0;
  373.         if (fromsize>max_copy_buf_size) fromsize=max_copy_buf_size;
  374.         if ((buf=AllocMem(fromsize,MEMF_PUBLIC))!=NULL)
  375.         {
  376.           allocd=fromsize;
  377.         }
  378.         if ((allocd==0) && (buf=AllocMem(COPYBUFSIZE,MEMF_PUBLIC))!=NULL)
  379.         {
  380.           allocd=COPYBUFSIZE;
  381.         }
  382.         if (allocd)
  383.         {
  384.           do
  385.           {
  386.             if (!(cancel=CheckStatCancel() ))
  387.             {
  388.               nr=Read(f1,buf,allocd);
  389.               nw=Write(f2,buf,nr);
  390.             }
  391.           } while (nr==nw && nr!=0 && !cancel);
  392.           if (nr!=nw)
  393.           {
  394.             errnum=IoErr();
  395.             if (!errnum) errnum=224;
  396.           }
  397.           FreeMem(buf,allocd);
  398.           if (cancel) errnum=1;
  399.         }
  400.         else
  401.         {
  402.           errnum=103;  /* NO FREE STORE! */
  403.         }
  404.         Close(f2);
  405.         if (errnum)
  406.         {
  407.           DeleteFile(toname);
  408.           IoErr();  /* Clear IO Error */
  409.         }
  410.       }
  411.       else
  412.       {
  413.         errnum=IoErr();
  414.       }
  415.       Close(f1);
  416.     }
  417.     else
  418.     {
  419.       errnum=IoErr();
  420.     }
  421.   }
  422.  
  423.   if (!errnum && !cancel)
  424.   {
  425.     if ((FL=Lock(fromname,(long)ACCESS_READ))==NULL)
  426.     {
  427.       errnum=IoErr();
  428.     }
  429.     else
  430.     {
  431.       FB=malloc(sizeof(struct FileInfoBlock));
  432.       errnum= !Examine(FL,FB);
  433.       if (!errnum)
  434.       {
  435.         SetComment(toname,FB->fib_Comment);
  436.         SetProtection(toname,prot);
  437.         SetFileDate(toname,&FB->fib_Date);
  438.         free(FB);
  439.         if (!overwrite) actuallytransferred=AT_YES;
  440.         else actuallytransferred=AT_OVERW;
  441.       }
  442.       UnLock(FL);
  443.     }
  444.   }
  445.   // moved from underneath the UnLock() above as it'd not get done if there was
  446.   // an error during the filecopying itself..
  447.   if (ChangedIt) SetProtection(fromname,prot);
  448.  
  449.   return(errnum);
  450. }
  451.  
  452. int filenuke(char *nukename)
  453. {
  454.   int errnum;
  455.  
  456. #ifdef DEBUG
  457.   puts("filenuke()");
  458. #endif
  459.  
  460.   DeleteFile(nukename);
  461.   errnum=IoErr();
  462.   if (errnum)
  463.   {
  464.     SetProtection(nukename,240);
  465.     errnum=IoErr();
  466.     if (!errnum)
  467.     {
  468.       DeleteFile(nukename);
  469.       errnum=IoErr();
  470.     }
  471.   }
  472.   return(errnum);
  473. }
  474.  
  475. int fileswap(char *fromname,char *toname)
  476. {
  477.   int errnum=0;
  478.  
  479. #ifdef DEBUG
  480.   puts("fileswap()");
  481. #endif
  482.  
  483.   if (!Rename(fromname,toname))
  484.   {
  485.     errnum=filecopy(fromname,toname);
  486.     if (errnum<=0)
  487.     {
  488.       errnum=filenuke(fromname);
  489.     }
  490.   }
  491.   else actuallytransferred=AT_YES;
  492.   return(errnum);
  493. }
  494.  
  495. void Makedir(short side)
  496. {
  497.   char strbuf[MAX_PATH_LEN+1];
  498.   BPTR FL;
  499.   int errnum;
  500.  
  501. #ifdef DEBUG
  502.   puts("Makedir()");
  503. #endif
  504.  
  505.   if (pathok[side])
  506.   {
  507.     strcpy(strbuf,cpath[side]);
  508.     addterm(strbuf);
  509.     if (rtGetString (strbuf, MAX_PATH_LEN, "Enter Directory Name", NULL,RT_Window,W, TAG_END))
  510.     {
  511.       if (strlen(FilePart(strbuf))>30)
  512.       {
  513.         rtEZRequest("Name Too Long!","Bogus!",NULL,(struct TagItem *)&reqtags,NULL);
  514.       }
  515.       else
  516.       {
  517.         FL=CreateDir(strbuf);
  518.         if (FL==NULL)
  519.         {
  520.           rtEZRequest ("Error Creating Directory","Bogus",NULL,(struct TagItem *)&reqtags,NULL);
  521.         }
  522.         else
  523.         {
  524.           UnLock(FL);
  525.  
  526.           if (SameDir(strbuf,cpath[side]))
  527.           {
  528.             if (AddToFileList(side,FilePart(strbuf),0,1,FALSE)) Updatedisplay(side);
  529.           }
  530.  
  531.           if (rtEZRequest("Do you want an icon ?","Yes|No",NULL,(struct TagItem *)&reqtags,NULL))
  532.           {
  533.             strfcat(strbuf,".info",MAX_PATH_LEN);
  534.             errnum=filecopy(defaulticonfile,strbuf);
  535.             if (errnum) DosError("Error Copying Icon File",defaulticonfile,errnum);
  536.             if (!errnum && SameDir(strbuf,cpath[side]))
  537.             {
  538.               if (AddToFileList(side,FilePart(strbuf),getfilesize(strbuf),-1,FALSE)) Updatedisplay(side);
  539.             }
  540.           }
  541.         }
  542.       }         /* it's attack of the killer pretty patterns!!! */
  543.     }           /* sorry, I just couldnt resist it... :-0 */
  544.   }
  545. }
  546.  
  547. int DirFunc(char *dirname,char *todirname,int mode)
  548. {
  549.   char fname[MAX_PATH_LEN+1],tofname[MAX_PATH_LEN+1];
  550.   BOOL cancel=FALSE;
  551.   int FuncErr=0;
  552.   BPTR FL;
  553.   struct FileInfoBlock *FB;
  554.   long err;
  555.   int rret=FALSE;
  556.  
  557. #ifdef DEBUG
  558.   puts("DirFunc()");
  559. #endif
  560.  
  561.   /* attempt a rename on a swap command for a directory */
  562.  
  563.   if (mode==G_Swap)
  564.   {
  565.     rret=Rename(dirname,todirname);
  566.   }
  567.  
  568.   if ((!rret && mode==G_Swap) || mode!=G_Swap)
  569.   {
  570.     switch (mode)
  571.     {
  572.       case G_Swap:
  573.       case G_Copy:
  574.         if ((FL=CreateDir(todirname))!=NULL)
  575.         {
  576.           UnLock(FL);
  577.         }
  578.         break;
  579.     }
  580.  
  581.     if ((FL=Lock(dirname,(long)ACCESS_READ))==NULL)
  582.     {
  583.       FuncErr=IoErr();
  584.     }
  585.     else
  586.     {
  587.       FB=malloc(sizeof(struct FileInfoBlock));
  588.       err= !Examine(FL,FB);
  589.       if (!err)
  590.       {
  591.         do
  592.         {
  593.           cancel=CheckStatCancel();
  594.           handlerefresh();
  595.           if (!cancel)
  596.           {
  597.             FuncErr=0;
  598.             if (mode==G_Delete)
  599.             {
  600.               // changed for v4.2, since i got a 2.04 machine I've found a bug
  601.               // when deleting files in the ram disk:
  602.               // so this always reads the first enry in the dir..
  603.               if (!(err= !Examine(FL,FB)))
  604.               {
  605.                 err=!ExNext(FL,FB);
  606.               }
  607.             }
  608.             else
  609.             {
  610.               err=!ExNext(FL,FB);
  611.             }
  612.             if (!err)
  613.             {
  614.               strcpy(fname,dirname);
  615.               addterm(fname);
  616.               strfcat(fname,FB->fib_FileName,MAX_PATH_LEN);
  617.  
  618.               strcpy(tofname,todirname);
  619.               addterm(tofname);
  620.               strfcat(tofname,FB->fib_FileName,MAX_PATH_LEN);
  621.  
  622.               if (FB->fib_DirEntryType<0)
  623.               { /* FILE */
  624.                 switch (mode)
  625.                 {
  626.                   case G_Delete:
  627.                     UpdateStat(0,0,"Delete",dirname,"",FB->fib_FileName);
  628.                     FuncErr=filenuke(fname);
  629.                     break;
  630.                   case G_Copy:
  631.                     UpdateStat(0,0,"Copy",dirname,todirname,FB->fib_FileName);
  632.                     FuncErr=filecopy(fname,tofname);
  633.                     break;
  634.                   case G_Swap:
  635.                     UpdateStat(0,0,"Swap",dirname,todirname,FB->fib_FileName);
  636.                     FuncErr=fileswap(fname,tofname);
  637.                     break;
  638.                 }
  639.               }
  640.               else
  641.               {
  642.                 if (FB->fib_DirEntryType>0)
  643.                 {
  644.                   switch (mode)
  645.                   {
  646.                     case G_Delete:
  647.                       UpdateStat(0,0,"Delete",dirname,"",FB->fib_FileName);
  648.                       FuncErr=DirFunc(fname,NULL,mode);
  649.                       break;
  650.                     case G_Copy:
  651.                       UpdateStat(0,0,"Copy",dirname,todirname,FB->fib_FileName);
  652.                       FuncErr=DirFunc(fname,tofname,mode);
  653.                       break;
  654.                     case G_Swap:
  655.                       UpdateStat(0,0,"Swap",dirname,todirname,FB->fib_FileName);
  656.                       FuncErr=DirFunc(fname,tofname,mode);
  657.                       break;
  658.                   }
  659.                 }
  660.                 else
  661.                 {
  662.                   rtEZRequest ("Encountered A Strange File Entry!","Hmm, I'll check my disk",NULL,(struct TagItem *)&reqtags,NULL);
  663.                }
  664.               }
  665.               if (FuncErr>1)
  666.               {
  667.                 DosError("Error On File/Dir",fname,FuncErr);
  668.               }
  669.             }
  670.             if (FuncErr==1) cancel=TRUE;
  671.           }
  672.           else
  673.           {
  674.             FuncErr=1; /* CANCEL */
  675.           }
  676.         } while (!err && !cancel);
  677.       }
  678.       UnLock(FL);
  679.       free(FB);
  680.       if (!cancel /*&& !FuncErr*/  )
  681.       {
  682.         switch (mode)
  683.         {
  684.           case G_Swap:
  685.           case G_Delete:
  686.             DeleteFile(dirname);
  687.             FuncErr=IoErr();
  688.             break;
  689.         }
  690.       }
  691.     }
  692.   }
  693.   return(FuncErr);
  694. }
  695.  
  696. long ExecCommand(char *command,BOOL asynch,BOOL shuffle)
  697. {
  698.   static ULONG sysargs[] =
  699.   {
  700.     SYS_Input,NULL,
  701.     SYS_Output,NULL,
  702.     SYS_Asynch,FALSE,  /* add option to this */
  703.     SYS_UserShell,TRUE,
  704.     NP_Priority,0L,
  705.     TAG_DONE
  706.   };
  707.   BPTR outputfile;
  708.   long retval=0;
  709.   char constr[500];
  710.  
  711.   remspaces(command,command);
  712.  
  713.   if (shuffle && customscreenopen) ScreenToBack(mysc);
  714.  
  715.   sysargs[5]=asynch ? TRUE : FALSE;
  716.  
  717.   replace(constr,outputcon,"@S@",screenname);
  718.  
  719.   if (sysargs[5]) /* open a new window if asynch otherwise use normal one */
  720.   {
  721.     outputfile = Open(constr,MODE_OLDFILE);
  722.   }
  723.   else
  724.   {
  725.     /* test to see if one is already open, if not open it! */
  726.     if (outputconfile==NULL) outputconfile = Open(constr,MODE_OLDFILE);
  727.     outputfile=outputconfile;
  728.   }
  729.   if (outputfile) /* have we got an output file ? */
  730.   {
  731.     sysargs[1]=(ULONG)outputfile;
  732.     retval=SystemTagList(command,(struct TagItem *)sysargs);
  733.     if (shuffle && customscreenopen && !asynch) ScreenToFront(mysc);
  734.   }
  735.   return(retval);
  736. }
  737.  
  738. void DoFormat( void )
  739. {
  740.   char *pmsg="Yes|No";
  741.   LONG which,FFS,DC,ICONS,QUICK;
  742.   char cmdstr[81]="\0",name[33]="\0";
  743.  
  744.   if ((which=rtEZRequest("Format What Drive ?","DF_0:|DF_1:|DF_2:|DF_3:|_CANCEL",NULL,(struct TagItem *)&reqtags,NULL))
  745.     && (rtGetString (name, 32, "Enter Volume Name", NULL,RT_Window,W, TAG_END))
  746.     && (name[0]!='\0'))
  747.   {
  748.     FFS=rtEZRequest("Fast File System ?",pmsg,NULL,(struct TagItem *)&reqtags,NULL);
  749.     DC=rtEZRequest("Directory Cache ?",pmsg,NULL,(struct TagItem *)&reqtags,NULL);
  750.     ICONS=rtEZRequest("Trashcan ?",pmsg,NULL,(struct TagItem *)&reqtags,NULL);
  751.     QUICK=rtEZRequest("QuickFormat ?",pmsg,NULL,(struct TagItem *)&reqtags,NULL);
  752.  
  753.     sprintf(cmdstr,"FORMAT DRIVE DF%d: NAME %s %s %s %s %s",which-1,name,FFS ? "FFS" : "",DC ? "DIRCACHE" : "",ICONS ? "" : "NOICONS",QUICK ? "QUICK" : "");
  754.     ExecCommand(cmdstr,TRUE,shufflescreens);
  755.   }
  756. }
  757.  
  758. void cdto( char *path )
  759. {
  760.   BPTR FL,NFL;
  761.  
  762.   if (FL=Lock(path,(long)ACCESS_READ))
  763.   {
  764.     NFL=CurrentDir(FL);
  765.     UnLock(NFL);
  766.   }
  767. }
  768.