repo_name
stringlengths
9
74
language
stringclasses
1 value
length_bytes
int64
11
9.34M
extension
stringclasses
2 values
content
stringlengths
11
9.34M
ohenley/awt
Ada
7,001
ads
-- SPDX-License-Identifier: Apache-2.0 -- -- Copyright (c) 2021 onox <[email protected]> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. package AWT.Inputs with SPARK_Mode => On is pragma Preelaborate; type Fixed is delta 2.0 ** (-8) range -(2.0 ** 23) .. +(2.0 ** 23 - 1.0); for Fixed'Size use Integer'Size; type Button_State is (Released, Pressed); ---------------------------------------------------------------------------- -- Drag-and-drop - ---------------------------------------------------------------------------- type Actions is record Copy : Boolean := False; Move : Boolean := False; Ask : Boolean := False; end record; type Action_Kind is (Copy, Move, Ask, None); ---------------------------------------------------------------------------- -- Pointer - ---------------------------------------------------------------------------- type Pointer_Button is (Left, Right, Middle, Unknown); type Pointer_Buttons is array (Pointer_Button) of Button_State; type Pointer_Mode is (Visible, Hidden, Locked); package Cursors is -- Cursors based on XDG cursor spec and CSS3 UI spec type Pointer_Cursor is (Default, -- Links and status Context_Menu, Help, Pointer, Progress, Wait, -- Selection Cell, Crosshair, Text, Vertical_Text, -- Drag and drop Alias, Copy, Move, -- CSS3 UI No_Drop, Not_Allowed, Grab, -- CSS3 UI Grabbing, -- CSS3 UI -- Resizing and scrolling All_Scroll, Row_Resize, Col_Resize, N_Resize, E_Resize, S_Resize, W_Resize, NE_Resize, NW_Resize, SE_Resize, SW_Resize, EW_Resize, NS_Resize, NESW_Resize, NWSE_Resize, -- Zooming Zoom_In, -- CSS3 UI Zoom_Out); -- CSS3 UI end Cursors; type Dimension is (X, Y); type Coordinate is array (Dimension) of Fixed; type Pointer_State is record Buttons : Pointer_Buttons := (others => Released); Focused : Boolean := False; Scrolling : Boolean := False; -- If Focused is True and Scrolling transitions from True to False, then, -- and only then, you should activate kinetic scrolling Mode : Pointer_Mode := Visible; Position : Coordinate := (others => 0.0); Relative : Coordinate := (others => 0.0); Scroll : Coordinate := (others => 0.0); end record; ---------------------------------------------------------------------------- -- Keyboard - ---------------------------------------------------------------------------- type Keyboard_Modifiers is record Shift : Boolean := False; Caps_Lock : Boolean := False; Ctrl : Boolean := False; Alt : Boolean := False; Num_Lock : Boolean := False; Logo : Boolean := False; end record; -- Keys based on the standard 104 keys US QWERTY keyboard layout type Keyboard_Button is (Key_Unknown, Key_Tab, Key_Left_Shift, Key_Left_Ctrl, Key_Left_Alt, Key_Left_Logo, Key_Right_Logo, Key_Right_Alt, Key_Right_Ctrl, Key_Right_Shift, Key_Enter, Key_Space, Key_Comma, Key_Period, Key_Slash, Key_Semicolon, Key_Apostrophe, Key_Left_Bracket, Key_Right_Bracket, Key_Backtick, Key_Backslash, Key_Backspace, Key_Minus, Key_Equal, Key_Arrow_Up, Key_Arrow_Down, Key_Arrow_Left, Key_Arrow_Right, Key_Home, Key_End, Key_Page_Up, Key_Page_Down, Key_Delete, Key_Insert, Key_Caps_Lock, Key_Num_Lock, Key_Scroll_Lock, Key_Print_Screen, Key_Pause, Key_Escape, Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, Key_F6, Key_F7, Key_F8, Key_F9, Key_F10, Key_F11, Key_F12, Key_1, Key_2, Key_3, Key_4, Key_5, Key_6, Key_7, Key_8, Key_9, Key_0, Key_A, Key_B, Key_C, Key_D, Key_E, Key_F, Key_G, Key_H, Key_I, Key_J, Key_K, Key_L, Key_M, Key_N, Key_O, Key_P, Key_Q, Key_R, Key_S, Key_T, Key_U, Key_V, Key_W, Key_X, Key_Y, Key_Z, Key_Numpad_Slash, Key_Numpad_Asterisk, Key_Numpad_Minus, Key_Numpad_Plus, Key_Numpad_Enter, Key_Numpad_Period, Key_Numpad_Delete, Key_Numpad_Insert, Key_Numpad_1, Key_Numpad_2, Key_Numpad_3, Key_Numpad_4, Key_Numpad_5, Key_Numpad_6, Key_Numpad_7, Key_Numpad_8, Key_Numpad_9, Key_Numpad_0); type Keyboard_Buttons is array (Keyboard_Button) of Button_State; type Keyboard_State is record Buttons : Keyboard_Buttons := (others => Released); Modifiers : Keyboard_Modifiers; Focused : Boolean := False; Last_Pressed : Keyboard_Button := Key_Unknown; Repeat_Rate : Natural := 0; Repeat_Delay : Duration := 0.0; end record; function Keyboard_Has_Focus return Boolean; -- Return True if some window has keyboard focus, False otherwise -- TODO Add keyboard UTF-8 text input -- TODO Add function to return key name based on Keyboard_Button and -- current keyboard layout. -- -- With US QWERTY layout Key_Q will return "q". -- With AZERTY layout Key_Q will return "a". private type Unsigned_32 is mod 2 ** Integer'Size with Size => Integer'Size; for Keyboard_Modifiers use record Shift at 0 range 0 .. 0; Caps_Lock at 0 range 1 .. 1; Ctrl at 0 range 2 .. 2; Alt at 0 range 3 .. 3; Num_Lock at 0 range 4 .. 4; Logo at 0 range 6 .. 6; end record; for Keyboard_Modifiers'Size use Unsigned_32'Size; end AWT.Inputs;
reznikmm/matreshka
Ada
4,599
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Smil.FadeColor_Attributes is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Smil_FadeColor_Attribute_Node is begin return Self : Smil_FadeColor_Attribute_Node do Matreshka.ODF_Smil.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Smil_Prefix); end return; end Create; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Smil_FadeColor_Attribute_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.FadeColor_Attribute; end Get_Local_Name; begin Matreshka.DOM_Documents.Register_Attribute (Matreshka.ODF_String_Constants.Smil_URI, Matreshka.ODF_String_Constants.FadeColor_Attribute, Smil_FadeColor_Attribute_Node'Tag); end Matreshka.ODF_Smil.FadeColor_Attributes;
onox/orka
Ada
2,430
adb
-- SPDX-License-Identifier: Apache-2.0 -- -- Copyright (c) 2016 onox <[email protected]> -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. package body Orka.SIMD.AVX.Doubles.Swizzle is Mask_LH : constant := 0 + 0 * 16 + 0 * 8 + 0 * 128; Mask_HL : constant := 1 + 1 * 16 + 0 * 8 + 0 * 128; function Duplicate_LH (Elements : m256d) return m256d is (Permute_Lanes (Elements, Elements, Mask_LH)); function Duplicate_HL (Elements : m256d) return m256d is (Permute_Lanes (Elements, Elements, Mask_HL)); Mask_0_2_0_0 : constant := 0 + 2 * 16 + 0 * 8 + 0 * 128; Mask_1_3_0_0 : constant := 1 + 3 * 16 + 0 * 8 + 0 * 128; procedure Transpose (Matrix : in out m256d_Array) is M0 : constant m256d := Unpack_Low (Matrix (X), Matrix (Y)); M1 : constant m256d := Unpack_High (Matrix (X), Matrix (Y)); M2 : constant m256d := Unpack_Low (Matrix (Z), Matrix (W)); M3 : constant m256d := Unpack_High (Matrix (Z), Matrix (W)); begin Matrix (X) := Permute_Lanes (M0, M2, Mask_0_2_0_0); Matrix (Y) := Permute_Lanes (M1, M3, Mask_0_2_0_0); Matrix (Z) := Permute_Lanes (M0, M2, Mask_1_3_0_0); Matrix (W) := Permute_Lanes (M1, M3, Mask_1_3_0_0); end Transpose; function Transpose (Matrix : m256d_Array) return m256d_Array is Result : m256d_Array; M0 : constant m256d := Unpack_Low (Matrix (X), Matrix (Y)); M1 : constant m256d := Unpack_High (Matrix (X), Matrix (Y)); M2 : constant m256d := Unpack_Low (Matrix (Z), Matrix (W)); M3 : constant m256d := Unpack_High (Matrix (Z), Matrix (W)); begin Result (X) := Permute_Lanes (M0, M2, Mask_0_2_0_0); Result (Y) := Permute_Lanes (M1, M3, Mask_0_2_0_0); Result (Z) := Permute_Lanes (M0, M2, Mask_1_3_0_0); Result (W) := Permute_Lanes (M1, M3, Mask_1_3_0_0); return Result; end Transpose; end Orka.SIMD.AVX.Doubles.Swizzle;
reznikmm/matreshka
Ada
3,639
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2013, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Attributes; package ODF.DOM.Attributes.FO.Margin_Left is type ODF_FO_Margin_Left is new XML.DOM.Attributes.DOM_Attribute with private; private type ODF_FO_Margin_Left is new XML.DOM.Attributes.DOM_Attribute with null record; end ODF.DOM.Attributes.FO.Margin_Left;
clinta/synth
Ada
55,790
adb
-- This file is covered by the Internet Software Consortium (ISC) License -- Reference: ../License.txt with Ada.Command_Line; with Ada.Strings.Fixed; with Ada.Exceptions; with PortScan.Ops; with PortScan.Packages; with PortScan.Buildcycle; with Signals; with Unix; package body PortScan.Pilot is package EX renames Ada.Exceptions; package CLI renames Ada.Command_Line; package ASF renames Ada.Strings.Fixed; package OPS renames PortScan.Ops; package PKG renames PortScan.Packages; package CYC renames PortScan.Buildcycle; package SIG renames Signals; --------------------- -- store_origins -- --------------------- function store_origins return Boolean is function trimmed_catport (S : String) return String; function trimmed_catport (S : String) return String is last : constant Natural := S'Last; begin if S (last) = '/' then return S (S'First .. last - 1); else return S (S'First .. last); end if; end trimmed_catport; begin if CLI.Argument_Count <= 1 then return False; end if; portlist.Clear; if CLI.Argument_Count = 2 then -- Check if this is a file declare Arg2 : constant String := trimmed_catport (CLI.Argument (2)); begin if AD.Exists (Arg2) then return valid_file (Arg2); end if; if valid_catport (catport => Arg2) then plinsert (Arg2, 2); return True; else TIO.Put_Line (badport & Arg2); return False; end if; end; end if; for k in 2 .. CLI.Argument_Count loop declare Argk : constant String := trimmed_catport (CLI.Argument (k)); begin if valid_catport (catport => Argk) then plinsert (Argk, k); else TIO.Put_Line (badport & "'" & Argk & "'" & k'Img); return False; end if; end; end loop; return True; end store_origins; ------------------------------- -- build_pkg8_as_necessary -- ------------------------------- function build_pkg8_as_necessary return Boolean is pkg_good : Boolean; good_scan : Boolean; selection : PortScan.port_id; result : Boolean := True; begin REP.initialize (testmode => False, num_cores => PortScan.cores_available); REP.launch_slave (id => PortScan.scan_slave, opts => noprocs); good_scan := PortScan.scan_single_port (catport => pkgng, always_build => False); if good_scan then PortScan.set_build_priority; else TIO.Put_Line ("Unexpected pkg(8) scan failure!"); result := False; goto clean_exit; end if; if SIG.graceful_shutdown_requested then goto clean_exit; end if; PKG.limited_sanity_check (repository => JT.USS (PM.configuration.dir_repository), dry_run => False, suppress_remote => True); if PKG.queue_is_empty then goto clean_exit; end if; CYC.initialize (test_mode => False, jail_env => REP.jail_environment); selection := OPS.top_buildable_port; if SIG.graceful_shutdown_requested or else selection = port_match_failed then goto clean_exit; end if; TIO.Put ("Stand by, building pkg(8) first ... "); pkg_good := CYC.build_package (id => PortScan.scan_slave, sequence_id => selection); if not pkg_good then TIO.Put_Line ("Failed!!" & bailing); result := False; goto clean_exit; end if; PortScan.reset_ports_tree; TIO.Put_Line ("done!"); <<clean_exit>> if SIG.graceful_shutdown_requested then TIO.Put_Line (shutreq); result := False; end if; REP.destroy_slave (id => PortScan.scan_slave, opts => noprocs); REP.finalize; reset_ports_tree; prescan_ports_tree (JT.USS (PM.configuration.dir_portsdir)); return result; end build_pkg8_as_necessary; ---------------------------------- -- scan_stack_of_single_ports -- ---------------------------------- function scan_stack_of_single_ports (testmode : Boolean; always_build : Boolean := False) return Boolean is procedure scan (plcursor : portkey_crate.Cursor); successful : Boolean := True; procedure scan (plcursor : portkey_crate.Cursor) is origin : constant String := JT.USS (portkey_crate.Key (plcursor)); begin if not successful then return; end if; if origin = pkgng then -- we've already built pkg(8) if we get here, just skip it return; end if; if SIG.graceful_shutdown_requested then successful := False; return; end if; if not PortScan.scan_single_port (origin, always_build) then TIO.Put_Line ("Scan of " & origin & " failed" & PortScan.obvious_problem (JT.USS (PM.configuration.dir_portsdir), origin) & ", it will not be considered."); end if; end scan; begin REP.initialize (testmode, PortScan.cores_available); REP.launch_slave (id => PortScan.scan_slave, opts => noprocs); if SIG.graceful_shutdown_requested then goto clean_exit; end if; if not REP.standalone_pkg8_install (PortScan.scan_slave) then TIO.Put_Line ("Failed to install pkg(8) scanner" & bailing); successful := False; goto clean_exit; end if; portlist.Iterate (Process => scan'Access); if successful then PortScan.set_build_priority; if PKG.queue_is_empty then successful := False; TIO.Put_Line ("There are no valid ports to build." & bailing); end if; end if; <<clean_exit>> if SIG.graceful_shutdown_requested then successful := False; TIO.Put_Line (shutreq); end if; REP.destroy_slave (id => PortScan.scan_slave, opts => noprocs); REP.finalize; return successful; end scan_stack_of_single_ports; --------------------------------- -- sanity_check_then_prefail -- --------------------------------- function sanity_check_then_prefail (delete_first : Boolean := False; dry_run : Boolean := False) return Boolean is procedure force_delete (plcursor : portkey_crate.Cursor); ptid : PortScan.port_id; num_skipped : Natural; block_remote : Boolean := True; update_external_repo : constant String := host_pkg8 & " update --quiet --repository "; no_packages : constant String := "No prebuilt packages will be used as a result."; procedure force_delete (plcursor : portkey_crate.Cursor) is origin : JT.Text := portkey_crate.Key (plcursor); pndx : constant port_index := ports_keys.Element (origin); tball : constant String := JT.USS (PM.configuration.dir_repository) & "/" & JT.USS (all_ports (pndx).package_name); begin if AD.Exists (tball) then AD.Delete_File (tball); end if; end force_delete; begin start_time := CAL.Clock; if delete_first and then not dry_run then portlist.Iterate (Process => force_delete'Access); end if; if not PKG.limited_cached_options_check then -- Error messages emitted by function return False; end if; if PM.configuration.defer_prebuilt then -- Before any remote operations, find the external repo if PKG.located_external_repository then block_remote := False; -- We're going to use prebuilt packages if available, so let's -- prepare for that case by updating the external repository TIO.Put ("Stand by, updating external repository catalogs ... "); if not Unix.external_command (update_external_repo & PKG.top_external_repository) then TIO.Put_Line ("Failed!"); TIO.Put_Line ("The external repository could not be updated."); TIO.Put_Line (no_packages); block_remote := True; else TIO.Put_Line ("done."); end if; else TIO.Put_Line ("The external repository does not seem to be " & "configured."); TIO.Put_Line (no_packages); end if; end if; OPS.initialize_hooks; PKG.limited_sanity_check (repository => JT.USS (PM.configuration.dir_repository), dry_run => dry_run, suppress_remote => block_remote); bld_counter := (OPS.queue_length, 0, 0, 0, 0); if dry_run then return True; end if; if SIG.graceful_shutdown_requested then TIO.Put_Line (shutreq); return False; end if; start_logging (total); start_logging (ignored); start_logging (skipped); start_logging (success); start_logging (failure); loop ptid := OPS.next_ignored_port; exit when ptid = PortScan.port_match_failed; exit when SIG.graceful_shutdown_requested; bld_counter (ignored) := bld_counter (ignored) + 1; TIO.Put_Line (Flog (total), CYC.elapsed_now & " " & OPS.port_name (ptid) & " has been ignored: " & OPS.ignore_reason (ptid)); TIO.Put_Line (Flog (ignored), CYC.elapsed_now & " " & OPS.port_name (ptid) & ": " & OPS.ignore_reason (ptid)); OPS.cascade_failed_build (id => ptid, numskipped => num_skipped, logs => Flog); bld_counter (skipped) := bld_counter (skipped) + num_skipped; end loop; stop_logging (ignored); TIO.Put_Line (Flog (total), CYC.elapsed_now & " Sanity check complete. " & "Ports remaining to build:" & OPS.queue_length'Img); TIO.Flush (Flog (total)); if SIG.graceful_shutdown_requested then TIO.Put_Line (shutreq); else if OPS.integrity_intact then return True; end if; end if; -- If here, we either got control-C or failed integrity check if not SIG.graceful_shutdown_requested then TIO.Put_Line ("Queue integrity lost! " & bailing); end if; stop_logging (total); stop_logging (skipped); stop_logging (success); stop_logging (failure); return False; end sanity_check_then_prefail; ------------------------ -- perform_bulk_run -- ------------------------ procedure perform_bulk_run (testmode : Boolean) is num_builders : constant builders := PM.configuration.num_builders; show_tally : Boolean := True; begin if PKG.queue_is_empty then TIO.Put_Line ("After inspection, it has been determined that there " & "are no packages that"); TIO.Put_Line ("require rebuilding; the task is therefore complete."); show_tally := False; else REP.initialize (testmode, PortScan.cores_available); CYC.initialize (testmode, REP.jail_environment); OPS.initialize_display (num_builders); OPS.parallel_bulk_run (num_builders, Flog); REP.finalize; end if; stop_time := CAL.Clock; stop_logging (total); stop_logging (success); stop_logging (failure); stop_logging (skipped); if show_tally then TIO.Put_Line (LAT.LF & LAT.LF); TIO.Put_Line ("The task is complete. Final tally:"); TIO.Put_Line ("Initial queue size:" & bld_counter (total)'Img); TIO.Put_Line (" packages built:" & bld_counter (success)'Img); TIO.Put_Line (" ignored:" & bld_counter (ignored)'Img); TIO.Put_Line (" skipped:" & bld_counter (skipped)'Img); TIO.Put_Line (" failed:" & bld_counter (failure)'Img); TIO.Put_Line (""); TIO.Put_Line (CYC.log_duration (start_time, stop_time)); TIO.Put_Line ("The build logs can be found at: " & JT.USS (PM.configuration.dir_logs)); end if; end perform_bulk_run; ------------------------------------------- -- verify_desire_to_rebuild_repository -- ------------------------------------------- function verify_desire_to_rebuild_repository return Boolean is answer : Boolean; YN : Character; screen_present : constant Boolean := Unix.screen_attached; begin if not screen_present then return False; end if; if SIG.graceful_shutdown_requested then -- catch previous shutdown request return False; end if; Unix.cone_of_silence (deploy => False); TIO.Put ("Would you like to rebuild the local repository (Y/N)? "); loop TIO.Get_Immediate (YN); case YN is when 'Y' | 'y' => answer := True; exit; when 'N' | 'n' => answer := False; exit; when others => null; end case; end loop; TIO.Put (YN & LAT.LF); Unix.cone_of_silence (deploy => True); return answer; end verify_desire_to_rebuild_repository; ----------------------------------------- -- verify_desire_to_install_packages -- ----------------------------------------- function verify_desire_to_install_packages return Boolean is answer : Boolean; YN : Character; begin Unix.cone_of_silence (deploy => False); TIO.Put ("Would you like to upgrade your system with the new " & "packages now (Y/N)? "); loop TIO.Get_Immediate (YN); case YN is when 'Y' | 'y' => answer := True; exit; when 'N' | 'n' => answer := False; exit; when others => null; end case; end loop; TIO.Put (YN & LAT.LF); Unix.cone_of_silence (deploy => True); return answer; end verify_desire_to_install_packages; ----------------------------- -- fully_scan_ports_tree -- ----------------------------- function fully_scan_ports_tree return Boolean is goodresult : Boolean; begin PortScan.reset_ports_tree; REP.initialize (testmode => False, num_cores => PortScan.cores_available); REP.launch_slave (id => PortScan.scan_slave, opts => noprocs); goodresult := PortScan.scan_entire_ports_tree (JT.USS (PM.configuration.dir_portsdir)); REP.destroy_slave (id => PortScan.scan_slave, opts => noprocs); REP.finalize; if goodresult then PortScan.set_build_priority; return True; else if SIG.graceful_shutdown_requested then TIO.Put_Line (shutreq); else TIO.Put_Line ("Failed to scan ports tree " & bailing); end if; return False; end if; end fully_scan_ports_tree; --------------------------------- -- rebuild_local_respository -- --------------------------------- function rebuild_local_respository (use_full_scan : Boolean := True) return Boolean is repo : constant String := JT.USS (PM.configuration.dir_repository); main : constant String := JT.USS (PM.configuration.dir_packages); xz_meta : constant String := main & "/meta.txz"; xz_digest : constant String := main & "/digests.txz"; xz_pkgsite : constant String := main & "/packagesite.txz"; build_res : Boolean; begin if SIG.graceful_shutdown_requested then -- In case it was previously requested return False; end if; if use_full_scan then REP.initialize (testmode => False, num_cores => PortScan.cores_available); REP.launch_slave (id => PortScan.scan_slave, opts => noprocs); PKG.preclean_repository (repo); REP.destroy_slave (id => PortScan.scan_slave, opts => noprocs); REP.finalize; if SIG.graceful_shutdown_requested then TIO.Put_Line (shutreq); return False; end if; TIO.Put_Line ("Stand by, recursively scanning" & portlist.Length'Img & " ports serially."); for k in dim_all_ports'Range loop all_ports (k).deletion_due := False; end loop; if scan_stack_of_single_ports (testmode => False) then PKG.limited_sanity_check (repository => repo, dry_run => False, suppress_remote => True); if SIG.graceful_shutdown_requested then TIO.Put_Line (shutreq); return False; end if; else return False; end if; end if; if AD.Exists (xz_meta) then AD.Delete_File (xz_meta); end if; if AD.Exists (xz_digest) then AD.Delete_File (xz_digest); end if; if AD.Exists (xz_pkgsite) then AD.Delete_File (xz_pkgsite); end if; TIO.Put_Line ("Packages validated, rebuilding local repository."); REP.initialize (testmode => False, num_cores => PortScan.cores_available); REP.launch_slave (id => PortScan.scan_slave, opts => noprocs); if valid_signing_command then build_res := REP.build_repository (id => PortScan.scan_slave, sign_command => signing_command); elsif acceptable_RSA_signing_support then build_res := REP.build_repository (PortScan.scan_slave); else build_res := False; end if; REP.destroy_slave (id => PortScan.scan_slave, opts => noprocs); REP.finalize; if build_res then TIO.Put_Line ("Local repository successfully rebuilt"); return True; else TIO.Put_Line ("Failed to rebuild repository" & bailing); return False; end if; end rebuild_local_respository; ------------------ -- valid_file -- ------------------ function valid_file (path : String) return Boolean is handle : TIO.File_Type; good : Boolean; total : Natural := 0; begin TIO.Open (File => handle, Mode => TIO.In_File, Name => path); good := True; while not TIO.End_Of_File (handle) loop declare line : constant String := JT.trim (TIO.Get_Line (handle)); begin if not JT.IsBlank (line) then if valid_catport (line) then plinsert (line, total); total := total + 1; else TIO.Put_Line (badport & line); good := False; exit; end if; end if; end; end loop; TIO.Close (handle); return (total > 0) and then good; exception when others => return False; end valid_file; --------------------- -- valid_catport -- --------------------- function valid_catport (catport : String) return Boolean is use type AD.File_Kind; begin if catport'Length = 0 then return False; end if; if catport (catport'First) = '/' then -- Invalid case where catport starts with "/" will cause an -- exception later as "cat" would be unexpectedly empty. return False; end if; if JT.contains (catport, "/") then declare cat : constant String := JT.part_1 (catport); port : constant String := JT.part_2 (catport); path1 : constant String := JT.USS (PM.configuration.dir_portsdir) & "/" & cat; fpath : constant String := path1 & "/" & port; alpha : constant Character := cat (1); begin if not AD.Exists (path1) then return False; end if; if alpha in 'A' .. 'Z' then return False; end if; if path1 = "distfiles" or else path1 = "packages" then return False; end if; if JT.contains (port, "/") then return False; end if; if not AD.Exists (fpath) then return False; end if; if AD.Kind (fpath) = AD.Directory then return True; end if; end; end if; return False; end valid_catport; ---------------- -- plinsert -- ---------------- procedure plinsert (key : String; dummy : Natural) is key2 : JT.Text := JT.SUS (key); ptid : constant PortScan.port_id := PortScan.port_id (dummy); begin if not portlist.Contains (key2) then portlist.Insert (key2, ptid); duplist.Insert (key2, ptid); end if; end plinsert; --------------------- -- start_logging -- --------------------- procedure start_logging (flavor : count_type) is logpath : constant String := JT.USS (PM.configuration.dir_logs) & "/" & logname (flavor); begin if AD.Exists (logpath) then AD.Delete_File (logpath); end if; TIO.Create (File => Flog (flavor), Mode => TIO.Out_File, Name => logpath); if flavor = total then TIO.Put_Line (Flog (flavor), "-=> Chronology of last build <=-"); TIO.Put_Line (Flog (flavor), "Started: " & CYC.timestamp (start_time)); TIO.Put_Line (Flog (flavor), "Ports to build:" & PKG.original_queue_size'Img); TIO.Put_Line (Flog (flavor), ""); TIO.Put_Line (Flog (flavor), "Purging any ignored/broken ports " & "first ..."); TIO.Flush (Flog (flavor)); end if; exception when others => raise pilot_log with "Failed to create or delete " & logpath & bailing; end start_logging; -------------------- -- stop_logging -- -------------------- procedure stop_logging (flavor : count_type) is begin if flavor = total then TIO.Put_Line (Flog (flavor), "Finished: " & CYC.timestamp (stop_time)); TIO.Put_Line (Flog (flavor), CYC.log_duration (start => start_time, stop => stop_time)); end if; TIO.Close (Flog (flavor)); end stop_logging; ----------------------- -- purge_distfiles -- ----------------------- procedure purge_distfiles is type disktype is mod 2**64; procedure scan (plcursor : portkey_crate.Cursor); procedure kill (plcursor : portkey_crate.Cursor); procedure walk (name : String); function display_kmg (number : disktype) return String; abort_purge : Boolean := False; bytes_purged : disktype := 0; distfiles : portkey_crate.Map; rmfiles : portkey_crate.Map; procedure scan (plcursor : portkey_crate.Cursor) is origin : JT.Text := portkey_crate.Key (plcursor); tracker : constant port_id := portkey_crate.Element (plcursor); pndx : constant port_index := ports_keys.Element (origin); distinfo : constant String := JT.USS (PM.configuration.dir_portsdir) & "/" & JT.USS (origin) & "/distinfo"; handle : TIO.File_Type; bookend : Natural; begin TIO.Open (File => handle, Mode => TIO.In_File, Name => distinfo); while not TIO.End_Of_File (handle) loop declare Line : String := TIO.Get_Line (handle); begin if Line (1 .. 4) = "SIZE" then bookend := ASF.Index (Line, ")"); declare S : JT.Text := JT.SUS (Line (7 .. bookend - 1)); begin if not distfiles.Contains (S) then distfiles.Insert (S, tracker); end if; exception when failed : others => TIO.Put_Line ("purge_distfiles::scan: " & JT.USS (S)); TIO.Put_Line (EX.Exception_Information (failed)); end; end if; end; end loop; exception when others => null; end scan; procedure walk (name : String) is procedure walkdir (item : AD.Directory_Entry_Type); procedure print (item : AD.Directory_Entry_Type); uniqid : port_id := 0; leftindent : Natural := JT.SU.Length (PM.configuration.dir_distfiles) + 2; procedure walkdir (item : AD.Directory_Entry_Type) is begin if AD.Simple_Name (item) /= "." and then AD.Simple_Name (item) /= ".." then walk (AD.Full_Name (item)); end if; exception when AD.Name_Error => abort_purge := True; TIO.Put_Line ("walkdir: " & name & " directory does not exist"); end walkdir; procedure print (item : AD.Directory_Entry_Type) is FN : constant String := AD.Full_Name (item); tball : JT.Text := JT.SUS (FN (leftindent .. FN'Last)); begin if not distfiles.Contains (tball) then if not rmfiles.Contains (tball) then uniqid := uniqid + 1; rmfiles.Insert (Key => tball, New_Item => uniqid); bytes_purged := bytes_purged + disktype (AD.Size (FN)); end if; end if; end print; begin AD.Search (name, "*", (AD.Ordinary_File => True, others => False), print'Access); AD.Search (name, "", (AD.Directory => True, others => False), walkdir'Access); exception when AD.Name_Error => abort_purge := True; TIO.Put_Line ("The " & name & " directory does not exist"); when AD.Use_Error => abort_purge := True; TIO.Put_Line ("Searching " & name & " directory is not supported"); when failed : others => abort_purge := True; TIO.Put_Line ("purge_distfiles: Unknown error - directory search"); TIO.Put_Line (EX.Exception_Information (failed)); end walk; function display_kmg (number : disktype) return String is type kmgtype is delta 0.01 digits 6; kilo : constant disktype := 1024; mega : constant disktype := kilo * kilo; giga : constant disktype := kilo * mega; XXX : kmgtype; begin if number > giga then XXX := kmgtype (number / giga); return XXX'Img & " gigabytes"; elsif number > mega then XXX := kmgtype (number / mega); return XXX'Img & " megabytes"; else XXX := kmgtype (number / kilo); return XXX'Img & " kilobytes"; end if; end display_kmg; procedure kill (plcursor : portkey_crate.Cursor) is tarball : String := JT.USS (portkey_crate.Key (plcursor)); path : JT.Text := PM.configuration.dir_distfiles; begin JT.SU.Append (path, "/" & tarball); TIO.Put_Line ("Deleting " & tarball); AD.Delete_File (JT.USS (path)); end kill; begin PortScan.prescan_ports_tree (JT.USS (PM.configuration.dir_portsdir)); TIO.Put ("Scanning the distinfo file of every port in the tree ... "); ports_keys.Iterate (Process => scan'Access); TIO.Put_Line ("done"); walk (name => JT.USS (PM.configuration.dir_distfiles)); if abort_purge then TIO.Put_Line ("Distfile purge operation aborted."); else rmfiles.Iterate (kill'Access); TIO.Put_Line ("Recovered" & display_kmg (bytes_purged)); end if; end purge_distfiles; ------------------------------------------ -- write_pkg_repos_configuration_file -- ------------------------------------------ function write_pkg_repos_configuration_file return Boolean is repdir : constant String := get_repos_dir; target : constant String := repdir & "/00_synth.conf"; pkgdir : constant String := JT.USS (PM.configuration.dir_packages); pubkey : constant String := PM.synth_confdir & "/" & JT.USS (PM.configuration.profile) & "-public.key"; keydir : constant String := PM.synth_confdir & "/keys"; tstdir : constant String := keydir & "/trusted"; autgen : constant String := "# Automatically generated." & LAT.LF; fpfile : constant String := tstdir & "/fingerprint." & JT.USS (PM.configuration.profile); handle : TIO.File_Type; vscmd : Boolean := False; begin if AD.Exists (target) then AD.Delete_File (target); elsif not AD.Exists (repdir) then AD.Create_Path (repdir); end if; TIO.Create (File => handle, Mode => TIO.Out_File, Name => target); TIO.Put_Line (handle, autgen); TIO.Put_Line (handle, "Synth: {"); TIO.Put_Line (handle, " url : file://" & pkgdir & ","); TIO.Put_Line (handle, " priority : 0,"); TIO.Put_Line (handle, " enabled : yes,"); if valid_signing_command then vscmd := True; TIO.Put_Line (handle, " signature_type : FINGERPRINTS,"); TIO.Put_Line (handle, " fingerprints : " & keydir); elsif set_synth_conf_with_RSA then TIO.Put_Line (handle, " signature_type : PUBKEY,"); TIO.Put_Line (handle, " pubkey : " & pubkey); end if; TIO.Put_Line (handle, "}"); TIO.Close (handle); if vscmd then if AD.Exists (fpfile) then AD.Delete_File (fpfile); elsif not AD.Exists (tstdir) then AD.Create_Path (tstdir); end if; TIO.Create (File => handle, Mode => TIO.Out_File, Name => fpfile); TIO.Put_Line (handle, autgen); TIO.Put_Line (handle, "function : sha256"); TIO.Put_Line (handle, "fingerprint : " & profile_fingerprint); TIO.Close (handle); end if; return True; exception when others => TIO.Put_Line ("Error: failed to create " & target); if TIO.Is_Open (handle) then TIO.Close (handle); end if; return False; end write_pkg_repos_configuration_file; --------------------------------- -- upgrade_system_everything -- --------------------------------- procedure upgrade_system_everything (skip_installation : Boolean := False; dry_run : Boolean := False) is command : constant String := host_pkg8 & " upgrade --yes --repository Synth"; query : constant String := host_pkg8 & " query -a %o"; sorry : constant String := "Unfortunately, the system upgrade failed."; begin portlist.Clear; TIO.Put_Line ("Querying system about current package installations."); declare comres : JT.Text; topline : JT.Text; crlen1 : Natural; crlen2 : Natural; uniqid : Natural := 0; begin comres := CYC.generic_system_command (query); crlen1 := JT.SU.Length (comres); loop JT.nextline (lineblock => comres, firstline => topline); crlen2 := JT.SU.Length (comres); exit when crlen1 = crlen2; crlen1 := crlen2; uniqid := uniqid + 1; plinsert (JT.USS (topline), uniqid); end loop; exception when others => TIO.Put_Line (sorry & " (system query)"); return; end; TIO.Put_Line ("Stand by, comparing installed packages against the " & "ports tree."); if build_pkg8_as_necessary and then scan_stack_of_single_ports (testmode => False) and then sanity_check_then_prefail (delete_first => False, dry_run => dry_run) then if dry_run then display_results_of_dry_run; return; else perform_bulk_run (testmode => False); end if; else if not SIG.graceful_shutdown_requested then TIO.Put_Line (sorry); end if; return; end if; if SIG.graceful_shutdown_requested then return; end if; if rebuild_local_respository then if not skip_installation then if not Unix.external_command (command) then TIO.Put_Line (sorry); end if; end if; end if; end upgrade_system_everything; ------------------------------ -- upgrade_system_exactly -- ------------------------------ procedure upgrade_system_exactly is procedure build_train (plcursor : portkey_crate.Cursor); base_command : constant String := host_pkg8 & " install --yes --repository Synth"; caboose : JT.Text; procedure build_train (plcursor : portkey_crate.Cursor) is begin JT.SU.Append (caboose, " "); JT.SU.Append (caboose, portkey_crate.Key (plcursor)); end build_train; begin duplist.Iterate (Process => build_train'Access); declare command : constant String := base_command & JT.USS (caboose); begin if not Unix.external_command (command) then TIO.Put_Line ("Unfortunately, the system upgraded failed."); end if; end; end upgrade_system_exactly; ------------------------------- -- insufficient_privileges -- ------------------------------- function insufficient_privileges return Boolean is command : constant String := "/usr/bin/id -u"; result : JT.Text := CYC.generic_system_command (command); topline : JT.Text; begin JT.nextline (lineblock => result, firstline => topline); declare resint : constant Integer := Integer'Value (JT.USS (topline)); begin return (resint /= 0); end; end insufficient_privileges; --------------- -- head_n1 -- --------------- function head_n1 (filename : String) return String is handle : TIO.File_Type; begin TIO.Open (File => handle, Mode => TIO.In_File, Name => filename); if TIO.End_Of_File (handle) then TIO.Close (handle); return ""; end if; declare line : constant String := TIO.Get_Line (handle); begin TIO.Close (handle); return line; end; end head_n1; ----------------------- -- already_running -- ----------------------- function already_running return Boolean is pid : Integer; comres : JT.Text; begin if AD.Exists (pidfile) then declare textpid : constant String := head_n1 (pidfile); command : constant String := "/bin/ps -p " & textpid; begin -- test if valid by converting it (exception if fails) pid := Integer'Value (textpid); -- exception raised by line below if pid not found. comres := CYC.generic_system_command (command); if JT.contains (comres, "synth") then return True; else -- pidfile is obsolete, remove it. AD.Delete_File (pidfile); return False; end if; exception when others => -- pidfile contains garbage, remove it AD.Delete_File (pidfile); return False; end; end if; return False; end already_running; ----------------------- -- destroy_pidfile -- ----------------------- procedure destroy_pidfile is begin if AD.Exists (pidfile) then AD.Delete_File (pidfile); end if; exception when others => null; end destroy_pidfile; ---------------------- -- create_pidfile -- ---------------------- procedure create_pidfile is pidtext : constant String := JT.int2str (Get_PID); handle : TIO.File_Type; begin TIO.Create (File => handle, Mode => TIO.Out_File, Name => pidfile); TIO.Put_Line (handle, pidtext); TIO.Close (handle); end create_pidfile; ------------------------------------ -- previous_run_mounts_detected -- ------------------------------------ function previous_run_mounts_detected return Boolean is begin return REP.synth_mounts_exist; end previous_run_mounts_detected; ------------------------------------- -- previous_realfs_work_detected -- ------------------------------------- function previous_realfs_work_detected return Boolean is begin return REP.disk_workareas_exist; end previous_realfs_work_detected; --------------------------------------- -- old_mounts_successfully_removed -- --------------------------------------- function old_mounts_successfully_removed return Boolean is begin if REP.clear_existing_mounts then TIO.Put_Line ("Dismounting successful!"); return True; end if; TIO.Put_Line ("The attempt failed. " & "Check for stuck or ongoing processes and kill them."); TIO.Put_Line ("After that, try running Synth again or just manually " & "unmount everything"); TIO.Put_Line ("still attached to " & JT.USS (PM.configuration.dir_buildbase)); return False; end old_mounts_successfully_removed; -------------------------------------------- -- old_realfs_work_successfully_removed -- -------------------------------------------- function old_realfs_work_successfully_removed return Boolean is begin if REP.clear_existing_workareas then TIO.Put_Line ("Directory removal successful!"); return True; end if; TIO.Put_Line ("The attempt to remove the work directories located at "); TIO.Put_Line (JT.USS (PM.configuration.dir_buildbase) & "failed."); TIO.Put_Line ("Please remove them manually before continuing"); return False; end old_realfs_work_successfully_removed; ------------------------- -- synthexec_missing -- ------------------------- function synthexec_missing return Boolean is synthexec : constant String := host_localbase & "/libexec/synthexec"; begin if AD.Exists (synthexec) then return False; end if; TIO.Put_Line (synthexec & " missing!" & bailing); return True; end synthexec_missing; ---------------------------------- -- display_results_of_dry_run -- ---------------------------------- procedure display_results_of_dry_run is procedure print (cursor : ranking_crate.Cursor); listlog : TIO.File_Type; filename : constant String := "/tmp/synth_status_results.txt"; goodlog : Boolean; procedure print (cursor : ranking_crate.Cursor) is id : port_id := ranking_crate.Element (cursor).ap_index; kind : verdiff; diff : constant String := version_difference (id, kind); origin : constant String := get_catport (all_ports (id)); begin case kind is when newbuild => TIO.Put_Line (" N => " & origin); when rebuild => TIO.Put_Line (" R => " & origin); when change => TIO.Put_Line (" U => " & origin & diff); end case; if goodlog then TIO.Put_Line (listlog, origin & diff); end if; end print; begin declare begin TIO.Create (File => listlog, Mode => TIO.Out_File, Name => filename); goodlog := True; exception when others => goodlog := False; end; TIO.Put_Line ("These are the ports that would be built ([N]ew, " & "[R]ebuild, [U]pgrade):"); rank_queue.Iterate (print'Access); TIO.Put_Line ("Total packages that would be built:" & rank_queue.Length'Img); if goodlog then TIO.Close (listlog); TIO.Put_Line ("The complete build list can also be found at:" & LAT.LF & filename); end if; end display_results_of_dry_run; --------------------- -- get_repos_dir -- --------------------- function get_repos_dir return String is command : String := host_pkg8 & " config repos_dir"; content : JT.Text; topline : JT.Text; crlen1 : Natural; crlen2 : Natural; begin content := CYC.generic_system_command (command); crlen1 := JT.SU.Length (content); loop JT.nextline (lineblock => content, firstline => topline); crlen2 := JT.SU.Length (content); exit when crlen1 = crlen2; crlen1 := crlen2; if not JT.equivalent (topline, "/etc/pkg/") then return JT.USS (topline); end if; end loop; -- fallback, use default return host_localbase & "/etc/pkg/repos"; end get_repos_dir; ------------------------------------ -- interact_with_single_builder -- ------------------------------------ function interact_with_single_builder return Boolean is use type CYC.phases; EA_defined : constant Boolean := Unix.env_variable_defined (brkname); begin if Natural (portlist.Length) /= 1 then return False; end if; if not EA_defined then return False; end if; return CYC.valid_test_phase (Unix.env_variable_value (brkname)) /= CYC.check_sanity; end interact_with_single_builder; ---------------------------------------------- -- bulk_run_then_interact_with_final_port -- ---------------------------------------------- procedure bulk_run_then_interact_with_final_port is uscatport : JT.Text := portkey_crate.Key (Position => portlist.First); brkphase : constant CYC.phases := CYC.valid_test_phase (Unix.env_variable_value (brkname)); buildres : Boolean; ptid : port_id; begin if ports_keys.Contains (Key => uscatport) then ptid := ports_keys.Element (Key => uscatport); end if; OPS.unlist_port (ptid); perform_bulk_run (testmode => True); if SIG.graceful_shutdown_requested then return; end if; if bld_counter (ignored) > 0 or else bld_counter (skipped) > 0 or else bld_counter (failure) > 0 then TIO.Put_Line ("It appears a prerequisite failed, so the interactive" & " build of"); TIO.Put_Line (JT.USS (uscatport) & " has been cancelled."); return; end if; TIO.Put_Line ("Starting interactive build of " & JT.USS (uscatport)); TIO.Put_Line ("Stand by, building up to the point requested ..."); REP.initialize (testmode => True, num_cores => PortScan.cores_available); CYC.initialize (test_mode => True, jail_env => REP.jail_environment); REP.launch_slave (id => PortScan.scan_slave, opts => noprocs); Unix.cone_of_silence (deploy => False); buildres := CYC.build_package (id => PortScan.scan_slave, sequence_id => ptid, interactive => True, interphase => brkphase); REP.destroy_slave (id => PortScan.scan_slave, opts => noprocs); REP.finalize; end bulk_run_then_interact_with_final_port; -------------------------- -- synth_launch_clash -- -------------------------- function synth_launch_clash return Boolean is function get_usrlocal return String; function get_usrlocal return String is ul : constant String := "/usr/local"; begin if JT.equivalent (PM.configuration.dir_system, "/") then return ul; end if; return JT.USS (PM.configuration.dir_system) & ul; end get_usrlocal; cwd : constant String := AD.Current_Directory; usrlocal : constant String := get_usrlocal; portsdir : constant String := JT.USS (PM.configuration.dir_portsdir); ullen : constant Natural := usrlocal'Length; pdlen : constant Natural := portsdir'Length; begin if cwd = usrlocal or else cwd = portsdir then return True; end if; if cwd'Length > ullen and then cwd (1 .. ullen + 1) = usrlocal & "/" then return True; end if; if cwd'Length > pdlen and then cwd (1 .. pdlen + 1) = portsdir & "/" then return True; end if; return False; exception when others => return True; end synth_launch_clash; -------------------------- -- version_difference -- -------------------------- function version_difference (id : port_id; kind : out verdiff) return String is dir_pkg : constant String := JT.USS (PM.configuration.dir_repository); current : constant String := JT.USS (all_ports (id).package_name); version : constant String := JT.USS (all_ports (id).port_version); begin if AD.Exists (dir_pkg & "/" & current) then kind := rebuild; return " (rebuild " & version & ")"; end if; declare currlen : constant Natural := current'Length; finish : constant Natural := currlen - version'Length - 4; pattern : constant String := current (1 .. finish) & "*.txz"; origin : constant String := get_catport (all_ports (id)); upgrade : JT.Text := JT.blank; pkg_search : AD.Search_Type; dirent : AD.Directory_Entry_Type; begin AD.Start_Search (Search => pkg_search, Directory => dir_pkg, Filter => (AD.Ordinary_File => True, others => False), Pattern => pattern); while AD.More_Entries (Search => pkg_search) loop AD.Get_Next_Entry (Search => pkg_search, Directory_Entry => dirent); declare sname : String := AD.Simple_Name (dirent); verend : Natural := sname'Length - 4; testorigin : String := PKG.query_origin (dir_pkg & "/" & sname); begin if testorigin = origin then upgrade := JT.SUS (" (" & sname (finish + 1 .. verend) & " => " & version & ")"); end if; end; end loop; if not JT.IsBlank (upgrade) then kind := change; return JT.USS (upgrade); end if; end; kind := newbuild; return " (new " & version & ")"; end version_difference; ------------------------ -- file_permissions -- ------------------------ function file_permissions (full_path : String) return String is command : constant String := "/usr/bin/stat -f %Lp " & full_path; content : JT.Text; topline : JT.Text; status : Integer; begin content := Unix.piped_command (command, status); if status /= 0 then return "000"; end if; JT.nextline (lineblock => content, firstline => topline); return JT.USS (topline); end file_permissions; -------------------------------------- -- acceptable_RSA_signing_support -- -------------------------------------- function acceptable_RSA_signing_support return Boolean is file_prefix : constant String := PM.synth_confdir & "/" & JT.USS (PM.configuration.profile) & "-"; key_private : constant String := file_prefix & "private.key"; key_public : constant String := file_prefix & "public.key"; found_private : constant Boolean := AD.Exists (key_private); found_public : constant Boolean := AD.Exists (key_public); sorry : constant String := "The generated repository will not " & "be signed due to the misconfiguration."; repo_key : constant String := JT.USS (PM.configuration.dir_buildbase) & ss_base & "/etc/repo.key"; begin if not found_private and then not found_public then return True; end if; if found_public and then not found_private then TIO.Put_Line ("A public RSA key file has been found without a " & "corresponding private key file."); TIO.Put_Line (sorry); return True; end if; if found_private and then not found_public then TIO.Put_Line ("A private RSA key file has been found without a " & "corresponding public key file."); TIO.Put_Line (sorry); return True; end if; declare mode : constant String := file_permissions (key_private); begin if mode /= "400" then TIO.Put_Line ("The private RSA key file has insecure file " & "permissions (" & mode & ")"); TIO.Put_Line ("Please change the mode of " & key_private & " to 400 before continuing."); return False; end if; end; declare begin AD.Copy_File (Source_Name => key_private, Target_Name => repo_key); return True; exception when failed : others => TIO.Put_Line ("Failed to copy private RSA key to builder."); TIO.Put_Line (EX.Exception_Information (failed)); return False; end; end acceptable_RSA_signing_support; ---------------------------------- -- acceptable_signing_command -- ---------------------------------- function valid_signing_command return Boolean is file_prefix : constant String := PM.synth_confdir & "/" & JT.USS (PM.configuration.profile) & "-"; fingerprint : constant String := file_prefix & "fingerprint"; ext_command : constant String := file_prefix & "signing_command"; found_finger : constant Boolean := AD.Exists (fingerprint); found_command : constant Boolean := AD.Exists (ext_command); sorry : constant String := "The generated repository will not " & "be externally signed due to the misconfiguration."; begin if found_finger and then found_command then if JT.IsBlank (one_line_file_contents (fingerprint)) or else JT.IsBlank (one_line_file_contents (ext_command)) then TIO.Put_Line ("At least one of the profile signing command " & "files is blank"); TIO.Put_Line (sorry); return False; end if; return True; end if; if found_finger then TIO.Put_Line ("The profile fingerprint was found but not the " & "signing command"); TIO.Put_Line (sorry); elsif found_command then TIO.Put_Line ("The profile signing command was found but not " & "the fingerprint"); TIO.Put_Line (sorry); end if; return False; end valid_signing_command; ----------------------- -- signing_command -- ----------------------- function signing_command return String is filename : constant String := PM.synth_confdir & "/" & JT.USS (PM.configuration.profile) & "-signing_command"; begin return one_line_file_contents (filename); end signing_command; --------------------------- -- profile_fingerprint -- --------------------------- function profile_fingerprint return String is filename : constant String := PM.synth_confdir & "/" & JT.USS (PM.configuration.profile) & "-fingerprint"; begin return one_line_file_contents (filename); end profile_fingerprint; ------------------------------- -- set_synth_conf_with_RSA -- ------------------------------- function set_synth_conf_with_RSA return Boolean is file_prefix : constant String := PM.synth_confdir & "/" & JT.USS (PM.configuration.profile) & "-"; key_private : constant String := file_prefix & "private.key"; key_public : constant String := file_prefix & "public.key"; found_private : constant Boolean := AD.Exists (key_private); found_public : constant Boolean := AD.Exists (key_public); begin return found_public and then found_private and then file_permissions (key_private) = "400"; end set_synth_conf_with_RSA; ------------------------------ -- one_line_file_contents -- ------------------------------ function one_line_file_contents (filename : String) return String is target_file : TIO.File_Type; contents : JT.Text := JT.blank; begin TIO.Open (File => target_file, Mode => TIO.In_File, Name => filename); if not TIO.End_Of_File (target_file) then contents := JT.SUS (TIO.Get_Line (target_file)); end if; TIO.Close (target_file); return JT.USS (contents); end one_line_file_contents; ------------------------- -- valid_system_root -- ------------------------- function valid_system_root return Boolean is begin if REP.boot_modules_directory_missing then TIO.Put_Line ("The /boot directory is optional, but when it exists, " & "the /boot/modules directory must also exist."); TIO.Put ("Please create the "); if not JT.equivalent (PM.configuration.dir_system, "/") then TIO.Put (JT.USS (PM.configuration.dir_system)); end if; TIO.Put_Line ("/boot/modules directory and retry."); return False; end if; return True; end valid_system_root; ------------------------------------------ -- host_pkg8_conservative_upgrade_set -- ------------------------------------------ function host_pkg8_conservative_upgrade_set return Boolean is command : constant String := host_pkg8 & " config CONSERVATIVE_UPGRADE"; content : JT.Text; topline : JT.Text; begin content := CYC.generic_system_command (command); JT.nextline (lineblock => content, firstline => topline); return JT.equivalent (topline, "yes"); end host_pkg8_conservative_upgrade_set; end PortScan.Pilot;
peterfrankjohnson/kernel
Ada
5,749
adb
with Console; use Console; with Debug.Instruction; use Debug.Instruction; with System.Machine_Code; use System.Machine_Code; with CPU; use CPU; with CPU.Interrupts; use CPU.Interrupts; package body Debug is function Nibble_To_Hex (Input : Nibble) return Nibble_Hex_String is Output : Nibble_Hex_String := "0"; begin if Input < 10 then Output (1) := Character'Val(Integer (Input) + 48); else Output (1) := Character'Val(Integer (Input) + 55); end if; return Output; end Nibble_To_Hex; function Byte_To_Hex (Input : Byte) return Byte_Hex_String is Output : Byte_Hex_String := "00"; WorkingValue : Byte; Result : Byte; Exponent : Natural := 1; Index : Natural := 1; function To_Hex_Char (Input : Byte) return Character is Output : Character; begin if Input < 10 then Output := Character'Val(Input + 48); else Output := Character'Val(Input + 55); end if; return Output; end To_Hex_Char; begin WorkingValue := Input; loop if Exponent = 0 then exit; end if; Result := WorkingValue / (16 ** Exponent); WorkingValue := WorkingValue - (Result * (16 ** Exponent)); Output (Index) := To_Hex_Char (Result); Exponent := Exponent - 1; Index := Index + 1; end loop; Result := WorkingValue mod 16; Output (Index) := To_Hex_Char (Result); return Output; end Byte_To_Hex; function Double_To_Hex (Input : Double) return Double_Hex_String is -- type Double is mod 2**32; -- Input : Double := 3735928559; -- Input : Double := 48879; -- Input : Double := 4660; WorkingValue : Double; Output : Double_Hex_String := "00000000"; Result : Double; Exponent : Natural := 7; Index : Natural := 1; function To_Hex_Char (Input : Double) return Character is Output : Character; begin if Input < 10 then Output := Character'Val(Input + 48); else Output := Character'Val(Input + 55); end if; return Output; end To_Hex_Char; begin WorkingValue := Input; loop if Exponent = 0 then exit; end if; Result := WorkingValue / (16 ** Exponent); WorkingValue := WorkingValue - (Result * (16 ** Exponent)); Output (Index) := To_Hex_Char (Result); Exponent := Exponent - 1; Index := Index + 1; end loop; Result := WorkingValue mod 16; Output (Index) := To_Hex_Char (Result); return Output; end Double_To_Hex; procedure DumpPageFaultCode is begin Put_Line ("Code: " & Double_To_Hex (GetPageFaultCode) ); end DumpPageFaultCode; procedure DumpRegisters is R : Registers_Ptr; M : Mnemonic; begin -- CPU.OutputByte (16#20#, 16#FF#); -- CPU.OutputByte (16#A0#, 16#FF#); -- Asm ("CLI"); -- Console.Clear; R := GetRegisters; -- Put_Line (""); -- Put_Line (""); Put_Line (" CS: " & Double_To_Hex (R.CS) & " EIP: " & Double_To_Hex (R.EIP)); Put_Line (" SS: " & Double_To_Hex (R.SS) & " ESP: " & Double_To_Hex (R.ESP) & " EBP: " & Double_To_Hex (R.EBP)); Put_Line (" ESI: " & Double_To_Hex (R.ESI) & " EDI: " & Double_To_Hex (R.EDI)); Put_Line (" DS: " & Double_To_Hex (R.DS) & " ES: " & Double_To_Hex (R.ES) & " FS: " & Double_To_Hex (R.FS) & " GS: " & Double_To_Hex (R.GS)); Put_Line (" EAX: " & Double_To_Hex (R.EAX) & " EBX: " & Double_To_Hex (R.EBX) & " ECX: " & Double_To_Hex (R.ECX) & " EDX: " & Double_To_Hex (R.EDX)); -- Put (" EFLAGS: " & Double_To_Hex (R.EFLAGS)); -- Put (" GDTR: "); -- Put (" IDTR: "); -- Put (" LDTR: "); -- Put (" TR : "); Instruction.SetAddress (R.EIP); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Put_Line (" " & Double_To_Hex (Instruction.EIP) & ": " & Instruction.Decode); Asm ("HLT"); end DumpRegisters; end Debug;
pmderodat/sdlada
Ada
5,495
ads
-------------------------------------------------------------------------------------------------------------------- -- Copyright (c) 2013-2018 Luke A. Guest -- -- This software is provided 'as-is', without any express or implied -- warranty. In no event will the authors be held liable for any damages -- arising from the use of this software. -- -- Permission is granted to anyone to use this software for any purpose, -- including commercial applications, and to alter it and redistribute it -- freely, subject to the following restrictions: -- -- 1. The origin of this software must not be misrepresented; you must not -- claim that you wrote the original software. If you use this software -- in a product, an acknowledgment in the product documentation would be -- appreciated but is not required. -- -- 2. Altered source versions must be plainly marked as such, and must not be -- misrepresented as being the original software. -- -- 3. This notice may not be removed or altered from any source -- distribution. -------------------------------------------------------------------------------------------------------------------- -- SDL.Events.Events -- -- Combines all of the various event types into a single variant record to match the union in the SDL library. Not -- the nicest of names for the package, but it works. -------------------------------------------------------------------------------------------------------------------- with SDL.Events.Windows; with SDL.Events.Keyboards; with SDL.Events.Mice; with SDL.Events.Joysticks; with SDL.Events.Controllers; with SDL.Events.Touches; with SDL.Events.Files; package SDL.Events.Events is type Event_Selector is (Is_Event, Is_Window_Event, Is_Keyboard_Event, Is_Text_Editing_Event, Is_Text_Input_Event, Is_Mouse_Motion_Event, Is_Mouse_Button_Event, Is_Mouse_Wheel_Event, Is_Joystick_Axis_Event, Is_Joystick_Ball_Event, Is_Joystick_Hat_Event, Is_Joystick_Button_Event, Is_Joystick_Device_Event, Is_Controller_Axis_Event, Is_Controller_Button_Event, Is_Controller_Device_Event, Is_Touch_Finger_Event, Is_Touch_Multi_Gesture_Event, Is_Touch_Dollar_Gesture, Is_Drop_Event); type Events (Event_Type : Event_Selector := Is_Event) is record case Event_Type is when Is_Window_Event => Window : SDL.Events.Windows.Window_Events; when Is_Keyboard_Event => Keyboard : SDL.Events.Keyboards.Keyboard_Events; when Is_Text_Editing_Event => Text_Editing : SDL.Events.Keyboards.Text_Editing_Events; when Is_Text_Input_Event => Text_Input : SDL.Events.Keyboards.Text_Input_Events; when Is_Mouse_Motion_Event => Mouse_Motion : SDL.Events.Mice.Motion_Events; when Is_Mouse_Button_Event => Mouse_Button : SDL.Events.Mice.Button_Events; when Is_Mouse_Wheel_Event => Mouse_Wheel : SDL.Events.Mice.Wheel_Events; when Is_Joystick_Axis_Event => Joystick_Axis : SDL.Events.Joysticks.Axis_Events; when Is_Joystick_Ball_Event => Joystick_Ball : SDL.Events.Joysticks.Ball_Events; when Is_Joystick_Hat_Event => Joystick_Hat : SDL.Events.Joysticks.Hat_Events; when Is_Joystick_Button_Event => Joystick_Button : SDL.Events.Joysticks.Button_Events; when Is_Joystick_Device_Event => Joystick_Device : SDL.Events.Joysticks.Device_Events; when Is_Controller_Axis_Event => Controller_Axis : SDL.Events.Controllers.Axis_Events; when Is_Controller_Button_Event => Controller_Button : SDL.Events.Controllers.Button_Events; when Is_Controller_Device_Event => Controller_Device : SDL.Events.Controllers.Device_Events; when Is_Touch_Finger_Event => Touch_Finger : SDL.Events.Touches.Finger_Events; when Is_Touch_Multi_Gesture_Event => Touch_Multi_Gesture : SDL.Events.Touches.Multi_Gesture_Events; when Is_Touch_Dollar_Gesture => Touch_Dollar_Gesture : SDL.Events.Touches.Dollar_Events; when Is_Drop_Event => Drop : SDL.Events.Files.Drop_Events; when others => Common : Common_Events; end case; end record with Unchecked_Union, Convention => C; -- Poll for currently pending events. -- -- If the are any pending events, the next event is removed from the queue -- and stored in Event, and then this returns True. Otherwise, this does -- nothing and returns False. function Poll (Event : out Events) return Boolean; end SDL.Events.Events;
sungyeon/drake
Ada
280
ads
pragma License (Unrestricted); -- extended unit with Ada.Strings.Wide_Wide_Functions.Maps; package Ada.Strings.Bounded_Wide_Wide_Strings.Functions.Maps is new Generic_Maps (Wide_Wide_Functions.Maps); pragma Preelaborate (Ada.Strings.Bounded_Wide_Wide_Strings.Functions.Maps);
optikos/oasis
Ada
2,260
ads
-- Copyright (c) 2019 Maxim Reznik <[email protected]> -- -- SPDX-License-Identifier: MIT -- License-Filename: LICENSE ------------------------------------------------------------- with Program.Elements.Statements; with Program.Elements.Defining_Identifiers; with Program.Lexical_Elements; with Program.Element_Vectors; with Program.Elements.Identifiers; package Program.Elements.Loop_Statements is pragma Pure (Program.Elements.Loop_Statements); type Loop_Statement is limited interface and Program.Elements.Statements.Statement; type Loop_Statement_Access is access all Loop_Statement'Class with Storage_Size => 0; not overriding function Statement_Identifier (Self : Loop_Statement) return Program.Elements.Defining_Identifiers.Defining_Identifier_Access is abstract; not overriding function Statements (Self : Loop_Statement) return not null Program.Element_Vectors.Element_Vector_Access is abstract; not overriding function End_Statement_Identifier (Self : Loop_Statement) return Program.Elements.Identifiers.Identifier_Access is abstract; type Loop_Statement_Text is limited interface; type Loop_Statement_Text_Access is access all Loop_Statement_Text'Class with Storage_Size => 0; not overriding function To_Loop_Statement_Text (Self : aliased in out Loop_Statement) return Loop_Statement_Text_Access is abstract; not overriding function Colon_Token (Self : Loop_Statement_Text) return Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Loop_Token (Self : Loop_Statement_Text) return not null Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function End_Token (Self : Loop_Statement_Text) return not null Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Loop_Token_2 (Self : Loop_Statement_Text) return not null Program.Lexical_Elements.Lexical_Element_Access is abstract; not overriding function Semicolon_Token (Self : Loop_Statement_Text) return not null Program.Lexical_Elements.Lexical_Element_Access is abstract; end Program.Elements.Loop_Statements;
reznikmm/matreshka
Ada
5,888
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2012, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ -- MarkedElement is a graphic element that can be decorated at its vertices -- with markers (e.g. arrowheads). ------------------------------------------------------------------------------ with AMF.DG.Graphical_Elements; limited with AMF.DG.Markers; package AMF.DG.Marked_Elements is pragma Preelaborate; type DG_Marked_Element is limited interface and AMF.DG.Graphical_Elements.DG_Graphical_Element; type DG_Marked_Element_Access is access all DG_Marked_Element'Class; for DG_Marked_Element_Access'Storage_Size use 0; not overriding function Get_Start_Marker (Self : not null access constant DG_Marked_Element) return AMF.DG.Markers.DG_Marker_Access is abstract; -- Getter of MarkedElement::startMarker. -- -- an optional start marker that aligns with the first vertex of the -- marked element. not overriding procedure Set_Start_Marker (Self : not null access DG_Marked_Element; To : AMF.DG.Markers.DG_Marker_Access) is abstract; -- Setter of MarkedElement::startMarker. -- -- an optional start marker that aligns with the first vertex of the -- marked element. not overriding function Get_End_Marker (Self : not null access constant DG_Marked_Element) return AMF.DG.Markers.DG_Marker_Access is abstract; -- Getter of MarkedElement::endMarker. -- -- an optional end marker that aligns with the last vertex of the marked -- element. not overriding procedure Set_End_Marker (Self : not null access DG_Marked_Element; To : AMF.DG.Markers.DG_Marker_Access) is abstract; -- Setter of MarkedElement::endMarker. -- -- an optional end marker that aligns with the last vertex of the marked -- element. not overriding function Get_Mid_Marker (Self : not null access constant DG_Marked_Element) return AMF.DG.Markers.DG_Marker_Access is abstract; -- Getter of MarkedElement::midMarker. -- -- an optional mid marker that aligns with all vertices of the marked -- element except the first and the last. not overriding procedure Set_Mid_Marker (Self : not null access DG_Marked_Element; To : AMF.DG.Markers.DG_Marker_Access) is abstract; -- Setter of MarkedElement::midMarker. -- -- an optional mid marker that aligns with all vertices of the marked -- element except the first and the last. end AMF.DG.Marked_Elements;
charlie5/cBound
Ada
1,413
ads
-- This file is generated by SWIG. Please do not modify by hand. -- with Interfaces.C; with xcb.xcb_screen_t; with Interfaces.C; with Interfaces.C.Pointers; package xcb.xcb_screen_iterator_t is -- Item -- type Item is record data : access xcb.xcb_screen_t.Item; the_rem : aliased Interfaces.C.int; index : aliased Interfaces.C.int; end record; -- Item_Array -- type Item_Array is array (Interfaces.C.size_t range <>) of aliased xcb.xcb_screen_iterator_t .Item; -- Pointer -- package C_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_screen_iterator_t.Item, Element_Array => xcb.xcb_screen_iterator_t.Item_Array, Default_Terminator => (others => <>)); subtype Pointer is C_Pointers.Pointer; -- Pointer_Array -- type Pointer_Array is array (Interfaces.C.size_t range <>) of aliased xcb.xcb_screen_iterator_t .Pointer; -- Pointer_Pointer -- package C_Pointer_Pointers is new Interfaces.C.Pointers (Index => Interfaces.C.size_t, Element => xcb.xcb_screen_iterator_t.Pointer, Element_Array => xcb.xcb_screen_iterator_t.Pointer_Array, Default_Terminator => null); subtype Pointer_Pointer is C_Pointer_Pointers.Pointer; end xcb.xcb_screen_iterator_t;
Fabien-Chouteau/GESTE
Ada
2,202
adb
with GESTE; with GESTE.Grid; with GESTE.Tile_Bank; with Ada.Text_IO; with Console_Char_Screen; procedure Grids is package Console_Screen is new Console_Char_Screen (Width => 20, Height => 20, Buffer_Size => 256, Init_Char => ' '); Palette : aliased constant GESTE.Palette_Type := ('#', '0', 'T', ' '); Background : constant Character := '_'; Tiles : aliased constant GESTE.Tile_Array := (1 => ((1, 1, 1, 1, 1), (1, 3, 3, 3, 1), (1, 3, 3, 3, 1), (1, 3, 3, 3, 1), (1, 1, 1, 1, 1)), 2 => ((2, 3, 3, 3, 2), (3, 2, 3, 2, 3), (3, 3, 2, 3, 3), (3, 2, 3, 2, 3), (2, 3, 3, 3, 2)), 3 => ((3, 3, 1, 3, 3), (3, 3, 1, 3, 3), (1, 1, 2, 1, 1), (3, 3, 1, 3, 3), (3, 3, 1, 3, 3)) ); Bank : aliased GESTE.Tile_Bank.Instance (Tiles'Unrestricted_Access, GESTE.No_Collisions, Palette'Unrestricted_Access); Grid_Data : aliased constant GESTE.Grid.Grid_Data := ((0, 2, 0), (3, 1, 3), (0, 2, 0)); Grid : aliased GESTE.Grid.Instance (Grid_Data'Unrestricted_Access, Bank'Unrestricted_Access); begin Console_Screen.Verbose; Grid.Move ((1, 1)); GESTE.Add (Grid'Unrestricted_Access, 0); GESTE.Render_Window (Window => Console_Screen.Screen_Rect, Background => Background, Buffer => Console_Screen.Buffer, Push_Pixels => Console_Screen.Push_Pixels'Unrestricted_Access, Set_Drawing_Area => Console_Screen.Set_Drawing_Area'Unrestricted_Access); Console_Screen.Print; Grid.Move ((5, 5)); GESTE.Render_Dirty (Screen_Rect => Console_Screen.Screen_Rect, Background => Background, Buffer => Console_Screen.Buffer, Push_Pixels => Console_Screen.Push_Pixels'Unrestricted_Access, Set_Drawing_Area => Console_Screen.Set_Drawing_Area'Unrestricted_Access); Console_Screen.Print; end Grids;
sungyeon/drake
Ada
36
adb
../machine-apple-darwin/s-naexti.adb
likai3g/afmt
Ada
140
ads
with Interfaces; with Fmt.Generic_Mod_Int_Argument; package Fmt.Uint32_Argument is new Generic_Mod_Int_Argument(Interfaces.Unsigned_32);
AdaCore/gpr
Ada
1,102
adb
-- -- Copyright (C) 2021-2023, AdaCore -- -- SPDX-License-Identifier: Apache-2.0 -- with Ada.Text_IO; with GPR2.Context; with GPR2.Log; with GPR2.Path_Name; with GPR2.Project.Tree; procedure Main is Tree : GPR2.Project.Tree.Object; Context : GPR2.Context.Object; use GPR2; procedure Print_Messages is begin if Tree.Has_Messages then for C in Tree.Log_Messages.Iterate (Information => False) loop Ada.Text_IO.Put_Line (GPR2.Log.Element (C).Format); end loop; end if; end Print_Messages; procedure Test (Project_Name : GPR2.Filename_Type) is begin Ada.Text_IO.Put_Line ("testing " & String (Project_Name)); Tree.Unload; Tree.Load_Autoconf (Filename => GPR2.Path_Name.Create_File (GPR2.Project.Ensure_Extension (Project_Name), GPR2.Path_Name.No_Resolution), Context => Context); Tree.Update_Sources; Print_Messages; exception when Project_Error => Print_Messages; end Test; begin Test ("files/test.gpr"); end Main;
reznikmm/matreshka
Ada
6,644
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- XML Processor -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2012-2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.XML_Schema.AST.Complex_Types; with XML.Schema.Object_Lists.Internals; with XML.Schema.Objects.Particles.Internals; package body XML.Schema.Objects.Type_Definitions.Complex_Type_Definitions is use type Matreshka.XML_Schema.AST.Complex_Type_Definition_Access; ------------------ -- Get_Abstract -- ------------------ function Get_Abstract (Self : XS_Complex_Type_Definition'Class) return Boolean is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Get_Abstract unimplemented"); raise Program_Error with "Unimplemented function Get_Abstract"; return Get_Abstract (Self); end Get_Abstract; -------------------- -- Get_Annotation -- -------------------- function Get_Annotation (Self : XS_Complex_Type_Definition'Class) return XML.Schema.Annotations.XS_Annotation is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Get_Annotation unimplemented"); raise Program_Error with "Unimplemented function Get_Annotation"; return Get_Annotation (Self); end Get_Annotation; ------------------------ -- Get_Attribute_Uses -- ------------------------ function Get_Attribute_Uses (Self : XS_Complex_Type_Definition'Class) return XML.Schema.Object_Lists.XS_Object_List is Node : constant Matreshka.XML_Schema.AST.Complex_Type_Definition_Access := Matreshka.XML_Schema.AST.Complex_Type_Definition_Access (Self.Node); begin if Node = null then return XML.Schema.Object_Lists.Empty_XS_Object_List; else return XML.Schema.Object_Lists.Internals.Create (Node.Attribute_Uses'Access); end if; end Get_Attribute_Uses; ---------------------- -- Get_Content_Type -- ---------------------- function Get_Content_Type (Self : XS_Complex_Type_Definition'Class) return Content_Types is package T renames Matreshka.XML_Schema.AST.Complex_Types; Convert : constant array (T.Content_Type_Variety) of Content_Types := (T.Empty => Empty, T.Simple => Simple, T.Element_Only => Element_Only, T.Mixed => Mixed); Node : constant Matreshka.XML_Schema.AST.Complex_Type_Definition_Access := Matreshka.XML_Schema.AST.Complex_Type_Definition_Access (Self.Node); begin if Node = null then return Empty; else return Convert (Node.Content_Type.Variety); end if; end Get_Content_Type; ------------------ -- Get_Particle -- ------------------ function Get_Particle (Self : XS_Complex_Type_Definition'Class) return XML.Schema.Objects.Particles.XS_Particle is Node : constant Matreshka.XML_Schema.AST.Complex_Type_Definition_Access := Matreshka.XML_Schema.AST.Complex_Type_Definition_Access (Self.Node); begin if Node = null then return XML.Schema.Objects.Particles.Null_XS_Particle; else return XML.Schema.Objects.Particles.Internals.Create (Node.Content_Type.Particle); end if; end Get_Particle; end XML.Schema.Objects.Type_Definitions.Complex_Type_Definitions;
reznikmm/matreshka
Ada
16,541
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011-2012, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with AMF.Elements; with AMF.Internals.Element_Collections; with AMF.Internals.Helpers; with AMF.Internals.Tables.UML_Attributes; with AMF.Visitors.UML_Iterators; with AMF.Visitors.UML_Visitors; with League.Strings.Internals; with Matreshka.Internals.Strings; package body AMF.Internals.UML_Abstractions is ------------------- -- Enter_Element -- ------------------- overriding procedure Enter_Element (Self : not null access constant UML_Abstraction_Proxy; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Control : in out AMF.Visitors.Traverse_Control) is begin if Visitor in AMF.Visitors.UML_Visitors.UML_Visitor'Class then AMF.Visitors.UML_Visitors.UML_Visitor'Class (Visitor).Enter_Abstraction (AMF.UML.Abstractions.UML_Abstraction_Access (Self), Control); end if; end Enter_Element; ------------------- -- Leave_Element -- ------------------- overriding procedure Leave_Element (Self : not null access constant UML_Abstraction_Proxy; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Control : in out AMF.Visitors.Traverse_Control) is begin if Visitor in AMF.Visitors.UML_Visitors.UML_Visitor'Class then AMF.Visitors.UML_Visitors.UML_Visitor'Class (Visitor).Leave_Abstraction (AMF.UML.Abstractions.UML_Abstraction_Access (Self), Control); end if; end Leave_Element; ------------------- -- Visit_Element -- ------------------- overriding procedure Visit_Element (Self : not null access constant UML_Abstraction_Proxy; Iterator : in out AMF.Visitors.Abstract_Iterator'Class; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Control : in out AMF.Visitors.Traverse_Control) is begin if Iterator in AMF.Visitors.UML_Iterators.UML_Iterator'Class then AMF.Visitors.UML_Iterators.UML_Iterator'Class (Iterator).Visit_Abstraction (Visitor, AMF.UML.Abstractions.UML_Abstraction_Access (Self), Control); end if; end Visit_Element; ----------------- -- Get_Mapping -- ----------------- overriding function Get_Mapping (Self : not null access constant UML_Abstraction_Proxy) return AMF.UML.Opaque_Expressions.UML_Opaque_Expression_Access is begin return AMF.UML.Opaque_Expressions.UML_Opaque_Expression_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.UML_Attributes.Internal_Get_Mapping (Self.Element))); end Get_Mapping; ----------------- -- Set_Mapping -- ----------------- overriding procedure Set_Mapping (Self : not null access UML_Abstraction_Proxy; To : AMF.UML.Opaque_Expressions.UML_Opaque_Expression_Access) is begin AMF.Internals.Tables.UML_Attributes.Internal_Set_Mapping (Self.Element, AMF.Internals.Helpers.To_Element (AMF.Elements.Element_Access (To))); end Set_Mapping; ---------------- -- Get_Client -- ---------------- overriding function Get_Client (Self : not null access constant UML_Abstraction_Proxy) return AMF.UML.Named_Elements.Collections.Set_Of_UML_Named_Element is begin return AMF.UML.Named_Elements.Collections.Wrap (AMF.Internals.Element_Collections.Wrap (AMF.Internals.Tables.UML_Attributes.Internal_Get_Client (Self.Element))); end Get_Client; ------------------ -- Get_Supplier -- ------------------ overriding function Get_Supplier (Self : not null access constant UML_Abstraction_Proxy) return AMF.UML.Named_Elements.Collections.Set_Of_UML_Named_Element is begin return AMF.UML.Named_Elements.Collections.Wrap (AMF.Internals.Element_Collections.Wrap (AMF.Internals.Tables.UML_Attributes.Internal_Get_Supplier (Self.Element))); end Get_Supplier; ---------------- -- Get_Source -- ---------------- overriding function Get_Source (Self : not null access constant UML_Abstraction_Proxy) return AMF.UML.Elements.Collections.Set_Of_UML_Element is begin return AMF.UML.Elements.Collections.Wrap (AMF.Internals.Element_Collections.Wrap (AMF.Internals.Tables.UML_Attributes.Internal_Get_Source (Self.Element))); end Get_Source; ---------------- -- Get_Target -- ---------------- overriding function Get_Target (Self : not null access constant UML_Abstraction_Proxy) return AMF.UML.Elements.Collections.Set_Of_UML_Element is begin return AMF.UML.Elements.Collections.Wrap (AMF.Internals.Element_Collections.Wrap (AMF.Internals.Tables.UML_Attributes.Internal_Get_Target (Self.Element))); end Get_Target; ------------------------- -- Get_Related_Element -- ------------------------- overriding function Get_Related_Element (Self : not null access constant UML_Abstraction_Proxy) return AMF.UML.Elements.Collections.Set_Of_UML_Element is begin return AMF.UML.Elements.Collections.Wrap (AMF.Internals.Element_Collections.Wrap (AMF.Internals.Tables.UML_Attributes.Internal_Get_Related_Element (Self.Element))); end Get_Related_Element; --------------------------- -- Get_Client_Dependency -- --------------------------- overriding function Get_Client_Dependency (Self : not null access constant UML_Abstraction_Proxy) return AMF.UML.Dependencies.Collections.Set_Of_UML_Dependency is begin return AMF.UML.Dependencies.Collections.Wrap (AMF.Internals.Element_Collections.Wrap (AMF.Internals.Tables.UML_Attributes.Internal_Get_Client_Dependency (Self.Element))); end Get_Client_Dependency; ------------------------- -- Get_Name_Expression -- ------------------------- overriding function Get_Name_Expression (Self : not null access constant UML_Abstraction_Proxy) return AMF.UML.String_Expressions.UML_String_Expression_Access is begin return AMF.UML.String_Expressions.UML_String_Expression_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.UML_Attributes.Internal_Get_Name_Expression (Self.Element))); end Get_Name_Expression; ------------------------- -- Set_Name_Expression -- ------------------------- overriding procedure Set_Name_Expression (Self : not null access UML_Abstraction_Proxy; To : AMF.UML.String_Expressions.UML_String_Expression_Access) is begin AMF.Internals.Tables.UML_Attributes.Internal_Set_Name_Expression (Self.Element, AMF.Internals.Helpers.To_Element (AMF.Elements.Element_Access (To))); end Set_Name_Expression; ------------------- -- Get_Namespace -- ------------------- overriding function Get_Namespace (Self : not null access constant UML_Abstraction_Proxy) return AMF.UML.Namespaces.UML_Namespace_Access is begin return AMF.UML.Namespaces.UML_Namespace_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.UML_Attributes.Internal_Get_Namespace (Self.Element))); end Get_Namespace; ------------------------ -- Get_Qualified_Name -- ------------------------ overriding function Get_Qualified_Name (Self : not null access constant UML_Abstraction_Proxy) return AMF.Optional_String is begin declare use type Matreshka.Internals.Strings.Shared_String_Access; Aux : constant Matreshka.Internals.Strings.Shared_String_Access := AMF.Internals.Tables.UML_Attributes.Internal_Get_Qualified_Name (Self.Element); begin if Aux = null then return (Is_Empty => True); else return (False, League.Strings.Internals.Create (Aux)); end if; end; end Get_Qualified_Name; ----------------------------------- -- Get_Owning_Template_Parameter -- ----------------------------------- overriding function Get_Owning_Template_Parameter (Self : not null access constant UML_Abstraction_Proxy) return AMF.UML.Template_Parameters.UML_Template_Parameter_Access is begin return AMF.UML.Template_Parameters.UML_Template_Parameter_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.UML_Attributes.Internal_Get_Owning_Template_Parameter (Self.Element))); end Get_Owning_Template_Parameter; ----------------------------------- -- Set_Owning_Template_Parameter -- ----------------------------------- overriding procedure Set_Owning_Template_Parameter (Self : not null access UML_Abstraction_Proxy; To : AMF.UML.Template_Parameters.UML_Template_Parameter_Access) is begin AMF.Internals.Tables.UML_Attributes.Internal_Set_Owning_Template_Parameter (Self.Element, AMF.Internals.Helpers.To_Element (AMF.Elements.Element_Access (To))); end Set_Owning_Template_Parameter; ---------------------------- -- Get_Template_Parameter -- ---------------------------- overriding function Get_Template_Parameter (Self : not null access constant UML_Abstraction_Proxy) return AMF.UML.Template_Parameters.UML_Template_Parameter_Access is begin return AMF.UML.Template_Parameters.UML_Template_Parameter_Access (AMF.Internals.Helpers.To_Element (AMF.Internals.Tables.UML_Attributes.Internal_Get_Template_Parameter (Self.Element))); end Get_Template_Parameter; ---------------------------- -- Set_Template_Parameter -- ---------------------------- overriding procedure Set_Template_Parameter (Self : not null access UML_Abstraction_Proxy; To : AMF.UML.Template_Parameters.UML_Template_Parameter_Access) is begin AMF.Internals.Tables.UML_Attributes.Internal_Set_Template_Parameter (Self.Element, AMF.Internals.Helpers.To_Element (AMF.Elements.Element_Access (To))); end Set_Template_Parameter; ------------------------- -- All_Owning_Packages -- ------------------------- overriding function All_Owning_Packages (Self : not null access constant UML_Abstraction_Proxy) return AMF.UML.Packages.Collections.Set_Of_UML_Package is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "All_Owning_Packages unimplemented"); raise Program_Error with "Unimplemented procedure UML_Abstraction_Proxy.All_Owning_Packages"; return All_Owning_Packages (Self); end All_Owning_Packages; ----------------------------- -- Is_Distinguishable_From -- ----------------------------- overriding function Is_Distinguishable_From (Self : not null access constant UML_Abstraction_Proxy; N : AMF.UML.Named_Elements.UML_Named_Element_Access; Ns : AMF.UML.Namespaces.UML_Namespace_Access) return Boolean is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Is_Distinguishable_From unimplemented"); raise Program_Error with "Unimplemented procedure UML_Abstraction_Proxy.Is_Distinguishable_From"; return Is_Distinguishable_From (Self, N, Ns); end Is_Distinguishable_From; --------------- -- Namespace -- --------------- overriding function Namespace (Self : not null access constant UML_Abstraction_Proxy) return AMF.UML.Namespaces.UML_Namespace_Access is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Namespace unimplemented"); raise Program_Error with "Unimplemented procedure UML_Abstraction_Proxy.Namespace"; return Namespace (Self); end Namespace; ------------------------ -- Is_Compatible_With -- ------------------------ overriding function Is_Compatible_With (Self : not null access constant UML_Abstraction_Proxy; P : AMF.UML.Parameterable_Elements.UML_Parameterable_Element_Access) return Boolean is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Is_Compatible_With unimplemented"); raise Program_Error with "Unimplemented procedure UML_Abstraction_Proxy.Is_Compatible_With"; return Is_Compatible_With (Self, P); end Is_Compatible_With; --------------------------- -- Is_Template_Parameter -- --------------------------- overriding function Is_Template_Parameter (Self : not null access constant UML_Abstraction_Proxy) return Boolean is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Is_Template_Parameter unimplemented"); raise Program_Error with "Unimplemented procedure UML_Abstraction_Proxy.Is_Template_Parameter"; return Is_Template_Parameter (Self); end Is_Template_Parameter; end AMF.Internals.UML_Abstractions;
MinimSecure/unum-sdk
Ada
922
adb
-- Copyright 2012-2016 Free Software Foundation, Inc. -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 3 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program. If not, see <http://www.gnu.org/licenses/>. package body Pck is function Ident (I : Integer) return Integer is begin return I; end Ident; procedure Do_Nothing (A : System.Address) is begin null; end Do_Nothing; end Pck;
reznikmm/matreshka
Ada
4,019
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with ODF.DOM.Table_Copy_Styles_Attributes; package Matreshka.ODF_Table.Copy_Styles_Attributes is type Table_Copy_Styles_Attribute_Node is new Matreshka.ODF_Table.Abstract_Table_Attribute_Node and ODF.DOM.Table_Copy_Styles_Attributes.ODF_Table_Copy_Styles_Attribute with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Table_Copy_Styles_Attribute_Node; overriding function Get_Local_Name (Self : not null access constant Table_Copy_Styles_Attribute_Node) return League.Strings.Universal_String; end Matreshka.ODF_Table.Copy_Styles_Attributes;
sungyeon/drake
Ada
26
adb
../../generic/a-nudsge.adb
reznikmm/matreshka
Ada
4,543
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Draw.Cy_Attributes is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Draw_Cy_Attribute_Node is begin return Self : Draw_Cy_Attribute_Node do Matreshka.ODF_Draw.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Draw_Prefix); end return; end Create; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Draw_Cy_Attribute_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Cy_Attribute; end Get_Local_Name; begin Matreshka.DOM_Documents.Register_Attribute (Matreshka.ODF_String_Constants.Draw_URI, Matreshka.ODF_String_Constants.Cy_Attribute, Draw_Cy_Attribute_Node'Tag); end Matreshka.ODF_Draw.Cy_Attributes;
stcarrez/ada-util
Ada
951
ads
----------------------------------------------------------------------- -- util-encoders-hmac -- Hashed message authentication code -- Copyright (C) 2011 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- package Util.Encoders.HMAC is pragma Preelaborate; end Util.Encoders.HMAC;
jwarwick/aoc_2020
Ada
316
adb
-- AOC 2020, Day 8 with Ada.Text_IO; use Ada.Text_IO; with Day; use Day; procedure main is acc : constant Integer := acc_before_repeat("input.txt"); h : constant Integer := acc_after_terminate("input.txt"); begin put_line("Part 1: " & Integer'Image(acc)); put_line("Part 2: " & Integer'Image(h)); end main;
Ada-Audio/audio_base
Ada
2,542
ads
------------------------------------------------------------------------------ -- -- -- AUDIO -- -- -- -- Common RIFF information -- -- -- -- The MIT License (MIT) -- -- -- -- Copyright (c) 2015 -- 2020 Gustavo A. Hoffmann -- -- -- -- Permission is hereby granted, free of charge, to any person obtaining -- -- a copy of this software and associated documentation files (the -- -- "Software"), to deal in the Software without restriction, including -- -- without limitation the rights to use, copy, modify, merge, publish, -- -- distribute, sublicense, and / or sell copies of the Software, and to -- -- permit persons to whom the Software is furnished to do so, subject to -- -- the following conditions: -- -- -- -- The above copyright notice and this permission notice shall be -- -- included in all copies or substantial portions of the Software. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -- -- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -- -- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -- -- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -- -- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -- -- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -- ------------------------------------------------------------------------------ with Interfaces; use Interfaces; package Audio.RIFF with Pure is subtype FOURCC_String is String (1 .. 4); type RIFF_Chunk_Header is record ID : FOURCC_String; Size : Unsigned_32; end record; end Audio.RIFF;
reznikmm/matreshka
Ada
5,689
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- XML Processor -- -- -- -- Tools Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2013-2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with League.Strings; with League.String_Vectors; with XML.Schema.Models; with XML.Schema.Type_Definitions; with XSD_To_Ada.Mappings; with XSD_To_Ada.Writers; package XSD_To_Ada.Utils is Is_Vector_Type : League.String_Vectors.Universal_String_Vector; type Anonyn_Vector_Declatarion is record Print_Level : Natural := 2; Print_State : Boolean := False; Term_Level : Natural := 2; Term_State : Boolean := False; end record; type Anonyn_Vector_Declatarion_Array is array (1 .. 100) of Anonyn_Vector_Declatarion; Anonyn_Vector : Anonyn_Vector_Declatarion_Array; Now_Term_Level : Natural := 2; Optional_Vector : League.String_Vectors.Universal_String_Vector; function Add_Separator (Text : League.Strings.Universal_String) return League.Strings.Universal_String; procedure Gen_Access_Type (Self : in out XSD_To_Ada.Writers.Writer; Name : League.Strings.Universal_String); function Split_Line (Str : Wide_Wide_String := ""; Tab : Natural := 0) return Wide_Wide_String; function Split_Line (Str : League.Strings.Universal_String; Tab : Natural := 0) return Wide_Wide_String; procedure Create_Simple_Type (Model : XML.Schema.Models.XS_Model; Writer : in out XSD_To_Ada.Writers.Writer); procedure Create_Complex_Type (Model : XML.Schema.Models.XS_Model; Mapping : XSD_To_Ada.Mappings.Mapping); procedure Gen_Line (Self : in out XSD_To_Ada.Writers.Writer; Str : Wide_Wide_String := ""); procedure Gen_Proc_Header (Self : in out XSD_To_Ada.Writers.Writer; Name : Wide_Wide_String; Offset : Positive := 3); procedure Put_Header (Self : in out XSD_To_Ada.Writers.Writer); function Is_Choice (Type_D : XML.Schema.Type_Definitions.XS_Type_Definition) return Boolean; -- Check if type is Choice function Has_Element_Session (Type_D : XML.Schema.Type_Definitions.XS_Type_Definition) return Boolean; Namespace : constant League.Strings.Universal_String := League.Strings.To_Universal_String ("http://www.actforex.com/iats"); Crutches_Namespace : constant League.Strings.Universal_String := League.Strings.To_Universal_String ("http://www.actforex.com/iats/crutches"); end XSD_To_Ada.Utils;
jscparker/math_packages
Ada
4,406
ads
-- -- package Four_Body -- -- The package defines a data structure for the N-Body -- gravitational problem in two dimensions. -- -- N = 4, but can be set to anything. -- -- N-Body equation: -- Acceleration(Body_j) -- = SumOver(Body_k) { Mass(Body_k) * G * Delta_R / NORM(Delta_R)**3 } -- -- where Delta_R = (X(Body_k) - X(Body_j)) is a vector, -- and where G is the gravitaional constant. -- -- Natural units: -- Unit of time is earth_orbital_period : t_0. -- Unit of distance is earth's orbital semi-major axis : a_0. -- Unit of mass is sum of Sun and Earth mass : m_0. -- The 3 quantities are related to each other by Kepler's law: -- -- t_0 = 2 * Pi * Sqrt (a_0**3 / (G * m_0)) -- -- where G is the gravitaional constant. If you divide variable of -- time in the N_Body equation by t_0 to get natural units, the equation -- becomes: -- -- Acceleration(Body_j) = 2*2*Pi*Pi* -- SumOver(Body_k) { Mass(Body_k) * Delta_R / NORM(Delta_R)**3 } -- -- where Delta_R = (X(Body_k) - X(Body_j)). -- -- Mass, time, and distance are in the natural units given above, -- which gets rid of the gravitational constant G. In the Equation -- as implemented below, the masses are multiplied by 2*2*pi*pi -- when they are defined in order to avoid excessive multiplication -- during evaluation of F(t, Y). -- -- Body1 is the larger, mass = 1.0. -- Body2 is the smaller, mass = 0.6. -- Assume that the orbital period of the 2 stars is 80.0 years. -- Say the planet is body 3: one earth distance -- from the larger star, with 1 earth mass. -- From these we get the semimajor axis "a" in -- Kepler's law given above ... then put the three bodies in -- near circular orbits and observe stability, and -- remember to use the reduced-mass formulas to get distance -- from center of mass: -- -- First_Body_Radius r1 = a*m2 / (m1+m2) -- Second_Body_Radius r2 = a*m1 / (m1+m2) -- -- Planet_Orbital_Radius : constant Real := 1.0;-- earth's orbital period -- Planet_Period : constant Real := 1.0; -- -- Planet_Orbital_Radius : constant Real := 2.0;-- Twice earth's orbit -- Planet_Period : constant Real := 2.82842712474619; -- -- Planet_Orbital_Radius : constant Real := 3.0;-- Thrice earth's orbit -- Planet_Period : constant Real := 5.196152422706632; -- -- Planet_Orbital_Radius : constant Real := 4.0;-- 4 times earth's orbit -- Planet_Period : constant Real := 8.0;-- 4**1.5 from Kepler's law -- -- a : constant Real := 21.71534093275925; -- OrbitalPeriod : constant Real := 80.0; -- generic type Real is digits <>; package Four_Body is No_Of_Bodies : constant := 4; subtype Bodies is Integer range 0 .. No_Of_Bodies-1; subtype XYUV_Index is Integer range 0 .. 3; type CartesianCoordinate is array(XYUV_Index) of Real; subtype State_Index is Integer range 0 .. 4*No_Of_Bodies-1; type Dynamical_Variable is array(State_Index) of Real; function F (Time : Real; Y : Dynamical_Variable) return Dynamical_Variable; -- This defines the equation to be integrated as -- dY/dt = F (t, Y). Even if the equation is t or Y -- independent, it must be entered in this form. procedure Update_State (Y : in out Dynamical_Variable; Body_id : in Bodies; X, Z, U, W : in Real); function State_Val (Y : Dynamical_Variable; Body_id : Bodies; XYUV_id : XYUV_Index) return Real; function "*" (Left : Real; Right : Dynamical_Variable) return Dynamical_Variable; function "+" (Left : Dynamical_Variable; Right : Dynamical_Variable) return Dynamical_Variable; function "-" (Left : Dynamical_Variable; Right : Dynamical_Variable) return Dynamical_Variable; function Norm (Y : Dynamical_Variable) return Real; pragma Inline (F, "*", "+", "-", Norm); R_Pi : constant := 3.14159_26535_89793_23846_26433_83279_50288; Pii : constant Real := R_Pi; TwoPii : constant Real := 2.0 * R_Pi; TwoPii2 : constant Real := 4.0 * R_Pi * R_Pi; Mass : constant array(Bodies) of Real := (1.0*TwoPii2, 0.6*TwoPii2, 3.0E-6 * TwoPii2, 1.0E-22 * TwoPii2); -- body1 has sun mass, body2 has 0.6 sun mass, and -- body3 has earth mass, body4 has negligible mass. end Four_Body;
reznikmm/matreshka
Ada
6,801
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Table.Filter_Elements is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Elements.Element_L2_Parameters) return Table_Filter_Element_Node is begin return Self : Table_Filter_Element_Node do Matreshka.ODF_Table.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Table_Prefix); end return; end Create; ---------------- -- Enter_Node -- ---------------- overriding procedure Enter_Node (Self : not null access Table_Filter_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Enter_Table_Filter (ODF.DOM.Table_Filter_Elements.ODF_Table_Filter_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Enter_Node (Visitor, Control); end if; end Enter_Node; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Table_Filter_Element_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Filter_Element; end Get_Local_Name; ---------------- -- Leave_Node -- ---------------- overriding procedure Leave_Node (Self : not null access Table_Filter_Element_Node; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Visitor in ODF.DOM.Visitors.Abstract_ODF_Visitor'Class then ODF.DOM.Visitors.Abstract_ODF_Visitor'Class (Visitor).Leave_Table_Filter (ODF.DOM.Table_Filter_Elements.ODF_Table_Filter_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Leave_Node (Visitor, Control); end if; end Leave_Node; ---------------- -- Visit_Node -- ---------------- overriding procedure Visit_Node (Self : not null access Table_Filter_Element_Node; Iterator : in out XML.DOM.Visitors.Abstract_Iterator'Class; Visitor : in out XML.DOM.Visitors.Abstract_Visitor'Class; Control : in out XML.DOM.Visitors.Traverse_Control) is begin if Iterator in ODF.DOM.Iterators.Abstract_ODF_Iterator'Class then ODF.DOM.Iterators.Abstract_ODF_Iterator'Class (Iterator).Visit_Table_Filter (Visitor, ODF.DOM.Table_Filter_Elements.ODF_Table_Filter_Access (Self), Control); else Matreshka.DOM_Elements.Abstract_Element_Node (Self.all).Visit_Node (Iterator, Visitor, Control); end if; end Visit_Node; begin Matreshka.DOM_Documents.Register_Element (Matreshka.ODF_String_Constants.Table_URI, Matreshka.ODF_String_Constants.Filter_Element, Table_Filter_Element_Node'Tag); end Matreshka.ODF_Table.Filter_Elements;
AdaCore/training_material
Ada
637
ads
pragma Ada_2005; pragma Style_Checks (Off); with Interfaces.C; use Interfaces.C; package umingw_off_t_h is subtype u_off_t is long; -- d:\install\gpl2018\x86_64-pc-mingw32\include\_mingw_off_t.h:5 subtype off32_t is long; -- d:\install\gpl2018\x86_64-pc-mingw32\include\_mingw_off_t.h:7 subtype u_off64_t is Long_Long_Integer; -- d:\install\gpl2018\x86_64-pc-mingw32\include\_mingw_off_t.h:13 subtype off64_t is Long_Long_Integer; -- d:\install\gpl2018\x86_64-pc-mingw32\include\_mingw_off_t.h:15 subtype off_t is off32_t; -- d:\install\gpl2018\x86_64-pc-mingw32\include\_mingw_off_t.h:26 end umingw_off_t_h;
AdaCore/langkit
Ada
215
ads
with Langkit_Support.Symbols; use Langkit_Support.Symbols; with Langkit_Support.Text; use Langkit_Support.Text; package Pkg is function Canonicalize (Name : Text_Type) return Symbolization_Result; end Pkg;
reznikmm/matreshka
Ada
4,001
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with ODF.DOM.Text_Date_Value_Attributes; package Matreshka.ODF_Text.Date_Value_Attributes is type Text_Date_Value_Attribute_Node is new Matreshka.ODF_Text.Abstract_Text_Attribute_Node and ODF.DOM.Text_Date_Value_Attributes.ODF_Text_Date_Value_Attribute with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Text_Date_Value_Attribute_Node; overriding function Get_Local_Name (Self : not null access constant Text_Date_Value_Attribute_Node) return League.Strings.Universal_String; end Matreshka.ODF_Text.Date_Value_Attributes;
Jellix/elan520
Ada
985
adb
------------------------------------------------------------------------ -- Copyright (C) 2004-2020 by <[email protected]> -- -- -- -- This work is free. You can redistribute it and/or modify it under -- -- the terms of the Do What The Fuck You Want To Public License, -- -- Version 2, as published by Sam Hocevar. See the LICENSE file for -- -- more details. -- ------------------------------------------------------------------------ pragma License (Unrestricted); ------------------------------------------------------------------------ -- AMD Élan(tm) SC 520 embedded microprocessor -- ------------------------------------------------------------------------ with Elan520.MMCR; package body Elan520 is procedure Init_MMCR is begin null; end Init_MMCR; end Elan520;
reznikmm/matreshka
Ada
7,632
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Complete Meta Object Facility -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with AMF.CMOF.Associations; with AMF.CMOF.Classes; with AMF.Elements.Collections; with AMF.Links.Collections; package AMF.Extents is pragma Preelaborate; type Extent is limited interface; type Extent_Access is access all Extent'Class; for Extent_Access'Storage_Size use 0; ---------------------- -- MOF Operations -- ---------------------- not overriding function Use_Containment (Self : not null access constant Extent) return Boolean is abstract; -- When true, recursively include all elements contained by members of the -- elements(). not overriding function Elements (Self : not null access constant Extent) return AMF.Elements.Collections.Set_Of_Element is abstract; -- Returns a ReflectiveSequence of the elements directly referenced by this -- extent. If exclusive()==true, these elements must have -- container()==null. Extent.elements() is a reflective operation, not a -- reference between Extent and Element. See Chapter 4, “Reflection” for a -- definition of ReflectiveSequence. not overriding function Elements_Of_Type (Self : not null access constant Extent; The_Type : not null AMF.CMOF.Classes.CMOF_Class_Access; Include_Subtypes : Boolean) return AMF.Elements.Collections.Set_Of_Element is abstract; -- This returns those elements in the extent that are instances of the -- supplied Class. If includeSubtypes is true, then instances of any -- subclasses are also returned. not overriding function Links_Of_Type (Self : not null access constant Extent; The_Type : not null AMF.CMOF.Associations.CMOF_Association_Access) return AMF.Links.Collections.Set_Of_Link is abstract; -- linksOfType(type : Association) : Link[0..*] -- This returns those links in the extent that are instances of the -- supplied Association. not overriding function Linked_Elements (Self : not null access constant Extent; Association : not null AMF.CMOF.Associations.CMOF_Association_Access; End_Element : not null AMF.Elements.Element_Access; End_1_To_End_2_Direction : Boolean) return AMF.Elements.Collections.Set_Of_Element is abstract; -- This navigates the supplied Association from the supplied Element. The -- direction of navigation is given by the end1ToEnd2Direction parameter: -- if true, then the supplied Element is treated as the first end of the -- Association. not overriding function Link_Exists (Self : not null access constant Extent; Association : not null AMF.CMOF.Associations.CMOF_Association_Access; First_Element : not null AMF.Elements.Element_Access; Second_Element : not null AMF.Elements.Element_Access) return Boolean is abstract; -- This returns true if there exists at least one link for the association -- between the supplied elements at their respective ends. ------------------------- -- MOFFOL Operations -- ------------------------- not overriding procedure Add_Element (Self : not null access Extent; Element : not null AMF.Elements.Element_Access) is abstract; -- Adds an existing Element to the extent. This is a null operation if the -- Element is already in the Extent. not overriding procedure Remove_Element (Self : not null access Extent; Element : not null AMF.Elements.Element_Access) is abstract; -- Removes the Element from the extent. It is an error if the Element is -- not a member. This may or may not result in it being deleted (see -- Section 6.3.2, “Deletion Semantics”). not overriding procedure Move_Element (Self : not null access Extent; Element : not null AMF.Elements.Element_Access; Target : not null access Extent'Class) is abstract; -- An atomic combination of addElement and removeElement. targetExtent must -- be different from the extent on which the operation is invoked. not overriding procedure Delete_Extent (Self : not null access Extent) is abstract; -- Deletes the Extent, but not necessarily the Elements it contains (see -- Section 6.3.2, “Deletion Semantics). end AMF.Extents;
reznikmm/matreshka
Ada
9,106
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- XML Processor -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with League.Strings; with XML.DOM.Attributes; with XML.DOM.Elements; with XML.DOM.Nodes; with XML.DOM.Texts; package XML.DOM.Documents is pragma Preelaborate; type DOM_Document is limited interface and XML.DOM.Nodes.DOM_Node; type DOM_Document_Access is access all DOM_Document'Class with Storage_Size => 0; not overriding function Create_Attribute_NS (Self : not null access DOM_Document; Namespace_URI : League.Strings.Universal_String; Qualified_Name : League.Strings.Universal_String) return not null XML.DOM.Attributes.DOM_Attribute_Access is abstract; -- Creates an attribute of the given qualified name and namespace URI. -- -- Per [XML Namespaces], applications must use the value null as the -- namespaceURI parameter for methods if they wish to have no namespace. -- -- Parameters -- -- namespaceURI of type DOMString -- The namespace URI of the attribute to create. -- -- qualifiedName of type DOMString -- The qualified name of the attribute to instantiate. -- -- Return Value -- -- Attr -- A new Attr object with the following attributes: -- -- Attribute Value -- Node.nodeName qualifiedName -- Node.namespaceURI namespaceURI -- Node.prefix prefix, extracted from qualifiedName, or null if -- there is no prefix -- Node.localName local name, extracted from qualifiedName -- Attr.name qualifiedName -- Node.nodeValue the empty string -- -- Exceptions -- -- DOMException -- -- INVALID_CHARACTER_ERR: Raised if the specified qualifiedName is not -- an XML name according to the XML version in use specified in the -- Document.xmlVersion attribute. -- -- NAMESPACE_ERR: Raised if the qualifiedName is a malformed qualified -- name, if the qualifiedName has a prefix and the namespaceURI is -- null, if the qualifiedName has a prefix that is "xml" and the -- namespaceURI is different from -- "http://www.w3.org/XML/1998/namespace", if the qualifiedName or its -- prefix is "xmlns" and the namespaceURI is different from -- "http://www.w3.org/2000/xmlns/", or if the namespaceURI is -- "http://www.w3.org/2000/xmlns/" and neither the qualifiedName nor -- its prefix is "xmlns". -- -- NOT_SUPPORTED_ERR: Always thrown if the current document does not -- support the "XML" feature, since namespaces were defined by XML. not overriding function Create_Element_NS (Self : not null access DOM_Document; Namespace_URI : League.Strings.Universal_String; Qualified_Name : League.Strings.Universal_String) return not null XML.DOM.Elements.DOM_Element_Access is abstract; -- Creates an element of the given qualified name and namespace URI. -- -- Per [XML Namespaces], applications must use the value null as the -- namespaceURI parameter for methods if they wish to have no namespace. -- -- Parameters -- -- namespaceURI of type DOMString -- The namespace URI of the element to create. -- -- qualifiedName of type DOMString -- The qualified name of the element type to instantiate. -- -- Return Value -- -- Element -- A new Element object with the following attributes: -- -- Attribute Value -- Node.nodeName qualifiedName -- Node.namespaceURI namespaceURI -- Node.prefix prefix, extracted from qualifiedName, or null if -- there is no prefix -- Node.localName local name, extracted from qualifiedName -- Element.tagName qualifiedName -- -- Exceptions -- -- DOMException -- -- INVALID_CHARACTER_ERR: Raised if the specified qualifiedName is not -- an XML name according to the XML version in use specified in the -- Document.xmlVersion attribute. -- -- NAMESPACE_ERR: Raised if the qualifiedName is a malformed qualified -- name, if the qualifiedName has a prefix and the namespaceURI is -- null, or if the qualifiedName has a prefix that is "xml" and the -- namespaceURI is different from -- "http://www.w3.org/XML/1998/namespace" [XML Namespaces], or if the -- qualifiedName or its prefix is "xmlns" and the namespaceURI is -- different from "http://www.w3.org/2000/xmlns/", or if the -- namespaceURI is "http://www.w3.org/2000/xmlns/" and neither the -- qualifiedName nor its prefix is "xmlns". -- -- NOT_SUPPORTED_ERR: Always thrown if the current document does not -- support the "XML" feature, since namespaces were defined by XML. not overriding function Create_Text_Node (Self : not null access DOM_Document; Data : League.Strings.Universal_String) return not null XML.DOM.Texts.DOM_Text_Access is abstract; -- Creates a Text node given the specified string. -- -- Parameters -- -- data of type DOMString -- The data for the node. -- -- Return Value -- -- Text -- The new Text object. not overriding function Error_Code (Self : not null access constant DOM_Document) return XML.DOM.Error_Code is abstract; -- Returns DOM error code for last raised DOM_Exception. not overriding function Error_String (Self : not null access constant DOM_Document) return League.Strings.Universal_String is abstract; -- Returns error string for last raised DOM_Exception. end XML.DOM.Documents;
AdaCore/gpr
Ada
3,990
adb
-- -- Copyright (C) 2019-2023, AdaCore -- -- SPDX-License-Identifier: Apache-2.0 -- with Ada.Directories; with Ada.Text_IO; with Ada.Strings.Fixed; with GPR2.Unit; with GPR2.Context; with GPR2.Path_Name; with GPR2.Project.Attribute.Set; with GPR2.Project.Source.Set; with GPR2.Project.Tree; with GPR2.Project.Variable.Set; with GPR2.Project.View; with GPR2.Source_Info.Parser.Ada_Language; procedure Main is use Ada; use GPR2; use GPR2.Project; procedure Display (Prj : Project.View.Object); procedure Changed_Callback (Prj : Project.View.Object); procedure Output_Filename (Filename : Path_Name.Full_Name); -- Remove the leading tmp directory ---------------------- -- Changed_Callback -- ---------------------- procedure Changed_Callback (Prj : Project.View.Object) is begin Text_IO.Put_Line (">>> Changed_Callback for " & Directories.Simple_Name (Prj.Path_Name.Value)); end Changed_Callback; ------------- -- Display -- ------------- procedure Display (Prj : Project.View.Object) is use GPR2.Project.Attribute.Set; use GPR2.Project.Variable.Set.Set; begin Text_IO.Put (String (Prj.Name) & " "); Text_IO.Set_Col (10); Text_IO.Put_Line (Prj.Qualifier'Img); for A of Prj.Attributes (With_Defaults => False) loop Text_IO.Put ("A: " & Image (A.Name.Id.Attr)); Text_IO.Put (" ->"); for V of A.Values loop Text_IO.Put (" " & V.Text); end loop; Text_IO.New_Line; end loop; for Source of Prj.Sources loop declare U : constant Optional_Name_Type := Source.Unit_Name (No_Index); begin Output_Filename (Source.Path_Name.Value); Text_IO.Set_Col (16); Text_IO.Put (" language: " & Image (Source.Language)); Text_IO.Set_Col (33); Text_IO.Put (" Kind: " & GPR2.Unit.Library_Unit_Type'Image (Source.Kind)); if U /= "" then Text_IO.Put (" unit: " & String (U)); end if; Text_IO.New_Line; end; end loop; end Display; --------------------- -- Output_Filename -- --------------------- procedure Output_Filename (Filename : Path_Name.Full_Name) is I : constant Positive := Strings.Fixed.Index (Filename, "unload-tree"); begin Text_IO.Put (" > " & Filename (I + 12 .. Filename'Last)); end Output_Filename; Prj1, Prj2 : Project.Tree.Object; Ctx1, Ctx2 : Context.Object; begin Ctx1.Include ("LSRC", "one"); Ctx2.Include ("LSRC", "two"); Project.Tree.Load (Prj1, Create ("first.gpr"), Ctx1); Project.Tree.Load (Prj2, Create ("second.gpr"), Ctx2); Text_IO.Put_Line ("**************** Iterator Prj1"); for C in Project.Tree.Iterate (Prj1) loop Display (Project.Tree.Element (C)); if Project.Tree.Is_Root (C) then Text_IO.Put_Line (" is root"); end if; end loop; Prj1.Unload; if Prj1.Is_Defined then Text_IO.Put_Line ("Not completely unloaded"); end if; Text_IO.Put_Line ("**************** Iterator Prj2"); for C in Project.Tree.Iterate (Prj2) loop Display (Project.Tree.Element (C)); if Project.Tree.Is_Root (C) then Text_IO.Put_Line (" is root"); end if; end loop; exception when GPR2.Project_Error => if Prj1.Has_Messages then Text_IO.Put_Line ("Messages found:"); for M of Prj1.Log_Messages.all loop declare Mes : constant String := M.Format; L : constant Natural := Strings.Fixed.Index (Mes, "/unload-tree"); begin if L /= 0 then Text_IO.Put_Line (Mes (L .. Mes'Last)); else Text_IO.Put_Line (Mes); end if; end; end loop; end if; end Main;
reznikmm/matreshka
Ada
26,129
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Localization, Internationalization, Globalization for Ada -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011-2012, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.Internals.Strings.Configuration; with Matreshka.Internals.Unicode.Characters.Latin; with Matreshka.Internals.Utf16; package body Matreshka.Internals.Text_Codecs.Windows1250 is use Matreshka.Internals.Strings.Configuration; use Matreshka.Internals.Unicode.Characters.Latin; use type Matreshka.Internals.Unicode.Code_Unit_32; use type Matreshka.Internals.Utf16.Utf16_String_Index; Decode_Table : constant array (Ada.Streams.Stream_Element range 16#80# .. 16#FF#) of Matreshka.Internals.Unicode.Code_Point := (16#80# => 16#20AC#, -- EURO SIGN 16#81# => Question_Mark, 16#82# => 16#201A#, -- SINGLE LOW-9 QUOTATION MARK 16#83# => Question_Mark, 16#84# => 16#201E#, -- DOUBLE LOW-9 QUOTATION MARK 16#85# => 16#2026#, -- HORIZONTAL ELLIPSIS 16#86# => 16#2020#, -- DAGGER 16#87# => 16#2021#, -- DOUBLE DAGGER 16#88# => Question_Mark, 16#89# => 16#2030#, -- PER MILLE SIGN 16#8A# => 16#0160#, -- LATIN CAPITAL LETTER S WITH CARON 16#8B# => 16#2039#, -- SINGLE LEFT-POINTING ANGLE QUOTATION MARK 16#8C# => 16#015A#, -- LATIN CAPITAL LETTER S WITH ACUTE 16#8D# => 16#0164#, -- LATIN CAPITAL LETTER T WITH CARON 16#8E# => 16#017D#, -- LATIN CAPITAL LETTER Z WITH CARON 16#8F# => 16#0179#, -- LATIN CAPITAL LETTER Z WITH ACUTE 16#90# => Question_Mark, 16#91# => 16#2018#, -- LEFT SINGLE QUOTATION MARK 16#92# => 16#2019#, -- RIGHT SINGLE QUOTATION MARK 16#93# => 16#201C#, -- LEFT DOUBLE QUOTATION MARK 16#94# => 16#201D#, -- RIGHT DOUBLE QUOTATION MARK 16#95# => 16#2022#, -- BULLET 16#96# => 16#2013#, -- EN DASH 16#97# => 16#2014#, -- EM DASH 16#98# => Question_Mark, 16#99# => 16#2122#, -- TRADE MARK SIGN 16#9A# => 16#0161#, -- LATIN SMALL LETTER S WITH CARON 16#9B# => 16#203A#, -- SINGLE RIGHT-POINTING ANGLE QUOTATION -- MARK 16#9C# => 16#015B#, -- LATIN SMALL LETTER S WITH ACUTE 16#9D# => 16#0165#, -- LATIN SMALL LETTER T WITH CARON 16#9E# => 16#017E#, -- LATIN SMALL LETTER Z WITH CARON 16#9F# => 16#017A#, -- LATIN SMALL LETTER Z WITH ACUTE 16#A0# => 16#00A0#, -- NO-BREAK SPACE 16#A1# => 16#02C7#, -- CARON 16#A2# => 16#02D8#, -- BREVE 16#A3# => 16#0141#, -- LATIN CAPITAL LETTER L WITH STROKE 16#A4# => 16#00A4#, -- CURRENCY SIGN 16#A5# => 16#0104#, -- LATIN CAPITAL LETTER A WITH OGONEK 16#A6# => 16#00A6#, -- BROKEN BAR 16#A7# => 16#00A7#, -- SECTION SIGN 16#A8# => 16#00A8#, -- DIAERESIS 16#A9# => 16#00A9#, -- COPYRIGHT SIGN 16#AA# => 16#015E#, -- LATIN CAPITAL LETTER S WITH CEDILLA 16#AB# => 16#00AB#, -- LEFT-POINTING DOUBLE ANGLE QUOTATION -- MARK 16#AC# => 16#00AC#, -- NOT SIGN 16#AD# => 16#00AD#, -- SOFT HYPHEN 16#AE# => 16#00AE#, -- REGISTERED SIGN 16#AF# => 16#017B#, -- LATIN CAPITAL LETTER Z WITH DOT ABOVE 16#B0# => 16#00B0#, -- DEGREE SIGN 16#B1# => 16#00B1#, -- PLUS-MINUS SIGN 16#B2# => 16#02DB#, -- OGONEK 16#B3# => 16#0142#, -- LATIN SMALL LETTER L WITH STROKE 16#B4# => 16#00B4#, -- ACUTE ACCENT 16#B5# => 16#00B5#, -- MICRO SIGN 16#B6# => 16#00B6#, -- PILCROW SIGN 16#B7# => 16#00B7#, -- MIDDLE DOT 16#B8# => 16#00B8#, -- CEDILLA 16#B9# => 16#0105#, -- LATIN SMALL LETTER A WITH OGONEK 16#BA# => 16#015F#, -- LATIN SMALL LETTER S WITH CEDILLA 16#BB# => 16#00BB#, -- RIGHT-POINTING DOUBLE ANGLE QUOTATION -- MARK 16#BC# => 16#013D#, -- LATIN CAPITAL LETTER L WITH CARON 16#BD# => 16#02DD#, -- DOUBLE ACUTE ACCENT 16#BE# => 16#013E#, -- LATIN SMALL LETTER L WITH CARON 16#BF# => 16#017C#, -- LATIN SMALL LETTER Z WITH DOT ABOVE 16#C0# => 16#0154#, -- LATIN CAPITAL LETTER R WITH ACUTE 16#C1# => 16#00C1#, -- LATIN CAPITAL LETTER A WITH ACUTE 16#C2# => 16#00C2#, -- LATIN CAPITAL LETTER A WITH CIRCUMFLEX 16#C3# => 16#0102#, -- LATIN CAPITAL LETTER A WITH BREVE 16#C4# => 16#00C4#, -- LATIN CAPITAL LETTER A WITH DIAERESIS 16#C5# => 16#0139#, -- LATIN CAPITAL LETTER L WITH ACUTE 16#C6# => 16#0106#, -- LATIN CAPITAL LETTER C WITH ACUTE 16#C7# => 16#00C7#, -- LATIN CAPITAL LETTER C WITH CEDILLA 16#C8# => 16#010C#, -- LATIN CAPITAL LETTER C WITH CARON 16#C9# => 16#00C9#, -- LATIN CAPITAL LETTER E WITH ACUTE 16#CA# => 16#0118#, -- LATIN CAPITAL LETTER E WITH OGONEK 16#CB# => 16#00CB#, -- LATIN CAPITAL LETTER E WITH DIAERESIS 16#CC# => 16#011A#, -- LATIN CAPITAL LETTER E WITH CARON 16#CD# => 16#00CD#, -- LATIN CAPITAL LETTER I WITH ACUTE 16#CE# => 16#00CE#, -- LATIN CAPITAL LETTER I WITH CIRCUMFLEX 16#CF# => 16#010E#, -- LATIN CAPITAL LETTER D WITH CARON 16#D0# => 16#0110#, -- LATIN CAPITAL LETTER D WITH STROKE 16#D1# => 16#0143#, -- LATIN CAPITAL LETTER N WITH ACUTE 16#D2# => 16#0147#, -- LATIN CAPITAL LETTER N WITH CARON 16#D3# => 16#00D3#, -- LATIN CAPITAL LETTER O WITH ACUTE 16#D4# => 16#00D4#, -- LATIN CAPITAL LETTER O WITH CIRCUMFLEX 16#D5# => 16#0150#, -- LATIN CAPITAL LETTER O WITH DOUBLE ACUTE 16#D6# => 16#00D6#, -- LATIN CAPITAL LETTER O WITH DIAERESIS 16#D7# => 16#00D7#, -- MULTIPLICATION SIGN 16#D8# => 16#0158#, -- LATIN CAPITAL LETTER R WITH CARON 16#D9# => 16#016E#, -- LATIN CAPITAL LETTER U WITH RING ABOVE 16#DA# => 16#00DA#, -- LATIN CAPITAL LETTER U WITH ACUTE 16#DB# => 16#0170#, -- LATIN CAPITAL LETTER U WITH DOUBLE ACUTE 16#DC# => 16#00DC#, -- LATIN CAPITAL LETTER U WITH DIAERESIS 16#DD# => 16#00DD#, -- LATIN CAPITAL LETTER Y WITH ACUTE 16#DE# => 16#0162#, -- LATIN CAPITAL LETTER T WITH CEDILLA 16#DF# => 16#00DF#, -- LATIN SMALL LETTER SHARP S 16#E0# => 16#0155#, -- LATIN SMALL LETTER R WITH ACUTE 16#E1# => 16#00E1#, -- LATIN SMALL LETTER A WITH ACUTE 16#E2# => 16#00E2#, -- LATIN SMALL LETTER A WITH CIRCUMFLEX 16#E3# => 16#0103#, -- LATIN SMALL LETTER A WITH BREVE 16#E4# => 16#00E4#, -- LATIN SMALL LETTER A WITH DIAERESIS 16#E5# => 16#013A#, -- LATIN SMALL LETTER L WITH ACUTE 16#E6# => 16#0107#, -- LATIN SMALL LETTER C WITH ACUTE 16#E7# => 16#00E7#, -- LATIN SMALL LETTER C WITH CEDILLA 16#E8# => 16#010D#, -- LATIN SMALL LETTER C WITH CARON 16#E9# => 16#00E9#, -- LATIN SMALL LETTER E WITH ACUTE 16#EA# => 16#0119#, -- LATIN SMALL LETTER E WITH OGONEK 16#EB# => 16#00EB#, -- LATIN SMALL LETTER E WITH DIAERESIS 16#EC# => 16#011B#, -- LATIN SMALL LETTER E WITH CARON 16#ED# => 16#00ED#, -- LATIN SMALL LETTER I WITH ACUTE 16#EE# => 16#00EE#, -- LATIN SMALL LETTER I WITH CIRCUMFLEX 16#EF# => 16#010F#, -- LATIN SMALL LETTER D WITH CARON 16#F0# => 16#0111#, -- LATIN SMALL LETTER D WITH STROKE 16#F1# => 16#0144#, -- LATIN SMALL LETTER N WITH ACUTE 16#F2# => 16#0148#, -- LATIN SMALL LETTER N WITH CARON 16#F3# => 16#00F3#, -- LATIN SMALL LETTER O WITH ACUTE 16#F4# => 16#00F4#, -- LATIN SMALL LETTER O WITH CIRCUMFLEX 16#F5# => 16#0151#, -- LATIN SMALL LETTER O WITH DOUBLE ACUTE 16#F6# => 16#00F6#, -- LATIN SMALL LETTER O WITH DIAERESIS 16#F7# => 16#00F7#, -- DIVISION SIGN 16#F8# => 16#0159#, -- LATIN SMALL LETTER R WITH CARON 16#F9# => 16#016F#, -- LATIN SMALL LETTER U WITH RING ABOVE 16#FA# => 16#00FA#, -- LATIN SMALL LETTER U WITH ACUTE 16#FB# => 16#0171#, -- LATIN SMALL LETTER U WITH DOUBLE ACUTE 16#FC# => 16#00FC#, -- LATIN SMALL LETTER U WITH DIAERESIS 16#FD# => 16#00FD#, -- LATIN SMALL LETTER Y WITH ACUTE 16#FE# => 16#0163#, -- LATIN SMALL LETTER T WITH CEDILLA 16#FF# => 16#02D9#); -- DOT ABOVE Encode_Table_00 : constant array (Matreshka.Internals.Unicode.Code_Point range 16#00A0# .. 16#00FD#) of Ada.Streams.Stream_Element := (16#00A0# => 16#A0#, -- NO-BREAK SPACE 16#00A4# => 16#A4#, -- CURRENCY SIGN 16#00A6# => 16#A6#, -- BROKEN BAR 16#00A7# => 16#A7#, -- SECTION SIGN 16#00A8# => 16#A8#, -- DIAERESIS 16#00A9# => 16#A9#, -- COPYRIGHT SIGN 16#00AB# => 16#AB#, -- LEFT-POINTING DOUBLE ANGLE QUOTATION -- MARK 16#00AC# => 16#AC#, -- NOT SIGN 16#00AD# => 16#AD#, -- SOFT HYPHEN 16#00AE# => 16#AE#, -- REGISTERED SIGN 16#00B0# => 16#B0#, -- DEGREE SIGN 16#00B1# => 16#B1#, -- PLUS-MINUS SIGN 16#00B4# => 16#B4#, -- ACUTE ACCENT 16#00B5# => 16#B5#, -- MICRO SIGN 16#00B6# => 16#B6#, -- PILCROW SIGN 16#00B7# => 16#B7#, -- MIDDLE DOT 16#00B8# => 16#B8#, -- CEDILLA 16#00BB# => 16#BB#, -- RIGHT-POINTING DOUBLE ANGLE QUOTATION -- MARK 16#00C1# => 16#C1#, -- LATIN CAPITAL LETTER A WITH ACUTE 16#00C2# => 16#C2#, -- LATIN CAPITAL LETTER A WITH CIRCUMFLEX 16#00C4# => 16#C4#, -- LATIN CAPITAL LETTER A WITH DIAERESIS 16#00C7# => 16#C7#, -- LATIN CAPITAL LETTER C WITH CEDILLA 16#00C9# => 16#C9#, -- LATIN CAPITAL LETTER E WITH ACUTE 16#00CB# => 16#CB#, -- LATIN CAPITAL LETTER E WITH DIAERESIS 16#00CD# => 16#CD#, -- LATIN CAPITAL LETTER I WITH ACUTE 16#00CE# => 16#CE#, -- LATIN CAPITAL LETTER I WITH CIRCUMFLEX 16#00D3# => 16#D3#, -- LATIN CAPITAL LETTER O WITH ACUTE 16#00D4# => 16#D4#, -- LATIN CAPITAL LETTER O WITH CIRCUMFLEX 16#00D6# => 16#D6#, -- LATIN CAPITAL LETTER O WITH DIAERESIS 16#00D7# => 16#D7#, -- MULTIPLICATION SIGN 16#00DA# => 16#DA#, -- LATIN CAPITAL LETTER U WITH ACUTE 16#00DC# => 16#DC#, -- LATIN CAPITAL LETTER U WITH DIAERESIS 16#00DD# => 16#DD#, -- LATIN CAPITAL LETTER Y WITH ACUTE 16#00DF# => 16#DF#, -- LATIN SMALL LETTER SHARP S 16#00E1# => 16#E1#, -- LATIN SMALL LETTER A WITH ACUTE 16#00E2# => 16#E2#, -- LATIN SMALL LETTER A WITH CIRCUMFLEX 16#00E4# => 16#E4#, -- LATIN SMALL LETTER A WITH DIAERESIS 16#00E7# => 16#E7#, -- LATIN SMALL LETTER C WITH CEDILLA 16#00E9# => 16#E9#, -- LATIN SMALL LETTER E WITH ACUTE 16#00EB# => 16#EB#, -- LATIN SMALL LETTER E WITH DIAERESIS 16#00ED# => 16#ED#, -- LATIN SMALL LETTER I WITH ACUTE 16#00EE# => 16#EE#, -- LATIN SMALL LETTER I WITH CIRCUMFLEX 16#00F3# => 16#F3#, -- LATIN SMALL LETTER O WITH ACUTE 16#00F4# => 16#F4#, -- LATIN SMALL LETTER O WITH CIRCUMFLEX 16#00F6# => 16#F6#, -- LATIN SMALL LETTER O WITH DIAERESIS 16#00F7# => 16#F7#, -- DIVISION SIGN 16#00FA# => 16#FA#, -- LATIN SMALL LETTER U WITH ACUTE 16#00FC# => 16#FC#, -- LATIN SMALL LETTER U WITH DIAERESIS 16#00FD# => 16#FD#, -- LATIN SMALL LETTER Y WITH ACUTE others => Question_Mark); Encode_Table_01 : constant array (Matreshka.Internals.Unicode.Code_Point range 16#0102# .. 16#017E#) of Ada.Streams.Stream_Element := (16#0102# => 16#C3#, -- LATIN CAPITAL LETTER A WITH BREVE 16#0103# => 16#E3#, -- LATIN SMALL LETTER A WITH BREVE 16#0104# => 16#A5#, -- LATIN CAPITAL LETTER A WITH OGONEK 16#0105# => 16#B9#, -- LATIN SMALL LETTER A WITH OGONEK 16#0106# => 16#C6#, -- LATIN CAPITAL LETTER C WITH ACUTE 16#0107# => 16#E6#, -- LATIN SMALL LETTER C WITH ACUTE 16#010C# => 16#C8#, -- LATIN CAPITAL LETTER C WITH CARON 16#010D# => 16#E8#, -- LATIN SMALL LETTER C WITH CARON 16#010E# => 16#CF#, -- LATIN CAPITAL LETTER D WITH CARON 16#010F# => 16#EF#, -- LATIN SMALL LETTER D WITH CARON 16#0110# => 16#D0#, -- LATIN CAPITAL LETTER D WITH STROKE 16#0111# => 16#F0#, -- LATIN SMALL LETTER D WITH STROKE 16#0118# => 16#CA#, -- LATIN CAPITAL LETTER E WITH OGONEK 16#0119# => 16#EA#, -- LATIN SMALL LETTER E WITH OGONEK 16#011A# => 16#CC#, -- LATIN CAPITAL LETTER E WITH CARON 16#011B# => 16#EC#, -- LATIN SMALL LETTER E WITH CARON 16#0139# => 16#C5#, -- LATIN CAPITAL LETTER L WITH ACUTE 16#013A# => 16#E5#, -- LATIN SMALL LETTER L WITH ACUTE 16#013D# => 16#BC#, -- LATIN CAPITAL LETTER L WITH CARON 16#013E# => 16#BE#, -- LATIN SMALL LETTER L WITH CARON 16#0141# => 16#A3#, -- LATIN CAPITAL LETTER L WITH STROKE 16#0142# => 16#B3#, -- LATIN SMALL LETTER L WITH STROKE 16#0143# => 16#D1#, -- LATIN CAPITAL LETTER N WITH ACUTE 16#0144# => 16#F1#, -- LATIN SMALL LETTER N WITH ACUTE 16#0147# => 16#D2#, -- LATIN CAPITAL LETTER N WITH CARON 16#0148# => 16#F2#, -- LATIN SMALL LETTER N WITH CARON 16#0150# => 16#D5#, -- LATIN CAPITAL LETTER O WITH DOUBLE ACUTE 16#0151# => 16#F5#, -- LATIN SMALL LETTER O WITH DOUBLE ACUTE 16#0154# => 16#C0#, -- LATIN CAPITAL LETTER R WITH ACUTE 16#0155# => 16#E0#, -- LATIN SMALL LETTER R WITH ACUTE 16#0158# => 16#D8#, -- LATIN CAPITAL LETTER R WITH CARON 16#0159# => 16#F8#, -- LATIN SMALL LETTER R WITH CARON 16#015A# => 16#8C#, -- LATIN CAPITAL LETTER S WITH ACUTE 16#015B# => 16#9C#, -- LATIN SMALL LETTER S WITH ACUTE 16#015E# => 16#AA#, -- LATIN CAPITAL LETTER S WITH CEDILLA 16#015F# => 16#BA#, -- LATIN SMALL LETTER S WITH CEDILLA 16#0160# => 16#8A#, -- LATIN CAPITAL LETTER S WITH CARON 16#0161# => 16#9A#, -- LATIN SMALL LETTER S WITH CARON 16#0162# => 16#DE#, -- LATIN CAPITAL LETTER T WITH CEDILLA 16#0163# => 16#FE#, -- LATIN SMALL LETTER T WITH CEDILLA 16#0164# => 16#8D#, -- LATIN CAPITAL LETTER T WITH CARON 16#0165# => 16#9D#, -- LATIN SMALL LETTER T WITH CARON 16#016E# => 16#D9#, -- LATIN CAPITAL LETTER U WITH RING ABOVE 16#016F# => 16#F9#, -- LATIN SMALL LETTER U WITH RING ABOVE 16#0170# => 16#DB#, -- LATIN CAPITAL LETTER U WITH DOUBLE ACUTE 16#0171# => 16#FB#, -- LATIN SMALL LETTER U WITH DOUBLE ACUTE 16#0179# => 16#8F#, -- LATIN CAPITAL LETTER Z WITH ACUTE 16#017A# => 16#9F#, -- LATIN SMALL LETTER Z WITH ACUTE 16#017B# => 16#AF#, -- LATIN CAPITAL LETTER Z WITH DOT ABOVE 16#017C# => 16#BF#, -- LATIN SMALL LETTER Z WITH DOT ABOVE 16#017D# => 16#8E#, -- LATIN CAPITAL LETTER Z WITH CARON 16#017E# => 16#9E#, -- LATIN SMALL LETTER Z WITH CARON others => Question_Mark); Encode_Table_02 : constant array (Matreshka.Internals.Unicode.Code_Point range 16#02C7# .. 16#02DD#) of Ada.Streams.Stream_Element := (16#02C7# => 16#A1#, -- CARON 16#02D8# => 16#A2#, -- BREVE 16#02D9# => 16#FF#, -- DOT ABOVE 16#02DB# => 16#B2#, -- OGONEK 16#02DD# => 16#BD#, -- DOUBLE ACUTE ACCENT others => Question_Mark); Encode_Table_20 : constant array (Matreshka.Internals.Unicode.Code_Point range 16#2013# .. 16#203A#) of Ada.Streams.Stream_Element := (16#2013# => 16#96#, -- EN DASH 16#2014# => 16#97#, -- EM DASH 16#2018# => 16#91#, -- LEFT SINGLE QUOTATION MARK 16#2019# => 16#92#, -- RIGHT SINGLE QUOTATION MARK 16#201A# => 16#82#, -- SINGLE LOW-9 QUOTATION MARK 16#201C# => 16#93#, -- LEFT DOUBLE QUOTATION MARK 16#201D# => 16#94#, -- RIGHT DOUBLE QUOTATION MARK 16#201E# => 16#84#, -- DOUBLE LOW-9 QUOTATION MARK 16#2020# => 16#86#, -- DAGGER 16#2021# => 16#87#, -- DOUBLE DAGGER 16#2022# => 16#95#, -- BULLET 16#2026# => 16#85#, -- HORIZONTAL ELLIPSIS 16#2030# => 16#89#, -- PER MILLE SIGN 16#2039# => 16#8B#, -- SINGLE LEFT-POINTING ANGLE QUOTATION MARK 16#203A# => 16#9B#, -- SINGLE RIGHT-POINTING ANGLE QUOTATION -- MARK others => Question_Mark); ------------------- -- Decode_Append -- ------------------- overriding procedure Decode_Append (Self : in out Windows1250_Decoder; Data : Ada.Streams.Stream_Element_Array; String : in out Matreshka.Internals.Strings.Shared_String_Access) is begin Matreshka.Internals.Strings.Mutate (String, String.Unused + Data'Length); for J in Data'Range loop case Data (J) is when 16#00# .. 16#7F# => -- Directly mapped. Self.Unchecked_Append (Self, String, Matreshka.Internals.Unicode.Code_Point (Data (J))); when 16#80# .. 16#FF# => -- Table translated. Self.Unchecked_Append (Self, String, Decode_Table (Data (J))); end case; end loop; String_Handler.Fill_Null_Terminator (String); end Decode_Append; ------------- -- Decoder -- ------------- function Decoder (Mode : Decoder_Mode) return Abstract_Decoder'Class is begin case Mode is when Raw => return Windows1250_Decoder' (Skip_LF => False, Unchecked_Append => Unchecked_Append_Raw'Access); when XML_1_0 => return Windows1250_Decoder' (Skip_LF => False, Unchecked_Append => Unchecked_Append_XML10'Access); when XML_1_1 => return Windows1250_Decoder' (Skip_LF => False, Unchecked_Append => Unchecked_Append_XML11'Access); end case; end Decoder; ------------ -- Encode -- ------------ overriding procedure Encode (Self : in out Windows1250_Encoder; String : not null Matreshka.Internals.Strings.Shared_String_Access; Buffer : out MISEV.Shared_Stream_Element_Vector_Access) is pragma Unreferenced (Self); use Matreshka.Internals.Stream_Element_Vectors; use Ada.Streams; Code : Matreshka.Internals.Unicode.Code_Point; Position : Matreshka.Internals.Utf16.Utf16_String_Index := 0; Element : Ada.Streams.Stream_Element; begin if String.Unused = 0 then Buffer := Empty_Shared_Stream_Element_Vector'Access; else Buffer := Allocate (Ada.Streams.Stream_Element_Offset (String.Unused)); while Position < String.Unused loop Matreshka.Internals.Utf16.Unchecked_Next (String.Value, Position, Code); if Code in 16#0000# .. 16#007F# then -- Direct mapping. Element := Stream_Element (Code); elsif Code in Encode_Table_00'Range then -- Table translation, range 00A0 .. 00FD Element := Encode_Table_00 (Code); elsif Code in Encode_Table_01'Range then -- Table translation, range 0102 .. 017E Element := Encode_Table_01 (Code); elsif Code in Encode_Table_02'Range then -- Table translation, range 02C7 .. 02DD Element := Encode_Table_02 (Code); elsif Code in Encode_Table_20'Range then -- Table translation, range 2013 .. 203A Element := Encode_Table_20 (Code); elsif Code = 16#20AC# then -- 16#20AC# => 16#80# -- EURO SIGN Element := 16#80#; elsif Code = 16#2122# then -- 16#2122# => 16#99# -- TRADE MARK SIGN Element := 16#99#; else Element := Question_Mark; end if; Buffer.Value (Buffer.Length) := Element; Buffer.Length := Buffer.Length + 1; end loop; end if; end Encode; ------------- -- Encoder -- ------------- function Encoder return Abstract_Encoder'Class is begin return Windows1250_Encoder'(null record); end Encoder; -------------- -- Is_Error -- -------------- overriding function Is_Error (Self : Windows1250_Decoder) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Error; ------------------- -- Is_Mailformed -- ------------------- overriding function Is_Mailformed (Self : Windows1250_Decoder) return Boolean is pragma Unreferenced (Self); begin return False; end Is_Mailformed; end Matreshka.Internals.Text_Codecs.Windows1250;
reznikmm/matreshka
Ada
4,037
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011-2012, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ -- A function behavior is an opaque behavior that does not access or modify -- any objects or other external data. ------------------------------------------------------------------------------ with AMF.UML.Opaque_Behaviors; package AMF.UML.Function_Behaviors is pragma Preelaborate; type UML_Function_Behavior is limited interface and AMF.UML.Opaque_Behaviors.UML_Opaque_Behavior; type UML_Function_Behavior_Access is access all UML_Function_Behavior'Class; for UML_Function_Behavior_Access'Storage_Size use 0; end AMF.UML.Function_Behaviors;
ZinebZaad/ENSEEIHT
Ada
9,488
adb
with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with SDA_Exceptions; use SDA_Exceptions; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; --! Les Unbounded_String ont une capacité variable, contrairement au String --! pour lesquelles une capacité doit être fixée. with TH; procedure Test_TH is package TH_String_Integer is new TH (Capacite => 11, T_Cle => Unbounded_String, T_Donnee => Integer, Hachage => Length); use TH_String_Integer; -- Retourner une chaîne avec des guillemets autour de S function Avec_Guillemets (S: Unbounded_String) return String is begin return '"' & To_String (S) & '"'; end; -- Utiliser & entre String à gauche et Unbounded_String à droite. Des -- guillemets sont ajoutées autour de la Unbounded_String -- Il s'agit d'un masquage de l'opérteur & défini dans Strings.Unbounded function "&" (Left: String; Right: Unbounded_String) return String is begin return Left & Avec_Guillemets (Right); end; -- Surcharge l'opérateur unaire "+" pour convertir une String -- en Unbounded_String. -- Cette astuce permet de simplifier l'initialisation -- de cles un peu plus loin. function "+" (Item : in String) return Unbounded_String renames To_Unbounded_String; -- Afficher une Unbounded_String et un entier. procedure Afficher (S : in Unbounded_String; N: in Integer) is begin Put (Avec_Guillemets (S)); Put (" : "); Put (N, 1); New_Line; end Afficher; -- Afficher la Sda. procedure Afficher is new Pour_Chaque (Afficher); Nb_Cles : constant Integer := 7; Cles : constant array (1..Nb_Cles) of Unbounded_String := (+"un", +"deux", +"trois", +"quatre", +"cinq", +"quatre-vingt-dix-neuf", +"vingt-et-un"); Inconnu : constant Unbounded_String := To_Unbounded_String ("Inconnu"); Donnees : constant array (1..Nb_Cles) of Integer := (1, 2, 3, 4, 5, 99, 21); Somme_Donnees : constant Integer := 135; Somme_Donnees_Len4 : constant Integer := 7; -- somme si Length (Cle) = 4 Somme_Donnees_Q: constant Integer := 103; -- somme si initiale de Cle = 'q' -- Initialiser l'annuaire avec les Donnees et Cles ci-dessus. -- Attention, c'est à l'appelant de libérer la mémoire associée en -- utilisant Vider. -- Si Bavard est vrai, les insertions sont tracées (affichées). procedure Construire_Exemple_Sujet (Annuaire : out T_TH; Bavard: Boolean := False) is begin Initialiser (Annuaire); pragma Assert (Est_Vide (Annuaire)); pragma Assert (Taille (Annuaire) = 0); for I in 1..Nb_Cles loop Enregistrer (Annuaire, Cles (I), Donnees (I)); if Bavard then Put_Line ("Après insertion de la clé " & Cles (I)); Afficher (Annuaire); New_Line; else null; end if; pragma Assert (not Est_Vide (Annuaire)); pragma Assert (Taille (Annuaire) = I); for J in 1..I loop pragma Assert (La_Donnee (Annuaire, Cles (J)) = Donnees (J)); end loop; for J in I+1..Nb_Cles loop pragma Assert (not Cle_Presente (Annuaire, Cles (J))); end loop; end loop; end Construire_Exemple_Sujet; procedure Tester_Exemple_Sujet is Annuaire : T_TH; begin Construire_Exemple_Sujet (Annuaire, True); Vider (Annuaire); end Tester_Exemple_Sujet; -- Tester suppression en commençant par les derniers éléments ajoutés procedure Tester_Supprimer_Inverse is Annuaire : T_TH; begin Put_Line ("=== Tester_Supprimer_Inverse..."); New_Line; Construire_Exemple_Sujet (Annuaire); for I in reverse 1..Nb_Cles loop Supprimer (Annuaire, Cles (I)); Put_Line ("Après suppression de " & Cles (I) & " :"); Afficher (Annuaire); New_Line; for J in 1..I-1 loop pragma Assert (Cle_Presente (Annuaire, Cles (J))); pragma Assert (La_Donnee (Annuaire, Cles (J)) = Donnees (J)); end loop; for J in I..Nb_Cles loop pragma Assert (not Cle_Presente (Annuaire, Cles (J))); end loop; end loop; Vider (Annuaire); end Tester_Supprimer_Inverse; -- Tester suppression en commençant les les premiers éléments ajoutés procedure Tester_Supprimer is Annuaire : T_TH; begin Put_Line ("=== Tester_Supprimer..."); New_Line; Construire_Exemple_Sujet (Annuaire); for I in 1..Nb_Cles loop Put_Line ("Suppression de " & Cles (I) & " :"); Supprimer (Annuaire, Cles (I)); Afficher (Annuaire); New_Line; for J in 1..I loop pragma Assert (not Cle_Presente (Annuaire, Cles (J))); end loop; for J in I+1..Nb_Cles loop pragma Assert (Cle_Presente (Annuaire, Cles (J))); pragma Assert (La_Donnee (Annuaire, Cles (J)) = Donnees (J)); end loop; end loop; Vider (Annuaire); end Tester_Supprimer; procedure Tester_Supprimer_Un_Element is -- Tester supprimer sur un élément, celui à Indice dans Cles. procedure Tester_Supprimer_Un_Element (Indice: in Integer) is Annuaire : T_TH; begin Construire_Exemple_Sujet (Annuaire); Put_Line ("Suppression de " & Cles (Indice) & " :"); Supprimer (Annuaire, Cles (Indice)); Afficher (Annuaire); New_Line; for J in 1..Nb_Cles loop if J = Indice then pragma Assert (not Cle_Presente (Annuaire, Cles (J))); else pragma Assert (Cle_Presente (Annuaire, Cles (J))); end if; end loop; Vider (Annuaire); end Tester_Supprimer_Un_Element; begin Put_Line ("=== Tester_Supprimer_Un_Element..."); New_Line; for I in 1..Nb_Cles loop Tester_Supprimer_Un_Element (I); end loop; end Tester_Supprimer_Un_Element; procedure Tester_Remplacer_Un_Element is -- Tester enregistrer sur un élément présent, celui à Indice dans Cles. procedure Tester_Remplacer_Un_Element (Indice: in Integer; Nouveau: in Integer) is Annuaire : T_TH; begin Construire_Exemple_Sujet (Annuaire); Put_Line ("Remplacement de " & Cles (Indice) & " par " & Integer'Image(Nouveau) & " :"); enregistrer (Annuaire, Cles (Indice), Nouveau); Afficher (Annuaire); New_Line; for J in 1..Nb_Cles loop pragma Assert (Cle_Presente (Annuaire, Cles (J))); if J = Indice then pragma Assert (La_Donnee (Annuaire, Cles (J)) = Nouveau); else pragma Assert (La_Donnee (Annuaire, Cles (J)) = Donnees (J)); end if; end loop; Vider (Annuaire); end Tester_Remplacer_Un_Element; begin Put_Line ("=== Tester_Remplacer_Un_Element..."); New_Line; for I in 1..Nb_Cles loop Tester_Remplacer_Un_Element (I, 0); null; end loop; end Tester_Remplacer_Un_Element; procedure Tester_Supprimer_Erreur is Annuaire : T_TH; begin begin Put_Line ("=== Tester_Supprimer_Erreur..."); New_Line; Construire_Exemple_Sujet (Annuaire); Supprimer (Annuaire, Inconnu); exception when Cle_Absente_Exception => null; when others => pragma Assert (False); end; Vider (Annuaire); end Tester_Supprimer_Erreur; procedure Tester_La_Donnee_Erreur is Annuaire : T_TH; Inutile: Integer; begin begin Put_Line ("=== Tester_Supprimer_Erreur..."); New_Line; Construire_Exemple_Sujet (Annuaire); Inutile := La_Donnee (Annuaire, Inconnu); exception when Cle_Absente_Exception => null; when others => pragma Assert (False); end; Vider (Annuaire); end Tester_La_Donnee_Erreur; procedure Tester_Pour_chaque is Annuaire : T_TH; Somme: Integer; procedure Sommer (Cle: Unbounded_String; Donnee: Integer) is begin Put (" + "); Put (Donnee, 2); New_Line; Somme := Somme + Donnee; end; procedure Sommer is new Pour_Chaque (Sommer); begin Put_Line ("=== Tester_Pour_Chaque..."); New_Line; Construire_Exemple_Sujet(Annuaire); Somme := 0; Sommer (Annuaire); pragma Assert (Somme = Somme_Donnees); Vider(Annuaire); New_Line; end Tester_Pour_chaque; procedure Tester_Pour_chaque_Somme_Si_Cle_Commence_Par_Q is Annuaire : T_TH; Somme: Integer; procedure Sommer_Cle_Commence_Par_Q (Cle: Unbounded_String; Donnee: Integer) is begin if To_String (Cle) (1) = 'q' then Put (" + "); Put (Donnee, 2); New_Line; Somme := Somme + Donnee; else null; end if; end; procedure Sommer is new Pour_Chaque (Sommer_Cle_Commence_Par_Q); begin Put_Line ("=== Tester_Pour_Chaque_Somme_Si_Cle_Commence_Par_Q..."); New_Line; Construire_Exemple_Sujet(Annuaire); Somme := 0; Sommer (Annuaire); pragma Assert (Somme = Somme_Donnees_Q); Vider(Annuaire); New_Line; end Tester_Pour_chaque_Somme_Si_Cle_Commence_Par_Q; procedure Tester_Pour_chaque_Somme_Len4_Erreur is Annuaire : T_TH; Somme: Integer; procedure Sommer_Len4_Erreur (Cle: Unbounded_String; Donnee: Integer) is Nouvelle_Exception: Exception; begin if Length (Cle) = 4 then Put (" + "); Put (Donnee, 2); New_Line; Somme := Somme + Donnee; else raise Nouvelle_Exception; end if; end; procedure Sommer is new Pour_Chaque (Sommer_Len4_Erreur); begin Put_Line ("=== Tester_Pour_Chaque_Somme_Len4_Erreur..."); New_Line; Construire_Exemple_Sujet(Annuaire); Somme := 0; Sommer (Annuaire); pragma Assert (Somme = Somme_Donnees_Len4); Vider(Annuaire); New_Line; end Tester_Pour_chaque_Somme_Len4_Erreur; begin Tester_Exemple_Sujet; Tester_Supprimer_Inverse; Tester_Supprimer; Tester_Supprimer_Un_Element; Tester_Remplacer_Un_Element; Tester_Supprimer_Erreur; Tester_La_Donnee_Erreur; Tester_Pour_chaque; Tester_Pour_chaque_Somme_Si_Cle_Commence_Par_Q; Tester_Pour_chaque_Somme_Len4_Erreur; Put_Line ("Fin des tests : OK."); end Test_TH;
reznikmm/matreshka
Ada
4,659
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2012-2013, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ with AMF.OCL.Feature_Call_Exps; limited with AMF.OCL.Ocl_Expressions.Collections; limited with AMF.UML.Properties; package AMF.OCL.Navigation_Call_Exps is pragma Preelaborate; type OCL_Navigation_Call_Exp is limited interface and AMF.OCL.Feature_Call_Exps.OCL_Feature_Call_Exp; type OCL_Navigation_Call_Exp_Access is access all OCL_Navigation_Call_Exp'Class; for OCL_Navigation_Call_Exp_Access'Storage_Size use 0; not overriding function Get_Qualifier (Self : not null access constant OCL_Navigation_Call_Exp) return AMF.OCL.Ocl_Expressions.Collections.Ordered_Set_Of_OCL_Ocl_Expression is abstract; -- Getter of NavigationCallExp::qualifier. -- not overriding function Get_Navigation_Source (Self : not null access constant OCL_Navigation_Call_Exp) return AMF.UML.Properties.UML_Property_Access is abstract; -- Getter of NavigationCallExp::navigationSource. -- not overriding procedure Set_Navigation_Source (Self : not null access OCL_Navigation_Call_Exp; To : AMF.UML.Properties.UML_Property_Access) is abstract; -- Setter of NavigationCallExp::navigationSource. -- end AMF.OCL.Navigation_Call_Exps;
reznikmm/matreshka
Ada
5,530
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011-2012, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ -- An unmarshall action is an action that breaks an object of a known type -- into outputs each of which is equal to a value from a structural feature -- of the object. ------------------------------------------------------------------------------ with AMF.UML.Actions; limited with AMF.UML.Classifiers; limited with AMF.UML.Input_Pins; limited with AMF.UML.Output_Pins.Collections; package AMF.UML.Unmarshall_Actions is pragma Preelaborate; type UML_Unmarshall_Action is limited interface and AMF.UML.Actions.UML_Action; type UML_Unmarshall_Action_Access is access all UML_Unmarshall_Action'Class; for UML_Unmarshall_Action_Access'Storage_Size use 0; not overriding function Get_Object (Self : not null access constant UML_Unmarshall_Action) return AMF.UML.Input_Pins.UML_Input_Pin_Access is abstract; -- Getter of UnmarshallAction::object. -- -- The object to be unmarshalled. not overriding procedure Set_Object (Self : not null access UML_Unmarshall_Action; To : AMF.UML.Input_Pins.UML_Input_Pin_Access) is abstract; -- Setter of UnmarshallAction::object. -- -- The object to be unmarshalled. not overriding function Get_Result (Self : not null access constant UML_Unmarshall_Action) return AMF.UML.Output_Pins.Collections.Set_Of_UML_Output_Pin is abstract; -- Getter of UnmarshallAction::result. -- -- The values of the structural features of the input object. not overriding function Get_Unmarshall_Type (Self : not null access constant UML_Unmarshall_Action) return AMF.UML.Classifiers.UML_Classifier_Access is abstract; -- Getter of UnmarshallAction::unmarshallType. -- -- The type of the object to be unmarshalled. not overriding procedure Set_Unmarshall_Type (Self : not null access UML_Unmarshall_Action; To : AMF.UML.Classifiers.UML_Classifier_Access) is abstract; -- Setter of UnmarshallAction::unmarshallType. -- -- The type of the object to be unmarshalled. end AMF.UML.Unmarshall_Actions;
reznikmm/matreshka
Ada
3,660
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Web Framework -- -- -- -- Tools Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2015, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Asis; with Engines.Contexts; with League.Strings; package Properties.Definitions.Variant is function Assign (Engine : access Engines.Contexts.Context; Element : Asis.Association; Name : Engines.Text_Property) return League.Strings.Universal_String; end Properties.Definitions.Variant;
reznikmm/matreshka
Ada
4,011
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with ODF.DOM.Table_Use_Labels_Attributes; package Matreshka.ODF_Table.Use_Labels_Attributes is type Table_Use_Labels_Attribute_Node is new Matreshka.ODF_Table.Abstract_Table_Attribute_Node and ODF.DOM.Table_Use_Labels_Attributes.ODF_Table_Use_Labels_Attribute with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Table_Use_Labels_Attribute_Node; overriding function Get_Local_Name (Self : not null access constant Table_Use_Labels_Attribute_Node) return League.Strings.Universal_String; end Matreshka.ODF_Table.Use_Labels_Attributes;
charlie5/aIDE
Ada
4,585
adb
-- with -- Ada.Assertions, -- -- Ada.Asynchronous_Task_Control, -- Ada.Calendar.Arithmetic, -- Ada.Calendar.Formatting, -- Ada.Calendar.Time_Zones, -- Ada.Characters.Conversions, -- Ada.Characters.Handling, -- Ada.Characters.Latin_1, -- Ada.Command_Line, -- Ada.Complex_Text_IO, -- Ada.Containers, -- Ada.Containers.Doubly_Linked_Lists, -- Ada.Containers.Generic_Array_Sort, -- Ada.Containers.Generic_Constrained_Array_Sort, -- Ada.Containers.Hashed_Maps, -- Ada.Containers.Hashed_Sets, -- Ada.Containers.Indefinite_Doubly_Linked_Lists, -- Ada.Containers.Indefinite_Hashed_Maps, -- Ada.Containers.Indefinite_Hashed_Sets, -- Ada.Containers.Indefinite_Ordered_Maps, -- Ada.Containers.Indefinite_Ordered_Sets, -- Ada.Containers.Indefinite_Vectors, -- Ada.Containers.Ordered_Maps, -- Ada.Containers.Ordered_Sets, -- Ada.Containers.Vectors, -- Ada.Decimal, -- Ada.Direct_IO, -- Ada.Directories, -- -- Ada.Directories.Information, -- Ada.Dispatching, -- -- Ada.Dispatching.EDF, -- -- Ada.Dispatching.Round_Robin, -- Ada.Dynamic_Priorities, -- Ada.Environment_Variables, -- Ada.Exceptions, -- Ada.Execution_Time, -- -- Ada.Execution_Time.Timers, -- -- Ada.Execution_Time.Group_Budgets, -- Ada.Finalization, -- Ada.Float_Text_IO, -- Ada.Float_Wide_Text_IO, -- -- Ada.Float_Wide_Wide_Text_IO, -- Ada.Integer_Text_IO, -- Ada.Integer_Wide_Text_IO, -- Ada.Integer_Wide_Wide_Text_IO, -- Ada.Interrupts, -- Ada.Interrupts.Names, -- Ada.IO_Exceptions, -- Ada.Numerics, -- Ada.Numerics.Complex_Arrays, -- Ada.Numerics.Complex_Elementary_Functions, -- Ada.Numerics.Complex_Types, -- Ada.Numerics.Discrete_Random, -- Ada.Numerics.Elementary_Functions, -- Ada.Numerics.Float_Random, -- Ada.Numerics.Generic_Complex_Arrays, -- Ada.Numerics.Generic_Complex_Elementary_Functions, -- Ada.Numerics.Generic_Complex_Types, -- Ada.Numerics.Generic_Elementary_Functions, -- Ada.Numerics.Generic_Real_Arrays, -- Ada.Numerics.Real_Arrays, -- Ada.Real_Time, -- Ada.Real_Time.Timing_Events, -- Ada.Sequential_IO, -- Ada.Storage_IO, -- Ada.Streams, -- Ada.Streams.Stream_IO, -- Ada.Strings, -- Ada.Strings.Bounded, -- Ada.Strings.Bounded.Hash, -- Ada.Strings.Fixed, -- Ada.Strings.Fixed.Hash, -- Ada.Strings.Hash, -- Ada.Strings.Maps, -- Ada.Strings.Maps.Constants, -- Ada.Strings.Unbounded, -- Ada.Strings.Unbounded.Hash, -- Ada.Strings.Wide_Bounded, -- Ada.Strings.Wide_Bounded.Wide_Hash, -- Ada.Strings.Wide_Fixed, -- Ada.Strings.Wide_Fixed.Wide_Hash, -- Ada.Strings.Wide_Hash, -- Ada.Strings.Wide_Maps, -- Ada.Strings.Wide_Maps.Wide_Constants, -- Ada.Strings.Wide_Unbounded, -- Ada.Strings.Wide_Unbounded.Wide_Hash, -- Ada.Strings.Wide_Wide_Bounded, -- Ada.Strings.Wide_Wide_Bounded.Wide_Wide_Hash, -- Ada.Strings.Wide_Wide_Fixed, -- Ada.Strings.Wide_Wide_Fixed.Wide_Wide_Hash, -- Ada.Strings.Wide_Wide_Hash, -- Ada.Strings.Wide_Wide_Maps, -- Ada.Strings.Wide_Wide_Maps.Wide_Wide_Constants, -- Ada.Strings.Wide_Wide_Unbounded, -- Ada.Strings.Wide_Wide_Unbounded.Wide_Wide_Hash, -- Ada.Synchronous_Task_Control, -- Ada.Tags, -- Ada.Tags.Generic_Dispatching_Constructor, -- Ada.Task_Attributes, -- Ada.Task_Identification, -- Ada.Task_Termination, -- Ada.Text_IO; -- Ada.Text_IO.Bounded_IO, -- Ada.Text_IO.Complex_IO, -- Ada.Text_IO.Editing, -- Ada.Text_IO.Text_Streams, -- Ada.Text_IO.Unbounded_IO, -- Ada.Unchecked_Conversion, -- Ada.Unchecked_Deallocation, -- Ada.Wide_Characters, -- Ada.Wide_Text_IO, -- -- Ada.Wide_Text_IO.Bounded_IO, -- Ada.Wide_Text_IO.Complex_IO, -- Ada.Wide_Text_IO.Editing, -- Ada.Wide_Text_IO.Text_Streams, -- -- Ada.Wide_Text_IO.Unbounded_IO, -- Ada.Wide_Wide_Characters, -- Ada.Wide_Wide_Text_IO, -- -- Ada.Wide_Wide_Text_IO.Bounded_IO, -- Ada.Wide_Wide_Text_IO.Complex_IO, -- Ada.Wide_Wide_Text_IO.Editing, -- Ada.Wide_Wide_Text_IO.Text_Streams; -- -- Ada.Wide_Wide_Text_IO.Unbounded_IO; procedure all_standard_Ada is begin null; end all_standard_Ada;
godunko/adawebpack
Ada
4,409
ads
------------------------------------------------------------------------------ -- -- -- AdaWebPack -- -- -- ------------------------------------------------------------------------------ -- Copyright © 2020-2022, Vadim Godunko -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- 3. Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- ------------------------------------------------------------------------------ -- Package to process strings. ------------------------------------------------------------------------------ private with Ada.Finalization; private with Interfaces; private with Web.Unicode; package Web.Strings with Preelaborate is type Web_String is tagged private with String_Literal => To_Web_String; Empty_Web_String : constant Web_String; function Is_Empty (Self : Web_String'Class) return Boolean; function Is_Null (Self : Web_String'Class) return Boolean; function Length (Self : Web_String'Class) return Natural; procedure Clear (Self : in out Web_String'Class); -- Clears the contents of the string and makes it null. function To_Web_String (Item : Wide_Wide_String) return Web_String; function To_Wide_Wide_String (Self : Web_String) return Wide_Wide_String; function "=" (Left : Web_String; Right : Web_String) return Boolean; function "&" (Left : Web_String; Right : Web_String) return Web_String; private type String_Data (Capacity : Interfaces.Unsigned_32) is record Counter : Interfaces.Unsigned_32 := 1; Size : Interfaces.Unsigned_32; Length : Natural; Data : Web.Unicode.UTF16_Code_Unit_Array (0 .. Capacity); end record; type String_Data_Access is access all String_Data; type Web_String is new Ada.Finalization.Controlled with record Data : String_Data_Access; end record; overriding procedure Adjust (Self : in out Web_String); overriding procedure Finalize (Self : in out Web_String); Empty_Web_String : constant Web_String := (Ada.Finalization.Controlled with Data => null); end Web.Strings;
LiberatorUSA/GUCEF
Ada
10,776
ads
with agar.core.event; with agar.core.slist; with agar.core.timeout; with agar.gui.surface; with agar.gui.widget.menu; with agar.gui.widget.scrollbar; with agar.gui.window; package agar.gui.widget.table is use type c.unsigned; type popup_t is limited private; type popup_access_t is access all popup_t; pragma convention (c, popup_access_t); txt_max : constant := 128; fmt_max : constant := 16; col_name_max : constant := 48; type select_mode_t is (SEL_ROWS, SEL_CELLS, SEL_COLS); for select_mode_t use (SEL_ROWS => 0, SEL_CELLS => 1, SEL_COLS => 2); for select_mode_t'size use c.unsigned'size; pragma convention (c, select_mode_t); package popup_slist is new agar.core.slist (entry_type => popup_access_t); type cell_type_t is ( CELL_NULL, CELL_STRING, CELL_INT, CELL_UINT, CELL_LONG, CELL_ULONG, CELL_FLOAT, CELL_DOUBLE, CELL_PSTRING, CELL_PINT, CELL_PUINT, CELL_PLONG, CELL_PULONG, CELL_PUINT8, CELL_PSINT8, CELL_PUINT16, CELL_PSINT16, CELL_PUINT32, CELL_PSINT32, CELL_PFLOAT, CELL_PDOUBLE, CELL_INT64, CELL_UINT64, CELL_PINT64, CELL_PUINT64, CELL_POINTER, CELL_FN_SU, CELL_FN_TXT, CELL_WIDGET ); for cell_type_t use ( CELL_NULL => 0, CELL_STRING => 1, CELL_INT => 2, CELL_UINT => 3, CELL_LONG => 4, CELL_ULONG => 5, CELL_FLOAT => 6, CELL_DOUBLE => 7, CELL_PSTRING => 8, CELL_PINT => 9, CELL_PUINT => 10, CELL_PLONG => 11, CELL_PULONG => 12, CELL_PUINT8 => 13, CELL_PSINT8 => 14, CELL_PUINT16 => 15, CELL_PSINT16 => 16, CELL_PUINT32 => 17, CELL_PSINT32 => 18, CELL_PFLOAT => 19, CELL_PDOUBLE => 20, CELL_INT64 => 21, CELL_UINT64 => 22, CELL_PINT64 => 23, CELL_PUINT64 => 24, CELL_POINTER => 25, CELL_FN_SU => 26, CELL_FN_TXT => 27, CELL_WIDGET => 28 ); for cell_type_t'size use c.unsigned'size; pragma convention (c, cell_type_t); type cell_data_text_t is array (1 .. txt_max) of aliased c.char; pragma convention (c, cell_data_text_t); type cell_data_selector_t is (sel_s, sel_i, sel_f, sel_p, sel_l, sel_u64); type cell_data_t (member : cell_data_selector_t := sel_s) is record case member is when sel_s => s : cell_data_text_t; when sel_i => i : c.int; when sel_f => f : c.double; when sel_p => p : agar.core.types.void_ptr_t; when sel_l => l : c.long; when sel_u64 => u64 : agar.core.types.uint64_t; end case; end record; pragma convention (c, cell_data_t); pragma unchecked_union (cell_data_t); type cell_format_t is array (1 .. fmt_max) of aliased c.char; pragma convention (c, cell_format_t); type cell_t is limited private; type cell_access_t is access all cell_t; pragma convention (c, cell_access_t); type column_name_t is array (1 .. col_name_max) of aliased c.char; pragma convention (c, column_name_t); type column_flags_t is new c.unsigned; TABLE_COL_FILL : constant column_flags_t := 16#01#; TABLE_SORT_ASCENDING : constant column_flags_t := 16#02#; TABLE_SORT_DESCENDING : constant column_flags_t := 16#04#; TABLE_HFILL : constant column_flags_t := 16#08#; TABLE_VFILL : constant column_flags_t := 16#10#; TABLE_EXPAND : constant column_flags_t := TABLE_HFILL or TABLE_VFILL; type column_t is limited private; type column_access_t is access all column_t; pragma convention (c, column_access_t); type table_flags_t is new c.unsigned; TABLE_MULTI : constant table_flags_t := 16#01#; TABLE_MULTITOGGLE : constant table_flags_t := 16#02#; TABLE_REDRAW_CELLS : constant table_flags_t := 16#04#; TABLE_POLL : constant table_flags_t := 16#08#; TABLE_HIGHLIGHT_COLS : constant table_flags_t := 16#40#; TABLE_MULTIMODE : constant table_flags_t := TABLE_MULTI or TABLE_MULTITOGGLE; type table_t is limited private; type table_access_t is access all table_t; pragma convention (c, table_access_t); type sort_callback_t is access function (elem1 : agar.core.types.void_ptr_t; elem2 : agar.core.types.void_ptr_t) return c.int; pragma convention (c, sort_callback_t); -- API function allocate (parent : widget_access_t; flags : table_flags_t) return table_access_t; pragma import (c, allocate, "AG_TableNew"); function allocate_polled (parent : widget_access_t; flags : table_flags_t; callback : agar.core.event.callback_t) return table_access_t; pragma inline (allocate_polled); procedure size_hint (table : table_access_t; width : positive; num_rows : positive); pragma inline (size_hint); procedure set_separator (table : table_access_t; separator : string); pragma inline (set_separator); function set_popup (table : table_access_t; row : integer; column : integer) return agar.gui.widget.menu.item_access_t; pragma inline (set_popup); procedure set_row_double_click_func (table : table_access_t; callback : agar.core.event.callback_t); pragma inline (set_row_double_click_func); procedure set_column_double_click_func (table : table_access_t; callback : agar.core.event.callback_t); pragma inline (set_column_double_click_func); -- table functions procedure table_begin (table : table_access_t); pragma import (c, table_begin, "AG_TableBegin"); procedure table_end (table : table_access_t); pragma import (c, table_end, "AG_TableEnd"); -- column functions function add_column (table : table_access_t; name : string; size_spec : string; sort_callback : sort_callback_t) return boolean; pragma inline (add_column); procedure select_column (table : table_access_t; column : integer); pragma inline (select_column); procedure deselect_column (table : table_access_t; column : integer); pragma inline (deselect_column); procedure select_all_columns (table : table_access_t); pragma import (c, select_all_columns, "AG_TableSelectAllCols"); procedure deselect_all_columns (table : table_access_t); pragma import (c, deselect_all_columns, "AG_TableDeselectAllCols"); function column_selected (table : table_access_t; column : integer) return boolean; pragma inline (column_selected); -- row functions -- TODO: how to get arguments to this function (format string)? -- function add_row -- (table : table_access_t -- ... -- pragma inline (add_row); procedure select_row (table : table_access_t; row : natural); pragma inline (select_row); procedure deselect_row (table : table_access_t; row : natural); pragma inline (deselect_row); procedure select_all_rows (table : table_access_t); pragma import (c, select_all_rows, "AG_TableSelectAllCols"); procedure deselect_all_rows (table : table_access_t); pragma import (c, deselect_all_rows, "AG_TableDeselectAllCols"); function row_selected (table : table_access_t; row : natural) return boolean; pragma inline (row_selected); -- cell functions procedure select_cell (table : table_access_t; row : natural; column : natural); pragma inline (select_cell); procedure deselect_cell (table : table_access_t; row : natural; column : natural); pragma inline (deselect_cell); function cell_selected (table : table_access_t; row : natural; column : natural) return boolean; pragma inline (cell_selected); function compare_cells (cell1 : cell_access_t; cell2 : cell_access_t) return integer; pragma inline (compare_cells); -- function rows (table : table_access_t) return natural; pragma inline (rows); function columns (table : table_access_t) return natural; pragma inline (columns); -- function widget (table : table_access_t) return widget_access_t; pragma inline (widget); private type table_t is record widget : aliased widget_t; flags : table_flags_t; selmode : select_mode_t; w_hint : c.int; h_hint : c.int; sep : cs.chars_ptr; h_row : c.int; h_col : c.int; w_col_min : c.int; w_col_default : c.int; x_offset : c.int; m_offset : c.int; cols : column_access_t; cells : access cell_access_t; n : c.unsigned; m : c.unsigned; m_vis : c.unsigned; n_resizing : c.int; v_bar : agar.gui.widget.scrollbar.scrollbar_access_t; h_bar : agar.gui.widget.scrollbar.scrollbar_access_t; poll_ev : agar.core.event.event_access_t; dbl_click_row_ev : agar.core.event.event_access_t; dbl_click_col_ev : agar.core.event.event_access_t; dbl_click_cell_ev : agar.core.event.event_access_t; dbl_clicked_row : c.int; dbl_clicked_col : c.int; dbl_clicked_cell : c.int; wheel_ticks : agar.core.types.uint32_t; inc_to : agar.core.timeout.timeout_t; dec_to : agar.core.timeout.timeout_t; r : agar.gui.rect.rect_t; w_total : c.int; popups : popup_slist.head_t; end record; pragma convention (c, table_t); type column_t is record name : column_name_t; sort_fn : access function (a, b : agar.core.types.void_ptr_t) return c.int; flags : column_flags_t; selected : c.int; w : c.int; w_pct : c.int; x : c.int; surface : c.int; pool : cell_access_t; mpool : c.unsigned; end record; pragma convention (c, column_t); type cell_t is record cell_type : cell_type_t; data : cell_data_t; fmt : cell_format_t; fn_su : access function (v : agar.core.types.void_ptr_t; n : c.int; m : c.int) return agar.gui.surface.surface_access_t; fn_txt : access procedure (v : agar.core.types.void_ptr_t; s : cs.chars_ptr; n : c.size_t); widget : widget_access_t; selected : c.int; surface : c.int; end record; pragma convention (c, cell_t); type popup_t is record m : c.int; n : c.int; menu : agar.gui.widget.menu.menu_access_t; item : agar.gui.widget.menu.item_access_t; panel : agar.gui.window.window_access_t; popups : popup_slist.entry_t; end record; pragma convention (c, popup_t); end agar.gui.widget.table;
reznikmm/matreshka
Ada
11,420
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011-2012, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with AMF.Internals.UML_Named_Elements; with AMF.UML.Connectors; with AMF.UML.Dependencies.Collections; with AMF.UML.Interactions; with AMF.UML.Message_Ends; with AMF.UML.Messages; with AMF.UML.Named_Elements; with AMF.UML.Namespaces; with AMF.UML.Packages.Collections; with AMF.UML.String_Expressions; with AMF.UML.Value_Specifications.Collections; with AMF.Visitors; package AMF.Internals.UML_Messages is type UML_Message_Proxy is limited new AMF.Internals.UML_Named_Elements.UML_Named_Element_Proxy and AMF.UML.Messages.UML_Message with null record; overriding function Get_Argument (Self : not null access constant UML_Message_Proxy) return AMF.UML.Value_Specifications.Collections.Ordered_Set_Of_UML_Value_Specification; -- Getter of Message::argument. -- -- The arguments of the Message overriding function Get_Connector (Self : not null access constant UML_Message_Proxy) return AMF.UML.Connectors.UML_Connector_Access; -- Getter of Message::connector. -- -- The Connector on which this Message is sent. overriding procedure Set_Connector (Self : not null access UML_Message_Proxy; To : AMF.UML.Connectors.UML_Connector_Access); -- Setter of Message::connector. -- -- The Connector on which this Message is sent. overriding function Get_Interaction (Self : not null access constant UML_Message_Proxy) return AMF.UML.Interactions.UML_Interaction_Access; -- Getter of Message::interaction. -- -- The enclosing Interaction owning the Message overriding procedure Set_Interaction (Self : not null access UML_Message_Proxy; To : AMF.UML.Interactions.UML_Interaction_Access); -- Setter of Message::interaction. -- -- The enclosing Interaction owning the Message overriding function Get_Message_Kind (Self : not null access constant UML_Message_Proxy) return AMF.UML.UML_Message_Kind; -- Getter of Message::messageKind. -- -- The derived kind of the Message (complete, lost, found or unknown) overriding function Get_Message_Sort (Self : not null access constant UML_Message_Proxy) return AMF.UML.UML_Message_Sort; -- Getter of Message::messageSort. -- -- The sort of communication reflected by the Message overriding procedure Set_Message_Sort (Self : not null access UML_Message_Proxy; To : AMF.UML.UML_Message_Sort); -- Setter of Message::messageSort. -- -- The sort of communication reflected by the Message overriding function Get_Receive_Event (Self : not null access constant UML_Message_Proxy) return AMF.UML.Message_Ends.UML_Message_End_Access; -- Getter of Message::receiveEvent. -- -- References the Receiving of the Message overriding procedure Set_Receive_Event (Self : not null access UML_Message_Proxy; To : AMF.UML.Message_Ends.UML_Message_End_Access); -- Setter of Message::receiveEvent. -- -- References the Receiving of the Message overriding function Get_Send_Event (Self : not null access constant UML_Message_Proxy) return AMF.UML.Message_Ends.UML_Message_End_Access; -- Getter of Message::sendEvent. -- -- References the Sending of the Message. overriding procedure Set_Send_Event (Self : not null access UML_Message_Proxy; To : AMF.UML.Message_Ends.UML_Message_End_Access); -- Setter of Message::sendEvent. -- -- References the Sending of the Message. overriding function Get_Signature (Self : not null access constant UML_Message_Proxy) return AMF.UML.Named_Elements.UML_Named_Element_Access; -- Getter of Message::signature. -- -- The signature of the Message is the specification of its content. It -- refers either an Operation or a Signal. overriding procedure Set_Signature (Self : not null access UML_Message_Proxy; To : AMF.UML.Named_Elements.UML_Named_Element_Access); -- Setter of Message::signature. -- -- The signature of the Message is the specification of its content. It -- refers either an Operation or a Signal. overriding function Get_Client_Dependency (Self : not null access constant UML_Message_Proxy) return AMF.UML.Dependencies.Collections.Set_Of_UML_Dependency; -- Getter of NamedElement::clientDependency. -- -- Indicates the dependencies that reference the client. overriding function Get_Name_Expression (Self : not null access constant UML_Message_Proxy) return AMF.UML.String_Expressions.UML_String_Expression_Access; -- Getter of NamedElement::nameExpression. -- -- The string expression used to define the name of this named element. overriding procedure Set_Name_Expression (Self : not null access UML_Message_Proxy; To : AMF.UML.String_Expressions.UML_String_Expression_Access); -- Setter of NamedElement::nameExpression. -- -- The string expression used to define the name of this named element. overriding function Get_Namespace (Self : not null access constant UML_Message_Proxy) return AMF.UML.Namespaces.UML_Namespace_Access; -- Getter of NamedElement::namespace. -- -- Specifies the namespace that owns the NamedElement. overriding function Get_Qualified_Name (Self : not null access constant UML_Message_Proxy) return AMF.Optional_String; -- Getter of NamedElement::qualifiedName. -- -- A name which allows the NamedElement to be identified within a -- hierarchy of nested Namespaces. It is constructed from the names of the -- containing namespaces starting at the root of the hierarchy and ending -- with the name of the NamedElement itself. overriding function Message_Kind (Self : not null access constant UML_Message_Proxy) return AMF.UML.UML_Message_Kind; -- Operation Message::messageKind. -- -- Missing derivation for Message::/messageKind : MessageKind overriding function All_Owning_Packages (Self : not null access constant UML_Message_Proxy) return AMF.UML.Packages.Collections.Set_Of_UML_Package; -- Operation NamedElement::allOwningPackages. -- -- The query allOwningPackages() returns all the directly or indirectly -- owning packages. overriding function Is_Distinguishable_From (Self : not null access constant UML_Message_Proxy; N : AMF.UML.Named_Elements.UML_Named_Element_Access; Ns : AMF.UML.Namespaces.UML_Namespace_Access) return Boolean; -- Operation NamedElement::isDistinguishableFrom. -- -- The query isDistinguishableFrom() determines whether two NamedElements -- may logically co-exist within a Namespace. By default, two named -- elements are distinguishable if (a) they have unrelated types or (b) -- they have related types but different names. overriding function Namespace (Self : not null access constant UML_Message_Proxy) return AMF.UML.Namespaces.UML_Namespace_Access; -- Operation NamedElement::namespace. -- -- Missing derivation for NamedElement::/namespace : Namespace overriding procedure Enter_Element (Self : not null access constant UML_Message_Proxy; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Control : in out AMF.Visitors.Traverse_Control); -- Dispatch call to corresponding subprogram of visitor interface. overriding procedure Leave_Element (Self : not null access constant UML_Message_Proxy; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Control : in out AMF.Visitors.Traverse_Control); -- Dispatch call to corresponding subprogram of visitor interface. overriding procedure Visit_Element (Self : not null access constant UML_Message_Proxy; Iterator : in out AMF.Visitors.Abstract_Iterator'Class; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Control : in out AMF.Visitors.Traverse_Control); -- Dispatch call to corresponding subprogram of iterator interface. end AMF.Internals.UML_Messages;
faelys/natools
Ada
11,143
adb
------------------------------------------------------------------------------ -- Copyright (c) 2013-2014, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ------------------------------------------------------------------------------ with Ada.Exceptions; with Natools.S_Expressions.Test_Tools; package body Natools.S_Expressions.Encodings.Tests is procedure All_Tests (Report : in out NT.Reporter'Class) is begin Hexadecimal_Test (Report); Base64_Test (Report); User_Base64_Test (Report); end All_Tests; procedure Hexadecimal_Test (Report : in out NT.Reporter'Class) is All_Octets : Atom (1 .. 256); begin for I in All_Octets'Range loop All_Octets (I) := Octet (I - All_Octets'First); end loop; declare Name : constant String := "Decoding upper-case hexadecimal encoded"; begin Test_Tools.Test_Atom (Report, Name, All_Octets, Decode_Hex (Encode_Hex (All_Octets, Upper))); exception when Error : others => Report.Report_Exception (Name, Error); end; declare Name : constant String := "Decoding lower-case hexadecimal encoded"; begin Test_Tools.Test_Atom (Report, Name, All_Octets, Decode_Hex (Encode_Hex (All_Octets, Lower))); exception when Error : others => Report.Report_Exception (Name, Error); end; declare Name : constant String := "Decoding garbage-laced text"; begin Test_Tools.Test_Atom (Report, Name, (16#01#, 16#23#, 16#45#, 16#67#, 16#89#, 16#AB#, 16#CD#, 16#EF#, 16#AB#, 16#CD#, 16#EF#), Decode_Hex (All_Octets)); exception when Error : others => Report.Report_Exception (Name, Error); end; declare Name : constant String := "Decoding an odd number of nibbles"; begin Test_Tools.Test_Atom (Report, Name, (16#45#, 16#56#, 16#70#), Decode_Hex (To_Atom ("45 56 7"))); exception when Error : others => Report.Report_Exception (Name, Error); end; declare Name : constant String := "Decode_Hex with non-hex-digit"; Result : Octet; begin Result := Decode_Hex (180); Report.Item (Name, NT.Fail); Report.Info ("No exception raised. Result: " & Octet'Image (Result)); exception when Constraint_Error => Report.Item (Name, NT.Success); when Error : others => Report.Item (Name, NT.Fail); Report.Info ("Unexpected exception " & Ada.Exceptions.Exception_Name (Error) & " has been raised"); end; declare Name : constant String := "Overflow in Encode_Hex"; Result : Octet; begin Result := Encode_Hex (16, Lower); Report.Item (Name, NT.Fail); Report.Info ("No exception raised. Result: " & Octet'Image (Result)); exception when Constraint_Error => Report.Item (Name, NT.Success); when Error : others => Report.Item (Name, NT.Fail); Report.Info ("Unexpected exception " & Ada.Exceptions.Exception_Name (Error) & " has been raised"); end; end Hexadecimal_Test; procedure Base64_Test (Report : in out NT.Reporter'Class) is begin declare Name : constant String := "Decoding encoding of all octet triplets"; Success : Boolean := True; Expected : Atom (1 .. 3); begin for A in Octet loop Expected (1) := A; for B in Octet loop Expected (2) := B; for C in Octet loop Expected (3) := C; declare Found : constant Atom := Decode_Base64 (Encode_Base64 (Expected)); begin if Expected /= Found then if Success then Success := False; Report.Item (Name, NT.Fail); end if; Test_Tools.Dump_Atom (Report, Found, "Found"); Test_Tools.Dump_Atom (Report, Expected, "Expected"); end if; end; end loop; end loop; end loop; if Success then Report.Item (Name, NT.Success); end if; exception when Error : others => Report.Report_Exception (Name, Error); end; declare Name : constant String := "Decoding encoding of all octet duets"; Success : Boolean := True; Expected : Atom (1 .. 2); begin for A in Octet loop Expected (1) := A; for B in Octet loop Expected (2) := B; declare Found : constant Atom := Decode_Base64 (Encode_Base64 (Expected)); begin if Expected /= Found then if Success then Success := False; Report.Item (Name, NT.Fail); end if; Test_Tools.Dump_Atom (Report, Found, "Found"); Test_Tools.Dump_Atom (Report, Expected, "Expected"); end if; end; end loop; end loop; if Success then Report.Item (Name, NT.Success); end if; exception when Error : others => Report.Report_Exception (Name, Error); end; declare Name : constant String := "Decoding encoding of all single octets"; Success : Boolean := True; Expected : Atom (1 .. 1); begin for A in Octet loop Expected (1) := A; declare Found : constant Atom := Decode_Base64 (Encode_Base64 (Expected)); begin if Expected /= Found then if Success then Success := False; Report.Item (Name, NT.Fail); end if; Test_Tools.Dump_Atom (Report, Found, "Found"); Test_Tools.Dump_Atom (Report, Expected, "Expected"); end if; end; end loop; if Success then Report.Item (Name, NT.Success); end if; exception when Error : others => Report.Report_Exception (Name, Error); end; declare Name : constant String := "Decode_Base64 with non-base64-digit"; Result : Octet; begin Result := Decode_Base64 (127); Report.Item (Name, NT.Fail); Report.Info ("No exception raised. Result: " & Octet'Image (Result)); exception when Constraint_Error => Report.Item (Name, NT.Success); when Error : others => Report.Item (Name, NT.Fail); Report.Info ("Unexpected exception " & Ada.Exceptions.Exception_Name (Error) & " has been raised"); end; declare Name : constant String := "Overflow in Encode_Base64"; Result : Octet; begin Result := Encode_Base64 (64); Report.Item (Name, NT.Fail); Report.Info ("No exception raised. Result: " & Octet'Image (Result)); exception when Constraint_Error => Report.Item (Name, NT.Success); when Error : others => Report.Item (Name, NT.Fail); Report.Info ("Unexpected exception " & Ada.Exceptions.Exception_Name (Error) & " has been raised"); end; end Base64_Test; procedure User_Base64_Test (Report : in out NT.Reporter'Class) is Test : NT.Test := Report.Item ("Base-64 with user-defined charset"); begin declare Digit_62 : constant Octet := Character'Pos ('-'); Digit_63 : constant Octet := Character'Pos ('_'); -- Charset for Base-64 URI (RFC 4648) Padding : constant Octet := Character'Pos ('|'); Source : constant Atom := (4#0000#, 4#0100#, 4#2003#, 4#0100#, 4#1101#, 4#2013#, 4#0200#, 4#2102#, 4#2023#, 4#0300#, 4#3103#, 4#2033#, 4#1001#, 4#0110#, 4#2103#, 4#1101#, 4#1111#, 4#2113#, 4#1201#, 4#2112#, 4#2123#, 4#1301#, 4#3113#, 4#2133#, 4#2002#, 4#0120#, 4#2203#, 4#2102#, 4#1121#, 4#2213#, 4#2202#, 4#2122#, 4#2223#, 4#2302#, 4#3123#, 4#2233#, 4#3003#, 4#0130#, 4#2303#, 4#3103#, 4#1131#, 4#2313#, 4#3203#, 4#2132#, 4#2323#, 4#3303#, 4#3133#, 4#2333#, 16#42#); Expected : constant Atom := (65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, Digit_62, Digit_63, 81, 103, Padding, Padding); Encoded_Short : constant Atom := Encode_Base64 (Source, Digit_62, Digit_63); Encoded_Long : constant Atom := Encode_Base64 (Source, Digit_62, Digit_63, Padding); begin Test_Tools.Test_Atom (Test, Expected, Encoded_Long); Test_Tools.Test_Atom (Test, Expected (Expected'First .. Expected'Last - 2), Encoded_Short); Test_Tools.Test_Atom (Test, Source, Decode_Base64 (Encoded_Long, Digit_62, Digit_63)); Test_Tools.Test_Atom (Test, Source, Decode_Base64 (Encoded_Short, Digit_62, Digit_63)); end; exception when Error : others => Test.Report_Exception (Error); end User_Base64_Test; end Natools.S_Expressions.Encodings.Tests;
Lyanf/pok
Ada
905
ads
-- --------------------------------------------------------------------------- -- -- -- TIME constant and type definitions and management services -- -- -- -- --------------------------------------------------------------------------- package APEX.Timing is procedure Timed_Wait (Delay_Time : in System_Time_Type; Return_Code : out Return_Code_Type); procedure Periodic_Wait (Return_Code : out Return_Code_Type); procedure Get_Time (System_Time : out System_Time_Type; Return_Code : out Return_Code_Type); procedure Replenish (Budget_Time : in System_Time_Type; Return_Code : out Return_Code_Type); -- POK BINDINGS pragma Import (C, Timed_Wait, "TIMED_WAIT"); pragma Import (C, Periodic_Wait, "PERIODIC_WAIT"); pragma Import (C, Get_Time, "GET_TIME"); pragma Import (C, Replenish, "REPLENISH"); -- END OF POK BINDINGS end Apex.Timing;
zhmu/ananas
Ada
3,133
adb
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- A D A . D I S P A T C H I N G -- -- -- -- B o d y -- -- -- -- Copyright (C) 2015-2022, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with Ada.Exceptions; with System.Tasking; with System.Task_Primitives.Operations; package body Ada.Dispatching is procedure Yield is Self_Id : constant System.Tasking.Task_Id := System.Task_Primitives.Operations.Self; begin -- If pragma Detect_Blocking is active, Program_Error must be -- raised if this potentially blocking operation is called from a -- protected action. if System.Tasking.Detect_Blocking and then Self_Id.Common.Protected_Action_Nesting > 0 then Ada.Exceptions.Raise_Exception (Program_Error'Identity, "potentially blocking operation"); else System.Task_Primitives.Operations.Yield; end if; end Yield; end Ada.Dispatching;
AdaCore/training_material
Ada
538
adb
package body Alarm with Refined_State => (Input_State => Temperature, Output_State => Status) is function Get_Temperature return Integer is Current : Integer := Temperature; begin return Current; end Get_Temperature; function Get_Status return Alarm_Status is begin return Status; end Get_Status; procedure Set_Status is Current : Integer := Get_Temperature; begin if Current > 100 then Status := On; end if; end Set_Status; end Alarm;
faelys/natools
Ada
5,838
ads
------------------------------------------------------------------------------ -- Copyright (c) 2016, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ------------------------------------------------------------------------------ with Ada.Characters.Latin_1; with Natools.Smaz.Original_Hash; package Natools.Smaz.Original is pragma Pure (Natools.Smaz.Original); LF : constant Character := Ada.Characters.Latin_1.LF; CR : constant Character := Ada.Characters.Latin_1.CR; Dictionary : constant Natools.Smaz.Dictionary := (Dict_Last => 253, String_Size => 593, Variable_Length_Verbatim => True, Max_Word_Length => 7, Offsets => (1, 2, 5, 6, 7, 8, 10, 11, 14, 15, 16, 17, 19, 20, 23, 25, 27, 29, 31, 32, 35, 37, 39, 40, 42, 43, 45, 47, 49, 50, 52, 54, 56, 59, 61, 64, 66, 68, 70, 71, 73, 76, 78, 80, 85, 86, 87, 89, 91, 95, 96, 99, 101, 103, 105, 107, 110, 112, 113, 115, 116, 117, 119, 121, 124, 127, 128, 130, 137, 140, 142, 145, 147, 150, 152, 154, 156, 159, 161, 164, 166, 168, 169, 172, 173, 175, 177, 181, 183, 185, 188, 189, 191, 193, 197, 199, 201, 203, 206, 208, 211, 216, 217, 219, 223, 225, 228, 230, 233, 235, 236, 237, 239, 242, 245, 247, 249, 252, 254, 257, 260, 262, 264, 267, 269, 272, 274, 277, 279, 283, 285, 287, 289, 292, 295, 298, 301, 303, 305, 307, 309, 312, 315, 318, 321, 323, 325, 328, 330, 333, 336, 338, 340, 342, 344, 347, 351, 354, 356, 359, 362, 365, 368, 371, 373, 375, 377, 379, 382, 385, 387, 390, 392, 395, 397, 400, 403, 406, 409, 411, 413, 415, 418, 420, 422, 425, 428, 430, 432, 435, 437, 440, 443, 445, 448, 450, 452, 454, 455, 459, 462, 464, 467, 470, 473, 474, 476, 479, 482, 484, 487, 492, 495, 497, 500, 502, 504, 507, 510, 513, 514, 516, 518, 519, 521, 523, 524, 526, 529, 531, 534, 536, 539, 541, 544, 546, 548, 550, 552, 555, 557, 559, 561, 563, 566, 569, 572, 575, 578, 581, 583, 584, 587, 590), Values => " theetaofoandinse r th tinhethhhe to" & CR & LF & "ls d a" & "anerc od on ofreof t , isuat n orwhichfmasitthat" & LF & "wa" & "sen wes an i" & CR & "f gpnd snd ed wedhttp://forteingy The " & "ctir hisst inarnt, toyng hwithlealto boubewere bseo enthang th" & "eir""hifrom fin deionmev.veallre rirois cof tareea. her mer p" & "es bytheydiraicnots, d tat celah neas tioon n tiowe a om, as o" & "urlillchhadthise tg e" & CR & LF & " where coe oa us dss" & LF & CR & LF & CR & LF & CR & "="" be es amaonet tor butelsol e ss,n" & "oter waivhoe a rhats tnsch whtrut/havely ta ha ontha- latien p" & "e rethereasssi fowaecourwhoitszfors>otun<imth ncate><verad wel" & "yee nid clacil</rt widive, itwhi magexe cmen.com", Hash => Natools.Smaz.Original_Hash.Hash'Access); -- Dictionary built by filtering the S-expression below in the `smaz` tool -- The S-expression itslef comes for the original `smaz.c`, after removing -- the commas. -- (( -- )" " "the" "e" "t" "a" "of" "o" "and" "i" "n" "s" "e " "r" " th" ( -- )" t" "in" "he" "th" "h" "he " "to" "\r\n" "l" "s " "d" " a" "an" ( -- )"er" "c" " o" "d " "on" " of" "re" "of " "t " ", " "is" "u" "at" ( -- )" " "n " "or" "which" "f" "m" "as" "it" "that" "\n" "was" "en" ( -- )" " " w" "es" " an" " i" "\r" "f " "g" "p" "nd" " s" "nd " "ed " ( -- )"w" "ed" "http://" "for" "te" "ing" "y " "The" " c" "ti" "r " "his" ( -- )"st" " in" "ar" "nt" "," " to" "y" "ng" " h" "with" "le" "al" "to " ( -- )"b" "ou" "be" "were" " b" "se" "o " "ent" "ha" "ng " "their" "\"" ( -- )"hi" "from" " f" "in " "de" "ion" "me" "v" "." "ve" "all" "re " ( -- )"ri" "ro" "is " "co" "f t" "are" "ea" ". " "her" " m" "er " " p" ( -- )"es " "by" "they" "di" "ra" "ic" "not" "s, " "d t" "at " "ce" "la" ( -- )"h " "ne" "as " "tio" "on " "n t" "io" "we" " a " "om" ", a" "s o" ( -- )"ur" "li" "ll" "ch" "had" "this" "e t" "g " "e\r\n" " wh" "ere" ( -- )" co" "e o" "a " "us" " d" "ss" "\n\r\n" "\r\n\r" "=\"" " be" " e" ( -- )"s a" "ma" "one" "t t" "or " "but" "el" "so" "l " "e s" "s," "no" ( -- )"ter" " wa" "iv" "ho" "e a" " r" "hat" "s t" "ns" "ch " "wh" "tr" ( -- )"ut" "/" "have" "ly " "ta" " ha" " on" "tha" "-" " l" "ati" "en " ( -- )"pe" " re" "there" "ass" "si" " fo" "wa" "ec" "our" "who" "its" "z" ( -- )"fo" "rs" ">" "ot" "un" "<" "im" "th " "nc" "ate" "><" "ver" "ad" ( -- )" we" "ly" "ee" " n" "id" " cl" "ac" "il" "</" "rt" " wi" "div" ( -- )"e, " " it" "whi" " ma" "ge" "x" "e c" "men" ".com") end Natools.Smaz.Original;
reznikmm/matreshka
Ada
4,899
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011-2012, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ with AMF.Generic_Collections; package AMF.UML.Behaviors.Collections is pragma Preelaborate; package UML_Behavior_Collections is new AMF.Generic_Collections (UML_Behavior, UML_Behavior_Access); type Set_Of_UML_Behavior is new UML_Behavior_Collections.Set with null record; Empty_Set_Of_UML_Behavior : constant Set_Of_UML_Behavior; type Ordered_Set_Of_UML_Behavior is new UML_Behavior_Collections.Ordered_Set with null record; Empty_Ordered_Set_Of_UML_Behavior : constant Ordered_Set_Of_UML_Behavior; type Bag_Of_UML_Behavior is new UML_Behavior_Collections.Bag with null record; Empty_Bag_Of_UML_Behavior : constant Bag_Of_UML_Behavior; type Sequence_Of_UML_Behavior is new UML_Behavior_Collections.Sequence with null record; Empty_Sequence_Of_UML_Behavior : constant Sequence_Of_UML_Behavior; private Empty_Set_Of_UML_Behavior : constant Set_Of_UML_Behavior := (UML_Behavior_Collections.Set with null record); Empty_Ordered_Set_Of_UML_Behavior : constant Ordered_Set_Of_UML_Behavior := (UML_Behavior_Collections.Ordered_Set with null record); Empty_Bag_Of_UML_Behavior : constant Bag_Of_UML_Behavior := (UML_Behavior_Collections.Bag with null record); Empty_Sequence_Of_UML_Behavior : constant Sequence_Of_UML_Behavior := (UML_Behavior_Collections.Sequence with null record); end AMF.UML.Behaviors.Collections;
zhmu/ananas
Ada
5,025
adb
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- G N A T . L O C K _ F I L E S -- -- -- -- B o d y -- -- -- -- Copyright (C) 1998-2022, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ with System; package body GNAT.Lock_Files is Dir_Separator : Character; pragma Import (C, Dir_Separator, "__gnat_dir_separator"); --------------- -- Lock_File -- --------------- procedure Lock_File (Directory : Path_Name; Lock_File_Name : Path_Name; Wait : Duration := 1.0; Retries : Natural := Natural'Last) is Dir : aliased String := Directory & ASCII.NUL; File : aliased String := Lock_File_Name & ASCII.NUL; function Try_Lock (Dir, File : System.Address) return Integer; pragma Import (C, Try_Lock, "__gnat_try_lock"); begin -- If a directory separator was provided, just remove the one we have -- added above. if Directory (Directory'Last) = Dir_Separator or else Directory (Directory'Last) = '/' then Dir (Dir'Last - 1) := ASCII.NUL; end if; -- Try to lock the file Retries times for I in 0 .. Retries loop if Try_Lock (Dir'Address, File'Address) = 1 then return; end if; exit when I = Retries; delay Wait; end loop; raise Lock_Error; end Lock_File; --------------- -- Lock_File -- --------------- procedure Lock_File (Lock_File_Name : Path_Name; Wait : Duration := 1.0; Retries : Natural := Natural'Last) is begin for J in reverse Lock_File_Name'Range loop if Lock_File_Name (J) = Dir_Separator or else Lock_File_Name (J) = '/' then Lock_File (Lock_File_Name (Lock_File_Name'First .. J - 1), Lock_File_Name (J + 1 .. Lock_File_Name'Last), Wait, Retries); return; end if; end loop; Lock_File (".", Lock_File_Name, Wait, Retries); end Lock_File; ----------------- -- Unlock_File -- ----------------- procedure Unlock_File (Lock_File_Name : Path_Name) is S : aliased String := Lock_File_Name & ASCII.NUL; procedure unlink (A : System.Address); pragma Import (C, unlink, "unlink"); begin unlink (S'Address); end Unlock_File; ----------------- -- Unlock_File -- ----------------- procedure Unlock_File (Directory : Path_Name; Lock_File_Name : Path_Name) is begin if Directory (Directory'Last) = Dir_Separator or else Directory (Directory'Last) = '/' then Unlock_File (Directory & Lock_File_Name); else Unlock_File (Directory & Dir_Separator & Lock_File_Name); end if; end Unlock_File; end GNAT.Lock_Files;
stcarrez/ada-asf
Ada
4,032
ads
----------------------------------------------------------------------- -- applications-main-configs -- Configuration support for ASF Applications -- Copyright (C) 2009, 2010, 2011, 2012, 2015, 2017, 2018, 2022 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with EL.Contexts.Default; with EL.Contexts.Properties; with ASF.Contexts.Faces; with Util.Beans.Objects; with Util.Serialize.Mappers.Record_Mapper; package ASF.Applications.Main.Configs is -- Read the configuration file associated with the application. This includes: -- <ul> -- <li>The servlet and filter mappings</li> -- <li>The managed bean definitions</li> -- <li>The navigation rules</li> -- </ul> procedure Read_Configuration (App : in out Application'Class; File : in String); -- Setup the XML parser to read the managed bean definitions. -- By instantiating this package, the <b>Reader</b> gets populated with the XML mappings -- to read the servlet, managed beans and navigation rules. generic Mapper : in out Util.Serialize.Mappers.Processing; App : in ASF.Contexts.Faces.Application_Access; Context : in EL.Contexts.Default.Default_Context_Access; Override_Context : in Boolean := False; package Reader_Config is Prop_Context : aliased EL.Contexts.Properties.Property_Resolver; end Reader_Config; -- Create the configuration parameter definition instance. generic -- The parameter name. Name : in String; -- The default value. Default : in String; package Parameter is -- Returns the configuration parameter. function P return Config_Param; pragma Inline_Always (P); end Parameter; -- ------------------------------ -- Application Specific Configuration -- ------------------------------ -- Read the application specific configuration by using the XML mapper. -- The application configuration looks like: -- -- <application> -- <message-bundle>name</message-bundle> -- <message-bundle var='name'>bundle-name</message-bundle> -- </application> -- type Application_Config is limited record Name : Util.Beans.Objects.Object; App : ASF.Contexts.Faces.Application_Access; end record; type Application_Config_Access is access all Application_Config; type Application_Fields is (TAG_MESSAGE_BUNDLE, TAG_MESSAGE_VAR, TAG_DEFAULT_LOCALE, TAG_SUPPORTED_LOCALE); -- Save in the application config object the value associated with the given field. -- When the <b>TAG_MESSAGE_BUNDLE</b> field is reached, insert the new bundle definition -- in the application. procedure Set_Member (N : in out Application_Config; Field : in Application_Fields; Value : in Util.Beans.Objects.Object); private package Application_Mapper is new Util.Serialize.Mappers.Record_Mapper (Element_Type => Application_Config, Element_Type_Access => Application_Config_Access, Fields => Application_Fields, Set_Member => Set_Member); end ASF.Applications.Main.Configs;
zhmu/ananas
Ada
3,227
ads
------------------------------------------------------------------------------ -- -- -- GNAT RUN-TIME COMPONENTS -- -- -- -- S Y S T E M . P A C K _ 2 5 -- -- -- -- S p e c -- -- -- -- Copyright (C) 1992-2022, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- Handling of packed arrays with Component_Size = 25 package System.Pack_25 is pragma Preelaborate; Bits : constant := 25; type Bits_25 is mod 2 ** Bits; for Bits_25'Size use Bits; -- In all subprograms below, Rev_SSO is set True if the array has the -- non-default scalar storage order. function Get_25 (Arr : System.Address; N : Natural; Rev_SSO : Boolean) return Bits_25 with Inline; -- Arr is the address of the packed array, N is the zero-based -- subscript. This element is extracted and returned. procedure Set_25 (Arr : System.Address; N : Natural; E : Bits_25; Rev_SSO : Boolean) with Inline; -- Arr is the address of the packed array, N is the zero-based -- subscript. This element is set to the given value. end System.Pack_25;
stcarrez/ada-ado
Ada
14,922
adb
----------------------------------------------------------------------- -- ado-queries-loaders -- Loader for Database Queries -- Copyright (C) 2011- 2022 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.IO_Exceptions; with Ada.Directories; with Util.Files; with Util.Log.Loggers; with Util.Beans.Objects; with Util.Serialize.IO.XML; with Util.Serialize.Mappers.Record_Mapper; with ADO.Configs; package body ADO.Queries.Loaders is use Util.Log; use ADO.Connections; use Ada.Calendar; Log : constant Loggers.Logger := Loggers.Create ("ADO.Queries.Loaders"); Init_Time : constant Ada.Calendar.Time := Ada.Calendar.Time_Of (Year => Ada.Calendar.Year_Number'First, Month => 1, Day => 1); Infinity_Time : constant Ada.Calendar.Time := Ada.Calendar.Time_Of (Year => Ada.Calendar.Year_Number'Last, Month => 1, Day => 1); -- Check for file modification time at most every 60 seconds. FILE_CHECK_DELTA_TIME : constant Duration := 60.0; -- The list of query files defined by the application. Query_Files : Query_File_Access := null; Last_Query : Query_Index := 0; Last_File : File_Index := 0; -- Get the modification time of the XML query file associated with the query. function Modification_Time (File : in Query_File_Info) return Ada.Calendar.Time; -- Initialize the query SQL pattern with the value procedure Set_Query_Pattern (Into : in out Query_Pattern; Value : in Util.Beans.Objects.Object); -- ------------------------------ -- Register the query definition in the query file. Registration is done -- in the package elaboration phase. -- ------------------------------ procedure Register (File : in Query_File_Access; Query : in Query_Definition_Access) is begin Last_Query := Last_Query + 1; Query.File := File; Query.Next := File.Queries; Query.Query := Last_Query; File.Queries := Query; if File.Next = null and then Query_Files /= File then Last_File := Last_File + 1; File.Next := Query_Files; File.File := Last_File; Query_Files := File; end if; end Register; function Find_Driver (Name : in String) return Integer; function Find_Driver (Name : in String) return Integer is begin if Name'Length = 0 then return 0; end if; declare Driver : constant Connections.Driver_Access := Connections.Get_Driver (Name); begin if Driver = null then -- There is no problem to have an SQL query for unsupported drivers, but still -- report some warning. Log.Warn ("Database driver {0} not found", Name); return -1; end if; return Integer (Driver.Get_Driver_Index); end; end Find_Driver; -- ------------------------------ -- Get the modification time of the XML query file associated with the query. -- ------------------------------ function Modification_Time (File : in Query_File_Info) return Ada.Calendar.Time is Path : constant String := To_String (File.Path); begin return Ada.Directories.Modification_Time (Path); exception when Ada.IO_Exceptions.Name_Error => Log.Error ("XML query file '{0}' does not exist", Path); return Init_Time; end Modification_Time; -- ------------------------------ -- Returns True if the XML query file must be reloaded. -- ------------------------------ function Is_Modified (File : in out Query_File_Info) return Boolean is Now : constant Ada.Calendar.Time := Ada.Calendar.Clock; begin -- Have we passed the next check time? if File.Next_Check > Now then return False; end if; -- Next check in N seconds (60 by default). File.Next_Check := Now + FILE_CHECK_DELTA_TIME; -- See if the file was changed. declare M : constant Ada.Calendar.Time := Modification_Time (File); begin if File.Last_Modified = M then return False; end if; File.Last_Modified := M; return True; end; end Is_Modified; -- ------------------------------ -- Initialize the query SQL pattern with the value -- ------------------------------ procedure Set_Query_Pattern (Into : in out Query_Pattern; Value : in Util.Beans.Objects.Object) is begin Into.SQL := Util.Beans.Objects.To_Unbounded_String (Value); end Set_Query_Pattern; procedure Read_Query (Manager : in Query_Manager; File : in out Query_File_Info) is type Query_Info_Fields is (FIELD_CLASS_NAME, FIELD_PROPERTY_TYPE, FIELD_PROPERTY_NAME, FIELD_QUERY_NAME, FIELD_SQL_DRIVER, FIELD_SQL, FIELD_SQL_COUNT, FIELD_QUERY); -- The Query_Loader holds context and state information for loading -- the XML query file and initializing the Query_Definition. type Query_Loader is limited record Hash_Value : Unbounded_String; Query_Def : Query_Definition_Access; Query : Query_Info_Ref.Ref; Driver : Integer; end record; type Query_Loader_Access is access all Query_Loader; procedure Set_Member (Into : in out Query_Loader; Field : in Query_Info_Fields; Value : in Util.Beans.Objects.Object); -- ------------------------------ -- Called by the de-serialization when a given field is recognized. -- ------------------------------ procedure Set_Member (Into : in out Query_Loader; Field : in Query_Info_Fields; Value : in Util.Beans.Objects.Object) is begin case Field is when FIELD_CLASS_NAME => Append (Into.Hash_Value, " class="); Append (Into.Hash_Value, Util.Beans.Objects.To_Unbounded_String (Value)); when FIELD_PROPERTY_TYPE => Append (Into.Hash_Value, " type="); Append (Into.Hash_Value, Util.Beans.Objects.To_Unbounded_String (Value)); when FIELD_PROPERTY_NAME => Append (Into.Hash_Value, " name="); Append (Into.Hash_Value, Util.Beans.Objects.To_Unbounded_String (Value)); when FIELD_QUERY_NAME => Into.Query_Def := Find_Query (File, Util.Beans.Objects.To_String (Value)); Into.Driver := 0; if Into.Query_Def /= null then Into.Query := Query_Info_Ref.Create; end if; when FIELD_SQL_DRIVER => Into.Driver := Find_Driver (Util.Beans.Objects.To_String (Value)); when FIELD_SQL => if not Into.Query.Is_Null and then Into.Driver >= 0 and then Into.Query_Def /= null then Set_Query_Pattern (Into.Query.Value.Main_Query (Driver_Index (Into.Driver)), Value); end if; Into.Driver := 0; when FIELD_SQL_COUNT => if not Into.Query.Is_Null and then Into.Driver >= 0 and then Into.Query_Def /= null then Set_Query_Pattern (Into.Query.Value.Count_Query (Driver_Index (Into.Driver)), Value); end if; Into.Driver := 0; when FIELD_QUERY => if Into.Query_Def /= null then -- Now we can safely setup the query info associated with the query definition. Manager.Queries (Into.Query_Def.Query) := Into.Query; end if; Into.Query_Def := null; end case; end Set_Member; package Query_Mapper is new Util.Serialize.Mappers.Record_Mapper (Element_Type => Query_Loader, Element_Type_Access => Query_Loader_Access, Fields => Query_Info_Fields, Set_Member => Set_Member); Loader : aliased Query_Loader; Sql_Mapper : aliased Query_Mapper.Mapper; Reader : Util.Serialize.IO.XML.Parser; Mapper : Util.Serialize.Mappers.Processing; Path : constant String := To_String (File.Path); begin Log.Info ("Reading XML query {0}", Path); Loader.Driver := 0; -- Create the mapping to load the XML query file. Sql_Mapper.Add_Mapping ("class/@name", FIELD_CLASS_NAME); Sql_Mapper.Add_Mapping ("class/property/@type", FIELD_PROPERTY_TYPE); Sql_Mapper.Add_Mapping ("class/property/@name", FIELD_PROPERTY_NAME); Sql_Mapper.Add_Mapping ("query/@name", FIELD_QUERY_NAME); Sql_Mapper.Add_Mapping ("query/sql", FIELD_SQL); Sql_Mapper.Add_Mapping ("query/sql/@driver", FIELD_SQL_DRIVER); Sql_Mapper.Add_Mapping ("query/sql-count", FIELD_SQL_COUNT); Sql_Mapper.Add_Mapping ("query/sql-count/@driver", FIELD_SQL_DRIVER); Sql_Mapper.Add_Mapping ("query", FIELD_QUERY); Mapper.Add_Mapping ("query-mapping", Sql_Mapper'Unchecked_Access); -- Set the context for Set_Member. Query_Mapper.Set_Context (Mapper, Loader'Access); -- Read the XML query file. if Ada.Directories.Exists (Path) then Reader.Parse (Path, Mapper); File.Next_Check := Ada.Calendar.Clock + FILE_CHECK_DELTA_TIME; return; end if; if Manager.Loader = null then Log.Error ("XML query file '{0}' does not exist", Path); File.Next_Check := Ada.Calendar.Clock + FILE_CHECK_DELTA_TIME; return; end if; Log.Info ("Loading query {0} from static loader", File.File.Name.all); declare Content : constant access constant String := Manager.Loader (File.File.Name.all); begin if Content /= null then Reader.Parse_String (Content.all, Mapper); File.Next_Check := Infinity_Time; else Log.Error ("XML query file '{0}' does not exist", Path); File.Next_Check := Ada.Calendar.Clock + FILE_CHECK_DELTA_TIME; end if; end; end Read_Query; -- ------------------------------ -- Read the query definition. -- ------------------------------ procedure Read_Query (Manager : in Query_Manager; Into : in Query_Definition_Access) is begin if Manager.Queries (Into.Query).Is_Null or else Is_Modified (Manager.Files (Into.File.File)) then Read_Query (Manager, Manager.Files (Into.File.File)); end if; end Read_Query; -- ------------------------------ -- Initialize the queries to look in the list of directories specified by <b>Paths</b>. -- Each search directory is separated by ';' (yes, even on Unix). -- When <b>Load</b> is true, read the XML query file and initialize the query -- definitions from that file. -- ------------------------------ procedure Initialize (Manager : in out Query_Manager; Config : in ADO.Connections.Configuration'Class) is function Get_Config (Name : in String) return String; function Get_Config (Name : in String) return String is Value : constant String := Config.Get_Property (Name); begin if Value'Length > 0 then return Value; else return ADO.Configs.Get_Config (Name); end if; end Get_Config; Paths : constant String := Get_Config (Configs.QUERY_PATHS_CONFIG); Load : constant Boolean := Get_Config (Configs.QUERY_LOAD_CONFIG) = "true"; File : Query_File_Access := Query_Files; begin Log.Info ("Initializing query search paths to {0}", Paths); if Manager.Queries = null then Manager.Queries := new Query_Table (1 .. Last_Query); end if; if Manager.Files = null then Manager.Files := new File_Table (1 .. Last_File); end if; Manager.Driver := Config.Get_Driver; while File /= null loop declare Path : constant String := Util.Files.Find_File_Path (Name => File.Name.all, Paths => Paths); begin Manager.Files (File.File).File := File; Manager.Files (File.File).Last_Modified := Init_Time; Manager.Files (File.File).Next_Check := Init_Time; Manager.Files (File.File).Path := To_Unbounded_String (Path); if Load then Read_Query (Manager, Manager.Files (File.File)); end if; end; File := File.Next; end loop; end Initialize; -- ------------------------------ -- Find the query identified by the given name. -- ------------------------------ function Find_Query (Name : in String) return Query_Definition_Access is File : Query_File_Access := Query_Files; begin while File /= null loop declare Query : Query_Definition_Access := File.Queries; begin while Query /= null loop if Query.Name.all = Name then return Query; end if; Query := Query.Next; end loop; end; File := File.Next; end loop; Log.Warn ("Query {0} not found", Name); return null; end Find_Query; package body File is begin File.Name := Name'Access; File.Sha1_Map := Hash'Access; end File; package body Query is begin Query.Name := Query_Name'Access; Query.File := File; Register (File => File, Query => Query'Access); end Query; end ADO.Queries.Loaders;
Gabriel-Degret/adalib
Ada
879
ads
-- Standard Ada library specification -- Copyright (c) 2003-2018 Maxim Reznik <[email protected]> -- Copyright (c) 2004-2016 AXE Consultants -- Copyright (c) 2004, 2005, 2006 Ada-Europe -- Copyright (c) 2000 The MITRE Corporation, Inc. -- Copyright (c) 1992, 1993, 1994, 1995 Intermetrics, Inc. -- SPDX-License-Identifier: BSD-3-Clause and LicenseRef-AdaReferenceManual --------------------------------------------------------------------------- generic type Index_Type is (<>); type Element_Type is private; type Array_Type is array (Index_Type) of Element_Type; with function "<" (Left : in Element_Type; Right : in Element_Type) return Boolean is <>; procedure Ada.Containers.Generic_Constrained_Array_Sort (Container : in out Array_Type); pragma Pure (Ada.Containers.Generic_Constrained_Array_Sort);
reznikmm/matreshka
Ada
3,669
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Elements; package ODF.DOM.Text_File_Name_Elements is pragma Preelaborate; type ODF_Text_File_Name is limited interface and XML.DOM.Elements.DOM_Element; type ODF_Text_File_Name_Access is access all ODF_Text_File_Name'Class with Storage_Size => 0; end ODF.DOM.Text_File_Name_Elements;
reznikmm/matreshka
Ada
4,155
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Localization, Internationalization, Globalization for Ada -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2012-2015, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ pragma Restrictions (No_Elaboration_Code); -- GNAT: enforce generation of preinitialized data section instead of -- generation of elaboration code. package Matreshka.Internals.Unicode.Ucd.Core_01F7 is pragma Preelaborate; Group_01F7 : aliased constant Core_Second_Stage := (16#74# .. 16#7F# => -- 01F774 .. 01F77F (Unassigned, Neutral, Other, Other, Other, Unknown, (others => False)), 16#D5# .. 16#FF# => -- 01F7D5 .. 01F7FF (Unassigned, Neutral, Other, Other, Other, Unknown, (others => False)), others => (Other_Symbol, Neutral, Other, Other, Other, Alphabetic, (Grapheme_Base => True, others => False))); end Matreshka.Internals.Unicode.Ucd.Core_01F7;
reznikmm/matreshka
Ada
3,624
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2012, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ with AMF.Elements.Generic_Hash; function AMF.DG.Graphical_Elements.Hash is new AMF.Elements.Generic_Hash (DG_Graphical_Element, DG_Graphical_Element_Access);
osannolik/ada-canopen
Ada
3,656
ads
with ACO.Messages; with ACO.OD_Types; with ACO.Configuration; private with ACO.Utils.DS.Generic_Queue; package ACO.SDO_Sessions is type Session_Manager is tagged limited private; type Services is (None, Download, Upload, Block_Download, Block_Upload); subtype Endpoint_Nr is Integer range -1 .. Integer'Last; No_Endpoint_Id : constant Endpoint_Nr := Endpoint_Nr'First; subtype Valid_Endpoint_Nr is Endpoint_Nr range No_Endpoint_Id + 1 .. ACO.Configuration.Max_Nof_Simultaneous_SDO_Sessions; type SDO_Parameters is record CAN_Id_C2S : ACO.Messages.Id_Type := 0; CAN_Id_S2C : ACO.Messages.Id_Type := 0; Node : ACO.Messages.Node_Nr := ACO.Messages.Not_A_Slave; end record; No_SDO_Parameters : constant SDO_Parameters := (CAN_Id_C2S => 0, CAN_Id_S2C => 0, Node => ACO.Messages.Not_A_Slave); type SDO_Parameter_Array is array (Natural range <>) of SDO_Parameters; type Endpoint_Type is record Id : Endpoint_Nr := No_Endpoint_Id; Parameters : SDO_Parameters; end record; No_Endpoint : constant Endpoint_Type := (Id => No_Endpoint_Id, Parameters => No_SDO_Parameters); function Image (Endpoint : Endpoint_Type) return String; type SDO_Status is (Pending, Complete, Error); Is_Complete : constant array (SDO_Status) of Boolean := (Pending | Error => False, Complete => True); subtype SDO_Result is SDO_Status range Complete .. Error; type SDO_Session (Service : Services := None) is record Endpoint : Endpoint_Type := No_Endpoint; Index : ACO.OD_Types.Entry_Index := (0, 0); Toggle : Boolean := False; end record; function Create_Download (Endpoint : Endpoint_Type; Index : ACO.OD_Types.Entry_Index) return SDO_Session; function Create_Upload (Endpoint : Endpoint_Type; Index : ACO.OD_Types.Entry_Index) return SDO_Session; function Get (This : Session_Manager; Id : Valid_Endpoint_Nr) return SDO_Session; procedure Put (This : in out Session_Manager; Session : in SDO_Session); function Service (This : Session_Manager; Id : Valid_Endpoint_Nr) return Services; procedure Clear (This : in out Session_Manager; Id : in Valid_Endpoint_Nr); procedure Clear_Buffer (This : in out Session_Manager; Id : in Valid_Endpoint_Nr); procedure Put_Buffer (This : in out Session_Manager; Id : in Valid_Endpoint_Nr; Data : in ACO.Messages.Data_Array); function Length_Buffer (This : Session_Manager; Id : Valid_Endpoint_Nr) return Natural; procedure Get_Buffer (This : in out Session_Manager; Id : in Valid_Endpoint_Nr; Data : out ACO.Messages.Data_Array) with Pre => Data'Length <= This.Length_Buffer (Id); function Peek_Buffer (This : Session_Manager; Id : Valid_Endpoint_Nr) return ACO.Messages.Data_Array; private package Q is new ACO.Utils.DS.Generic_Queue (Item_Type => ACO.Messages.Data_Type); type Session_Array is array (Endpoint_Nr range <>) of SDO_Session; type Buffer_Array is array (Endpoint_Nr range <>) of Q.Queue (Max_Nof_Items => ACO.Configuration.Max_SDO_Transfer_Size); type Session_Manager is tagged limited record List : Session_Array (Valid_Endpoint_Nr'Range); Buffers : Buffer_Array (Valid_Endpoint_Nr'Range); end record; end ACO.SDO_Sessions;
Fabien-Chouteau/Ada_Drivers_Library
Ada
3,570
ads
------------------------------------------------------------------------------ -- -- -- Copyright (C) 2015-2016, AdaCore -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions are -- -- met: -- -- 1. Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- 2. Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in -- -- the documentation and/or other materials provided with the -- -- distribution. -- -- 3. Neither the name of the copyright holder nor the names of its -- -- contributors may be used to endorse or promote products derived -- -- from this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -- -- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -- -- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -- -- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -- -- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ with STM32; use STM32; with STM32.GPIO; use STM32.GPIO; with STM32.USARTs; use STM32.USARTs; package Serial_IO is type Peripheral_Descriptor is record Transceiver : not null access USART; Transceiver_AF : GPIO_Alternate_Function; Tx_Pin : GPIO_Point; Rx_Pin : GPIO_Point; end record; procedure Initialize_Peripheral (Device : access Peripheral_Descriptor); procedure Configure (Device : access Peripheral_Descriptor; Baud_Rate : Baud_Rates; Parity : Parities := No_Parity; Data_Bits : Word_Lengths := Word_Length_8; End_Bits : Stop_Bits := Stopbits_1; Control : Flow_Control := No_Flow_Control); type Error_Conditions is mod 256; No_Error_Detected : constant Error_Conditions := 2#0000_0000#; Parity_Error_Detected : constant Error_Conditions := 2#0000_0001#; Noise_Error_Detected : constant Error_Conditions := 2#0000_0010#; Frame_Error_Detected : constant Error_Conditions := 2#0000_0100#; Overrun_Error_Detected : constant Error_Conditions := 2#0000_1000#; DMA_Error_Detected : constant Error_Conditions := 2#0001_0000#; end Serial_IO;
mitchelhaan/ncurses
Ada
11,259
adb
------------------------------------------------------------------------------ -- -- -- GNAT ncurses Binding -- -- -- -- Terminal_Interface.Curses.Forms.Field_Types -- -- -- -- B O D Y -- -- -- ------------------------------------------------------------------------------ -- Copyright (c) 1998 Free Software Foundation, Inc. -- -- -- -- Permission is hereby granted, free of charge, to any person obtaining a -- -- copy of this software and associated documentation files (the -- -- "Software"), to deal in the Software without restriction, including -- -- without limitation the rights to use, copy, modify, merge, publish, -- -- distribute, distribute with modifications, sublicense, and/or sell -- -- copies of the Software, and to permit persons to whom the Software is -- -- furnished to do so, subject to the following conditions: -- -- -- -- The above copyright notice and this permission notice shall be included -- -- in all copies or substantial portions of the Software. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -- -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -- -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -- -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR -- -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. -- -- -- -- Except as contained in this notice, the name(s) of the above copyright -- -- holders shall not be used in advertising or otherwise to promote the -- -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------ -- Author: Juergen Pfeifer <[email protected]> 1996 -- Version Control: -- $Revision: 1.8 $ -- Binding Version 00.93 ------------------------------------------------------------------------------ with Interfaces.C; with Terminal_Interface.Curses.Aux; use Terminal_Interface.Curses.Aux; with Ada.Unchecked_Deallocation; with Ada.Unchecked_Conversion; with Terminal_Interface.Curses.Forms.Field_Types.User; with Terminal_Interface.Curses.Forms.Field_Types.User.Choice; -- | -- |===================================================================== -- | man page form_fieldtype.3x -- |===================================================================== -- | package body Terminal_Interface.Curses.Forms.Field_Types is use type Interfaces.C.int; use type System.Address; function To_Argument_Access is new Ada.Unchecked_Conversion (System.Address, Argument_Access); function Get_Fieldtype (F : Field) return C_Field_Type; pragma Import (C, Get_Fieldtype, "field_type"); function Get_Arg (F : Field) return System.Address; pragma Import (C, Get_Arg, "field_arg"); -- | -- |===================================================================== -- | man page form_field_validation.3x -- |===================================================================== -- | -- | -- | function Get_Type (Fld : in Field) return Field_Type_Access is Low_Level : constant C_Field_Type := Get_Fieldtype (Fld); Arg : Argument_Access; begin if Low_Level = Null_Field_Type then return null; else if Low_Level = M_Builtin_Router or else Low_Level = M_Generic_Type or else Low_Level = M_Choice_Router or else Low_Level = M_Generic_Choice then Arg := To_Argument_Access (Get_Arg (Fld)); if Arg = null then raise Form_Exception; else return Arg.Typ; end if; else raise Form_Exception; end if; end if; end Get_Type; function Make_Arg (Args : System.Address) return System.Address is function Getarg (Arg : System.Address := Args) return System.Address; pragma Import (C, Getarg, "_nc_ada_getvarg"); begin return Getarg; end Make_Arg; function Copy_Arg (Usr : System.Address) return System.Address is begin return Usr; end Copy_Arg; procedure Free_Arg (Usr : in System.Address) is procedure Free_Type is new Ada.Unchecked_Deallocation (Field_Type'Class, Field_Type_Access); procedure Freeargs is new Ada.Unchecked_Deallocation (Argument, Argument_Access); To_Be_Free : Argument_Access := To_Argument_Access (Usr); Low_Level : C_Field_Type; begin if To_Be_Free /= null then if To_Be_Free.Usr /= System.Null_Address then Low_Level := To_Be_Free.Cft; if Low_Level.Freearg /= null then Low_Level.Freearg (To_Be_Free.Usr); end if; end if; if To_Be_Free.Typ /= null then Free_Type (To_Be_Free.Typ); end if; Freeargs (To_Be_Free); end if; end Free_Arg; procedure Wrap_Builtin (Fld : Field; Typ : Field_Type'Class; Cft : C_Field_Type := C_Builtin_Router) is Usr_Arg : System.Address := Get_Arg (Fld); Low_Level : constant C_Field_Type := Get_Fieldtype (Fld); Arg : Argument_Access; Res : Eti_Error; function Set_Fld_Type (F : Field := Fld; Cf : C_Field_Type := Cft; Arg1 : Argument_Access) return C_Int; pragma Import (C, Set_Fld_Type, "set_field_type"); begin pragma Assert (Low_Level /= Null_Field_Type); if Cft /= C_Builtin_Router and then Cft /= C_Choice_Router then raise Form_Exception; else Arg := new Argument'(Usr => System.Null_Address, Typ => new Field_Type'Class'(Typ), Cft => Get_Fieldtype (Fld)); if Usr_Arg /= System.Null_Address then if Low_Level.Copyarg /= null then Arg.Usr := Low_Level.Copyarg (Usr_Arg); else Arg.Usr := Usr_Arg; end if; end if; Res := Set_Fld_Type (Arg1 => Arg); if Res /= E_Ok then Eti_Exception (Res); end if; end if; end Wrap_Builtin; function Field_Check_Router (Fld : Field; Usr : System.Address) return C_Int is Arg : constant Argument_Access := To_Argument_Access (Usr); begin pragma Assert (Arg /= null and then Arg.Cft /= Null_Field_Type and then Arg.Typ /= null); if Arg.Cft.Fcheck /= null then return Arg.Cft.Fcheck (Fld, Arg.Usr); else return 1; end if; end Field_Check_Router; function Char_Check_Router (Ch : C_Int; Usr : System.Address) return C_Int is Arg : constant Argument_Access := To_Argument_Access (Usr); begin pragma Assert (Arg /= null and then Arg.Cft /= Null_Field_Type and then Arg.Typ /= null); if Arg.Cft.Ccheck /= null then return Arg.Cft.Ccheck (Ch, Arg.Usr); else return 1; end if; end Char_Check_Router; function Next_Router (Fld : Field; Usr : System.Address) return C_Int is Arg : constant Argument_Access := To_Argument_Access (Usr); begin pragma Assert (Arg /= null and then Arg.Cft /= Null_Field_Type and then Arg.Typ /= null); if Arg.Cft.Next /= null then return Arg.Cft.Next (Fld, Arg.Usr); else return 1; end if; end Next_Router; function Prev_Router (Fld : Field; Usr : System.Address) return C_Int is Arg : constant Argument_Access := To_Argument_Access (Usr); begin pragma Assert (Arg /= null and then Arg.Cft /= Null_Field_Type and then Arg.Typ /= null); if Arg.Cft.Prev /= null then return Arg.Cft.Prev (Fld, Arg.Usr); else return 1; end if; end Prev_Router; -- ----------------------------------------------------------------------- -- function C_Builtin_Router return C_Field_Type is Res : Eti_Error; T : C_Field_Type; begin if M_Builtin_Router = Null_Field_Type then T := New_Fieldtype (Field_Check_Router'Access, Char_Check_Router'Access); if T = Null_Field_Type then raise Form_Exception; else Res := Set_Fieldtype_Arg (T, Make_Arg'Access, Copy_Arg'Access, Free_Arg'Access); if Res /= E_Ok then Eti_Exception (Res); end if; end if; M_Builtin_Router := T; end if; pragma Assert (M_Builtin_Router /= Null_Field_Type); return M_Builtin_Router; end C_Builtin_Router; -- ----------------------------------------------------------------------- -- function C_Choice_Router return C_Field_Type is Res : Eti_Error; T : C_Field_Type; begin if M_Choice_Router = Null_Field_Type then T := New_Fieldtype (Field_Check_Router'Access, Char_Check_Router'Access); if T = Null_Field_Type then raise Form_Exception; else Res := Set_Fieldtype_Arg (T, Make_Arg'Access, Copy_Arg'Access, Free_Arg'Access); if Res /= E_Ok then Eti_Exception (Res); end if; Res := Set_Fieldtype_Choice (T, Next_Router'Access, Prev_Router'Access); if Res /= E_Ok then Eti_Exception (Res); end if; end if; M_Choice_Router := T; end if; pragma Assert (M_Choice_Router /= Null_Field_Type); return M_Choice_Router; end C_Choice_Router; end Terminal_Interface.Curses.Forms.Field_Types;
skill-lang/adaCommon
Ada
1,183
ads
-- ___ _ ___ _ _ -- -- / __| |/ (_) | | Common SKilL implementation -- -- \__ \ ' <| | | |__ iterator over types -- -- |___/_|\_\_|_|____| by: Timm Felden -- -- -- pragma Ada_2012; with Skill.Types.Pools; package Skill.Iterators.Type_Hierarchy_Iterator is use type Skill.Types.Pools.Pool; type Iterator is tagged record Current : Skill.Types.Pools.Pool; End_Height : Natural; end record; procedure Init (This : access Iterator'Class; First : Skill.Types.Pools.Pool := null); function Element (This : access Iterator'Class) return Skill.Types.Pools.Pool is (This.Current); function Has_Next (This : access Iterator'Class) return Boolean is (null /= This.Current); procedure Next (This : access Iterator'Class); function Next (This : access Iterator'Class) return Skill.Types.Pools.Pool; end Skill.Iterators.Type_Hierarchy_Iterator;
reznikmm/matreshka
Ada
4,672
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Style.Leader_Text_Style_Attributes is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Style_Leader_Text_Style_Attribute_Node is begin return Self : Style_Leader_Text_Style_Attribute_Node do Matreshka.ODF_Style.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Style_Prefix); end return; end Create; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Style_Leader_Text_Style_Attribute_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Leader_Text_Style_Attribute; end Get_Local_Name; begin Matreshka.DOM_Documents.Register_Attribute (Matreshka.ODF_String_Constants.Style_URI, Matreshka.ODF_String_Constants.Leader_Text_Style_Attribute, Style_Leader_Text_Style_Attribute_Node'Tag); end Matreshka.ODF_Style.Leader_Text_Style_Attributes;
stcarrez/ada-css
Ada
3,699
ads
----------------------------------------------------------------------- -- css-comments -- CSS comments recording -- Copyright (C) 2017 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- private with Ada.Finalization; -- == CSS Comments == -- The CSS comments can be recorded during the parsing of CSS content. -- When a comment is recorded, a comment reference represented by the -- <tt>Comment_Type</tt> type is returned. The CSS comment can be a multi-line -- comment and the package provides several operations to either retrieve -- the full comment or a specific line. package CSS.Comments is type Comment_Type is private; NULL_COMMENT : constant Comment_Type; -- Get the line number where the comment was written. function Get_Line_Number (Comment : in Comment_Type) return Natural; -- Get the number of lines that the comment span. function Get_Line_Count (Comment : in Comment_Type) return Natural; -- Get the full or stripped comment text. function Get_Text (Comment : in Comment_Type; Strip : in Boolean := False) return String; -- Get the given line of the comment text. function Get_Text (Comment : in Comment_Type; Line : in Positive; Strip : in Boolean := False) return String; -- Definition of the list of comments found in the CSS document. type CSSComment_List is tagged limited private; -- Insert in the comment list the comment described by <tt>Text</tt> -- and associated with source line number <tt>Line</tt>. After insertion -- the comment reference is returned to identify the new comment. procedure Insert (List : in out CSSComment_List; Text : in String; Line : in Natural; Index : out Comment_Type); private type Comment; type Const_Comment_Access is access constant Comment; type Comment_Access is access all Comment; type Line_Info is record Start : Natural := 0; Finish : Natural := 0; end record; type Line_Info_Array is array (Natural range <>) of Line_Info; type Comment (Len : Natural; Line_Count : Natural) is limited record Next : Comment_Access; Line : Natural := 0; Text : String (1 .. Len); Lines : Line_Info_Array (1 .. Line_Count); end record; type CSSComment_List is limited new Ada.Finalization.Limited_Controlled with record Chain : Comment_Access; end record; -- Release the memory used by the comment list. overriding procedure Finalize (List : in out CSSComment_List); EMPTY_COMMENT : aliased constant Comment := Comment '(Len => 0, Line_Count => 0, Next => null, Text => "", Line => 0, others => <>); type Comment_Type is record Object : Const_Comment_Access := EMPTY_COMMENT'Access; end record; NULL_COMMENT : constant Comment_Type := Comment_Type '(Object => EMPTY_COMMENT'Access); end CSS.Comments;
reznikmm/matreshka
Ada
3,961
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with ODF.DOM.Draw_Color_Attributes; package Matreshka.ODF_Draw.Color_Attributes is type Draw_Color_Attribute_Node is new Matreshka.ODF_Draw.Abstract_Draw_Attribute_Node and ODF.DOM.Draw_Color_Attributes.ODF_Draw_Color_Attribute with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Draw_Color_Attribute_Node; overriding function Get_Local_Name (Self : not null access constant Draw_Color_Attribute_Node) return League.Strings.Universal_String; end Matreshka.ODF_Draw.Color_Attributes;
reznikmm/matreshka
Ada
23,167
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2011-2012, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with AMF.Internals.Tables.CMOF_Attributes; with AMF.Internals.Element_Collections; with AMF.Internals.Helpers; with AMF.Visitors.CMOF_Iterators; with AMF.Visitors.CMOF_Visitors; package body AMF.Internals.CMOF_Operations is use AMF.Internals.Tables.CMOF_Attributes; ------------------- -- Enter_Element -- ------------------- overriding procedure Enter_Element (Self : not null access constant CMOF_Operation_Proxy; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Control : in out AMF.Visitors.Traverse_Control) is begin if Visitor in AMF.Visitors.CMOF_Visitors.CMOF_Visitor'Class then AMF.Visitors.CMOF_Visitors.CMOF_Visitor'Class (Visitor).Enter_Operation (AMF.CMOF.Operations.CMOF_Operation_Access (Self), Control); end if; end Enter_Element; ------------------------ -- Get_Body_Condition -- ------------------------ overriding function Get_Body_Condition (Self : not null access constant CMOF_Operation_Proxy) return AMF.CMOF.Constraints.CMOF_Constraint_Access is begin return AMF.CMOF.Constraints.CMOF_Constraint_Access (AMF.Internals.Helpers.To_Element (Internal_Get_Body_Condition (Self.Element))); end Get_Body_Condition; --------------- -- Get_Class -- --------------- overriding function Get_Class (Self : not null access constant CMOF_Operation_Proxy) return AMF.CMOF.Classes.CMOF_Class_Access is begin return AMF.CMOF.Classes.CMOF_Class_Access (AMF.Internals.Helpers.To_Element (Internal_Get_Class (Self.Element))); end Get_Class; ------------------ -- Get_Datatype -- ------------------ overriding function Get_Datatype (Self : not null access constant CMOF_Operation_Proxy) return AMF.CMOF.Data_Types.CMOF_Data_Type_Access is begin return AMF.CMOF.Data_Types.CMOF_Data_Type_Access (AMF.Internals.Helpers.To_Element (Internal_Get_Datatype (Self.Element))); end Get_Datatype; ------------------ -- Get_Is_Query -- ------------------ overriding function Get_Is_Query (Self : not null access constant CMOF_Operation_Proxy) return Boolean is begin return Internal_Get_Is_Query (Self.Element); end Get_Is_Query; ------------------------- -- Get_Owned_Parameter -- ------------------------- overriding function Get_Owned_Parameter (Self : not null access constant CMOF_Operation_Proxy) return AMF.CMOF.Parameters.Collections.Ordered_Set_Of_CMOF_Parameter is begin -- XXX This subprogram overrides Get_Owned_Parameter from -- Behavioral_Feature. It ca be reasonable to move it to corresponding -- package, but Behavioral_Feat is not used as superclass for other -- classes of MOF. return AMF.CMOF.Parameters.Collections.Wrap (AMF.Internals.Element_Collections.Wrap (Internal_Get_Owned_Parameter (Self.Element))); end Get_Owned_Parameter; ----------------------- -- Get_Postcondition -- ----------------------- overriding function Get_Postcondition (Self : not null access constant CMOF_Operation_Proxy) return AMF.CMOF.Constraints.Collections.Set_Of_CMOF_Constraint is begin return AMF.CMOF.Constraints.Collections.Wrap (AMF.Internals.Element_Collections.Wrap (Internal_Get_Postcondition (Self.Element))); end Get_Postcondition; ---------------------- -- Get_Precondition -- ---------------------- overriding function Get_Precondition (Self : not null access constant CMOF_Operation_Proxy) return AMF.CMOF.Constraints.Collections.Set_Of_CMOF_Constraint is begin return AMF.CMOF.Constraints.Collections.Wrap (AMF.Internals.Element_Collections.Wrap (Internal_Get_Precondition (Self.Element))); end Get_Precondition; -------------------------- -- Get_Raised_Exception -- -------------------------- overriding function Get_Raised_Exception (Self : not null access constant CMOF_Operation_Proxy) return AMF.CMOF.Types.Collections.Set_Of_CMOF_Type is begin return AMF.CMOF.Types.Collections.Wrap (AMF.Internals.Element_Collections.Wrap (Internal_Get_Raised_Exception (Self.Element))); end Get_Raised_Exception; ----------------------------- -- Get_Redefined_Operation -- ----------------------------- overriding function Get_Redefined_Operation (Self : not null access constant CMOF_Operation_Proxy) return AMF.CMOF.Operations.Collections.Set_Of_CMOF_Operation is begin return AMF.CMOF.Operations.Collections.Wrap (AMF.Internals.Element_Collections.Wrap (Internal_Get_Redefined_Operation (Self.Element))); end Get_Redefined_Operation; -------------- -- Get_Type -- -------------- overriding function Get_Type (Self : not null access constant CMOF_Operation_Proxy) return AMF.CMOF.Types.CMOF_Type_Access is begin return AMF.CMOF.Types.CMOF_Type_Access (AMF.Internals.Helpers.To_Element (Internal_Get_Type (Self.Element))); end Get_Type; ------------------- -- Leave_Element -- ------------------- overriding procedure Leave_Element (Self : not null access constant CMOF_Operation_Proxy; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Control : in out AMF.Visitors.Traverse_Control) is begin if Visitor in AMF.Visitors.CMOF_Visitors.CMOF_Visitor'Class then AMF.Visitors.CMOF_Visitors.CMOF_Visitor'Class (Visitor).Leave_Operation (AMF.CMOF.Operations.CMOF_Operation_Access (Self), Control); end if; end Leave_Element; ------------------ -- Set_Is_Query -- ------------------ overriding procedure Set_Is_Query (Self : not null access CMOF_Operation_Proxy; To : Boolean) is begin Internal_Set_Is_Query (Self.Element, To); end Set_Is_Query; ------------------- -- Visit_Element -- ------------------- overriding procedure Visit_Element (Self : not null access constant CMOF_Operation_Proxy; Iterator : in out AMF.Visitors.Abstract_Iterator'Class; Visitor : in out AMF.Visitors.Abstract_Visitor'Class; Control : in out AMF.Visitors.Traverse_Control) is begin if Iterator in AMF.Visitors.CMOF_Iterators.CMOF_Iterator'Class then AMF.Visitors.CMOF_Iterators.CMOF_Iterator'Class (Iterator).Visit_Operation (Visitor, AMF.CMOF.Operations.CMOF_Operation_Access (Self), Control); end if; end Visit_Element; ------------------------ -- All_Owned_Elements -- ------------------------ overriding function All_Owned_Elements (Self : not null access constant CMOF_Operation_Proxy) return AMF.CMOF.Elements.Collections.Set_Of_CMOF_Element is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "All_Owned_Elements unimplemented"); raise Program_Error; return All_Owned_Elements (Self); end All_Owned_Elements; ------------------------ -- Get_Qualified_Name -- ------------------------ overriding function Get_Qualified_Name (Self : not null access constant CMOF_Operation_Proxy) return Optional_String is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Get_Qualified_Name unimplemented"); raise Program_Error; return Get_Qualified_Name (Self); end Get_Qualified_Name; ----------------------------- -- Is_Distinguishable_From -- ----------------------------- overriding function Is_Distinguishable_From (Self : not null access constant CMOF_Operation_Proxy; N : AMF.CMOF.Named_Elements.CMOF_Named_Element_Access; Ns : AMF.CMOF.Namespaces.CMOF_Namespace_Access) return Boolean is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Is_Distinguishable_From unimplemented"); raise Program_Error; return Is_Distinguishable_From (Self, N, Ns); end Is_Distinguishable_From; --------------------- -- Imported_Member -- --------------------- overriding function Imported_Member (Self : not null access constant CMOF_Operation_Proxy) return AMF.CMOF.Packageable_Elements.Collections.Set_Of_CMOF_Packageable_Element is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Imported_Member unimplemented"); raise Program_Error; return Imported_Member (Self); end Imported_Member; ------------------------- -- Get_Names_Of_Member -- ------------------------- overriding function Get_Names_Of_Member (Self : not null access constant CMOF_Operation_Proxy; Element : AMF.CMOF.Named_Elements.CMOF_Named_Element_Access) return AMF.String_Collections.Set_Of_String is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Get_Names_Of_Member unimplemented"); raise Program_Error; return Get_Names_Of_Member (Self, Element); end Get_Names_Of_Member; -------------------- -- Import_Members -- -------------------- overriding function Import_Members (Self : not null access constant CMOF_Operation_Proxy; Imps : AMF.CMOF.Packageable_Elements.Collections.Set_Of_CMOF_Packageable_Element) return AMF.CMOF.Packageable_Elements.Collections.Set_Of_CMOF_Packageable_Element is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Import_Members unimplemented"); raise Program_Error; return Import_Members (Self, Imps); end Import_Members; ------------------------ -- Exclude_Collisions -- ------------------------ overriding function Exclude_Collisions (Self : not null access constant CMOF_Operation_Proxy; Imps : AMF.CMOF.Packageable_Elements.Collections.Set_Of_CMOF_Packageable_Element) return AMF.CMOF.Packageable_Elements.Collections.Set_Of_CMOF_Packageable_Element is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Exclude_Collisions unimplemented"); raise Program_Error; return Exclude_Collisions (Self, Imps); end Exclude_Collisions; --------------------------------- -- Members_Are_Distinguishable -- --------------------------------- overriding function Members_Are_Distinguishable (Self : not null access constant CMOF_Operation_Proxy) return Boolean is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Members_Are_Distinguishable unimplemented"); raise Program_Error; return Members_Are_Distinguishable (Self); end Members_Are_Distinguishable; ----------------- -- Set_Is_Leaf -- ----------------- overriding procedure Set_Is_Leaf (Self : not null access CMOF_Operation_Proxy; To : Boolean) is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Set_Is_Leaf unimplemented"); raise Program_Error; end Set_Is_Leaf; ----------------------------------- -- Is_Redefinition_Context_Valid -- ----------------------------------- overriding function Is_Redefinition_Context_Valid (Self : not null access constant CMOF_Operation_Proxy; Redefined : AMF.CMOF.Redefinable_Elements.CMOF_Redefinable_Element_Access) return Boolean is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Is_Redefinition_Context_Valid unimplemented"); raise Program_Error; return Is_Redefinition_Context_Valid (Self, Redefined); end Is_Redefinition_Context_Valid; -------------------- -- Get_Is_Ordered -- -------------------- overriding function Get_Is_Ordered (Self : not null access constant CMOF_Operation_Proxy) return Boolean is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Get_Is_Ordered unimplemented"); raise Program_Error; return Get_Is_Ordered (Self); end Get_Is_Ordered; -------------------- -- Set_Is_Ordered -- -------------------- overriding procedure Set_Is_Ordered (Self : not null access CMOF_Operation_Proxy; To : Boolean) is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Set_Is_Ordered unimplemented"); raise Program_Error; end Set_Is_Ordered; ------------------- -- Get_Is_Unique -- ------------------- overriding function Get_Is_Unique (Self : not null access constant CMOF_Operation_Proxy) return Boolean is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Get_Is_Unique unimplemented"); raise Program_Error; return Get_Is_Unique (Self); end Get_Is_Unique; ------------------- -- Set_Is_Unique -- ------------------- overriding procedure Set_Is_Unique (Self : not null access CMOF_Operation_Proxy; To : Boolean) is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Set_Is_Unique unimplemented"); raise Program_Error; end Set_Is_Unique; --------------- -- Get_Lower -- --------------- overriding function Get_Lower (Self : not null access constant CMOF_Operation_Proxy) return Optional_Integer is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Get_Lower unimplemented"); raise Program_Error; return Get_Lower (Self); end Get_Lower; --------------- -- Set_Lower -- --------------- overriding procedure Set_Lower (Self : not null access CMOF_Operation_Proxy; To : Optional_Integer) is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Set_Lower unimplemented"); raise Program_Error; end Set_Lower; --------------- -- Get_Upper -- --------------- overriding function Get_Upper (Self : not null access constant CMOF_Operation_Proxy) return Optional_Unlimited_Natural is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Get_Upper unimplemented"); raise Program_Error; return Get_Upper (Self); end Get_Upper; --------------- -- Set_Upper -- --------------- overriding procedure Set_Upper (Self : not null access CMOF_Operation_Proxy; To : Optional_Unlimited_Natural) is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Set_Upper unimplemented"); raise Program_Error; end Set_Upper; --------------- -- Set_Class -- --------------- overriding procedure Set_Class (Self : not null access CMOF_Operation_Proxy; To : AMF.CMOF.Classes.CMOF_Class_Access) is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Set_Class unimplemented"); raise Program_Error; end Set_Class; ------------------ -- Set_Datatype -- ------------------ overriding procedure Set_Datatype (Self : not null access CMOF_Operation_Proxy; To : AMF.CMOF.Data_Types.CMOF_Data_Type_Access) is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Set_Datatype unimplemented"); raise Program_Error; end Set_Datatype; -------------- -- Set_Type -- -------------- overriding procedure Set_Type (Self : not null access CMOF_Operation_Proxy; To : AMF.CMOF.Types.CMOF_Type_Access) is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Set_Type unimplemented"); raise Program_Error; end Set_Type; ------------------------ -- Set_Body_Condition -- ------------------------ overriding procedure Set_Body_Condition (Self : not null access CMOF_Operation_Proxy; To : AMF.CMOF.Constraints.CMOF_Constraint_Access) is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Set_Body_Condition unimplemented"); raise Program_Error; end Set_Body_Condition; ---------------- -- Is_Ordered -- ---------------- overriding function Is_Ordered (Self : not null access constant CMOF_Operation_Proxy) return Boolean is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Is_Ordered unimplemented"); raise Program_Error; return Is_Ordered (Self); end Is_Ordered; --------------- -- Is_Unique -- --------------- overriding function Is_Unique (Self : not null access constant CMOF_Operation_Proxy) return Boolean is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Is_Unique unimplemented"); raise Program_Error; return Is_Unique (Self); end Is_Unique; ----------- -- Lower -- ----------- overriding function Lower (Self : not null access constant CMOF_Operation_Proxy) return Integer is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Lower unimplemented"); raise Program_Error; return Lower (Self); end Lower; ----------- -- Upper -- ----------- overriding function Upper (Self : not null access constant CMOF_Operation_Proxy) return Unlimited_Natural is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Upper unimplemented"); raise Program_Error; return Upper (Self); end Upper; ------------------------ -- Is_Consistent_With -- ------------------------ overriding function Is_Consistent_With (Self : not null access constant CMOF_Operation_Proxy; Redefinee : AMF.CMOF.Redefinable_Elements.CMOF_Redefinable_Element_Access) return Boolean is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Is_Consistent_With unimplemented"); raise Program_Error; return Is_Consistent_With (Self, Redefinee); end Is_Consistent_With; ------------------- -- Return_Result -- ------------------- overriding function Return_Result (Self : not null access constant CMOF_Operation_Proxy) return AMF.CMOF.Parameters.Collections.Set_Of_CMOF_Parameter is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Return_Result unimplemented"); raise Program_Error; return Return_Result (Self); end Return_Result; ----------- -- Types -- ----------- overriding function Types (Self : not null access constant CMOF_Operation_Proxy) return AMF.CMOF.Types.CMOF_Type_Access is begin -- Generated stub: replace with real body! pragma Compile_Time_Warning (Standard.True, "Types unimplemented"); raise Program_Error; return Types (Self); end Types; end AMF.Internals.CMOF_Operations;
apple-oss-distributions/old_ncurses
Ada
8,467
adb
------------------------------------------------------------------------------ -- -- -- GNAT ncurses Binding Samples -- -- -- -- Sample -- -- -- -- B O D Y -- -- -- ------------------------------------------------------------------------------ -- Copyright (c) 1998 Free Software Foundation, Inc. -- -- -- -- Permission is hereby granted, free of charge, to any person obtaining a -- -- copy of this software and associated documentation files (the -- -- "Software"), to deal in the Software without restriction, including -- -- without limitation the rights to use, copy, modify, merge, publish, -- -- distribute, distribute with modifications, sublicense, and/or sell -- -- copies of the Software, and to permit persons to whom the Software is -- -- furnished to do so, subject to the following conditions: -- -- -- -- The above copyright notice and this permission notice shall be included -- -- in all copies or substantial portions of the Software. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -- -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -- -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -- -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR -- -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. -- -- -- -- Except as contained in this notice, the name(s) of the above copyright -- -- holders shall not be used in advertising or otherwise to promote the -- -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------ -- Author: Juergen Pfeifer <[email protected]> 1996 -- Version Control -- $Revision: 1.1.1.1 $ -- Binding Version 01.00 ------------------------------------------------------------------------------ with Text_IO; with Ada.Exceptions; use Ada.Exceptions; with Terminal_Interface.Curses; use Terminal_Interface.Curses; with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels; with Terminal_Interface.Curses.Menus; use Terminal_Interface.Curses.Menus; with Terminal_Interface.Curses.Menus.Menu_User_Data; with Terminal_Interface.Curses.Menus.Item_User_Data; with Sample.Manifest; use Sample.Manifest; with Sample.Function_Key_Setting; use Sample.Function_Key_Setting; with Sample.Keyboard_Handler; use Sample.Keyboard_Handler; with Sample.Header_Handler; use Sample.Header_Handler; with Sample.Explanation; use Sample.Explanation; with Sample.Menu_Demo.Handler; with Sample.Curses_Demo; with Sample.Form_Demo; with Sample.Menu_Demo; with Sample.Text_IO_Demo; with GNAT.OS_Lib; package body Sample is type User_Data is record Data : Integer; end record; type User_Access is access User_Data; package Ud is new Terminal_Interface.Curses.Menus.Menu_User_Data (User_Data, User_Access); package Id is new Terminal_Interface.Curses.Menus.Item_User_Data (User_Data, User_Access); procedure Whow is procedure Main_Menu; procedure Main_Menu is function My_Driver (M : Menu; K : Key_Code; Pan : Panel) return Boolean; package Mh is new Sample.Menu_Demo.Handler (My_Driver); I : Item_Array_Access := new Item_Array' (New_Item ("Curses Core Demo"), New_Item ("Menu Demo"), New_Item ("Form Demo"), New_Item ("Text IO Demo"), Null_Item); M : Menu := New_Menu (I); D1, D2 : User_Access; I1, I2 : User_Access; function My_Driver (M : Menu; K : Key_Code; Pan : Panel) return Boolean is Idx : constant Positive := Get_Index (Current (M)); begin if K in User_Key_Code'Range then if K = QUIT then return True; elsif K = SELECT_ITEM then if Idx in 1 .. 4 then Hide (Pan); Update_Panels; end if; case Idx is when 1 => Sample.Curses_Demo.Demo; when 2 => Sample.Menu_Demo.Demo; when 3 => Sample.Form_Demo.Demo; when 4 => Sample.Text_IO_Demo.Demo; when others => null; end case; if Idx in 1 .. 4 then Top (Pan); Show (Pan); Update_Panels; Update_Screen; end if; end if; end if; return False; end My_Driver; begin if (1 + Item_Count (M)) /= I'Length then raise Constraint_Error; end if; D1 := new User_Data'(Data => 4711); Ud.Set_User_Data (M, D1); I1 := new User_Data'(Data => 1174); Id.Set_User_Data (I (1), I1); Set_Spacing (Men => M, Row => 2); Default_Labels; Notepad ("MAINPAD"); Mh.Drive_Me (M, " Demo "); Ud.Get_User_Data (M, D2); pragma Assert (D1 = D2); pragma Assert (D1.Data = D2.Data); Id.Get_User_Data (I (1), I2); pragma Assert (I1 = I2); pragma Assert (I1.Data = I2.Data); Delete (M); Free (I, True); end Main_Menu; begin Initialize (PC_Style_With_Index); Init_Header_Handler; Init_Screen; if Has_Colors then Start_Color; Init_Pair (Pair => Default_Colors, Fore => Black, Back => White); Init_Pair (Pair => Menu_Back_Color, Fore => Black, Back => Cyan); Init_Pair (Pair => Menu_Fore_Color, Fore => Red, Back => Cyan); Init_Pair (Pair => Menu_Grey_Color, Fore => White, Back => Cyan); Init_Pair (Pair => Notepad_Color, Fore => Black, Back => Yellow); Init_Pair (Pair => Help_Color, Fore => Blue, Back => Cyan); Init_Pair (Pair => Form_Back_Color, Fore => Black, Back => Cyan); Init_Pair (Pair => Form_Fore_Color, Fore => Red, Back => Cyan); Init_Pair (Pair => Header_Color, Fore => Black, Back => Green); Set_Background (Ch => (Color => Default_Colors, Attr => Normal_Video, Ch => ' ')); Set_Character_Attributes (Attr => Normal_Video, Color => Default_Colors); Erase; Set_Soft_Label_Key_Attributes (Color => Header_Color); -- This propagates the attributes to the label window Clear_Soft_Label_Keys; Restore_Soft_Label_Keys; end if; Init_Keyboard_Handler; Set_Echo_Mode (False); Set_Raw_Mode; Set_Meta_Mode; Set_KeyPad_Mode; -- Initialize the Function Key Environment -- We have some fixed key throughout this sample Main_Menu; End_Windows; exception when Event : others => Terminal_Interface.Curses.End_Windows; Text_IO.Put ("Exception: "); Text_IO.Put (Exception_Name (Event)); Text_IO.New_Line; GNAT.OS_Lib.OS_Exit (1); end Whow; end Sample;
kjseefried/coreland-cgbc
Ada
880
adb
with Ada.Strings; with CGBC.Bounded_Strings; with Test; procedure T_Bstr_Append_RB03 is package BS renames CGBC.Bounded_Strings; TC : Test.Context_t; S1 : BS.Bounded_String (8); S : constant String := " H"; begin Test.Initialize (Test_Context => TC, Program => "t_bstr_append_rb03", Test_DB => "TEST_DB", Test_Results => "TEST_RESULTS"); BS.Append (S1, "ABCDEFGH"); -- As Append_R03 but with unusual bounds on New_Item. pragma Assert (S (11 .. 11) = "H"); BS.Append (Source => S1, New_Item => S (11 .. 11), Drop => Ada.Strings.Right); Test.Check (TC, 298, BS.Length (S1) = 8, "BS.Length (S1) = 8"); Test.Check (TC, 299, BS.Maximum_Length (S1) = 8, "BS.Maximum_Length (S1) = 8"); Test.Check (TC, 300, BS.To_String (S1) = "ABCDEFGH", "BS.To_String (S1) = ""ABCDEFGH"""); end T_Bstr_Append_RB03;
pdaxrom/Kino2
Ada
8,972
adb
------------------------------------------------------------------------------ -- -- -- GNAT ncurses Binding Samples -- -- -- -- Sample.Menu_Demo.Aux -- -- -- -- B O D Y -- -- -- ------------------------------------------------------------------------------ -- Copyright (c) 1998 Free Software Foundation, Inc. -- -- -- -- Permission is hereby granted, free of charge, to any person obtaining a -- -- copy of this software and associated documentation files (the -- -- "Software"), to deal in the Software without restriction, including -- -- without limitation the rights to use, copy, modify, merge, publish, -- -- distribute, distribute with modifications, sublicense, and/or sell -- -- copies of the Software, and to permit persons to whom the Software is -- -- furnished to do so, subject to the following conditions: -- -- -- -- The above copyright notice and this permission notice shall be included -- -- in all copies or substantial portions of the Software. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -- -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -- -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -- -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR -- -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. -- -- -- -- Except as contained in this notice, the name(s) of the above copyright -- -- holders shall not be used in advertising or otherwise to promote the -- -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------ -- Author: Juergen Pfeifer, 1996 -- Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en -- Version Control -- $Revision: 1.10 $ -- Binding Version 01.00 ------------------------------------------------------------------------------ with Ada.Characters.Latin_1; use Ada.Characters.Latin_1; with Sample.Manifest; use Sample.Manifest; with Sample.Helpers; use Sample.Helpers; with Sample.Keyboard_Handler; use Sample.Keyboard_Handler; with Sample.Explanation; use Sample.Explanation; package body Sample.Menu_Demo.Aux is procedure Geometry (M : in Menu; L : out Line_Count; C : out Column_Count; Y : out Line_Position; X : out Column_Position; Fy : out Line_Position; Fx : out Column_Position); procedure Geometry (M : in Menu; L : out Line_Count; -- Lines used for menu C : out Column_Count; -- Columns used for menu Y : out Line_Position; -- Proposed Line for menu X : out Column_Position; -- Proposed Column for menu Fy : out Line_Position; -- Vertical inner frame Fx : out Column_Position) -- Horiz. inner frame is Spc_Desc : Column_Position; -- spaces between description and item begin Set_Mark (M, Menu_Marker); Spacing (M, Spc_Desc, Fy, Fx); Scale (M, L, C); Fx := Fx + Column_Position (Fy - 1); -- looks a bit nicer L := L + 2 * Fy; -- count for frame at top and bottom C := C + 2 * Fx; -- " -- Calculate horizontal coordinate at the screen center X := (Columns - C) / 2; Y := 1; -- always startin line 1 end Geometry; procedure Geometry (M : in Menu; L : out Line_Count; -- Lines used for menu C : out Column_Count; -- Columns used for menu Y : out Line_Position; -- Proposed Line for menu X : out Column_Position) -- Proposed Column for menu is Fy : Line_Position; Fx : Column_Position; begin Geometry (M, L, C, Y, X, Fy, Fx); end Geometry; function Create (M : Menu; Title : String; Lin : Line_Position; Col : Column_Position) return Panel is W, S : Window; L : Line_Count; C : Column_Count; Y, Fy : Line_Position; X, Fx : Column_Position; Pan : Panel; begin Geometry (M, L, C, Y, X, Fy, Fx); W := New_Window (L, C, Lin, Col); Set_Meta_Mode (W); Set_KeyPad_Mode (W); if Has_Colors then Set_Background (Win => W, Ch => (Ch => ' ', Color => Menu_Back_Color, Attr => Normal_Video)); Set_Foreground (Men => M, Color => Menu_Fore_Color); Set_Background (Men => M, Color => Menu_Back_Color); Set_Grey (Men => M, Color => Menu_Grey_Color); Erase (W); end if; S := Derived_Window (W, L - Fy, C - Fx, Fy, Fx); Set_Meta_Mode (S); Set_KeyPad_Mode (S); Box (W); Set_Window (M, W); Set_Sub_Window (M, S); if Title'Length > 0 then Window_Title (W, Title); end if; Pan := New_Panel (W); Post (M); return Pan; end Create; procedure Destroy (M : in Menu; P : in out Panel) is W, S : Window; begin W := Get_Window (M); S := Get_Sub_Window (M); Post (M, False); Erase (W); Delete (P); Set_Window (M, Null_Window); Set_Sub_Window (M, Null_Window); Delete (S); Delete (W); Update_Panels; end Destroy; function Get_Request (M : Menu; P : Panel) return Key_Code is W : constant Window := Get_Window (M); K : Real_Key_Code; Ch : Character; begin Top (P); loop K := Get_Key (W); if K in Special_Key_Code'Range then case K is when HELP_CODE => Explain_Context; when EXPLAIN_CODE => Explain ("MENUKEYS"); when Key_Home => return REQ_FIRST_ITEM; when QUIT_CODE => return QUIT; when Key_Cursor_Down => return REQ_DOWN_ITEM; when Key_Cursor_Up => return REQ_UP_ITEM; when Key_Cursor_Left => return REQ_LEFT_ITEM; when Key_Cursor_Right => return REQ_RIGHT_ITEM; when Key_End => return REQ_LAST_ITEM; when Key_Backspace => return REQ_BACK_PATTERN; when Key_Next_Page => return REQ_SCR_DPAGE; when Key_Previous_Page => return REQ_SCR_UPAGE; when others => return K; end case; elsif K in Normal_Key_Code'Range then Ch := Character'Val (K); case Ch is when CAN => return QUIT; -- CTRL-X when SO => return REQ_NEXT_ITEM; -- CTRL-N when DLE => return REQ_PREV_ITEM; -- CTRL-P when NAK => return REQ_SCR_ULINE; -- CTRL-U when EOT => return REQ_SCR_DLINE; -- CTRL-D when ACK => return REQ_SCR_DPAGE; -- CTRL-F when STX => return REQ_SCR_UPAGE; -- CTRL-B when EM => return REQ_CLEAR_PATTERN; -- CTRL-Y when BS => return REQ_BACK_PATTERN; -- CTRL-H when SOH => return REQ_NEXT_MATCH; -- CTRL-A when ENQ => return REQ_PREV_MATCH; -- CTRL-E when DC4 => return REQ_TOGGLE_ITEM; -- CTRL-T when CR | LF => return SELECT_ITEM; when others => return K; end case; else return K; end if; end loop; end Get_Request; end Sample.Menu_Demo.Aux;
reznikmm/matreshka
Ada
5,295
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Ada Modeling Framework -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2012, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- This file is generated, don't edit it. ------------------------------------------------------------------------------ with AMF.Generic_Collections; package AMF.Utp.Timer_Running_Actions.Collections is pragma Preelaborate; package Utp_Timer_Running_Action_Collections is new AMF.Generic_Collections (Utp_Timer_Running_Action, Utp_Timer_Running_Action_Access); type Set_Of_Utp_Timer_Running_Action is new Utp_Timer_Running_Action_Collections.Set with null record; Empty_Set_Of_Utp_Timer_Running_Action : constant Set_Of_Utp_Timer_Running_Action; type Ordered_Set_Of_Utp_Timer_Running_Action is new Utp_Timer_Running_Action_Collections.Ordered_Set with null record; Empty_Ordered_Set_Of_Utp_Timer_Running_Action : constant Ordered_Set_Of_Utp_Timer_Running_Action; type Bag_Of_Utp_Timer_Running_Action is new Utp_Timer_Running_Action_Collections.Bag with null record; Empty_Bag_Of_Utp_Timer_Running_Action : constant Bag_Of_Utp_Timer_Running_Action; type Sequence_Of_Utp_Timer_Running_Action is new Utp_Timer_Running_Action_Collections.Sequence with null record; Empty_Sequence_Of_Utp_Timer_Running_Action : constant Sequence_Of_Utp_Timer_Running_Action; private Empty_Set_Of_Utp_Timer_Running_Action : constant Set_Of_Utp_Timer_Running_Action := (Utp_Timer_Running_Action_Collections.Set with null record); Empty_Ordered_Set_Of_Utp_Timer_Running_Action : constant Ordered_Set_Of_Utp_Timer_Running_Action := (Utp_Timer_Running_Action_Collections.Ordered_Set with null record); Empty_Bag_Of_Utp_Timer_Running_Action : constant Bag_Of_Utp_Timer_Running_Action := (Utp_Timer_Running_Action_Collections.Bag with null record); Empty_Sequence_Of_Utp_Timer_Running_Action : constant Sequence_Of_Utp_Timer_Running_Action := (Utp_Timer_Running_Action_Collections.Sequence with null record); end AMF.Utp.Timer_Running_Actions.Collections;
reznikmm/matreshka
Ada
8,174
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- XML Processor -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2010-2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ -- Abstract interface of XML reader. ------------------------------------------------------------------------------ with League.Strings; with XML.SAX.Content_Handlers; with XML.SAX.Declaration_Handlers; with XML.SAX.DTD_Handlers; with XML.SAX.Entity_Resolvers; with XML.SAX.Error_Handlers; with XML.SAX.Lexical_Handlers; package XML.SAX.Readers is pragma Preelaborate; type SAX_Content_Handler_Access is access all XML.SAX.Content_Handlers.SAX_Content_Handler'Class; type SAX_Declaration_Handler_Access is access all XML.SAX.Declaration_Handlers.SAX_Declaration_Handler'Class; type SAX_DTD_Handler_Access is access all XML.SAX.DTD_Handlers.SAX_DTD_Handler'Class; type SAX_Error_Handler_Access is access all XML.SAX.Error_Handlers.SAX_Error_Handler'Class; type SAX_Lexical_Handler_Access is access all XML.SAX.Lexical_Handlers.SAX_Lexical_Handler'Class; type SAX_Entity_Resolver_Access is access all XML.SAX.Entity_Resolvers.SAX_Entity_Resolver'Class; type SAX_Reader is limited interface; not overriding function Content_Handler (Self : SAX_Reader) return SAX_Content_Handler_Access is abstract; -- Returns the current content handler, or null if none has been -- registered. not overriding function Declaration_Handler (Self : SAX_Reader) return SAX_Declaration_Handler_Access is abstract; -- Returns the current declaration handler, or null if has not been -- registered. not overriding function DTD_Handler (Self : SAX_Reader) return SAX_DTD_Handler_Access is abstract; -- Returns the current DTD handler, or null if none has been registered. not overriding function Entity_Resolver (Self : SAX_Reader) return SAX_Entity_Resolver_Access is abstract; -- Returns the current entity resolver, or null if none has been -- registered. not overriding function Error_Handler (Self : SAX_Reader) return SAX_Error_Handler_Access is abstract; -- Returns the current error handler, or null if none has been registered. not overriding function Feature (Self : SAX_Reader; Name : League.Strings.Universal_String) return Boolean is abstract; -- Look up the value of a feature flag. Returns value of the feature or -- false if feature is not recognized or not acceptable at this time. -- -- The feature name is any fully-qualified URI. It is possible for an -- XMLReader to recognize a feature name but temporarily be unable to -- return its value. Some feature values may be available only in specific -- contexts, such as before, during, or after a parse. Also, some feature -- values may not be programmatically accessible. -- -- All Readers are required to recognize the -- http://xml.org/sax/features/namespaces and the -- http://xml.org/sax/features/namespace-prefixes feature names. not overriding function Has_Feature (Self : SAX_Reader; Name : League.Strings.Universal_String) return Boolean is abstract; -- Returns True if the reader has the feature called Name; otherwise -- returns False. not overriding function Lexical_Handler (Self : SAX_Reader) return SAX_Lexical_Handler_Access is abstract; -- Returns the current lexical handler, or null if none has been -- registered. not overriding procedure Set_Content_Handler (Self : in out SAX_Reader; Handler : SAX_Content_Handler_Access) is abstract; not overriding procedure Set_Declaration_Handler (Self : in out SAX_Reader; Handler : SAX_Declaration_Handler_Access) is abstract; not overriding procedure Set_DTD_Handler (Self : in out SAX_Reader; Handler : SAX_DTD_Handler_Access) is abstract; not overriding procedure Set_Entity_Resolver (Self : in out SAX_Reader; Resolver : SAX_Entity_Resolver_Access) is abstract; not overriding procedure Set_Error_Handler (Self : in out SAX_Reader; Handler : SAX_Error_Handler_Access) is abstract; not overriding procedure Set_Feature (Self : in out SAX_Reader; Name : League.Strings.Universal_String; Value : Boolean) is abstract; -- Set the value of a feature flag. -- -- The feature name is any fully-qualified URI. It is possible for an -- XMLReader to expose a feature value but to be unable to change the -- current value. Some feature values may be immutable or mutable only in -- specific contexts, such as before, during, or after a parse. -- -- All XMLReaders are required to support setting -- http://xml.org/sax/features/namespaces to true and -- http://xml.org/sax/features/namespace-prefixes to false. not overriding procedure Set_Lexical_Handler (Self : in out SAX_Reader; Handler : SAX_Lexical_Handler_Access) is abstract; end XML.SAX.Readers;
zhmu/ananas
Ada
227
ads
with Inline17_Pkg3; use Inline17_Pkg3; package Inline17_Pkg2 is subtype SQL_Field is Inline17_Pkg3.SQL_Field; function "+" (Field : SQL_Field'Class) return Integer renames Inline17_Pkg3."+"; end Inline17_Pkg2;
ytomino/gnat4drake
Ada
216
ads
pragma License (Unrestricted); with System.Tasking; package System.Task_Primitives.Operations is pragma Preelaborate; procedure Abort_Task (T : System.Tasking.Task_Id); end System.Task_Primitives.Operations;
reznikmm/matreshka
Ada
3,759
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with XML.DOM.Attributes; package ODF.DOM.Table_Display_Duplicates_Attributes is pragma Preelaborate; type ODF_Table_Display_Duplicates_Attribute is limited interface and XML.DOM.Attributes.DOM_Attribute; type ODF_Table_Display_Duplicates_Attribute_Access is access all ODF_Table_Display_Duplicates_Attribute'Class with Storage_Size => 0; end ODF.DOM.Table_Display_Duplicates_Attributes;
clairvoyant/anagram
Ada
3,471
adb
-- Check extended grammar constructor and debuger output with Anagram.Grammars_Debug; with Anagram.Grammars; with Anagram.Grammars.Constructors; with League.Strings; procedure TS_00003 is use Anagram.Grammars.Constructors; C : Anagram.Grammars.Constructors.Constructor; begin C.Create_Terminal (League.Strings.To_Universal_String ("T2")); C.Create_Terminal (League.Strings.To_Universal_String ("T1")); C.Create_Terminal (League.Strings.To_Universal_String ("T3")); declare T1 : constant Part := C.Create_Terminal_Reference (League.Strings.To_Universal_String ("t1"), League.Strings.To_Universal_String ("T1")); NT3 : constant Part := C.Create_Non_Terminal_Reference (League.Strings.To_Universal_String ("nt3"), League.Strings.To_Universal_String ("NT3")); P2 : Production := C.Create_Production (League.Strings.To_Universal_String ("P2")); PL : Production_List := C.Create_Production_List; begin P2.Add (T1); P2.Add (NT3); PL.Add (P2); C.Create_Non_Terminal (League.Strings.To_Universal_String ("NT2"), PL); end; declare NT3 : constant Part := C.Create_Non_Terminal_Reference (League.Strings.To_Universal_String ("nt3"), League.Strings.To_Universal_String ("NT3")); L1 : constant Part := C.Create_List_Reference (League.Strings.To_Universal_String ("L1"), League.Strings.To_Universal_String ("L1")); P1 : Production := C.Create_Production (League.Strings.To_Universal_String ("P1")); PL : Production_List := C.Create_Production_List; begin P1.Add (NT3); P1.Add (L1); PL.Add (P1); C.Create_Non_Terminal (League.Strings.To_Universal_String ("NT1"), PL); end; declare NT2 : constant Part := C.Create_Non_Terminal_Reference (League.Strings.To_Universal_String ("nt2"), League.Strings.To_Universal_String ("NT2")); T3 : constant Part := C.Create_Terminal_Reference (League.Strings.To_Universal_String ("t3"), League.Strings.To_Universal_String ("T3")); PL1 : Production := C.Create_Production (League.Strings.To_Universal_String ("PL1")); PL : Production_List := C.Create_Production_List; begin PL1.Add (NT2); PL1.Add (T3); PL.Add (PL1); C.Create_List (League.Strings.To_Universal_String ("L1"), PL); end; declare T2 : constant Part := C.Create_Terminal_Reference (League.Strings.To_Universal_String ("t2"), League.Strings.To_Universal_String ("T2")); NT1 : constant Part := C.Create_Non_Terminal_Reference (League.Strings.To_Universal_String ("nt1"), League.Strings.To_Universal_String ("NT1")); OP3 : Production := C.Create_Production (League.Strings.To_Universal_String ("OP3")); P3 : Production := C.Create_Production (League.Strings.To_Universal_String ("P3")); PL : Production_List := C.Create_Production_List; begin OP3.Add (T2); OP3.Add (NT1); PL.Add (OP3); P3.Add (C.Create_Option (League.Strings.To_Universal_String ("O3"), PL)); PL := C.Create_Production_List; PL.Add (P3); C.Create_Non_Terminal (League.Strings.To_Universal_String ("NT3"), PL); end; declare Result : constant Anagram.Grammars.Grammar := C.Complete; begin Anagram.Grammars_Debug.Print (Result); end; end TS_00003;
stcarrez/dynamo
Ada
2,640
adb
-- part of AdaYaml, (c) 2017 Felix Krause -- released under the terms of the MIT license, see the file "copying.txt" with Ada.Unchecked_Deallocation; package body Yaml.Stacks is overriding procedure Adjust (Object : in out Stack) is begin if Object.Data /= null then Object.Data.Refcount := Object.Data.Refcount + 1; end if; end Adjust; procedure Free_Element_Array is new Ada.Unchecked_Deallocation (Element_Array, Element_Array_Access); overriding procedure Finalize (Object : in out Stack) is procedure Free_Holder is new Ada.Unchecked_Deallocation (Holder, Holder_Access); Reference : Holder_Access := Object.Data; begin Object.Data := null; if Reference /= null then Reference.Refcount := Reference.Refcount - 1; if Reference.Refcount = 0 then Free_Element_Array (Reference.Elements); Free_Holder (Reference); end if; end if; end Finalize; function New_Stack (Initial_Capacity : Positive) return Stack is begin return Ret : constant Stack := (Ada.Finalization.Controlled with Data => new Holder) do Ret.Data.Elements := new Element_Array (1 .. Initial_Capacity); Ret.Data.Length := 0; end return; end New_Stack; function Top (Object : in out Stack) return access Element_Type is (Object.Data.Elements (Object.Data.Length)'Access); function Length (Object : Stack) return Natural is (if Object.Data = null then 0 else Object.Data.Length); function Element (Object : Stack; Index : Positive) return access Element_Type is (Object.Data.Elements (Index)'Access); procedure Pop (Object : in out Stack) is begin Object.Data.Length := Object.Data.Length - 1; end Pop; procedure Push (Object : in out Stack; Value : Element_Type) is begin if Object.Data = null then Object := New_Stack (32); end if; if Object.Data.Length = Object.Data.Elements.all'Last then declare New_Array : constant Element_Array_Access := new Element_Array (1 .. Object.Data.Length * 2); begin New_Array (1 .. Object.Data.Length) := Object.Data.Elements.all; Free_Element_Array (Object.Data.Elements); Object.Data.Elements := New_Array; end; end if; Object.Data.Length := Object.Data.Length + 1; Object.Data.Elements (Object.Data.Length) := Value; end Push; function Initialized (Object : Stack) return Boolean is (Object.Data /= null); end Yaml.Stacks;
stcarrez/ada-keystore
Ada
23,355
adb
----------------------------------------------------------------------- -- keystore-io-files -- Ada keystore IO for files -- Copyright (C) 2019, 2020, 2022 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.IO_Exceptions; with Ada.Unchecked_Deallocation; with Ada.Directories; with Interfaces.C.Strings; with Util.Log.Loggers; with Util.Strings; with Util.Systems.Os; with Util.Systems.Constants; -- File header -- +------------------+ -- | 41 64 61 00 | 4b = Ada -- | 00 9A 72 57 | 4b = 10/12/1815 -- | 01 9D B1 AC | 4b = 27/11/1852 -- | 00 00 00 01 | 4b = Version 1 -- +------------------+ -- | Keystore UUID | 16b -- | Storage ID | 4b -- | Block size | 4b -- | PAD 0 | 4b -- | Header HMAC-256 | 32b -- +------------------+----- package body Keystore.IO.Files is use Ada.Strings.Unbounded; use type Util.Systems.Types.File_Type; use type Interfaces.C.int; use Util.Systems.Constants; Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("Keystore.IO.Files"); subtype off_t is Util.Systems.Types.off_t; function Sys_Error return String; function Get_Default_Data (Path : in String) return String; procedure Free is new Ada.Unchecked_Deallocation (Object => File_Stream, Name => File_Stream_Access); function Sys_Error return String is Msg : constant Interfaces.C.Strings.chars_ptr := Util.Systems.Os.Strerror (Util.Systems.Os.Errno); begin return Interfaces.C.Strings.Value (Msg); end Sys_Error; function Hash (Value : Storage_Identifier) return Ada.Containers.Hash_Type is begin return Ada.Containers.Hash_Type (Value); end Hash; function Get_Default_Data (Path : in String) return String is Pos : constant Natural := Util.Strings.Rindex (Path, '.'); begin if Pos > 0 then return Path (Path'First .. Pos - 1); else return Ada.Directories.Containing_Directory (Path); end if; end Get_Default_Data; -- ------------------------------ -- Open the wallet stream. -- ------------------------------ procedure Open (Stream : in out Wallet_Stream; Path : in String; Data_Path : in String) is begin if Data_Path'Length > 0 then Stream.Descriptor.Open (Path, Data_Path, Stream.Sign); else Stream.Descriptor.Open (Path, Get_Default_Data (Path), Stream.Sign); end if; end Open; procedure Create (Stream : in out Wallet_Stream; Path : in String; Data_Path : in String; Config : in Wallet_Config) is begin if Data_Path'Length > 0 then Stream.Descriptor.Create (Path, Data_Path, Config, Stream.Sign); else Stream.Descriptor.Create (Path, Get_Default_Data (Path), Config, Stream.Sign); end if; if Config.Storage_Count > 1 then Stream.Add_Storage (Config.Storage_Count - 1); end if; end Create; -- ------------------------------ -- Get information about the keystore file. -- ------------------------------ function Get_Info (Stream : in out Wallet_Stream) return Wallet_Info is File : File_Stream_Access; begin Stream.Descriptor.Get (DEFAULT_STORAGE_ID, File); return File.Get_Info; end Get_Info; -- ------------------------------ -- Read from the wallet stream the block identified by the number and -- call the `Process` procedure with the data block content. -- ------------------------------ overriding procedure Read (Stream : in out Wallet_Stream; Block : in Storage_Block; Process : not null access procedure (Data : in IO_Block_Type)) is File : File_Stream_Access; begin Stream.Descriptor.Get (Block.Storage, File); File.Read (Block.Block, Process); end Read; -- ------------------------------ -- Write in the wallet stream the block identified by the block number. -- ------------------------------ overriding procedure Write (Stream : in out Wallet_Stream; Block : in Storage_Block; Process : not null access procedure (Data : out IO_Block_Type)) is File : File_Stream_Access; begin Stream.Descriptor.Get (Block.Storage, File); File.Write (Block.Block, Process); end Write; -- ------------------------------ -- Allocate a new block and return the block number in `Block`. -- ------------------------------ overriding procedure Allocate (Stream : in out Wallet_Stream; Kind : in Block_Kind; Block : out Storage_Block) is File : File_Stream_Access; begin Stream.Descriptor.Allocate (Kind, Block.Storage, File); File.Allocate (Block.Block); end Allocate; -- ------------------------------ -- Release the block number. -- ------------------------------ overriding procedure Release (Stream : in out Wallet_Stream; Block : in Storage_Block) is File : File_Stream_Access; begin Stream.Descriptor.Get (Block.Storage, File); File.Release (Block.Block); end Release; overriding function Is_Used (Stream : in out Wallet_Stream; Block : in Storage_Block) return Boolean is File : File_Stream_Access; begin Stream.Descriptor.Get (Block.Storage, File); return File.Is_Used (Block.Block); end Is_Used; overriding procedure Set_Header_Data (Stream : in out Wallet_Stream; Index : in Header_Slot_Index_Type; Kind : in Header_Slot_Type; Data : in Ada.Streams.Stream_Element_Array) is File : File_Stream_Access; begin Stream.Descriptor.Get (DEFAULT_STORAGE_ID, File); File.Set_Header_Data (Index, Kind, Data, Stream.Sign); end Set_Header_Data; overriding procedure Get_Header_Data (Stream : in out Wallet_Stream; Index : in Header_Slot_Index_Type; Kind : out Header_Slot_Type; Data : out Ada.Streams.Stream_Element_Array; Last : out Ada.Streams.Stream_Element_Offset) is File : File_Stream_Access; begin Stream.Descriptor.Get (DEFAULT_STORAGE_ID, File); File.Get_Header_Data (Index, Kind, Data, Last); end Get_Header_Data; -- ------------------------------ -- Add up to Count data storage files associated with the wallet. -- ------------------------------ procedure Add_Storage (Stream : in out Wallet_Stream; Count : in Positive) is begin Stream.Descriptor.Add_Storage (Count, Stream.Sign); end Add_Storage; -- ------------------------------ -- Close the wallet stream and release any resource. -- ------------------------------ overriding procedure Close (Stream : in out Wallet_Stream) is begin Stream.Descriptor.Close; end Close; function Get_Block_Offset (Block : in Block_Number) return off_t is (Util.Systems.Types.off_t (Block) * Block_Size); protected body File_Stream is procedure Open (File_Descriptor : in Util.Systems.Types.File_Type; Storage : in Storage_Identifier; Sign : in Secret_Key; File_Size : in Block_Count; UUID : out UUID_Type) is begin File.Initialize (File_Descriptor); Size := File_Size; Current_Pos := Block_Size; Header.Buffer := Buffers.Allocate ((Storage, HEADER_BLOCK_NUM)); declare Buf : constant Buffers.Buffer_Accessor := Header.Buffer.Data.Value; Last : Ada.Streams.Stream_Element_Offset; begin File.Read (Data, Last); if Last /= Data'Last then Log.Warn ("Header block is too short"); raise Invalid_Keystore; end if; Buf.Data := Data (Buf.Data'Range); Keystore.IO.Headers.Sign_Header (Header, Sign); if Header.HMAC /= Data (BT_HMAC_HEADER_POS .. Data'Last) then Log.Warn ("Header block HMAC signature is invalid"); raise Invalid_Block; end if; Keystore.IO.Headers.Read_Header (Header); UUID := Header.UUID; end; end Open; procedure Create (File_Descriptor : in Util.Systems.Types.File_Type; Storage : in Storage_Identifier; UUID : in UUID_Type; Sign : in Secret_Key) is begin File.Initialize (File_Descriptor); Size := 1; Current_Pos := Block_Size; Header.Buffer := Buffers.Allocate ((Storage, HEADER_BLOCK_NUM)); Header.UUID := UUID; Keystore.IO.Headers.Build_Header (UUID, Storage, Header); Keystore.IO.Headers.Sign_Header (Header, Sign); declare Buf : constant Buffers.Buffer_Accessor := Header.Buffer.Data.Value; begin File.Write (Buf.Data); File.Write (Header.HMAC); end; end Create; function Get_Info return Wallet_Info is Result : Wallet_Info; begin Result.UUID := Header.UUID; Result.Header_Count := Header.Data_Count; Result.Storage_Count := Header.Storage_Count; return Result; end Get_Info; -- Read from the wallet stream the block identified by the number and -- call the `Process` procedure with the data block content. procedure Read (Block : in Block_Number; Process : not null access procedure (Data : in IO_Block_Type)) is Pos : constant off_t := Get_Block_Offset (Block); Last : Ada.Streams.Stream_Element_Offset; begin if Pos /= Current_Pos then File.Seek (Pos => Pos, Mode => Util.Systems.Types.SEEK_SET); end if; File.Read (Data, Last); Process (Data); Current_Pos := Pos + Block_Size; end Read; -- Write in the wallet stream the block identified by the block number. procedure Write (Block : in Block_Number; Process : not null access procedure (Data : out IO_Block_Type)) is Pos : constant off_t := Get_Block_Offset (Block); begin if Pos /= Current_Pos then File.Seek (Pos => Pos, Mode => Util.Systems.Types.SEEK_SET); end if; Process (Data); File.Write (Data); Current_Pos := Pos + Block_Size; end Write; -- ------------------------------ -- Returns true if the block number is allocated. -- ------------------------------ function Is_Used (Block : in Block_Number) return Boolean is begin return Block <= Size and then not Free_Blocks.Contains (Block); end Is_Used; -- ------------------------------ -- Allocate a new block and return the block number in `Block`. -- ------------------------------ procedure Allocate (Block : out Block_Number) is begin if not Free_Blocks.Is_Empty then Block := Free_Blocks.First_Element; Free_Blocks.Delete_First; else Block := Block_Number (Size); Size := Size + 1; end if; end Allocate; -- ------------------------------ -- Release the block number. -- ------------------------------ procedure Release (Block : in Block_Number) is begin Free_Blocks.Insert (Block); end Release; procedure Save_Header (Sign : in Secret_Key) is Buf : constant Buffers.Buffer_Accessor := Header.Buffer.Data.Value; begin Keystore.IO.Headers.Sign_Header (Header, Sign); File.Seek (Pos => 0, Mode => Util.Systems.Types.SEEK_SET); File.Write (Buf.Data); File.Write (Header.HMAC); Current_Pos := Block_Size; end Save_Header; procedure Set_Header_Data (Index : in Header_Slot_Index_Type; Kind : in Header_Slot_Type; Data : in Ada.Streams.Stream_Element_Array; Sign : in Secret_Key) is begin IO.Headers.Set_Header_Data (Header, Index, Kind, Data); Save_Header (Sign); end Set_Header_Data; procedure Get_Header_Data (Index : in Header_Slot_Index_Type; Kind : out Header_Slot_Type; Data : out Ada.Streams.Stream_Element_Array; Last : out Ada.Streams.Stream_Element_Offset) is begin IO.Headers.Get_Header_Data (Header, Index, Kind, Data, Last); end Get_Header_Data; procedure Add_Storage (Identifier : in Storage_Identifier; Sign : in Secret_Key) is Pos : Block_Index; begin IO.Headers.Add_Storage (Header, Identifier, 1, Pos); Save_Header (Sign); end Add_Storage; procedure Scan_Storage (Process : not null access procedure (Storage : in Wallet_Storage)) is begin IO.Headers.Scan_Storage (Header, Process); end Scan_Storage; procedure Close is Last : Block_Number := Size; Free_Block : Block_Number; Iter : Block_Number_Sets.Cursor := Free_Blocks.Last; begin -- Look at free blocks to see if we can truncate the file when -- the last blocks are all deleted. while Block_Number_Sets.Has_Element (Iter) loop Free_Block := Block_Number_Sets.Element (Iter); exit when Free_Block /= Last - 1; Last := Last - 1; Block_Number_Sets.Previous (Iter); end loop; -- We have the last deleted block and we can truncate the file to it inclusive. if Last /= Size then declare Length : constant off_t := Get_Block_Offset (Last); Result : Integer; begin Result := Util.Systems.Os.Sys_Ftruncate (File.Get_File, Length); if Result /= 0 then Log.Warn ("Truncate to drop deleted blocks failed: {0}", Sys_Error); end if; end; end if; File.Close; end Close; end File_Stream; protected body Stream_Descriptor is function Get_Storage_Path (Storage_Id : in Storage_Identifier) return String is Prefix : constant String := To_String (UUID); Index : constant String := Storage_Identifier'Image (Storage_Id); Name : constant String := Prefix & "-" & Index (Index'First + 1 .. Index'Last); begin return Ada.Directories.Compose (To_String (Directory), Name & ".dkt"); end Get_Storage_Path; procedure Open (Path : in String; Identifier : in Storage_Identifier; Sign : in Secret_Key; Tag : out UUID_Type) is Fd : Util.Systems.Types.File_Type := Util.Systems.Os.NO_FILE; P : Interfaces.C.Strings.chars_ptr; File : File_Stream_Access; Flags : Interfaces.C.int; Stat : aliased Util.Systems.Types.Stat_Type; Size : Block_Count; Result : Integer; begin Flags := O_CLOEXEC + O_RDWR; P := Interfaces.C.Strings.New_String (Path); Fd := Util.Systems.Os.Sys_Open (P, Flags, 8#600#); Interfaces.C.Strings.Free (P); if Fd = Util.Systems.Os.NO_FILE then Log.Warn ("Cannot open keystore '{0}': {1}", Path, Sys_Error); raise Ada.IO_Exceptions.Name_Error with Path; end if; Result := Util.Systems.Os.Sys_Fstat (Fd, Stat'Access); if Result /= 0 or else Stat.st_size mod IO.Block_Size /= 0 then Result := Util.Systems.Os.Sys_Close (Fd); Log.Error ("Invalid or truncated keystore file '{0}': size is incorrect", Path); raise Keystore.Invalid_Keystore with Path; end if; Size := Block_Count (Stat.st_size / IO.Block_Size); File := new File_Stream; Files.Insert (Identifier, File); File.Open (Fd, Identifier, Sign, Size, Tag); end Open; procedure Open (Path : in String; Data_Path : in String; Sign : in Secret_Key) is procedure Open_Storage (Storage : in Wallet_Storage); procedure Open_Storage (Storage : in Wallet_Storage) is Path : constant String := Get_Storage_Path (Storage.Identifier); Tag : UUID_Type; begin Open (Path, Storage.Identifier, Sign, Tag); if Tag /= UUID then Log.Error ("Invalid UUID for storage file {0}", Path); end if; if Storage.Identifier > Last_Id then Last_Id := Storage.Identifier; end if; Alloc_Id := 1; exception when Ada.IO_Exceptions.Name_Error => raise Keystore.Invalid_Storage with Path; end Open_Storage; File : File_Stream_Access; begin if Data_Path'Length > 0 then Directory := To_Unbounded_String (Data_Path); else Directory := To_Unbounded_String (Ada.Directories.Containing_Directory (Path)); end if; Open (Path, DEFAULT_STORAGE_ID, Sign, UUID); Get (DEFAULT_STORAGE_ID, File); Last_Id := DEFAULT_STORAGE_ID; File.Scan_Storage (Open_Storage'Access); end Open; procedure Create (Path : in String; Data_Path : in String; Config : in Wallet_Config; Sign : in Secret_Key) is Fd : Util.Systems.Types.File_Type := Util.Systems.Os.NO_FILE; P : Interfaces.C.Strings.chars_ptr; File : File_Stream_Access; Flags : Interfaces.C.int; Result : Integer with Unreferenced => True; begin Directory := To_Unbounded_String (Data_Path); Flags := O_CREAT + O_TRUNC + O_CLOEXEC + O_RDWR; if not Config.Overwrite then Flags := Flags + O_EXCL; end if; P := Interfaces.C.Strings.New_String (Path); Fd := Util.Systems.Os.Sys_Open (P, Flags, 8#600#); Interfaces.C.Strings.Free (P); if Fd = Util.Systems.Os.NO_FILE then Log.Error ("Cannot create keystore '{0}': {1}", Path, Sys_Error); raise Ada.IO_Exceptions.Name_Error with Path; end if; File := new File_Stream; Random.Generate (UUID); File.Create (Fd, DEFAULT_STORAGE_ID, UUID, Sign); Files.Insert (DEFAULT_STORAGE_ID, File); Last_Id := DEFAULT_STORAGE_ID; end Create; procedure Create_Storage (Storage_Id : in Storage_Identifier; Sign : in Secret_Key) is Path : constant String := Get_Storage_Path (Storage_Id); Fd : Util.Systems.Types.File_Type := Util.Systems.Os.NO_FILE; P : Interfaces.C.Strings.chars_ptr; File : File_Stream_Access; Flags : Interfaces.C.int; Result : Integer with Unreferenced => True; begin Flags := O_CREAT + O_TRUNC + O_CLOEXEC + O_RDWR; P := Interfaces.C.Strings.New_String (Path); Fd := Util.Systems.Os.Sys_Open (P, Flags, 8#600#); Interfaces.C.Strings.Free (P); if Fd = Util.Systems.Os.NO_FILE then Log.Error ("Cannot create keystore storage '{0}': {1}", Path, Sys_Error); raise Ada.IO_Exceptions.Name_Error with Path; end if; File := new File_Stream; File.Create (Fd, Storage_Id, UUID, Sign); Files.Insert (Storage_Id, File); end Create_Storage; procedure Add_Storage (Count : in Positive; Sign : in Secret_Key) is File : File_Stream_Access; Dir : constant String := To_String (Directory); begin Get (DEFAULT_STORAGE_ID, File); if not Ada.Directories.Exists (Dir) then Ada.Directories.Create_Path (Dir); end if; for I in 1 .. Count loop Last_Id := Last_Id + 1; Create_Storage (Last_Id, Sign); File.Add_Storage (Last_Id, Sign); end loop; if Alloc_Id = DEFAULT_STORAGE_ID then Alloc_Id := 1; end if; end Add_Storage; procedure Get (Storage : in Storage_Identifier; File : out File_Stream_Access) is Pos : constant File_Stream_Maps.Cursor := Files.Find (Storage); begin if not File_Stream_Maps.Has_Element (Pos) then Log.Error ("Storage{0} not found", Storage_Identifier'Image (Storage)); raise Keystore.Invalid_Storage; end if; File := File_Stream_Maps.Element (Pos); end Get; procedure Allocate (Kind : in Block_Kind; Storage : out Storage_Identifier; File : out File_Stream_Access) is begin if Kind in IO.MASTER_BLOCK | IO.DIRECTORY_BLOCK or else Last_Id = DEFAULT_STORAGE_ID then Storage := DEFAULT_STORAGE_ID; else Storage := Alloc_Id; Alloc_Id := Alloc_Id + 1; if Alloc_Id > Last_Id then Alloc_Id := 1; end if; end if; Get (Storage, File); end Allocate; procedure Close is First : File_Stream_Maps.Cursor; File : File_Stream_Access; begin while not File_Stream_Maps.Is_Empty (Files) loop First := Files.First; File := File_Stream_Maps.Element (First); Files.Delete (First); File.Close; Free (File); end loop; end Close; end Stream_Descriptor; end Keystore.IO.Files;
zhmu/ananas
Ada
417
ads
-- { dg-do compile } package Double_Record_Extension3 is type Rec1 is tagged record Id : Integer; end record; for Rec1 use record Id at 8 range 0 .. 31; end record; type Rec2 (Size : Integer) is new Rec1 with record Data : String (1 .. Size); end record; type Rec3 is new Rec2 (Size => 128) with record Valid : Boolean; end record; end Double_Record_Extension3;
rveenker/sdlada
Ada
3,442
adb
-------------------------------------------------------------------------------------------------------------------- -- Copyright (c) 2013-2020, Luke A. Guest -- -- This software is provided 'as-is', without any express or implied -- warranty. In no event will the authors be held liable for any damages -- arising from the use of this software. -- -- Permission is granted to anyone to use this software for any purpose, -- including commercial applications, and to alter it and redistribute it -- freely, subject to the following restrictions: -- -- 1. The origin of this software must not be misrepresented; you must not -- claim that you wrote the original software. If you use this software -- in a product, an acknowledgment in the product documentation would be -- appreciated but is not required. -- -- 2. Altered source versions must be plainly marked as such, and must not be -- misrepresented as being the original software. -- -- 3. This notice may not be removed or altered from any source -- distribution. -------------------------------------------------------------------------------------------------------------------- with Ada.Unchecked_Conversion; with Interfaces.C.Strings; with SDL.Error; with System; package body SDL.Libraries is package C renames Interfaces.C; procedure Load (Self : out Handles; Name : in String) is function SDL_Load_Object (C_Str : in C.Strings.chars_ptr) return Internal_Handle_Access with Import => True, Convention => C, External_Name => "SDL_LoadObject"; C_Str : C.Strings.chars_ptr := C.Strings.New_String (Name); begin Self.Internal := SDL_Load_Object (C_Str); C.Strings.Free (C_Str); if Self.Internal = null then raise Library_Error with SDL.Error.Get; end if; end Load; procedure Unload (Self : in out Handles) is procedure SDL_Unload_Object (H : in Internal_Handle_Access) with Import => True, Convention => C, External_Name => "SDL_UnloadObject"; begin SDL_Unload_Object (Self.Internal); Self.Internal := null; end Unload; function Load_Sub_Program (From_Library : in Handles) return Access_To_Sub_Program is -- TODO: How can I get rid of this Address use? function To_Sub_Program is new Ada.Unchecked_Conversion (Source => System.Address, Target => Access_To_Sub_Program); function SDL_Load_Function (H : in Internal_Handle_Access; N : in C.Strings.chars_ptr) return System.Address with Import => True, Convention => C, External_Name => "SDL_LoadFunction"; C_Str : C.Strings.chars_ptr := C.Strings.New_String (Name); Func_Ptr : constant System.Address := SDL_Load_Function (From_Library.Internal, C_Str); use type System.Address; begin C.Strings.Free (C_Str); if Func_Ptr = System.Null_Address then raise Library_Error with SDL.Error.Get; end if; -- return To_Sub_Program (Func_Ptr); return To_Sub_Program (Func_Ptr); end Load_Sub_Program; overriding procedure Finalize (Self : in out Handles) is begin -- In case the user has already called Unload or Finalize on a derived type. if Self.Internal /= null then Unload (Self); end if; end Finalize; end SDL.Libraries;
mgrojo/smk
Ada
1,227
adb
-- ----------------------------------------------------------------------------- -- smk, the smart make -- © 2018 Lionel Draghi <[email protected]> -- SPDX-License-Identifier: APSL-2.0 -- ----------------------------------------------------------------------------- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- http://www.apache.org/licenses/LICENSE-2.0 -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- ----------------------------------------------------------------------------- with Ada.Text_IO; use Ada.Text_IO; separate (Smk.Main) -- ----------------------------------------------------------------------------- procedure Put_Error (Msg : in String := ""; With_Help : in Boolean := False) is begin IO.Put_Error (Msg); if With_Help then Put_Help; end if; end Put_Error;
stcarrez/mat
Ada
1,652
ads
----------------------------------------------------------------------- -- mat-readers -- Reader -- Copyright (C) 2014, 2015 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with System; with Util.Streams.Buffered; with MAT.Events; package MAT.Readers is type Buffer_Type is private; type Buffer_Ptr is access all Buffer_Type; type Message_Type is record Kind : MAT.Events.Event_Type; Size : Natural; Buffer : Buffer_Ptr; end record; subtype Message is Message_Type; type Endian_Type is (BIG_ENDIAN, LITTLE_ENDIAN); -- Get the buffer endian format. function Get_Endian (Msg : in Message_Type) return Endian_Type; private type Buffer_Type is record Current : System.Address; Start : System.Address; Last : System.Address; Buffer : Util.Streams.Buffered.Buffer_Access; Size : Natural; Total : Natural; Endian : Endian_Type := LITTLE_ENDIAN; end record; end MAT.Readers;
zhmu/ananas
Ada
3,784
ads
------------------------------------------------------------------------------ -- -- -- GNAT COMPILER COMPONENTS -- -- -- -- G N A T . C O M P I L E R _ V E R S I O N -- -- -- -- S p e c -- -- -- -- Copyright (C) 2002-2022, AdaCore -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- GNAT was originally developed by the GNAT team at New York University. -- -- Extensive contributions were provided by Ada Core Technologies Inc. -- -- -- ------------------------------------------------------------------------------ -- This package provides a routine for obtaining the version number of the -- GNAT compiler used to compile the program. It relies on the generated -- constant in the binder generated package that records this information. -- Note: to use this package you must first instantiate it, for example: -- package CVer is new GNAT.Compiler_Version; -- and then you use the function in the instantiated package (Cver.Version). -- The reason that this unit is generic is that otherwise the direct attempt -- to import the necessary variable from the binder file causes trouble when -- building a shared library, since the symbol is not available. -- Note: this unit is only useable if the main program is written in Ada. -- It cannot be used if the main program is written in foreign language. generic package GNAT.Compiler_Version is pragma Pure; function Version return String; -- This function returns the version in the form "v.vvx (yyyyddmm)". -- Here v.vv is the main version number (e.g. 3.16), x is the version -- designator (e.g. a1 in 3.16a1), and yyyyddmm is the date in ISO form. -- An example of the returned value would be "3.16w (20021029)". The -- version is actually that of the binder used to bind the program, -- which will be the same as the compiler version if a consistent -- set of tools is used to build the program. end GNAT.Compiler_Version;
burratoo/Acton
Ada
3,265
ads
------------------------------------------------------------------------------------------ -- -- -- OAK CORE SUPPORT PACKAGE -- -- ARM CORTEX M4F -- -- -- -- OAK.CORE_SUPPORT_PACKAGE.CALL_STACK -- -- -- -- Copyright (C) 2014-2021, Patrick Bernardi -- -- -- ------------------------------------------------------------------------------------------ with System.Storage_Elements; package Oak.Core_Support_Package.Call_Stack with Pure is -- Call_Stack_Alignment in bytes Call_Stack_Allignment : constant := 8; Oak_Call_Stack_Size : constant := 2 * 1024; Minimum_Call_Stack_Size : constant := 512; Sleep_Stack_Size : constant := 72; -- Warning! These are not a real variable. It is defined in the linker -- script and as such does not have any data storage allocated for it. -- Instead only a memory address is attached. Stack_Pointer_Init : constant System.Storage_Elements.Storage_Element with Import, Convention => Assembler, External_Name => "__stack_space_start"; Stack_Pointer_End : constant System.Storage_Elements.Storage_Element with Import, Convention => Assembler, External_Name => "__stack_space_end"; -- -- SPRG0 -> Kernel stack pointer -- SPRG4 -> Task stack pointer. -- -- Storing Registers on the Stack during a context switch for tasks: -- ----------------------------- -- | GPR0 | -- -- | GPR13 - 2 | |- 64 bit registers -- -- | GPR31 -> GPR14 | | | -- | Accumulator | -- | -- | SPEFSCR | -- | -- 284 bytes! -- | XER | | | -- | LR | | | -- | CTR | |- 32 bit registers -- -- | CR | | -- | USPRG0 | | -- | Instruction Pointer | <---- Bottom of stack -- ----------------------------- -- Storing Registers on the Stack during a context switch for the kernel: -- ----------------------------- -- | GPR0 | -- -- | GPR13 - 2 | | -- | GPR31 -> GPR14 | | -- | XER | | 37 x 32 bit registers -- 144 bytes! -- | LR | | -- | CTR | | -- | CR | | -- | USPRG0 | | -- | Instruction Pointer | <---- Bottom of stack -- ----------------------------- end Oak.Core_Support_Package.Call_Stack;
Fabien-Chouteau/coffee-clock
Ada
7,105
adb
------------------------------------------------------------------------------- -- -- -- Coffee Clock -- -- -- -- Copyright (C) 2016-2017 Fabien Chouteau -- -- -- -- Coffee Clock is free software: you can redistribute it and/or -- -- modify it under the terms of the GNU General Public License as -- -- published by the Free Software Foundation, either version 3 of the -- -- License, or (at your option) any later version. -- -- -- -- Coffee Clock is distributed in the hope that it will be useful, -- -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- -- General Public License for more details. -- -- -- -- You should have received a copy of the GNU General Public License -- -- along with We Noise Maker. If not, see <http://www.gnu.org/licenses/>. -- -- -- ------------------------------------------------------------------------------- with Giza.Colors; use Giza.Colors; with Giza.Bitmap_Fonts.FreeSansBold18pt7b; package body Date_Widget is package Selected_Font renames Giza.Bitmap_Fonts.FreeSansBold18pt7b; function Image (Day_Of_Week : RTC_Day_Of_Week) return String; function Image (Month : RTC_Month) return String; function Image (Day : RTC_Day) return String; function Image (Year : RTC_Year) return String; ---------- -- Next -- ---------- function Next (Day_Of_Week : RTC_Day_Of_Week) return RTC_Day_Of_Week is begin if Day_Of_Week = RTC_Day_Of_Week'Last then return RTC_Day_Of_Week'First; else return RTC_Day_Of_Week'Succ (Day_Of_Week); end if; end Next; ---------- -- Prev -- ---------- function Prev (Day_Of_Week : RTC_Day_Of_Week) return RTC_Day_Of_Week is begin if Day_Of_Week = RTC_Day_Of_Week'First then return RTC_Day_Of_Week'Last; else return RTC_Day_Of_Week'Pred (Day_Of_Week); end if; end Prev; ---------- -- Next -- ---------- function Next (Month : RTC_Month) return RTC_Month is begin if Month = RTC_Month'Last then return RTC_Month'First; else return RTC_Month'Succ (Month); end if; end Next; ---------- -- Prev -- ---------- function Prev (Month : RTC_Month) return RTC_Month is begin if Month = RTC_Month'First then return RTC_Month'Last; else return RTC_Month'Pred (Month); end if; end Prev; ---------- -- Next -- ---------- function Next (Day : RTC_Day) return RTC_Day is begin if Day = RTC_Day'Last then return RTC_Day'First; else return RTC_Day'Succ (Day); end if; end Next; ---------- -- Prev -- ---------- function Prev (Day : RTC_Day) return RTC_Day is begin if Day = RTC_Day'First then return RTC_Day'Last; else return RTC_Day'Pred (Day); end if; end Prev; ---------- -- Next -- ---------- function Next (Year : RTC_Year) return RTC_Year is begin if Year = RTC_Year'Last then return RTC_Year'First; else return RTC_Year'Succ (Year); end if; end Next; ---------- -- Prev -- ---------- function Prev (Year : RTC_Year) return RTC_Year is begin if Year = RTC_Year'First then return RTC_Year'Last; else return RTC_Year'Pred (Year); end if; end Prev; ----------- -- Image -- ----------- function Image (Day_Of_Week : RTC_Day_Of_Week) return String is (case Day_Of_Week is when Monday => "Monday", when Tuesday => "Tuesday", when Wednesday => "Wednesday", when Thursday => "Thursday", when Friday => "Friday", when Saturday => "Saturday", when Sunday => "Sunday"); ----------- -- Image -- ----------- function Image (Month : RTC_Month) return String is (case Month is when January => "January", when February => "February", when March => "March", when April => "April", when May => "May", when June => "June", when July => "July", when August => "August", when September => "September", when October => "October", when November => "November", when December => "December"); ----------- -- Image -- ----------- function Image (Day : RTC_Day) return String is begin return Day'Img & (case Day is when 1 | 21 | 31 => "st", when 2 | 22 => "nd", when 3 | 23 => "rd", when others => "th"); end Image; ----------- -- Image -- ----------- function Image (Year : RTC_Year) return String is Str : constant String := Year'Img; begin -- Remove the whitespace prefix of Ada's 'Image... return (if Year < 10 then "200" else "20") & Str (Str'First + 1 .. Str'Last); end Image; ---------- -- Draw -- ---------- overriding procedure Draw (This : in out Instance; Ctx : in out Giza.Context.Class; Force : Boolean := True) is begin if not This.Dirty and then not Force then return; end if; Ctx.Set_Color (Black); Ctx.Fill_Rectangle (((0, 0), This.Get_Size)); Ctx.Set_Font (Selected_Font.Font); Ctx.Set_Color (Red); Ctx.Print_In_Rect ((if This.Show_Day_Of_Week then Image (This.Date.Day_Of_Week) & ", " else "") & Image (This.Date.Month) & Image (This.Date.Day) & ", " & Image (This.Date.Year), ((0, 0), This.Get_Size)); end Draw; -------------- -- Set_Date -- -------------- procedure Set_Date (This : in out Instance; Date : HAL.Real_Time_Clock.RTC_Date) is begin This.Date := Date; This.Set_Dirty; end Set_Date; -------------- -- Get_Date -- -------------- function Get_Date (This : Instance) return HAL.Real_Time_Clock.RTC_Date is (This.Date); ------------------- -- Required_Size -- ------------------- function Required_Size (This : Instance) return Size_T is pragma Unreferenced (This); begin return (400, 100); end Required_Size; end Date_Widget;
Fabien-Chouteau/lvgl-ada
Ada
6,253
ads
with System; with Lv.Style; package Lv.Objx.Calendar is subtype Instance is Obj_T; type Date_T is record Year : aliased Uint16_T; Month : aliased Int8_T; Day : aliased Int8_T; end record; pragma Convention (C_Pass_By_Copy, Date_T); type Style_T is (Style_BG, -- Also the style of the "normal" date numbers Style_HEADER, Style_HEADER_PR, Style_DAY_NAMES, Style_HIGHLIGHTED_DAYS, Style_INACTIVE_DAYS, Style_WEEK_BOX, Style_TODAY_BOX); type Date_Array is array (Natural range <>) of aliased Date_T with Convention => C; pragma Suppress (All_Checks, Date_Array); -- Create a calendar objects -- @param par pointer to an object, it will be the parent of the new calendar -- @param copy pointer to a calendar object, if not NULL then the new object will be copied from it -- @return pointer to the created calendar function Create (Parent : Obj_T; Copy : Instance) return Instance; ---------------------- -- Setter functions -- ---------------------- -- Set the today's date -- @param self pointer to a calendar object -- @param today pointer to an `lv_calendar_date_t` variable containing the date of today. The value will be saved it can be local variable too. procedure Set_Today_Date (Self : Instance; Today : access Date_T); -- Set the currently showed -- @param self pointer to a calendar object -- @param showed pointer to an `lv_calendar_date_t` variable containing the date to show. The value will be saved it can be local variable too. procedure Set_Showed_Date (Self : Instance; Showed : access Date_T); -- Set the the highlighted dates -- @param self pointer to a calendar object -- @param highlighted pointer to an `lv_calendar_date_t` array containing the dates. ONLY A POINTER WILL BE SAVED! CAN'T BE LOCAL ARRAY. -- @param date_num number of dates in the array procedure Set_Highlighted_Dates (Self : Instance; Highlighted : access constant Date_Array; Date_Num : Uint16_T); -- Set the name of the days -- @param self pointer to a calendar object -- @param day_names pointer to an array with the names. E.g. `const char -- days[7] = {"Sun", "Mon", ...}` -- Only the pointer will be saved so this variable can't be local which will be destroyed later. procedure Set_Day_Names (Self : Instance; Day_Names : access constant String_Array); -- Set the name of the month -- @param self pointer to a calendar object -- @param month_names pointer to an array with the names. E.g. `const char -- days[12] = {"Jan", "Feb", ...}` -- Only the pointer will be saved so this variable can't be local which will be destroyed later. procedure Set_Month_Names (Self : Instance; Month_Names : access constant String_Array); -- Set a style of a calendar. -- @param self pointer to calendar object -- @param type which style should be set -- @param style pointer to a style procedure Set_Style (Self : Instance; Type_P : Style_T; Style : Lv.Style.Style); ---------------------- -- Getter functions -- ---------------------- -- Get the today's date -- @param self pointer to a calendar object -- @return return pointer to an `lv_calendar_date_t` variable containing the date of today. function Today_Date (Self : Instance) return access Date_T; -- Get the currently showed -- @param self pointer to a calendar object -- @return pointer to an `lv_calendar_date_t` variable containing the date is being shown. function Showed_Date (Self : Instance) return access Date_T; -- Get the the highlighted dates -- @param self pointer to a calendar object -- @return pointer to an `lv_calendar_date_t` array containing the dates. function Highlighted_Dates (Self : Instance) return access Date_T; -- Get the number of the highlighted dates -- @param self pointer to a calendar object -- @return number of highlighted days function Highlighted_Dates_Num (Self : Instance) return Uint16_T; -- Get the name of the days -- @param self pointer to a calendar object -- @return pointer to the array of day names function Day_Names (Self : Instance) return System.Address; -- Get the name of the month -- @param self pointer to a calendar object -- @return pointer to the array of month names function Month_Names (Self : Instance) return System.Address; -- Get style of a calendar. -- @param self pointer to calendar object -- @param type which style should be get -- @return style pointer to the style function Style (Self : Instance; Type_P : Style_T) return Lv.Style.Style; ------------- -- Imports -- ------------- pragma Import (C, Create, "lv_calendar_create"); pragma Import (C, Set_Today_Date, "lv_calendar_set_today_date"); pragma Import (C, Set_Showed_Date, "lv_calendar_set_showed_date"); pragma Import (C, Set_Highlighted_Dates, "lv_calendar_set_highlighted_dates"); pragma Import (C, Set_Day_Names, "lv_calendar_set_day_names"); pragma Import (C, Set_Month_Names, "lv_calendar_set_month_names"); pragma Import (C, Set_Style, "lv_calendar_set_style"); pragma Import (C, Today_Date, "lv_calendar_get_today_date"); pragma Import (C, Showed_Date, "lv_calendar_get_showed_date"); pragma Import (C, Highlighted_Dates, "lv_calendar_get_highlighted_dates"); pragma Import (C, Highlighted_Dates_Num, "lv_calendar_get_highlighted_dates_num"); pragma Import (C, Day_Names, "lv_calendar_get_day_names"); pragma Import (C, Month_Names, "lv_calendar_get_month_names"); pragma Import (C, Style, "lv_calendar_get_style"); for Style_T'Size use 8; for Style_T use (Style_BG => 0, Style_HEADER => 1, Style_HEADER_PR => 2, Style_DAY_NAMES => 3, Style_HIGHLIGHTED_DAYS => 4, Style_INACTIVE_DAYS => 5, Style_WEEK_BOX => 6, Style_TODAY_BOX => 7); end Lv.Objx.Calendar;
stcarrez/ada-asf
Ada
13,669
adb
----------------------------------------------------------------------- -- Faces Context Tests - Unit tests for ASF.Contexts.Faces -- Copyright (C) 2010, 2011, 2012, 2013, 2015, 2018, 2019, 2023 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Calendar; with Ada.Calendar.Formatting; with Ada.Unchecked_Deallocation; with Ada.Strings.UTF_Encoding.Wide_Wide_Strings; with Util.Beans.Objects.Time; with Util.Test_Caller; with Util.Dates; with ASF.Tests; with ASF.Components.Html.Text; with ASF.Converters.Dates; with ASF.Converters.Numbers; package body ASF.Converters.Tests is -- This file contains Wide_Wide_String constants. pragma Wide_Character_Encoding (UTF8); use Util.Tests; use ASF.Converters.Dates; package Caller is new Util.Test_Caller (Test, "Converters"); procedure Test_Date_Conversion (T : in out Test; Date_Style : in Dates.Style_Type; Time_Style : in Dates.Style_Type; Expect : in String); procedure Test_Conversion_Error (T : in out Test; Value : in String); procedure Test_Number_Conversion (T : in out Test; Picture : in String; Value : in Float; Expect : in Wide_Wide_String); procedure Add_Tests (Suite : in Util.Tests.Access_Test_Suite) is begin -- To document what is tested, register the test methods for each -- operation that is tested. Caller.Add_Test (Suite, "Test ASF.Converters.Dates.To_String (Date, Short)", Test_Date_Short_Converter'Access); Caller.Add_Test (Suite, "Test ASF.Converters.Dates.To_String (Date, Medium)", Test_Date_Medium_Converter'Access); Caller.Add_Test (Suite, "Test ASF.Converters.Dates.To_String (Date, Long)", Test_Date_Long_Converter'Access); Caller.Add_Test (Suite, "Test ASF.Converters.Dates.To_String (Date, Full)", Test_Date_Full_Converter'Access); Caller.Add_Test (Suite, "Test ASF.Converters.Dates.To_String (Time, Short)", Test_Time_Short_Converter'Access); Caller.Add_Test (Suite, "Test ASF.Converters.Dates.To_String (Time, Medium)", Test_Time_Medium_Converter'Access); Caller.Add_Test (Suite, "Test ASF.Converters.Dates.To_String (Time, Long)", Test_Time_Long_Converter'Access); Caller.Add_Test (Suite, "Test ASF.Converters.Dates.To_Object (Error)", Test_Date_Converter_Error'Access); Caller.Add_Test (Suite, "Test ASF.Converters.Numbers.To_String (Float)", Test_Number_Converter'Access); end Add_Tests; -- ------------------------------ -- Test getting an attribute from the faces context. -- ------------------------------ procedure Test_Date_Conversion (T : in out Test; Date_Style : in Dates.Style_Type; Time_Style : in Dates.Style_Type; Expect : in String) is procedure Free is new Ada.Unchecked_Deallocation (Object => ASF.Converters.Dates.Date_Converter'Class, Name => ASF.Converters.Dates.Date_Converter_Access); Ctx : aliased ASF.Contexts.Faces.Faces_Context; UI : ASF.Components.Html.Text.UIOutput; C : ASF.Converters.Dates.Date_Converter_Access; D : constant Ada.Calendar.Time := Ada.Calendar.Formatting.Time_Of (2011, 11, 19, 3, 4, 5); begin T.Setup (Ctx); ASF.Contexts.Faces.Set_Current (Ctx'Unchecked_Access, ASF.Tests.Get_Application.all'Access); if Date_Style = Dates.DEFAULT then C := ASF.Converters.Dates.Create_Date_Converter (Date => Date_Style, Time => Time_Style, Format => ASF.Converters.Dates.TIME, Locale => "en", Pattern => ""); elsif Time_Style = Dates.DEFAULT then C := ASF.Converters.Dates.Create_Date_Converter (Date => Date_Style, Time => Time_Style, Format => ASF.Converters.Dates.DATE, Locale => "en", Pattern => ""); else C := ASF.Converters.Dates.Create_Date_Converter (Date => Date_Style, Time => Time_Style, Format => ASF.Converters.Dates.BOTH, Locale => "en", Pattern => ""); end if; UI.Set_Converter (C.all'Access); declare R : constant String := C.To_String (Ctx, UI, Util.Beans.Objects.Time.To_Object (D)); V : Util.Beans.Objects.Object; S : Util.Dates.Date_Record; begin Util.Tests.Assert_Equals (T, Expect, R, "Invalid date conversion"); V := C.To_Object (Ctx, UI, R); Util.Dates.Split (Into => S, Date => Util.Beans.Objects.Time.To_Time (V)); if Date_Style /= Dates.DEFAULT then T.Assert (Util.Dates.Is_Same_Day (Util.Beans.Objects.Time.To_Time (V), D), "Invalid date"); else Util.Tests.Assert_Equals (T, 3, Natural (S.Hour), "Invalid date conversion: hour"); Util.Tests.Assert_Equals (T, 4, Natural (S.Minute), "Invalid date conversion: minute"); if Time_Style = Dates.LONG then Util.Tests.Assert_Equals (T, 5, Natural (S.Second), "Invalid date conversion: second"); end if; end if; exception when others => T.Fail ("Exception when converting date string: " & R); end; Free (C); end Test_Date_Conversion; -- ------------------------------ -- Test the date short converter. -- ------------------------------ procedure Test_Date_Short_Converter (T : in out Test) is begin Test_Date_Conversion (T, ASF.Converters.Dates.SHORT, ASF.Converters.Dates.DEFAULT, "19/11/2011"); end Test_Date_Short_Converter; -- ------------------------------ -- Test the date medium converter. -- ------------------------------ procedure Test_Date_Medium_Converter (T : in out Test) is begin Test_Date_Conversion (T, ASF.Converters.Dates.MEDIUM, ASF.Converters.Dates.DEFAULT, "Nov 19, 2011"); end Test_Date_Medium_Converter; -- ------------------------------ -- Test the date long converter. -- ------------------------------ procedure Test_Date_Long_Converter (T : in out Test) is begin Test_Date_Conversion (T, ASF.Converters.Dates.LONG, ASF.Converters.Dates.DEFAULT, "November 19, 2011"); end Test_Date_Long_Converter; -- ------------------------------ -- Test the date full converter. -- ------------------------------ procedure Test_Date_Full_Converter (T : in out Test) is begin Test_Date_Conversion (T, ASF.Converters.Dates.FULL, ASF.Converters.Dates.DEFAULT, "Saturday, November 19, 2011"); end Test_Date_Full_Converter; -- ------------------------------ -- Test the time short converter. -- ------------------------------ procedure Test_Time_Short_Converter (T : in out Test) is begin Test_Date_Conversion (T, ASF.Converters.Dates.DEFAULT, ASF.Converters.Dates.SHORT, "03:04"); end Test_Time_Short_Converter; -- ------------------------------ -- Test the time short converter. -- ------------------------------ procedure Test_Time_Medium_Converter (T : in out Test) is begin Test_Date_Conversion (T, ASF.Converters.Dates.DEFAULT, ASF.Converters.Dates.MEDIUM, "03:04"); end Test_Time_Medium_Converter; -- ------------------------------ -- Test the time long converter. -- ------------------------------ procedure Test_Time_Long_Converter (T : in out Test) is begin Test_Date_Conversion (T, ASF.Converters.Dates.DEFAULT, ASF.Converters.Dates.LONG, "03:04:05"); end Test_Time_Long_Converter; -- ------------------------------ -- Test getting an attribute from the faces context. -- ------------------------------ procedure Test_Conversion_Error (T : in out Test; Value : in String) is procedure Free is new Ada.Unchecked_Deallocation (Object => ASF.Converters.Dates.Date_Converter'Class, Name => ASF.Converters.Dates.Date_Converter_Access); Ctx : aliased ASF.Contexts.Faces.Faces_Context; UI : ASF.Components.Html.Text.UIOutput; C : ASF.Converters.Dates.Date_Converter_Access; begin T.Setup (Ctx); ASF.Contexts.Faces.Set_Current (Ctx'Unchecked_Access, ASF.Tests.Get_Application.all'Access); C := ASF.Converters.Dates.Create_Date_Converter (Date => ASF.Converters.Dates.LONG, Time => ASF.Converters.Dates.LONG, Format => ASF.Converters.Dates.BOTH, Locale => "en", Pattern => ""); UI.Set_Converter (C.all'Access); declare V : Util.Beans.Objects.Object; pragma Unreferenced (V); begin V := C.To_Object (Ctx, UI, Value); T.Fail ("No exception raised for " & Value); exception when Invalid_Conversion => null; end; Free (C); end Test_Conversion_Error; -- ------------------------------ -- Test converter reporting conversion errors when converting a string back to a date. -- ------------------------------ procedure Test_Date_Converter_Error (T : in out Test) is begin Test_Conversion_Error (T, "some invalid date"); end Test_Date_Converter_Error; -- Test number converter. procedure Test_Number_Conversion (T : in out Test; Picture : in String; Value : in Float; Expect : in Wide_Wide_String) is procedure Free is new Ada.Unchecked_Deallocation (Object => ASF.Converters.Numbers.Number_Converter'Class, Name => ASF.Converters.Numbers.Number_Converter_Access); Ctx : aliased ASF.Contexts.Faces.Faces_Context; UI : ASF.Components.Html.Text.UIOutput; C : ASF.Converters.Numbers.Number_Converter_Access; D : constant Util.Beans.Objects.Object := Util.Beans.Objects.To_Object (Value); begin T.Setup (Ctx); ASF.Contexts.Faces.Set_Current (Ctx'Unchecked_Access, ASF.Tests.Get_Application.all'Access); C := new ASF.Converters.Numbers.Number_Converter; UI.Set_Converter (C.all'Access); C.Set_Picture (Picture); declare use Ada.Strings.UTF_Encoding; R : constant String := C.To_String (Ctx, UI, D); begin Util.Tests.Assert_Equals (T, Wide_Wide_Strings.Encode (Expect), R, "Invalid number conversion with picture " & Picture); end; Free (C); end Test_Number_Conversion; -- ------------------------------ -- Test converter reporting conversion errors when converting a string back to a date. -- ------------------------------ procedure Test_Number_Converter (T : in out Test) is begin Test_Number_Conversion (T, "Z9.99", 12.345323, "12.35"); Test_Number_Conversion (T, "Z9.99", 2.334323, " 2.33"); Test_Number_Conversion (T, "<$Z_ZZ9.99>", 2.334323, " € 2.33 "); Test_Number_Conversion (T, "Z_ZZ9.99B$", 2.334323, " 2.33 €"); Test_Number_Conversion (T, "Z_ZZ9.99B$", 2342.334323, "2,342.33 €"); -- Test_Number_Conversion (T, "Z_ZZ9.99B$", 21342.334323, "2,342.33 €"); end Test_Number_Converter; end ASF.Converters.Tests;
reznikmm/matreshka
Ada
4,153
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with ODF.DOM.Draw_Start_Line_Spacing_Horizontal_Attributes; package Matreshka.ODF_Draw.Start_Line_Spacing_Horizontal_Attributes is type Draw_Start_Line_Spacing_Horizontal_Attribute_Node is new Matreshka.ODF_Draw.Abstract_Draw_Attribute_Node and ODF.DOM.Draw_Start_Line_Spacing_Horizontal_Attributes.ODF_Draw_Start_Line_Spacing_Horizontal_Attribute with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Draw_Start_Line_Spacing_Horizontal_Attribute_Node; overriding function Get_Local_Name (Self : not null access constant Draw_Start_Line_Spacing_Horizontal_Attribute_Node) return League.Strings.Universal_String; end Matreshka.ODF_Draw.Start_Line_Spacing_Horizontal_Attributes;
OneWingedShark/Byron
Ada
1,305
adb
Pragma Ada_2012; Pragma Assertion_Policy( Check ); With Ada.Wide_Wide_Characters.Handling, Byron.Internals.SPARK.Pure_Types; -- Byron.Internals.SPARK.Functions is a package package for internal functions -- which are verified and proven via SPARK-mode. Package Body Byron.Internals.SPARK.Functions with SPARK_Mode => On is Function Equal_Case_Insensitive( Left, Right : Internal_String ) return Boolean is Package ACH renames Ada.Wide_Wide_Characters.Handling; Function Lower_Equal(Left, Right : Wide_Wide_Character)return Boolean is (ACH.To_Lower(Left) = ACH.To_Lower(Right)) with Pure_Function, Inline_Always; Begin Return Result : Boolean := Left'Length = Right'Length and then (For all Offset in 0..Natural'Pred(Right'Length) => Lower_Equal (Left(Left'First+Offset), Right(Right'First+Offset)) ); End Equal_Case_Insensitive; Function "="(Left, Right : Internal_String) return Boolean renames Equal_Case_Insensitive with Pure_Function; Function "+"(Right : Identifier) return Internal_String is ( Internal_String(Right) ) with Pure_Function, Global => Null, Inline, Depends => ("+"'Result =>(Right)); Function Equal_Case_Insensitive( Left, Right : Identifier ) return Boolean is ((+Left) = (+Right)); End Byron.Internals.SPARK.Functions;
zhmu/ananas
Ada
128,015
adb
------------------------------------------------------------------------------ -- -- -- GNAT LIBRARY COMPONENTS -- -- -- -- A D A . C O N T A I N E R S . I N D E F I N I T E _ V E C T O R S -- -- -- -- B o d y -- -- -- -- Copyright (C) 2004-2022, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- -- ware Foundation; either version 3, or (at your option) any later ver- -- -- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- -- or FITNESS FOR A PARTICULAR PURPOSE. -- -- -- -- As a special exception under Section 7 of GPL version 3, you are granted -- -- additional permissions described in the GCC Runtime Library Exception, -- -- version 3.1, as published by the Free Software Foundation. -- -- -- -- You should have received a copy of the GNU General Public License and -- -- a copy of the GCC Runtime Library Exception along with this program; -- -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- -- <http://www.gnu.org/licenses/>. -- -- -- -- This unit was originally developed by Matthew J Heaney. -- ------------------------------------------------------------------------------ with Ada.Containers.Generic_Array_Sort; with Ada.Unchecked_Deallocation; with System; use type System.Address; with System.Put_Images; package body Ada.Containers.Indefinite_Vectors with SPARK_Mode => Off is pragma Warnings (Off, "variable ""Busy*"" is not referenced"); pragma Warnings (Off, "variable ""Lock*"" is not referenced"); -- See comment in Ada.Containers.Helpers procedure Free is new Ada.Unchecked_Deallocation (Elements_Type, Elements_Access); procedure Free is new Ada.Unchecked_Deallocation (Element_Type, Element_Access); procedure Append_Slow_Path (Container : in out Vector; New_Item : Element_Type; Count : Count_Type); -- This is the slow path for Append. This is split out to minimize the size -- of Append, because we have Inline (Append). --------- -- "&" -- --------- -- We decide that the capacity of the result of "&" is the minimum needed -- -- the sum of the lengths of the vector parameters. We could decide to -- make it larger, but we have no basis for knowing how much larger, so we -- just allocate the minimum amount of storage. function "&" (Left, Right : Vector) return Vector is begin return Result : Vector do Reserve_Capacity (Result, Length (Left) + Length (Right)); Append_Vector (Result, Left); Append_Vector (Result, Right); end return; end "&"; function "&" (Left : Vector; Right : Element_Type) return Vector is begin return Result : Vector do Reserve_Capacity (Result, Length (Left) + 1); Append_Vector (Result, Left); Append (Result, Right); end return; end "&"; function "&" (Left : Element_Type; Right : Vector) return Vector is begin return Result : Vector do Reserve_Capacity (Result, 1 + Length (Right)); Append (Result, Left); Append_Vector (Result, Right); end return; end "&"; function "&" (Left, Right : Element_Type) return Vector is begin return Result : Vector do Reserve_Capacity (Result, 1 + 1); Append (Result, Left); Append (Result, Right); end return; end "&"; --------- -- "=" -- --------- overriding function "=" (Left, Right : Vector) return Boolean is begin if Left.Last /= Right.Last then return False; end if; if Left.Length = 0 then return True; end if; declare -- Per AI05-0022, the container implementation is required to detect -- element tampering by a generic actual subprogram. Lock_Left : With_Lock (Left.TC'Unrestricted_Access); Lock_Right : With_Lock (Right.TC'Unrestricted_Access); begin for J in Index_Type range Index_Type'First .. Left.Last loop if Left.Elements.EA (J) = null then if Right.Elements.EA (J) /= null then return False; end if; elsif Right.Elements.EA (J) = null then return False; elsif Left.Elements.EA (J).all /= Right.Elements.EA (J).all then return False; end if; end loop; end; return True; end "="; ------------ -- Adjust -- ------------ procedure Adjust (Container : in out Vector) is begin -- If the counts are nonzero, execution is technically erroneous, but -- it seems friendly to allow things like concurrent "=" on shared -- constants. Zero_Counts (Container.TC); if Container.Last = No_Index then Container.Elements := null; return; end if; declare L : constant Index_Type := Container.Last; E : Elements_Array renames Container.Elements.EA (Index_Type'First .. L); begin Container.Elements := null; Container.Last := No_Index; Container.Elements := new Elements_Type (L); for J in E'Range loop if E (J) /= null then Container.Elements.EA (J) := new Element_Type'(E (J).all); end if; Container.Last := J; end loop; end; end Adjust; ------------------- -- Append_Vector -- ------------------- procedure Append_Vector (Container : in out Vector; New_Item : Vector) is begin if Is_Empty (New_Item) then return; elsif Checks and then Container.Last = Index_Type'Last then raise Constraint_Error with "vector is already at its maximum length"; else Insert_Vector (Container, Container.Last + 1, New_Item); end if; end Append_Vector; procedure Append (Container : in out Vector; New_Item : Element_Type; Count : Count_Type) is begin -- In the general case, we pass the buck to Insert, but for efficiency, -- we check for the usual case where Count = 1 and the vector has enough -- room for at least one more element. if Count = 1 and then Container.Elements /= null and then Container.Last /= Container.Elements.Last then TC_Check (Container.TC); -- Increment Container.Last after assigning the New_Item, so we -- leave the Container unmodified in case Finalize/Adjust raises -- an exception. declare New_Last : constant Index_Type := Container.Last + 1; -- The element allocator may need an accessibility check in the -- case actual type is class-wide or has access discriminants -- (see RM 4.8(10.1) and AI12-0035). pragma Unsuppress (Accessibility_Check); begin Container.Elements.EA (New_Last) := new Element_Type'(New_Item); Container.Last := New_Last; end; else Append_Slow_Path (Container, New_Item, Count); end if; end Append; ------------ -- Append -- ------------ procedure Append (Container : in out Vector; New_Item : Element_Type) is begin Insert (Container, Last_Index (Container) + 1, New_Item, 1); end Append; ---------------------- -- Append_Slow_Path -- ---------------------- procedure Append_Slow_Path (Container : in out Vector; New_Item : Element_Type; Count : Count_Type) is begin if Count = 0 then return; elsif Checks and then Container.Last = Index_Type'Last then raise Constraint_Error with "vector is already at its maximum length"; else Insert (Container, Container.Last + 1, New_Item, Count); end if; end Append_Slow_Path; ------------ -- Assign -- ------------ procedure Assign (Target : in out Vector; Source : Vector) is begin if Target'Address = Source'Address then return; else Target.Clear; Target.Append_Vector (Source); end if; end Assign; -------------- -- Capacity -- -------------- function Capacity (Container : Vector) return Count_Type is begin if Container.Elements = null then return 0; else return Container.Elements.EA'Length; end if; end Capacity; ----------- -- Clear -- ----------- procedure Clear (Container : in out Vector) is begin TC_Check (Container.TC); while Container.Last >= Index_Type'First loop declare X : Element_Access := Container.Elements.EA (Container.Last); begin Container.Elements.EA (Container.Last) := null; Container.Last := Container.Last - 1; Free (X); end; end loop; end Clear; ------------------------ -- Constant_Reference -- ------------------------ function Constant_Reference (Container : aliased Vector; Position : Cursor) return Constant_Reference_Type is begin if Checks then if Position.Container = null then raise Constraint_Error with "Position cursor has no element"; end if; if Position.Container /= Container'Unrestricted_Access then raise Program_Error with "Position cursor denotes wrong container"; end if; if Position.Index > Position.Container.Last then raise Constraint_Error with "Position cursor is out of range"; end if; end if; declare TC : constant Tamper_Counts_Access := Container.TC'Unrestricted_Access; begin -- The following will raise Constraint_Error if Element is null return R : constant Constant_Reference_Type := (Element => Container.Elements.EA (Position.Index), Control => (Controlled with TC)) do Busy (TC.all); end return; end; end Constant_Reference; function Constant_Reference (Container : aliased Vector; Index : Index_Type) return Constant_Reference_Type is begin if Checks and then Index > Container.Last then raise Constraint_Error with "Index is out of range"; end if; declare TC : constant Tamper_Counts_Access := Container.TC'Unrestricted_Access; begin -- The following will raise Constraint_Error if Element is null return R : constant Constant_Reference_Type := (Element => Container.Elements.EA (Index), Control => (Controlled with TC)) do Busy (TC.all); end return; end; end Constant_Reference; -------------- -- Contains -- -------------- function Contains (Container : Vector; Item : Element_Type) return Boolean is begin return Find_Index (Container, Item) /= No_Index; end Contains; ---------- -- Copy -- ---------- function Copy (Source : Vector; Capacity : Count_Type := 0) return Vector is C : Count_Type; begin if Capacity < Source.Length then if Checks and then Capacity /= 0 then raise Capacity_Error with "Requested capacity is less than Source length"; end if; C := Source.Length; else C := Capacity; end if; return Target : Vector do Target.Reserve_Capacity (C); Target.Assign (Source); end return; end Copy; ------------ -- Delete -- ------------ procedure Delete (Container : in out Vector; Index : Extended_Index; Count : Count_Type := 1) is Old_Last : constant Index_Type'Base := Container.Last; New_Last : Index_Type'Base; Count2 : Count_Type'Base; -- count of items from Index to Old_Last J : Index_Type'Base; -- first index of items that slide down begin -- The tampering bits exist to prevent an item from being deleted (or -- otherwise harmfully manipulated) while it is being visited. Query, -- Update, and Iterate increment the busy count on entry, and decrement -- the count on exit. Delete checks the count to determine whether it is -- being called while the associated callback procedure is executing. TC_Check (Container.TC); -- Delete removes items from the vector, the number of which is the -- minimum of the specified Count and the items (if any) that exist from -- Index to Container.Last. There are no constraints on the specified -- value of Count (it can be larger than what's available at this -- position in the vector, for example), but there are constraints on -- the allowed values of the Index. -- As a precondition on the generic actual Index_Type, the base type -- must include Index_Type'Pred (Index_Type'First); this is the value -- that Container.Last assumes when the vector is empty. However, we do -- not allow that as the value for Index when specifying which items -- should be deleted, so we must manually check. (That the user is -- allowed to specify the value at all here is a consequence of the -- declaration of the Extended_Index subtype, which includes the values -- in the base range that immediately precede and immediately follow the -- values in the Index_Type.) if Checks and then Index < Index_Type'First then raise Constraint_Error with "Index is out of range (too small)"; end if; -- We do allow a value greater than Container.Last to be specified as -- the Index, but only if it's immediately greater. This allows the -- corner case of deleting no items from the back end of the vector to -- be treated as a no-op. (It is assumed that specifying an index value -- greater than Last + 1 indicates some deeper flaw in the caller's -- algorithm, so that case is treated as a proper error.) if Index > Old_Last then if Checks and then Index > Old_Last + 1 then raise Constraint_Error with "Index is out of range (too large)"; else return; end if; end if; -- Here and elsewhere we treat deleting 0 items from the container as a -- no-op, even when the container is busy, so we simply return. if Count = 0 then return; end if; -- The internal elements array isn't guaranteed to exist unless we have -- elements, so we handle that case here in order to avoid having to -- check it later. (Note that an empty vector can never be busy, so -- there's no semantic harm in returning early.) if Container.Is_Empty then return; end if; -- We first calculate what's available for deletion starting at -- Index. Here and elsewhere we use the wider of Index_Type'Base and -- Count_Type'Base as the type for intermediate values. (See function -- Length for more information.) if Count_Type'Base'Last >= Index_Type'Pos (Index_Type'Base'Last) then Count2 := Count_Type'Base (Old_Last) - Count_Type'Base (Index) + 1; else Count2 := Count_Type'Base (Old_Last - Index + 1); end if; -- If the number of elements requested (Count) for deletion is equal to -- (or greater than) the number of elements available (Count2) for -- deletion beginning at Index, then everything from Index to -- Container.Last is deleted (this is equivalent to Delete_Last). if Count >= Count2 then -- Elements in an indefinite vector are allocated, so we must iterate -- over the loop and deallocate elements one-at-a-time. We work from -- back to front, deleting the last element during each pass, in -- order to gracefully handle deallocation failures. declare EA : Elements_Array renames Container.Elements.EA; begin while Container.Last >= Index loop declare K : constant Index_Type := Container.Last; X : Element_Access := EA (K); begin -- We first isolate the element we're deleting, removing it -- from the vector before we attempt to deallocate it, in -- case the deallocation fails. EA (K) := null; Container.Last := K - 1; -- Container invariants have been restored, so it is now -- safe to attempt to deallocate the element. Free (X); end; end loop; end; return; end if; -- There are some elements that aren't being deleted (the requested -- count was less than the available count), so we must slide them down -- to Index. We first calculate the index values of the respective array -- slices, using the wider of Index_Type'Base and Count_Type'Base as the -- type for intermediate calculations. For the elements that slide down, -- index value New_Last is the last index value of their new home, and -- index value J is the first index of their old home. if Index_Type'Base'Last >= Count_Type_Last then New_Last := Old_Last - Index_Type'Base (Count); J := Index + Index_Type'Base (Count); else New_Last := Index_Type'Base (Count_Type'Base (Old_Last) - Count); J := Index_Type'Base (Count_Type'Base (Index) + Count); end if; -- The internal elements array isn't guaranteed to exist unless we have -- elements, but we have that guarantee here because we know we have -- elements to slide. The array index values for each slice have -- already been determined, so what remains to be done is to first -- deallocate the elements that are being deleted, and then slide down -- to Index the elements that aren't being deleted. declare EA : Elements_Array renames Container.Elements.EA; begin -- Before we can slide down the elements that aren't being deleted, -- we need to deallocate the elements that are being deleted. for K in Index .. J - 1 loop declare X : Element_Access := EA (K); begin -- First we remove the element we're about to deallocate from -- the vector, in case the deallocation fails, in order to -- preserve representation invariants. EA (K) := null; -- The element has been removed from the vector, so it is now -- safe to attempt to deallocate it. Free (X); end; end loop; EA (Index .. New_Last) := EA (J .. Old_Last); Container.Last := New_Last; end; end Delete; procedure Delete (Container : in out Vector; Position : in out Cursor; Count : Count_Type := 1) is begin if Checks then if Position.Container = null then raise Constraint_Error with "Position cursor has no element"; elsif Position.Container /= Container'Unrestricted_Access then raise Program_Error with "Position cursor denotes wrong container"; elsif Position.Index > Container.Last then raise Program_Error with "Position index is out of range"; end if; end if; Delete (Container, Position.Index, Count); Position := No_Element; end Delete; ------------------ -- Delete_First -- ------------------ procedure Delete_First (Container : in out Vector; Count : Count_Type := 1) is begin if Count = 0 then return; elsif Count >= Length (Container) then Clear (Container); return; else Delete (Container, Index_Type'First, Count); end if; end Delete_First; ----------------- -- Delete_Last -- ----------------- procedure Delete_Last (Container : in out Vector; Count : Count_Type := 1) is begin -- It is not permitted to delete items while the container is busy (for -- example, we're in the middle of a passive iteration). However, we -- always treat deleting 0 items as a no-op, even when we're busy, so we -- simply return without checking. if Count = 0 then return; end if; -- We cannot simply subsume the empty case into the loop below (the loop -- would iterate 0 times), because we rename the internal array object -- (which is allocated), but an empty vector isn't guaranteed to have -- actually allocated an array. (Note that an empty vector can never be -- busy, so there's no semantic harm in returning early here.) if Container.Is_Empty then return; end if; -- The tampering bits exist to prevent an item from being deleted (or -- otherwise harmfully manipulated) while it is being visited. Query, -- Update, and Iterate increment the busy count on entry, and decrement -- the count on exit. Delete_Last checks the count to determine whether -- it is being called while the associated callback procedure is -- executing. TC_Check (Container.TC); -- Elements in an indefinite vector are allocated, so we must iterate -- over the loop and deallocate elements one-at-a-time. We work from -- back to front, deleting the last element during each pass, in order -- to gracefully handle deallocation failures. declare E : Elements_Array renames Container.Elements.EA; begin for Indx in 1 .. Count_Type'Min (Count, Container.Length) loop declare J : constant Index_Type := Container.Last; X : Element_Access := E (J); begin -- Note that we first isolate the element we're deleting, -- removing it from the vector, before we actually deallocate -- it, in order to preserve representation invariants even if -- the deallocation fails. E (J) := null; Container.Last := J - 1; -- Container invariants have been restored, so it is now safe -- to deallocate the element. Free (X); end; end loop; end; end Delete_Last; ------------- -- Element -- ------------- function Element (Container : Vector; Index : Index_Type) return Element_Type is begin if Checks and then Index > Container.Last then raise Constraint_Error with "Index is out of range"; end if; declare EA : constant Element_Access := Container.Elements.EA (Index); begin if Checks and then EA = null then raise Constraint_Error with "element is empty"; else return EA.all; end if; end; end Element; function Element (Position : Cursor) return Element_Type is begin if Checks then if Position.Container = null then raise Constraint_Error with "Position cursor has no element"; end if; if Position.Index > Position.Container.Last then raise Constraint_Error with "Position cursor is out of range"; end if; end if; declare EA : constant Element_Access := Position.Container.Elements.EA (Position.Index); begin if Checks and then EA = null then raise Constraint_Error with "element is empty"; else return EA.all; end if; end; end Element; ----------- -- Empty -- ----------- function Empty (Capacity : Count_Type := 10) return Vector is begin return Result : Vector do Reserve_Capacity (Result, Capacity); end return; end Empty; -------------- -- Finalize -- -------------- procedure Finalize (Container : in out Vector) is begin Clear (Container); -- Checks busy-bit declare X : Elements_Access := Container.Elements; begin Container.Elements := null; Free (X); end; end Finalize; procedure Finalize (Object : in out Iterator) is begin Unbusy (Object.Container.TC); end Finalize; ---------- -- Find -- ---------- function Find (Container : Vector; Item : Element_Type; Position : Cursor := No_Element) return Cursor is begin if Checks and then Position.Container /= null then if Position.Container /= Container'Unrestricted_Access then raise Program_Error with "Position cursor denotes wrong container"; end if; if Position.Index > Container.Last then raise Program_Error with "Position index is out of range"; end if; end if; -- Per AI05-0022, the container implementation is required to detect -- element tampering by a generic actual subprogram. declare Lock : With_Lock (Container.TC'Unrestricted_Access); begin for J in Position.Index .. Container.Last loop if Container.Elements.EA (J).all = Item then return Cursor'(Container'Unrestricted_Access, J); end if; end loop; return No_Element; end; end Find; ---------------- -- Find_Index -- ---------------- function Find_Index (Container : Vector; Item : Element_Type; Index : Index_Type := Index_Type'First) return Extended_Index is -- Per AI05-0022, the container implementation is required to detect -- element tampering by a generic actual subprogram. Lock : With_Lock (Container.TC'Unrestricted_Access); begin for Indx in Index .. Container.Last loop if Container.Elements.EA (Indx).all = Item then return Indx; end if; end loop; return No_Index; end Find_Index; ----------- -- First -- ----------- function First (Container : Vector) return Cursor is begin if Is_Empty (Container) then return No_Element; end if; return (Container'Unrestricted_Access, Index_Type'First); end First; function First (Object : Iterator) return Cursor is begin -- The value of the iterator object's Index component influences the -- behavior of the First (and Last) selector function. -- When the Index component is No_Index, this means the iterator -- object was constructed without a start expression, in which case the -- (forward) iteration starts from the (logical) beginning of the entire -- sequence of items (corresponding to Container.First, for a forward -- iterator). -- Otherwise, this is iteration over a partial sequence of items. -- When the Index component isn't No_Index, the iterator object was -- constructed with a start expression, that specifies the position -- from which the (forward) partial iteration begins. if Object.Index = No_Index then return First (Object.Container.all); else return Cursor'(Object.Container, Object.Index); end if; end First; ------------------- -- First_Element -- ------------------- function First_Element (Container : Vector) return Element_Type is begin if Checks and then Container.Last = No_Index then raise Constraint_Error with "Container is empty"; end if; declare EA : constant Element_Access := Container.Elements.EA (Index_Type'First); begin if Checks and then EA = null then raise Constraint_Error with "first element is empty"; else return EA.all; end if; end; end First_Element; ----------------- -- New_Vector -- ----------------- function New_Vector (First, Last : Index_Type) return Vector is begin return (To_Vector (Count_Type (Last - First + 1))); end New_Vector; ----------------- -- First_Index -- ----------------- function First_Index (Container : Vector) return Index_Type is pragma Unreferenced (Container); begin return Index_Type'First; end First_Index; --------------------- -- Generic_Sorting -- --------------------- package body Generic_Sorting is ----------------------- -- Local Subprograms -- ----------------------- function Is_Less (L, R : Element_Access) return Boolean; pragma Inline (Is_Less); ------------- -- Is_Less -- ------------- function Is_Less (L, R : Element_Access) return Boolean is begin if L = null then return R /= null; elsif R = null then return False; else return L.all < R.all; end if; end Is_Less; --------------- -- Is_Sorted -- --------------- function Is_Sorted (Container : Vector) return Boolean is begin if Container.Last <= Index_Type'First then return True; end if; -- Per AI05-0022, the container implementation is required to detect -- element tampering by a generic actual subprogram. declare Lock : With_Lock (Container.TC'Unrestricted_Access); E : Elements_Array renames Container.Elements.EA; begin for J in Index_Type'First .. Container.Last - 1 loop if Is_Less (E (J + 1), E (J)) then return False; end if; end loop; return True; end; end Is_Sorted; ----------- -- Merge -- ----------- procedure Merge (Target, Source : in out Vector) is I, J : Index_Type'Base; begin TC_Check (Source.TC); -- The semantics of Merge changed slightly per AI05-0021. It was -- originally the case that if Target and Source denoted the same -- container object, then the GNAT implementation of Merge did -- nothing. However, it was argued that RM05 did not precisely -- specify the semantics for this corner case. The decision of the -- ARG was that if Target and Source denote the same non-empty -- container object, then Program_Error is raised. if Source.Last < Index_Type'First then -- Source is empty return; end if; if Checks and then Target'Address = Source'Address then raise Program_Error with "Target and Source denote same non-empty container"; end if; if Target.Last < Index_Type'First then -- Target is empty Move (Target => Target, Source => Source); return; end if; I := Target.Last; -- original value (before Set_Length) Target.Set_Length (Length (Target) + Length (Source)); -- Per AI05-0022, the container implementation is required to detect -- element tampering by a generic actual subprogram. declare TA : Elements_Array renames Target.Elements.EA; SA : Elements_Array renames Source.Elements.EA; Lock_Target : With_Lock (Target.TC'Unchecked_Access); Lock_Source : With_Lock (Source.TC'Unchecked_Access); begin J := Target.Last; -- new value (after Set_Length) while Source.Last >= Index_Type'First loop pragma Assert (Source.Last <= Index_Type'First or else not (Is_Less (SA (Source.Last), SA (Source.Last - 1)))); if I < Index_Type'First then declare Src : Elements_Array renames SA (Index_Type'First .. Source.Last); begin TA (Index_Type'First .. J) := Src; Src := [others => null]; end; Source.Last := No_Index; exit; end if; pragma Assert (I <= Index_Type'First or else not (Is_Less (TA (I), TA (I - 1)))); declare Src : Element_Access renames SA (Source.Last); Tgt : Element_Access renames TA (I); begin if Is_Less (Src, Tgt) then Target.Elements.EA (J) := Tgt; Tgt := null; I := I - 1; else Target.Elements.EA (J) := Src; Src := null; Source.Last := Source.Last - 1; end if; end; J := J - 1; end loop; end; end Merge; ---------- -- Sort -- ---------- procedure Sort (Container : in out Vector) is procedure Sort is new Generic_Array_Sort (Index_Type => Index_Type, Element_Type => Element_Access, Array_Type => Elements_Array, "<" => Is_Less); -- Start of processing for Sort begin if Container.Last <= Index_Type'First then return; end if; -- The exception behavior for the vector container must match that -- for the list container, so we check for cursor tampering here -- (which will catch more things) instead of for element tampering -- (which will catch fewer things). It's true that the elements of -- this vector container could be safely moved around while (say) an -- iteration is taking place (iteration only increments the busy -- counter), and so technically all we would need here is a test for -- element tampering (indicated by the lock counter), that's simply -- an artifact of our array-based implementation. Logically Sort -- requires a check for cursor tampering. TC_Check (Container.TC); -- Per AI05-0022, the container implementation is required to detect -- element tampering by a generic actual subprogram. declare Lock : With_Lock (Container.TC'Unchecked_Access); begin Sort (Container.Elements.EA (Index_Type'First .. Container.Last)); end; end Sort; end Generic_Sorting; ------------------------ -- Get_Element_Access -- ------------------------ function Get_Element_Access (Position : Cursor) return not null Element_Access is Ptr : constant Element_Access := Position.Container.Elements.EA (Position.Index); begin -- An indefinite vector may contain spaces that hold no elements. -- Any iteration over an indefinite vector with spaces will raise -- Constraint_Error. if Ptr = null then raise Constraint_Error; else return Ptr; end if; end Get_Element_Access; ----------------- -- Has_Element -- ----------------- function Has_Element (Position : Cursor) return Boolean is begin if Position.Container = null then return False; else return Position.Index <= Position.Container.Last; end if; end Has_Element; ------------ -- Insert -- ------------ procedure Insert (Container : in out Vector; Before : Extended_Index; New_Item : Element_Type; Count : Count_Type := 1) is Old_Length : constant Count_Type := Container.Length; Max_Length : Count_Type'Base; -- determined from range of Index_Type New_Length : Count_Type'Base; -- sum of current length and Count New_Last : Index_Type'Base; -- last index of vector after insertion Index : Index_Type'Base; -- scratch for intermediate values J : Count_Type'Base; -- scratch New_Capacity : Count_Type'Base; -- length of new, expanded array Dst_Last : Index_Type'Base; -- last index of new, expanded array Dst : Elements_Access; -- new, expanded internal array begin -- The tampering bits exist to prevent an item from being harmfully -- manipulated while it is being visited. Query, Update, and Iterate -- increment the busy count on entry, and decrement the count on -- exit. Insert checks the count to determine whether it is being called -- while the associated callback procedure is executing. TC_Check (Container.TC); if Checks then -- As a precondition on the generic actual Index_Type, the base type -- must include Index_Type'Pred (Index_Type'First); this is the value -- that Container.Last assumes when the vector is empty. However, we -- do not allow that as the value for Index when specifying where the -- new items should be inserted, so we must manually check. (That the -- user is allowed to specify the value at all here is a consequence -- of the declaration of the Extended_Index subtype, which includes -- the values in the base range that immediately precede and -- immediately follow the values in the Index_Type.) if Before < Index_Type'First then raise Constraint_Error with "Before index is out of range (too small)"; end if; -- We do allow a value greater than Container.Last to be specified as -- the Index, but only if it's immediately greater. This allows for -- the case of appending items to the back end of the vector. (It is -- assumed that specifying an index value greater than Last + 1 -- indicates some deeper flaw in the caller's algorithm, so that case -- is treated as a proper error.) if Before > Container.Last + 1 then raise Constraint_Error with "Before index is out of range (too large)"; end if; end if; -- We treat inserting 0 items into the container as a no-op, even when -- the container is busy, so we simply return. if Count = 0 then return; end if; -- There are two constraints we need to satisfy. The first constraint is -- that a container cannot have more than Count_Type'Last elements, so -- we must check the sum of the current length and the insertion count. -- Note: we cannot simply add these values, because of the possibility -- of overflow. if Checks and then Old_Length > Count_Type'Last - Count then raise Constraint_Error with "Count is out of range"; end if; -- It is now safe compute the length of the new vector, without fear of -- overflow. New_Length := Old_Length + Count; -- The second constraint is that the new Last index value cannot exceed -- Index_Type'Last. In each branch below, we calculate the maximum -- length (computed from the range of values in Index_Type), and then -- compare the new length to the maximum length. If the new length is -- acceptable, then we compute the new last index from that. if Index_Type'Base'Last >= Count_Type_Last then -- We have to handle the case when there might be more values in the -- range of Index_Type than in the range of Count_Type. if Index_Type'First <= 0 then -- We know that No_Index (the same as Index_Type'First - 1) is -- less than 0, so it is safe to compute the following sum without -- fear of overflow. Index := No_Index + Index_Type'Base (Count_Type'Last); if Index <= Index_Type'Last then -- We have determined that range of Index_Type has at least as -- many values as in Count_Type, so Count_Type'Last is the -- maximum number of items that are allowed. Max_Length := Count_Type'Last; else -- The range of Index_Type has fewer values than in Count_Type, -- so the maximum number of items is computed from the range of -- the Index_Type. Max_Length := Count_Type'Base (Index_Type'Last - No_Index); end if; else -- No_Index is equal or greater than 0, so we can safely compute -- the difference without fear of overflow (which we would have to -- worry about if No_Index were less than 0, but that case is -- handled above). if Index_Type'Last - No_Index >= Count_Type_Last then -- We have determined that range of Index_Type has at least as -- many values as in Count_Type, so Count_Type'Last is the -- maximum number of items that are allowed. Max_Length := Count_Type'Last; else -- The range of Index_Type has fewer values than in Count_Type, -- so the maximum number of items is computed from the range of -- the Index_Type. Max_Length := Count_Type'Base (Index_Type'Last - No_Index); end if; end if; elsif Index_Type'First <= 0 then -- We know that No_Index (the same as Index_Type'First - 1) is less -- than 0, so it is safe to compute the following sum without fear of -- overflow. J := Count_Type'Base (No_Index) + Count_Type'Last; if J <= Count_Type'Base (Index_Type'Last) then -- We have determined that range of Index_Type has at least as -- many values as in Count_Type, so Count_Type'Last is the maximum -- number of items that are allowed. Max_Length := Count_Type'Last; else -- The range of Index_Type has fewer values than Count_Type does, -- so the maximum number of items is computed from the range of -- the Index_Type. Max_Length := Count_Type'Base (Index_Type'Last) - Count_Type'Base (No_Index); end if; else -- No_Index is equal or greater than 0, so we can safely compute the -- difference without fear of overflow (which we would have to worry -- about if No_Index were less than 0, but that case is handled -- above). Max_Length := Count_Type'Base (Index_Type'Last) - Count_Type'Base (No_Index); end if; -- We have just computed the maximum length (number of items). We must -- now compare the requested length to the maximum length, as we do not -- allow a vector expand beyond the maximum (because that would create -- an internal array with a last index value greater than -- Index_Type'Last, with no way to index those elements). if Checks and then New_Length > Max_Length then raise Constraint_Error with "Count is out of range"; end if; -- New_Last is the last index value of the items in the container after -- insertion. Use the wider of Index_Type'Base and Count_Type'Base to -- compute its value from the New_Length. if Index_Type'Base'Last >= Count_Type_Last then New_Last := No_Index + Index_Type'Base (New_Length); else New_Last := Index_Type'Base (Count_Type'Base (No_Index) + New_Length); end if; if Container.Elements = null then pragma Assert (Container.Last = No_Index); -- This is the simplest case, with which we must always begin: we're -- inserting items into an empty vector that hasn't allocated an -- internal array yet. Note that we don't need to check the busy bit -- here, because an empty container cannot be busy. -- In an indefinite vector, elements are allocated individually, and -- stored as access values on the internal array (the length of which -- represents the vector "capacity"), which is separately allocated. Container.Elements := new Elements_Type (New_Last); -- The element backbone has been successfully allocated, so now we -- allocate the elements. for Idx in Container.Elements.EA'Range loop -- In order to preserve container invariants, we always attempt -- the element allocation first, before setting the Last index -- value, in case the allocation fails (either because there is no -- storage available, or because element initialization fails). declare -- The element allocator may need an accessibility check in the -- case actual type is class-wide or has access discriminants -- (see RM 4.8(10.1) and AI12-0035). pragma Unsuppress (Accessibility_Check); begin Container.Elements.EA (Idx) := new Element_Type'(New_Item); end; -- The allocation of the element succeeded, so it is now safe to -- update the Last index, restoring container invariants. Container.Last := Idx; end loop; return; end if; if New_Length <= Container.Elements.EA'Length then -- In this case, we're inserting elements into a vector that has -- already allocated an internal array, and the existing array has -- enough unused storage for the new items. declare E : Elements_Array renames Container.Elements.EA; K : Index_Type'Base; begin if Before > Container.Last then -- The new items are being appended to the vector, so no -- sliding of existing elements is required. for Idx in Before .. New_Last loop -- In order to preserve container invariants, we always -- attempt the element allocation first, before setting the -- Last index value, in case the allocation fails (either -- because there is no storage available, or because element -- initialization fails). declare -- The element allocator may need an accessibility check -- in case the actual type is class-wide or has access -- discriminants (see RM 4.8(10.1) and AI12-0035). pragma Unsuppress (Accessibility_Check); begin E (Idx) := new Element_Type'(New_Item); end; -- The allocation of the element succeeded, so it is now -- safe to update the Last index, restoring container -- invariants. Container.Last := Idx; end loop; else -- The new items are being inserted before some existing -- elements, so we must slide the existing elements up to their -- new home. We use the wider of Index_Type'Base and -- Count_Type'Base as the type for intermediate index values. if Index_Type'Base'Last >= Count_Type_Last then Index := Before + Index_Type'Base (Count); else Index := Index_Type'Base (Count_Type'Base (Before) + Count); end if; -- The new items are being inserted in the middle of the array, -- in the range [Before, Index). Copy the existing elements to -- the end of the array, to make room for the new items. E (Index .. New_Last) := E (Before .. Container.Last); Container.Last := New_Last; -- We have copied the existing items up to the end of the -- array, to make room for the new items in the middle of -- the array. Now we actually allocate the new items. -- Note: initialize K outside loop to make it clear that -- K always has a value if the exception handler triggers. K := Before; declare -- The element allocator may need an accessibility check in -- the case the actual type is class-wide or has access -- discriminants (see RM 4.8(10.1) and AI12-0035). pragma Unsuppress (Accessibility_Check); begin while K < Index loop E (K) := new Element_Type'(New_Item); K := K + 1; end loop; exception when others => -- Values in the range [Before, K) were successfully -- allocated, but values in the range [K, Index) are -- stale (these array positions contain copies of the -- old items, that did not get assigned a new item, -- because the allocation failed). We must finish what -- we started by clearing out all of the stale values, -- leaving a "hole" in the middle of the array. E (K .. Index - 1) := [others => null]; raise; end; end if; end; return; end if; -- In this case, we're inserting elements into a vector that has already -- allocated an internal array, but the existing array does not have -- enough storage, so we must allocate a new, longer array. In order to -- guarantee that the amortized insertion cost is O(1), we always -- allocate an array whose length is some power-of-two factor of the -- current array length. (The new array cannot have a length less than -- the New_Length of the container, but its last index value cannot be -- greater than Index_Type'Last.) New_Capacity := Count_Type'Max (1, Container.Elements.EA'Length); while New_Capacity < New_Length loop if New_Capacity > Count_Type'Last / 2 then New_Capacity := Count_Type'Last; exit; end if; New_Capacity := 2 * New_Capacity; end loop; if New_Capacity > Max_Length then -- We have reached the limit of capacity, so no further expansion -- will occur. (This is not a problem, as there is never a need to -- have more capacity than the maximum container length.) New_Capacity := Max_Length; end if; -- We have computed the length of the new internal array (and this is -- what "vector capacity" means), so use that to compute its last index. if Index_Type'Base'Last >= Count_Type_Last then Dst_Last := No_Index + Index_Type'Base (New_Capacity); else Dst_Last := Index_Type'Base (Count_Type'Base (No_Index) + New_Capacity); end if; -- Now we allocate the new, longer internal array. If the allocation -- fails, we have not changed any container state, so no side-effect -- will occur as a result of propagating the exception. Dst := new Elements_Type (Dst_Last); -- We have our new internal array. All that needs to be done now is to -- copy the existing items (if any) from the old array (the "source" -- array) to the new array (the "destination" array), and then -- deallocate the old array. declare Src : Elements_Access := Container.Elements; begin Dst.EA (Index_Type'First .. Before - 1) := Src.EA (Index_Type'First .. Before - 1); if Before > Container.Last then -- The new items are being appended to the vector, so no -- sliding of existing elements is required. -- We have copied the elements from to the old source array to the -- new destination array, so we can now deallocate the old array. Container.Elements := Dst; Free (Src); -- Now we append the new items. for Idx in Before .. New_Last loop -- In order to preserve container invariants, we always attempt -- the element allocation first, before setting the Last index -- value, in case the allocation fails (either because there -- is no storage available, or because element initialization -- fails). declare -- The element allocator may need an accessibility check in -- the case the actual type is class-wide or has access -- discriminants (see RM 4.8(10.1) and AI12-0035). pragma Unsuppress (Accessibility_Check); begin Dst.EA (Idx) := new Element_Type'(New_Item); end; -- The allocation of the element succeeded, so it is now safe -- to update the Last index, restoring container invariants. Container.Last := Idx; end loop; else -- The new items are being inserted before some existing elements, -- so we must slide the existing elements up to their new home. if Index_Type'Base'Last >= Count_Type_Last then Index := Before + Index_Type'Base (Count); else Index := Index_Type'Base (Count_Type'Base (Before) + Count); end if; Dst.EA (Index .. New_Last) := Src.EA (Before .. Container.Last); -- We have copied the elements from to the old source array to the -- new destination array, so we can now deallocate the old array. Container.Elements := Dst; Container.Last := New_Last; Free (Src); -- The new array has a range in the middle containing null access -- values. Fill in that partition of the array with the new items. for Idx in Before .. Index - 1 loop -- Note that container invariants have already been satisfied -- (in particular, the Last index value of the vector has -- already been updated), so if this allocation fails we simply -- let it propagate. declare -- The element allocator may need an accessibility check in -- the case the actual type is class-wide or has access -- discriminants (see RM 4.8(10.1) and AI12-0035). pragma Unsuppress (Accessibility_Check); begin Dst.EA (Idx) := new Element_Type'(New_Item); end; end loop; end if; end; end Insert; procedure Insert_Vector (Container : in out Vector; Before : Extended_Index; New_Item : Vector) is N : constant Count_Type := Length (New_Item); J : Index_Type'Base; begin -- Use Insert_Space to create the "hole" (the destination slice) into -- which we copy the source items. Insert_Space (Container, Before, Count => N); if N = 0 then -- There's nothing else to do here (vetting of parameters was -- performed already in Insert_Space), so we simply return. return; end if; if Container'Address /= New_Item'Address then -- This is the simple case. New_Item denotes an object different -- from Container, so there's nothing special we need to do to copy -- the source items to their destination, because all of the source -- items are contiguous. declare subtype Src_Index_Subtype is Index_Type'Base range Index_Type'First .. New_Item.Last; Src : Elements_Array renames New_Item.Elements.EA (Src_Index_Subtype); Dst : Elements_Array renames Container.Elements.EA; Dst_Index : Index_Type'Base; begin Dst_Index := Before - 1; for Src_Index in Src'Range loop Dst_Index := Dst_Index + 1; if Src (Src_Index) /= null then Dst (Dst_Index) := new Element_Type'(Src (Src_Index).all); end if; end loop; end; return; end if; -- New_Item denotes the same object as Container, so an insertion has -- potentially split the source items. The first source slice is -- [Index_Type'First, Before), and the second source slice is -- [J, Container.Last], where index value J is the first index of the -- second slice. (J gets computed below, but only after we have -- determined that the second source slice is non-empty.) The -- destination slice is always the range [Before, J). We perform the -- copy in two steps, using each of the two slices of the source items. declare L : constant Index_Type'Base := Before - 1; subtype Src_Index_Subtype is Index_Type'Base range Index_Type'First .. L; Src : Elements_Array renames Container.Elements.EA (Src_Index_Subtype); Dst : Elements_Array renames Container.Elements.EA; Dst_Index : Index_Type'Base; begin -- We first copy the source items that precede the space we -- inserted. (If Before equals Index_Type'First, then this first -- source slice will be empty, which is harmless.) Dst_Index := Before - 1; for Src_Index in Src'Range loop Dst_Index := Dst_Index + 1; if Src (Src_Index) /= null then Dst (Dst_Index) := new Element_Type'(Src (Src_Index).all); end if; end loop; if Src'Length = N then -- The new items were effectively appended to the container, so we -- have already copied all of the items that need to be copied. -- We return early here, even though the source slice below is -- empty (so the assignment would be harmless), because we want to -- avoid computing J, which will overflow if J is greater than -- Index_Type'Base'Last. return; end if; end; -- Index value J is the first index of the second source slice. (It is -- also 1 greater than the last index of the destination slice.) Note: -- avoid computing J if J is greater than Index_Type'Base'Last, in order -- to avoid overflow. Prevent that by returning early above, immediately -- after copying the first slice of the source, and determining that -- this second slice of the source is empty. if Index_Type'Base'Last >= Count_Type_Last then J := Before + Index_Type'Base (N); else J := Index_Type'Base (Count_Type'Base (Before) + N); end if; declare subtype Src_Index_Subtype is Index_Type'Base range J .. Container.Last; Src : Elements_Array renames Container.Elements.EA (Src_Index_Subtype); Dst : Elements_Array renames Container.Elements.EA; Dst_Index : Index_Type'Base; begin -- We next copy the source items that follow the space we inserted. -- Index value Dst_Index is the first index of that portion of the -- destination that receives this slice of the source. (For the -- reasons given above, this slice is guaranteed to be non-empty.) if Index_Type'Base'Last >= Count_Type_Last then Dst_Index := J - Index_Type'Base (Src'Length); else Dst_Index := Index_Type'Base (Count_Type'Base (J) - Src'Length); end if; for Src_Index in Src'Range loop if Src (Src_Index) /= null then Dst (Dst_Index) := new Element_Type'(Src (Src_Index).all); end if; Dst_Index := Dst_Index + 1; end loop; end; end Insert_Vector; procedure Insert_Vector (Container : in out Vector; Before : Cursor; New_Item : Vector) is Index : Index_Type'Base; begin if Checks and then Before.Container /= null and then Before.Container /= Container'Unrestricted_Access then raise Program_Error with "Before cursor denotes wrong container"; end if; if Is_Empty (New_Item) then return; end if; if Before.Container = null or else Before.Index > Container.Last then if Checks and then Container.Last = Index_Type'Last then raise Constraint_Error with "vector is already at its maximum length"; end if; Index := Container.Last + 1; else Index := Before.Index; end if; Insert_Vector (Container, Index, New_Item); end Insert_Vector; procedure Insert_Vector (Container : in out Vector; Before : Cursor; New_Item : Vector; Position : out Cursor) is Index : Index_Type'Base; begin if Checks and then Before.Container /= null and then Before.Container /= Container'Unrestricted_Access then raise Program_Error with "Before cursor denotes wrong container"; end if; if Is_Empty (New_Item) then if Before.Container = null or else Before.Index > Container.Last then Position := No_Element; else Position := (Container'Unrestricted_Access, Before.Index); end if; return; end if; if Before.Container = null or else Before.Index > Container.Last then if Checks and then Container.Last = Index_Type'Last then raise Constraint_Error with "vector is already at its maximum length"; end if; Index := Container.Last + 1; else Index := Before.Index; end if; Insert_Vector (Container, Index, New_Item); Position := (Container'Unrestricted_Access, Index); end Insert_Vector; procedure Insert (Container : in out Vector; Before : Cursor; New_Item : Element_Type; Count : Count_Type := 1) is Index : Index_Type'Base; begin if Checks and then Before.Container /= null and then Before.Container /= Container'Unrestricted_Access then raise Program_Error with "Before cursor denotes wrong container"; end if; if Count = 0 then return; end if; if Before.Container = null or else Before.Index > Container.Last then if Checks and then Container.Last = Index_Type'Last then raise Constraint_Error with "vector is already at its maximum length"; end if; Index := Container.Last + 1; else Index := Before.Index; end if; Insert (Container, Index, New_Item, Count); end Insert; procedure Insert (Container : in out Vector; Before : Cursor; New_Item : Element_Type; Position : out Cursor; Count : Count_Type := 1) is Index : Index_Type'Base; begin if Checks and then Before.Container /= null and then Before.Container /= Container'Unrestricted_Access then raise Program_Error with "Before cursor denotes wrong container"; end if; if Count = 0 then if Before.Container = null or else Before.Index > Container.Last then Position := No_Element; else Position := (Container'Unrestricted_Access, Before.Index); end if; return; end if; if Before.Container = null or else Before.Index > Container.Last then if Checks and then Container.Last = Index_Type'Last then raise Constraint_Error with "vector is already at its maximum length"; end if; Index := Container.Last + 1; else Index := Before.Index; end if; Insert (Container, Index, New_Item, Count); Position := (Container'Unrestricted_Access, Index); end Insert; ------------------ -- Insert_Space -- ------------------ procedure Insert_Space (Container : in out Vector; Before : Extended_Index; Count : Count_Type := 1) is Old_Length : constant Count_Type := Container.Length; Max_Length : Count_Type'Base; -- determined from range of Index_Type New_Length : Count_Type'Base; -- sum of current length and Count New_Last : Index_Type'Base; -- last index of vector after insertion Index : Index_Type'Base; -- scratch for intermediate values J : Count_Type'Base; -- scratch New_Capacity : Count_Type'Base; -- length of new, expanded array Dst_Last : Index_Type'Base; -- last index of new, expanded array Dst : Elements_Access; -- new, expanded internal array begin -- The tampering bits exist to prevent an item from being harmfully -- manipulated while it is being visited. Query, Update, and Iterate -- increment the busy count on entry, and decrement the count on exit. -- Insert checks the count to determine whether it is being called while -- the associated callback procedure is executing. TC_Check (Container.TC); if Checks then -- As a precondition on the generic actual Index_Type, the base type -- must include Index_Type'Pred (Index_Type'First); this is the value -- that Container.Last assumes when the vector is empty. However, we -- do not allow that as the value for Index when specifying where the -- new items should be inserted, so we must manually check. (That the -- user is allowed to specify the value at all here is a consequence -- of the declaration of the Extended_Index subtype, which includes -- the values in the base range that immediately precede and -- immediately follow the values in the Index_Type.) if Before < Index_Type'First then raise Constraint_Error with "Before index is out of range (too small)"; end if; -- We do allow a value greater than Container.Last to be specified as -- the Index, but only if it's immediately greater. This allows for -- the case of appending items to the back end of the vector. (It is -- assumed that specifying an index value greater than Last + 1 -- indicates some deeper flaw in the caller's algorithm, so that case -- is treated as a proper error.) if Before > Container.Last + 1 then raise Constraint_Error with "Before index is out of range (too large)"; end if; end if; -- We treat inserting 0 items into the container as a no-op, even when -- the container is busy, so we simply return. if Count = 0 then return; end if; -- There are two constraints we need to satisfy. The first constraint is -- that a container cannot have more than Count_Type'Last elements, so -- we must check the sum of the current length and the insertion count. -- Note: we cannot simply add these values, because of the possibility -- of overflow. if Checks and then Old_Length > Count_Type'Last - Count then raise Constraint_Error with "Count is out of range"; end if; -- It is now safe compute the length of the new vector, without fear of -- overflow. New_Length := Old_Length + Count; -- The second constraint is that the new Last index value cannot exceed -- Index_Type'Last. In each branch below, we calculate the maximum -- length (computed from the range of values in Index_Type), and then -- compare the new length to the maximum length. If the new length is -- acceptable, then we compute the new last index from that. if Index_Type'Base'Last >= Count_Type_Last then -- We have to handle the case when there might be more values in the -- range of Index_Type than in the range of Count_Type. if Index_Type'First <= 0 then -- We know that No_Index (the same as Index_Type'First - 1) is -- less than 0, so it is safe to compute the following sum without -- fear of overflow. Index := No_Index + Index_Type'Base (Count_Type'Last); if Index <= Index_Type'Last then -- We have determined that range of Index_Type has at least as -- many values as in Count_Type, so Count_Type'Last is the -- maximum number of items that are allowed. Max_Length := Count_Type'Last; else -- The range of Index_Type has fewer values than in Count_Type, -- so the maximum number of items is computed from the range of -- the Index_Type. Max_Length := Count_Type'Base (Index_Type'Last - No_Index); end if; else -- No_Index is equal or greater than 0, so we can safely compute -- the difference without fear of overflow (which we would have to -- worry about if No_Index were less than 0, but that case is -- handled above). if Index_Type'Last - No_Index >= Count_Type_Last then -- We have determined that range of Index_Type has at least as -- many values as in Count_Type, so Count_Type'Last is the -- maximum number of items that are allowed. Max_Length := Count_Type'Last; else -- The range of Index_Type has fewer values than in Count_Type, -- so the maximum number of items is computed from the range of -- the Index_Type. Max_Length := Count_Type'Base (Index_Type'Last - No_Index); end if; end if; elsif Index_Type'First <= 0 then -- We know that No_Index (the same as Index_Type'First - 1) is less -- than 0, so it is safe to compute the following sum without fear of -- overflow. J := Count_Type'Base (No_Index) + Count_Type'Last; if J <= Count_Type'Base (Index_Type'Last) then -- We have determined that range of Index_Type has at least as -- many values as in Count_Type, so Count_Type'Last is the maximum -- number of items that are allowed. Max_Length := Count_Type'Last; else -- The range of Index_Type has fewer values than Count_Type does, -- so the maximum number of items is computed from the range of -- the Index_Type. Max_Length := Count_Type'Base (Index_Type'Last) - Count_Type'Base (No_Index); end if; else -- No_Index is equal or greater than 0, so we can safely compute the -- difference without fear of overflow (which we would have to worry -- about if No_Index were less than 0, but that case is handled -- above). Max_Length := Count_Type'Base (Index_Type'Last) - Count_Type'Base (No_Index); end if; -- We have just computed the maximum length (number of items). We must -- now compare the requested length to the maximum length, as we do not -- allow a vector expand beyond the maximum (because that would create -- an internal array with a last index value greater than -- Index_Type'Last, with no way to index those elements). if Checks and then New_Length > Max_Length then raise Constraint_Error with "Count is out of range"; end if; -- New_Last is the last index value of the items in the container after -- insertion. Use the wider of Index_Type'Base and Count_Type'Base to -- compute its value from the New_Length. if Index_Type'Base'Last >= Count_Type_Last then New_Last := No_Index + Index_Type'Base (New_Length); else New_Last := Index_Type'Base (Count_Type'Base (No_Index) + New_Length); end if; if Container.Elements = null then pragma Assert (Container.Last = No_Index); -- This is the simplest case, with which we must always begin: we're -- inserting items into an empty vector that hasn't allocated an -- internal array yet. Note that we don't need to check the busy bit -- here, because an empty container cannot be busy. -- In an indefinite vector, elements are allocated individually, and -- stored as access values on the internal array (the length of which -- represents the vector "capacity"), which is separately allocated. -- We have no elements here (because we're inserting "space"), so all -- we need to do is allocate the backbone. Container.Elements := new Elements_Type (New_Last); Container.Last := New_Last; return; end if; if New_Length <= Container.Elements.EA'Length then -- In this case, we are inserting elements into a vector that has -- already allocated an internal array, and the existing array has -- enough unused storage for the new items. declare E : Elements_Array renames Container.Elements.EA; begin if Before <= Container.Last then -- The new space is being inserted before some existing -- elements, so we must slide the existing elements up to -- their new home. We use the wider of Index_Type'Base and -- Count_Type'Base as the type for intermediate index values. if Index_Type'Base'Last >= Count_Type_Last then Index := Before + Index_Type'Base (Count); else Index := Index_Type'Base (Count_Type'Base (Before) + Count); end if; E (Index .. New_Last) := E (Before .. Container.Last); E (Before .. Index - 1) := [others => null]; end if; end; Container.Last := New_Last; return; end if; -- In this case, we're inserting elements into a vector that has already -- allocated an internal array, but the existing array does not have -- enough storage, so we must allocate a new, longer array. In order to -- guarantee that the amortized insertion cost is O(1), we always -- allocate an array whose length is some power-of-two factor of the -- current array length. (The new array cannot have a length less than -- the New_Length of the container, but its last index value cannot be -- greater than Index_Type'Last.) New_Capacity := Count_Type'Max (1, Container.Elements.EA'Length); while New_Capacity < New_Length loop if New_Capacity > Count_Type'Last / 2 then New_Capacity := Count_Type'Last; exit; end if; New_Capacity := 2 * New_Capacity; end loop; if New_Capacity > Max_Length then -- We have reached the limit of capacity, so no further expansion -- will occur. (This is not a problem, as there is never a need to -- have more capacity than the maximum container length.) New_Capacity := Max_Length; end if; -- We have computed the length of the new internal array (and this is -- what "vector capacity" means), so use that to compute its last index. if Index_Type'Base'Last >= Count_Type_Last then Dst_Last := No_Index + Index_Type'Base (New_Capacity); else Dst_Last := Index_Type'Base (Count_Type'Base (No_Index) + New_Capacity); end if; -- Now we allocate the new, longer internal array. If the allocation -- fails, we have not changed any container state, so no side-effect -- will occur as a result of propagating the exception. Dst := new Elements_Type (Dst_Last); -- We have our new internal array. All that needs to be done now is to -- copy the existing items (if any) from the old array (the "source" -- array) to the new array (the "destination" array), and then -- deallocate the old array. declare Src : Elements_Access := Container.Elements; begin Dst.EA (Index_Type'First .. Before - 1) := Src.EA (Index_Type'First .. Before - 1); if Before <= Container.Last then -- The new items are being inserted before some existing elements, -- so we must slide the existing elements up to their new home. if Index_Type'Base'Last >= Count_Type_Last then Index := Before + Index_Type'Base (Count); else Index := Index_Type'Base (Count_Type'Base (Before) + Count); end if; Dst.EA (Index .. New_Last) := Src.EA (Before .. Container.Last); end if; -- We have copied the elements from to the old, source array to the -- new, destination array, so we can now restore invariants, and -- deallocate the old array. Container.Elements := Dst; Container.Last := New_Last; Free (Src); end; end Insert_Space; procedure Insert_Space (Container : in out Vector; Before : Cursor; Position : out Cursor; Count : Count_Type := 1) is Index : Index_Type'Base; begin if Checks and then Before.Container /= null and then Before.Container /= Container'Unrestricted_Access then raise Program_Error with "Before cursor denotes wrong container"; end if; if Count = 0 then if Before.Container = null or else Before.Index > Container.Last then Position := No_Element; else Position := (Container'Unrestricted_Access, Before.Index); end if; return; end if; if Before.Container = null or else Before.Index > Container.Last then if Checks and then Container.Last = Index_Type'Last then raise Constraint_Error with "vector is already at its maximum length"; end if; Index := Container.Last + 1; else Index := Before.Index; end if; Insert_Space (Container, Index, Count); Position := (Container'Unrestricted_Access, Index); end Insert_Space; -------------- -- Is_Empty -- -------------- function Is_Empty (Container : Vector) return Boolean is begin return Container.Last < Index_Type'First; end Is_Empty; ------------- -- Iterate -- ------------- procedure Iterate (Container : Vector; Process : not null access procedure (Position : Cursor)) is Busy : With_Busy (Container.TC'Unrestricted_Access); begin for Indx in Index_Type'First .. Container.Last loop Process (Cursor'(Container'Unrestricted_Access, Indx)); end loop; end Iterate; function Iterate (Container : Vector) return Vector_Iterator_Interfaces.Reversible_Iterator'Class is V : constant Vector_Access := Container'Unrestricted_Access; begin -- The value of its Index component influences the behavior of the First -- and Last selector functions of the iterator object. When the Index -- component is No_Index (as is the case here), this means the iterator -- object was constructed without a start expression. This is a complete -- iterator, meaning that the iteration starts from the (logical) -- beginning of the sequence of items. -- Note: For a forward iterator, Container.First is the beginning, and -- for a reverse iterator, Container.Last is the beginning. return It : constant Iterator := (Limited_Controlled with Container => V, Index => No_Index) do Busy (Container.TC'Unrestricted_Access.all); end return; end Iterate; function Iterate (Container : Vector; Start : Cursor) return Vector_Iterator_Interfaces.Reversible_Iterator'Class is V : constant Vector_Access := Container'Unrestricted_Access; begin -- It was formerly the case that when Start = No_Element, the partial -- iterator was defined to behave the same as for a complete iterator, -- and iterate over the entire sequence of items. However, those -- semantics were unintuitive and arguably error-prone (it is too easy -- to accidentally create an endless loop), and so they were changed, -- per the ARG meeting in Denver on 2011/11. However, there was no -- consensus about what positive meaning this corner case should have, -- and so it was decided to simply raise an exception. This does imply, -- however, that it is not possible to use a partial iterator to specify -- an empty sequence of items. if Checks then if Start.Container = null then raise Constraint_Error with "Start position for iterator equals No_Element"; end if; if Start.Container /= V then raise Program_Error with "Start cursor of Iterate designates wrong vector"; end if; if Start.Index > V.Last then raise Constraint_Error with "Start position for iterator equals No_Element"; end if; end if; -- The value of its Index component influences the behavior of the First -- and Last selector functions of the iterator object. When the Index -- component is not No_Index (as is the case here), it means that this -- is a partial iteration, over a subset of the complete sequence of -- items. The iterator object was constructed with a start expression, -- indicating the position from which the iteration begins. Note that -- the start position has the same value irrespective of whether this -- is a forward or reverse iteration. return It : constant Iterator := (Limited_Controlled with Container => V, Index => Start.Index) do Busy (Container.TC'Unrestricted_Access.all); end return; end Iterate; ---------- -- Last -- ---------- function Last (Container : Vector) return Cursor is begin if Is_Empty (Container) then return No_Element; end if; return (Container'Unrestricted_Access, Container.Last); end Last; function Last (Object : Iterator) return Cursor is begin -- The value of the iterator object's Index component influences the -- behavior of the Last (and First) selector function. -- When the Index component is No_Index, this means the iterator -- object was constructed without a start expression, in which case the -- (reverse) iteration starts from the (logical) beginning of the entire -- sequence (corresponding to Container.Last, for a reverse iterator). -- Otherwise, this is iteration over a partial sequence of items. -- When the Index component is not No_Index, the iterator object was -- constructed with a start expression, that specifies the position -- from which the (reverse) partial iteration begins. if Object.Index = No_Index then return Last (Object.Container.all); else return Cursor'(Object.Container, Object.Index); end if; end Last; ------------------ -- Last_Element -- ------------------ function Last_Element (Container : Vector) return Element_Type is begin if Checks and then Container.Last = No_Index then raise Constraint_Error with "Container is empty"; end if; declare EA : constant Element_Access := Container.Elements.EA (Container.Last); begin if Checks and then EA = null then raise Constraint_Error with "last element is empty"; else return EA.all; end if; end; end Last_Element; ---------------- -- Last_Index -- ---------------- function Last_Index (Container : Vector) return Extended_Index is begin return Container.Last; end Last_Index; ------------ -- Length -- ------------ function Length (Container : Vector) return Count_Type is L : constant Index_Type'Base := Container.Last; F : constant Index_Type := Index_Type'First; begin -- The base range of the index type (Index_Type'Base) might not include -- all values for length (Count_Type). Contrariwise, the index type -- might include values outside the range of length. Hence we use -- whatever type is wider for intermediate values when calculating -- length. Note that no matter what the index type is, the maximum -- length to which a vector is allowed to grow is always the minimum -- of Count_Type'Last and (IT'Last - IT'First + 1). -- For example, an Index_Type with range -127 .. 127 is only guaranteed -- to have a base range of -128 .. 127, but the corresponding vector -- would have lengths in the range 0 .. 255. In this case we would need -- to use Count_Type'Base for intermediate values. -- Another case would be the index range -2**63 + 1 .. -2**63 + 10. The -- vector would have a maximum length of 10, but the index values lie -- outside the range of Count_Type (which is only 32 bits). In this -- case we would need to use Index_Type'Base for intermediate values. if Count_Type'Base'Last >= Index_Type'Pos (Index_Type'Base'Last) then return Count_Type'Base (L) - Count_Type'Base (F) + 1; else return Count_Type (L - F + 1); end if; end Length; ---------- -- Move -- ---------- procedure Move (Target : in out Vector; Source : in out Vector) is begin if Target'Address = Source'Address then return; end if; TC_Check (Source.TC); Clear (Target); -- Checks busy-bit declare Target_Elements : constant Elements_Access := Target.Elements; begin Target.Elements := Source.Elements; Source.Elements := Target_Elements; end; Target.Last := Source.Last; Source.Last := No_Index; end Move; ---------- -- Next -- ---------- function Next (Position : Cursor) return Cursor is begin if Position.Container = null then return No_Element; elsif Position.Index < Position.Container.Last then return (Position.Container, Position.Index + 1); else return No_Element; end if; end Next; function Next (Object : Iterator; Position : Cursor) return Cursor is begin if Position.Container = null then return No_Element; elsif Checks and then Position.Container /= Object.Container then raise Program_Error with "Position cursor of Next designates wrong vector"; else return Next (Position); end if; end Next; procedure Next (Position : in out Cursor) is begin if Position.Container = null then return; elsif Position.Index < Position.Container.Last then Position.Index := Position.Index + 1; else Position := No_Element; end if; end Next; ------------- -- Prepend -- ------------- procedure Prepend (Container : in out Vector; New_Item : Element_Type; Count : Count_Type := 1) is begin Insert (Container, Index_Type'First, New_Item, Count); end Prepend; ------------- -- Prepend_Vector -- ------------- procedure Prepend_Vector (Container : in out Vector; New_Item : Vector) is begin Insert_Vector (Container, Index_Type'First, New_Item); end Prepend_Vector; -------------- -- Previous -- -------------- function Previous (Position : Cursor) return Cursor is begin if Position.Container = null then return No_Element; elsif Position.Index > Index_Type'First then return (Position.Container, Position.Index - 1); else return No_Element; end if; end Previous; function Previous (Object : Iterator; Position : Cursor) return Cursor is begin if Position.Container = null then return No_Element; elsif Checks and then Position.Container /= Object.Container then raise Program_Error with "Position cursor of Previous designates wrong vector"; else return Previous (Position); end if; end Previous; procedure Previous (Position : in out Cursor) is begin if Position.Container = null then return; elsif Position.Index > Index_Type'First then Position.Index := Position.Index - 1; else Position := No_Element; end if; end Previous; ---------------------- -- Pseudo_Reference -- ---------------------- function Pseudo_Reference (Container : aliased Vector'Class) return Reference_Control_Type is TC : constant Tamper_Counts_Access := Container.TC'Unrestricted_Access; begin return R : constant Reference_Control_Type := (Controlled with TC) do Busy (TC.all); end return; end Pseudo_Reference; ------------------- -- Query_Element -- ------------------- procedure Query_Element (Container : Vector; Index : Index_Type; Process : not null access procedure (Element : Element_Type)) is Lock : With_Lock (Container.TC'Unrestricted_Access); V : Vector renames Container'Unrestricted_Access.all; begin if Checks and then Index > Container.Last then raise Constraint_Error with "Index is out of range"; end if; if Checks and then V.Elements.EA (Index) = null then raise Constraint_Error with "element is null"; end if; Process (V.Elements.EA (Index).all); end Query_Element; procedure Query_Element (Position : Cursor; Process : not null access procedure (Element : Element_Type)) is begin if Checks and then Position.Container = null then raise Constraint_Error with "Position cursor has no element"; else Query_Element (Position.Container.all, Position.Index, Process); end if; end Query_Element; --------------- -- Put_Image -- --------------- procedure Put_Image (S : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class; V : Vector) is First_Time : Boolean := True; use System.Put_Images; procedure Put_Elem (Position : Cursor); procedure Put_Elem (Position : Cursor) is begin if First_Time then First_Time := False; else Simple_Array_Between (S); end if; Element_Type'Put_Image (S, Element (Position)); end Put_Elem; begin Array_Before (S); Iterate (V, Put_Elem'Access); Array_After (S); end Put_Image; ---------- -- Read -- ---------- procedure Read (Stream : not null access Root_Stream_Type'Class; Container : out Vector) is Length : Count_Type'Base; Last : Index_Type'Base := Index_Type'Pred (Index_Type'First); B : Boolean; begin Clear (Container); Count_Type'Base'Read (Stream, Length); if Length > Capacity (Container) then Reserve_Capacity (Container, Capacity => Length); end if; for J in Count_Type range 1 .. Length loop Last := Last + 1; Boolean'Read (Stream, B); if B then Container.Elements.EA (Last) := new Element_Type'(Element_Type'Input (Stream)); end if; Container.Last := Last; end loop; end Read; procedure Read (Stream : not null access Root_Stream_Type'Class; Position : out Cursor) is begin raise Program_Error with "attempt to stream vector cursor"; end Read; procedure Read (Stream : not null access Root_Stream_Type'Class; Item : out Reference_Type) is begin raise Program_Error with "attempt to stream reference"; end Read; procedure Read (Stream : not null access Root_Stream_Type'Class; Item : out Constant_Reference_Type) is begin raise Program_Error with "attempt to stream reference"; end Read; --------------- -- Reference -- --------------- function Reference (Container : aliased in out Vector; Position : Cursor) return Reference_Type is begin if Checks then if Position.Container = null then raise Constraint_Error with "Position cursor has no element"; end if; if Position.Container /= Container'Unrestricted_Access then raise Program_Error with "Position cursor denotes wrong container"; end if; if Position.Index > Position.Container.Last then raise Constraint_Error with "Position cursor is out of range"; end if; end if; declare TC : constant Tamper_Counts_Access := Container.TC'Unrestricted_Access; begin -- The following will raise Constraint_Error if Element is null return R : constant Reference_Type := (Element => Container.Elements.EA (Position.Index), Control => (Controlled with TC)) do Busy (TC.all); end return; end; end Reference; function Reference (Container : aliased in out Vector; Index : Index_Type) return Reference_Type is begin if Checks and then Index > Container.Last then raise Constraint_Error with "Index is out of range"; end if; declare TC : constant Tamper_Counts_Access := Container.TC'Unrestricted_Access; begin -- The following will raise Constraint_Error if Element is null return R : constant Reference_Type := (Element => Container.Elements.EA (Index), Control => (Controlled with TC)) do Busy (TC.all); end return; end; end Reference; --------------------- -- Replace_Element -- --------------------- procedure Replace_Element (Container : in out Vector; Index : Index_Type; New_Item : Element_Type) is begin TE_Check (Container.TC); if Checks and then Index > Container.Last then raise Constraint_Error with "Index is out of range"; end if; declare X : Element_Access := Container.Elements.EA (Index); -- The element allocator may need an accessibility check in the case -- where the actual type is class-wide or has access discriminants -- (see RM 4.8(10.1) and AI12-0035). pragma Unsuppress (Accessibility_Check); begin Container.Elements.EA (Index) := new Element_Type'(New_Item); Free (X); end; end Replace_Element; procedure Replace_Element (Container : in out Vector; Position : Cursor; New_Item : Element_Type) is begin TE_Check (Container.TC); if Checks then if Position.Container = null then raise Constraint_Error with "Position cursor has no element"; end if; if Position.Container /= Container'Unrestricted_Access then raise Program_Error with "Position cursor denotes wrong container"; end if; if Position.Index > Container.Last then raise Constraint_Error with "Position cursor is out of range"; end if; end if; declare X : Element_Access := Container.Elements.EA (Position.Index); -- The element allocator may need an accessibility check in the case -- where the actual type is class-wide or has access discriminants -- (see RM 4.8(10.1) and AI12-0035). pragma Unsuppress (Accessibility_Check); begin Container.Elements.EA (Position.Index) := new Element_Type'(New_Item); Free (X); end; end Replace_Element; ---------------------- -- Reserve_Capacity -- ---------------------- procedure Reserve_Capacity (Container : in out Vector; Capacity : Count_Type) is N : constant Count_Type := Length (Container); Index : Count_Type'Base; Last : Index_Type'Base; begin -- Reserve_Capacity can be used to either expand the storage available -- for elements (this would be its typical use, in anticipation of -- future insertion), or to trim back storage. In the latter case, -- storage can only be trimmed back to the limit of the container -- length. Note that Reserve_Capacity neither deletes (active) elements -- nor inserts elements; it only affects container capacity, never -- container length. if Capacity = 0 then -- This is a request to trim back storage, to the minimum amount -- possible given the current state of the container. if N = 0 then -- The container is empty, so in this unique case we can -- deallocate the entire internal array. Note that an empty -- container can never be busy, so there's no need to check the -- tampering bits. declare X : Elements_Access := Container.Elements; begin -- First we remove the internal array from the container, to -- handle the case when the deallocation raises an exception -- (although that's unlikely, since this is simply an array of -- access values, all of which are null). Container.Elements := null; -- Container invariants have been restored, so it is now safe -- to attempt to deallocate the internal array. Free (X); end; elsif N < Container.Elements.EA'Length then -- The container is not empty, and the current length is less than -- the current capacity, so there's storage available to trim. In -- this case, we allocate a new internal array having a length -- that exactly matches the number of items in the -- container. (Reserve_Capacity does not delete active elements, -- so this is the best we can do with respect to minimizing -- storage). TC_Check (Container.TC); declare subtype Array_Index_Subtype is Index_Type'Base range Index_Type'First .. Container.Last; Src : Elements_Array renames Container.Elements.EA (Array_Index_Subtype); X : Elements_Access := Container.Elements; begin -- Although we have isolated the old internal array that we're -- going to deallocate, we don't deallocate it until we have -- successfully allocated a new one. If there is an exception -- during allocation (because there is not enough storage), we -- let it propagate without causing any side-effect. Container.Elements := new Elements_Type'(Container.Last, Src); -- We have successfully allocated a new internal array (with a -- smaller length than the old one, and containing a copy of -- just the active elements in the container), so we can -- deallocate the old array. Free (X); end; end if; return; end if; -- Reserve_Capacity can be used to expand the storage available for -- elements, but we do not let the capacity grow beyond the number of -- values in Index_Type'Range. (Were it otherwise, there would be no way -- to refer to the elements with index values greater than -- Index_Type'Last, so that storage would be wasted.) Here we compute -- the Last index value of the new internal array, in a way that avoids -- any possibility of overflow. if Index_Type'Base'Last >= Count_Type_Last then -- We perform a two-part test. First we determine whether the -- computed Last value lies in the base range of the type, and then -- determine whether it lies in the range of the index (sub)type. -- Last must satisfy this relation: -- First + Length - 1 <= Last -- We regroup terms: -- First - 1 <= Last - Length -- Which can rewrite as: -- No_Index <= Last - Length if Checks and then Index_Type'Base'Last - Index_Type'Base (Capacity) < No_Index then raise Constraint_Error with "Capacity is out of range"; end if; -- We now know that the computed value of Last is within the base -- range of the type, so it is safe to compute its value: Last := No_Index + Index_Type'Base (Capacity); -- Finally we test whether the value is within the range of the -- generic actual index subtype: if Checks and then Last > Index_Type'Last then raise Constraint_Error with "Capacity is out of range"; end if; elsif Index_Type'First <= 0 then -- Here we can compute Last directly, in the normal way. We know that -- No_Index is less than 0, so there is no danger of overflow when -- adding the (positive) value of Capacity. Index := Count_Type'Base (No_Index) + Capacity; -- Last if Checks and then Index > Count_Type'Base (Index_Type'Last) then raise Constraint_Error with "Capacity is out of range"; end if; -- We know that the computed value (having type Count_Type) of Last -- is within the range of the generic actual index subtype, so it is -- safe to convert to Index_Type: Last := Index_Type'Base (Index); else -- Here Index_Type'First (and Index_Type'Last) is positive, so we -- must test the length indirectly (by working backwards from the -- largest possible value of Last), in order to prevent overflow. Index := Count_Type'Base (Index_Type'Last) - Capacity; -- No_Index if Checks and then Index < Count_Type'Base (No_Index) then raise Constraint_Error with "Capacity is out of range"; end if; -- We have determined that the value of Capacity would not create a -- Last index value outside of the range of Index_Type, so we can now -- safely compute its value. Last := Index_Type'Base (Count_Type'Base (No_Index) + Capacity); end if; -- The requested capacity is non-zero, but we don't know yet whether -- this is a request for expansion or contraction of storage. if Container.Elements = null then -- The container is empty (it doesn't even have an internal array), -- so this represents a request to allocate storage having the given -- capacity. Container.Elements := new Elements_Type (Last); return; end if; if Capacity <= N then -- This is a request to trim back storage, but only to the limit of -- what's already in the container. (Reserve_Capacity never deletes -- active elements, it only reclaims excess storage.) if N < Container.Elements.EA'Length then -- The container is not empty (because the requested capacity is -- positive, and less than or equal to the container length), and -- the current length is less than the current capacity, so there -- is storage available to trim. In this case, we allocate a new -- internal array having a length that exactly matches the number -- of items in the container. TC_Check (Container.TC); declare subtype Array_Index_Subtype is Index_Type'Base range Index_Type'First .. Container.Last; Src : Elements_Array renames Container.Elements.EA (Array_Index_Subtype); X : Elements_Access := Container.Elements; begin -- Although we have isolated the old internal array that we're -- going to deallocate, we don't deallocate it until we have -- successfully allocated a new one. If there is an exception -- during allocation (because there is not enough storage), we -- let it propagate without causing any side-effect. Container.Elements := new Elements_Type'(Container.Last, Src); -- We have successfully allocated a new internal array (with a -- smaller length than the old one, and containing a copy of -- just the active elements in the container), so it is now -- safe to deallocate the old array. Free (X); end; end if; return; end if; -- The requested capacity is larger than the container length (the -- number of active elements). Whether this represents a request for -- expansion or contraction of the current capacity depends on what the -- current capacity is. if Capacity = Container.Elements.EA'Length then -- The requested capacity matches the existing capacity, so there's -- nothing to do here. We treat this case as a no-op, and simply -- return without checking the busy bit. return; end if; -- There is a change in the capacity of a non-empty container, so a new -- internal array will be allocated. (The length of the new internal -- array could be less or greater than the old internal array. We know -- only that the length of the new internal array is greater than the -- number of active elements in the container.) We must check whether -- the container is busy before doing anything else. TC_Check (Container.TC); -- We now allocate a new internal array, having a length different from -- its current value. declare X : Elements_Access := Container.Elements; subtype Index_Subtype is Index_Type'Base range Index_Type'First .. Container.Last; begin -- We now allocate a new internal array, having a length different -- from its current value. Container.Elements := new Elements_Type (Last); -- We have successfully allocated the new internal array, so now we -- move the existing elements from the existing the old internal -- array onto the new one. Note that we're just copying access -- values, to this should not raise any exceptions. Container.Elements.EA (Index_Subtype) := X.EA (Index_Subtype); -- We have moved the elements from the old internal array, so now we -- can deallocate it. Free (X); end; end Reserve_Capacity; ---------------------- -- Reverse_Elements -- ---------------------- procedure Reverse_Elements (Container : in out Vector) is begin if Container.Length <= 1 then return; end if; -- The exception behavior for the vector container must match that for -- the list container, so we check for cursor tampering here (which will -- catch more things) instead of for element tampering (which will catch -- fewer things). It's true that the elements of this vector container -- could be safely moved around while (say) an iteration is taking place -- (iteration only increments the busy counter), and so technically all -- we would need here is a test for element tampering (indicated by the -- lock counter), that's simply an artifact of our array-based -- implementation. Logically Reverse_Elements requires a check for -- cursor tampering. TC_Check (Container.TC); declare I : Index_Type; J : Index_Type; E : Elements_Array renames Container.Elements.EA; begin I := Index_Type'First; J := Container.Last; while I < J loop declare EI : constant Element_Access := E (I); begin E (I) := E (J); E (J) := EI; end; I := I + 1; J := J - 1; end loop; end; end Reverse_Elements; ------------------ -- Reverse_Find -- ------------------ function Reverse_Find (Container : Vector; Item : Element_Type; Position : Cursor := No_Element) return Cursor is Last : Index_Type'Base; begin if Checks and then Position.Container /= null and then Position.Container /= Container'Unrestricted_Access then raise Program_Error with "Position cursor denotes wrong container"; end if; Last := (if Position.Container = null or else Position.Index > Container.Last then Container.Last else Position.Index); -- Per AI05-0022, the container implementation is required to detect -- element tampering by a generic actual subprogram. declare Lock : With_Lock (Container.TC'Unrestricted_Access); begin for Indx in reverse Index_Type'First .. Last loop if Container.Elements.EA (Indx) /= null and then Container.Elements.EA (Indx).all = Item then return Cursor'(Container'Unrestricted_Access, Indx); end if; end loop; return No_Element; end; end Reverse_Find; ------------------------ -- Reverse_Find_Index -- ------------------------ function Reverse_Find_Index (Container : Vector; Item : Element_Type; Index : Index_Type := Index_Type'Last) return Extended_Index is -- Per AI05-0022, the container implementation is required to detect -- element tampering by a generic actual subprogram. Lock : With_Lock (Container.TC'Unrestricted_Access); Last : constant Index_Type'Base := Index_Type'Min (Container.Last, Index); begin for Indx in reverse Index_Type'First .. Last loop if Container.Elements.EA (Indx) /= null and then Container.Elements.EA (Indx).all = Item then return Indx; end if; end loop; return No_Index; end Reverse_Find_Index; --------------------- -- Reverse_Iterate -- --------------------- procedure Reverse_Iterate (Container : Vector; Process : not null access procedure (Position : Cursor)) is Busy : With_Busy (Container.TC'Unrestricted_Access); begin for Indx in reverse Index_Type'First .. Container.Last loop Process (Cursor'(Container'Unrestricted_Access, Indx)); end loop; end Reverse_Iterate; ---------------- -- Set_Length -- ---------------- procedure Set_Length (Container : in out Vector; Length : Count_Type) is Count : constant Count_Type'Base := Container.Length - Length; begin -- Set_Length allows the user to set the length explicitly, instead of -- implicitly as a side-effect of deletion or insertion. If the -- requested length is less than the current length, this is equivalent -- to deleting items from the back end of the vector. If the requested -- length is greater than the current length, then this is equivalent to -- inserting "space" (nonce items) at the end. if Count >= 0 then Container.Delete_Last (Count); elsif Checks and then Container.Last >= Index_Type'Last then raise Constraint_Error with "vector is already at its maximum length"; else Container.Insert_Space (Container.Last + 1, -Count); end if; end Set_Length; ---------- -- Swap -- ---------- procedure Swap (Container : in out Vector; I, J : Index_Type) is begin TE_Check (Container.TC); if Checks then if I > Container.Last then raise Constraint_Error with "I index is out of range"; end if; if J > Container.Last then raise Constraint_Error with "J index is out of range"; end if; end if; if I = J then return; end if; declare EI : Element_Access renames Container.Elements.EA (I); EJ : Element_Access renames Container.Elements.EA (J); EI_Copy : constant Element_Access := EI; begin EI := EJ; EJ := EI_Copy; end; end Swap; procedure Swap (Container : in out Vector; I, J : Cursor) is begin if Checks then if I.Container = null then raise Constraint_Error with "I cursor has no element"; end if; if J.Container = null then raise Constraint_Error with "J cursor has no element"; end if; if I.Container /= Container'Unrestricted_Access then raise Program_Error with "I cursor denotes wrong container"; end if; if J.Container /= Container'Unrestricted_Access then raise Program_Error with "J cursor denotes wrong container"; end if; end if; Swap (Container, I.Index, J.Index); end Swap; --------------- -- To_Cursor -- --------------- function To_Cursor (Container : Vector; Index : Extended_Index) return Cursor is begin if Index not in Index_Type'First .. Container.Last then return No_Element; end if; return Cursor'(Container'Unrestricted_Access, Index); end To_Cursor; -------------- -- To_Index -- -------------- function To_Index (Position : Cursor) return Extended_Index is begin if Position.Container = null then return No_Index; elsif Position.Index <= Position.Container.Last then return Position.Index; else return No_Index; end if; end To_Index; --------------- -- To_Vector -- --------------- function To_Vector (Length : Count_Type) return Vector is Index : Count_Type'Base; Last : Index_Type'Base; Elements : Elements_Access; begin if Length = 0 then return Empty_Vector; end if; -- We create a vector object with a capacity that matches the specified -- Length, but we do not allow the vector capacity (the length of the -- internal array) to exceed the number of values in Index_Type'Range -- (otherwise, there would be no way to refer to those components via an -- index). We must therefore check whether the specified Length would -- create a Last index value greater than Index_Type'Last. if Index_Type'Base'Last >= Count_Type_Last then -- We perform a two-part test. First we determine whether the -- computed Last value lies in the base range of the type, and then -- determine whether it lies in the range of the index (sub)type. -- Last must satisfy this relation: -- First + Length - 1 <= Last -- We regroup terms: -- First - 1 <= Last - Length -- Which can rewrite as: -- No_Index <= Last - Length if Checks and then Index_Type'Base'Last - Index_Type'Base (Length) < No_Index then raise Constraint_Error with "Length is out of range"; end if; -- We now know that the computed value of Last is within the base -- range of the type, so it is safe to compute its value: Last := No_Index + Index_Type'Base (Length); -- Finally we test whether the value is within the range of the -- generic actual index subtype: if Checks and then Last > Index_Type'Last then raise Constraint_Error with "Length is out of range"; end if; elsif Index_Type'First <= 0 then -- Here we can compute Last directly, in the normal way. We know that -- No_Index is less than 0, so there is no danger of overflow when -- adding the (positive) value of Length. Index := Count_Type'Base (No_Index) + Length; -- Last if Checks and then Index > Count_Type'Base (Index_Type'Last) then raise Constraint_Error with "Length is out of range"; end if; -- We know that the computed value (having type Count_Type) of Last -- is within the range of the generic actual index subtype, so it is -- safe to convert to Index_Type: Last := Index_Type'Base (Index); else -- Here Index_Type'First (and Index_Type'Last) is positive, so we -- must test the length indirectly (by working backwards from the -- largest possible value of Last), in order to prevent overflow. Index := Count_Type'Base (Index_Type'Last) - Length; -- No_Index if Checks and then Index < Count_Type'Base (No_Index) then raise Constraint_Error with "Length is out of range"; end if; -- We have determined that the value of Length would not create a -- Last index value outside of the range of Index_Type, so we can now -- safely compute its value. Last := Index_Type'Base (Count_Type'Base (No_Index) + Length); end if; Elements := new Elements_Type (Last); return Vector'(Controlled with Elements, Last, TC => <>); end To_Vector; function To_Vector (New_Item : Element_Type; Length : Count_Type) return Vector is Index : Count_Type'Base; Last : Index_Type'Base; Elements : Elements_Access; begin if Length = 0 then return Empty_Vector; end if; -- We create a vector object with a capacity that matches the specified -- Length, but we do not allow the vector capacity (the length of the -- internal array) to exceed the number of values in Index_Type'Range -- (otherwise, there would be no way to refer to those components via an -- index). We must therefore check whether the specified Length would -- create a Last index value greater than Index_Type'Last. if Index_Type'Base'Last >= Count_Type_Last then -- We perform a two-part test. First we determine whether the -- computed Last value lies in the base range of the type, and then -- determine whether it lies in the range of the index (sub)type. -- Last must satisfy this relation: -- First + Length - 1 <= Last -- We regroup terms: -- First - 1 <= Last - Length -- Which can rewrite as: -- No_Index <= Last - Length if Checks and then Index_Type'Base'Last - Index_Type'Base (Length) < No_Index then raise Constraint_Error with "Length is out of range"; end if; -- We now know that the computed value of Last is within the base -- range of the type, so it is safe to compute its value: Last := No_Index + Index_Type'Base (Length); -- Finally we test whether the value is within the range of the -- generic actual index subtype: if Checks and then Last > Index_Type'Last then raise Constraint_Error with "Length is out of range"; end if; elsif Index_Type'First <= 0 then -- Here we can compute Last directly, in the normal way. We know that -- No_Index is less than 0, so there is no danger of overflow when -- adding the (positive) value of Length. Index := Count_Type'Base (No_Index) + Length; -- Last if Checks and then Index > Count_Type'Base (Index_Type'Last) then raise Constraint_Error with "Length is out of range"; end if; -- We know that the computed value (having type Count_Type) of Last -- is within the range of the generic actual index subtype, so it is -- safe to convert to Index_Type: Last := Index_Type'Base (Index); else -- Here Index_Type'First (and Index_Type'Last) is positive, so we -- must test the length indirectly (by working backwards from the -- largest possible value of Last), in order to prevent overflow. Index := Count_Type'Base (Index_Type'Last) - Length; -- No_Index if Checks and then Index < Count_Type'Base (No_Index) then raise Constraint_Error with "Length is out of range"; end if; -- We have determined that the value of Length would not create a -- Last index value outside of the range of Index_Type, so we can now -- safely compute its value. Last := Index_Type'Base (Count_Type'Base (No_Index) + Length); end if; Elements := new Elements_Type (Last); -- We use Last as the index of the loop used to populate the internal -- array with items. In general, we prefer to initialize the loop index -- immediately prior to entering the loop. However, Last is also used in -- the exception handler (to reclaim elements that have been allocated, -- before propagating the exception), and the initialization of Last -- after entering the block containing the handler confuses some static -- analysis tools, with respect to whether Last has been properly -- initialized when the handler executes. So here we initialize our loop -- variable earlier than we prefer, before entering the block, so there -- is no ambiguity. Last := Index_Type'First; declare -- The element allocator may need an accessibility check in the case -- where the actual type is class-wide or has access discriminants -- (see RM 4.8(10.1) and AI12-0035). pragma Unsuppress (Accessibility_Check); begin loop Elements.EA (Last) := new Element_Type'(New_Item); exit when Last = Elements.Last; Last := Last + 1; end loop; exception when others => for J in Index_Type'First .. Last - 1 loop Free (Elements.EA (J)); end loop; Free (Elements); raise; end; return (Controlled with Elements, Last, TC => <>); end To_Vector; -------------------- -- Update_Element -- -------------------- procedure Update_Element (Container : in out Vector; Index : Index_Type; Process : not null access procedure (Element : in out Element_Type)) is Lock : With_Lock (Container.TC'Unchecked_Access); begin if Checks and then Index > Container.Last then raise Constraint_Error with "Index is out of range"; end if; if Checks and then Container.Elements.EA (Index) = null then raise Constraint_Error with "element is null"; end if; Process (Container.Elements.EA (Index).all); end Update_Element; procedure Update_Element (Container : in out Vector; Position : Cursor; Process : not null access procedure (Element : in out Element_Type)) is begin if Checks then if Position.Container = null then raise Constraint_Error with "Position cursor has no element"; elsif Position.Container /= Container'Unrestricted_Access then raise Program_Error with "Position cursor denotes wrong container"; end if; end if; Update_Element (Container, Position.Index, Process); end Update_Element; ----------- -- Write -- ----------- procedure Write (Stream : not null access Root_Stream_Type'Class; Container : Vector) is N : constant Count_Type := Length (Container); begin Count_Type'Base'Write (Stream, N); if N = 0 then return; end if; declare E : Elements_Array renames Container.Elements.EA; begin for Indx in Index_Type'First .. Container.Last loop if E (Indx) = null then Boolean'Write (Stream, False); else Boolean'Write (Stream, True); Element_Type'Output (Stream, E (Indx).all); end if; end loop; end; end Write; procedure Write (Stream : not null access Root_Stream_Type'Class; Position : Cursor) is begin raise Program_Error with "attempt to stream vector cursor"; end Write; procedure Write (Stream : not null access Root_Stream_Type'Class; Item : Reference_Type) is begin raise Program_Error with "attempt to stream reference"; end Write; procedure Write (Stream : not null access Root_Stream_Type'Class; Item : Constant_Reference_Type) is begin raise Program_Error with "attempt to stream reference"; end Write; end Ada.Containers.Indefinite_Vectors;
yluo39github/MachineLearningSAT
Ada
3,720
adb
---------------------------------------------------------------- -- ZLib for Ada thick binding. -- -- -- -- Copyright (C) 2002-2004 Dmitriy Anisimkov -- -- -- -- Open source license information is in the zlib.ads file. -- ---------------------------------------------------------------- -- -- $Id: buffer_demo.adb,v 1.1 2008/12/11 02:41:27 xulin730 Exp $ -- This demo program provided by Dr Steve Sangwine <[email protected]> -- -- Demonstration of a problem with Zlib-Ada (already fixed) when a buffer -- of exactly the correct size is used for decompressed data, and the last -- few bytes passed in to Zlib are checksum bytes. -- This program compresses a string of text, and then decompresses the -- compressed text into a buffer of the same size as the original text. with Ada.Streams; use Ada.Streams; with Ada.Text_IO; with ZLib; use ZLib; procedure Buffer_Demo is EOL : Character renames ASCII.LF; Text : constant String := "Four score and seven years ago our fathers brought forth," & EOL & "upon this continent, a new nation, conceived in liberty," & EOL & "and dedicated to the proposition that `all men are created equal'."; Source : Stream_Element_Array (1 .. Text'Length); for Source'Address use Text'Address; begin Ada.Text_IO.Put (Text); Ada.Text_IO.New_Line; Ada.Text_IO.Put_Line ("Uncompressed size : " & Positive'Image (Text'Length) & " bytes"); declare Compressed_Data : Stream_Element_Array (1 .. Text'Length); L : Stream_Element_Offset; begin Compress : declare Compressor : Filter_Type; I : Stream_Element_Offset; begin Deflate_Init (Compressor); -- Compress the whole of T at once. Translate (Compressor, Source, I, Compressed_Data, L, Finish); pragma Assert (I = Source'Last); Close (Compressor); Ada.Text_IO.Put_Line ("Compressed size : " & Stream_Element_Offset'Image (L) & " bytes"); end Compress; -- Now we decompress the data, passing short blocks of data to Zlib -- (because this demonstrates the problem - the last block passed will -- contain checksum information and there will be no output, only a -- check inside Zlib that the checksum is correct). Decompress : declare Decompressor : Filter_Type; Uncompressed_Data : Stream_Element_Array (1 .. Text'Length); Block_Size : constant := 4; -- This makes sure that the last block contains -- only Adler checksum data. P : Stream_Element_Offset := Compressed_Data'First - 1; O : Stream_Element_Offset; begin Inflate_Init (Decompressor); loop Translate (Decompressor, Compressed_Data (P + 1 .. Stream_Element_Offset'Min (P + Block_Size, L)), P, Uncompressed_Data (Total_Out (Decompressor) + 1 .. Uncompressed_Data'Last), O, No_Flush); Ada.Text_IO.Put_Line ("Total in : " & Count'Image (Total_In (Decompressor)) & ", out : " & Count'Image (Total_Out (Decompressor))); exit when P = L; end loop; Ada.Text_IO.New_Line; Ada.Text_IO.Put_Line ("Decompressed text matches original text : " & Boolean'Image (Uncompressed_Data = Source)); end Decompress; end; end Buffer_Demo;
rveenker/sdlada
Ada
6,155
adb
-------------------------------------------------------------------------------------------------------------------- -- Copyright (c) 2013-2020, Luke A. Guest -- -- This software is provided 'as-is', without any express or implied -- warranty. In no event will the authors be held liable for any damages -- arising from the use of this software. -- -- Permission is granted to anyone to use this software for any purpose, -- including commercial applications, and to alter it and redistribute it -- freely, subject to the following restrictions: -- -- 1. The origin of this software must not be misrepresented; you must not -- claim that you wrote the original software. If you use this software -- in a product, an acknowledgment in the product documentation would be -- appreciated but is not required. -- -- 2. Altered source versions must be plainly marked as such, and must not be -- misrepresented as being the original software. -- -- 3. This notice may not be removed or altered from any source -- distribution. -------------------------------------------------------------------------------------------------------------------- with Interfaces.C; with SDL.C_Pointers; with SDL.Error; with System; package body SDL.Inputs.Mice is package C renames Interfaces.C; use type C.int; use type C.unsigned; function Capture (Enabled : in Boolean) return Supported is function SDL_Capture_Mouse (Enabled : in C.unsigned) return C.int with Import => True, Convention => C, External_Name => "SDL_CaptureMouse"; begin if SDL_Capture_Mouse (if Enabled = True then 1 else 0) /= Success then return No; end if; return Yes; end Capture; function Get_Global_State (X_Relative, Y_Relative : out SDL.Events.Mice.Movement_Values) return SDL.Events.Mice.Button_Masks is function SDL_Get_Global_Mouse_State (X, Y : out C.int) return C.unsigned with Import => True, Convention => C, External_Name => "SDL_GetGlobalMouseState"; X, Y : C.int; Masks : C.unsigned := SDL_Get_Global_Mouse_State (X, Y); use SDL.Events.Mice; begin X_Relative := Movement_Values (X); Y_Relative := Movement_Values (Y); return Button_Masks (Masks); end Get_Global_State; function Get_State (X_Relative, Y_Relative : out SDL.Events.Mice.Movement_Values) return SDL.Events.Mice.Button_Masks is function SDL_Get_Mouse_State (X, Y : out C.int) return C.unsigned with Import => True, Convention => C, External_Name => "SDL_GetMouseState"; X, Y : C.int; Masks : C.unsigned := SDL_Get_Mouse_State (X, Y); use SDL.Events.Mice; begin X_Relative := Movement_Values (X); Y_Relative := Movement_Values (Y); return Button_Masks (Masks); end Get_State; function In_Relative_Mode return Boolean is function SDL_Get_Relative_Mouse_Mode return SDL_Bool with Import => True, Convention => C, External_Name => "SDL_GetRelativeMouseMode"; begin return SDL_Get_Relative_Mouse_Mode = SDL_True; end In_Relative_Mode; function Get_Relative_State (X_Relative, Y_Relative : out SDL.Events.Mice.Movement_Values) return SDL.Events.Mice.Button_Masks is function SDL_Get_Relative_Mouse_State (X, Y : out C.int) return C.unsigned with Import => True, Convention => C, External_Name => "SDL_GetRelativeMouseState"; X, Y : C.int; Masks : C.unsigned := SDL_Get_Relative_Mouse_State (X, Y); use SDL.Events.Mice; begin X_Relative := Movement_Values (X); Y_Relative := Movement_Values (Y); return Button_Masks (Masks); end Get_Relative_State; procedure Set_Relative_Mode (Enable : in Boolean := True) is function SDL_Set_Relative_Mouse_Mode (Enable : in C.unsigned) return C.int with Import => True, Convention => C, External_Name => "SDL_SetRelativeMouseMode"; begin if SDL_Set_Relative_Mouse_Mode (if Enable = True then 1 else 0) /= Success then raise Mice_Error with SDL.Error.Get; end if; end Set_Relative_Mode; procedure Show_Cursor (Enable : in Boolean := True) is procedure SDL_Show_Cursor (Enable : in C.int) with Import => True, Convention => C, External_Name => "SDL_ShowCursor"; begin SDL_Show_Cursor (if Enable = True then SDL.SDL_Enable else SDL.SDL_Disable); end Show_Cursor; function Is_Cursor_Shown return Boolean is function SDL_Show_Cursor (Enable : in C.int) return C.int with Import => True, Convention => C, External_Name => "SDL_ShowCursor"; begin case SDL_Show_Cursor (SDL.SDL_Query) is when SDL.SDL_Enable => return True; when SDL.SDL_Disable => return False; when others => raise Mice_Error with "SDL_Show_Cursor should never return any other value!"; end case; end Is_Cursor_Shown; procedure Warp (To : in SDL.Coordinates) is function SDL_Warp_Mouse_Global (X, Y : in C.int) return C.int with Import => True, Convention => C, External_Name => "SDL_WarpMouseGlobal"; begin if SDL_Warp_Mouse_Global (C.int (To.X), C.int (To.Y)) /= SDL.Success then raise Mice_Error with SDL.Error.Get; end if; end Warp; procedure Warp (Window : in SDL.Video.Windows.Window; To : in SDL.Coordinates) is function Get_Internal_Window (Self : in SDL.Video.Windows.Window) return SDL.C_Pointers.Windows_Pointer with Import => True, Convention => Ada; procedure SDL_Warp_Mouse_In_Window (Window : in SDL.C_Pointers.Windows_Pointer; X, Y : in C.int) with Import => True, Convention => C, External_Name => "SDL_WarpMouseInWindow"; begin SDL_Warp_Mouse_In_Window (Get_Internal_Window (Window), C.int (To.X), C.int (To.Y)); end Warp; end SDL.Inputs.Mice;
shintakezou/drake
Ada
8,536
adb
with Ada.Exception_Identification.From_Here; with Ada.Exceptions.Finally; with System.Formatting; with System.Long_Long_Integer_Types; with System.Synchronous_Control; with C.errno; with C.netinet.in_h; with C.unistd; package body System.Native_IO.Sockets is use Ada.Exception_Identification.From_Here; use type C.size_t; use type C.netdb.struct_addrinfo_ptr; use type C.sys.socket.socklen_t; subtype Word_Unsigned is Long_Long_Integer_Types.Word_Unsigned; -- implementation procedure Close_Socket (Handle : Handle_Type; Raise_On_Error : Boolean) is R : C.signed_int; begin R := C.unistd.close (Handle); if R < 0 and then Raise_On_Error then Raise_Exception (Use_Error'Identity); end if; end Close_Socket; -- client function Get ( Host_Name : not null access constant C.char; Service : not null access constant C.char; Hints : not null access constant C.netdb.struct_addrinfo) return End_Point; function Get ( Host_Name : not null access constant C.char; Service : not null access constant C.char; Hints : not null access constant C.netdb.struct_addrinfo) return End_Point is Data : aliased C.netdb.struct_addrinfo_ptr; R : C.signed_int; begin R := C.netdb.getaddrinfo (Host_Name, Service, Hints, Data'Access); if R /= 0 then Raise_Exception (Use_Error'Identity); else return Data; end if; end Get; -- implementation of client function Resolve (Host_Name : String; Service : String) return End_Point is Hints : aliased constant C.netdb.struct_addrinfo := ( ai_flags => 0, ai_family => C.sys.socket.AF_UNSPEC, ai_socktype => C.sys.socket.SOCK_STREAM, ai_protocol => C.netinet.in_h.IPPROTO_TCP, ai_addrlen => 0, ai_canonname => null, ai_addr => null, ai_next => null); C_Host_Name : C.char_array ( 0 .. Host_Name'Length * Zero_Terminated_Strings.Expanding); C_Service : C.char_array ( 0 .. Service'Length * Zero_Terminated_Strings.Expanding); begin Zero_Terminated_Strings.To_C (Host_Name, C_Host_Name (0)'Access); Zero_Terminated_Strings.To_C (Service, C_Service (0)'Access); return Get (C_Host_Name (0)'Access, C_Service (0)'Access, Hints'Access); end Resolve; function Resolve (Host_Name : String; Port : Port_Number) return End_Point is Hints : aliased constant C.netdb.struct_addrinfo := ( ai_flags => 0, -- darwin9 does not have AI_NUMERICSERV ai_family => C.sys.socket.AF_UNSPEC, ai_socktype => C.sys.socket.SOCK_STREAM, ai_protocol => C.netinet.in_h.IPPROTO_TCP, ai_addrlen => 0, ai_canonname => null, ai_addr => null, ai_next => null); C_Host_Name : C.char_array ( 0 .. Host_Name'Length * Zero_Terminated_Strings.Expanding); Service : C.char_array (0 .. 5); -- "65535" & NUL Service_Length : C.size_t; Error : Boolean; begin Zero_Terminated_Strings.To_C (Host_Name, C_Host_Name (0)'Access); declare Service_As_String : String (1 .. 5); for Service_As_String'Address use Service'Address; Service_Last : Natural; begin Formatting.Image ( Word_Unsigned (Port), Service_As_String, Service_Last, Base => 10, Error => Error); Service_Length := C.size_t (Service_Last); end; Service (Service_Length) := C.char'Val (0); return Get (C_Host_Name (0)'Access, Service (0)'Access, Hints'Access); end Resolve; procedure Connect (Handle : aliased out Handle_Type; Peer : End_Point) is I : C.netdb.struct_addrinfo_ptr := Peer; begin while I /= null loop Handle := C.sys.socket.socket (I.ai_family, I.ai_socktype, I.ai_protocol); if Handle >= 0 then if C.sys.socket.connect (Handle, I.ai_addr, I.ai_addrlen) = 0 then -- connected Set_Close_On_Exec (Handle); return; end if; declare Closing_Handle : constant Handle_Type := Handle; begin Handle := Invalid_Handle; Close_Socket (Closing_Handle, Raise_On_Error => True); end; end if; I := I.ai_next; end loop; Raise_Exception (Use_Error'Identity); end Connect; procedure Finalize (Item : End_Point) is begin C.netdb.freeaddrinfo (Item); end Finalize; -- implementation of server procedure Listen (Server : aliased out Listener; Port : Port_Number) is Hints : aliased constant C.netdb.struct_addrinfo := ( ai_flags => C.netdb.AI_PASSIVE, -- or AI_NUMERICSERV ai_family => C.sys.socket.AF_UNSPEC, ai_socktype => C.sys.socket.SOCK_STREAM, ai_protocol => C.netinet.in_h.IPPROTO_TCP, ai_addrlen => 0, ai_canonname => null, ai_addr => null, ai_next => null); Data : aliased C.netdb.struct_addrinfo_ptr; Service : C.char_array (0 .. 5); -- "65535" & NUL Service_Length : C.size_t; begin declare Service_As_String : String (1 .. 5); for Service_As_String'Address use Service'Address; Service_Last : Natural; Error : Boolean; begin Formatting.Image ( Word_Unsigned (Port), Service_As_String, Service_Last, Base => 10, Error => Error); Service_Length := C.size_t (Service_Last); end; Service (Service_Length) := C.char'Val (0); if C.netdb.getaddrinfo ( null, Service (0)'Access, Hints'Access, Data'Access) /= 0 then Raise_Exception (Use_Error'Identity); end if; declare procedure Finally (X : in out C.netdb.struct_addrinfo_ptr); procedure Finally (X : in out C.netdb.struct_addrinfo_ptr) is begin C.netdb.freeaddrinfo (X); end Finally; package Holder is new Ada.Exceptions.Finally.Scoped_Holder ( C.netdb.struct_addrinfo_ptr, Finally); Reuse_Addr_Option : aliased C.signed_int; begin Holder.Assign (Data); Server := C.sys.socket.socket ( Data.ai_family, Data.ai_socktype, Data.ai_protocol); -- set FD_CLOEXEC Set_Close_On_Exec (Server); -- set SO_REUSEADDR Reuse_Addr_Option := 1; if C.sys.socket.setsockopt ( Server, C.sys.socket.SOL_SOCKET, C.sys.socket.SO_REUSEADDR, C.void_const_ptr (Reuse_Addr_Option'Address), Reuse_Addr_Option'Size / Standard'Storage_Unit) < 0 then Raise_Exception (Use_Error'Identity); end if; -- bind if C.sys.socket.bind (Server, Data.ai_addr, Data.ai_addrlen) < 0 then Raise_Exception (Use_Error'Identity); end if; -- listen if C.sys.socket.listen (Server, C.sys.socket.SOMAXCONN) < 0 then Raise_Exception (Use_Error'Identity); end if; end; end Listen; procedure Accept_Socket ( Server : Listener; Handle : aliased out Handle_Type; Remote_Address : out Socket_Address) is begin loop declare Len : aliased C.sys.socket.socklen_t := Socket_Address'Size / Standard'Storage_Unit; New_Socket : C.signed_int; errno : C.signed_int; begin Synchronous_Control.Unlock_Abort; New_Socket := C.sys.socket.C_accept ( Server, Remote_Address'Unrestricted_Access, Len'Access); errno := C.errno.errno; Synchronous_Control.Lock_Abort; if New_Socket < 0 then if errno /= C.errno.EINTR then Raise_Exception (Use_Error'Identity); end if; -- interrupted and the signal is not "abort", then retry else Handle := New_Socket; Set_Close_On_Exec (Handle); exit; end if; end; end loop; end Accept_Socket; end System.Native_IO.Sockets;
AdaCore/gpr
Ada
393
ads
-- -- Copyright (C) 2019-2023, AdaCore -- -- SPDX-License-Identifier: Apache-2.0 WITH LLVM-Exception -- with Ada.Containers.Vectors; package GPR2.Project.View.Vector is package Vector is new Ada.Containers.Vectors (Positive, GPR2.Project.View.Object); subtype Object is Vector.Vector; Empty_Vector : constant Object := Vector.Empty_Vector; end GPR2.Project.View.Vector;
reznikmm/matreshka
Ada
4,656
adb
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.DOM_Documents; with Matreshka.ODF_String_Constants; with ODF.DOM.Iterators; with ODF.DOM.Visitors; package body Matreshka.ODF_Style.Paper_Tray_Name_Attributes is ------------ -- Create -- ------------ overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Style_Paper_Tray_Name_Attribute_Node is begin return Self : Style_Paper_Tray_Name_Attribute_Node do Matreshka.ODF_Style.Constructors.Initialize (Self'Unchecked_Access, Parameters.Document, Matreshka.ODF_String_Constants.Style_Prefix); end return; end Create; -------------------- -- Get_Local_Name -- -------------------- overriding function Get_Local_Name (Self : not null access constant Style_Paper_Tray_Name_Attribute_Node) return League.Strings.Universal_String is pragma Unreferenced (Self); begin return Matreshka.ODF_String_Constants.Paper_Tray_Name_Attribute; end Get_Local_Name; begin Matreshka.DOM_Documents.Register_Attribute (Matreshka.ODF_String_Constants.Style_URI, Matreshka.ODF_String_Constants.Paper_Tray_Name_Attribute, Style_Paper_Tray_Name_Attribute_Node'Tag); end Matreshka.ODF_Style.Paper_Tray_Name_Attributes;
Letractively/ada-el
Ada
9,618
adb
----------------------------------------------------------------------- -- EL.Contexts -- Default contexts for evaluating an expression -- Copyright (C) 2009, 2010, 2011, 2012 Stephane Carrez -- Written by Stephane Carrez ([email protected]) -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. ----------------------------------------------------------------------- with Ada.Unchecked_Deallocation; with EL.Variables.Default; package body EL.Contexts.Default is procedure Free is new Ada.Unchecked_Deallocation (Object => EL.Variables.Variable_Mapper'Class, Name => EL.Variables.Variable_Mapper_Access); -- ------------------------------ -- Retrieves the ELResolver associated with this ELcontext. -- ------------------------------ overriding function Get_Resolver (Context : Default_Context) return ELResolver_Access is begin return Context.Resolver; end Get_Resolver; -- ------------------------------ -- Set the ELResolver associated with this ELcontext. -- ------------------------------ procedure Set_Resolver (Context : in out Default_Context; Resolver : in ELResolver_Access) is begin Context.Resolver := Resolver; end Set_Resolver; -- ------------------------------ -- Retrieves the Variable_Mapper associated with this ELContext. -- ------------------------------ overriding function Get_Variable_Mapper (Context : Default_Context) return access EL.Variables.Variable_Mapper'Class is begin return Context.Var_Mapper; end Get_Variable_Mapper; -- ------------------------------ -- Retrieves the Function_Mapper associated with this ELContext. -- The Function_Mapper is only used when parsing an expression. -- ------------------------------ overriding function Get_Function_Mapper (Context : Default_Context) return EL.Functions.Function_Mapper_Access is begin return Context.Function_Mapper; end Get_Function_Mapper; -- ------------------------------ -- Set the function mapper to be used when parsing an expression. -- ------------------------------ overriding procedure Set_Function_Mapper (Context : in out Default_Context; Mapper : access EL.Functions.Function_Mapper'Class) is begin if Mapper = null then Context.Function_Mapper := null; else Context.Function_Mapper := Mapper.all'Unchecked_Access; end if; end Set_Function_Mapper; -- ------------------------------ -- Set the Variable_Mapper associated with this ELContext. -- ------------------------------ overriding procedure Set_Variable_Mapper (Context : in out Default_Context; Mapper : access EL.Variables.Variable_Mapper'Class) is use EL.Variables; begin if Context.Var_Mapper_Created then Free (Context.Var_Mapper); end if; if Mapper = null then Context.Var_Mapper := null; else Context.Var_Mapper := Mapper.all'Unchecked_Access; end if; end Set_Variable_Mapper; procedure Set_Variable (Context : in out Default_Context; Name : in String; Value : access Util.Beans.Basic.Readonly_Bean'Class) is use EL.Variables; begin if Context.Var_Mapper = null then Context.Var_Mapper := new EL.Variables.Default.Default_Variable_Mapper; Context.Var_Mapper_Created := True; end if; Context.Var_Mapper.Bind (Name, EL.Objects.To_Object (Value, EL.Objects.STATIC)); end Set_Variable; -- Handle the exception during expression evaluation. overriding procedure Handle_Exception (Context : in Default_Context; Ex : in Ada.Exceptions.Exception_Occurrence) is begin null; end Handle_Exception; -- ------------------------------ -- Guarded Context -- ------------------------------ -- ------------------------------ -- Retrieves the ELResolver associated with this ELcontext. -- ------------------------------ overriding function Get_Resolver (Context : in Guarded_Context) return ELResolver_Access is begin return Context.Context.Get_Resolver; end Get_Resolver; -- ------------------------------ -- Retrieves the Variable_Mapper associated with this ELContext. -- ------------------------------ overriding function Get_Variable_Mapper (Context : in Guarded_Context) return access EL.Variables.Variable_Mapper'Class is begin return Context.Context.Get_Variable_Mapper; end Get_Variable_Mapper; -- ------------------------------ -- Retrieves the Function_Mapper associated with this ELContext. -- The Function_Mapper is only used when parsing an expression. -- ------------------------------ overriding function Get_Function_Mapper (Context : in Guarded_Context) return EL.Functions.Function_Mapper_Access is begin return Context.Context.Get_Function_Mapper; end Get_Function_Mapper; -- ------------------------------ -- Set the function mapper to be used when parsing an expression. -- ------------------------------ overriding procedure Set_Function_Mapper (Context : in out Guarded_Context; Mapper : access EL.Functions.Function_Mapper'Class) is begin Context.Context.Set_Function_Mapper (Mapper); end Set_Function_Mapper; -- ------------------------------ -- Set the Variable_Mapper associated with this ELContext. -- ------------------------------ overriding procedure Set_Variable_Mapper (Context : in out Guarded_Context; Mapper : access EL.Variables.Variable_Mapper'Class) is begin Context.Context.Set_Variable_Mapper (Mapper); end Set_Variable_Mapper; -- ------------------------------ -- Handle the exception during expression evaluation. -- ------------------------------ overriding procedure Handle_Exception (Context : in Guarded_Context; Ex : in Ada.Exceptions.Exception_Occurrence) is begin Context.Handler.all (Ex); end Handle_Exception; -- ------------------------------ -- Get the value associated with a base object and a given property. -- ------------------------------ overriding function Get_Value (Resolver : Default_ELResolver; Context : ELContext'Class; Base : access Util.Beans.Basic.Readonly_Bean'Class; Name : Unbounded_String) return Object is pragma Unreferenced (Context); Key : constant String := To_String (Name); begin if Base /= null then return Base.Get_Value (Key); end if; declare Pos : constant Objects.Maps.Cursor := Resolver.Map.Find (Key); begin if Objects.Maps.Has_Element (Pos) then return Objects.Maps.Element (Pos); end if; end; return Util.Beans.Objects.Null_Object; end Get_Value; -- ------------------------------ -- Set the value associated with a base object and a given property. -- ------------------------------ overriding procedure Set_Value (Resolver : in out Default_ELResolver; Context : in ELContext'Class; Base : access Util.Beans.Basic.Bean'Class; Name : in Unbounded_String; Value : in Object) is begin null; end Set_Value; -- ------------------------------ -- Register the value under the given name. -- ------------------------------ procedure Register (Resolver : in out Default_ELResolver; Name : in Unbounded_String; Value : in Util.Beans.Basic.Readonly_Bean_Access) is begin Resolver.Register (Name, To_Object (Value)); end Register; -- ------------------------------ -- Register the value under the given name. -- ------------------------------ procedure Register (Resolver : in out Default_ELResolver; Name : in Unbounded_String; Value : in EL.Objects.Object) is Key : constant String := To_String (Name); begin Objects.Maps.Include (Resolver.Map, Key, Value); end Register; overriding procedure Finalize (Obj : in out Default_Context) is begin if Obj.Var_Mapper_Created then Free (Obj.Var_Mapper); end if; end Finalize; end EL.Contexts.Default;
reznikmm/matreshka
Ada
3,977
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2014, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with ODF.DOM.Text_Custom3_Attributes; package Matreshka.ODF_Text.Custom3_Attributes is type Text_Custom3_Attribute_Node is new Matreshka.ODF_Text.Abstract_Text_Attribute_Node and ODF.DOM.Text_Custom3_Attributes.ODF_Text_Custom3_Attribute with null record; overriding function Create (Parameters : not null access Matreshka.DOM_Attributes.Attribute_L2_Parameters) return Text_Custom3_Attribute_Node; overriding function Get_Local_Name (Self : not null access constant Text_Custom3_Attribute_Node) return League.Strings.Universal_String; end Matreshka.ODF_Text.Custom3_Attributes;
1Crazymoney/LearnAda
Ada
4,141
adb
with J_String_Pkg, Text_IO, Ada.Integer_Text_IO; use J_String_Pkg, Text_IO, Ada.Integer_Text_IO; procedure spec is Str : String := "test"; Js : J_String := Create(Str); Js1 : J_String := Create("test"); Js2 : J_String := Create("tes"); numberOfTests : Natural := 46; numberOfpassedTests : Natural := 0; procedure passed(Func : String) is begin Put_Line(Func & " - passed"); numberOfpassedTests := numberOfpassedTests + 1; end passed; begin if Value_Of(Create("asd")) = "asd" then passed("Create"); end if; if Value_Of(Js) = "test" then passed("Value_Of"); end if; if Char_At(Js, 1) = 't' then passed("Char_At"); end if; if Compare_To(Js, Js1) then passed("Compare_To"); end if; if Compare_To(Js, Js2) = false then passed("Compare_To"); end if; if Value_Of(Concat(Js1, Js2)) = "testtes" then passed("Concat"); end if; if Contains(Js1, "es") then passed("Contains"); end if; if Contains(Js2, "os") = false then passed("Contains"); end if; if Ends_With(Js1, 't') then passed("Ends_With"); end if; if Ends_With(Js1, 'a') = false then passed("Ends_With"); end if; if Ends_With(Js1, "st") then passed("Ends_With"); end if; if Ends_With(Js1, "at") = false then passed("Ends_With"); end if; if Js = Js1 then passed("="); end if; if Js1 /= Js2 then passed("="); end if; if Index_Of(Js1, 's') = 3 then passed("Index_Of"); end if; if Index_Of(Js1, 't') = 1 then passed("Index_Of"); end if; if Index_Of(Js1, 'x') = -1 then passed("Index_Of"); end if; if Index_Of(Js1, 'e', 5) = -1 then passed("Index_Of"); end if; if Index_Of(Js1, "est") = 2 then passed("Index_Of"); end if; if Index_Of(Js1, "tes") = 1 then passed("Index_Of"); end if; if Index_Of(Js1, "testt") = -1 then passed("Index_Of"); end if; if Index_Of(Js1, "os") = -1 then passed("Index_Of"); end if; if Is_Empty(Create("")) then passed("Is_Empty"); end if; if Is_Empty(Create("a")) = false then passed("Is_Empty"); end if; if Last_Index_Of(Create("abca"), 'a') = 4 then passed("Last_Index_Of"); end if; if Last_Index_Of(Create("abca"), 'x') = -1 then passed("Last_Index_Of"); end if; if Last_Index_Of(Create("abca"), 'a', 3) = 1 then passed("Last_Index_Of"); end if; if Last_Index_Of(Create("abca"), 'c', 2) = -1 then passed("Last_Index_Of"); end if; if Last_Index_Of(Create("abc"), 'c', 4) = -1 then passed("Last_Index_Of"); end if; if Length(Create("abc")) = 3 then passed("Length"); end if; if Length(Create("a")) = 1 then passed("Length"); end if; if Length(Create("")) = 0 then passed("Length"); end if; if Value_Of(Replace(Create("abc"), 'b', 'x')) = "axc" then passed("Replace"); end if; if Value_Of(Replace(Create("abca"), 'a', 'x')) = "xbcx" then passed("Replace"); end if; if Starts_With(Create("abc"), 'a') then passed("Starts_With"); end if; if Starts_With(Create("bc"), 'a') = false then passed("Starts_With"); end if; if Starts_With(Create("a"), 'a') then passed("Starts_With"); end if; if Starts_With(Create("b"), 'a') = false then passed("Starts_With"); end if; if Starts_With(Create("abc"), "ab") then passed("Starts_With"); end if; if Starts_With(Create("abc"), "ba") = false then passed("Starts_With"); end if; if Starts_With(Create("abc"), "abc") then passed("Starts_With"); end if; if Starts_With(Create("abc"), "abcd") = false then passed("Starts_With"); end if; if Value_Of(Substring(Create("abc"), 1)) = "abc" then passed("Substring"); end if; if Value_Of(Substring(Create("abc"), 2)) = "bc" then passed("Substring"); end if; if Value_Of(Substring(Create("abc"), 1, 2)) = "ab" then passed("Substring"); end if; if Value_Of(Substring(Create("abc"), 1, 1)) = "a" then passed("Substring"); end if; Put_Line("==============="); Put(numberOfpassedTests, 0); Put(" / "); Put(numberOfTests, 0); Put(" passed"); end spec;
reznikmm/matreshka
Ada
3,847
ads
------------------------------------------------------------------------------ -- -- -- Matreshka Project -- -- -- -- Open Document Toolkit -- -- -- -- Runtime Library Component -- -- -- ------------------------------------------------------------------------------ -- -- -- Copyright © 2013, Vadim Godunko <[email protected]> -- -- All rights reserved. -- -- -- -- Redistribution and use in source and binary forms, with or without -- -- modification, are permitted provided that the following conditions -- -- are met: -- -- -- -- * Redistributions of source code must retain the above copyright -- -- notice, this list of conditions and the following disclaimer. -- -- -- -- * Redistributions in binary form must reproduce the above copyright -- -- notice, this list of conditions and the following disclaimer in the -- -- documentation and/or other materials provided with the distribution. -- -- -- -- * Neither the name of the Vadim Godunko, IE nor the names of its -- -- contributors may be used to endorse or promote products derived from -- -- this software without specific prior written permission. -- -- -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- -- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- -- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- -- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- -- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- -- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- -- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- -- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- -- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- -- -- ------------------------------------------------------------------------------ -- $Revision$ $Date$ ------------------------------------------------------------------------------ with Matreshka.ODF_Elements.Text.Outline_Style; package ODF.DOM.Elements.Text.Outline_Style.Internals is function Create (Node : Matreshka.ODF_Elements.Text.Outline_Style.Text_Outline_Style_Access) return ODF.DOM.Elements.Text.Outline_Style.ODF_Text_Outline_Style; function Wrap (Node : Matreshka.ODF_Elements.Text.Outline_Style.Text_Outline_Style_Access) return ODF.DOM.Elements.Text.Outline_Style.ODF_Text_Outline_Style; end ODF.DOM.Elements.Text.Outline_Style.Internals;
AdaCore/libadalang
Ada
127
adb
package body Foo is procedure Bar (A : Integer) is type Foo is null record; begin null; end Bar; end Foo;