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],
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 }
unsigned char uchar
GadgetSeedの文字(列)は unsigned char 型となる
Definition: str.h:13
void * memoryset(void *dest, uchar data, unsigned int count)
メモリを任意の値に設定
Definition: str.c:738
ラインエディタ
Definition: lineedit.h:30
uchar buf[GSC_SHELL_MAX_LINE_COLUMS+1]
編集中文字列
Definition: lineedit.h:31
文字列処理
コマンドヒストリ
Definition: history.h:18
short num
記録されているヒストリ数
Definition: history.h:21
void set_str_lineedit(struct st_lineedit *le, uchar *str)
編集文字列を設定する
Definition: lineedit.c:308
unsigned int strleng(const uchar *str)
文字列長
Definition: str.c:657
コマンドヒストリ
short pos
現在表示編集中のヒストリ
Definition: history.h:20
uchar his_buf[GSC_SHELL_MAX_COM_HIS+1][GSC_SHELL_MAX_LINE_COLUMS+1]
ヒストリバッファ
Definition: history.h:19
uchar * strncopy(uchar *dest, const uchar *src, unsigned int n)
文字列コピー
Definition: str.c:632
#define GSC_SHELL_MAX_LINE_COLUMS
$gsc shellコマンドラインの最大文字数
Definition: lineedit.h:16