📄 property.cpp
字号:
#include "Property.h"
#ifdef BUFSIZ
#undef BUFSIZ
#define BUFSIZ 4096
#endif
map<string, string> Property::getProperty() const
{ return property; }
static char *NextToken(char *buf);
static int GetKey(char *buf, char *ptr);
/* parse configure file, store it in cmap as (string, string) couple */
void Property::parseConfigFile(const string file)
{
/* The following codes are in c style. */
char *p = NULL;
char buf[BUFSIZ];
char key[BUFSIZ];
FILE *fp = NULL;
/*
* We read in the configure file, with each line as following:
* # hello(comment) or
* alpha = 0.25 (format: key = string) or
* blank line(having no charactors)
*/
fp = fopen(file.c_str(), "r");
if(!fp) {
printf("Open file for reading failed: %s, abort now\n", strerror(errno));
exit(-1);
}
while(fgets(buf, BUFSIZ, fp))
{
p = NextToken(buf);
if(!p)
continue;
else if(*p == '#')
continue;
else {
assert(GetKey(key, p) > 0);
string tmp = key;
p = NextToken(NULL);
p = NextToken(NULL);
assert(p);
assert(GetKey(key, p) > 0);
property[tmp] = key;
}
}
}
static char *NextToken(char *pbuf)
{
char *pp;
static char *p;
static char buf[BUFSIZ];
if(pbuf)
{
strcpy(buf, pbuf);
p = buf;
}
while((*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r') && *p != '\0')
p++;
if(*p)
pp = p;
else
pp = NULL;
while(*p != '\0' && *p != ' ' && *p != '\t' && *p != '\n' && *p != '\r')
p++;
return pp;
}
static int GetKey(char *buf, char *ptr)
{
char *p;
if(!buf || !ptr)
return 0;
p = buf;
while(*ptr != '\0' && *ptr != ' ' && *ptr != '\t' && *ptr != '\n' && *p != '\r')
*p++ = *ptr++;
*p = '\0';
return strlen(buf);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -