]> git.sesse.net Git - vlc/blob - modules/visualization/galaktos/init_cond.c
Simplify configure for win32
[vlc] / modules / visualization / galaktos / init_cond.c
1 /*****************************************************************************
2  * init_cond.:
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet <asmax@videolan.org>
8  *          code from projectM http://xmms-projectm.sourceforge.net
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <vlc_common.h>
30
31 /* Library functions to manipulate initial condition values */
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36
37 #include "common.h"
38 #include "fatal.h"
39
40 #include "param_types.h"
41 #include "expr_types.h"
42 #include "init_cond_types.h"
43 #include "init_cond.h"
44
45 #include "splaytree_types.h"
46 #include "splaytree.h"
47 char init_cond_string_buffer[STRING_BUFFER_SIZE];
48 int init_cond_string_buffer_index = 0;
49
50
51 void init_cond_to_string(init_cond_t * init_cond);
52
53 /* Frees initial condition structure */
54 void free_init_cond(init_cond_t * init_cond) {
55   free(init_cond);
56 }
57
58 /* Evaluate an initial conditon */
59 void eval_init_cond(init_cond_t * init_cond) {
60
61   if (init_cond == NULL)
62     return;
63  
64   /* Parameter is of boolean type, either a 1 or 0 value integer */
65
66   /* Set matrix flag to zero. This ensures
67      its constant value will be used rather than a matrix value 
68   */
69   init_cond->param->matrix_flag = 0;
70   if (init_cond->param->type == P_TYPE_BOOL) {
71          if (INIT_COND_DEBUG) printf("init_cond: %s = %d (TYPE BOOL)\n", init_cond->param->name, init_cond->init_val.bool_val); 
72          *((int*)init_cond->param->engine_val) = init_cond->init_val.bool_val;
73      return;
74   }
75   
76   /* Parameter is an integer type, just like C */
77   
78   if (init_cond->param->type == P_TYPE_INT) {
79          if (INIT_COND_DEBUG) printf("init_cond: %s = %d (TYPE INT)\n", init_cond->param->name, init_cond->init_val.int_val);
80          *((int*)init_cond->param->engine_val) = init_cond->init_val.int_val;
81      return;
82   }
83
84   /* Parameter is of a double type, just like C */
85
86   if (init_cond->param->type == P_TYPE_DOUBLE) {
87         if (INIT_COND_DEBUG) printf("init_cond: %s = %f (TYPE DOUBLE)\n", init_cond->param->name, init_cond->init_val.double_val);
88         *((double*)init_cond->param->engine_val) = init_cond->init_val.double_val;
89     return;
90   }
91
92   /* Unknown type of parameter */
93   return;
94 }
95
96 /* Creates a new initial condition */
97 init_cond_t * new_init_cond(param_t * param, value_t init_val) {
98
99   init_cond_t * init_cond;
100
101   init_cond = (init_cond_t*)malloc(sizeof(init_cond_t));
102    
103   if (init_cond == NULL)
104     return NULL;
105  
106   init_cond->param = param;
107   init_cond->init_val = init_val;
108   return init_cond;
109 }
110
111 /* WIP */
112 void init_cond_to_string(init_cond_t * init_cond) {
113         
114         int string_length;
115         char string[MAX_TOKEN_SIZE];
116         
117         if (init_cond == NULL)
118                 return;
119
120         /* Create a string "param_name=val" */
121         switch (init_cond->param->type) {
122                 lldiv_t div;
123                 
124                 case P_TYPE_BOOL:
125                         sprintf(string, "%s=%d\n", init_cond->param->name, init_cond->init_val.bool_val);
126                         break; 
127                 case P_TYPE_INT:
128                         sprintf(string, "%s=%d\n", init_cond->param->name, init_cond->init_val.int_val);
129                         break;
130                 case P_TYPE_DOUBLE:
131                         div = lldiv( init_cond->init_val.double_val * 1000000,
132                                      1000000 );
133                         sprintf(string, "%s=%"PRId64".%06u\n", init_cond->param->name, div.quot, (unsigned int) div.rem );
134                         break;
135                 default:
136                         return;
137         }               
138                 
139         /* Compute the length of the string */
140         string_length = strlen(string);
141         
142         /* Buffer overflow check */
143         if ((init_cond_string_buffer_index + string_length + 1)  > (STRING_BUFFER_SIZE - 1))
144                 return;
145         
146         /* Copy the string into the initial condition string buffer */
147         
148         strncpy(init_cond_string_buffer + init_cond_string_buffer_index, string, string_length);
149         
150         /* Increment the string buffer, offset by one for the null terminator, which will be
151            overwritten by the next call to this function */
152         init_cond_string_buffer_index+= string_length + 1;
153                 
154 }
155
156
157 char * create_init_cond_string_buffer(splaytree_t * init_cond_tree) {
158
159         if (init_cond_tree == NULL)
160                 return NULL;
161         
162         init_cond_string_buffer_index = 0;
163         
164         splay_traverse(init_cond_to_string, init_cond_tree);
165         
166         return init_cond_string_buffer;
167                 
168 }