📄 mesg.c
字号:
/* * mesg.c - message loop * * Author: David Scott * Date Started: 25-Aug-2000 * * Modification history: * * .000830 initial beta release */#include <curses.h>#include <unistd.h>#include <stdlib.h>#include <ctype.h>#include "hview.h"int x,y;/* * the main message loop * inputs: pointing to current window * input stream */void message_loop( WINDOW *wp, FILE *in ){ int offset, pagelen,bytesread; int ch; bool in_echo; in_echo = FALSE; offset = 0; pagelen = (screen_y-4)*16; bytesread=printscr( wp, in, 0 ); move(1,10); refresh(); x = 10; y = 1; noecho(); while (((ch = getch()) != 'q') && (ch != 'Q')) { switch(toupper(ch)) { case KEY_DOWN: /* down arrow or control-n */ case CTRL('N'): y++; if( y > screen_y-4 ) { if( offset != totalbytes) { offset+=16; move(0,60); printheader(wp,bytesread=printscr(wp,in, offset)); } y--; } if( OFFSET(x,y) > bytesread) y--; break; case KEY_UP: /* up arrow or control-p */ case CTRL('P'): y-=1; if( y < 1 ) {/* if( in_echo ) { }*/ if( offset != 0 ) { offset-=16; move(0,60); printheader(wp,bytesread=printscr(wp,in,offset)); } y++; } break; case KEY_LEFT: /* left arrow or control-f */ case CTRL('F'): if( (x-3) < 10 ) { if( y == 1 ) { if( offset != 0 ) { offset-=16; move(0,60); printheader(wp,bytesread=printscr(wp,in,offset)); x=55; } } else { y--; x=55; } } else { x = ((x-3)<10)?10:x-3; } break; case KEY_RIGHT: /* right arrow or control-b */ case CTRL('B'): if( ((x+3) > 56) ) { if( y < screen_y-4) { x=10; y++; } else if (offset != totalbytes) { offset+=16; move(0,60); printheader(wp,bytesread=printscr(wp,in, offset)); x = 10; } } else { x+=3; } if(OFFSET(x+3,y) > bytesread) x-=3; break; case CTRL('V'): /* Control-V (Page Down) */ offset = ((offset+pagelen)<=abs(totalbytes))?offset+pagelen:offset; move( 0,60 ); printheader(wp, bytesread=printscr(wp,in,offset)); x = 10; y=1; break; case CTRL('Y'): /* Control-Y (Page up) */ offset = ((offset-pagelen) >= 0)?offset-pagelen:0; move( 0,60 ); printheader(wp, bytesread=printscr(wp,in,offset)); x = 10, y = 1; break; case CTRL('R'): /* Control-R (Refresh) */ move(0,60); printheader(wp, bytesread=printscr(wp,in,offset)); break; case 'M': /* M - modify */ in_echo = !in_echo; move(0,0); printw("%c", (in_echo)?'*':' '); move(y,x); break; case 'W': /* W -write block out */ writeblock( in, offset, bytesread ) ; break; default: if( in_echo ) edit(toupper(ch)); } move( y, x ); refresh(); } echo(); }void edit(int ch){ int z; if( isxdigit( ch ) ) { if(!( (y < 1) || (y > screen_y -4))) { move(y,x); printw("%c", toupper(ch) ); /* * calc offset once instead of every time we need * the value. */ z = OFFSET(x,y); /* * this checks to see if the next position of the cursor * will be a break. * * If it is then we are dealing with the low nibble so * mask off the high nibble and add in the new bits. * else mask off the high nibble, shift the current bits * into the high nibble and mask off the low. */ buffer[z] = ((x+1)%3)? (xtoi(ch)<<4) + (buffer[z] & 0x0f): xtoi(ch) + (buffer[z] & 0xf0); move(y,XOFFSET(x)+60); printch(buffer[z]); refresh(); x += ((x+1)%3)?1:2; if (x > 56 && y <=(screen_y -4)) { y++; x=10; } move(y,x); refresh(); } }}int writeblock( FILE *in, int offset, int len){ int x, ch, err; FILE *tmp; err = 1; fseek(in, offset,SEEK_SET); for( x = 0; x<len && err!=EOF;x++ ) { fprintf(tmp,"%x ",x); err = fputc(buffer[x],in); } return err;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -