📄 dial.c
字号:
/* If the list order changed, redraw the directory window */ if (cur != ocur) { /* First remove cursor bar from the old position */ mc_wcurbar(dialw, ocur + 1 - *top, XA_NORMAL | stdattr); if (cur < *top) (*top)--; else if (cur - *top > dialw->ys - 3) (*top)++; prdir(dialw, *top, *top); mc_wcurbar(dialw, cur + 1 - *top, XA_REVERSE | stdattr); ocur = cur; } /* end redraw condition */ } /* end loop */ return cur;}/* Little menu. */static const char *d_yesno[] = { N_(" Yes "), N_(" No "), NULL };/* Try to dial an entry. */static void dial_entry(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, -1, -1, d->flags & FL_ECHO, -1, -1); local_echo = d->flags & FL_ECHO; 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(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(void){ 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 const char *tag_exit = N_("( Escape to exit, Space to tag )"), *move_exit = N_(" Move entry up/down, Escape to exit"); unsigned int tagmvlen = 0; size_t i; int position_dialing_directory = ((COLS / 2) + 32 - DIALOPTS * DIAL_WIDTH) / 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 = mc_wopen(x1 - 1, LINES - 3, x2 + 1, LINES - 3, BNONE, XA_REVERSE | stdattr, mfcolor, mbcolor, 0, 0, 1); w = mc_wopen(x1, 2, x2, LINES - 6, BSINGLE, stdattr, mfcolor, mbcolor, 0, 0, 1); mc_wcursor(w, CNONE); mc_wtitle(w, TMID, _("Dialing Directory")); mc_wputs(w, _(" Name Number Last on Times Script\n")); for (i = 0; i < DIALOPTS; i++) { const char *str, *c; size_t j; str = _(what[i]); c = str; for (j = 0; j < DIAL_WIDTH - 1 && *c != 0; j++) { wchar_t wc; c += one_mbtowc(&wc, c, MB_LEN_MAX); } what_lens[i] = c - str; j = DIAL_WIDTH - j; /* Characters left for padding */ what_padding[i][1] = j / 2; /* Rounding down */ what_padding[i][0] = j - what_padding[i][1]; /* >= 1 */ } mc_wlocate(dsub, position_dialing_directory, 0); for (i = 0; i < DIALOPTS; i++) horiz_draw(i); mc_wsetregion(w, 1, w->ys - 1); w->doscroll = 0; prdir(w, top, top); mc_wlocate(w, position_dialing_directory, w->ys - 1); mc_wprintf(w, "%*.*s", tagmvlen,tagmvlen, tag_exit); dhili(position_dialing_directory, subm); dirflush = 1; mc_wredraw(dsub, 1);again: mc_wcurbar(w, cur + 1 - top, XA_REVERSE | stdattr); if (first) { mc_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 ' ': /* Tag. */ mc_wlocate(w, 4, cur + 1 - top); d->flags ^= FL_TAG; mc_wsetattr(w, XA_REVERSE | stdattr); mc_wprintf(w, "%c", d->flags & FL_TAG ? '>' : ' '); mc_wsetattr(w, XA_NORMAL | stdattr); cur += (cur < nrents - 1); break; case '\033': case '\r': case '\n': selected: quit = (subm == 5 ? 2 : 1); break; default: for (i = 0; i < DIALOPTS; i++) { if (strchr(_(what[i]), toupper(c)) != NULL) { subm = i; goto selected; } } break; } /* Decide if we have to delete the cursor bar */ if (cur != ocur || quit == 1) mc_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) mc_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(); mc_wclose(w, 1); mc_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) { mc_wclose(w, 1); mc_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) { mc_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) { mc_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++; mc_wlocate(w, 0, cur + 1 - top); mc_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) { mc_wlocate(w, 0, nrents - top + 1); mc_wclreol(w); } ocur = cur; } /* Move the entry up/down in directory. */ if (subm == 5) { mc_wlocate(w, position_dialing_directory, w->ys - 1); mc_wprintf(w, "%*.*s", tagmvlen,tagmvlen, move_exit); cur = move_entry (w, d, cur, &top); if (cur != ocur) changed++; ocur = cur; mc_wlocate(w, position_dialing_directory, w->ys - 1); mc_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(); mc_wclose(w, 1); mc_wclose(dsub, 1); strncpy(d_man->number, manual, sizeof(d_man->number)); 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 + -