]> git.sesse.net Git - vlc/commitdiff
Reverts [21943] for galaktos as it is external to vlc.
authorRafaël Carré <funman@videolan.org>
Tue, 11 Sep 2007 10:14:01 +0000 (10:14 +0000)
committerRafaël Carré <funman@videolan.org>
Tue, 11 Sep 2007 10:14:01 +0000 (10:14 +0000)
Just in case it is merged one day with upstream source.

31 files changed:
modules/visualization/galaktos/PCM.c
modules/visualization/galaktos/beat_detect.c
modules/visualization/galaktos/builtin_funcs.c
modules/visualization/galaktos/builtin_funcs.h
modules/visualization/galaktos/common.h
modules/visualization/galaktos/custom_shape.c
modules/visualization/galaktos/custom_shape_types.h
modules/visualization/galaktos/custom_wave.c
modules/visualization/galaktos/custom_wave_types.h
modules/visualization/galaktos/engine_vars.c
modules/visualization/galaktos/engine_vars.h
modules/visualization/galaktos/eval.c
modules/visualization/galaktos/eval.h
modules/visualization/galaktos/expr_types.h
modules/visualization/galaktos/fftsg.c
modules/visualization/galaktos/func.c
modules/visualization/galaktos/func_types.h
modules/visualization/galaktos/init_cond.c
modules/visualization/galaktos/param.c
modules/visualization/galaktos/param.h
modules/visualization/galaktos/param_types.h
modules/visualization/galaktos/parser.c
modules/visualization/galaktos/per_frame_eqn.c
modules/visualization/galaktos/per_pixel_eqn.c
modules/visualization/galaktos/per_pixel_eqn_types.h
modules/visualization/galaktos/per_point_types.h
modules/visualization/galaktos/preset.c
modules/visualization/galaktos/preset_types.h
modules/visualization/galaktos/splaytree.c
modules/visualization/galaktos/tree_types.c
modules/visualization/galaktos/video_init.c

index 0ebee5f55f16d544c11e7c9cae4d1d2fb46bd1b5..3c159bd30a967c86fa9c437abe12244645a44eb5 100644 (file)
@@ -48,13 +48,13 @@ int new;          //how many new samples
 
 void initPCM(int samples)
 {
-  int i;
+  int i; 
 
   //Allocate memory for PCM data buffer
   PCMd = (double **)malloc(2 * sizeof(double *));
   PCMd[0] = (double *)malloc(samples * sizeof(double));
   PCMd[1] = (double *)malloc(samples * sizeof(double));
+  
   maxsamples=samples;
   new=0;
 
@@ -83,15 +83,15 @@ void addPCM(int16_t PCMdata[2][512])
   int i,j;
   int samples=512;
 
-     for(i=0;i<samples;i++)
-       {
-         j=i+start;
-         PCMd[0][j%maxsamples]=(PCMdata[0][i]/16384.0);
-         PCMd[1][j%maxsamples]=(PCMdata[1][i]/16384.0);
-       }
+        for(i=0;i<samples;i++)
+          {
+            j=i+start;
+            PCMd[0][j%maxsamples]=(PCMdata[0][i]/16384.0);
+            PCMd[1][j%maxsamples]=(PCMdata[1][i]/16384.0);  
+          }
+       
  
-     // printf("Added %d samples %d %d %f\n",samples,start,(start+samples)%maxsamples,PCM[0][start+10]);
+        // printf("Added %d samples %d %d %f\n",samples,start,(start+samples)%maxsamples,PCM[0][start+10]); 
 
  start+=samples;
  start=start%maxsamples;
@@ -113,28 +113,28 @@ void addPCM(int16_t PCMdata[2][512])
 void getPCM(double *PCMdata, int samples, int channel, int freq, double smoothing, int derive)
 {
    int i,index;
+   
    index=start-1;
 
    if (index<0) index=maxsamples+index;
 
    PCMdata[0]=PCMd[channel][index];
+   
    for(i=1;i<samples;i++)
      {
        index=start-1-i;
        if (index<0) index=maxsamples+index;
+       
        PCMdata[i]=(1-smoothing)*PCMd[channel][index]+smoothing*PCMdata[i-1];
      }
+   
    //return derivative of PCM data
    if(derive)
      {
        for(i=0;i<samples-1;i++)
-     {    
-       PCMdata[i]=PCMdata[i]-PCMdata[i+1];
-     }
+        {         
+          PCMdata[i]=PCMdata[i]-PCMdata[i+1];
+        }
        PCMdata[samples-1]=0;
      }
 
@@ -142,7 +142,7 @@ void getPCM(double *PCMdata, int samples, int channel, int freq, double smoothin
    if (freq) rdft(samples, 1, PCMdata, ip, w);
 
 
+     
 }
 
 //getPCMnew
@@ -154,28 +154,28 @@ void getPCM(double *PCMdata, int samples, int channel, int freq, double smoothin
 int getPCMnew(double *PCMdata, int channel, int freq, double smoothing, int derive, int reset)
 {
    int i,index;
+   
    index=start-1;
 
    if (index<0) index=maxsamples+index;
 
    PCMdata[0]=PCMd[channel][index];
+   
    for(i=1;i<new;i++)
      {
        index=start-1-i;
        if (index<0) index=maxsamples+index;
+       
        PCMdata[i]=(1-smoothing)*PCMd[channel][index]+smoothing*PCMdata[i-1];
      }
+   
    //return derivative of PCM data
    if(derive)
      {
        for(i=0;i<new-1;i++)
-     {    
-       PCMdata[i]=PCMdata[i]-PCMdata[i+1];
-     }
+        {         
+          PCMdata[i]=PCMdata[i]-PCMdata[i+1];
+        }
        PCMdata[new-1]=0;
      }
 
index f351cf0a24143b6c832ee2c0f9b66736d2e15246..9d9291181ea7c1e45e7eb50e16bb2c5acece0274 100644 (file)
@@ -41,7 +41,7 @@ double vol_buffer[80],vol_instant,vol_history;
 void initBeatDetect()
 {
 
-  int x,y;
+  int x,y; 
 
   vol_instant=0;
   vol_history=0;
@@ -65,12 +65,12 @@ void initBeatDetect()
       beat_att[x]=1.0;
       beat_variance[x]=0;
       for (y=0;y<80;y++)
-    {
-      beat_buffer[x][y]=0;
-    }
+       {
+         beat_buffer[x][y]=0;
+       }
     }
 
-}
+} 
 
 void getBeatVals(double *vdataL,double *vdataR, double *vol)
 {
@@ -80,29 +80,29 @@ void getBeatVals(double *vdataL,double *vdataR, double *vol)
   vol_instant=0;
 
       for ( x=0;x<16;x++)
-    {
-    
-      beat_instant[x]=0;
-      for ( y=linear*2;y<(linear+8+x)*2;y++)
-        {
-          beat_instant[x]+=((vdataL[y]*vdataL[y])+(vdataR[y]*vdataR[y]))*(1.0/(8+x));
-          vol_instant+=((vdataL[y]*vdataL[y])+(vdataR[y]*vdataR[y]))*(1.0/512.0);
-
-        }
-    
-      linear=y/2;
-      beat_history[x]-=(beat_buffer[x][beat_buffer_pos])*.0125;
-      beat_buffer[x][beat_buffer_pos]=beat_instant[x];
-      beat_history[x]+=(beat_instant[x])*.0125;
-    
-      beat_val[x]=(beat_instant[x])/(beat_history[x]);
-    
-      beat_att[x]+=(beat_instant[x])/(beat_history[x]);
-
-
-     
-    }
+       {
+         
+         beat_instant[x]=0;
+         for ( y=linear*2;y<(linear+8+x)*2;y++)
+           {
+             beat_instant[x]+=((vdataL[y]*vdataL[y])+(vdataR[y]*vdataR[y]))*(1.0/(8+x)); 
+             vol_instant+=((vdataL[y]*vdataL[y])+(vdataR[y]*vdataR[y]))*(1.0/512.0);
+
+           }
+         
+         linear=y/2;
+         beat_history[x]-=(beat_buffer[x][beat_buffer_pos])*.0125;
+         beat_buffer[x][beat_buffer_pos]=beat_instant[x];
+         beat_history[x]+=(beat_instant[x])*.0125;
+         
+         beat_val[x]=(beat_instant[x])/(beat_history[x]);
+         
+         beat_att[x]+=(beat_instant[x])/(beat_history[x]);
+
+
+         
+       }
+      
       vol_history-=(vol_buffer[beat_buffer_pos])*.0125;
       vol_buffer[beat_buffer_pos]=vol_instant;
       vol_history+=(vol_instant)*.0125;
@@ -110,33 +110,33 @@ void getBeatVals(double *vdataL,double *vdataR, double *vol)
       double temp2=0;
       mid=0;
       for(x=1;x<10;x++)
-    {
-     mid+=(beat_instant[x]);
-      temp2+=(beat_history[x]);
-    
-    }
-    
-     mid=mid/(1.5*temp2);
-     temp2=0;
-     treb=0;
-       for(x=10;x<16;x++)
-        {
-          treb+=(beat_instant[x]);
-          temp2+=(beat_history[x]);
-        }
-      treb=treb/(1.5*temp2);
-      *vol=vol_instant/(1.5*vol_history);
-      bass=(beat_instant[0])/(1.5*beat_history[0]);
-
-      treb_att=.6 * treb_att + .4 * treb;
-      mid_att=.6 * mid_att + .4 * mid;
-      bass_att=.6 * bass_att + .4 * bass;
-      //printf("%f %f %f %f\n",bass,mid,treb,*vol);
-       // *vol=(beat_instant[3])/(beat_history[3]);
-      beat_buffer_pos++;
-      if( beat_buffer_pos>79)beat_buffer_pos=0;
-    
+       {
+        mid+=(beat_instant[x]);
+         temp2+=(beat_history[x]);
+        
+       }
+       
+        mid=mid/(1.5*temp2);
+        temp2=0;
+        treb=0;
+         for(x=10;x<16;x++)
+           { 
+             treb+=(beat_instant[x]);
+             temp2+=(beat_history[x]);
+           }
+         treb=treb/(1.5*temp2);
+         *vol=vol_instant/(1.5*vol_history);
+  
+         bass=(beat_instant[0])/(1.5*beat_history[0]);
+
+         treb_att=.6 * treb_att + .4 * treb;
+         mid_att=.6 * mid_att + .4 * mid;
+         bass_att=.6 * bass_att + .4 * bass;
+         //printf("%f %f %f %f\n",bass,mid,treb,*vol);
+          // *vol=(beat_instant[3])/(beat_history[3]);
+         beat_buffer_pos++;
+         if( beat_buffer_pos>79)beat_buffer_pos=0;
+       
 }
 void freeBeatDetect()
 {
index af626f9e5df8eeca60435cbc32fa9b962fa882ab..0e3bcef4b9e4e404ed233df2157bc61340e26b98 100644 (file)
@@ -25,8 +25,8 @@
 
 #include <math.h>
 /* Values to optimize the sigmoid function */
-#define R  32767
-#define RR 65534
+#define R  32767   
+#define RR 65534   
  
 inline double int_wrapper(double * arg_list) {
 
@@ -36,57 +36,57 @@ inline double int_wrapper(double * arg_list) {
 
 
 inline double sqr_wrapper(double * arg_list) {
-    
-    return pow(2, arg_list[0]);
-}    
-    
-    
-inline double sign_wrapper(double * arg_list) {    
-    
-    return -arg_list[0];    
-}    
+       
+       return pow(2, arg_list[0]);
+}      
+       
+       
+inline double sign_wrapper(double * arg_list) {        
+       
+       return -arg_list[0];    
+}      
 
 inline double min_wrapper(double * arg_list) {
-    
-    if (arg_list[0] > arg_list[1])
-        return arg_list[1];
-    
-    return arg_list[0];
-}        
+       
+       if (arg_list[0] > arg_list[1])
+               return arg_list[1];
+       
+       return arg_list[0];
+}              
 
 inline double max_wrapper(double * arg_list) {
 
-    if (arg_list[0] > arg_list[1])
-      return arg_list[0];
+       if (arg_list[0] > arg_list[1])
+         return arg_list[0];
 
-    return arg_list[1];
+       return arg_list[1];
 }
 
 /* consult your AI book */
 inline double sigmoid_wrapper(double * arg_list) {
   return (RR / (1 + exp( -(((double)(arg_list[0])) * arg_list[1]) / R) - R));
 }
-    
-    
+       
+       
 inline double bor_wrapper(double * arg_list) {
 
-    return (double)((int)arg_list[0] || (int)arg_list[1]);
-}    
-    
+       return (double)((int)arg_list[0] || (int)arg_list[1]);
+}      
+       
 inline double band_wrapper(double * arg_list) {
-    return (double)((int)arg_list[0] && (int)arg_list[1]);
-}    
+       return (double)((int)arg_list[0] && (int)arg_list[1]);
+}      
 
 inline double bnot_wrapper(double * arg_list) {
-    return (double)(!(int)arg_list[0]);
-}        
+       return (double)(!(int)arg_list[0]);
+}              
 
 inline double if_wrapper(double * arg_list) {
 
-        if ((int)arg_list[0] == 0)
-            return arg_list[2];
-        return arg_list[1];
-}        
+               if ((int)arg_list[0] == 0)
+                       return arg_list[2];
+               return arg_list[1];
+}              
 
 
 inline double rand_wrapper(double * arg_list) {
@@ -96,48 +96,48 @@ inline double rand_wrapper(double * arg_list) {
   l = (double)((rand()) % ((int)arg_list[0]));
   //printf("VAL: %f\n", l);
   return l;
-}    
+}      
 
 inline double equal_wrapper(double * arg_list) {
 
-    return (arg_list[0] == arg_list[1]);
-}    
+       return (arg_list[0] == arg_list[1]);
+}      
 
 
 inline double above_wrapper(double * arg_list) {
 
-    return (arg_list[0] > arg_list[1]);
-}    
+       return (arg_list[0] > arg_list[1]);
+}      
 
 
 inline double below_wrapper(double * arg_list) {
 
-    return (arg_list[0] < arg_list[1]);
+       return (arg_list[0] < arg_list[1]);
 }
 
 inline double sin_wrapper(double * arg_list) {
-    return (sin (arg_list[0]));    
+       return (sin (arg_list[0]));     
 }
 
 
 inline double cos_wrapper(double * arg_list) {
-    return (cos (arg_list[0]));
+       return (cos (arg_list[0]));
 }
 
 inline double tan_wrapper(double * arg_list) {
-    return (tan(arg_list[0]));
+       return (tan(arg_list[0]));
 }
 
 inline double asin_wrapper(double * arg_list) {
-    return (asin (arg_list[0]));
+       return (asin (arg_list[0]));
 }
 
 inline double acos_wrapper(double * arg_list) {
-    return (acos (arg_list[0]));
+       return (acos (arg_list[0]));
 }
 
 inline double atan_wrapper(double * arg_list) {
-    return (atan (arg_list[0]));
+       return (atan (arg_list[0]));
 }
 
 inline double atan2_wrapper(double * arg_list) {
@@ -193,9 +193,9 @@ inline double fact_wrapper(double * arg_list) {
 
 
   int result = 1;
+  
   int n = (int)arg_list[0];
+  
   while (n > 1) {
     result = result * n;
     n--;
index f9c7dcfdd72b9fc1b000aef6b43f69cfa6738145..a1816845e27558f96db0bf1da78ea8fa796eb6c5 100644 (file)
@@ -1,4 +1,4 @@
-/* Wrappers for all the builtin functions
+/* Wrappers for all the builtin functions 
    The arg_list pointer is a list of doubles. Its
    size is equal to the number of arguments the parameter
    takes */
index 8d06034c33011227675fcea994fc1158fe8c7bf5..560a6cc5e699ceae777b539a8e4dcb78513d7347 100644 (file)
@@ -13,7 +13,7 @@
 #endif
 #ifndef FALSE
 #define FALSE 0
-#endif
+#endif 
 
 #define PROJECTM_FILE_EXTENSION ".prjm"
 #define MILKDROP_FILE_EXTENSION ".milk"
index 18578be499c4b1ef32d855539c74c79cc12297e1..9a57201715e882020e34e061874d84ae636fd310 100644 (file)
@@ -77,25 +77,25 @@ custom_shape_t * new_custom_shape(int id) {
 
   /* Initialize tree data structures */
 
-  if ((custom_shape->param_tree =
+  if ((custom_shape->param_tree = 
        create_splaytree(compare_string, copy_string, free_string)) == NULL) {
     free_custom_shape(custom_shape);
     return NULL;
   }
 
-  if ((custom_shape->per_frame_eqn_tree =
+  if ((custom_shape->per_frame_eqn_tree = 
        create_splaytree(compare_int, copy_int, free_int)) == NULL) {
     free_custom_shape(custom_shape);
     return NULL;
   }
 
-  if ((custom_shape->init_cond_tree =
+  if ((custom_shape->init_cond_tree = 
        create_splaytree(compare_string, copy_string, free_string)) == NULL) {
     free_custom_shape(custom_shape);
     return NULL;
   }
-  if ((custom_shape->per_frame_init_eqn_tree =
+  
+  if ((custom_shape->per_frame_init_eqn_tree = 
        create_splaytree(compare_string, copy_string, free_string)) == NULL) {
     free_custom_shape(custom_shape);
     return NULL;
@@ -125,7 +125,7 @@ custom_shape_t * new_custom_shape(int id) {
 
   if ((param = new_param_double("b", P_FLAG_NONE, &custom_shape->b, NULL, 1.0, 0.0, .5)) == NULL){
     free_custom_shape(custom_shape);
-    return NULL;                
+    return NULL;                                      
   }
 
   if (insert_param(param, custom_shape->param_tree) < 0) {
@@ -165,7 +165,7 @@ custom_shape_t * new_custom_shape(int id) {
 
   if ((param = new_param_double("border_b", P_FLAG_NONE, &custom_shape->border_b, NULL, 1.0, 0.0, .5)) == NULL){
     free_custom_shape(custom_shape);
-    return NULL;                
+    return NULL;                                      
   }
 
   if (insert_param(param, custom_shape->param_tree) < 0) {
@@ -205,7 +205,7 @@ custom_shape_t * new_custom_shape(int id) {
 
   if ((param = new_param_double("b2", P_FLAG_NONE, &custom_shape->b2, NULL, 1.0, 0.0, .5)) == NULL){
     free_custom_shape(custom_shape);
-    return NULL;                
+    return NULL;                                      
   }
 
   if (insert_param(param, custom_shape->param_tree) < 0) {
@@ -217,7 +217,7 @@ custom_shape_t * new_custom_shape(int id) {
     free_custom_shape(custom_shape);
     return NULL;
   }
+  
   if (insert_param(param, custom_shape->param_tree) < 0) {
     free_custom_shape(custom_shape);
     return NULL;
@@ -322,7 +322,7 @@ custom_shape_t * new_custom_shape(int id) {
     free_custom_shape(custom_shape);
     return NULL;
   }
+   
    if ((param = new_param_double("tex_ang", P_FLAG_NONE, &custom_shape->tex_ang, NULL, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0)) == NULL) {
     free_custom_shape(custom_shape);
     return NULL;
@@ -409,7 +409,7 @@ custom_shape_t * new_custom_shape(int id) {
   }
  
   /* End of parameter loading. Note that the read only parameters associated
-     with custom shapes (ie, sample) are global variables, and not specific to
+     with custom shapes (ie, sample) are global variables, and not specific to 
      the custom shape datastructure. */
 
 
@@ -475,7 +475,7 @@ void free_custom_shape(custom_shape_t * custom_shape) {
   destroy_init_cond_tree_shape(custom_shape->init_cond_tree);
   destroy_param_db_tree_shape(custom_shape->param_tree);
   destroy_per_frame_init_eqn_tree_shape(custom_shape->per_frame_init_eqn_tree);
+  
   free(custom_shape);
 
   return;
@@ -489,32 +489,32 @@ custom_shape_t * find_custom_shape(int id, preset_t * preset, int create_flag) {
 
   if (preset == NULL)
     return NULL;
+  
   if ((custom_shape = splay_find(&id, preset->custom_shape_tree)) == NULL) {
+    
     if (CUSTOM_SHAPE_DEBUG) { printf("find_custom_shape: creating custom shape (id = %d)...", id);fflush(stdout);}
+    
     if (create_flag == FALSE) {
       if (CUSTOM_SHAPE_DEBUG) printf("you specified not to (create flag = false), returning null\n");
       return NULL;
     }
+    
     if ((custom_shape = new_custom_shape(id)) == NULL) {
       if (CUSTOM_SHAPE_DEBUG) printf("failed...out of memory?\n");
       return NULL;
     }
+    
     if (CUSTOM_SHAPE_DEBUG) { printf("success.Inserting..."); fflush(stdout);}
+    
     if (splay_insert(custom_shape, &custom_shape->id, preset->custom_shape_tree) < 0) {
       if (CUSTOM_SHAPE_DEBUG) printf("failed, probably a duplicated!!\n");
       free_custom_shape(custom_shape);
       return NULL;
     }
+    
     if (CUSTOM_SHAPE_DEBUG) printf("done.\n");
   }
+  
   return custom_shape;
 }
 
@@ -555,14 +555,14 @@ void load_unspec_init_cond_shape(param_t * param) {
   /* If initial condition was not defined by the preset file, force a default one
      with the following code */
   if ((init_cond = splay_find(param->name, interface_shape->init_cond_tree)) == NULL) {
+    
     /* Make sure initial condition does not exist in the set of per frame initial equations */
     if ((init_cond = splay_find(param->name, interface_shape->per_frame_init_eqn_tree)) != NULL)
       return;
+    
     if (param->type == P_TYPE_BOOL)
       init_val.bool_val = 0;
+    
     else if (param->type == P_TYPE_INT)
       init_val.int_val = *(int*)param->engine_val;
 
@@ -573,13 +573,13 @@ void load_unspec_init_cond_shape(param_t * param) {
     /* Create new initial condition */
     if ((init_cond = new_init_cond(param, init_val)) == NULL)
       return;
+    
     /* Insert the initial condition into this presets tree */
     if (splay_insert(init_cond, init_cond->param->name, interface_shape->init_cond_tree) < 0) {
       free_init_cond(init_cond);
       return;
     }
+    
   }
  
 }
index b72326e1ed6daa1bb6f578b231ae0fb5ce9901e5..23b69e9fa21a390e0ad67cf209ddf1609a7e6c35 100644 (file)
@@ -23,7 +23,7 @@ typedef struct CUSTOM_SHAPE_T {
 
   double tex_zoom;
   double tex_ang;
+  
   double x; /* x position for per point equations */
   double y; /* y position for per point equations */
   double rad;
@@ -67,8 +67,8 @@ typedef struct CUSTOM_SHAPE_T {
   char per_frame_eqn_string_buffer[STRING_BUFFER_SIZE];
   char per_frame_init_eqn_string_buffer[STRING_BUFFER_SIZE];
   /* Per point equation array */
+  
+  
 } custom_shape_t;
 
 
index 55088363795c560972e3c7076a15c11fafae2027..48548ab643b85d6ffd58761fff1681fca7d36396 100644 (file)
@@ -72,7 +72,7 @@ custom_wave_t * new_custom_wave(int id) {
 
   custom_wave_t * custom_wave;
   param_t * param;
+  
   if ((custom_wave = (custom_wave_t*)malloc(sizeof(custom_wave_t))) == NULL)
     return NULL;
 
@@ -103,38 +103,38 @@ custom_wave_t * new_custom_wave(int id) {
   custom_wave->sample_mesh = malloc(MAX_SAMPLE_SIZE*sizeof(double));
 
   /* Initialize tree data structures */
-  if ((custom_wave->param_tree =
+  
+  if ((custom_wave->param_tree = 
        create_splaytree(compare_string, copy_string, free_string)) == NULL) {
     free_custom_wave(custom_wave);
     return NULL;
   }
 
-  if ((custom_wave->per_point_eqn_tree =
+  if ((custom_wave->per_point_eqn_tree = 
        create_splaytree(compare_int, copy_int, free_int)) == NULL) {
     free_custom_wave(custom_wave);
     return NULL;
   }
 
-  if ((custom_wave->per_frame_eqn_tree =
+  if ((custom_wave->per_frame_eqn_tree = 
        create_splaytree(compare_int, copy_int, free_int)) == NULL) {
     free_custom_wave(custom_wave);
     return NULL;
   }
 
-  if ((custom_wave->init_cond_tree =
+  if ((custom_wave->init_cond_tree = 
        create_splaytree(compare_string, copy_string, free_string)) == NULL) {
     free_custom_wave(custom_wave);
     return NULL;
   }
-  if ((custom_wave->per_frame_init_eqn_tree =
+  
+  if ((custom_wave->per_frame_init_eqn_tree = 
        create_splaytree(compare_string, copy_string, free_string)) == NULL) {
     free_custom_wave(custom_wave);
     return NULL;
   }
 
+  
   /* Start: Load custom wave parameters */
 
   if ((param = new_param_double("r", P_FLAG_DONT_FREE_MATRIX | P_FLAG_PER_POINT, &custom_wave->r, custom_wave->r_mesh, 1.0, 0.0, .5)) == NULL) {
@@ -159,7 +159,7 @@ custom_wave_t * new_custom_wave(int id) {
 
   if ((param = new_param_double("b", P_FLAG_DONT_FREE_MATRIX | P_FLAG_PER_POINT, &custom_wave->b,  custom_wave->b_mesh, 1.0, 0.0, .5)) == NULL){
     free_custom_wave(custom_wave);
-    return NULL;                
+    return NULL;                                      
   }
 
   if (insert_param(param, custom_wave->param_tree) < 0) {
@@ -171,7 +171,7 @@ custom_wave_t * new_custom_wave(int id) {
     free_custom_wave(custom_wave);
     return NULL;
   }
+  
   if (insert_param(param, custom_wave->param_tree) < 0) {
     free_custom_wave(custom_wave);
     return NULL;
@@ -268,7 +268,7 @@ custom_wave_t * new_custom_wave(int id) {
   }
 
   if ((param = new_param_double("sample", P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX | P_FLAG_ALWAYS_MATRIX | P_FLAG_PER_POINT,
-                &custom_wave->sample, custom_wave->sample_mesh, 1.0, 0.0, 0.0)) == NULL) {
+                               &custom_wave->sample, custom_wave->sample_mesh, 1.0, 0.0, 0.0)) == NULL) {
     free_custom_wave(custom_wave);
     return NULL;
   }
@@ -394,9 +394,9 @@ custom_wave_t * new_custom_wave(int id) {
     free_custom_wave(custom_wave);
     return NULL;
   }
+  
   /* End of parameter loading. Note that the read only parameters associated
-     with custom waves (ie, sample) are global variables, and not specific to
+     with custom waves (ie, sample) are global variables, and not specific to 
      the custom wave datastructure. */
 
 
@@ -498,12 +498,12 @@ int add_per_point_eqn(char * name, gen_expr_t * gen_expr, custom_wave_t * custom
 
   /* Argument checks */
   if (custom_wave == NULL)
-      return FAILURE;
+         return FAILURE;
   if (gen_expr == NULL)
-      return FAILURE;
+         return FAILURE;
   if (name == NULL)
-      return FAILURE;
+         return FAILURE;
+  
  if (CUSTOM_WAVE_DEBUG) printf("add_per_point_eqn: per pixel equation (name = \"%s\")\n", name);
 
  /* Search for the parameter so we know what matrix the per pixel equation is referencing */
@@ -512,7 +512,7 @@ int add_per_point_eqn(char * name, gen_expr_t * gen_expr, custom_wave_t * custom
    if (CUSTOM_WAVE_DEBUG) printf("add_per_point_eqn: failed to allocate a new parameter!\n");
    return FAILURE;
  
- }     
+ }      
 
  /* Find most largest index in the splaytree */
  if ((per_point_eqn = splay_find_max(custom_wave->per_point_eqn_tree)) == NULL)
@@ -522,49 +522,49 @@ int add_per_point_eqn(char * name, gen_expr_t * gen_expr, custom_wave_t * custom
 
  /* Create the per pixel equation given the index, parameter, and general expression */
  if ((per_point_eqn = new_per_point_eqn(index, param, gen_expr)) == NULL)
-     return FAILURE;
- if (CUSTOM_WAVE_DEBUG)
+        return FAILURE;
+ if (CUSTOM_WAVE_DEBUG) 
    printf("add_per_point_eqn: created new equation (index = %d) (name = \"%s\")\n", per_point_eqn->index, per_point_eqn->param->name);
  /* Insert the per pixel equation into the preset per pixel database */
  if (splay_insert(per_point_eqn, &per_point_eqn->index, custom_wave->per_point_eqn_tree) < 0) {
-    free_per_point_eqn(per_point_eqn);
-    return FAILURE;    
+       free_per_point_eqn(per_point_eqn);
+       return FAILURE;  
  }
-    
- /* Done */
+        
+ /* Done */ 
  return SUCCESS;
 }
 
 per_point_eqn_t * new_per_point_eqn(int index, param_t * param, gen_expr_t * gen_expr) {
 
-    per_point_eqn_t * per_point_eqn;
-    
-    if (param == NULL)
-        return NULL;
-    if (gen_expr == NULL)
-        return NULL;
-
-    if ((per_point_eqn = (per_point_eqn_t*)malloc(sizeof(per_point_eqn_t))) == NULL)
-        return NULL;
-
-    per_point_eqn->index = index;
-    per_point_eqn->gen_expr = gen_expr;
-    per_point_eqn->param = param;
-    return per_point_eqn;    
+       per_point_eqn_t * per_point_eqn;
+       
+       if (param == NULL)
+               return NULL;
+       if (gen_expr == NULL)
+               return NULL;
+
+       if ((per_point_eqn = (per_point_eqn_t*)malloc(sizeof(per_point_eqn_t))) == NULL)
+               return NULL;
+
+      
+       per_point_eqn->index = index;
+       per_point_eqn->gen_expr = gen_expr;
+       per_point_eqn->param = param;
+       return per_point_eqn;   
 }
 
 
 void free_per_point_eqn(per_point_eqn_t * per_point_eqn) {
 
-    if (per_point_eqn == NULL)
-        return;
-    
-    free_gen_expr(per_point_eqn->gen_expr);
-    
-    free(per_point_eqn);
-    
-    return;
+       if (per_point_eqn == NULL)
+               return;
+       
+       free_gen_expr(per_point_eqn->gen_expr);
+       
+       free(per_point_eqn);
+       
+       return;
 }
 
 custom_wave_t * find_custom_wave(int id, preset_t * preset, int create_flag) {
@@ -573,7 +573,7 @@ custom_wave_t * find_custom_wave(int id, preset_t * preset, int create_flag) {
 
   if (preset == NULL)
     return NULL;
+  
   if ((custom_wave = splay_find(&id, preset->custom_wave_tree)) == NULL) {
 
     if (CUSTOM_WAVE_DEBUG) { printf("find_custom_wave: creating custom wave (id = %d)...", id);fflush(stdout);}
@@ -628,7 +628,7 @@ inline custom_wave_t * nextCustomWave() {
 }
 
 
-inline void evalPerPointEqns() {
+inline void evalPerPointEqns() { 
 
   int x;
 
@@ -655,8 +655,8 @@ inline void evalPerPointEqns() {
 
 /* Evaluates a per point equation for the current custom wave given by interface_wave ptr */
 inline void evalPerPointEqn(per_point_eqn_t * per_point_eqn) {
+  
+  
   int samples, size;
   double * param_matrix;
   gen_expr_t * eqn_ptr;
@@ -669,17 +669,17 @@ inline void evalPerPointEqn(per_point_eqn_t * per_point_eqn) {
       return;
     memset(param_matrix, 0, size);
   }
-  else
+  else 
     param_matrix = (double*)per_point_eqn->param->matrix;
-  for (mesh_i = 0; mesh_i < samples; mesh_i++) {
+  
+  for (mesh_i = 0; mesh_i < samples; mesh_i++) {    
       param_matrix[mesh_i] = eval_gen_expr(eqn_ptr);
   }
+  
   /* Now that this parameter has been referenced with a per
      point equation, we let the evaluator know by setting
      this flag */
-  per_point_eqn->param->matrix_flag = 1;
+  per_point_eqn->param->matrix_flag = 1; 
 
 }
 
@@ -710,14 +710,14 @@ void load_unspec_init_cond(param_t * param) {
   /* If initial condition was not defined by the preset file, force a default one
      with the following code */
   if ((init_cond = splay_find(param->name, interface_wave->init_cond_tree)) == NULL) {
+    
     /* Make sure initial condition does not exist in the set of per frame initial equations */
     if ((init_cond = splay_find(param->name, interface_wave->per_frame_init_eqn_tree)) != NULL)
       return;
+    
     if (param->type == P_TYPE_BOOL)
       init_val.bool_val = 0;
+    
     else if (param->type == P_TYPE_INT)
       init_val.int_val = *(int*)param->engine_val;
 
@@ -728,13 +728,13 @@ void load_unspec_init_cond(param_t * param) {
     /* Create new initial condition */
     if ((init_cond = new_init_cond(param, init_val)) == NULL)
       return;
+    
     /* Insert the initial condition into this presets tree */
     if (splay_insert(init_cond, init_cond->param->name, interface_wave->init_cond_tree) < 0) {
       free_init_cond(init_cond);
       return;
     }
+    
   }
  
 }
index 9466c4ddbdff5a393d87f6e7359c1cde7bd39010..31481812788ae8586b4007e65587c4d18a0cce98 100644 (file)
@@ -15,7 +15,7 @@
 typedef struct PER_POINT_EQN_T {
   int index;
   param_t * param;
-  gen_expr_t * gen_expr;    
+  gen_expr_t * gen_expr;       
 } per_point_eqn_t;
 
 typedef struct CUSTOM_WAVE_T {
@@ -85,7 +85,7 @@ typedef struct CUSTOM_WAVE_T {
   char per_frame_init_eqn_string_buffer[STRING_BUFFER_SIZE];
   /* Per point equation array */
   gen_expr_t * per_point_eqn_array[NUM_POINT_OPS];
+  
 } custom_wave_t;
 
 
index 99fac64f0498f9add65551215db25ee499f0d9b1..ca0de20f464db2624970723fa3e422e5b22ec8fe 100644 (file)
@@ -72,7 +72,7 @@
  double mv_y = 12.0;
  double mv_dy = 0.02;
  double mv_dx = 0.02;
+  
  int meshx = 0;
  int meshy = 0;
  
index d1293dfc37c3868844675b543b5f289033057a2a..3854d3da0c6bcb10272ce45ad2e563df94f5e700 100644 (file)
@@ -96,7 +96,7 @@ extern int bDarken;
 extern int bSolarize;
 extern int bInvert;
 extern int bMotionVectorsOn;
-extern int fps;
+extern int fps; 
 
 extern double fWaveAlpha ;
 extern double fWaveScale;
index e509326533a0b97c29e6f0642c2dcc7080bd30bb..4ad7bc28676e1da682bc823e2eb82f770670178f 100644 (file)
@@ -50,16 +50,16 @@ static inline double eval_val_expr(val_expr_t * val_expr);
 inline double eval_gen_expr(gen_expr_t * gen_expr) {
   double l;
 
-  if (gen_expr == NULL)
-        return 0;
-     
+  if (gen_expr == NULL) 
+       return 0;
+       
   switch(gen_expr->type) {
-  case VAL_T:
+  case VAL_T:  
     return eval_val_expr(gen_expr->item);
   case PREFUN_T:
     l = eval_prefun_expr(gen_expr->item);
     //if (EVAL_DEBUG) printf("eval_gen_expr: prefix function return value: %f\n", l);
-    return l;        
+    return l;          
   case TREE_T:
     return eval_tree_expr(gen_expr->item);
   default:
@@ -67,46 +67,46 @@ inline double eval_gen_expr(gen_expr_t * gen_expr) {
     printf("eval_gen_expr: general expression matched no cases!\n");
     #endif
     return EVAL_ERROR;
-  }
-    
+  }  
+       
 }
 
 /* Evaluates functions in prefix form */
 static inline double eval_prefun_expr(prefun_expr_t * prefun_expr) {
-    int i;
-    
-    /* This is slightly less than safe, since
-       who knows if the passed argument is valid. For
-       speed purposes we'll go with this */
-    double arg_list[prefun_expr->num_args];
-    
-    #ifdef EVAL_DEBUG
-        printf("fn[");
-        fflush(stdout);
-    #endif
-    /* Evaluate each argument before calling the function itself */
-    for (i = 0; i < prefun_expr->num_args; i++) {
-        arg_list[i] = eval_gen_expr(prefun_expr->expr_list[i]);
-        #ifdef EVAL_DEBUG
-            if (i < (prefun_expr->num_args - 1))
-                printf(", ");
-            fflush(stdout);
-        #endif
-    }
-    
-    #ifdef EVAL_DEBUG
-        printf("]");
-        fflush(stdout);
-    #endif
-    
-    /* Now we call the function, passing a list of     
-       doubles as its argument */
+       int i;
+       
+       
+       /* This is slightly less than safe, since
+          who knows if the passed argument is valid. For 
+          speed purposes we'll go with this */
+       double arg_list[prefun_expr->num_args];
+       
+       #ifdef EVAL_DEBUG 
+               printf("fn[");
+               fflush(stdout);
+       #endif
+       /* Evaluate each argument before calling the function itself */
+       for (i = 0; i < prefun_expr->num_args; i++) {
+               arg_list[i] = eval_gen_expr(prefun_expr->expr_list[i]);
+               #ifdef EVAL_DEBUG 
+                       if (i < (prefun_expr->num_args - 1))
+                               printf(", ");
+                       fflush(stdout);
+               #endif
+       }
+       
+       #ifdef EVAL_DEBUG 
+               printf("]");
+               fflush(stdout);
+       #endif
+       
+       /* Now we call the function, passing a list of  
+          doubles as its argument */
+     
 
-    return (prefun_expr->func_ptr)(arg_list);    
-}    
+     
+       return (prefun_expr->func_ptr)(arg_list);       
+}      
 
 /* Evaluates a value expression */
 static inline double eval_val_expr(val_expr_t * val_expr) {
@@ -117,50 +117,50 @@ static inline double eval_val_expr(val_expr_t * val_expr) {
 
   /* Value is a constant, return the double value */
   if (val_expr->type == CONSTANT_TERM_T) {
-    #ifdef EVAL_DEBUG
-        printf("%.4f", val_expr->term.constant);
-        fflush(stdout);
+    #ifdef EVAL_DEBUG 
+               printf("%.4f", val_expr->term.constant);
+               fflush(stdout);
     #endif
     return (val_expr->term.constant);
   }
 
   /* Value is variable, dereference it */
   if (val_expr->type == PARAM_TERM_T) {
-       switch (val_expr->term.param->type) {
-        
-    case P_TYPE_BOOL:
-        #ifdef EVAL_DEBUG
-            printf("(%s:%.4f)", val_expr->term.param->name, (double)(*((int*)(val_expr->term.param->engine_val))));
-            fflush(stdout);
-        #endif
-    
-        
-        return (double)(*((int*)(val_expr->term.param->engine_val)));
-    case P_TYPE_INT:
-        #ifdef EVAL_DEBUG
-            printf("(%s:%.4f)", val_expr->term.param->name, (double)(*((int*)(val_expr->term.param->engine_val))));
-            fflush(stdout);
-        #endif
-
-    
-        return (double)(*((int*)(val_expr->term.param->engine_val)));
-    case P_TYPE_DOUBLE:        
-        #ifdef EVAL_DEBUG
-            printf("(%s:%.4f)", val_expr->term.param->name, (*((double*)val_expr->term.param->engine_val)));
-            fflush(stdout);
-        #endif
-            
-        if (val_expr->term.param->matrix_flag | (val_expr->term.param->flags & P_FLAG_ALWAYS_MATRIX)) {
-          if (mesh_j >= 0) {
-            return (((double**)val_expr->term.param->matrix)[mesh_i][mesh_j]);
-          }
-          else {
-            return (((double*)val_expr->term.param->matrix)[mesh_i]);
-          }
-        }
-        return *((double*)(val_expr->term.param->engine_val));
-    default:
-      return ERROR;    
+       switch (val_expr->term.param->type) {
+               
+       case P_TYPE_BOOL:
+               #ifdef EVAL_DEBUG 
+                       printf("(%s:%.4f)", val_expr->term.param->name, (double)(*((int*)(val_expr->term.param->engine_val))));
+                       fflush(stdout);
+               #endif
+              
+                 
+               return (double)(*((int*)(val_expr->term.param->engine_val)));
+       case P_TYPE_INT:
+               #ifdef EVAL_DEBUG 
+                       printf("(%s:%.4f)", val_expr->term.param->name, (double)(*((int*)(val_expr->term.param->engine_val))));
+                       fflush(stdout);
+               #endif
+
+            
+               return (double)(*((int*)(val_expr->term.param->engine_val)));
+       case P_TYPE_DOUBLE:             
+               #ifdef EVAL_DEBUG 
+                       printf("(%s:%.4f)", val_expr->term.param->name, (*((double*)val_expr->term.param->engine_val)));
+                       fflush(stdout);
+               #endif
+                       
+               if (val_expr->term.param->matrix_flag | (val_expr->term.param->flags & P_FLAG_ALWAYS_MATRIX)) {
+                 if (mesh_j >= 0) {
+                   return (((double**)val_expr->term.param->matrix)[mesh_i][mesh_j]);
+                 }
+                 else {
+                   return (((double*)val_expr->term.param->matrix)[mesh_i]);
+                 }
+               }
+               return *((double*)(val_expr->term.param->engine_val));
+       default:
+         return ERROR; 
     }
   }
   /* Unknown type, return failure */
@@ -169,107 +169,107 @@ static inline double eval_val_expr(val_expr_t * val_expr) {
 
 /* Evaluates an expression tree */
 static inline double eval_tree_expr(tree_expr_t * tree_expr) {
-        
-    double left_arg, right_arg;    
-    infix_op_t * infix_op;
-    
-    /* Shouldn't happen */
-    if (tree_expr == NULL)
-      return EVAL_ERROR;
-
-    /* A leaf node, evaluate the general expression. If the expression is null as well, return zero */
-    if (tree_expr->infix_op == NULL) {
-        if (tree_expr->gen_expr == NULL)
-            return 0;
-        else
-              return eval_gen_expr(tree_expr->gen_expr);
-    }
-    
-    /* Otherwise, this node is an infix operator. Evaluate
-       accordingly */
-    
-    infix_op = (infix_op_t*)tree_expr->infix_op;    
-    #ifdef EVAL_DEBUG
-        printf("(");
-        fflush(stdout);
-    #endif
-    
-    left_arg = eval_tree_expr(tree_expr->left);
-
-    #ifdef EVAL_DEBUG
-        
-        switch (infix_op->type) {
-        case INFIX_ADD:
-            printf("+");
-            break;        
-        case INFIX_MINUS:
-            printf("-");
-            break;
-        case INFIX_MULT:
-            printf("*");
-            break;
-        case INFIX_MOD:
-            printf("%%");
-            break;
-        case INFIX_OR:
-            printf("|");
-            break;
-        case INFIX_AND:
-            printf("&");
-            break;
-        case INFIX_DIV:
-            printf("/");
-            break;
-        default:
-            printf("?");
-        }
-    
-    fflush(stdout);    
-    #endif
-    
-    right_arg = eval_tree_expr(tree_expr->right);
-    
-    #ifdef EVAL_DEBUG
-        printf(")");
-        fflush(stdout);
-    #endif
-    
-    switch (infix_op->type) {        
-    case INFIX_ADD:
-      return (left_arg + right_arg);        
-    case INFIX_MINUS:
-        return (left_arg - right_arg);
-    case INFIX_MULT:
-        return (left_arg * right_arg);
-    case INFIX_MOD:
-      if ((int)right_arg == 0) {
-        #ifdef EVAL_DEBUG
-        printf("eval_tree_expr: modulo zero!\n");
-        #endif
-        return DIV_BY_ZERO;
-      }
-      return ((int)left_arg % (int)right_arg);
-    case INFIX_OR:
-        return ((int)left_arg | (int)right_arg);
-    case INFIX_AND:
-        return ((int)left_arg & (int)right_arg);
-    case INFIX_DIV:
-      if (right_arg == 0) {
-        #ifdef EVAL_DEBUG
-        printf("eval_tree_expr: division by zero!\n");
-        #endif
-        return MAX_DOUBLE_SIZE;
-      }        
-      return (left_arg / right_arg);
-    default:
-          #ifdef EVAL_DEBUG
-        printf("eval_tree_expr: unknown infix operator!\n");
+               
+       double left_arg, right_arg;     
+       infix_op_t * infix_op;
+       
+       /* Shouldn't happen */
+       if (tree_expr == NULL)
+         return EVAL_ERROR;
+
+       /* A leaf node, evaluate the general expression. If the expression is null as well, return zero */
+       if (tree_expr->infix_op == NULL) {
+               if (tree_expr->gen_expr == NULL)
+                       return 0;
+               else
+                       return eval_gen_expr(tree_expr->gen_expr);
+       }
+       
+       /* Otherwise, this node is an infix operator. Evaluate
+          accordingly */
+       
+       infix_op = (infix_op_t*)tree_expr->infix_op;    
+       #ifdef EVAL_DEBUG 
+               printf("(");
+               fflush(stdout);
+       #endif
+       
+       left_arg = eval_tree_expr(tree_expr->left);
+
+       #ifdef EVAL_DEBUG 
+               
+               switch (infix_op->type) {
+               case INFIX_ADD:
+                       printf("+");
+                       break;          
+               case INFIX_MINUS:
+                       printf("-");
+                       break;
+               case INFIX_MULT:
+                       printf("*");
+                       break;
+               case INFIX_MOD:
+                       printf("%%");
+                       break;
+               case INFIX_OR:
+                       printf("|");
+                       break;
+               case INFIX_AND:
+                       printf("&");
+                       break;
+               case INFIX_DIV:
+                       printf("/");
+                       break;
+               default:
+                       printf("?");
+               }
+       
+       fflush(stdout); 
+       #endif
+       
+       right_arg = eval_tree_expr(tree_expr->right);
+       
+       #ifdef EVAL_DEBUG
+               printf(")");
+               fflush(stdout);
+       #endif
+       
+       switch (infix_op->type) {               
+       case INFIX_ADD:
+         return (left_arg + right_arg);                
+       case INFIX_MINUS:
+               return (left_arg - right_arg);
+       case INFIX_MULT:
+               return (left_arg * right_arg);
+       case INFIX_MOD:
+         if ((int)right_arg == 0) {
+           #ifdef EVAL_DEBUG 
+           printf("eval_tree_expr: modulo zero!\n");
+           #endif
+           return DIV_BY_ZERO; 
+         }
+         return ((int)left_arg % (int)right_arg);
+       case INFIX_OR:
+               return ((int)left_arg | (int)right_arg);
+       case INFIX_AND:
+               return ((int)left_arg & (int)right_arg);
+       case INFIX_DIV:
+         if (right_arg == 0) {
+           #ifdef EVAL_DEBUG 
+           printf("eval_tree_expr: division by zero!\n");
+           #endif
+           return MAX_DOUBLE_SIZE;
+         }             
+         return (left_arg / right_arg);
+       default:
+          #ifdef EVAL_DEBUG 
+           printf("eval_tree_expr: unknown infix operator!\n");
           #endif
-        return ERROR;
-    }
-    
-    return ERROR;
-}    
+               return ERROR;
+       }
+       
+       return ERROR;
+}      
 
 /* Converts a double value to a general expression */
 gen_expr_t * const_to_expr(double val) {
@@ -277,18 +277,18 @@ gen_expr_t * const_to_expr(double val) {
   gen_expr_t * gen_expr;
   val_expr_t * val_expr;
   term_t term;
+  
   term.constant = val;
+    
   if ((val_expr = new_val_expr(CONSTANT_TERM_T, term)) == NULL)
     return NULL;
 
   gen_expr = new_gen_expr(VAL_T, (void*)val_expr);
 
   if (gen_expr == NULL) {
-    free_val_expr(val_expr);
+       free_val_expr(val_expr);
   }
+  
   return gen_expr;
 }
 
@@ -303,27 +303,27 @@ gen_expr_t * param_to_expr(param_t * param) {
     return NULL;
  
   /* This code is still a work in progress. We need
-     to figure out if the initial condition is used for
+     to figure out if the initial condition is used for 
      each per frame equation or not. I am guessing that
      it isn't, and it is thusly implemented this way */
+  
   /* Current guess of true behavior (08/01/03) note from carm
-     First try to use the per_pixel_expr (with cloning).
+     First try to use the per_pixel_expr (with cloning). 
      If it is null however, use the engine variable instead. */
+  
   /* 08/20/03 : Presets are now objects, as well as per pixel equations. This ends up
      making the parser handle the case where parameters are essentially per pixel equation
      substitutions */
+       
+  
   term.param = param;
   if ((val_expr = new_val_expr(PARAM_TERM_T, term)) == NULL)
     return NULL;
+  
   if ((gen_expr = new_gen_expr(VAL_T, (void*)val_expr)) == NULL) {
     free_val_expr(val_expr);
-    return NULL;    
-  }
+       return NULL;      
+  } 
   return gen_expr;
 }
 
@@ -332,14 +332,14 @@ gen_expr_t * prefun_to_expr(double (*func_ptr)(), gen_expr_t ** expr_list, int n
 
   gen_expr_t * gen_expr;
   prefun_expr_t * prefun_expr;
+  
 
   /* Malloc a new prefix function expression */
   prefun_expr = (prefun_expr_t*)malloc(sizeof(prefun_expr_t));
 
   if (prefun_expr == NULL)
-      return NULL;
+         return NULL;
+  
   prefun_expr->num_args = num_args;
   prefun_expr->func_ptr = func_ptr;
   prefun_expr->expr_list = expr_list;
@@ -347,24 +347,24 @@ gen_expr_t * prefun_to_expr(double (*func_ptr)(), gen_expr_t ** expr_list, int n
   gen_expr = new_gen_expr(PREFUN_T, (void*)prefun_expr);
 
   if (gen_expr == NULL)
-      free_prefun_expr(prefun_expr);
+         free_prefun_expr(prefun_expr);
+  
   return gen_expr;
 }
 
 /* Creates a new tree expression */
 tree_expr_t * new_tree_expr(infix_op_t * infix_op, gen_expr_t * gen_expr, tree_expr_t * left, tree_expr_t * right) {
 
-        tree_expr_t * tree_expr;
-        tree_expr = (tree_expr_t*)malloc(sizeof(tree_expr_t));
-    
-        if (tree_expr == NULL)
-            return NULL;
-        tree_expr->infix_op = infix_op;
-        tree_expr->gen_expr = gen_expr;
-        tree_expr->left = left;
-        tree_expr->right = right;
-        return tree_expr;
+               tree_expr_t * tree_expr;
+               tree_expr = (tree_expr_t*)malloc(sizeof(tree_expr_t));
+       
+               if (tree_expr == NULL)
+                       return NULL;
+               tree_expr->infix_op = infix_op;
+               tree_expr->gen_expr = gen_expr;
+               tree_expr->left = left;
+               tree_expr->right = right;
+               return tree_expr;
 }
 
 
@@ -386,39 +386,39 @@ val_expr_t * new_val_expr(int type, term_t term) {
 /* Creates a new general expression */
 gen_expr_t * new_gen_expr(int type, void * item) {
 
-    gen_expr_t * gen_expr;
+       gen_expr_t * gen_expr;
 
-    gen_expr = (gen_expr_t*)malloc(sizeof(gen_expr_t));
-    if (gen_expr == NULL)
-        return NULL;
-    gen_expr->type = type;
-    gen_expr->item = item;    
+       gen_expr = (gen_expr_t*)malloc(sizeof(gen_expr_t));
+       if (gen_expr == NULL)
+               return NULL;
+       gen_expr->type = type;
+       gen_expr->item = item;  
 
-    return gen_expr;
+       return gen_expr;
 }
 
 /* Frees a general expression */
 int free_gen_expr(gen_expr_t * gen_expr) {
 
-    if (gen_expr == NULL)
-         return SUCCESS;
-    
-    switch (gen_expr->type) {
-    case VAL_T:
-        free_val_expr(gen_expr->item);
-        break;
-    case PREFUN_T:
-        free_prefun_expr(gen_expr->item);
-        break;
-    case TREE_T:
-        free_tree_expr(gen_expr->item);
-        break;
-    default:
-        return FAILURE;
-    }    
-
-    free(gen_expr);
-    return SUCCESS;
+       if (gen_expr == NULL)
+               return SUCCESS;
+       
+       switch (gen_expr->type) {
+       case VAL_T:
+               free_val_expr(gen_expr->item);
+               break;
+       case PREFUN_T:
+               free_prefun_expr(gen_expr->item);
+               break;
+       case TREE_T:
+               free_tree_expr(gen_expr->item);
+               break;
+       default:
+               return FAILURE;
+       }       
+
+       free(gen_expr);
+       return SUCCESS;
 
 }
 
@@ -426,52 +426,52 @@ int free_gen_expr(gen_expr_t * gen_expr) {
 /* Frees a function in prefix notation */
 int free_prefun_expr(prefun_expr_t * prefun_expr) {
 
-    int i;
-    if (prefun_expr == NULL)
-        return SUCCESS;
-    
-    /* Free every element in expression list */
-    for (i = 0 ; i < prefun_expr->num_args; i++) {
-        free_gen_expr(prefun_expr->expr_list[i]);
-    }
-
-    free(prefun_expr);
-    return SUCCESS;
+       int i;
+       if (prefun_expr == NULL)
+               return SUCCESS;
+       
+       /* Free every element in expression list */
+       for (i = 0 ; i < prefun_expr->num_args; i++) {
+               free_gen_expr(prefun_expr->expr_list[i]);
+       }
+
+       free(prefun_expr);
+       return SUCCESS;
 }
 
 /* Frees values of type VARIABLE and CONSTANT */
 int free_val_expr(val_expr_t * val_expr) {
 
-    if (val_expr == NULL)
-        return SUCCESS;    
-    
-    free(val_expr);
-    return SUCCESS;
+       if (val_expr == NULL)
+               return SUCCESS; 
+       
+       free(val_expr);
+       return SUCCESS;
 }
 
 /* Frees a tree expression */
 int free_tree_expr(tree_expr_t * tree_expr) {
 
-    if (tree_expr == NULL)
-        return SUCCESS;
-    
-    /* free left tree */
-    free_tree_expr(tree_expr->left);
-    
-    /* free general expression object */
-    free_gen_expr(tree_expr->gen_expr);
-    
-    /* Note that infix operators are always
-       stored in memory unless the program
-       exits, so we don't remove them here */
-    
-    /* free right tree */
-    free_tree_expr(tree_expr->right);
-    
-    
-    /* finally, free the struct itself */
-    free(tree_expr);
-    return SUCCESS;
+       if (tree_expr == NULL)
+               return SUCCESS;
+       
+       /* free left tree */
+       free_tree_expr(tree_expr->left);
+       
+       /* free general expression object */
+       free_gen_expr(tree_expr->gen_expr);
+       
+       /* Note that infix operators are always
+          stored in memory unless the program 
+          exits, so we don't remove them here */
+       
+       /* free right tree */
+       free_tree_expr(tree_expr->right);
+       
+       
+       /* finally, free the struct itself */
+       free(tree_expr);
+       return SUCCESS;
 }
 
 
@@ -479,19 +479,19 @@ int free_tree_expr(tree_expr_t * tree_expr) {
 /* Initializes all infix operators */
 int init_infix_ops() {
 
-    infix_add = new_infix_op(INFIX_ADD, 4);
-    infix_minus = new_infix_op(INFIX_MINUS, 3);
-    infix_div = new_infix_op(INFIX_DIV, 2);
-    infix_or = new_infix_op(INFIX_OR, 5);
-    infix_and = new_infix_op(INFIX_AND,4);
-    infix_mod = new_infix_op(INFIX_MOD, 1);
-    infix_mult = new_infix_op(INFIX_MULT, 2);
-    
-    /* Prefix operators */
-    infix_positive = new_infix_op(INFIX_ADD, 0);
-    infix_negative = new_infix_op(INFIX_MINUS, 0);
-
-    return SUCCESS;
+       infix_add = new_infix_op(INFIX_ADD, 4);
+       infix_minus = new_infix_op(INFIX_MINUS, 3);
+       infix_div = new_infix_op(INFIX_DIV, 2);
+       infix_or = new_infix_op(INFIX_OR, 5);
+       infix_and = new_infix_op(INFIX_AND,4);
+       infix_mod = new_infix_op(INFIX_MOD, 1);
+       infix_mult = new_infix_op(INFIX_MULT, 2);
+       
+       /* Prefix operators */
+       infix_positive = new_infix_op(INFIX_ADD, 0);
+       infix_negative = new_infix_op(INFIX_MINUS, 0);
+
+       return SUCCESS;
 }
 
 /* Destroys the infix operator list. This should
@@ -515,17 +515,17 @@ int destroy_infix_ops()
 /* Initializes an infix operator */
 infix_op_t * new_infix_op(int type, int precedence) {
 
-    infix_op_t * infix_op;
-    
-    infix_op = (infix_op_t*)malloc(sizeof(infix_op_t));
-    
-    if (infix_op == NULL)
-        return NULL;
-    
-    infix_op->type = type;
-    infix_op->precedence = precedence;
-    
-    return infix_op;
+       infix_op_t * infix_op;
+       
+       infix_op = (infix_op_t*)malloc(sizeof(infix_op_t));
+       
+       if (infix_op == NULL)
+               return NULL;
+       
+       infix_op->type = type;
+       infix_op->precedence = precedence;
+       
+       return infix_op;
 }
 
 
@@ -557,7 +557,7 @@ gen_expr_t * clone_gen_expr(gen_expr_t * gen_expr) {
     }
     new_gen_expr->item = (void*)val_expr;
     break;
+    
   case PREFUN_T: /* prefix function expression */
     if ((prefun_expr = clone_prefun_expr((prefun_expr_t*)gen_expr->item)) == NULL) {
       free(new_gen_expr);
@@ -565,7 +565,7 @@ gen_expr_t * clone_gen_expr(gen_expr_t * gen_expr) {
     }
     new_gen_expr->item = (void*)prefun_expr;
     break;
+    
   case TREE_T:  /* tree expression */
     if ((tree_expr = clone_tree_expr((tree_expr_t*)gen_expr->item)) == NULL) {
       free(new_gen_expr);
@@ -573,12 +573,12 @@ gen_expr_t * clone_gen_expr(gen_expr_t * gen_expr) {
     }
     new_gen_expr->item = (void*)tree_expr;
     break;
+    
   default: /* unknown type, ut oh.. */
     free(new_gen_expr);
     return NULL;
   }
+  
   return new_gen_expr; /* Return the new (cloned) general expression */
 }
 
@@ -591,11 +591,11 @@ tree_expr_t * clone_tree_expr(tree_expr_t * tree_expr) {
   /* Null argument */
   if (tree_expr == NULL)
     return NULL;
+  
   /* Out of memory */
-  if ((new_tree_expr = (tree_expr_t*)malloc(sizeof(tree_expr_t))) == NULL)
+  if ((new_tree_expr = (tree_expr_t*)malloc(sizeof(tree_expr_t))) == NULL) 
     return NULL;
+  
   /* Set each argument in tree_expr_t struct */
   new_tree_expr->infix_op = tree_expr->infix_op;  /* infix operators are in shared memory */
   new_tree_expr->gen_expr = clone_gen_expr(tree_expr->gen_expr); /* clone the general expression */
@@ -605,7 +605,7 @@ tree_expr_t * clone_tree_expr(tree_expr_t * tree_expr) {
   return new_tree_expr; /* Return the new (cloned) tree expression */
 }
 
-/* Clones a value expression, currently only passes the pointer to
+/* Clones a value expression, currently only passes the pointer to 
    the value that this object represents, not a pointer to a copy of the value */
 val_expr_t * clone_val_expr(val_expr_t * val_expr) {
 
@@ -614,15 +614,15 @@ val_expr_t * clone_val_expr(val_expr_t * val_expr) {
   /* Null argument */
   if (val_expr == NULL)
     return NULL;
+  
   /* Allocate space, check for out of memory */
-  if ((new_val_expr = (val_expr_t*)malloc(sizeof(val_expr_t))) == NULL)
+  if ((new_val_expr = (val_expr_t*)malloc(sizeof(val_expr_t))) == NULL) 
     return NULL;
 
   /* Set the values in the val_expr_t struct */
   new_val_expr->type = val_expr->type;
   new_val_expr->term = val_expr->term;
+  
   /* Return the new (cloned) value expression */
   return new_val_expr;
 }
@@ -632,15 +632,15 @@ prefun_expr_t * clone_prefun_expr(prefun_expr_t * prefun_expr) {
 
   int i;
   prefun_expr_t * new_prefun_expr;
+  
   /* Null argument */
   if (prefun_expr == NULL)
     return NULL;
+  
   /* Out of memory */
-  if ((new_prefun_expr = (prefun_expr_t*)malloc(sizeof(prefun_expr_t))) == NULL)
+  if ((new_prefun_expr = (prefun_expr_t*)malloc(sizeof(prefun_expr_t))) == NULL) 
     return NULL;
+  
   /* Set the function argument paired with its number of arguments */
   new_prefun_expr->num_args = prefun_expr->num_args;
   new_prefun_expr->func_ptr = prefun_expr->func_ptr;
@@ -652,9 +652,9 @@ prefun_expr_t * clone_prefun_expr(prefun_expr_t * prefun_expr) {
   }
 
   /* Now copy each general expression from the argument expression list */
-  for (i = 0; i < new_prefun_expr->num_args;i++)
+  for (i = 0; i < new_prefun_expr->num_args;i++) 
     new_prefun_expr->expr_list[i] = clone_gen_expr(prefun_expr->expr_list[i]);
+  
   /* Finally, return the new (cloned) prefix function expression */
   return new_prefun_expr;
 }
@@ -666,7 +666,7 @@ void reset_engine_vars() {
   zoomexp= 1.0;
   rot= 0.0;
   warp= 0.0;
+  
   sx= 1.0;
   sy= 1.0;
   dx= 0.0;
@@ -674,9 +674,9 @@ void reset_engine_vars() {
   cx= 0.5;
   cy= 0.5;
 
+  
   decay=.98;
+  
   wave_r= 1.0;
   wave_g= 0.2;
   wave_b= 0.0;
@@ -705,7 +705,7 @@ void reset_engine_vars() {
   mv_y = 12.0;
   mv_dy = 0.02;
   mv_dx = 0.02;
+  
   meshx = 0;
   meshy = 0;
  
index 1dc07db3f75cb95afcfeb8e70d953c14f3be88af..60ae143d63dec717d732231809a66a30e49f955c 100644 (file)
@@ -21,7 +21,7 @@
 #define INFIX_OR 5
 #define INFIX_AND 6
 
-//#define EVAL_DEBUG
+//#define EVAL_DEBUG 
 
 
 inline double eval_gen_expr(gen_expr_t * gen_expr);
index b6af8547fe1a48e20874a18f394f2b48c895db7c..a5563f093687a61ca0b5341e36552dbfaa170a6a 100644 (file)
@@ -25,7 +25,7 @@ typedef struct VAL_EXPR_T {
 /* Infix Operator Function */
 typedef struct INFIX_OP_T {
   int type;
-  int precedence;
+  int precedence;  
 } infix_op_t;
 
 /* A binary expression tree ordered by operator precedence */
index 8c07c13bb832d2a67a9bce63eb021ff461f4abed..37997fe0742d8d08bee935e62fbb4b2d759a6aa6 100644 (file)
@@ -74,23 +74,23 @@ macro definitions
                         n >= 1, n = power of 2
         a[0...2*n-1]   :input/output data (double *)
                         input data
-                            a[2*j] = Re(x[j]),
+                            a[2*j] = Re(x[j]), 
                             a[2*j+1] = Im(x[j]), 0<=j<n
                         output data
-                            a[2*k] = Re(X[k]),
+                            a[2*k] = Re(X[k]), 
                             a[2*k+1] = Im(X[k]), 0<=k<n
         ip[0...*]      :work area for bit reversal (int *)
                         length of ip >= 2+sqrt(n)
-                        strictly,
-                        length of ip >=
+                        strictly, 
+                        length of ip >= 
                             2+(1<<(int)(log(n+0.5)/log(2))/2).
                         ip[0],ip[1] are pointers of the cos/sin table.
         w[0...n/2-1]   :cos/sin table (double *)
                         w[],ip[] are initialized if ip[0] == 0.
     [remark]
-        Inverse of
+        Inverse of 
             cdft(2*n, -1, a, ip, w);
-        is
+        is 
             cdft(2*n, 1, a, ip, w);
             for (j = 0; j <= 2 * n - 1; j++) {
                 a[j] *= 1.0 / n;
@@ -104,8 +104,8 @@ macro definitions
             R[k] = sum_j=0^n-1 a[j]*cos(2*pi*j*k/n), 0<=k<=n/2
             I[k] = sum_j=0^n-1 a[j]*sin(2*pi*j*k/n), 0<k<n/2
         <case2> IRDFT (excluding scale)
-            a[k] = (R[0] + R[n/2]*cos(pi*k))/2 +
-                   sum_j=1^n/2-1 R[j]*cos(2*pi*j*k/n) +
+            a[k] = (R[0] + R[n/2]*cos(pi*k))/2 + 
+                   sum_j=1^n/2-1 R[j]*cos(2*pi*j*k/n) + 
                    sum_j=1^n/2-1 I[j]*sin(2*pi*j*k/n), 0<=k<n
     [usage]
         <case1>
@@ -130,16 +130,16 @@ macro definitions
                                 a[1] = R[n/2]
         ip[0...*]      :work area for bit reversal (int *)
                         length of ip >= 2+sqrt(n/2)
-                        strictly,
-                        length of ip >=
+                        strictly, 
+                        length of ip >= 
                             2+(1<<(int)(log(n/2+0.5)/log(2))/2).
                         ip[0],ip[1] are pointers of the cos/sin table.
         w[0...n/2-1]   :cos/sin table (double *)
                         w[],ip[] are initialized if ip[0] == 0.
     [remark]
-        Inverse of
+        Inverse of 
             rdft(n, 1, a, ip, w);
-        is
+        is 
             rdft(n, -1, a, ip, w);
             for (j = 0; j <= n - 1; j++) {
                 a[j] *= 2.0 / n;
@@ -168,16 +168,16 @@ macro definitions
                             a[k] = C[k], 0<=k<n
         ip[0...*]      :work area for bit reversal (int *)
                         length of ip >= 2+sqrt(n/2)
-                        strictly,
-                        length of ip >=
+                        strictly, 
+                        length of ip >= 
                             2+(1<<(int)(log(n/2+0.5)/log(2))/2).
                         ip[0],ip[1] are pointers of the cos/sin table.
         w[0...n*5/4-1] :cos/sin table (double *)
                         w[],ip[] are initialized if ip[0] == 0.
     [remark]
-        Inverse of
+        Inverse of 
             ddct(n, -1, a, ip, w);
-        is
+        is 
             a[0] *= 0.5;
             ddct(n, 1, a, ip, w);
             for (j = 0; j <= n - 1; j++) {
@@ -215,16 +215,16 @@ macro definitions
                                 a[0] = S[n]
         ip[0...*]      :work area for bit reversal (int *)
                         length of ip >= 2+sqrt(n/2)
-                        strictly,
-                        length of ip >=
+                        strictly, 
+                        length of ip >= 
                             2+(1<<(int)(log(n/2+0.5)/log(2))/2).
                         ip[0],ip[1] are pointers of the cos/sin table.
         w[0...n*5/4-1] :cos/sin table (double *)
                         w[],ip[] are initialized if ip[0] == 0.
     [remark]
-        Inverse of
+        Inverse of 
             ddst(n, -1, a, ip, w);
-        is
+        is 
             a[0] *= 0.5;
             ddst(n, 1, a, ip, w);
             for (j = 0; j <= n - 1; j++) {
@@ -248,18 +248,18 @@ macro definitions
         t[0...n/2]     :work area (double *)
         ip[0...*]      :work area for bit reversal (int *)
                         length of ip >= 2+sqrt(n/4)
-                        strictly,
-                        length of ip >=
+                        strictly, 
+                        length of ip >= 
                             2+(1<<(int)(log(n/4+0.5)/log(2))/2).
                         ip[0],ip[1] are pointers of the cos/sin table.
         w[0...n*5/8-1] :cos/sin table (double *)
                         w[],ip[] are initialized if ip[0] == 0.
     [remark]
-        Inverse of
+        Inverse of 
             a[0] *= 0.5;
             a[n] *= 0.5;
             dfct(n, a, t, ip, w);
-        is
+        is 
             a[0] *= 0.5;
             a[n] *= 0.5;
             dfct(n, a, t, ip, w);
@@ -285,16 +285,16 @@ macro definitions
         t[0...n/2-1]   :work area (double *)
         ip[0...*]      :work area for bit reversal (int *)
                         length of ip >= 2+sqrt(n/4)
-                        strictly,
-                        length of ip >=
+                        strictly, 
+                        length of ip >= 
                             2+(1<<(int)(log(n/4+0.5)/log(2))/2).
                         ip[0],ip[1] are pointers of the cos/sin table.
         w[0...n*5/8-1] :cos/sin table (double *)
                         w[],ip[] are initialized if ip[0] == 0.
     [remark]
-        Inverse of
+        Inverse of 
             dfst(n, a, t, ip, w);
-        is
+        is 
             dfst(n, a, t, ip, w);
             for (j = 1; j <= n - 1; j++) {
                 a[j] *= 2.0 / n;
@@ -314,7 +314,7 @@ void cdft(int n, int isgn, double *a, int *ip, double *w)
     void cftfsub(int n, double *a, int *ip, int nw, double *w);
     void cftbsub(int n, double *a, int *ip, int nw, double *w);
     int nw;
+    
     nw = ip[0];
     if (n > (nw << 2)) {
         nw = n >> 2;
@@ -338,7 +338,7 @@ void rdft(int n, int isgn, double *a, int *ip, double *w)
     void rftbsub(int n, double *a, int nc, double *c);
     int nw, nc;
     double xi;
+    
     nw = ip[0];
     if (n > (nw << 2)) {
         nw = n >> 2;
@@ -383,7 +383,7 @@ void ddct(int n, int isgn, double *a, int *ip, double *w)
     void dctsub(int n, double *a, int nc, double *c);
     int j, nw, nc;
     double xr;
+    
     nw = ip[0];
     if (n > (nw << 2)) {
         nw = n >> 2;
@@ -439,7 +439,7 @@ void ddst(int n, int isgn, double *a, int *ip, double *w)
     void dstsub(int n, double *a, int nc, double *c);
     int j, nw, nc;
     double xr;
+    
     nw = ip[0];
     if (n > (nw << 2)) {
         nw = n >> 2;
@@ -493,7 +493,7 @@ void dfct(int n, double *a, double *t, int *ip, double *w)
     void dctsub(int n, double *a, int nc, double *c);
     int j, k, l, m, mh, nw, nc;
     double xr, xi, yr, yi;
+    
     nw = ip[0];
     if (n > (nw << 3)) {
         nw = n >> 3;
@@ -586,7 +586,7 @@ void dfst(int n, double *a, double *t, int *ip, double *w)
     void dstsub(int n, double *a, int nc, double *c);
     int j, k, l, m, mh, nw, nc;
     double xr, xi, yr, yi;
+    
     nw = ip[0];
     if (n > (nw << 3)) {
         nw = n >> 3;
@@ -671,7 +671,7 @@ void makewt(int nw, int *ip, double *w)
     void makeipt(int nw, int *ip);
     int j, nwh, nw0, nw1;
     double delta, wn4r, wk1r, wk1i, wk3r, wk3i;
+    
     ip[0] = nw;
     ip[1] = 1;
     if (nw > 2) {
@@ -730,7 +730,7 @@ void makewt(int nw, int *ip, double *w)
 void makeipt(int nw, int *ip)
 {
     int j, l, m, m2, p, q;
+    
     ip[2] = 0;
     ip[3] = 16;
     m = 2;
@@ -751,7 +751,7 @@ void makect(int nc, int *ip, double *c)
 {
     int j, nch;
     double delta;
+    
     ip[1] = nc;
     if (nc > 1) {
         nch = nc >> 1;
@@ -835,14 +835,14 @@ void cftfsub(int n, double *a, int *ip, int nw, double *w)
 #ifdef USE_CDFT_THREADS
     void cftrec4_th(int n, double *a, int nw, double *w);
 #endif /* USE_CDFT_THREADS */
+    
     if (n > 8) {
         if (n > 32) {
             cftf1st(n, a, &w[nw - (n >> 2)]);
 #ifdef USE_CDFT_THREADS
             if (n > CDFT_THREADS_BEGIN_N) {
                 cftrec4_th(n, a, nw, w);
-            } else
+            } else 
 #endif /* USE_CDFT_THREADS */
             if (n > 512) {
                 cftrec4(n, a, nw, w);
@@ -883,14 +883,14 @@ void cftbsub(int n, double *a, int *ip, int nw, double *w)
 #ifdef USE_CDFT_THREADS
     void cftrec4_th(int n, double *a, int nw, double *w);
 #endif /* USE_CDFT_THREADS */
+    
     if (n > 8) {
         if (n > 32) {
             cftb1st(n, a, &w[nw - (n >> 2)]);
 #ifdef USE_CDFT_THREADS
             if (n > CDFT_THREADS_BEGIN_N) {
                 cftrec4_th(n, a, nw, w);
-            } else
+            } else 
 #endif /* USE_CDFT_THREADS */
             if (n > 512) {
                 cftrec4(n, a, nw, w);
@@ -919,7 +919,7 @@ void bitrv2(int n, int *ip, double *a)
 {
     int j, j1, k, k1, l, m, nh, nm;
     double xr, xi, yr, yi;
+    
     m = 1;
     for (l = n >> 2; l > 8; l >>= 2) {
         m <<= 1;
@@ -1266,7 +1266,7 @@ void bitrv2conj(int n, int *ip, double *a)
 {
     int j, j1, k, k1, l, m, nh, nm;
     double xr, xi, yr, yi;
+    
     m = 1;
     for (l = n >> 2; l > 8; l >>= 2) {
         m <<= 1;
@@ -1619,10 +1619,10 @@ void bitrv2conj(int n, int *ip, double *a)
 
 void bitrv216(double *a)
 {
-    double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i,
-        x5r, x5i, x7r, x7i, x8r, x8i, x10r, x10i,
+    double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i, 
+        x5r, x5i, x7r, x7i, x8r, x8i, x10r, x10i, 
         x11r, x11i, x12r, x12i, x13r, x13i, x14r, x14i;
+    
     x1r = a[2];
     x1i = a[3];
     x2r = a[4];
@@ -1676,11 +1676,11 @@ void bitrv216(double *a)
 
 void bitrv216neg(double *a)
 {
-    double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i,
-        x5r, x5i, x6r, x6i, x7r, x7i, x8r, x8i,
-        x9r, x9i, x10r, x10i, x11r, x11i, x12r, x12i,
+    double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i, 
+        x5r, x5i, x6r, x6i, x7r, x7i, x8r, x8i, 
+        x9r, x9i, x10r, x10i, x11r, x11i, x12r, x12i, 
         x13r, x13i, x14r, x14i, x15r, x15i;
+    
     x1r = a[2];
     x1i = a[3];
     x2r = a[4];
@@ -1747,7 +1747,7 @@ void bitrv216neg(double *a)
 void bitrv208(double *a)
 {
     double x1r, x1i, x3r, x3i, x4r, x4i, x6r, x6i;
+    
     x1r = a[2];
     x1i = a[3];
     x3r = a[6];
@@ -1769,9 +1769,9 @@ void bitrv208(double *a)
 
 void bitrv208neg(double *a)
 {
-    double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i,
+    double x1r, x1i, x2r, x2i, x3r, x3i, x4r, x4i, 
         x5r, x5i, x6r, x6i, x7r, x7i;
+    
     x1r = a[2];
     x1i = a[3];
     x2r = a[4];
@@ -1806,11 +1806,11 @@ void bitrv208neg(double *a)
 void cftf1st(int n, double *a, double *w)
 {
     int j, j0, j1, j2, j3, k, m, mh;
-    double wn4r, csc1, csc3, wk1r, wk1i, wk3r, wk3i,
+    double wn4r, csc1, csc3, wk1r, wk1i, wk3r, wk3i, 
         wd1r, wd1i, wd3r, wd3i;
-    double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i,
+    double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, 
         y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i;
+    
     mh = n >> 3;
     m = 2 * mh;
     j1 = m;
@@ -2012,11 +2012,11 @@ void cftf1st(int n, double *a, double *w)
 void cftb1st(int n, double *a, double *w)
 {
     int j, j0, j1, j2, j3, k, m, mh;
-    double wn4r, csc1, csc3, wk1r, wk1i, wk3r, wk3i,
+    double wn4r, csc1, csc3, wk1r, wk1i, wk3r, wk3i, 
         wd1r, wd1i, wd3r, wd3i;
-    double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i,
+    double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, 
         y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i;
+    
     mh = n >> 3;
     m = 2 * mh;
     j1 = m;
@@ -2233,7 +2233,7 @@ void cftrec4_th(int n, double *a, int nw, double *w)
     int i, idiv4, m, nthread;
     cdft_thread_t th[4];
     cdft_arg_t ag[4];
+    
     nthread = 2;
     idiv4 = 0;
     m = n >> 1;
@@ -2267,7 +2267,7 @@ void *cftrec1_th(void *p)
     void cftmdl1(int n, double *a, double *w);
     int isplt, j, k, m, n, n0, nw;
     double *a, *w;
+    
     n0 = ((cdft_arg_t *) p)->n0;
     n = ((cdft_arg_t *) p)->n;
     a = ((cdft_arg_t *) p)->a;
@@ -2296,7 +2296,7 @@ void *cftrec2_th(void *p)
     void cftmdl2(int n, double *a, double *w);
     int isplt, j, k, m, n, n0, nw;
     double *a, *w;
+    
     n0 = ((cdft_arg_t *) p)->n0;
     n = ((cdft_arg_t *) p)->n;
     a = ((cdft_arg_t *) p)->a;
@@ -2327,7 +2327,7 @@ void cftrec4(int n, double *a, int nw, double *w)
     void cftleaf(int n, int isplt, double *a, int nw, double *w);
     void cftmdl1(int n, double *a, double *w);
     int isplt, j, k, m;
+    
     m = n;
     while (m > 512) {
         m >>= 2;
@@ -2348,7 +2348,7 @@ int cfttree(int n, int j, int k, double *a, int nw, double *w)
     void cftmdl1(int n, double *a, double *w);
     void cftmdl2(int n, double *a, double *w);
     int i, isplt, m;
+    
     if ((k & 3) != 0) {
         isplt = k & 1;
         if (isplt != 0) {
@@ -2386,7 +2386,7 @@ void cftleaf(int n, int isplt, double *a, int nw, double *w)
     void cftf162(double *a, double *w);
     void cftf081(double *a, double *w);
     void cftf082(double *a, double *w);
+    
     if (n == 512) {
         cftmdl1(128, a, &w[nw - 64]);
         cftf161(a, &w[nw - 8]);
@@ -2448,7 +2448,7 @@ void cftmdl1(int n, double *a, double *w)
     int j, j0, j1, j2, j3, k, m, mh;
     double wn4r, wk1r, wk1i, wk3r, wk3i;
     double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
+    
     mh = n >> 3;
     m = 2 * mh;
     j1 = m;
@@ -2558,7 +2558,7 @@ void cftmdl2(int n, double *a, double *w)
     int j, j0, j1, j2, j3, k, kr, m, mh;
     double wn4r, wk1r, wk1i, wk3r, wk3i, wd1r, wd1i, wd3r, wd3i;
     double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, y0r, y0i, y2r, y2i;
+    
     mh = n >> 3;
     m = 2 * mh;
     wn4r = w[1];
@@ -2693,7 +2693,7 @@ void cftfx41(int n, double *a, int nw, double *w)
     void cftf162(double *a, double *w);
     void cftf081(double *a, double *w);
     void cftf082(double *a, double *w);
+    
     if (n == 128) {
         cftf161(a, &w[nw - 8]);
         cftf162(&a[32], &w[nw - 32]);
@@ -2710,13 +2710,13 @@ void cftfx41(int n, double *a, int nw, double *w)
 
 void cftf161(double *a, double *w)
 {
-    double wn4r, wk1r, wk1i,
-        x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i,
-        y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i,
-        y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i,
-        y8r, y8i, y9r, y9i, y10r, y10i, y11r, y11i,
+    double wn4r, wk1r, wk1i, 
+        x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, 
+        y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i, 
+        y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i, 
+        y8r, y8i, y9r, y9i, y10r, y10i, y11r, y11i, 
         y12r, y12i, y13r, y13i, y14r, y14i, y15r, y15i;
+    
     wn4r = w[1];
     wk1r = w[2];
     wk1i = w[3];
@@ -2869,13 +2869,13 @@ void cftf161(double *a, double *w)
 
 void cftf162(double *a, double *w)
 {
-    double wn4r, wk1r, wk1i, wk2r, wk2i, wk3r, wk3i,
-        x0r, x0i, x1r, x1i, x2r, x2i,
-        y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i,
-        y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i,
-        y8r, y8i, y9r, y9i, y10r, y10i, y11r, y11i,
+    double wn4r, wk1r, wk1i, wk2r, wk2i, wk3r, wk3i, 
+        x0r, x0i, x1r, x1i, x2r, x2i, 
+        y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i, 
+        y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i, 
+        y8r, y8i, y9r, y9i, y10r, y10i, y11r, y11i, 
         y12r, y12i, y13r, y13i, y14r, y14i, y15r, y15i;
+    
     wn4r = w[1];
     wk1r = w[4];
     wk1i = w[5];
@@ -3052,10 +3052,10 @@ void cftf162(double *a, double *w)
 
 void cftf081(double *a, double *w)
 {
-    double wn4r, x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i,
-        y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i,
+    double wn4r, x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i, 
+        y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i, 
         y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i;
+    
     wn4r = w[1];
     x0r = a[0] + a[8];
     x0i = a[1] + a[9];
@@ -3114,10 +3114,10 @@ void cftf081(double *a, double *w)
 
 void cftf082(double *a, double *w)
 {
-    double wn4r, wk1r, wk1i, x0r, x0i, x1r, x1i,
-        y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i,
+    double wn4r, wk1r, wk1i, x0r, x0i, x1r, x1i, 
+        y0r, y0i, y1r, y1i, y2r, y2i, y3r, y3i, 
         y4r, y4i, y5r, y5i, y6r, y6i, y7r, y7i;
+    
     wn4r = w[1];
     wk1r = w[2];
     wk1i = w[3];
@@ -3187,7 +3187,7 @@ void cftf082(double *a, double *w)
 void cftf040(double *a)
 {
     double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
+    
     x0r = a[0] + a[4];
     x0i = a[1] + a[5];
     x1r = a[0] - a[4];
@@ -3210,7 +3210,7 @@ void cftf040(double *a)
 void cftb040(double *a)
 {
     double x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i;
+    
     x0r = a[0] + a[4];
     x0i = a[1] + a[5];
     x1r = a[0] - a[4];
@@ -3233,7 +3233,7 @@ void cftb040(double *a)
 void cftx020(double *a)
 {
     double x0r, x0i;
+    
     x0r = a[0] - a[2];
     x0i = a[1] - a[3];
     a[0] += a[2];
@@ -3247,7 +3247,7 @@ void rftfsub(int n, double *a, int nc, double *c)
 {
     int j, k, kk, ks, m;
     double wkr, wki, xr, xi, yr, yi;
+    
     m = n >> 1;
     ks = 2 * nc / m;
     kk = 0;
@@ -3272,7 +3272,7 @@ void rftbsub(int n, double *a, int nc, double *c)
 {
     int j, k, kk, ks, m;
     double wkr, wki, xr, xi, yr, yi;
+    
     m = n >> 1;
     ks = 2 * nc / m;
     kk = 0;
@@ -3297,7 +3297,7 @@ void dctsub(int n, double *a, int nc, double *c)
 {
     int j, k, kk, ks, m;
     double wkr, wki, xr;
+    
     m = n >> 1;
     ks = nc / n;
     kk = 0;
@@ -3318,7 +3318,7 @@ void dstsub(int n, double *a, int nc, double *c)
 {
     int j, k, kk, ks, m;
     double wkr, wki, xr;
+    
     m = n >> 1;
     ks = nc / n;
     kk = 0;
index c4b7340386225d28371f74d6d31a7bf53b380e15..b165a0ad7fbc1a9caed04eac636bbaf3414fe7ee 100644 (file)
@@ -24,16 +24,16 @@ void * copy_func_key(char * string);
 
 
 void * copy_func_key(char * string) {
-    
-    char * clone_string;
-    
-    if ((clone_string = malloc(MAX_TOKEN_SIZE)) == NULL)
-        return NULL;
-    
-    strncpy(clone_string, string, MAX_TOKEN_SIZE-1);
-    
-    return (void*)clone_string;
-}    
+       
+       char * clone_string;
+       
+       if ((clone_string = malloc(MAX_TOKEN_SIZE)) == NULL)
+               return NULL;
+       
+       strncpy(clone_string, string, MAX_TOKEN_SIZE-1);
+       
+       return (void*)clone_string;
+}      
 
 
 func_t * create_func (char * name, double (*func_ptr)(), int num_args) {
@@ -44,12 +44,12 @@ func_t * create_func (char * name, double (*func_ptr)(), int num_args) {
   if (func == NULL)
     return NULL;
 
+  
   /* Clear name space */
   memset(func->name, 0, MAX_TOKEN_SIZE);
 
   /* Copy given name into function structure */
-  strncpy(func->name, name, MAX_TOKEN_SIZE);
+  strncpy(func->name, name, MAX_TOKEN_SIZE); 
 
   /* Assign value pointer */
   func->func_ptr = func_ptr;
@@ -118,7 +118,7 @@ func_t * find_func(char * name) {
 
   /* First look in the builtin database */
   func = (func_t *)splay_find(name, builtin_func_tree);
-    
+       
   return func;
 
 }
@@ -130,15 +130,15 @@ int compare_func(char * name, char * name2) {
 
   /* Uses string comparison function */
   cmpval = strncmp(name, name2, MAX_TOKEN_SIZE-1);
+  
   return cmpval;
 }
 
 /* Loads a builtin function */
 int load_builtin_func(char * name,  double (*func_ptr)(), int num_args) {
 
-  func_t * func;
-  int retval;
+  func_t * func; 
+  int retval; 
 
   /* Create new function */
   func = create_func(name, func_ptr, num_args);
@@ -155,7 +155,7 @@ int load_builtin_func(char * name,  double (*func_ptr)(), int num_args) {
 /* Loads all builtin functions */
 int load_all_builtin_func() {
 
+  
   if (load_builtin_func("int", int_wrapper, 1) < 0)
     return ERROR;
   if (load_builtin_func("abs", abs_wrapper, 1) < 0)
index f35d4c78de6aa6f09e79591a77cf35491e9169d3..dcd758350c884f472175c2e0ecdb18da0f303e9c 100644 (file)
@@ -5,7 +5,7 @@
 
 /* Function Type */
 typedef struct FUNC_T {
-  char name[MAX_TOKEN_SIZE];
+  char name[MAX_TOKEN_SIZE];  
   double (*func_ptr)();
   int num_args;
 } func_t;
index 381df494dfd3bf790f45749044eb7c72c137d274..c5ccc71a471cde4eafa24bf68068f8f3ed1edefd 100644 (file)
@@ -57,28 +57,28 @@ void eval_init_cond(init_cond_t * init_cond) {
   /* Parameter is of boolean type, either a 1 or 0 value integer */
 
   /* Set matrix flag to zero. This ensures
-     its constant value will be used rather than a matrix value
+     its constant value will be used rather than a matrix value 
   */
   init_cond->param->matrix_flag = 0;
   if (init_cond->param->type == P_TYPE_BOOL) {
-     if (INIT_COND_DEBUG) printf("init_cond: %s = %d (TYPE BOOL)\n", init_cond->param->name, init_cond->init_val.bool_val);
-     *((int*)init_cond->param->engine_val) = init_cond->init_val.bool_val;
+        if (INIT_COND_DEBUG) printf("init_cond: %s = %d (TYPE BOOL)\n", init_cond->param->name, init_cond->init_val.bool_val); 
+        *((int*)init_cond->param->engine_val) = init_cond->init_val.bool_val;
      return;
   }
+  
   /* Parameter is an integer type, just like C */
+  
   if (init_cond->param->type == P_TYPE_INT) {
-     if (INIT_COND_DEBUG) printf("init_cond: %s = %d (TYPE INT)\n", init_cond->param->name, init_cond->init_val.int_val);
-     *((int*)init_cond->param->engine_val) = init_cond->init_val.int_val;
+        if (INIT_COND_DEBUG) printf("init_cond: %s = %d (TYPE INT)\n", init_cond->param->name, init_cond->init_val.int_val);
+        *((int*)init_cond->param->engine_val) = init_cond->init_val.int_val;
      return;
   }
 
   /* Parameter is of a double type, just like C */
 
   if (init_cond->param->type == P_TYPE_DOUBLE) {
-    if (INIT_COND_DEBUG) printf("init_cond: %s = %f (TYPE DOUBLE)\n", init_cond->param->name, init_cond->init_val.double_val);
-    *((double*)init_cond->param->engine_val) = init_cond->init_val.double_val;
+       if (INIT_COND_DEBUG) printf("init_cond: %s = %f (TYPE DOUBLE)\n", init_cond->param->name, init_cond->init_val.double_val);
+       *((double*)init_cond->param->engine_val) = init_cond->init_val.double_val;
     return;
   }
 
@@ -92,7 +92,7 @@ init_cond_t * new_init_cond(param_t * param, value_t init_val) {
   init_cond_t * init_cond;
 
   init_cond = (init_cond_t*)malloc(sizeof(init_cond_t));
+   
   if (init_cond == NULL)
     return NULL;
  
@@ -103,59 +103,59 @@ init_cond_t * new_init_cond(param_t * param, value_t init_val) {
 
 /* WIP */
 void init_cond_to_string(init_cond_t * init_cond) {
-    
-    int string_length;
-    char string[MAX_TOKEN_SIZE];
-    
-    if (init_cond == NULL)
-        return;
-
-    /* Create a string "param_name=val" */
-    switch (init_cond->param->type) {
+       
+       int string_length;
+       char string[MAX_TOKEN_SIZE];
+       
+       if (init_cond == NULL)
+               return;
+
+       /* Create a string "param_name=val" */
+       switch (init_cond->param->type) {
                 lldiv_t div;
-        
-        case P_TYPE_BOOL:
-            sprintf(string, "%s=%d\n", init_cond->param->name, init_cond->init_val.bool_val);
-            break;
-        case P_TYPE_INT:
-            sprintf(string, "%s=%d\n", init_cond->param->name, init_cond->init_val.int_val);
-            break;
-        case P_TYPE_DOUBLE:
+               
+               case P_TYPE_BOOL:
+                       sprintf(string, "%s=%d\n", init_cond->param->name, init_cond->init_val.bool_val);
+                       break; 
+               case P_TYPE_INT:
+                       sprintf(string, "%s=%d\n", init_cond->param->name, init_cond->init_val.int_val);
+                       break;
+               case P_TYPE_DOUBLE:
                         div = lldiv( init_cond->init_val.double_val * 1000000,
                                      1000000 );
-            sprintf(string, "%s="I64Fd".%06u\n", init_cond->param->name, div.quot, (unsigned int) div.rem );
-            break;
-        default:
-            return;
-    }        
-        
-    /* Compute the length of the string */
-    string_length = strlen(string);
-    
-    /* Buffer overflow check */
-    if ((init_cond_string_buffer_index + string_length + 1)  > (STRING_BUFFER_SIZE - 1))
-        return;
-    
-    /* Copy the string into the initial condition string buffer */
-    
-    strncpy(init_cond_string_buffer + init_cond_string_buffer_index, string, string_length);
-    
-    /* Increment the string buffer, offset by one for the null terminator, which will be
-       overwritten by the next call to this function */
-    init_cond_string_buffer_index+= string_length + 1;
-        
+                       sprintf(string, "%s="I64Fd".%06u\n", init_cond->param->name, div.quot, (unsigned int) div.rem );
+                       break;
+               default:
+                       return;
+       }               
+               
+       /* Compute the length of the string */
+       string_length = strlen(string);
+       
+       /* Buffer overflow check */
+       if ((init_cond_string_buffer_index + string_length + 1)  > (STRING_BUFFER_SIZE - 1))
+               return;
+       
+       /* Copy the string into the initial condition string buffer */
+       
+       strncpy(init_cond_string_buffer + init_cond_string_buffer_index, string, string_length);
+       
+       /* Increment the string buffer, offset by one for the null terminator, which will be
+          overwritten by the next call to this function */
+       init_cond_string_buffer_index+= string_length + 1;
+               
 }
 
 
 char * create_init_cond_string_buffer(splaytree_t * init_cond_tree) {
 
-    if (init_cond_tree == NULL)
-        return NULL;
-    
-    init_cond_string_buffer_index = 0;
-    
-    splay_traverse(init_cond_to_string, init_cond_tree);
-    
-    return init_cond_string_buffer;
-        
+       if (init_cond_tree == NULL)
+               return NULL;
+       
+       init_cond_string_buffer_index = 0;
+       
+       splay_traverse(init_cond_to_string, init_cond_tree);
+       
+       return init_cond_string_buffer;
+               
 }
index 9465cac25384b45a32b317b26566983f218753ee..27a430fbd65cd78c17ef9b9aa5d923049baa9199 100644 (file)
@@ -42,7 +42,7 @@
 #include "expr_types.h"
 #include "eval.h"
 
-#include "engine_vars.h"
+#include "engine_vars.h" 
 
 void reset_param(param_t * param);
 
@@ -59,35 +59,35 @@ int insert_builtin_param(param_t * param);
 /* Private function prototypes */
 int compare_param(char * name, char * name2);
 
-int load_builtin_param_double(char * name, void * engine_val, void * matrix, short int flags,
-                                double init_val, double upper_bound, double lower_bound, char * alt_name);
-
-int load_builtin_param_int(char * name, void * engine_val, short int flags,
-                                int init_val, int upper_bound, int lower_bound, char * alt_name);
-                                
-int load_builtin_param_bool(char * name, void * engine_val, short int flags,
-                                int init_val, char * alt_name);
-                                
-                                
-                                
+int load_builtin_param_double(char * name, void * engine_val, void * matrix, short int flags, 
+                                                               double init_val, double upper_bound, double lower_bound, char * alt_name);
+
+int load_builtin_param_int(char * name, void * engine_val, short int flags, 
+                                                               int init_val, int upper_bound, int lower_bound, char * alt_name);
+                                                               
+int load_builtin_param_bool(char * name, void * engine_val, short int flags, 
+                                                               int init_val, char * alt_name);
+                                                               
+                                                               
+                                                               
 param_t * create_param (char * name, short int type, short int flags, void * engine_val, void * matrix,
-                            value_t default_init_val, value_t upper_bound, value_t lower_bound) {
+                                                       value_t default_init_val, value_t upper_bound, value_t lower_bound) {
 
   param_t * param = NULL;
 
   param = (param_t*)malloc(sizeof(param_t));
  
   if (param == NULL) {
-    printf("create_param: out of memory!!!\n");
-    return NULL;
+       printf("create_param: out of memory!!!\n");
+       return NULL;
   }
+  
   /* Clear name space, think the strncpy statement makes this redundant */
   //memset(param->name, 0, MAX_TOKEN_SIZE);
 
   /* Copy given name into parameter structure */
-  strncpy(param->name, name, MAX_TOKEN_SIZE-1);
+  strncpy(param->name, name, MAX_TOKEN_SIZE-1); 
+  
   /* Assign other entries in a constructor like fashion */
   param->type = type;
   param->flags = flags;
@@ -98,7 +98,7 @@ param_t * create_param (char * name, short int type, short int flags, void * eng
   //*param->init_val = default_init_val;
   param->upper_bound = upper_bound;
   param->lower_bound = lower_bound;
+  
   /* Return instantiated parameter */
   return param;
 
@@ -112,7 +112,7 @@ param_t * create_user_param(char * name) {
   value_t ub;
   value_t lb;
   double * engine_val;
+  
   /* Set initial values to default */
   iv.double_val = DEFAULT_DOUBLE_IV;
   ub.double_val = DEFAULT_DOUBLE_UB;
@@ -127,7 +127,7 @@ param_t * create_user_param(char * name) {
     return NULL;
 
   (*engine_val) = iv.double_val; /* set some default init value */
+  
   /* Create the new user parameter */
   if ((param = create_param(name, P_TYPE_DOUBLE, P_FLAG_USERDEF, engine_val, NULL, iv, ub, lb)) == NULL) {
     free(engine_val);
@@ -141,26 +141,26 @@ param_t * create_user_param(char * name) {
 /* Initialize the builtin parameter database.
    Should only be necessary once */
 int init_builtin_param_db() {
-    
+       
   /* Create the builtin parameter splay tree (go Sleator...) */
   if ((builtin_param_tree = create_splaytree(compare_string, copy_string, free_string)) == NULL) {
-      if (PARAM_DEBUG) printf("init_builtin_param_db: failed to initialize database (FATAL)\n");
-      return OUTOFMEM_ERROR;
-  }
+         if (PARAM_DEBUG) printf("init_builtin_param_db: failed to initialize database (FATAL)\n");  
+         return OUTOFMEM_ERROR;
+  } 
 
   if (PARAM_DEBUG) {
-      printf("init_builtin_param: loading database...");
-      fflush(stdout);
+         printf("init_builtin_param: loading database...");
+         fflush(stdout);
   }
+  
   /* Loads all builtin parameters into the database */
   if (load_all_builtin_param() < 0) {
-    if (PARAM_DEBUG) printf("failed loading builtin parameters (FATAL)\n");
+       if (PARAM_DEBUG) printf("failed loading builtin parameters (FATAL)\n");
     return ERROR;
   }
+  
   if (PARAM_DEBUG) printf("success!\n");
-    
+         
   /* Finished, no errors */
   return SUCCESS;
 }
@@ -168,23 +168,23 @@ int init_builtin_param_db() {
 /* Destroy the builtin parameter database.
    Generally, do this on projectm exit */
 int destroy_builtin_param_db() {
+  
   splay_traverse(free_param, builtin_param_tree);
   destroy_splaytree(builtin_param_tree);
   builtin_param_tree = NULL;
-  return SUCCESS;    
+  return SUCCESS;      
 
 }
 
 
 /* Insert a parameter into the database with an alternate name */
 int insert_param_alt_name(param_t * param, char * alt_name) {
+  
   if (param == NULL)
     return ERROR;
   if (alt_name == NULL)
-      return ERROR;
-      
+         return ERROR;
+       
   splay_insert_link(alt_name, param->name, builtin_param_tree);
 
   return SUCCESS;
@@ -195,8 +195,8 @@ param_t * find_builtin_param(char * name) {
 
   /* Null argument checks */
   if (name == NULL)
-      return NULL;
+         return NULL;
+    
   return splay_find(name, builtin_param_tree);
 
 }
@@ -208,10 +208,10 @@ param_t * find_param(char * name, preset_t * preset, int flags) {
 
   /* Null argument checks */
   if (name == NULL)
-      return NULL;
+         return NULL;
   if (preset == NULL)
-      return NULL;
+         return NULL;
+  
   /* First look in the builtin database */
   param = (param_t *)splay_find(name, builtin_param_tree);
 
@@ -219,13 +219,13 @@ param_t * find_param(char * name, preset_t * preset, int flags) {
   if (param == NULL) {
     param = (param_t*)splay_find(name, preset->user_param_tree);
   }
-  /* If it doesn't exist in the user (or builtin) database and
-        create_flag is set, then make it and insert into the database
+  /* If it doesn't exist in the user (or builtin) database and 
+         create_flag is set, then make it and insert into the database 
   */
+  
   if ((param == NULL) && (flags & P_CREATE)) {
-    
-    /* Check if string is valid */
+       
+       /* Check if string is valid */
     if (!is_valid_param_string(name)) {
       if (PARAM_DEBUG) printf("find_param: invalid parameter name:\"%s\"\n", name);
       return NULL;
@@ -240,13 +240,13 @@ param_t * find_param(char * name, preset_t * preset, int flags) {
       if (PARAM_DEBUG) printf("PARAM \"%s\" already exists in user parameter tree!\n", param->name);
       free_param(param);
       return NULL;
-    }    
-  }    
+    }   
+    
+  }      
+  
   /* Return the found (or created) parameter. Note that if P_CREATE is not set, this could be null */
   return param;
+  
 }
 
 /* Compare string name with parameter name */
@@ -256,7 +256,7 @@ int compare_param(char * name, char * name2) {
   printf("am i used\n");
   /* Uses string comparison function */
   cmpval = strncmp(name, name2, MAX_TOKEN_SIZE-1);
+  
   return cmpval;
 }
 
@@ -269,18 +269,18 @@ int load_all_builtin_param() {
   load_builtin_param_double("echo_zoom", (void*)&fVideoEchoZoom, NULL, P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, 0, "fVideoEchoZoom");
   load_builtin_param_double("echo_alpha", (void*)&fVideoEchoAlpha, NULL, P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, 0, "fVideoEchoAlpha");
   load_builtin_param_double("wave_a", (void*)&fWaveAlpha, NULL, P_FLAG_NONE, 0.0, 1.0, 0, "fWaveAlpha");
-  load_builtin_param_double("fWaveSmoothing", (void*)&fWaveSmoothing, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL);
+  load_builtin_param_double("fWaveSmoothing", (void*)&fWaveSmoothing, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL);  
   load_builtin_param_double("fModWaveAlphaStart", (void*)&fModWaveAlphaStart, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL);
   load_builtin_param_double("fModWaveAlphaEnd", (void*)&fModWaveAlphaEnd, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL);
   load_builtin_param_double("fWarpAnimSpeed",  (void*)&fWarpAnimSpeed, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL);
   //  load_builtin_param_double("warp", (void*)&warp, warp_mesh, P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, 0, NULL);
-    
+       
   load_builtin_param_double("fShader", (void*)&fShader, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL);
   load_builtin_param_double("decay", (void*)&decay, NULL, P_FLAG_NONE, 0.0, 1.0, 0, "fDecay");
 
   load_builtin_param_int("echo_orient", (void*)&nVideoEchoOrientation, P_FLAG_NONE, 0, 3, 0, "nVideoEchoOrientation");
   load_builtin_param_int("wave_mode", (void*)&nWaveMode, P_FLAG_NONE, 0, 7, 0, "nWaveMode");
+  
   load_builtin_param_bool("wave_additive", (void*)&bAdditiveWaves, P_FLAG_NONE, FALSE, "bAdditiveWaves");
   load_builtin_param_bool("bModWaveAlphaByVolume", (void*)&bModWaveAlphaByVolume, P_FLAG_NONE, FALSE, NULL);
   load_builtin_param_bool("wave_brighten", (void*)&bMaximizeWaveColor, P_FLAG_NONE, FALSE, "bMaximizeWaveColor");
@@ -295,8 +295,8 @@ int load_all_builtin_param() {
   load_builtin_param_bool("wave_dots", (void*)&bWaveDots, P_FLAG_NONE, FALSE, "bWaveDots");
   load_builtin_param_bool("wave_thick", (void*)&bWaveThick, P_FLAG_NONE, FALSE, "bWaveThick");
  
+  
+  
   load_builtin_param_double("zoom", (void*)&zoom, zoom_mesh,  P_FLAG_PER_PIXEL |P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, 0, NULL);
   load_builtin_param_double("rot", (void*)&rot, rot_mesh,  P_FLAG_PER_PIXEL |P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, NULL);
   load_builtin_param_double("zoomexp", (void*)&zoomexp, zoomexp_mesh,  P_FLAG_PER_PIXEL |P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, 0, "fZoomExponent");
@@ -314,7 +314,7 @@ int load_all_builtin_param() {
   load_builtin_param_double("wave_x", (void*)&wave_x, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
   load_builtin_param_double("wave_y", (void*)&wave_y, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
   load_builtin_param_double("wave_mystery", (void*)&wave_mystery, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, "fWaveParam");
+  
   load_builtin_param_double("ob_size", (void*)&ob_size, NULL, P_FLAG_NONE, 0.0, 0.5, 0, NULL);
   load_builtin_param_double("ob_r", (void*)&ob_r, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
   load_builtin_param_double("ob_g", (void*)&ob_g, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
@@ -337,9 +337,9 @@ int load_all_builtin_param() {
   load_builtin_param_double("mv_dx", (void*)&mv_dx,  NULL,P_FLAG_NONE, 0.0, 1.0, -1.0, NULL);
   load_builtin_param_double("mv_a", (void*)&mv_a,  NULL,P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
 
-  load_builtin_param_double("time", (void*)&Time,  NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0.0, NULL);
+  load_builtin_param_double("time", (void*)&Time,  NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0.0, NULL);        
   load_builtin_param_double("bass", (void*)&bass,  NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0.0, NULL);
-  load_builtin_param_double("mid", (void*)&mid,  NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0, NULL);
+  load_builtin_param_double("mid", (void*)&mid,  NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0, NULL);      
   load_builtin_param_double("bass_att", (void*)&bass_att,  NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0, NULL);
   load_builtin_param_double("mid_att", (void*)&mid_att,  NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0, NULL);
   load_builtin_param_double("treb_att", (void*)&treb_att,  NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0, NULL);
@@ -349,14 +349,14 @@ int load_all_builtin_param() {
 
 
 
-  load_builtin_param_double("x", (void*)&x_per_pixel, x_mesh,  P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX,
-                0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
-  load_builtin_param_double("y", (void*)&y_per_pixel, y_mesh,  P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX |P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX,
-                0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
-  load_builtin_param_double("ang", (void*)&ang_per_pixel, theta_mesh,  P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX,
-                0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
-  load_builtin_param_double("rad", (void*)&rad_per_pixel, rad_mesh,  P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX,
-                0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
+  load_builtin_param_double("x", (void*)&x_per_pixel, x_mesh,  P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX, 
+                           0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
+  load_builtin_param_double("y", (void*)&y_per_pixel, y_mesh,  P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX |P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX, 
+                           0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
+  load_builtin_param_double("ang", (void*)&ang_per_pixel, theta_mesh,  P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX, 
+                           0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);      
+  load_builtin_param_double("rad", (void*)&rad_per_pixel, rad_mesh,  P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX, 
+                           0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
 
 
   load_builtin_param_double("q1", (void*)&q1,  NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
@@ -374,16 +374,16 @@ int load_all_builtin_param() {
   load_builtin_param_int("meshx", (void*)&gx, P_FLAG_READONLY, 32, 96, 8, NULL);
   load_builtin_param_int("meshy", (void*)&gy, P_FLAG_READONLY, 24, 72, 6, NULL);
 
-  return SUCCESS;
+  return SUCCESS;  
+  
 }
 
 /* Free's a parameter type */
 void free_param(param_t * param) {
   int x;
   if (param == NULL)
-    return;
+       return;
+  
   if (param->flags & P_FLAG_USERDEF) {
     free(param->engine_val);
 
@@ -395,8 +395,8 @@ void free_param(param_t * param) {
       free(param->matrix);
 
     else if (param->flags & P_FLAG_PER_PIXEL) {
-       for(x = 0; x < gx; x++)
-       free(((double**)param->matrix)[x]);
+       for(x = 0; x < gx; x++) 
+          free(((double**)param->matrix)[x]);
        free(param->matrix);
       }
   }
@@ -407,8 +407,8 @@ void free_param(param_t * param) {
 }
 
 /* Loads a double parameter into the builtin database */
-int load_builtin_param_double(char * name, void * engine_val, void * matrix, short int flags,
-                        double init_val, double upper_bound, double lower_bound, char * alt_name) {
+int load_builtin_param_double(char * name, void * engine_val, void * matrix, short int flags, 
+                                               double init_val, double upper_bound, double lower_bound, char * alt_name) {
 
   param_t * param = NULL;
   value_t iv, ub, lb;
@@ -416,48 +416,48 @@ int load_builtin_param_double(char * name, void * engine_val, void * matrix, sho
   iv.double_val = init_val;
   ub.double_val = upper_bound;
   lb.double_val = lower_bound;
-                            
+                                                       
   /* Create new parameter of type double */
   if (PARAM_DEBUG == 2) {
-      printf("load_builtin_param_double: (name \"%s\") (alt_name = \"%s\") ", name, alt_name);
-      fflush(stdout);
-  }
+         printf("load_builtin_param_double: (name \"%s\") (alt_name = \"%s\") ", name, alt_name);
+         fflush(stdout);
+  }  
+  
  if ((param = create_param(name, P_TYPE_DOUBLE, flags, engine_val, matrix, iv, ub, lb)) == NULL) {
     return OUTOFMEM_ERROR;
   }
+  
   if (PARAM_DEBUG == 2) {
-    printf("created...");
-    fflush(stdout);
-   }    
+       printf("created...");
+       fflush(stdout);
+   }     
+   
   /* Insert the paremeter into the database */
 
   if (insert_builtin_param(param) < 0) {
-    free_param(param);
+       free_param(param);
     return ERROR;
   }
 
   if (PARAM_DEBUG == 2) {
-      printf("inserted...");
-      fflush(stdout);
-  }
+         printf("inserted...");
+         fflush(stdout);
+  }  
+  
   /* If this parameter has an alternate name, insert it into the database as link */
+  
   if (alt_name != NULL) {
-    insert_param_alt_name(param, alt_name);
+       insert_param_alt_name(param, alt_name); 
 
   if (PARAM_DEBUG == 2) {
-      printf("alt_name inserted...");
-      fflush(stdout);
-      }
-    
-  }      
-
-  if (PARAM_DEBUG == 2) printf("finished\n");    
+         printf("alt_name inserted...");
+         fflush(stdout);
+       }
+  
+       
+  }      
+
+  if (PARAM_DEBUG == 2) printf("finished\n");    
   /* Finished, return success */
   return SUCCESS;
 }
@@ -466,7 +466,7 @@ int load_builtin_param_double(char * name, void * engine_val, void * matrix, sho
 
 /* Loads a double parameter into the builtin database */
 param_t * new_param_double(char * name, short int flags, void * engine_val, void * matrix,
-                        double upper_bound, double lower_bound, double init_val) {
+                                               double upper_bound, double lower_bound, double init_val) {
 
   param_t * param;
   value_t iv, ub, lb;
@@ -474,11 +474,11 @@ param_t * new_param_double(char * name, short int flags, void * engine_val, void
   iv.double_val = init_val;
   ub.double_val = upper_bound;
   lb.double_val = lower_bound;
-                             
-  if ((param = create_param(name, P_TYPE_DOUBLE, flags, engine_val, matrix,iv, ub, lb)) == NULL)
+                                               
+  if ((param = create_param(name, P_TYPE_DOUBLE, flags, engine_val, matrix,iv, ub, lb)) == NULL) 
     return NULL;
+  
+  
   /* Finished, return success */
   return param;
 }
@@ -486,7 +486,7 @@ param_t * new_param_double(char * name, short int flags, void * engine_val, void
 
 /* Creates a new parameter of type int */
 param_t * new_param_int(char * name, short int flags, void * engine_val,
-                        int upper_bound, int lower_bound, int init_val) {
+                                               int upper_bound, int lower_bound, int init_val) {
 
   param_t * param;
   value_t iv, ub, lb;
@@ -494,10 +494,10 @@ param_t * new_param_int(char * name, short int flags, void * engine_val,
   iv.int_val = init_val;
   ub.int_val = upper_bound;
   lb.int_val = lower_bound;
-                            
-  if ((param = create_param(name, P_TYPE_INT, flags, engine_val, NULL, iv, ub, lb)) == NULL)
+                                                       
+  if ((param = create_param(name, P_TYPE_INT, flags, engine_val, NULL, iv, ub, lb)) == NULL) 
     return NULL;
+  
  
   /* Finished, return success */
   return param;
@@ -505,7 +505,7 @@ param_t * new_param_int(char * name, short int flags, void * engine_val,
 
 /* Creates a new parameter of type bool */
 param_t * new_param_bool(char * name, short int flags, void * engine_val,
-                        int upper_bound, int lower_bound, int init_val) {
+                                               int upper_bound, int lower_bound, int init_val) {
 
   param_t * param;
   value_t iv, ub, lb;
@@ -513,10 +513,10 @@ param_t * new_param_bool(char * name, short int flags, void * engine_val,
   iv.bool_val = init_val;
   ub.bool_val = upper_bound;
   lb.bool_val = lower_bound;
-                            
+                                                       
   if ((param = create_param(name, P_TYPE_BOOL, flags, engine_val, NULL, iv, ub, lb)) == NULL)
     return NULL;
+  
  
   /* Finished, return success */
   return param;
@@ -525,15 +525,15 @@ param_t * new_param_bool(char * name, short int flags, void * engine_val,
 
 /* Loads a integer parameter into the builtin database */
 int load_builtin_param_int(char * name, void * engine_val, short int flags,
-                        int init_val, int upper_bound, int lower_bound, char * alt_name) {
+                                               int init_val, int upper_bound, int lower_bound, char * alt_name) {
 
   param_t * param;
   value_t iv, ub, lb;
 
   iv.int_val = init_val;
   ub.int_val = upper_bound;
-  lb.int_val = lower_bound;    
-                            
+  lb.int_val = lower_bound;    
+                                                       
   param = create_param(name, P_TYPE_INT, flags, engine_val, NULL, iv, ub, lb);
 
   if (param == NULL) {
@@ -541,29 +541,29 @@ int load_builtin_param_int(char * name, void * engine_val, short int flags,
   }
 
   if (insert_builtin_param(param) < 0) {
-    free_param(param);
+       free_param(param);
     return ERROR;
   }
+  
   if (alt_name != NULL) {
-    insert_param_alt_name(param, alt_name);      
-  }
+       insert_param_alt_name(param, alt_name);          
+  }  
+  
   return SUCCESS;
 
-}                            
-                            
+}                                                      
+                                                       
 /* Loads a boolean parameter */
-int load_builtin_param_bool(char * name, void * engine_val, short int flags,
-                                int init_val, char * alt_name) {
+int load_builtin_param_bool(char * name, void * engine_val, short int flags, 
+                                                               int init_val, char * alt_name) {
 
   param_t * param;
   value_t iv, ub, lb;
 
   iv.int_val = init_val;
   ub.int_val = TRUE;
-  lb.int_val = FALSE;    
-                                                                
+  lb.int_val = FALSE;  
+                                                                                                                               
   param = create_param(name, P_TYPE_BOOL, flags, engine_val, NULL, iv, ub, lb);
 
   if (param == NULL) {
@@ -571,115 +571,115 @@ int load_builtin_param_bool(char * name, void * engine_val, short int flags,
   }
 
   if (insert_builtin_param(param) < 0) {
-    free_param(param);
+       free_param(param);
     return ERROR;
   }
+  
   if (alt_name != NULL) {
-    insert_param_alt_name(param, alt_name);      
-  }
+       insert_param_alt_name(param, alt_name);          
+  }  
+  
   return SUCCESS;
 
 }
 
 
-    
+       
 
 /* Returns nonzero if the string is valid parameter name */
 int is_valid_param_string(char * string) {
+  
   if (string == NULL)
     return FALSE;
+  
   /* This ensures the first character is non numeric */
   if( ((*string) >= 48) && ((*string) <= 57))
-    return FALSE;
+    return FALSE; 
 
   /* These probably should never happen */
   if (*string == '.')
-    return FALSE;
+       return FALSE;
+  
   if (*string == '+')
-    return FALSE;
+       return FALSE;
+  
   if (*string == '-')
-    return FALSE;
+       return FALSE;
+  
   /* Could also add checks for other symbols. May do later */
+  
   return TRUE;
+   
 }
 
 /* Inserts a parameter into the builtin database */
 int insert_builtin_param(param_t * param) {
 
-    if (param == NULL)
-        return FAILURE;
-    
-    return splay_insert(param, param->name, builtin_param_tree);    
+       if (param == NULL)
+               return FAILURE;
+       
+       return splay_insert(param, param->name, builtin_param_tree);    
 }
 
 /* Inserts a parameter into the builtin database */
 int insert_param(param_t * param, splaytree_t * database) {
 
-    if (param == NULL)
-      return FAILURE;
-    if (database == NULL)
-      return FAILURE;
+       if (param == NULL)
+         return FAILURE;
+       if (database == NULL)
+         return FAILURE;
 
-    return splay_insert(param, param->name, database);    
+       return splay_insert(param, param->name, database);      
 }
 
 
 /* Sets the parameter engine value to value val.
-    clipping occurs if necessary */
+       clipping occurs if necessary */
 void set_param(param_t * param, double val) {
 
-    switch (param->type) {
-        
-    case P_TYPE_BOOL:
-        if (val < 0)
-            *((int*)param->engine_val) = 0;
-        else if (val > 0)
-            *((int*)param->engine_val) = 1;
-        else
-            *((int*)param->engine_val) = 0;
-        break;
-    case P_TYPE_INT:
-        /* Make sure value is an integer */
-        val = floor(val);
-        if (val < param->lower_bound.int_val)
-                *((int*)param->engine_val) = param->lower_bound.int_val;
-        else if (val > param->upper_bound.int_val)
-                *((int*)param->engine_val) = param->upper_bound.int_val;
-        else
-                *((int*)param->engine_val) = val;
-        break;
-    case P_TYPE_DOUBLE:
-      /* Make sure value is an integer */    
-
-    
-      if (val < param->lower_bound.double_val)
-        *((double*)param->engine_val) = param->lower_bound.double_val;    
-      else if (val > param->upper_bound.double_val)
-        *((double*)param->engine_val) = param->upper_bound.double_val;
-      else
-        *((double*)param->engine_val) = val;
-      break;
-    default:
-      break;
-
-    }
-    
-    return;
+       switch (param->type) {
+               
+       case P_TYPE_BOOL:
+               if (val < 0)
+                       *((int*)param->engine_val) = 0;
+               else if (val > 0)
+                       *((int*)param->engine_val) = 1;
+               else
+                       *((int*)param->engine_val) = 0;
+               break;
+       case P_TYPE_INT:
+               /* Make sure value is an integer */
+               val = floor(val);
+               if (val < param->lower_bound.int_val)
+                               *((int*)param->engine_val) = param->lower_bound.int_val;
+               else if (val > param->upper_bound.int_val)
+                               *((int*)param->engine_val) = param->upper_bound.int_val;
+               else
+                               *((int*)param->engine_val) = val;
+               break;
+       case P_TYPE_DOUBLE:
+         /* Make sure value is an integer */   
+
+        
+         if (val < param->lower_bound.double_val) 
+           *((double*)param->engine_val) = param->lower_bound.double_val;        
+         else if (val > param->upper_bound.double_val)
+           *((double*)param->engine_val) = param->upper_bound.double_val;
+         else
+           *((double*)param->engine_val) = val;
+         break;
+       default:
+         break;
+
+       }
+       
+       return;
 }
 
 
 
 
-/* Search for parameter 'name' in 'database', if create_flag is true, then generate the parameter
+/* Search for parameter 'name' in 'database', if create_flag is true, then generate the parameter 
    and insert it into 'database' */
 param_t * find_param_db(char * name, splaytree_t * database, int create_flag) {
 
@@ -690,29 +690,29 @@ param_t * find_param_db(char * name, splaytree_t * database, int create_flag) {
     return NULL;
   if (database == NULL)
     return NULL;
+  
   /* First look in the builtin database */
   param = (param_t *)splay_find(name, database);
 
+  
   if (((param = (param_t *)splay_find(name, database)) == NULL) && (create_flag == TRUE)) {
-    
-    /* Check if string is valid */
-    if (!is_valid_param_string(name))
-        return NULL;
-    
-    /* Now, create the user defined parameter given the passed name */
-    if ((param = create_user_param(name)) == NULL)
-        return NULL;
-    
-    /* Finally, insert the new parameter into this preset's proper splaytree */
-    if (splay_insert(param, param->name, database) < 0) {
-        free_param(param);
-        return NULL;
-    }    
-    
-  }    
+       
+       /* Check if string is valid */
+       if (!is_valid_param_string(name))
+               return NULL;
+       
+       /* Now, create the user defined parameter given the passed name */
+       if ((param = create_user_param(name)) == NULL)
+               return NULL;
+       
+       /* Finally, insert the new parameter into this preset's proper splaytree */
+       if (splay_insert(param, param->name, database) < 0) {
+               free_param(param);
+               return NULL;
+       }        
+       
+  }      
+  
   /* Return the found (or created) parameter. Note that this could be null */
   return param;
 
index 53552aec7e2af5ead9101803317329d8bd2c4a1f..1fc6713a9c77e92dbe02c9b48bd660aca81d16e6 100644 (file)
@@ -9,7 +9,7 @@
 
 /* Function prototypes */
 param_t * create_param (char * name, short int type, short int flags, void * eqn_val, void * matrix,
-                            value_t default_init_val, value_t upper_bound, value_t lower_bound);
+                                                       value_t default_init_val, value_t upper_bound, value_t lower_bound);
 param_t * create_user_param(char * name);
 int init_builtin_param_db();
 int init_user_param_db();
@@ -23,13 +23,13 @@ int load_all_builtin_param();
 int insert_param(param_t * param, splaytree_t * database);
 param_t * find_builtin_param(char * name);
 param_t * new_param_double(char * name, short int flags, void * engine_val, void * matrix,
-                double upper_bound, double lower_bound, double init_val);
+                       double upper_bound, double lower_bound, double init_val);
 
 param_t * new_param_int(char * name, short int flags, void * engine_val,
-            int upper_bound, int lower_bound, int init_val);
+                       int upper_bound, int lower_bound, int init_val);
 
 param_t * new_param_bool(char * name, short int flags, void * engine_val,
-             int upper_bound, int lower_bound, int init_val);
+                        int upper_bound, int lower_bound, int init_val);
 
 param_t * find_param_db(char * name, splaytree_t * database, int create_flag);
 
index c92cd4f6bcbc6cd8391e3b65977b089aba6fca60..aae00cff406a0d04dccfd8a925ff5da96fa89458 100644 (file)
 typedef union VALUE_T {
   int bool_val;
   int int_val;
-  double double_val;    
+  double double_val;   
 } value_t;
 
 /* Parameter Type */
 typedef struct PARAM_T {
   char name[MAX_TOKEN_SIZE]; /* name of the parameter, not necessary but useful neverthless */
-  short int type; /* parameter number type (int, bool, or double) */    
-  short int flags; /* read, write, user defined, etc */    
+  short int type; /* parameter number type (int, bool, or double) */   
+  short int flags; /* read, write, user defined, etc */        
   short int matrix_flag; /* for optimization purposes */
   void * engine_val; /* pointer to the engine variable */
   void * matrix; /* per pixel / per point matrix for this variable */
index d255290edf57b05e86eed69e3b8dec9784d48a53..8beaca46183bdfeb12b171029557df142bb4c5ab 100644 (file)
 #define WAVE_INIT_STRING_LENGTH 4
 
 /* Stores a line of a file as its being parsed */
-char string_line_buffer[STRING_LINE_SIZE];
+char string_line_buffer[STRING_LINE_SIZE]; 
 
 /* The current position of the string line buffer (see above) */
 int string_line_buffer_index = 0;
@@ -191,69 +191,69 @@ int string_to_float(char * string, double * float_ptr);
    to the raw string */
 
 token_t parseToken(FILE * fs, char * string) {
+  
   char c;
   int i;
+  
   if (string != NULL)
     memset(string, 0, MAX_TOKEN_SIZE);
+  
   /* Loop until a delimiter is found, or the maximum string size is found */
   for (i = 0; i < MAX_TOKEN_SIZE;i++) {
     c = fgetc(fs);
+    
     /* If the string line buffer is full, quit */
     if (string_line_buffer_index == (STRING_LINE_SIZE - 1))
       return tStringBufferFilled;
+    
     /* Otherwise add this character to the string line buffer */
     string_line_buffer[string_line_buffer_index++] = c;
     /* Now interpret the character */
     switch (c) {
+      
     case '+':
-      return tPlus;
+      return tPlus; 
     case '-':
       return tMinus;
     case '%':
       return tMod;
     case '/':
+      
       /* check for line comment here */
       if ((c = fgetc(fs)) == '/') {
-    while(1) {
-      c = fgetc(fs);
-      if (c == EOF) {
-        line_mode = NORMAL_LINE_MODE;
-        return tEOF;                
-      }
-      if (c == '\n') {
-        line_mode = NORMAL_LINE_MODE;
-        return tEOL;
-      }
-    }
-    
+       while(1) {
+         c = fgetc(fs);
+         if (c == EOF) {
+           line_mode = NORMAL_LINE_MODE;
+           return tEOF;                                
+         }
+         if (c == '\n') {
+           line_mode = NORMAL_LINE_MODE;
+           return tEOL;
+         }
+       }
+       
       }
+      
       /* Otherwise, just a regular division operator */
       ungetc(c, fs);
       return tDiv;
+      
     case '*':
       return tMult;
     case '|':
       return tOr;
     case '&':
       return tAnd;
-    case '(':
+    case '(': 
       return tLPr;
     case ')':
       return tRPr;
-    case '[':
+    case '[': 
       return tLBr;
     case ']':
       return tRBr;
-    case '=':
+    case '=': 
       return tEq;
       //    case '\r':
       //break;
@@ -272,20 +272,20 @@ token_t parseToken(FILE * fs, char * string) {
       line_count = 1;
       line_mode = NORMAL_LINE_MODE;
       return tEOF;
-    default:
+      
+    default: 
       if (string != NULL)
-    string[i] = c;
-    }
+       string[i] = c;
+    } 
+    
   }
- /* String reached maximum length, return special token error */
+  
+ /* String reached maximum length, return special token error */ 
   return tStringTooLong;
+  
 }
 
-/* Parse input in the form of "exp, exp, exp, ...)"
+/* Parse input in the form of "exp, exp, exp, ...)" 
    Returns a general expression list */
 
 gen_expr_t ** parse_prefix_args(FILE * fs, int num_args, struct PRESET_T * preset) {
@@ -293,15 +293,15 @@ gen_expr_t ** parse_prefix_args(FILE * fs, int num_args, struct PRESET_T * prese
   int i, j;
   gen_expr_t ** expr_list; /* List of arguments to function */
   gen_expr_t * gen_expr;
+  
   /* Malloc the expression list */
   expr_list =  (gen_expr_t**)malloc(sizeof(gen_expr_t*)*num_args);
+  
   /* Malloc failed */
   if (expr_list == NULL)
     return NULL;
+  
+  
   i = 0;
 
   while (i < num_args) {
@@ -309,19 +309,19 @@ gen_expr_t ** parse_prefix_args(FILE * fs, int num_args, struct PRESET_T * prese
     /* Parse the ith expression in the list */
     if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL) {
       //if (PARSE_DEBUG) printf("parse_prefix_args: failed to get parameter # %d for function (LINE %d)\n", i+1, line_count);
-      for (j = 0; j < i; j++)
-    free_gen_expr(expr_list[j]);
+      for (j = 0; j < i; j++) 
+       free_gen_expr(expr_list[j]);
       free(expr_list);
       return NULL;
     }
     /* Assign entry in expression list */
     expr_list[i++] = gen_expr;
   }
-  //if (PARSE_DEBUG) printf("parse_prefix_args: finished parsing %d arguments (LINE %d)\n", num_args, line_count);    
+  
+  //if (PARSE_DEBUG) printf("parse_prefix_args: finished parsing %d arguments (LINE %d)\n", num_args, line_count);     
   /* Finally, return the resulting expression list */
   return expr_list;
+  
 }
 
 /* Parses a comment at the top of the file. Stops when left bracket is found */
@@ -329,16 +329,16 @@ int parse_top_comment(FILE * fs) {
 
   char string[MAX_TOKEN_SIZE];
   token_t token;
-    
+         
   /* Process tokens until left bracket is found */
   while ((token = parseToken(fs, string)) != tLBr) {
-    if (token == tEOF)
+    if (token == tEOF) 
       return PARSE_ERROR;
   }
 
  /* Done, return success */
- return SUCCESS;
-}    
+ return SUCCESS; 
+}      
 
 /* Right Bracket is parsed by this function.
    puts a new string into name */
@@ -347,13 +347,13 @@ int parse_preset_name(FILE * fs, char * name) {
   token_t token;
 
   if (name == NULL)
-    return FAILURE;
+       return FAILURE;
 
   if ((token = parseToken(fs, name)) != tRBr)
     return PARSE_ERROR;
-     
+       
   //if (PARSE_DEBUG) printf("parse_preset_name: parsed preset (name = \"%s\")\n", name);
+  
   return SUCCESS;
 }
 
@@ -368,17 +368,17 @@ int parse_per_pixel_eqn(FILE * fs, preset_t * preset) {
   if (PARSE_DEBUG) printf("parse_per_pixel: per_pixel equation parsing start...(LINE %d)\n", line_count);
 
   if (parseToken(fs, string) != tEq) { /* parse per pixel operator  name */
-    if (PARSE_DEBUG) printf("parse_per_pixel: equal operator expected after per pixel operator \"%s\", but not found (LINE %d)\n",
-                    string, line_count);
+    if (PARSE_DEBUG) printf("parse_per_pixel: equal operator expected after per pixel operator \"%s\", but not found (LINE %d)\n", 
+                           string, line_count);
     return PARSE_ERROR;
   }
+  
   /* Parse right side of equation as an expression */
   if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL) {
     if (PARSE_DEBUG) printf("parse_per_pixel: equation evaluated to null? (LINE %d)\n", line_count);
     return PARSE_ERROR;
   }
+  
   /* Add the per pixel equation */
   if (add_per_pixel_eqn(string, gen_expr, preset) < 0) {
     free_gen_expr(gen_expr);
@@ -395,14 +395,14 @@ int parse_line(FILE * fs, struct PRESET_T * preset) {
   token_t token;
   init_cond_t * init_cond;
   per_frame_eqn_t * per_frame_eqn;
+  
   /* Clear the string line buffer */
   memset(string_line_buffer, 0, STRING_LINE_SIZE);
   string_line_buffer_index = 0;
+  
+  
   switch (token = parseToken(fs, eqn_string)) {
+    
     /* Invalid Cases */
   case tRBr:
   case tLPr:
@@ -416,222 +416,222 @@ int parse_line(FILE * fs, struct PRESET_T * preset) {
   case tOr:
   case tAnd:
   case tDiv:
+    
     //    if (PARSE_DEBUG) printf("parse_line: invalid token found at start of line (LINE %d)\n", line_count);
     /* Invalid token found, return a parse error */
     return PARSE_ERROR;
+    
+    
   case tEOL:  /* Empty line */
     line_mode = NORMAL_LINE_MODE;
     return SUCCESS;
+    
   case tEOF: /* End of File */
     line_mode = NORMAL_LINE_MODE;
     line_count = 1;
     return EOF;
+    
   case tSemiColon: /* Indicates end of expression */
     return SUCCESS;
+    
     /* Valid Case, either an initial condition or equation should follow */
   case tEq:
-    /* CASE: PER FRAME INIT EQUATION */    
+    
+    /* CASE: PER FRAME INIT EQUATION */            
     if (!strncmp(eqn_string, PER_FRAME_INIT_STRING, PER_FRAME_INIT_STRING_LENGTH)) {
+      
       //if (PARSE_DEBUG) printf("parse_line: per frame init equation found...(LINE %d)\n", line_count);
+      
       /* Set the line mode to normal */
       line_mode = NORMAL_LINE_MODE;
+      
       /* Parse the per frame equation */
       if ((init_cond = parse_per_frame_init_eqn(fs, preset, NULL)) == NULL) {
-    //if (PARSE_DEBUG) printf("parse_line: per frame init equation parsing failed (LINE %d)\n", line_count);
-    return PARSE_ERROR;
-      }    
+       //if (PARSE_DEBUG) printf("parse_line: per frame init equation parsing failed (LINE %d)\n", line_count);
+       return PARSE_ERROR;
+      }        
+      
       /* Insert the equation in the per frame equation tree */
       if (splay_insert(init_cond, init_cond->param->name, preset->per_frame_init_eqn_tree) < 0) {
-    //if (PARSE_DEBUG) printf("parse_line: failed to add a perframe equation (ERROR)\n");
-    free_init_cond(init_cond); /* will free the gen expr too */        
-    return ERROR;
+       //if (PARSE_DEBUG) printf("parse_line: failed to add a perframe equation (ERROR)\n");
+       free_init_cond(init_cond); /* will free the gen expr too */             
+       return ERROR;
       }
-      if (update_string_buffer(preset->per_frame_init_eqn_string_buffer,
-                   &preset->per_frame_init_eqn_string_index) < 0)
-    {    return FAILURE;}
+      
+     
+      if (update_string_buffer(preset->per_frame_init_eqn_string_buffer, 
+                              &preset->per_frame_init_eqn_string_index) < 0)
+       {       return FAILURE;}
+      
       return SUCCESS;
+      
     }
 
-    /* Per frame equation case */    
+    /* Per frame equation case */          
     if (!strncmp(eqn_string, PER_FRAME_STRING, PER_FRAME_STRING_LENGTH)) {
+      
       /* Sometimes per frame equations are implicitly defined without the
-     per_frame_ prefix. This informs the parser that one could follow */
+        per_frame_ prefix. This informs the parser that one could follow */
       line_mode = PER_FRAME_LINE_MODE;
+      
       //if (PARSE_DEBUG) printf("parse_line: per frame equation found...(LINE %d)\n", line_count);
+      
       /* Parse the per frame equation */
       if ((per_frame_eqn = parse_per_frame_eqn(fs, ++per_frame_eqn_count, preset)) == NULL) {
-    if (PARSE_DEBUG) printf("parse_line: per frame equation parsing failed (LINE %d)\n", line_count);
-    return PARSE_ERROR;
-      }    
+       if (PARSE_DEBUG) printf("parse_line: per frame equation parsing failed (LINE %d)\n", line_count);
+       return PARSE_ERROR;
+      }        
+      
       /* Insert the equation in the per frame equation tree */
       if (splay_insert(per_frame_eqn, &per_frame_eqn_count, preset->per_frame_eqn_tree) < 0) {
-    if (PARSE_DEBUG) printf("parse_line: failed to add a perframe equation (ERROR)\n");
-    free_per_frame_eqn(per_frame_eqn); /* will free the gen expr too */        
-    return ERROR;
+       if (PARSE_DEBUG) printf("parse_line: failed to add a perframe equation (ERROR)\n");
+       free_per_frame_eqn(per_frame_eqn); /* will free the gen expr too */             
+       return ERROR;
       }
-      if (update_string_buffer(preset->per_frame_eqn_string_buffer,
-                   &preset->per_frame_eqn_string_index) < 0)
-    return FAILURE;
+    
+      if (update_string_buffer(preset->per_frame_eqn_string_buffer, 
+                              &preset->per_frame_eqn_string_index) < 0)
+       return FAILURE;
+      
+      
+      
       return SUCCESS;
+      
     }
+    
     /* Wavecode initial condition case */
     if (!strncmp(eqn_string, WAVECODE_STRING, WAVECODE_STRING_LENGTH)) {
+      
           line_mode = CUSTOM_WAVE_WAVECODE_LINE_MODE;
 
-      //if (PARSE_DEBUG)
+      //if (PARSE_DEBUG) 
       //      printf("parse_line: wavecode prefix found: \"%s\"\n", eqn_string);
 
-      //      printf("string:%d\n", 5);
+         //      printf("string:%d\n", 5);
 
-      //SUPER MYSTERIO-BUG - Don't Remove
-      printf("");
-    
+         //SUPER MYSTERIO-BUG - Don't Remove
+         printf("");
+         
       return parse_wavecode(eqn_string, fs, preset);
     }
+    
     /* Custom Wave Prefix */
-    if ((!strncmp(eqn_string, WAVE_STRING, WAVE_STRING_LENGTH)) &&
-    ((eqn_string[5] >= 48) && (eqn_string[5] <= 57))) {
+    if ((!strncmp(eqn_string, WAVE_STRING, WAVE_STRING_LENGTH)) && 
+       ((eqn_string[5] >= 48) && (eqn_string[5] <= 57))) {
+      
       //    if (PARSE_DEBUG) printf("parse_line wave prefix found: \"%s\"\n", eqn_string);
+      
       return parse_wave(eqn_string, fs, preset);
+      
     }
+    
+    
     /* Shapecode initial condition case */
     if (!strncmp(eqn_string, SHAPECODE_STRING, SHAPECODE_STRING_LENGTH)) {
+      
       line_mode = CUSTOM_SHAPE_SHAPECODE_LINE_MODE;
+      
       if (PARSE_DEBUG) printf("parse_line: shapecode prefix found: \"%s\"\n", eqn_string);
+      
       return parse_shapecode(eqn_string, fs, preset);
     }
+    
     /* Custom Shape Prefix */
-    if ((!strncmp(eqn_string, SHAPE_STRING, SHAPE_STRING_LENGTH)) &&
-    ((eqn_string[6] >= 48) && (eqn_string[6] <= 57))) {
+    if ((!strncmp(eqn_string, SHAPE_STRING, SHAPE_STRING_LENGTH)) && 
+       ((eqn_string[6] >= 48) && (eqn_string[6] <= 57))) {
+      
       if (PARSE_DEBUG) printf("parse_line shape prefix found: \"%s\"\n", eqn_string);
       return parse_shape(eqn_string, fs, preset);
+      
     }
+    
     /* Per pixel equation case */
     if (!strncmp(eqn_string, PER_PIXEL_STRING, PER_PIXEL_STRING_LENGTH)) {
       line_mode = PER_PIXEL_LINE_MODE;
+      
       if (parse_per_pixel_eqn(fs, preset) < 0)
-    return PARSE_ERROR;
-      if (update_string_buffer(preset->per_pixel_eqn_string_buffer,
-                   &preset->per_pixel_eqn_string_index) < 0)
-    return FAILURE;
+       return PARSE_ERROR;
+      
+      
+      if (update_string_buffer(preset->per_pixel_eqn_string_buffer, 
+                              &preset->per_pixel_eqn_string_index) < 0)
+       return FAILURE;
+      
       if (PARSE_DEBUG) printf("parse_line: finished parsing per pixel equation (LINE %d)\n", line_count);
       return SUCCESS;
-    }
+    } 
+    
     /* Sometimes equations are written implicitly in milkdrop files, in the form
-    per_frame_1 = p1 = eqn1; p2 = eqn2; p3 = eqn3;..;
+       
+    per_frame_1 = p1 = eqn1; p2 = eqn2; p3 = eqn3;..; 
+    
     which is analagous to:
+    
     per_frame_1 = p1 = eqn1; per_frame_2 = p2 = eqn2; per_frame_3 = p3 = eqn3; ...;
-    The following line mode hack allows such implicit declaration of the
+    
+    The following line mode hack allows such implicit declaration of the 
     prefix that specifies the equation type. An alternative method
     may be to associate each equation line as list of equations separated
     by semicolons (and a new line ends the list). Instead, however, a global
     variable called "line_mode" specifies the last type of equation found,
     and bases any implicitly typed input on this fact
+    
     Note added by Carmelo Piccione (cep@andrew.cmu.edu) 10/19/03
     */
+    
     /* Per frame line mode previously, try to parse the equation implicitly */
     if (line_mode == PER_FRAME_LINE_MODE) {
       if ((per_frame_eqn = parse_implicit_per_frame_eqn(fs, eqn_string, ++per_frame_eqn_count, preset)) == NULL)
-    return PARSE_ERROR;
+       return PARSE_ERROR;
+      
       /* Insert the equation in the per frame equation tree */
       if (splay_insert(per_frame_eqn, &per_frame_eqn_count, preset->per_frame_eqn_tree) < 0) {
-    if (PARSE_DEBUG) printf("parse_line: failed to add a perframe equation (ERROR)\n");
-    free_per_frame_eqn(per_frame_eqn); /* will free the gen expr too */        
-    return ERROR;
+       if (PARSE_DEBUG) printf("parse_line: failed to add a perframe equation (ERROR)\n");
+       free_per_frame_eqn(per_frame_eqn); /* will free the gen expr too */             
+       return ERROR;
       }
-      if (update_string_buffer(preset->per_frame_eqn_string_buffer,
-                   &preset->per_frame_eqn_string_index) < 0)
-    return FAILURE;
+      
+      
+      if (update_string_buffer(preset->per_frame_eqn_string_buffer, 
+                              &preset->per_frame_eqn_string_index) < 0)
+       return FAILURE;
+      
+      
+      
       return SUCCESS;
     }
+    
     //if (PARSE_DEBUG) printf("parse_line: found initial condition: name = \"%s\" (LINE %d)\n", eqn_string, line_count);
+    
     /* Evaluate the initial condition */
     if ((init_cond = parse_init_cond(fs, eqn_string, preset)) == NULL) {
        if (PARSE_DEBUG) printf("parse_line: failed to parse initial condition (LINE %d)\n", line_count);
-      return PARSE_ERROR;
-    }    
+      return PARSE_ERROR; 
+    }  
+    
     /* Add equation to initial condition tree */
     if (splay_insert(init_cond, init_cond->param->name, preset->init_cond_tree) < 0) {
-      if (PARSE_DEBUG) printf("parse_line: failed to add initial condition \"%s\" to equation tree (LINE %d)\n",
-                    init_cond->param->name, line_count);
+      if (PARSE_DEBUG) printf("parse_line: failed to add initial condition \"%s\" to equation tree (LINE %d)\n", 
+                     init_cond->param->name, line_count);
       free_init_cond(init_cond);
       return FAILURE;
     }
+    
     /* Finished with initial condition line */
     //    if (PARSE_DEBUG) printf("parse_line: initial condition parsed successfully\n");
+    
     return SUCCESS;
+    
     /* END INITIAL CONDITIONING PARSING */
+    
+    
   default: /* an uncaught type or an error has occurred */
-    if (PARSE_DEBUG) printf("parse_line: uncaught case, token val = %d\n", token);
+    if (PARSE_DEBUG) printf("parse_line: uncaught case, token val = %d\n", token); 
     return PARSE_ERROR;
   }
-  /* Because of the default in the case statement,
-     control flow should never actually reach here */
+  
+  /* Because of the default in the case statement, 
+     control flow should never actually reach here */ 
   return PARSE_ERROR;
 }
 
@@ -639,7 +639,7 @@ int parse_line(FILE * fs, struct PRESET_T * preset) {
 
 /* Parses a general expression, this function is the meat of the parser */
 gen_expr_t * parse_gen_expr (FILE * fs, tree_expr_t * tree_expr, struct PRESET_T * preset) {
+  
   int i;
   char string[MAX_TOKEN_SIZE];
   token_t token;
@@ -652,101 +652,101 @@ gen_expr_t * parse_gen_expr (FILE * fs, tree_expr_t * tree_expr, struct PRESET_T
   switch (token = parseToken(fs,string)) {
   /* Left Parentice Case */
   case tLPr:
+    
     /* CASE 1 (Left Parentice): See if the previous string before this parentice is a function name */
     if ((func = find_func(string)) != NULL) {
         if (PARSE_DEBUG) printf("parse_gen_expr: found prefix function (name = %s) (LINE %d)\n", func->name, line_count);
+      
       /* Parse the functions arguments */
       if ((expr_list = parse_prefix_args(fs, func->num_args, preset)) == NULL) {
-    if (PARSE_DEBUG) printf("parse_prefix_args: failed to generate an expresion list! (LINE %d) \n", line_count);
-    free_tree_expr(tree_expr);
-    return NULL;
+       if (PARSE_DEBUG) printf("parse_prefix_args: failed to generate an expresion list! (LINE %d) \n", line_count);
+       free_tree_expr(tree_expr);
+       return NULL;
       }
+      
       /* Convert function to expression */
-      if ((gen_expr = prefun_to_expr((void*)func->func_ptr, expr_list, func->num_args)) == NULL)  {     
-      if (PARSE_DEBUG) printf("parse_prefix_args: failed to convert prefix function to general expression (LINE %d) \n",
-                      line_count);
-    free_tree_expr(tree_expr);
-    for (i = 0; i < func->num_args;i++)
-      free_gen_expr(expr_list[i]);
-    free(expr_list);
-    return NULL;
+      if ((gen_expr = prefun_to_expr((void*)func->func_ptr, expr_list, func->num_args)) == NULL)  {    
+         if (PARSE_DEBUG) printf("parse_prefix_args: failed to convert prefix function to general expression (LINE %d) \n", 
+                                       line_count);
+       free_tree_expr(tree_expr);
+       for (i = 0; i < func->num_args;i++)
+         free_gen_expr(expr_list[i]);
+       free(expr_list);
+       return NULL;
       }
+    
+      
+      
       token = parseToken(fs, string);
 
       if (*string != 0) {
-    if (PARSE_DEBUG) printf("parse_prefix_args: empty string expected, but not found...(LINE %d)\n", line_count);
-    /* continue anyway for now, could be implicit multiplication */                
-      }        
+       if (PARSE_DEBUG) printf("parse_prefix_args: empty string expected, but not found...(LINE %d)\n", line_count);
+       /* continue anyway for now, could be implicit multiplication */                         
+      }                
+      
       return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset);
     }
-    /* Case 2: (Left Parentice), a string coupled with a left parentice. Either an error or implicit
+     
+    
+    /* Case 2: (Left Parentice), a string coupled with a left parentice. Either an error or implicit 
        multiplication operator. For now treat it as an error */
     if (*string != 0) {
       if (PARSE_DEBUG) printf("parse_gen_expr: implicit multiplication case unimplemented!\n");
       free_tree_expr(tree_expr);
       return NULL;
     }
+    
     /* CASE 3 (Left Parentice): the following is enclosed parentices to change order
        of operations. So we create a new expression tree */
+    
     if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL) {
       //if (PARSE_DEBUG) printf("parse_gen_expr:  found left parentice, but failed to create new expression tree \n");
       free_tree_expr(tree_expr);
       return NULL;
     }
-    if (PARSE_DEBUG) printf("parse_gen_expr: finished enclosed expression tree...\n");    
+    
+    if (PARSE_DEBUG) printf("parse_gen_expr: finished enclosed expression tree...\n"); 
     token = parseToken(fs, string);
     return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset);
 
     /* Plus is a prefix operator check */
   case tPlus:
     if (*string == 0) {
+      
       //if (PARSE_DEBUG) printf("parse_gen_expr: plus used as prefix (LINE %d)\n", line_count);
 
-      /* Treat prefix plus as implict 0 preceding operator */
+         /* Treat prefix plus as implict 0 preceding operator */
       gen_expr = const_to_expr(0);
 
-      return parse_infix_op(fs, tPositive, insert_gen_expr(gen_expr, &tree_expr), preset);    
+      return parse_infix_op(fs, tPositive, insert_gen_expr(gen_expr, &tree_expr), preset);     
     }
+    
     /* Minus is a prefix operator check */
   case tMinus:
     if (*string == 0) {
+     
       /* Use the negative infix operator, but first add an implicit zero to the operator tree */
       gen_expr = const_to_expr(0);
       //return parse_gen_expr(fs, insert_gen_expr(gen_expr, &tree_expr), preset);
-        return parse_infix_op(fs, tNegative, insert_gen_expr(gen_expr, &tree_expr), preset);
+               return parse_infix_op(fs, tNegative, insert_gen_expr(gen_expr, &tree_expr), preset);
     }
+    
     /* All the following cases are strings followed by an infix operator or terminal */
   case tRPr:
-  case tEOL:
+  case tEOL: 
   case tEOF:
   case tSemiColon:
   case tComma:
+    
     /* CASE 1 (terminal): string is empty, but not null. Not sure if this will actually happen
        any more. */
     if (*string == 0) {
       //if (PARSE_DEBUG) printf("parse_gen_expr: empty string coupled with terminal (LINE %d) \n", line_count);
       return parse_infix_op(fs, token, tree_expr, preset);
+      
     }
-  default:
+    
+  default:  
 
     /* CASE 0: Empty string, parse error */
     if (*string == 0) {
@@ -758,100 +758,100 @@ gen_expr_t * parse_gen_expr (FILE * fs, tree_expr_t * tree_expr, struct PRESET_T
     /* CASE 1: Check if string is a just a floating point number */
     if (string_to_float(string, &val) != PARSE_ERROR) {
       if ((gen_expr = const_to_expr(val)) == NULL) {
-    free_tree_expr(tree_expr);
-    return NULL;
+       free_tree_expr(tree_expr);
+       return NULL;
       }
+      
       /* Parse the rest of the line */
-      return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset);
+      return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset);          
+    
     }
 
+      
     /* CASE 4: custom shape variable */
     if (current_shape != NULL) {
       if ((param = find_param_db(string, current_shape->param_tree, FALSE)) == NULL) {
-    if ((param = find_builtin_param(string)) == NULL)
-      if ((param = find_param_db(string, current_shape->param_tree, TRUE)) == NULL) {
-        free_tree_expr(tree_expr);
-        return NULL;
+       if ((param = find_builtin_param(string)) == NULL)
+         if ((param = find_param_db(string, current_shape->param_tree, TRUE)) == NULL) {
+           free_tree_expr(tree_expr);
+           return NULL;
+         }
       }
-      }
+      
       if (PARSE_DEBUG) {
-    printf("parse_gen_expr: custom shape parameter (name = %s)... ", param->name);
-    fflush(stdout);
-      }
+       printf("parse_gen_expr: custom shape parameter (name = %s)... ", param->name);
+       fflush(stdout);
+      }  
+      
       /* Convert parameter to an expression */
       if ((gen_expr = param_to_expr(param)) == NULL) {
-    free_tree_expr(tree_expr);
-    return NULL;
+       free_tree_expr(tree_expr);
+       return NULL;
       }
+      
       //if (PARSE_DEBUG) printf("converted to expression (LINE %d)\n", line_count);
+      
       /* Parse the rest of the line */
       return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset);
     }
+    
     /* CASE 5: custom wave variable */
     if (current_wave != NULL) {
       if ((param = find_param_db(string, current_wave->param_tree, FALSE)) == NULL) {
-    if ((param = find_builtin_param(string)) == NULL)
-      if ((param = find_param_db(string, current_wave->param_tree, TRUE)) == NULL) {
-        free_tree_expr(tree_expr);
-        return NULL;
-      }
+       if ((param = find_builtin_param(string)) == NULL) 
+         if ((param = find_param_db(string, current_wave->param_tree, TRUE)) == NULL) {
+           free_tree_expr(tree_expr);
+           return NULL;
+         }
+        
       }
 
       if (PARSE_DEBUG) {
-    printf("parse_gen_expr: custom wave parameter (name = %s)... ", param->name);
-    fflush(stdout);
+       printf("parse_gen_expr: custom wave parameter (name = %s)... ", param->name);
+       fflush(stdout);
       }
-    
-    /* Convert parameter to an expression */
-    if ((gen_expr = param_to_expr(param)) == NULL) {
-      free_tree_expr(tree_expr);
-      return NULL;
-    }
-    
-    if (PARSE_DEBUG) printf("converted to expression (LINE %d)\n", line_count);
-    
-    /* Parse the rest of the line */
-    return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset);
+       
+       /* Convert parameter to an expression */
+       if ((gen_expr = param_to_expr(param)) == NULL) {
+         free_tree_expr(tree_expr);
+         return NULL;
+       }
+       
+       if (PARSE_DEBUG) printf("converted to expression (LINE %d)\n", line_count);
+       
+       /* Parse the rest of the line */
+       return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset);
+      
     }
 
     /* CASE 6: regular parameter. Will be created if necessary and the string has no invalid characters */
     if ((param = find_param(string, preset, P_CREATE)) != NULL) {
+      
       if (PARSE_DEBUG) {
-    printf("parse_gen_expr: parameter (name = %s)... ", param->name);
-    fflush(stdout);
-      }
-        /* Convert parameter to an expression */
+       printf("parse_gen_expr: parameter (name = %s)... ", param->name);
+       fflush(stdout);
+      }  
+    
+               /* Convert parameter to an expression */
       if ((gen_expr = param_to_expr(param)) == NULL) {
-    free_tree_expr(tree_expr);
-    return NULL;
+       free_tree_expr(tree_expr);
+       return NULL;
       }
+      
       if (PARSE_DEBUG) printf("converted to expression (LINE %d)\n", line_count);
+      
       /* Parse the rest of the line */
       return parse_infix_op(fs, token, insert_gen_expr(gen_expr, &tree_expr), preset);
+          
     }
+   
     /* CASE 7: Bad string, give up */
     if (PARSE_DEBUG) printf("parse_gen_expr: syntax error [string = \"%s\"] (LINE %d)\n", string, line_count);
     free_tree_expr(tree_expr);
     return NULL;
   }
 }
+  
 
 
 /* Inserts expressions into tree according to operator precedence.
@@ -860,70 +860,70 @@ gen_expr_t * parse_gen_expr (FILE * fs, tree_expr_t * tree_expr, struct PRESET_T
 tree_expr_t * insert_infix_op(infix_op_t * infix_op, tree_expr_t **root) {
 
   tree_expr_t * new_root;
+  
   /* Sanity check */
   if (infix_op == NULL)
     return NULL;
+  
   /* The root is null, so make this operator
      the new root */
+  
   if (*root == NULL) {
     new_root = new_tree_expr(infix_op, NULL, NULL, NULL);
     *root = new_root;
-    return new_root;        
+    return new_root;           
   }
+  
   /* The root node is not an infix function,
-     so we make this infix operator the new root  */
+     so we make this infix operator the new root  */ 
+  
   if ((*root)->infix_op == NULL) {
     new_root = new_tree_expr(infix_op, NULL, *root, NULL);
     (*root) = new_root;
     return new_root;
   }
+  
   /* The root is an infix function. If the precedence
      of the item to be inserted is greater than the root's
      precedence, then make gen_expr the root */
+  
   if (infix_op->precedence > (*root)->infix_op->precedence) {
     new_root = new_tree_expr(infix_op, NULL, *root, NULL);
     (*root) = new_root;
       return new_root;
   }
+  
   /* If control flow reaches here, use a recursive helper
      with the knowledge that the root is higher precedence
      than the item to be inserted */
+  
   insert_infix_rec(infix_op, *root);
   return *root;
+  
 }
 
 
 tree_expr_t * insert_gen_expr(gen_expr_t * gen_expr, tree_expr_t ** root) {
 
   tree_expr_t * new_root;
+  
   /* If someone foolishly passes a null
      pointer to insert, return the original tree */
+  
   if (gen_expr == NULL) {
     return *root;
   }
 
   /* If the root is null, generate a new expression tree,
      using the passed expression as the root element */
+  
   if (*root == NULL) {
     new_root = new_tree_expr(NULL, gen_expr, NULL, NULL);
     *root = new_root;
     return new_root;
   }
+  
+  
   /* Otherwise. the new element definitely will not replace the current root.
      Use a recursive helper function to do insertion */
 
@@ -933,45 +933,45 @@ tree_expr_t * insert_gen_expr(gen_expr_t * gen_expr, tree_expr_t ** root) {
 
 /* A recursive helper function to insert general expression elements into the operator tree */
 int insert_gen_rec(gen_expr_t * gen_expr, tree_expr_t * root) {
+  
   /* Trivial Case: root is null */
+  
   if (root == NULL) {
     ////if (PARSE_DEBUG) printf("insert_gen_rec: root is null, returning failure\n");
     return FAILURE;
   }
+  
+  
   /* The current node's left pointer is null, and this
      current node is an infix operator, so insert the
      general expression at the left pointer */
+  
   if ((root->left == NULL) && (root->infix_op != NULL)) {
     root->left = new_tree_expr(NULL, gen_expr, NULL, NULL);
     return SUCCESS;
   }
+  
   /* The current node's right pointer is null, and this
      current node is an infix operator, so insert the
      general expression at the right pointer */
+  
   if ((root->right == NULL) && (root->infix_op != NULL)) {
     root->right = new_tree_expr(NULL, gen_expr, NULL, NULL);
     return SUCCESS;
   }
+  
   /* Otherwise recurse down to the left. If
      this succeeds then return. If it fails, try
      recursing down to the right */
-  if (insert_gen_rec(gen_expr, root->left) == FAILURE)
+  
+  if (insert_gen_rec(gen_expr, root->left) == FAILURE) 
     return insert_gen_rec(gen_expr, root->right);
 
   /* Impossible for control flow to reach here, but in
      the world of C programming, who knows... */
-  //if (PARSE_DEBUG) printf("insert_gen_rec: should never reach here!\n");
-  return FAILURE;    
-}    
+  //if (PARSE_DEBUG) printf("insert_gen_rec: should never reach here!\n");  
+  return FAILURE;      
+}      
 
 
 /* A recursive helper function to insert infix arguments by operator precedence */
@@ -981,13 +981,13 @@ int insert_infix_rec(infix_op_t * infix_op, tree_expr_t * root) {
 
   if (root == NULL)
     return FAILURE;
+  
   /* Also shouldn't happen, also implies a (different) parse error */
 
   if (root->infix_op == NULL)
     return FAILURE;
 
-  /* Left tree is empty, attach this operator to it.
+  /* Left tree is empty, attach this operator to it. 
      I don't think this will ever happen */
   if (root->left == NULL) {
     root->left = new_tree_expr(infix_op, NULL, root->left, NULL);
@@ -1011,14 +1011,14 @@ int insert_infix_rec(infix_op_t * infix_op, tree_expr_t * root) {
     root->right = new_tree_expr(infix_op, NULL, root->right, NULL);
     return SUCCESS;
   }
+  
   /* Traverse deeper if the inserting operator precedence is less than the
      the root's right operator precedence */
-  if (infix_op->precedence < root->right->infix_op->precedence)
+  if (infix_op->precedence < root->right->infix_op->precedence) 
     return insert_infix_rec(infix_op, root->right);
 
   /* Otherwise, insert the operator here */
+  
   root->right = new_tree_expr(infix_op, NULL, root->right, NULL);
   return SUCCESS;
 
@@ -1026,11 +1026,11 @@ int insert_infix_rec(infix_op_t * infix_op, tree_expr_t * root) {
 
 /* Parses an infix operator */
 gen_expr_t * parse_infix_op(FILE * fs, token_t token, tree_expr_t * tree_expr, struct PRESET_T * preset) {
-    
+       
   gen_expr_t * gen_expr;
 
   switch (token) {
-     /* All the infix operators */
+       /* All the infix operators */
   case tPlus:
     //if (PARSE_DEBUG) printf("parse_infix_op: found addition operator (LINE %d)\n", line_count);
     return parse_gen_expr(fs, insert_infix_op(infix_add, &tree_expr), preset);
@@ -1041,41 +1041,41 @@ gen_expr_t * parse_infix_op(FILE * fs, token_t token, tree_expr_t * tree_expr, s
     //if (PARSE_DEBUG) printf("parse_infix_op: found multiplication operator (LINE %d)\n", line_count);
     return parse_gen_expr(fs, insert_infix_op(infix_mult, &tree_expr), preset);
   case tDiv:
-    //if (PARSE_DEBUG) printf("parse_infix_op: found division operator (LINE %d)\n", line_count);
+    //if (PARSE_DEBUG) printf("parse_infix_op: found division operator (LINE %d)\n", line_count);  
     return parse_gen_expr(fs, insert_infix_op(infix_div, &tree_expr), preset);
   case tMod:
-    //if (PARSE_DEBUG) printf("parse_infix_op: found modulo operator (LINE %d)\n", line_count);
+    //if (PARSE_DEBUG) printf("parse_infix_op: found modulo operator (LINE %d)\n", line_count);  
     return parse_gen_expr(fs, insert_infix_op(infix_mod, &tree_expr), preset);
-  case tOr:
-    //if (PARSE_DEBUG) printf("parse_infix_op: found bitwise or operator (LINE %d)\n", line_count);      
+  case tOr:  
+    //if (PARSE_DEBUG) printf("parse_infix_op: found bitwise or operator (LINE %d)\n", line_count);      
     return parse_gen_expr(fs, insert_infix_op(infix_or, &tree_expr), preset);
-  case tAnd:     
-    //if (PARSE_DEBUG) printf("parse_infix_op: found bitwise and operator (LINE %d)\n", line_count);      
+  case tAnd:     
+    //if (PARSE_DEBUG) printf("parse_infix_op: found bitwise and operator (LINE %d)\n", line_count);     
     return parse_gen_expr(fs, insert_infix_op(infix_and, &tree_expr), preset);
   case tPositive:
-    //if (PARSE_DEBUG) printf("parse_infix_op: found positive operator (LINE %d)\n", line_count);      
+    //if (PARSE_DEBUG) printf("parse_infix_op: found positive operator (LINE %d)\n", line_count);        
     return parse_gen_expr(fs, insert_infix_op(infix_positive, &tree_expr), preset);
   case tNegative:
-    //if (PARSE_DEBUG) printf("parse_infix_op: found negative operator (LINE %d)\n", line_count);      
+    //if (PARSE_DEBUG) printf("parse_infix_op: found negative operator (LINE %d)\n", line_count);        
     return parse_gen_expr(fs, insert_infix_op(infix_negative, &tree_expr), preset);
 
   case tEOL:
   case tEOF:
   case tSemiColon:
   case tRPr:
-  case tComma:    
-    //if (PARSE_DEBUG) printf("parse_infix_op: terminal found (LINE %d)\n", line_count);
-      gen_expr = new_gen_expr(TREE_T, (void*)tree_expr);
-      return gen_expr;
+  case tComma:   
+       //if (PARSE_DEBUG) printf("parse_infix_op: terminal found (LINE %d)\n", line_count);
+       gen_expr = new_gen_expr(TREE_T, (void*)tree_expr);
+       return gen_expr;
   default:
     //if (PARSE_DEBUG) printf("parse_infix_op: operator or terminal expected, but not found (LINE %d)\n", line_count);
     free_tree_expr(tree_expr);
     return NULL;
-  }
+  }  
 
   /* Will never happen */
   return NULL;
+  
 }
 
 /* Parses an integer, checks for +/- prefix */
@@ -1085,41 +1085,41 @@ char string[MAX_TOKEN_SIZE];
   token_t token;
   int sign;
   char * end_ptr = " ";
-    
+       
   token = parseToken(fs, string);
 
  
   switch (token) {
   case tMinus:
     sign = -1;
-    token = parseToken(fs, string);
+    token = parseToken(fs, string); 
     break;
   case tPlus:
     sign = 1;
     token = parseToken(fs, string);
     break;
-  default:
+  default: 
     sign = 1;
     break;
   }
 
  
-  if (string[0] == 0)
+  if (string[0] == 0) 
     return PARSE_ERROR;
+  
   /* Convert the string to an integer. *end_ptr
-     should end up pointing to null terminator of 'string'
+     should end up pointing to null terminator of 'string' 
      if the conversion was successful. */
   //  printf("STRING: \"%s\"\n", string);
 
   (*int_ptr) = sign*strtol(string, &end_ptr, 10);
 
   /* If end pointer is a return character or null terminator, all is well */
-  if ((*end_ptr == '\r') || (*end_ptr == '\0'))
+  if ((*end_ptr == '\r') || (*end_ptr == '\0')) 
     return SUCCESS;
 
     return PARSE_ERROR;
+  
 }
 /* Parses a floating point number */
 int string_to_float(char * string, double * float_ptr) {
@@ -1130,7 +1130,7 @@ int string_to_float(char * string, double * float_ptr) {
     return PARSE_ERROR;
 
   error_ptr = malloc(sizeof(char**));
+  
   (*float_ptr) = strtod(string, error_ptr);
  
   /* These imply a succesful parse of the string */
@@ -1138,10 +1138,10 @@ int string_to_float(char * string, double * float_ptr) {
     free(error_ptr);
     return SUCCESS;
   }
+    
   (*float_ptr) = 0;
   free(error_ptr);
-  return PARSE_ERROR;
+  return PARSE_ERROR;  
 }
 
 /* Parses a floating point number */
@@ -1151,7 +1151,7 @@ int parse_float(FILE * fs, double * float_ptr) {
   char ** error_ptr;
   token_t token;
   int sign;
+  
   error_ptr = malloc(sizeof(char**));
 
   token = parseToken(fs, string);
@@ -1159,14 +1159,14 @@ int parse_float(FILE * fs, double * float_ptr) {
   switch (token) {
   case tMinus:
   sign = -1;
-  token = parseToken(fs, string);
+  token = parseToken(fs, string); 
   break;
   case tPlus:
   sign = 1;
   token = parseToken(fs, string);
   break;
-  default:
-    sign = 1;
+  default: 
+    sign = 1;  
   }
  
   if (string[0] == 0) {
@@ -1181,68 +1181,68 @@ int parse_float(FILE * fs, double * float_ptr) {
     free(error_ptr);
     return SUCCESS;
   }
+    
   //if (PARSE_DEBUG) printf("parse_float: double conversion failed for string \"%s\"\n", string);
 
   (*float_ptr) = 0;
   free(error_ptr);
   return PARSE_ERROR;
+  
 
+  
 }
 
 /* Parses a per frame equation. That is, interprets a stream of data as a per frame equation */
 per_frame_eqn_t * parse_per_frame_eqn(FILE * fs, int index, struct PRESET_T * preset) {
+  
   char string[MAX_TOKEN_SIZE];
   param_t * param;
   per_frame_eqn_t * per_frame_eqn;
   gen_expr_t * gen_expr;
+  
   if (parseToken(fs, string) != tEq) {
     //if (PARSE_DEBUG) printf("parse_per_frame_eqn: no equal sign after string \"%s\" (LINE %d)\n", string, line_count);
-    return NULL;            
+    return NULL;                       
   }
+  
   /* Find the parameter associated with the string, create one if necessary */
-  if ((param = find_param(string, preset, P_CREATE)) == NULL) {
-    return NULL;    
+  if ((param = find_param(string, preset, P_CREATE)) == NULL) { 
+    return NULL;       
   }
+  
   /* Make sure parameter is writable */
   if (param->flags & P_FLAG_READONLY) {
-      //if (PARSE_DEBUG) printf("parse_per_frame_eqn: parameter %s is marked as read only (LINE %d)\n", param->name, line_count);
+      //if (PARSE_DEBUG) printf("parse_per_frame_eqn: parameter %s is marked as read only (LINE %d)\n", param->name, line_count);  
       return NULL;
   }
+  
   /* Parse right side of equation as an expression */
   if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL) {
     //if (PARSE_DEBUG) printf("parse_per_frame_eqn: equation evaluated to null (LINE %d)\n", line_count);
     return NULL;
   }
+  
   //if (PARSE_DEBUG) printf("parse_per_frame_eqn: finished per frame equation evaluation (LINE %d)\n", line_count);
+  
   /* Create a new per frame equation */
   if ((per_frame_eqn = new_per_frame_eqn(index, param, gen_expr)) == NULL) {
     //if (PARSE_DEBUG) printf("parse_per_frame_eqn: failed to create a new per frame eqn, out of memory?\n");
     free_gen_expr(gen_expr);
     return NULL;
   }
+  
   //if (PARSE_DEBUG) printf("parse_per_frame_eqn: per_frame eqn parsed succesfully\n");
+  
   return per_frame_eqn;
 }
 
 /* Parses an 'implicit' per frame equation. That is, interprets a stream of data as a per frame equation without a prefix */
 per_frame_eqn_t * parse_implicit_per_frame_eqn(FILE * fs, char * param_string, int index, struct PRESET_T * preset) {
+  
   param_t * param;
   per_frame_eqn_t * per_frame_eqn;
   gen_expr_t * gen_expr;
+  
   if (fs == NULL)
     return NULL;
   if (param_string == NULL)
@@ -1252,35 +1252,35 @@ per_frame_eqn_t * parse_implicit_per_frame_eqn(FILE * fs, char * param_string, i
 
   //rintf("param string: %s\n", param_string);
   /* Find the parameter associated with the string, create one if necessary */
-  if ((param = find_param(param_string, preset, P_CREATE)) == NULL) {
-    return NULL;    
+  if ((param = find_param(param_string, preset, P_CREATE)) == NULL) { 
+    return NULL;       
   }
+  
   //printf("parse_implicit_per_frame_eqn: param is %s\n", param->name);
 
   /* Make sure parameter is writable */
   if (param->flags & P_FLAG_READONLY) {
-    //if (PARSE_DEBUG) printf("parse_implicit_per_frame_eqn: parameter %s is marked as read only (LINE %d)\n", param->name, line_count);
+    //if (PARSE_DEBUG) printf("parse_implicit_per_frame_eqn: parameter %s is marked as read only (LINE %d)\n", param->name, line_count);  
     return NULL;
   }
+  
   /* Parse right side of equation as an expression */
   if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL) {
     //if (PARSE_DEBUG) printf("parse_implicit_per_frame_eqn: equation evaluated to null (LINE %d)\n", line_count);
     return NULL;
   }
+  
   //if (PARSE_DEBUG) printf("parse_implicit_per_frame_eqn: finished per frame equation evaluation (LINE %d)\n", line_count);
+  
   /* Create a new per frame equation */
   if ((per_frame_eqn = new_per_frame_eqn(index, param, gen_expr)) == NULL) {
     //if (PARSE_DEBUG) printf("parse_implicit_per_frame_eqn: failed to create a new per frame eqn, out of memory?\n");
     free_gen_expr(gen_expr);
     return NULL;
   }
+  
   //if (PARSE_DEBUG) printf("parse_implicit_per_frame_eqn: per_frame eqn parsed succesfully\n");
+  
   return per_frame_eqn;
 }
 
@@ -1290,37 +1290,37 @@ init_cond_t * parse_init_cond(FILE * fs, char * name, struct PRESET_T * preset)
   param_t * param;
   value_t init_val;
   init_cond_t * init_cond;
-    
+       
   if (name == NULL)
     return NULL;
   if (preset == NULL)
     return NULL;
+  
   /* Search for the paramater in the database, creating it if necessary */
   if ((param = find_param(name, preset, P_CREATE)) == NULL) {
     return NULL;
   }
+  
   //if (PARSE_DEBUG) printf("parse_init_cond: parameter = \"%s\" (LINE %d)\n", param->name, line_count);
+  
   if (param->flags & P_FLAG_READONLY) {
     //if (PARSE_DEBUG) printf("parse_init_cond: builtin parameter \"%s\" marked as read only!\n", param->name);
     return NULL;
-  }        
+  }            
+  
   /* At this point, a parameter has been created or was found
      in the database. */
+  
   //if (PARSE_DEBUG) printf("parse_init_cond: parsing initial condition value... (LINE %d)\n", line_count);
+  
   /* integer value (boolean is an integer in C) */
   if ((param->type == P_TYPE_INT) || (param->type == P_TYPE_BOOL)) {
-    if ((parse_int(fs, (int*)&init_val.int_val)) == PARSE_ERROR) {    
+    if ((parse_int(fs, (int*)&init_val.int_val)) == PARSE_ERROR) {     
       //if (PARSE_DEBUG) printf("parse_init_cond: error parsing integer!\n");
       return NULL;
     }
   }
+  
   /* double value */
   else if (param->type == P_TYPE_DOUBLE) {
     if ((parse_float(fs, (double*)&init_val.double_val)) == PARSE_ERROR) {
@@ -1328,26 +1328,26 @@ init_cond_t * parse_init_cond(FILE * fs, char * name, struct PRESET_T * preset)
       return NULL;
     }
   }
+  
   /* Unknown value */
   else {
     //if (PARSE_DEBUG) printf("parse_init_cond: unknown parameter type!\n");
     return NULL;
   }
+  
   /* Create new initial condition */
   if ((init_cond = new_init_cond(param, init_val)) == NULL) {
       //if (PARSE_DEBUG) printf("parse_init_cond: new_init_cond failed!\n");
       return NULL;
   }
+  
   /* Finished */
   return init_cond;
 }
 
 /* Parses a per frame init equation, not sure if this works right now */
 init_cond_t * parse_per_frame_init_eqn(FILE * fs, struct PRESET_T * preset, splaytree_t * database) {
+  
   char name[MAX_TOKEN_SIZE];
   param_t * param = NULL;
   value_t init_val;
@@ -1364,7 +1364,7 @@ init_cond_t * parse_per_frame_init_eqn(FILE * fs, struct PRESET_T * preset, spla
 
   if ((token = parseToken(fs, name)) != tEq)
     return NULL;
+  
 
   /* If a database was specified,then use find_param_db instead */
   if ((database != NULL) && ((param = find_param_db(name, database, TRUE)) == NULL)) {
@@ -1375,19 +1375,19 @@ init_cond_t * parse_per_frame_init_eqn(FILE * fs, struct PRESET_T * preset, spla
   if ((param == NULL) && ((param = find_param(name, preset, P_CREATE)) == NULL)) {
     return NULL;
   }
+  
   //if (PARSE_DEBUG) printf("parse_per_frame_init_eqn: parameter = \"%s\" (LINE %d)\n", param->name, line_count);
+  
   if (param->flags & P_FLAG_READONLY) {
     //if (PARSE_DEBUG) printf("pars_per_frame_init_eqn: builtin parameter \"%s\" marked as read only!\n", param->name);
     return NULL;
-  }        
+  }            
+  
   /* At this point, a parameter has been created or was found
      in the database. */
+  
   //if (PARSE_DEBUG) printf("parse_per_frame_init_eqn: parsing right hand side of per frame init equation.. (LINE %d)\n", line_count);
+  
   if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL) {
     //if (PARSE_DEBUG) printf("parse_per_frame_init_eqn: failed to parse general expresion!\n");
     return NULL;
@@ -1395,7 +1395,7 @@ init_cond_t * parse_per_frame_init_eqn(FILE * fs, struct PRESET_T * preset, spla
  
   /* Compute initial condition value */
   val = eval_gen_expr(gen_expr);
+  
   /* Free the general expression now that we are done with it */
   free_gen_expr(gen_expr);
 
@@ -1403,18 +1403,18 @@ init_cond_t * parse_per_frame_init_eqn(FILE * fs, struct PRESET_T * preset, spla
   if ((param->type == P_TYPE_INT) || (param->type == P_TYPE_BOOL)) {
     init_val.int_val = (int)val;
   }
+  
   /* double value */
   else if (param->type == P_TYPE_DOUBLE) {
     init_val.double_val = val;
   }
+  
   /* Unknown value */
   else {
     //if (PARSE_DEBUG) printf("parse_per_frame_init_eqn: unknown parameter type!\n");
     return NULL;
   }
+  
 
   /* Create new initial condition */
   if ((init_cond = new_init_cond(param, init_val)) == NULL) {
@@ -1445,11 +1445,11 @@ int parse_wavecode(char * token, FILE * fs, preset_t * preset) {
     return FAILURE;
 
   /* token should be in the form wavecode_N_var, such as wavecode_1_samples */
+  
   /* Get id and variable name from token string */
-  if (parse_wavecode_prefix(token, &id, &var_string) < 0)
+  if (parse_wavecode_prefix(token, &id, &var_string) < 0)   
     return PARSE_ERROR;
+  
   //if (PARSE_DEBUG) printf("parse_wavecode: wavecode id = %d, parameter = \"%s\"\n", id, var_string);
 
   /* Retrieve custom wave information from preset. The 3rd argument
@@ -1468,12 +1468,12 @@ int parse_wavecode(char * token, FILE * fs, preset_t * preset) {
 
   /* integer value (boolean is an integer in C) */
   if ((param->type == P_TYPE_INT) || (param->type == P_TYPE_BOOL)) {
-    if ((parse_int(fs, (int*)&init_val.int_val)) == PARSE_ERROR) {    
+    if ((parse_int(fs, (int*)&init_val.int_val)) == PARSE_ERROR) {     
       //if (PARSE_DEBUG) printf("parse_wavecode: error parsing integer!\n");
       return PARSE_ERROR;
     }
   }
+  
   /* double value */
   else if (param->type == P_TYPE_DOUBLE) {
     if ((parse_float(fs, (double*)&init_val.double_val)) == PARSE_ERROR) {
@@ -1481,19 +1481,19 @@ int parse_wavecode(char * token, FILE * fs, preset_t * preset) {
       return PARSE_ERROR;
     }
   }
+  
   /* Unknown value */
   else {
     //if (PARSE_DEBUG) printf("parse_wavecode: unknown parameter type!\n");
     return PARSE_ERROR;
   }
+  
   /* Create new initial condition */
   if ((init_cond = new_init_cond(param, init_val)) == NULL) {
       //if (PARSE_DEBUG) printf("parse_wavecode: new_init_cond failed!\n");
       return FAILURE;
   }
+  
   if (splay_insert(init_cond, param->name, custom_wave->init_cond_tree) < 0) {
     free_init_cond(init_cond);
     return PARSE_ERROR;
@@ -1521,11 +1521,11 @@ int parse_shapecode(char * token, FILE * fs, preset_t * preset) {
     return FAILURE;
 
   /* token should be in the form shapecode_N_var, such as shapecode_1_samples */
+  
   /* Get id and variable name from token string */
-  if (parse_shapecode_prefix(token, &id, &var_string) < 0)
+  if (parse_shapecode_prefix(token, &id, &var_string) < 0)   
     return PARSE_ERROR;
+  
   //if (PARSE_DEBUG) printf("parse_shapecode: shapecode id = %d, parameter = \"%s\"\n", id, var_string);
 
   /* Retrieve custom shape information from preset. The 3rd argument
@@ -1545,12 +1545,12 @@ int parse_shapecode(char * token, FILE * fs, preset_t * preset) {
 
   /* integer value (boolean is an integer in C) */
   if ((param->type == P_TYPE_INT) || (param->type == P_TYPE_BOOL)) {
-    if ((parse_int(fs, (int*)&init_val.int_val)) == PARSE_ERROR) {    
+    if ((parse_int(fs, (int*)&init_val.int_val)) == PARSE_ERROR) {     
       //if (PARSE_DEBUG) printf("parse_shapecode: error parsing integer!\n");
       return PARSE_ERROR;
     }
   }
+  
   /* double value */
   else if (param->type == P_TYPE_DOUBLE) {
     if ((parse_float(fs, (double*)&init_val.double_val)) == PARSE_ERROR) {
@@ -1558,13 +1558,13 @@ int parse_shapecode(char * token, FILE * fs, preset_t * preset) {
       return PARSE_ERROR;
     }
   }
+  
   /* Unknown value */
   else {
     //if (PARSE_DEBUG) printf("parse_shapecode: unknown parameter type!\n");
     return PARSE_ERROR;
   }
+  
   /* Create new initial condition */
   if ((init_cond = new_init_cond(param, init_val)) == NULL) {
       //if (PARSE_DEBUG) printf("parse_shapecode: new_init_cond failed!\n");
@@ -1585,14 +1585,14 @@ int parse_shapecode(char * token, FILE * fs, preset_t * preset) {
 int parse_wavecode_prefix(char * token, int * id, char ** var_string) {
 
   int len, i, j;
+  
   if (token == NULL)
     return FAILURE;
   if (*var_string == NULL)
     return FAILURE;
   if (id == NULL)
     return FAILURE;
+  
   len = strlen(token);
 
   /* Move pointer passed "wavecode_" prefix */
@@ -1601,12 +1601,12 @@ int parse_wavecode_prefix(char * token, int * id, char ** var_string) {
   i = WAVECODE_STRING_LENGTH;
   j = 0;
   (*id) = 0;
+  
   /* This loop grabs the integer id for this custom wave */
   while ((i < len) && (token[i] >=  48) && (token[i] <= 57)) {
     if (j >= MAX_TOKEN_SIZE)
       return FAILURE;
+    
     (*id) = 10*(*id) + (token[i]-48);
     j++;
     i++;
@@ -1615,7 +1615,7 @@ int parse_wavecode_prefix(char * token, int * id, char ** var_string) {
  
   if (i > (len - 2))
     return FAILURE;
+  
   *var_string = token + i + 1;
  
   return SUCCESS;
@@ -1626,14 +1626,14 @@ int parse_wavecode_prefix(char * token, int * id, char ** var_string) {
 int parse_shapecode_prefix(char * token, int * id, char ** var_string) {
 
   int len, i, j;
+  
   if (token == NULL)
     return FAILURE;
   if (*var_string == NULL)
     return FAILURE;
   if (id == NULL)
     return FAILURE;
+  
   len = strlen(token);
 
   /* Move pointer passed "shapecode_" prefix */
@@ -1642,12 +1642,12 @@ int parse_shapecode_prefix(char * token, int * id, char ** var_string) {
   i = SHAPECODE_STRING_LENGTH;
   j = 0;
   (*id) = 0;
+  
   /* This loop grabs the integer id for this custom shape */
   while ((i < len) && (token[i] >=  48) && (token[i] <= 57)) {
     if (j >= MAX_TOKEN_SIZE)
       return FAILURE;
+    
     (*id) = 10*(*id) + (token[i]-48);
     j++;
     i++;
@@ -1656,7 +1656,7 @@ int parse_shapecode_prefix(char * token, int * id, char ** var_string) {
  
   if (i > (len - 2))
     return FAILURE;
+  
   *var_string = token + i + 1;
  
   return SUCCESS;
@@ -1666,14 +1666,14 @@ int parse_shapecode_prefix(char * token, int * id, char ** var_string) {
 int parse_wave_prefix(char * token, int * id, char ** eqn_string) {
 
   int len, i, j;
+  
   if (token == NULL)
     return FAILURE;
   if (eqn_string == NULL)
     return FAILURE;
   if (id == NULL)
     return FAILURE;
+  
   len = strlen(token);
  
   if (len <= WAVE_STRING_LENGTH)
@@ -1683,12 +1683,12 @@ int parse_wave_prefix(char * token, int * id, char ** eqn_string) {
   i = WAVE_STRING_LENGTH;
   j = 0;
   (*id) = 0;
+  
   /* This loop grabs the integer id for this custom wave */
   while ((i < len) && (token[i] >=  48) && (token[i] <= 57)) {
     if (j >= MAX_TOKEN_SIZE)
       return FAILURE;
+    
     (*id) = 10*(*id) + (token[i]-48);
     j++;
     i++;
@@ -1706,14 +1706,14 @@ int parse_wave_prefix(char * token, int * id, char ** eqn_string) {
 int parse_shape_prefix(char * token, int * id, char ** eqn_string) {
 
   int len, i, j;
+  
   if (token == NULL)
     return FAILURE;
   if (eqn_string == NULL)
     return FAILURE;
   if (id == NULL)
     return FAILURE;
+  
   len = strlen(token);
  
   if (len <= SHAPE_STRING_LENGTH)
@@ -1723,12 +1723,12 @@ int parse_shape_prefix(char * token, int * id, char ** eqn_string) {
   i = SHAPE_STRING_LENGTH;
   j = 0;
   (*id) = 0;
+  
   /* This loop grabs the integer id for this custom wave */
   while ((i < len) && (token[i] >=  48) && (token[i] <= 57)) {
     if (j >= MAX_TOKEN_SIZE)
       return FAILURE;
+    
     (*id) = 10*(*id) + (token[i]-48);
     j++;
     i++;
@@ -1745,7 +1745,7 @@ int parse_shape_prefix(char * token, int * id, char ** eqn_string) {
 
 /* Parses custom wave equations */
 int parse_wave(char * token, FILE * fs, preset_t * preset) {
+  
   int id;
   char * eqn_type;
   char string[MAX_TOKEN_SIZE];
@@ -1761,7 +1761,7 @@ int parse_wave(char * token, FILE * fs, preset_t * preset) {
     return FAILURE;
   if (preset == NULL)
     return FAILURE;
+  
   /* Grab custom wave id and equation type (per frame or per point) from string token */
   if (parse_wave_prefix(token, &id, &eqn_type) < 0) {
     //if (PARSE_DEBUG) printf("parse_wave: syntax error in custom wave prefix!\n");
@@ -1772,7 +1772,7 @@ int parse_wave(char * token, FILE * fs, preset_t * preset) {
     return FAILURE;
 
 
-  /* per frame init equation case */    
+  /* per frame init equation case */       
   if (!strncmp(eqn_type, WAVE_INIT_STRING, WAVE_INIT_STRING_LENGTH)) {
 
     //if (PARSE_DEBUG) printf("parse_wave (per frame init): [begin] (LINE %d)\n", line_count);
@@ -1781,46 +1781,46 @@ int parse_wave(char * token, FILE * fs, preset_t * preset) {
     if ((init_cond = parse_per_frame_init_eqn(fs, preset, custom_wave->param_tree)) == NULL) {
       //if (PARSE_DEBUG) printf("parse_wave (per frame init): equation parsing failed (LINE %d)\n", line_count);
       return PARSE_ERROR;
-    }    
+    }  
 
     /* Insert the equation in the per frame equation tree */
     if (splay_insert(init_cond, init_cond->param->name, custom_wave->per_frame_init_eqn_tree) < 0) {
       //if (PARSE_DEBUG) printf("parse_wave (per frame init): failed to add equation (ERROR)\n");
-       free_init_cond(init_cond); /* will free the gen expr too */        
+       free_init_cond(init_cond); /* will free the gen expr too */             
       return FAILURE;
     }
-    if (update_string_buffer(custom_wave->per_frame_init_eqn_string_buffer,
-                 &custom_wave->per_frame_init_eqn_string_index) < 0)
+   
+    if (update_string_buffer(custom_wave->per_frame_init_eqn_string_buffer, 
+                            &custom_wave->per_frame_init_eqn_string_index) < 0)
       return FAILURE;
-    
+       
     return SUCCESS;
+  
   }
 
   /* per frame equation case */
   if (!strncmp(eqn_type, PER_FRAME_STRING_NO_UNDERSCORE, PER_FRAME_STRING_NO_UNDERSCORE_LENGTH)) {
 
     //if (PARSE_DEBUG) printf("parse_wave (per_frame): [start] (custom wave id = %d)\n", custom_wave->id);
+    
     if (parseToken(fs, string) != tEq) {
       //if (PARSE_DEBUG) printf("parse_wave (per_frame): no equal sign after string \"%s\" (LINE %d)\n", string, line_count);
-      return PARSE_ERROR;            
+      return PARSE_ERROR;                      
     }
+  
     /* Find the parameter associated with the string in the custom wave database */
-    if ((param = find_param_db(string, custom_wave->param_tree, TRUE)) == NULL) {
+    if ((param = find_param_db(string, custom_wave->param_tree, TRUE)) == NULL) { 
       //if (PARSE_DEBUG) printf("parse_wave (per_frame): parameter \"%s\" not found or cannot be malloc'ed!!\n", string);
-      return FAILURE;    
+      return FAILURE;  
     }
+  
+    
     /* Make sure parameter is writable */
     if (param->flags & P_FLAG_READONLY) {
-      //if (PARSE_DEBUG) printf("parse_wave (per_frame): parameter %s is marked as read only (LINE %d)\n", param->name, line_count);
+      //if (PARSE_DEBUG) printf("parse_wave (per_frame): parameter %s is marked as read only (LINE %d)\n", param->name, line_count);  
       return FAILURE;
     }
+  
     /* Parse right side of equation as an expression */
 
     current_wave = custom_wave;
@@ -1833,7 +1833,7 @@ int parse_wave(char * token, FILE * fs, preset_t * preset) {
     current_wave = NULL;
 
     //if (PARSE_DEBUG) printf("parse_wave (per_frame): [finished parsing equation] (LINE %d)\n", line_count);
+  
     /* Create a new per frame equation */
     if ((per_frame_eqn = new_per_frame_eqn(custom_wave->per_frame_count++, param, gen_expr)) == NULL) {
       //if (PARSE_DEBUG) printf("parse_wave (per_frame): failed to create a new per frame eqn, out of memory?\n");
@@ -1845,15 +1845,15 @@ int parse_wave(char * token, FILE * fs, preset_t * preset) {
       free_per_frame_eqn(per_frame_eqn);
       return FAILURE;
     }
-    //if (PARSE_DEBUG) printf("parse_wave (per_frame): equation %d associated with custom wave %d [success]\n",
-    //                per_frame_eqn->index, custom_wave->id);
+       
+    //if (PARSE_DEBUG) printf("parse_wave (per_frame): equation %d associated with custom wave %d [success]\n", 
+    //                     per_frame_eqn->index, custom_wave->id);
 
-    /* Need to add stuff to string buffer so the editor can read the equations.
+    
+    /* Need to add stuff to string buffer so the editor can read the equations. 
        Why not make a nice little helper function for this? - here it is: */
 
+   
     if (update_string_buffer(custom_wave->per_frame_eqn_string_buffer, &custom_wave->per_frame_eqn_string_index) < 0)
       return FAILURE;
 
@@ -1871,7 +1871,7 @@ int parse_wave(char * token, FILE * fs, preset_t * preset) {
       //if (PARSE_DEBUG) printf("parse_wave (per_point): equal operator missing after per pixel operator! (LINE %d)\n", line_count);
       return PARSE_ERROR;
     }
+    
     /* Parse right side of equation as an expression */
     current_wave = custom_wave;
     if ((gen_expr = parse_gen_expr(fs, NULL, preset)) == NULL) {
@@ -1886,7 +1886,7 @@ int parse_wave(char * token, FILE * fs, preset_t * preset) {
       return PARSE_ERROR;
     }
 
+   
     if (update_string_buffer(custom_wave->per_point_eqn_string_buffer, &custom_wave->per_point_eqn_string_index) < 0)
       return FAILURE;
 
@@ -1903,7 +1903,7 @@ int parse_wave(char * token, FILE * fs, preset_t * preset) {
 
 /* Parses custom shape equations */
 int parse_shape(char * token, FILE * fs, preset_t * preset) {
+  
   int id;
   char * eqn_type;
   char string[MAX_TOKEN_SIZE];
@@ -1920,7 +1920,7 @@ int parse_shape(char * token, FILE * fs, preset_t * preset) {
     return FAILURE;
   if (preset == NULL)
     return FAILURE;
+  
   /* Grab custom shape id and equation type (per frame or per point) from string token */
   if (parse_shape_prefix(token, &id, &eqn_type) < 0) {
     //if (PARSE_DEBUG) printf("parse_shape: syntax error in custom shape prefix!\n");
@@ -1931,7 +1931,7 @@ int parse_shape(char * token, FILE * fs, preset_t * preset) {
     return FAILURE;
 
 
-  /* per frame init equation case */    
+  /* per frame init equation case */       
   if (!strncmp(eqn_type, SHAPE_INIT_STRING, SHAPE_INIT_STRING_LENGTH)) {
 
     //if (PARSE_DEBUG) printf("parse_shape (per frame init): [begin] (LINE %d)\n", line_count);
@@ -1940,46 +1940,46 @@ int parse_shape(char * token, FILE * fs, preset_t * preset) {
     if ((init_cond = parse_per_frame_init_eqn(fs, preset, custom_shape->param_tree)) == NULL) {
       //if (PARSE_DEBUG) printf("parse_shape (per frame init): equation parsing failed (LINE %d)\n", line_count);
       return PARSE_ERROR;
-    }    
+    }  
+    
     /* Insert the equation in the per frame equation tree */
     if (splay_insert(init_cond, init_cond->param->name, custom_shape->per_frame_init_eqn_tree) < 0) {
       //if (PARSE_DEBUG) printf("parse_shape (per frame init): failed to add equation (ERROR)\n");
-      free_init_cond(init_cond); /* will free the gen expr too */        
+      free_init_cond(init_cond); /* will free the gen expr too */              
       return ERROR;
     }
 
-    if (update_string_buffer(custom_shape->per_frame_init_eqn_string_buffer,
-                 &custom_shape->per_frame_init_eqn_string_index) < 0)
+    if (update_string_buffer(custom_shape->per_frame_init_eqn_string_buffer, 
+                            &custom_shape->per_frame_init_eqn_string_index) < 0)
       return FAILURE;
-    
+       
     return SUCCESS;
+  
   }
 
   /* per frame equation case */
   if (!strncmp(eqn_type, PER_FRAME_STRING_NO_UNDERSCORE, PER_FRAME_STRING_NO_UNDERSCORE_LENGTH)) {
 
     //if (PARSE_DEBUG) printf("parse_shape (per_frame): [start] (custom shape id = %d)\n", custom_shape->id);
+    
     if (parseToken(fs, string) != tEq) {
       //if (PARSE_DEBUG) printf("parse_shape (per_frame): no equal sign after string \"%s\" (LINE %d)\n", string, line_count);
-      return PARSE_ERROR;            
+      return PARSE_ERROR;                      
     }
+  
     /* Find the parameter associated with the string in the custom shape database */
-    if ((param = find_param_db(string, custom_shape->param_tree, TRUE)) == NULL) {
+    if ((param = find_param_db(string, custom_shape->param_tree, TRUE)) == NULL) { 
       //if (PARSE_DEBUG) printf("parse_shape (per_frame): parameter \"%s\" not found or cannot be malloc'ed!!\n", string);
-      return FAILURE;    
+      return FAILURE;  
     }
+  
+    
     /* Make sure parameter is writable */
     if (param->flags & P_FLAG_READONLY) {
-      //if (PARSE_DEBUG) printf("parse_shape (per_frame): parameter %s is marked as read only (LINE %d)\n", param->name, line_count);
+      //if (PARSE_DEBUG) printf("parse_shape (per_frame): parameter %s is marked as read only (LINE %d)\n", param->name, line_count);  
       return FAILURE;
     }
+  
     /* Parse right side of equation as an expression */
 
     current_shape = custom_shape;
@@ -1992,7 +1992,7 @@ int parse_shape(char * token, FILE * fs, preset_t * preset) {
     current_shape = NULL;
 
     //if (PARSE_DEBUG) printf("parse_shape (per_frame): [finished parsing equation] (LINE %d)\n", line_count);
+  
     /* Create a new per frame equation */
     if ((per_frame_eqn = new_per_frame_eqn(custom_shape->per_frame_count++, param, gen_expr)) == NULL) {
       //if (PARSE_DEBUG) printf("parse_shape (per_frame): failed to create a new per frame eqn, out of memory?\n");
@@ -2004,14 +2004,14 @@ int parse_shape(char * token, FILE * fs, preset_t * preset) {
       free_per_frame_eqn(per_frame_eqn);
       return FAILURE;
     }
-    //if (PARSE_DEBUG) printf("parse_shape (per_frame): equation %d associated with custom shape %d [success]\n",
-    //                per_frame_eqn->index, custom_shape->id);
+       
+    //if (PARSE_DEBUG) printf("parse_shape (per_frame): equation %d associated with custom shape %d [success]\n", 
+    //                     per_frame_eqn->index, custom_shape->id);
 
+    
     /* Need to add stuff to string buffer so the editor can read the equations.
        Why not make a nice little helper function for this? - here it is: */
+    
     if (update_string_buffer(custom_shape->per_frame_eqn_string_buffer, &custom_shape->per_frame_eqn_string_index) < 0)
       return FAILURE;
 
@@ -2035,7 +2035,7 @@ int update_string_buffer(char * buffer, int * index) {
   if (!index)
     return FAILURE;
 
+  
   /* If the string line buffer used by the parser is already full then quit */
   if (string_line_buffer_index == (STRING_LINE_SIZE-1))
     return FAILURE;
@@ -2055,20 +2055,20 @@ int update_string_buffer(char * buffer, int * index) {
     return FAILURE;
 
   /* Add line to string buffer */
-  strncpy(buffer + (*index),
-      string_line_buffer + skip_size, string_length);
+  strncpy(buffer + (*index), 
+         string_line_buffer + skip_size, string_length);
+  
   /* Buffer full, quit */
   if ((*index) > (STRING_BUFFER_SIZE - 1)) {
     //if (PARSE_DEBUG) printf("update_string_buffer: string buffer full!\n");
     return FAILURE;
-  }    
+  }    
+  
   /* Otherwise, increment string index by the added string length */
   (*index)+=string_length;
+    
   return SUCCESS;
+  
 }
 
 
@@ -2079,14 +2079,14 @@ int update_string_buffer(char * buffer, int * index) {
 */
 
 int get_string_prefix_len(char * string) {
+  
   int i = 0;
 
   /* Null argument check */
   if (string == NULL)
     return FAILURE;
 
+  
   /* First find the equal sign */
   while (string[i] != '=') {
     if (string[i] == 0)
index 7151aa2263d7cef75faf11c82838f95520d7b058..0b835f5b861017f759f4b0f60b8d6b44e1eba215 100644 (file)
@@ -39,15 +39,15 @@ void eval_per_frame_eqn(per_frame_eqn_t * per_frame_eqn) {
   if (per_frame_eqn == NULL)
     return;
 
-     if (PER_FRAME_EQN_DEBUG) {
-         printf("per_frame_%d=%s= ", per_frame_eqn->index, per_frame_eqn->param->name);
-         fflush(stdout);
-     }
-    
+     if (PER_FRAME_EQN_DEBUG) { 
+                printf("per_frame_%d=%s= ", per_frame_eqn->index, per_frame_eqn->param->name);
+                fflush(stdout);
+        }
+        
     //*((double*)per_frame_eqn->param->engine_val) = eval_gen_expr(per_frame_eqn->gen_expr);
-    set_param(per_frame_eqn->param, eval_gen_expr(per_frame_eqn->gen_expr));
-     if (PER_FRAME_EQN_DEBUG) printf(" = %.4f\n", *((double*)per_frame_eqn->param->engine_val));
-        
+       set_param(per_frame_eqn->param, eval_gen_expr(per_frame_eqn->gen_expr));
+     if (PER_FRAME_EQN_DEBUG) printf(" = %.4f\n", *((double*)per_frame_eqn->param->engine_val)); 
+                
 }
 
 /*
@@ -58,25 +58,25 @@ void eval_per_frame_init_eqn(per_frame_eqn_t * per_frame_eqn) {
    if (per_frame_eqn == NULL)
      return;
 
-     if (PER_FRAME_EQN_DEBUG) {
-         printf("per_frame_init: %s = ", per_frame_eqn->param->name);
-         fflush(stdout);
-     }
-             
-    
+     if (PER_FRAME_EQN_DEBUG) { 
+                printf("per_frame_init: %s = ", per_frame_eqn->param->name);
+                fflush(stdout);
+        }
+                       
+       
     val = *((double*)per_frame_eqn->param->engine_val) = eval_gen_expr(per_frame_eqn->gen_expr);
-    if (PER_FRAME_EQN_DEBUG) printf(" = %f\n", *((double*)per_frame_eqn->param->engine_val));
-    if (per_frame_eqn->param->flags & P_FLAG_QVAR) {
-        
-        per_frame_eqn->param->init_val.double_val = val;
-        if ((init_cond = new_init_cond(per_frame_eqn->param)) == NULL)
-            return;
-        
-        if ((list_append(init_cond_list, init_cond)) < 0) {
-            free_init_cond(init_cond);
-            return;
-        }
+    if (PER_FRAME_EQN_DEBUG) printf(" = %f\n", *((double*)per_frame_eqn->param->engine_val)); 
+     
+       if (per_frame_eqn->param->flags & P_FLAG_QVAR) {
+               
+               per_frame_eqn->param->init_val.double_val = val;
+               if ((init_cond = new_init_cond(per_frame_eqn->param)) == NULL)
+                       return;
+               
+               if ((list_append(init_cond_list, init_cond)) < 0) {
+                       free_init_cond(init_cond);
+                       return;
+               }
     }
 }
 */
@@ -84,9 +84,9 @@ void eval_per_frame_init_eqn(per_frame_eqn_t * per_frame_eqn) {
 /* Frees perframe equation structure */
 void free_per_frame_eqn(per_frame_eqn_t * per_frame_eqn) {
 
-    if (per_frame_eqn == NULL)
-      return;
-    
+       if (per_frame_eqn == NULL)
+         return;
+       
   free_gen_expr(per_frame_eqn->gen_expr);
   free(per_frame_eqn);
 }
index 64c4e90ed82d262931e3695b62ed8fd43149655a..1062b2248156c95b585d2e9f2d60e6a9afde9e18 100644 (file)
@@ -56,40 +56,40 @@ inline void evalPerPixelEqn(per_pixel_eqn_t * per_pixel_eqn) {
   gen_expr_t * eqn_ptr = NULL;
   int x,y;
 
-  eqn_ptr = per_pixel_eqn->gen_expr;
+  eqn_ptr = per_pixel_eqn->gen_expr; 
  if (per_pixel_eqn->param->matrix == NULL) {
-    if (PER_PIXEL_EQN_DEBUG) printf("evalPerPixelEqn: [begin initializing matrix] (index = %d) (name = %s)\n",
-                per_pixel_eqn->index, per_pixel_eqn->param->name);
+    if (PER_PIXEL_EQN_DEBUG) printf("evalPerPixelEqn: [begin initializing matrix] (index = %d) (name = %s)\n", 
+                         per_pixel_eqn->index, per_pixel_eqn->param->name);
+    
     param_matrix = per_pixel_eqn->param->matrix = (double**)malloc(gx*sizeof(double*));
+    
     for(x = 0; x < gx; x++)
       param_matrix[x] = (double *)malloc(gy * sizeof(double));
 
     for (x = 0; x < gx; x++)
       for (y = 0; y < gy; y++)
-    param_matrix[x][y] = 0.0;
+       param_matrix[x][y] = 0.0;
 
     if (per_pixel_eqn->param->name == NULL)
       printf("null parameter?\n");
 
     //    printf("PARAM MATRIX: \"%s\" initialized.\n", per_pixel_eqn->param->name);
   }
-  else
+  else 
     param_matrix = (double**)per_pixel_eqn->param->matrix;
  
   if (eqn_ptr == NULL)
     printf("something is seriously wrong...\n");
-  for (mesh_i = 0; mesh_i < gx; mesh_i++) {
-    for (mesh_j = 0; mesh_j < gy; mesh_j++) {
+  for (mesh_i = 0; mesh_i < gx; mesh_i++) {    
+    for (mesh_j = 0; mesh_j < gy; mesh_j++) {     
       param_matrix[mesh_i][mesh_j] = eval_gen_expr(eqn_ptr);
     }
   }
+  
   /* Now that this parameter has been referenced with a per
      pixel equation, we let the evaluator know by setting
      this flag */
-  per_pixel_eqn->param->matrix_flag = 1;
+  per_pixel_eqn->param->matrix_flag = 1; 
 }
 
 inline void evalPerPixelEqns() {
@@ -112,25 +112,25 @@ int add_per_pixel_eqn(char * name, gen_expr_t * gen_expr, preset_t * preset) {
 
   /* Argument checks */
   if (preset == NULL)
-      return FAILURE;
+         return FAILURE;
   if (gen_expr == NULL)
-      return FAILURE;
+         return FAILURE;
   if (name == NULL)
-      return FAILURE;
+         return FAILURE;
+  
  if (PER_PIXEL_EQN_DEBUG) printf("add_per_pixel_eqn: per pixel equation (name = \"%s\")\n", name);
  
- if (!strncmp(name, "dx", strlen("dx")))
+ if (!strncmp(name, "dx", strlen("dx"))) 
    preset->per_pixel_flag[DX_OP] = TRUE;
- else if (!strncmp(name, "dy", strlen("dy")))
+ else if (!strncmp(name, "dy", strlen("dy"))) 
    preset->per_pixel_flag[DY_OP] = TRUE;
- else if (!strncmp(name, "cx", strlen("cx")))
+ else if (!strncmp(name, "cx", strlen("cx"))) 
    preset->per_pixel_flag[CX_OP] = TRUE;
- else if (!strncmp(name, "cy", strlen("cy")))
+ else if (!strncmp(name, "cy", strlen("cy"))) 
    preset->per_pixel_flag[CX_OP] = TRUE;
- else if (!strncmp(name, "zoom", strlen("zoom")))
+ else if (!strncmp(name, "zoom", strlen("zoom"))) 
    preset->per_pixel_flag[ZOOM_OP] = TRUE;
- else if (!strncmp(name, "zoomexp", strlen("zoomexp")))
+ else if (!strncmp(name, "zoomexp", strlen("zoomexp"))) 
    preset->per_pixel_flag[ZOOMEXP_OP] = TRUE;
  else if (!strncmp(name, "rot", strlen("rot")))
    preset->per_pixel_flag[ROT_OP] = TRUE;
@@ -146,14 +146,14 @@ int add_per_pixel_eqn(char * name, gen_expr_t * gen_expr, preset_t * preset) {
    if (PER_PIXEL_EQN_DEBUG) printf("add_per_pixel_eqn: failed to allocate a new parameter!\n");
    return FAILURE;
  
- }     
+ }      
 
  /* Find most largest index in the splaytree */
  // if ((per_pixel_eqn = splay_find_max(active_preset->per_pixel_eqn_tree)) == NULL)
  // index = 0;
  // else
  index = splay_size(preset->per_pixel_eqn_tree);
+   
  /* Create the per pixel equation given the index, parameter, and general expression */
  if ((per_pixel_eqn = new_per_pixel_eqn(index, param, gen_expr)) == NULL) {
    if (PER_PIXEL_EQN_DEBUG) printf("add_per_pixel_eqn: failed to create new per pixel equation!\n");
@@ -161,56 +161,56 @@ int add_per_pixel_eqn(char * name, gen_expr_t * gen_expr, preset_t * preset) {
 
  }
 
- if (PER_PIXEL_EQN_DEBUG) printf("add_per_pixel_eqn: new equation (index = %d) (param = \"%s\")\n",
-                 per_pixel_eqn->index, per_pixel_eqn->param->name);
+ if (PER_PIXEL_EQN_DEBUG) printf("add_per_pixel_eqn: new equation (index = %d) (param = \"%s\")\n", 
+                                per_pixel_eqn->index, per_pixel_eqn->param->name);
  /* Insert the per pixel equation into the preset per pixel database */
  if (splay_insert(per_pixel_eqn, &per_pixel_eqn->index, preset->per_pixel_eqn_tree) < 0) {
    free_per_pixel_eqn(per_pixel_eqn);
    printf("failed to add per pixel eqn!\n");
-   return FAILURE;    
+   return FAILURE;      
  }
 
- /* Done */
+ /* Done */ 
  return SUCCESS;
 }
 
 per_pixel_eqn_t * new_per_pixel_eqn(int index, param_t * param, gen_expr_t * gen_expr) {
 
-    per_pixel_eqn_t * per_pixel_eqn;
-    
-    if (index < 0)
-      return NULL;
-    if (param == NULL)
-      return NULL;
-    if (gen_expr == NULL)
-      return NULL;
-    
-    if ((per_pixel_eqn = (per_pixel_eqn_t*)malloc(sizeof(per_pixel_eqn_t))) == NULL)
-      return NULL;
-
-    
-    per_pixel_eqn->index = index;
-    per_pixel_eqn->param = param;
-    per_pixel_eqn->gen_expr = gen_expr;
-    
-    return per_pixel_eqn;    
+       per_pixel_eqn_t * per_pixel_eqn;
+       
+       if (index < 0)
+         return NULL;
+       if (param == NULL)
+         return NULL;
+       if (gen_expr == NULL)
+         return NULL;
+       
+       if ((per_pixel_eqn = (per_pixel_eqn_t*)malloc(sizeof(per_pixel_eqn_t))) == NULL)
+         return NULL;
+
+       
+       per_pixel_eqn->index = index;
+       per_pixel_eqn->param = param;
+       per_pixel_eqn->gen_expr = gen_expr;
+       
+       return per_pixel_eqn;   
 }
 
 
 void free_per_pixel_eqn(per_pixel_eqn_t * per_pixel_eqn) {
 
-    if (per_pixel_eqn == NULL)
-        return;
-    
-    free_gen_expr(per_pixel_eqn->gen_expr);
-    
-    free(per_pixel_eqn);
-    
-    return;
+       if (per_pixel_eqn == NULL)
+               return;
+       
+       free_gen_expr(per_pixel_eqn->gen_expr);
+       
+       free(per_pixel_eqn);
+       
+       return;
 }
 
 inline int isPerPixelEqn(int op) {
+    
   return active_preset->per_pixel_flag[op];
 
 }
index cb87152158cb34cd328376f97dc3aa8aedd379a0..a5d4021f8761135f08887783c889e85bd6fc6343 100644 (file)
@@ -7,8 +7,8 @@
 typedef struct PER_PIXEL_EQN_T {
   int index; /* used for splay tree ordering. */
   int flags; /* primarily to specify if this variable is user-defined */
-  param_t * param;
-  gen_expr_t * gen_expr;    
+  param_t * param; 
+  gen_expr_t * gen_expr;       
 } per_pixel_eqn_t;
 
 
index 16fa01052c862196d39075a499cbc16da5ef2ebf..ce10a4116dd25069d9272cc92394c658bdaa1969 100644 (file)
@@ -6,7 +6,7 @@
 typedef struct PER_POINT_EQN {
 
   custom_wave_t * custom_wave;
+  
 
 } per_point_eqn_t;
 
index 8f4b1b711acf8af461eb22e75ab5e0ee4a7b486e..af0471a238ad54874ecfe1507af9fd66cd56c551 100644 (file)
@@ -83,7 +83,7 @@ int preset_name_buffer_size = 0;
 splaytree_t * chrono_order_preset_name_tree = NULL;
 int get_preset_path(char ** preset_path_ptr, char * filepath, char * filename);
 preset_t * load_preset(char * pathname);
-int is_valid_extension(char * name);    
+int is_valid_extension(char * name);   
 int load_preset_file(char * pathname, preset_t * preset);
 int close_preset(preset_t * preset);
 
@@ -105,90 +105,90 @@ void load_custom_shape_init(custom_shape_t * custom_shape);
 
 /* loadPresetDir: opens the directory buffer
    denoted by 'dir' to load presets */
+   
 int loadPresetDir(char * dir) {
 
   struct dirent ** name_list;
   char * preset_name;
   int i, j, dir_size;
+  
   if (dir == NULL)
-    return ERROR;
+       return ERROR;
  
   if (chrono_order_preset_name_tree != NULL) {
-    if (PRESET_DEBUG) printf("loadPresetDir: previous directory doesn't appear to be closed!\n");
-    /* Let this slide for now */
-  }    
-  /* Scan the entire directory, storing each entry in a dirent struct array that needs
+       if (PRESET_DEBUG) printf("loadPresetDir: previous directory doesn't appear to be closed!\n");
+       /* Let this slide for now */
+  }    
+  
+  /* Scan the entire directory, storing each entry in a dirent struct array that needs 
      to be freed later. For more information, consult scandir(3) in the man pages */
   if ((dir_size = scandir(dir, &name_list, 0, alphasort)) < 0) {
-    if (PRESET_DEBUG) printf("loadPresetDir: failed to open directory \"%s\"\n", dir);
-    return ERROR;
+       if (PRESET_DEBUG) printf("loadPresetDir: failed to open directory \"%s\"\n", dir);
+       return ERROR;
   }
+  
   chrono_order_preset_name_tree = create_splaytree(compare_int, copy_int, free_int);
+  
   /* Iterate through entire dirent name list, adding to the preset name list if it
-     is valid */
+     is valid */  
   for (i = 0; ((i < dir_size) && (i < MAX_PRESETS_IN_DIR));i++) {
 
-    /* Only perform the next set of operations if the preset name
-       contains a valid extension */
-    if (is_valid_extension(name_list[i]->d_name)) {
-        
-        /* Handle the out of memory case. My guess is xmms would
-           crash before this program would, but whatever...*/
-        if ((preset_name = (char*)malloc(MAX_PATH_SIZE)) == NULL) {
-            if (PRESET_DEBUG) printf("loadPresetDir: out of memory! \n");
-            
-            /* Free the rest of the dirent name list */
-            for (j = i; j < dir_size; j++)
-                free(name_list[j]);
-            destroy_splaytree(chrono_order_preset_name_tree);
-            return OUTOFMEM_ERROR;
-        }
-                
-        /* Now create the full path */
-        if (get_preset_path(&preset_name, dir, name_list[i]->d_name) < 0) {
-            if (PRESET_DEBUG) printf("loadPresetDir: failed to generate full preset path name!\n");
-            
-            /* Free the rest of the dirent name list */
-            for (j = i; j < dir_size; j++)
-                free(name_list[j]);
-            destroy_splaytree(chrono_order_preset_name_tree);
-            return OUTOFMEM_ERROR;
-            
-        }
-        
-        /* Insert the character string into the splay tree, with the key being its sequence number */
-        splay_insert(preset_name, &preset_name_buffer_size, chrono_order_preset_name_tree);
-        preset_name_buffer_size++;
-    }
-    
-    /* Free the dirent struct */
-    free(name_list[i]);
-    
-  }    
+       /* Only perform the next set of operations if the preset name 
+          contains a valid extension */
+       if (is_valid_extension(name_list[i]->d_name)) {
+               
+               /* Handle the out of memory case. My guess is xmms would
+                  crash before this program would, but whatever...*/
+               if ((preset_name = (char*)malloc(MAX_PATH_SIZE)) == NULL) {
+                       if (PRESET_DEBUG) printf("loadPresetDir: out of memory! \n");
+                       
+                       /* Free the rest of the dirent name list */
+                       for (j = i; j < dir_size; j++) 
+                               free(name_list[j]);
+                       destroy_splaytree(chrono_order_preset_name_tree);
+                       return OUTOFMEM_ERROR;
+               }
+                               
+               /* Now create the full path */
+           if (get_preset_path(&preset_name, dir, name_list[i]->d_name) < 0) {
+                       if (PRESET_DEBUG) printf("loadPresetDir: failed to generate full preset path name!\n");
+                       
+                       /* Free the rest of the dirent name list */
+                       for (j = i; j < dir_size; j++) 
+                               free(name_list[j]);
+                       destroy_splaytree(chrono_order_preset_name_tree);
+                       return OUTOFMEM_ERROR;
+                       
+               }
+               
+               /* Insert the character string into the splay tree, with the key being its sequence number */
+               splay_insert(preset_name, &preset_name_buffer_size, chrono_order_preset_name_tree);
+               preset_name_buffer_size++;
+       }
+       
+       /* Free the dirent struct */
+       free(name_list[i]);
+       
+  }    
+  
   free(name_list);
+  
   /* No valid files in directory! */
   if (chrono_order_preset_name_tree->root == NULL) {
-    if (PRESET_DEBUG) printf("loadPresetDir: no valid files in directory \"%s\"\n", dir);
-    destroy_splaytree(chrono_order_preset_name_tree);
-    chrono_order_preset_name_tree = NULL;
-    return FAILURE;    
-  }    
-      
+       if (PRESET_DEBUG) printf("loadPresetDir: no valid files in directory \"%s\"\n", dir);
+       destroy_splaytree(chrono_order_preset_name_tree);
+       chrono_order_preset_name_tree = NULL;
+       return FAILURE;   
+  }    
+         
   /* Start the prefix index right before the first entry, so next preset
      starts at the top of the list */
   preset_index = -1;
+  
   /* Start the first preset */
 
   switchPreset(ALPHA_NEXT, HARD_CUT);
+  
   return SUCCESS;
 }
 
@@ -197,63 +197,63 @@ int loadPresetDir(char * dir) {
 
 int closePresetDir() {
 
-  /* No preset director appears to be loaded */    
-  if (chrono_order_preset_name_tree == NULL)
+  /* No preset director appears to be loaded */        
+  if (chrono_order_preset_name_tree == NULL) 
     return SUCCESS;
+  
   if (PRESET_DEBUG) {
-     printf("closePresetDir: freeing directory buffer...");
-     fflush(stdout);
-  }
+        printf("closePresetDir: freeing directory buffer...");
+        fflush(stdout);
+  }  
+  
   /* Free each entry in the directory preset name tree */
   splay_traverse(free_int, chrono_order_preset_name_tree);
+  
   /* Destroy the chronological order splay tree */
   destroy_splaytree(chrono_order_preset_name_tree);
   chrono_order_preset_name_tree = NULL;
   preset_name_buffer_size = 0;
   if (PRESET_DEBUG) printf("finished\n");
+  
   return SUCCESS;
 }
 
 
 
-/* Converts a preset file name to a full path */
+/* Converts a preset file name to a full path */ 
 int get_preset_path(char ** preset_path_ptr, char * filepath, char * filename) {
 
   char * preset_path;
-    
+       
   /* An insanely paranoid sequence of argument checks */
   if (preset_path_ptr == NULL)
-    return ERROR;
+       return ERROR;
   if (*preset_path_ptr == NULL)
     return ERROR;
   if (filename == NULL)
-    return ERROR;
+       return ERROR;
   if (filepath == NULL)
-    return ERROR;
+       return ERROR;
+  
   /* Mostly here for looks */
   preset_path = *preset_path_ptr;
 
   /* Clear the name space first */
   memset(preset_path, 0, MAX_PATH_SIZE);
+  
   /* Now create the string "PATH/FILENAME", where path is either absolute or relative location
      of the .milk file, and filename is the name of the preset file itself */
   strcat(
-      strcat(
-          strncpy(
-              preset_path,
-              filepath,
-            MAX_PATH_SIZE-1),
-        "/"),
-    filename);    
+       strcat(
+               strncpy(
+                       preset_path, 
+                   filepath, 
+            MAX_PATH_SIZE-1),   
+        "/"), 
+    filename); 
 
   return SUCCESS;
-}    
+}      
 
 /* switchPreset: loads the next preset from the directory stream.
    loadPresetDir() must be called first. This is a
@@ -262,52 +262,52 @@ int get_preset_path(char ** preset_path_ptr, char * filepath, char * filename) {
 int switchPreset(switch_mode_t switch_mode, int cut_type) {
 
   preset_t * new_preset;
-    
+       
   int switch_index;
-    
+       
   /* Make sure a preset directory list is in the buffer */
   if (chrono_order_preset_name_tree == NULL) {
     if (PRESET_DEBUG) printf("switchPreset: it helps if you open a directory first with a loadPresetDir() call\n");
     return ERROR;
   }
+  
+  
   switch (switch_mode) {
-    
+         
   case ALPHA_NEXT:
   /* An index variable that iterates through the directory
      buffer, doing wrap around when it reaches the end of
-       the buffer */
+        the buffer */
+  
   if (preset_index == (preset_name_buffer_size - 1))
-        switch_index = preset_index = 0;
-  else    
-          switch_index = ++preset_index;
+               switch_index = preset_index = 0;
+  else 
+               switch_index = ++preset_index;
   break;
 
   case ALPHA_PREVIOUS:
-    
+         
   if (preset_index == 0)
-        switch_index = preset_index = preset_name_buffer_size - 1;
-  else    
-          switch_index = --preset_index;
+               switch_index = preset_index = preset_name_buffer_size - 1;
+  else 
+               switch_index = --preset_index;
   break;
+  
   case RANDOM_NEXT:
-    switch_index = (int) (preset_name_buffer_size*(rand()/(RAND_MAX+1.0)));
-    break;
+       switch_index = (int) (preset_name_buffer_size*(rand()/(RAND_MAX+1.0)));
+       break;
   case RESTART_ACTIVE:
-    switch_index = preset_index;
-    break;
+       switch_index = preset_index;
+       break;
   default:
-      return FAILURE;
+       return FAILURE;
   }
+  
+    
   /* Finally, load the preset using its actual path */
   if ((new_preset = load_preset((char*)splay_find(&switch_index, chrono_order_preset_name_tree))) == NULL) {
-    if (PRESET_DEBUG) printf("switchPreset: failed to load preset\n");
-    return ERROR;
+       if (PRESET_DEBUG) printf("switchPreset: failed to load preset\n");
+       return ERROR;
   }
 
   /* Closes a preset currently loaded, if any */
@@ -345,13 +345,13 @@ int loadPresetByFile(char * filename) {
  
   /* Finally, load the preset using its actual path */
   if ((new_preset = load_preset(filename)) == NULL) {
-    if (PRESET_DEBUG) printf("loadPresetByFile: failed to load preset!\n");
-    return ERROR;    
+       if (PRESET_DEBUG) printf("loadPresetByFile: failed to load preset!\n");
+       return ERROR;     
   }
 
   /* Closes a preset currently loaded, if any */
   if ((active_preset != NULL) && (active_preset != idle_preset))
-    close_preset(active_preset);
+    close_preset(active_preset); 
 
   /* Sets active preset global pointer */
   active_preset = new_preset;
@@ -368,7 +368,7 @@ int loadPresetByFile(char * filename) {
 
   /* Add any missing initial conditions */
   load_init_conditions();
+  
   /* Need to do this once for menu */
   evalInitConditions();
   //  evalPerFrameInitEquations();
@@ -385,7 +385,7 @@ int init_idle_preset() {
   if ((preset = (preset_t*)malloc(sizeof(preset_t))) == NULL)
     return FAILURE;
 
+  
   strncpy(preset->name, "idlepreset", strlen("idlepreset"));
 
   /* Initialize equation trees */
@@ -397,29 +397,29 @@ int init_idle_preset() {
   preset->custom_wave_tree = create_splaytree(compare_int, copy_int, free_int);
   preset->custom_shape_tree = create_splaytree(compare_int, copy_int, free_int);
  
-  /* Set file path to dummy name */
+  /* Set file path to dummy name */  
   strncpy(preset->file_path, "IDLE PRESET", MAX_PATH_SIZE-1);
+  
   /* Set initial index values */
   preset->per_pixel_eqn_string_index = 0;
   preset->per_frame_eqn_string_index = 0;
   preset->per_frame_init_eqn_string_index = 0;
   memset(preset->per_pixel_flag, 0, sizeof(int)*NUM_OPS);
+  
   /* Clear string buffers */
   memset(preset->per_pixel_eqn_string_buffer, 0, STRING_BUFFER_SIZE);
   memset(preset->per_frame_eqn_string_buffer, 0, STRING_BUFFER_SIZE);
   memset(preset->per_frame_init_eqn_string_buffer, 0, STRING_BUFFER_SIZE);
 
   idle_preset = preset;
+  
   return SUCCESS;
 }
 
 int destroy_idle_preset() {
 
   return close_preset(idle_preset);
+  
 }
 
 /* initPresetLoader: initializes the preset
@@ -432,7 +432,7 @@ int initPresetLoader() {
 
   /* Initializes the builtin function database */
   init_builtin_func_db();
-    
+       
   /* Initializes all infix operators */
   init_infix_ops();
 
@@ -485,17 +485,17 @@ void switchToIdlePreset() {
 }
 
 /* destroyPresetLoader: closes the preset
-   loading library. This should be done when
+   loading library. This should be done when 
    projectM does cleanup */
 
 int destroyPresetLoader() {
-  if ((active_preset != NULL) && (active_preset != idle_preset)) {    
-      close_preset(active_preset);
-  }    
+  
+  if ((active_preset != NULL) && (active_preset != idle_preset)) {     
+       close_preset(active_preset);      
+  }    
 
   active_preset = NULL;
+  
   destroy_idle_preset();
   destroy_builtin_param_db();
   destroy_builtin_func_db();
@@ -507,19 +507,19 @@ int destroyPresetLoader() {
 
 /* load_preset_file: private function that loads a specific preset denoted
    by the given pathname */
-int load_preset_file(char * pathname, preset_t * preset) {
+int load_preset_file(char * pathname, preset_t * preset) { 
   FILE * fs;
   int retval;
 
   if (pathname == NULL)
-      return FAILURE;
+         return FAILURE;
   if (preset == NULL)
-      return FAILURE;
+         return FAILURE;
+  
   /* Open the file corresponding to pathname */
   if ((fs = utf8_fopen(pathname, "r")) == 0) {
     if (PRESET_DEBUG) printf("load_preset_file: loading of file %s failed!\n", pathname);
-    return ERROR;    
+    return ERROR;      
   }
 
   if (PRESET_DEBUG) printf("load_preset_file: file stream \"%s\" opened successfully\n", pathname);
@@ -530,14 +530,14 @@ int load_preset_file(char * pathname, preset_t * preset) {
     fclose(fs);
     return FAILURE;
   }
+  
   /* Parse the preset name and a left bracket */
   if (parse_preset_name(fs, preset->name) < 0) {
     if (PRESET_DEBUG) printf("load_preset_file: loading of preset name in file \"%s\" failed\n", pathname);
     fclose(fs);
     return ERROR;
   }
+  
   if (PRESET_DEBUG) printf("load_preset_file: preset \"%s\" parsed\n", preset->name);
 
   /* Parse each line until end of file */
@@ -547,18 +547,18 @@ int load_preset_file(char * pathname, preset_t * preset) {
       if (PRESET_DEBUG > 1) printf("load_preset_file: parse error in file \"%s\"\n", pathname);
     }
   }
-  if (PRESET_DEBUG) printf("load_preset_file: finished line parsing successfully\n");
+  
+  if (PRESET_DEBUG) printf("load_preset_file: finished line parsing successfully\n"); 
 
   /* Now the preset has been loaded.
      Evaluation calls can be made at appropiate
      times in the frame loop */
+  
   fclose(fs);
+   
   if (PRESET_DEBUG) printf("load_preset_file: file \"%s\" closed, preset ready\n", pathname);
   return SUCCESS;
+  
 }
 
 void evalInitConditions() {
@@ -573,29 +573,29 @@ void evalPerFrameEquations() {
 void evalPerFrameInitEquations() {
   //printf("evalPerFrameInitEquations: per frame init unimplemented!\n");
   //  splay_traverse(eval_per_frame_eqn, active_preset->per_frame_init_eqn_tree);
-}    
+}      
 
 /* Returns nonzero if string 'name' contains .milk or
    (the better) .prjm extension. Not a very strong function currently */
 int is_valid_extension(char * name) {
 
-    if (PRESET_DEBUG > 1) {
-        printf("is_valid_extension: scanning string \"%s\"...", name);
-        fflush(stdout);
-    }
-
-    if (strstr(name, MILKDROP_FILE_EXTENSION)) {
-            if (PRESET_DEBUG > 1) printf("\".milk\" extension found in string [true]\n");
-            return TRUE;
-    }    
-    
-    if (strstr(name, PROJECTM_FILE_EXTENSION)) {
-            if (PRESET_DEBUG > 1) printf("\".prjm\" extension found in string [true]\n");
-            return TRUE;
-    }
-    
-    if (PRESET_DEBUG > 1) printf("no valid extension found [false]\n");
-    return FALSE;
+       if (PRESET_DEBUG > 1) {
+               printf("is_valid_extension: scanning string \"%s\"...", name);
+               fflush(stdout);
+       }
+
+       if (strstr(name, MILKDROP_FILE_EXTENSION)) {
+                       if (PRESET_DEBUG > 1) printf("\".milk\" extension found in string [true]\n");
+                       return TRUE;
+       }       
+       
+       if (strstr(name, PROJECTM_FILE_EXTENSION)) {
+                   if (PRESET_DEBUG > 1) printf("\".prjm\" extension found in string [true]\n");
+                       return TRUE;
+       }
+        
+       if (PRESET_DEBUG > 1) printf("no valid extension found [false]\n");
+       return FALSE;
 }
 
 /* Private function to close a preset file */
@@ -607,33 +607,33 @@ int close_preset(preset_t * preset) {
 
   splay_traverse(free_init_cond, preset->init_cond_tree);
   destroy_splaytree(preset->init_cond_tree);
+  
   splay_traverse(free_init_cond, preset->per_frame_init_eqn_tree);
   destroy_splaytree(preset->per_frame_init_eqn_tree);
+  
   splay_traverse(free_per_pixel_eqn, preset->per_pixel_eqn_tree);
   destroy_splaytree(preset->per_pixel_eqn_tree);
+  
   splay_traverse(free_per_frame_eqn, preset->per_frame_eqn_tree);
   destroy_splaytree(preset->per_frame_eqn_tree);
+  
   splay_traverse(free_param, preset->user_param_tree);
   destroy_splaytree(preset->user_param_tree);
+  
   splay_traverse(free_custom_wave, preset->custom_wave_tree);
   destroy_splaytree(preset->custom_wave_tree);
 
   splay_traverse(free_custom_shape, preset->custom_shape_tree);
   destroy_splaytree(preset->custom_shape_tree);
 
-  free(preset);
+  free(preset); 
+  
   return SUCCESS;
 
 }
 
 void reloadPerPixel(char *s, preset_t * preset) {
+  
   FILE * fs;
   int slen;
   char c;
@@ -740,7 +740,7 @@ preset_t * load_preset(char * pathname) {
   /* Initialize preset struct */
   if ((preset = (preset_t*)malloc(sizeof(preset_t))) == NULL)
     return NULL;
+   
   /* Initialize equation trees */
   preset->init_cond_tree = create_splaytree(compare_string, copy_string, free_string);
   preset->user_param_tree = create_splaytree(compare_string, copy_string, free_string);
@@ -752,25 +752,25 @@ preset_t * load_preset(char * pathname) {
 
   memset(preset->per_pixel_flag, 0, sizeof(int)*NUM_OPS);
 
-  /* Copy file path */
+  /* Copy file path */  
   strncpy(preset->file_path, pathname, MAX_PATH_SIZE-1);
+  
   /* Set initial index values */
   preset->per_pixel_eqn_string_index = 0;
   preset->per_frame_eqn_string_index = 0;
   preset->per_frame_init_eqn_string_index = 0;
+  
+  
   /* Clear string buffers */
   memset(preset->per_pixel_eqn_string_buffer, 0, STRING_BUFFER_SIZE);
   memset(preset->per_frame_eqn_string_buffer, 0, STRING_BUFFER_SIZE);
   memset(preset->per_frame_init_eqn_string_buffer, 0, STRING_BUFFER_SIZE);
+  
+  
   if (load_preset_file(pathname, preset) < 0) {
-    if (PRESET_DEBUG) printf("load_preset: failed to load file \"%s\"\n", pathname);
-    close_preset(preset);
-    return NULL;
+       if (PRESET_DEBUG) printf("load_preset: failed to load file \"%s\"\n", pathname);
+       close_preset(preset);
+       return NULL;
   }
 
   /* It's kind of ugly to reset these values here. Should definitely be placed in the parser somewhere */
@@ -787,11 +787,11 @@ void savePreset(char * filename) {
 
   if (filename == NULL)
     return;
+  
   /* Open the file corresponding to pathname */
   if ((fs = utf8_fopen(filename, "w+")) == 0) {
     if (PRESET_DEBUG) printf("savePreset: failed to create filename \"%s\"!\n", filename);
-    return;    
+    return;    
   }
 
   write_stream = fs;
@@ -863,7 +863,7 @@ int write_init_conditions(FILE * fs) {
 
 
   splay_traverse(write_init, active_preset->init_cond_tree);
+  
   return SUCCESS;
 }
 
@@ -880,7 +880,7 @@ void write_init(init_cond_t * init_cond) {
   if (init_cond->param->type == P_TYPE_BOOL)
     sprintf(s, "%s=%d\n", init_cond->param->name, init_cond->init_val.bool_val);
 
-  else if (init_cond->param->type == P_TYPE_INT)
+  else if (init_cond->param->type == P_TYPE_INT)    
     sprintf(s, "%s=%d\n", init_cond->param->name, init_cond->init_val.int_val);
 
   else if (init_cond->param->type == P_TYPE_DOUBLE)
@@ -908,7 +908,7 @@ int write_per_frame_init_equations(FILE * fs) {
     return FAILURE;
   if (active_preset == NULL)
     return FAILURE;
+  
   len = strlen(active_preset->per_frame_init_eqn_string_buffer);
 
   if (fwrite(active_preset->per_frame_init_eqn_string_buffer, 1, len, fs) != len)
@@ -973,14 +973,14 @@ void load_init_cond(param_t * param) {
   /* If initial condition was not defined by the preset file, force a default one
      with the following code */
   if ((init_cond = splay_find(param->name, active_preset->init_cond_tree)) == NULL) {
+    
     /* Make sure initial condition does not exist in the set of per frame initial equations */
     if ((init_cond = splay_find(param->name, active_preset->per_frame_init_eqn_tree)) != NULL)
       return;
+    
     if (param->type == P_TYPE_BOOL)
       init_val.bool_val = 0;
+    
     else if (param->type == P_TYPE_INT)
       init_val.int_val = *(int*)param->engine_val;
 
@@ -991,13 +991,13 @@ void load_init_cond(param_t * param) {
     /* Create new initial condition */
     if ((init_cond = new_init_cond(param, init_val)) == NULL)
       return;
+    
     /* Insert the initial condition into this presets tree */
     if (splay_insert(init_cond, init_cond->param->name, active_preset->init_cond_tree) < 0) {
       free_init_cond(init_cond);
       return;
     }
+    
   }
  
 }
index 4dbaaa00e51c277a0da563f95e31ec8d50ca638d..06cfa895d00af72879d5143034315d3c17515389 100644 (file)
@@ -5,7 +5,7 @@
 #include "expr_types.h"
 #include "per_pixel_eqn_types.h"
 
-typedef enum {    
+typedef enum { 
   ALPHA_NEXT,
   ALPHA_PREVIOUS,
   RANDOM_NEXT,
@@ -13,14 +13,14 @@ typedef enum {
 } switch_mode_t;
 
 typedef struct PRESET_T {
+  
   char name[MAX_TOKEN_SIZE]; /* preset name as parsed in file */
   char file_path[MAX_PATH_SIZE]; /* Points to the preset file name */
+  
   int per_pixel_eqn_string_index;
   int per_frame_eqn_string_index;
   int per_frame_init_eqn_string_index;
-    
+       
   int per_pixel_flag[NUM_OPS];
   char per_pixel_eqn_string_buffer[STRING_BUFFER_SIZE];
   char per_frame_eqn_string_buffer[STRING_BUFFER_SIZE];
index f70a888e2bbf34532ea909b27b6768e96d73f1e2..c509d5b5a79ab9e16086f8ddc2ec782ee83df762 100644 (file)
@@ -27,7 +27,7 @@
 /*
                 An implementation of top-down splaying
                     D. Sleator <sleator@cs.cmu.edu>
-                             March 1992
+                            March 1992
 
   "Splay trees", or "self-adjusting search trees" are a simple and
   efficient data structure for storing an ordered set.  The data
@@ -69,7 +69,7 @@
 
   The following code was written by Daniel Sleator, and is released
   in the public domain. It has been heavily modified by Carmelo Piccione,
-  (cep@andrew.cmu.edu), to suit personal needs,
+  (cep@andrew.cmu.edu), to suit personal needs, 
 */
 
 #include <stdlib.h>
@@ -107,7 +107,7 @@ inline splaytree_t * create_splaytree(int (*compare)(), void * (*copy_key)(), vo
   splaytree->compare = compare;
   splaytree->copy_key = copy_key;
   splaytree->free_key = free_key;
+  
   /* Return instantiated splay tree */
   return splaytree;
 }
@@ -124,7 +124,7 @@ inline int destroy_splaytree(splaytree_t * splaytree) {
 
   /* Free the splaytree struct itself */
   free(splaytree);
+  
   /* Done, return success */
   return SUCCESS;
 
@@ -139,16 +139,16 @@ static inline int free_splaynode(splaynode_t * splaynode, void (*free_key)()) {
 
   /* Free left node */
   free_splaynode(splaynode->left, free_key);
+  
   /* Free right node */
   free_splaynode(splaynode->right, free_key);
+  
   /* Free this node's key */
   free_key(splaynode->key);
+  
   /* Note that the data pointers are not freed here.
      Should be freed with a splay traversal function */
+  
   /* Free the splaynode structure itself */
   free(splaynode);
  
@@ -163,10 +163,10 @@ inline void splay_traverse(void (*func_ptr)(), splaytree_t * splaytree) {
   /* Null argument check */
 
   if (splaytree == NULL)
-    return;
+    return; 
   if (func_ptr == NULL)
-    return;
+       return;
+  
   /* Call recursive helper function */
   splay_traverse_helper(func_ptr, splaytree->root);
 
@@ -174,7 +174,7 @@ inline void splay_traverse(void (*func_ptr)(), splaytree_t * splaytree) {
 }
 
 /* Helper function to traverse the entire splaytree */
-static inline void splay_traverse_helper (void (*func_ptr)(), splaynode_t * splaynode) {
+static inline void splay_traverse_helper (void (*func_ptr)(), splaynode_t * splaynode) {  
 
   /* Normal if this happens, its a base case of recursion */
   if (splaynode == NULL)
@@ -182,20 +182,20 @@ static inline void splay_traverse_helper (void (*func_ptr)(), splaynode_t * spla
 
   /* Recursively traverse to the left */
   splay_traverse_helper(func_ptr, splaynode->left);
+  
+  
   /* Node is a of regular type, so its ok to perform the function on it */
   if (splaynode->type == REGULAR_NODE_TYPE)
-      func_ptr(splaynode->data);
+       func_ptr(splaynode->data);
+  
   /* Node is of symbolic link type, do nothing */
   else if (splaynode->type == SYMBOLIC_NODE_TYPE)
-    ;
+       ;
+  
   /* Unknown node type */
   else
     ;
+  
   /* Recursively traverse to the right */
   splay_traverse_helper(func_ptr, splaynode->right);
 
@@ -210,35 +210,35 @@ inline void * splay_find(void * key, splaytree_t * splaytree) {
   int match_type;
 
   if (key == NULL)
-      return NULL;
+         return NULL;
+  
   if (splaytree == NULL)
-      return NULL;
+         return NULL;
+  
   splaynode = splaytree->root;
+  
   /* Bring the targeted splay node to the top of the splaytree */
   splaynode = splay(key, splaynode, &match_type, splaytree->compare);
   splaytree->root = splaynode;
+  
+  
   /* We only want perfect matches, so return null when match isn't perfect */
-  if (match_type == CLOSEST_MATCH)
+  if (match_type == CLOSEST_MATCH) 
     return NULL;
 
   /* This shouldn't happen because of the match type check, but whatever */
   if (splaytree->root == NULL)
-      return NULL;
+         return NULL;
+  
   /* Node is a regular type, return its data pointer */
   if (splaytree->root->type == REGULAR_NODE_TYPE) /* regular node */
-      return splaytree->root->data;
+       return splaytree->root->data;
+  
   /* If the node is a symlink, pursue one link */
   if (splaytree->root->type == SYMBOLIC_NODE_TYPE) /* symbolic node */
-    return ((splaynode_t*)splaytree->root->data)->data;
+       return ((splaynode_t*)splaytree->root->data)->data;
+    
+  
   /* Unknown type */
   return NULL;
 }
@@ -248,14 +248,14 @@ inline splaynode_t * get_splaynode_of(void * key, splaytree_t * splaytree) {
 
   splaynode_t * splaynode;
   int match_type;
-  /* Null argument checks */    
+  
+  /* Null argument checks */   
   if (splaytree == NULL)
-      return NULL;
+         return NULL;
+  
   if (key == NULL)
-      return NULL;
+         return NULL;
+  
   splaynode = splaytree->root;
 
   /* Find the splaynode */
@@ -272,52 +272,52 @@ inline splaynode_t * get_splaynode_of(void * key, splaytree_t * splaytree) {
 
 /* Finds the desired node, and changes the tree such that it is the root */
 static inline splaynode_t * splay (void * key, splaynode_t * t, int * match_type, int (*compare)()) {
-/* Simple top down splay, not requiring key to be in the tree t.
+  
+/* Simple top down splay, not requiring key to be in the tree t. 
    What it does is described above. */
  
     splaynode_t N, *l, *r, *y;
     *match_type = CLOSEST_MATCH;
-    if (t == NULL) return t;
+  
+       if (t == NULL) return t;
     N.left = N.right = NULL;
     l = r = &N;
+  
     for (;;) {
-    if (compare(key, t->key) < 0) {
-        if (t->left == NULL) break;
-        if (compare(key, t->left->key) < 0) {
-        y = t->left;                           /* rotate right */
-        t->left = y->right;
-        y->right = t;
-        t = y;
-        if (t->left == NULL) break;
-        }
-        r->left = t;                               /* link right */
-        r = t;
-        t = t->left;
-    } else if (compare(key, t->key) > 0) {
-        if (t->right == NULL) break;
-        if (compare(key, t->right->key) > 0) {
-        y = t->right;                          /* rotate left */
-        t->right = y->left;
-        y->left = t;
-        t = y;
-        if (t->right == NULL) break;
-        }
-        l->right = t;                              /* link left */
-        l = t;
-        t = t->right;
-    } else {
-      *match_type = PERFECT_MATCH;
-      break;
-    }
+       if (compare(key, t->key) < 0) {
+           if (t->left == NULL) break;
+           if (compare(key, t->left->key) < 0) {
+               y = t->left;                           /* rotate right */
+               t->left = y->right;
+               y->right = t;
+               t = y;
+               if (t->left == NULL) break;
+           }
+           r->left = t;                               /* link right */
+           r = t;
+           t = t->left;
+       } else if (compare(key, t->key) > 0) {
+           if (t->right == NULL) break;
+           if (compare(key, t->right->key) > 0) {
+               y = t->right;                          /* rotate left */
+               t->right = y->left;
+               y->left = t;
+               t = y;
+               if (t->right == NULL) break;
+           }
+           l->right = t;                              /* link left */
+           l = t;
+           t = t->right;
+       } else {
+         *match_type = PERFECT_MATCH;
+         break;
+       }
     }
     l->right = t->left;                                /* assemble */
     r->left = t->right;
     t->left = N.right;
     t->right = N.left;
+    
     return t;
 
     //return NULL;
@@ -326,79 +326,79 @@ static inline splaynode_t * splay (void * key, splaynode_t * t, int * match_type
 /* Deletes a splay node from a splay tree. If the node doesn't exist
    then nothing happens */
 inline int splay_delete(void * key, splaytree_t * splaytree) {
+  
   splaynode_t * splaynode;
 
   /* Use helper function to delete the node and return the resulting tree */
   if ((splaynode = splay_delete_helper(key, splaytree->root, splaytree->compare, splaytree->free_key)) == NULL)
-      return FAILURE;
+         return FAILURE;
+  
   /* Set new splaytree root equal to the returned splaynode after deletion */
   splaytree->root = splaynode;
+  
   /* Finished, no errors */
   return SUCCESS;
 }
 
 /* Deletes a splay node */
 static inline splaynode_t * splay_delete_helper(void * key, splaynode_t * splaynode, int (*compare)(), void (*free_key)()) {
-    
+       
     splaynode_t * new_root;
     int match_type;
-    
-    /* Argument check */    
-    if (splaynode == NULL)
-        return NULL;
-    
+       
+       /* Argument check */    
+    if (splaynode == NULL) 
+               return NULL;
+       
     splaynode = splay(key, splaynode, &match_type, compare);
-    
-    /* If entry wasn't found, quit here */
-    if (match_type == CLOSEST_MATCH)
-        return NULL;
-    
-    /* If the targeted node's left pointer is null, then set the new root
-       equal to the splaynode's right child */
-    if (splaynode->left == NULL) {
-        new_root = splaynode->right;
-    }
-    
-    /* Otherwise, do something I don't currently understand */
-    else {
-        new_root = splay(key, splaynode->left, &match_type, compare);
-        new_root->right = splaynode->right;
-    }
-
-    /* Set splay nodes children pointers to null */
-    splaynode->left = splaynode->right = NULL;
-    
-    /* Free the splaynode (and only this node since its children are now empty */
-    free_splaynode(splaynode, free_key);
-    
-    /* Return the resulting tree */
-    return new_root;
-    
+       
+       /* If entry wasn't found, quit here */
+       if (match_type == CLOSEST_MATCH) 
+               return NULL;
+       
+       /* If the targeted node's left pointer is null, then set the new root
+          equal to the splaynode's right child */
+       if (splaynode->left == NULL) {
+           new_root = splaynode->right;
+       } 
+       
+       /* Otherwise, do something I don't currently understand */
+       else {
+           new_root = splay(key, splaynode->left, &match_type, compare);
+           new_root->right = splaynode->right;
+       }
+
+       /* Set splay nodes children pointers to null */
+       splaynode->left = splaynode->right = NULL;
+       
+       /* Free the splaynode (and only this node since its children are now empty */
+       free_splaynode(splaynode, free_key);
+       
+       /* Return the resulting tree */
+       return new_root;
+       
 }
 
 /* Create a new splay node type */
 static inline splaynode_t * new_splaynode(int type, void * key, void * data) {
-    splaynode_t * splaynode;    
-    /* Argument checks */
-    if (data == NULL)
-        return NULL;
-    
-    if (key == NULL)
-        return NULL;
-    
-    /* Creates the new splay node struct */
-    if ((splaynode = (splaynode_t*)malloc(sizeof(splaynode_t))) == NULL)
-        return NULL;
-    
-    splaynode->data = data;
-    splaynode->type = type;
-    splaynode->key = key;
-    
-    /* Return the new splay node */
-    return splaynode;
+       splaynode_t * splaynode;        
+       /* Argument checks */
+       if (data == NULL)
+               return NULL;
+       
+       if (key == NULL)
+               return NULL;
+       
+       /* Creates the new splay node struct */
+       if ((splaynode = (splaynode_t*)malloc(sizeof(splaynode_t))) == NULL)
+               return NULL;
+       
+       splaynode->data = data;
+       splaynode->type = type;
+       splaynode->key = key;
+       
+       /* Return the new splay node */
+       return splaynode;
 }
 
 /* Inserts a link into the splay tree */
@@ -407,24 +407,24 @@ inline int splay_insert_link(void * alias_key, void * orig_key, splaytree_t * sp
    splaynode_t * splaynode, * data_node;
    void * key_clone;
 
-   /* Null arguments */    
+   /* Null arguments */        
    if (splaytree == NULL)
-        return FAILURE;
+               return FAILURE;
+   
    if (alias_key == NULL)
-           return FAILURE;
+               return FAILURE;
 
    if (orig_key == NULL)
-           return FAILURE;
+               return FAILURE;
+   
    /* Find the splaynode corresponding to the original key */
    if ((data_node = get_splaynode_of(orig_key, splaytree)) == NULL)
-       return FAILURE;
+          return FAILURE;
+   
    /* Create a new splay node of symbolic link type */
    if ((splaynode = new_splaynode(SYMBOLIC_NODE_TYPE, (key_clone = splaytree->copy_key(alias_key)), data_node)) == NULL) {
-        splaytree->free_key(key_clone);
-        return OUTOFMEM_ERROR;
+               splaytree->free_key(key_clone);
+               return OUTOFMEM_ERROR;
    }
 
    /* Insert the splaynode into the given splaytree */
@@ -432,45 +432,45 @@ inline int splay_insert_link(void * alias_key, void * orig_key, splaytree_t * sp
      splaynode->left=splaynode->right = NULL;
      free_splaynode(splaynode, splaytree->free_key);
      return FAILURE;
-   }        
-    
+   }           
+       
    /* Done, return success */
    return SUCCESS;
-}    
+}      
 
 /* Inserts 'data' into the 'splaytree' paired with the passed 'key' */
 inline int splay_insert(void * data, void * key, splaytree_t * splaytree) {
 
-    splaynode_t * splaynode;
-    void * key_clone;
-    
-    /* Null argument checks */
-    if (splaytree == NULL) {
-        return FAILURE;
-    }
-    
-    if (key == NULL)
-        return FAILURE;
-    
-    /* Clone the key argument */
-    key_clone = splaytree->copy_key(key);
-
-    /* Create a new splaynode (of regular type) */
-    if ((splaynode = new_splaynode(REGULAR_NODE_TYPE, key_clone, data)) == NULL) {
-        splaytree->free_key(key_clone);
-        return OUTOFMEM_ERROR;        
-    }
-    
-    /* Inserts the splaynode into the splaytree */
-    if (splay_insert_node(splaynode, splaytree) < 0) {
-      splaynode->left=splaynode->right=NULL;
-      free_splaynode(splaynode, splaytree->free_key);
-      return FAILURE;        
-    }    
-
-    return SUCCESS;
+       splaynode_t * splaynode;
+       void * key_clone;
+       
+       /* Null argument checks */
+       if (splaytree == NULL) {
+           return FAILURE;
+       }
+       
+       if (key == NULL)
+               return FAILURE;
+       
+       /* Clone the key argument */
+       key_clone = splaytree->copy_key(key);
+
+       /* Create a new splaynode (of regular type) */
+       if ((splaynode = new_splaynode(REGULAR_NODE_TYPE, key_clone, data)) == NULL) {
+               splaytree->free_key(key_clone);
+               return OUTOFMEM_ERROR;          
+       }
+       
+       
+       /* Inserts the splaynode into the splaytree */
+       if (splay_insert_node(splaynode, splaytree) < 0) {
+         splaynode->left=splaynode->right=NULL;
+         free_splaynode(splaynode, splaytree->free_key);
+         return FAILURE;               
+       }       
+     
+
+       return SUCCESS;
 }
 
 /* Helper function to insert splaynodes into the splaytree */
@@ -479,216 +479,216 @@ static inline int splay_insert_node(splaynode_t * splaynode, splaytree_t * splay
   int cmpval;
   void * key;
   splaynode_t * t;
-    
+       
   /* Null argument checks */
   if (splaytree == NULL)
     return FAILURE;
 
   if (splaynode == NULL)
-    return FAILURE;
+       return FAILURE;
+  
   key = splaynode->key;
-  t = splaytree->root;
+  
+  t = splaytree->root; 
 
 
   /* Root is null, insert splaynode here */
   if (t == NULL) {
-    splaynode->left = splaynode->right = NULL;
-    splaytree->root = splaynode;
-    return SUCCESS;
+       splaynode->left = splaynode->right = NULL;
+       splaytree->root = splaynode;
+       return SUCCESS;
 
   }
+  
   t = splay(key, t, &match_type, splaytree->compare);
+  
   if ((cmpval = splaytree->compare(key,t->key)) < 0) {
-    splaynode->left = t->left;
-    splaynode->right = t;
-    t->left = NULL;
-    splaytree->root = splaynode;
-    return SUCCESS;
+       splaynode->left = t->left;
+       splaynode->right = t;
+       t->left = NULL;
+       splaytree->root = splaynode;
+       return SUCCESS;
 
-  }
+  } 
 
   else if (cmpval > 0) {
-    splaynode->right = t->right;
-    splaynode->left = t;
-    t->right = NULL;
-    splaytree->root = splaynode;
-    return SUCCESS;
-   }
+       splaynode->right = t->right;
+       splaynode->left = t;
+       t->right = NULL; 
+       splaytree->root = splaynode;
+       return SUCCESS;
+   } 
+   
    /* Item already exists in tree, don't reinsert */
   else {
+    
     return FAILURE;
   }
 }
 
 /* Returns the 'maximum' key that is less than the given key in the splaytree */
 inline void * splay_find_below_max(void * key, splaytree_t * splaytree) {
-    
-    void * closest_key;
-    
-    if (splaytree == NULL)
-        return NULL;
-    if (splaytree->root == NULL)
-        return NULL;
-    if (key == NULL)
-        return NULL;
-    
-    closest_key = NULL;
-    
-    splay_find_below_max_helper(key, &closest_key, splaytree->root, splaytree->compare);
-
-    if (closest_key == NULL) return NULL;
-    return splay_find(closest_key, splaytree);
+       
+       void * closest_key;
+       
+       if (splaytree == NULL)
+               return NULL;
+       if (splaytree->root == NULL)
+               return NULL;
+       if (key == NULL)
+               return NULL;
+       
+       closest_key = NULL;
+       
+       splay_find_below_max_helper(key, &closest_key, splaytree->root, splaytree->compare);
+
+       if (closest_key == NULL) return NULL;
+       return splay_find(closest_key, splaytree);
 }
 
 
 /* Returns the 'minimum' key that is greater than the given key in the splaytree */
 inline void * splay_find_above_min(void * key, splaytree_t * splaytree) {
-    
-    void * closest_key;
-    
-    if (splaytree == NULL)
-        return NULL;
-    if (splaytree->root == NULL)
-        return NULL;
-    if (key == NULL)
-        return NULL;
-    closest_key = NULL;
-    
-    splay_find_above_min_helper(key, &closest_key, splaytree->root, splaytree->compare);
-
-    if (closest_key == NULL) {
-        return NULL;
-    }
-    
-    return splay_find(closest_key, splaytree);
+       
+       void * closest_key;
+       
+       if (splaytree == NULL)
+               return NULL;
+       if (splaytree->root == NULL)
+               return NULL;
+       if (key == NULL)
+               return NULL;
+       closest_key = NULL;
+       
+       splay_find_above_min_helper(key, &closest_key, splaytree->root, splaytree->compare);
+
+       if (closest_key == NULL) { 
+               return NULL;
+       }
+       
+       return splay_find(closest_key, splaytree);
 }
 
 /* Helper function */
 static inline void splay_find_below_max_helper(void * min_key, void ** closest_key, splaynode_t * root, int (*compare)()) {
 
-        /* Empty root, return*/    
-        if (root == NULL)
-            return;
-            
-        /* The root key is less than the previously found closest key.
-           Also try to make the key non null if the value is less than the max key */
-        
-        if ((*closest_key == NULL) || (compare(root->key, *closest_key) < 0)) {
-            
-            /*  The root key is less than the given max key, so this is the
-                smallest change from the given max key */
-            if (compare(root->key, min_key) > 0) {
-                
-                *closest_key = root->key;
-                
-                /* Look right again in case even a greater key exists that is
-                   still less than the given max key */
-                splay_find_below_max_helper(min_key, closest_key, root->left, compare);
-            }
-            
-            /* The root key is greater than the given max key, and greater than
-               the closest key, so search left */
-            else {
-                splay_find_below_max_helper(min_key, closest_key, root->right, compare);                
-            }    
-        }    
-        
-        /* The root key is less than the found closest key, search right */
-        else {
-                splay_find_below_max_helper(min_key, closest_key, root->left, compare);                
-        }
-    
+               /* Empty root, return*/ 
+               if (root == NULL)
+                       return;
+                       
+               /* The root key is less than the previously found closest key.
+                  Also try to make the key non null if the value is less than the max key */
+               
+               if ((*closest_key == NULL) || (compare(root->key, *closest_key) < 0)) {
+                       
+                       /*  The root key is less than the given max key, so this is the
+                               smallest change from the given max key */
+                       if (compare(root->key, min_key) > 0) {
+                               
+                               *closest_key = root->key;
+                               
+                               /* Look right again in case even a greater key exists that is 
+                                  still less than the given max key */
+                               splay_find_below_max_helper(min_key, closest_key, root->left, compare);
+                       }
+                       
+                       /* The root key is greater than the given max key, and greater than 
+                          the closest key, so search left */
+                       else {
+                               splay_find_below_max_helper(min_key, closest_key, root->right, compare);                                
+                       }       
+               }       
+               
+               /* The root key is less than the found closest key, search right */
+               else {
+                               splay_find_below_max_helper(min_key, closest_key, root->left, compare);                         
+               }
+       
 }
 
 /* Helper function */
 static inline void splay_find_above_min_helper(void * max_key, void ** closest_key, splaynode_t * root, int (*compare)()) {
 
-        /* Empty root, stop */    
-        if (root == NULL)
-            return;
-            
-        /* The root key is greater than the previously found closest key.
-           Also try to make the key non null if the value is less than the min key */
-        
-        if ((*closest_key == NULL) || (compare(root->key, *closest_key) > 0)) {
-            
-            /*  The root key is greater than the given min key, so this is the
-                smallest change from the given min key */
-            if (compare(root->key, max_key) < 0) {
-                
-                *closest_key = root->key;
-                
-               /* Look left again in case even a smaller key exists that is
-                  still greater than the given min key */
-                splay_find_above_min_helper(max_key, closest_key, root->right, compare);
-            }
-            
-            /* The root key is less than the given min key, and less than
-               the closest key, so search right */
-            else {
-                splay_find_above_min_helper(max_key, closest_key, root->left, compare);                
-            }    
-        }    
-        
-        /* The root key is greater than the found closest key, search left */
-        else {
-                splay_find_above_min_helper(max_key, closest_key, root->right, compare);                
-        }
-}    
+               /* Empty root, stop */  
+               if (root == NULL)
+                       return;
+                       
+               /* The root key is greater than the previously found closest key.
+                  Also try to make the key non null if the value is less than the min key */
+               
+               if ((*closest_key == NULL) || (compare(root->key, *closest_key) > 0)) {
+                       
+                       /*  The root key is greater than the given min key, so this is the
+                               smallest change from the given min key */
+                       if (compare(root->key, max_key) < 0) {
+                               
+                               *closest_key = root->key;
+                               
+                          /* Look left again in case even a smaller key exists that is 
+                                 still greater than the given min key */
+                               splay_find_above_min_helper(max_key, closest_key, root->right, compare);
+                       }
+                       
+                       /* The root key is less than the given min key, and less than 
+                          the closest key, so search right */
+                       else {
+                               splay_find_above_min_helper(max_key, closest_key, root->left, compare);                         
+                       }       
+               }       
+               
+               /* The root key is greater than the found closest key, search left */
+               else {
+                               splay_find_above_min_helper(max_key, closest_key, root->right, compare);                                
+               }
+}      
 
 /* Find the minimum entry of the splay tree */
 inline void * splay_find_min(splaytree_t * t) {
 
-    splaynode_t * splaynode;
-    
-    if (t == NULL)
-        return NULL;
-    if (t->root == NULL)
-        return NULL;
-    
-    splaynode = t->root;
-    
-    while (splaynode->left != NULL)
-        splaynode= splaynode->left;
-    
-    return splaynode->data;
+       splaynode_t * splaynode;
+       
+       if (t == NULL)
+               return NULL;
+       if (t->root == NULL)
+               return NULL;
+       
+       splaynode = t->root;
+       
+       while (splaynode->left != NULL)
+               splaynode= splaynode->left;
+       
+       return splaynode->data;
 }
 
 
 /* Find the maximum entry of the splay tree */
 inline void * splay_find_max(splaytree_t * t) {
 
-    splaynode_t * splaynode;
-    
-    if (t == NULL)
-        return NULL;
-    if (t->root == NULL)
-        return NULL;
-    
-    splaynode = t->root;
-    
-    while (splaynode->right != NULL) {
-      printf("data:%d\n", *(int*)splaynode->key);
-        splaynode = splaynode->right;
-    }
-    return splaynode->data;
+       splaynode_t * splaynode;
+       
+       if (t == NULL)
+               return NULL;
+       if (t->root == NULL)
+               return NULL;
+       
+       splaynode = t->root;
+        
+       while (splaynode->right != NULL) {
+         printf("data:%d\n", *(int*)splaynode->key);
+               splaynode = splaynode->right;
+       }
+       return splaynode->data;
 }
 
 inline int splay_size(splaytree_t * t) {
 
-    if (t == NULL)
-      return 0;
-    if (t->root == NULL)
-      return 0;
-    
-    return splay_rec_size(t->root);
-    
+       if (t == NULL)
+         return 0;
+       if (t->root == NULL)
+         return 0;
+       
+       return splay_rec_size(t->root);
+        
 }
 
 static inline int splay_rec_size(splaynode_t * splaynode) {
index 171aa5ed2b6531ad28a78dd9f1e4bde76e736c4a..0201222c826718054f86091e7ba8fc53f26ab366 100644 (file)
 /* Compares integer value numbers in 32 bit range */
 int compare_int(int * num1, int * num2) {
 
-    if ((*num1) < (*num2))
-        return -1;
-    if ((*num1) > (*num2))
-        return 1;
-    
-    return 0;
+       if ((*num1) < (*num2))
+               return -1;
+       if ((*num1) > (*num2))
+               return 1;
+       
+       return 0;
 }
 
 /* Compares strings in lexographical order */
@@ -43,8 +43,8 @@ int compare_string(char * str1, char * str2) {
   //  printf("comparing \"%s\" to \"%s\"\n", str1, str2);
   //return strcmp(str1, str2);
   return strncmp(str1, str2, MAX_TOKEN_SIZE-1);
-    
-}    
+       
+}      
 
 /* Compares a string in version order. That is, file1 < file2 < file10 */
 int compare_string_version(char * str1, char * str2) {
@@ -55,36 +55,36 @@ int compare_string_version(char * str1, char * str2) {
 
 
 void free_int(void * num) {
-    free(num);
+       free(num);
 }
 
 
 void free_string(char * string) {
-    
-    free(string);    
-}    
+       
+       free(string);   
+}      
  
 void * copy_int(int * num) {
-    
-    int * new_num;
-    
-    if ((new_num = (int*)malloc(sizeof(int))) == NULL)
-        return NULL;
+       
+       int * new_num;
+       
+       if ((new_num = (int*)malloc(sizeof(int))) == NULL)
+               return NULL;
 
-    *new_num = *num;
-    
-    return (void*)new_num;
-}    
+       *new_num = *num;
+       
+       return (void*)new_num;
+}      
 
 
 void * copy_string(char * string) {
-    
-    char * new_string;
-    
-    if ((new_string = (char*)malloc(MAX_TOKEN_SIZE)) == NULL)
-        return NULL;
-    
-    strncpy(new_string, string, MAX_TOKEN_SIZE-1);
-    
-    return (void*)new_string;
+       
+       char * new_string;
+       
+       if ((new_string = (char*)malloc(MAX_TOKEN_SIZE)) == NULL)
+               return NULL;
+       
+       strncpy(new_string, string, MAX_TOKEN_SIZE-1);
+       
+       return (void*)new_string;
 }
index b3a0e3369a8c851b4915ac5b0eb21d5fb382e12e..9839a01a649d824a204eef0ec4b8dcb961df178b 100644 (file)
@@ -43,7 +43,7 @@ extern char *buffer;
 
 void setup_opengl( int w, int h )
 {
+   
     /* Our shading model--Gouraud (smooth). */
      glShadeModel( GL_SMOOTH);
     /* Culling. */
@@ -60,21 +60,21 @@ void setup_opengl( int w, int h )
      */
     glMatrixMode(GL_TEXTURE);
     glLoadIdentity();
+    
     //    gluOrtho2D(0.0, (GLfloat) width, 0.0, (GLfloat) height);
     glMatrixMode(GL_PROJECTION);
-    glLoadIdentity();
+    glLoadIdentity();  
+   
     //    glFrustum(0.0, height, 0.0,width,10,40);
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
 
-glDrawBuffer(GL_BACK);
-  glReadBuffer(GL_BACK);
-  glEnable(GL_BLEND);
+glDrawBuffer(GL_BACK); 
+  glReadBuffer(GL_BACK); 
+  glEnable(GL_BLEND); 
 
-     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-     // glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
+     // glBlendFunc(GL_SRC_ALPHA, GL_ONE); 
   glEnable(GL_LINE_SMOOTH);
   glEnable(GL_POINT_SMOOTH);
   glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
@@ -83,8 +83,8 @@ glDrawBuffer(GL_BACK);
   // glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,texsize,texsize,0);
   //glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,texsize,texsize);
    glLineStipple(2, 0xAAAA);
+  
+    
 }
 
 void CreateRenderTarget(int texsize,int *RenderTargetTextureID, int *RenderTarget )
@@ -98,23 +98,23 @@ void CreateRenderTarget(int texsize,int *RenderTargetTextureID, int *RenderTarge
     /* Create the render target */
     *RenderTarget = SDL_GL_CreateRenderTarget(texsize,texsize, NULL);
         if ( *RenderTarget ) {
-    int value;
-
-    //printf("Created render target:\n");
-    SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_RED_SIZE, &value );
-    //    printf( "SDL_GL_RED_SIZE: %d\n", value);
-    SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_GREEN_SIZE, &value );
-    //    printf( "SDL_GL_GREEN_SIZE: %d\n", value);
-    SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_BLUE_SIZE, &value );
-    //    printf( "SDL_GL_BLUE_SIZE: %d\n", value);
-    SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_ALPHA_SIZE, &value );
-    //    printf( "SDL_GL_ALPHA_SIZE: %d\n", value);
-    SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_DEPTH_SIZE, &value );
-    //    printf( "SDL_GL_DEPTH_SIZE: %d\n", value );
-
-    SDL_GL_BindRenderTarget(*RenderTarget, *RenderTargetTextureID);
+    
+       int value;
+
+       //printf("Created render target:\n");
+       SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_RED_SIZE, &value );
+       //      printf( "SDL_GL_RED_SIZE: %d\n", value);
+       SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_GREEN_SIZE, &value );
+       //      printf( "SDL_GL_GREEN_SIZE: %d\n", value);
+       SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_BLUE_SIZE, &value );
+       //      printf( "SDL_GL_BLUE_SIZE: %d\n", value);
+       SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_ALPHA_SIZE, &value );
+       //      printf( "SDL_GL_ALPHA_SIZE: %d\n", value);
+       SDL_GL_GetRenderTargetAttribute( *RenderTarget, SDL_GL_DEPTH_SIZE, &value );
+       //      printf( "SDL_GL_DEPTH_SIZE: %d\n", value );
+
+       SDL_GL_BindRenderTarget(*RenderTarget, *RenderTargetTextureID);
+       
     } else {
 #endif
         /* We can fake a render target in this demo by rendering to the
@@ -124,13 +124,13 @@ void CreateRenderTarget(int texsize,int *RenderTargetTextureID, int *RenderTarge
 
         glBindTexture(GL_TEXTURE_2D, *RenderTargetTextureID);
         glTexImage2D(GL_TEXTURE_2D,
-            0,
-            GL_RGB,
-            texsize, texsize,
-            0,
-            GL_RGB,
-            GL_UNSIGNED_BYTE,
-            buffer);
+                       0,
+                       GL_RGB,
+                       texsize, texsize,
+                       0,
+                       GL_RGB,
+                       GL_UNSIGNED_BYTE,
+                       buffer);
  //   }
 
 }