2025-02-28 08:38:23 +07:00
|
|
|
#!/bin/bash
|
|
|
|
|
2025-02-28 10:22:52 +07:00
|
|
|
# Check if input file is provided
|
|
|
|
if [ $# -ne 1 ]; then
|
|
|
|
echo "Usage: $0 <input_file>"
|
2025-02-28 10:14:34 +07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2025-02-28 10:22:52 +07:00
|
|
|
input_file="$1"
|
|
|
|
|
|
|
|
# Check if input file exists
|
|
|
|
if [ ! -f "$input_file" ]; then
|
|
|
|
echo "Error: File '$input_file' not found"
|
2025-02-28 08:38:23 +07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2025-02-28 10:22:52 +07:00
|
|
|
changes_made=0
|
2025-02-28 10:14:34 +07:00
|
|
|
|
2025-02-28 10:22:52 +07:00
|
|
|
# Process each line
|
2025-02-28 09:46:43 +07:00
|
|
|
while IFS=':' read -r file_path line_err status desc data; do
|
2025-02-28 10:22:52 +07:00
|
|
|
# Trim whitespace from all parts (both leading and trailing)
|
|
|
|
file_path=$(echo "$file_path" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
|
|
|
line_err=$(echo "$line_err" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
|
|
|
status=$(echo "$status" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
|
|
|
desc=$(echo "$desc" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
|
|
|
data=$(echo "$data" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
2025-02-28 10:14:34 +07:00
|
|
|
|
2025-02-28 10:22:52 +07:00
|
|
|
echo "DEBUG: Processing line:"
|
|
|
|
echo "DEBUG: file_path=[$file_path]"
|
|
|
|
echo "DEBUG: line_err=[$line_err]"
|
|
|
|
echo "DEBUG: status=[$status]"
|
|
|
|
echo "DEBUG: desc=[$desc]"
|
|
|
|
echo "DEBUG: data=[$data]"
|
2025-02-28 09:46:43 +07:00
|
|
|
|
2025-02-28 10:22:52 +07:00
|
|
|
# Check if file exists and description matches conditions
|
|
|
|
if [ -f "$file_path" ]; then
|
|
|
|
echo "DEBUG: File exists: $file_path"
|
|
|
|
|
|
|
|
if [ "$desc" = "undefined label" ]; then
|
|
|
|
echo "DEBUG: Found 'undefined label' case"
|
|
|
|
# Replace \, /, or _ with - in data
|
|
|
|
new_data=$(echo "$data" | tr '\\/_' '-')
|
|
|
|
echo "DEBUG: Changing '$data' to '$new_data'"
|
|
|
|
# Replace the old data with new data in the file
|
|
|
|
if sed -i "s|$data|$new_data|g" "$file_path"; then
|
|
|
|
changes_made=$((changes_made + 1))
|
|
|
|
echo "Processed: $file_path - Changed '$data' to '$new_data'"
|
2025-02-28 10:14:34 +07:00
|
|
|
else
|
2025-02-28 10:22:52 +07:00
|
|
|
echo "WARNING: Failed to modify $file_path"
|
2025-02-28 10:14:34 +07:00
|
|
|
fi
|
|
|
|
|
2025-02-28 10:22:52 +07:00
|
|
|
elif [[ "$desc" =~ "toctree contains reference to nonexisting document" ]]; then
|
|
|
|
echo "DEBUG: Found 'toctree' case"
|
|
|
|
# Extract the document reference from data (assuming it's in single quotes)
|
|
|
|
doc_ref=$(echo "$data" | grep -o "'[^']*'" | tr -d "'")
|
|
|
|
if [ -n "$doc_ref" ]; then
|
|
|
|
# Replace \, /, or _ with - in doc_ref
|
|
|
|
new_data=$(echo "$doc_ref" | tr '\\/_' '-')
|
|
|
|
echo "DEBUG: Changing '$doc_ref' to '$new_data'"
|
|
|
|
# Replace the old data with new data in the file
|
|
|
|
if sed -i "s|$doc_ref|$new_data|g" "$file_path"; then
|
|
|
|
changes_made=$((changes_made + 1))
|
|
|
|
echo "Processed: $file_path - Changed '$doc_ref' to '$new_data'"
|
|
|
|
else
|
|
|
|
echo "WARNING: Failed to modify $file_path"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "WARNING: Could not extract document reference from '$data' in $file_path"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "DEBUG: Description '$desc' doesn't match any conditions"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "WARNING: File not found: $file_path"
|
|
|
|
fi
|
|
|
|
echo "DEBUG: ---"
|
2025-02-28 10:14:34 +07:00
|
|
|
|
2025-02-28 10:22:52 +07:00
|
|
|
done < "$input_file"
|
2025-02-28 10:14:34 +07:00
|
|
|
|
2025-02-28 10:22:52 +07:00
|
|
|
echo "Processing completed!"
|
|
|
|
echo "Total changes made: $changes_made"
|