int main( int argc, const char *argv[] )
{
  // If you are using OpenNURBS as a Windows DLL, then you MUST use
  // ON::OpenFile() to open the file.  If you are not using OpenNURBS
  // as a Windows DLL, then you may use either ON::OpenFile() or fopen()
  // to open the file.

  const char* example_read_exe_name = 0;
  if ( argc >= 1 && 0 != argv && 0 != argv[0] && 0 != argv[0][0] )
  {
    on_splitpath(argv[0],0,0,&example_read_exe_name,0);
  }
  if ( 0 == example_read_exe_name || 0 == example_read_exe_name[0] )
  {
#if defined(ON_OS_WINDOWS)
    example_read_exe_name = "example_read.exe";
#else
    example_read_exe_name = "example_read";
#endif
  }

  int argi;
  if ( argc < 2 ) 
  {
    print_help(example_read_exe_name);
    return 0;
  }

  // Call once in your application to initialze opennurbs library
  ON::Begin();

  // default dump is to stdout
  ON_TextLog dump_to_stdout;
  dump_to_stdout.SetIndentSize(2);
  ON_TextLog* dump = &dump_to_stdout;
  FILE* dump_fp = 0;

  bool bVerboseTextDump = true;

  bool bChunkDump = false;


  int maximum_directory_depth = 0;

  int file_count = 0;

  for ( argi = 1; argi < argc; argi++ ) 
  {
    const char* arg = argv[argi];

    // check for -out or /out option
    if ( (    0 == strncmp(arg,"-out:",5) || 0 == strncmp(arg,"-out:",5)
#if defined(ON_OS_WINDOWS)
           || 0 == strncmp(arg,"/out:",5) 
#endif
         ) 
         && arg[5] )
    {
      // change destination of dump file
      if ( dump != &dump_to_stdout )
      {
        delete dump;
        dump = 0;
      }
        if ( dump_fp )
        {
          ON::CloseFile(dump_fp);
        }

      const char* sDumpFilename = arg+5;
      FILE* text_fp = ON::OpenFile(sDumpFilename,"w");
      if ( text_fp )
      {
        dump_fp = text_fp;
        dump = new ON_TextLog(dump_fp);
        dump->SetIndentSize(2);
    }

      if ( 0 == dump )
        dump = &dump_to_stdout;

      continue;
    }

    // check for -chunkdump or /chunkdump option
    if (    0 == strcmp(arg,"-C") 
         || 0 == strcmp(arg,"-c") 
         || 0 == strcmp(arg,"-chunk") 
         || 0 == strcmp(arg,"-chunkdump") 
#if defined(ON_OS_WINDOWS)
         || 0 == strcmp(arg,"/C") 
         || 0 == strcmp(arg,"/c") 
         || 0 == strcmp(arg,"/chunk") 
         || 0 == strcmp(arg,"/chunkdump") 
#endif
         )
    {
      bChunkDump = true;
      continue;
    }

    // check for -recursive or /recursive option
    if (    0 == strcmp(arg,"-R") 
         || 0 == strcmp(arg,"-r") 
         || 0 == strcmp(arg,"-recurse") 
         || 0 == strcmp(arg,"-recursive") 
#if defined(ON_OS_WINDOWS)
         || 0 == strcmp(arg,"/R") 
         || 0 == strcmp(arg,"/r") 
         || 0 == strcmp(arg,"/recurse") 
         || 0 == strcmp(arg,"/recursive") 
#endif
         )
    {
      maximum_directory_depth = 32;
      continue;
    }

    ON_wString ws_arg = arg;
    const wchar_t* wchar_arg = ws_arg;

    if ( ON::IsDirectory(wchar_arg) )
    {
      file_count += ReadDirectoryHelper( 0, maximum_directory_depth, wchar_arg, 0, bVerboseTextDump, bChunkDump, *dump );
    }
    else
    {
      if ( ReadFileHelper( wchar_arg, bVerboseTextDump, bChunkDump, *dump ) )
        file_count++;
    }

  }

  dump->Print("%s read %d opennurbs model files.\n",example_read_exe_name,file_count);
  if ( dump != &dump_to_stdout )
  {
    delete dump;
    dump = 0;
  }

  if ( dump_fp )
  {
    // close the text dump file
    ON::CloseFile( dump_fp );
    dump_fp = 0;
  }
  
  // OPTIONAL: Call just before your application exits to clean
  //           up opennurbs class definition information.
  //           Opennurbs will not work correctly after ON::End()
  //           is called.
  ON::End();

  return 0;
}
Пример #2
0
int main( int argc, const char *argv[] )
{
  // If you are using OpenNURBS as a Windows DLL, then you MUST use
  // ON::OpenFile() to open the file.  If you are not using OpenNURBS
  // as a Windows DLL, then you may use either ON::OpenFile() or fopen()
  // to open the file.

  const char* example_test_exe_name = 0;
  if ( argc >= 1 && 0 != argv && 0 != argv[0] && 0 != argv[0][0] )
  {
    on_splitpath(
      argv[0],
      nullptr, // volume
      nullptr, // directory,
      &example_test_exe_name,
      nullptr // extension
      );
  }

  if ( 0 == example_test_exe_name || 0 == example_test_exe_name[0] )
  {
#if defined(ON_OS_WINDOWS)
    example_test_exe_name = "example_test.exe";
#else
    example_test_exe_name = "example_test";
#endif
  }

  const ON_wString exe_name((nullptr != argv && argc > 0) ? argv[0] : ((const char*)nullptr));

  ON_TextLog print_to_stdout;
  print_to_stdout.SetIndentSize(2);

  int argi;
  if ( argc < 2 ) 
  {
    Internal_PrintHelp(example_test_exe_name, print_to_stdout);
    return 0;
  }

  // Call once in your application to initialze opennurbs library
  ON::Begin();

  // default text_log is to stdout
  ON_TextLog* text_log = &print_to_stdout;
  FILE* text_log_fp = nullptr;
  
  unsigned int maximum_directory_depth = 0;

  bool bVerbose = false; // true = output will include a full listing of all 3dm file contents.

  ONX_ErrorCounter err;
  unsigned int file_count = 0;
  unsigned int folder_count = 0;
  unsigned int directory_arg_counter = 0;

  bool bPrintIntroduction = true;

  for ( argi = 1; argi < argc; argi++ ) 
  {
    const char* arg = argv[argi];

    // check for -out:<file name> option
    ON_String output_file_name;
    if ( Internal_ParseOption_OUT(arg,output_file_name) )
    {
      // need a new introduction when output destination changes.
      bPrintIntroduction = true;

      if (output_file_name.IsEmpty())
        continue; // invalid option systax

      // change destination of text_log file
      if ( text_log != &print_to_stdout )
      {
        delete text_log;
        text_log = nullptr;
      }
      if ( text_log_fp )
      {
        ON::CloseFile(text_log_fp);
      }

      FILE* text_fp = ON::OpenFile(output_file_name,"w");
      if ( text_fp )
      {
        text_log_fp = text_fp;
        text_log = new ON_TextLog(text_log_fp);
        text_log->SetIndentSize(2);
      }

      continue;
    }

    // check for -recursive:<directory depth> option
    if (Internal_Parse_ParsOption_RECURSE(arg, maximum_directory_depth))
    {
      continue;
    }

    if (Internal_Parse_ParsOption_VERBOSE(arg))
    {
      bVerbose = true;
      continue;
    }

    ON_wString full_path(arg);

    if ( nullptr == text_log )
      text_log = &print_to_stdout;

    if (bPrintIntroduction)
    {
      bPrintIntroduction = false;
      Internal_PrintIntroduction(exe_name, *text_log);
    }

    err += Internal_Test(
      maximum_directory_depth,
      full_path,
      bVerbose,
      *text_log,
      directory_arg_counter,
      file_count,
      folder_count
    );
  }

  if (bPrintIntroduction)
  {
    bPrintIntroduction = false;
    Internal_PrintIntroduction(exe_name, *text_log);
  }

  if (folder_count > 0)
  {
    text_log->Print(
      L"Tested %u 3dm files in %u folders.",
      file_count,
      folder_count
    );
  }
  else
  {
    text_log->Print(
      L"Tested %u 3dm files.",
      file_count
    );
  }

  if (err.FailureCount() > 0)
    text_log->Print(" Failures. ");
  else if (err.ErrorCount() > 0)
    text_log->Print(" Errors. ");
  else if (err.FailureCount() > 0)
    text_log->Print(" Warnings. ");
  else
    text_log->Print(" All tests passed. ");
  err.Dump(*text_log);
  text_log->PrintNewLine();

  if ( text_log != &print_to_stdout )
  {
    delete text_log;
    text_log = nullptr;
  }

  if ( text_log_fp )
  {
    // close the text text_log file
    ON::CloseFile( text_log_fp );
    text_log_fp = 0;
  }
  
  // OPTIONAL: Call just before your application exits to clean
  //           up opennurbs class definition information.
  //           Opennurbs will not work correctly after ON::End()
  //           is called.
  ON::End();

  return err.TotalCount();
}