⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ckuusy.c

📁 linux终端仿真程序
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "ckcsym.h"#define XFATAL fatal#ifndef NOCMDL/*  C K U U S Y --  "User Interface" for Unix Kermit, part Y  *//*  Command-Line Argument Parser */ /*  Author: Frank da Cruz (fdc@columbia.edu),  Columbia University, New York City.  Copyright (C) 1985, 1996, Trustees of Columbia University in the City of  New York.  All rights reserved.*/#ifdef COMMENT  Census of command-line options ( "grep ^case ckuusy.c | sort" :-)  Update this if you add a new one:case '8':				/* 8-bit clean */case 'B':				/* Batch (no controlling terminal) */case 'C':				/* Commands for parser */case 'D':				/* Delay */case 'E':				/* Exit on close */case 'F':				/* Socket file descriptor */case 'J':				/* Like j but exits on disconnect */case 'M':				/* Username for Telnet, Rlogin, etc */case 'N':               		/* NetBios Adapter Number follows */case 'P':				/* Pipe */case 'Q':				/* Use quick settings */case 'R':				/* Remote-Only */case 'S':				/* "Stay" - enter interactive */case 'T':				/* Text file transfer mode */case 'U':                               /* X.25 call user data */case 'W':				/* Win32 Window Handle */case 'X':				/* SET HOST to X.25 address */case 'Y':				/* No initialization file */case 'Z':				/* SET HOST to X.25 file descriptor */case 'a':				/* "as" */case 'b':   	    			/* set bits-per-second for serial */case 'c':				/* connect before */case 'd':				/* DEBUG */case 'e':				/* Extended packet length */case 'f':				/* finish */case 'g':				/* get */case 'h':				/* help */case 'i':				/* Treat files as binary */case 'j':				/* SET HOST (TCP/IP socket) */case 'k':				/* receive to stdout */case 'l':				/* SET LINE */case 'm':				/* Modem type */case 'n':				/* connect after */case 'o':                               /* X.25 closed user group */case 'p':				/* SET PARITY */case 'q':				/* Quiet */case 'r':				/* receive */case 's': 				/* send */case 't':				/* Line turnaround handshake */case 'u':                               /* X.25 reverse charge call */case 'v':				/* Vindow size */case 'w':				/* Writeover */case 'x':				/* server */case 'y':				/* Alternate init-file name */case 'z':				/* Not background */#endif /* COMMENT */#include "ckcdeb.h"#include "ckcasc.h"#include "ckcker.h"#include "ckucmd.h"#include "ckcnet.h"#include "ckuusr.h"#ifdef OS2#include <io.h>#endif /* OS2 */#ifdef NETCONN#ifdef ANYX25extern int revcall, closgr, cudata;extern char udata[];extern int x25fd;#endif /* ANYX25 */#ifndef VMS#ifndef OS2#ifndef OSKextern#endif /* OSK */#endif /* OS2 */#endif /* VMS */int telnetfd;extern struct keytab netcmd[];extern int tn_exit;#ifndef NOICP#ifndef NODIALextern int nnets, nnetdir;		/* Network services directory */extern char *netdir[];extern char *nh_p[];			/* Network directory entry pointers */extern char *nh_p2[];			/* Network directory entry nettype */#endif /* NODIAL */extern int nhcount;extern char * n_name;			/* Network name pointer */#endif /* NOICP */#endif /* NETCONN */#ifndef NOSPLextern char uidbuf[];#endif /* NOSPL */extern char *ckxsys, *ckzsys, *cmarg, *cmarg2, **xargv, **cmlist, *clcmds;extern int action, cflg, xargc, stdouf, stdinf, displa, cnflg, nfils,  local, quiet, escape, network, mdmtyp, maxrps, rpsiz, bgset, backgrd, xargs,  urpsiz, wslotr, swcapr, binary, warn, parity, turn, turnch, duplex, flow,  fncact, clfils, noinit, stayflg, nettype, cfilef, delay, noherald,  cmask, cmdmsk, backgrd, exitonclose;extern long speed;extern char ttname[];extern char * pipedata;#ifdef OS2extern struct keytab os2devtab[];extern int nos2dev;extern int ttslip;#ifdef OS2PMextern int os2pm;#endif /* OS2PM */#endif /* OS2 */#ifdef CK_NETBIOSextern unsigned char NetBiosAdapter;#endif /* CK_NETBIOS */#ifdef XFATAL#undef XFATAL#endif /* XFATAL */#ifndef NOICP#ifndef NODIALextern int nmdm, telephony;extern struct keytab mdmtab[];extern int usermdm, dialudt;#endif /* NODIAL */extern int what;_PROTOTYP(static int pmsg, (char *) );_PROTOTYP(static int fmsg, (char *) );static int pmsg(s) char *s; { printf("%s\n", s); return(0); }static int fmsg(s) char *s; { fatal(s); return(0); }#define XFATAL(s) return(what==W_COMMAND?pmsg(s):fmsg(s))#else#define XFATAL fatal#endif /* NOICP */VOIDfatal2(msg1,msg2) char *msg1, *msg2; {    char buf[256];    if (!msg1) msg1 = "";    if (!msg2) msg2 = "";    sprintf(buf,"\"%s\" - %s",msg1,msg2);#ifndef NOICP    if (what == W_COMMAND)      printf("%s\n",buf);    else#endif /* NOICP */      fatal((char *)buf);}/*  C M D L I N  --  Get arguments from command line  *//* Simple Unix-style command line parser, conforming with 'A Proposed Command Syntax Standard for Unix Systems', Hemenway & Armitage, Unix/World, Vol.1, No.3, 1984.*/intcmdlin() {    char x;				/* Local general-purpose char */    cmarg = "";				/* Initialize globals */    cmarg2 = "";    action = 0;    cflg = 0;     debug(F111,"cmdlin",*xargv,xargc);/* If we were started directly from a Kermit application file, its name is *//* in argv[1], so skip past it. */    debug(F101,"cmdlin cfilef","",cfilef);    if (xargc > 1) {	if (*xargv[1] != '-') {	    if (cfilef) {		/* Command file found in prescan() */		xargc -= 1;		/* Skip past it */		xargv += 1;		cfilef = 0;	    }	}    }    while (--xargc > 0) {		/* Go through command line words */	xargv++;	debug(F111,"xargv",*xargv,xargc);	if (**xargv == '=') return(0);#ifdef VMS	else if (**xargv == '/') continue;#endif /* VMS */    	else if (**xargv == '-') {	/* Got an option (begins with dash) */	    x = *(*xargv+1);		/* Get the option letter */	    if (doarg(x) < 0) {#ifndef NOICP		if (what == W_COMMAND)		  return(0);		else#endif /* NOICP */		  {#ifdef OS2		      sleep(1);		/* Give it a chance... */#endif /* OS2 */		      doexit(BAD_EXIT,1); /* Go handle option */		  }	    }    	} else {			/* No dash where expected */	    fatal2(*xargv,#ifdef NT		   "invalid command-line option, type \"k95 -h\" for help"#else#ifdef OS2		   "invalid command-line option, type \"ckermit -h\" for help"#else		   "invalid command-line option, type \"kermit -h\" for help"#endif /* OS2 */#endif /* NT */		   );	}    }    debug(F101,"action","",action);#ifndef NOLOCAL    if (!local) {	if ((action == 'c') || (cflg != 0)) {	    XFATAL("-l or -j or -X required");	}    }#endif /* NOLOCAL */    if (*cmarg2 != 0) {	if ((action != 's') && (action != 'r') && (action != 'v')) {	    XFATAL("-a without -s, -r, or -g");	}	if (action == 'r' || action == 'v') {#ifdef CK_TMPDIR	    if (isdir(cmarg2)) {	/* -a is a directory */		if (!zchdir(cmarg2)) {	/* try to change to it */		    XFATAL("can't change to '-a' directory");		} else cmarg2 = "";	    } else#endif /* CK_TMPDIR */	      if (zchko(cmarg2) < 0) {		  XFATAL("write access to -a file denied");	      }	}    }    if ((action == 'v') && (stdouf) && (!local)) {	if (is_a_tty(1)) {	    XFATAL("unredirected -k can only be used in local mode");	}    }    if ((action == 's') || (action == 'v') ||	(action == 'r') || (action == 'x')) {	if (local)	  displa = 1;	if (stdouf) {	    displa = 0;	    quiet = 1;	}    }    if (quiet) displa = 0;		/* No display if quiet requested */    return(action);			/* Then do any requested protocol */}/*  D O A R G  --  Do a command-line argument.  */ int#ifdef CK_ANSICdoarg(char x)#elsedoarg(x) char x; #endif /* CK_ANSIC *//* doarg */ {    int i, n, y, z, xx; long zz; char *xp; #ifdef NETCONN#define YYBUFLEN 256    char tmpbuf[YYBUFLEN+1];		/* Local storage for network things */    char line[YYBUFLEN+1];#endif /* NETCONN */    xp = *xargv+1;			/* Pointer for bundled args */    debug(F111,"doarg entry",xp,xargc);    while (x) {	debug(F000,"doarg arg","",x);	switch (x) {#ifndef NOSPLcase 'C':				/* Commands for parser */    xargv++, xargc--;    if ((xargc < 1) || (**xargv == '-')) {	XFATAL("No commands given for -C");    }    clcmds = *xargv;			/* Get the argument (must be quoted) */    break;#endif /* NOSPL */case 'D':				/* Delay */    if (*(xp+1)) {	XFATAL("invalid argument bundling");    }    xargv++, xargc--;    if ((xargc < 1) || (**xargv == '-')) {	XFATAL("missing delay value");    }    z = atoi(*xargv);			/* Convert to number */    if (z > -1)				/* If in range */      delay = z;			/* set it */    else {	XFATAL("bad delay value");    }    break;case 'E':				/* Exit on close */#ifdef NETCONN    tn_exit = 1;#endif /* NETCONN */    exitonclose = 1;    break;#ifndef NOICPcase 'S':				/* "Stay" - enter interactive */    stayflg = 1;			/* command parser after executing */    break;				/* command-line actions. */#endif /* NOICP */case 'T':				/* File transfer mode = text */    binary = XYFT_T;    break;case 'Q':				/* Quick (i.e. FAST) */    wslotr = 20;			/* 20 window slots */    rpsiz = 94;				/* 4K packets */    urpsiz = 4096;    if (urpsiz > MAXSP)      urpsiz = MAXSP;#ifdef CK_SPEED    setprefix(PX_CAU);			/* Cautious unprefixing */#endif /* CK_SPEED */    break;case 'R':				/* Remote-Only */    break;				/* This is handled in prescan(). */#ifndef NOSERVERcase 'x':				/* server */    if (action) {	XFATAL("conflicting actions");    }    action = 'x';    break;#endif /* NOSERVER */ case 'f':				/* finish */    if (action) {	XFATAL("conflicting actions");    }    action = setgen('F',"","","");    break; case 'r': {				/* receive */    if (action) {	XFATAL("conflicting actions");    }    action = 'v';    break;  } case 'k':				/* receive to stdout */    if (action) {	XFATAL("conflicting actions");    }    stdouf = 1;    action = 'v';    break; case 's': 				/* send */    if (action) {	XFATAL("conflicting actions");    }    if (*(xp+1)) {	XFATAL("invalid argument bundling after -s");    }    nfils = 0;				/* Initialize file counter */    z = 0;				/* Flag for stdin */    cmlist = xargv + 1;			/* Remember this pointer */    while (--xargc > 0) {		/* Traverse the list */		xargv++;	if (**xargv == '-') {		/* Check for sending stdin */	    if (strcmp(*xargv,"-") != 0) /* Watch out for next option. */	      break;	    z++;			/* "-" alone means send from stdin. */        } else if (zchki(*xargv) > -1) { /* Check if file exists */	    nfils++;			/* Bump file counter */	} else if (iswild(*xargv) && zxpand(*xargv) > 0) {	    /* or contains wildcard characters matching real files */	    nfils++;	}    }    xargc++, xargv--;			/* Adjust argv/argc */    if (nfils < 1 && z == 0) {#ifdef VMS	XFATAL("%CKERMIT-E-SEARCHFAIL, no files for -s");#else	XFATAL("No files for -s");#endif /* VMS */    }    if (z > 1) {	XFATAL("-s: too many -'s");    }    if (z == 1 && nfils > 0) {	XFATAL("invalid mixture of filenames and '-' in -s");    }    debug(F101,"doarg s nfils","",nfils);    debug(F101,"doarg s z","",z);    if (nfils == 0) {	if (is_a_tty(0)) {		/* (used to be is_a_tty(1) - why?) */	    XFATAL("sending from terminal not allowed");	} else stdinf = 1;    }    debug(F101,"doarg s stdinf","",stdinf);    debug(F101,*xargv,"",nfils);    action = 's';    break; case 'g':				/* get */    if (action) {	XFATAL("conflicting actions");    }    if (*(xp+1)) {	XFATAL("invalid argument bundling after -g");    }    xargv++, xargc--;    if ((xargc == 0) || (**xargv == '-')) {    	XFATAL("missing filename for -g");    }    cmarg = *xargv;    action = 'r';    break; #ifndef NOLOCALcase 'c':				/* connect before */    cflg = 1;    break;case 'n':				/* connect after */    cnflg = 1;    break;#endif /* NOLOCAL */ case 'h':				/* help */    usage();#ifndef NOICP    if (stayflg || what == W_COMMAND)      break;    else#endif /* NOICP */      doexit(GOOD_EXIT,-1);case 'a':				/* "as" */    if (*(xp+1)) {	XFATAL("invalid argument bundling after -a");    }    xargv++, xargc--;    if ((xargc < 1) || (**xargv == '-')) {    	XFATAL("missing name in -a");    }    cmarg2 = *xargv;    break; #ifndef NOICPcase 'Y':				/* No initialization file */    noinit = 1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -