Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

inifile.cc

Go to the documentation of this file.
00001 
00002 /*
00003    inifile.cc
00004 
00005    INI file reader
00006 
00007    Modification history:
00008 
00009    18-Dec-1997  FMP split out C code into _inifile.c
00010    7-Nov-1997  FMP fixed bug in afterequal so that it terminates at a 0
00011    25-Jul-1996  FMP added find_section() and ::section()
00012    11-Jul-1996  Fred Proctor made sure ini_find() returned NULL if a
00013    section were provided and no match was detected when the section
00014    was left; fixed bug which required the last line to have a newline
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>              /* FILE *, fopen(), fclose(), NULL */
00025 #endif
00026 #include <string.h>             /* strstr() */
00027 #include <ctype.h>              /* isspace() */
00028 #include <stdlib.h>             /* exit() */
00029 #include <stdarg.h>             /* va_list */
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    given 'section' and array of strings, fills strings with what was
00130    found in the section, one line per string. Comments and blank lines
00131    are omitted. 'array' is assumed to be allocated, of 'max' entries
00132    of size INIFILE_MAX_LINELEN.
00133 
00134    Returns number of entries found; 0 if section is there but no entries
00135    in it, or -1 if section is not there.
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 }

Generated on Sun Dec 2 15:56:50 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001