Ejemplo n.º 1
0
ta_identity_t *ta_identity_create(char *name, xt_core_log_t *log)
{
  assert(name);
  assert(log);
  ta_identity_t *identity;
  xt_core_bool_t so_far_so_good;

  identity = malloc(sizeof *identity);
  if (identity) {
    identity->log = log;
    identity->phrases_qutex = NULL;
    identity->phrases = NULL;
    identity->name = xt_core_string_copy(name);
    if (identity->name) {
      so_far_so_good = xt_core_bool_true;
    } else {
      so_far_so_good = xt_core_bool_false;
      xt_core_log_trace(log, " ta ", "xt_core_string_copy");
    }
  } else {
    so_far_so_good = xt_core_bool_false;
    xt_core_log_trace(log, " ta ", "malloc");
  }

  if (so_far_so_good) {
    identity->phrases = xt_case_list_create(ta_phrase_compare, ta_phrase_copy,
        ta_phrase_destroy);
    if (identity->phrases) {
      so_far_so_good = xt_core_bool_true;
      xt_case_list_set_size_limit(identity->phrases, MAX_PHRASES_SIZE);
    } else {
      so_far_so_good = xt_core_bool_false;
      xt_core_log_enter(log, " ta ", "xt_case_list_create");
    }
  }

  if (so_far_so_good) {
    identity->phrases_qutex = xt_sync_qutex_create();
    if (!identity->phrases_qutex) {
      so_far_so_good = xt_core_bool_false;
      xt_core_log_enter(log, " ta ", "xt_sync_qutex_create");
    }
  }

  if (identity && !so_far_so_good) {
    if (identity->name) {
      xt_core_string_destroy(identity->name);
    }
    if (identity->phrases) {
      xt_case_list_destroy(identity->phrases);
    }
    if (identity->phrases_qutex) {
      xt_sync_qutex_destroy(identity->phrases_qutex);
    }
    free(identity);
    identity = NULL;
  }

  return identity;
}
Ejemplo n.º 2
0
Archivo: array.c Proyecto: xtools/xt
xt_case_array_t *xt_case_array_create_strings_from_string
(char *string, char *separators)
{
  assert(string);
  assert(separators);
  xt_case_array_t *array;
  char *strtok_context;
  char *token;
  char *token_copy;
  unsigned long index;
  unsigned long field_count;
  char *string_char;
  char *separators_char;

  field_count = 0;
  for (string_char = string; *string_char != '\0'; string_char++) {
    for (separators_char = separators; *separators_char != '\0';
         separators_char++) {
      if (*string_char == *separators_char) {
        field_count++;
        break;
      }
    }
  }
  field_count++;

  array = xt_case_array_create(field_count, xt_core_string_compare,
      xt_core_string_copy, xt_core_string_destroy);
  if (array) {
    index = 0;
    token = strtok_r(string, separators, &strtok_context);
    while (token) {
      token_copy = xt_core_string_copy(token);
      if (token_copy) {
        xt_case_array_add(array, index, token_copy);
        index++;
      } else {
        xt_core_trace("x_core_string_copy");
      }
      token = strtok_r(NULL, separators, &strtok_context);
    }
  } else {
    xt_core_trace("create");
  }

  return array;
}
Ejemplo n.º 3
0
ta_identity_t *ta_identity_create_decoy(char *name, xt_core_log_t *log)
{
  assert(name);
  assert(log);
  ta_identity_t *identity;

  identity = malloc(sizeof *identity);
  if (identity) {
    identity->log = log;
    identity->name = xt_core_string_copy(name);
    if (!identity->name) {
      xt_core_log_trace(log, " ta ", "xt_core_string_copy");
      free(identity);
      identity = NULL;
    }
  } else {
    xt_core_log_trace(log, " ta ", "malloc");
  }

  return identity;
}
Ejemplo n.º 4
0
Archivo: csv.c Proyecto: xtools/xt
xt_case_map_t *create_name_to_index_map(xt_file_csv_t *csv,
    xt_file_basic_t *file)
{
  assert(csv);
  assert(file);
  xt_case_list_t *line_list;
  xt_case_map_t *map;
  xt_case_list_t *field_names;
  char *first_line;
  char *name_object;
  unsigned long index;
  unsigned long *index_object;
  char *name;

  map = NULL;

  line_list = xt_file_basic_get_as_line_list(file);
  if (line_list) {
    first_line = xt_case_list_find_first(line_list);
    if (first_line) {
      field_names = xt_case_list_create_strings_from_string
        (first_line, ",");
      if (field_names) {
        csv->field_count = xt_case_list_get_size(field_names);
        map = xt_case_map_create(&xt_core_objects.string_iobject,
            &xt_core_objects.unsigned_long_iobject, XT_CASE_MAP_DESTROY);
        if (map) {
          index = 0;
          xt_case_list_iterate_start(field_names);
          while ((name = xt_case_list_iterate_next(field_names))) {
            name_object = xt_core_string_copy(name);
            if (name_object) {
              index_object = malloc(sizeof *index_object);
              if (index_object) {
                *index_object = index;
                if (!xt_case_map_add(map, name_object, index_object)) {
                  xt_core_trace("x_case_map_add");
                }
              } else {
                xt_core_trace("malloc");
              }
            } else {
              xt_core_trace("x_core_string_copy");
            }
            index++;
          }
        } else {
          xt_core_trace("x_case_map_create");
        }
        xt_case_list_destroy(field_names);
      } else {
        xt_core_trace("x_case_list_create_strings_from_string");
      }
    } else {
      xt_core_trace("x_case_list_find_first");
    }
    xt_case_list_destroy(line_list);
  } else {
    xt_core_trace("x_file_basic_get_as_line_list");
  }

  return map;
}