goinfre/libs/libcfgfile/parse.c

goinfre/libs/libcfgfile/parse.c

  _____________________________________________________________________________ 
 /   / Index / Goinfre / Resume / Links / Contact / Sitemap /    .: v0.6.1.0 |^|
|\__/-------+         +--------+-------+---------+---------+-----------------+#|
|  1| /goinfre/libs/libcfgfile/parse.c                                       |#|
|  2| ==========================================                             |#|
|  3|                                                                        |#|
|  4|                                                   [ raw ] [ download ] |#|
|  5|                                             ` `` ````````````````````` |#|
|  6|                                                                        |#|
|  7| /**                                                                    |#|
|  8|  * libcfgfile/parse.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 "core.h"                                                      |#|
| 22|                                                                        |#|
| 23| char            *_cfgfile_getopt(cfgfile c, char *cat, const char      |#|
| 24| *key)                                                                  |#|
| 25| {                                                                      |#|
| 26|   char            *line;                                               |#|
| 27|                                                                        |#|
| 28|   lseek(c->fd, 0, SEEK_SET);                                           |#|
| 29|   while (rbuf_read(c->fd, c->rbuf, BUF_SIZE))                          |#|
| 30|     ;                                                                  |#|
| 31|   while ((line = rbuf_get(c->rbuf)))                                   |#|
| 32|     if (strlen(line) > 1 && line[0] != '#')                            |#|
| 33|       if (!strncmp(line, cat, strlen(cat)) && line[strlen(cat)] ==     |#|
| 34| '.')                                                                   |#|
| 35|       if (!strncmp(line + strlen(cat) + 1, key, strlen(key)) &&        |#|
| 36|           line[strlen(cat)] == '.')                                    |#|
| 37|         return (strchr(line, '=') + 1);                                |#|
| 38|   return (NULL);                                                       |#|
| 39| }                                                                      |#|
| 40|                                                                        |#|
| 41| int            _cfgfile_cat_exists(cfgfile c, char *cat)               |#|
| 42| {                                                                      |#|
| 43|   char            *line;                                               |#|
| 44|                                                                        |#|
| 45|   lseek(c->fd, 0, SEEK_SET);                                           |#|
| 46|   while (rbuf_read(c->fd, c->rbuf, BUF_SIZE))                          |#|
| 47|     ;                                                                  |#|
| 48|   while ((line = rbuf_get(c->rbuf)))                                   |#|
| 49|     if (strlen(line) > 1 && line[0] != '#')                            |#|
| 50|       if (!strncmp(line, cat, strlen(cat)) && line[strlen(cat)] ==     | |
| 51| '.')                                                                   | |
| 52|       return (1);                                                      | |
| 53|   return (0);                                                          | |
| 54| }                                                                      | |
| 55|                                                                        | |
| 56| int            _cfgfile_key_exists(cfgfile c, char *cat, const char    | |
| 57| *key)                                                                  | |
| 58| {                                                                      | |
| 59|   char            *line;                                               | |
| 60|                                                                        | |
| 61|   lseek(c->fd, 0, SEEK_SET);                                           | |
| 62|   while (rbuf_read(c->fd, c->rbuf, BUF_SIZE))                          | |
| 63|     ;                                                                  | |
| 64|   while ((line = rbuf_get(c->rbuf)))                                   | |
| 65|     if (strlen(line) > 1 && line[0] != '#')                            | |
| 66|       if (!strncmp(line, cat, strlen(cat)) && line[strlen(cat)] ==     | |
| 67| '.')                                                                   | |
| 68|       if (!strncmp(line + strlen(cat) + 1, key, strlen(key)) &&        | |
| 69|           line[strlen(cat)] == '.')                                    | |
| 70|         return (1);                                                    | |
| 71|   return (0);                                                          | |
| 72| }                                                                      | |
| 73|                                                                        | |
+---+                                                                        | |
\_   \______ mo5.so - normal - 1337.so - rev.so - video_r.so +---------------+ |
  |__       \_____   plain.so - color.so - comment.so       /  moul 2008 (c) |V|
     \-----\______\________________________________________/-----------------+-+