rfx.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,950 行 · 第 1/4 页
C
1,950 行
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Remote File eXchange utility.
*
****************************************************************************/
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <conio.h>
#include <ctype.h>
#include <process.h>
#include <dos.h>
#include "fparse.h"
#include "banner.h"
#include "dbgdefn.h"
#include "dbgio.h"
#include "dbgtoggl.h"
#include "trpcore.h"
#include "trpfile.h"
#include "dta.h"
#include "trprfx.h"
#include "tcerr.h"
#include "local.h"
char _Literal_No_Mem_4_Path[] = { "no memory for PATH" };
enum {
IO_OK,
IO_EOF,
IO_FILE_NOT_FOUND,
IO_PATH_NOT_FOUND,
IO_NO_HANDLES,
IO_NO_ACCESS,
IO_BAD_HANDLE,
IO_BAD_MEM,
IO_NO_MEM,
IO_BAD_ADDR,
IO_BAD_ENV,
IO_BAD_FORMAT,
IO_BAD_ACCESS,
IO_BAD_DATA,
IO_EOR,
IO_BAD_DRIVE,
IO_BAD_RMDIR,
IO_DIFF_DEV,
IO_NO_FILES,
IO_CANT_COPY_TO_SELF,
IO_DUP_OR_NOT_FOUND,
IO_INTERRUPT,
IO_DISK_FULL,
IO_FIND_ERROR = 2,
IO_FIND_NO_MORE_FILES = 18,
};
#define IO_SUBDIRECTORY 0x10
#define BUFF_LEN 4096
typedef struct copyspec {
struct copyspec *next;
char *src;
int src_loc;
char *dst;
int dst_loc;
} COPYSPEC, *COPYPTR;
extern void SysFileInit( void );
extern void PathInit( void );
extern bool InitTrap( char * );
extern bool InitFileSupp( void );
extern bool InitRFXSupp( void );
extern void FiniTrap( void );
extern void InitInt( void );
extern void FiniInt( void );
extern int CtrlCHit( void );
extern char *RealFName( char *, open_access * );
extern sys_error GetSystemErrCode( unsigned );
extern unsigned RemoteWriteConsole( void *, unsigned );
extern unsigned GetLastErr(void);
extern sys_handle GetSystemHandle(handle);
extern char *_FileParse( char *name, file_parse *file );
extern char *Squish( file_parse *parse, char *into );
extern unsigned RemoteRename( char *, char * );
extern unsigned RemoteMkDir( char *);
extern unsigned RemoteRmDir( char *);
extern unsigned RemoteSetDrv( int );
extern int RemoteGetDrv(void);
extern unsigned RemoteSetCWD( char *);
extern long RemoteGetFileAttr( char * );
extern unsigned RemoteSetFileAttr( char * , long );
extern long RemoteGetFreeSpace( int );
extern unsigned RemoteDateTime( sys_handle , int *, int *, int);
extern unsigned RemoteGetCwd( int , char *);
extern unsigned RemoteFindFirst( char *, void *, unsigned , int );
extern unsigned RemoteFindNext( void *, unsigned );
extern unsigned RemoteFindClose(void);
dbg_switches DbgSwitches;
char *TrpFile;
char *TxtBuff;
char Buff[ BUFF_LEN ];
char NullStr[] = { '\0' };
int MaxOnLine = { 0 };
int Typing = { 0 };
int ErrorStatus = { 0 };
int DefaultLocation = { 0 };
static file_parse Parse1;
static file_parse Parse2;
static file_parse Parse3;
static char Name1[MAX_DRIVE+MAX_PATH+MAX_NAME+MAX_EXT+2];
static char Name2[MAX_DRIVE+MAX_PATH+MAX_NAME+MAX_EXT+2];
static char Name3[MAX_DRIVE+MAX_PATH+MAX_NAME+MAX_EXT+2];
static int FilesCopied;
static int DirectoriesMade;
trap_dta Info;
system_config SysConfig;
COPYPTR CopySpecs;
#define REAL_CODE( err ) (GetSystemErrCode(err)&0xffff)
#define NL "\r\n"
char HelpText[] = {
NL
"Commands which accept special file names are:" NL
NL
" copy [/s] src_spec [dst_spec] [/s] - copy files (/s=recursive)" NL
" dir [/w] dir_spec [/w] - directory (/w=wide)" NL
" cd dir_spec - set current directory" NL
" chdir dir_spec - set current directory" NL
" md dir_spec - create directory" NL
" mkdir dir_spec - create directory" NL
" rd [/s] dir_spec [/s] - delete directory" NL
" rmdir [/s] dir_spec [/s] - delete directory" NL
" type dir_spec - type a file" NL
" del [/s] file_spec [/s] - erase files (/s= recursive)" NL
" erase [/s] file_spec [/s] - erase files (/s= recursive)" NL
" ren src_spec dst_spec - rename files" NL
" drive: - set drive and XXLcle" NL
" exit - leave rfx" NL
NL
" Special file names are the same as DOS file names except" NL
" they may be preceded by a XXLcle specifier of the form:" NL
" @[XXLcle]" NL
" - where: XXLcle = 'l' for XXLcl machine, 'r' for XXRem machine" NL
" - if a file name starts with an '@', then double it e.g. '@@file'" NL
" Note:" NL
" If [dst_spec] is omitted from the copy command, it defaults to the" NL
" current directory on the machine NOT specified by [src_spec]" NL
};
char * ErrMessages[] = {
"",
"End of file encountered",
"File not found",
"Path not found",
"Too many open files",
"Access denied",
"Invalid operation",
"Memory control blocks destroyed",
"Insufficient memory",
"Invalid memory block address",
"Invalid environment",
"Invalid format",
"Invalid access code",
"Invalid data",
"Record truncated",
"Invalid drive",
"Attempt to remove current directory",
"Not same device",
"No more files",
"File cannot be copied to itself",
"Duplicate file name or file not found",
"Interrupted from keyboard",
"Disk is full",
/* Start of Critical error messages */
"Attempt to write on write-protected diskette",
"Unknown unit",
"Device not ready",
"Unknown command",
"Data error (CRC)",
"Bad request structure length",
"Seek error",
"Unknown media type",
"Sector not found",
"Printer out of paper",
"Write fault",
"Read fault",
"General failure"
};
static char * Day[] = {
"Sun ",
"Mon ",
"Tue ",
"Wed ",
"Thu ",
"Fri ",
"Sat "
};
/**************************************************************************/
/* UTILITIES */
/**************************************************************************/
static void Help( void )
{
WriteStream( STD_ERR, HelpText, sizeof( HelpText )-1 );
}
static void WhatDidYouSay( void )
{
#define whadjasay "Not understood: Type '?' for help"
WriteText( STD_ERR, whadjasay, sizeof( whadjasay )-1 );
}
static void Error( char *err )
{
WriteText( STD_ERR, err, strlen( err ) );
}
static void Usage( void )
{
Error( "Usage: rfx trap_file[;trap_parm] [rfx_command]" );
}
char *StrCopy( char *src, char *dest )
{
while( (*dest = *src) != 0 ) {
++src;
++dest;
}
return( dest );
}
static char *RealRFXName( char *name, int *loc )
{
open_access op;
name = RealFName( name, &op );
if( op & OP_LOCAL ) {
*loc = -1;
} else if( op & OP_REMOTE ) {
*loc = 1;
} else {
*loc = 0;
}
return( name );
}
static open_access RFX2Acc( int loc )
{
if( loc == 0 ) loc = DefaultLocation;
if( loc < 0 ) return( OP_LOCAL );
return( OP_REMOTE );
}
static char * RealName( char * name, int * loc )
{
name = RealRFXName( name, loc );
if( *loc == 0 ) {
*loc = DefaultLocation;
}
if( *name == '\0' ) return( "." );
return( name );
}
void StartupErr( char *err )
{
Error( err );
exit( 2 );
}
void RestoreHandlers( void )
{
}
void GrabHandlers( void )
{
}
void WriteNL( void )
{
WriteStream( STD_ERR, NL, sizeof( NL ) - 1 );
}
void CheckError( void )
{
char *p;
char buff[ 256 ];
if( ErrorStatus != 0 ) {
p = SysErrMsg( ErrorStatus, buff );
WriteText( STD_ERR, buff, p - buff );
}
while( CopySpecs ) {
FreeCopySpec( CopySpecs );
}
}
void *DbgAlloc( int size )
{
return( malloc( size ) );
}
void DbgFree( void * chunk )
{
free( chunk );
}
void FreeRing( void )
{
}
int WriteBoth( char * buff, int len ) {
int written;
written = WriteStream( STD_ERR, buff, len );
if( written != len ) return( written );
written = RemoteWriteConsole( buff, len );
return( written );
}
unsigned TransSetErr( unsigned err )
{
ErrorStatus = err;
return( err );
}
unsigned SysSetErr( int err )
{
return( TransSetErr( StashErrCode( err, OP_LOCAL ) ) );
}
char *MyStrDup( char * str ) {
char * new;
new = DbgAlloc( strlen( str ) + 1 );
strcpy( new, str );
return( new );
}
extern char *Copy( void *s, void *d, int len ) {
char *dst = d,*src = s;
while( len-- ) {
*dst++ = *src++;
}
return( dst );
}
extern char *Fill( void *d, int len, char filler ) {
char *dst = d;
while( len-- ) {
*dst++ = filler;
}
return( dst );
}
extern char *CopyStr( char *src, char *dst ) {
while( *dst++ = *src++ );
return( dst - 1 );
}
extern void DItoD( long s, char *d ) {
if( s == 0 ) {
*d = '0';
} else {
do {
*d-- = s % 10 + '0';
s /= 10;
} while( s != 0 );
}
}
extern void ItoD( unsigned int i, char *b ) {
b[ 1 ] = i % 10 + '0';
i /= 10;
b[ 0 ] = i % 10 + '0';
}
/**************************************************************************/
/* ACTUAL OS CALLS */
/**************************************************************************/
char GetDrv( int loc )
/********************/
{
if( loc == 1 ) {
return( RemoteGetDrv() + 'A' );
} else {
return( LocalGetDrv() + 'A' );
}
}
void SetDrv( int drive, int loc )
/*******************************/
{
drive = toupper( drive );
if( loc == 1 ) {
RemoteSetDrv( drive - 'A' );
} else {
LocalSetDrv( drive - 'A' );
}
if( GetDrv( loc ) != drive ) {
SysSetErr( IO_BAD_DRIVE );
}
}
unsigned RemoveDir( char *name, int loc )
/***********************************/
{
if( loc == 1 ) {
return( RemoteRmDir( name ) );
} else {
return( LocalRmDir( name ) );
}
}
unsigned SetDir( char *name, int loc )
/********************************/
{
if( loc == 1 ) {
return( RemoteSetCWD( name ) );
} else {
return( LocalSetCWD( name ) );
}
}
unsigned GetDir( int drive, char *name, int loc )
/*******************************************/
{
/* drive=0 means current drive A:=1, B:=2, etc. */
if( loc == 1 ) {
return( RemoteGetCwd( drive, name ) );
} else {
return( LocalGetCwd( drive, name ) );
}
}
unsigned Erase( char *name, int loc )
/*******************************/
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?