00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "rcs_defs.hh"
00018
00019 #ifdef EXTERN_C_STD_HEADERS
00020 extern "C" {
00021 #endif
00022
00023 #ifndef NO_STDIO
00024 #include <stdio.h>
00025 #endif
00026 #include <string.h>
00027 #include <ctype.h>
00028 #include <stdlib.h>
00029 #include <stdarg.h>
00030
00031 #ifdef EXTERN_C_STD_HEADERS
00032 }
00033 #endif
00034
00035
00036
00037 #include "inifile.h"
00038 #include "rcs_prnt.hh"
00039
00040 INIFILE::INIFILE()
00041 {
00042 #ifndef NO_STDIO
00043 fp = NULL;
00044 #endif
00045
00046 #ifdef INIFILE_USE_INET_FILES
00047 ifp = NULL;
00048 #endif
00049 }
00050
00051 INIFILE::INIFILE(const char *path)
00052 {
00053 #ifndef INIFILE_USE_INET_FILES
00054 if (NULL == (fp = fopen(path, "r")))
00055 {
00056 fprintf(stderr, "can't open %s\n", path);
00057 }
00058 #else
00059 if (NULL == (ifp = inet_file_open(path,"r")))
00060 {
00061 rcs_print_error("can't open %s\n",path);
00062 }
00063 #endif
00064 }
00065
00066 INIFILE::~INIFILE()
00067 {
00068 #ifdef INIFILE_USE_INET_FILES
00069 if(NULL != ifp)
00070 {
00071 inet_file_close(ifp);
00072 }
00073 #else
00074 #ifndef NO_STDIO
00075 if (NULL != fp)
00076 {
00077 fclose(fp);
00078 }
00079 #endif
00080 #endif
00081 }
00082
00083 const int INIFILE::open(const char *path)
00084 {
00085 #ifndef INIFILE_USE_INET_FILES
00086 if (NULL == (fp = fopen(path, "r")))
00087 {
00088 return -1;
00089 }
00090 #else
00091 if (NULL == (ifp = inet_file_open(path, "r")))
00092 {
00093 return -1;
00094 }
00095 #endif
00096 return 0;
00097 }
00098
00099 const int INIFILE::close()
00100 {
00101 int retval = 0;
00102 #ifndef NO_STDIO
00103 if (fp != NULL)
00104 {
00105 retval = fclose(fp);
00106 fp = NULL;
00107 }
00108 #endif
00109 #ifdef INIFILE_USE_INET_FILES
00110 if (ifp != NULL)
00111 {
00112 retval = inet_file_close(ifp);
00113 ifp = NULL;
00114 }
00115 #endif
00116 return retval;
00117 }
00118
00119 const char * INIFILE::find(const char *tag, const char *section)
00120 {
00121 #ifndef INIFILE_USE_INET_FILES
00122 return iniFind(fp, tag, section);
00123 #else
00124 return iniFind(ifp, tag, section);
00125 #endif
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 int INIFILE::section(const char *section,
00139 INIFILE_ENTRY array[],
00140 int max)
00141 {
00142 #ifndef INIFILE_USE_INET_FILES
00143 return iniSection(fp, section, array, max);
00144 #else
00145 return iniSection(ifp, section, array, max);
00146 #endif
00147 }
00148
00149 const int INIFILE::valid()
00150 {
00151 #ifndef INIFILE_USE_INET_FILES
00152 if (NULL == fp)
00153 return 0;
00154 #else
00155 if (NULL == ifp)
00156 return 0;
00157 #endif
00158 return 1;
00159 }