home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1998 August / VPR9808B.BIN / APUPDATE / VC / Tx300d / TX300D.LZH / PROF.C < prev    next >
Text File  |  1997-03-27  |  4KB  |  177 lines

  1. // WZ EDITOR 標準TLL INIファイル操作
  2. // Thanks dieさん
  3.  
  4. // prof -- INIファイル操作(将来はレジストリ対応かな)
  5.  
  6. //{###INIファイル操作}
  7. //任意のINIファイルやWZ.INIファイルから、データを読み込んだり、
  8. //データを書き込んだりする機能を提供します。
  9. //利用方法:
  10. //[1]#include "prof.h"
  11. //[2]変数を用意
  12. //TxProfile prof;
  13. //[3]profWzIniNewかprofWzDirNewかprofNewを使って初期化
  14. //[4]profReadIntやprofWriteIntでアクセス
  15. //[5]アクセスが終わったらprofDeleteしてください
  16. //利用例:filer.c
  17. //thanks dieさん
  18.  
  19. #include "wintxx.h"
  20.  
  21. #export
  22. typedef struct tagTxProfile
  23. {
  24.     mchar m_szPath[CCHPATHNAME];
  25.     mchar m_szSection[32];
  26. } TxProfile;
  27. #endexport
  28.  
  29. void TXAPI profNew(TxProfile* pProf, mchar* pPath, mchar* pSection)
  30. {
  31. // 初期化(一般用)
  32. // pPathでINIファイル名、
  33. // pSectionでアクセスするセクションを指定してください
  34.     strcpy(pProf->m_szPath, pPath);
  35.     strcpy(pProf->m_szSection, pSection);
  36. }
  37.  
  38. void TXAPI profWzDirNew(TxProfile* pProf, mchar* pPath, mchar* pSection)
  39. {
  40. // 初期化(WZディレクトリ内のINIファイル用)
  41. // pPathでINIファイル名、
  42. // pSectionでアクセスするセクションを指定してください
  43.     mchar sz[CCHPATHNAME];
  44. #if 1//2.00E ユーザ毎設定対応
  45.     pathFullConfig(sz,pPath);
  46. #else
  47.     strcpy(sz, text->szexedir);
  48.     strcat(sz, pPath);
  49. #endif
  50.     profNew(pProf, sz, pSection);
  51. }
  52.  
  53. void TXAPI profWzIniNew(TxProfile* pProf, mchar* pSection)
  54. {
  55. // 初期化(WZ.INI専用)
  56. // pSectionでアクセスするセクションを指定してください
  57.     profWzDirNew(pProf, "wz.ini", pSection);
  58. }
  59.  
  60.  
  61. void TXAPI profDelete(TxProfile* pProf)
  62. {
  63. // 後始末(デストラクタ)
  64.     /// 今の所なにもする必要はない
  65. }
  66.  
  67.  
  68. void TXAPI profWriteStr(TxProfile* pProf, mchar* pKey, mchar* pStr)
  69. {
  70. // 文字列出力
  71. // データ名pKeyの内容を文字列pStrとします
  72.     WritePrivateProfileString(    pProf->m_szSection,
  73.                                 pKey,
  74.                                 pStr,
  75.                                 pProf->m_szPath);
  76. }
  77.  
  78.  
  79. void TXAPI profWriteInt(TxProfile* pProf, mchar* pKey, int nVal)
  80. {
  81. // 数値出力
  82. // データ名pKeyの内容を数値nValとします
  83.     mchar sz[20];
  84.     sprintf(sz, "%d", nVal);
  85.     profWriteStr(pProf, pKey, sz);
  86. }
  87.  
  88.  
  89. void TXAPI profReadStr(
  90.         TxProfile* pProf, mchar* pKey, mchar* pBuf, int nMax, mchar* pDef)
  91. {
  92. // 文字列入力
  93. // データ名pKeyの内容を文字列バッファpBufに読み込みます
  94. // バッファのサイズをnMaxに指定してください。最大nMax-1バイト読み込みます
  95. // pDefには、データ名pKeyが見つからなかった時にpBufにセットする内容を指定します。
  96.     GetPrivateProfileString(pProf->m_szSection,
  97.                             pKey,
  98.                             pDef,
  99.                             pBuf,
  100.                             nMax,
  101.                             pProf->m_szPath);
  102. }
  103.  
  104.  
  105. int TXAPI profReadInt(TxProfile* pProf, mchar* pKey, int nDef)
  106. {
  107. // 数値入力
  108. // データ名pKeyの内容を読み込みます。読み込んだ数値を返します。
  109. // nDefには、データ名pKeyが見つからなかった時に返す値を指定します。
  110.     mchar szBuf[20], szDef[20];
  111.     sprintf(szDef, "%d", nDef);
  112.     profReadStr(pProf, pKey, szBuf, sizeof (szBuf), szDef);
  113.     return atoi(szBuf);
  114. }
  115.  
  116.  
  117. void TXAPI profReadWriteStr(
  118.         TxProfile* pProf, mchar* pKey, mchar* pBuf, int nMax, mchar* pDef,BOOL fWrite)
  119. {
  120. // 文字列入出力
  121. // fWriteがFALSEなら、profReadStrします。
  122. // fWriteがTRUEなら、profWriteStr(pProf,pKey,pBuf)します。
  123. //1.00Dで追加
  124.     if (fWrite) {
  125.         profWriteStr(pProf,pKey,pBuf);
  126.     } else {
  127.         profReadStr(pProf,pKey,pBuf,nMax,pDef);
  128.     }
  129. }
  130.  
  131.  
  132. int TXAPI profReadWriteInt(TxProfile* pProf, mchar* pKey,int* nVal,int nDef,BOOL fWrite)
  133. {
  134. // 数値入出力
  135. // fWriteがFALSEなら、*nVal = profReadInt(pProf,pKey,nDef)します。
  136. // fWriteがTRUEなら、profWriteInt(pProf,pKey,*nVal)します。
  137. // *nValを返します。
  138. //1.00Dで追加
  139.     if (fWrite) {
  140.         profWriteInt(pProf,pKey,*nVal);
  141.     } else {
  142.         *nVal = profReadInt(pProf,pKey,nDef);
  143.     }
  144.     return *nVal;
  145. }
  146.  
  147. int TXAPI profReadWriteIntW(TxProfile* pProf, mchar* pKey,short* nVal,int nDef,BOOL fWrite)
  148. {
  149. // 数値入出力
  150. // fWriteがFALSEなら、*nVal = profReadInt(pProf,pKey,nDef)します。
  151. // fWriteがTRUEなら、profWriteInt(pProf,pKey,*nVal)します。
  152. // *nValを返します。
  153. //1.00Dで追加
  154.     if (fWrite) {
  155.         profWriteInt(pProf,pKey,*nVal);
  156.     } else {
  157.         *nVal = profReadInt(pProf,pKey,nDef);
  158.     }
  159.     return *nVal;
  160. }
  161.  
  162. int TXAPI profReadWriteIntB(TxProfile* pProf, mchar* pKey,signed char* nVal,int nDef,BOOL fWrite)
  163. {
  164. // 数値入出力
  165. // fWriteがFALSEなら、*nVal = profReadInt(pProf,pKey,nDef)します。
  166. // fWriteがTRUEなら、profWriteInt(pProf,pKey,*nVal)します。
  167. // *nValを返します。
  168. //1.00Dで追加
  169.     if (fWrite) {
  170.         profWriteInt(pProf,pKey,*nVal);
  171.     } else {
  172.         *nVal = profReadInt(pProf,pKey,nDef);
  173.     }
  174.     return *nVal;
  175. }
  176.  
  177.