#!/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.
#
#***********************************************************************/

domains="core nations ruledit"

if test "$1" == "" ; then
  echo Usage: $0 '<path to source root directory with trailing slash>'
  exit 1;
fi

for domain in $domains ; do
  if ! test -f $1/translations/$domain/POTFILES.in ; then
    echo "Cannot find $1/translations/$domain/POTFILES.in" >&2
    exit 1
  fi
  POTLIST="$POTLIST $1/translations/$domain/POTFILES.in"
done

cat $POTLIST | grep -v "^#" | sed "s,^,$1," | sort > /tmp/potfile

echo Suggestions for addition or removal of files with translatable strings to/from POTFILES.in:
echo Please check the output manually

find "$1" -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.sav' -o -name '*.lua' -o -name '*.ruleset' -o -name '*.tilespec' -o -name '*.txt' -o -name '*.in' |
  xargs grep -l -I '_("' |
    sort |
      diff -u /tmp/potfile - |
        grep -E '^[+-]'
