#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BLSIZE 2000000
int count(FILE *, char, int *);
int main()
{
FILE *input = fopen("convertor.in", "rb");
FILE *output = fopen("convertor.out", "w");
int i, j, nr = 0;
char *array, *p;
int poz[BLSIZE];
nr = count(input, '}', poz);
array = calloc(poz[1], 1);
fread(array, 1, poz[1], input);
p = strchr(array, ':');
while (p) {
i = 0;
while (p[i] != '\"')
i--;
i--;
while (p[i] != '\"')
i--;
i++;
while (p[i] != '\"') {
fprintf(output, "%c", p[i]);
i++;
}
fprintf(output, ",");
p = strchr(p + 1, ':');
}
fprintf(output, "\n");
fseek(input, 0, 0);
free(array);
for(i = 1; i < nr; i++) {
array = calloc(poz[i] - poz[i - 1], 1);
fread(array, 1, poz[i] - poz[i - 1], input);
p = strchr(array, ':');
while (p) {
j = 1;
while (p[j] <= 32)
j++;
if (p[j] == '\"') {
j++;
while (p[j] != '"') {
fprintf(output, "%c", p[j]);
j++;
}
} else {
while (strchr("0123456789-", p[j])) {
fprintf(output, "%c", p[j]);
j++;
}
}
fprintf(output, ",");
p = strchr(p + 1, ':');
}
free(array);
fprintf(output, "\n");
}
fclose(input);
fclose(output);
return 0;
}
int count(FILE * f, char c, int *v)
{
fseek(f, 0, 0);
int nr = 1, poz = 0, len;
char buff[BLSIZE], *p;
while (fread(buff, 1, BLSIZE, f)) {
p = strchr(buff, c);
while (p) {
v[nr] = poz + (p - buff);
nr++;
p = strchr(p + 1, c);
}
poz += BLSIZE;
}
fseek(f, 0, 0);
return nr;
}