<commit_before>/**
 * This file is part of the CernVM File System.
 *
 * libcvmfs provides an API for the CernVM-FS client.  This is an
 * alternative to FUSE for reading a remote CernVM-FS repository.
 */

#define _FILE_OFFSET_BITS 64

#include "cvmfs_config.h"

#include <sys/stat.h>
#include <errno.h>
#include <cstdlib>
#include <stddef.h>

#include <string>

#include "util.h"
#include "logging.h"
#include "smalloc.h"
#include "libcvmfs_int.h"
#include "libcvmfs.h"

using namespace std;  // NOLINT


int set_option(char const *name, char const *value, bool *var) {
  if( *value != '\0' ) {
    fprintf(stderr,"Option %s=%s contains a value when none was expected.\n",name,value);
    return -1;
  }
  *var = true;
  return 0;
}

int set_option(char const *name, char const *value, unsigned *var) {
  unsigned v = 0;
  int end = 0;
  int rc = sscanf(value,"%u%n",&v,&end);
  if( rc != 1 || value[end] != '\0' ) {
    fprintf(stderr,"Invalid unsigned integer value for %s=%s\n",name,value);
    return -1;
  }
  *var = v;
  return 0;
}

int set_option(char const *name, char const *value, unsigned long *var) {
  unsigned long v = 0;
  int end = 0;
  int rc = sscanf(value,"%lu%n",&v,&end);
  if( rc != 1 || value[end] != '\0' ) {
    fprintf(stderr,"Invalid unsigned long integer value for %s=%s\n",name,value);
    return -1;
  }
  *var = v;
  return 0;
}

int set_option(char const *name, char const *value, int *var) {
  int v = 0;
  int end = 0;
  int rc = sscanf(value,"%d%n",&v,&end);
  if( rc != 1 || value[end] != '\0' ) {
    fprintf(stderr,"Invalid integer value for %s=%s\n",name,value);
    return -1;
  }
  *var = v;
  return 0;
}

int set_option(char const *name, char const *value, string *var) {
  *var = value;
  return 0;
}


#define CVMFS_OPT(var) if( strcmp(name,#var)==0 ) return ::set_option(name,value,&var)

struct cvmfs_repo_options : public cvmfs_context::options {
  int set_option(char const *name, char const *value) {
    CVMFS_OPT(url);
    CVMFS_OPT(timeout);
    CVMFS_OPT(timeout_direct);
    CVMFS_OPT(proxies);
    CVMFS_OPT(tracefile);
    CVMFS_OPT(allow_unsigned);
    CVMFS_OPT(pubkey);
    CVMFS_OPT(deep_mount);
    CVMFS_OPT(repo_name);
    CVMFS_OPT(mountpoint);
    CVMFS_OPT(blacklist);

    fprintf(stderr,"Unknown repo option: %s\n", name);
    return -1;
  }

  int verify_sanity() {
    if( mountpoint.empty() && !repo_name.empty()) {
      mountpoint = "/cvmfs/";
      mountpoint += repo_name;
    }
    while( mountpoint.length()>0 && mountpoint[mountpoint.length()-1] == '/' ) {
      mountpoint.resize(mountpoint.length()-1);
    }

    return 0;
  }
};

struct cvmfs_global_options : public cvmfs_globals::options {
  int set_option(char const *name, char const *value) {
    CVMFS_OPT(cache_directory);
    CVMFS_OPT(change_to_cache_directory);
    CVMFS_OPT(log_syslog_level);
    CVMFS_OPT(log_prefix);
    CVMFS_OPT(log_file);
    CVMFS_OPT(max_open_files);

    fprintf(stderr,"Unknown global option: %s\n", name);
    return -1;
  }

  int verify_sanity() {
    return 0;
  }
};


/**
 * Structure to parse the file system options.
 */
template <class DerivedT>
struct cvmfs_options : public DerivedT {

  //#define CVMFS_OPT(var) if( strcmp(name,#var)==0 ) return cvmfs_options::set_option(name,value,&var)
  int set_option(char const *name, char const *value) {
    return DerivedT::set_option(name, value);<commit_msg>add alien_cache config parameter<commit_after>/**
 * This file is part of the CernVM File System.
 *
 * libcvmfs provides an API for the CernVM-FS client.  This is an
 * alternative to FUSE for reading a remote CernVM-FS repository.
 */

#define _FILE_OFFSET_BITS 64

#include "cvmfs_config.h"

#include <sys/stat.h>
#include <errno.h>
#include <cstdlib>
#include <stddef.h>

#include <string>

#include "util.h"
#include "logging.h"
#include "smalloc.h"
#include "libcvmfs_int.h"
#include "libcvmfs.h"

using namespace std;  // NOLINT


int set_option(char const *name, char const *value, bool *var) {
  if( *value != '\0' ) {
    fprintf(stderr,"Option %s=%s contains a value when none was expected.\n",name,value);
    return -1;
  }
  *var = true;
  return 0;
}

int set_option(char const *name, char const *value, unsigned *var) {
  unsigned v = 0;
  int end = 0;
  int rc = sscanf(value,"%u%n",&v,&end);
  if( rc != 1 || value[end] != '\0' ) {
    fprintf(stderr,"Invalid unsigned integer value for %s=%s\n",name,value);
    return -1;
  }
  *var = v;
  return 0;
}

int set_option(char const *name, char const *value, unsigned long *var) {
  unsigned long v = 0;
  int end = 0;
  int rc = sscanf(value,"%lu%n",&v,&end);
  if( rc != 1 || value[end] != '\0' ) {
    fprintf(stderr,"Invalid unsigned long integer value for %s=%s\n",name,value);
    return -1;
  }
  *var = v;
  return 0;
}

int set_option(char const *name, char const *value, int *var) {
  int v = 0;
  int end = 0;
  int rc = sscanf(value,"%d%n",&v,&end);
  if( rc != 1 || value[end] != '\0' ) {
    fprintf(stderr,"Invalid integer value for %s=%s\n",name,value);
    return -1;
  }
  *var = v;
  return 0;
}

int set_option(char const *name, char const *value, string *var) {
  *var = value;
  return 0;
}


#define CVMFS_OPT(var) if( strcmp(name,#var)==0 ) return ::set_option(name,value,&var)

struct cvmfs_repo_options : public cvmfs_context::options {
  int set_option(char const *name, char const *value) {
    CVMFS_OPT(url);
    CVMFS_OPT(timeout);
    CVMFS_OPT(timeout_direct);
    CVMFS_OPT(proxies);
    CVMFS_OPT(tracefile);
    CVMFS_OPT(allow_unsigned);
    CVMFS_OPT(pubkey);
    CVMFS_OPT(deep_mount);
    CVMFS_OPT(repo_name);
    CVMFS_OPT(mountpoint);
    CVMFS_OPT(blacklist);

    fprintf(stderr,"Unknown repo option: %s\n", name);
    return -1;
  }

  int verify_sanity() {
    if( mountpoint.empty() && !repo_name.empty()) {
      mountpoint = "/cvmfs/";
      mountpoint += repo_name;
    }
    while( mountpoint.length()>0 && mountpoint[mountpoint.length()-1] == '/' ) {
      mountpoint.resize(mountpoint.length()-1);
    }

    return 0;
  }
};

struct cvmfs_global_options : public cvmfs_globals::options {
  int set_option(char const *name, char const *value) {
    CVMFS_OPT(cache_directory);
    CVMFS_OPT(change_to_cache_directory);
    CVMFS_OPT(alien_cache);
    CVMFS_OPT(log_syslog_level);
    CVMFS_OPT(log_prefix);
    CVMFS_OPT(log_file);
    CVMFS_OPT(max_open_files);

    fprintf(stderr,"Unknown global option: %s\n", name);
    return -1;
  }

  int verify_sanity() {
    return 0;
  }
};


/**
 * Structure to parse the file system options.
 */
template <class DerivedT>
struct cvmfs_options : public DerivedT {

  //#define CVMFS_OPT(var) if( strcmp(name,#var)==0 ) return cvmfs_options::set_option(name,value,&var)
  int set_option(char const *name, char const *value) {
    return DerivedT::set_option(name, value);
{'fraction_non_alphanumeric': 0.15135531135531136, 'fraction_numerical': 0.00967032967032967, 'mean_word_length': 3.7173462335867313, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '5585168', 'n_tokens_mistral': 2639, 'n_tokens_neox': 2582, 'n_words': 631}