依赖的类

 /*1 utils.h
*# A variety of utility functions.
*#
*# Some of the functions are duplicates of well known C functions that are not
*# standard.
*2 License
*[
*# Author: Werner Stoop
*# This software is provided under the terms of the unlicense.
*# See http://unlicense.org/ for more details.
*]
*2 API
*/
#include "stdafx.h"
/*@ MY_MIN(a,b)
*# Macro that returns the smallest of its parameters.\n
*# As with all macros, {{a}} and {{b}} should not have side effects.
*/
#define MY_MIN(a,b) (((a)<(b))?(a):(b)) /*@ MY_MAX(a,b)
*# Macro that returns the largest of its parameters.\n
*# As with all macros, {{a}} and {{b}} should not have side effects.
*/
#define MY_MAX(a,b) (((a)>(b))?(a):(b)) /*@ int my_stricmp(const char *p, const char *q)
*# Compares two strings {{p}} and {{q}} case insensitively.
*#
*# It returns 0 if the strings are the same, a positive number if {{p}} comes after {{q}},
*# and negative if {{p}} comes before {{q}}.
*/
int my_stricmp(const char *p, const char *q); /*@ char *my_strdup(const char *s)
*# Creates a duplicate of a string {{s}} in a dynamic memory buffer.\n
*# The returned buffer needs to be {{free()}}d after use. It may return
*# {{NULL}} if the memory allocation fails.
*/
char *my_strdup(const char *s); /*@ char *my_strlower (char *p)
*# Converts a string {{p}} to lowercase in place.
*# It returns {{p}}.
*/
char *my_strlower (char *p); /*@ char *my_strupper (char *p)
*# Converts a string {{p}} to uppercase in place.
*# It returns {{p}}.
*/
char *my_strupper (char *p); /*@ char *my_strtok_r(char *str, const char *delim, char **saveptr)
*# Works the same as {{strtok_r(3)}} for platforms which lack it.
*/
char *my_strtok_r(char *str, const char *delim, char **saveptr); /*@ char *my_readfile (const char *fn)
*# Reads an entire file identified by {{fn}} into a dynamically allocated memory buffer.\n
*# The returned buffer needs to be {{free()}}d afterwards.\n
*# It returns {{NULL}} if the file could not be read.
*/
char *my_readfile (const char *fn);

utils.h

 /*
* A variety of utility functions.
*
* See utils.h for more info
*
* This is free and unencumbered software released into the public domain.
* http://unlicense.org/
*/
#include "stdafx.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h> /* Case insensitive strcmp()
*/
int my_stricmp(const char *p, const char *q) {
for(;*p && tolower(*p) == tolower(*q); p++, q++);
return tolower(*p) - tolower(*q);
} /* strdup() is not ANSI C */
char *my_strdup(const char *s) {
char *a;
size_t len = strlen(s);
a = (char*)malloc(len + );
if(!a) return NULL;
memcpy(a, s, len + );
return a;
} /* converts a string to lowercase */
char *my_strlower (char *p) {
char *s;
for (s = p; s[]; s++)
s[] = tolower (s[]); return p;
} /* converts a string to lowercase */
char *my_strupper (char *p)
{
char *s;
for (s = p; s[]; s++)
s[] = toupper (s[]); return p;
} char *my_strtok_r(char *str, const char *delim, char **saveptr) {
if(!str)
str = *saveptr;
if(!str[]) {
*saveptr = str;
return NULL;
}
char *s = strpbrk(str, delim);
if(s) {
s[] = '\0';
*saveptr = s + ;
} else
for(*saveptr = str; (*saveptr)[]; (*saveptr)++);
return str;
} /* Reads an entire file into a dynamically allocated memory buffer.
* The returned buffer needs to be free()d afterwards
*/
char *my_readfile(const char *fname) {
FILE *f;
long len,r;
char *str; if(!(f = fopen(fname, "rb")))
return NULL; fseek(f, , SEEK_END);
len = ftell(f);
rewind(f); if(!(str = (char*)malloc(len+)))
return NULL;
r = fread(str, , len, f); if(r != len) {
free(str);
return NULL;
} fclose(f);
str[len] = '\0';
return str;
}

utils.cpp

