Update copyright date.
[asdcplib.git] / src / kmfilegen.cpp
index bc1243d9da8e7106801b6508d7bdea0687004a1a..9ab1f00b95dbf92dea28e2ae9b920285cf55d823 100755 (executable)
@@ -83,23 +83,26 @@ void
 usage(FILE* stream = stdout)
 {
   fprintf(stream, "\
-USAGE: %s [-c <file-size>][-o <fwd|rev|rand>][-w <filename>][-v]\n\
-       <filename>\n\
+USAGE: %s [-c <file-size>] [-v] <output-file>\n\
+\n\
+       %s [-o <fwd|rev|rand>] [-v] <input-file>\n\
+\n\
+       %s [-w <output-file>] [-v] <input-file>\n\
 \n\
        %s [-h|-help] [-V]\n\
 \n\
-  -c <file-size>  - Create a test file containing <file-size> megabytes of data\n\
-  -h | -help      - Show help\n\
-  -o <order>      - Specify order used when validating a file.\n\
-                    One of fwd|rev|rand, default is rand\n\
-  -v              - Verbose. Prints informative messages to stderr\n\
-  -V              - Show version information\n\
-  -w              - Read-Validate-Write - file is written to <filename>\n\
-                    (sequential read only)\n\
+  -c <file-size>     - Create test file containing <file-size> megabytes of data\n\
+  -h | -help         - Show help\n\
+  -o <fwd|rev|rand>  - Specify order used when validating a file.\n\
+                       One of fwd|rev|rand, default is rand\n\
+  -v                 - Verbose. Prints informative messages to stderr\n\
+  -V                 - Show version information\n\
+  -w <output-file>   - Read-Validate-Write - file is written to <output-file>\n\
+                       (sequential read only)\n\
 \n\
   NOTES: o There is no option grouping, all options must be distinct arguments.\n\
          o All option arguments must be separated from the option by whitespace.\n\
-\n", PACKAGE, PACKAGE);
+\n", PACKAGE, PACKAGE, PACKAGE, PACKAGE);
 }
 
 enum MajorMode_t {
@@ -127,19 +130,19 @@ public:
 
   //
   CommandOptions(int argc, const char** argv) :
-    error_flag(true), order(0), verbose_flag(false), version_flag(false), help_flag(false),
+    error_flag(true), order(""), verbose_flag(false), version_flag(false), help_flag(false),
     filename(""), write_filename(""), chunk_count(0), mode(MMT_VALIDATE)
   {
-    order = "rand";
+    //    order = "rand";
 
     for ( int i = 1; i < argc; i++ )
       {
 
-        if ( (strcmp( argv[i], "-help") == 0) )
-          {
-            help_flag = true;
-            continue;
-          }
+       if ( (strcmp( argv[i], "-help") == 0) )
+         {
+           help_flag = true;
+           continue;
+         }
      
        if ( argv[i][0] == '-' && isalpha(argv[i][1]) && argv[i][2] == 0 )
          {
@@ -200,22 +203,31 @@ public:
          }
       }
     
-     if ( help_flag || version_flag )
-       return;
-  
-     if ( strlen ( filename ) == 0 )
+    if ( help_flag || version_flag )
+      return;
+    
+    if ( strlen ( filename ) == 0 )
       {
        fprintf(stderr, "Filename required.\n");
        return;
       }
+    
+    if ( mode != MMT_VALIDATE && strcmp(order, "") != 0 )
+      {
+       fprintf(stderr, "-o option not valid with -c or -w options.\n");
+       return;
+      }
+    else
+      if ( strcmp(order, "") == 0 )
+       order = "rand";
 
-   if ( strcmp ( filename, write_filename ) == 0 )
-     {
-       fprintf(stderr, "Output and input files must be different.\n");
-       return;
-     }
-
-   error_flag = false;
+    if ( strcmp ( filename, write_filename ) == 0 )
+      {
+       fprintf(stderr, "Output and input files must be different.\n");
+       return;
+      }
+    
+    error_flag = false;
   }
 };
 
@@ -287,7 +299,7 @@ CreateLargeFile(CommandOptions& Options)
   FB.Capacity(Megabyte);
   assert(FB.Capacity() == Megabyte);
 
-  fprintf(stderr, "Writing %lu chunks:\n", Options.chunk_count);
+  fprintf(stderr, "Writing %u chunks:\n", Options.chunk_count);
   s_Nonce = Options.chunk_count;
   Result_t result = Writer.OpenWrite(Options.filename);
 
@@ -300,7 +312,7 @@ CreateLargeFile(CommandOptions& Options)
          CTR.FillRandom(FB.Data() + CTR.WriteSize(), Megabyte - CTR.WriteSize());
          result = Writer.Write(FB.RoData(), Megabyte, &write_count);
          assert(write_count == Megabyte);
-         fprintf(stderr, "\r%8lu ", ++write_total);
+         fprintf(stderr, "\r%8u ", ++write_total);
        }
     }
   
@@ -399,7 +411,7 @@ ReadValidateWriteLargeFile(CommandOptions& Options)
        {
          if ( read_count < Megabyte )
            {
-             fprintf(stderr, "Read() returned short buffer: %lu\n", read_count);
+             fprintf(stderr, "Read() returned short buffer: %u\n", read_count);
              result = RESULT_FAIL;
            }
 
@@ -409,7 +421,7 @@ ReadValidateWriteLargeFile(CommandOptions& Options)
            {
              result = Writer.Write(FB.RoData(), Megabyte, &write_count);
              assert(write_count == Megabyte);
-             fprintf(stderr, "\r%8lu ", ++write_total);
+             fprintf(stderr, "\r%8u ", ++write_total);
            }
        }
       else if ( result == RESULT_ENDOFFILE )
@@ -449,7 +461,7 @@ ValidateLargeFile(CommandOptions& Options)
 
       if ( read_count < Megabyte )
        {
-         fprintf(stderr, "Read() returned short buffer: %lu\n", read_count);
+         fprintf(stderr, "Read() returned short buffer: %u\n", read_count);
          result = RESULT_FAIL;
        }
       else if ( KM_SUCCESS(result) )
@@ -457,7 +469,7 @@ ValidateLargeFile(CommandOptions& Options)
 
       if ( KM_SUCCESS(result) )
        {
-         fprintf(stderr, "Validating %lu chunk%s in %s order:\n",
+         fprintf(stderr, "Validating %u chunk%s in %s order:\n",
                  check_total, (check_total == 1 ? "" : "s"), Options.order);
          assert(read_list == 0);
          read_list = (read_list_t*)malloc(check_total * sizeof(read_list_t));
@@ -498,7 +510,7 @@ ValidateLargeFile(CommandOptions& Options)
            read_list_i < check_total && KM_SUCCESS(result);
            read_list_i++ )
        {
-         fprintf(stderr, "\r%8lu [%8lu] ", read_list_i+1, read_list[read_list_i]);
+         fprintf(stderr, "\r%8u [%8u] ", read_list_i+1, read_list[read_list_i].nonce);
          result = Reader.Seek(read_list[read_list_i].position);
 
          if ( KM_SUCCESS(result) )
@@ -509,7 +521,7 @@ ValidateLargeFile(CommandOptions& Options)
 
          else if ( read_count < Megabyte )
            {
-             fprintf(stderr, "Read() returned short buffer: %lu\n", read_count);
+             fprintf(stderr, "Read() returned short buffer: %u\n", read_count);
              result = RESULT_FAIL;
            }
          else if ( KM_SUCCESS(result) )
@@ -518,7 +530,7 @@ ValidateLargeFile(CommandOptions& Options)
              
              if ( nonce != read_list[read_list_i].nonce )
                {
-                 fprintf(stderr, "Nonce mismatch: expecting %lu, got %lu\n",
+                 fprintf(stderr, "Nonce mismatch: expecting %u, got %u\n",
                          nonce, read_list[read_list_i].nonce);
 
                  return RESULT_FAIL;
@@ -535,7 +547,7 @@ ValidateLargeFile(CommandOptions& Options)
        result = RESULT_OK;
       else
        {
-         fprintf(stderr, "Unexpected chunk count, got %lu, wanted %lu\n",
+         fprintf(stderr, "Unexpected chunk count, got %u, wanted %u\n",
                  read_list_i, check_total);
          result = RESULT_FAIL;
        }