zoukankan      html  css  js  c++  java
  • 闲云控制台(二)查看文件功能,支持十六进制查看文件

    命令处理区增加

    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("文件不存在或路径错误。
    ");
    		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("
    ");
    				else 
    					printf(" ");
    				if (_line_number && !n)
    					printf("%04d: ", ++line);
    			}
    			else
    			{
    				printf("%c", ch);
    				if (_line_number && '
    ' == ch)
    					printf("%04d: ", ++line);
    			}
    		}
    	}
    	fclose(in_file);
    	printf("
    ");
    	return OK;
    }


    注冊区增加

    _register_one_cmd("look", Look_File, "查看文件, 參数:x十六进制,n取消行号");


  • 相关阅读:
    vue 开发系列 企业微信整合
    MongoDB基础3
    MongoDB基础2
    MongoDB基础1
    SpringBoot MongoDB
    UWSGI
    Nginx
    编译python源码
    Flask部署
    Django个人工作总结
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/5197283.html
Copyright © 2011-2022 走看看