From: "jimmaureenrogers@worldnet.att.net" <jimmaureenrogers@worldnet.att.net>
Subject: Re: Char type verification
Date: 15 Nov 2006 17:08:53 -0800
Date: 2006-11-15T17:08:53-08:00 [thread overview]
Message-ID: <1163639333.330603.208930@k70g2000cwa.googlegroups.com> (raw)
In-Reply-To: 1163628033.606530.190550@i42g2000cwa.googlegroups.com
This is an awful piece of code because it must perform a number
of conversions between character and numeric values. Nonetheless,
I believe I have produced a transliteration of the C into Ada, with the
addition of dealing with the first character of each value on the
command
line, not just the first value.
--Assume that I have the following C code:
--#include <stdio.h>
--#define uchar unsigned char
--static uchar UCASE[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
--int _isupper(uchar c)
--{
-- return (c==UCASE[(c%'A')%26]);
--}
--int main(int argc, char *argv[])
--{
-- uchar c = (uchar) *argv[1];
-- printf("_isupper('%c')? = %d\n",c,_isupper(c));
-- return 0;
--}
with Ada.Text_Io;
with Ada.Command_Line;
procedure Simulate_Uchar is
type Uchar is mod 256;
function Is_Upper(Item : in Uchar) return Boolean is
subtype Char_Index is Positive range 1..26;
begin
return ((1 + Character'Pos(Character'Val(Positive(Item))) -
Character'Pos('A')) in Char_Index);
end Is_Upper;
Input : Character;
U_Input : Uchar;
begin
for N in 1..Ada.Command_Line.Argument_Count loop
Input := Ada.Command_Line.Argument(N)(1);
U_Input := Uchar(Character'Pos(Input));
Ada.Text_Io.Put("Is_Upper(" & Uchar'Image(U_Input) & ")? = ");
Ada.Text_IO.Put_Line(Boolean'Image(Is_Upper(U_Input)) );
end loop;
end Simulate_Uchar;
Jim Rogers
next prev parent reply other threads:[~2006-11-16 1:08 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-15 22:00 Char type verification KE
2006-11-15 21:57 ` Georg Bauhaus
2006-11-15 23:15 ` KE
2006-11-16 4:48 ` Jeffrey R. Carter
2006-11-16 19:53 ` Adam Beneschan
2006-11-16 23:30 ` Yves Bailly
2006-11-17 0:48 ` Jeffrey R. Carter
2006-11-17 1:59 ` Adam Beneschan
2006-11-17 11:30 ` Stephen Leake
2006-11-17 15:33 ` KE
2006-11-17 15:10 ` Georg Bauhaus
2006-11-17 18:30 ` Ludovic Brenta
2006-11-18 2:29 ` Brian May
2006-11-17 19:45 ` Jeffrey R. Carter
[not found] ` <mQm7h.8782$ig4.3262@newsread2.news.pas.earthlink.net>
2006-11-17 19:56 ` Jeffrey R. Carter
[not found] ` <omz7h.222$1s6.165@newsread2.news.pas.earthlink.net>
2006-11-19 2:19 ` OT: French Idioms (was Re: Char type verification) Jeffrey R. Carter
2006-11-19 9:04 ` Dmitry A. Kazakov
2006-11-17 21:22 ` Char type verification Simon Wright
2006-11-17 23:59 ` Yves Bailly
2006-11-15 23:23 ` Simon Wright
2006-11-15 23:33 ` KE
2006-11-16 4:52 ` Jeffrey R. Carter
2006-11-15 23:36 ` Adam Beneschan
2006-11-15 23:55 ` KE
2006-11-16 4:54 ` Jeffrey R. Carter
2006-11-16 1:08 ` jimmaureenrogers [this message]
2006-11-16 1:45 ` KE
2006-11-16 2:15 ` jimmaureenrogers
2006-11-16 2:42 ` Steve Whalen
2006-11-16 9:36 ` Alex R. Mosteo
2006-11-16 7:02 ` KE
2006-11-16 17:04 ` Dmitry A. Kazakov
2006-11-16 22:43 ` Brian May
-- strict thread matches above, loose matches on Subject: below --
2006-11-16 16:01 Anh Vo
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox