青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆 - 16, 文章 - 0, 評論 - 55, 引用 - 0
數據加載中……

跨平臺的INI處理源代碼

// IniFile.h

#ifndef INIFILE_H
#define INIFILE_H

#include < stdio.h >
#include < stdlib.h >
#include < string.h >

#ifndef OWP_DONT_DEF_FALSE
#ifndef FALSE
#define FALSE 0
#endif
#endif

#ifndef OWP_DONT_DEF_TRUE
#ifndef TRUE
#define TRUE 1
#endif
#endif

#ifndef OWP_DONT_DEF_BOOL
#ifndef BOOL
#define BOOL unsigned int
#endif
#endif

#ifndef OWP_DONT_DEF_CCHR
#ifndef CCHR
#define CCHR const char
#endif
#endif

#ifndef OWP_DONT_DEF_UCHR
#ifndef UCHR
#define UCHR unsigned char
#endif
#endif

#ifndef OWP_DONT_DEF_UCCHR
#ifndef UCCHR
#define UCCHR const unsigned char
#endif
#endif

#ifndef OWP_DONT_DEF_UINT
#ifndef UINT
#define UINT unsigned int
#endif
#endif

#ifndef OWP_DONT_DEF_WORD
#ifndef WORD
#define WORD unsigned short
#endif
#endif

#ifdef LINUX /* Remove CR, on unix systems. */
#define INI_REMOVE_CR
#define DONT_HAVE_STRUPR
#endif

#define tpNULL 0
#define tpSECTION 1
#define tpKEYVALUE 2
#define tpCOMMENT 3

struct ENTRY
{
char Type;
char *pText;
struct ENTRY *pPrev;
struct ENTRY *pNext;
};

typedef struct
{
struct ENTRY *pSec;
struct ENTRY *pKey;
char KeyText [128];
char ValText [128];
char Comment [255];
} EFIND;

/* Macros */
#define ArePtrValid(Sec,Key,Val) ((Sec!=NULL)&&(Key!=NULL)&&(Val!=NULL))

class CIniFile
{
public:
CIniFile (void)
??{
????m_pEntry = NULL;
????m_pCurEntry = NULL;
????m_result [0] = 0;
????m_pIniFile = NULL;
??}

??~CIniFile (void)
??{
????FreeAllMem ();
??}

BOOL OpenIniFile (CCHR *pFileName)
??{
????char Str [255];
????char *pStr;
????struct ENTRY *pEntry;
????
????FreeAllMem ();
????
????if (pFileName == NULL) { return FALSE; }
????if ((m_pIniFile = fopen (pFileName, "r")) == NULL) { return FALSE; }
????
????while (fgets (Str, 255, m_pIniFile) != NULL) {
??????pStr = strchr (Str, '\n');
??????if (pStr != NULL) { *pStr = 0; }
??????pEntry = MakeNewEntry ();
??????if (pEntry == NULL) { return FALSE; }
??????
??????#ifdef INI_REMOVE_CR
??????Len = strlen(Str);
??????if ( Len > 0 ) {
????????if ( Str[Len-1] == '\r' ) {
??????????Str[Len-1] = '\0';
????????}
??????}
??????#endif
??????
??????pEntry->pText = (char *)malloc (strlen (Str)+1);
??????if (pEntry->pText == NULL) {
????????FreeAllMem ();
????????return FALSE;
??????}
??????strcpy (pEntry->pText, Str);
??????pStr = strchr (Str,';');
??????if (pStr != NULL) { *pStr = 0; } /* Cut all comments */
??????if ( (strstr (Str, "[") > 0) && (strstr (Str, "]") > 0) ) /* Is Section */ {
????????pEntry->Type = tpSECTION;
??????} else {
????????if (strstr (Str, "=") > 0) {
??????????pEntry->Type = tpKEYVALUE;
????????} else {
??????????pEntry->Type = tpCOMMENT;
????????}
??????}
??????m_pCurEntry = pEntry;
????}
????fclose (m_pIniFile);
????m_pIniFile = NULL;
????return TRUE;
??}

void CloseIniFile ()
??{
????FreeAllMem ();
????if (m_pIniFile != NULL) {
??????fclose (m_pIniFile);
??????m_pIniFile = NULL;
????}
??}

bool WriteIniFile (CCHR *pFileName)
??{
????struct ENTRY *pEntry = m_pEntry;
????if (m_pIniFile != NULL) {
??????fclose (m_pIniFile);
????}
????if ((m_pIniFile = fopen (pFileName, "wb")) == NULL) {
??????FreeAllMem ();
??????return FALSE;
????}
????
????while (pEntry != NULL) {
??????if (pEntry->Type != tpNULL) {
??????#ifdef INI_REMOVE_CR
????????fprintf (m_pIniFile, "%s\n", pEntry->pText);
??????#else
????????fprintf (m_pIniFile, "%s\r\n", pEntry->pText);
??????#endif
??????}
??????pEntry = pEntry->pNext;
????}
????
????fclose (m_pIniFile);
????m_pIniFile = NULL;
????return TRUE;
??}
??
??bool??DeleteKey (CCHR *pSection, CCHR *pKey)
??{
????EFIND List;
????struct ENTRY *pPrev;
????struct ENTRY *pNext;
????
????if (FindKey (pSection, pKey, &List) == TRUE) {
??????pPrev = List.pKey->pPrev;
??????pNext = List.pKey->pNext;
??????if (pPrev) {
????????pPrev->pNext=pNext;
??????}
??????if (pNext) {
????????pNext->pPrev=pPrev;
??????}
??????FreeMem (List.pKey->pText);
??????FreeMem (List.pKey);
??????return TRUE;
????}
????return FALSE;
??}

??BOOL ReadBool (CCHR *pSection, CCHR *pKey, BOOL Default)
??{
????char Val [2] = {"0"};
????if (Default != 0) { Val [0] = '1'; }
????return (atoi (ReadString (pSection, pKey, Val))?1:0); /* Only allow 0 or 1 */
??}

int ReadInt (CCHR *pSection, CCHR *pKey, int Default)
??{
????char Val [12];
????sprintf (Val,"%d", Default);
????return (atoi (ReadString (pSection, pKey, Val)));
??}

double ReadDouble (CCHR *pSection, CCHR *pKey, double Default)
??{
????double Val;
????sprintf (m_result, "%1.10lE", Default);
????sscanf (ReadString (pSection, pKey, m_result), "%lE", &Val);
????return Val;
??}

CCHR *ReadString (CCHR *pSection, CCHR *pKey, CCHR *pDefault)
??{
????EFIND List;
????if (ArePtrValid (pSection, pKey, pDefault) == FALSE) { return pDefault; }
????if (FindKey (pSection, pKey, &List) == TRUE) {
??????strcpy (m_result, List.ValText);
??????return m_result;
????}
????return pDefault;
??}

void WriteBool (CCHR *pSection, CCHR *pKey, bool Value)
??{
????char Val [2] = {'0',0};
????if (Value != 0) { Val [0] = '1'; }
????WriteString (pSection, pKey, Val);
??}
??
void WriteInt (CCHR *pSection, CCHR *pKey, int Value)
??{
????char Val [12]; /* 32bit maximum + sign + \0 */
????sprintf (Val, "%d", Value);
????WriteString (pSection, pKey, Val);
??}

void WriteDouble (CCHR *pSection, CCHR *pKey, double Value)
??{
????char Val [32]; /* DDDDDDDDDDDDDDD+E308\0 */
????sprintf (Val, "%1.10lE", Value);
????WriteString (pSection, pKey, Val);
??}

void WriteString (CCHR *pSection, CCHR *pKey, CCHR *pValue)
??{
????EFIND List;
????char Str [255];
????
????if (ArePtrValid (pSection, pKey, pValue) == FALSE) { return; }
????if (FindKey (pSection, pKey, &List) == TRUE) {
??????sprintf (Str, "%s=%s%s", List.KeyText, pValue, List.Comment);
??????FreeMem (List.pKey->pText);
??????List.pKey->pText = (char *)malloc (strlen (Str)+1);
??????strcpy (List.pKey->pText, Str);
????} else {
??????if ((List.pSec != NULL) && (List.pKey == NULL)) /* section exist, Key not */ {
????????AddKey (List.pSec, pKey, pValue);
??????} else {
????????AddSectionAndKey (pSection, pKey, pValue);
??????}
????}
??}

protected:
??struct ENTRY *m_pEntry;
??struct ENTRY *m_pCurEntry;
??char m_result [255];
??FILE *m_pIniFile;
??
??void AddKey (struct ENTRY *pEntry, CCHR *pKey, CCHR *pValue)
??{
????char Text [255];
????sprintf (Text, "%s=%s", pKey, pValue);
????AddItemAt (pEntry, tpKEYVALUE, Text);
??}
??
??BOOL AddItem (char Type, CCHR *pText)
??{
????struct ENTRY *pEntry = MakeNewEntry ();
????if (pEntry == NULL) { return FALSE; }
????pEntry->Type = Type;
????pEntry->pText = (char*)malloc (strlen (pText) +1);
????if (pEntry->pText == NULL) {
??????free (pEntry);
??????return FALSE;
????}
????strcpy (pEntry->pText, pText);
????pEntry->pNext = NULL;
????if (m_pCurEntry != NULL) { m_pCurEntry->pNext = pEntry; }
????m_pCurEntry = pEntry;
????return TRUE;
??}
??
??bool AddItemAt (struct ENTRY *pEntryAt, char Mode, CCHR *pText)
??{
????struct ENTRY *pNewEntry;
????if (pEntryAt == NULL) { return FALSE; }
????pNewEntry = (struct ENTRY*) malloc (sizeof (ENTRY));
????if (pNewEntry == NULL) { return FALSE; }
????pNewEntry->pText = (char *) malloc (strlen (pText)+1);
????if (pNewEntry->pText == NULL) {
??????free (pNewEntry);
??????return FALSE;
????}
????strcpy (pNewEntry->pText, pText);
????if (pEntryAt->pNext == NULL) /* No following nodes. */ {
??????pEntryAt->pNext = pNewEntry;
??????pNewEntry->pNext = NULL;
????} else {
??????pNewEntry->pNext = pEntryAt->pNext;
??????pEntryAt->pNext = pNewEntry;
????}
????pNewEntry->pPrev = pEntryAt;
????pNewEntry->Type = Mode;
????return TRUE;
??}
??
??void FreeMem (void *pPtr)
??{
????if (pPtr != NULL) { free (pPtr); }
??}
??
??void FreeAllMem (void)
??{
????struct ENTRY *pEntry;
????struct ENTRY *pNextEntry;
????pEntry = m_pEntry;
????while (1) {
??????if (pEntry == NULL) { break; }
??????pNextEntry = pEntry->pNext;
??????FreeMem (pEntry->pText); /* Frees the pointer if not NULL */
??????FreeMem (pEntry);
??????pEntry = pNextEntry;
????}
????m_pEntry = NULL;
????m_pCurEntry = NULL;
??}
??
??bool FindKey (CCHR *pSection, CCHR *pKey, EFIND *pList)
??{
????char Search [130];
????char Found [130];
????char Text [255];
????char *pText;
????struct ENTRY *pEntry;
????pList->pSec = NULL;
????pList->pKey = NULL;
????pEntry = FindSection (pSection);
????if (pEntry == NULL) { return FALSE; }
????pList->pSec = pEntry;
????pList->KeyText[0] = 0;
????pList->ValText[0] = 0;
????pList->Comment[0] = 0;
????pEntry = pEntry->pNext;
????if (pEntry == NULL) { return FALSE; }
????sprintf (Search, "%s",pKey);
????strupr (Search);
????while (pEntry != NULL) {
??????if ((pEntry->Type == tpSECTION) || /* Stop after next section or EOF */
????????(pEntry->Type == tpNULL )) {
????????return FALSE;
??????}
??????if (pEntry->Type == tpKEYVALUE) {
????????strcpy (Text, pEntry->pText);
????????pText = strchr (Text, ';');
????????if (pText != NULL) {
??????????strcpy (pList->Comment, pText);
??????????*pText = 0;
????????}
????????pText = strchr (Text, '=');
????????if (pText != NULL) {
??????????*pText = 0;
??????????strcpy (pList->KeyText, Text);
??????????strcpy (Found, Text);
??????????*pText = '=';
??????????strupr (Found);
??????????/* printf ("%s,%s\n", Search, Found); */
??????????if (strcmp (Found,Search) == 0) {
????????????strcpy (pList->ValText, pText+1);
????????????pList->pKey = pEntry;
????????????return TRUE;
??????????}
????????}
??????}
??????pEntry = pEntry->pNext;
????}
????return NULL;
??}

??bool AddSectionAndKey (CCHR *pSection, CCHR *pKey, CCHR *pValue)
??{
????char Text [255];
????sprintf (Text, "[%s]", pSection);
????if (AddItem (tpSECTION, Text) == FALSE) { return FALSE; }
????sprintf (Text, "%s=%s", pKey, pValue);
????return AddItem (tpKEYVALUE, Text)? 1 : 0;
??}
??
??struct ENTRY *MakeNewEntry (void)
??{
????struct ENTRY *pEntry;
????pEntry = (struct ENTRY *)malloc (sizeof (ENTRY));
????if (pEntry == NULL) {
??????FreeAllMem ();
??????return NULL;
????}
????if (m_pEntry == NULL) {
??????m_pEntry = pEntry;
????}
????pEntry->Type = tpNULL;
????pEntry->pPrev = m_pCurEntry;
????pEntry->pNext = NULL;
????pEntry->pText = NULL;
????if (m_pCurEntry != NULL) {
??????m_pCurEntry->pNext = pEntry;
????}
????return pEntry;
??}
??
??struct ENTRY *FindSection (CCHR *pSection)
??{
????char Sec [130];
????char iSec [130];
????struct ENTRY *pEntry;
????sprintf (Sec, "[%s]", pSection);
????strupr (Sec);
????pEntry = m_pEntry; /* Get a pointer to the first Entry */
????while (pEntry != NULL) {
??????if (pEntry->Type == tpSECTION) {
????????strcpy (iSec, pEntry->pText);
????????strupr (iSec);
????????if (strcmp (Sec, iSec) == 0) {
??????????return pEntry;
????????}
??????}
??????pEntry = pEntry->pNext;
????}
????return NULL;
??}

??#ifdef DONT_HAVE_STRUPR
??/* DONT_HAVE_STRUPR is set when INI_REMOVE_CR is defined */
??void strupr( char *str )
??{
????// We dont check the ptr because the original also dont do it.
????while (*str != 0) {
??????if ( islower( *str ) ) {
????????*str = toupper( *str );
??????}
??????str++;
????}
??}
??#endif
??
private:
};

