boost::uint32_t Support::diff_files(const std::string& file1, const std::string& file2, boost::uint32_t ignorable_start, boost::uint32_t ignorable_length) { boost::uint32_t start[] = { ignorable_start }; boost::uint32_t len[] = { ignorable_length }; return diff_files(file1, file2, start, len, 1); }
static void check_dir(const char *dire, const struct test *test) { char filename[4096]; int fd, reffd; if (test->nocommentref) { snprintf(filename, sizeof(filename), "%s/nocomment.html", dire); fd = open(filename, O_RDONLY); fail_unless(fd > 0,"unable to open: %s", filename); reffd = open_testfile(test->nocommentref); diff_files(fd, reffd); close(reffd); close(fd); } if (test->notagsref) { snprintf(filename, sizeof(filename), "%s/notags.html", dire); fd = open(filename, O_RDONLY); fail_unless(fd > 0,"unable to open: %s", filename); reffd = open_testfile(test->notagsref); diff_files(fd, reffd); close(reffd); close(fd); } if (test->jsref) { snprintf(filename, sizeof(filename), "%s/javascript", dire); fd = open(filename, O_RDONLY); fail_unless(fd > 0,"unable to open: %s", filename); reffd = open_testfile(test->jsref); diff_files(fd, reffd); close(reffd); close(fd); } }
int main ( int argc, char **argv ) { int file_times; int c = 0; bool single_file = false; int verbosity = 0; /* ensure we received a file argument */ if ( argc < 3 ) { print_usage( argv, NULL ); goto clean; } while ((c = getopt( argc, argv, "sv" )) != -1) { switch (c) { case 's': single_file = true; break; case 'v': verbosity++; break; default: fprintf( stderr, "Got Filename\n" ); break; } } if ( single_file ) { diff_in_file( argv[argc - 1], verbosity ); } else { diff_files( argv[argc - 1], argv[argc - 2], verbosity ); } clean: return 0; }
bool Support::compare_files(const std::string& file1, const std::string& file2) { const boost::uint32_t numdiffs = diff_files(file1, file2); return (numdiffs == 0); }
boost::uint32_t Support::diff_files(const std::string& file1, const std::string& file2) { return diff_files(file1, file2, NULL, NULL, 0); }
/** * ostree_diff_dirs_with_options: * @flags: Flags * @a: First directory path, or %NULL * @b: First directory path * @modified: (element-type OstreeDiffItem): Modified files * @removed: (element-type Gio.File): Removed files * @added: (element-type Gio.File): Added files * @cancellable: Cancellable * @options: (allow-none): Options * @error: Error * * Compute the difference between directory @a and @b as 3 separate * sets of #OstreeDiffItem in @modified, @removed, and @added. */ gboolean ostree_diff_dirs_with_options (OstreeDiffFlags flags, GFile *a, GFile *b, GPtrArray *modified, GPtrArray *removed, GPtrArray *added, OstreeDiffDirsOptions *options, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; GError *temp_error = NULL; g_autoptr(GFileEnumerator) dir_enum = NULL; g_autoptr(GFile) child_a = NULL; g_autoptr(GFile) child_b = NULL; g_autoptr(GFileInfo) child_a_info = NULL; g_autoptr(GFileInfo) child_b_info = NULL; OstreeDiffDirsOptions default_opts = OSTREE_DIFF_DIRS_OPTIONS_INIT; if (!options) options = &default_opts; /* If we're diffing versus a repo, and either of them have xattrs disabled, * then disable for both. */ OstreeRepo *repo; if (OSTREE_IS_REPO_FILE (a)) repo = ostree_repo_file_get_repo ((OstreeRepoFile*)a); else if (OSTREE_IS_REPO_FILE (b)) repo = ostree_repo_file_get_repo ((OstreeRepoFile*)b); else repo = NULL; if (repo != NULL && repo->disable_xattrs) flags |= OSTREE_DIFF_FLAGS_IGNORE_XATTRS; if (a == NULL) { if (!diff_add_dir_recurse (b, added, cancellable, error)) goto out; ret = TRUE; goto out; } child_a_info = g_file_query_info (a, OSTREE_GIO_FAST_QUERYINFO, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!child_a_info) goto out; child_b_info = g_file_query_info (b, OSTREE_GIO_FAST_QUERYINFO, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!child_b_info) goto out; /* Fast path test for unmodified directories */ if (g_file_info_get_file_type (child_a_info) == G_FILE_TYPE_DIRECTORY && g_file_info_get_file_type (child_b_info) == G_FILE_TYPE_DIRECTORY && OSTREE_IS_REPO_FILE (a) && OSTREE_IS_REPO_FILE (b)) { OstreeRepoFile *a_repof = (OstreeRepoFile*) a; OstreeRepoFile *b_repof = (OstreeRepoFile*) b; if (strcmp (ostree_repo_file_tree_get_contents_checksum (a_repof), ostree_repo_file_tree_get_contents_checksum (b_repof)) == 0) { ret = TRUE; goto out; } } g_clear_object (&child_a_info); g_clear_object (&child_b_info); dir_enum = g_file_enumerate_children (a, OSTREE_GIO_FAST_QUERYINFO, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!dir_enum) goto out; while ((child_a_info = g_file_enumerator_next_file (dir_enum, cancellable, &temp_error)) != NULL) { const char *name; GFileType child_a_type; GFileType child_b_type; name = g_file_info_get_name (child_a_info); g_clear_object (&child_a); child_a = g_file_get_child (a, name); child_a_type = g_file_info_get_file_type (child_a_info); g_clear_object (&child_b); child_b = g_file_get_child (b, name); g_clear_object (&child_b_info); child_b_info = g_file_query_info (child_b, OSTREE_GIO_FAST_QUERYINFO, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, &temp_error); if (!child_b_info) { if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_clear_error (&temp_error); g_ptr_array_add (removed, g_object_ref (child_a)); } else { g_propagate_error (error, temp_error); goto out; } } else { if (options->owner_uid >= 0) g_file_info_set_attribute_uint32 (child_b_info, "unix::uid", options->owner_uid); if (options->owner_gid >= 0) g_file_info_set_attribute_uint32 (child_b_info, "unix::gid", options->owner_gid); child_b_type = g_file_info_get_file_type (child_b_info); if (child_a_type != child_b_type) { OstreeDiffItem *diff_item = diff_item_new (child_a, child_a_info, child_b, child_b_info, NULL, NULL); g_ptr_array_add (modified, diff_item); } else { OstreeDiffItem *diff_item = NULL; if (!diff_files (flags, child_a, child_a_info, child_b, child_b_info, &diff_item, cancellable, error)) goto out; if (diff_item) g_ptr_array_add (modified, diff_item); /* Transfer ownership */ if (child_a_type == G_FILE_TYPE_DIRECTORY) { if (!ostree_diff_dirs_with_options (flags, child_a, child_b, modified, removed, added, options, cancellable, error)) goto out; } } } g_clear_object (&child_a_info); } if (temp_error != NULL) { g_propagate_error (error, temp_error); goto out; } g_clear_object (&dir_enum); dir_enum = g_file_enumerate_children (b, OSTREE_GIO_FAST_QUERYINFO, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!dir_enum) goto out; g_clear_object (&child_b_info); while ((child_b_info = g_file_enumerator_next_file (dir_enum, cancellable, &temp_error)) != NULL) { const char *name; name = g_file_info_get_name (child_b_info); g_clear_object (&child_a); child_a = g_file_get_child (a, name); g_clear_object (&child_b); child_b = g_file_get_child (b, name); g_clear_object (&child_a_info); child_a_info = g_file_query_info (child_a, OSTREE_GIO_FAST_QUERYINFO, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, &temp_error); if (!child_a_info) { if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_clear_error (&temp_error); g_ptr_array_add (added, g_object_ref (child_b)); if (g_file_info_get_file_type (child_b_info) == G_FILE_TYPE_DIRECTORY) { if (!diff_add_dir_recurse (child_b, added, cancellable, error)) goto out; } } else { g_propagate_error (error, temp_error); goto out; } } g_clear_object (&child_b_info); } if (temp_error != NULL) { g_propagate_error (error, temp_error); goto out; } ret = TRUE; out: return ret; }
int main(int argc, char *argv[ ]) { FILE *modelIn, *dataIn, *out; init_data(example, sv, lambda, svNonZeroFeature, nonZeroFeature, target, weight, output, zeroFeatureExample, rbfConstant, degree , b, numSv, numExample, kernelType, maxFeature); char* mfile = "C:\\Users\\Owner\\Desktop\\SVM\\SMO\\smosynth\\smosynth\\linear_results\\model.dat"; if(( modelIn = fopen( mfile, "r" ) ) == ((void *)0) ) { fprintf( (&_iob[2]), "Can't open %s\n", mfile); exit(2); } char* tfile = "C:\\Users\\Owner\\Desktop\\SVM\\SMO\\smosynth\\smosynth\\linear_results\\test.dat"; if(( dataIn = fopen( tfile, "r" ) ) == ((void *)0) ) { fprintf( (&_iob[2]), "Can't open %s\n", tfile ); exit(2); } char* pfile = "C:\\Users\\Owner\\Desktop\\SVM\\SMO\\smosynth\\smosynth\\linear_results\\pred.dat"; if(( out = fopen( pfile, "w" ) ) == ((void *)0) ) { fprintf( (&_iob[2]), "Can't open %s\n", pfile ); exit(2); } if( ! readModel( modelIn, example, sv, lambda, svNonZeroFeature, nonZeroFeature, target, weight, output, zeroFeatureExample, rbfConstant, degree , b, numSv, numExample, kernelType, maxFeature ) ) { fprintf( (&_iob[2]), "Error in reading model file %s\n", mfile ); exit (3); } else fclose( modelIn ); printf("Finish reading model file\n"); if( !readData( dataIn, example, sv, lambda, svNonZeroFeature, nonZeroFeature, target, weight, output, zeroFeatureExample, rbfConstant, degree , b, numSv, numExample, kernelType, maxFeature )) { printf("Error reading data file\n"); exit(4); } fclose( dataIn ); printf("Finish reading test data file\n"); int ret=synth_top(example, sv, lambda, svNonZeroFeature, nonZeroFeature, weight, output, 0); if ( ret==0 ) printf("Classification is completed\n"); else fprintf( (&_iob[2]), "Classification process failed\n"); write_result(out, output, b); fclose( out ); ret = diff_files(); printf("RETURN VALUE %d\n", ret); if (ret != 0) { printf("Test failed %d!!!\n", ret); return 1; } else { printf("Test passed %d!\n", ret); return 0; } }