中国开发网: 论坛: 程序员情感CBD: 贴子 558387
Fish: ini.h
/***************************************************************************
ini.h - Ini database definition

--------------------------------------------------------------------
begin : Fri Apr 21 2000
copyright : (C) 2000 by Simon White
email : s_a_white@email.com
***************************************************************************/

#ifndef _ini_h_
#define _ini_h_

#include <stdio.h>

// =======================================================================
// 原 libini.h 内容

#ifdef __cplusplus
extern "C" {
#endif

#include <string.h>

#define INI_ADD_EXTRAS

// 清除了关于 Windows 系统的没必要的定义
// #define INI_LINKAGE

/* DLL building support on win32 hosts */
//#ifndef INI_EXTERN
//#define extern extern
//#endif

/* Compatibility with future C++ code */
#ifndef ini_fd_t
#define ini_fd_t ini_fd_t
typedef void* ini_fd_t;
#endif


/* Rev 1.2 增加新函数 */
extern ini_fd_t ini_open (const char *name, const char *mode,
const char *comment);
extern int ini_close (ini_fd_t fd);
extern int ini_flush (ini_fd_t fd);
extern int ini_delete (ini_fd_t fd);

/* Rev 1.2 为了方便些增加这些函数, 也可以通过 ini_writeString 来实现这些 */
extern int ini_locateKey (ini_fd_t fd, const char *key);
extern int ini_locateHeading (ini_fd_t fd, const char *heading);
extern int ini_deleteKey (ini_fd_t fd);
extern int ini_deleteHeading (ini_fd_t fd);

extern const char * ini_currentKey (ini_fd_t fd);
extern const char * ini_currentHeading (ini_fd_t fd);

/* Returns the number of bytes required to be able to read the key as a
* string from the file. (1 should be added to this length to account
* for a NULL character). If delimiters are used, returns the length
* of the next data element in the key to be read */
extern int ini_dataLength (ini_fd_t fd);

/* 默认的数据类型操作
* Arrays implemented to help with reading, for writing you should format the
* complete array as a string and perform an ini_writeString. */
extern int ini_readString (ini_fd_t fd, char *str, size_t size);
extern int ini_writeString (ini_fd_t fd, const char *str);
extern int ini_readInt (ini_fd_t fd, int *value);


#ifdef INI_ADD_EXTRAS
/* 读操作 */
extern int ini_readLong (ini_fd_t fd, long *value);
extern int ini_readDouble (ini_fd_t fd, double *value);
extern int ini_readBool (ini_fd_t fd, int *value);

/* 写操作 */
extern int ini_writeInt (ini_fd_t fd, int value);
extern int ini_writeLong (ini_fd_t fd, long value);
extern int ini_writeDouble (ini_fd_t fd, double value);
extern int ini_writeBool (ini_fd_t fd, int value);

/* 额外的函数 */
extern int ini_append (ini_fd_t fddst, ini_fd_t fdsrc);
#endif /* INI_ADD_EXTRAS */

#ifdef __cplusplus
}
#endif


//==========================================================================
// 原 headings.h 的内容

struct keys_tag;
struct ini_t;

// 保存节(section)/头(heading) 信息的链表结构
struct section_tag
{
char *heading;
struct key_tag *first;
struct key_tag *last;
struct key_tag *selected;
struct section_tag *pNext;
struct section_tag *pPrev;
};

static struct section_tag *__ini_addHeading (struct ini_t *ini, char *heading);
static struct section_tag *__ini_faddHeading (struct ini_t *ini, FILE *file, long pos, size_t length);
static struct section_tag *__ini_createHeading (struct ini_t *ini, char *heading);
static void __ini_deleteHeading (struct ini_t *ini);
static struct section_tag *__ini_locateHeading (struct ini_t *ini, const char *heading);


//==========================================================================
// 原 keys.h 的内容

struct ini_t;
struct section_tag;

// 保存键值信息的链表结构
struct key_tag
{
char *key;
long pos;
size_t length;
struct key_tag *pNext;
struct key_tag *pPrev;
};

static struct key_tag *__ini_addKey (struct ini_t *ini, char *key);
static struct key_tag *__ini_faddKey (struct ini_t *ini, FILE *file, long pos, size_t length);
static struct key_tag *__ini_createKey (struct ini_t *ini, char *key);
static void __ini_deleteKey (struct ini_t *ini);
static struct key_tag *__ini_locateKey (struct ini_t *ini, const char *key);
static size_t __ini_averageLengthKey (struct section_tag *current_h);


//=========================================================================
// 原 ini.h 的内容

typedef enum {INI_NEW, INI_EXIST, INI_READ} ini_mode_t;

enum
{
INI_NONE = 0,
INI_MODIFIED = 1 << 0,
INI_NEWFILE = 1 << 1,
INI_BACKUP = 1 << 2, // Create backup file 创建备份文件
INI_CASE = 1 << 3 // Case sensitive 大小写敏感
};

// 包含某个 ini 文件所有信息的数据库
// Database containing all information about an ini file.
typedef struct ini_t
{
char *filename;
FILE *ftmp; // Temporary work file 临时工作文件
ini_mode_t mode; // Access mode 存取模式
int flags;

struct section_tag *first;
struct section_tag *last;
struct section_tag *selected;
char *heading; // Last written section in tmp file. 临时文件中写的最后一个节(section)
struct section_tag tmpSection;
struct key_tag tmpKey;

} ini_t;

static void __ini_strtrim (char *str);

#endif // _ini_h_
大家都是出来卖的,何苦自己人为难自己人
那些活好的,或者活新的,或者花样多的,
或者老板拉皮条功夫好能拉到肯多花钱的客的,
拜托不要老是打击年老色衰的同行了

老鱼记事 老鱼侃棋 老鱼围脖


相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录