3
#####################################################################
4
# Print warning message.
11
#####################################################################
12
# Print error message and exit.
21
#####################################################################
24
# Usage: yesno OPTIONS QUESTION
27
# --timeout N Timeout if no input seen in N seconds.
28
# --default ANS Use ANS as the default answer on timeout or
29
# if an empty answer is provided.
31
# Exit status is the answer.
47
if [[ ! "$default" ]]; then error "Missing default value"; fi
48
t=$(tr '[:upper:]' '[:lower:]' <<<$default)
50
if [[ "$t" != 'y' && "$t" != 'yes' && "$t" != 'n' && "$t" != 'no' ]]; then
51
error "Illegal default answer: $default"
60
if [[ ! "$timeout" ]]; then error "Missing timeout value"; fi
61
if [[ ! "$timeout" =~ ^[0-9][0-9]*$ ]]; then error "Illegal timeout value: $timeout"; fi
66
error "Unrecognized option: $1"
75
if [[ $timeout -ne 0 && ! "$default" ]]; then
76
error "Non-zero timeout requires a default answer"
79
if [[ ! "$*" ]]; then error "Missing question"; fi
83
if [[ $timeout -ne 0 ]]; then
84
if ! read -t $timeout -p "$*" ans; then
87
# Turn off timeout if answer entered.
89
if [[ ! "$ans" ]]; then ans=$default; fi
93
if [[ ! "$ans" ]]; then
96
ans=$(tr '[:upper:]' '[:lower:]' <<<$ans)
100
if [[ "$ans" == 'y' || "$ans" == 'yes' || "$ans" == 'n' || "$ans" == 'no' ]]; then
104
if [[ $ok -eq 0 ]]; then warning "Valid answers are: yes y no n"; fi
106
[[ "$ans" = "y" || "$ans" == "yes" ]]
111
[ "$#" -eq 2 ] || error "2 argument required, $# provided\n\nUse $0 gsc_file.dic lsc_file.dic"
117
error "$0 not exists. Provide a valid GSC Dictionary file."
122
if yesno --default no "\"$2\" exists. Do you want overwrite it? (y/N) "
124
if yesno --default yes "Do you want make a backup copy of \"$2\"? (Y/n) "
127
printf "\n$2.bak writed successfully!\n"
131
error "Operation aborted."
135
printf "\nSaving old comments...."
137
sed -i '/^[^\/].*$/d' $2
143
sed -i '/^[^123456789].*$/d' $2
149
printf "\nStarting converting...."
151
printf "\nRemoving comments...."
153
sed -i '/^[\/123456789].*$/d' $2
156
printf "\nDone!\nAppling GSC rule 1 (x -> gh)...."
158
awk '/xer\/K.*GSC 3/ {gsub("xer\/K ", "ghere\/I", $0); gsub(", GSC 3", "", $0); print $0; p=1;} {if(p == 0) {print $0;} else {p=0;};}' $2 1> $2.tmp 2>/dev/null
161
awk '/xes\/K.*GSC 3/ {gsub("xes\/K ", "go\/I", $0); gsub("xer ", "ghere", $0); gsub(", GSC 3", "", $0); print $0; p=1;} {if(p == 0) {print $0;} else {p=0;};}' $2 1> $2.tmp 2>/dev/null
164
awk '/GSC 1/ {gsub("x", "gh", $0); gsub(", GSC 1", "", $0); print $0; p=1;} {if(p == 0) {print $0;} else {p=0;};}' $2 > $2.tmp
167
printf "\nRule 1 done!\nAppling GSC rule 2 (k -> ch)...."
169
awk '/GSC 2/ {gsub("k", "ch", $0); gsub(", GSC 2", "", $0); print $0; p=1;} {if(p == 0) {print $0;} else {p=0;};}' $2 > $2.tmp
172
printf "\nRule 2 done!\nAppling GSC rule 3 (er -> ere)...."
174
awk '/er\/I.*GSC 3/ {gsub("er\/I ", "ere\/I", $0); gsub(", GSC 3", "", $0); print $0; p=1;} {if(p == 0) {print $0;} else {p=0;};}' $2 1> $2.tmp 2>/dev/null
177
awk '/er\/K.*GSC 3/ {gsub("er\/K ", "ere\/K", $0); gsub(", GSC 3", "", $0); print $0; p=1;} {if(p == 0) {print $0;} else {p=0;};}' $2 1> $2.tmp 2>/dev/null
180
awk '/er\/J.*GSC 3/ {gsub("er\/J ", "ere\/J", $0); gsub(", GSC 3", "", $0); print $0; p=1;} {if(p == 0) {print $0;} else {p=0;};}' $2 1> $2.tmp 2>/dev/null
183
awk '/er\/O.*GSC 3/ {gsub("er\/O ", "ere\/O", $0); gsub(", GSC 3", "", $0); print $0; p=1;} {if(p == 0) {print $0;} else {p=0;};}' $2 1> $2.tmp 2>/dev/null
186
awk '/er\/P.*GSC 3/ {gsub("er\/P ", "ere\/P", $0); gsub(", GSC 3", "", $0); print $0; p=1;} {if(p == 0) {print $0;} else {p=0;};}' $2 1> $2.tmp 2>/dev/null
189
awk '/er\/L.*GSC 3/ {gsub("er\/L ", "ere\/L", $0); gsub(", GSC 3", "", $0); print $0; p=1;} {if(p == 0) {print $0;} else {p=0;};}' $2 1> $2.tmp 2>/dev/null
192
awk '/er *#.*GSC 3/ {gsub("er ", "ere", $0); gsub(", GSC 3", "", $0); print $0; p=1;} {if(p == 0) {print $0;} else {p=0;};}' $2 > $2.tmp
195
printf "\nRule 3 done!\nAppling GSC rule 4 (s -> is)...."
197
awk '/^s.*GSC 4/ {gsub("^s", "is", $0); gsub(", GSC 4", "", $0); print $0; p=1;} {if(p == 0) {print $0;} else {p=0;};}' $2 > $2.tmp
200
awk '/s.*GSC 4/ {gsub("s", "is", $0); gsub(", GSC 4", "", $0); print $0; p=1;} {if(p == 0) {print $0;} else {p=0;};}' $2 > $2.tmp
203
printf "\nRule 3 done!\nFormating text...."
205
awk '{if(index($0, "po:")==29){gsub("po:", " po:", $0)} else if(index($0, "po:")==28){gsub("po:", " po:", $0)} else if(index($0, "po:")==27){gsub("po:", " po:", $0)} print $0;}' $2 > $2.tmp
208
awk '{if(index($0, "po:")==31){gsub(" po:", "po:", $0)} else if(index($0, "po:")==32){gsub(" po:", "po:", $0)} else if(index($0, "po:")==33){gsub(" po:", "po:", $0)} print $0;}' $2 > $2.tmp
211
awk '{if(index($0, "#")==61){gsub(" #", "#", $0)} else if(index($0, "#")==62){gsub(" #", "#", $0)} else if(index($0, "#")==63){gsub(" #", "#", $0)} print $0;}' $2 > $2.tmp
214
printf "\nDone!\nSorting...\n"
221
printf "\nDone!\nAdding old comments..."
223
cat $2.num.tmp $2.comms.tmp $2 > $2.tmp
225
rm -f $2.comms.tmp $2.num.tmp
227
printf "\nAll done!\n$2 writed successfully!\n"