/*
 * input map code
 *
 * Copyright 2003 Jacob Robbins
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <stdio.h>
#include <stdlib.h>

#include "../include.h"




void print_action(event_map_action_t* act){
  if (event_map_action_get_type(act) == EVENT_MAP_ACTION_TYPE_REMAP_EXTERN)
    printf("(extern, ");
  else if (event_map_action_get_type(act) == EVENT_MAP_ACTION_TYPE_REMAP_LOCAL)
    printf("(local, ");
  else if (event_map_action_get_type(act) == EVENT_MAP_ACTION_TYPE_CALLBACK_FUNCTION)
    printf("(callbk %d, ", event_map_action_get_function_index(act));

  printf("trgt:%d, ",  event_map_action_get_target_index(act));
  if (event_map_action_get_fixed_event(act))
    printf("fxd  ");
  printf("off:%d ",  event_map_action_get_source_offset(act));
  printf(")  ");
}

void print_submap(event_submap_t* sbmap){
  int i,j;
  unsigned char min,max;
  min = max = 0;

  if (event_submap_get_parameter_test_type(sbmap) == SUBMAP_TEST_TYPE_EXACT)
    printf("test type exact,   ");
  else
    printf("test type range,   ");

  if (event_submap_get_parameter_data_type(sbmap) == EVENT_PARAMETER_DATA_TYPE_UCHAR)
    printf("data type unsigned char\n");
  else if (event_submap_get_parameter_data_type(sbmap) == EVENT_PARAMETER_DATA_TYPE_CHAR)
    printf("data type char\n");
  else if (event_submap_get_parameter_data_type(sbmap) == EVENT_PARAMETER_DATA_TYPE_INT)
    printf("data type int\n");
  else if (event_submap_get_parameter_data_type(sbmap) == EVENT_PARAMETER_DATA_TYPE_FLOAT)
    printf("data type float\n");


  /*print test array*/
  printf("  test array: size %i\n",event_submap_get_test_array_size(sbmap) );
  for (i=0;i<event_submap_get_test_array_size(sbmap);++i){

    if (event_submap_get_parameter_test_type(sbmap) == SUBMAP_TEST_TYPE_EXACT){
      if (event_submap_get_test_exact(sbmap,i,(void*)&min) < 0) printf("ERROR");
      printf("    test%d (%d) has %d actions:  \n",i,min,event_submap_get_test_action_count(sbmap, i)  );
    }else{
      if (event_submap_get_test_min(sbmap,i,(void*)&min) < 0) printf("ERROR");
      if (event_submap_get_test_max(sbmap,i,(void*)&max) < 0) printf("ERROR");
      printf("    test%d (%d,%d) has %d actions:  ",i,min,max,event_submap_get_test_action_count(sbmap, i)  );
    }

    for (j=0; j < event_submap_get_test_action_count(sbmap, i); ++j)
      print_action(event_submap_get_test_action(sbmap,i,j));
    
    printf("\n");
  }

}


void print_input_map(event_input_map_t* inmap){
  int i;
  

  printf("\ninput map with event type  %i  ",event_input_map_get_event_type(inmap));
  printf("has  %i  submap(s):",event_input_map_get_submap_array_size(inmap));

  /*print all submaps*/
  for (i=0; i < event_input_map_get_submap_array_size(inmap); ++i){
    printf("\n  submap %i:   ",i);
    print_submap(event_input_map_get_submap(inmap,i));
  }

  printf("\n");
}

