#!/bin/sh

# This script will convert an msieve stlye polynomial .fb file
# into the format expected by the ggnfs tools and siever.
# Original version of this script contributed by: tmorrow
#
# Usage:  ./convertpoly filename_base

MSIEVE_FB="msieve.fb"

if [ "$1" == "" ]
then
  echo "Usage: `basename $0` poly_filename_base"
  echo ""
  echo "Example: `basename $0` C113_109_41"
  echo "         will convert file $MSIEVE_FB to C113_109_41.poly"
  exit -1
fi

echo "Converting $MSIEVE_FB to $1.poly ..."

echo "type: gnfs" | sed '
s/^N/n:/
s/^SKEW/skew:/
s/^R\(.\)/Y\1:/
s/^A\(.\)/c\1:/
' $MSIEVE_FB - | awk '
{
  if ($1=="skew:")
    skew=$0
  else if ($1=="type:")
    type=$0
  else
    print
}
END {
  print skew
  print type
}
' > $1.poly

echo "Done."

