develooper Front page | perl.perl5.porters | Postings from May 2002

[Patch] Inplace editing on Cygwin and others?

Thread Next
From:
Gerrit P. Haase
Date:
May 31, 2002 19:13
Subject:
[Patch] Inplace editing on Cygwin and others?
Message ID:
199100765833.20020601041443@familiehaase.de
Hallo perl5-porters,

The inplace editing problem again.  The KDE-Cygwin guys came in
contact with me (again) and they remembered me that Ralf Habacker has
patched perl-5.6.1 for doing the KDE port to Cygwin.  In the KDE build
scripts they use 'perl -i' all over the place and it would be a hassle
to change it everywhere there to do 'perl -i.bak' instead of real
inplace editing so Ralf patched perl-5.6.1 to do it automagically.

This is the patch including the relevant README.cygwin change and the
retract of Change 16382 (doio.c).

I just finished a build (patchlevel 16937) and it works as expected.

Before the change:
==================
$ perl -i -p -e 's#Vorname#VVoorrnnaammee#;' out.test
Can't do inplace edit without backup.

$ ls out.test*
out.test*


After the change:
=================
$ perl -i -p -e 's#Vorname#VVoorrnnaammee#;' out.test

$ ls out.test*
out.test*  out.test.bak*


Eventually this would work also with DOSISH, AMIGAOS, VMS, (others?),
but I cannot test this here.

Patch (also attached):
======================
--- README.cygwin~      2002-05-31 22:55:48.000000000 +0200
+++ README.cygwin       2002-05-31 22:57:51.000000000 +0200
@@ -401,8 +401,9 @@
 The Cygwin chroot() implementation has holes (it can not restrict file
 access by native Win32 programs).
 
-Inplace editing ( perl -i ) of files doesn't work without doing a backup 
-of the file being edited ( perl -i.bak ).
+Inplace editing C<perl -i> of files doesn't work without doing a backup 
+of the file being edited C<perl -i.bak> because of windowish restrictions,
+so Perl does this automagically if you just use C<perl -i>.
 
 =back
 
--- doio.c~     2002-05-31 23:09:06.000000000 +0200
+++ doio.c      2002-05-31 23:09:06.000000000 +0200
@@ -790,7 +790,7 @@
 #endif
                }
                else {
-#if !defined(DOSISH) && !defined(AMIGAOS) && !defined(__CYGWIN__)
+#if !defined(DOSISH) && !defined(AMIGAOS)
 #  ifndef VMS  /* Don't delete; use automatic file versioning */
                    if (UNLINK(PL_oldname) < 0) {
                        if (ckWARN_d(WARN_INPLACE))     

--- perl.c~     2002-05-31 22:39:08.000000000 +0200
+++ perl.c      2002-05-31 22:39:08.000000000 +0200
@@ -2363,6 +2363,12 @@
     case 'i':
        if (PL_inplace)
            Safefree(PL_inplace);
+#if defined(__CYGWIN__) /* do backup extension automagically */
+       if (*(s+1) == '\0') {
+       PL_inplace = savepv(".bak");
+       return s+1;
+       }
+#endif /* __CYGWIN__ */
        PL_inplace = savepv(s+1);
        /*SUPPRESS 530*/
        for (s = PL_inplace; *s && !isSPACE(*s); s++) ;

#END OF PATCH

Gerrit
-- 
=^..^=
Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About