<commit_before>// Filename: fltCopy.cxx
// Created by:  drose (01Nov00)
// 
////////////////////////////////////////////////////////////////////

#include "fltCopy.h"

#include <cvsSourceDirectory.h>
#include <fltHeader.h>
#include <fltFace.h>
#include <fltExternalReference.h>
#include <fltError.h>

////////////////////////////////////////////////////////////////////
//     Function: FltCopy::Constructor
//       Access: Public
//  Description: 
////////////////////////////////////////////////////////////////////
FltCopy::
FltCopy() {
  set_program_description
    ("This program copies one or more MultiGen .flt files into a "
     "CVS source hierarchy.  "
     "Rather than copying the named files immediately into the current "
     "directory, it first scans the entire source hierarchy, identifying all "
     "the already-existing files.  If the named file to copy matches the "
     "name of an already-existing file in the current directory or elsewhere "
     "in the hierarchy, that file is overwritten.  Other .flt files, as "
     "well as texture files, that are externally referenced by the "
     "named .flt file(s) are similarly copied.");

  clear_runlines();
  add_runline("[opts] file.flt [file.flt ... ]");

  add_option
    ("s", "dirname", 0, 
     "Specify the directory or directories that are to be searched for "
     "relative pathnames appearing in the flt file.  This may be a "
     "single directory name or a colon-delimited list of directories.  "
     "It may also be " 
     "repeated multiple times on the command line; each time it appears "
     "its named directories will be appended to the search path.",
     &FltCopy::dispatch_search_path, NULL, &_search_path);
}

////////////////////////////////////////////////////////////////////
//     Function: FltCopy::run
//       Access: Public
//  Description: 
////////////////////////////////////////////////////////////////////
void FltCopy::
run() {
  if (_search_path.get_num_directories() == 0) {
    _search_path.append_directory(".");
  }
  SourceFiles::iterator fi;
  for (fi = _source_files.begin(); fi != _source_files.end(); ++fi) {
    ExtraData ed;
    ed._type = FT_flt;

    CVSSourceDirectory *dest = import(*fi, &ed, _model_dir);
    if (dest == (CVSSourceDirectory *)NULL) {
      exit(1);
    }
  }
}

////////////////////////////////////////////////////////////////////
//     Function: FltCopy::copy_file
//       Access: Protected, Virtual
//  Description: Called by import() if the timestamps indicate that a
//               file needs to be copied.  This does the actual copy
//               of a file from source to destination.  If new_file is
//               true, then dest does not already exist.
////////////////////////////////////////////////////////////////////
bool FltCopy::
copy_file(const Filename &source, const Filename &dest,
	  CVSSourceDirectory *dir, void *extra_data, bool new_file) {
  ExtraData *ed = (ExtraData *)extra_data;
  switch (ed->_type) {
  case FT_flt:
    return copy_flt_file(source, dest, dir);

  case FT_texture:
    return copy_texture(source, dest, dir, ed->_texture, new_file);
  }

  nout << "Internal error: invalid type " << (int)ed->_type << "\n";
  return false;
}

////////////////////////////////////////////////////////////////////
//     Function: FltCopy::copy_flt_file
//       Access: Private
//  Description: 
////////////////////////////////////////////////////////////////////
bool FltCopy::
copy_flt_file(const Filename &source, const Filename &dest,
	      CVSSourceDirectory *dir) {
  PT(FltHeader) header = new FltHeader;
  header->set_texture_path(_search_path);

  // We don't want to automatically generate .attr files--we'd rather
  // write them out explicitly.
  header->set_auto_attr_update(FltHeader::AU_none);

  FltError result = header->read_flt(source);
  if (result != FE_ok) {
    nout << "Cannot read " << source << "\n";
    return false;
  }
<commit_msg>*** empty log message ***<commit_after>// Filename: fltCopy.cxx
// Created by:  drose (01Nov00)
// 
////////////////////////////////////////////////////////////////////

#include "fltCopy.h"

#include <cvsSourceDirectory.h>
#include <fltHeader.h>
#include <fltFace.h>
#include <fltExternalReference.h>
#include <fltError.h>

////////////////////////////////////////////////////////////////////
//     Function: FltCopy::Constructor
//       Access: Public
//  Description: 
////////////////////////////////////////////////////////////////////
FltCopy::
FltCopy() {
  set_program_description
    ("This program copies one or more MultiGen .flt files into a "
     "CVS source hierarchy.  "
     "Rather than copying the named files immediately into the current "
     "directory, it first scans the entire source hierarchy, identifying all "
     "the already-existing files.  If the named file to copy matches the "
     "name of an already-existing file in the current directory or elsewhere "
     "in the hierarchy, that file is overwritten.  Other .flt files, as "
     "well as texture files, that are externally referenced by the "
     "named .flt file(s) are similarly copied.");

  clear_runlines();
  add_runline("[opts] file.flt [file.flt ... ]");

  add_option
    ("s", "dirname", 0, 
     "Specify the directory or directories that are to be searched for "
     "relative pathnames appearing in the flt file.  This may be a "
     "single directory name or a colon-delimited list of directories.  "
     "It may also be " 
     "repeated multiple times on the command line; each time it appears "
     "its named directories will be appended to the search path.",
     &FltCopy::dispatch_search_path, NULL, &_search_path);
}

////////////////////////////////////////////////////////////////////
//     Function: FltCopy::run
//       Access: Public
//  Description: 
////////////////////////////////////////////////////////////////////
void FltCopy::
run() {
  if (_search_path.get_num_directories() == 0) {
    _search_path.append_directory(".");
  }
  SourceFiles::iterator fi;
  for (fi = _source_files.begin(); fi != _source_files.end(); ++fi) {
    ExtraData ed;
    ed._type = FT_flt;

    CVSSourceDirectory *dest = import(*fi, &ed, _model_dir);
    if (dest == (CVSSourceDirectory *)NULL) {
      exit(1);
    }
  }
}

////////////////////////////////////////////////////////////////////
//     Function: FltCopy::copy_file
//       Access: Protected, Virtual
//  Description: Called by import() if the timestamps indicate that a
//               file needs to be copied.  This does the actual copy
//               of a file from source to destination.  If new_file is
//               true, then dest does not already exist.
////////////////////////////////////////////////////////////////////
bool FltCopy::
copy_file(const Filename &source, const Filename &dest,
	  CVSSourceDirectory *dir, void *extra_data, bool new_file) {
  ExtraData *ed = (ExtraData *)extra_data;
  switch (ed->_type) {
  case FT_flt:
    return copy_flt_file(source, dest, dir);

  case FT_texture:
    return copy_texture(source, dest, dir, ed->_texture, new_file);
  }

  nout << "Internal error: invalid type " << (int)ed->_type << "\n";
  return false;
}

////////////////////////////////////////////////////////////////////
//     Function: FltCopy::copy_flt_file
//       Access: Private
//  Description: 
////////////////////////////////////////////////////////////////////
bool FltCopy::
copy_flt_file(const Filename &source, const Filename &dest,
	      CVSSourceDirectory *dir) {
  PT(FltHeader) header = new FltHeader;
  header->set_texture_path(_search_path);

  // We don't want to automatically generate .attr files--we'd rather
  // write them out explicitly.
  header->set_auto_attr_update(FltHeader::AU_none);

  FltError result = header->read_flt(source);
  if (result != FE_ok) {
    nout << "Cannot read " << source << ": " << result << "\n";
    return false;
  }

{'fraction_non_alphanumeric': 0.25081884605694127, 'fraction_numerical': 0.001763668430335097, 'mean_word_length': 1.7875702247191012, 'pattern_counts': {'":': 1, '<': 41, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1346240', 'n_tokens_mistral': 2176, 'n_tokens_neox': 2119, 'n_words': 693}