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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,330113ca111da154 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-24 17:39:08 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread4.news.pas.earthlink.net.POSTED!a6202946!not-for-mail Message-ID: <3F99C629.90903@spam.com> From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Hex ouput References: <3F97F61A.13088097@raytheon.com> <3F99407E.5070305@psu.edu> In-Reply-To: <3F99407E.5070305@psu.edu> Content-Type: multipart/mixed; boundary="------------000506020404040100030000" Date: Sat, 25 Oct 2003 00:39:08 GMT NNTP-Posting-Host: 63.184.17.236 X-Complaints-To: abuse@earthlink.net X-Trace: newsread4.news.pas.earthlink.net 1067042348 63.184.17.236 (Fri, 24 Oct 2003 17:39:08 PDT) NNTP-Posting-Date: Fri, 24 Oct 2003 17:39:08 PDT Xref: archiver1.google.com comp.lang.ada:1634 Date: 2003-10-25T00:39:08+00:00 List-Id: This is a multi-part message in MIME format. --------------000506020404040100030000 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Robert Spooner wrote: > > I would like to get a copy of the body of your package. It looks like a > more simple approach than using picture strings - which I've been using > for a home project of controlling an amateur radio transceiver. See attached. The test program produces a lot of lines on standard output, so you'll probably want to redirect it to a file, or pipe it into a more program. Please let me know if it works well for you, and any problems you encounter. > Nice signature line. I've found that trying to do safe programming in > C++ involves a lot of abstraction inversion because the granularity on > safety is so coarse. Only one of many, chosen randomly each day. Only a few have to do with S/W. -- Jeff Carter "We use a large, vibrating egg." Annie Hall 44 --------------000506020404040100030000 Content-Type: text/plain; name="images.ads" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="images.ads" with Ada.Text_IO; package Images is subtype Field is Ada.Text_IO.Field; subtype Number_Base is Ada.Text_IO.Number_Base; generic -- Signed_Image type Number is range <>; function Signed_Image (Value : Number; Width : Field := 0; Zero_Filled : Boolean := False; Base : Number_Base := 10) return String; -- Returns an image of Value, at least Width characters wide, in base Base, padded with blanks or zeroes, -- according to Zero_Filled generic -- Modular_Image type Number is mod <>; function Modular_Image (Value : Number; Width : Field := 0; Zero_Filled : Boolean := False; Base : Number_Base := 10) return String; -- Returns an image of Value, at least Width characters wide, in base Base, padded with blanks or zeroes, -- according to Zero_Filled end Images; --------------000506020404040100030000 Content-Type: text/plain; name="images.adb" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="images.adb" with Ada.Strings.Fixed; package body Images is use Ada.Strings.Fixed; use Ada.Text_IO; function Adjust (Image : String; Width : Field; Negative : Boolean; Zero_Filled : Boolean) return String is -- Apply Width, Negative, & Zero_Filled to Image Blank : constant Character := ' '; Zero : constant Character := '0'; Minus : constant Character := '-'; begin -- Adjust if Zero_Filled then if Negative then return Minus & (1 .. Width - Image'Length - 1 => Zero) & Image; else return (1 .. Width - Image'Length => Zero) & Image; end if; else if Negative then return (1 .. Width - Image'Length - 1 => Blank) & Minus & Image; else return (1 .. Width - Image'Length => Blank) & Image; end if; end if; end Adjust; function Signed_Image (Value : Number; Width : Field := 0; Zero_Filled : Boolean := False; Base : Number_Base := 10) return String is package Number_IO is new Integer_IO (Number); use Number_IO; Image : String (1 .. 100); Start : Positive; Stop : Positive; Negative : constant Boolean := Value < 0; begin -- Signed_Image Put (To => Image, Item => Value, Base => Base); case Base is when 10 => Start := Index_Non_Blank (Image); Stop := Image'Last; if Negative then Start := Start + 1; end if; when 2 .. 9 | 11 .. 16 => Start := 1 + Index (Image, "#"); Stop := Image'Last - 1; when others => raise Program_Error; end case; return Adjust (Image (Start .. Stop), Width, Negative, Zero_Filled); end Signed_Image; function Modular_Image (Value : Number; Width : Field := 0; Zero_Filled : Boolean := False; Base : Number_Base := 10) return String is package Number_IO is new Modular_IO (Number); use Number_IO; Image : String (1 .. 100); Start : Positive; Stop : Positive; begin -- Modular_Image Put (To => Image, Item => Value, Base => Base); case Base is when 10 => Start := Index_Non_Blank (Image); Stop := Image'Last; when 2 .. 9 | 11 .. 16 => Start := 1 + Index (Image, "#"); Stop := Image'Last - 1; when others => raise Program_Error; end case; return Adjust (Image (Start .. Stop), Width, False, Zero_Filled); end Modular_Image; end Images; --------------000506020404040100030000 Content-Type: text/plain; name="test_images.adb" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="test_images.adb" with Ada.Text_IO; with Images; use Ada.Text_IO; procedure Test_Images is type Mod_Int is mod 2 ** Integer'Size; function Image is new Images.Signed_Image (Integer); function Image is new Images.Modular_Image (Mod_Int); Middle : constant Mod_Int := Mod_Int'Last / 2; begin -- Test_Images All_Fills : for Fill in Boolean loop All_Bases : for Base in Images.Number_Base loop Put_Line ('>' & Image (Integer'First, 0, Fill, Base) & '<'); Put_Line ('>' & Image (Integer'(0), 0, Fill, Base) & '<'); Put_Line ('>' & Image (Integer'Last, 0, Fill, Base) & '<'); Put_Line ('>' & Image (Integer'First, 17, Fill, Base) & '<'); Put_Line ('>' & Image (Integer'(0), 17, Fill, Base) & '<'); Put_Line ('>' & Image (Integer'Last, 17, Fill, Base) & '<'); Put_Line ('>' & Image (Integer'First, 35, Fill, Base) & '<'); Put_Line ('>' & Image (Integer'(0), 35, Fill, Base) & '<'); Put_Line ('>' & Image (Integer'Last, 35, Fill, Base) & '<'); Put_Line ('>' & Image (Mod_Int'First, 0, Fill, Base) & '<'); Put_Line ('>' & Image (Middle, 0, Fill, Base) & '<'); Put_Line ('>' & Image (Mod_Int'Last, 0, Fill, Base) & '<'); Put_Line ('>' & Image (Mod_Int'First, 17, Fill, Base) & '<'); Put_Line ('>' & Image (Middle, 17, Fill, Base) & '<'); Put_Line ('>' & Image (Mod_Int'Last, 17, Fill, Base) & '<'); Put_Line ('>' & Image (Mod_Int'First, 35, Fill, Base) & '<'); Put_Line ('>' & Image (Middle, 35, Fill, Base) & '<'); Put_Line ('>' & Image (Mod_Int'Last, 35, Fill, Base) & '<'); end loop All_Bases; end loop All_Fills; end Test_Images; --------------000506020404040100030000--