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

inifile.h File Reference

#include "rcs_defs.hh"
#include <stdio.h>

Include dependency graph for inifile.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Data Structures

struct  INIFILE_ENTRY

Defines

#define INIFILE_MAX_LINELEN   256
#define COMMENT_CHAR   ';'

Functions

const char * iniFind (void *fp, const char *tag, const char *section)
int iniSection (void *fp, const char *section, INIFILE_ENTRY array[], int max)


Define Documentation

#define INIFILE_MAX_LINELEN   256
 

Definition at line 36 of file inifile.h.

#define COMMENT_CHAR   ';'
 

Definition at line 38 of file inifile.h.


Function Documentation

const char* iniFind void *    fp,
const char *    tag,
const char *    section
 

Definition at line 209 of file _inifile.c.

00210 {
00211   static char line[INIFILE_MAX_LINELEN + 2];    /* 1 for newline, 1 for NULL */
00212   static char bracketsection[INIFILE_MAX_LINELEN + 2];
00213   char *nonwhite;
00214   int newlinepos;               /* position of newline to strip */
00215   int len;
00216   char tagend;
00217   char *value_string;
00218   char *end_value_string;
00219   /* check valid file */
00220   if (NULL == fp)
00221     return NULL;
00222 
00223   /* start from beginning */
00224 #ifndef INIFILE_USE_INET_FILES
00225   rewind ((FILE *) fp);
00226 #else
00227   inet_file_rewind ((INET_FILE *) fp);
00228 #endif
00229 
00230   /* check for section first-- if it's non-NULL, then position file at line
00231      after [section] */
00232   if (NULL != section)
00233     {
00234 #ifndef NO_STDIO
00235       sprintf (bracketsection, "[%s]", section);
00236 #else
00237       strcpy (bracketsection, "[");
00238       strcat (bracketsection, section);
00239       strcat (bracketsection, "]");
00240 #endif
00241 
00242       /* find [section], and position fp just after it */
00243 
00244 #ifndef INIFILE_USE_INET_FILES
00245       while (!feof ((FILE *) fp))
00246 #else
00247       while (!inet_file_eof ((INET_FILE *) fp))
00248 #endif
00249         {
00250 
00251 
00252 #ifndef INIFILE_USE_INET_FILES
00253           if (NULL == fgets (line, INIFILE_MAX_LINELEN + 1, (FILE *) fp))
00254             {
00255               /* got to end of file without finding it */
00256               return NULL;
00257             }
00258 #else
00259           if (NULL ==
00260               inet_file_gets (line, INIFILE_MAX_LINELEN + 1,
00261                               (INET_FILE *) fp))
00262             {
00263               /* got to end of file without finding it */
00264               return NULL;
00265             }
00266 #endif
00267           /* got a line */
00268 
00269           /* strip off newline */
00270           newlinepos = strlen (line) - 1;       /* newline is on back from 0 */
00271           if (newlinepos < 0)
00272             {
00273               newlinepos = 0;
00274             }
00275           if (line[newlinepos] == '\n')
00276             {
00277               line[newlinepos] = 0;     /* make the newline 0 */
00278             }
00279 
00280           if (NULL == (nonwhite = skipwhite (line)))
00281             {
00282               /* blank line-- skip */
00283               continue;
00284             }
00285 
00286           /* not a blank line, and nonwhite is first char */
00287           if (0 !=
00288               strncmp (bracketsection, nonwhite, strlen (bracketsection)))
00289             {
00290               /* not on this line */
00291               continue;
00292             }
00293 
00294           /* it matches-- fp is now set up for search on tag */
00295           break;
00296         }
00297     }
00298 
00299 #ifndef INIFILE_USE_INET_FILES
00300   while (!feof ((FILE *) fp))
00301 #else
00302   while (!inet_file_eof ((INET_FILE *) fp))
00303 #endif
00304     {
00305       /* check for end of file */
00306 #ifndef INIFILE_USE_INET_FILES
00307       if (NULL == fgets (line, INIFILE_MAX_LINELEN + 1, (FILE *) fp))
00308         {
00309           /* got to end of file without finding it */
00310           return NULL;
00311         }
00312 #else
00313       if (NULL ==
00314           inet_file_gets (line, INIFILE_MAX_LINELEN + 1, (INET_FILE *) fp))
00315         {
00316           /* got to end of file without finding it */
00317           return NULL;
00318         }
00319 #endif
00320 
00321       /* got a line */
00322 
00323       /* strip off newline */
00324       newlinepos = strlen (line) - 1;   /* newline is on back from 0 */
00325       if (newlinepos < 0)
00326         {
00327           newlinepos = 0;
00328         }
00329       if (line[newlinepos] == '\n')
00330         {
00331           line[newlinepos] = 0; /* make the newline 0 */
00332         }
00333 
00334       /* skip leading whitespace */
00335       if (NULL == (nonwhite = skipwhite (line)))
00336         {
00337           /* blank line-- skip */
00338           continue;
00339         }
00340 
00341       /* check for '[' char-- if so, it's a section tag, and we're out of
00342          our section */
00343       if (NULL != section && nonwhite[0] == '[')
00344         {
00345           return NULL;
00346         }
00347 
00348       len = strlen (tag);
00349 
00350       if (0 != strncmp (tag, nonwhite, len))
00351         {
00352           /* not on this line */
00353           continue;
00354         }
00355 
00356       /* it matches the first part of the string-- if whitespace or =
00357          is next char then call it a match */
00358       tagend = nonwhite[len];
00359       if (tagend == ' ' || tagend == '\r' || tagend == '\t' || tagend == '\n'
00360           || tagend == '=')
00361         {
00362           /* it matches-- return string after =, or NULL */
00363           nonwhite += len;
00364           value_string = (char *) afterequal (nonwhite);        /* Cast is needed because we are discarding the const. */
00365           /* Eliminate white space at the end of a line also. */
00366           if (NULL == value_string)
00367             {
00368               return NULL;
00369             }
00370           end_value_string = value_string + strlen (value_string) - 1;
00371           while (*end_value_string == ' ' || *end_value_string == '\t'
00372                  || *end_value_string == '\r')
00373             {
00374               *end_value_string = 0;
00375               end_value_string--;
00376             }
00377           return value_string;
00378         }
00379       /* else continue */
00380     }
00381 
00382   return NULL;
00383 }

