comp.lang.ada
 help / color / mirror / Atom feed
* Text control characters
@ 1997-09-10  0:00 John Woodruff
  1997-09-11  0:00 ` Anonymous
  1997-09-11  0:00 ` Dale Stanbrough
  0 siblings, 2 replies; 8+ messages in thread
From: John Woodruff @ 1997-09-10  0:00 UTC (permalink / raw)




By coincidence, Jeff Meyer asked a question on this forum that is a
topic I have been puzzling.  He wants a multi-line text box; I want
multiple lines in a string constant.  Maybe one answer fits all ...

I can construct some function that returns a string.  I wish to compose
such functions in a way to make a textual report, and deliver that
report as a string.  I wish I could format the string into lines in a
way to make it relatively easy to read.  

The caller of this function may very well choose to Ada.Text_IO.Put the
string into a file, or perhaps might use the string in some other way.

How can I construct a string so that Put will produce line_terminators
in the output?  

Example:
  output : constant string := "line 1 " & <*what goes here?*> & "line 2";

  -- I want the result of 
  Ada.Text_IO.Put (output) ; 
  -- to be 
line 1
line 2

Partial answer:  if I use

    ada.characters.latin_1.CR & ada.characters.latin_1.LF 

this works on some operating system.  Is there a standard-compliant way
to solve the problem in general?

--
John Woodruff                                             N I F   \ ^ /
Lawrence Livermore National Lab                         =====---- < 0 >
510 422 4661                                                      / v \




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

* Re: Text control characters
  1997-09-10  0:00 Text control characters John Woodruff
  1997-09-11  0:00 ` Anonymous
@ 1997-09-11  0:00 ` Dale Stanbrough
  1997-09-12  0:00   ` Robert A Duff
                     ` (2 more replies)
  1 sibling, 3 replies; 8+ messages in thread
From: Dale Stanbrough @ 1997-09-11  0:00 UTC (permalink / raw)



The question is

	"how can i write operating system dependent stuff in an 
	 operation independent manner"


and the answer is

	"by isolating O/S dependent stuff in a package"


package Unix.Line_Terminators is
   Line_Terminator : constant String := Ascii.LF & "";
   
end;


with Unix.Line_Terminators;
package OS.Line_Terminators is


   Line_Terminator : String renames Unix.Line_Terminators.Line_Terminator;


end;


and then get your configuration system to choose the appropriate with
(maybe even use a preprocessor! to select a with statement).

Thinking about it, the preprocessor selection of a with statement
would seem to be a fairly benign use of preprocessors. Can anyone see
any great harm in this scheme?


Dale




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

* Re: Text control characters
  1997-09-10  0:00 Text control characters John Woodruff
@ 1997-09-11  0:00 ` Anonymous
  1997-09-11  0:00 ` Dale Stanbrough
  1 sibling, 0 replies; 8+ messages in thread
From: Anonymous @ 1997-09-11  0:00 UTC (permalink / raw)



On 10 Sep 1997 10:24:35 -0700, woodruff@tanana.llnl.gov (John Woodruff)
wrote:
..
> Example:
>   output : constant string := "line 1 " & <*what goes here?*> & "line 2";
> 
>   -- I want the result of 
>   Ada.Text_IO.Put (output) ; 
>   -- to be 
> line 1
> line 2
> 
> Partial answer:  if I use
> 
>     ada.characters.latin_1.CR & ada.characters.latin_1.LF 
> 
> this works on some operating system.  Is there a standard-compliant way
> to solve the problem in general?

The definition of a line terminator is outside the Ada language
definition, being platform dependent. I don't remember of the POSIX-Ada
bindings address this, and don't have them available to check. One could
do

generic -- Multi_Line_String_Handler
   Max_Line : Positive;
package Multi_Line_String_Handler is
   subtype Line is String (1 .. Max_Line);

   type Multi_Line_String is array (Positive range <>) of Line;

   procedure Put (Item : in Multi_Line_String);
end Multi_Line_String_Handler;

package MLS is new Multi_Line_String_Handler (Max_Line => 6);

Output : constant MLS.Multi_Line_String := ("line 1", "line 2");
..
Put (Item => Output);

and be platform independent.

Jeff Carter  PGP:1024/440FBE21
My real e-mail address: ( carter @ innocon . com )
"English bed-wetting types."
Monty Python & the Holy Grail

Posted with Spam Hater - see
http://www.compulink.co.uk/~net-services/spam/




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

* Re: Text control characters
  1997-09-11  0:00 ` Dale Stanbrough
@ 1997-09-12  0:00   ` Robert A Duff
  1997-09-15  0:00     ` Larry Kilgallen
  1997-09-12  0:00   ` Stephen Leake
  1997-09-13  0:00   ` Tarjei T. Jensen
  2 siblings, 1 reply; 8+ messages in thread
From: Robert A Duff @ 1997-09-12  0:00 UTC (permalink / raw)



In article <5v9vj1$dge$1@goanna.cs.rmit.edu.au>,
Dale Stanbrough  <dale@goanna.cs.rmit.edu.au> wrote:
>Thinking about it, the preprocessor selection of a with statement
>would seem to be a fairly benign use of preprocessors. Can anyone see
>any great harm in this scheme?

To me, it seems better than putting various hacks in your make files or
shell scripts or whatever.  Or, at least, it *would* seem better, if
there were a standard preprocessor for Ada, defined by the language.

- Bob




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

* Re: Text control characters
  1997-09-12  0:00   ` Stephen Leake
@ 1997-09-12  0:00     ` Robert A Duff
  0 siblings, 0 replies; 8+ messages in thread
From: Robert A Duff @ 1997-09-12  0:00 UTC (permalink / raw)



In article <341954D6.162C@gsfc.nasa.gov>,
Stephen Leake  <Stephen.Leake@gsfc.nasa.gov> wrote:
>Dale Stanbrough wrote:
>> Thinking about it, the preprocessor selection of a with statement
>> would seem to be a fairly benign use of preprocessors. Can anyone see
>> any great harm in this scheme?
>
>you don't need a preprocessor;

True, but it doesn't answer Dale's question: Is there any great harm?

>... you can set things up so only the BODY of
>the package is OS dependent, and let the CM system choose which FILE to
>use for the body:

Quite true, but what does moving the OS-dependent stuff into the body
have to do with the issue of whether one uses preprocessors or CM
systems to select pieces of code?  I mean, your technique of selecting a
particular file would work fine on specs, too.

In fact, it might be important for whatever-it-is to be in the spec.
E.g. suppose I want to declare an integer constant whose value is
OS-dependent, but I desperately want the constant to be static?

>Under GNAT, since we're not using the conventional name for the body
>file, we need a configuration pragma:
>
>file gnat.adc:
>--------------------
>pragma Source_File_Name (OS.Line_Terminators,
>                         BODY_FILE_NAME =>
>"os-line_terminator__aix432.adb");
>--------------------

Then you need some way of selecting configuration files.  You can move
this problem around, and solve it with different tools, but you can't
make it go away!

- Bob




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

* Re: Text control characters
  1997-09-11  0:00 ` Dale Stanbrough
  1997-09-12  0:00   ` Robert A Duff
@ 1997-09-12  0:00   ` Stephen Leake
  1997-09-12  0:00     ` Robert A Duff
  1997-09-13  0:00   ` Tarjei T. Jensen
  2 siblings, 1 reply; 8+ messages in thread
From: Stephen Leake @ 1997-09-12  0:00 UTC (permalink / raw)



Dale Stanbrough wrote:
> 
> package Unix.Line_Terminators is
>    Line_Terminator : constant String := Ascii.LF & "";
> 
> end;
> 
> with Unix.Line_Terminators;
> package OS.Line_Terminators is
> 
>    Line_Terminator : String renames Unix.Line_Terminators.Line_Terminator;
> 
> end;
> 
> and then get your configuration system to choose the appropriate with
> (maybe even use a preprocessor! to select a with statement).
> 
> Thinking about it, the preprocessor selection of a with statement
> would seem to be a fairly benign use of preprocessors. Can anyone see
> any great harm in this scheme?

you don't need a preprocessor; you can set things up so only the BODY of
the package is OS dependent, and let the CM system choose which FILE to
use for the body:

file os-line_terminator.ads:
--------------------
package OS.Line_Terminators is
   function Line_Terminator return String;
end OS.Line_Terminators;
--------------------

file os-line_terminator__aix432.adb:
--------------------
package body OS.Line_Terminators is
   -- this is for AIX 4.3.2
   function Line_Terminator return String is
   begin
      return "" & Ascii.LF;
   end Line_terminator;
end OS.Line_Terminators;
--------------------

Under GNAT, since we're not using the conventional name for the body
file, we need a configuration pragma:

file gnat.adc:
--------------------
pragma Source_File_Name (OS.Line_Terminators,
                         BODY_FILE_NAME =>
"os-line_terminator__aix432.adb");
--------------------

other compilers will have other ways of specifying which file contains
which
compilation unit.

-- 
- Stephe




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

* Re: Text control characters
  1997-09-11  0:00 ` Dale Stanbrough
  1997-09-12  0:00   ` Robert A Duff
  1997-09-12  0:00   ` Stephen Leake
@ 1997-09-13  0:00   ` Tarjei T. Jensen
  2 siblings, 0 replies; 8+ messages in thread
From: Tarjei T. Jensen @ 1997-09-13  0:00 UTC (permalink / raw)



>Dale Stanbrough wrote:
> package Unix.Line_Terminators is
>    Line_Terminator : constant String := Ascii.LF & "";
> 
> end;
> 
> with Unix.Line_Terminators;
> package OS.Line_Terminators is
> 
>    Line_Terminator : String renames Unix.Line_Terminators.Line_Terminator;
> 

> end;
> 
> and then get your configuration system to choose the appropriate with
> (maybe even use a preprocessor! to select a with statement).
> 
> Thinking about it, the preprocessor selection of a with statement
> would seem to be a fairly benign use of preprocessors. Can anyone see
> any great harm in this scheme?
> 

You have not solved the problem.

The problem is that CR an LF is not recognized as control characters on
a PC Ada implementation. The I/O system probably pokes the characters
straight to the screen instead of doing a carriage return and line feed.

The easiest way of working around the problem is probably by using a
dynamic array of strings or pointers to strings. If one want to save
overhead one could use one dynamic array with pointers (high, low) to
text fragments in an character array.

One would write the text to the screen in the normal way and put in
explicit calls to do newlines.

Greetings,

-- 
// Tarjei T. Jensen 
//    tarjei@online.no || voice +47 51 62 85 58
//   Support you local rescue centre: GET LOST!




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

* Re: Text control characters
  1997-09-12  0:00   ` Robert A Duff
@ 1997-09-15  0:00     ` Larry Kilgallen
  0 siblings, 0 replies; 8+ messages in thread
From: Larry Kilgallen @ 1997-09-15  0:00 UTC (permalink / raw)



In article <EGEoGL.CH3@world.std.com>, bobduff@world.std.com (Robert A Duff) writes:
> In article <5v9vj1$dge$1@goanna.cs.rmit.edu.au>,
> Dale Stanbrough  <dale@goanna.cs.rmit.edu.au> wrote:
>>Thinking about it, the preprocessor selection of a with statement
>>would seem to be a fairly benign use of preprocessors. Can anyone see
>>any great harm in this scheme?
> 
> To me, it seems better than putting various hacks in your make files or
> shell scripts or whatever.  Or, at least, it *would* seem better, if
> there were a standard preprocessor for Ada, defined by the language.

Ok, so we are talking about an environment in which one has the choice
of building objects for an operating system called Unix or for a totally
distinct operating system (potentially also called Unix :-).  The result
will be bits which will not execute correctly in the "other" environment,
so one is already depending on variations in the build mechanism to put
the output in one place or the other depending on the target.  What is
wrong with also having the build mechanism pull the "os-specific"  package
from one place or the other depending on the target.

Larry Kilgallen




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

end of thread, other threads:[~1997-09-15  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-09-10  0:00 Text control characters John Woodruff
1997-09-11  0:00 ` Anonymous
1997-09-11  0:00 ` Dale Stanbrough
1997-09-12  0:00   ` Robert A Duff
1997-09-15  0:00     ` Larry Kilgallen
1997-09-12  0:00   ` Stephen Leake
1997-09-12  0:00     ` Robert A Duff
1997-09-13  0:00   ` Tarjei T. Jensen

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