On 5/7/19 7:02 AM, Jan Tulak wrote: > Turn all the "x , y , z" into "x, y, z" and "for (moo ; foo ; bar)" > to "for (moo; foo; bar)". The only exception is a double semicolon surrounded > by some other commands, e.g. for(bar ; ; baz), for increased readability. > > Created by this script: > ***** > #!/usr/bin/env bash > set -euo pipefail > # remove the space before , and ; > > # regex explanation: > # We are avoiding strings - replacing only those spaces that are not surrounded > # by ". At the same time, we want to ignore also those cases, where > # there are only whitespace in front of the commas/semicolons, as those are > # likely aligned. At the end, return a space between two semicolons in cases > # like for (foo ; ; bar), where the spaces are important for readability. > > find . -name '*.[ch]' ! -type d -exec gawk -i inplace '{ > $0 = gensub(/^([^"]*[^[:space:]"][^"]*) ,/, "\\1,", "g") > $0 = gensub(/^([^"]*[^[:space:]"][^"]*) ;/, "\\1;", "g") > $0 = gensub(/^(.*[^[:space:]"].*) ,([^"]*)$/, "\\1,\\2", "g") > $0 = gensub(/^(.*[^[:space:]"].*) ;([^"]*)$/, "\\1;\\2", "g") > $0 = gensub(/([^([:space:]]);;([^\n])/, "\\1 ; ;\\2", "g") > }; {print }' {} \; > ***** > > Signed-off-by: Jan Tulak <jtulak@xxxxxxxxxx> > --- > CHANGES: > v2: special cases: for (foo ; ; bar) can keep the spaces, a few more > lines that were skipped before have been added. Thanks, I've committed & pushed this change. -Eric