int iniSection void *    fp,
const char *    section,
INIFILE_ENTRY    array[],
int    max
 

Definition at line 396 of file _inifile.c.

00397 {
00398   static char line[INIFILE_MAX_LINELEN + 2];    /* 1 for newline, 1 for NULL */
00399   int count = 0;
00400   char *nonwhite;
00401   int newlinepos;
00402   const char *entry;
00403 #ifdef UNDER_CE
00404   int i = 0;
00405 #endif
00406 
00407   if (NULL == fp)
00408     {
00409       return -1;
00410     }
00411 
00412   /*  position at section */
00413   if (-1 == findSection (fp, section))
00414     {
00415       /* didn't find it */
00416       return -1;
00417     }
00418 
00419   /* found section-- start loading lines */
00420 
00421 #ifndef INIFILE_USE_INET_FILES
00422   while (!feof ((FILE *) fp) &&
00423 #else
00424   while (!inet_file_eof ((INET_FILE *) fp) &&
00425 #endif
00426          count < max)
00427     {
00428 #ifndef INIFILE_USE_INET_FILES
00429       if (NULL == fgets (line, INIFILE_MAX_LINELEN + 1, (FILE *) fp))
00430         {
00431           /* got to end of file without finding it */
00432           return count;
00433         }
00434 #else
00435       if (NULL ==
00436           inet_file_gets (line, INIFILE_MAX_LINELEN + 1, (INET_FILE *) fp))
00437         {
00438           /* got to end of file without finding it */
00439           return count;
00440         }
00441 #endif
00442 
00443       /* got a line-- check for blank */
00444       if (NULL == (nonwhite = skipwhite (line)))
00445         {
00446           continue;
00447         }
00448 
00449       /* check for new section-- if so, we're done */
00450       if ('[' == *nonwhite)
00451         {
00452           return count;
00453         }
00454 
00455       /* strip off newline  */
00456       newlinepos = strlen (line) - 1;   /* newline is one back from 0 */
00457       if (newlinepos < 0)
00458         {
00459           newlinepos = 0;
00460         }
00461       if (line[newlinepos] == '\n')
00462         {
00463           line[newlinepos] = 0; /* make the newline 0 */
00464         }
00465 
00466       /* it's a valid line-- copy into entry struct */
00467 
00468       /* read first tag */
00469 #ifndef UNDER_CE
00470       sscanf (line, "%s", array[count].tag);
00471 #else
00472       i = 0;
00473       while (line[i] != 0 && line[i] != ' ' && line[i] != '\t'
00474              && line[i] != '\r')
00475         {
00476           array[count].tag[i] = line[i];
00477           i++;
00478         }
00479       array[count].tag[i] = 0;
00480 #endif
00481 
00482       /* copy everything after equal to the rest */
00483 
00484       entry = afterequal (line);
00485       if (NULL != entry)
00486         {
00487           strcpy (array[count].rest, afterequal (line));
00488         }
00489       else
00490         {
00491           array[count].rest[0] = 0;     /* make it the empty string */
00492         }
00493       count++;
00494     }
00495 
00496   /* got to end of file */
00497   return count;
00498 }


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