Sha256: ae7e7cab50d3ab62b293a6ae94717bfa867b34759ca321d686777f56e7f8b020

Contents?: true

Size: 947 Bytes

Versions: 71

Compression:

Stored size: 947 Bytes

Contents

#include "etl.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>

static int compare(const void *a, const void *b)
{
   new_map *p = (new_map *) a;
   new_map *q = (new_map *) b;
   return (p->key - q->key);
}

int convert(const legacy_map * input, const size_t input_len, new_map ** output)
{
   if (input == NULL || input_len <= 0)
      return 0;

   int len = 0;
   for (size_t i = 0; i < input_len; i++) {
      len += strlen(input[i].keys);
   }

   *output = malloc(len * sizeof(new_map));
   if (*output == NULL) {
      fprintf(stderr, "Memory error!\n");
      return -1;
   }

   int pos = 0;
   for (size_t i = 0; i < input_len; i++) {
      char *tmp = (char *)input[i].keys;
      while (*tmp) {
         (*output)[pos].key = tolower(*tmp);
         (*output)[pos].value = input[i].value;
         tmp++;
         pos++;
      }
   }

   qsort(*output, len, sizeof(new_map), compare);

   return len;
}

Version data entries

71 entries across 71 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.179 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.178 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.177 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.176 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.175 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.174 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.173 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.172 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.171 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.170 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.169 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.167 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.166 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.165 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.164 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.163 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.162 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.161 tracks/c/exercises/etl/src/example.c
trackler-2.2.1.160 tracks/c/exercises/etl/src/example.c