diff --git a/ChangeLog b/ChangeLog index 83ebaee71..14fec14d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-05-20 16:01 anmaster + * brest/pshops/pshop_copier: Update the script to make it work correctly, + it assumed too much about the layout of the file, so it was broken. + New script should be somewhat more robust. + 2008-05-18 19:37 rednaxela * mlab/citydeclouds/*, darcap/darcap/pirates.1, diff --git a/brest/pshops/pshop_copier b/brest/pshops/pshop_copier index 2936f1512..4dcb9a358 100755 --- a/brest/pshops/pshop_copier +++ b/brest/pshops/pshop_copier @@ -16,70 +16,80 @@ mv pshop1 PSHOP rm -f pshop*/* #copy PSHOP to all the pshop directories -for FILE in pshop*;do - if [ -d "$FILE" ] - then - #copy the files into the pshops directories - cp PSHOP/* "$FILE"/ +for FILE in pshop*; do + if [[ -d "$FILE" ]]; then + #copy the files into the pshops directories + cp PSHOP/* "${FILE}/" - #go there - cd $FILE + #go there + cd $FILE - #for each file in the pshop directory - for MYFILE in *;do - #correct the key values on inventory checkers - sed s/pshop1/$FILE/ $MYFILE > "$MYFILE"_2 - rm -f $MYFILE - mv "$MYFILE"_2 $MYFILE - done + #for each file in the pshop directory + for MYFILE in *; do + #correct the key values on inventory checkers + sed "s/pshop1/${FILE}/" "$MYFILE" > "${MYFILE}_2" + rm -f $MYFILE + mv "${MYFILE}_2" $MYFILE + done - #get the pshopnum - PSHOPNUM=`echo "$FILE" | cut -d p -f3` + #get the pshopnum + PSHOPNUM=$(cut -d p -f3 <<< "$FILE") - #calculate HP and SP based on pshopnum - if [ $PSHOPNUM -lt 14 ] - then - #top row of shops - SP="2" - TEMPHP=`expr $PSHOPNUM \* 3` - HP=`expr $TEMPHP + 1` - else - #bottom row of shops - SP="6" - MODPSHOPNUM=`expr $PSHOPNUM - 14` - TEMPHP=`expr $MODPSHOPNUM \* 3` - HP=`expr $TEMPHP + 1` + #calculate HP and SP based on pshopnum + if [[ $PSHOPNUM -lt 14 ]]; then + #top row of shops + SP="2" + HP=$(( PSHOPNUM * 3 + 1 )) + else + #bottom row of shops + SP="6" + MODPSHOPNUM=$(( PSHOPNUM - 14 )) + HP=$(( MODPSHOPNUM * 3 + 1 )) + fi + + # Keep track of state when parsing. + # 0 Before/after exit, looking for slaying + # 1 During exit, looking for hp and sp + state=0 + hadhp=0 + hadsp=0 + #fix the exit on gfloor + while read LINE; do + case $state in + 0) + if [[ "$LINE" == "slaying ../pshops_main" ]]; then + state=1 + fi + echo "$LINE" >> gfloor2 + ;; + 1) + case $LINE in + "hp "*) + echo "hp $HP" >> gfloor2 + hadhp=1 + ;; + "sp "*) + echo "sp $SP" >> gfloor2 + hadsp=1 + ;; + *) + echo "$LINE" >> gfloor2 + ;; + esac + if [[ ( $hadhp == 1 ) && ( $hadsp == 1 ) ]]; then + state=1 + fi + ;; + esac + done < gfloor + + #replace gfloor with gfloor2 + rm -f gfloor + mv gfloor2 gfloor + + #go back up + cd .. fi - - #fix the exit on gfloor - while read LINE - do - if [ "$LINE" == "slaying ../pshops_main" ] - then - #remove the 2 lines - read dummy_hp_line - read dummp_sp_line - - #add the original back - echo "$LINE" >> gfloor2 - - #write the new lines - echo "hp $HP" >> gfloor2 - echo "sp $SP" >> gfloor2 - - else - #just add it back to the file - echo "$LINE" >> gfloor2 - fi - done < gfloor - - #replace gfloor with gfloor2 - rm -f gfloor - mv gfloor2 gfloor - - #go back up - cd .. - fi done #put pshop1 back