ini格式配置文件的读写

 /*1 ini.h
*# Header file for the {*INI*} parser.\n
*#
*# This is a simple parser for {*.INI*} files.
*# It is based around the syntax described in the Wikipedia entry at
*# {_http://en.wikipedia.org/wiki/INI_file_}\n
*#
*# The API has these features:
*{
** Use {{~~ini_read()}} to read an INI file from the disc into an {{~~ini_file}}
*# structure or create an empty {{~~ini_file}} structure.
** Use {{~~ini_get()}} to retrieve values from the {{~~ini_file}} structure.
** Use {{~~ini_put()}} and {{~~ini_putf()}} to set values in the {{~~ini_file}} structure.
** Use {{~~ini_write()}} to write the contents of the {{~~ini_file}} structure back to disc.
** Use {{~~ini_free()}} to deallocate the {{~~ini_file}} structure.
** {{~~ini_errstr()}} is used for reporting errors.
*}
*2 License
*[
*# Author: Werner Stoop
*# This software is provided under the terms of the unlicense.
*# See http://unlicense.org/ for more details.
*]
*2 API
*/
#ifndef INI_H
#define INI_H #if defined(__cplusplus)
extern "C" {
#endif /*
* Encapsulates a parameter-value pair in an INI section.
* Parameters are stored in a binary search tree, which attempts (but does not
* guarantee) O(log(n)) behaviour.
*/
typedef struct INI_PAIR
{
char *param; /* The parameter */
char *value; /* Its value */ /* Nodes in the tree */
struct INI_PAIR *left, *right;
} ini_pair; /*
* Encapsulates a section within a INI file.
* Sections are stored in a binary search tree, which attempts (but does not
* guarantee) O(log(n)) behaviour.
*/
typedef struct INI_SECTION
{
char *name; /* Name of the section */
ini_pair *fields; /* Fields in the section */ /* Nodes in the tree */
struct INI_SECTION *left, *right;
} ini_section; /*@ struct ##ini_file;
*# Structure to encapsulate an INI file.
*/
struct ini_file
{
ini_pair *globals;
ini_section *sections;
}; /*@ ini_file *##ini_read(const char *filename, int *err, int *line);
*# Reads an INI file named by {{filename}} and returns it as a {{~~ini_file}} object.
*# If {{filename}} is {{NULL}}, an empty {{ini_file}} object is created and returned.
*# Comments are discarded, so a later call to {{~~ini_write()}} will be
*# commentless.\n
*# It returns {{NULL}} if the INI file couldn't be read, in which case {{err}} will contain the error code
*# (see {{~~ini_errstr()}}) and {{line}} will contain the line in the file where the error occured.
*# ({{err}} and {{line}} may be {{NULL}}).
*/
struct ini_file *ini_read(const char *filename, int *err, int *line); /*@ ini_file *##ini_parse(const char *text, int *err, int *line);
*# Parses a null-terminated string {{text}} as an INI file.\n
*# It returns {{NULL}} if the INI file couldn't be read, in which case {{err}} will contain the error code
*# (see {{~~ini_errstr()}}) and {{line}} will contain the line in the file where the error occured.
*# ({{err}} and {{line}} may be {{NULL}}).
*/
struct ini_file *ini_parse(const char *text, int *err, int *line); /*@ int ##ini_write(ini_file *ini, const char *fname);
*# Saves all the sections and parameters in an {{ini_file}} to a file.\n
*# {{fname}} is the file to which to save. If {{fname}} is {{NULL}}, it is written to
*# {{stdout}}.
*# It returns 1 on success, an error code otherwise (see {{~~ini_errstr()}}).
*/
int ini_write(struct ini_file *ini, const char *fname); /*@ void ##ini_free(ini_file *ini);
*# Free's all the memory allocated to a {{ini_file}} object created in {{~~ini_read()}}.\n
*# {{ini}} is the {{ini_file}} to free
*/
void ini_free(struct ini_file *ini); /*@ int ini_has_section(struct ini_file *ini, const char *sec)
*# Returns true if the ini file has a specific section.
*/
int ini_has_section(struct ini_file *ini, const char *sec); /*@ const char *##ini_get(struct ini_file *ini, const char *sec, const char *par, const char *def);
*# Retrieves a parameter {{par}} from a section {{sec}} within the struct ini_file {{ini}}
*# and returns its value.\n
*# If {{sec}} is {{NULL}}, the global parameters in {{ini}} are searched.\n
*# If the value is not found, the default {{def}}, which may be {{NULL}}, is
*# returned.
*/
const char *ini_get(struct ini_file *ini,
const char *sec,
const char *par,
const char *def); /*@ int ##ini_put(struct ini_file *ini, const char *sec, const char *par, const char *val);
*# Sets a parameter {{par}} in section {{sec}}'s value to {{val}}, replacing the
*# current value if it already exists, or creates the section if it does not
*# exist.\n
*# If {{sec}} is {{NULL}}, the parameter is added to {{ini}}'s global parameters.\n
*# It returns 1 on success, 0 on failure (which only happens if {{malloc()}} fails).
*/
int ini_put(struct ini_file *ini, const char *sec, const char *par, const char *val); /*@ int ##ini_putf(struct ini_file *ini, const char *sec, const char *par, const char *fmt, ...);
*# {{~~ini_putf()}} takes a {{printf()}} style format string and uses vsnprintf() to
*# pass a value to {{~~ini_put()}}. This function is intended for placing
*# data types that are not strings into the {{ini_file}}
*#
*# The other parameters are the same as those of {{ini_put()}}.
*/
int ini_putf(struct ini_file *ini,
const char *sec,
const char *par,
const char *fmt,
...); /*@ const char *##ini_errstr(int err)
*# Returns a textual description of an error code
*/
const char *ini_errstr(int err); #if defined(__cplusplus)
} /* extern "C" */
#endif #endif /* INI_H */

ini.h

 /*
* This is a simple parser for .INI files.
* It is based around the syntax described in the Wikipedia entry at
* "http://en.wikipedia.org/wiki/INI_file"
*
* See ini.h for more info
*
* This is free and unencumbered software released into the public domain.
* http://unlicense.org/
*/
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include <setjmp.h> #include <assert.h> /* Remember to define NDEBUG for release */ #include "ini.h"
#include "utils.h"
#include <crtdbg.h> /* Maximum number of characters expected on a line.
It is only used by the ini_putf() function.
*/
#define MAX_LINE 1024 /* Various error codes */
#define SUCCESS 1
#define FILE_CREATED 0
#define NO_SUCH_FILE -1
#define OUT_OF_MEMORY -2
#define MISSING_END_BRACE -3
#define EMPTY_SECTION -4
#define EXPECTED_EQUALS -5
#define EXPECTED_END_OF_STRING -6
#define ER_FOPEN -7
#define BAD_SYMBOL -8
#define EXPECTED_PARAMETER -9
#define EXPECTED_VALUE -10 const char *ini_errstr(int err)
{
switch(err)
{
case SUCCESS : return "Success";
case FILE_CREATED: return "New INI object created";
case NO_SUCH_FILE: return "Unable to open file";
case OUT_OF_MEMORY: return "Out of memory";
case MISSING_END_BRACE: return "Missing ']' at end of section";
case EMPTY_SECTION: return "Empty [] for section";
case EXPECTED_EQUALS : return "Expected an '='/':'";
case EXPECTED_END_OF_STRING : return "Expected an end of string";
case ER_FOPEN : return "Unable to open file";
case BAD_SYMBOL : return "Bad symbol";
case EXPECTED_PARAMETER : return "Expected a parameter (or section)";
case EXPECTED_VALUE : return "Expected a value";
}
return "Unknown";
} /** Configurable parameters *************************************************/ /*
* Recursively adds sections to the tree of sections
*/
static void insert_section(ini_section *r, ini_section *n) {
assert(r);
assert(n); if(my_stricmp(r->name, n->name) < ) {
if(!r->left)
r->left = n;
else
insert_section(r->left, n);
} else {
if(!r->right)
r->right = n;
else
insert_section(r->right, n);
}
} /*
* Searches a tree of pairs for a specific parameter
*/
static ini_pair *find_pair(ini_pair *root, const char *name) {
int c; if(!root) return NULL; c = my_stricmp(root->param, name);
if(c == )
return root;
else if(c < )
return find_pair(root->left, name);
else
return find_pair(root->right, name);
} /*
* Searches for a specific section
*/
static ini_section *find_section(ini_section *root, const char *name) {
int c; if(!root) return NULL; c = my_stricmp(root->name, name);
if(c == )
return root;
else if(c < )
return find_section(root->left, name);
else
return find_section(root->right, name);
} /*
* Creates a new section, and adds it to a tree of sections
*/
static ini_section *add_section(ini_section **root, char *name) {
ini_section *n; assert(root);
assert(name); n = find_section(*root, name);
if(n) {
free(name);
return n;
} n = (ini_section*)malloc(sizeof *n);
if(!n) return NULL; n->name = name; n->fields = NULL;
n->left = n->right = NULL; if(*root)
insert_section(*root, n);
else
*root = n; return n;
} /*
* Inserts a new pair n into a pair tree p
*/
static void insert_pair(ini_pair *p, ini_pair *n) {
if(my_stricmp(p->param, n->param) < ) {
if(!p->left)
p->left = n;
else
insert_pair(p->left, n);
} else {
if(!p->right)
p->right = n;
else
insert_pair(p->right, n);
}
} /*
* Adds a parameter-value pair to section s
*/
static ini_pair *add_pair(ini_section *s, char *p, char *v) {
ini_pair *n; assert(s); n = (ini_pair*)malloc(sizeof *n);
if(!n) return NULL; n->param = p;
n->value = v; n->left = n->right = NULL; if(!s->fields)
s->fields = n;
else
insert_pair(s->fields, n); return n;
} /** Functions for memory deallocation ***************************************/ /*
* Free's a tree of parameter-value pairs
*/
static void free_pair(ini_pair *p) {
if(!p) return; free_pair(p->left);
free_pair(p->right); free(p->param);
free(p->value);
free(p);
} /*
* Free's all the memory allocated to a ini_section s
*/
static void free_section(ini_section *s) {
if(!s) return; free_section(s->left);
free_section(s->right); free(s->name);
free_pair(s->fields);
free(s);
} /*
* Free's all the memory allocated to a ini_file object in ini_read()
*/
void ini_free(struct ini_file *ini) {
if(!ini) return;
free_pair(ini->globals);
free_section(ini->sections);
free(ini);
} /** Parsing functions *******************************************************/ static struct ini_file *make_ini()
{
struct ini_file *ini = (ini_file*)malloc(sizeof *ini);
if(!ini) return NULL;
ini->globals = NULL;
ini->sections = NULL;
return ini;
} /*
* Reads an INI file and returns it as a ini_file object.
* If filename is NULL, an empty ini_file object is created and returned.
*/
struct ini_file *ini_read(const char *filename, int *err, int *line) {
if(line) *line = ;
if(!filename)
{
if(err) *err = FILE_CREATED;
return make_ini();
}
else
{
char *text = my_readfile(filename);
if(!text) {
if(err) *err = NO_SUCH_FILE;
return NULL;
}
struct ini_file * ini = ini_parse(text, err, line);
free(text);
return ini;
}
} #define T_END 0
#define T_VALUE 1 static int get_token(const char **tp, const char **tstart, const char **tend, int *line, jmp_buf err) {
/* *tstart points to the start of the token, while *tend points one char past the end */ const char *t = *tp;
int tok = T_END; assert(tp && tstart && tend); whitespace:
while(isspace(t[])) {
if(t[] == '\n' && line)
(*line)++;
t++;
}
if(t[] == ';' || t[] == '#') {
while(t[] != '\n' && t[] != '\0')
t++;
goto whitespace;
} *tstart = t;
*tend = t;
if(t[]) {
if(strchr("[]:=", t[])) {
tok = *t++;
} else if(isgraph(t[]) && !strchr("\"'[];#", t[])) {
while(isgraph(t[]) && !strchr("\"'[];#", t[])) {
t++;
}
*tend = t;
tok = T_VALUE;
} else if(t[] == '\"' || t[] == '\'') {
char delim = t[];
if(t[] == delim && t[] == delim) {
/* """Python style long strings""" */
t += ;
*tstart = t;
while(!(t[] == delim && t[] == delim && t[] == delim)) {
if(t[] == '\0') {
longjmp(err, EXPECTED_END_OF_STRING);
} else if(t[] == '\\')
t++;
t++;
}
*tend = t;
t+=;
} else {
*tstart = ++t;
while(t[] != delim) {
if(t[] == '\0' || t[] == '\n') {
longjmp(err, EXPECTED_END_OF_STRING);
} else if(t[] == '\\')
t++;
t++;
}
*tend = t++;
}
tok = T_VALUE;
} else {
/* Unrecognized token */
longjmp(err, BAD_SYMBOL);
}
} *tp = t;
return tok;
} static char *get_string(const char *tstart, const char *tend, jmp_buf err)
{
char *string, *s;
const char *i; assert(tend > tstart);
string = (char*)malloc(tend - tstart + );
if(!string)
longjmp(err, OUT_OF_MEMORY); for(i = tstart, s = string; i < tend; i++) {
if(i[] == '\\') {
switch(*++i) {
case '\\':
case '\'':
case '\"': *s++ = i[]; break;
case 'r': *s++ = '\r'; break;
case 'n': *s++ = '\n'; break;
case 't': *s++ = '\t'; break;
case '': *s++ = '\0'; break;
default: break;
}
} else {
*s++ = i[];
}
}
assert(s - string <= tend - tstart);
s[] = '\0';
return string;
} struct ini_file *ini_parse(const char *text, int *err, int *line) {
jmp_buf on_error;
int e_code; struct ini_file *ini = NULL;
ini_section *cur_sec = NULL; const char *tstart, *tend; int t; if(err) *err = SUCCESS;
if(line) *line = ; ini = make_ini(); if((e_code = setjmp(on_error)) != ) {
if(err) *err = e_code;
ini_free(ini);
return NULL;
} while((t = get_token(&text, &tstart, &tend, line, on_error)) != T_END) {
if(t == '[') {
char *section_name;
if(get_token(&text, &tstart, &tend, line, on_error) != T_VALUE) {
longjmp(on_error, EMPTY_SECTION);
} section_name = get_string(tstart, tend, on_error); cur_sec = add_section(&ini->sections, section_name);
if(!cur_sec)
longjmp(on_error, OUT_OF_MEMORY); if(get_token(&text, &tstart, &tend, line, on_error) != ']') {
longjmp(on_error, MISSING_END_BRACE);
} } else if (t == T_VALUE ) {
char *par, *val;
par = get_string(tstart, tend, on_error);
t = get_token(&text, &tstart, &tend, line, on_error);
if(t != '=' && t != ':') {
longjmp(on_error, EXPECTED_EQUALS);
}
if(get_token(&text, &tstart, &tend, line, on_error) != T_VALUE) {
longjmp(on_error, EXPECTED_VALUE);
}
val = get_string(tstart, tend, on_error); if(cur_sec)
add_pair(cur_sec, par, val);
else {
/* Add the parameter and value to the INI file's globals */
ini_pair *pair;
if(!(pair = (ini_pair*)malloc(sizeof *pair)))
longjmp(on_error, OUT_OF_MEMORY); pair->param = par;
pair->value = val; pair->left = pair->right = NULL; if(!ini->globals)
ini->globals = pair;
else
insert_pair(ini->globals, pair);
} } else
longjmp(on_error, EXPECTED_PARAMETER);
} return ini;
} /** Printing functions ******************************************************/ static void string_to_file(FILE *f, const char *s) {
fputc('\"', f);
for(; s[]; s++) {
switch(s[]) {
case '\n': fputs("\\n",f); break;
case '\r': fputs("\\r",f); break;
case '\t': fputs("\\t",f); break;
case '\"': fputs("\\\"",f); break;
case '\'': fputs("\\\'",f); break;
case '\\': fputs("\\\\",f); break;
default : fputc(s[], f); break;
}
}
fputc('\"', f);
} /*
* Recursively prints a tree of ini_pairs
*/
static void write_pair(ini_pair *p, FILE *f) {
if(!p) return; string_to_file(f, p->param);
fputs(" = ", f);
string_to_file(f, p->value);
fputc('\n', f); write_pair(p->left, f);
write_pair(p->right, f);
} /*
* Recursively prints a tree of INI sections
*/
static void write_section(ini_section *s, FILE *f) {
if(!s) return; fputs("\n[", f);
string_to_file(f, s->name);
fputs("]\n", f); write_pair(s->fields, f); /* The akward sequence is to ensure that values are not written sorted */ write_section(s->left, f);
write_section(s->right, f);
} /*
* Saves all the sections and parameters in an ini_file to a file.
* If fname is NULL, it is written to stdout.
*/
int ini_write(struct ini_file *ini, const char *fname) {
FILE *f; if(fname) {
f = fopen(fname, "w");
if(!f)
return ER_FOPEN;
} else
f = stdout; write_pair(ini->globals, f);
write_section(ini->sections, f); if(fname)
fclose(f); return SUCCESS;
} /****************************************************************************/ int ini_has_section(struct ini_file *ini, const char *sec) {
return find_section(ini->sections, sec) != NULL;
} /*
* Finds a specific parameter-value pair in the configuration file
*/
static ini_pair *find_param(const struct ini_file *ini,
const char *sec,
const char *par) {
ini_section *s;
ini_pair *p; if(!ini) return NULL; if(sec) {
s = find_section(ini->sections, sec);
if(!s) return NULL;
p = s->fields;
} else
p = ini->globals; if(!p) return NULL; return find_pair(p, par);
} /*
* Retrieves a parameter 'par' from a section 'sec' within the ini_file 'ini'
* and returns its value.
* If 'sec' is NULL, the global parameters ini 'ini' are searched.
* If the value is not found, 'def' is returned.
* It returns a string. Functions like atoi(), atof(), strtol() and even
* sscanf() can be used to convert it to the relevant type.
*/
const char *ini_get(struct ini_file *ini,
const char *sec,
const char *par,
const char *def) {
ini_pair *p; p = find_param(ini, sec, par);
if(!p) {
if(def)
ini_put(ini, sec, par, def);
return def;
} return p->value;
} /*
* Sets a parameter 'par' in section 'sec's value to 'val', replacing the
* current value if it already exists, or creates the section if it does not
* exist
*/
int ini_put(struct ini_file *ini, const char *sec, const char *par, const char *val) {
ini_section *s;
ini_pair *p, **pp; if(!ini || !val) return ; p = find_param(ini, sec, par);
if(p) {
/* Replace the existing value */
char *t = p->value;
if(!(p->value = my_strdup(val))) {
p->value = t;
return ;
} free(t);
return ;
} if(sec) {
s = find_section(ini->sections, sec);
if(!s) {
/* Create a new section */
if(!(s = (ini_section*)malloc(sizeof *s))) return ;
if(!(s->name = my_strdup(sec))) {
free(s);
return ;
} s->fields = NULL;
s->left = s->right = NULL; if(ini->sections)
insert_section(ini->sections, s);
else
ini->sections = s;
} pp = &s->fields;
} else
pp = &ini->globals; if(!(p = (ini_pair*)malloc(sizeof *p)))
return ; if(!(p->param = my_strdup(par)) || !(p->value = my_strdup(val))) {
free(p);
return ;
} p->left = p->right = NULL; if(!*pp)
*pp = p;
else
insert_pair(*pp, p); return ;
} /*
* ini_putf() takes a printf() style format string and uses vsnprintf() to
* pass a value to ini_put(). This function is intended for placing
* data types that are not strings into the ini_file
*
* The other parameters are the same as those of ini_put().
*/
int ini_putf(struct ini_file *ini,
const char *sec,
const char *par,
const char *fmt,
...) {
char buffer[MAX_LINE];
va_list arg; va_start(arg, fmt); #ifdef _MSC_VER /* Microsoft Visual C++? */
/* VC++ messes around with _'s before vsnprintf(): */
#define vsnprintf _vsnprintf
#endif #if 1
vsnprintf(buffer, MAX_LINE, fmt, arg);
#else
vsprintf(buffer, fmt, arg );
assert(strlen(buffer) < MAX_LINE);
#endif
va_end(arg); return ini_put(ini, sec, par, buffer);
}

ini.cpp

调用

 static struct ini_file *gamedb = NULL;
BOOL CRobomoduleTestDlg::ResetConfig()
{
ini_put(gamedb, "System", "Half", "");
ini_put(gamedb, "InitialPose", "X", "0.0");
ini_put(gamedb, "InitialPose", "Y", "0.0");
ini_put(gamedb, "InitialPose", "theta", "0.0"); ini_put(gamedb, "TilingUnit_Pose", "XTrans", "0.0");
ini_put(gamedb, "TilingUnit_Pose", "YTrans", "0.0");
ini_put(gamedb, "TilingUnit_Pose", "Height", "1.10"); ini_put(gamedb, "Laser_TilingUnitO", "RotateX", "0.0");
ini_put(gamedb, "Laser_TilingUnitO", "RotateY", "0.0");
ini_put(gamedb, "Laser_TilingUnitO", "RotateZ", "0.785398163"); ini_put(gamedb, "Laser_TilingUnitO", "TransformX", "0.165");
ini_put(gamedb, "Laser_TilingUnitO", "TransformY", "0.0");
ini_put(gamedb, "Laser_TilingUnitO", "TransformZ", "0.0"); ini_put(gamedb, "LaserO", "CalibRotateX", "-0.023289177");
ini_put(gamedb, "LaserO", "CalibRotateY", "0.0");
ini_put(gamedb, "LaserO", "CalibRotateZ", "-0.01573419"); ini_put(gamedb, "LaserO", "CalibTransformX", "0.0");
ini_put(gamedb, "LaserO", "CalibTransformY", "0.0");
ini_put(gamedb, "LaserO", "CalibTransformZ", "0.0"); char buffer[];
_snprintf(buffer, sizeof buffer, "%s/%s", "D:", "config.ini"); int result = ini_write(gamedb,"config.ini");
ini_free(gamedb); gamedb=NULL ;
return TRUE;
} BOOL CRobomoduleTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
ini_free(gamedb);
gamedb = ini_read(NULL, NULL, NULL);
int err, line;
ini_free(gamedb);
gamedb = ini_read("config.ini", &err, &line);
if(ini_get(gamedb,"InitialPose", "X", NULL) != NULL)
{
const char* a=ini_get(gamedb, "InitialPose", "X", NULL);
InitialPoseX= atof(a);
}
if(ini_get(gamedb,"InitialPose", "Y", NULL) != NULL)
{
const char* a=ini_get(gamedb, "InitialPose", "Y", NULL);
InitialPoseY= atof(a);
}
if(ini_get(gamedb,"InitialPose", "theta", NULL) != NULL)
{
const char* a=ini_get(gamedb, "InitialPose", "theta", NULL);
InitialPoseTheta= atof(a);
}
if(ini_get(gamedb,"TilingUnit_Pose", "XTrans", NULL) != NULL)
{
const char* a=ini_get(gamedb, "TilingUnit_Pose", "XTrans", NULL);
XTrans= atof(a);
}
if(ini_get(gamedb,"TilingUnit_Pose", "YTrans", NULL) != NULL)
{
const char* a=ini_get(gamedb, "TilingUnit_Pose", "YTrans", NULL);
YTrans= atof(a);
}
if(ini_get(gamedb,"TilingUnit_Pose", "Height", NULL) != NULL)
{
const char* a=ini_get(gamedb, "TilingUnit_Pose", "Height", NULL);
Height= atof(a);
}
if(ini_get(gamedb,"Laser_TilingUnitO", "RotateX", NULL) != NULL)
{
const char* b=ini_get(gamedb, "Laser_TilingUnitO", "RotateX", NULL);
RotateX= atof(b);
}
if(ini_get(gamedb,"Laser_TilingUnitO", "RotateY", NULL) != NULL)
{
const char* a=ini_get(gamedb, "Laser_TilingUnitO", "RotateY", NULL);
RotateY= atof(a);
}
if(ini_get(gamedb,"Laser_TilingUnitO", "RotateZ", NULL) != NULL)
{
const char* a=ini_get(gamedb, "Laser_TilingUnitO", "RotateZ", NULL);
RotateZ= atof(a);
}
if(ini_get(gamedb,"Laser_TilingUnitO", "TransformX", NULL) != NULL)
{
const char* a=ini_get(gamedb, "Laser_TilingUnitO", "TransformX", NULL);
TransformX= atof(a);
}
if(ini_get(gamedb,"Laser_TilingUnitO", "TransformY", NULL) != NULL)
{
const char* a=ini_get(gamedb, "Laser_TilingUnitO", "TransformY", NULL);
TransformY= atof(a);
}
if(ini_get(gamedb,"Laser_TilingUnitO", "TransformZ", NULL) != NULL)
{
const char* a=ini_get(gamedb, "Laser_TilingUnitO", "TransformZ", NULL);
TransformZ= atof(a);
}
if(ini_get(gamedb,"LaserO", "CalibRotateX", NULL) != NULL)
{
const char* a=ini_get(gamedb, "LaserO", "CalibRotateX", NULL);
CalibRotateX= atof(a);
}
if(ini_get(gamedb,"LaserO", "CalibRotateY", NULL) != NULL)
{
const char* a=ini_get(gamedb, "LaserO", "CalibRotateY", NULL);
CalibRotateY= atof(a);
}
if(ini_get(gamedb,"LaserO", "CalibRotateZ", NULL) != NULL)
{
const char* a=ini_get(gamedb, "LaserO", "CalibRotateZ", NULL);
CalibRotateZ= atof(a);
}
if(ini_get(gamedb,"LaserO", "CalibTransformX", NULL) != NULL)
{
const char* a=ini_get(gamedb, "LaserO", "CalibTransformX", NULL);
CalibTransformX= atof(a);
}
if(ini_get(gamedb,"LaserO", "CalibTransformY", NULL) != NULL)
{
const char* a=ini_get(gamedb, "LaserO", "CalibTransformY", NULL);
CalibTransformY= atof(a);
}
if(ini_get(gamedb,"LaserO", "CalibTransformZ", NULL) != NULL)
{
const char* a=ini_get(gamedb, "LaserO", "CalibTransformZ", NULL);
CalibTransformZ= atof(a);
}
if(ini_get(gamedb,"System", "Half", NULL) != NULL)
{
const char* a=ini_get(gamedb, "System", "Half", NULL);
useHalf= atof(a);
}

