txt_ctl.h

来自「AMLOGIC DPF source code」· C头文件 代码 · 共 280 行

H
280
字号
#ifndef __TXT_CTL_H_
#define __TXT_CTL_H_

#ifdef AVOS
	#define TXT_FOR_AVOS
#else
	#define TXT_FOR_WINDOWS
#endif

#define USE_REAL_PIXEL


#define ESC_CHAR_HT						0x09
#define ESC_CHAR_LF						0x0A
#define ESC_CHAR_CR						0x0D

#define CN_CHAR_START					0x81

#define TXT_MAX_ROW						26
#define TXT_MAX_COL						80
#define	TXT_TRIM_SPACE_SIZE				20
#define TXT_TRIM_RETURN_SIZE			10
#define TXT_TAB_SIZE					4

#define TXT_PAGE_SIZE					(TXT_MAX_ROW*(TXT_MAX_COL+1))
#define TXT_PAGE_NUMS					8
#define TXT_PAGE_MIN					2
#define	TXT_BUFFER_SIZE					(TXT_PAGE_SIZE*TXT_PAGE_NUMS)

#if defined TXT_FOR_WINDOWS
	#define FILE_HANDLE					HANDLE
	#define INVALID_FILE_HANDLE			INVALID_HANDLE_VALUE

	#define txt_malloc(x)				new BYTE[x]
	#define txt_realloc					realloc
	#define txt_free(x)					delete[] x
#elif defined TXT_FOR_AVOS
	#include "includes.h"
	#include "aw_windows.h"

	#define FILE_HANDLE					int
	#define INVALID_FILE_HANDLE			-1

	#define txt_malloc					AVMem_malloc
	#define txt_realloc					AVMem_realloc
	#define txt_free					AVMem_free

	//#define NULL						0
#endif

typedef struct _page_link
{
	unsigned long file_offset;
	unsigned long data_len;
	unsigned long lines_cnt;
	unsigned long lines_start;

	struct _page_link *prev;
	struct _page_link *next;
} page_link_t;

typedef struct _line_link
{
	unsigned long file_offset;
	unsigned long data_len;
	unsigned long line_index;
	char *line_text;

	struct _line_link *prev;
	struct _line_link *next;
} line_link_t;

typedef struct _txt_contorl
{
	FILE_HANDLE hFile;

	unsigned long max_row;
	unsigned long max_col;
	unsigned long trim_space_size;
	unsigned long trim_return_size;
	unsigned long tab_size;
	unsigned long buf_size;
	unsigned long page_size;

	int disable_set;

	unsigned long file_pointer;
	unsigned long file_size;

	char **show_lines;

	page_link_t *page_head;
	line_link_t *line_head;
	page_link_t *cur_page;
	line_link_t *cur_line;
	unsigned long total_lines;
} txt_contorl_t;


/****************************************************************************************************************
 * Name		: txt_open_file																						*
 * Function	: open a txt file for show																			*
 * Input	: txt_ctl = poiniter to a txt_contorl_t struct													    *
 * Input	: filename = the text file name need to be opened													*
			: max_row = how many rows in a page				 													*
			: max_clo = how many columns in a page			 													*
 * Output	: none																								*
 * return	: 0 = succeed																						*
 *            -1 = failed																						*
 ****************************************************************************************************************/
int txt_open_file(txt_contorl_t *txt_ctl, char *filename, unsigned long max_row, unsigned long max_col);

/****************************************************************************************************************
 * Name		: txt_close_file																					*
 * Function	: close the txt file and release memory																*
 * Input	: none																								*
 * Output	: none																								*
 * return	: 0 = succeed																						*
 ****************************************************************************************************************/
void txt_close_file(txt_contorl_t *txt_ctl);

/****************************************************************************************************************
 * Name		: txt_show																							*
 * Function	: first time to show a text page																	*
 * Input	: none																								*
 * Output	: none																								*
 * return	: 0 = nothing to show again																			*
 *            char** = a point to a string array																*
 ****************************************************************************************************************/
char **txt_show(txt_contorl_t *txt_ctl);

/****************************************************************************************************************
 * Name		: txt_line_up																						*
 * Function	: show text from the previous line																	*
 * Input	: none																								*
 * Output	: none																								*
 * return	: 0 = nothing to show again																			*
 *            char** = a point to a string array																*
 ****************************************************************************************************************/
char **txt_line_up(txt_contorl_t *txt_ctl);

/****************************************************************************************************************
 * Name		: txt_line_down																						*
 * Function	: show text from the next line																		*
 * Input	: none																								*
 * Output	: none																								*
 * return	: 0 = nothing to show again																			*
 *            char** = a point to a string array																*
 ****************************************************************************************************************/
char **txt_line_down(txt_contorl_t *txt_ctl);

/****************************************************************************************************************
 * Name		: txt_page_up																						*
 * Function	: show text from the previous page																	*
 * Input	: none																								*
 * Output	: none																								*
 * return	: 0 = nothing to show again																			*
 *            char** = a point to a string array																*
 ****************************************************************************************************************/
char **txt_page_up(txt_contorl_t *txt_ctl);

/****************************************************************************************************************
 * Name		: txt_page_down																						*
 * Function	: show text from the next page																		*
 * Input	: none																								*
 * Output	: none																								*
 * return	: 0 = nothing to show again																			*
 *            char** = a point to a string array																*
 ****************************************************************************************************************/
char **txt_page_down(txt_contorl_t *txt_ctl);

/****************************************************************************************************************
 * Name		: txt_get_total_lines																				*
 * Function	: get the number of total lines																		*
 * Input	: none																								*
 * Output	: none																								*
 * return	: number of total lines																				*
 ****************************************************************************************************************/
#ifdef TXT_FOR_AVOS
unsigned long txt_get_total_lines(txt_contorl_t *txt_ctl, PAPPTASKARG app);
#else
unsigned long txt_get_total_lines(txt_contorl_t *txt_ctl);
#endif

/****************************************************************************************************************
 * Name		: txt_get_total_pages																				*
 * Function	: get the number of total pages																		*
 * Input	: txt_ctl = poiniter to a txt_contorl_t struct													    *
 * Output	: none																								*
 * return	: number of total pages																				*
 ****************************************************************************************************************/
#ifdef TXT_FOR_AVOS
unsigned long txt_get_total_pages(txt_contorl_t *txt_ctl, PAPPTASKARG app);
#else
unsigned long txt_get_total_pages(txt_contorl_t *txt_ctl);
#endif

/****************************************************************************************************************
 * Name		: txt_goto_line																						*
 * Function	: show text from the specified line	index															*
 * Input	: txt_ctl = poiniter to a txt_contorl_t struct													    *
 * Input	: line_index = line index number to jump, index value starts from 0									*
 * Output	: none																								*
 * return	: 0 = nothing to show again																			*
 *            char** = a point to a string array																*
 ****************************************************************************************************************/
char **txt_goto_line(txt_contorl_t *txt_ctl, unsigned long line_index);

/****************************************************************************************************************
 * Name		: txt_goto_page																						*
 * Function	: show text from the specified page index															*
 * Input	: txt_ctl = poiniter to a txt_contorl_t struct													    *
 * Input	: line_index = line index number to jump, index value starts from 0									*
 * Output	: none																								*
 * return	: 0 = nothing to show again																			*
 *            char** = a point to a string array																*
 ****************************************************************************************************************/
char **txt_goto_page(txt_contorl_t *txt_ctl, unsigned long page_index);

/****************************************************************************************************************
 * Name		: txt_get_current_line																				*
 * Function	: Get current start line number         															*
 * Input	: txt_ctl = poiniter to a txt_contorl_t struct													    *
 * Output	: none																								*
 * return	: Number of current start line ( from 1 ~ max lines )												*
 ****************************************************************************************************************/
unsigned long txt_get_current_line(txt_contorl_t *txt_ctl);

/****************************************************************************************************************
 * Name		: txt_get_current_page																				*
 * Function	: Get current page number         																	*
 * Input	: txt_ctl = poiniter to a txt_contorl_t struct													    *
 * Output	: none																								*
 * return	: Number of current page ( from 1 ~ max pages )														*
 ****************************************************************************************************************/
unsigned long txt_get_current_page(txt_contorl_t *txt_ctl);

/****************************************************************************************************************
 * Example to show a text file:																					*
 *																												*
 * txt_contorl_t *txt_ctl = malloc(sizeof(txt_contorl_t));														*																											*
 * int ret = txt_open_file(txt_ctl, "//mnt/c/example.txt", 20, 80);//page size = 20 * 80 = 20 lines * 80 columns*
 * if(!ret)																										*
 * {																											*
 *		//First time to show text																				*
 *		char **lines = txt_show();																				*
 *		if(lines)																								*
 *		{																										*
 *			while(*lines)																						*
 *				printf("%s\n", *lines++)																		*
 *		}																										*
 *																												*
 *		//Show next page																						*
 *		lines = txt_page_down();																				*
 *		if(lines)																								*
 *		{																										*
 *			while(*lines)																						*
 *				printf("%s\n", *lines++)																		*
 *		}																										*
 *																												*
 *		//Goto last page																						*
 *		unsigned long pages = txt_get_total_pages();															*
 *		if(pages)																								*
 *		{																										*
 *			lines = txt_goto_page(pages-1);																		*
 *			if(lines)																							*
 *			{																									*
 *				while(*lines)																					*
 *					printf("%s\n", *lines++)																	*
 *			}																									*
 *		}																										*
 *																												*
 *		//Operations finshied, close the text file																*
 *		txt_close_file();																						*
 *		free(txt_ctl);																				*
 *	}																											*
 *																												*
 ****************************************************************************************************************/
 
#endif	//__TXT_APP_H_

⌨️ 快捷键说明

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