#!/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 "x$1" = "x-h" || test "x$1" = "x--help" || test "x$3" = "x" ; 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 )
