#!/usr/bin/env bash
#/***********************************************************************
# Freeciv - Copyright (C) 2017-2023
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2, or (at your option)
#   any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#***********************************************************************/

if test "$1" = "-h" || test "$1" = "--help" || test "$3" = "" ; then
  echo "Usage: $0 <path> <string to replace> <replace with>"
  exit
fi

find "$1" -name "*.[ch]" |
  (while read FILE ; do
     if grep "$2" "$FILE" >/dev/null ; then
       echo "Updating $FILE"
       sed "s/$2/$3/g" "$FILE" > "$FILE.new"
       mv "$FILE.new" "$FILE"
     fi
   done )
