예제 #1
0
int oc_out_class(OUT_RESULT_FUNCS *funcs, const char* class_name) {
    head_capital((char*)class_name);
    out_data *out_data = funcs->data;
    size_t size = sizeof(char)*(strlen(out_data->path)+strlen(class_name)+strlen(".h")+3+1);
    char *fn = (char*)malloc(size);
    
    sprintf(fn, "%s/%s%s", out_data->path, class_name, ".h");
    FILE *f_h = open_file(fn, "w+");
    if(f_h) {
        FILE *head_info = open_file("objective-c_head.txt", "r");
        if(head_info) {
            merge_file(f_h, head_info);
            fclose(head_info);
        }
        fprintf(f_h, "\n%s\n", "#import <Foundation/Foundation.h>");
        out_data->file = f_h;
    } else {
        free(fn);
        return 0;
    }
    
    fn[size-4] = 'm';
    FILE *f_m = open_file(fn, "w+");
    if(f_m) {
        FILE *head_info = open_file("objective-c_head.txt", "r");
        if(head_info) {
            merge_file(f_m, head_info);
            fclose(head_info);
        }
        fprintf(f_m, "\n#import \"%s.h\"\n", class_name);
        fprintf(f_m, "\n@implementation %s\n", class_name);
        fprintf(f_m, "\n@end");
        fflush(f_m);
        fclose(f_m);
    } else {
        free(fn);
        return 0;
    }
    
    strcpy(fn+size-4, "tmp");
    FILE *f_tmp = open_file(fn, "w+");
    if(f_tmp) {
        fprintf(f_tmp, "\n\n@interface %s : NSObject\n\n", class_name);
        out_data->tmp_file = f_tmp;
        out_data->tmp_path = fn;
        return 1;
    } else {
        free(fn);
        return 0;
    }
}
예제 #2
0
파일: romsplit.c 프로젝트: ullman/romsplit
int main(int argc, char**argv){

    if(argc!=5)
    {
        print_man();
    }
    else
    {
        if(!strcmp(argv[1],"-s"))
        {
        printf("Splitting rom...\n");
        split_files(argv[2],argv[3],argv[4]);
        }
        else if(!strcmp(argv[1],"-m"))
        {
        printf("Merging rom...\n");
        merge_file(argv[2],argv[3],argv[4]);

        }
        else
        {
            print_man();
        }
    }

    return 0;
}
예제 #3
0
void oc_to_next_class(OUT_RESULT_FUNCS *funcs) {
    out_data *out_data = funcs->data;
    fprintf(out_data->tmp_file, "\n@end");
    
    fflush(out_data->tmp_file);
    fflush(out_data->file);
    
    merge_file(out_data->file, out_data->tmp_file);
    
    fclose(out_data->tmp_file);
    fclose(out_data->file);
    
    remove(out_data->tmp_path);
    free(out_data->tmp_path);
}
예제 #4
0
파일: merge-index.c 프로젝트: DJHartley/git
int main(int argc, char **argv)
{
	int i, force_file = 0;

	/* Without this we cannot rely on waitpid() to tell
	 * what happened to our children.
	 */
	signal(SIGCHLD, SIG_DFL);

	if (argc < 3)
		usage("git merge-index [-o] [-q] <merge-program> (-a | [--] <filename>*)");

	git_extract_argv0_path(argv[0]);

	setup_git_directory();
	read_cache();

	i = 1;
	if (!strcmp(argv[i], "-o")) {
		one_shot = 1;
		i++;
	}
	if (!strcmp(argv[i], "-q")) {
		quiet = 1;
		i++;
	}
	pgm = argv[i++];
	for (; i < argc; i++) {
		char *arg = argv[i];
		if (!force_file && *arg == '-') {
			if (!strcmp(arg, "--")) {
				force_file = 1;
				continue;
			}
			if (!strcmp(arg, "-a")) {
				merge_all();
				continue;
			}
			die("git merge-index: unknown option %s", arg);
		}
		merge_file(arg);
	}
	if (err && !quiet)
		die("merge program failed");
	return err;
}
예제 #5
0
static void *result(struct merge_list *entry, unsigned long *size)
{
	enum object_type type;
	struct blob *base, *our, *their;

	if (!entry->stage)
		return read_sha1_file(entry->blob->object.sha1, &type, size);
	base = NULL;
	if (entry->stage == 1) {
		base = entry->blob;
		entry = entry->link;
	}
	our = NULL;
	if (entry && entry->stage == 2) {
		our = entry->blob;
		entry = entry->link;
	}
	their = NULL;
	if (entry)
		their = entry->blob;
	return merge_file(base, our, their, size);
}
예제 #6
0
파일: merge-recursive.c 프로젝트: emk/git
static int process_renames(struct merge_options *o,
			   struct string_list *a_renames,
			   struct string_list *b_renames)
{
	int clean_merge = 1, i, j;
	struct string_list a_by_dst = {NULL, 0, 0, 0}, b_by_dst = {NULL, 0, 0, 0};
	const struct rename *sre;

	for (i = 0; i < a_renames->nr; i++) {
		sre = a_renames->items[i].util;
		string_list_insert(sre->pair->two->path, &a_by_dst)->util
			= sre->dst_entry;
	}
	for (i = 0; i < b_renames->nr; i++) {
		sre = b_renames->items[i].util;
		string_list_insert(sre->pair->two->path, &b_by_dst)->util
			= sre->dst_entry;
	}

	for (i = 0, j = 0; i < a_renames->nr || j < b_renames->nr;) {
		int compare;
		char *src;
		struct string_list *renames1, *renames2, *renames2Dst;
		struct rename *ren1 = NULL, *ren2 = NULL;
		const char *branch1, *branch2;
		const char *ren1_src, *ren1_dst;

		if (i >= a_renames->nr) {
			compare = 1;
			ren2 = b_renames->items[j++].util;
		} else if (j >= b_renames->nr) {
			compare = -1;
			ren1 = a_renames->items[i++].util;
		} else {
			compare = strcmp(a_renames->items[i].string,
					b_renames->items[j].string);
			if (compare <= 0)
				ren1 = a_renames->items[i++].util;
			if (compare >= 0)
				ren2 = b_renames->items[j++].util;
		}

		/* TODO: refactor, so that 1/2 are not needed */
		if (ren1) {
			renames1 = a_renames;
			renames2 = b_renames;
			renames2Dst = &b_by_dst;
			branch1 = o->branch1;
			branch2 = o->branch2;
		} else {
			struct rename *tmp;
			renames1 = b_renames;
			renames2 = a_renames;
			renames2Dst = &a_by_dst;
			branch1 = o->branch2;
			branch2 = o->branch1;
			tmp = ren2;
			ren2 = ren1;
			ren1 = tmp;
		}
		src = ren1->pair->one->path;

		ren1->dst_entry->processed = 1;
		ren1->src_entry->processed = 1;

		if (ren1->processed)
			continue;
		ren1->processed = 1;

		ren1_src = ren1->pair->one->path;
		ren1_dst = ren1->pair->two->path;

		if (ren2) {
			const char *ren2_src = ren2->pair->one->path;
			const char *ren2_dst = ren2->pair->two->path;
			/* Renamed in 1 and renamed in 2 */
			if (strcmp(ren1_src, ren2_src) != 0)
				die("ren1.src != ren2.src");
			ren2->dst_entry->processed = 1;
			ren2->processed = 1;
			if (strcmp(ren1_dst, ren2_dst) != 0) {
				clean_merge = 0;
				output(o, 1, "CONFLICT (rename/rename): "
				       "Rename \"%s\"->\"%s\" in branch \"%s\" "
				       "rename \"%s\"->\"%s\" in \"%s\"%s",
				       src, ren1_dst, branch1,
				       src, ren2_dst, branch2,
				       o->call_depth ? " (left unresolved)": "");
				if (o->call_depth) {
					remove_file_from_cache(src);
					update_file(o, 0, ren1->pair->one->sha1,
						    ren1->pair->one->mode, src);
				}
				conflict_rename_rename(o, ren1, branch1, ren2, branch2);
			} else {
				struct merge_file_info mfi;
				remove_file(o, 1, ren1_src, 1);
				mfi = merge_file(o,
						 ren1->pair->one,
						 ren1->pair->two,
						 ren2->pair->two,
						 branch1,
						 branch2);
				if (mfi.merge || !mfi.clean)
					output(o, 1, "Renaming %s->%s", src, ren1_dst);

				if (mfi.merge)
					output(o, 2, "Auto-merging %s", ren1_dst);

				if (!mfi.clean) {
					output(o, 1, "CONFLICT (content): merge conflict in %s",
					       ren1_dst);
					clean_merge = 0;

					if (!o->call_depth)
						update_stages(ren1_dst,
							      ren1->pair->one,
							      ren1->pair->two,
							      ren2->pair->two,
							      1 /* clear */);
				}
				update_file(o, mfi.clean, mfi.sha, mfi.mode, ren1_dst);
			}
		} else {
			/* Renamed in 1, maybe changed in 2 */
			struct string_list_item *item;
			/* we only use sha1 and mode of these */
			struct diff_filespec src_other, dst_other;
			int try_merge, stage = a_renames == renames1 ? 3: 2;

			remove_file(o, 1, ren1_src, o->call_depth || stage == 3);

			hashcpy(src_other.sha1, ren1->src_entry->stages[stage].sha);
			src_other.mode = ren1->src_entry->stages[stage].mode;
			hashcpy(dst_other.sha1, ren1->dst_entry->stages[stage].sha);
			dst_other.mode = ren1->dst_entry->stages[stage].mode;

			try_merge = 0;

			if (string_list_has_string(&o->current_directory_set, ren1_dst)) {
				clean_merge = 0;
				output(o, 1, "CONFLICT (rename/directory): Rename %s->%s in %s "
				       " directory %s added in %s",
				       ren1_src, ren1_dst, branch1,
				       ren1_dst, branch2);
				conflict_rename_dir(o, ren1, branch1);
			} else if (sha_eq(src_other.sha1, null_sha1)) {
				clean_merge = 0;
				output(o, 1, "CONFLICT (rename/delete): Rename %s->%s in %s "
				       "and deleted in %s",
				       ren1_src, ren1_dst, branch1,
				       branch2);
				update_file(o, 0, ren1->pair->two->sha1, ren1->pair->two->mode, ren1_dst);
				update_stages(ren1_dst, NULL,
						branch1 == o->branch1 ?
						ren1->pair->two : NULL,
						branch1 == o->branch1 ?
						NULL : ren1->pair->two, 1);
			} else if (!sha_eq(dst_other.sha1, null_sha1)) {
				const char *new_path;
				clean_merge = 0;
				try_merge = 1;
				output(o, 1, "CONFLICT (rename/add): Rename %s->%s in %s. "
				       "%s added in %s",
				       ren1_src, ren1_dst, branch1,
				       ren1_dst, branch2);
				new_path = unique_path(o, ren1_dst, branch2);
				output(o, 1, "Adding as %s instead", new_path);
				update_file(o, 0, dst_other.sha1, dst_other.mode, new_path);
			} else if ((item = string_list_lookup(ren1_dst, renames2Dst))) {
				ren2 = item->util;
				clean_merge = 0;
				ren2->processed = 1;
				output(o, 1, "CONFLICT (rename/rename): "
				       "Rename %s->%s in %s. "
				       "Rename %s->%s in %s",
				       ren1_src, ren1_dst, branch1,
				       ren2->pair->one->path, ren2->pair->two->path, branch2);
				conflict_rename_rename_2(o, ren1, branch1, ren2, branch2);
			} else
				try_merge = 1;

			if (try_merge) {
				struct diff_filespec *one, *a, *b;
				struct merge_file_info mfi;
				src_other.path = (char *)ren1_src;

				one = ren1->pair->one;
				if (a_renames == renames1) {
					a = ren1->pair->two;
					b = &src_other;
				} else {
					b = ren1->pair->two;
					a = &src_other;
				}
				mfi = merge_file(o, one, a, b,
						o->branch1, o->branch2);

				if (mfi.clean &&
				    sha_eq(mfi.sha, ren1->pair->two->sha1) &&
				    mfi.mode == ren1->pair->two->mode)
					/*
					 * This messaged is part of
					 * t6022 test. If you change
					 * it update the test too.
					 */
					output(o, 3, "Skipped %s (merged same as existing)", ren1_dst);
				else {
					if (mfi.merge || !mfi.clean)
						output(o, 1, "Renaming %s => %s", ren1_src, ren1_dst);
					if (mfi.merge)
						output(o, 2, "Auto-merging %s", ren1_dst);
					if (!mfi.clean) {
						output(o, 1, "CONFLICT (rename/modify): Merge conflict in %s",
						       ren1_dst);
						clean_merge = 0;

						if (!o->call_depth)
							update_stages(ren1_dst,
								      one, a, b, 1);
					}
					update_file(o, mfi.clean, mfi.sha, mfi.mode, ren1_dst);
				}
			}
		}
	}
	string_list_clear(&a_by_dst, 0);
	string_list_clear(&b_by_dst, 0);

