Back to index

im-sdk  12.3.91
Functions
config-reader.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <alloca.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <le-options.h>
#include "configapi.h"
#include "util.h"

Go to the source code of this file.

Functions

static Bool parse_line (const char *line, KOLE_config **option)
Bool get_configuration (const char *fname, int *ret_noptions, KOLE_config ***options)

Function Documentation

Bool get_configuration ( const char *  fname,
int *  ret_noptions,
KOLE_config ***  options 
)

Definition at line 35 of file config-reader.c.

{
  FILE *fp;
  char *line;
  KOLE_config *pconf;
  
  /* read file */
  assert (fname != NULL);
  if (!fname){
    /* TO DO: log error */
    return False;
  }

  assert (ret_noptions != NULL);
  if (!ret_noptions){
    /* TO DO: log error */
    return False;
  }
  
  fp = fopen (fname, "r");

  if (!fp)
    return False;
  *ret_noptions = 0;
  *options = NULL;
  while ((line = (char *)safe_getline (fp))){
    if (parse_line (line, &pconf)){
      *options =
       (KOLE_config **) realloc (*options, sizeof (KOLE_config *) * *ret_noptions);
      (*options)[*ret_noptions] = pconf;
      (*ret_noptions)++;
    } else
      continue;
  }
  return True;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Bool parse_line ( const char *  line,
KOLE_config **  option 
) [static]

Definition at line 74 of file config-reader.c.

{
  char *buffer;
  char *p, *delim;
  char *name, *value;
  
  assert (line != NULL);
  if (!line)
    return False;

  assert (option != NULL);
  if (!option)
    return False;
  
  buffer = alloca (strlen (line) + 1);
  strncpy (buffer, line, strlen (line) + 1);
  p = buffer;

  /* ':' is delimeter */
  delim = strchr (buffer, ':');
  if (!delim) /* invalid format */
    return False;
  

  while (*p && isspace (*p)) p++;
  /* start of name */

  if (!*p || *p == '#')
    return False;
  else 
    name = p;

#if 0  
  while (*p && p < delim && !isspace (*p)) p++;
  
  
  /* end of name */
  if (!*p)
    return False;
  else if (*p == ':' || isspace (*p))
    /* even if p == delim, it doesn't matter */
    *p = '\0';
  else
    return False;
  /* done with name, now start getting value */
#endif

  p = delim - 1;
  while ( p > name && isspace (*p)) p--;
  
  if (p == name) /* error */
    return False;
  *(p + 1) = '\0';
  /* done with name, now start getting value */
  
  p = delim + 1;

  while (*p && isspace (*p)) p++;
  /* start of value */
  if (!*p) /* invalid format(no value) */
    return False;
  else
    value = p;

  while (*p && !isspace (*p)) p++;

  if (*p == '\n')
    *p = '\0';
  /* I don't need to check EOL here */
  *option = leoption_make_option_with_string_value (name, value);

  if (!*option)
    return False;
  else
    return True;
}

Here is the call graph for this function:

Here is the caller graph for this function: