comp.lang.ada
 help / color / mirror / Atom feed
* Ada Characters?
@ 2002-02-28  2:07 Wannabe h4x0r
  2002-02-28  2:28 ` Jim Rogers
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Wannabe h4x0r @ 2002-02-28  2:07 UTC (permalink / raw)


I'm trying to figure out how to get my Ada program to single out ASCII
control codes without hosing the output of the rest of the text file. 

Basically, I'm doing it like this...
with Ada.Characters; use Ada.Characters.Handling;

	TEXT : string(1..200);
	chk_char: character;  -- Check to see if this is a control character.
	chk_result : boolean;
	
and the code goes like this ...

	for l in TEXT'range loop
		chk_char := TEXT(l);
		chk_result := Is_control(chk_char);
			if chk_result is True then
				if <how do I check to see if it's a NL(new line) character?> then
					NEW_LINE;
				else
					NULL;
				end if;
			else
				Put(chk_char); --Put each character individually
			end if;
	end loop;

Anyways, that's the general gist of it.

Now, I got a short program that opens a text file, and reads from it, but
all it does is spew out control codes. Really odd. I really dont have a
handle on this as I can tell.

Tips?

Chris



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

* Re: Ada Characters?
  2002-02-28  2:07 Ada Characters? Wannabe h4x0r
@ 2002-02-28  2:28 ` Jim Rogers
  2002-02-28  2:37 ` sk
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Jim Rogers @ 2002-02-28  2:28 UTC (permalink / raw)


Wannabe h4x0r wrote:

> I'm trying to figure out how to get my Ada program to single out ASCII
> control codes without hosing the output of the rest of the text file. 
> 
> Basically, I'm doing it like this...
> with Ada.Characters; use Ada.Characters.Handling;
> 
> 	TEXT : string(1..200);
> 	chk_char: character;  -- Check to see if this is a control character.
> 	chk_result : boolean;
> 	
> and the code goes like this ...
> 
> 	for l in TEXT'range loop
> 		chk_char := TEXT(l);
> 		chk_result := Is_control(chk_char);
> 			if chk_result is True then
> 				if <how do I check to see if it's a NL(new line) character?> then
> 					NEW_LINE;
> 				else
> 					NULL;
> 				end if;
> 			else
> 				Put(chk_char); --Put each character individually
> 			end if;
> 	end loop;


with Ada.Characters.Latin_1;
with Ada.Characters.Handling; use Ada.Characters.Handling;

...

for l in TEXT'range loop
    chk_char := TEXT(l);
    if Is_Control(chk_char) then
       if chk_char = Ada.Characters.Latin_1.LF then
          Ada.Text_IO.Put(chk_char);
       end if;
     else
       Ada.Text_IO.Put(chk_char);
     end if;
end loop;

Jim Rogers





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

* Re: Ada Characters?
  2002-02-28  2:07 Ada Characters? Wannabe h4x0r
  2002-02-28  2:28 ` Jim Rogers
@ 2002-02-28  2:37 ` sk
  2002-02-28 13:16 ` Georg Bauhaus
  2002-02-28 22:54 ` Jeffrey Carter
  3 siblings, 0 replies; 9+ messages in thread
From: sk @ 2002-02-28  2:37 UTC (permalink / raw)


Hi,

> if <how do I check to see if it's a NL(new line) character?> then

???

How about looking at the packages Ada.Characters.Latin_1 or ASCII ?

if TEXT(I) = Ada.Characters.Latin_1.NL ...

if TEXT(I) = ASCII.NL ...

or even 

if Ada.Text_Io.End_Of_Line (<file>) then ...

These are quick-and-dirty, so the names of constants might be
wrong (NL ?, perhaps CR, cannot remember).

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



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

* Re: Ada Characters?
  2002-02-28  2:07 Ada Characters? Wannabe h4x0r
  2002-02-28  2:28 ` Jim Rogers
  2002-02-28  2:37 ` sk
@ 2002-02-28 13:16 ` Georg Bauhaus
  2002-02-28 19:30   ` Wannabe h4x0r
  2002-02-28 22:54 ` Jeffrey Carter
  3 siblings, 1 reply; 9+ messages in thread
From: Georg Bauhaus @ 2002-02-28 13:16 UTC (permalink / raw)


Wannabe h4x0r <chris@dont.spam.me> wrote:

: 
:        TEXT : string(1..200);

how do you fill this?

- georg



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

* Re: Ada Characters?
  2002-02-28 13:16 ` Georg Bauhaus
@ 2002-02-28 19:30   ` Wannabe h4x0r
  2002-03-01 10:50     ` Georg Bauhaus
  2002-03-05 20:58     ` Nick Roberts
  0 siblings, 2 replies; 9+ messages in thread
From: Wannabe h4x0r @ 2002-02-28 19:30 UTC (permalink / raw)


On Thu, 28 Feb 2002 08:16:42 -0500, Georg Bauhaus wrote:

> Wannabe h4x0r <chris@dont.spam.me> wrote:
> 
> :
> :        TEXT : string(1..200);
> 
> how do you fill this?
> 
> - georg

Usually from a text file, like this ...

with Ada.Text_IO; use Ada.Text_IO;

	Length : Natural;
	Open(File, IN_FILE, TEXT(1..LENGTH));

This usually works fine. All I have to do is use a loop to however many
lines my terminal will support in order to page the output on screen.

Chris



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

* Re: Ada Characters?
  2002-02-28  2:07 Ada Characters? Wannabe h4x0r
                   ` (2 preceding siblings ...)
  2002-02-28 13:16 ` Georg Bauhaus
@ 2002-02-28 22:54 ` Jeffrey Carter
  3 siblings, 0 replies; 9+ messages in thread
From: Jeffrey Carter @ 2002-02-28 22:54 UTC (permalink / raw)


Wannabe h4x0r wrote:
> 
> I'm trying to figure out how to get my Ada program to single out ASCII
> control codes without hosing the output of the rest of the text file.
> 
> Basically, I'm doing it like this...
> with Ada.Characters; use Ada.Characters.Handling;
> 
>         TEXT : string(1..200);
>         chk_char: character;  -- Check to see if this is a control character.
>         chk_result : boolean;
> 
> and the code goes like this ...
> 
>         for l in TEXT'range loop
>                 chk_char := TEXT(l);
>                 chk_result := Is_control(chk_char);
>                         if chk_result is True then
>                                 if <how do I check to see if it's a NL(new line) character?> then
>                                         NEW_LINE;
>                                 else
>                                         NULL;
>                                 end if;
>                         else
>                                 Put(chk_char); --Put each character individually
>                         end if;
>         end loop;
> 
> Anyways, that's the general gist of it.

I don't understand what you're trying to do. How do you fill Text and
how does it get control characters in it? What character do you mean by
NL? No such character is defined in Ada.Characters.Latin_1. Ada.Text_IO
line terminators are not defined by the language and differ from OS to
OS; on some systems a line terminator is a single character while on
others it is a sequence of characters.

-- 
Jeffrey Carter



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

* Re: Ada Characters?
  2002-02-28 19:30   ` Wannabe h4x0r
@ 2002-03-01 10:50     ` Georg Bauhaus
  2002-03-05 20:58     ` Nick Roberts
  1 sibling, 0 replies; 9+ messages in thread
From: Georg Bauhaus @ 2002-03-01 10:50 UTC (permalink / raw)


Wannabe h4x0r <chris@dont.spam.me> wrote:
 
:> :        TEXT : string(1..200);
:> 
:> how do you fill this?
: 
: Usually from a text file, like this ...
: 
:        Open(File, IN_FILE, TEXT(1..LENGTH));

uhm so text is both a file name and a buffer
for I/O via text_IO? So how is text filled, exactly?

: This usually works fine. All I have to do is use a loop to however many
: lines my terminal will support in order to page the output on screen.

Ah, a pager then?



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

* Re: Ada Characters?
  2002-02-28 19:30   ` Wannabe h4x0r
  2002-03-01 10:50     ` Georg Bauhaus
@ 2002-03-05 20:58     ` Nick Roberts
  2002-03-06  1:45       ` Wannabe h4x0r
  1 sibling, 1 reply; 9+ messages in thread
From: Nick Roberts @ 2002-03-05 20:58 UTC (permalink / raw)


On Thu, 28 Feb 2002 19:30:39 GMT, Wannabe h4x0r <chris@dont.spam.me>
strongly typed:

>This usually works fine. All I have to do is use a loop to however many
>lines my terminal will support in order to page the output on screen.

I feel sure I can get away with providing a couple of hints. First, it is
not necessary or advisable to deal with control codes: use Get_Line and
New_Line. Second, you may (or may not) wish to detect End_of_Page, and
perhaps stop displaying lines in the current 'frame' when encountering one.

For the sake of clean programming (at least), I suggest two text buffers
are kept: one for the file name, and one for buffering lines of text as
they are read in. Two other variables should be kept, integers, containing
the actual length of the string in each text buffer.

-- 
Nick Roberts



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

* Re: Ada Characters?
  2002-03-05 20:58     ` Nick Roberts
@ 2002-03-06  1:45       ` Wannabe h4x0r
  0 siblings, 0 replies; 9+ messages in thread
From: Wannabe h4x0r @ 2002-03-06  1:45 UTC (permalink / raw)


Your right. This method greatly simplifies things.

Thanks.

Chris



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

end of thread, other threads:[~2002-03-06  1:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-28  2:07 Ada Characters? Wannabe h4x0r
2002-02-28  2:28 ` Jim Rogers
2002-02-28  2:37 ` sk
2002-02-28 13:16 ` Georg Bauhaus
2002-02-28 19:30   ` Wannabe h4x0r
2002-03-01 10:50     ` Georg Bauhaus
2002-03-05 20:58     ` Nick Roberts
2002-03-06  1:45       ` Wannabe h4x0r
2002-02-28 22:54 ` Jeffrey Carter

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