From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,edafb2ab7e8839bc X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!k70g2000cwa.googlegroups.com!not-for-mail From: "jimmaureenrogers@worldnet.att.net" Newsgroups: comp.lang.ada Subject: Re: Char type verification Date: 15 Nov 2006 17:08:53 -0800 Organization: http://groups.google.com Message-ID: <1163639333.330603.208930@k70g2000cwa.googlegroups.com> References: <1163628033.606530.190550@i42g2000cwa.googlegroups.com> NNTP-Posting-Host: 69.170.65.169 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1163639338 953 127.0.0.1 (16 Nov 2006 01:08:58 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 16 Nov 2006 01:08:58 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.8) Gecko/20061025 Firefox/1.5.0.8,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: k70g2000cwa.googlegroups.com; posting-host=69.170.65.169; posting-account=SqOfxAwAAAAkL81YAPGH1JdBwpUXw9ZG Xref: g2news2.google.com comp.lang.ada:7487 Date: 2006-11-15T17:08:53-08:00 List-Id: 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 --#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