Skip to content

Commit

Permalink
Revert "#124 printf.sh"
Browse files Browse the repository at this point in the history
This reverts commit c9b9dcc.
  • Loading branch information
yegor256 committed Oct 23, 2023
1 parent c9b9dcc commit 1a68470
Show file tree
Hide file tree
Showing 29 changed files with 62 additions and 126 deletions.
4 changes: 2 additions & 2 deletions filters/010-delete-non-java-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ while IFS= read -r f; do
done < "${list}"

if [ -s "${list}" ]; then
"${LOCAL}/help/printf.sh" "%'d files out of %'d without the \\\ff{.java} extension were deleted" \
printf "%'d files out of %'d without the \\\ff{.java} extension were deleted" \
"$(wc -l < "${list}" | xargs)" "${total}"
else
"${LOCAL}/help/printf.sh" "%'d files were \\\ff{.java} files, nothing was deleted" \
printf "%'d files were \\\ff{.java} files, nothing was deleted" \
"${total}"
fi
4 changes: 2 additions & 2 deletions filters/020-delete-package-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ while IFS= read -r f; do
done < "${list}"

if [ -s "${list}" ]; then
"${LOCAL}/help/printf.sh" "%'d files named as \\\ff{package-info.java} were deleted" \
printf "%'d files named as \\\ff{package-info.java} were deleted" \
"$(wc -l < "${list}" | xargs)"
else
"${LOCAL}/help/printf.sh" "There were no files named \\\ff{package-info.java}, nothing to delete"
printf "There were no files named \\\ff{package-info.java}, nothing to delete"
fi
4 changes: 2 additions & 2 deletions filters/030-delete-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ while IFS= read -r f; do
done < "${list}"

if [ -s "${list}" ]; then
"${LOCAL}/help/printf.sh" "%'d files out of %'d with \\\ff{Test} or \\\ff{ITCase} suffixes were deleted" \
printf "%'d files out of %'d with \\\ff{Test} or \\\ff{ITCase} suffixes were deleted" \
"$(wc -l < "${list}" | xargs)" "${total}"
else
"${LOCAL}/help/printf.sh" "There were no test files among %d files seen" "${total}"
printf "There were no test files among %d files seen" "${total}"
fi
6 changes: 3 additions & 3 deletions filters/040-delete-unparseable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ mkdir -p "$(dirname "${candidates}")"
find "${home}" -type f -name '*.java' -print > "${candidates}"
py=${LOCAL}/filters/delete-unparseable.py
while IFS= read -r f; do
"${LOCAL}/help/printf.sh" "python3 %s %s %s\n" "${py@Q}" "${f@Q}" "${list@Q}" >> "${jobs}"
printf "python3 %s %s %s\n" "${py@Q}" "${f@Q}" "${list@Q}" >> "${jobs}"
done < "${candidates}"
"${LOCAL}/help/parallel.sh" "${jobs}"
wait

total=$(wc -l < "${candidates}" | xargs)
if [ -s "${list}" ]; then
"${LOCAL}/help/printf.sh" "%'d files out of %'d with broken Java syntax were deleted" \
printf "%'d files out of %'d with broken Java syntax were deleted" \
"$(wc -l < "${list}" | xargs)" "${total}"
else
"${LOCAL}/help/printf.sh" "No files out of %'d had broken Java syntax" \
printf "No files out of %'d had broken Java syntax" \
"${total}"
fi
4 changes: 2 additions & 2 deletions filters/050-delete-long-lines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ done < "${candidates}"

total=$(wc -l < "${candidates}" | xargs)
if [ -s "${list}" ]; then
"${LOCAL}/help/printf.sh" "%'d files out of %'d with at least one line longer than %'d characters, which most probably is a symptom of an auto-generated code, were deleted" \
printf "%'d files out of %'d with at least one line longer than %'d characters, which most probably is a symptom of an auto-generated code, were deleted" \
"$(wc -l < "${list}" | xargs)" "${total}" "${max}"
else
"${LOCAL}/help/printf.sh" "No files out of %'d had lines longer than %'d characters" \
printf "No files out of %'d had lines longer than %'d characters" \
"${total}" "${max}"
fi
6 changes: 3 additions & 3 deletions filters/060-delete-non-classes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ mkdir -p "$(dirname "${candidates}")"
find "${home}" -type f -name '*.java' -print > "${candidates}"
py=${LOCAL}/filters/delete-non-classes.py
while IFS= read -r f; do
"${LOCAL}/help/printf.sh" "python3 %s %s %s\n" "${py@Q}" "${f@Q}" "${list@Q}" >> "${jobs}"
printf "python3 %s %s %s\n" "${py@Q}" "${f@Q}" "${list@Q}" >> "${jobs}"
done < "${candidates}"
"${LOCAL}/help/parallel.sh" "${jobs}"
wait

total=$(wc -l < "${candidates}" | xargs)
if [ -s "${list}" ]; then
"${LOCAL}/help/printf.sh" "%'d files out of %'d with interfaces or enums (instead of classes) inside were deleted" \
printf "%'d files out of %'d with interfaces or enums (instead of classes) inside were deleted" \
"$(wc -l < "${list}" | xargs)" "${total}"
else
"${LOCAL}/help/printf.sh" "All %d files are Java classes, nothing to delete" \
printf "All %d files are Java classes, nothing to delete" \
"${total}"
fi
8 changes: 4 additions & 4 deletions filters/070-delete-invalid-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ mkdir -p "$(dirname "${candidates}")"
find "${home}" -type f -name '*.java' -print > "${candidates}"
py=${LOCAL}/filters/delete-invalid-files.py
while IFS= read -r f; do
"${LOCAL}/help/printf.sh" "python3 %s %s %s\n" "${py@Q}" "${f@Q}" "${list@Q}" >> "${jobs}"
printf "python3 %s %s %s\n" "${py@Q}" "${f@Q}" "${list@Q}" >> "${jobs}"
done < "${candidates}"
"${LOCAL}/help/parallel.sh" "${jobs}"
wait

total=$(wc -l < "${candidates}" | xargs)
if [ -s "${list}" ]; then
"${LOCAL}/help/printf.sh" "%'d files out of %'d with more than one Java class inside were deleted" \
printf "%'d files out of %'d with more than one Java class inside were deleted" \
"$(wc -l < "${list}")" "${total}"
else
if [ "${total}" -eq 0 ]; then
"${LOCAL}/help/printf.sh" "There were no Java classes, nothing to delete"
printf "There were no Java classes, nothing to delete"
else
"${LOCAL}/help/printf.sh" "All %'d files are Java classes, nothing to delete" \
printf "All %'d files are Java classes, nothing to delete" \
"${total}"
fi
fi
4 changes: 2 additions & 2 deletions filters/080-delete-symlinks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ done

total=$(wc -l < "${list}" | xargs)
if [ "${total}" -eq 0 ]; then
"${LOCAL}/help/printf.sh" "There were no symlinks"
printf "There were no symlinks"
else
"${LOCAL}/help/printf.sh" "%'d symlinks were deleted" "${total}"
printf "%'d symlinks were deleted" "${total}"
fi

4 changes: 2 additions & 2 deletions filters/090-delete-empty-directories.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ done

total=$(wc -l < "${list}" | xargs)
if [ "${total}" -eq 0 ]; then
"${LOCAL}/help/printf.sh" "There were no empty directories"
printf "There were no empty directories"
else
"${LOCAL}/help/printf.sh" "%'d empty directories were deleted" "${total}"
printf "%'d empty directories were deleted" "${total}"
fi

4 changes: 2 additions & 2 deletions help/float.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ set -o pipefail
num=$(cat)

if [ "${num}" == 'NaN' ]; then
"${LOCAL}/help/printf.sh" '%s' "${num}"
printf '%s' "${num}"
exit
fi

("${LOCAL}/help/printf.sh" '%.8f' "${num}" 2>/dev/null || echo 0) | sed -e 's/0\+$//' | sed -e 's/\.$//'
(printf '%.8f' "${num}" 2>/dev/null || echo 0) | sed -e 's/0\+$//' | sed -e 's/\.$//'
31 changes: 0 additions & 31 deletions help/printf.sh

This file was deleted.

10 changes: 5 additions & 5 deletions help/tdiff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ mks=$(echo "($(date +%s%N) - ${start}) / 1000" | bc)
if ((mks < 100)); then
exit
elif ((mks < 1000)); then
"${LOCAL}/help/printf.sh" '%s%dμs' "${pfx}" "${mks}"
printf '%s%dμs' "${pfx}" "${mks}"
elif ((mks < 1000 * 1000)); then
"${LOCAL}/help/printf.sh" '%s%dms' "${pfx}" "$((mks / 1000))"
printf '%s%dms' "${pfx}" "$((mks / 1000))"
elif ((mks < 60 * 1000 * 1000)); then
"${LOCAL}/help/printf.sh" '%s%ds' "${pfx}" "$((mks / (1000 * 1000)))"
printf '%s%ds' "${pfx}" "$((mks / (1000 * 1000)))"
elif ((mks < 60 * 60 * 1000 * 1000)); then
minutes=$((mks / (60 * 1000 * 1000)))
seconds=$(((mks - minutes * 60 * 1000 * 1000) / (1000 * 1000)))
"${LOCAL}/help/printf.sh" '%s%dm%ds' "${pfx}" "${minutes}" "${seconds}"
printf '%s%dm%ds' "${pfx}" "${minutes}" "${seconds}"
else
hours=$((mks / (60 * 60 * 1000 * 1000)))
minutes=$(((mks - hours * 60 * 60 * 1000 * 1000) / (60 * 1000 * 1000)))
"${LOCAL}/help/printf.sh" '%s%dh%dm' "${pfx}" "${hours}" "${minutes}"
printf '%s%dh%dm' "${pfx}" "${hours}" "${minutes}"
fi
2 changes: 1 addition & 1 deletion help/to-csv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ set -o pipefail
# suitable for CSV: replacing commas.

data=$(cat)
"${LOCAL}/help/printf.sh" '%s' "${data}" | sed 's/,/\\,/'
printf '%s' "${data}" | sed 's/,/\\,/'
4 changes: 2 additions & 2 deletions steps/aggregate-join.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ echo "${csvs}" | while IFS= read -r csv; do
mkdir -p "$(dirname "${join}")"
while IFS= read -r t; do
if [ ! -e "${join}" ]; then
"${LOCAL}/help/printf.sh" 'repo,%s\n' "${t}" > "${join}"
printf 'repo,%s\n' "${t}" > "${join}"
else
"${LOCAL}/help/printf.sh" '%s,%s\n' "$(echo "${repo}" | "${LOCAL}/help/to-csv.sh")" "${t}" >> "${join}"
printf '%s,%s\n' "$(echo "${repo}" | "${LOCAL}/help/to-csv.sh")" "${t}" >> "${join}"
fi
done < "${dir}/${csv}"
done
Expand Down
18 changes: 9 additions & 9 deletions steps/aggregate-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,33 @@ find "${dir}" -type f -name '*.m' | {
csv=${ddir}/${metric}.csv
mkdir -p "$(dirname "${csv}")"
if [ ! -e "${csv}" ]; then
"${LOCAL}/help/printf.sh" 'java_file,%s\n' "${metric}" > "${csv}"
printf 'java_file,%s\n' "${metric}" > "${csv}"
fi
"${LOCAL}/help/printf.sh" '%s,%s\n' "$(echo "${java}" | "${LOCAL}/help/to-csv.sh")" "$(cat "${v}")" >> "${csv}"
printf '%s,%s\n' "$(echo "${java}" | "${LOCAL}/help/to-csv.sh")" "$(cat "${v}")" >> "${csv}"
done
csv=${ddir}/all.csv
mkdir -p "$(dirname "${csv}")"
if [ ! -e "${csv}" ]; then
"${LOCAL}/help/printf.sh" 'java_file' > "${csv}"
printf 'java_file' > "${csv}"
for a in ${metrics}; do
"${LOCAL}/help/printf.sh" ",%s" "${a}" >> "${csv}"
printf ",%s" "${a}" >> "${csv}"
done
"${LOCAL}/help/printf.sh" '\n' >> "${csv}"
printf '\n' >> "${csv}"
fi
java=$(echo "${m}" | sed "s|${dir}||" | sed "s|\.m$||")
"${LOCAL}/help/printf.sh" '%s' "$(echo "${java}" | "${LOCAL}/help/to-csv.sh")" >> "${csv}"
printf '%s' "$(echo "${java}" | "${LOCAL}/help/to-csv.sh")" >> "${csv}"
for a in ${metrics}; do
if [ -e "${m}.${a}" ]; then
value=$("${LOCAL}/help/float.sh" < "${m}.${a}")
"${LOCAL}/help/printf.sh" ",%s" "${value}" >> "${csv}"
printf ",%s" "${value}" >> "${csv}"
if [ ! "${value}" = "NaN" ]; then
sum=$(echo "${sum} + ${value}" | bc | "${LOCAL}/help/float.sh")
fi
else
"${LOCAL}/help/printf.sh" ',-' >> "${csv}"
printf ',-' >> "${csv}"
fi
done
"${LOCAL}/help/printf.sh" '\n' >> "${csv}"
printf '\n' >> "${csv}"
total=$((total+1))
done
echo "${repo} (${pos}/${total}) aggregated (files=${total}, sum=${sum})$("${LOCAL}/help/tdiff.sh" "${start}")"
Expand Down
10 changes: 5 additions & 5 deletions steps/aggregate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ declare -i repo=0
sh="$(dirname "$0")/aggregate-repo.sh"
echo "${repos}" | while IFS= read -r r; do
repo=$((repo+1))
"${LOCAL}/help/printf.sh" "%s %s %s %s %s\n" "${sh@Q}" "${r@Q}" "${repo@Q}" "${total@Q}" "${metrics@Q}" >> "${jobs}"
printf "%s %s %s %s %s\n" "${sh@Q}" "${r@Q}" "${repo@Q}" "${total@Q}" "${metrics@Q}" >> "${jobs}"
done
"${LOCAL}/help/parallel.sh" "${jobs}"
wait

mkdir -p "${TARGET}/data"
rm -rf "${TARGET}/data/*.csv"
all=${TARGET}/data/all.csv
"${LOCAL}/help/printf.sh" "repository,file" >> "${all}"
printf "repository,file" >> "${all}"
echo "${metrics}" | while IFS= read -r a; do
"${LOCAL}/help/printf.sh" ',%s' "${a}" >> "${all}"
printf ',%s' "${a}" >> "${all}"
done
"${LOCAL}/help/printf.sh" "\n" >> "${all}"
printf "\n" >> "${all}"

jobs=${TARGET}/temp/jobs/aggregate-join-jobs.txt
rm -rf "${jobs}"
Expand All @@ -64,7 +64,7 @@ repos=$(find "${TARGET}/data" -maxdepth 2 -mindepth 2 -type d -print)
echo "${repos}" | while IFS= read -r d; do
r=$(realpath --relative-to="${TARGET}/data" "${d}" )
repo=$((repo+1))
"${LOCAL}/help/printf.sh" "%s %s %s %s %s\n" "${sh@Q}" "${r@Q}" "${d@Q}" "${repo@Q}" "${total@Q}" >> "${jobs}"
printf "%s %s %s %s %s\n" "${sh@Q}" "${r@Q}" "${d@Q}" "${repo@Q}" "${total@Q}" >> "${jobs}"
done
"${LOCAL}/help/parallel.sh" "${jobs}"
wait
Expand Down
4 changes: 2 additions & 2 deletions steps/clone-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ done

hashes=${TARGET}/hashes.csv
if [ ! -e "${hashes}" ]; then
"${LOCAL}/help/printf.sh" "repo,hash\n" > "${hashes}"
printf "repo,hash\n" > "${hashes}"
fi
"${LOCAL}/help/printf.sh" "%s,%s\n" "$(echo "${repo}" | "${LOCAL}/help/to-csv.sh")" "$(git --git-dir "${dir}/.git" rev-parse HEAD)" >> "${hashes}"
printf "%s,%s\n" "$(echo "${repo}" | "${LOCAL}/help/to-csv.sh")" "$(git --git-dir "${dir}/.git" rev-parse HEAD)" >> "${hashes}"

echo "${repo} cloned (${pos}/${total}), $(du -sh "${dir}" | cut -f1 | xargs)$("${LOCAL}/help/tdiff.sh" "${start}")"
2 changes: 1 addition & 1 deletion steps/clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ while IFS=',' read -r r tag tail; do
if [ -e "${TARGET}/github/${r}" ]; then
echo "${r}: Git repo is already here (${tail})"
else
"${LOCAL}/help/printf.sh" "%s %s %s %s %s\n" "${sh@Q}" "${r@Q}" "${tag@Q}" "${repo@Q}" "${total@Q}" >> "${jobs}"
printf "%s %s %s %s %s\n" "${sh@Q}" "${r@Q}" "${tag@Q}" "${repo@Q}" "${total@Q}" >> "${jobs}"
fi
done < "${repos}"

Expand Down
6 changes: 3 additions & 3 deletions steps/discover.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ if [ -e "${csv}" ]; then
echo "Before using REPO environment variable you should delete the ${csv} file ($(wc -l < "${csv}" | xargs) lines)"
clones=${TARGET}/github
if [ -e "${clones}" ]; then
"${LOCAL}/help/printf.sh" "ATTENTION: If you do this (delete the CSV file), and then run 'make' again, all cloned repositories in the '%s' directory will be deleted (%d directories). " \
printf "ATTENTION: If you do this (delete the CSV file), and then run 'make' again, all cloned repositories in the '%s' directory will be deleted (%d directories). " \
"${TARGET}/github/" "$(find "${clones}" -type d -depth 2 | wc -l | xargs)"
"${LOCAL}/help/printf.sh" "After this, the dataset will not be suitable for further analysis! "
"${LOCAL}/help/printf.sh" "Think twice! If you just want to analyze one repository, do it in a different directory.\n"
printf "After this, the dataset will not be suitable for further analysis! "
printf "Think twice! If you just want to analyze one repository, do it in a different directory.\n"
fi
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion steps/jpeek-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ mkdir -p "$(dirname "${values}")"
echo > "${values}"
files=${TARGET}/temp/jpeek-files/${repo}.txt
mkdir -p "$(dirname "${files}")"
"${LOCAL}/help/printf.sh" '' > "${files}"
printf '' > "${files}"
for type in all cvc; do
dir=${TARGET}/temp/jpeek/${type}/${repo}
if [ ! -e "${dir}" ]; then
Expand Down
2 changes: 1 addition & 1 deletion steps/jpeek.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ sh="$(dirname "$0")/jpeek-repo.sh"
for d in ${repos}; do
r=$(realpath --relative-to="${TARGET}/github" "${d}" )
repo=$((repo+1))
"${LOCAL}/help/printf.sh" "timeout 1h %s %s %s %s || true\n" "${sh@Q}" "${r@Q}" "${repo@Q}" "${total@Q}" >> "${jobs}"
printf "timeout 1h %s %s %s %s || true\n" "${sh@Q}" "${r@Q}" "${repo@Q}" "${total@Q}" >> "${jobs}"
done

"${LOCAL}/help/parallel.sh" "${jobs}"
Expand Down
2 changes: 1 addition & 1 deletion steps/measure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ echo "${javas}" | while IFS= read -r java; do
echo "Metrics already exist for $(basename "${java}") (${file}/${total})"
continue
fi
"${LOCAL}/help/printf.sh" "%s %s %s %s %s\n" "${sh@Q}" "${java@Q}" "${javam@Q}" "${file@Q}" "${total@Q}" >> "${jobs}"
printf "%s %s %s %s %s\n" "${sh@Q}" "${java@Q}" "${javam@Q}" "${file@Q}" "${total@Q}" >> "${jobs}"
if [ "${file: -4}" = '0000' ]; then
echo "Prepared ${file} jobs out of ${total}$("${LOCAL}/help/tdiff.sh" "${pstart}")..."
pstart=$(date +%s%N)
Expand Down
2 changes: 1 addition & 1 deletion steps/unregister.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ while IFS=',' read -r r tag tail; do
if [ ! -e "${TARGET}/github/${r}" ]; then
echo "The clone of ${r} is absent, unregistered"
else
"${LOCAL}/help/printf.sh" "%s,%s,%s\n" "${r}" "${tag}" "${tail}" >> "${csv}"
printf "%s,%s,%s\n" "${r}" "${tag}" "${tail}" >> "${csv}"
good=$((good+1))
fi
done < "${before}"
Expand Down
4 changes: 2 additions & 2 deletions tests/filters/test-050-delete-long-lines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ echo "👍🏻 A Java file with short lines wasn't deleted"
{
java="${temp}/foo/bb/Привет.java"
mkdir -p "$(dirname "${java}")"
"${LOCAL}/help/printf.sh" 'a%.0s' {1..5000} > "${java}"
printf 'a%.0s' {1..5000} > "${java}"
rm -f "${list}"
msg=$("${LOCAL}/filters/050-delete-long-lines.sh" "${temp}" "${temp}/temp")
echo "${msg}"
Expand All @@ -60,7 +60,7 @@ echo "👍🏻 A Java file with a long line was deleted"
# see https://stackoverflow.com/questions/77169978/how-to-reproduce-awk-warning-invalid-multibyte-data-detected
java="${temp}/foo/bb/привет/Привет.java"
mkdir -p "$(dirname "${java}")"
"${LOCAL}/help/printf.sh" '\xC0\x80' > "${java}"
printf '\xC0\x80' > "${java}"
rm -f "${list}"
msg=$(LC_ALL=en_US.UTF-8 "${LOCAL}/filters/050-delete-long-lines.sh" "$(dirname "${java}")" "${temp}/temp" 2>&1)
test "$(echo "${msg}" | grep -c "Invalid multibyte data detected")" = 0
Expand Down
2 changes: 1 addition & 1 deletion tests/help/test-float.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
n#!/usr/bin/env bash
#!/usr/bin/env bash
# The MIT License (MIT)
#
# Copyright (c) 2021-2023 Yegor Bugayenko
Expand Down
Loading

0 comments on commit 1a68470

Please sign in to comment.