home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
bbs
/
mar94
/
os20
/
cli
/
move.lha
/
Move
/
Move.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-31
|
28KB
|
1,178 lines
/*
Auto: sc <file>
*/
/* $Revision Header built automatically *************** (do not edit) ************
**
** © Copyright by GuntherSoft
**
** File : SnakeSYS:CPrgs/Utils/Move.c
** Created on : Wednesday, 11.08.93 15:01:14
** Created by : Kai Iske
** Current revision : V1.8
**
**
** Purpose
** -------
** - Small move utility which supports wildcards and doesn`t use
** Rename() nor Copy() nor anything similar...
**
** Revision V1.8
** --------------
** created on Sunday, 19.12.93 01:44:05 by Kai Iske. LogMessage :
** -*- changed on Sunday, 19.12.93 01:47:54 by Kai Iske. LogMessage :
** - Added PURE information to Doc, since Move really is pure
** (Suggested by : Albert-Jan Brouver)
** -*- changed on Sunday, 19.12.93 01:46:23 by Kai Iske. LogMessage :
** - Due to the move-renaming bug one couldn`t rename a dir
** an Assign was put on.
** (Reported by : Albert-Jan Brouver)
** -*- created on Sunday, 19.12.93 01:44:05 by Kai Iske. LogMessage :
** - Fixed move-renaming of directories.
** (Reported by : Albert-Jan Brouver)
** - Move had some severe problems recursively moving
** the contents of a directory
**
** Revision V1.7
** --------------
** created on Saturday, 04.12.93 23:19:03 by Kai Iske. LogMessage :
** -*- changed on Saturday, 04.12.93 23:26:25 by Kai Iske. LogMessage :
** - Error while moving to a "device full" disk
** (Reported by : Chris Conger)
** -*- created on Saturday, 04.12.93 23:19:03 by Kai Iske. LogMessage :
** - FileName length-bug fixed
** (Reported by : Juergen Lang)
** - Recompiled using SAS 6.50
** - Stack usage reduced
**
** Revision V1.6
** --------------
** created on Friday, 15.10.93 15:51:13 by Kai Iske. LogMessage :
** -*- changed on Saturday, 16.10.93 15:17:29 by Kai Iske. LogMessage :
** - Move got screwed up, when attempting to move a
** zero size file
** -*- changed on Friday, 15.10.93 16:03:35 by Kai Iske. LogMessage :
** - Added Buffer Keyword to specify the maximum buffer
** size for an inter device move. Normally Move would have used
** the max amount of available free memory in order to
** accomplish the move, or the size needed by the file...
** (Suggested by : Christof Damian)
** -*- created on Friday, 15.10.93 15:51:13 by Kai Iske. LogMessage :
** - One couldn`t rename a file using move, because the
** "destination" file was removed before doing the rename,
** ie. the source file was deleted.
** (Reported by : Chris Conger)
**
** Revision V1.5
** --------------
** created on Tuesday, 05.10.93 01:42:53 by Kai Iske. LogMessage :
** -*- changed on Tuesday, 05.10.93 02:03:22 by Kai Iske. LogMessage :
** - Freed the FileInfoBlock _BEFORE_ setting the Bits, Comment
** etc. This lead to MungWall hits (of course it did)
** (Reported by Nico Francois)
** -*- created on Tuesday, 05.10.93 01:42:53 by Kai Iske. LogMessage :
** - Exidentially called one ExAll() without ED_SIZE
** This lead to some calls to DoTheMove without the Size set ;)
** (Reported by Karsten Weiss)
**
** Revision V1.4
** --------------
** created on Friday, 01.10.93 16:55:15 by Kai Iske. LogMessage :
** -*- created on Friday, 01.10.93 16:55:15 by Kai Iske. LogMessage :
** - Now uses Rename() when source and dest are on the same
** device. This is faster ;) Why haven`t I thought of that
** earlier ??? ;)
**
** Revision V1.3
** --------------
** created on Wednesday, 25.08.93 16:32:43 by Kai Iske. LogMessage :
** - UnLock Problem solved when doing recursive Dir-Moves
** This bug lead to "Object in use" error messages
**
** Revision V1.2
** --------------
** created on Tuesday, 17.08.93 22:48:38 by Kai Iske. LogMessage :
** - Added CTRL-C checking
** - Added FORCE Flag in order to move read/deleteprotected or
** to overwrite a delete/writeprotected files
**
** Revision V1.1
** --------------
** created on Monday, 16.08.93 22:53:34 by Kai Iske. LogMessage :
** - Added well known CLONE, DATES, COM, NOPRO,
** QUIET and NOREQ options also used by e.g. Rename
**
** Revision V1.0
** --------------
** created on Wednesday, 11.08.93 15:01:14 by Kai Iske. LogMessage :
** --- Initial release ---
**
*********************************************************************************/
#define REVISION "1.8"
#define REVDATE "19.12.93"
#define REVTIME "01:47:54"
#define AUTHOR "Kai Iske"
#define VERNUM 1
#define REVNUM 8
#include <string.h>
#include <stdlib.h>
#include <exec/types.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <exec/memory.h>
#include <exec/execbase.h>
#include <dos/exall.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
/**********************************************************************/
/* Defines for Flags */
/**********************************************************************/
#define CLONE 0x0001
#define DATES 0x0002
#define NOPRO 0x0004
#define COM 0x0008
#define QUIET 0x0010
#define FORCE 0x0020
#define WATCHSIGS SIGBREAKF_CTRL_C
/**********************************************************************/
/* Static char definitions */
/**********************************************************************/
static const char *Version = "$VER: Move "REVISION" ("REVDATE")\0";
static const char *Template = "FROM/M,TO/A,CLONE/S,DATES/S,NOPRO/S,COM/S,QUIET/S,NOREQ/S,FORCE/S,BUFFER/N/K";
enum {FROM_ARG, TO_ARG, CLONE_ARG, DATES_ARG, NOPRO_ARG, COM_ARG, QUIET_ARG, NOREQ_ARG, FORCE_ARG, BUFFER_ARG, LAST_ARG};
/**********************************************************************/
/* Prototypes */
/**********************************************************************/
int __saveds DoMove(void);
BOOL __stdargs DoTheMove(char *FromFile, char *ToPath, BOOL PatternFrom, BPTR OutHandle, struct DOSBase *DOSBase, LONG Type, ULONG Size, UWORD CopyFlags, LONG *HitMask, ULONG MaxBuffer);
BOOL __stdargs DoMoveFile(char *FromFile, char *ToPath, char *Buffer, BPTR OutHandle, struct DOSBase *DOSBase, ULONG Size, UWORD CopyFlags, LONG *HitMask, ULONG MaxBuffer);
/**********************************************************************/
/* The main program */
/**********************************************************************/
int __saveds DoMove(void)
{
struct FileInfoBlock *FIB;
struct ExecBase *SysBase = *((struct ExecBase **)0x4L);
struct DOSBase *DOSBase;
struct Process *MyProc = (struct Process *)SysBase->ThisTask;
struct RDArgs *RDArgs;
struct ExAllControl *EAC;
struct ExAllData *EAB, *EAD;
APTR *Args,
*OldWindow;
BPTR DirLock,
OutHandle;
char **FromPtr;
char *ToPtr;
char *Pattern;
char *PathName = NULL;
char *Buffer = NULL;
LONG HitMask;
UWORD NumFrom = 0, PatternType, CopyFlags = 0;
ULONG MaxBuffer = 0;
BOOL PatternFrom, GoOn = FALSE, Scanning;
// Ignore startup from WB
if(!(MyProc->pr_CLI))
{
struct Message *MyMsg;
WaitPort(&MyProc->pr_MsgPort);
MyMsg = GetMsg(&MyProc->pr_MsgPort);
Disable();
ReplyMsg(MyMsg);
return(10);
}
// Do the wild thing
if((DOSBase = (struct DOSBase *)OpenLibrary("dos.library", 37)))
{
// Allocate buffers
if((Pattern = AllocVec(1024, MEMF_CLEAR)) && (PathName = AllocVec(1024, MEMF_CLEAR)) && (Buffer = AllocVec(1024, MEMF_CLEAR)))
{
if((FIB = AllocVec(sizeof(struct FileInfoBlock), MEMF_CLEAR)))
{
// Get buffer for ReadArgs()
if((Args = AllocVec((LAST_ARG * sizeof(ULONG)), MEMF_CLEAR)))
{
// Get structure for ExAll()
if((EAC = AllocDosObject(DOS_EXALLCONTROL, NULL)))
{
// Get buffer for ExAll()
if((EAB = AllocVec((sizeof(struct ExAllData)*20), MEMF_CLEAR)))
{
// Parse commandline
if((RDArgs = ReadArgs((char *)Template, (LONG *)Args, NULL)))
{
// From and to really there ??
if(Args[FROM_ARG] && Args[TO_ARG])
{
// A O.K. so far
GoOn = TRUE;