📄 ecurcvr.c
字号:
if(!tty_is_multiscreen) tcap_delete_chars(param);} /* end of ansi_DCH *//*+------------------------------------------------------------------------- ansi_CPL() - cursor to previous line--------------------------------------------------------------------------*/voidansi_CPL(){ register uint param; if(ansilen == 2) /* no param */ param = 1; else param = atoi(ansibuf + 1); if((shm->cursor_y -= param) >= tcap_LINES) /* unsigned comparison */ shm->cursor_y = 0; shm->cursor_x = 0; if(!tty_is_multiscreen) tcap_cursor(shm->cursor_y,shm->cursor_x);} /* end of ansi_CPL *//*+------------------------------------------------------------------------- ansi_CNL() - cursor to next line--------------------------------------------------------------------------*/voidansi_CNL(){ register uint param; if(ansilen == 2) /* no param */ param = 1; else param = atoi(ansibuf + 1); if((shm->cursor_y += param) >= tcap_LINES) shm->cursor_y = tcap_LINES - 1; shm->cursor_x = 0; if(!tty_is_multiscreen) tcap_cursor(shm->cursor_y,shm->cursor_x);} /* end of ansi_CNL *//*+------------------------------------------------------------------------- saved_cursor_save_cursor() - nice but unfortunate IBM extensionI can't find this used anywhere but in the DOS world. Supporting thispair of sequences is what started this whole complex mess.--------------------------------------------------------------------------*/voidsaved_cursor_save_cursor(){ saved_cursor_y = shm->cursor_y; saved_cursor_x = shm->cursor_x;} /* end of saved_cursor_save_cursor *//*+------------------------------------------------------------------------- saved_cursor_restore_cursor() - nice but unfortunate IBM extensionI can't find this used anywhere but in the DOS world. Supporting thispair of sequences is what started this whole complex mess.--------------------------------------------------------------------------*/voidsaved_cursor_restore_cursor(){ shm->cursor_y = saved_cursor_y; shm->cursor_x = saved_cursor_x; tcap_cursor(shm->cursor_y,shm->cursor_x);} /* end of saved_cursor_restore_cursor *//*+------------------------------------------------------------------------- rcvd_ESC() - ESC seen-prepare to accumulate ansi sequence--------------------------------------------------------------------------*/voidrcvd_ESC(){#ifdef ANSI_DEBUG if(wfp) fprintf(wfp,"ESC ");#endif ansi = ansibuf; ansilen = 0; in_ansi_accumulation = 1;} /* end of rcvd_ESC *//*+------------------------------------------------------------------------- is_ansi_terminator(rchar) - is character terminator for ansi sequence?--------------------------------------------------------------------------*/intis_ansi_terminator(rchar)register uint rchar;{ return(isalpha(rchar) || (rchar == '@'));} /* end of is_ansi_terminator *//*+------------------------------------------------------------------------- accumulate_ansi_sequence(rchar)--------------------------------------------------------------------------*/voidaccumulate_ansi_sequence(rchar)uint rchar;{ if(ansilen == (MAX_ANSI_LEN - 2)) { in_ansi_accumulation = 0; return; }#ifdef ANSI_DEBUG_2 if(wfp) { fprintf(wfp,"\naas: %02x %c ansilen=%d", rchar,(rchar & 0x7F < SPACE) ? '.' : (rchar & 0x7F),ansilen); }#endif *ansi++ = (uchar)rchar; *ansi = 0; ansilen++;} /* end of accumulate_ansi_sequence *//*+------------------------------------------------------------------------- process_ansi_sequence() - a full ansi sequence is to be decoded--------------------------------------------------------------------------*/voidprocess_ansi_sequence(){ register itmp;#ifdef ANSI_DEBUG if(wfp) fprintf(wfp,"\npas: len=%d '%s' y,x=%d,%d\n",ansilen,ansibuf, shm->cursor_y,shm->cursor_x);#endif if(!in_ansi_accumulation) return; in_ansi_accumulation = 0; itmp = 1; /* assume write needed */ if((ansilen > 1) && (ansibuf[1] == '=')) ; else switch(ansibuf[ansilen - 1]) { case '@': ansi_ICH(); break; case 'A': ansi_CUU(); break; case 'B': ansi_CUD(); break; case 'C': ansi_CUF(); break; case 'D': ansi_CUB(); break; case 'E': ansi_CNL(); break; case 'F': ansi_CPL(); break; case 'H': ansi_CUP(); break; case 'J': ansi_ED(); break; case 'K': ansi_EL(); break; case 'L': ansi_IL(); break; case 'M': ansi_DL(); break; case 'P': ansi_DCH(); break; case 'S': ansi_SU(); break; case 'T': ansi_SD(); break; case 'X': ansi_ECH(); break; case '`': ansi_HPA(); break; case 'a': ansi_CUF(); break; /* HPR */ case 'd': ansi_VPA(); break; case 'e': ansi_CUD(); break; /* VPR */ case 'f': ansi_CUP(); break; /* HVP */ case 'm': ansi_SGR(); itmp = 0; break; case 'n': ansi_DSR(); itmp = 0; break; case 's': saved_cursor_save_cursor(); itmp = 0; break; case 'u': saved_cursor_restore_cursor(); itmp = 0; break;#ifdef FUTURES case 'h': ansi_SM(); break; /* Set Mode: SCO: lock keyboard * MSDOS: host of shit */ case 'i': ansi_MC(); break; /* Media Copy: send screen to line */ case 'l': ansi_RM(); break; /* Reset Mode: SCO: unlock keyboard * MSDOS: host of shit */#endif /* FUTURES */ default: break; }/* if proper ansi console and indicated, write the buffer to the screen */ if(tty_is_multiscreen && itmp) { rcvrdisp(&esc,1); rcvrdisp(ansibuf,ansilen); }#ifdef ANSI_DEBUG if(wfp) fprintf(wfp,"pas: new cursor y,x=%d,%d\n",shm->cursor_y,shm->cursor_x);#endif} /* end of process_ansi_sequence *//*+------------------------------------------------------------------------- rcvr_log_open()--------------------------------------------------------------------------*/voidrcvr_log_open(){ if(rcvr_log) /* if xmtr set us up for logging */ { rcvr_log_fp = fopen(rcvr_log_file,rcvr_log_append ? "a" : "w"); rcvr_log_append = 1; /* until next %log -s */ if(!rcvr_log_fp) { ff(se,"ecu RCVR: Could not open log file: %s\r\n",rcvr_log_file); ff(se,"recording aborted.\r\n"); rcvr_log = 0; } else if(!rcvr_log_raw && rcvr_log_gen_title) {#if 0 /* decommitted - security risk */ char tstr[80]; get_tod(2,tstr); fprintf(rcvr_log_fp,"\n====> %s (%s, %s, %s) %s\n\n", shm->Lrname,shm->Llogical, shm->Ldescr,(shm->Ltelno[0]) ? shm->Ltelno : "NONE",tstr);#endif } rcvr_log_gen_title = 0; }} /* end of rcvr_log_open *//*+------------------------------------------------------------------------- process_rcvd_char(rchar) - process a received characterReturn 0 if char should be written to console, 1 otherwise--------------------------------------------------------------------------*/intprocess_rcvd_char(rchar)register uint rchar;{ register itmp;#ifdef LIMIT_BELL long now; static long last_bell_time = -1L;#endif /* * automatic ZMODEM frame detection (expensive CPU burners for lazy folks) */ if(shm->autorz) { if((uchar)rchar == autorz_frame[shm->autorz_pos]) { itmp = shm->autorz_pos; /* copy to register trying to be quick */ if(++itmp == sizeof(autorz_frame)) { if(lgetc_count) { rcvrdisp(lgetc_ptr,lgetc_count); lgetc_count = 0; } shmr_notify_zmodem_frame(); pause(); /* wait for death */ itmp = 0; /* in case something starts us up */ } shm->autorz_pos = itmp; return(!itmp); /* don't try to print ^X */ } else shm->autorz_pos = 0; } /* * BEL and alarm-on-incoming-data processing */ if(shm->bell_notify_state == 2) { shm->bell_notify_state = 1; bell_notify(XBELL_3T); } else if(rchar == BEL) {#ifdef LIMIT_BELL time(&now); if((now - last_bell_time) < 2L) return(1); last_bell_time = now;#endif bell_notify(XBELL_ATTENTION); return(0); } /* * video control sequences */ if(rchar == ESC) { rcvd_ESC(); return(1); } else if(in_ansi_accumulation) { accumulate_ansi_sequence(rchar); if(is_ansi_terminator(rchar)) process_ansi_sequence(); return(1); } /* * the bread and butter of the receiver: * print printable characters and obey formatting characters */ if(rchar < SPACE) { switch(rchar) { case CTL_L: spaces((char *)shm->screen,LINESxCOLS); shm->cursor_y = 0; shm->cursor_x = 0; break; case BS: case DEL: if(shm->cursor_x) shm->cursor_x--; break; case NL: if(shm->cursor_y != tcap_LINES - 1) shm->cursor_y++; else { mem_cpy((char *)shm->screen,(char *)shm->screen + tcap_COLS, LINESxCOLS - tcap_COLS); spaces(&shm->screen[shm->cursor_y][0],tcap_COLS); } break; case CRET: shm->cursor_x = 0; break; case TAB: itmp = 8 - (shm->cursor_x % 8); shm->cursor_x += itmp; if(shm->cursor_x >= tcap_COLS) { shm->cursor_x = 0; if(++shm->cursor_y >= tcap_LINES) shm->cursor_y = tcap_LINES - 1; } spaces(&shm->screen[shm->cursor_y][shm->cursor_x],itmp); break;#ifdef TANDEM_ENQ_ACK /* for my friend John Dashner at Tandem */ case ENQ: lputc(ACK); return(0);#endif } } else { shm->screen[shm->cursor_y][shm->cursor_x++] = (uchar)rchar; if(shm->cursor_x >= tcap_COLS) { shm->cursor_x = 0; if(shm->cursor_y != tcap_LINES - 1) shm->cursor_y++; else { mem_cpy((char *)shm->screen,(char *)shm->screen + tcap_COLS, LINESxCOLS - tcap_COLS); spaces(&shm->screen[shm->cursor_y][shm->cursor_x],tcap_COLS); } } }#ifdef ANSI_DEBUG_2 if(wfp) { if((rchar & 0x7F) == NL) fputs("\n",wfp); else fputc(((rchar & 0x7F) < SPACE) ? '.' : (rchar & 0x7F),wfp); }#endif /* * receiver logging */ if(rcvr_log && rcvr_log_fp) { /* if raw mode or character not excluded from "cooked" logging */ if(rcvr_log_raw || ((rchar >= SPACE) && (rchar <= '~')) || (rchar == NL) || (rchar == TAB)) { LOGPUTC(rchar,rcvr_log_fp); } /* back if log file if not raw and char is backspace */ else if(!rcvr_log_raw && ((rchar == BS)||(rchar == DEL))) { long logpos = 0; if(logpos = ftell(rcvr_log_fp)) fseek(rcvr_log_fp,logpos - 1,0); } if(rcvr_log_flusheach) fflush(rcvr_log_fp); } return(0);} /* end of process_rcvd_char *//*+----------------------------------------------------------------------- rcvr() - copy characters from remote line to screen------------------------------------------------------------------------*/voidrcvr(){ uchar rchar; uchar nlchar = NL;#ifdef ANSI_DEBUGchar s80[80]; wfp = fopen(ANSI_DEBUG_LOGFILE,"a"); if(ulindex(ANSI_DEBUG_LOGFILE,"/dev/tty") != -1) { sprintf(s80,"stty opost ocrnl < %s",ANSI_DEBUG_LOGFILE); system(s80); } fprintf(wfp,"***************\n");#ifdef ANSI_DEBUG_NOBUF setbuf(wfp,NULL);#endif /* ANSI_DEBUG_NOBUF */#endif /* ANSI_DEBUG */ rcvr_pid = getpid(); shm->autorz_pos = 0; lgetc_count = 0; in_ansi_accumulation = 0; ansi = ansibuf; ansilen = 0; shm->rcvrdisp_ptr = shm->rcvrdisp_buffer; shm->rcvrdisp_count = 0;/* yetch - magic number gretching for lines and columns */ if(!tcap_LINES || !tcap_COLS) { tcap_LINES = 25; tcap_COLS = 80; } if(tcap_LINES > SCREEN_LINES_MAX) tcap_LINES = SCREEN_LINES_MAX; if(tcap_COLS > SCREEN_COLS_MAX) tcap_COLS = SCREEN_COLS_MAX; LINESxCOLS = tcap_LINES * tcap_COLS; rcvr_signals(); rcvr_log_open(); saved_cursor_y = shm->cursor_y; saved_cursor_x = shm->cursor_x;/* receive loop - keep tight as possible! */ if(tty_is_multiscreen) { while(1) { rchar = lgetc_rcvr(); if(process_rcvd_char(rchar)) continue; rcvrdisp((char *)&rchar,1); if(shm->Ladd_nl_incoming && (rchar == CRET)) rcvrdisp((char *)&nlchar,1); } } else { while(1) { rchar = lgetc_rcvr(); if(rchar >= 0x80) rchar = non_multiscreen_hi_map[rchar - 0x80]; if(process_rcvd_char(rchar)) continue; rcvrdisp((char *)&rchar,1); if(shm->Ladd_nl_incoming && (rchar == CRET)) rcvrdisp((char *)&nlchar,1); } }} /* end of rcvr *//* end of ecurcvr.c *//* vi: set tabstop=4 shiftwidth=4: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -