博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
读取配置文件
阅读量:2222 次
发布时间:2019-05-08

本文共 2320 字,大约阅读时间需要 7 分钟。

ContractedBlock.gif
ExpandedBlockStart.gif
Code
// ConfigFileMng.cpp: implementation of the CConfigFileMng class.
//
//
#include 
"ConfigFileMng.h"
//
// Construction/Destruction
//
CConfigFileMng::CConfigFileMng()
{
}
CConfigFileMng::
~CConfigFileMng()
{
}
bool CConfigFileMng::Open(const char *strFileName)
{
    
char szFileName[50]="";
    
int nFileNameLen=0;
    
char szFilePox[5]="";
    FILE 
*pFile;
    
/*1.对传入的指针进行非空判断*/
    
if(0==strFileName)
    {
      
return false;
    }
    
//
    strcpy(szFileName,strFileName);
    
if(strcmp(szFileName,"")==0)
    {
       
return false;
    }
    nFileNameLen
=strlen(szFileName);
    
if(0!=nFileNameLen)
    {
        
for(int i=0;i<4,i++)
        {
            szFilePox[i]
=szFileName[nFileLen-1-i];            
        }
        szFilePox[i]
='\0';
        
if(0!=strcmp(strFilePox,"ini."))
        {
            strcat(szFileName,
".ini");
        }
        
if(strlen(szFileName)>MAX_FILENAME_LEN)
        {
            
return  false;
        }
        pFile
=fopen(szFileName,"r");
        
if(pFile==0)
        {
            
return false;
        }
        m_bOpenFlag
=true;
        
return true;
    }
    m_bOpenFlag
=false;
    
return false;
}
bool CConfigFileMng::isOpen()
{
    
return m_bOpenFlag;
}
char*  CConfigFileMng::getSession(const char *pStr,const char *strSesName)
{
    
char szTmpSes[1024]="";
    
int nPosBeg=0;
    
int nPosEnd=0;
    
if(0!=strstr(strSesName,"[")||0!=strstr(strSesName,"]"))
    {
        
return false;
    }
    
else
    {
        nPosBeg
=strstr(strSesName,"[");
        nPosEnd
=strstr(strSes,"]");
    }
    
for(int i=nPosBeg+1,i<nPosEnd,i++)
    {
        szTmpSes[i
-nPosBeg-1]=strSesName[i];
    }
    
if(0==strcmp(szTmpSes,szFileName))
    {
        
return true;
    }
    
else
    {
        
return false;
    }
}
char* CConfigFileMng::getContent(const char *pStr,const char *valueName,char *retStr)
{
    
char tmpStr[100];
    
int i=0;
    
int j=0;
    retStr[
0]=0;
    
while(pStr[i]==''||pStr[i]=='\t')
    {
        i
++;
    }
    
if(pStr[i]=="#")
    {
        
return "this is a Comment!";
    }
    
    
if(pStr[i]=="[")
    {
        
return "this is a Session!";
    }
    
if(pStr[i]==0)
    {
        
return "noThing!";
    }
    
while(pStr[i]!=''&&pStr[i]!='='&&pStr!='\t'&&pStr=0)
    {
        tmpStr[i]
=pStr[i];
        i
++;
        j
++;
    }
    TmpStr[j]
=0;
    
if(strcmp(tmpStr,valueName)!=0)
    {
        
return "not Found!";
    }
    
/*获取变量的值*/
    
while(pStr[i]==''||pStr[i]=='='||pStr[i]=='\t')
    {
        i
++;
    }
    
if(pStr[i]!="")
    {
        i
++;
      j
=0;
    
while( pStr[i] !='"' && i< MAX_LINE_LENGTH)
        {
              RetStr[j] 
= pStr[i];
              i
++;
              j
++;
        }
        RetStr[j] 
= 0;
    }
    
else
    {
        j
=0;
        
while( pStr[i] >' ' && pStr[i] != '#' && pStr[i] != 127)//
        {
              RetStr[j] 
= pStr[i];
              i
++;
              j
++;
        }
        RetStr[j] 
= 0;
    }
    
return *RetStr;
}
short CConfigFileMng::getValue(const char *Session,const char *ValueName,char *RetStr)
{
    
}

转载于:https://www.cnblogs.com/xianqingzh/archive/2009/11/23/1608805.html

你可能感兴趣的文章
面试题 —— 关于main方法的十个面试题
查看>>
集成测试(一)—— 使用PHP页面请求Spring项目的Java接口数据
查看>>
使用Maven构建的简单的单模块SSM项目
查看>>
Intellij IDEA使用(十四)—— 在IDEA中创建包(package)的问题
查看>>
FastDFS集群架构配置搭建(转载)
查看>>
HTM+CSS实现立方体图片旋转展示效果
查看>>
FFmpeg 命令操作音视频
查看>>
问题:Opencv(3.1.0/3.4)找不到 /opencv2/gpu/gpu.hpp 问题
查看>>
目的:使用CUDA环境变量CUDA_VISIBLE_DEVICES来限定CUDA程序所能使用的GPU设备
查看>>
问题:Mysql中字段类型为text的值, java使用selectByExample查询为null
查看>>
程序员--学习之路--技巧
查看>>
解决问题之 MySQL慢查询日志设置
查看>>
contOS6 部署 lnmp、FTP、composer、ThinkPHP5、docker详细步骤
查看>>
TP5.1模板布局中遇到的坑,配置完不生效解决办法
查看>>
PHPstudy中遇到的坑No input file specified,以及传到linux环境下遇到的坑,模板文件不存在
查看>>
TP5.1事务操作和TP5事务回滚操作多表
查看>>
composer install或composer update 或 composer require phpoffice/phpexcel 失败解决办法
查看>>
TP5.1项目从windows的Apache服务迁移到linux的Nginx服务需要注意几点。
查看>>
win10安装软件 打开时报错 找不到 msvcp120.dll
查看>>
PHPunit+Xdebug代码覆盖率以及遇到的问题汇总
查看>>