📄 eculine.c
字号:
register lchar; char *lastfew = (char *)malloc(lookfor_len); int success_flag = 0; int old_ttymode = get_ttymode(); if(!lastfew) { pputs("memory exhausted\n"); return(0); } ttymode(2); memset(lastfew,0,lookfor_len); while((lchar = lgetc_timeout(msecs)) >= 0) { if(!lchar) /* skip nulls */ continue; process_xmtr_rcvd_char(lchar,echo_flag); mem_cpy(lastfew,lastfew + 1,lookfor_len - 1); *(lastfew + lookfor_len - 1) = lchar; if(!strncmp(lastfew,lookfor,lookfor_len)) { success_flag = 1; break; } } free(lastfew); ttymode(old_ttymode); return(success_flag);} /* end of llookfor *//*+------------------------------------------------------------------------- lquiet(msecs,echo_flag)--------------------------------------------------------------------------*/voidlquiet(msecs,echo_flag)ulong msecs;int echo_flag;{ register lchar; int old_ttymode = get_ttymode(); ttymode(2); while((lchar = lgetc_timeout(msecs)) >= 0) { if(sigint) /* if interrupt, return */ break; if(!lchar) /* skip nulls */ continue; process_xmtr_rcvd_char(lchar,!!echo_flag); } ttymode(old_ttymode);} /* end of lquiet *//*+------------------------------------------------------------------------- lflush(flush_type) -- flush line driver input &/or output buffers0 == input buffer1 == output buffer2 == both buffers--------------------------------------------------------------------------*/voidlflush(flush_type)int flush_type;{ switch(flush_type) { case 0: lgetc_count = 0; ioctl(shm->Liofd,TCFLSH,(char *)0); break; case 1: ioctl(shm->Liofd,TCFLSH,(char *)1); break; case 2: lgetc_count = 0; ioctl(shm->Liofd,TCFLSH,(char *)2); break; }} /* end of lflush *//*+------------------------------------------------------------------------- lreset_ksr() This procedure restores the termio for the comm line to the values in Ltermio--------------------------------------------------------------------------*/voidlreset_ksr(){ ioctl(shm->Liofd,TCSETA,(char *)Ltermio);} /* end of lreset_ksr *//*+------------------------------------------------------------------------- ldraino(inflush_flag) - wait for output to drainIf inflush_flag is set, also flush input after output drains--------------------------------------------------------------------------*/voidldraino(inflush_flag)int inflush_flag;{#if defined(sun) int retries = 50; int outq_count; int old_outq_count = 0; do { ioctl(shm->Liofd,TIOCOUTQ,&outq_count); if(!outq_count) break; if(old_outq_count == outq_count) /* don't hang if flow control lock */ retries--; old_outq_count = outq_count; Nap(50); } while(outq_count && retries); if(inflush_flag) ioctl(shm->Liofd,TCFLSH,TCIFLUSH);#else ioctl(shm->Liofd,(inflush_flag) ? TCSETAF : TCSETAW,(char *)Ltermio);#endif} /* end of ldraino *//*+----------------------------------------------------------------------- lputc(lchar) -- write lchar to comm line------------------------------------------------------------------------*/voidlputc(lchar)char lchar;{ while(write(shm->Liofd,&lchar,1) < 0) { if(errno == EINTR) continue; pperror("lputc write error"); termecu(TERMECU_XMTR_WRITE_ERROR); } shm->xmit_chars++; shm->xmit_chars_this_connect++;} /* end of lputc *//*+----------------------------------------------------------------------- lputc_paced(pace_msec,lchar) -- write lchar to comm line with time between each character ------------------------------------------------------------------------*/voidlputc_paced(pace_msec,lchar)register pace_msec;char lchar;{ lputc(lchar); Nap((long)(pace_msec ? pace_msec : LPUTS_NAP_COUNT));} /* end of lputc_paced *//*+----------------------------------------------------------------------- lputs(string) -- write string to comm line------------------------------------------------------------------------*/voidlputs(string)register char *string;{ while(*string) lputc(*string++);}/*+----------------------------------------------------------------------- lputs_paced(pace_msec,string) -- write string to comm line with time between each character ------------------------------------------------------------------------*/voidlputs_paced(pace_msec,string)register pace_msec;register char *string;{ while(*string) lputc_paced(pace_msec,*string++);} /* end of lputs_paced *//*+------------------------------------------------------------------------- valid_baud_rate(baud) -- returns (positive) baud rate selectoror -1 if invalid baud rate--------------------------------------------------------------------------*/valid_baud_rate(baud)uint baud;{ switch(baud) { case 110: return(B110); case 300: return(B300); case 600: return(B600); case 1200: return(B1200); case 2400: return(B2400); case 4800: return(B4800); case 9600: return(B9600); case 19200: return(EXTA); case 38400: return(EXTB); default: return(-1); }} /* end of valid_baud_rate *//*+----------------------------------------------------------------------- lset_baud_rate(ioctl_flag) If 'ioctl_flag' is set, then perform ioctl call is executed after setting baud rate------------------------------------------------------------------------*/lset_baud_rate(ioctl_flag)int ioctl_flag;{ int baud_selector = valid_baud_rate(shm->Lbaud); if(shm->Liofd < 0) return(0); if(baud_selector == -1) baud_selector = valid_baud_rate(shm->Lbaud = DEFAULT_BAUD_RATE); shm->Lmodem_already_init = 0; Ltermio->c_cflag &= ~CBAUD; Ltermio->c_cflag |= baud_selector; if(baud_selector < B300) Ltermio->c_cflag |= CSTOPB; else Ltermio->c_cflag &= ~CSTOPB; if(ioctl_flag) ioctl(shm->Liofd,TCSETA,(char *)Ltermio); return(0);} /* end of lset_baud_rate *//*+------------------------------------------------------------------------- display_hw_flow_config() - display hardware flow control configuration--------------------------------------------------------------------------*/#if defined(HW_FLOW_CONTROL) /* see ecu.h */voiddisplay_hw_flow_config(){#undef ____HANDLED#ifdef RTSFLOW /* SCO */#define ____HANDLED pprintf("RTSFLOW %s CTSFLOW %s", (Ltermio->c_cflag & RTSFLOW) ? "on" : "off", (Ltermio->c_cflag & CTSFLOW) ? "on" : "off");#ifdef CRTSFL pprintf(" CRTSFL %s", (Ltermio->c_cflag & CRTSFL) ? "on" : "off");#endif /* CRTSFL */ pprintf("\n");#endif /* RTSFLOW */#ifdef RTSXOFF /* SVR4 */#define ____HANDLED pprintf("RTSXOFF %s CTSXON %s\n", (hx_flag & RTSXOFF) ? "on" : "off", (hx_flag & CTSXON) ? "on" : "off");#endif /* RTSXOFF */#if defined(CRTSCTS) /* sun */#define ____HANDLED pprintf(" CRTSCTS %s\n", (Ltermio->c_cflag & CRTSCTS) ? "on" : "off");#endif /* sun */#ifndef ____HANDLEDporting_attention_needed_here; /* HW_FLOW_CONTROL but no recognized flags *//* * if you are reading this because of a compilation error, you may wish to * go ahead and grep for 'RTSFLOW' and 'display_hw_flow_control' to find other * hardware control dependencies (like in lRTSCTS_control() below). This is * the only rigrous test in ECU for making sure that if HW_FLOW_CONTROL is on * we know what to do about it. */#endif /* ____HANDLED */} /* end of display_hw_flow_config */#endif /* HW_FLOW_CONTROL *//*+------------------------------------------------------------------------- lRTSCTS_control(flag)--------------------------------------------------------------------------*/voidlRTSCTS_control(flag)int flag;{#ifdef RTSXOFF /* SVR4 */ struct termiox flowctrl; ioctl(shm->Liofd, TCGETX, &flowctrl); switch(flag) { case 0: flowctrl.x_hflag &= ~(RTSXOFF | CTSXON); Ltermio->c_iflag |= (IXOFF); break; case 1: flowctrl.x_hflag |= CTSXON; flowctrl.x_hflag &= ~RTSXOFF; Ltermio->c_iflag &= ~(IXON | IXOFF | IXANY); break; case 2: flowctrl.x_hflag |= RTSXOFF; flowctrl.x_hflag &= ~CTSXON; Ltermio->c_iflag &= ~(IXON | IXOFF | IXANY); break; case 3: flowctrl.x_hflag |= (RTSXOFF | CTSXON); Ltermio->c_iflag &= ~(IXON | IXOFF | IXANY); break; } shm->Lxonxoff = Ltermio->c_iflag & (IXON|IXOFF); ioctl(shm->Liofd,TCSETA,(char *)Ltermio); ioctl(shm->Liofd, TCSETX, &flowctrl); hx_flag = flowctrl.x_hflag;#else /* !SVR4 */#if defined(RTSFLOW) /* only SCO */ switch(flag & 3) { case 0: Ltermio->c_iflag |= (IXOFF); Ltermio->c_cflag &= ~(RTSFLOW | CTSFLOW); break; case 1: Ltermio->c_iflag &= ~(IXON | IXOFF | IXANY); Ltermio->c_cflag |= CTSFLOW; Ltermio->c_cflag &= ~RTSFLOW; break; case 2: Ltermio->c_iflag &= ~(IXON | IXOFF | IXANY); Ltermio->c_cflag |= RTSFLOW; Ltermio->c_cflag &= ~CTSFLOW; break; case 3: Ltermio->c_iflag &= ~(IXON | IXOFF | IXANY); Ltermio->c_cflag |= (RTSFLOW | CTSFLOW); break; }#if defined(CRTSFL) if(flag & 4) { Ltermio->c_iflag &= ~(IXON | IXOFF | IXANY | RTSFLOW | CTSFLOW); Ltermio->c_cflag |= CRTSFL; }#endif shm->Lxonxoff = Ltermio->c_iflag & (IXON|IXOFF); ioctl(shm->Liofd,TCSETA,(char *)Ltermio);#else#if defined(CRTSCTS) /* sun */ switch(flag) { case 0: Ltermio->c_iflag |= (IXOFF); Ltermio->c_cflag &= ~(CRTSCTS); break; default: Ltermio->c_iflag &= ~(IXON | IXOFF | IXANY); Ltermio->c_cflag |= CRTSCTS; break; } shm->Lxonxoff = Ltermio->c_iflag & (IXON|IXOFF); ioctl(shm->Liofd,TCSETA,(char *)Ltermio);#endif /* sun */#endif /* RTSFLOW */#endif /* SVR4 */} /* end of lRTSCTS_control *//*+------------------------------------------------------------------------- lnew_baud_rate(new_baud)--------------------------------------------------------------------------*/intlnew_baud_rate(new_baud)uint new_baud;{ if(valid_baud_rate(new_baud) < 0) return(-1); if(shm->Lbaud != new_baud) shm->Lmodem_already_init = 0; shm->Lbaud = new_baud; lset_baud_rate(1); return(0);} /* end of lnew_baud_rate *//*+----------------------------------------------------------------------- lset_parity(ioctl_flag) If 'ioctl_flag' is set, then perform ioctl call is executed after setting parity------------------------------------------------------------------------*/voidlset_parity(ioctl_flag)int ioctl_flag;{ if(shm->Liofd < 0) return; Ltermio->c_cflag &= ~(CS8 | PARENB | PARODD); switch(to_lower(shm->Lparity)) { case 'e': Ltermio->c_cflag |= CS7 | PARENB; Ltermio->c_iflag |= ISTRIP; break; case 'o': Ltermio->c_cflag |= CS7 | PARENB | PARODD; Ltermio->c_iflag |= ISTRIP; break; default: ff(se,"invalid parity: '%c' ... defaulting to no parity\r\n", to_lower(shm->Lparity)); case 'n': shm->Lparity = 0; case 0: Ltermio->c_cflag |= CS8; Ltermio->c_iflag &= ~(ISTRIP); shm->Lparity = 0; break; } if(ioctl_flag) ioctl(shm->Liofd,TCSETA,(char *)Ltermio);} /* end of lset_parity *//*+------------------------------------------------------------------------- lclear_xmtr_xoff()--------------------------------------------------------------------------*/voidlclear_xmtr_xoff(){ ioctl(shm->Liofd,TCXONC,(char *)1); /* restart xmtr output */} /* end of lclear_xmtr_xoff *//*+------------------------------------------------------------------------- lbreak()--------------------------------------------------------------------------*/voidlbreak(){ ioctl(shm->Liofd,TCSBRK,(char *)0);} /* end of lbreak *//*+------------------------------------------------------------------------- linst_err_text(lerr)--------------------------------------------------------------------------*/char *linst_err_text(lerr)int lerr;{ static char lerr_s80[80]; extern uchar last_ugstat; char *ugstat_text(); if(lopen_err_str[0]) return(lopen_err_str); switch(lerr) { case LINST_INVALID: return("invalid line name"); case LINST_UNKPID: return("unknown pid is using line"); case LINST_LCKERR: return("error creating lock file"); case LINST_NODEV: return("line does not exist"); case LINST_ALREADY: return("line already open!?"); case LINST_OPNFAIL: sprintf(lerr_s80,"open error (%-.60s)", errno_text(errno)); return(lerr_s80); case LINST_ENABLED: return("line enabled for incoming login"); case LINST_ENABLED_IN_USE: return("line in use by incoming login"); case LINST_DIALOUT_IN_USE: return("line in use by another dial out"); case LINST_NOPTY: return("ptys not supported"); case LINST_WEGOTIT: return("line is locked by this process"); case LINST_ECUUNGETTY: sprintf(lerr_s80,"ecuungetty error (%-.45s)", ugstat_text(last_ugstat)); return(lerr_s80); case LINST_ECUUNGETTY2: return("ecuungetty execution error"); case LINST_NOTCHR: return("not a character special device"); } if(lerr > 0) sprintf(lerr_s80,"pid %d using line",lerr); else sprintf(lerr_s80,"unknown line error %d",lerr); return(lerr_s80);} /* end of linst_err_text *//*+------------------------------------------------------------------------- lopen_failed(sig) - see lopen() below--------------------------------------------------------------------------*/voidlopen_failed(sig)int sig;{ if(sig != SIGALRM) ff(se,"error %d in lopen_failed: tell wht@n4hgf\r\n",sig); longjmp(_insurance_jmpbuf,1);} /* end of lopen_failed *//*+----------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -