GadgetSeed  0.9.6
batch.c
[詳解]
1 /** @file
2  @brief バッチ処理
3 
4  GadgetSeed は内臓 shell のコマンドをバッチ処理で実行することが出来ます。
5 
6  @date 2009.01.03
7  @author Takashi SHUDO
8 */
9 
10 #include "sysconfig.h"
11 #include "file.h"
12 #include "tprintf.h"
13 #include "shell.h"
14 
15 //#define DEBUGKBITS 0x03
16 #include "dkprintf.h"
17 
18 
19 extern struct st_shell gs_shell;
20 
21 static int read_line(int fd, uchar *str)
22 {
23  int rt, len = 0;
24 
25  while(1) {
26  rt = read_file(fd, str, 1);
27  if(rt <= 0) {
28  goto end;
29  }
30  DKPRINTF(0x01, "(%02X)", *str);
31  if(len > GSC_SHELL_MAX_LINE_COLUMS) {
32  goto end;
33  }
34  if(*str == '\n') {
35  goto end;
36  }
37  if(*str != '\r') {
38  len ++;
39  str ++;
40  }
41  }
42 end:
43  *str = 0;
44 
45  return len;
46 }
47 
48 /**
49  @brief バッチファイルを実行する
50 
51  @param[in] path バッチファイルのパス
52 
53  @return 実行結果の戻り値
54 */
55 int exec_batch(uchar *path)
56 {
57  int fd;
58  int fr;
59  int res = 0;
61 
62  fd = open_file(path, FA_READ);
63  if(fd < 0) {
64  return -1;
65  }
66 
67  while(1) {
68  fr = read_line(fd, cmd);
69  DKPRINTF(0x01, "### %ld\n", fr);
70  if(fr == 0) {
71  res = 0;
72  goto error;
73  } else if(fr < 0) {
74  res = -1;
75  goto error;
76  }
77  DKPRINTF(0x01, "###[%s]\n", cmd);
78 
79  res = exec_shell_command(&gs_shell, cmd);
80  if(res < 0) {
81  goto error;
82  }
83  };
84 
85 error:
86  close_file(fd);
87 
88  return res;
89 }
unsigned char uchar
GadgetSeedの文字(列)は unsigned char 型となる
Definition: str.h:13
コマンドシェル
int exec_batch(uchar *path)
バッチファイルを実行する
Definition: batch.c:55
シェルデータ構造体
Definition: shell.h:43
int close_file(int fd)
ファイルを閉じる
Definition: file.c:297
ファイル
int exec_shell_command(struct st_shell *shell, uchar *str)
str文字列のコマンドを実行する
Definition: shell.c:218
int open_file(const uchar *path, int flags)
ファイルを開く
Definition: file.c:144
t_ssize read_file(int fd, void *buf, t_size count)
ファイルからデータを読み出す
Definition: file.c:188
カーネル、ドライバ(非タスク)デバッグ用マクロ
#define GSC_SHELL_MAX_LINE_COLUMS
$gsc shellコマンドラインの最大文字数
Definition: lineedit.h:16
機能限定printf