Skip to content
Snippets Groups Projects
Commit dec317bb authored by afarrell's avatar afarrell
Browse files

Manually case-insensitive regexes making up for macOS sed lack of i flag

parent 9e6c3bf1
Branches
Tags 2.5
No related merge requests found
......@@ -51,15 +51,13 @@ fi
#
#The | alternation and (capture) must be escaped because
#these aren't extended regexes.
regex='\$\(author\|date\|header\|id\|locker\|log\|RCSfile\|revision\|source\|state\):[^$]*\$'
#Case insensitive version of regex='\$\(author\|date\|header\|id\|locker\|log\|RCSfile\|revision\|source\|state\):[^$]*\$'
regex='\$\([aA][uU][tT][hH][oO][rR]\|[dD][aA][tT][eE]\|[hH][eE][aA][dD][eE][rR]\|[iI][dD]\|[lL][oO][cC][kK][eE][rR]\|[lL][oO][gG]\|[rR][cC][sS][fF][iI][lL][eE]\|[rR][eE][vV][iI][sS][iI][oO][nN]\|[sS][oO][uU][rR][cC][eE]\|[sS][tT][aA][tT][eE]\):[^$]*\$'
#Escapes both '$' in this replacement
#Also the \1 is escaped
#gi: Case insensitive, replace *all* instances
sedscript="s/$regex/\$\\1\$/gi"
sedscript="s/$regex/\$\\1\$/g"
regex='\$\(author\|date\|header\|id\|locker\|log\|RCSfile\|revision\|source\|state\):[^$]*\$'
sedscript="s/$regex/\$\\1\$/gi"
sed "$sedscript" "$tmp";
rm "$tmp";
......@@ -97,34 +97,49 @@ date="$(git log --pretty='%aD' -- "$abspath" | head -n1 |
sed -Ee 's/^([A-Z][a-z][a-z]), ([123]?[0-9]) ([A-Z][a-z][a-z]) ([0-9]+) ([0-2][0-9]:[0-5][0-9]:[0-5][0-9]) \+([0-9][0-9])[0-9][0-9]/\2-\3\-4 \5+\6/g' | head -n1 )"
#Clean then convert. This regex same as rcs-keywords.clean
regex='\$\(author\|date\|header\|id\|locker\|log\|RCSfile\|revision\|source\|state\):[^$]*\$'
#Case insensitive version of regex='\$\(author\|date\|header\|id\|locker\|log\|RCSfile\|revision\|source\|state\):[^$]*\$'
regex='\$\([aA][uU][tT][hH][oO][rR]\|[dD][aA][tT][eE]\|[hH][eE][aA][dD][eE][rR]\|[iI][dD]\|[lL][oO][cC][kK][eE][rR]\|[lL][oO][gG]\|[rR][cC][sS][fF][iI][lL][eE]\|[rR][eE][vV][iI][sS][iI][oO][nN]\|[sS][oO][uU][rR][cC][eE]\|[sS][tT][aA][tT][eE]\):[^$]*\$'
#We clean before doing any substitution
sedscriptclean="s/$regex/\$\\1\$/gi"
sedscriptclean="s/$regex/\$\\1\$/g"
#RCS Keyword substitution:
#Note that the \1 is used in all substitutions to preserve case of the keyword
#For each keyword, substitute the $Keyword.*$ with $Keyword: keyword value$ using 1 sed expression each
#\1 is used in all substitutions to preserve case of the keyword
#I switch from 'single quotes' to "double quotes" to better use escapes for the pattern, then use variables
sedscriptauthor='s@\$\(author\)\$@$\1: '"$(sedescape "$author \$")@gi"
#Case insensitive version of 's@\$\(author\)\$@$\1: '
sedscriptauthor='s@\$\([aA][uU][tT][hH][oO][rR]\)\$@$\1: '"$(sedescape "$author \$")@g"
# Since there is no such thing as locker, we do this instead
# But I haven't seen locker used in real-world ACMM yet, so not sure if this wo`uld work
sedscriptlocker='s@\$\(locker\)\$@$\1: '"$(sedescape "$(git config user.email) \$")@gi"
#Case insensitive version of 's@\$\(locker\)\$@$\1: '
sedscriptlocker='s@\$\([lL][oO][cC][kK][eE][rR]\)\$@$\1: '"$(sedescape "$(git config user.email) \$")@g"
#Case insensitive version of 's@\$\(date\)\$@$\1: '
sedscriptdate='s@\$\([dD][aA][tT][eE]\)\$@$\1: '"$(sedescape "$date \$")@g"
sedscriptdate='s@\$\(date\)\$@$\1: '"$(sedescape "$date \$")@gi"
sedscriptrevision='s@\$\(revision\)\$@$\1: '"$(sedescape "$commit \$")@gi"
#Case insensitive version of 's@\$\(revision\)\$@$\1: '
sedscriptrevision='s@\$\([rR][eE][vV][iI][sS][iI][oO][nN]\)\$@$\1: '"$(sedescape "$commit \$")@g"
# Difference is abspath/relpath
sedscriptid='s@\$\(id\)\$@$\1: '"$(sedescape "GIT:$relpath, $commit $date $author\$")@gi"
sedscriptheader='s@\$\(header\)\$@$\1: '"$(sedescape "GIT:$abspath, $commit $date $author\$")@gi"
#Case insensitive version of 's@\$\(id\)\$@$\1: '
sedscriptid='s@\$\([iI][dD]\)\$@$\1: '"$(sedescape "GIT:$relpath, $commit $date $author\$")@g"
#Case insensitive version of 's@\$\(header\)\$@$\1: '
sedscriptheader='s@\$\([hH][eE][aA][dD][eE][rR]\)\$@$\1: '"$(sedescape "GIT:$abspath, $commit $date $author\$")@g"
# Difference is abspath/relpath
sedscriptrcsfile='s@\$\(rcsfile\)\$@$\1: '"$(sedescape "$(basename "$relpath") \$")@gi"
sedscriptsource='s@\$\(source\)\$@$\1: '"$(sedescape "$abspath \$")@gi"
#Case insensitive version of 's@\$\(rcsfile\)\$@$\1: '
sedscriptrcsfile='s@\$\([rR][cC][sS][fF][iI][lL][eE]\)\$@$\1: '"$(sedescape "$(basename "$relpath") \$")@g"
#Case insensitive version of 's@\$\(source\)\$@$\1: '
sedscriptsource='s@\$\([sS][oO][uU][rR][cC][eE]\)\$@$\1: '"$(sedescape "$abspath \$")@g"
# I Have not seen $Log$ actually used, just in comments only,
# I think ACMM might have something bad with its format of it.
# I have removed the ',v '
sedscriptlog='s@\$\(log\)\$@$\1: '"$(sedescape "$(basename $relpath) \$")@gi"
#Case insensitive version of 's@\$\(log\)\$@$\1: '
sedscriptlog='s@\$\([lL][oO][gG]\)\$@$\1: '"$(sedescape "$(basename $relpath) \$")@g"
sed -e"$sedscriptclean" \
-e"$sedscriptauthor" \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment