Revert back to vesion dcb8b68ada4f8e05ad124203b1ab401838fc5a34 due to erroneous fix in latest version of canonizer.c

This commit is contained in:
VilhoRaatikka
2014-11-03 08:51:32 +02:00
parent dcb8b68ada
commit dc71322cbf

View File

@ -24,76 +24,67 @@ static char* server_groups[] = {
NULL NULL
}; };
/**
* @return 0 if succeed, 1 if failed
*/
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int fdin;
int fdout; int fdin,fdout,i=0,fnamelen,fsz,lines = 0;
int fsz;
int i;
int bsz = 4;
int z=0;
unsigned int psize; unsigned int psize;
GWBUF** qbuff; GWBUF** qbuff;
char *qin; char *qin, *outnm, *buffer, *tok;
char *buffer;
char *tok;
bool failed;
if (argc != 3) if(argc != 3){
{
printf("Usage: canonizer <input file> <output file>\n"); printf("Usage: canonizer <input file> <output file>\n");
return 1; return 1;
} }
failed = mysql_library_init(num_elements, server_options, server_groups);
if (failed)
{
bool failed = mysql_library_init(num_elements, server_options, server_groups);
if(failed){
printf("Embedded server init failed.\n"); printf("Embedded server init failed.\n");
return 1; return 1;
} }
fnamelen = strlen(argv[1]) + 16;
fdin = open(argv[1],O_RDONLY); fdin = open(argv[1],O_RDONLY);
fsz = lseek(fdin,0,SEEK_END); fsz = lseek(fdin,0,SEEK_END);
lseek(fdin,0,SEEK_SET); lseek(fdin,0,SEEK_SET);
if (!(buffer = (char *)calloc(1, fsz+1))) if(!(buffer = malloc(sizeof(char)*fsz + 1))){
{
mysql_library_end();
printf("Error: Failed to allocate memory."); printf("Error: Failed to allocate memory.");
return 1; return 1;
} }
read(fdin,buffer,fsz); read(fdin,buffer,fsz);
buffer[fsz] = '\0';
qbuff = (GWBUF **)calloc(bsz, sizeof(GWBUF*));
tok = strtok(buffer,"\n");
i = 0; i = 0;
int bsz = 4,z=0;
qbuff = calloc(bsz,sizeof(GWBUF*));
tok = strtok(buffer,"\n");
while(tok) while(tok){
{
if (i>=bsz) if(i>=bsz){
{ GWBUF** tmp = calloc(bsz*2,sizeof(GWBUF*));
GWBUF** tmp = (GWBUF **)calloc(bsz*2, sizeof(GWBUF*)); if(!tmp){
if (!tmp)
{
printf("Error: Failed to allocate memory."); printf("Error: Failed to allocate memory.");
return 1; return 1;
} }
for (z=0; z<bsz; z++) for(z=0;z<bsz;z++){
{
tmp[z] = qbuff[z]; tmp[z] = qbuff[z];
} }
free(qbuff); free(qbuff);
qbuff = tmp; qbuff = tmp;
bsz *= 2; bsz *= 2;
} }
if (strlen(tok) > 0) if(strlen(tok) > 0){
{
qin = strdup(tok); qin = strdup(tok);
psize = strlen(qin); psize = strlen(qin);
qbuff[i] = gwbuf_alloc(psize + 6); qbuff[i] = gwbuf_alloc(psize + 6);
@ -108,24 +99,23 @@ int main(int argc, char** argv)
i++; i++;
} }
} }
fdout = open(argv[2],O_TRUNC|O_CREAT|O_WRONLY,S_IRWXU|S_IXGRP|S_IXOTH); fdout = open(argv[2],O_TRUNC|O_CREAT|O_WRONLY,S_IRWXU|S_IXGRP|S_IXOTH);
for (i = 0;i<bsz;i++) for(i = 0;i<bsz;i++){
{ if(qbuff[i]){
if (qbuff[i])
{
parse_query(qbuff[i]); parse_query(qbuff[i]);
tok = skygw_get_canonical(qbuff[i]); tok = skygw_get_canonical(qbuff[i]);
write(fdout,tok,strlen(tok)); write(fdout,tok,strlen(tok));
write(fdout,"\n",1); write(fdout,"\n",1);
gwbuf_free(qbuff[i]); gwbuf_free(qbuff[i]);
} }
} }
free(qbuff); free(qbuff);
free(buffer); free(buffer);
close(fdin); close(fdin);
close(fdout); close(fdout);
mysql_library_end();
return 0; return 0;
} }