/usr/share/ada/adainclude/gtkada/glib-option.adb is in libgtkada16.1.0-dev 17.0.2017-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 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 91 92 93 94 95 96 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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 | ------------------------------------------------------------------------------
-- --
-- Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet --
-- Copyright (C) 2000-2017, AdaCore --
-- --
-- This library is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
-- Software Foundation; either version 3, or (at your option) any later --
-- version. This library is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- 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/>. --
-- --
------------------------------------------------------------------------------
pragma Style_Checks (Off);
pragma Warnings (Off, "*is already use-visible*");
with Ada.Unchecked_Conversion;
with Glib.Object;
package body Glib.Option is
function From_Object_Free
(B : access Goption_Context'Class) return Goption_Context
is
Result : constant Goption_Context := Goption_Context (B.all);
begin
Glib.g_free (B.all'Address);
return Result;
end From_Object_Free;
function From_Object (Object : System.Address) return Goption_Context is
S : Goption_Context;
begin
S.Set_Object (Object);
return S;
end From_Object;
function From_Object_Free (B : access GOption_Group) return GOption_Group is
Result : constant GOption_Group := B.all;
begin
Glib.g_free (B.all'Address);
return Result;
end From_Object_Free;
function From_Object_Free (B : access GOption_Entry) return GOption_Entry is
Result : constant GOption_Entry := B.all;
begin
Glib.g_free (B.all'Address);
return Result;
end From_Object_Free;
-----------
-- Parse --
-----------
procedure Parse
(Self : Goption_Context;
Command_Line : not null access Glib.Application.Gapplication_Command_Line_Record'Class;
Filter : Parse_Filter := null;
Success : out Boolean;
Error : out Glib.Error.GError)
is
function Get_Args
(Self : System.Address;
Argc : access Glib.Gint) return chars_ptr_array_access;
pragma Import (C, Get_Args, "g_application_command_line_get_arguments");
function Internal
(Self : System.Address;
Argc : access Glib.Gint;
Argv : System.Address;
Error : System.Address) return Glib.Gboolean;
pragma Import (C, Internal, "g_option_context_parse");
pragma Warnings (Off, "possible aliasing problem for*");
function Convert is new Ada.Unchecked_Conversion
(System.Address, chars_ptr_array_access);
pragma Warnings (On, "possible aliasing problem for*");
Argc : aliased Glib.Gint;
Argv : chars_ptr_array_access;
Err : Glib.Error.GError;
Ret : Glib.Gboolean;
begin
Argv := Get_Args (Command_Line.Get_Object, Argc'Access);
if Filter = null then
Ret := Internal (Get_Object (Self), Argc'Access, Argv'Address, Err'Address);
else
declare
Args : aliased ICS.chars_ptr_array := To_Chars_Ptr (Argv);
Idx : aliased Glib.Gint := 1;
begin
-- Copy command name argument
Args (0) := Argv (0);
Idx := 1;
for J in 1 .. Argc - 1 loop
if Filter (ICS.Value (Argv (Interfaces.C.size_t (J)))) then
Args (Interfaces.C.size_t (Idx)) :=
Argv (Interfaces.C.size_t (J));
Idx := Idx + 1;
end if;
end loop;
Argv := Convert (Args'Address);
Ret := Internal
(Get_Object (Self), Idx'Access, Argv'Address, Err'Address);
end;
end if;
Error := Err;
Success := Ret /= 0;
end Parse;
-----------
-- Parse --
-----------
procedure Parse
(Self : Goption_Context;
Argv : access chars_ptr_array_access;-- Null-terminated
Success : out Boolean;
Error : out Glib.Error.GError)
is
use Interfaces.C;
function Internal
(Self : System.Address;
Argc : access Glib.Gint;
Argv : access chars_ptr_array_access;
Error : System.Address) return Glib.Gboolean;
pragma Import (C, Internal, "g_option_context_parse");
Err : Glib.Error.GError;
Ret : Glib.Gboolean;
Argc : aliased Glib.Gint := 0;
begin
while Argv.all (size_t (Argc)) /= Null_Ptr loop
Argc := Argc + 1;
end loop;
Ret := Internal (Get_Object (Self), Argc'Access, Argv, Err'Address);
Argv.all (size_t (Argc)) := Null_Ptr;
Error := Err;
Success := Ret /= 0;
end Parse;
procedure C_G_Option_Context_Set_Translate_Func
(Self : System.Address;
Func : System.Address;
Data : System.Address;
Destroy_Notify : Glib.G_Destroy_Notify_Address);
pragma Import (C, C_G_Option_Context_Set_Translate_Func, "g_option_context_set_translate_func");
-- Sets the function which is used to translate the contexts user-visible
-- strings, for `--help` output. If Func is null, strings are not
-- translated.
-- Note that option groups have their own translation functions, this
-- function only affects the Parameter_String (see Glib.Option.G_New), the
-- summary (see Glib.Option.Set_Summary) and the description (see
-- Glib.Option.Set_Description).
-- If you are using gettext, you only need to set the translation domain,
-- see Glib.Option.Set_Translation_Domain.
-- Since: gtk+ 2.12
-- "func": the Gtranslate_Func, or null
-- "data": user data to pass to Func, or null
-- "destroy_notify": a function which gets called to free Data, or null
function To_Gtranslate_Func is new Ada.Unchecked_Conversion
(System.Address, Gtranslate_Func);
function To_Address is new Ada.Unchecked_Conversion
(Gtranslate_Func, System.Address);
function Internal_Gtranslate_Func
(Str : Interfaces.C.Strings.chars_ptr;
Data : System.Address) return Interfaces.C.Strings.chars_ptr;
pragma Convention (C, Internal_Gtranslate_Func);
-- "str": the untranslated string
-- "data": user data specified when installing the function, e.g. in
-- g_option_group_set_translate_func
------------------------------
-- Internal_Gtranslate_Func --
------------------------------
function Internal_Gtranslate_Func
(Str : Interfaces.C.Strings.chars_ptr;
Data : System.Address) return Interfaces.C.Strings.chars_ptr
is
Func : constant Gtranslate_Func := To_Gtranslate_Func (Data);
begin
return New_String (Func (Gtkada.Bindings.Value_Allowing_Null (Str)));
end Internal_Gtranslate_Func;
---------------
-- Add_Group --
---------------
procedure Add_Group (Self : Goption_Context; Group : GOption_Group) is
procedure Internal (Self : System.Address; Group : GOption_Group);
pragma Import (C, Internal, "g_option_context_add_group");
begin
Internal (Get_Object (Self), Group);
end Add_Group;
----------------------
-- Add_Main_Entries --
----------------------
procedure Add_Main_Entries
(Self : Goption_Context;
Entries : GOption_Entry_Array;
Translation_Domain : UTF8_String := "")
is
procedure Internal
(Self : System.Address;
Entries : GOption_Entry_Array;
Translation_Domain : Interfaces.C.Strings.chars_ptr);
pragma Import (C, Internal, "g_option_context_add_main_entries");
Tmp_Translation_Domain : Interfaces.C.Strings.chars_ptr;
begin
if Translation_Domain = "" then
Tmp_Translation_Domain := Interfaces.C.Strings.Null_Ptr;
else
Tmp_Translation_Domain := New_String (Translation_Domain);
end if;
Internal (Get_Object (Self), Entries, Tmp_Translation_Domain);
Free (Tmp_Translation_Domain);
end Add_Main_Entries;
----------
-- Free --
----------
procedure Free (Self : Goption_Context) is
procedure Internal (Self : System.Address);
pragma Import (C, Internal, "g_option_context_free");
begin
Internal (Get_Object (Self));
end Free;
---------------------
-- Get_Description --
---------------------
function Get_Description (Self : Goption_Context) return UTF8_String is
function Internal
(Self : System.Address) return Interfaces.C.Strings.chars_ptr;
pragma Import (C, Internal, "g_option_context_get_description");
begin
return Gtkada.Bindings.Value_Allowing_Null (Internal (Get_Object (Self)));
end Get_Description;
--------------
-- Get_Help --
--------------
function Get_Help
(Self : Goption_Context;
Main_Help : Boolean;
Group : GOption_Group) return UTF8_String
is
function Internal
(Self : System.Address;
Main_Help : Glib.Gboolean;
Group : GOption_Group) return Interfaces.C.Strings.chars_ptr;
pragma Import (C, Internal, "g_option_context_get_help");
begin
return Gtkada.Bindings.Value_And_Free (Internal (Get_Object (Self), Boolean'Pos (Main_Help), Group));
end Get_Help;
----------------------
-- Get_Help_Enabled --
----------------------
function Get_Help_Enabled (Self : Goption_Context) return Boolean is
function Internal (Self : System.Address) return Glib.Gboolean;
pragma Import (C, Internal, "g_option_context_get_help_enabled");
begin
return Internal (Get_Object (Self)) /= 0;
end Get_Help_Enabled;
--------------------------------
-- Get_Ignore_Unknown_Options --
--------------------------------
function Get_Ignore_Unknown_Options
(Self : Goption_Context) return Boolean
is
function Internal (Self : System.Address) return Glib.Gboolean;
pragma Import (C, Internal, "g_option_context_get_ignore_unknown_options");
begin
return Internal (Get_Object (Self)) /= 0;
end Get_Ignore_Unknown_Options;
--------------------
-- Get_Main_Group --
--------------------
function Get_Main_Group (Self : Goption_Context) return GOption_Group is
function Internal (Self : System.Address) return access GOption_Group;
pragma Import (C, Internal, "g_option_context_get_main_group");
begin
return Internal (Get_Object (Self)).all;
end Get_Main_Group;
-----------------
-- Get_Summary --
-----------------
function Get_Summary (Self : Goption_Context) return UTF8_String is
function Internal
(Self : System.Address) return Interfaces.C.Strings.chars_ptr;
pragma Import (C, Internal, "g_option_context_get_summary");
begin
return Gtkada.Bindings.Value_Allowing_Null (Internal (Get_Object (Self)));
end Get_Summary;
---------------------
-- Set_Description --
---------------------
procedure Set_Description
(Self : Goption_Context;
Description : UTF8_String := "")
is
procedure Internal
(Self : System.Address;
Description : Interfaces.C.Strings.chars_ptr);
pragma Import (C, Internal, "g_option_context_set_description");
Tmp_Description : Interfaces.C.Strings.chars_ptr;
begin
if Description = "" then
Tmp_Description := Interfaces.C.Strings.Null_Ptr;
else
Tmp_Description := New_String (Description);
end if;
Internal (Get_Object (Self), Tmp_Description);
Free (Tmp_Description);
end Set_Description;
----------------------
-- Set_Help_Enabled --
----------------------
procedure Set_Help_Enabled
(Self : Goption_Context;
Help_Enabled : Boolean)
is
procedure Internal
(Self : System.Address;
Help_Enabled : Glib.Gboolean);
pragma Import (C, Internal, "g_option_context_set_help_enabled");
begin
Internal (Get_Object (Self), Boolean'Pos (Help_Enabled));
end Set_Help_Enabled;
--------------------------------
-- Set_Ignore_Unknown_Options --
--------------------------------
procedure Set_Ignore_Unknown_Options
(Self : Goption_Context;
Ignore_Unknown : Boolean)
is
procedure Internal
(Self : System.Address;
Ignore_Unknown : Glib.Gboolean);
pragma Import (C, Internal, "g_option_context_set_ignore_unknown_options");
begin
Internal (Get_Object (Self), Boolean'Pos (Ignore_Unknown));
end Set_Ignore_Unknown_Options;
--------------------
-- Set_Main_Group --
--------------------
procedure Set_Main_Group (Self : Goption_Context; Group : GOption_Group) is
procedure Internal (Self : System.Address; Group : GOption_Group);
pragma Import (C, Internal, "g_option_context_set_main_group");
begin
Internal (Get_Object (Self), Group);
end Set_Main_Group;
-----------------
-- Set_Summary --
-----------------
procedure Set_Summary
(Self : Goption_Context;
Summary : UTF8_String := "")
is
procedure Internal
(Self : System.Address;
Summary : Interfaces.C.Strings.chars_ptr);
pragma Import (C, Internal, "g_option_context_set_summary");
Tmp_Summary : Interfaces.C.Strings.chars_ptr;
begin
if Summary = "" then
Tmp_Summary := Interfaces.C.Strings.Null_Ptr;
else
Tmp_Summary := New_String (Summary);
end if;
Internal (Get_Object (Self), Tmp_Summary);
Free (Tmp_Summary);
end Set_Summary;
------------------------
-- Set_Translate_Func --
------------------------
procedure Set_Translate_Func
(Self : Goption_Context;
Func : Gtranslate_Func;
Destroy_Notify : Glib.G_Destroy_Notify_Address)
is
begin
if Func = null then
C_G_Option_Context_Set_Translate_Func (Get_Object (Self), System.Null_Address, System.Null_Address, Destroy_Notify);
else
C_G_Option_Context_Set_Translate_Func (Get_Object (Self), Internal_Gtranslate_Func'Address, To_Address (Func), Destroy_Notify);
end if;
end Set_Translate_Func;
package body Set_Translate_Func_User_Data is
package Users is new Glib.Object.User_Data_Closure
(User_Data_Type, Destroy);
function To_Gtranslate_Func is new Ada.Unchecked_Conversion
(System.Address, Gtranslate_Func);
function To_Address is new Ada.Unchecked_Conversion
(Gtranslate_Func, System.Address);
function Internal_Cb
(Str : Interfaces.C.Strings.chars_ptr;
Data : System.Address) return Interfaces.C.Strings.chars_ptr;
pragma Convention (C, Internal_Cb);
-- The type of functions which are used to translate user-visible
-- strings, for <option>--help</option> output.
-- "str": the untranslated string
-- "data": user data specified when installing the function, e.g. in
-- g_option_group_set_translate_func
-----------------
-- Internal_Cb --
-----------------
function Internal_Cb
(Str : Interfaces.C.Strings.chars_ptr;
Data : System.Address) return Interfaces.C.Strings.chars_ptr
is
D : constant Users.Internal_Data_Access := Users.Convert (Data);
begin
return New_String (To_Gtranslate_Func (D.Func) (Gtkada.Bindings.Value_Allowing_Null (Str), D.Data.all));
end Internal_Cb;
------------------------
-- Set_Translate_Func --
------------------------
procedure Set_Translate_Func
(Self : Glib.Option.Goption_Context;
Func : Gtranslate_Func;
Data : User_Data_Type;
Destroy_Notify : Glib.G_Destroy_Notify_Address)
is
D : System.Address;
begin
if Func = null then
C_G_Option_Context_Set_Translate_Func (Get_Object (Self), System.Null_Address, System.Null_Address, Destroy_Notify);
else
D := Users.Build (To_Address (Func), Data);
C_G_Option_Context_Set_Translate_Func (Get_Object (Self), Internal_Cb'Address, D, Destroy_Notify);
end if;
end Set_Translate_Func;
end Set_Translate_Func_User_Data;
----------------------------
-- Set_Translation_Domain --
----------------------------
procedure Set_Translation_Domain
(Self : Goption_Context;
Domain : UTF8_String)
is
procedure Internal
(Self : System.Address;
Domain : Interfaces.C.Strings.chars_ptr);
pragma Import (C, Internal, "g_option_context_set_translation_domain");
Tmp_Domain : Interfaces.C.Strings.chars_ptr := New_String (Domain);
begin
Internal (Get_Object (Self), Tmp_Domain);
Free (Tmp_Domain);
end Set_Translation_Domain;
-----------
-- G_New --
-----------
function G_New
(Parameter_String : UTF8_String := "") return Goption_Context
is
function Internal
(Parameter_String : Interfaces.C.Strings.chars_ptr)
return System.Address;
pragma Import (C, Internal, "g_option_context_new");
Tmp_Parameter_String : Interfaces.C.Strings.chars_ptr;
Tmp_Return : System.Address;
begin
if Parameter_String = "" then
Tmp_Parameter_String := Interfaces.C.Strings.Null_Ptr;
else
Tmp_Parameter_String := New_String (Parameter_String);
end if;
Tmp_Return := Internal (Tmp_Parameter_String);
Free (Tmp_Parameter_String);
return From_Object (Tmp_Return);
end G_New;
end Glib.Option;
|