#!/bin/sh
# Utility to rebuild the player index, should it become corrupt.
# It will correct corrupt pfiles to the extent that the mud will boot.
# Created 8/16/97
# Rewritten 6/12/98

rm -rf plr_index.fsh
for FILE in ?/*
do
  NAME=`echo $FILE | cut -d"/" -f 2 | cut -d" " -f 1`
  FG=`echo $NAME | grep [~,\.]`
  DELETED=`grep "Act :" $FILE |cut -d":" -f 2 | grep -c "k"`
  if [ ! $FG ]; then 
    if [ $DELETED != 1 ]; then 
      IDNUM=`grep "Id  :" $FILE |cut -d" " -f 4`
      [ ! $IDNUM ] && IDNUM=-1
      LEVEL=`grep "Levl:" $FILE |cut -d" " -f 2`
      [ ! $LEVEL ] && LEVEL=0
      RACE=`grep "Race:" $FILE |cut -d" " -f 2`
      [ ! $RACE ] && RACE=0
      PCLASS=`grep "Clas:" $FILE |cut -d" " -f 2`
      [ ! $PCLASS ] && PCLASS=0
      CLAN=`grep "Clan:" $FILE |cut -d" " -f 2`
      [ ! $CLAN ] && CLAN=0
      LAST=`grep "Last:" $FILE |cut -d" " -f 2`
      [ ! $LAST ] && LAST=0
      echo $NAME $IDNUM $LEVEL $RACE $PCLASS $CLAN $LAST >> plr_index.fsh
    fi
  fi
done
