xcmd/inc/xcmd.h

274 lines
6.0 KiB
C
Raw Normal View History

2021-09-12 18:01:02 +08:00
#ifndef XCMD_H
#define XCMD_H
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
2021-09-13 20:10:34 +08:00
#include <stdarg.h>
2021-09-12 18:01:02 +08:00
typedef void(*cmd_func_t)(int argv, char* argc[]);
typedef int(*cmd_key_func_t)(void *data);
typedef enum
{
CTR_A = 1,
CTR_B = 2,
CTR_C = 3,
CTR_D = 4,
CTR_E = 5,
CTR_F = 6,
CTR_G = 7,
CTR_H = 8,
BACKSPACE = 8,
CTR_I = 9,
LF = 9,
TAB = 9,
CTR_J = 10,
CTR_K = 11,
CTR_L = 12,
CTR_M = 13,
CR = 13,
CTR_N = 14,
CTR_O = 15,
CTR_P = 16,
CTR_Q = 17,
CTR_R = 18,
CTR_S = 19,
CTR_T = 20,
CTR_U = 21,
CTR_V = 22,
CTR_W = 23,
CTR_X = 24,
CTR_Y = 25,
CTR_Z = 26,
ESC = 27,
FS = 28,
GS = 29,
RS = 30,
US = 31,
L_DELETE = 127,
UP = 0x00415B1B,
DW = 0x00425B1B,
RIGHT = 0x00435B1B,
LEFT = 0x00445B1B,
END = 0x00465B1B,
HOME = 0x00485B1B,
INSERT = 0x7E325B1B,
R_DELETE = 0x7E335B1B,
PGUP = 0x7E355B1B,
PGDW = 0x7E365B1B,
}XCMD_KEY_T;
typedef struct __cmd
{
char* name;
cmd_func_t func;
char* help;
struct __cmd *next;
}xcmd_t;
typedef struct __key
{
XCMD_KEY_T key;
cmd_key_func_t func;
struct __key *next;
}xcmd_key_t;
typedef struct __history
{
char *line;
struct __history *next;
struct __history *prev;
}xcmd_history_t;
typedef struct
{
struct
{
int (*get_c)(uint8_t*);
int (*put_c)(uint8_t);
}io;
struct
{
uint16_t len;
xcmd_t *next;
xcmd_t *tail;
}cmd_list;
struct
{
uint16_t len;
xcmd_key_t *next;
2021-09-14 18:11:49 +08:00
struct
{
XCMD_KEY_T key;
uint16_t count;
}untreated;
2021-09-12 18:01:02 +08:00
}key_list;
struct
{
struct
{
uint16_t len;
xcmd_history_t *next;
xcmd_history_t *handle;
}history_list;
char *display_line; /* 显示区的缓存 */
uint16_t line_totle; /* 一共有多少行 */
uint16_t line_len; /* 每一行的最大长度 */
uint16_t byte_num; /* 当前行的字符个数 */
uint16_t cursor; /* 光标所在位置 */
uint8_t encode_case_stu;
uint32_t key_val;
uint16_t param_len;
}parser;
uint8_t _initOK;
} xcmder_t;
2021-09-12 22:01:20 +08:00
/**
* @description: 641016
* @param {p_func}getchar
* @param {p_func}putchar:
* @return
*/
2021-09-12 18:01:02 +08:00
#define xcmd_create_default(getchar, putchar) xcmd_create(getchar, putchar, 64, 10, 16);
2021-09-12 22:01:20 +08:00
/**
* @description:
* @param {p_func}getchar
* @param {p_func}putchar:
* @param {uint16_t} cmd_len
* @param {uint16_t} history_len
* @param {uint16_t} param_len
* @return
*/
2021-09-12 18:01:02 +08:00
xcmder_t *xcmd_create( int (*get_c)(uint8_t*), int (*put_c)(uint8_t), uint16_t cmd_len, uint16_t history_len, uint16_t param_len);
2021-09-12 22:01:20 +08:00
/**
* @description:
* @param {xcmder_t*} cmder
* @return
*/
2021-09-12 18:01:02 +08:00
void xcmd_destory(xcmder_t* cmder);
2021-09-12 22:01:20 +08:00
/**
* @description:
* @param {xcmder_t*} cmder
* @return {*}
*/
void xcmd_task(xcmder_t* cmder);
/**
* @description:
* @param {xcmder_t*} cmder
* @param {xcmd_t*} cmds
* @param {uint16_t} number
* @return {int}
*/
int xcmd_register(xcmder_t* cmder, xcmd_t* cmds, uint16_t number);
/**
* @description:
* @param {xcmder_t*} cmder
* @param {xcmd_key_t*} keys
* @param {uint16_t} number
* @return {int}
*/
int xcmd_key_register(xcmder_t* cmder, xcmd_key_t* keys, uint16_t number);
2021-09-12 18:01:02 +08:00
2021-09-12 22:01:20 +08:00
/**
* @description:
* @param {xcmder_t} cmder
* @param {char* } str
* @return {uint8_t}
*/
2021-09-12 18:01:02 +08:00
uint8_t xcmd_exec(xcmder_t *cmder, char *str);
2021-09-12 22:01:20 +08:00
/**
* @description:
* @param {xcmder_t *} cmder
* @param {char*} str
* @return
*/
2021-09-13 20:10:34 +08:00
void xcmd_print(xcmder_t * cmder, const char *fmt, ...);
2021-09-12 18:01:02 +08:00
2021-09-12 22:01:20 +08:00
/**
* @description:
* @param {xcmder_t} *cmder
* @param {char} c
* @return
*/
2021-09-12 18:01:02 +08:00
void xcmd_display_insert_char(xcmder_t *cmder, char c);
2021-09-12 22:01:20 +08:00
/**
* @description:
* @param {xcmder_t} *cmder
* @return
*/
2021-09-12 18:01:02 +08:00
void xcmd_display_delete_char(xcmder_t *cmder);
2021-09-12 22:01:20 +08:00
/**
* @description:
* @param {xcmder_t} *cmder
* @return
*/
2021-09-12 18:01:02 +08:00
void xcmd_display_clear(xcmder_t *cmder);
2021-09-12 22:01:20 +08:00
/**
* @description:
* @param {xcmder_t} *cmder
* @return {char*} *
*/
char* xcmd_display_get(xcmder_t *cmder);
/**
* @description:
* @param {xcmder_t} *cmder
* @return {uint16_t}
*/
2021-09-12 18:01:02 +08:00
uint16_t xcmd_history_len(xcmder_t *cmder);
2021-09-12 22:01:20 +08:00
/**
* @description:
* @param {xcmder_t} *cmder
* @param {char*} str
* @return
*/
2021-09-12 18:01:02 +08:00
void xcmd_history_insert(xcmder_t *cmder, char* str);
2021-09-12 22:01:20 +08:00
/**
* @description:
* @param {xcmder_t*} cmder
* @return
*/
char *xcmd_history_next(xcmder_t* cmder);
/**
* @description:
* @param {xcmder_t*} cmder
* @return
*/
2021-09-12 18:01:02 +08:00
char *xcmd_history_prev(xcmder_t *cmder);
2021-09-12 22:01:20 +08:00
/**
* @description:
* @param {xcmder_t*} cmder
* @return
*/
2021-09-12 18:01:02 +08:00
char *xcmd_history_current(xcmder_t *cmder);
2021-09-12 22:01:20 +08:00
/**
* @description:
* @param {xcmder_t*} cmder
* @return
*/
2021-09-12 18:01:02 +08:00
void xcmd_history_reset(xcmder_t *cmder);
#endif /*XCMD_H*/