#diff2unix
#Ruoqian, Chen<
[email protected]>
#2013.2.7
#----------
#trans diff patch with windows LE (CRLF) to Unix LE(LF)
#-----------
#usage
#diff2unix trans curent dir
#diff2unix path trans dir or file
#when trans dir, will trans all files and child dir in it.
#----------
if [ $# == 0 ]
then
path=`pwd`
else
path=$1
fi
if [ -f $path ]
then
file=${path##*/}
ext=${file##*.}
if [[ "$file" != mac* ]] && [ $ext = "diff" ]
then
new_file="mac_"$file
echo $path "->" $new_file
awk '/^/+/+/+|^---|^@@|^diff|^Binary|^File/ { sub(//r$/,"") }; {print}' < $path > $new_file
fi
else
for file in `ls $path`
do
diff2unix $path"/"$file
done
fi
::diff2win
::Ruoqian,Chen<
[email protected]>
::----------
::Trans file with unix LE(LF) or mix LE(LF/CRLF) to window LE(CRLF)
::----------
::2013.2.16
::usage
::diff2win trans curent dir
::diff2win path trans dir or file
::----------
@echo off
setlocal enabledelayedexpansion
set WorkPath=%cd%
if [%1] neq [] set WorkPath=%1&& (dir /ad %1 >nul 2>nul ) && goto TRANS_DIR || goto TRANS_FILE
:TRANS_DIR
for /f "delims=" %%i in ('dir !WorkPath! /a-d /b ^| findstr .diff$ ^| findstr -v ^win_') do (
echo !WorkPath!/%%i -^> win_%%i
gawk -v BINMODE="rw" "/^/+/+/+|^---|^@@|^diff|^Binary|^File/ { sub(/$/,/"/r/") }; {print}" < !WorkPath!/%%i > win_%%i
)
goto :eof
:TRANS_FILE
for /f "delims=" %%i in ('dir %WorkPath% /b') do (
echo %WorkPath% -^> win_%%i
gawk -v BINMODE="rw" "/^/+/+/+|^---|^@@|^diff|^Binary|^File/ { sub(/$/,/"/r/") }; {print}" < %WorkPath% > win_%%i
)
::gawk -v BINMODE="rw" "/^/+/+/+|^---|^@@|^diff|^Binary|^File/ { sub(/$/,/"/r/") }; {print}" < in > out
::----------
::2013.2.8
::usage
::diff2win < file_in > file_out
::e.g.
::diff2win < unix.diff > win.diff
::----------
::@echo off
::gawk 1
::http://www.gnu.org/software/gawk/manual/html_node/PC-Using.html
::Under MS-Windows, OS/2 and MS-DOS, gawk (and many other text programs) silently translate end-of-line "/r/n" to "/n" on input and "/n" to "/r/n" on output.
::winpatch
::Ruoqian, Chen<
[email protected]>
::2013.2.16
::
::call gnu patch to patch a diff file with windows LE (CRLF) or Unix LE(LF) or mix LE
::----------
::usage
::the same to patch use patch --help to read it
::e.g. winpatch -p1 < ../mac.diff
::or winpatch -p1 -R < ../mac.diff
::----------
@echo off
gawk -v BINMODE="rw" "/^/+/+/+|^---|^@@|^diff|^Binary|^File/ { sub(/$/,/"/r/") }; {print}" > dosCRLF.diff
patch %1 %2 %3 %4 %5 %6 %7 %8 %9 < dosCRLF.diff