⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inifile.cpp

📁 diablo图形引擎例子
💻 CPP
字号:
/*			    Tao's 45 Engine 
说句实话:
	程序的算法是从Jim Adams 1996 年的 Isometric Views 一
文中来的,我自己的东西并不多,我当时得到这个比较实用的算法是非
常高兴的,觉得自己终于可以编个小游戏了,特别因为我喜欢Dialbo这
样的游戏,不过没有美工也却实是件可怕的事......
	这个程序有Alpha的代码,不过太慢了,我一直无法使他支持M
MX,唉!我的p54c(你不知道p54c p55c的区别?)...
	如果您改进了他或完善了,请给我一份好吗?让我们共同进步!
	
	
	                                 TAO
				http://fireice.yeah.net
				Antao@telekbird.com.cn
	       				1999.10.		*/
// IniFile.cpp: implementation of the IniFile class.
//
//////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include "IniFile.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

IniFile::IniFile()
{
	m_lpDataBuffer=NULL;
}

IniFile::~IniFile()
{
	if (m_lpDataBuffer!=NULL) free(m_lpDataBuffer);
}

bool IniFile::Load(char * lpszFilename)
{
	FILE *fp=fopen(lpszFilename,"rb");
	if (fp==NULL) return false;
	fseek(fp,0,SEEK_END);
	int size=ftell(fp);
	m_lpDataBuffer=(char *)malloc(size*sizeof(char));
	fseek(fp,0,SEEK_SET);
	fread(m_lpDataBuffer,size,1,fp);
	fclose(fp);
	return true;
}

int IniFile::GetValue(char *section, char *keywords)
{
	assert(section);
	assert(keywords);
	char *lpdest=strstr(m_lpDataBuffer,section);
	if (lpdest==NULL) return -1;
	char *found=strstr(lpdest,keywords);
	if (found==NULL) return -1;
	found=strstr(found,"=");
	found++;
	int value=atoi(found);
	return value;
}

int IniFile::GetString(char * section , char * keywords, char * buffer, int len)
{
	assert(section);
	assert(keywords);
	char *lpdest=strstr(m_lpDataBuffer,section);
	if (lpdest==NULL) return -1;
	char *found=strstr(lpdest,keywords);
	if (found==NULL) return -1;
	found=strstr(found,"=");
	found++;
	int count=0;
	while(count<len)
	{
		if (*found==0xd) { *buffer=0;break; }
		*buffer++=*found++;
		count++;	
	}
	return count;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -