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

📄 history.c

📁 motorola自己开发的针对coldfire 5272的Dbug bootloader程序
💻 C
字号:
/*
 * File:		history.c
 * Purpose:		dBUG command line history and recall
 *
 * Notes:		After much consideration, decided to use simple
 *				array and physical copy to move strings in the
 * 				history buffer rather than using linked lists.
 *				The code was much simpler, much less in size, and
 *				didn't need to waste space on pointers for the
 *				linked list.
 *
 * Author:		Eric DeVolder
 * Date
 *
 * Modifications:
 *
 */

#include "src/include/dbug.h"
#include "src/uif/uif.h"

/********************************************************************/

#ifndef MAX_HISTORY
#define MAX_HISTORY (5)
#endif

#define CTRL_U	0x15	/* command line previous */
#define CTRL_D	0x04	/* command line next */
#define CTRL_R	0x12	/* last command repeat */

typedef char HISTENT[UIF_MAX_LINE];

HISTENT
history[MAX_HISTORY];

/*******************************************************************/
void
history_init (void)
{
	int index;

	for (index = 0; index < MAX_HISTORY; ++index)
	{
		history[index][0] = '\0';
	}
}

/********************************************************************/
static int
history_down (int *curr_hist, char *line)
{
	*curr_hist -= 1;

	if (*curr_hist < 0)
	{
		*curr_hist = -1;
		line[0] = '\0';
		return 0;
	}

	strcpy(line, history[*curr_hist]);
	printf("%s",line);
	return strlen(line);
}

/********************************************************************/
static int
history_up (int *curr_hist, char *line)
{
	if (*curr_hist == -1)
	{
		*curr_hist = 0;
	}
	else
	{
		*curr_hist += 1;
		if (*curr_hist >= MAX_HISTORY)
		{
			*curr_hist = (MAX_HISTORY-1);
		}
	}

	strcpy(line, history[*curr_hist]);
	printf("%s",line);
	return strlen(line);
}

/********************************************************************/
static int
history_repeat (char *line)
{
	strcpy(line, history[0]);
	printf("%s",line);
	return strlen(line);
}

/********************************************************************/
static void
history_add (char *line)
{
	/*
	 * This routine is called after use has entered a line
	 */
	int index;

	/*
	 * Move all history line buffers down
	 */
	for (index = (MAX_HISTORY-1); index > 0; --index)
	{
		strcpy(history[index],history[index-1]);
	}

	/*
	 * Copy in the new one
	 */
	strcpy(history[0], line);
}

/********************************************************************/
char *
get_history_line (char *userline)
{
	char line[UIF_MAX_LINE];
	int pos, ch, i, curr_hist, repeat;

	curr_hist = -1;	/* invalid */

	repeat = FALSE;
	pos = 0;

	ch = (int)board_getchar();
	while (	(ch != 0x0D /* CR */) &&
			(ch != 0x0A /* LF/NL */) &&
			(pos < UIF_MAX_LINE))
	{
		switch (ch)
		{
			case 0x08:		/* Backspace */
			case 0x7F:		/* Delete */
				if (pos > 0)
				{
					pos -= 1;
					board_putchar(0x08);	/* backspace */
					board_putchar(' ');
					board_putchar(0x08);	/* backspace */
				}
				break;
			case CTRL_U:
			case CTRL_D:
			case CTRL_R:
				for (i = 0; i < pos; ++i)
				{
					board_putchar(0x08);	/* backspace */
					board_putchar(' ');
					board_putchar(0x08);	/* backspace */
				}
				if (ch == CTRL_U)
				{
					pos = history_up(&curr_hist,line);
					break;
				}
				if (ch == CTRL_D)
				{
					pos = history_down(&curr_hist,line);
					break;
				}
				if (ch == CTRL_R)
				{
					pos = history_repeat(line);
					repeat = TRUE;
				}
				break;
			default:
				if ((pos+1) < UIF_MAX_LINE)
				{
					/* only printable characters */
					if ((ch > 0x1f) && (ch < 0x80))
					{
						line[pos++] = (char)ch;
						board_putchar((char)ch);
					}
				}
				break;
		}

		if (repeat)
		{
			break;
		}
		ch = (int)board_getchar();
	}
	line[pos] = '\0';
	board_putchar(0x0D);	/* CR */
	board_putchar(0x0A);	/* LF */

	if ((strlen(line) != 0) && !repeat)
	{
		history_add(line);
	}
	strcpy(userline,line);

	return userline;
}

/********************************************************************/

⌨️ 快捷键说明

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