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

ks_fact.c

Go to the documentation of this file.
00001 /*
00002  * libkarmaclient - A C Library to the Karmasphere Reputation Server
00003  * Copyright (C) 2006 Karmasphere <http://www.karmasphere.com/>
00004  *  - Shevek <shevek@karmasphere.com>
00005  *  - Dave Stewart <dave.stewart@karmasphere.com>
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020  */
00021 
00026 #include "ks_config.h"
00027 #include "ks_fact.h"
00028 #include "ks_string.h"
00029 #include "ks_assoc.h"
00030 #include "ks_number.h"
00031 
00032 #ifdef HAVE_STDIO_H
00033 #include <stdio.h>
00034 #endif
00035 
00036 #ifdef HAVE_STDLIB_H
00037 #include <stdlib.h>
00038 #endif
00039 
00040 #ifdef HAVE_STRING_H
00041 #include <string.h>
00042 #endif
00043 
00053 const char *
00054 ks_fact_identity(ks_fact_t *f)
00055 {
00056         ks_base_t       *b = ks_assoc_get(f, "i", 1);
00057         ks_string_t     *r;
00058         if (b == NULL)
00059                 return NULL;
00060         r = KS_CAST(ks_string, b);
00061         return ks_string_get(r);
00062 }
00063 
00070 const char *
00071 ks_fact_feed(ks_fact_t *f)
00072 {
00073         ks_base_t       *b = ks_assoc_get(f, "f", 1);
00074         ks_number_t     *n;
00075         ks_string_t     *r;
00076         if (b == NULL)
00077                 return NULL;
00078         if (b->type == ks_number_type()) {
00079                 n = KS_CAST(ks_number, b);
00080                 char    buf[64];
00081                 sprintf(buf, "%ld", ks_number_get(n));
00082                 r = ks_string_new(buf, strlen(buf));
00083                 b = (ks_base_t *)r;
00084                 ks_assoc_put(f, "f", 1, b);     /* XXX */
00085         }
00086         /* XXX Check if it's a number, and convert it. */
00087         r = KS_CAST(ks_string, b);
00088         return ks_string_get(r);
00089 }
00090 
00097 long
00098 ks_fact_value(ks_fact_t *f)
00099 {
00100         ks_base_t       *b = ks_assoc_get(f, "v", 1);
00101         ks_number_t     *n;
00102         if (b == NULL)
00103                 return 0L;
00104         n = KS_CAST(ks_number, b);
00105         return ks_number_get(n);
00106 }
00107 
00114 const char *
00115 ks_fact_data(ks_fact_t *f)
00116 {
00117         ks_base_t       *b = ks_assoc_get(f, "d", 1);
00118         ks_string_t     *r;
00119         if (b == NULL)
00120                 return NULL;
00121         r = KS_CAST(ks_string, b);
00122         return ks_string_get(r);
00123 }

Generated on Tue Aug 7 21:11:30 2007 for libkarmaclient by  doxygen 1.4.4