Пример #1
0
void
blocking_generate_keys(project_t *project, uint32_t id) {
  size_t i, j;
  conjunction_t *conjunction;
  part_t *part;
  record_t *record;
  char buffer[5], key[1024];

  record = array_get(project->d0->records, id);

  for(i = 0; i < array_size(project->conjunctions); i++) {
    conjunction = array_get(project->conjunctions, i);
    key[0] = '\0';

    for(j = 0; j < array_size(conjunction->parts); j++) {
      part = array_get(conjunction->parts, j);

      if(!part->transform) {
        strcat(key, record_get_field(record, part->field));
      } else if(!strcmp(part->transform, "brsoundex")) {
        brsoundex(record_get_field(record, part->field), buffer, 5);
        strcat(key, buffer);
      }
      else {
        handle_error("Unknown transformation");
      }
    }
    if(strlen(key)) {
      block_insert(project->block, key, id);
    }
  }
}
Пример #2
0
static cv_t default_handler(obj_t cont, obj_t values)
{
    /*
     * For all non-message-irritants-who conditions,
     *     print the condition's class.
     * For all message conditions, print the condition's message.
     * If who or irritants given, print (cons who irritants).
     */

    assert(is_cont(cont));
    EVAL_LOG("cont=%O values=%O", cont, values);
    obj_t ex = CAR(values);
    obj_t parts = record_get_field(ex, 0);
    const char *psn = program_short_name();
    size_t psnl = strlen(psn);
    size_t i, size = vector_len(parts);
    for (i = 0; i < size; i++) {
	obj_t rtd = record_rtd(vector_ref(parts, i));
	if (rtd != message && rtd != irritants && rtd != who) {
	    ofprintf(stderr, "%*s: %O\n", (int)psnl, psn, rtd_name(rtd));
	    psn = "";
	}
    }
    obj_t who_p = FALSE_OBJ;
    obj_t irr_p = make_uninitialized();
    for (i = 0; i < size; i++) {
	obj_t p = vector_ref(parts, i);
	obj_t rtd = record_rtd(p);
	if (rtd == message) {
	    obj_t msg = record_get_field(p, 0);
	    const wchar_t *chars = string_value(msg);
	    fprintf(stderr, "%*s  %ls\n", (int)psnl, psn, chars);
	    psn = "";
	} else if (rtd == who)
	    who_p = record_get_field(p, 0);
	else if (rtd == irritants)
	    irr_p = record_get_field(p, 0);
    }
    if (who_p != FALSE_OBJ && !is_uninitialized(irr_p)) {
	ofprintf(stderr, "%*s  %O\n", (int)psnl, psn, CONS(who_p, irr_p));
	psn = "";
    } else if (who_p != FALSE_OBJ) {
	ofprintf(stderr, "%*s  %O\n", (int)psnl, psn, who_p);
	psn = "";
    } else if (!is_uninitialized(irr_p)) {
	ofprintf(stderr, "%*s  %O\n", (int)psnl, psn, irr_p);
	psn = "";
    }
    if (*psn)
	fprintf(stderr, "%s: unknown exception\n", psn);
    ofprintf(stderr, "\n");
    return cv(EMPTY_LIST, CONS(make_uninitialized(), EMPTY_LIST));
}
Пример #3
0
static cv_t push_exception(obj_t cont, obj_t values)
{
    assert(is_cont(cont));
    obj_t ex = add_who_irritants(cont, values, eval_exception);
    obj_t handler = record_get_field(eval_dyn_env, DE_HANDLER);
    obj_t second = make_cont4(c_exception_returned,
			      EMPTY_LIST,
			      cont_env(cont),
			      EMPTY_LIST);
    obj_t first = make_cont5(c_apply_proc,
			     second,
			     cont_env(cont),
			     handler,
			     values);
    return cv(first, CONS(ex, values));
}
Пример #4
0
bool fldata_parse(struct fdict_s *fdict, struct record_s *record, char *data)
{
  struct field_s *field;
  char *start, *end;
  int idx = 0;

  start = data;
  end = data;
  while (*end != '\0' && *end != '\n') {
    end = fldata_field_end_pos(end);
    *end = '\0';
    field = record_get_field(fdict, record, idx);
    if (!field_set_value(fdict, field, idx, (const char*)start)) {
      if (fdict->error)
	printf("%s\n", fdict->error);
      else
	printf("Unknow Error!!");
      return false;
    }
    start = ++end;
    idx++;
  }
  return true;
}
Пример #5
0
void
test_record() {
  record_t *record;
  char fields[] = "ab\0abc\0abcd\0abcde\0ab\0c";
  uint8_t *sizes;
  size_t num_fields = 6;

  sizes = malloc(sizeof(uint8_t) * 6);

  sizes[0] = 3;
  sizes[1] = 4;
  sizes[2] = 5;
  sizes[3] = 6;
  sizes[4] = 3;
  sizes[5] = 2;

  record = record_new(num_fields, fields, sizes);

  assert_string_equal("ab", record_get_field(record, 0));
  assert_string_equal("abc", record_get_field(record, 1));
  assert_string_equal("abcd", record_get_field(record, 2));
  assert_string_equal("abcde", record_get_field(record, 3));
  assert_string_equal("ab", record_get_field(record, 4));
  assert_string_equal("c", record_get_field(record, 5));

  assert_string_equal("ab", record_get_id(record));

  assert_int_equal(2, record_field_size(record, 0));
  assert_int_equal(3, record_field_size(record, 1));
  assert_int_equal(4, record_field_size(record, 2));
  assert_int_equal(5, record_field_size(record, 3));
  assert_int_equal(2, record_field_size(record, 4));
  assert_int_equal(1, record_field_size(record, 5));

  record_free(record);
}
Пример #6
0
static cv_t c_test_handler(obj_t cont, obj_t values)
{
    obj_t ex = vector_ref(record_get_field(CAR(values), 0), 0);
    return cv(EMPTY_LIST, MAKE_LIST(ex));
}