SHARE
TWEET

Untitled

a guest May 25th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. changeChar() {  #line $1 change $2 to $3
  4.     change="$( echo "$1" | tr "$2" "$3" )"
  5.     echo "$change"
  6. }
  7. #text='if ( "the end" > 365 ) then'
  8. #echo "oryginal $text"
  9. #changeChar "$text" '(' '['
  10.  
  11. changeWord() {  #line $1 change $2 to $3
  12.     change="$( echo "$1" | sed "s/$2/$3/" )"
  13.     echo "$change"
  14. }
  15. #text='hello sara , my name is sara too .'
  16. #echo "$text"
  17. #changeWord "$text" 'sara' 'mary'
  18.  
  19. deleteWord() {  #line $1 word to delete $2
  20.     change="$( echo "$1" | sed "s/$2//" )"
  21.     echo "$change"
  22. }
  23. #text='hello sara , my name is sara too .'
  24. #echo "$text"
  25. #deleteWord "$text" 'hello'
  26.  
  27.  
  28. findWordByID() {    #line $1 ID word $2 | $1-first word $2-seccond ...
  29.     change="$( echo "$1" | awk "{print $2;}" )"
  30.     echo "$change"
  31. }
  32. #text='Word1 Word2 Word3 if'
  33. #echo "$text"
  34. #findWordByID "$text" '$2'
  35.  
  36. findWord() {    #line $1 word $2
  37.     #change="$( echo $1 | awk '{print match($0,">");}' )"
  38.     change="$( echo $1 | grep -c "$2" )"
  39.     echo "$change"
  40. }
  41. #text='if ( "the end" > 365 ) then'
  42. #echo "$text"
  43. #findWord "$text" '>'
  44.  
  45. signsInequality() { #sign $1
  46.     if [ `findWord "$1" '\-eq'` -ge 1 ]
  47.     then
  48.         line=`changeWord "$1" '-eq' '=='`
  49.     fi
  50.     if [ `findWord "$1" '\-ne'` -ge 1 ]
  51.     then
  52.         line=`changeWord "$1" '-ne' '!='`
  53.     fi
  54.     if [ `findWord "$1" '\-gt'` -ge 1 ]
  55.     then
  56.         line=`changeWord "$1" '-gt' '>'`
  57.     fi
  58.     if [ `findWord "$1" '\-lt'` -ge 1 ]
  59.     then
  60.         line=`changeWord "$1" '-lt' '<'`
  61.     fi
  62.     if [ `findWord "$1" '\-ge'` -ge 1 ]
  63.     then
  64.         line=`changeWord "$1" '\-ge' '>='`
  65.     fi
  66.     if [ `findWord "$1" '\-le'` -ge 1 ]
  67.     then
  68.         line=`changeWord "$1" '-le' '<='`
  69.     fi
  70.  
  71.     echo "$line"
  72. }
  73. if_elseif() {
  74.     line=`changeWord "$line" '\[' '('`
  75.     line=`signsInequality "$line"`
  76.     line=`changeWord "$line" ']' ')'`
  77. }
  78.  
  79. while IFS='' read -r line || [ -n "$line" ];
  80. do
  81.     func=`findWordByID "$line" '$1'`
  82.  
  83.     case $func in
  84.         "#!/bin/sh") line='#!/bin/csh' ;;
  85.  
  86.         "if") if_elseif ;;
  87.         "then") ;;
  88.         "else")
  89.             if [ `findWord "$line" 'if'` -ge 0 ]
  90.             then
  91.                 if_elseif
  92.             fi
  93.         ;;
  94.         "elseif") if_elseif ;;
  95.         "fi") line=`changeWord "$line" 'fi' 'endif'` ;;
  96.  
  97.         "for")
  98.             line=`changeWord "$line" 'for' 'foreach'`
  99.             line=`changeWord "$line" 'in' '( '`
  100.             line=' )'
  101.         ;;
  102.  
  103.         "while")
  104.             line=`changeWord "$line" '\[' '('`
  105.             line=`signsInequality "$line"`
  106.             line=`changeWord "$line" ']' ')'`
  107.         ;;
  108.         "done") line=`changeWord "$line" 'done' 'end'` ;;
  109.         "break") ;;
  110.         "do") ;;
  111.         "continue") ;;
  112.  
  113.  
  114.  
  115.         "case")
  116.             line=`changeWord "$line" 'case (' 'switch'`
  117.             line=`changeWord "$line" 'in' ')'`
  118.         ;;
  119.  
  120.         ";;") line=`changeWord "$line" ';;' 'breaksw'` ;;
  121.         "*)") line=`changeWord "$line" '*)' 'default:'` ;;
  122.         "esac") line=`changeWord "$line" 'esac' "endsw"` ;;
  123.  
  124.         "echo") ;;
  125.  
  126.         "function") ;;
  127.         "}") ;;
  128.         "{") ;;
  129.         "()") ;;
  130.  
  131.         "#") ;;
  132.  
  133.         "@")
  134.             line=`deleteWord "$line" '@ '`
  135.             line="$( echo $line | sed 's/ //' )"
  136.  
  137.             variable=`findWordByID "$line" '$1'`
  138.  
  139.             if [ `findWord "$line" '+='` -ge 1 ]
  140.             then
  141.                 v="=\`expr \$$variable \'+\'"
  142.                 line=`changeWord "$line" '+=' "$v"`
  143.             fi
  144.             if [ `findWord "$line" '\-='` -ge 1 ]
  145.             then
  146.                 v="=\`expr \$$variable \'-\'"
  147.                 line=`changeWord "$line" '-=' "$v"`
  148.             fi
  149.             if [ `findWord "$line" '*='` -ge 1 ]
  150.             then
  151.                 v="=\`expr \$$variable \'*\'"
  152.                 line=`changeWord "$line" '*=' "$v"`
  153.             fi
  154.             if [ `findWord "$line" '/='` -ge 1 ]
  155.             then
  156.                 v="=\`expr \$$variable \'/\'"
  157.                 line=`changeWord "$line" '/=' "$v"`
  158.             fi
  159.             if [ `findWord "$line" '++'` -ge 1 ]
  160.             then
  161.                 v="=\`expr \$$variable \'+\' 1"
  162.                 line=`changeWord "$line" '++' "$v"`
  163.                 line=`deleteWord "$line" '++'`
  164.             fi
  165.             if [ `findWord "$line" '\--'` -ge 1 ]
  166.             then
  167.                 v="=\`expr \$$variable \'-\' 1"
  168.                 line=`changeWord "$line" '--' "$v"`
  169.                 line=`deleteWord "$line" '--'`
  170.             fi
  171.  
  172.  
  173.             line=$line'`'
  174.         ;;
  175.  
  176.         *)  
  177.             ll=`findWordByID "$line" '$1'`
  178.             if [ `findWord "$ll" '='` -ge 1  ]
  179.             then
  180.                 line=$line
  181.             else if [ `findWord "$ll" ')'` -ge 1  ]
  182.                 then
  183.                     line=$line
  184.                 else
  185.                     echo "Error: $line"
  186.                 fi
  187.             fi
  188.  
  189.            
  190.         ;;
  191.  
  192.     esac
  193.  
  194.     out="$out$line\n"
  195.  
  196.  
  197. done < "$1"
  198.  
  199. echo "\n$out"
  200. echo "$out" >"$2"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top