Skip to content

Commit

Permalink
Use the same shell in normal mode instead of forking a new one. Compr…
Browse files Browse the repository at this point in the history
…ess Makefile. Lint dicts refactor.
  • Loading branch information
vlajos committed Dec 26, 2014
1 parent f25aa1a commit e2fc3a0
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 62 deletions.
26 changes: 5 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
#!/usr/bin/make

.PHONY: test
.PHONY: test prepare_environment coveralls

all: misspell_fixer_safe.0.sed misspell_fixer_safe.1.sed misspell_fixer_safe.2.sed misspell_fixer_not_so_safe.sed misspell_fixer_gb_to_us.sed
all: lint_dicts $(wildcard *.sed)

misspell_fixer_safe.0.sed: dict/misspell_fixer_safe.0.dict
./dict/misspell_convert_dict_to_sed.pl <dict/misspell_fixer_safe.0.dict >./misspell_fixer_safe.0.sed

misspell_fixer_safe.1.sed: dict/misspell_fixer_safe.1.dict
./dict/misspell_convert_dict_to_sed.pl <dict/misspell_fixer_safe.1.dict >./misspell_fixer_safe.1.sed

misspell_fixer_safe.2.sed: dict/misspell_fixer_safe.2.dict
./dict/misspell_convert_dict_to_sed.pl <dict/misspell_fixer_safe.2.dict >./misspell_fixer_safe.2.sed

misspell_fixer_not_so_safe.sed: dict/misspell_fixer_not_so_safe.dict
./dict/misspell_convert_dict_to_sed.pl <dict/misspell_fixer_not_so_safe.dict >./misspell_fixer_not_so_safe.sed

misspell_fixer_gb_to_us.sed: dict/misspell_fixer_gb_to_us.dict
./dict/misspell_convert_dict_to_sed.pl <dict/misspell_fixer_gb_to_us.dict >./misspell_fixer_gb_to_us.sed
%.sed: dict/%.dict
./dict/misspell_convert_dict_to_sed.pl <$< >./$@

lint_dicts:
sort -u ./dict/misspell_fixer_safe.dict >misspell_fixer_safe.dict.su
sort -u ./dict/misspell_fixer_not_so_safe.dict >misspell_fixer_not_so_safe.dict.su
comm -23 misspell_fixer_safe.dict.su misspell_fixer_not_so_safe.dict.su >./dict/misspell_fixer_safe.dict
mv misspell_fixer_not_so_safe.dict.su ./dict/misspell_fixer_not_so_safe.dict
rm misspell_fixer_safe.dict.su
cd dict;./misspell_lint_dicts.sh

test:
/usr/local/bin/kcov --include-pattern=misspell_fixer.sh --path-strip-level=1 /tmp/coverage/ test/tests.sh
Expand Down
14 changes: 7 additions & 7 deletions dict/misspell_fixer_gb_to_us.dict
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
criticised|criticized
characterised|characterized
colouring|coloring
amortised|amortized
analysed|analyzed
analysers|analyzers
analyser|analyzer
organisation|organization
specialised|specialized
characterised|characterized
colouring|coloring
counsellor|counselor
minimise|minimize
amortised|amortized
criticised|criticized
emphasised|emphasized
minimise|minimize
organisation|organization
specialised|specialized
utilised|utilized
2 changes: 1 addition & 1 deletion dict/misspell_fixer_not_so_safe.dict
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
\bdifer|differ
\bwanna\b|want to
addresse\b|address
adres\b|address
alot|a lot
Expand All @@ -8,4 +9,3 @@ decompressions|decompression's
desn't|doesn't
diagnostic's|diagnostics
does't|doesn't
\bwanna\b|want to
18 changes: 18 additions & 0 deletions dict/misspell_lint_dicts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

function remove_duplications {
export actual=$1
sort -u /tmp/already_processed.dict >/tmp/already_processed.dict.su
sort -u misspell_fixer_$actual.dict >misspell_fixer_$actual.dict.su
comm -23 misspell_fixer_$actual.dict.su /tmp/already_processed.dict.su >misspell_fixer_$actual.dict
mv /tmp/already_processed.dict.su /tmp/already_processed.dict
rm misspell_fixer_$actual.dict.su
}

sort -u misspell_fixer_safe.0.dict >/tmp/already_processed.dict
cp /tmp/already_processed.dict misspell_fixer_safe.0.dict

for i in safe.1 safe.2 not_so_safe gb_to_us
do
remove_duplications $i
done
20 changes: 11 additions & 9 deletions misspell_fixer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function main_work_fast {
return 0
}