	return clean_merge;
}
예제 #7
0
파일: merge-recursive.c 프로젝트: emk/git
/* Per entry merge function */
static int process_entry(struct merge_options *o,
			 const char *path, struct stage_data *entry)
{
	/*
	printf("processing entry, clean cache: %s\n", index_only ? "yes": "no");
	print_index_entry("\tpath: ", entry);
	*/
	int clean_merge = 1;
	unsigned o_mode = entry->stages[1].mode;
	unsigned a_mode = entry->stages[2].mode;
	unsigned b_mode = entry->stages[3].mode;
	unsigned char *o_sha = stage_sha(entry->stages[1].sha, o_mode);
	unsigned char *a_sha = stage_sha(entry->stages[2].sha, a_mode);
	unsigned char *b_sha = stage_sha(entry->stages[3].sha, b_mode);

	if (o_sha && (!a_sha || !b_sha)) {
		/* Case A: Deleted in one */
		if ((!a_sha && !b_sha) ||
		    (sha_eq(a_sha, o_sha) && !b_sha) ||
		    (!a_sha && sha_eq(b_sha, o_sha))) {
			/* Deleted in both or deleted in one and
			 * unchanged in the other */
			if (a_sha)
				output(o, 2, "Removing %s", path);
			/* do not touch working file if it did not exist */
			remove_file(o, 1, path, !a_sha);
		} else {
			/* Deleted in one and changed in the other */
			clean_merge = 0;
			if (!a_sha) {
				output(o, 1, "CONFLICT (delete/modify): %s deleted in %s "
				       "and modified in %s. Version %s of %s left in tree.",
				       path, o->branch1,
				       o->branch2, o->branch2, path);
				update_file(o, 0, b_sha, b_mode, path);
			} else {
				output(o, 1, "CONFLICT (delete/modify): %s deleted in %s "
				       "and modified in %s. Version %s of %s left in tree.",
				       path, o->branch2,
				       o->branch1, o->branch1, path);
				update_file(o, 0, a_sha, a_mode, path);
			}
		}

	} else if ((!o_sha && a_sha && !b_sha) ||
		   (!o_sha && !a_sha && b_sha)) {
		/* Case B: Added in one. */
		const char *add_branch;
		const char *other_branch;
		unsigned mode;
		const unsigned char *sha;
		const char *conf;

		if (a_sha) {
			add_branch = o->branch1;
			other_branch = o->branch2;
			mode = a_mode;
			sha = a_sha;
			conf = "file/directory";
		} else {
			add_branch = o->branch2;
			other_branch = o->branch1;
			mode = b_mode;
			sha = b_sha;
			conf = "directory/file";
		}
		if (string_list_has_string(&o->current_directory_set, path)) {
			const char *new_path = unique_path(o, path, add_branch);
			clean_merge = 0;
			output(o, 1, "CONFLICT (%s): There is a directory with name %s in %s. "
			       "Adding %s as %s",
			       conf, path, other_branch, path, new_path);
			remove_file(o, 0, path, 0);
			update_file(o, 0, sha, mode, new_path);
		} else {
			output(o, 2, "Adding %s", path);
			update_file(o, 1, sha, mode, path);
		}
	} else if (a_sha && b_sha) {
		/* Case C: Added in both (check for same permissions) and */
		/* case D: Modified in both, but differently. */
		const char *reason = "content";
		struct merge_file_info mfi;
		struct diff_filespec one, a, b;

		if (!o_sha) {
			reason = "add/add";
			o_sha = (unsigned char *)null_sha1;
		}
		output(o, 2, "Auto-merging %s", path);
		one.path = a.path = b.path = (char *)path;
		hashcpy(one.sha1, o_sha);
		one.mode = o_mode;
		hashcpy(a.sha1, a_sha);
		a.mode = a_mode;
		hashcpy(b.sha1, b_sha);
		b.mode = b_mode;

		mfi = merge_file(o, &one, &a, &b,
				 o->branch1, o->branch2);

		clean_merge = mfi.clean;
		if (mfi.clean)
			update_file(o, 1, mfi.sha, mfi.mode, path);
		else if (S_ISGITLINK(mfi.mode))
			output(o, 1, "CONFLICT (submodule): Merge conflict in %s "
			       "- needs %s", path, sha1_to_hex(b.sha1));
		else {
			output(o, 1, "CONFLICT (%s): Merge conflict in %s",
					reason, path);

			if (o->call_depth)
				update_file(o, 0, mfi.sha, mfi.mode, path);
			else
				update_file_flags(o, mfi.sha, mfi.mode, path,
					      0 /* update_cache */, 1 /* update_working_directory */);
		}
	} else if (!o_sha && !a_sha && !b_sha) {
		/*
		 * this entry was deleted altogether. a_mode == 0 means
		 * we had that path and want to actively remove it.
		 */
		remove_file(o, 1, path, !a_mode);
	} else
		die("Fatal merge failure, shouldn't happen.");

	return clean_merge;
}
예제 #8
0
WordsEdit::WordsEdit( QWidget *parent, const char *name, int win_num, ResourcesWin *res )
    : QWidget( parent, name ,Qt::WDestructiveClose )
{
  
  setCaption("WORDS.TOK Editor");
  wordlist = new WordList();

  winnum = win_num;
  resources_win = res;
  wordsfind = NULL;
  
  Q3PopupMenu *file = new Q3PopupMenu( this );
  Q_CHECK_PTR( file );

  file->insertItem( "New", this, SLOT(new_file()) );
  file->insertItem( "Open", this, SLOT(open_file()) );
  file->insertItem( "Merge", this, SLOT(merge_file()) );
  file->insertItem( "Save", this, SLOT(save_file()) );
  file->insertItem( "Save As", this, SLOT(save_as_file()) );
  file->insertSeparator();
  file->insertItem( "Close", this, SLOT(close()) );

  Q3PopupMenu *words = new Q3PopupMenu( this );
  Q_CHECK_PTR( words );

  words->insertItem( "Add word group", this, SLOT(add_group_cb()) );
  words->insertItem( "Delete word group", this, SLOT(delete_group_cb()) );
  words->insertItem( "Change group number", this, SLOT(change_group_number_cb()) );
  words->insertSeparator();
  words->insertItem( "Add word", this, SLOT(add_word_cb()) );
  words->insertItem( "Delete word", this, SLOT(delete_word_cb()) );
  words->insertSeparator();
  words->insertItem( "Count word groups", this, SLOT(count_groups_cb()) );
  words->insertItem( "Count words", this, SLOT(count_words_cb()) );
  words->insertItem( "&Find...", this, SLOT(find_cb()) , Qt::CTRL+Qt::Key_F);


  QMenuBar *menu = new QMenuBar(this);  
  Q_CHECK_PTR( menu );
  menu->insertItem( "File", file );
  menu->insertItem( "Words", words );
  menu->setSeparator( QMenuBar::InWindowsStyle );

  Q3BoxLayout *all =  new Q3VBoxLayout(this,10);

  QSplitter *split = new QSplitter(Qt::Horizontal,this);


  QWidget *left = new QWidget(split);
  Q3BoxLayout *lgroup = new Q3VBoxLayout(left,4);   
  QLabel *labelgroup = new QLabel("Word groups",left,"Word groups");
  labelgroup->setAlignment(Qt::AlignCenter);  
  lgroup->addWidget(labelgroup);
  
  listgroup = new Q3ListBox(left);
  listgroup->setColumnMode (1);
  listgroup->setMinimumSize(200,300);
  connect( listgroup, SIGNAL(highlighted(int)), SLOT(select_group(int)) );
  connect( listgroup, SIGNAL(selected(int)), SLOT(select_group(int)) );

  lgroup->addWidget(listgroup);


  QWidget *right = new QWidget(split);
  Q3BoxLayout *lwords =  new Q3VBoxLayout(right,4);
  labelword = new QLabel("Word group",right,"Word group");
  labelword->setAlignment(Qt::AlignCenter);
  lwords->addWidget(labelword);

  listwords = new Q3ListBox(right);
  listwords->setColumnMode (1);
  listwords->setMinimumSize(200,300);
  connect( listwords, SIGNAL(highlighted(int)), SLOT(select_word(int)) );
  connect( listwords, SIGNAL(selected(int)), SLOT(select_word(int)) );
  lwords->addWidget(listwords);
  
  lineword = new QLineEdit(right);
  lineword->setEnabled(false);
  connect( lineword, SIGNAL(returnPressed()), SLOT(do_add_word()) );
  lwords->addWidget(lineword);  
  

  all->addWidget(split);  

  Q3BoxLayout *buttons =  new Q3HBoxLayout(all,20);

  add_group = new QPushButton("Add group",this);
  connect( add_group, SIGNAL(clicked()), SLOT(add_group_cb()) );
  buttons->addWidget(add_group);

  delete_group = new QPushButton("Delete group",this);
  connect( delete_group, SIGNAL(clicked()), SLOT(delete_group_cb()) );
  buttons->addWidget(delete_group);

  add_word = new QPushButton("Add word",this);
  connect( add_word, SIGNAL(clicked()), SLOT(add_word_cb()) );
  buttons->addWidget(add_word);

  delete_word = new QPushButton("Delete word",this);
  connect( delete_word, SIGNAL(clicked()), SLOT(delete_word_cb()) );
  buttons->addWidget(delete_word);

  Q3BoxLayout *buttons1 =  new Q3HBoxLayout(all,20);

  change_group_number = new QPushButton("&Change group number",this);
  connect( change_group_number, SIGNAL(clicked()), SLOT(change_group_number_cb()) );
  buttons1->addWidget(change_group_number);

  find = new QPushButton("Find",this);
  connect( find, SIGNAL(clicked()), SLOT(find_cb()) );
  buttons1->addWidget(find);
  

  adjustSize();

  changed=false;
  filename="";
  SelectedGroup=0;
  FindLastGroup = FindLastWord = -1;
}
예제 #9
0
int main(void)
{
    unsigned long bs;
    int i, status;
    FILE *fp[5] = {NULL, NULL, NULL, NULL, NULL};
    char *filename[] = {"test_raid5.dat",
                        "test_raid5.dev0.dat",
                        "test_raid5.dev1.dat",
                        "test_raid5.dev2.dat",
                        "test_raid5.out.dat",
                        "test_raid5.meta.dat",
                        "test_raid5.move.dat"
                       };

#if CHECKING == 1
    unsigned char *ascii = NULL;
    char *assumed[] = {"3b6f5cf4c8c3e8b6c6894da81c1fcea588db14d088c5970c1b98faed940b2ce4",
                       "",
                       "7d325d944a81a11c86b904ddd113d418bb1de188db55a14654cc489cb761f011",
                       "ea9a1b730b11572714cedc1cdf3d3dd31b37283b608587661edf6e781c05f5fe",
                       "3b6f5cf4c8c3e8b6c6894da81c1fcea588db14d088c5970c1b98faed940b2ce4",
                       "27a24e8b433337896e1559fd0359cc4e2df9c9c2a085668f0f336c1553d5ab7c",
                       "f7e1a1681fef523d4091b91d5d27ac56015698548ffc32a29ca521ba1926ea20"
                      };
#endif

#if BENCHMARK == 1
    struct timeval start, end;
    float elapsed_split, elapsed_merge;
#else
    printf("Running test for RAID5:\n\n");
#endif
    /* BENCHSIZE must be between 1 byte and MAXSIZE */
    if(BENCHSIZE < 0 || BENCHSIZE > MAXSIZE) {
        fprintf(stderr, "Aborting. BENCHSIZE out of range.\n");
        return 1;
    }

    /** Create test file **/
    fp[0] = fopen(filename[0], "wb");
    if(!fp[0]) {
        fprintf(stderr, "Cannot write test file!\n");
        return 1;
    }
    for(bs = 0; bs < BENCHSIZE; bs++) {
        /* Every device becomes the parity twice. dev2 three
           times but the third time only 512+256 Bytes
           (3/4 BLOCKSIZE).
           2 * BLOCKSIZE * 6 + 3/4 BLOCKSIZE = 13056 */
        fprintf(fp[0], "%c", (unsigned char)((bs * bs + bs) % 256));
    }
    fclose(fp[0]);

    /** Open test file for split **/
    fp[0] = fopen(filename[0], "rb");
    if(!fp[0]) {
        fprintf(stderr, "Cannot read test file!\n");
        return 1;
    }

    /** Create device and metadata files **/
    for(i = 1; i <= 3; i++) {
        fp[i] = fopen(filename[i], "wb");
        if(!fp[i]) {
            fprintf(stderr, "Cannot create device file %d!\n", i - 1);
            return 1;
        }
    }

    fp[4] = fopen(filename[5], "wb");
    if(!fp[4]) {
        fprintf(stderr, "Cannot create metadata file!\n");
        return 1;
    }

    /** perform the split **/
#if BENCHMARK == 1
    gettimeofday(&start, NULL);
    split_file(fp[0], &fp[1], fp[4], (char *) "password", 8);
    gettimeofday(&end, NULL);
    elapsed_split = ((end.tv_sec - start.tv_sec) * 1000000.0f + end.tv_usec - start.tv_usec) / 1000.0f;
#else
    printf("Start split ... ");
    fflush(stdout);
    status = split_file(fp[0], &fp[1], fp[4], (unsigned char *) "password", 8);
    if((status & SUCCESS_SPLIT) == 0) {
        fprintf(stderr, "Return code of split does not include the success flag(%d). Got %d.\n", SUCCESS_SPLIT, status);
    }
    printf("Done\n");
    fflush(stdout);
#endif

    /** Close the input file **/
    fclose(fp[0]);

    /** Close and reopen device and metadata files for merge **/
    for(i = 1; i <= 3; i++) {
        fclose(fp[i]);
        if(i == FILEID) {
            rename(filename[FILEID], filename[6]);
            fprintf(stderr, "renamed %s to %s\n", filename[FILEID], filename[6]);
        }
        fp[i] = fopen(filename[i], "rb");
#if BENCHMARK != 1
        if(!fp[i]) {
            fprintf(stderr, "Cannot open device file %d!", i - 1);
            if(i == FILEID) {
                fprintf(stderr, " [OK]\n");
            } else {
                fprintf(stderr, "\n");
            }
        }
#endif
    }

    fclose(fp[4]);
    fp[4] = fopen(filename[5], "rb");
    if(!fp[4]) {
        fprintf(stderr, "Cannot open metadata file!\n");
        return 1;
    }

    /** Open output file for merge **/
    fp[0] = fopen(filename[4], "wb");
    if(!fp[0]) {
        fprintf(stderr, "Cannot write output file!\n");
        return 1;
    }

    /** perform the merge **/
#if BENCHMARK == 1
    gettimeofday(&start, NULL);
    merge_file(fp[0], &fp[1], fp[4], (char *) "password", 8);
    gettimeofday(&end, NULL);
    elapsed_merge = ((end.tv_sec - start.tv_sec) * 1000000.0f + end.tv_usec - start.tv_usec) / 1000.0f;
#else
    printf("Start merge ... ");
    fflush(stdout);
    status = merge_file(fp[0], &fp[1], fp[4], (unsigned char *) "password", 8);
    if((status & SUCCESS_MERGE) == 0) {
        fprintf(stderr, "Return code of merge does not include the success flag(%d). Got %d.\n", SUCCESS_MERGE, status);
    }
    printf("Done\n");
    fflush(stdout);
#endif

    /** Close ALL files **/
    for(i = 0; i <= 4; i++) {
        if(fp[i]) {
            fclose(fp[i]);
        }
    }

    status = 0;
    for(i = 0; i <= 6; i++) {
        if(i == 1) {
            continue;
        }
#if CHECKING == 1
        printf("Checking file %s ... ", filename[i]);
        ascii = check_sha256_sum(filename[i], (unsigned char *) assumed[i]);

        if(ascii == NULL) {
            printf("CORRECT!\n");
        } else {
            if(memcmp(ascii, assumed[i], 64) == 0) {
                fprintf(stdout, "Memory Error!\n");
            } else {
                fprintf(stdout, "FALSE!\n");
                printf("%-12s%s\n%-12s%s\n", "Calculated:" , ascii, "Assumed:", assumed[i]);
                free(ascii);
            }
            status++;
        }
#endif
        /*remove ( filename[i] );*/
    }
#if BENCHMARK == 1
    printf("\"split\";\"%.3f\";\"merge\";\"%.3f\";\"bytes\";\"%d\"\n", elapsed_split, elapsed_merge , BENCHSIZE);
#endif
    return status;
}