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

📄 ckuscr.c

📁 C-Kermit源码。是使用串口/Modem和网络通讯的程序
💻 C
📖 第 1 页 / 共 2 页
字号:
    ckThreadEnd(threadinfo);#endif /* NTSIG */    SIGRETURN;}static SIGTYP#ifdef CK_ANSICfailrseq(void * threadinfo)#else /* CK_ANSIC */failrseq(threadinfo) VOID * threadinfo;#endif /* CK_ANSIC *//* failrseq */ {     got_it = 0;			/* Timed out here */     SIGRETURN;}/*  Receive sequence -- see if expected response comes,  return success (or failure) in got_it.*/static VOIDrecvseq() {    char *e, got[7], trace[SBUFL];    int i, l;    sequenc();    l = (int)strlen(e=seq_buf);		/* no more than 7 chars allowed */    if (l > 7) {	e += l-7;	l = 7;    }    tlog(F111,"expecting sequence",e,(long) l);    if (l == 0) {			/* null sequence, delay a little */	sleep (NULL_EXP);	got_it = 1;	tlog(F100,"got it (null sequence)","",0L);	return;    }    *trace = '\0';    for (i = 0; i < 7; i++) got[i]='\0';    rseqtrace = trace;    rseqe = e;    rseqgot = got;    rseql = l;    alrm_execute(ckjaddr(alrmrng), exp_alrm, scrtime, dorseq, failrseq);    tlog(F110,"received sequence: ",trace,0L);    tlog(F101,"returning with got-it code","",(long) got_it);    myflsh();				/* Flush buffered output */    return;}/* Output A Sequence starting at pointer s, return 0 if okay, 1 if failed to read (modem hangup or whatever)*/static int oseqret = 0;			/* Return code for outseq */					/* Out here to prevent clobbering */					/* by longjmp. */static SIGTYP#ifdef CK_ANSICdooseq(void * threadinfo)#else /* CK_ANSIC */dooseq(threadinfo) VOID * threadinfo;#endif /* CK_ANSIC */{    int l;    char *sb;#ifdef TCPSOCKET    extern int tn_nlm, tn_b_nlm;#endif /* TCPSOCKET */#ifdef NTSIG    setint();    if (threadinfo) {			/* Thread local storage... */	TlsSetValue(TlsIndex,threadinfo);    }#endif /* NTSIG */#ifdef CK_LOGIN#ifdef NT#ifdef IKSD    if (inserver)      setntcreds();#endif /* IKSD */#endif /* NT */#endif /* CK_LOGIN */    l = (int)strlen(seq_buf);    tlog(F111,"sending sequence ",seq_buf,(long) l);    if (!strcmp(seq_buf,"EOT")) {	ttoc(dopar('\004'));	if (scr_echo) conol("<EOT>");	if (seslog && duplex)            logstr("<EOT>",5);    } else if (!strcmp(seq_buf,"BREAK") ||	       !strcmp(seq_buf,"\\b") ||	       !strcmp(seq_buf,"\\B")) {	ttsndb();	if (scr_echo) conol("<BREAK>");	if (seslog)	  logstr("{BREAK}",7);    } else {	if (l > 0) {	    for ( sb = seq_buf; *sb; sb++)	      *sb = dopar(*sb);	/* add parity */	    ttol((CHAR *)seq_buf,l); /* send it */	    if (scr_echo && duplex) {#ifdef OS2		{			/* Echo to emulator */		    char *s = seq_buf;		    while (*s) {			scriptwrtbuf((USHORT)*s);		    }		}#endif /* OS2 */		conxo(l,seq_buf);	    }	    if (seslog && duplex) /* log it */	      logstr(seq_buf,strlen(seq_buf));	}	if (!no_cr) {	    ttoc( dopar(CR) );#ifdef TCPSOCKET	    if (is_tn) {		if (!TELOPT_ME(TELOPT_BINARY) && tn_nlm != TNL_CR)		  ttoc((char)((tn_nlm == TNL_CRLF) ?			      dopar(LF) : dopar(NUL)));		else if (TELOPT_ME(TELOPT_BINARY) &&			 (tn_b_nlm == TNL_CRLF || tn_b_nlm == TNL_CRNUL))		  ttoc((char)((tn_b_nlm == TNL_CRLF) ?			      dopar(LF) : dopar(NUL)));	    }#endif /* TCPSOCKET */	    if (seslog && duplex)	      logchar(dopar(CR));	}    }#ifdef NTSIG    ckThreadEnd(threadinfo);#endif /* NTSIG */    SIGRETURN;}SIGTYP#ifdef CK_ANSICfailoseq(void * threadinfo)#else /* CK_ANSIC */failoseq(threadinfo) VOID * threadinfo;#endif /* CK_ANSIC *//* failoseq */ {     oseqret = -1;		/* else -- alarm rang */     SIGRETURN;}static intoutseq() {    int delay;    oseqret = 0;			/* Initialize return code */    while(1) {	delay = sequenc();	alrm_execute( ckjaddr(alrmrng), SND_ALRM, scrtime, dooseq, failoseq ) ;	if (!delay)	  return(oseqret);#ifndef MAC	msleep(DEL_MSEC);		/* delay, loop to next send */#endif /* MAC */    }}/*  L O G I N  --  (historical misnomer) Execute the SCRIPT command */intdologin(cmdstr) char *cmdstr; {#ifdef OS2#ifdef NT    SIGTYP (* savealm)(int);		/* Save incoming alarm function */#else /* NT */    SIGTYP (* volatile savealm)(int);	/* Save incoming alarm function */#endif /* NT */#else /* OS2 */    SIGTYP (*savealm)();		/* Save incoming alarm function */#endif /* OS2 */    char *e;    s = cmdstr;				/* Make global to this module */    tlog(F100,loginv,"",0L);    if (speed < 0L) speed = ttgspd();    if (ttopen(ttname,&local,mdmtyp,0) < 0) {	sprintf(seq_buf,"Sorry, can't open %s",ttname);	perror(seq_buf);	return(0);    }    /* Whether to echo script commands ... */    scr_echo = (!quiet && !backgrd && secho);#ifndef NOSPL    if (scr_echo && cmdlvl > 1) {	if (cmdstk[cmdlvl].src == CMD_TF)	  scr_echo = techo;	if (cmdstk[cmdlvl].src == CMD_MD)	  scr_echo = mecho;    }#endif /* NOSPL */    if (scr_echo) {#ifdef NETCONN	if (network)	  printf("Executing SCRIPT to host %s.\n",ttname);	else#endif /* NETCONN */	  printf("Executing SCRIPT through %s, speed %ld.\n",ttname,speed);    }#ifdef TNCODE    /* TELNET input must be scanned for IAC */    is_tn = (local && network && (ttnproto == NP_TELNET)) ||	    (!local && sstelnet);#endif /* TNCODE */    *seq_buf = 0;    for (e = s; *e; e++) strcat(seq_buf, dbchr(*e) );#ifdef COMMENT/* Skip this because it tends to contain a password... */    if (scr_echo) printf("SCRIPT string: %s\n",seq_buf);#endif /* COMMENT */    tlog(F110,"SCRIPT string: ",seq_buf, 0L);/* Condition console terminal and communication line... */    if (ttvt(speed,flow) < 0) {	printf("Sorry, Can't condition communication line\n");	return(0);    }    /* Save initial timer interrupt value */    savealm = signal(SIGALRM,SIG_IGN);    flushi();				/* Flush stale input *//* start expect - send sequence */    while (*s) {			/* While not done with buffer */	while (*s && isspace(*s)) s++;	/* Skip over separating whitespaces */					/* Gather up expect sequence */	got_it = 0;	recvseq();	while (!got_it) {		/* Have it yet? */	    if (*s++ != '-')		/* No, is there a conditional send? */	      goto failret;		/* No, return failure */	    flushi();			/* Yes, flush out input buffer */	    if (outseq())		/* If unable to send, */	      goto failret;		/* return failure. */	    if (*s++ != '-')		/* If no conditional response here, */	      goto failret;		/* return failure. */	    recvseq();			/* All OK, read response from host. */	}				/* Loop back and check got_it */	while (*s && !isspace(*s++) ) ;	/* Skip over conditionals */	while (*s && isspace(*s)) s++;	/* Skip over separating whitespaces */	flushi();			/* Flush */	if (*s) if (outseq()) goto failret; /* If any */    }    signal(SIGALRM,savealm);    if (scr_echo) printf("Script successful.\n");    tlog(F100,"Script successful.","",0L);    return(1);failret:    signal(SIGALRM,savealm);    if (scr_echo) printf("Sorry, script failed\n");    tlog(F100,"Script failed","",0L);    return(0);}/*  F L U S H I  --  Flush, but log, SCRIPT input buffer  */VOIDflushi() {    int n, x;    if (	seslog				/* Logging session? */	|| scr_echo			/* Or console echoing? */#ifdef NETCONN#ifdef TNCODE	/* TELNET input must be scanned for IAC */	|| is_tn#endif /* TNCODE */#endif /* NETCONN */	) {        if ((n = ttchk()) < 0)		/* Yes, anything in buffer? */	  return;	if (n > MAXBURST) n = MAXBURST;	/* Make sure not too much, */	myflsh();			/* and that buffers are empty. */	while (n-- > 0) {  	    x = ttinc(0);		/* Collect a character */#ifdef NETCONN#ifdef TNCODE/* Check for telnet protocol negotiation */  	    if (is_tn && ((x & 0xff) == IAC) ) {		myflsh();		/* Sync output */  		switch (tn_doop((CHAR)(x & 0xff),duplex,ttinc)) {  		  case 2: duplex = 0; break;  		  case 1: duplex = 1;		  default: break;		}		/* Recalculate flush count */		if ((n = ttchk()) < 0)		  return;		if (n > MAXBURST) n = MAXBURST;  		continue;  	    }#endif /* TNCODE */#endif /* NETCONN */	    if (scr_echo) conbuf[concnt++] = (CHAR) x; /* buffer for console */	    if (seslog)#ifdef UNIX	      if (sessft != 0 || x != '\r')#else#ifdef OSK	      if (sessft != 0 || x != '\012')#endif /* OSK */#endif /* UNIX */		sesbuf[sescnt++] = (CHAR) x; /* buffer for session log */  	}	myflsh();    } else ttflui();			/* Otherwise just flush. */}#else /* NOSCRIPT */char *loginv = "Script Command Disabled";#endif /* NOSCRIPT */#endif /* NOICP */

⌨️ 快捷键说明

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