#endif

#ifdef INIFILE_TEST_THIS_FILE
int main (void)
{
??CIniFile iFile;
??printf ("Hello World\n");
??iFile.OpenIniFile ("Test.Ini");
??iFile.WriteString ("Test", "Name", "Value");
??iFile.WriteString ("Test", "Name", "OverWrittenValue");
??iFile.WriteString ("Test", "Port", "COM1");
??iFile.WriteString ("Test", "User", "James Brown jr.");
??iFile.WriteString ("Configuration", "eDriver", "MBM2.VXD");
??iFile.WriteString ("Configuration", "Wrap", "LPT.VXD");
??iFile.WriteInt ("IO-Port", "Com", 2);
??iFile.WriteBool ("IO-Port", "IsValid", 0);
??iFile.WriteDouble ("TheMoney", "TheMoney", 67892.00241);
??iFile.WriteInt ("Test" , "ToDelete", 1234);
??iFile.WriteIniFile ("Test.Ini");
??printf ("Key ToDelete created. Check ini file. Any key to continue");
??while (!kbhit());
??iFile.OpenIniFile ("Test.Ini");
??iFile.DeleteKey ("Test"?? , "ToDelete");
??iFile.WriteIniFile ("Test.Ini");
??printf ("[Test] Name = %s\n", iFile.ReadString ("Test", "Name", "NotFound"));
??printf ("[Test] Port = %s\n", iFile.ReadString ("Test", "Port", "NotFound"));
??printf ("[Test] User = %s\n", iFile.ReadString ("Test", "User", "NotFound"));
??printf ("[Configuration] eDriver = %s\n", iFile.ReadString ("Configuration", "eDriver", "NotFound"));
??printf ("[Configuration] Wrap = %s\n", iFile.ReadString ("Configuration", "Wrap", "NotFound"));
??printf ("[IO-Port] Com = %d\n", iFile.ReadInt ("IO-Port", "Com", 0));
??printf ("[IO-Port] IsValid = %d\n", iFile.ReadBool ("IO-Port", "IsValid", 0));
??printf ("[TheMoney] TheMoney = %1.10lf\n", iFile.ReadDouble ("TheMoney", "TheMoney", 111));
??iFile.CloseIniFile ();
??return 0;
}
#endif

posted on 2006-05-31 13:20 cyantree 閱讀(887) 評論(1)  編輯 收藏 引用

評論

# re: 跨平臺的INI處理源代碼  回復  更多評論   

混合類型的編碼,又C又類的。
2006-05-31 13:31 | LOGOS
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美77777| 亚洲精品四区| 伊人久久亚洲美女图片| 国产精品二区在线观看| 欧美午夜精品久久久久久孕妇 | 欧美jizzhd精品欧美巨大免费| 久久国产综合精品| 久久中文字幕一区| 欧美激情综合| 亚洲精品欧美精品| 亚洲婷婷在线| 久久精品99无色码中文字幕| 玖玖玖国产精品| 欧美日韩福利视频| 国产酒店精品激情| 精品成人乱色一区二区| 99精品视频免费观看视频| 亚洲欧美经典视频| 久久伊人亚洲| 亚洲精品黄网在线观看| 一区二区三区偷拍| 久久精品最新地址| 欧美视频一区二| 国产在线精品二区| 一本不卡影院| 久久久精品国产免大香伊| 亚洲高清久久久| 亚洲欧美日韩国产综合| 嫩模写真一区二区三区三州| 国产精品久久婷婷六月丁香| 亚洲高清不卡一区| 亚洲欧美综合v| 亚洲国产日韩欧美在线99| 亚洲男人的天堂在线| 欧美激情片在线观看| 国产综合精品| 午夜精品久久久99热福利| 欧美大尺度在线观看| 亚洲欧美在线一区| 欧美日韩在线播| 久久久久国产一区二区| 欧美中文字幕| 男人天堂欧美日韩| 亚洲综合欧美| 欧美日韩极品在线观看一区| 国产自产在线视频一区| 亚洲视频免费| 亚洲精品极品| 欧美高清视频在线播放| 伊人影院久久| 久久婷婷蜜乳一本欲蜜臀| 亚洲一区三区在线观看| 欧美日本精品| 亚洲美女91| 亚洲国产欧洲综合997久久| 蜜桃伊人久久| 亚洲激情视频在线观看| 猛男gaygay欧美视频| 香蕉久久精品日日躁夜夜躁| 国产精品国色综合久久| 亚洲小视频在线| 99re视频这里只有精品| 欧美日韩国产大片| 这里是久久伊人| 亚洲精品中文字幕女同| 欧美老女人xx| 亚洲一区二区三区激情| 中文一区二区| 国产美女精品免费电影| 久久国产一区二区| 久久精品日产第一区二区三区| 国产最新精品精品你懂的| 久久久欧美精品| 玖玖玖免费嫩草在线影院一区| 亚洲国产欧美一区二区三区丁香婷| 巨胸喷奶水www久久久免费动漫| 久久精品国产99精品国产亚洲性色| 国产亚洲精品一区二区| 欧美成人三级在线| 欧美日韩国产系列| 香蕉国产精品偷在线观看不卡 | 久久久久久夜| 久久精品99国产精品酒店日本| 加勒比av一区二区| 亚洲国产精品视频一区| 欧美日韩国产影片| 欧美专区日韩专区| 久久综合九色综合欧美就去吻| 亚洲精品系列| 亚洲女人av| 91久久精品美女高潮| 一区二区不卡在线视频 午夜欧美不卡'| 欧美日韩一区二区三区四区五区| 午夜国产精品影院在线观看| 久久精品官网| aa级大片欧美三级| 午夜激情一区| 99在线精品观看| 亚洲欧美另类在线| 亚洲国产精品精华液2区45| 日韩一级免费| 久久精品视频导航| 欧美精品一区二区高清在线观看| 亚洲欧美日韩另类| 欧美a级一区| 久久久久国产精品麻豆ai换脸| 噜噜噜躁狠狠躁狠狠精品视频| 一区二区电影免费观看| 欧美一区国产二区| 中文日韩在线视频| 在线欧美亚洲| 亚洲美女视频在线观看| 国产日韩欧美制服另类| 亚洲国内在线| 精品96久久久久久中文字幕无| 亚洲人午夜精品免费| 国产综合久久久久久| 亚洲宅男天堂在线观看无病毒| 亚洲日本精品国产第一区| 性欧美办公室18xxxxhd| 亚洲天堂第二页| 欧美激情亚洲国产| 欧美成人免费全部| 国产一区二区三区直播精品电影| 亚洲免费观看在线视频| 亚洲国产成人av| 欧美一区影院| 久久九九免费视频| 国产精品视频免费一区| 亚洲精品久久在线| 亚洲欧洲在线播放| 久久亚洲精选| 久久噜噜亚洲综合| 国产亚洲一二三区| 午夜视频在线观看一区二区| 亚洲一区二区免费视频| 欧美金8天国| 亚洲精品乱码久久久久久蜜桃91| 精品粉嫩aⅴ一区二区三区四区| 欧美一区二区三区播放老司机| 亚洲午夜激情免费视频| 欧美日韩八区| 日韩午夜中文字幕| 99在线精品视频在线观看| 欧美黄色aaaa| 亚洲黄色在线视频| 亚洲精品免费在线| 欧美激情在线狂野欧美精品| 亚洲激情婷婷| 中文网丁香综合网| 国产精品普通话对白| 午夜精品在线观看| 久久香蕉国产线看观看av| 永久免费毛片在线播放不卡| 久久频这里精品99香蕉| 欧美黑人国产人伦爽爽爽| 亚洲精品自在久久| 欧美日韩高清一区| 亚洲欧美日韩国产成人| 久久综合图片| 亚洲精品视频二区| 国产精品v亚洲精品v日韩精品| 一区二区三区高清在线观看| 亚洲综合日韩| 极品尤物一区二区三区| 欧美黑人在线播放| 亚洲一区二区精品| 老司机午夜精品视频| 一本久久a久久精品亚洲| 国产综合色在线视频区| 久久久久久久999| 欧美激情视频网站| 亚洲综合精品四区| 在线免费观看日本欧美| 欧美精品在线免费| 午夜久久一区| 亚洲国产一区二区三区高清| 中文日韩电影网站| 黄色成人91| 欧美天堂亚洲电影院在线播放| 亚洲欧美日韩一区在线观看| 蜜臀av在线播放一区二区三区| 一本色道精品久久一区二区三区| 国产美女诱惑一区二区| 蜜臀久久99精品久久久画质超高清 | 久久久久亚洲综合| 日韩亚洲综合在线| 免费成人高清视频| 欧美一级大片在线观看| 亚洲精品一区二区网址| 国产日韩欧美二区| 国产精品v欧美精品v日韩精品| 老鸭窝亚洲一区二区三区| 亚洲视频在线一区| 亚洲韩国日本中文字幕| 久久一二三区| 欧美在线视频免费| 亚洲资源av| 亚洲深夜影院| 99re6热在线精品视频播放速度|