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

📄 new_curse.c

📁 aee是一种易使用的文本编辑器。你可以不用说明书来使用它。它提供终端接口和本地的X-windows接口。它的特性包括即弹的菜单
💻 C
📖 第 1 页 / 共 5 页
字号:
void Key_Get()		/* create linked list with all key sequences obtained from terminal database	*/{	int Counter;	int Klen;	int key_def;	struct KEY_STACK *Spoint;	Max_Key_len = 0;	Counter = 0;	key_def = kb__;	while (key_def <= kf63__)	{		if (key_def == ke__)			key_def = K1__;		else if (key_def == (K5__ + 1))			key_def = kcbt__;		else if (key_def == (kcbt__ + 1))			key_def = kbeg__;		else if (key_def == (kUND__ + 1))			key_def = kf11__;		if (String_table[key_def] != NULL)		{			if (KEY_TOS == NULL)				Spoint = KEY_TOS = (struct KEY_STACK *) malloc(sizeof(struct KEY_STACK));			else			{				Spoint = KEY_TOS;				while (Spoint->next != NULL)					Spoint = Spoint->next;				Spoint->next = (struct KEY_STACK *) malloc(sizeof(struct KEY_STACK));				Spoint = Spoint->next;			}			Spoint->next = NULL;			Spoint->element = (struct KEYS *) malloc(sizeof(struct KEYS));			Spoint->element->string = String_table[key_def];			Spoint->element->length = strlen(String_table[key_def]);			Spoint->element->value = Key_vals[Counter];			Klen = strlen(Spoint->element->string);			if (Klen > Max_Key_len)				Max_Key_len = Klen;			/*			 |  Some terminal types accept keystrokes of the form			 |  \E[A and \EOA, substituting '[' for 'O'.  Make a 			 |  duplicate of such key strings (since the 			 |  database will only have one version) so new_curse 			 |  can understand both.			 */			if ((Spoint->element->length > 1) && 			    ((String_table[key_def][1] == '[') || 			     (String_table[key_def][1] == 'O')))			{				Spoint->next = (struct KEY_STACK *) malloc(sizeof(struct KEY_STACK));				Spoint = Spoint->next;				Spoint->next = NULL;				Spoint->element = (struct KEYS *) malloc(sizeof(struct KEYS));				Spoint->element->length = strlen(String_table[key_def]);				Spoint->element->string = malloc(Spoint->element->length + 1);				strcpy(Spoint->element->string, String_table[key_def]);				Spoint->element->value = Key_vals[Counter];				Klen = strlen(Spoint->element->string);				if (Klen > Max_Key_len)					Max_Key_len = Klen;							if (String_table[key_def][1] == '[')					Spoint->element->string[1] = 'O';				else					Spoint->element->string[1] = '[';			}		}		key_def++;		Counter++;	}}/* |	insert information about keys for a vt100 terminal */voidkeys_vt100(){	int counter;	int Klen;	struct KEY_STACK *Spoint;	Spoint = KEY_TOS;	while (Spoint->next != NULL)		Spoint = Spoint->next;	for (counter = 0; vt100[counter].length != 0; counter++)	{		Spoint->next = (struct KEY_STACK *) malloc(sizeof(struct KEY_STACK));		Spoint = Spoint->next;		Spoint->next = NULL;		Spoint->element = &vt100[counter];		Klen = strlen(Spoint->element->string);		if (Klen > Max_Key_len)			Max_Key_len = Klen;	}}#ifdef CAPchar *String_Get(param)		/* read the string */char *param;{	char *String;	char *Temp;	int Counter;	if (param == NULL)	{		while (*TERM_data_ptr != '=')			TERM_data_ptr++;		Temp = ++TERM_data_ptr;		Counter = 1;		while ((*Temp != ':') && (*Temp != (char)NULL))		{			Counter++;			Temp++;		}		if (Counter == 1)	/* no data */			return(NULL);		String = Temp = malloc(Counter);		while ((*TERM_data_ptr != ':') && (*TERM_data_ptr != (char)NULL))		{			if (*TERM_data_ptr == '\\')			{				TERM_data_ptr++;				if (*TERM_data_ptr == 'n')					*Temp = '\n';				else if (*TERM_data_ptr == 't')					*Temp = '\t';				else if (*TERM_data_ptr == 'b')					*Temp = '\b';				else if (*TERM_data_ptr == 'r')					*Temp = '\r';				else if (*TERM_data_ptr == 'f')					*Temp = '\f';				else if ((*TERM_data_ptr == 'e') || (*TERM_data_ptr == 'E'))					*Temp = '\033';		/* escape */				else if (*TERM_data_ptr == '\\')					*Temp = '\\';				else if (*TERM_data_ptr == '\'')					*Temp = '\'';				else if ((*TERM_data_ptr >= '0') && (*TERM_data_ptr <= '9'))				{					Counter = 0;					while ((*TERM_data_ptr >= '0') && (*TERM_data_ptr <= '9'))					{						Counter = (8 * Counter) + (*TERM_data_ptr - '0');						TERM_data_ptr++;  /* ? */					}					*Temp = Counter;					TERM_data_ptr--;				}				TERM_data_ptr++;				Temp++;			}			else if (*TERM_data_ptr == '^')			{				TERM_data_ptr++;				if ((*TERM_data_ptr >= '@') && (*TERM_data_ptr <= '_'))					*Temp = *TERM_data_ptr - '@';				else if (*TERM_data_ptr == '?')					*Temp = 127;				TERM_data_ptr++;				Temp++;			}			else				*Temp++ = *TERM_data_ptr++;		}		*Temp = (char)NULL;		param = String;	}	else	{		while ((*TERM_data_ptr != (char)NULL) && (*TERM_data_ptr != ':'))			TERM_data_ptr++;	}	return(param);}int tc_Get_int(param)		/* read the integer			*/int param;{	int Itemp;	if (param == 0)	{		while ((*TERM_data_ptr != (char)NULL) && (*TERM_data_ptr != '#'))			TERM_data_ptr++;		TERM_data_ptr++;		Itemp = AtoI();		param = Itemp;	}	else	{		while (*TERM_data_ptr != ':')			TERM_data_ptr++;	}	return(param);}void Find_term()		/* find terminal description in termcap file	*/{	char *Name;	char *Ftemp;	Ftemp = Name = malloc(strlen(TERMINAL_TYPE + 1) + 1);	strcpy(Name, TERMINAL_TYPE);	while (*Ftemp != (char)NULL)		Ftemp++;	*Ftemp++ = '|';	*Ftemp = (char)NULL;	CFOUND = FALSE;	Data_Line_len = strlen(TERMINAL_TYPE) + 1;	while ((!CFOUND) && ((TERM_data_ptr=fgets(Data_Line, 512, TFP)) != NULL))	{		if ((*TERM_data_ptr != ' ') && (*TERM_data_ptr != '\t') && (*TERM_data_ptr != '#'))		{			while ((!CFOUND) && (*TERM_data_ptr != (char)NULL))			{				CFOUND = !strncmp(TERM_data_ptr, Name, Data_Line_len);				while ((*TERM_data_ptr != (char)NULL) && (*TERM_data_ptr != '|') && (*TERM_data_ptr != '#') && (*TERM_data_ptr != ':'))					TERM_data_ptr++;				if (*TERM_data_ptr == '|')					TERM_data_ptr++;				else if (!CFOUND)					*TERM_data_ptr = (char)NULL;			}		}	}	if (!CFOUND)	{		printf("terminal type %s not found\n", TERMINAL_TYPE);		exit(0);	}}void CAP_PARSE()		/* parse off the data in the termcap data file	*/{	int offset;	int found;	do	{		while (*TERM_data_ptr != (char)NULL)		{			for (found = FALSE, offset = 0; (!found) && (offset < 26); offset++)			{				if (!strncmp(TERM_data_ptr, Boolean_names[offset], 2))				{					found = TRUE;					Booleans[offset] = TRUE;				}			}			if (!found)			{				for (found = FALSE, offset = 0; (!found) && (offset < lw__); offset++)				{					if (!strncmp(TERM_data_ptr, Number_names[offset], 3))					{						found = TRUE;						Numbers[offset] = tc_Get_int(Numbers[offset]);					}				}			}			if (!found)			{				for (found = FALSE, offset = 0; (!found) && (offset < smgr__); offset++)				{					if (!strncmp(TERM_data_ptr, String_names[offset], 3))					{						found = TRUE;						String_table[offset] = String_Get(String_table[offset]);					}				}			}			if (!strncmp(TERM_data_ptr, "tc=", 3))				tc_ = String_Get(NULL);			while ((*TERM_data_ptr != ':') && (*TERM_data_ptr != (char)NULL))				TERM_data_ptr++;			if (*TERM_data_ptr == ':')				TERM_data_ptr++;		}	} while (((TERM_data_ptr = fgets(Data_Line, 512, TFP)) != NULL) && ((*TERM_data_ptr == ' ') || (*TERM_data_ptr == '\t')));	if (tc_ != NULL)	{		TERMINAL_TYPE = tc_;		rewind(TFP);		Find_term();		free(tc_);		tc_ = NULL;		CAP_PARSE();	}	else		fclose(TFP);}#endif		/* ifdef CAP	*/struct _line *Screenalloc(columns)int columns;{	int i;	struct _line *tmp;	tmp = (struct _line *) malloc(sizeof (struct _line));	tmp->row = malloc(columns + 1);	tmp->attributes = malloc(columns + 1);	tmp->prev_screen = NULL;	tmp->next_screen = NULL;	for (i = 0; i < columns; i++)	{		tmp->row[i] = ' ';		tmp->attributes[i] = (char) NULL;	}	tmp->scroll = tmp->changed = FALSE;	tmp->row[0] = (char) NULL;	tmp->attributes[0] = (char) NULL;	tmp->row[columns] = (char) NULL;	tmp->attributes[columns] = (char) NULL;	tmp->last_char = 0;	return(tmp);}WINDOW *newwin(lines, cols, start_l, start_c)int lines, cols;	/* number of lines and columns to be in window	*/int start_l, start_c;	/* starting line and column to be inwindow	*/{	WINDOW *Ntemp;	struct _line *temp_screen;	int i;	Ntemp = (WINDOW *) malloc(sizeof(WINDOW));	Ntemp->SR = start_l;	Ntemp->SC = start_c;	Ntemp->Num_lines = lines;	Ntemp->Num_cols = cols;	Ntemp->LX = 0;	Ntemp->LY = 0;	Ntemp->scroll_down = Ntemp->scroll_up = 0;	Ntemp->SCROLL_CLEAR = FALSE;	Ntemp->Attrib = FALSE;	Ntemp->first_line = temp_screen = Screenalloc(cols);	Ntemp->first_line->number = 0;	Ntemp->line_array = (struct _line **) malloc(LINES * sizeof(struct _line *));		Ntemp->line_array[0] = Ntemp->first_line;	for (i = 1; i < lines; i++)	{		temp_screen->next_screen = Screenalloc(cols);		temp_screen->next_screen->number = i;		temp_screen->next_screen->prev_screen = temp_screen;		temp_screen = temp_screen->next_screen;		Ntemp->line_array[i] = temp_screen;	}	Ntemp->first_line->prev_screen = NULL;	temp_screen->next_screen = NULL;	return(Ntemp);}#ifdef CAPvoid Cap_Out(string, p_list, place)	/* interpret the output string if necessary */char *string;int p_list[];			/* stack of values	*/int place;			/* place keeper of top of stack	*/{	char *Otemp;		/* temporary string pointer to parse output */	int delay;	int p1, p2, temp;	float chars;	if (string == NULL)		return;	if (p_list != NULL)	{		p1 = p_list[--place];		p2 = p_list[--place];	}	delay = 0;	Otemp = string;	if ((*Otemp >= '0') && (*Otemp <= '9'))	{		delay = atoi(Otemp);		while ((*Otemp >= '0') && (*Otemp <= '9'))			Otemp++;		if (*Otemp == '*')			Otemp++;	}	while (*Otemp != (char)NULL)	{		if (*Otemp == '%')		{			Otemp++;			if ((*Otemp == 'd') || (*Otemp == '2') || (*Otemp == '3') || (*Otemp == '.') || (*Otemp == '+')) 			{				if (*Otemp == 'd')				 	printf("%d", p1);				else if (*Otemp == '2')					printf("%02d", p1);				else if (*Otemp == '3')					printf("%03d", p1);				else if (*Otemp == '+')				{					Otemp++;					p1 += *Otemp;					putchar(p1);				}				else if (*Otemp == '.')					putchar(p1);				p1 = p2;				p2 = 0;			}			else if (*Otemp == '>')			{				Otemp++;				if (p1 > *Otemp)				{					Otemp++;					p1 += *Otemp;				}				else					Otemp++;			}			else if (*Otemp == 'r')			{				temp = p1;				p1 = p2;				p2 = temp;			}			else if (*Otemp == 'i')			{				p1++;				p2++;			}			else if (*Otemp == '%')				putchar(*Otemp);			else if (*Otemp == 'n')			{				p1 ^= 0140;				p2 ^= 0140;			}			else if (*Otemp == 'B')			{				p1 = (16 * (p1/10)) + (p1 % 10);				p2 = (16 * (p2/10)) + (p2 % 10);			}			else if (*Otemp == 'D')			{				p1 = (p1 - 2 * (p1 % 16));				p2 = (p2 - 2 * (p2 % 16));			}		}		else			putchar (*Otemp);		Otemp++;	}	if (delay != 0)	{		chars = delay * chars_per_millisecond;		delay = chars;		if ((chars - delay) > 0.0)			delay++;		for (; delay > 0; delay--)			putchar(*String_table[pc__]);	}	fflush(stdout);}#else	char *Otemp;		/* temporary string pointer to parse output */	float chars;	int p[10];	int variable[27];int Operation(Temp_Stack, place)	/* handle conditional operations	*/int Temp_Stack[];int place;{	int temp;	if (*Otemp == 'd')	{		Otemp++;		temp = Temp_Stack[--place];	 	printf("%d", temp);	}	else if (!strncmp(Otemp, "2d", 2))	{		temp = Temp_Stack[--place];		printf("%2d", temp);		Otemp++;		Otemp++;	}	else if (!strncmp(Otemp, "3d", 2))	{		temp = Temp_Stack[--place];		printf("%0d", temp);		Otemp++;		Otemp++;	}	else if (!strncmp(Otemp, "02d", 3))	{		temp = Temp_Stack[--place];		printf("%02d", temp);		Otemp++;		Otemp++;		Otemp++;	}	else if (!strncmp(Otemp, "03d", 3))	{		temp = Temp_Stack[--place];		printf("%03d", temp);		Otemp++;		Otemp++;		Otemp++;	}	else if (*Otemp == '+')	{		Otemp++;		temp = Temp_Stack[--place];		temp += Temp_Stack[--place];		Temp_Stack[place++] = temp;	}	else if (*Otemp == '-')	{		Otemp++;		temp = Temp_Stack[--place];		temp -= Temp_Stack[--place];		Temp_Stack[place++] = temp;	}	else if (*Otemp == '*')	{		Otemp++;		temp = Temp_Stack[--place];		temp *= Temp_Stack[--place];		Temp_Stack[place++] = temp;	}	else if (*Otemp == '/')	{		Otemp++;		temp = Temp_Stack[--place];		temp /= Temp_Stack[--place];		Temp_Stack[place++] = temp;	}	else if (*Otemp == 'm')	{		Otemp++;		temp = Temp_Stack[--place];		temp %= Temp_Stack[--place];		Temp_Stack[place++] = temp;	}	else if (*Otemp == '&')	{		Otemp++;		temp = Temp_Stack[--place];		temp &= Temp_Stack[--place];		Temp_Stack[place++] = temp;	}	else if (*Otemp == '|')	{		Otemp++;		temp = Temp_Stack[--place];

⌨️ 快捷键说明

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