GadgetSeed
0.9.6
history.c
[詳解]
1
/** @file
2
@brief コマンドヒストリ
3
4
@date 2007.03.18
5
@author Takashi SHUDO
6
*/
7
8
#include "
history.h
"
9
#include "
str.h
"
10
11
/*
12
ヒストリーのクリア
13
*/
14
void
init_history(
struct
st_history
*his)
15
{
16
int
j;
17
18
for
(j=0; j<(GSC_SHELL_MAX_COM_HIS+1); j++) {
19
(void)
memoryset
(his->
his_buf
[j], 0,
GSC_SHELL_MAX_LINE_COLUMS
+1);
20
}
21
22
his->
pos
= 0;
23
his->
num
= 0;
24
}
25
26
/*
27
ヒストリーに記録
28
*/
29
void
save_history(
struct
st_history
*his,
uchar
*com)
30
{
31
int
i;
32
33
if
(
strleng
(com) != 0) {
34
(void)
strncopy
(his->
his_buf
[0], com,
GSC_SHELL_MAX_LINE_COLUMS
);
35
36
for
(i=GSC_SHELL_MAX_COM_HIS; i>0; i--) {
37
(void)
strncopy
(his->
his_buf
[i], his->
his_buf
[i-1],
38
GSC_SHELL_MAX_LINE_COLUMS
);
39
}
40
if
(his->
num
<= GSC_SHELL_MAX_COM_HIS) {
41
his->
num
++;
42
}
43
his->
pos
= 0;
44
}
45
}
46
47
/*
48
次のヒストリーを表示
49
*/
50
void
foward_history(
struct
st_history
*his,
struct
st_lineedit
*le)
51
{
52
if
(his->
pos
> 0) {
53
his->
pos
--;
54
set_str_lineedit
(le, his->
his_buf
[his->
pos
]);
55
}
56
}
57
58
/*
59
前のヒストリーを表示
60
*/
61
void
back_history(
struct
st_history
*his,
struct
st_lineedit
*le)
62
{
63
if
((his->
pos
< GSC_SHELL_MAX_COM_HIS) &&
64
(his->
pos
< his->
num
)) {
65
if
(his->
pos
== 0) {
66
(void)
strncopy
(his->
his_buf
[0], le->
buf
,
GSC_SHELL_MAX_LINE_COLUMS
);
67
}
68
69
his->
pos
++;
70
71
set_str_lineedit
(le, his->
his_buf
[his->
pos
]);
72
}
73
}
uchar
unsigned char uchar
GadgetSeedの文字(列)は unsigned char 型となる
Definition:
str.h:13
memoryset
void * memoryset(void *dest, uchar data, unsigned int count)
メモリを任意の値に設定
Definition:
str.c:738
st_lineedit
ラインエディタ
Definition:
lineedit.h:30
st_lineedit::buf
uchar buf[GSC_SHELL_MAX_LINE_COLUMS+1]
編集中文字列
Definition:
lineedit.h:31
str.h
文字列処理
st_history
コマンドヒストリ
Definition:
history.h:18
st_history::num
short num
記録されているヒストリ数
Definition:
history.h:21
set_str_lineedit
void set_str_lineedit(struct st_lineedit *le, uchar *str)
編集文字列を設定する
Definition:
lineedit.c:308
strleng
unsigned int strleng(const uchar *str)
文字列長
Definition:
str.c:657
history.h
コマンドヒストリ
st_history::pos
short pos
現在表示編集中のヒストリ
Definition:
history.h:20
st_history::his_buf
uchar his_buf[GSC_SHELL_MAX_COM_HIS+1][GSC_SHELL_MAX_LINE_COLUMS+1]
ヒストリバッファ
Definition:
history.h:19
strncopy
uchar * strncopy(uchar *dest, const uchar *src, unsigned int n)
文字列コピー
Definition:
str.c:632
GSC_SHELL_MAX_LINE_COLUMS
#define GSC_SHELL_MAX_LINE_COLUMS
$gsc shellコマンドラインの最大文字数
Definition:
lineedit.h:16
shell
history.c
構築:
1.8.13