Main Page | Data Structures | Directories | File List | Data Fields | Globals

cupl.h File Reference

Go to the source code of this file.

Data Structures

struct  cfg_array
struct  cfg_data

Defines

#define CUPL_VERSION   "0.8"
#define CFG_VAR_LEN   32
#define CFG_VAL_LEN   512

Typedefs

typedef cfg_array cfg_array
typedef cfg_data cfg_data

Functions

void cupl_print_info ()
cfg_datacupl_init_cfg (char *path)
char * cupl_get_var (char *var, cfg_data *cfg)
int cupl_release_cfg (cfg_data *cfg)
void cupl_print_items (cfg_data *cfg)
unsigned int cupl_hash_get (char *buf, unsigned int len, int tbl_size)
int cupl_match_regex (char *buffer, char *pattern)


Define Documentation

#define CFG_VAL_LEN   512
 

Definition at line 29 of file cupl.h.

#define CFG_VAR_LEN   32
 

Definition at line 28 of file cupl.h.

#define CUPL_VERSION   "0.8"
 

Definition at line 27 of file cupl.h.

Referenced by cupl_print_info().


Typedef Documentation

typedef struct cfg_array cfg_array
 

typedef struct cfg_data cfg_data
 


Function Documentation

char* cupl_get_var char *  var,
cfg_data cfg
 

Definition at line 253 of file cfg.c.

References cfg_array::next, cfg_array::val, cfg_array::var, and cfg_data::vars.

Referenced by main().

00254 {
00255     cfg_array *tmp = cfg->vars;
00256 
00257     if (cfg == NULL) return NULL;
00258 
00259     while (tmp != NULL) {
00260         if (strncmp(tmp->var, var, sizeof(tmp->var)) == 0) 
00261             return tmp->val;
00262         tmp = tmp->next;
00263     }
00264 
00265     return NULL;
00266 }

unsigned int cupl_hash_get char *  buf,
unsigned int  len,
int  tbl_size
 

Definition at line 42 of file ds.c.

Referenced by main().

00043 {
00044     unsigned int h;
00045 
00046     h = CDB_HASHSTART;
00047     while (len) {
00048         h = cdb_hashadd(h,*buf++);
00049         --len;
00050     }
00051 
00052     return h % tbl_size;
00053 }

cfg_data* cupl_init_cfg char *  path  ) 
 

Definition at line 39 of file cfg.c.

References cfg_data::cfd, errno, cfg_data::nov, and cfg_data::vars.

Referenced by main().

00040 {
00041     cfg_data *cfg;
00042 
00043     if ((cfg = (cfg_data *) malloc(sizeof(cfg_data))) == NULL) {
00044         fprintf(stderr, "%s: %d: malloc(): %s.\n", __FILE__, __LINE__,
00045                 strerror(errno));
00046         return NULL;
00047     }
00048 
00049     if ((cfg->cfd = fopen(path, "r")) == NULL) {
00050         fprintf(stderr, "%s: %d: fopen(): %s.\n", __FILE__, __LINE__,
00051                 strerror(errno));
00052         return NULL;
00053     }
00054 
00055     cfg->vars = NULL;
00056     cfg->nov = 0;
00057 
00058     if (parse_config_file(cfg) == -1)
00059         return NULL;
00060     
00061     return cfg;
00062 }

int cupl_match_regex char *  buffer,
char *  pattern
 

Definition at line 63 of file string.c.

References errno.

Referenced by main().

00064 {
00065     int ret = 0;
00066     regex_t *regexp; /* Regular expression pointer for the filter. */
00067 
00068     /* Allocate space for the regular expressions. */
00069     if ((regexp = (regex_t *) malloc(sizeof(regex_t))) == NULL) {
00070         fprintf(stderr, "%s: %d: malloc(): %s.\n", __FILE__, __LINE__, strerror(errno));
00071         return -1;
00072     }
00073 
00074     memset(regexp, 0, sizeof(regex_t));
00075 
00076     if ((ret = regcomp(regexp, pattern, 0)) != 0) /* Compile the regular expression. */
00077     {
00078         regfree(regexp);
00079         free(regexp);
00080         return -1;
00081     }
00082 
00083     ret = regex_match_pattern(regexp, buffer);
00084 
00085     regfree(regexp);
00086     free(regexp);
00087 
00088     return ret;
00089 }

void cupl_print_info  ) 
 

Definition at line 31 of file cupl.c.

References CUPL_VERSION.

Referenced by main().

00032 {
00033     printf("\n");
00034     printf("Common UNIX Programming Library, version %s\n", CUPL_VERSION);
00035     printf("(c)opyright Baris Simsek, http://www.enderunix.org/simsek\n\n");
00036 
00037     return;
00038 }

void cupl_print_items cfg_data cfg  ) 
 

Definition at line 233 of file cfg.c.

References cfg_array::next, cfg_data::nov, cfg_array::val, cfg_array::var, and cfg_data::vars.

Referenced by main().

00234 {
00235     cfg_array *tmp;
00236 
00237     if (cfg == NULL) return;
00238 
00239     printf("Number of items parsed: %d\n\n", cfg->nov);
00240     printf("Items:\n");
00241 
00242     tmp = cfg->vars;
00243 
00244     while (tmp != NULL) {
00245         printf("%s: %s\n", tmp->var, tmp->val);
00246         tmp = tmp->next;
00247     }
00248 
00249     return;
00250 }

int cupl_release_cfg cfg_data cfg  ) 
 

Definition at line 65 of file cfg.c.

References cfg_data::cfd, and cfg_data::vars.

Referenced by main().

00066 {
00067     if (cfg == NULL) return 0;
00068 
00069     fclose(cfg->cfd);
00070 
00071     if (cfg->vars) release_cfg_array(cfg->vars);
00072 
00073     free(cfg);
00074 
00075     return 1;
00076 }


Generated on Sat Aug 26 12:34:54 2006 for CUPL (Common UNIX Programming Library) by  doxygen 1.3.9.1