📄 dial.c
字号:
nrents = 1; fclose(fp); return(0); } for(f = 1; f <= nrents; f++) { if ((d = (struct dialent *)malloc(sizeof (struct dialent))) == (struct dialent *)0) { if(f == 1) dialents = mkstdent(); else prev->next = (struct dialent *)0; werror("Out of memory while reading dialing directory"); fclose(fp); return(-1); } switch(dial_ver.version) { case 0: v0_read(fp, d); break; case 1: v1_read(fp, d); break; case 2: v2_read(fp, d); break; case 3: v3_read(fp, d); break; } /* MINIX terminal type is obsolete */ if (d->term == 2) d->term = 1; if (prev != (struct dialent *)0) prev->next = d; else dialents = d; prev = d; } d->next = (struct dialent *)0; fclose(fp); return(0);}/* * Write the new $HOME/.dialdir */static void writedialdir(){ struct dialent *d; char dfile[256]; FILE *fp; struct dver dial_ver; char oldfl; int omask; /* Make no sense if access denied */ if (dendd) return; sprintf(dfile, "%s/.dialdir", homedir); omask = umask(077); if ((fp = sfopen(dfile, "w")) == (FILE *)0) { (void)umask(omask); werror("Can't write to ~/.dialdir"); dendd = 1; return; } (void)umask(omask); d = dialents; /* Set up version info. */ dial_ver.magic = DIALMAGIC; dial_ver.version = 3; dial_ver.size = sizeof(struct dialent); fwrite(&dial_ver, sizeof(dial_ver), (size_t)1, fp); /* Write dialing directory */ while(d) { oldfl = d->flags; d->flags &= FL_SAVE; if (fwrite(d, sizeof(struct dialent), (size_t)1, fp) != 1) { werror("Error writing ~/.dialdir!"); fclose(fp); return; } d->flags = oldfl; d = d->next; } fclose(fp);}/* * Get entry "no" in list. */static struct dialent *getno(no)int no;{ struct dialent *d; d = dialents; if (no >= nrents) return((struct dialent *)NULL); while(no--) d = d->next; return(d);}/* Note: Minix does not exist anymore. */static char *te[] = { "VT102", "MINIX", "ANSI " };/* * Edit an entry. */static void dedit(d)struct dialent *d;{ WIN *w; int c; w = wopen(5, 5, 75, 17, BDOUBLE, stdattr, mfcolor, mbcolor, 0, 0, 1); wprintf(w, " A - Name : %s\n", d->name); wprintf(w, " B - Number : %s\n", d->number); wprintf(w, " C - Dial string # : %d\n", d->dialtype + 1); wprintf(w, " D - Local echo : %s\n", yesno(d->flags & FL_ECHO)); wprintf(w, " E - Script : %s\n", d->script); wprintf(w, " F - Username : %s\n", d->username); wprintf(w, " G - Password : %s\n", d->password); wprintf(w, " H - Terminal Emulation : %s\n", te[d->term - 1]); wprintf(w, " I - Backspace key sends : %s\n", d->flags & FL_DEL ? "Delete" : "Backspace"); wprintf(w, " J - Linewrap : %s\n", d->flags & FL_WRAP ? "On" : "Off"); wprintf(w, " K - Line Settings : %s %s%s1", d->baud, d->bits, d->parity); wlocate(w, 4, 13); wputs(w, "Change which setting? "); wredraw(w, 1); while(1) { wlocate(w, 26, 13); c = wxgetch(); if (c >= 'a') c -= 32; switch(c) { case '\033': case '\r': case '\n': wclose(w, 1); return; case 'A': wlocate(w, 28, 0); (void) wgets(w, d->name, 31, 32); break; case 'B': wlocate(w, 28, 1); (void) wgets(w, d->number, 31, 32); break; case 'C': d->dialtype = (d->dialtype + 1) % 3; wlocate(w, 28, 2); wprintf(w, "%d", d->dialtype + 1); wflush(); break; case 'D': d->flags ^= FL_ECHO; wlocate(w, 28, 3); wprintf(w, "%s", yesno(d->flags & FL_ECHO)); wflush(); break; case 'E': wlocate(w, 28, 4); (void) wgets(w, d->script, 31, 32); break; case 'F': wlocate(w, 28, 5); (void) wgets(w, d->username, 31, 32); break; case 'G': wlocate(w, 28, 6); (void) wgets(w, d->password, 31, 32); break; case 'H': d->term = (d->term % 3) + 1; /* MINIX == 2 is obsolete. */ if (d->term == 2) d->term = 3; wlocate(w, 28, 7); wputs(w, te[d->term - 1]); /* Also set backspace key. */ if (d->term == ANSI) { d->flags &= ~FL_DEL; d->flags |= FL_WRAP; } else { d->flags &= ~FL_WRAP; d->flags |= FL_DEL; } wlocate(w, 28, 8); wputs(w, d->flags & FL_DEL ? "Delete " : "Backspace"); wlocate(w, 28, 9); wputs(w, d->flags & FL_WRAP ? "On " : "Off"); break; case 'I': d->flags ^= FL_DEL; wlocate(w, 28, 8); wputs(w, d->flags & FL_DEL ? "Delete " : "Backspace"); break; case 'J': d->flags ^= FL_WRAP; wlocate(w, 28, 9); wputs(w, d->flags & FL_WRAP ? "On " : "Off"); break; case 'K': get_bbp(d->baud, d->bits, d->parity, 1); wlocate(w, 28, 10); wprintf(w, "%s %s%s1 ", d->baud, d->bits, d->parity); break; default: break; } }}static WIN *dsub;static char *what = " Dial Find Add Edit Remove Manual ";static int dprev;/* * Highlight a choice in the horizontal menu. */static void dhili(k)int k;{ if (k == dprev) return; if (dprev >= 0) { wlocate(dsub, 14 + 8*dprev, 0); if (!useattr) { wputs(dsub, " "); } else { wsetattr(dsub, XA_REVERSE | stdattr); wprintf(dsub, "%8.8s", what + 8*dprev); } } dprev = k; wlocate(dsub, 14 + 8*k, 0); if (!useattr) { wputs(dsub, ">"); } else { wsetattr(dsub, stdattr); wprintf(dsub, "%8.8s", what + 8*k); }}static char *fmt = "\r %2d %c %-16.16s %-16.16s%5s %s%s1 %-6.6s %-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) ? 16 : ' ', d->name, d->number, d->baud, d->bits, d->parity, te[d->term - 1], d->script); } dirflush = 1; wflush();}/* Little menu. */static char *d_yesno[] = { " Yes ", " No ", CNULL };/* Try to dial an entry. */static void dial_entry(d)struct dialent *d;{ int nb; /* 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); port_init(); mode_status(); } newtype = d->term; vt_set(-1, d->flags & FL_WRAP, NULL, -1, -1, d->flags & FL_ECHO, -1);#ifdef _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)) < 0) return; /* Did we detect a baudrate , and can we set it? */ if (P_MAUTOBAUD[0] == 'Y' && nb) { sprintf(P_BAUDRATE, "%d", nb); port_init(); mode_status(); } /* 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; return;}/* * Dial an entry from the dialing directory; this * is used for the "-d" command line flag. */void dialone(entry)char *entry;{ int num; struct dialent *d; char buf[128]; /* Find entry. */ if ((num = atoi(entry)) != 0) d = getno(num - 1); else for(d = dialents; d; d = d->next) if (strstr(d->name, entry)) break; /* Not found. */ if (d == NULL) { sprintf(buf, "Entry \"%s\" not found. Enter dialdir?", entry); if (ask(buf, d_yesno) != 0) return; dialdir(); return; } /* Dial the number! */ sleep(1); dial_entry(d);}/* * 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[64]; static char manual[64]; int changed = 0; dprev = -1; dname[0] = 0; /* 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 Line Format Terminal Script\n"); wlocate(dsub, 14, 0); wputs(dsub, what); wsetregion(w, 1, w->ys - 1); w->doscroll = 0; prdir(w, top, top); wlocate(w, 14, w->ys - 1); wputs(w, "( Escape to exit, Space to tag )"); dhili(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 = 5; break; case K_RT: case 'l': subm = (subm + 1) % 6; 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 'm': /* Manual. */ subm = 5; 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 ? 16 : ' '); wsetattr(w, XA_NORMAL | stdattr); cur += (cur < nrents - 1); break; case '\033': case '\r': case '\n': quit = 1; break; default: break; } /* Decide if we have to delete the cursor bar */ if (cur != ocur || quit) 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(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)) { for(d1 = dialents; d1; d1 = d1->next) if (d1->flags & FL_TAG) { d = d1; break; } } 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->baud, d->bits, d->parity, te[d->term - 1], 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; } /* Dial a number manually. */ if (subm == 5) { s = input("Enter number", manual); if (s && *s) { if (changed) writedialdir(); wclose(w, 1); wclose(dsub, 1); strcpy(d_man->number, manual); (void) dial(d_man); return; } } goto again;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -