docs/69086: Porters Handbook: How to convert from CR/LF to LF using REINPLACE_CMD
Alexey Dokuchaev
danfe at regency.nsu.ru
Thu Jul 15 07:00:45 UTC 2004
>Number: 69086
>Category: docs
>Synopsis: Porters Handbook: How to convert from CR/LF to LF using REINPLACE_CMD
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-doc
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Thu Jul 15 07:00:44 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator: Alexey Dokuchaev
>Release: FreeBSD 4.9-STABLE i386
>Organization:
CNIT NSU
>Environment:
System: FreeBSD regency.nsu.ru 4.9-STABLE FreeBSD 4.9-STABLE #1: Wed Mar 3 13:17:54 NOVT 2004 root at regency.nsu.ru:/usr/src/sys/compile/REGENCY i386
>Description:
Quite often, we have to port sotfware written for or under Windows/DOS,
which use dumb CR/LF convention for text files instead of Unix plain LF.
This often causes problems with further patching, compiler warning,
scipts execution (/bin/sh^M not found), etc.
Since there's no standard practice of dealing with such situations,
people often come up with all sorts of solutions, i.e. supplying
explicit patches in files/, adding dependency(!!!) on dos2unix, of
wrapping tr -d '\r' in a script and calling it instead of sed(1) in my
proposal, which is simple and straightforward.
I therefore suggest including this in Porter's Handbook, as in attached
patch.
>How-To-Repeat:
Try porting some fairly complex CR/LF code.
>Fix:
Index: book.sgml
===================================================================
RCS file: /home/pub/ftp/pub/FreeBSD/development/FreeBSD-CVS//doc/en_US.ISO8859-1/books/porters-handbook/book.sgml,v
retrieving revision 1.461
diff -u -r1.461 book.sgml
--- book.sgml 12 Jul 2004 08:24:15 -0000 1.461
+++ book.sgml 15 Jul 2004 06:55:26 -0000
@@ -681,6 +681,24 @@
lines!); define <literal>USE_AUTOCONF_VER=213</literal> and take the
diffs of <filename>configure.in</filename>.</para>
+ <para>Quite often, there is a situation when ported software, being
+ primarily developed on Windows, uses CR/LF convention for most of its
+ source files. This may cause problems with further patching, compiler
+ warnings, scipts execution (<command>/bin/sh^M</command> not found),
+ etc. To quickly convert those files from CR/LF to just LF, you can do
+ something like this:</para>
+
+ <programlisting>USE_REINPLACE= yes
+
+post-extract:
+ @${FIND} -E ${WRKDIR} -type f -iregex ".*\.(c|cpp|h|txt)" \
+ -exec ${REINPLACE_CMD} -e 's/[[:cntrl:]]*$$//' '{}' \;</programlisting>
+
+ <para>Of course, if you need to process each and every file,
+ <option>-iregex</option> above can be omitted. Be aware that this
+ piece of code will strip all trailing control characters from each
+ line of processed file (except <literal>\n</literal>).</para>
+
<para>Also, if you had to delete a file, then you can do it in the
<maketarget>post-extract</maketarget> target rather than as part of
the patch. Once you are happy with the resulting diff, please split
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-doc
mailing list