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

📄 window.c

📁 小型通讯程序的C语言源程序的C语言源程序库
💻 C
📖 第 1 页 / 共 3 页
字号:
  int ocurx = w->curx;    w->curx = 0;  (void) _wclreol(w);  w->curx = ocurx;  wlocate(w, ocurx, w->cury);}/* * Clear to end of line. */void wclreol(w)WIN *w;{  if (_wclreol(w) && w->direct) _gotoxy(w->x1 + w->curx, w->y1 + w->cury);  if (dirflush) wflush();}/* * Clear to begin of line */void wclrbol(w)WIN *w;{  register x;  int y;  #ifdef SMOOTH  curwin = w;#endif  y = w->curx + w->y1;  if (w->direct) _gotoxy(w->x1, y);    for(x = w->x1; x <= w->x2; x++) _write(' ', w->direct, x, y,  		w->attr, w->color);  if (w->direct) {  	_gotoxy(w->x1 + curx, y);	if (dirflush) wflush();  }}/* * Clear to end of screen */void wclreos(w)WIN *w;{  register y;  int ocurx, ocury;    ocurx = w->curx;  ocury = w->cury;    w->curx = 0;  for(y = w->cury + 1; y <= w->y2 - w->y1; y++) {  	w->cury = y;  	(void) _wclreol(w);  }  w->curx = ocurx;  w->cury = ocury;  if (_wclreol(w) && w->direct) _gotoxy(w->x1 + w->curx, w->y1 + w->cury);  if (dirflush && w->direct) wflush();}/* * Clear to begin of screen. */void wclrbos(w)WIN *w;{  int ocurx, ocury;  register y;    ocurx = w->curx;  ocury = w->cury;    w->curx = 0;    for(y = 0; y < ocury; y++) {  	w->cury = y;  	(void) _wclreol(w);  }  w->curx = ocurx;  w->cury = ocury;  wclrbol(w);}/* * Clear a window. */void winclr(w)WIN *w;{  register y;  int olddir = w->direct;  _setattr(w->attr, w->color);  w->curx = 0;  if (CL && w->y1 == 0 && w->y2 == LINES-1 &&            w->x1 == 0 && w->x2 == COLS-1) {	w->direct = 0;	curx = 0;	cury = 0;	outstr(CL);  }  for(y = w->ys - 1; y >= 0; y--) { 	w->cury = y; 	(void) _wclreol(w);  }  w->direct = olddir;  _gotoxy(w->x1, w->y1);  if (dirflush) wflush();}/* ==== Insert / Delete functions ==== */void winsline(w)WIN *w;{  int osy1, osy2;    osy1 = w->sy1;  osy2 = w->sy2;    w->sy1 = w->y1 + w->cury;  w->sy2 = w->y2;  wscroll(w, S_DOWN);    w->sy1 = osy1;  w->sy2 = osy2;}void wdelline(w)WIN *w;{  int osy1, osy2;  int ocury;    ocury = w->cury;  osy1 = w->sy1;  osy2 = w->sy2;    w->sy1 = w->y1 + w->cury;  w->sy2 = w->y2;    _intern = 1;  wscroll(w, S_UP);  _intern = 0;  wlocate(w, 0, ocury);  w->sy1 = osy1;  w->sy2 = osy2;}/* * Insert a space at cursor position. */void winschar(w)WIN *w;{  int y;  register x;  int doit = 1;  ELM buf[128];  ELM *e = buf;#ifdef SMOOTH  curwin = w;#endif  if (w->curx == w->xs - 1) {  	wputc(w, ' ');  	return;  }  if (w->xs == COLS && IC != CNULL) {  	doit = 0;  	if (w->direct) outstr(IC);  }    /* Get the rest of line into buffer */  y = w->y1 + w->cury;  x = w->x1 + w->curx;  memcpy(buf, gmap + COLS * y + x, sizeof(ELM) * (w->xs - w->curx));    _write(' ', doit && w->direct, x++, y, w->attr, w->color);  /* Write buffer to screen */  for(; x <= w->x2; x++) {  	_write(e->value, doit && w->direct, x, y, e->attr, e->color);  	e++;  }  wlocate(w, w->curx, w->cury);}/* * Delete character under the cursor. */void wdelchar(w)WIN *w;{  register x, y;  int doit = 1;  ELM *e;#ifdef SMOOTH  curwin = w;#endif  x = w->x1 + w->curx;  y = w->y1 + w->cury;    if (w->direct && w->xs == COLS && DC != CNULL) {  	/*_gotoxy(x - 1, y);*/  	_gotoxy(x, y);  	outstr(DC);  	doit = 0;  }    e = gmap + y * COLS + x + 1;    for(; x < w->x2; x++) {  	_write(e->value, doit && w->direct, x, y, e->attr, e->color);  	e++;  }  _write(' ', doit && w->direct, x, y, w->attr, w->color);  wlocate(w, w->curx, w->cury);}/* ============= Support: edit a line on the screen. ============ *//* Redraw the line we are editting. */static void lredraw(w, x, y, s, len)WIN *w;int x;int y;char *s;int len;{  int i, f;  i = 0;  wlocate(w, x, y);  for(f = 0; f < len; f++) {	if (s[f] == 0) i++;	wputc(w, i ? ' ' : s[f]);  }}/* wgets - edit one line in a window. */int wgets(w, s, linelen, maxlen)WIN *w;char *s;int linelen;int maxlen;{  int c;  int idx;  int offs = 0;  int f, st, i;  char buf[256];  int quit = 0;  int x, y, r;  int direct = dirflush;  x = w->curx;  y = w->cury;  i = w->xs - x;  if (linelen >= i - 1) linelen = i - 1;  /* We assume the line has already been drawn on the screen. */  if ((idx = strlen(s)) > linelen)	idx = linelen;  strcpy(buf, s);  wlocate(w, x + idx, y);  dirflush = 0;  wflush();  while(!quit) {	c = getch();	switch(c) {		case '\r':		case '\n':			st = 0;			quit = 1;			break;		case K_ESC: /* Exit without changing. */			wlocate(w, x, y);			lredraw(w, x, y, s, linelen);			wflush();			st = -1;			quit = 1;			break;		case K_HOME: /* Home */			r = (offs > 0);			offs = 0;			idx = 0;			if (r) lredraw(w, x, y, buf, linelen);			wlocate(w, x, y);			wflush();			break;		case K_END: /* End of line. */			idx = strlen(buf);			r = 0;			while(idx - offs > linelen) {				r = 1;				offs += 4;			}			if (r) lredraw(w, x, y, buf + offs, linelen);			wlocate(w, x + idx - offs, y);			wflush();			break;		case K_LT: /* Cursor left. */		case K_BS: /* Backspace is first left, then DEL. */			if (idx == 0) break;			idx--;			if (idx < offs) {				offs -= 4;				/*if (c == K_LT) FIXME? */					lredraw(w, x, y, buf + offs, linelen);			}			if(c == K_LT) {				wlocate(w, x + idx - offs, y);				wflush();				break;			}			/*FALLTHRU*/		case K_DEL: /* Delete character under cursor. */			if (buf[idx] == 0) break;			for(f = idx; buf[f]; f++)				buf[f] = buf[f+1];			lredraw(w, x + idx - offs, y, buf + idx,				linelen - (idx - offs));			wlocate(w, x + idx - offs, y);			wflush();			break;		case K_RT:			if (buf[idx] == 0) break;			idx++;			if (idx - offs > linelen) {				offs += 4;				lredraw(w, x, y, buf + offs, linelen);			}			wlocate(w, x + idx - offs, y);			wflush();			break;		default:			/* Insert character at cursor position. */			if (c < 32 || c > 127) break;			if (idx + 1 >= maxlen) break;			for(f = strlen(buf) + 1; f > idx; f--)				buf[f] = buf[f-1];			i = buf[idx];			buf[idx] = c;			if (i == 0) buf[idx+1] = i;			if (idx - offs >= linelen) {				offs += 4;				lredraw(w, x, y, buf + offs, linelen);			} else				lredraw(w, x + idx - offs, y, buf + idx,					linelen - (idx - offs));			idx++;			wlocate(w, x + idx - offs, y);			wflush();			break;	}  }  if (st == 0) strcpy(s, buf);  dirflush = direct;  return(st);}/* ==== Initialization code ==== */static char tbuf[1024];static char cbuf[1024];/* * Initialize the window system */#ifdef BBS/* Code for the BBS system.. */int win_init(term, lines)char *term;int lines;{  int fg = WHITE;  int bg = BLACK;  int attr = A_NORMAL;#else/* Code for other applications (minicom!) */int win_init(fg, bg, attr)int fg;int bg;int attr;{  char *term;#endif  static WIN _stdwin;  char *p;  int f, olduseattr;  if (w_init) return(0);#ifndef BBS  if ((term = getenv("TERM")) == CNULL) {  	fprintf(stderr, "Environment variable TERM not set\n");	return(-1);  }#endif  switch((f = tgetent(cbuf, term))) {  	case 0:  		fprintf(stderr, "No termcap entry for %s\n", term);  		return(-1);  	case -1:  		fprintf(stderr, "No /etc/termcap present!\n");  		return(-1);  	default:  		break;  }  _tptr = tbuf;  if ((CM = tgetstr("cm", &_tptr)) == CNULL) {  	fprintf(stderr, "No cursor motion capability (cm)\n");  	return(-1);  }  getrowcols(&LINES, &COLS);#ifdef BBS  LINES = lines;#endif  if (LINES == 0 && (LINES = tgetnum("li")) <= 0) {  	fprintf(stderr, "Number of terminal lines unknown\n");  	return(-1);  }  if (COLS == 0 && (COLS = tgetnum("co")) <= 0) {  	fprintf(stderr, "Number of terminal columns unknown\n");  	return(-1);  }  /* Terminal Capabilities */  ME = tgetstr("me", &_tptr);  SE = tgetstr("se", &_tptr);  UE = tgetstr("ue", &_tptr);  AS = tgetstr("as", &_tptr);  AE = tgetstr("ae", &_tptr);  MB = tgetstr("mb", &_tptr);  MD = tgetstr("md", &_tptr);  MR = tgetstr("mr", &_tptr);  SO = tgetstr("so", &_tptr);  US = tgetstr("us", &_tptr);  CE = tgetstr("ce", &_tptr);  Al = tgetstr("al", &_tptr);  Dl = tgetstr("dl", &_tptr);  AL = tgetstr("AL", &_tptr);  DL = tgetstr("DL", &_tptr);  CS = tgetstr("cs", &_tptr);  SF = tgetstr("sf", &_tptr);  SR = tgetstr("sr", &_tptr);  VB = tgetstr("vb", &_tptr);  VE = tgetstr("ve", &_tptr);  VI = tgetstr("vi", &_tptr);  IS = tgetstr("is", &_tptr);  RS = tgetstr("rs", &_tptr);  KS = tgetstr("ks", &_tptr);  KE = tgetstr("ke", &_tptr);  CD = tgetstr("cd", &_tptr);  CL = tgetstr("cl", &_tptr);  IC = tgetstr("ic", &_tptr);  DC = tgetstr("dc", &_tptr);  BC = tgetstr("bc", &_tptr);  CR = tgetstr("cr", &_tptr);  NL = tgetstr("nl", &_tptr);  if (MR == CNULL) MR = SO;  /* Try standout */  if (MR == CNULL) MR = US;  /* Try underline */  if (MR == CNULL) MR = MD;  /* Try bold */  if (SF == CNULL) SF = "\n";  /* cr and nl are often not defined but result in great optimization.   * I only hope that minicom does not break on terminals where this   * really does not work..   */  if (CR == CNULL) CR = "\r";  if (NL == CNULL) NL = "\n";  /* Reset attributes */  olduseattr = useattr;  useattr = 1;  _setattr(A_NORMAL, COLATTR(WHITE, BLACK));  useattr = olduseattr;  /* No reverse? don't use attributes at all. */  if (MR == CNULL) useattr = 0;  /* If we have the "ug" flag, don't allow attributes to be displayed. */  if (tgetnum("ug") > 0) useattr = 0;    _has_am = tgetflag("am");  _mv_standout = tgetflag("ms");  if (tgetflag("bs"))	if (BC == CNULL) BC = "\b";  else  	BC = CNULL;	  /* Special box-drawing characters */  D_UL  = 201;  D_HOR = 205;  D_UR  = 187;  D_LL  = 200;  D_VER = 186;  D_LR  = 188;    S_UL  = 218;  S_HOR = 196;  S_UR  = 191;  S_LL  = 192;  S_VER = 179;  S_LR  = 217;    if ((p = tgetstr("gA", &_tptr)) != CNULL) wcharmap[201] = *p;  if ((p = tgetstr("gB", &_tptr)) != CNULL) wcharmap[205] = *p;  if ((p = tgetstr("gC", &_tptr)) != CNULL) wcharmap[187] = *p;  if ((p = tgetstr("gD", &_tptr)) != CNULL) wcharmap[200] = *p;  if ((p = tgetstr("gE", &_tptr)) != CNULL) wcharmap[186] = *p;  if ((p = tgetstr("gF", &_tptr)) != CNULL) wcharmap[188] = *p;  if ((p = tgetstr("gG", &_tptr)) != CNULL) wcharmap[218] = *p;  if ((p = tgetstr("gH", &_tptr)) != CNULL) wcharmap[196] = *p;  if ((p = tgetstr("gI", &_tptr)) != CNULL) wcharmap[191] = *p;  if ((p = tgetstr("gJ", &_tptr)) != CNULL) wcharmap[192] = *p;  if ((p = tgetstr("gK", &_tptr)) != CNULL) wcharmap[179] = *p;  if ((p = tgetstr("gL", &_tptr)) != CNULL) wcharmap[217] = *p;  /* Memory for global map */  if ((gmap = (ELM *)malloc(sizeof(ELM) * LINES * COLS)) == (ELM *)0) {  	fprintf(stderr, "Not enough memory\n");  	return(-1);  };  _buffend = _bufstart + BUFFERSIZE;  /* Initialize stdwin */  stdwin = &_stdwin;  stdwin->wrap = 1;  stdwin->cursor = CNORMAL;  stdwin->autocr = 1;  stdwin->doscroll = 1;  stdwin->x1 = 0;  stdwin->sy1 = stdwin->y1 = 0;  stdwin->x2 = COLS - 1;  stdwin->sy2 = stdwin->y2 = LINES - 1;  stdwin->xs = COLS;  stdwin->ys = LINES;  stdwin->attr = attr;  stdwin->color = COLATTR(fg, bg);  stdwin->direct = 1;#if HISTORY  stdwin->histbuf = (ELM *)0;#endif  if (KS != CNULL) outstr(KS); /* Keypad mode */  if (IS != CNULL) outstr(IS); /* Initialization string */    (void) setcbreak(1); /* Cbreak, no echo */  winclr(stdwin);  w_init = 1;  return(0);}void win_end(){  if (gmap == (ELM *)0 || w_init == 0) return;  (void) setcbreak(0); /* Reset */  stdwin->attr = A_NORMAL;  stdwin->color = COLATTR(WHITE, BLACK);  _setattr(stdwin->attr, stdwin->color);  winclr(stdwin);  wcursor(stdwin, CNORMAL);  if (KE != CNULL) outstr(KE);  if (RS != CNULL) outstr(RS);  wflush();  free(gmap);  gmap = (ELM *)0;  stdwin = NIL_WIN;  w_init = 0;}

⌨️ 快捷键说明

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