<commit_before>#!/bin/bash -eu
#
# Copyright 2009 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
#
# Outputs a header file comment, with the appropriate comments based on the
# language, as deduced from the extension of the file.
#
# Sample usage:
#   autogen.sh file.js
#   autogen.sh file.py

declare -r SRCDIR="${TEST_SRCDIR:-$(dirname $0)}"

LICENSE_NAME="apache"
LICENSE_FILE="${SRCDIR}/licenses/apache-2.0.txt"
COPYRIGHT_HOLDER="Google Inc."
YEAR="${YEAR:-$(date +%Y)}"
MODIFY_FILE_INPLACE=0

function printLicenseWithYear() {
  cat "${LICENSE_FILE}" \
    | sed "s/%YEAR%/${YEAR}/" \
    | sed "s/%COPYRIGHT_HOLDER%/${COPYRIGHT_HOLDER}/"
}

function printLicenseNonHashComment() {
  printLicenseWithYear | sed -E "s#^#$1 #;s/ +$//"
}

function printLicenseHashComment() {
  printLicenseWithYear | sed -E "s/^/# /;s/ +$//"
}

# Prepend piped-in text to a file in-place.
#
# Args:
#   $1: filename to modify
function prependToFileInPlace() {
  local -r target="${1}"
  local -r tempfile="$(mktemp /tmp/$(basename $0).XXXXXX)"
  cat - "${target}" > "${tempfile}"
  mv -f "${tempfile}" "${target}"
  rm -f "${tempfile}"
}

readonly TODO_COMMENT="TODO: High-level file comment."
function printFileCommentTemplate() {
  local comment=$1
  # Fit into 80 cols: repeat enough times, depending on our comment width.
  local repeat=$(echo 80 / $(echo -n "${comment}" | wc -c) | bc)
  echo $comment
  perl -e "print \"$comment\" x $repeat . \"\n\""
  echo $comment
  echo "$comment ${TODO_COMMENT}"
}

while getopts c:il:y: opt ; do
  case "${opt}" in
    c)
      COPYRIGHT_HOLDER="${OPTARG}"
      ;;

    i)
      MODIFY_FILE_INPLACE=1
      ;;

    l)
      LICENSE_NAME="${OPTARG}"
      case "${LICENSE_NAME}" in
        apache)
          LICENSE_FILE="${SRCDIR}/licenses/apache-2.0.txt"
          ;;
        bsd2|bsd-2)
          LICENSE_FILE="${SRCDIR}/licenses/bsd-2-clause.txt"
          ;;
        bsd3|bsd-3)
          LICENSE_FILE="${SRCDIR}/licenses/bsd-3-clause.txt"
          ;;
        bsd4|bsd-4)
          LICENSE_FILE="${SRCDIR}/licenses/bsd-4-clause.txt"
          ;;
        gpl2|gpl-2)
          LICENSE_FILE="${SRCDIR}/licenses/gpl-2.txt"
          ;;
        gpl3|gpl-3)
          LICENSE_FILE="${SRCDIR}/licenses/gpl-3.txt"
          ;;
        lgpl|lgpl2|lgpl-2|lgpl2.1|lgpl-2.1)
          LICENSE_FILE="${SRCDIR}/licenses/lgpl-2.1.txt"
          ;;
        mit)
          LICENSE_FILE="${SRCDIR}/licenses/mit.txt"
          ;;
        *)
          echo "Invalid license selected: ${LICENSE_NAME}" >&2
          exit 1
      esac
      ;;
    y)
      YEAR="${OPTARG}"
      ;;
  esac
done

shift $((OPTIND - 1))

if [[ $# -eq 0 ]]; then
  echo "\
Syntax: $0 [options] <filename>

Options:
  -c [copyright holder]    set copyright holder (default: "${COPYRIGHT_HOLDER}")
  -i                       modify the given file in-place
  -l [license]             choose the license (default: "${LICENSE_NAME}")
  -y [year]                choose the year (default: ${YEAR})

Licenses:
  apache:       Apache 2.0
  bsd2:         BSD, 2-clause, aka Simplified/FreeBSD
  bsd3:         BSD, 3-clause, aka Revised/New/Modified
  bsd4:         BSD, 4-clause, aka Original
  gpl2:         GPL 2
  gpl3:         GPL 3
  lgpl2.1:      LGPL 2.1 (aliases: lgpl, lgpl2)
  mit:          MIT" >&2
  exit 1
fi<commit_msg>Do not duplicate license file path in variable.<commit_after>#!/bin/bash -eu
#
# Copyright 2009 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
################################################################################
#
# Outputs a header file comment, with the appropriate comments based on the
# language, as deduced from the extension of the file.
#
# Sample usage:
#   autogen.sh file.js
#   autogen.sh file.py

declare -r SRCDIR="${TEST_SRCDIR:-$(dirname $0)}"

# Path to license file will be computed from LICENSE_NAME below.
LICENSE_NAME="apache"
LICENSE_FILE=""
COPYRIGHT_HOLDER="Google Inc."
YEAR="${YEAR:-$(date +%Y)}"
MODIFY_FILE_INPLACE=0

function printLicenseWithYear() {
  cat "${LICENSE_FILE}" \
    | sed "s/%YEAR%/${YEAR}/" \
    | sed "s/%COPYRIGHT_HOLDER%/${COPYRIGHT_HOLDER}/"
}

function printLicenseNonHashComment() {
  printLicenseWithYear | sed -E "s#^#$1 #;s/ +$//"
}

function printLicenseHashComment() {
  printLicenseWithYear | sed -E "s/^/# /;s/ +$//"
}

# Prepend piped-in text to a file in-place.
#
# Args:
#   $1: filename to modify
function prependToFileInPlace() {
  local -r target="${1}"
  local -r tempfile="$(mktemp /tmp/$(basename $0).XXXXXX)"
  cat - "${target}" > "${tempfile}"
  mv -f "${tempfile}" "${target}"
  rm -f "${tempfile}"
}

readonly TODO_COMMENT="TODO: High-level file comment."
function printFileCommentTemplate() {
  local comment=$1
  # Fit into 80 cols: repeat enough times, depending on our comment width.
  local repeat=$(echo 80 / $(echo -n "${comment}" | wc -c) | bc)
  echo $comment
  perl -e "print \"$comment\" x $repeat . \"\n\""
  echo $comment
  echo "$comment ${TODO_COMMENT}"
}

while getopts c:il:y: opt ; do
  case "${opt}" in
    c)
      COPYRIGHT_HOLDER="${OPTARG}"
      ;;

    i)
      MODIFY_FILE_INPLACE=1
      ;;

    l)
      LICENSE_NAME="${OPTARG}"
      ;;

    y)
      YEAR="${OPTARG}"
      ;;
  esac
done

shift $((OPTIND - 1))

# Compute license file path given the license name.
case "${LICENSE_NAME}" in
  apache)
    LICENSE_FILE="${SRCDIR}/licenses/apache-2.0.txt"
    ;;
  bsd2|bsd-2)
    LICENSE_FILE="${SRCDIR}/licenses/bsd-2-clause.txt"
    ;;
  bsd3|bsd-3)
    LICENSE_FILE="${SRCDIR}/licenses/bsd-3-clause.txt"
    ;;
  bsd4|bsd-4)
    LICENSE_FILE="${SRCDIR}/licenses/bsd-4-clause.txt"
    ;;
  gpl2|gpl-2)
    LICENSE_FILE="${SRCDIR}/licenses/gpl-2.txt"
    ;;
  gpl3|gpl-3)
    LICENSE_FILE="${SRCDIR}/licenses/gpl-3.txt"
    ;;
  lgpl|lgpl2|lgpl-2|lgpl2.1|lgpl-2.1)
    LICENSE_FILE="${SRCDIR}/licenses/lgpl-2.1.txt"
    ;;
  mit)
    LICENSE_FILE="${SRCDIR}/licenses/mit.txt"
    ;;
  *)
    echo "Invalid license selected: ${LICENSE_NAME}" >&2
    exit 1
esac

if [[ $# -eq 0 ]]; then
  echo "\
Syntax: $0 [options] <filename>

Options:
  -c [copyright holder]    set copyright holder (default: "${COPYRIGHT_HOLDER}")
  -i                       modify the given file in-place
  -l [license]             choose the license (default: "${LICENSE_NAME}")
  -y [year]                choose the year (default: ${YEAR})

Licenses:
  apache:       Apache 2.0
  bsd2:         BSD, 2-clause, aka Simplified/FreeBSD
  bsd3:         BSD, 3-clause, aka Revised/New/Modified
  bsd4:         BSD, 4-clause, aka Original
  gpl2:         GPL 2
  gpl3:         GPL 3
  lgpl2.1:      LGPL 2.1 (aliases: lgpl, lgpl2)
  mit:          MIT" >&2
  exit 1
fi
{'fraction_non_alphanumeric': 0.16602366255144033, 'fraction_numerical': 0.01800411522633745, 'mean_word_length': 2.8461918892185953, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5640340', 'n_tokens_mistral': 2750, 'n_tokens_neox': 2630, 'n_words': 712}