createPatterns.sh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #! /bin/bash
  2. if [ $# != 2 ]; then
  3. echo "Usage: $0 [Directory] [2 symbols language code]";
  4. exit 1;
  5. fi
  6. if ! [ -d $1 ]; then
  7. echo "Error: $1 is not directory or doesn't exist";
  8. exit 1;
  9. fi
  10. GENERATORPATH=$(pwd) >> /dev/null
  11. pushd $1 >> /dev/null
  12. if ! [ -e ./encodings ]; then
  13. echo "Configuration file \"encodings\" doesn't exist";
  14. popd >> /dev/null;
  15. exit 1;
  16. else
  17. echo "Patterns for directory $1 is creating"
  18. if ! [ -d ./temp ]; then
  19. mkdir temp
  20. fi
  21. SOURCE_ENCODING=$(cat ./encodings | line);
  22. for TARGET_ENCODING in $(cat ./encodings)
  23. do
  24. echo "$2_$TARGET_ENCODING"
  25. for txtfile in *.txt
  26. do
  27. if [ $TARGET_ENCODING != $SOURCE_ENCODING ]; then
  28. iconv -c -f $SOURCE_ENCODING -t $TARGET_ENCODING $txtfile > tmp;
  29. mv tmp "./temp/$TARGET_ENCODING"_"$txtfile";
  30. #echo "./temp/$TARGET_ENCODING"_"$txtfile";
  31. else
  32. cp $txtfile ./temp/
  33. fi
  34. done
  35. $GENERATORPATH/PatternGenerator ./temp/
  36. mv ./temp/pattern.stat $GENERATORPATH/patterns/$2_$TARGET_ENCODING
  37. rm ./temp/*
  38. done
  39. rmdir temp
  40. fi
  41. popd >> /dev/null;
  42. exit 0