From edb2431cf91a1e3ee6a9f5e9022028b8a8c08fcd Mon Sep 17 00:00:00 2001 From: Diptanshu8 Date: Wed, 28 Jun 2017 19:07:44 +0000 Subject: [PATCH] Cyclic rotation patch --- src/ccextractor.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/ccextractor.c b/src/ccextractor.c index 57006cdd..ebae1da9 100644 --- a/src/ccextractor.c +++ b/src/ccextractor.c @@ -433,28 +433,25 @@ void checking_configuration_file(struct ccx_s_options api_options){ } int compile_params(struct ccx_s_options *api_options,int argc){ - + printf("Inside compile params\n"); + char** temp = malloc(api_options->argument_count*sizeof(char *)); + int i=0; + while(iargument_count){ + temp[i]=malloc(strlen(api_options->myarguments[i])); + strcpy(temp[i],api_options->myarguments[i]); + i++; + } api_options->myarguments = realloc(api_options->myarguments, (api_options->argument_count+1) * sizeof *api_options->myarguments); - api_options->myarguments[api_options->argument_count] = malloc(strlen("./ccextractor")+1); - strcpy(api_options->myarguments[api_options->argument_count], "./ccextractor"); + api_options->myarguments[0] = realloc(api_options->myarguments[0],strlen("./ccextractor")+1); + strcpy(api_options->myarguments[0], "./ccextractor"); api_options->argument_count++; - // int i=0; - //while(iargument_count){ - // mprint("argument[%d] = %s",i++,api_options->myarguments[i]); - //} - // mprint("argument_count = %d\n",api_options->argument_count); - //Cyclic rotation for bringing the ./ccextractor param to the start of the arguments array - int i = 0; - char* temp = NULL; - temp = realloc(temp,strlen(api_options->myarguments[0])+1); - strcpy(temp,api_options->myarguments[0]); - //mprint("Temp = %s \t argument[0] = %s \t argument[count-1] = %s\n",temp,api_options->myarguments[0],api_options->myarguments[api_options->argument_count-1]); - api_options->myarguments[0] = realloc(api_options->myarguments[0],strlen(api_options->myarguments[api_options->argument_count-1])+1); - strcpy(api_options->myarguments[0],api_options->myarguments[api_options->argument_count-1]); - //mprint("Temp = %s \t argument[0] = %s \t argument[count-1] = %s\n",temp,api_options->myarguments[0],api_options->myarguments[api_options->argument_count-1]); - api_options->myarguments[api_options->argument_count-1] = realloc(api_options->myarguments[api_options->argument_count-1],strlen(temp)+1); - strcpy(api_options->myarguments[api_options->argument_count-1],temp); - //mprint("Temp = %s \t argument[0] = %s \t argument[count-1] = %s\n",temp,api_options->myarguments[0],api_options->myarguments[api_options->argument_count-1]); + i=1; + while(iargument_count){ + api_options->myarguments[i] = realloc(api_options->myarguments[i],strlen(temp[i-1])); + strcpy(api_options->myarguments[i],temp[i-1]); + i++; + } + free(temp); int ret = parse_parameters (api_options, api_options->argument_count, api_options->myarguments); if (ret == EXIT_NO_INPUT_FILES) { @@ -470,7 +467,7 @@ int compile_params(struct ccx_s_options *api_options,int argc){ exit(ret); } return EXIT_OK; -} + } void api_add_param(struct ccx_s_options* api_options,char* arg){ api_options->myarguments = realloc(api_options->myarguments, (api_options->argument_count+1) * sizeof *api_options->myarguments);