redial.c

来自「通讯程序源码」· C语言 代码 · 共 101 行

C
101
字号
/* * The redial option (actually a misnomer, it's really a queuing system). * We expect a space-separated list of dialing directory entries (although * new users always try to put in a phone number).  A non-zero return code * means we're ready to dial. */#include <stdio.h>#include <curses.h>#include "config.h"#include "dial_dir.h"#include "misc.h"intredial(){	extern int fd;	WINDOW *rd_win, *newwin();	char *ans, *entry, *get_str(), *strchr(), *strtok(), ld_code, buf[256];	int i, oops, number, ret_code;	rd_win = newwin(6, 70, 5, 5);	mvwaddstr(rd_win, 4, 23, "(<CR> for previous numbers)");	mvwaddstr(rd_win, 2, 4, "Directory Entry Number(s): ");	box(rd_win, VERT, HORZ);	mvwattrstr(rd_win, 0, 3, A_BOLD, " Redial Queue ");	wmove(rd_win, 2, 31);	wrefresh(rd_win);					/* get the string of numbers */	ret_code = 0;	while ((ans = get_str(rd_win, 35, "0123456789+-@# ", "")) != NULL) {		oops = 0;		if (*ans == '\0') {					/* use previous queue */			if (dir->q_num[0] != -1) {				ret_code++;				break;			}					/* there is no previous queue */			beep();			mvwattrstr(rd_win, 3, 4, A_BOLD, "No previous numbers");			wrefresh(rd_win);			wait_key(rd_win, 3);			clear_line(rd_win, 3, 4, TRUE);			wmove(rd_win, 2, 31);			wrefresh(rd_win);			continue;		}					/* parse the queue values */		entry = strtok(ans, " \t");		for (i=0; i<NUM_QUEUE; i++) {			if (entry == NULL) {				dir->q_num[i] = -1;				continue;			}					/* is there a LD code? */			ld_code = '\0';			if (strchr("+-@#", *entry)) {				ld_code = *entry;				entry++;			}			/*			 * Zero is valid here, because it means use			 * the current entry information.			 */			number = atoi(entry);			if (number > NUM_DIR || *dir->number[number] == '\0') {				beep();				sprintf(buf, "Invalid or empty directory entry number %d", number);				mvwattrstr(rd_win, 3, 14, A_BOLD, buf);				wrefresh(rd_win);				wait_key(rd_win, 3);				clear_line(rd_win, 3, 4, TRUE);				clear_line(rd_win, 2, 31, TRUE);				wrefresh(rd_win);				oops++;				break;			}					/* store the number in the queue */			dir->q_ld[i] = ld_code;			dir->q_num[i] = number;			entry = strtok((char *) NULL, " \t");		}		if (oops) {			dir->q_num[0] = -1;			continue;		}		ret_code++;		break;	}	if (fd == -1) {		werase(rd_win);		wrefresh(rd_win);	}	delwin(rd_win);	return(ret_code);}

⌨️ 快捷键说明

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