📄 ckufio.c
字号:
}/* Z D E L E T -- Delete the named file. */intzdelet(name) char *name; {#ifdef NT return(_unlink(name));#else /* NT */ return(unlink(name));#endif /* NT */}/* Z R T O L -- Convert remote filename into local form */VOIDzrtol(name,name2) char *name, *name2; { char *p; int flag = 0, n = 0; int acase = 0; if (!name || !name2) return; debug(F101,"zrtol original name","",name); p = name2; for ( ; *name != '\0' && n < maxnam; name++) { if (*name > ' ') flag = 1; /* Strip leading blanks and controls */ if (flag == 0 && *name < '!') continue; if (isupper(*name)) /* Check for mixed case */ acase |= 1; else if (islower(*name)) acase |= 2; *p++ = *name; n++; } *p-- = '\0'; /* Terminate */ while (*p < '!' && p > name2) /* Strip trailing blanks & controls */ *p-- = '\0'; if (*name2 == '\0') { /* Nothing left? */ strcpy(name2,"NONAME"); /* do this... */ } else if (acase == 1) { /* All uppercase? */ p = name2; /* So convert all letters to lower */ while (*p) { if (isupper(*p)) *p = tolower(*p); p++; } } #ifdef OS2 if (!IsFileNameValid(name2)) ChangeNameForFAT(name2);#endif /* OS2 */ debug(F110,"zrtol new name",name2,0);}/* Z S T R I P -- Strip device & directory name from file specification *//* Strip pathname from filename "name", return pointer to result in name2 */#ifdef pdp11#define ZSTRPLEN 64#else#define ZSTRPLEN MAXPATH#endif /* pdp11 */static char work[ZSTRPLEN+1];VOIDzstrip(name,name2) char *name, **name2; { char *cp, *pp; int n = 0; debug(F110,"zstrip before",name,0); if (!name) { *name2 = ""; return; } pp = work;#ifdef DTILDE /* Strip leading tilde */ if (*name == '~') name++; debug(F110,"zstrip after tilde-stripping",name,0);#else#ifdef OS2 /* Strip disk letter and colon */ if (isalpha(*name) && (*(name+1) == ':')) name += 2; debug(F110,"zstrip after disk-stripping",name,0);#endif /* OS2 */#endif /* DTILDE */ for (cp = name; *cp; cp++) { if (ISDIRSEP(*cp)) { pp = work; n = 0; } else { *pp++ = *cp; if (n++ >= ZSTRPLEN) break; } } *pp = '\0'; /* Terminate the string */ *name2 = work; debug(F110,"zstrip after",*name2,0);}/* Z L T O R -- Local TO Remote */VOIDzltor(name,name2) char *name, *name2; { char *cp, *pp; int dc = 0; char *dotp = NULL;#ifdef aegis char *namechars; int tilde = 0, bslash = 0; if ((namechars = getenv("NAMECHARS")) != NULL) { if (xindex(namechars, '~' ) != NULL) tilde = '~'; if (xindex(namechars, '\\') != NULL) bslash = '\\'; } else { tilde = '~'; bslash = '\\'; }#endif /* aegis */ debug(F110,"zltor",name,0); pp = work;#ifdef OS2 if (isalpha(*name) && (*(name+1) == ':')) /* Strip disk name */ name += 2;#endif /* OS2 */ for (cp = name; *cp; cp++) { /* Strip path name */ if (ISDIRSEP(*cp)) { dc = 0; /* Start over... */ dotp = NULL; pp = work; } else if (islower(*cp)) /* Uppercase letters */ *pp++ = toupper(*cp); /* Change tilde to 'X' */ else if (*cp == '~') *pp++ = 'X'; else if (*cp == '#') /* Change number sign to 'X' */ *pp++ = 'X'; else if (*cp == '.') { /* Change dot to underscore */ dotp = pp; /* Remember where we last did this */ *pp++ = '_'; } else *pp++ = *cp; } *pp = NUL; /* Tie it off. */ if (dotp) *dotp = '.'; /* Restore last dot (if any) */ cp = name2; /* If nothing before dot, */ if (*work == '.') *cp++ = 'X'; /* insert 'X' */ strcpy(cp,work); debug(F110," name2",name2,0);}/* Z C H D I R -- Change directory *//* Call with: dirnam = pointer to name of directory to change to, which may be "" or NULL to indicate user's home directory. Returns: 0 on failure 1 on success*/intzchdir(dirnam) char *dirnam; { char *hd, *sp, *p; debug(F110,"zchdir",dirnam,0); if (dirnam == NULL || dirnam == "" || *dirnam == '\0') /* If arg is null */ dirnam = zhome(); /* use user's home directory. */ sp = dirnam; debug(F110,"zchdir 2",dirnam,0);#ifdef DTILDE hd = tilde_expand(dirnam); /* Attempt to expand tilde */ if (*hd == '\0') hd = dirnam; /* in directory name. */#else hd = dirnam;#endif /* DTILDE */ debug(F110,"zchdir 3",hd,0);#ifdef pdp11 /* Just to save some space */ return((#ifdef NT _chdir(hd)#else chdir(hd)#endif /* NT */ == 0) ? 1 : 0);#else#ifdef OS2 if (isalpha(hd[0]) && hd[1] == ':') { if (zchdsk(hd[0])) return(0); if (hd[2] == 0) return(1); /* Handle drive-only case */ } { /* strip trailing DIRSEP except after d:; chdir() doesn't like it */ int len = strlen(hd) ; if ( len > 1 && ISDIRSEP(hd[len - 1]) && hd[len - 2] != ':' ) hd[len - 1] = 0; }#endif /* OS2 */ if (#ifdef NT _chdir(hd)#else chdir(hd)#endif /* NT */ == 0) return(1); /* Try to cd */ else return(0);#ifdef COMMENT/* This doesn't help in Windows or OS/2, and it's wrong in UNIX */ p = sp; /* Failed, lowercase it. */ while (*p) { if (isupper(*p)) *p = tolower(*p); p++; } debug(F110,"zchdir 4",hd,0);#ifdef DTILDE hd = tilde_expand(sp); /* Try again to expand tilde */ if (*hd == '\0') hd = sp;#else hd = sp; /* Point to result */#endif /* DTILDE */ debug(F110,"zchdir 5",hd,0); return((#ifdef NT _chdir(hd)#else chdir(hd)#endif /* NT */ == 0) ? 1 : 0);#endif /* COMMENT */#endif /* pdp11 */}/* Z H O M E -- Return pointer to user's home directory */char *zhome() {#ifdef Plan9 char *home = getenv("home");#else char *home = getenv("HOME");#endif /* Plan9 */#ifdef OS2 extern char startupdir[]; return(home ? home : startupdir);#else return(home ? home : ".");#endif /* OS2 */}/* Z G T D I R -- Return pointer to user's current directory */#ifdef pdp11#define CWDBL 80 /* Save every byte we can... */#else#define CWDBL MAXPATH#endif /* pdp11 */static char cwdbuf[CWDBL+1];char *zgtdir() { char *buf;#ifdef BSD44 extern char *getcwd(); buf = cwdbuf; debug(F101,"zgtdir CWDBL","",CWDBL); return(getcwd(buf,CWDBL));#else#ifdef SVORPOSIX extern char *getcwd(); buf = cwdbuf; debug(F101,"zgtdir CWDBL","",CWDBL); return(getcwd(buf,CWDBL));#else#ifdef COHERENT#ifdef _I386 extern char *getcwd(); buf = cwdbuf; debug(F101,"zgtdir CWDBL","",CWDBL); return(getcwd(buf,CWDBL));#else extern char *getwd(); buf = cwdbuf; debug(F101,"zgtdir CWDBL","",CWDBL); return(getwd(buf));#endif /* _I386 */#else#ifdef OS2#ifndef __IBMC__ /* which has a macro for this */ extern char *getcwd();#endif /* __IBMC__ */ buf = cwdbuf; debug(F101,"zgtdir CWDBL","",CWDBL);#ifdef NT _getcwd(buf,CWDBL);#else getcwd(buf,CWDBL);#endif /* NT */ return(buf);#else /* OS2 */#ifdef BSD4 extern char *getwd(); buf = cwdbuf; debug(F100,"zgtdir getwd()","",0); return(getwd(buf));#else return("directory unknown");#endif /* BSD4 */#endif /* OS2 */#endif /* COHERENT */#endif /* SYSVORPOSIX */#endif /* BSD44 */}/* Z X C M D -- Run a system command so its output can be read like a file */#ifdef NT_PROTOTYP( FILE * win95popen, (char *cmd, char *mode) );_PROTOTYP( int win95pclose, (FILE *pipe) );#endif /* NT */intzxcmd(filnum,comand) int filnum; char *comand; {#ifdef OS2 if (chkfn(filnum) < 0) return(-1); /* Need a valid Kermit file number. */ if (filnum == ZSTDIO || filnum == ZCTERM) /* But not one of these. */ return(0); if (filnum == ZIFILE || filnum == ZRFILE) { /* Input from a command */ if (priv_chk() || #ifdef NT isWin95() ? ((fp[filnum] = win95popen(comand,"rb")) == NULL) :#endif /* NT */ ((fp[filnum] = popen(comand,"rb")) == NULL) ) return(0); } else { /* Output to a command */ if (priv_chk() || #ifdef NT isWin95() ? ((fp[filnum] = win95popen(comand,"w")) == NULL) :#endif /* NT */ ((fp[filnum] = popen(comand,"w")) == NULL) ) return(0); } fp[ZSYSFN] = fp[filnum]; /* remember the pipe handle */ ispipe[filnum] = 1; return(1);#else /* Not OS2 */ int pipes[2]; int out; if (chkfn(filnum) < 0) return(-1); /* Need a valid Kermit file number. */ if (filnum == ZSTDIO || filnum == ZCTERM) /* But not one of these. */ return(0); out = (filnum == ZIFILE || filnum == ZRFILE) ? 0 : 1 ;/* Output to a command */ if (out) { /* Need popen() to do this. */#ifdef NOPOPEN return(0); /* no popen(), fail. */#else/* Use popen() to run the command. */#ifdef _POSIX_SOURCE/* Strictly speaking, popen() is not available in POSIX.1 */#define DCLPOPEN#endif /* _POSIX_SOURCE */#ifdef COHERENT#define DCLPOPEN FILE * fdopen();#endif /* COHERENT */#ifdef DCLPOPEN /* popen() needs declaring because it's not declared in <stdio.h> */ FILE *popen();#endif /* DCLPOPEN */ if (priv_chk() || ((fp[filnum] = popen(comand,"w")) == NULL)) return(0); else return(1);#endif /* NOPOPEN */ }/* Input from a command */ if (pipe(pipes) != 0) { debug(F100,"zxcmd pipe failure","",0); return(0); /* can't make pipe, fail */ }/* Create a fork in which to run the named process */ if ((#ifdef aegis pid = vfork() /* child */#else pid = fork() /* child */#endif /* aegis */ ) == 0) {/* We're in the fork. */ char *shpath, *shname, *shptr; /* Find user's preferred shell */#ifndef aegis struct passwd *p; char *defshell;#ifdef HPUX10 /* Default shell */ defshell = "/usr/bin/sh";#else#ifdef Plan9 defshell = "/bin/rc";#else defshell = "/bin/sh";#endif /* Plan9 */#endif /* HPUX10 */#endif /* aegis */ if (priv_can()) exit(1); /* Turn off any privileges! */ debug(F101,"zxcmd pid","",pid); close(pipes[0]); /* close input side of pipe */ close(0); /* close stdin */ if (open("/dev/null",0) < 0) return(0); /* replace input by null */#ifndef OXOS#ifndef SVORPOSIX dup2(pipes[1],1); /* BSD: replace stdout & stderr */ dup2(pipes[1],2); /* by the pipe */#else close(1); /* AT&T: close stdout */ if ( dup(pipes[1]) != 1 ) /* Send stdout to the pipe */ return(0); close(2); /* Send stderr to the pipe */ if ( dup(pipes[1]) != 2 ) return(0);#endif /* SVORPOSIX */#else /* OXOS */ dup2(pipes[1],1); dup2(pipes[1],2);#endif /* OXOS */ close(pipes[1]); /* Don't need this any more. */#ifdef aegis if ((shpath = getenv("SERVERSHELL")) == NULL) shpath = "/bin/sh";#else shpath = getenv("SHELL"); /* What shell? */ if (shpath == NULL) { p = getpwuid( real_uid() ); /* Get login data */ if (p == (struct passwd *)NULL || !*(p->pw_shell)) shpath = defshell; else shpath = p->pw_shell; }#endif /* aegis */ shptr = shname = shpath; while (*shptr != '\0') if (*shptr++ == '/') shname = shptr; debug(F100,"zxcmd...","",0); debug(F110,shpath,shname,0); execl(shpath,shname,"-c",comand,(char *)NULL); /* Execute the cmd */ exit(0); /* just punt if it failed. */ } else if (pid == (PID_T) -1) { debug(F100,"zxcmd fork failure","",0); return(0); } debug(F101,"zxcmd pid","",pid); if (out) { close(pipes[0]); /* Don't need the input side */ fp[filnum] = fdopen(pipes[1],"w"); /* Open a stream for output. */ fp[ZSYSFN] = fp[filnum]; /* Remember. */ zoutcnt = 0; /* (PWP) reset input buffer */ zoutptr = zoutbuffer; } else { close(pipes[1]); /* Don't need the output side */ fp[filnum] = fdopen(pipes[0],"r"); /* Open a stream for input. */ fp[ZSYSFN] = fp[filnum]; /* Remember. */ zincnt = 0; /* (PWP) reset input buffer */ zinptr = zinbuffer; } return(1);#endif /* OS2 */} /* zxcmd *//* Z C L O S F - wait for the child fork to terminate and close the pipe. */intzclosf(filnum) int filnum; { int wstat; debug(F101,"zclosf filnum","",filnum);#ifndef NOPOPEN#ifdef OS2 if (ispipe[filnum]) { int x;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -