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

📄 dial.c

📁 minicom2.0源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
int position_dialing_directory, k;{  /* acme@conectiva.com.br 28/02/1998      hack to make i18n strings work with _this_ hack ;> :     the i18n string must have a options with the same size (padded      with spaces... I only hope the translations are smart enough to     figure this out... ;> */  int option_size = strlen (_(what)) / DIALOPTS;  if (k == dprev) return;  if (dprev >= 0) {  	wlocate(dsub, position_dialing_directory + option_size * dprev, 0);	if (!useattr) {		wputs(dsub, " ");	} else {  		wsetattr(dsub, XA_REVERSE | stdattr);  		wprintf(dsub, "%*.*s", option_size, option_size, _(what) + option_size * dprev);	}  }  dprev = k;  wlocate(dsub, position_dialing_directory + option_size * k, 0);  if (!useattr) {	wputs(dsub, ">");  } else {	wsetattr(dsub, stdattr);	wprintf(dsub, "%*.*s", option_size, option_size, _(what) + option_size * k);  }}static char *fmt = "\r %2d %c%-16.16s%-16.16s%8.8s %5.5s %4d %-15.15s\n";/* * Print the dialing directory. Only draw from "cur" to bottom. */static void prdir(dialw, top, cur)WIN *dialw;int top, cur;{  int f, start;  struct dialent *d;  start = cur - top;  dirflush = 0;  wlocate(dialw, 0, start + 1);  for(f = start; f < dialw->ys - 2; f++) {  	d = getno(f + top);  	if (d == (struct dialent *)0) break;  	wprintf(dialw, fmt, f+1+top, (d->flags & FL_TAG) ? '>' : ' ',		d->name, d->number, d->lastdate, d->lasttime,   		d->count, d->script);  }  dirflush = 1;  wflush();}/* * Move an entry forward/back in the dial directory. jl 1.9.1999 */int move_entry(WIN *dialw, struct dialent *d, int cur, int *top){  int ocur = cur,      quit = 0,      c = 0;  struct dialent *dtmp;  while (!quit) {    switch (c = wxgetch()) {    	case K_DN:    	case 'j':	  if (!(d->next))	    break;	  if (cur == 0) {   /* special case: move d from start to 2nd */	    dtmp = d->next;	    d->next = dtmp->next;	    dtmp->next = d;	    dialents = dtmp;	  } else {	    /* swap d with the next one in the list */	    dtmp = getno(cur - 1);	    dtmp->next = d->next;	    d->next = d->next->next;	    dtmp->next->next = d;	  }	  cur++;	  break;    	case K_UP:    	case 'k':	  if (cur == 0)	    break;	  if (cur == 1) { /* special case: move d to start of list */	    dtmp = dialents;	    dtmp->next = d-> next;	    d->next = dtmp;	    dialents = d;	  } else {	  /* swap d with the previous one in the list */	    dtmp = getno(cur - 2);	    dtmp->next->next = d-> next;	    d->next = dtmp->next;	    dtmp->next = d;	  }	  cur--;	  break;    	case '\033':    	case '\r':    	case '\n':	  quit = 1;	  break;    	default:	  break;    } /* end switch */    /* If the list order changed, redraw the directory window */    if (cur != ocur) {      /* First remove cursor bar from the old position */      wcurbar(dialw, ocur + 1 - *top, XA_NORMAL | stdattr);      if (cur < *top)	(*top)--;      else if (cur - *top > dialw->ys - 3)	(*top)++;      prdir(dialw, *top, *top);      wcurbar(dialw, cur + 1 - *top, XA_REVERSE | stdattr);      ocur = cur;    } /* end redraw condition */  }   /* end loop   */  return cur;}/* Little menu. */static char *d_yesno[] = { N_("   Yes  "), N_("   No   "), CNULL };/* Try to dial an entry. */static void dial_entry(d)struct dialent *d;{  long nb;  struct dialent *d2;  /* Change settings for this entry. */  if (atoi(d->baud) != 0) {  	strcpy(P_BAUDRATE, d->baud);	strcpy(P_PARITY, d->parity);	strcpy(P_BITS, d->bits);	strcpy(P_STOPB, d->stopb);	port_init();	mode_status();  }  newtype = d->term;  vt_set(-1, d->flags & FL_WRAP, NULL, -1, -1, d->flags & FL_ECHO, -1, -1);#ifdef HAVE_SELECT  local_echo = d->flags & FL_ECHO;#endif  if (newtype != terminal)	init_emul(newtype, 1);  /* Set backspace key. */  keyboard(KSETBS, d->flags & FL_DEL ? 127 : 8);  strcpy(P_BACKSPACE, d->flags & FL_DEL ? "DEL" : "BS");  /* Now that everything has been set, dial. */  if ((nb = dial(d, &d2)) < 0) return;    if (d2 != (struct dialent *)NULL)    d = d2;	/* jl 22.09.97 */  /* Did we detect a baudrate , and can we set it? */  if (P_MAUTOBAUD[0] == 'Y' && nb) {	sprintf(P_BAUDRATE, "%ld", nb);	port_init();	mode_status();  }  else if (P_SHOWSPD[0] == 'l')    mode_status();  /* Make sure the last date is updated   / jl 22.06.97 */  writedialdir();  /* Run script if needed. */  if (d->script[0]) runscript(0, d->script, d->username, d->password);  /* Remember _what_ we dialed.. */  dial_name = d->name;  dial_number = d->number;  dial_user = d->username;  dial_pass = d->password;  return;}/* * Dial an entry from the dialing directory; this * is used for the "-d" command line flag. * Now you can tag multiple entries with the -d option / jl 3.5.1999 */void dialone(entry)char *entry;{  int num;  struct dialent *d;  struct dialent *d1 = (struct dialent *)NULL;  char *s;  char buf[128];  s = strtok(entry,",;");  while (s) {    /* Find entry. */    if ((num = atoi(s)) != 0) {      if (d = getno(num - 1)) {	d->flags |= FL_TAG;	if (d1 == (struct dialent *)NULL)	  d1 = d;      }    } else {      for(d = dialents; d; d = d->next)	if (strstr(d->name, s)) {	  d->flags |= FL_TAG;	  if (d1 == (struct dialent *)NULL)	    d1 = d;	}    }    s = strtok(NULL,",;");  }  /* Not found. */  if (d1 == NULL) {	snprintf(buf, sizeof(buf), _("Entry \"%s\" not found. Enter dialdir?"), entry);	if (ask(buf, d_yesno) != 0) return;	dialdir();	return;  }  /* Dial the number! */  sleep(1);  dial_entry(d1);}/* * Draw the dialing directory. */void dialdir(){  WIN *w;  struct dialent *d = NULL, *d1, *d2;  static int cur = 0;  static int ocur = 0;  int subm = 0;  int quit = 0;  static int top = 0;  int c = 0;  int pgud = 0;  int first = 1;  int x1, x2;  char *s, dname[128];  static char manual[128];  int changed = 0;  static char *tag_exit  = N_("( Escape to exit, Space to tag )"),    	      *move_exit = N_(" Move entry up/down, Escape to exit");  int tagmvlen = 0;  int position_dialing_directory = ((COLS / 2) + 32 - strlen (_(what))) / 2;  dprev = -1;  dname[0] = 0;  tagmvlen = strlen(_(move_exit));  if (strlen(_(tag_exit)) > tagmvlen)	tagmvlen = strlen(_(tag_exit));  /* Allright, draw the dialing directory! */    dirflush = 0;  x1 = (COLS / 2) - 37;  x2 = (COLS / 2) + 37;  dsub = wopen(x1 - 1, LINES - 3, x2 + 1, LINES - 3, BNONE,   		XA_REVERSE | stdattr, mfcolor, mbcolor, 0, 0, 1);  w = wopen(x1, 2, x2, LINES - 6, BSINGLE, stdattr, mfcolor, mbcolor, 0, 0, 1);  wcursor(w, CNONE);  wtitle(w, TMID, _("Dialing Directory"));  wputs(w,      _("     Name            Number            Last on      Times Script\n"));  wlocate(dsub, position_dialing_directory, 0);  wputs(dsub, _(what));  wsetregion(w, 1, w->ys - 1);  w->doscroll = 0;  prdir(w, top, top);    wlocate(w, position_dialing_directory, w->ys - 1);  wprintf(w, "%*.*s", tagmvlen,tagmvlen, tag_exit);  dhili(position_dialing_directory, subm);  dirflush = 1;  wredraw(dsub, 1);again:    wcurbar(w, cur + 1 - top, XA_REVERSE | stdattr);  if (first) {  	wredraw(w, 1);  	first = 0;  }  while(!quit) {  	d = getno(cur);  	switch(c = wxgetch()) {  		case K_UP:  		case 'k':  			cur -= (cur > 0);  			break;  		case K_DN:  		case 'j':  			cur += (cur < nrents - 1);  			break;  		case K_LT:  		case 'h':			subm--;			if (subm < 0) subm = DIALOPTS - 1;  			break;  		case K_RT:  		case 'l':  			subm = (subm + 1) % DIALOPTS;  			break;  		case K_PGUP:  		case '\002': /* Control-B */  			pgud = 1;  			quit = 1;  			break;	  		case K_PGDN:  		case '\006': /* Control-F */  			pgud = 2;  			quit = 1;  			break;			case 'd':    /* Dial. */			subm = 0;			quit = 1;			break;		case 'f':    /* Find. */			subm = 1;			quit = 1;			break;		case 'a':    /* Add. */			subm = 2;			quit = 1;			break;		case 'e':    /* Edit. */			subm = 3;			quit = 1;			break;		case 'r':    /* Remove. */			subm = 4;			quit = 1;			break;		case 'v':    /* moVe entry */		  	subm = 5;			quit = 2;			break;		case 'm':    /* Manual. */			subm = 6;			quit = 1;			break;		case ' ':    /* Tag. */  			wlocate(w, 4, cur + 1 - top);			d->flags ^= FL_TAG;			wsetattr(w, XA_REVERSE | stdattr);			wprintf(w, "%c", d->flags & FL_TAG ? '>' : ' ');			wsetattr(w, XA_NORMAL | stdattr);  			cur += (cur < nrents - 1);			break;  		case '\033':  		case '\r':  		case '\n':  			quit = (subm==5 ? 2 : 1);  			break;  		default:  			break;  	}  	/* Decide if we have to delete the cursor bar */  	if (cur != ocur || quit == 1)	  	wcurbar(w, ocur + 1 - top, XA_NORMAL | stdattr);  		  	if (cur < top) {  		top--;  		prdir(w, top, top);		}	if (cur - top > w->ys - 3) {		top++;  		prdir(w, top, top);	}  	if (cur != ocur) wcurbar(w, cur + 1 - top, XA_REVERSE | stdattr);  	ocur = cur;  	dhili(position_dialing_directory, subm);  }  quit = 0;  /* ESC means quit */  if (c == '\033') {  	if (changed) writedialdir();	wclose(w, 1);	wclose(dsub, 1);	return;  }  /* Page up or down ? */  if (pgud == 1) { /* Page up */  	ocur = top;  	top -= w->ys - 2;  	if (top < 0) top = 0;  	cur = top;  	pgud = 0;  	if (ocur != top) prdir(w, top, cur);  	ocur = cur;	goto again;  }  if (pgud == 2) { /* Page down */  	ocur = top;  	if (top < nrents - w->ys + 2) {		top += w->ys - 2;		if (top > nrents - w->ys + 2) {			top = nrents - w->ys + 2;		}		cur = top;	} else		cur = nrents - 1;	pgud = 0;	if (ocur != top) prdir(w, top, cur);	ocur = cur;	goto again;  }    /* Dial an entry */  if (subm == 0) {  	wclose(w, 1);  	wclose(dsub, 1);  	if (changed) writedialdir();	/* See if any entries were tagged. */	if (!(d->flags & FL_TAG)) {	  /* First check the entries from the highlighted one to end.. */	  for (d1 = d; d1; d1 = d1->next)	    if (d1->flags & FL_TAG) {	      d = d1;	      break;	    }	  /* ..and if none of them was tagged, check from the begining. */	  if (!d1)	    for(d1 = dialents; d1 && d1!=d; d1 = d1->next)	      if (d1->flags & FL_TAG) {		d = d1;		break;	      }	  /* If no tags were found, we'll dial the highlighted one */	}	dial_entry(d);	return;  }  /* Find an entry */  if (subm == 1) {	s = input(_("Find an entry"), dname);	if (s == NULL || s[0] == 0) goto again;	x1 = 0;	for(d = dialents; d; d = d->next, x1++)		if (strstr(d->name, s)) break;	if (d == NULL) {		wbell();		goto again;	}	/* Set current to found entry. */	ocur = top;	cur = x1;	/* Find out if it fits on screen. */	if (cur < top || cur >= top + w->ys - 2) {		/* No, try to put it in the middle. */		top = cur - (w->ys / 2) + 1;		if (top < 0) top = 0;		if (top > nrents - w->ys + 2) {			top = nrents - w->ys + 2;		}	}	if (ocur != top) prdir(w, top, top);	ocur = cur;  }  /* Add / insert an entry */  if (subm == 2) {  	d1 = mkstdent();  	if (d1 == (struct dialent *)0) {  		wbell();  		goto again;  	}	changed++;  	cur++;  	ocur = cur;  	d2 = d->next;  	d->next = d1;  	d1->next = d2;  	  	nrents++;  	if (cur - top > w->ys - 3) {  		top++;  		prdir(w, top, top);  	} else {  		prdir(w, top, cur);	}  }  /* Edit an entry */  if (subm == 3) {  	dedit(d);	changed++;  	wlocate(w, 0, cur + 1 - top);  	wprintf(w, fmt, cur+1, (d->flags & FL_TAG) ? 16 : ' ', d->name,	d->number, d->lastdate, d->lasttime, d->count, d->script);  }    /* Delete an entry from the list */  if (subm == 4 && ask(_("Remove entry?"), d_yesno) == 0) {	changed++;  	if (nrents == 1) {  		free((char *)d);  		d = dialents = mkstdent();  		prdir(w, top, top);  		goto again;  	}  	if (cur == 0)  		dialents = d->next;  	else  		getno(cur - 1)->next = d->next;  	free((char *)d);  	nrents--;  	if (cur - top == 0 && top == nrents) {  		top--;  		cur--;  		prdir(w, top, top);  	} else {  		if (cur == nrents) cur--;		prdir(w, top, cur);  	}	if (nrents - top <= w->ys - 3) {		wlocate(w, 0, nrents - top + 1);		wclreol(w);	}  	ocur = cur;  }  /* Move the entry up/down in directory. */  if (subm == 5) {	wlocate(w, position_dialing_directory, w->ys - 1);	wprintf(w, "%*.*s", tagmvlen,tagmvlen, move_exit);	cur = move_entry (w, d, cur, &top);	if (cur != ocur)	  changed++;	ocur = cur;	wlocate(w, position_dialing_directory, w->ys - 1);	wprintf(w, "%*.*s", tagmvlen,tagmvlen, tag_exit);  }  /* Dial a number manually. */  if (subm == 6) {	s = input(_("Enter number"), manual);	if (s && *s) {  		if (changed) writedialdir();		wclose(w, 1);		wclose(dsub, 1);				strncpy(d_man->number, manual, sizeof(d_man->number));  		(void) dial(d_man, (struct dialent**)NULL);		if (P_SHOWSPD[0] == 'l')		  mode_status();  		return;	}  }  goto again;}

⌨️ 快捷键说明

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