📄 ckufio.c
字号:
#ifdef OS2char *ckzv = "OS/2 File support, 5A(067) 11 Nov 92";#else#ifdef aegischar *ckzv = "Aegis File support, 5A(067) 11 Nov 92";#elsechar *ckzv = "UNIX File support, 5A(067) 11 Nov 92";#endif /* aegis */#endif /* OS2 *//* C K U F I O -- Kermit file system support for UNIX, OS/2, and Aegis *//* Author: Frank da Cruz (fdc@columbia.edu, FDCCU@CUVMA.BITNET), Columbia University Center for Computing Activities. First released January 1985. Copyright (C) 1985, 1992, Trustees of Columbia University in the City of New York. Permission is granted to any individual or institution to use this software as long as it is not sold for profit. This copyright notice must be retained. This software may not be included in commercial products without written permission of Columbia University.*//* Include Files */#include "ckcdeb.h"#include <signal.h>#ifdef MINIX#include <limits.h>#endif /* MINIX */#ifdef POSIX#include <limits.h>#endif /* POSIX *//* Directory structure header file */#ifdef OS2/* C-Kermit's OS/2 support originally by Chris Adie <C.Adie@uk.ac.edinburgh> Edinburgh University Computing Service, Scotland, for C-Kermit 4F. Adapted to C-Kermit 5A and integrated into the UNIX support module by Kai Uwe Rommel <rommel@informatik.tu-muenchen.de>, Muenchen, Germany, December 1991.*//* Directory Separator macros, to allow this module to work with both UNIX and OS/2: Because of ambiguity with the command line editor escape \ character, the directory separator is currently left as / for OS/2 too, because the OS/2 kernel also accepts / as directory separator. But this is subject to change in future versions to conform to the normal OS/2 style.*/#define DIRSEP '/'/* #define DIRSEP '\\' */#define ISDIRSEP(c) ((c)=='/'||(c)=='\\')#else /* not OS2 */#define DIRSEP '/'#define ISDIRSEP(c) ((c)=='/')#endif /* OS2 */#ifdef SDIRENT#define DIRENT#endif /* SDIRENT */#ifdef XNDIR#include <sys/ndir.h>#else /* !XNDIR */#ifdef NDIR#include <ndir.h>#else /* !NDIR, !XNDIR */#ifdef RTU#include "/usr/lib/ndir.h"#else /* !RTU, !NDIR, !XNDIR */#ifdef DIRENT#ifdef SDIRENT#include <sys/dirent.h>#else#include <dirent.h>#endif /* SDIRENT */#else#ifdef OS2#define OPENDIR#define DIRENT#include "ckodir.h"#else/* !RTU, !NDIR, !XNDIR, !DIRENT, !OS2, i.e. all others */#include <sys/dir.h>#endif /* OS2 */#endif /* DIRENT */#endif /* RTU */#endif /* NDIR */#endif /* XNDIR */#ifdef OS2 /* OS/2 file system interface */#define BSD4 /* is like Berkeley UNIX */#define NOFILEH /* with no <file.h> */#include <sys/utime.h>#include <stdlib.h>#include <process.h>extern int binary; /* We need to know this for open() */#ifdef __IBMC__extern FILE *popen(char *, char *);extern int pclose(FILE *);#else#ifndef __EMX__#define popen _popen#define pclose _pclose#include <share.h>#define fopen(n, m) _fsopen(n, m, SH_DENYWR)#endif /* __EMX__ */#endif /* __IBMC__ */#else#include <pwd.h> /* Password file for shell name */#endif /* OS2 */#ifndef OS2#ifdef SYSUTIMEH /* <sys/utime.h> if requested, */#include <sys/utime.h> /* for extra fields required by */#endif /* SYSUTIMEH */ /* 88Open spec. */#endif /* OS2 */#ifdef BSD44 /* BSD 4.4 */#define TIMESTAMP /* Can do file dates */#include <sys/time.h>#include <sys/timeb.h>#else#ifdef BSD4 /* BSD 4.3 and below */#define TIMESTAMP /* Can do file dates */#include <time.h> /* Need this */#include <sys/timeb.h> /* Need this if really BSD */#else#ifdef ATTSV/* 4.4 BSD uses utimes() instead of utime() for this, which accepts a...*/#define TIMESTAMP#include <time.h>/* void tzset(); (the "void" type upsets some compilers) */#ifndef ultrixextern long timezone;#endif /* ultrix */#endif /* ATTSV */#endif /* BSD4 */#endif /* BSD44 *//* Is `y' a leap year? */#define leap(y) (((y) % 4 == 0 && (y) % 100 != 0) || (y) % 400 == 0)/* Number of leap years from 1970 to `y' (not including `y' itself). */#define nleap(y) (((y) - 1969) / 4 - ((y) - 1901) / 100 + ((y) - 1601) / 400)#ifdef COMMENT /* not used *//* Number of days in each month of the year. */static char monlens[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };#endif /* COMMENT */#ifdef CIE#include <stat.h> /* File status */#else#include <sys/stat.h>#ifdef OS2#include <sys/types.h>/* because standard stat has trouble with trailing /'s we have to wrap it */int os2stat(char *, struct stat *);#define stat(path, buf) os2stat(path, buf)#endif /* OS2 */#endif /* CIE *//* Functions (n is one of the predefined file numbers from ckcker.h): zopeni(n,name) -- Opens an existing file for input. zopeno(n,name,attr,fcb) -- Opens a new file for output. zclose(n) -- Closes a file. zchin(n,&c) -- Gets the next character from an input file. zsinl(n,&s,x) -- Read a line from file n, max len x, into address s. zsout(n,s) -- Write a null-terminated string to output file, buffered. zsoutl(n,s) -- Like zsout, but appends a line terminator. zsoutx(n,s,x) -- Write x characters to output file, unbuffered. zchout(n,c) -- Add a character to an output file, unbuffered. zchki(name) -- Check if named file exists and is readable, return size. zchko(name) -- Check if named file can be created. zchkspa(name,n) -- Check if n bytes available to create new file, name. znewn(name,s) -- Make a new unique file name based on the given name. zdelet(name) -- Delete the named file. zxpand(string) -- Expands the given wildcard string into a list of files. znext(string) -- Returns the next file from the list in "string". zxcmd(n,cmd) -- Execute the command in a lower fork on file number n. zclosf() -- Close input file associated with zxcmd()'s lower fork. zrtol(n1,n2) -- Convert remote filename into local form. zltor(n1,n2) -- Convert local filename into remote form. zchdir(dirnam) -- Change working directory. zhome() -- Return pointer to home directory name string. zkself() -- Kill self, log out own job. zsattr(struct zattr *) -- Return attributes for file which is being sent. zstime(f, struct zattr *, x) - Set file creation date from attribute packet. zrename(old, new) -- Rename a file. *//* Kermit-specific includes *//* Definitions here supersede those from system include files. ckcdeb.h is included above.*/#include "ckcker.h" /* Kermit definitions */#include "ckucmd.h" /* For sys-dependent keyword tables */#include "ckuver.h" /* Version herald */char *ckzsys = HERALD;/* Support for tilde-expansion in file and directory names */#ifdef POSIX#define NAMEENV "LOGNAME"#endif /* POSIX */#ifdef BSD4#define NAMEENV "USER"#endif /* BSD4 */#ifdef ATTSV#define NAMEENV "LOGNAME"#endif /* ATTSV *//* Berkeley Unix Version 4.x *//* 4.1bsd support from Charles E Brooks, EDN-VAX */#ifdef BSD4#ifdef MAXNAMLEN#define BSD42#endif /* MAXNAMLEN */#endif /* BSD4 *//* Definitions of some system commands */#ifdef OS2char *DELCMD = "del "; /* For file deletion */char *PWDCMD = "chdir "; /* For saying where I am */char *TYPCMD = "type "; /* For typing a file */char *DIRCMD = "dir "; /* For directory listing */char *DIRCM2 = "dir "; /* For directory listing, no args */char *WHOCMD = ""; /* Who's there? */char *SPACMD = "dir | find \"bytes free\""; /* For space on disk */char *SPACM2 = "dir | find \"bytes free\""; /* For space on disk */#else /* Not OS2, ergo UNIX */char *DELCMD = "rm -f "; /* For file deletion */char *PWDCMD = "pwd "; /* For saying where I am */#ifdef COMMENTchar *DIRCMD = "/bin/ls -ld "; /* For directory listing */char *DIRCM2 = "/bin/ls -ld *"; /* For directory listing, no args */#elsechar *DIRCMD = "/bin/ls -l "; /* For directory listing */char *DIRCM2 = "/bin/ls -l "; /* For directory listing, no args */#endif /* COMMENT */char *TYPCMD = "cat "; /* For typing a file */#ifdef FT18 /* Fortune For:Pro 1.8 */#undef BSD4#endif /* FT18 */#ifdef BSD4char *SPACMD = "pwd ; df ."; /* Space in current directory */#else#ifdef FT18char *SPACMD = "pwd ; du ; df .";#elsechar *SPACMD = "df ";#endif /* FT18 */#endif /* BSD4 */char *SPACM2 = "df "; /* For space in specified directory */#ifdef FT18#define BSD4#endif /* FT18 */#ifdef OXOS /* For seeing who's logged in */char *WHOCMD = "who ";#else#ifdef BSD4char *WHOCMD = "finger ";#elsechar *WHOCMD = "who ";#endif /* BSD4 */#endif /* OSOS */#endif /* OS2 */#ifdef DTILDE /* For tilde expansion */_PROTOTYP( char * tilde_expand, (char *) );#endif /* DTILDE *//* More system-dependent includes, which depend on symbols defined *//* in the Kermit-specific includes. Oh what a tangled web we weave... */#ifdef COHERENT /* <sys/file.h> */#define NOFILEH#endif /* COHERENT */#ifdef MINIX#define NOFILEH#endif /* MINIX */#ifdef aegis#define NOFILEH#endif /* aegis */#ifdef unos#define NOFILEH#endif /* unos */#ifndef NOFILEH#include <sys/file.h>#endif /* NOFILEH */#ifndef is68k /* Whether to include <fcntl.h> */#ifndef BSD41 /* All but a couple UNIXes have it. */#ifndef FT18#ifndef COHERENT#include <fcntl.h>#endif /* COHERENT */#endif /* FT18 */#endif /* BSD41 */#endif /* not is68k */#ifdef COHERENT#include <sys/fcntl.h>#endif /* COHERENT *//* Change argument to "(const char *)" if this causes trouble. Or... if it causes trouble, then maybe it was already declared in a header file after all, so you can remove this prototype.*/#ifndef _POSIX_SOURCE#ifndef NEXT#ifndef SVR4/* POSIX <pwd.h> already gave prototypes for these. */#ifdef IRIX40_PROTOTYP( struct passwd * getpwnam, (const char *) );#else_PROTOTYP( struct passwd * getpwnam, (char *) );#endif /* IRIX40 */#ifndef SUNOS4_PROTOTYP( struct passwd * getpwuid, (PWID_T) );#endif /* SUNOS4 */_PROTOTYP( struct passwd * getpwent, (void) );#endif /* SVR4 */#endif /* NEXT */#endif /* _POSIX_SOURCE *//* Define macros for getting file type */#ifdef OXOS/* Olivetti X/OS 2.3 has S_ISREG and S_ISDIR defined incorrectly, so we force their redefinition.*/#undef S_ISREG#undef S_ISDIR#endif /* OXOS */#ifdef UTSV /* Same deal for Amdahl UTSV */#undef S_ISREG#undef S_ISDIR#endif /* UTSV */#ifdef UNISYS52 /* And for UNISYS UTS V 5.2 */#undef S_ISREG#undef S_ISDIR#endif /* UNISYS52 */#ifndef S_ISREG#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)#endif /* S_ISREG */#ifndef S_ISDIR#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)#endif /* S_ISDIR *//* Define maximum length for a file name if not already defined */#ifndef MAXNAMLEN#ifdef sun#define MAXNAMLEN 255#else#ifdef FILENAME_MAX#define MAXNAMLEN FILENAME_MAX#else#ifdef NAME_MAX#define MAXNAMLEN NAME_MAX#else#ifdef _POSIX_NAME_MAX#define MAXNAMLEN _POSIX_NAME_MAX#else#ifdef _D_NAME_MAX#define MAXNAMLEN _D_NAME_MAX#else#ifdef DIRSIZ#define MAXNAMLEN DIRSIZ#else#define MAXNAMLEN 14#endif /* DIRSIZ */#endif /* _D_NAME_MAX */#endif /* _POSIX_NAME_MAX */#endif /* NAME_MAX */#endif /* FILENAME_MAX */#endif /* sun */#endif /* MAXNAMLEN *//* Longest pathname */#ifdef MAXPATHLEN#ifdef MAXPATH#undef MAXPATH#endif /* MAXPATH */#define MAXPATH MAXPATHLEN#else#ifdef PATH_MAX#define MAXPATH PATH_MAX#else#ifdef _POSIX_PATH_MAX#define MAXPATH _POSIX_PATH_MAX#else#ifdef BSD42#define MAXPATH 1024#else#define MAXPATH 255#endif /* BSD42 */#endif /* _POSIX_PATH_MAX */#endif /* PATH_MAX */#endif /* MAXPATHLEN *//* Maximum number of filenames for wildcard expansion */#ifdef PROVX1#define MAXWLD 50#else#ifdef BSD29#define MAXWLD 50#else#ifdef pdp11#define MAXWLD 50#else#define MAXWLD 1000#endif /* pdp11 */#endif /* BSD29 */#endif /* PROVX1 *//* More internal function prototypes *//* * The path structure is used to represent the name to match. * Each slash-separated segment of the name is kept in one * such structure, and they are linked together, to make * traversing the name easier. */struct path { char npart[MAXNAMLEN+4]; /* name part of path segment */ struct path *fwd; /* forward ptr */};_PROTOTYP( int shxpand, (char *, char *[], int ) );_PROTOTYP( static int fgen, (char *, char *[], int ) );_PROTOTYP( static VOID traverse, (struct path *, char *, char *) );_PROTOTYP( static VOID addresult, (char *) );_PROTOTYP( static int match, (char *, char *) );_PROTOTYP( static char * whoami, (void) );_PROTOTYP( char * xindex, (char *, char) );_PROTOTYP( UID_T real_uid, (void) );_PROTOTYP( struct path *splitpath, (char *p) );/* Some systems define these symbols in include files, others don't... */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -