Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11341) convert old savegames character encodings
Home

[Freeciv-Dev] (PR#11341) convert old savegames character encodings

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11341) convert old savegames character encodings
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 4 Dec 2004 19:45:36 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=11341 >

This script will convert old savegames (in latin1) into the new format 
(in UTF-8).  Run it with no parameters to get some short help.  Back up 
your saved games before using it!

Another alternative is to have Freeciv take care of this automatically. 
  This wouldn't be that hard.  We'd have to change the registry code to 
convert from the secfile's encoding into the internal encoding on load. 
  The secfile's encoding would have to be set before starting the load. 
  I had thought the encoding was stored in the savegame but perhaps this 
isn't done correctly.

-jason

#!/bin/bash

files="$@"

if test "$files" = ""; then
  echo "Usage: $0 <file1> [<file2> [...]]"
  echo
  echo "This program will convert freeciv savegames from the 1.14 format "
  echo "into 2.0 format."
  echo
  echo "In 1.14 charsets were usually stored in an ISO-8859-1 (latin1) "
  echo "encoding.  If you used a different encoding you may set the "
  echo "SRC_CHARSET environment variable to convert from that encoding "
  echo "instead.  See the FAQ at http://freeciv.org/ for more information."
fi

if test "$DST_CHARSET" = ""; then
  DST_CHARSET="UTF-8"
fi
if test "$SRC_CHARSET" = ""; then
  SRC_CHARSET="ISO-8859-1"
fi

error=0
unchanged=""

for file in $files; do
  tmp_file="$file.$$"

  echo "Converting $file from $SRC_CHARSET to $DST_CHARSET."
  if echo $file | grep "\.gz\$" >/dev/null; then
    zcat $file | iconv -f "$SRC_CHARSET" -t "$DST_CHARSET//TRANSLIT" | gzip -c 
> $tmp_file
    if test "$?" != "0"; then
      error=1
    fi
  else
    cat $file | iconv -f "$SRC_CHARSET" -t "$DST_CHARSET//TRANSLIT" > $tmp_file
  fi
  if test "$?" != "0"; then
    error=1
    unchanged="$unchanged $file"
  else
    rm "$file"
    mv "$tmp_file" "$file"
  fi
done

if test "$error" != "0"; then
  echo "Some files could not be correctly converted.  The following files "
  echo "have been left unchanged:"
  echo "$unchanged"
fi

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11341) convert old savegames character encodings, Jason Short <=