frodo.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. #
  3. # "How do you pick up the threads of an old life?
  4. # How do you go on, when in your heart you begin
  5. # to understand... there is no going back?
  6. # There are some things that time cannot mend.
  7. # Some hurts that go too deep, that have taken hold."
  8. # Frodo, The Return of the King
  9. #
  10. #
  11. # This script shall repair the patches for the little
  12. # broken programs using the old patches in this directory
  13. # first, to heal them and then create new and better
  14. # patches, with Gollum's help.
  15. #
  16. set -e
  17. # We check ourselves before we wreck ourselves.
  18. if [ ! -f patches/frodo.sh ]
  19. then
  20. echo "But I must be run from the project root directory."
  21. exit 1
  22. fi
  23. # Create directory of answers if it doesn't already exist.
  24. mkdir -p answers
  25. # Cycle through all the little broken Zig applications.
  26. i=0
  27. for broken in exercises/*.zig
  28. do
  29. ((i=i+1))
  30. # Remove the dir and extension, rendering the True Name.
  31. true_name=$(basename "$broken" .zig)
  32. patch_name="patches/patches/$true_name.patch"
  33. healed_name="answers/$true_name.zig"
  34. cp "$broken" "$healed_name"
  35. # echo "$patch_name"
  36. if [ -f "$patch_name" ]
  37. then
  38. # Apply the bandages to the wounds, grow new limbs, let
  39. # new life spring into the broken bodies of the fallen.
  40. echo Healing "$true_name"...
  41. patch -i "$patch_name" "$healed_name"
  42. # Create new prescriptions...
  43. echo Repairing "$patch_name"...
  44. if [ "$true_name.patch" = "999_the_end.patch" ]
  45. then
  46. i=999
  47. fi
  48. # with gollum's help!
  49. ./patches/gollum.sh $i
  50. else
  51. echo Cannot repair "$true_name". No patch found.
  52. fi
  53. done