Mercurial > audlegacy-plugins
comparison src/paranormal-ng/libcalc/storage.c @ 2078:1fa3c8cd366a
paranormal-ng: a GL visualiser. lots to do, most stuff won't work, but hey, this will do cool stuff too soon
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Mon, 15 Oct 2007 06:20:13 -0500 |
parents | |
children | f1b6f1b2cdb3 |
comparison
equal
deleted
inserted
replaced
2077:e5b639ab62b0 | 2078:1fa3c8cd366a |
---|---|
1 /* storage.c -- | |
2 * | |
3 * Copyright (C) 2001 Janusz Gregorczyk <jgregor@kki.net.pl> | |
4 * | |
5 * This file is part of xvs. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
20 */ | |
21 | |
22 #include <glib.h> | |
23 #include <stddef.h> | |
24 | |
25 #include "storage.h" | |
26 | |
27 /* Code block. */ | |
28 | |
29 expression_t *expr_new (void) { | |
30 expression_t *new_expr; | |
31 | |
32 new_expr = (expression_t *)g_malloc (sizeof(expression_t)); | |
33 new_expr->data = g_string_new (NULL); | |
34 return new_expr; | |
35 } | |
36 | |
37 void expr_free (expression_t *expr) { | |
38 if (!expr) | |
39 return; | |
40 | |
41 g_string_free (expr->data, TRUE); | |
42 g_free (expr); | |
43 } | |
44 | |
45 static void load_data (char *str, void *dest, size_t size) { | |
46 char *ch = (char *)dest; | |
47 while (size--) | |
48 *ch++ = *str++; | |
49 } | |
50 | |
51 int load_int (char *str) { | |
52 int val; | |
53 load_data (str, &val, sizeof(val)); | |
54 return val; | |
55 } | |
56 | |
57 double load_double (char *str) { | |
58 double val; | |
59 load_data (str, &val, sizeof(val)); | |
60 return val; | |
61 } | |
62 | |
63 static void store_data (expression_t *expr, void *src, size_t size) { | |
64 char *ch = (char *)src; | |
65 while (size--) | |
66 store_byte (expr, *ch++); | |
67 } | |
68 | |
69 void store_byte (expression_t *expr, char byte) { | |
70 g_string_append_c (expr->data, byte); | |
71 } | |
72 | |
73 void store_int (expression_t *expr, int val) { | |
74 store_data (expr, &val, sizeof(val)); | |
75 } | |
76 | |
77 void store_double (expression_t *expr, double val) { | |
78 store_data (expr, &val, sizeof(val)); | |
79 } |