function loop_core {
function main_work_normal_one {
if [[ $opt_debug = 1 ]]
then
set -x
Expand All @@ -197,31 +197,29 @@ function loop_core {
verbose "temp file: $tmpfile"
cp -a "$1" "$tmpfile"
sed -i $cmd_part_rules "$tmpfile"
IFS=''
diff=$(diff -uwb $1 $tmpfile)
if [[ $? = 0 ]]
then
verbose "nothing changed"
rm $tmpfile
rm "$tmpfile"
else
verbose "misspells are fixed!"
if [[ $opt_show_diff = 1 ]]
then
echo $diff
echo "$diff"
fi
if [[ $opt_real_run = 1 ]]
then
if [[ $opt_backup = 1 ]]
then
mv $1 $tmpfile.BAK
mv "$1" "$tmpfile.BAK"
fi
mv $tmpfile $1
mv "$tmpfile" "$1"
else
rm $tmpfile
rm "$tmpfile"
fi
fi
}
export -f loop_core verbose warning

function main_work_normal {
if [[ $opt_debug = 1 ]]
Expand All @@ -233,7 +231,11 @@ function main_work_normal {
-type f\
$cmd_part_ignore \
-and \( $opt_name_filter \) \
-exec bash -c 'loop_core "$0"' {} \;
-print0 |\
while IFS="" read -r -d "" file
do
main_work_normal_one "$file"
done
warning "Done."
return 0
}
Expand Down
42 changes: 21 additions & 21 deletions misspell_fixer_gb_to_us.sed
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
#!/bin/sed
s/criticised/criticized/g
s/CRITICISED/CRITICIZED/g
s/Criticised/Criticized/g
s/characterised/characterized/g
s/CHARACTERISED/CHARACTERIZED/g
s/Characterised/Characterized/g
s/colouring/coloring/g
s/COLOURING/COLORING/g
s/Colouring/Coloring/g
s/amortised/amortized/g
s/AMORTISED/AMORTIZED/g
s/Amortised/Amortized/g
s/analysed/analyzed/g
s/ANALYSED/ANALYZED/g
s/Analysed/Analyzed/g
Expand All @@ -17,24 +11,30 @@ s/Analysers/Analyzers/g
s/analyser/analyzer/g
s/ANALYSER/ANALYZER/g
s/Analyser/Analyzer/g
s/organisation/organization/g
s/ORGANISATION/ORGANIZATION/g
s/Organisation/Organization/g
s/specialised/specialized/g
s/SPECIALISED/SPECIALIZED/g
s/Specialised/Specialized/g
s/characterised/characterized/g
s/CHARACTERISED/CHARACTERIZED/g
s/Characterised/Characterized/g
s/colouring/coloring/g
s/COLOURING/COLORING/g
s/Colouring/Coloring/g
s/counsellor/counselor/g
s/COUNSELLOR/COUNSELOR/g
s/Counsellor/Counselor/g
s/minimise/minimize/g
s/MINIMISE/MINIMIZE/g
s/Minimise/Minimize/g
s/amortised/amortized/g
s/AMORTISED/AMORTIZED/g
s/Amortised/Amortized/g
s/criticised/criticized/g
s/CRITICISED/CRITICIZED/g
s/Criticised/Criticized/g
s/emphasised/emphasized/g
s/EMPHASISED/EMPHASIZED/g
s/Emphasised/Emphasized/g
s/minimise/minimize/g
s/MINIMISE/MINIMIZE/g
s/Minimise/Minimize/g
s/organisation/organization/g
s/ORGANISATION/ORGANIZATION/g
s/Organisation/Organization/g
s/specialised/specialized/g
s/SPECIALISED/SPECIALIZED/g
s/Specialised/Specialized/g
s/utilised/utilized/g
s/UTILISED/UTILIZED/g
s/Utilised/Utilized/g
6 changes: 3 additions & 3 deletions misspell_fixer_not_so_safe.sed
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
s/\bdifer/differ/g
s/\bDIFER/DIFFER/g
s/\bDifer/Differ/g
s/\bwanna\b/want to/g
s/\bWANNA\b/WANT TO/g
s/\bWanna\b/Want to/g
s/addresse\b/address/g
s/ADDRESSE\b/ADDRESS/g
s/Addresse\b/Address/g
Expand Down Expand Up @@ -29,6 +32,3 @@ s/Diagnostic's/Diagnostics/g
s/does't/doesn't/g
s/DOES'T/DOESN'T/g
s/Does't/Doesn't/g
s/\bwanna\b/want to/g
s/\bWANNA\b/WANT TO/g
s/\bWanna\b/Want to/g

0 comments on commit e2fc3a0

Please sign in to comment.