命令处理区加入
int Look_File(pCommand b)
{
int _out_style = 1;
int _line_number = 1;
int _len_argu = strlen(b->Cmd_Arguments);
while (--_len_argu >= 0)
{
switch (b->Cmd_Arguments[_len_argu])
{
case 'x':
_out_style = 16;
break;
case 'n':
_line_number = 0;
break;
}
}
FILE *in_file = fopen(b->Cmd_Object, "rb");
if (!in_file)
{
printf("文件不存在或路径错误!\n");
return NO;
}
else
{
unsigned char ch;
int line = 1;
int n = 0;
if (_line_number) printf("%04d: ", line);
while (EOF != fscanf(in_file, "%c", &ch))
{
if (16 == _out_style)
{
printf("%0X%0X", ch / 16, ch % 16);
if (!(n = (n+1)%16))
printf("\n");
else
printf(" ");
if (_line_number && !n)
printf("%04d: ", ++line);
}
else
{
printf("%c", ch);
if (_line_number && '\n' == ch)
printf("%04d: ", ++line);
}
}
}
fclose(in_file);
printf("\n");
return OK;
}
注册区加入
_register_one_cmd("look", Look_File, "查看文件, 参数:x十六进制,n取消行号");