]> Softwares of Agnibho - mscore.git/blob - mscore
Initialized Repo
[mscore.git] / mscore
1 #! /bin/bash
2
3 # Copyright (c) 2017 Agnibho Mondal
4 # All rights reserved
5 #
6 # This file is part of Mscore.
7 #
8 # Mscore is free software: you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation, either version 3 of the License, or (at your option) any later
11 # version.
12 #
13 # Mscore is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 # PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # Mscore. If not, see <http://www.gnu.org/licenses/>.
19 #
20 # Agnibho Mondal
21 # contact@agnibho.com
22 # www.agnibho.com
23
24 DIR="/home/agnibho/program/mscore/data/";
25
26 INPUT=(0);
27 GROUP=(0 0);
28 G=1;
29 TOT=0;
30
31 function invalid {
32 echo "Invalid input";
33 exit 1;
34 }
35
36 function input {
37 if [ -z "$1" ];then
38 exit 1;
39 else
40 line=$1;
41 fi
42 REG=$(grep -Eo "\[.*?\]" <<< "$line" | sed "s/[][]//g" | sed "s/ //g");
43 PR=$(echo "$line" | sed "s/\[.*\]//g")"[$REG] : ";
44 read -p "$PR" -u 3 IN;
45 if [[ -z "$IN" ]];then
46 IN=0;
47 fi
48 if [[ "$IN" =~ ' ' ]];then
49 invalid;
50 elif [[ "$REG" =~ - ]];then
51 l=$(echo "$REG" | sed "s/-.*//g");
52 u=$(echo "$REG" | sed "s/.*-//g");
53 if (( "$IN" >= "$l" && "$IN" <= "$u" ));then
54 INPUT+=("$IN");
55 GROUP[$G]+="+$IN";
56 else
57 invalid;
58 fi
59 elif [[ "$REG" =~ , ]];then
60 readarray -d , -t n <<< "$REG";
61 if [[ "${n[@]}" =~ "$IN" ]];then
62 INPUT+=("$IN");
63 GROUP[$G]+="+$IN";
64 else
65 invalid;
66 fi
67 elif [[ "$REG" =~ [yn] ]];then
68 if [[ "${IN,,}" =~ [y1] ]];then
69 INPUT+=(1);
70 GROUP[$G]+="+1";
71 elif [[ "${IN,,}" =~ [n0] ]];then
72 INPUT+=(0);
73 else
74 invalid;
75 fi
76 else
77 echo "Error processing [$REG]";
78 exit 1;
79 fi
80 }
81
82 function output {
83 if [ -z "$1" ];then
84 exit 1;
85 else
86 line=$1;
87 fi
88 FLAG="";
89 readarray -t PATS <<<"$(grep -Po "\[.*?\]" <<< "$line")";
90 for P in "${PATS[@]}";do
91 I="$(echo "$P" | sed "s/[][]//g" | sed "s/ //g" | sed "s/vt/$TOT/g" | sed -r "s/v([0-9]+)/$\{INPUT\[\1\]\}/g" | sed -r "s/g([0-9]+)/$\{GROUP\[\1\]\}/g" | sed -r "s/([=\<\>])/ \1 /g" | sed -r "s/([\<\>])\s+=/\1=/g" | sed "s/and/ \&\& /g" | sed "s/or/ \|\| /g")";
92 if [[ "$I" =~ [=\<\>\&\|] ]];then
93 if ! eval "(( $I ))";then
94 return;
95 fi
96 line=${line/"$P"/""};
97 elif [[ "$I" == "!" ]];then
98 FLAG="stop";
99 line=${line/"$P"/""};
100 else
101 I=$(eval "echo $I" | bc);
102 line=${line/"$P"/"$I"};
103 fi
104 done
105 echo "$line";
106 if [ "$FLAG" = "stop" ];then
107 exit 0;
108 fi
109 }
110
111 if [ -f "$DIR$1" ];then
112 SECTION="";
113 while read line;do
114 if [[ "$line" =~ ^# ]];then
115 continue;
116 elif [[ "$line" =~ ^= ]];then
117 if [ "$SECTION" = "input" ];then
118 SECTION="output";
119 TOT=$(echo ${INPUT[@]} | sed "s/ /+/g" | bc);
120 GROUP[$G]=$(echo "${GROUP[$G]}"|bc);
121 fi
122 echo "$line";
123 elif [[ "$line" =~ ^- ]];then
124 if [ "$SECTION" = "input" ];then
125 GROUP[$G]=$(echo "${GROUP[$G]}"|bc);
126 ((G++));
127 GROUP[$G]="0";
128 fi
129 echo "$line";
130 elif [[ "$line" =~ \[.*?\] ]];then
131 if [ "$SECTION" = "input" ];then
132 input "$line";
133 elif [ "$SECTION" = "output" ];then
134 output "$line";
135 else
136 SECTION="input";
137 input "$line";
138 fi
139 else
140 echo "$line";
141 fi
142 done 3<&0 < "$DIR$1"
143 else
144 echo "Available scores: ";
145 ls "$DIR";
146 fi