参考:https://github.com/wernsey/rengine/blob/master/src/ini.c

C语言ini格式配置文件的读写的更多相关文章

  1. 纯C#的ini格式配置文件读写

    虽然C#里都是添加app.config 并且访问也很方便 ,有时候还是不习惯用他.那么我们来做个仿C++下的那种ini配置文件读写吧,其他人写的都是调用非托管kernel32.dll.我也用过 但是感 ...

  2. Python学习笔记:configparser(INI格式配置文件解析)

    在平时的开发中感觉INI格式的配置文件使用还是挺需要的,有时会使用一个单独的py来存放一些常量或者配置项,大多时候这样倒是挺好用的,但是如果某些配置项需要在运行时由用户来修改指定,比如很多app在关闭 ...

  3. delphi读写INI系统配置文件

    delphi读写INI系统配置文件 一.调用delphi内建单元 uses System.IniFiles; .使用类TIniFile .类TIniFile的主要方法和函数: {$IFDEF MSWI ...

  4. C#+Access 员工信息管理--简单的增删改查操作和.ini配置文件的读写操作。

    1.本程序的使用的语言是C#,数据库是Access2003.主要是对员工信息进行简单的增删改查操作和对.ini配置文件的读写操作. 2.代码运行效果如下: 功能比较简单.其中在得到查询结果后,在查询结 ...

  5. SHELL读取 ini 格式文件做配置文件

    ini文件格式一般都是由节.键.值三部分组成 格式: [第一节 ] 第一个键 = 值 第二个键 = 第二个值 [第二节 ] 第一个键 = val1,val2,val3 例子: [COM] KINGGO ...

  6. C语言解析Ini格式文件

    引用别人的博文: http://www.open-open.com/lib/view/open1402278076447.html 可以解析 INI 格式的字符串.解析文件.保存到文件. 下面是头文件 ...

  7. 纯C语言INI文件解析

    原地址:http://blog.csdn.net/foruok/article/details/17715969 在一个跨平台( Android .Windows.Linux )项目中配置文件用 IN ...

  8. Golang 入门系列(九) 如何读取YAML,JSON,INI等配置文件

    实际项目中,读取相关的系统配置文件是很常见的事情.今天就来说一说,Golang 是如何读取YAML,JSON,INI等配置文件的. 1. json使用 JSON 应该比较熟悉,它是一种轻量级的数据交换 ...

  9. 配置文件Java读写

    今天把配置文件的Bug修复了,总结一下Java配置文件如何读写 配置文件的格式 以.properties后缀结尾,内容不出现空格和双引号 //config.properties Driver=com. ...

随机推荐

  1. 获取linux服务进程号

    ps -ef | grep "服务名" | grep -v "grep" | awk '{print $2}' # ps -ef|grep "被查询的 ...

  2. 给hmailserver添加DKIM签名

    上一篇说了hmailserver如何设置反垃圾邮件功能,现在来说说如何让自己的hmailserver发出去的邮件不要被别人反垃圾了.在hmailserver的反垃圾邮件功能中有提到给垃圾评分标准,其中 ...

  3. vmware虚拟机的tomcat启动以后,主机无法访问

    处理: 关闭防火墙服务:/etc/init.d/iptables stop ..................... 在wmware中安装linux后安装好数据库,JDK及tomcat后启动服务,虚 ...

  4. 9.25中间件和Django的学过的知识总结

    2018-9-25 12:10:54 参考连接:http://www.cnblogs.com/liwenzhou/p/8761803.html 浏览器访问Django的过程 面试时容易问到   Dja ...

  5. aspectj 注解

    aspectj是一个面向切面编程的框架,即实现了aop,这不是spring,它本身很小,方便简洁,spring将其整合成自己的. 与spring本身对aop的支持不同,顾问采用正则表达式或者方法名或通 ...

  6. jdbc-------JDBCUtil类 工具类

    jdbcutil 主要处理的是 连接数据库, 和关闭各个流 1, 数据库连接的配置信息: mysql.properties (在工程的目录下)个人配置 url=jdbc:mysql://localho ...

  7. 在Spring的Bean注入中,即使你私有化构造函数,默认他还是会去调用你的私有构造函数去实例化

    在Spring的Bean注入中,即使你私有化构造函数,默认他还是会去调用你的私有构造函数去实例化. 如果我们想保证实例的单一性,就要在定义<bean>时加上factory-method=” ...

  8. Struts2 框架使用 核心以及其他详细配置

    因为在使用SSH框架的过程,关于struts2的配置比较繁琐,所以做个总结. 一.导入并且关联其他XML 1.   因为在核心配置文件(Struts2.xml)中,如果存在很多需要配置的Action项 ...

  9. linux 音频编程

    http://blog.csdn.net/sea918/article/details/7249216   1.音频开发模型: OSS(open sound system)  linux/unix 平 ...

  10. OLTP/OLAP

    原文地址:https://www.cnblogs.com/hhandbibi/p/7118740.html 数据处理大致可以分成两大类:联机事务处理OLTP(on-line transaction p ...