int run_main (int, ACE_TCHAR *[]) { ACE_START_TEST (ACE_TEXT ("Mem_Map_Test")); #if !defined (ACE_LACKS_MMAP) // = Initialize the temporary variable names ACE_TCHAR test_file[MAXPATHLEN + 1]; ACE_TCHAR temp_file1[MAXPATHLEN + 1]; ACE_TCHAR temp_file2[MAXPATHLEN + 1]; // Get the temporary directory // - 18 is for the filenames, ace_mem_map_temp_1 is the longest if (ACE::get_temp_dir (test_file, MAXPATHLEN - 18) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Temporary path too long\n")), -1); // Copy the temp directory to the other variables ACE_OS::strcpy (temp_file1, test_file); ACE_OS::strcpy (temp_file2, test_file); // Add the filenames to the end ACE_OS::strcat (test_file, ACE_TEXT ("ace_mem_map_test")); ACE_OS::strcat (temp_file1, ACE_TEXT ("ace_mem_map_temp_1")); ACE_OS::strcat (temp_file2, ACE_TEXT ("ace_mem_map_temp_2")); // First create a test file to work on if (create_test_file (test_file, LINE_LENGTH, NUM_LINES) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Create test file failed\n")), -1); ACE_Mem_Map mmap; // First memory map the test file if (mmap.map (test_file) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%n: %p\n%a"), ACE_TEXT ("mmap")), -1); // Now create a temporary file for intermediate processing ACE_HANDLE temp_file_handle = ACE_OS::open (temp_file1, O_RDWR | O_TRUNC | O_CREAT, ACE_DEFAULT_FILE_PERMS); if (temp_file_handle == ACE_INVALID_HANDLE) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Open failed\n")), -1); // Reverse the original file and write the output to the temporary // file. reverse_file (temp_file_handle, (char *) mmap.addr (), mmap.size ()); ACE_OS::close (temp_file_handle); ACE_Mem_Map temp_mmap; // Now memory map the temporary file if (temp_mmap.map (temp_file1) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%n: %p\n%a"), ACE_TEXT ("mmap")), -1); if ((temp_file_handle = ACE_OS::open (temp_file2, O_RDWR | O_TRUNC | O_CREAT, ACE_DEFAULT_FILE_PERMS)) == ACE_INVALID_HANDLE) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Open failed\n")), -1); // Now reverse the temporary file and write everything to the second // temporary file. reverse_file (temp_file_handle, (char *) temp_mmap.addr (), temp_mmap.size ()); ACE_OS::close (temp_file_handle); // Memory map the second temporary file ACE_Mem_Map temp_mmap2; if (temp_mmap2.map (temp_file2) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%n: %p\n%a"), ACE_TEXT ("mmap")), -1); // Now do a memcmp -- the orig file and the second temporary file // should be identical. ACE_ASSERT (ACE_OS::memcmp (temp_mmap2.addr (), mmap.addr (), mmap.size ()) == 0); // Delete the test file mmap.remove (); // Delete ACE_TEMP_TEST_FILE temp_mmap.remove (); // Delete ACE_TEMP_TEST_FILE_2 temp_mmap2.remove (); #else /* !ACE_LACKS_MMAP */ ACE_ERROR ((LM_INFO, ACE_TEXT ("mmap is not supported on this platform\n"))); #endif /* !ACE_LACKS_MMAP */ ACE_END_TEST; return 0; }
void Package::reverse_directory(QDir & d, bool rec) { if (! allowed(DirFilter, d.dirName())) return; // reads files QFileInfoList list = d.entryInfoList(QDir::Files | QDir::Readable); if (!list.isEmpty()) { QFileInfoList::iterator it = list.begin(); while (it != list.end()) { if ((*it).extension(FALSE) == Ext) { if (allowed(FileFilter, (*it).fileName())) reverse_file(WrapperStr((*it).filePath().toAscii().constData()), WrapperStr(my_baseName(&(*it)).toAscii().constData())); if (progress) progress->tic(); app->processEvents(); } ++it; } /* while ((fi = it.current()) != 0) { if (fi->extension(FALSE) == Ext) { if (allowed(FileFilter, fi->fileName())) reverse_file(WrapperStr(fi->filePath()), WrapperStr(my_baseName(fi))); if (progress) progress->tic(); app->processEvents(); } ++it; }*/ } if (rec) { // sub directories list = d.entryInfoList(QDir::Dirs | QDir::NoSymLinks); if (!list.isEmpty()) { QFileInfoList::iterator itd = list.begin(); while (itd != list.end()) { if ((*itd).fileName()[0] != '.') { QDir sd((*itd).filePath()); Package * p = find(WrapperStr(sd.dirName().toAscii().constData()), TRUE); if (p != 0) p->reverse_directory(sd, TRUE); } ++itd; } } } }
// process the command line arguments int main(int argc, char *argv[]) { // loadfile("alpha.txt"); // get_rand_test(); printf("Shuffle arguments %d\n", argc); if ( argc < 3 ) /* argc should be 2 for correct execution */ { /* We print argv[0] assuming it is the program name */ printf("Binary shuffle v1.0\n" ); printf( "usage: %s -rev filename\n", argv[0] ); // reverse file printf( "usage: %s -hex filename\n\n", argv[0] ); printf( "usage: %s -sh filename\n", argv[0] ); printf( "usage: %s -ush filename\n", argv[0] ); printf( "usage: %s -add filename\n", argv[0] ); printf( "usage: %s -sub filename\n\n", argv[0] ); printf( "usage: %s -add number filename\n", argv[0] ); printf( "usage: %s -sub number filename\n", argv[0] ); printf( "usage: %s -addlist rng filename\n", argv[0] ); printf( "usage: %s -sublist rng filename\n", argv[0] ); printf( "usage: %s -addlist rng iterations filename\n", argv[0] ); printf( "usage: %s -sublist rng iterations filename\n\n", argv[0] ); printf( "usage: %s -sh seed iterations filename\n", argv[0] ); printf( "usage: %s -ush seed iterations filename\n", argv[0] ); exit(1); } else if (argc == 3) { if (strcmp(argv[1], "-sh") == 0) /* Process optional arguments. */ { shuffle_file(argv[2]); } if (strcmp(argv[1], "-ush") == 0) /* Process optional arguments. */ { unshuffle_file(argv[2]); } if (strcmp(argv[1], "-hex") == 0) /* Process optional arguments. */ { // dumphex_file(argv[2]); dumphex_file2(argv[2],0, 16, 16); } if (strcmp(argv[1], "-rev") == 0) /* Process optional arguments. */ { reverse_file(argv[2]); } if (strcmp(argv[1], "-add") == 0) { add_file(argv[2]); } if (strcmp(argv[1], "-sub") == 0) { subtract_file(argv[2]); } } else if (argc == 4) { unsigned long sum = atoi(argv[2]); if (strcmp(argv[1], "-add") == 0) { add_file(argv[3]); } if (strcmp(argv[1], "-sub") == 0) { subtract_file(argv[3]); } // add and subtract list if (strcmp(argv[1], "-addlist") == 0) { add_file_rnglist(argv[3], sum); } if (strcmp(argv[1], "-sublist") == 0) { subtract_file_rnglist(argv[3], sum); } } if (argc == 5 ) { unsigned long seed = atoi(argv[2]); unsigned long iterations = atoi(argv[3]); nSeed = seed; nSeed2 = seed; timeslast = iterations; timeslast = iterations; if (strcmp(argv[1], "-addlist") == 0) /* Process optional arguments. */ { add_file_rnglist(argv[4], seed); } if (strcmp(argv[1], "-sublist") == 0) /* Process optional arguments. */ { subtract_file_rnglist(argv[4], seed); } // shuffle and unshuffle with a rng seed and n iterations if (strcmp(argv[1], "-sh") == 0) /* Process optional arguments. */ { shuffle_file(argv[4]); } if (strcmp(argv[1], "-ush") == 0) /* Process optional arguments. */ { unshuffle_file(argv[4]); } } return 0; }
int main(int argc, char *const *argv){ char buf[PATH_MAX+1]; char *simcount = 0; int simul_count = 10; char *original_path = 0; int path_passed = 0; int opt= 0; //Specifying the expected options // TODO: set simcount as an optional parameter static struct option long_options[] = { {"simcount", required_argument, 0, 's' }, {"path", required_argument, 0, 'p' }, {"help", no_argument, 0, 'h' }, {0, 0, 0, 0 } }; int long_index =0; while ((opt = getopt_long(argc, argv, "s:p:", long_options, &long_index )) != -1) { switch (opt) { // `optarg` is a global variable from getopt.h case 's' : simcount = strdup(optarg); break; case 'p' : path_passed = 1; original_path = realpath(optarg, buf); break; case 'h' : print_usage(); exit(0); default: print_usage(); exit(EXIT_FAILURE); } } // Check that a path was specified and that it is a valid path if (path_passed && !original_path) { printf("Path was given, but was invalid.\n"); print_usage(); exit(EXIT_FAILURE); } else if (!path_passed) { printf("Path was not specified.\n"); print_usage(); exit(EXIT_FAILURE); } // Convert the given "simcount" to a number, store in `simul_count` if (simcount){ errno = 0; long tmp = strtol(simcount, 0, 10); // TODO: implement converter if (errno != 0){ printf("Could not convert specified simcount into a valid number.\n"); print_usage(); exit(EXIT_FAILURE); } simul_count = tmp; } printf("original_path: %s, simul_count: %d\n", original_path, simul_count); reverse_file(original_path, simul_count); //char* test[] = { // "spinelessness prayed doppelgangers notabilities syllabification unflinching", // "coccyx Msgr environments subjecting Duroc ibis fetus whack wile", // "nippy demoed pretax voltmeters bougainvillea garish weedkillers", //}; //int i = 0; //for (i = 0; i < 3; ++i){ // char* rv = in_place_reverse_words(strdup(test[i])); // free(rv); //} return 0; }