int execute_modifier(int mod) { int success = 1; switch(mod) { case F_EXIT: success = f_exit(); break; case F_COPY: success = f_copy(); break; case F_CUT: success = f_cut(); break; case F_PASTE: success = f_paste(); break; case F_FIND: success = f_find(); break; case F_GOTO: success = f_goto(); break; case F_HELP: success = f_help(); break; case F_MORE: success = f_more(); break; case F_NEW: success = f_new(); break; case F_OPEN: success = f_open(); break; case F_NEXTPAGE: success = f_nextpage(); break; case F_PREVPAGE: success = f_prevpage(); break; case F_RUN: success = f_run(); break; case F_SAVE: success = f_save(); break; case F_SAVEAS: success = f_saveas(); break; case F_UNDO: success = f_undo(); break; default: success = 0; /* Don't want the program to close for any other key */ break; } return success; }
// lifts a map from f:F -> Y over the map map: X -> Y. We only need relations // for Y. // Remark 1: does NOT catch if such a lift doesn't exist! // Remark 2: If the map X -> Y is injective, then for a map A -> Y the lift F_A // -> X of the map // F_A -> Y induces a well-defined map A -> X. // In general, the problem whether there IS such a lift, and how to // compute it, // will involve additional work. MatrixQ lift_from_free(const mod_t p, const MatrixQ& f, const MatrixQ& map, const AbelianGroup& Y) { MatrixQ rel_y_map(map.height(), Y.tor_rank() + map.width()); rel_y_map(Y.free_rank(), 0, Y.tor_rank(), Y.tor_rank()) = Y.torsion_matrix(p); rel_y_map(0, Y.tor_rank(), map.height(), map.width()) = map; MatrixQ proj(map.width(), Y.tor_rank() + map.width()); proj(0, Y.tor_rank(), map.width(), map.width()) = MatrixQ::identity(map.width()); MatrixQ f_copy(f); MatrixQRefList to_X_dummy; MatrixQRefList from_Y_dummy; MatrixQRefList from_X_ref; MatrixQRefList to_Y_ref; from_X_ref.emplace_back(proj); to_Y_ref.emplace_back(f_copy); smith_reduce_p(p, rel_y_map, to_X_dummy, from_X_ref, to_Y_ref, from_Y_dummy); MatrixQ lift(rel_y_map.width(), f.width()); dim_t d_max = 0; while (d_max < rel_y_map.height() && d_max < rel_y_map.width() && rel_y_map(d_max, d_max) != 0) { d_max++; } for (dim_t i = 0; i < d_max; i++) { for (dim_t j = 0; j < f.width(); j++) { lift(i, j) = f_copy(i, j) / rel_y_map(i, i); } } return proj * lift; }
bool TestExtFile::test_copy() { if (f_file_exists("test/test_ext_file2.tmp")) { f_unlink("test/test_ext_file2.tmp"); VERIFY(!f_file_exists("test/test_ext_file2.tmp")); } if (f_file_exists("test/test_ext_file3.tmp")) { f_unlink("test/test_ext_file3.tmp"); VERIFY(!f_file_exists("test/test_ext_file3.tmp")); } f_touch("test/test_ext_file.tmp"); f_copy("test/test_ext_file.tmp", "test/test_ext_file2.tmp"); VERIFY(f_file_exists("test/test_ext_file2.tmp")); VERIFY(f_file_exists("test/test_ext_file.tmp")); // XXX disabled until we work out flaky network issues. t2183444 #if 0 f_copy("http://facebook.com", "test/test_ext_file3.tmp"); VERIFY(f_file_exists("test/test_ext_file3.tmp")); #endif return Count(true); }
int main(int argc, char* argv[]) { try { // create a new empty file saga::filesystem::file f_orig("/tmp/hello.txt", saga::filesystem::Create); // write the string "Hello, World!" to the file char txt[] = "Hello, World!"; f_orig.write(saga::buffer(txt, sizeof(txt))); // copy the file f_orig.copy("/tmp/hello_copy.txt"); // open the copy and read the content saga::filesystem::file f_copy("/tmp/hello_copy.txt"); saga::mutable_buffer buf (1024*64); while (true) { // read a chunk into the buffer if ( f_copy.read (buf, 1024*64) ) { std::cout << (char*) (buf.get_data ()); } else break; } // delete both files f_orig.remove(); f_copy.remove(); } catch(saga::exception const & e) { std::cerr << e.what() << std::endl; } return 0; }