#include <stdio.h>
#include <string.h>
using namespace std;
void delete_enter(char c[1025])
{
c[strlen(c)-1]=0;
}
void delete_spaces(char c[1025])
{
char* p;
for(p=strstr(c,": ");p;p=strstr(p,": "))
strcpy(p+1,p+2);
for(p=strstr(c," \"");p;p=strstr(p," \""))
strcpy(p,p+1);
for(p=strstr(c,"\" ");p;p=strstr(p,"\" "))
strcpy(p+1,p+2);
}
void delete_quotations(char c[1025])
{
char* p;
p=strstr(c,"\"");
if(p)
strcpy(p,p+1);
p=strstr(c,"\"");
if(p)
p[0]=0;
}
void extract_header(FILE* f, FILE* g)
{
char c[1025], *p, copie[1025];
do
{
fgets(c,1025,f);
delete_enter(c);
delete_spaces(c);
strcpy(copie,c);
// printf("%s",copie);
for(p=strtok(copie,",:\"");p && strstr(p,"}")==NULL;p=strtok(NULL,",:\""))
{
if(strstr(p,"{"))
continue;
else
{
fprintf(g,"%s,",p);
p=strtok(NULL,",:\"");
}
}
}while(strstr(c,"}")==NULL);
fprintf(g,"\n");
fseek(f,0L,SEEK_SET);
}
int main()
{
int end_line=0;
char c[1025], *p, copie[1025];
FILE* f;
FILE *g;
f=fopen("convertor.in","rt");
g=fopen("convertor.out","wt");
extract_header(f,g);
do
{
fgets(c,1025,f);
delete_enter(c);
delete_spaces(c);
strcpy(copie,c);
// printf("%s",copie);
for(p=strtok(copie,",:");p;p=strtok(NULL,":,"))
{
p=strtok(NULL,":,");
if(strstr(p,"}"))
end_line=1;
delete_quotations(p);
fprintf(g,"%s,",p);
if(end_line==1)
{
fprintf(g,"\n");
end_line=0;
}
}
}while(strstr(c,"]")==NULL);
return 0;
}