goinfre/libs/libcfgfile/core.c

goinfre/libs/libcfgfile/core.c

  _____________________________________________________________________________ 
 /   / Index / Goinfre / Resume / Links / Contact / Sitemap /    .: v0.6.1.0 |^|
|\__/-------+         +--------+-------+---------+---------+-----------------+#|
|  1| /goinfre/libs/libcfgfile/core.c                                        |#|
|  2| ==========================================                             |#|
|  3|                                                                        |#|
|  4|                                                   [ raw ] [ download ] |#|
|  5|                                             ` `` ````````````````````` |#|
|  6|                                                                        |#|
|  7| /**                                                                    |#|
|  8|  * libcfgfile/core.c                                                   |#|
|  9|  *                                                                     |#|
| 10|  * Copyright (c) Manfred Touron 2008                                   |#|
| 11|  */                                                                    |#|
| 12|                                                                        |#|
| 13| #include <stdlib.h>                                                    |#|
| 14| #include <string.h>                                                    |#|
| 15| #include <unistd.h>                                                    |#|
| 16| #include <stdio.h>                                                     |#|
| 17| #include <fcntl.h>                                                     |#|
| 18|                                                                        |#|
| 19| #include <liblc/lc.h>                                                  |#|
| 20|                                                                        |#|
| 21| #include <librbuf/librbuf.h>                                           |#|
| 22|                                                                        |#|
| 23| #include "core.h"                                                      |#|
| 24|                                                                        |#|
| 25| lc      _cfgfile_list;                                                 |#|
| 26|                                                                        |#|
| 27| cfgfile            cfgfile_find(const char *name)                      |#|
| 28| {                                                                      |#|
| 29|   cfgfile      c;                                                      |#|
| 30|                                                                        |#|
| 31|   cfgfile_init();                                                      |#|
| 32|   if ((c = lc_find_cmpfn(_cfgfile_list, (void *)name,                  |#|
| 33|                    cfgfile_cmpfn)) != NULL)                            |#|
| 34|     return (c);                                                        |#|
| 35|   return (cfgfile_new(name));                                          |#|
| 36| }                                                                      |#|
| 37|                                                                        |#|
| 38| void      cfgfile_init(void)                                           |#|
| 39| {                                                                      |#|
| 40|   static int      inited = 0;                                          |#|
| 41|                                                                        |#|
| 42|   if (!inited)                                                         |#|
| 43|     {                                                                  |#|
| 44|       _cfgfile_list = lc_new();                                        |#|
| 45|       inited = 1;                                                      | |
| 46|     }                                                                  | |
| 47|   return ;                                                             | |
| 48| }                                                                      | |
| 49|                                                                        | |
| 50| cfgfile      cfgfile_new(const char *filename)                         | |
| 51| {                                                                      | |
| 52|   cfgfile      new;                                                    | |
| 53|                                                                        | |
| 54|   cfgfile_init();                                                      | |
| 55|   if ((new = ALLOC(*new)) == NULL)                                     | |
| 56|     {                                                                  | |
| 57|       perror("malloc");                                                | |
| 58|       exit (-1);                                                       | |
| 59|     }                                                                  | |
| 60|   new->filename = filename;                                            | |
| 61|   new->fd = open(filename, O_RDONLY);                                  | |
| 62|   new->rbuf = rbuf_new(0);                                             | |
| 63|   return (new);                                                        | |
| 64| }                                                                      | |
| 65|                                                                        | |
+---+                                                                        | |
\_   \______ mo5.so - normal - 1337.so - rev.so - video_r.so +---------------+ |
  |__       \_____   plain.so - color.so - comment.so       /  moul 2008 (c) |V|
     \-----\______\________________________________________/-----------------+-+