* How to rename a file?
@ 2001-09-27 19:43 Pi
2001-09-27 23:09 ` tmoran
` (2 more replies)
0 siblings, 3 replies; 16+ messages in thread
From: Pi @ 2001-09-27 19:43 UTC (permalink / raw)
It may sound stupid, but I didn't find anything.
Is there a way to rename files in Ada?
Other than :
create a new file,
copy every byte into the new one,
delete the old one.
--
3,14159265359
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: How to rename a file?
2001-09-27 19:43 How to rename a file? Pi
@ 2001-09-27 23:09 ` tmoran
2001-09-27 23:36 ` Larry Kilgallen
2001-09-28 2:16 ` DuckE
2001-09-28 3:16 ` David Botton
2 siblings, 1 reply; 16+ messages in thread
From: tmoran @ 2001-09-27 23:09 UTC (permalink / raw)
>Is there a way to rename files in Ada?
Often. Consult your compiler's docs. Renaming files is usually
impossible in embedded systems, systems living entirely in ROM, etc.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: How to rename a file?
2001-09-27 23:09 ` tmoran
@ 2001-09-27 23:36 ` Larry Kilgallen
0 siblings, 0 replies; 16+ messages in thread
From: Larry Kilgallen @ 2001-09-27 23:36 UTC (permalink / raw)
In article <WkOs7.54950$L%5.36196502@news1.rdc1.sfba.home.com>, tmoran@acm.org writes:
>>Is there a way to rename files in Ada?
> Often. Consult your compiler's docs. Renaming files is usually
> impossible in embedded systems, systems living entirely in ROM, etc.
And renaming on a general purpose operating system is highly specific
to the operating system in use. Some things are possible in one
environment but not another.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: How to rename a file?
2001-09-27 19:43 How to rename a file? Pi
2001-09-27 23:09 ` tmoran
@ 2001-09-28 2:16 ` DuckE
2001-09-28 2:54 ` Pi
2001-09-28 3:41 ` David Botton
2001-09-28 3:16 ` David Botton
2 siblings, 2 replies; 16+ messages in thread
From: DuckE @ 2001-09-28 2:16 UTC (permalink / raw)
Here's how I make the OS call on WindowsNT/W2K using ObjectAda or GNAT:
WITH Win32;
WITH Win32.WinBase;
WITH Interfaces.C;
...
PACKAGE WinBase RENAMES Win32.WinBase;
PACKAGE C RENAMES Interfaces.C;
USE TYPE Win32.BOOL;
USE TYPE Win32.DWORD;
...
PROCEDURE RenameFileDFU( sourceFileNameDFU, destFileNameDFU : STRING;
renamedDFU : out BOOLEAN ) IS
result : Win32.BOOL;
sourceName : ALIASED C.Char_Array := C.To_C( sourceFileNameDFU );
destName : ALIASED C.Char_Array := C.To_C( destFileNameDFU );
BEGIN
result := WinBase.MoveFile( sourceName(0)'UNCHECKED_ACCESS,
destName(0)'UNCHECKED_ACCESS );
renamedDFU := result /= Win32.FALSE;
END RenameFileDFU;
I hope this helps,
SteveD
"Pi" <pi3_1415926536@yahoo.ca> wrote in message
news:MYKs7.11405$%r.2963162@news20.bellglobal.com...
> It may sound stupid, but I didn't find anything.
>
> Is there a way to rename files in Ada?
>
> Other than :
> create a new file,
> copy every byte into the new one,
> delete the old one.
>
> --
> 3,14159265359
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: How to rename a file?
2001-09-28 2:16 ` DuckE
@ 2001-09-28 2:54 ` Pi
2001-09-28 3:41 ` David Botton
1 sibling, 0 replies; 16+ messages in thread
From: Pi @ 2001-09-28 2:54 UTC (permalink / raw)
Thanks buddy,
I'll try it tomorrow :-)
DuckE wrote :
> Here's how I make the OS call on WindowsNT/W2K using ObjectAda or GNAT:
>
> WITH Win32;
> WITH Win32.WinBase;
> WITH Interfaces.C;
> ...
> PACKAGE WinBase RENAMES Win32.WinBase;
> PACKAGE C RENAMES Interfaces.C;
>
> USE TYPE Win32.BOOL;
> USE TYPE Win32.DWORD;
> ...
> PROCEDURE RenameFileDFU( sourceFileNameDFU, destFileNameDFU : STRING;
> renamedDFU : out BOOLEAN ) IS
> result : Win32.BOOL;
> sourceName : ALIASED C.Char_Array := C.To_C( sourceFileNameDFU );
> destName : ALIASED C.Char_Array := C.To_C( destFileNameDFU );
> BEGIN
> result := WinBase.MoveFile( sourceName(0)'UNCHECKED_ACCESS,
> destName(0)'UNCHECKED_ACCESS );
> renamedDFU := result /= Win32.FALSE;
> END RenameFileDFU;
>
> I hope this helps,
> SteveD
>
> "Pi" <pi3_1415926536@yahoo.ca> wrote in message
> news:MYKs7.11405$%r.2963162@news20.bellglobal.com...
> > It may sound stupid, but I didn't find anything.
> >
> > Is there a way to rename files in Ada?
> >
> > Other than :
> > create a new file,
> > copy every byte into the new one,
> > delete the old one.
> >
> > --
> > 3,14159265359
> >
>
>
--
3,14159265359
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: How to rename a file?
2001-09-27 19:43 How to rename a file? Pi
2001-09-27 23:09 ` tmoran
2001-09-28 2:16 ` DuckE
@ 2001-09-28 3:16 ` David Botton
2001-09-28 16:03 ` Jeffrey Carter
2 siblings, 1 reply; 16+ messages in thread
From: David Botton @ 2001-09-28 3:16 UTC (permalink / raw)
To: comp.lang.ada
> Is there a way to rename files in Ada?
Using GNAT, you would use
GNAT.OS_Lib.Rename_File (Old_Name, New_Name);
Take a look around the GNAT.* packages, you will find many goodies!
David Botton
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: How to rename a file?
2001-09-28 2:16 ` DuckE
2001-09-28 2:54 ` Pi
@ 2001-09-28 3:41 ` David Botton
2001-09-28 7:39 ` Lutz Donnerhacke
` (2 more replies)
1 sibling, 3 replies; 16+ messages in thread
From: David Botton @ 2001-09-28 3:41 UTC (permalink / raw)
To: comp.lang.ada
On Win32 if you wish to be cross compiler (this also demonstrates why thin
bindings are mostly a waste of time for Ada):
First the ugly method:
function Rename_File (Old_File, New_File : String) return Boolean
is
Old_C : Interfaces.C.Char_Array := Interfaces.C.To_C (Old_File);
New_C : Interfaces.C.Char_Array := Interfaces.C.To_C (New_File);
function MoveFile
(Old_Name : Interfaces.C.Char_Array := Old_C;
New_Name : Interfaces.C.Char_Array := New_C)
return Boolean;
pragma Import (StdCall, MoveFile, "MoveFileA");
begin
return MoveFile;
end Rename_File;
Now the cool method:
function Rename_File2 (Old_File, New_File : String) return Boolean
is
function MoveFile
(Old_Name : String := Old_File & Character'Val (0);
New_Name : String := New_File & Character'Val (0))
return Boolean;
pragma Import (StdCall, MoveFile, "MoveFileA");
begin
return MoveFile;
end Rename_File2;
Ada arrays are passed as C arrays do to the import so the use of String is
valid, we just need to Zero terminate. Ada record types are also passed as
pointers, which makes life a lot easier. For many more examples look through
the bodies of GWindows code http://www.adapower.com/gwindows
BTW, if you don't care about the result:
procedure Rename_File3 (Old_File, New_File : String)
is
procedure MoveFile
(Old_Name : String := Old_File & Character'Val (0);
New_Name : String := New_File & Character'Val (0));
pragma Import (StdCall, MoveFile, "MoveFileA");
begin
MoveFile;
end Rename_File3;
If you are using a compiler other then GNAT, you may need to insure that
WinBase.lib is linked in (as you would using a Win32 thin binding).
David Botton
----- Original Message -----
From: "DuckE" <nospam_steved94@home.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Thursday, September 27, 2001 10:16 PM
Subject: Re: How to rename a file?
> Here's how I make the OS call on WindowsNT/W2K using ObjectAda or GNAT:
>
> WITH Win32;
> WITH Win32.WinBase;
> WITH Interfaces.C;
> ...
> PACKAGE WinBase RENAMES Win32.WinBase;
> PACKAGE C RENAMES Interfaces.C;
>
> USE TYPE Win32.BOOL;
> USE TYPE Win32.DWORD;
> ...
> PROCEDURE RenameFileDFU( sourceFileNameDFU, destFileNameDFU : STRING;
> renamedDFU : out BOOLEAN ) IS
> result : Win32.BOOL;
> sourceName : ALIASED C.Char_Array := C.To_C( sourceFileNameDFU );
> destName : ALIASED C.Char_Array := C.To_C( destFileNameDFU );
> BEGIN
> result := WinBase.MoveFile( sourceName(0)'UNCHECKED_ACCESS,
> destName(0)'UNCHECKED_ACCESS );
> renamedDFU := result /= Win32.FALSE;
> END RenameFileDFU;
>
> I hope this helps,
> SteveD
>
> "Pi" <pi3_1415926536@yahoo.ca> wrote in message
> news:MYKs7.11405$%r.2963162@news20.bellglobal.com...
> > It may sound stupid, but I didn't find anything.
> >
> > Is there a way to rename files in Ada?
> >
> > Other than :
> > create a new file,
> > copy every byte into the new one,
> > delete the old one.
> >
> > --
> > 3,14159265359
> >
>
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: How to rename a file?
2001-09-28 3:41 ` David Botton
@ 2001-09-28 7:39 ` Lutz Donnerhacke
2001-09-28 17:34 ` Pascal Obry
2001-09-29 5:02 ` DuckE
2 siblings, 0 replies; 16+ messages in thread
From: Lutz Donnerhacke @ 2001-09-28 7:39 UTC (permalink / raw)
* David Botton wrote:
>Ada arrays are passed as C arrays do to the import so the use of String is
>valid, we just need to Zero terminate. Ada record types are also passed as
>pointers, which makes life a lot easier.
There is no guarantee AFAIK. Even GCC (not to mention Ada) has different
ways to do this. Therefore I prefer passing Interfaces.C.Strings.char_p over
Interfaces.C.char_array over Standard.String. Especially, if you look how
Standard.String is implemented: As a small struct, passable in registers or
as a pointer to this struct. In the latter case your C-function may assume
the pointer to the memory area containing the string values and the bounds.
-fpcc-struct-return
Use the same convention for returning struct and
union values that is used by the usual C compiler
on your system. This convention is less efficient
for small structures, and on many machines it fails
to be reentrant; but it has the advantage of allow�
ing intercallability between GCC-compiled code and
PCC-compiled code.
-freg-struct-return
Use the convention that struct and union values are
returned in registers when possible. This is more
efficient for small structures than
-fpcc-struct-return.
If you specify neither -fpcc-struct-return nor
-freg-struct-return, GNU CC defaults to whichever
convention is standard for the target. If there is
no standard convention, GNU CC defaults to
-fpcc-struct-return.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: How to rename a file?
2001-09-28 3:16 ` David Botton
@ 2001-09-28 16:03 ` Jeffrey Carter
0 siblings, 0 replies; 16+ messages in thread
From: Jeffrey Carter @ 2001-09-28 16:03 UTC (permalink / raw)
For portability, I would suggest using Posix.Files.Rename. Posix is both
OS and compiler independent. Implementations exist for most platforms.
GNAT.OS_Lib is OS independent but compiler dependent. Putting Win32
calls in your code is probably compiler independent but definitely OS
dependent.
--
Jeffrey Carter
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: How to rename a file?
2001-09-28 3:41 ` David Botton
2001-09-28 7:39 ` Lutz Donnerhacke
@ 2001-09-28 17:34 ` Pascal Obry
2001-09-28 18:39 ` Larry Kilgallen
2001-09-30 1:51 ` David Botton
2001-09-29 5:02 ` DuckE
2 siblings, 2 replies; 16+ messages in thread
From: Pascal Obry @ 2001-09-28 17:34 UTC (permalink / raw)
"David Botton" <David@Botton.com> writes:
> On Win32 if you wish to be cross compiler (this also demonstrates why thin
> bindings are mostly a waste of time for Ada):
>
> First the ugly method:
>
(code removed)
>
> Now the cool method:
>
(code removed)
Now the really cool method :)
POSIX.Files.Rename ("myoldfile", "whateveristhenewname");
All the ugly binding to the OS has been done by the POSIX bindings
developers... don't waste your time !
Pascal.
--
--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: How to rename a file?
2001-09-28 17:34 ` Pascal Obry
@ 2001-09-28 18:39 ` Larry Kilgallen
2001-09-30 1:51 ` David Botton
1 sibling, 0 replies; 16+ messages in thread
From: Larry Kilgallen @ 2001-09-28 18:39 UTC (permalink / raw)
In article <uofnvnrrz.fsf@wanadoo.fr>, Pascal Obry <p.obry@wanadoo.fr> writes:
>
> "David Botton" <David@Botton.com> writes:
>
>> On Win32 if you wish to be cross compiler (this also demonstrates why thin
>> bindings are mostly a waste of time for Ada):
>>
>> First the ugly method:
>>
>
> (code removed)
>
>>
>> Now the cool method:
>>
>
> (code removed)
>
> Now the really cool method :)
>
> POSIX.Files.Rename ("myoldfile", "whateveristhenewname");
>
> All the ugly binding to the OS has been done by the POSIX bindings
> developers...
Only if you are satisfied with least-common-denominator semantics,
avoiding OS-specific features.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: How to rename a file?
2001-09-28 3:41 ` David Botton
2001-09-28 7:39 ` Lutz Donnerhacke
2001-09-28 17:34 ` Pascal Obry
@ 2001-09-29 5:02 ` DuckE
2 siblings, 0 replies; 16+ messages in thread
From: DuckE @ 2001-09-29 5:02 UTC (permalink / raw)
I've used both methods. I don't find thin bindings to be a waste of time,
mainly because it keeps me from having to define constants, structures,
function and procedure prototypes. Creating these definitions can be
tricky.
Using the thin bindings _usually_ the prototypes are right, it's just a
matter of setting up the arguments correctly.
IMHO
SteveD
"David Botton" <David@Botton.com> wrote in message
news:mailman.1001648485.22108.comp.lang.ada@ada.eu.org...
> On Win32 if you wish to be cross compiler (this also demonstrates why thin
> bindings are mostly a waste of time for Ada):
>
[snip]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: How to rename a file?
2001-09-28 17:34 ` Pascal Obry
2001-09-28 18:39 ` Larry Kilgallen
@ 2001-09-30 1:51 ` David Botton
2001-09-30 8:53 ` Pascal Obry
1 sibling, 1 reply; 16+ messages in thread
From: David Botton @ 2001-09-30 1:51 UTC (permalink / raw)
To: comp.lang.ada
That's not cool, but certainly an alternative.
The coolness is in that code was that you don't need any "special" bindings
for accessing low level C calls. In fact I think far to much emphasis has
been placed on the need of thin bindings. Concentration should rather be
made on "frameworks" (which POSIX bindings may perhaps also be included, as
cross platform was in mind) and tools that abstract the C interfaces and
work in a more Ada like nature.
David Botton
----- Original Message -----
From: "Pascal Obry" <p.obry@wanadoo.fr>
> Now the really cool method :)
>
> POSIX.Files.Rename ("myoldfile", "whateveristhenewname");
>
> All the ugly binding to the OS has been done by the POSIX bindings
> developers... don't waste your time !
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: How to rename a file?
2001-09-30 1:51 ` David Botton
@ 2001-09-30 8:53 ` Pascal Obry
2001-09-30 10:21 ` Florian Weimer
0 siblings, 1 reply; 16+ messages in thread
From: Pascal Obry @ 2001-09-30 8:53 UTC (permalink / raw)
"David Botton" <David@Botton.com> writes:
> That's not cool, but certainly an alternative.
;)
> The coolness is in that code was that you don't need any "special" bindings
> for accessing low level C calls. In fact I think far to much emphasis has
> been placed on the need of thin bindings. Concentration should rather be
David, really POSIX is *far* from being a thin binding.
Your cool example is way more thin than mine :)
<<
function Rename_File2 (Old_File, New_File : String) return Boolean
is
function MoveFile
(Old_Name : String := Old_File & Character'Val (0);
New_Name : String := New_File & Character'Val (0))
return Boolean;
pragma Import (StdCall, MoveFile, "MoveFileA");
begin
return MoveFile;
end Rename_File2;
>>
Character'Val (0), Stdcall, pragma Import...
> made on "frameworks" (which POSIX bindings may perhaps also be included, as
> cross platform was in mind) and tools that abstract the C interfaces and
> work in a more Ada like nature.
I won't call POSIX a framework since it is a _binding_ but yet not a
thin one. And yes in cross-platform environemnt it is definitly the
choice, this is why I do use it!
Pascal.
--
--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: How to rename a file?
2001-09-30 8:53 ` Pascal Obry
@ 2001-09-30 10:21 ` Florian Weimer
2001-09-30 14:53 ` Pascal Obry
0 siblings, 1 reply; 16+ messages in thread
From: Florian Weimer @ 2001-09-30 10:21 UTC (permalink / raw)
Pascal Obry <p.obry@wanadoo.fr> writes:
>> made on "frameworks" (which POSIX bindings may perhaps also be included, as
>> cross platform was in mind) and tools that abstract the C interfaces and
>> work in a more Ada like nature.
>
> I won't call POSIX a framework since it is a _binding_ but yet not a
> thin one.
Most POSIX.5 implementations aren't bindings.
> And yes in cross-platform environemnt it is definitly the choice,
> this is why I do use it!
IMHO, the POSIX.5 interface is a horrible mess, combining the
uselessness of POSIX.1 with some additional unfortunate design
decisions.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: How to rename a file?
2001-09-30 10:21 ` Florian Weimer
@ 2001-09-30 14:53 ` Pascal Obry
0 siblings, 0 replies; 16+ messages in thread
From: Pascal Obry @ 2001-09-30 14:53 UTC (permalink / raw)
Florian Weimer <fw@deneb.enyo.de> writes:
> Pascal Obry <p.obry@wanadoo.fr> writes:
>
> >> made on "frameworks" (which POSIX bindings may perhaps also be included, as
> >> cross platform was in mind) and tools that abstract the C interfaces and
> >> work in a more Ada like nature.
> >
> > I won't call POSIX a framework since it is a _binding_ but yet not a
> > thin one.
>
> Most POSIX.5 implementations aren't bindings.
>
> > And yes in cross-platform environemnt it is definitly the choice,
> > this is why I do use it!
>
> IMHO, the POSIX.5 interface is a horrible mess, combining the
> uselessness of POSIX.1 with some additional unfortunate design
> decisions.
Maybe, maybe not... I'm not a POSIX expert ! But yet I have some large
applications that run without modification on Linux and Windows using a lot
OS routines (Renaming files, running subprocess, waiting for process to
terminate, retrieving environment variable values, retrieving all files on a
specific directory...). I'm not saying that POSIX is in theory a good choice
but it is the best choice I have seen so far... Do you know of other choices ?
Pascal.
--
--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2001-09-30 14:53 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-27 19:43 How to rename a file? Pi
2001-09-27 23:09 ` tmoran
2001-09-27 23:36 ` Larry Kilgallen
2001-09-28 2:16 ` DuckE
2001-09-28 2:54 ` Pi
2001-09-28 3:41 ` David Botton
2001-09-28 7:39 ` Lutz Donnerhacke
2001-09-28 17:34 ` Pascal Obry
2001-09-28 18:39 ` Larry Kilgallen
2001-09-30 1:51 ` David Botton
2001-09-30 8:53 ` Pascal Obry
2001-09-30 10:21 ` Florian Weimer
2001-09-30 14:53 ` Pascal Obry
2001-09-29 5:02 ` DuckE
2001-09-28 3:16 ` David Botton
2001-09-28 16:03 ` Jeffrey Carter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox