comp.lang.ada
 help / color / mirror / Atom feed
* Detecting the OS type before clearing screen
@ 2003-03-24 23:55 Redy RAMAMONJISOA
  2003-03-25  0:58 ` sk
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Redy RAMAMONJISOA @ 2003-03-24 23:55 UTC (permalink / raw)


hello,
Do someone now how can i detect on which operating system my binary
file is executed. I need to write a program in ada and in it, i have
to write a procedure which clear the screen. But i wish to use the
same source code for all systems targeted (MS Windows and Linux
families). I think that this is essential because as far as i know,
Ada does'nt have any build function which clear the terminal screen.
Thanks in advance



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Detecting the OS type before clearing screen
  2003-03-24 23:55 Detecting the OS type before clearing screen Redy RAMAMONJISOA
@ 2003-03-25  0:58 ` sk
  2003-03-25 10:24   ` Samuel Tardieu
  2003-03-25 12:25   ` Wojtek Narczynski
  2003-03-25 17:27 ` Warren W. Gay VE3WWG
  2003-03-25 20:54 ` sk
  2 siblings, 2 replies; 13+ messages in thread
From: sk @ 2003-03-25  0:58 UTC (permalink / raw)
  To: comp.lang.ada mail to news gateway

Hi,

 > ... which operating system my binary file is executed.

I cannot think of circumstances where it is sensible to
expect one binary to be able to run on both on Linux and
Windows.

This is a compile time issue and depends upon the libraries
used (either windows libraries when on windows, Linux
libraries when on Linux).

If you are using Gnat then look at the gnat preprocessor
for methods on how to compile different parts of the code
for each platform.

-- 
-------------------------------------------------
-- Merge vertically for real address
--
--     s n p @ t . o
--      k i e k c c m
-------------------------------------------------




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Detecting the OS type before clearing screen
  2003-03-25  0:58 ` sk
@ 2003-03-25 10:24   ` Samuel Tardieu
  2003-03-25 11:19     ` sk
  2003-03-25 12:25   ` Wojtek Narczynski
  1 sibling, 1 reply; 13+ messages in thread
From: Samuel Tardieu @ 2003-03-25 10:24 UTC (permalink / raw)


>>>>> "sk" == sk  <noname@myob.com> writes:

sk> If you are using Gnat then look at the gnat preprocessor for
sk> methods on how to compile different parts of the code for each
sk> platform.

Rather than using a preprocessor which is really a "non-Ada" way of
doing things, I would suggest using a package with two versions of the
body (and even two version of the spec if the private part is
different).

A link or a copy in the build procedure should do the job.

  Sam
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/sam



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Detecting the OS type before clearing screen
  2003-03-25 10:24   ` Samuel Tardieu
@ 2003-03-25 11:19     ` sk
  2003-03-25 12:47       ` Lutz Donnerhacke
  0 siblings, 1 reply; 13+ messages in thread
From: sk @ 2003-03-25 11:19 UTC (permalink / raw)
  To: comp.lang.ada mail to news gateway

Hi,

sam@rfc1149.net :
 > Rather than using a preprocessor which is really a "non-Ada"
 > way of doing things, I would suggest using a package with
 > two versions of the body (and even two version of the
 > spec if the private part is different).
 >
 > A link or a copy in the build procedure should do the job.

I have found that either way tends to get messy. I don't like
"make" files so I prefer to keep one source and use the gnat
preprocesser.

I would gladly welcome any experience of a "clean Ada" way
of setting this up if you would care to share.

-- 
-------------------------------------------------
-- Merge vertically for real address
--
--     s n p @ t . o
--      k i e k c c m
-------------------------------------------------




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Detecting the OS type before clearing screen
  2003-03-25  0:58 ` sk
  2003-03-25 10:24   ` Samuel Tardieu
@ 2003-03-25 12:25   ` Wojtek Narczynski
  1 sibling, 0 replies; 13+ messages in thread
From: Wojtek Narczynski @ 2003-03-25 12:25 UTC (permalink / raw)


> If you are using Gnat then look at the gnat preprocessor
> for methods on how to compile different parts of the code
> for each platform.

Preprocessors are evil. 

Group all OS specific things in an OS specific file / module.

Regards,
Wojtek



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Detecting the OS type before clearing screen
  2003-03-25 11:19     ` sk
@ 2003-03-25 12:47       ` Lutz Donnerhacke
  2003-03-25 14:26         ` SIMON Claude
  0 siblings, 1 reply; 13+ messages in thread
From: Lutz Donnerhacke @ 2003-03-25 12:47 UTC (permalink / raw)


* sk wrote:
> I would gladly welcome any experience of a "clean Ada" way
> of setting this up if you would care to share.

with Config.OS1; -- Change here

package Config is
   package OS renames Config.OS1; -- and here
   type os-depended-type renames OS.os-depended-type;
   function os-depended-function renames OS.os-depended-function;
   ...
end Config;

private package Config.OS1 is
  ...
end Config.OS1;

private package Config.OS2 is
  ...
end Config.OS2;



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Detecting the OS type before clearing screen
  2003-03-25 12:47       ` Lutz Donnerhacke
@ 2003-03-25 14:26         ` SIMON Claude
  2003-03-25 14:33           ` Lutz Donnerhacke
  0 siblings, 1 reply; 13+ messages in thread
From: SIMON Claude @ 2003-03-25 14:26 UTC (permalink / raw)


Lutz Donnerhacke wrote:
> 
> * sk wrote:
> > I would gladly welcome any experience of a "clean Ada" way
> > of setting this up if you would care to share.
> 
> with Config.OS1; -- Change here
> 
> package Config is
>    package OS renames Config.OS1; -- and here
>    type os-depended-type renames OS.os-depended-type;
>    function os-depended-function renames OS.os-depended-function;
>    ...
> end Config;
> 
> private package Config.OS1 is
>   ...
> end Config.OS1;
> 
> private package Config.OS2 is
>   ...
> end Config.OS2;


why not :

--  file os1.ads
package OS1 is
   ...
end OS1;

-- file os2.ads
package OS2 is
   ...
end OS2;


-- file os.ads
with OS2; -- select the OS --
package OS renames OS2;


-- others files 

with OS;
package is .....


..........renaming the package renames all specifications in one
instruction.........



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Detecting the OS type before clearing screen
  2003-03-25 14:26         ` SIMON Claude
@ 2003-03-25 14:33           ` Lutz Donnerhacke
  2003-03-25 21:48             ` Wojtek Narczynski
  0 siblings, 1 reply; 13+ messages in thread
From: Lutz Donnerhacke @ 2003-03-25 14:33 UTC (permalink / raw)


* SIMON Claude wrote:
> ..........renaming the package renames all specifications in one
> instruction.........

Yep, the reason for my approach was to configure additional items and to
keep the os dependant packages outside the visibility of any other package,
even in the case of errors.

The GNAT approach to solve this is to write several OS-dependant files
containing the *same* package os and linking the right one to os.ads.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Detecting the OS type before clearing screen
  2003-03-24 23:55 Detecting the OS type before clearing screen Redy RAMAMONJISOA
  2003-03-25  0:58 ` sk
@ 2003-03-25 17:27 ` Warren W. Gay VE3WWG
  2003-03-25 20:54 ` sk
  2 siblings, 0 replies; 13+ messages in thread
From: Warren W. Gay VE3WWG @ 2003-03-25 17:27 UTC (permalink / raw)


Redy RAMAMONJISOA wrote:
> hello,
> Do someone now how can i detect on which operating system my binary
> file is executed. I need to write a program in ada and in it, i have
> to write a procedure which clear the screen. But i wish to use the
> same source code for all systems targeted (MS Windows and Linux
> families). I think that this is essential because as far as i know,
> Ada does'nt have any build function which clear the terminal screen.
> Thanks in advance

Apart from the fact (as others have pointed out), you won't have
a single binary, you can use a binding to Curses. Then compile with
curses/ncurses on *NIX platforms, and use PDCurses for Windows.  If
you don't mind making it a CYGWIN executable (under Windows that is),
you can use the ncurses library there as well.

-- 
Warren W. Gay VE3WWG
http://home.cogeco.ca/~ve3wwg




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Detecting the OS type before clearing screen
  2003-03-24 23:55 Detecting the OS type before clearing screen Redy RAMAMONJISOA
  2003-03-25  0:58 ` sk
  2003-03-25 17:27 ` Warren W. Gay VE3WWG
@ 2003-03-25 20:54 ` sk
  2003-03-26 18:43   ` Randy Brukardt
  2003-03-26 20:36   ` Simon Wright
  2 siblings, 2 replies; 13+ messages in thread
From: sk @ 2003-03-25 20:54 UTC (permalink / raw)
  To: comp.lang.ada mail to news gateway

Hi,

 > ... preprocessors are evil

I am going to take that statement with a grain of salt :-)

 > ... <various renames schemes> ...

I like, and use, package renaming to establish different
implementations, but I do not think that the actual build
issue has been addressed.

At some point in the build, a decision has to be made
as to which implementation is required. Some form of
preprocessing is required.

Manually edit the renames every time ? No thanks.

Using make files ? Then either you somehow get "make" to
detect which version you require or edit the makefile
to set a variable.

Shell scripts ? Same as above.

I have found that a simple script similar to ...

#!/bin/bash
gnatprep -D WITHCURSES infile.ada outfile.adb
gnatmake outfile.adb
rm outfile.adb

... is a lot simpler to maintain than messing around with
make files or fancy "sed" scripts to properly set up the
necessary Ada "renames" statements.

I have yet to be convinced that one should refute the
preprocessor based upon the current discussions :-)

-- 
-------------------------------------------------
-- Merge vertically for real address
--
--     s n p @ t . o
--      k i e k c c m
-------------------------------------------------




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Detecting the OS type before clearing screen
  2003-03-25 14:33           ` Lutz Donnerhacke
@ 2003-03-25 21:48             ` Wojtek Narczynski
  0 siblings, 0 replies; 13+ messages in thread
From: Wojtek Narczynski @ 2003-03-25 21:48 UTC (permalink / raw)


Lutz Donnerhacke <lutz@iks-jena.de> wrote in message news:<slrnb80q6c.nt.lutz@taranis.iks-jena.de>...
> * SIMON Claude wrote:
> > ..........renaming the package renames all specifications in one
> > instruction.........
> 
> Yep, the reason for my approach was to configure additional items and to
> keep the os dependant packages outside the visibility of any other package,
> even in the case of errors.
> 
> The GNAT approach to solve this is to write several OS-dependant files
> containing the *same* package os and linking the right one to os.ads.

Symlinks work for this. Well, on some systems ;-)

Regards,
Wojtek



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Detecting the OS type before clearing screen
  2003-03-25 20:54 ` sk
@ 2003-03-26 18:43   ` Randy Brukardt
  2003-03-26 20:36   ` Simon Wright
  1 sibling, 0 replies; 13+ messages in thread
From: Randy Brukardt @ 2003-03-26 18:43 UTC (permalink / raw)


sk wrote in message ...
>I like, and use, package renaming to establish different
>implementations, but I do not think that the actual build
>issue has been addressed.
>
>At some point in the build, a decision has to be made
>as to which implementation is required. Some form of
>preprocessing is required.
>
>Manually edit the renames every time ? No thanks.


We just keep a copy of each version of the files in different
directories, and point the make file (or whatever) at the correct one.

Generally, when this sort of thing is required, you're building the two
versions with different toolchains: a different version of the compiler,
runtime, linker, make tool, etc. Sometimes even with tools from
different vendors (with Claw, for instance, we regularly test with four
different compilers). Using a different make file and maintaining
multiple copies of a handful of source files is the least of the
problems.

The original questioner certainly was going to have to face that: you
need different versions of Gnat to make Linux and Windows files.
Preprocessing doesn't help here.

What preprocessing is good for is separating debugging/testing
infrastructure from the rest of the program. That's especially important
if its expensive (in time or space); usually it's best to keep that
stuff around for the inevitable debugging that happens when users find
bugs - sometimes you can reuse previous debugging code to find new
problems. But it's better to deliver code without that; otherwise it is
tied to a particular compiler, and that is bad.

          Randy.





^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Detecting the OS type before clearing screen
  2003-03-25 20:54 ` sk
  2003-03-26 18:43   ` Randy Brukardt
@ 2003-03-26 20:36   ` Simon Wright
  1 sibling, 0 replies; 13+ messages in thread
From: Simon Wright @ 2003-03-26 20:36 UTC (permalink / raw)


sk <noname@myob.com> writes:

> Using make files ? Then either you somehow get "make" to
> detect which version you require or edit the makefile
> to set a variable.

The new GNAT Project feature lets you do this based on envirnment
variables or gnatmake switches.

   project Foo is

      type Target_Type is ("host", "target");

      Target : Target_Type := external ("TARGET", "host");

      case Target is

         when "host" =>
            for Source_Dirs use (".", "./host");

         when "target" =>
            for Source_Dirs use (".", "./target");

      end case;

   end Foo;

means you put the spec inthe same directory as the project file, the
target (eg VxWorks) body in ./target and the host (eg Linux) body in
./host. The default is the host version; select the other by either

   TARGET=target gnatmake -PFoo

or 

   gnatmake -PFoo -XTARGET=target

See http://gcc.gnu.org/onlinedocs/gnat_ug_unx/GNAT-Project-Manager.html#GNAT%20Project%20Manager

-S



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2003-03-26 20:36 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-24 23:55 Detecting the OS type before clearing screen Redy RAMAMONJISOA
2003-03-25  0:58 ` sk
2003-03-25 10:24   ` Samuel Tardieu
2003-03-25 11:19     ` sk
2003-03-25 12:47       ` Lutz Donnerhacke
2003-03-25 14:26         ` SIMON Claude
2003-03-25 14:33           ` Lutz Donnerhacke
2003-03-25 21:48             ` Wojtek Narczynski
2003-03-25 12:25   ` Wojtek Narczynski
2003-03-25 17:27 ` Warren W. Gay VE3WWG
2003-03-25 20:54 ` sk
2003-03-26 18:43   ` Randy Brukardt
2003-03-26 20:36   ` Simon Wright

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox