diff --git a/.gitignore b/.gitignore index 619986c..ce50467 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ gmem.out build __pycache__ logs +danger_zone diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f9d8c2..6997943 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.2.3] - 2021-02-05 +### Added +- Added complete colour/palette support for C. +### Fixed +- Fixed Malef.h formatting. +- Fixed functions return value. + ## [0.2.2] - 2021-01-30 ### Added - Added Surface type for Python3. diff --git a/VERSION b/VERSION index ee1372d..7179039 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.2 +0.2.3 diff --git a/ada-malef/src-base/malef-surfaces.adb b/ada-malef/src-base/malef-surfaces.adb index 6937c5e..46c4dde 100644 --- a/ada-malef/src-base/malef-surfaces.adb +++ b/ada-malef/src-base/malef-surfaces.adb @@ -29,7 +29,12 @@ with Ada.Text_IO; with Ada.Unchecked_Deallocation; with Malef.Systems; + +pragma Warnings (Off); +with System; +with System.Address_Image; with System.Atomic_Counters; +pragma Warnings (On); package body Malef.Surfaces is @@ -212,6 +217,100 @@ package body Malef.Surfaces is end Unreference; + +-- ------- DEBUG ------- + + +-- procedure Put (Operation : String; +-- Reference : not null Shared_Surface_Access) is +-- use type Ada.Text_IO.Count; +-- Is_Null : constant Boolean := Reference = Shared_Null_Surface'Access; +-- Address : constant System.Address := Reference.all'Address; +-- Length : constant := 15; +-- begin + +-- Ada.Text_IO.Set_Col (File => Ada.Text_IO.Standard_Error, +-- To => Length - Operation'Length); +-- Ada.Text_IO.Put_Line(File => Ada.Text_IO.Standard_Error, +-- Item => +-- Operation & ": " & +-- (if Is_Null then +-- ASCII.ESC & "[31m NULL " & ASCII.ESC & "[0m " +-- else +-- ASCII.ESC & "[32mNOT NULL" & ASCII.ESC & "[0m ") & +-- System.Address_Image (Address)); + +-- end Put; + + +-- overriding +-- procedure Initialize (Object : in out Surface_Type) is +-- begin + +-- Reference (Object.Reference); +-- Put ("Initialize", Object.Reference); + +-- end Initialize; + + +-- overriding +-- procedure Adjust (Object : in out Surface_Type) is +-- begin + +-- Reference (Object.Reference); +-- Put ("Adjust", Object.Reference); + +-- end Adjust; + +-- +-- overriding +-- procedure Finalize (Object : in out Surface_Type) is +-- Old_Reference : constant not null Shared_Surface_Access +-- := Object.Reference; +-- begin + +-- Put ("Finalize", Object.Reference); +-- if Old_Reference /= Shared_Null_Surface'Access then +-- -- This is used to avoid finalizing the same object twice. +-- Object.Reference := Shared_Null_Surface'Access; +-- Unreference(Old_Reference); +-- end if; + +-- end Finalize; + + + +-- procedure Reference (Item : not null Shared_Surface_Access) is +-- begin + +-- if Item = Shared_Null_Surface'Access then +-- return; +-- end if; + +-- System.Atomic_Counters.Increment (Item.Counter); + +-- end Reference; + + +-- procedure Unreference (Item : not null Shared_Surface_Access) is +-- procedure Free is new Ada.Unchecked_Deallocation (Shared_Surface_Type, +-- Shared_Surface_Access); +-- Old : Shared_Surface_Access := Item; +-- begin + +-- if Old = Shared_Null_Surface'Access then +-- return; +-- end if; + +-- if System.Atomic_Counters.Decrement (Old.Counter) then +-- Put ("Free", Item); +-- Free(Old); +-- end if; + +-- end Unreference; + + + end Malef.Surfaces; ---=======================-------------------------=========================--- diff --git a/alire.toml b/alire.toml index 52e56c3..b2e2f91 100644 --- a/alire.toml +++ b/alire.toml @@ -10,7 +10,7 @@ description = "Malef is a terminal handling library." long-description = "Malef is a terminal handling library written in Ada with bindings to other programming languages like C and Python3. It replaces the NCurses library with a more Adaish interface. It uses ANSI Escape Sequences as much as possible, but it can also handle other kinds of terminals/consoles." # The version of the package. -version = "0.2.2" +version = "0.2.3" # The authors, maintainer and maintainers' logins. authors = ["José Antonio Verde Jiménez"] diff --git a/c-malef/include/Malef.h b/c-malef/include/Malef.h index c7b1c4e..16c7b56 100644 --- a/c-malef/include/Malef.h +++ b/c-malef/include/Malef.h @@ -214,7 +214,6 @@ typedef malef_char_t *malef_str_t ; * This is the most important type in the library, it's the surface. It acts * similarly to a sprite in graphic libraries. In Ada it has garbage collection * I will try to make it happen for C, or add some kind of deallocator for it. - * TODO: Add deallocator. */ typedef struct _malef_surface_t { void* object ; @@ -377,6 +376,9 @@ malef_newPage ( void ) ; * it and it will be set this title during execution (even if the library is * finalized). TODO: Find a way to recover it. * + * @param titleName + * (IN) The new title. + * * @return * - malef_INITIALIZATION_ERROR: This exception is raised if the library was * not initialized. @@ -390,7 +392,7 @@ malef_setTitle ( const char* in titleName ) ; * will always return false. However in Windows, (for now XXX) you have to call * it to check if it has changed. * - * @param + * @param is_updated * (OUT) Whether the terminal size has been updated. * * @return @@ -431,16 +433,48 @@ malef_wrapper ( void* (*function)(void*), /////////////////////////////////////////////////////////////////////// -// TODO: malef_assingSurface function +/* + * This function is used to assign one surface to another. You should do it + * this way so the internal components can keep track of the surfaces and + * perfom automatic garbage collection when a surface is destroyed without + * freeing a surface which is referenced by many other surfaces. + * + * @param surface + * (IN) The surface you want to assign to another surface, this is the one + * that will be modified, keep in mind it should be either a null surface + * or an initialized surface. + * + * @param to_surface + * (IN) This is the surface you want your surface to assigned to. This one + * also shouldn't be an uninitialized surface. + * + * @return + * It returns the error code, it will return very nasty errors if you try to + * use any uninitialized surface. + */ +extern malef_error_t +malef_assignSurface ( malef_surface_t in surface, + malef_surface_t in to_surface ) ; + /* * This function is used to create a surface. Sizes lower than 1 aren't * allowed due to Ada's type checking. + * + * @param rows + * (IN) The number of rows (the height) of the new surface. + * + * @param rows + * (IN) The number of columns (the width) of the new surface. + * + * @param surface + * (IN) The null or initialized surface variable where you want to place the + * new created surface. */ extern malef_error_t -malef_createSurface ( malef_col_t cols, - malef_row_t rows, - malef_surface_t surface) ; +malef_createSurface ( malef_row_t in rows, + malef_col_t in cols, + malef_surface_t in surface ) ; /* @@ -456,18 +490,18 @@ malef_createSurface ( malef_col_t cols, * | malef_appendBox ( my_box, my_surf ) ; * | malef_destroy ( my_surf ) ; * | The surface won't be freed, because the Box still has access to it. - * | In orther to assing to another surface use the `malef_assingSurface' + * | In orther to assing to another surface use the `malef_assignSurface' * | function. * * @param surface - * The surface to destroy. + * (IN) The surface to destroy. */ extern malef_error_t -malef_destroySurface ( malef_surface_t surface ) ; +malef_destroySurface ( malef_surface_t in surface ) ; /* - * + * DEBUGGING! */ extern void _malef_debugPutSurface ( malef_surface_t surface ) ; @@ -496,39 +530,260 @@ malef_getNullSurface ( void ) ; //---------- COLOUR FUNCTIONS ---------------------------------------// /////////////////////////////////////////////////////////////////////// -extern void malef_getSurfaceForeground (malef_surface_t, - malef_row_t, - malef_col_t, - malef_color_t) ; -extern void malef_getSurfaceBackground (malef_surface_t, - malef_row_t, - malef_col_t, - malef_color_t) ; -extern void malef_setSurfaceForeground (malef_surface_t, - malef_row_t, - malef_row_t, - malef_col_t, - malef_col_t, - malef_color_t) ; -extern void malef_setSurfaceBackground (malef_surface_t, - malef_row_t, - malef_row_t, - malef_col_t, - malef_col_t, - malef_color_t) ; -extern void malef_getCursorForeground (malef_surface_t, - malef_color_t) ; -extern void malef_getCursorBackground (malef_surface_t, - malef_color_t) ; -extern void malef_setCursorForeground (malef_surface_t, - malef_color_t) ; -extern void malef_setCursorBackground (malef_surface_t, - malef_color_t) ; -extern void malef_getPalette (malef_palette_t) ; -extern void malef_getPaletteKind (malef_paletteKind_t, - malef_palette_t) ; -extern void malef_setPalette (malef_palette_t) ; -extern void malef_setPaletteKind (malef_paletteKind_t) ; +/* + * This function gets the foreground colour from a certain position of + * the Surface. + * + * @param surface + * (IN) The surface where we want to get the colour. + * + * @param row + * (IN) The row from where we want to retrieve the colour. Keep in mind, in + * this whole library we start counting at one, so if you try to use any + * other number a very nasty error will be raised. + * + * @param col + * (IN) The column from where we want to retrieve the colour. It's a positive + * integer bigger than zero, keep that in mind. + * + * @param color + * (OUT) The foreground colour in the given position. + * + * @return + * - malef_BOUNDS_ERROR: The position is out of bounds. + */ +extern malef_error_t +malef_getSurfaceForeground ( malef_surface_t in surface, + malef_row_t in row, + malef_col_t in col, + malef_color_t out color ) ; + +/* + * This function gets the background colour from a certain position of the + * Surface. + * + * @param surface + * (IN) The surface where we want to get the colour. + * + * @param row + * (IN) The row from where we want to retrieve the colour. Keep in mind, in + * this whole library we start counting at one, so if you try to use any + * other number a very nasty error will be raised. + * + * @param col + * (IN) The column from where we want to retrieve the colour. It's a positive + * integer bigger than zero, keep that in mind. + * + * @param color + * (OUT) The background colour in the given position. + * + * @return + * - malef_BOUNDS_ERROR: The position is out of bounds. + */ +extern malef_error_t +malef_getSurfaceBackground ( malef_surface_t in surface, + malef_row_t in row, + malef_col_t in col, + malef_color_t in color ) ; + +/* + * This function changes the foreground colour in a given block. + * + * @param surface + * (IN) The surface to edit. + * + * @param from_row + * (IN) The block's starting row position. + * + * @param to_row + * (IN) The block's ending row position. + * + * @param from_col + * (IN) The block's starting column position. + * + * @param to_col + * (IN) The block's ending column position. + * + * @param color + * (IN) The colour to dye the given position with. + * + * @return + * - malef_BOUNDS_ERROR: Any of the positions is out of bounds or the range + * is negative. + * - malef_NULL_SURFACE_ERROR: You are trying to modify a null surface which + * is not possible. + */ +extern malef_error_t +malef_setSurfaceForeground ( malef_surface_t in surface, + malef_row_t in from_row, + malef_row_t in to_row, + malef_col_t in from_col, + malef_col_t in to_col, + malef_color_t in color ) ; + +/* + * This function changes the background colour in a given block. + * + * @param surface + * (IN) The surface to edit. + * + * @param from_row + * (IN) The block's starting row position. + * + * @param to_row + * (IN) The block's ending row position. + * + * @param from_col + * (IN) The block's starting column position. + * + * @param to_col + * (IN) The block's ending column position. + * + * @param color + * (IN) The colour to dye the given position with. + * + * @return + * - malef_BOUNDS_ERROR: Any of the positions is out of bounds or the range + * is negative. + * - malef_NULL_SURFACE_ERROR: You are trying to modify a null surface which + * is not possible. + */ +extern malef_error_t +malef_setSurfaceBackground ( malef_surface_t in surface, + malef_row_t in from_row, + malef_row_t in to_row, + malef_col_t in from_row, + malef_col_t in to_row, + malef_color_t in color ) ; + +/* + * This function gets the default Surface's writing colour. This is the colour + * that will be used when writing a string text into the Surface by default. + * + * @param surface + * (IN) The surface from which you want to get the default writing colour. + * + * @param color + * (OUT) The surface's default writing colour. + * + * @return + * It usually returns no errors, if it returns any, it is fatal one. + */ +extern malef_error_t +malef_getCursorForeground ( malef_surface_t in surface, + malef_color_t out color ) ; + +/* + * This function gets the default Surface's writing colour. This is the colour + * that will be used when writing a string text into the Surface by default. + * + * @param surface + * (IN) The surface from which you want to get the default writing colour. + * + * @param color + * (OUT) The surface's default writing colour. + * + * @return + * It usually returns no errors, if it returns any, it is fatal one. + */ +extern malef_error_t +malef_getCursorBackground ( malef_surface_t in surface, + malef_color_t out color ) ; + +/* + * This function changes the default Surface's writing foreground colour. You + * can even change it in a null surface because it won't have any effect on it + * because it can't be written. + * + * @param surface + * (IN) The surface whose default cursor colour you want to change. + * + * @param color + * (IN) The colour. + * + * @return + * It won't return any error, but you can always check it if anything goes + * wrong unexpectedly. + */ +extern malef_error_t +malef_setCursorForeground ( malef_surface_t in surface, + malef_color_t in color ) ; + +/* + * This function changes the default Surface's writing background colour. The + * null surfaces can also be changed because it won't have any effect at all. + * + * @param surface + * (IN) The surface whose default background cursor colour you want to change. + * + * @param color + * (IN) The new colour. + * + * @return + * It shouldn't return any errors, but check it if you can because if any error + * is raised it must be a fatal one. + */ +extern malef_error_t +malef_setCursorBackground ( malef_surface_t in surface, + malef_color_t in color ) ; + +/* + * This function gets the current surface palette. + * + * @param palette + * (OUT) This is the current palette that is being used by the internal engine. + * + * @return + * - malef_INITIALIZATION_ERROR: This error is returned if the library hasn't + * been initialized yet. + */ +extern malef_error_t +malef_getPalette ( malef_palette_t out palette ) ; + +/* + * This function gets a palette of a given palette name. + * + * @param palette_kind + * (IN) This is the palette kind whose palette you want to get. + * + * @param palette + * (OUT) This is the palette where the new palette will be stored. + * + * @return + * It shouldn't return any error if you give the palette_kind in its range. + */ +extern malef_error_t +malef_getPaletteKind ( malef_paletteKind_t in palette_kind, + malef_palette_t out palette ) ; + +/* + * This function changes the current palette to another one, you can change it + * before initialization but keep in mind that it will be overwritten after + * initialization for the most suitable one for the operating system. + * + * @param palette + * (IN) The palette you want to set as default. + * + * @return + * It shouldn't return any error if the palettes aren't corrupted or anything. + */ +extern malef_error_t +malef_setPalette ( malef_palette_t in palette ) ; + +/* + * This function changes the current Malef palette to another one, you can + * change it before initialization but it won't have any effects because during + * the initialization process the most suitable one is chose depending on the + * operating system and the terminal/console emulator. + * + * @param palette_kind + * (IN) The palette you want to set as default. + * + * @return + * It shouldn't return any error, if it does report it immediately. + */ +extern malef_error_t +malef_setPaletteKind ( malef_paletteKind_t in palette_kind ) ; # ifdef _malef_temp_out diff --git a/c-malef/src-base/c_malef-colors.adb b/c-malef/src-base/c_malef-colors.adb index 2d7456f..67cc715 100644 --- a/c-malef/src-base/c_malef-colors.adb +++ b/c-malef/src-base/c_malef-colors.adb @@ -26,13 +26,17 @@ -- -- ------------------------------------------------------------------------------- +with C_Malef.Errors; +with Malef.Exceptions; + package body C_Malef.Colors is - procedure Get_Foreground (Surface : Surface_Type; - Row : Row_Type; - Col : Col_Type; - Color : out Color_Type) is + function Get_Foreground (Surface : Surface_Type; + Row : Row_Type; + Col : Col_Type; + Color : out Color_Type) + return Error_Kind is begin Color := To_C(Malef.Colors.Get_Foreground( @@ -40,13 +44,23 @@ package body C_Malef.Colors is Row => Malef.Row_Type(Row), Col => Malef.Col_Type(Col))); + return No_Error; + + exception + when Ada_Exception : Malef.Exceptions.Bounds_Error => + C_Malef.Errors.Push(Ada_Exception); + return Bounds_Error; + when Ada_Exception : others => + C_Malef.Errors.Push(Ada_Exception); + return Ada_Error; end Get_Foreground; - procedure Get_Background (Surface : Surface_Type; - Row : Row_Type; - Col : Col_Type; - Color : out Color_Type) is + function Get_Background (Surface : Surface_Type; + Row : Row_Type; + Col : Col_Type; + Color : out Color_Type) + return Error_Kind is begin Color := To_C(Malef.Colors.Get_Background( @@ -54,16 +68,26 @@ package body C_Malef.Colors is Row => Malef.Row_Type(Row), Col => Malef.Col_Type(Col))); + return No_Error; + + exception + when Ada_Exception : Malef.Exceptions.Bounds_Error => + C_Malef.Errors.Push(Ada_Exception); + return Bounds_Error; + when Ada_Exception : others => + C_Malef.Errors.Push(Ada_Exception); + return Ada_Error; end Get_Background; - procedure Set_Foreground (Surface : Surface_Type; - From_Row : Row_Type; - To_Row : Row_Type; - From_Col : Col_Type; - To_Col : Col_Type; - Color : Color_Type) is + function Set_Foreground (Surface : Surface_Type; + From_Row : Row_Type; + To_Row : Row_Type; + From_Col : Col_Type; + To_Col : Col_Type; + Color : Color_Type) + return Error_Kind is begin Malef.Colors.Set_Foreground(Surface => Surface.Object, @@ -73,15 +97,28 @@ package body C_Malef.Colors is To_Col => Malef.Col_Type(To_Col), Color => To_Ada(Color)); + return No_Error; + + exception + when Ada_Exception : Malef.Exceptions.Bounds_Error => + C_Malef.Errors.Push(Ada_Exception); + return Bounds_Error; + when Ada_Exception : Malef.Exceptions.Null_Surface_Error => + C_Malef.Errors.Push(Ada_Exception); + return Null_Surface_Error; + when Ada_Exception : others => + C_Malef.Errors.Push(Ada_Exception); + return Ada_Error; end Set_Foreground; - procedure Set_Background (Surface : Surface_Type; + function Set_Background (Surface : Surface_Type; From_Row : Row_Type; To_Row : Row_Type; From_Col : Col_Type; To_Col : Col_Type; - Color : Color_Type) is + Color : Color_Type) + return Error_Kind is begin Malef.Colors.Set_Background(Surface => Surface.Object, @@ -91,81 +128,150 @@ package body C_Malef.Colors is To_Col => Malef.Col_Type(To_Col), Color => To_Ada(Color)); + return No_Error; + + exception + when Ada_Exception : Malef.Exceptions.Bounds_Error => + C_Malef.Errors.Push(Ada_Exception); + return Bounds_Error; + when Ada_Exception : Malef.Exceptions.Null_Surface_Error => + C_Malef.Errors.Push(Ada_Exception); + return Null_Surface_Error; + when Ada_Exception : others => + C_Malef.Errors.Push(Ada_Exception); + return Ada_Error; + end Set_Background; - procedure Get_Cursor_Foreground (Surface : Surface_Type; - Color : out Color_Type) is + function Get_Cursor_Foreground (Surface : Surface_Type; + Color : out Color_Type) + return Error_Kind is begin Color := To_C(Malef.Colors.Get_Cursor_Foreground(Surface.Object)); + return No_Error; + + exception + when Ada_Exception : others => + C_Malef.Errors.Push(Ada_Exception); + return Ada_Error; end Get_Cursor_Foreground; - procedure Get_Cursor_Background (Surface : Surface_Type; - Color : out Color_Type) is + function Get_Cursor_Background (Surface : Surface_Type; + Color : out Color_Type) + return Error_Kind is begin Color := To_C(Malef.Colors.Get_Cursor_Background(Surface.Object)); + return No_Error; + + exception + when Ada_Exception : others => + C_Malef.Errors.Push(Ada_Exception); + return Ada_Error; end Get_Cursor_Background; - procedure Set_Cursor_Foreground (Surface : Surface_Type; - Color : Color_Type) is + function Set_Cursor_Foreground (Surface : Surface_Type; + Color : Color_Type) + return Error_Kind is begin Malef.Colors.Set_Cursor_Foreground(Surface => Surface.Object, Color => To_Ada(Color)); + return No_Error; + + exception + when Ada_Exception : others => + C_Malef.Errors.Push(Ada_Exception); + return Ada_Error; end Set_Cursor_Foreground; - procedure Set_Cursor_Background (Surface : Surface_Type; - Color : Color_Type) is + function Set_Cursor_Background (Surface : Surface_Type; + Color : Color_Type) + return Error_Kind is begin Malef.Colors.Set_Cursor_Background(Surface => Surface.Object, Color => To_Ada(Color)); + return No_Error; + + exception + when Ada_Exception : others => + C_Malef.Errors.Push(Ada_Exception); + return Ada_Error; end Set_Cursor_Background; - procedure Get_Palette (Palette : out Palette_Type) is + function Get_Palette (Palette : out Palette_Type) + return Error_Kind is begin Palette := To_C(Malef.Colors.Get_Palette); + return No_Error; + + exception + when Ada_Exception : others => + C_Malef.Errors.Push(Ada_Exception); + return Ada_Error; end Get_Palette; - procedure Get_Palette (Kind : Palette_Kind; - Palette : out Palette_Type) is + function Get_Palette (Kind : Palette_Kind; + Palette : out Palette_Type) + return Error_Kind is begin Palette := To_C(Malef.Colors.Palettes(To_Ada(Kind))); + return No_Error; + + exception + when Ada_Exception : others => + C_Malef.Errors.Push(Ada_Exception); + return Ada_Error; end Get_Palette; - procedure Set_Palette (Palette : Palette_Type) is + function Set_Palette (Palette : Palette_Type) + return Error_Kind is begin Malef.Colors.Set_Palette(To_Ada(Palette)); + return No_Error; + + exception + when Ada_Exception : others => + C_Malef.Errors.Push(Ada_Exception); + return Ada_Error; end Set_Palette; - procedure Set_Palette (Kind : Palette_Kind) is + function Set_Palette (Kind : Palette_Kind) + return Error_Kind is begin Malef.Colors.Set_Palette(To_Ada(Kind)); + return No_Error; + + exception + when Ada_Exception : others => + C_Malef.Errors.Push(Ada_Exception); + return Ada_Error; end Set_Palette; diff --git a/c-malef/src-base/c_malef-colors.ads b/c-malef/src-base/c_malef-colors.ads index e7c0240..0470ecb 100644 --- a/c-malef/src-base/c_malef-colors.ads +++ b/c-malef/src-base/c_malef-colors.ads @@ -31,13 +31,18 @@ with C_Malef.Surfaces; use C_Malef.Surfaces; -- -- @summary --- +-- This package contains functions to work with colours and palettes. -- -- @description +-- This package contains colours, palettes and some default palettes. You can +-- use this package to modify a Surface's colours. Read the original Ada +-- documentation or the C Header file. (I'm not going to write everything +-- three times). -- package C_Malef.Colors is - type Color_Kind is (Black, Red, Green, Yellow, Blue, Magenta, Cyan, White); + type Color_Kind is (Black, Red, Green, Yellow, Blue, Magenta, Cyan, White) + with Convention => C; for Color_Kind use (Black => 0, Red => 1, @@ -47,10 +52,9 @@ package C_Malef.Colors is Magenta => 5, Cyan => 6, White => 7); - pragma Convention (C, Color_Kind); - type Palette_Type is array (bool'Range, Color_Kind'Range) of Color_Type; - pragma Convention (C, Palette_Type); + type Palette_Type is array (bool'Range, Color_Kind'Range) of Color_Type + with Convention => C; type Palette_Kind is (Malef_Palette, VGA, @@ -62,7 +66,8 @@ package C_Malef.Colors is PuTTY, mIRC, xterm, - Ubuntu); + Ubuntu) + with Convention => C; for Palette_Kind use (Malef_Palette => 0, VGA => 1, @@ -75,101 +80,139 @@ package C_Malef.Colors is mIRC => 8, xterm => 9, Ubuntu => 10); - pragma Convention (C, Palette_Kind); - - procedure Get_Foreground (Surface : Surface_Type; - Row : Row_Type; - Col : Col_Type; - Color : out Color_Type); - pragma Export (C, Get_Foreground, "malef_getSurfaceForeground"); - - - procedure Get_Background (Surface : Surface_Type; - Row : Row_Type; - Col : Col_Type; - Color : out Color_Type); - pragma Export (C, Get_Background, "malef_getSurfaceBackground"); - - procedure Set_Foreground (Surface : Surface_Type; - From_Row : Row_Type; - To_Row : Row_Type; - From_Col : Col_Type; - To_Col : Col_Type; - Color : Color_Type); - pragma Export (C, Set_Foreground, "malef_setSurfaceForeground"); - - procedure Set_Background (Surface : Surface_Type; - From_Row : Row_Type; - To_Row : Row_Type; - From_Col : Col_Type; - To_Col : Col_Type; - Color : Color_Type); - pragma Export (C, Set_Background, "malef_setSurfaceBackground"); - - - procedure Get_Cursor_Foreground (Surface : Surface_Type; - Color : out Color_Type); - pragma Export (C, Get_Cursor_Foreground, "malef_getCursorForeground"); - procedure Get_Cursor_Background (Surface : Surface_Type; - Color : out Color_Type); - pragma Export (C, Get_Cursor_Background, "malef_getCursorBackground"); - procedure Set_Cursor_Foreground (Surface : Surface_Type; - Color : Color_Type); - pragma Export (C, Set_Cursor_Foreground, "malef_setCursorForeground"); - - procedure Set_Cursor_Background (Surface : Surface_Type; - Color : Color_Type); - pragma Export (C, Set_Cursor_Background, "malef_setCursorBackground"); - - - procedure Get_Palette (Palette : out Palette_Type); - pragma Export (C, Get_Palette, "malef_getPalette"); - - procedure Get_Palette (Kind : Palette_Kind; - Palette : out Palette_Type); - pragma Export (C, Get_Palette, "malef_getPaletteKind"); - - procedure Set_Palette (Palette : Palette_Type); - pragma Export (C, Set_Palette, "malef_setPalette"); - - procedure Set_Palette (Kind : Palette_Kind); - pragma Export (C, Set_Palette, "malef_setPaletteKind"); + -- TODO: Handle Constraint_Error + function Get_Foreground (Surface : Surface_Type; + Row : Row_Type; + Col : Col_Type; + Color : out Color_Type) + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_getSurfaceForeground"; + + function Get_Background (Surface : Surface_Type; + Row : Row_Type; + Col : Col_Type; + Color : out Color_Type) + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_getSurfaceBackground"; + + function Set_Foreground (Surface : Surface_Type; + From_Row : Row_Type; + To_Row : Row_Type; + From_Col : Col_Type; + To_Col : Col_Type; + Color : Color_Type) + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_setSurfaceForeground"; + + function Set_Background (Surface : Surface_Type; + From_Row : Row_Type; + To_Row : Row_Type; + From_Col : Col_Type; + To_Col : Col_Type; + Color : Color_Type) + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_setSurfaceBackground"; + + + function Get_Cursor_Foreground (Surface : Surface_Type; + Color : out Color_Type) + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_getCursorForeground"; + + function Get_Cursor_Background (Surface : Surface_Type; + Color : out Color_Type) + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_getCursorBackground"; + + function Set_Cursor_Foreground (Surface : Surface_Type; + Color : Color_Type) + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_setCursorForeground"; + + function Set_Cursor_Background (Surface : Surface_Type; + Color : Color_Type) + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_setCursorBackground"; + + + function Get_Palette (Palette : out Palette_Type) + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_getPalette"; + + -- TODO: Check for ranges. + function Get_Palette (Kind : Palette_Kind; + Palette : out Palette_Type) + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_getPaletteKind"; + + function Set_Palette (Palette : Palette_Type) + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_setPalette"; + + function Set_Palette (Kind : Palette_Kind) + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_setPaletteKind"; private - -- TODO: Check if it's truly worth to inline it. + -- The following functions are used to quickly converta Ada types to C + -- types and viceversa. + function To_Ada (Item : Color_Type) - return Malef.Color_Type; - pragma Pure_Function (To_Ada); - pragma Inline (To_Ada); + return Malef.Color_Type + with Pure_Function, + Inline; function To_C (Item : Malef.Color_Type) - return Color_Type; - pragma Pure_Function (To_C); - pragma Inline (To_C); + return Color_Type + with Pure_Function, + Inline; function To_Ada (Item : Palette_Type) - return Malef.Colors.Palette_Type; - pragma Pure_Function (To_Ada); - pragma Inline (To_Ada); + return Malef.Colors.Palette_Type + with Pure_Function, + Inline; function To_C (Item : Malef.Colors.Palette_Type) - return Palette_Type; - pragma Pure_Function (To_C); - pragma Inline (To_C); + return Palette_Type + with Pure_Function, + Inline; function To_Ada (Item : Palette_Kind) - return Malef.Colors.Palette_Kind; - pragma Pure_Function (To_Ada); - pragma Inline (To_Ada); + return Malef.Colors.Palette_Kind + with Pure_Function, + Inline; function To_C (Item : Malef.Colors.Palette_Kind) - return Palette_Kind; - pragma Pure_Function (To_C); - pragma Inline (To_C); - + return Palette_Kind + with Pure_Function, + Inline; end C_Malef.Colors; diff --git a/c-malef/src-base/c_malef-surfaces.adb b/c-malef/src-base/c_malef-surfaces.adb index e59d60f..c130a3a 100644 --- a/c-malef/src-base/c_malef-surfaces.adb +++ b/c-malef/src-base/c_malef-surfaces.adb @@ -31,6 +31,22 @@ with C_Malef.Errors; package body C_Malef.Surfaces is + function Assign (Surface : out Surface_Type; + To_Surface : in Surface_Type) + return Error_Kind is + begin + + Surface.Object := To_Surface.Object; + + return No_Error; + + exception + when Ada_Exception : others => + C_Malef.Errors.Push(Ada_Exception); + return Ada_Error; + end Assign; + + function Create (Rows : Row_Type; Cols : Col_Type; Surface : in out Surface_Type) @@ -54,13 +70,13 @@ package body C_Malef.Surfaces is end Create; - function Destroy (Object : in out Surface_Type) + function Destroy (Surface : in out Surface_Type) return Error_Kind is begin -- This is enough to destroy a surface, controlled types and finalization -- function will take care of the rest. - Object := Get_Null_Surface; + Surface := Get_Null_Surface; return No_Error; @@ -71,10 +87,10 @@ package body C_Malef.Surfaces is end Destroy; - procedure Debug_Put (Object : Surface_Type) is + procedure Debug_Put (Surface : Surface_Type) is begin - Object.Object.Debug_Put; + Surface.Object.Debug_Put; end Debug_Put; diff --git a/c-malef/src-base/c_malef-surfaces.ads b/c-malef/src-base/c_malef-surfaces.ads index 633b4f4..372b15f 100644 --- a/c-malef/src-base/c_malef-surfaces.ads +++ b/c-malef/src-base/c_malef-surfaces.ads @@ -30,33 +30,121 @@ with Malef.Surfaces; -- -- @summary --- +-- This package contains functions to work with surfaces. -- -- @description +-- This package contains the functions to work with Surfaces from C. There is +-- a new surface type with the C convention that wraps the Ada type. This +-- package is written so the C side can use the Controlled type functionalities +-- from Ada. -- package C_Malef.Surfaces is + -- + -- This C type wraps the Ada surface type. It's made so you can also use + -- the Ada Controlled types from the C binding, but you have to use the + -- functions in this package. Also, it must be first initialized, otherwise + -- it will raise a Segmentation Fault error. + -- + -- @field Object + -- It's the Ada controlled type. + -- type Surface_Type is record Object : Malef.Surfaces.Surface_Type := Malef.Surfaces.Null_Surface; - end record; - pragma Convention (C, Surface_Type); + end record + with Convention => C; + + + -- + -- This function is used to assign an object to another and keep the + -- reference count. Both must be initialized, otherwise it won't work. + -- + -- @param Surface + -- The surface we want to get assigned to another one. + -- + -- @param To_Surface + -- The surface it will be assigned to. + -- + -- @return + -- It returns Ada_Error if something went wrong. + -- + function Assign (Surface : out Surface_Type; + To_Surface : in Surface_Type) + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_assignSurface"; + -- + -- This function creates an empty surface of a given number of Rows (Height) + -- and Columns (Width). + -- + -- @param Rows + -- The height, the number of rows. + -- + -- @param Cols + -- The width, the number of columns. + -- + -- @param Surface + -- The surface object that we want to modify to contain the new surface. + -- + -- @return + -- It returns if there was an error. If the number of rows or columns is not + -- in range 1 .. Row/Col_Type'Last, then a Bounds_Error is returned, + -- otherwise an Ada_Error is returned as always. + -- function Create (Rows : Row_Type; Cols : Col_Type; Surface : in out Surface_Type) - return Error_Kind; - pragma Export (C, Create, "malef_createSurface"); + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_createSurface"; - function Destroy (Object : in out Surface_Type) - return Error_Kind; - pragma Export (C, Destroy, "malef_destroySurface"); + -- + -- This function unreferences a Surface, it doesn't actually destroy it, I + -- just couldn't find a good name at the moment and this one sounds cool. A + -- Surface can't be never deallocated unless all the variables that + -- reference it have completely fade away. So no `free'-like function is + -- available. This is the same as falling out of the scope in Ada. + -- + -- @param Surface + -- The surface to unreference. + -- + -- @return + -- It returns an Ada_Error if the Surface hasn't been initialised. + -- + function Destroy (Surface : in out Surface_Type) + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_destroySurface"; - procedure Debug_Put (Object : Surface_Type); - pragma Export (C, Debug_Put, "_malef_debugPutSurface"); + -- + -- This procedure is here just for debugging purposes, as you can it + -- returns no errors. It will be replaced by a normal Put function in the + -- future. + -- + -- @param Surface + -- The surface to display into the screen. + -- + procedure Debug_Put (Surface : Surface_Type) + with Export => True, + Convention => C, + External_Name => "_malef_debugPutSurface"; - function Get_Null_Surface return Surface_Type; - pragma Export (C, Get_Null_Surface, "malef_getNullSurface"); + -- + -- This function just returns a null surface and references it. It can't + -- raise any error because there is no surface involved. + -- + -- @return + -- It returns a null surface for initialization. + -- + function Get_Null_Surface return Surface_Type + with Export => True, + Convention => C, + External_Name => "malef_getNullSurface"; end C_Malef.Surfaces; diff --git a/c-malef/src-base/c_malef.ads b/c-malef/src-base/c_malef.ads index 2ef7b94..3edea35 100644 --- a/c-malef/src-base/c_malef.ads +++ b/c-malef/src-base/c_malef.ads @@ -94,21 +94,21 @@ package C_Malef is No_Error, Initialization_Error, Bounds_Error, - Null_Surface_Error); + Null_Surface_Error) + with Convention => C; for Error_Kind use (Ada_Error => -1, No_Error => 0, Initialization_Error => 1, Bounds_Error => 2, Null_Surface_Error => 3); - pragma Convention (C, Error_Kind); -- -- This type is used for the components of the Color_Type. -- - type Color_Component_Type is mod 256; + type Color_Component_Type is mod 256 + with Convention => C; for Color_Component_Type'Size use 8; - pragma Convention (C, Color_Component_Type); -- -- This type is used to represent the indexes of the Color_Type. @@ -125,17 +125,17 @@ package C_Malef is -- @value A -- Alpha (Opacity, 255 -> Completely opaque) -- - type Color_Component_Kind is (R, G, B, A); + type Color_Component_Kind is (R, G, B, A) + with Convention => C; for Color_Component_Kind use (R => 0, G => 1, B => 2, A => 3); - pragma Convention (C, Color_Component_Kind); -- -- This type is used to represent RGBA colours with a 4 byte unsigned array -- of 8 bit integers. -- type Color_Type is array (Color_Component_Kind'Range) - of aliased Color_Component_Type; - pragma Convention (C, Color_Type); + of aliased Color_Component_Type + with Convention => C; -- -- This type is used to describe different effects you can place on the @@ -154,7 +154,8 @@ package C_Malef is -- type Style_Type is (Bold, Faint, Italic, Underline, Slow_Blink, Rapid_Blink, Reverse_Video, Conceal, - Crossed_Out, Doubly_Underline); + Crossed_Out, Doubly_Underline) + with Convention => C; for Style_Type use ( Bold => 0, Faint => 1, @@ -166,14 +167,13 @@ package C_Malef is Conceal => 7, Crossed_Out => 8, Doubly_Underline => 9); - pragma Convention (C, Style_Type); -- -- TODO: Change for an integer to use the `|' (or) operator. (More C-ish) -- This is just an array of styles telling whether they are on or off. -- - type Style_Array is array (Style_Type'Range) of Boolean; - pragma Convention (C, Style_Array); + type Style_Array is array (Style_Type'Range) of Boolean + with Convention => C; -- -- This is the format type, it's used to store a specific format and use it @@ -193,24 +193,24 @@ package C_Malef is Foreground_Color : Color_Type; Background_Color : Color_Type; Styles : Style_Array; - end record; - pragma Convention (C, Format_Type); + end record + with Convention => C; -- -- This is the Row_Type, as you can see, 0 is forbidden, and an exception -- will be raised if the value given is ZERO. It's used to cound rows. -- type Row_Type is new unsigned_short - range 1 .. unsigned_short(Malef.Row_Type'Last); - pragma Convention (C, Row_Type); + range 1 .. unsigned_short(Malef.Row_Type'Last) + with Convention => C; -- -- Similarly to Row_Type, Col_Type counts columns and forbids the use of -- 0 as a valid integer. -- type Col_Type is new unsigned_short - range 1 .. unsigned_short(Malef.Col_Type'Last); - pragma Convention (C, Col_Type); + range 1 .. unsigned_short(Malef.Col_Type'Last) + with Convention => C; -- -- This is the cursor type. @@ -219,27 +219,27 @@ package C_Malef is record Row : Row_Type; Col : Col_Type; - end record; - pragma Convention (C, Cursor_Type); + end record + with Convention => C; -- -- These are each of the components of a character. -- - type Char_Component_Type is mod 256; + type Char_Component_Type is mod 256 + with Convention => C; for Char_Component_Type'Size use 8; - pragma Convention (C, Char_Component_Type); -- -- This is the character type, it's used to store unicode values. -- - type Char_Type is array (unsigned range 0 .. 3) of Char_Component_Type; - pragma Convention (C, Char_Type); + type Char_Type is array (unsigned range 0 .. 3) of Char_Component_Type + with Convention => C; -- -- This is the string type, it's an array of characters. -- - type Str_Type is array (unsigned range <>) of Char_Type; - pragma Convention (C, Str_Type); + type Str_Type is array (unsigned range <>) of Char_Type + with Convention => C; @@ -256,14 +256,18 @@ package C_Malef is -- -- This function initializes the library. -- - function Initialize return Error_Kind; - pragma Export (C, Initialize, "malef_initialize"); + function Initialize return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_initialize"; -- -- This function finalizes the library -- - function Finalize return Error_Kind; - pragma Export (C, Finalize, "malef_finalize"); + function Finalize return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_finalize"; -- -- This function checks if the library is initialized. @@ -271,8 +275,10 @@ package C_Malef is -- @return -- Whether it has been intialized. -- - function Is_Initialized return bool; - pragma Export (C, Is_Initialized, "malef_isInitialized"); + function Is_Initialized return bool + with Export => True, + Convention => C, + External_Name => "malef_isInitialized"; -- -- This functionn gets the height of the terminal. @@ -281,8 +287,10 @@ package C_Malef is -- The height of the terminal. -- function Get_Height (Height : out Row_Type) - return Error_Kind; - pragma Export (C, Get_Height, "malef_getHeight"); + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_getHeight"; -- -- This function gets the width of the terminal. @@ -291,15 +299,19 @@ package C_Malef is -- The width of the terminal. -- function Get_Width (Width : out Col_Type) - return Error_Kind; - pragma Export (C, Get_Width, "malef_getWidth"); + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_getWidth"; -- -- This function adds enough blank lines to move everything up and allow for -- a clean space. -- - function New_Page return Error_Kind; - pragma Export (C, New_Page, "malef_newPage"); + function New_Page return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_newPage"; -- -- This function changes the title of the terminal. @@ -308,8 +320,10 @@ package C_Malef is -- The new title. -- function Set_Title (Name : chars_ptr) - return Error_Kind; - pragma Export (C, Set_Title, "malef_setTitle"); + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_setTitle"; -- -- This function updates the terminal size. @@ -318,12 +332,14 @@ package C_Malef is -- Whether the size has been changed. -- function Update_Terminal_Size (Is_Updated : out bool) - return Error_Kind; - pragma Export (C, Update_Terminal_Size, "malef_updateTerminalSize"); + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_updateTerminalSize"; - type Wrapped_Function is access function (Args: void_ptr) return void_ptr; - pragma Convention (C, Wrapped_Function); + type Wrapped_Function is access function (Args: void_ptr) return void_ptr + with Convention => C; -- -- This function wraps other functions and protects them from any critical @@ -342,8 +358,10 @@ package C_Malef is function Wrapper (Func : Wrapped_Function; Args : void_ptr; Ret_Val : out void_ptr) - return Error_Kind; - pragma Export (C, Wrapper, "malef_wrapper"); + return Error_Kind + with Export => True, + Convention => C, + External_Name => "malef_wrapper"; end C_Malef; diff --git a/dev-tools/do.py b/dev-tools/do.py index 6cc9578..0f5a14f 100755 --- a/dev-tools/do.py +++ b/dev-tools/do.py @@ -232,7 +232,8 @@ def status (filename, status, description=""): "todo": _todo, "commit": _commit, "lines": _lines, - "install": "gprinstall -f -p -Pmalef --prefix=./alire/opt", + "install": ["rm -r alire/opt", + "gprinstall -f -p -Pmalef --prefix=./alire/opt"], } diff --git a/dev-tools/todo.py b/dev-tools/todo.py index 7f2ec9c..b010b8e 100755 --- a/dev-tools/todo.py +++ b/dev-tools/todo.py @@ -77,6 +77,7 @@ def _get_task (todo_dict, data): "sys" : lambda name : "_sys" in name or "sys_" in name, "tests" : lambda name : "tests" in name, "cleanup" : lambda name : "cleanup" in name, + "colors" : lambda name : "colors" in name, } diff --git a/malef.gpr b/malef.gpr index 69ab73c..3bb3043 100644 --- a/malef.gpr +++ b/malef.gpr @@ -68,20 +68,34 @@ project Malef is --====-====-----------====-====-- --====-====- PROJECT -====-====-- --====-====-----------====-====-- - - Ada_API := ("Malef", - "Malef.Colors", - "Malef.Events", - "Malef.Exceptions", - "Malef.Subsystems", - "Malef.Surfaces", - "Malef.Systems", - "Malef.Wrapper"); - - C_API := ("C_Malef", - "C_Malef.Colors", - "C_Malef.Errors", - "C_Malef.Surfaces"); + + Ada_API := ("malef.ads", + "malef-colors.ads", + "malef-events.ads", + "malef-exceptions.ads", + "malef-surfaces.ads", + "malef-systems.ads", + "malef-wrapper.ads"); + + C_API := ("c_malef.ads", + "c_malef-colors.ads", + "c_malef-errors.ads", + "c_malef-surfaces.ads", + "Malef.h"); + +-- Ada_API := ("Malef", +-- "Malef.Colors", +-- "Malef.Events", +-- "Malef.Exceptions", +-- "Malef.Subsystems", +-- "Malef.Surfaces", +-- "Malef.Systems", +-- "Malef.Wrapper"); + +-- C_API := ("C_Malef", +-- "C_Malef.Colors", +-- "C_Malef.Errors", +-- "C_Malef.Surfaces"); API := Ada_API; @@ -110,8 +124,9 @@ project Malef is for Library_Name use "Malef"; for Library_Kind use Library_Type; for Library_Version use "libMalef.so." & "0"; - for Library_Standalone use "standard"; - for Library_Interface use API; + for Interfaces use API; +-- for Library_Standalone use "standard"; +-- for Library_Interface use API; for Library_Dir use Prefix & "lib-" & System & "." & Subsystem; for Languages use ("Ada", "C"); @@ -120,7 +135,6 @@ project Malef is for Create_Missing_Dirs use "True"; - --====-====------------====-====-- --====-====- SWITCHES -====-====-- --====-====------------====-====-- diff --git a/py-malef/run.sh b/py-malef/run.sh index 8ef607f..e5e79fb 100755 --- a/py-malef/run.sh +++ b/py-malef/run.sh @@ -6,6 +6,6 @@ if [ "$1" = "--compile" ]; then fi cd build/lib* -export LD_LIBRARY_PATH=/home/jose/Development/Malef/alire/build/lib-linux && \ +export LD_LIBRARY_PATH=/home/jose/Development/Malef/alire/build/lib-linux.ansi && \ echo $LD_LIBRARY_PATH && python3 diff --git a/py-malef/setup.py b/py-malef/setup.py index 93fdccf..9368d11 100644 --- a/py-malef/setup.py +++ b/py-malef/setup.py @@ -52,12 +52,13 @@ def main (): depends = [os.path.join("src-base", f) for f in os.listdir("src-base") if f.endswith(".h")], - extra_compile_args = ["-Wall", "-Werror"], + extra_compile_args = ["-Wall", "-Werror", + "-std=c99", "-pedantic"], #define_macros = [(name, value)] #undef_macros = [] - library_dirs = ["../alire/build/lib-linux"], + library_dirs = ["../alire/build/lib-linux.ansi"], libraries = ["Malef"], - runtime_library_dirs = ["../alire/build/lib-linux"]) + runtime_library_dirs = ["../alire/build/lib-linux.ansi"]) setup(name = "malef", version = _get_version(), description = "MALEF", # TODO diff --git a/py-malef/src-base/py_malef-surfaces.h b/py-malef/src-base/py_malef-surfaces.h index ed35073..9d841bf 100644 --- a/py-malef/src-base/py_malef-surfaces.h +++ b/py-malef/src-base/py_malef-surfaces.h @@ -186,13 +186,12 @@ pyMalef_surfaceStruct_debugPut ( _pyMalef_surfaceStruct *self, _malef_debugPutSurface ( self->surface ) ; Py_RETURN_NONE ; } -static const PyMethodDef -pyMalef_surfaceStruct_debugPut_method = { - "debugPut", - (PyCFunction)pyMalef_surfaceStruct_debugPut, - METH_NOARGS, - pyMalef_surfaceStruct_debugPut_doc -} ; +#define pyMalef_surfaceStruct_debugPut_method { \ + "debugPut", \ + (PyCFunction)pyMalef_surfaceStruct_debugPut, \ + METH_NOARGS, \ + pyMalef_surfaceStruct_debugPut_doc \ +} diff --git a/py-malef/src-base/py_malef-utils.h b/py-malef/src-base/py_malef-utils.h index 4e9f8e5..382e7b9 100644 --- a/py-malef/src-base/py_malef-utils.h +++ b/py-malef/src-base/py_malef-utils.h @@ -76,3 +76,6 @@ _pyMalef_finalizeUtils ( void ) { ///=======================/////////////////////////=========================/// //=======================// E N D O F F I L E //=========================// ///=======================/////////////////////////=========================/// +///=======================/////////////////////////=========================/// +//=======================// E N D O F F I L E //=========================// +///=======================/////////////////////////=========================/// diff --git a/py-malef/src-base/py_malef.c b/py-malef/src-base/py_malef.c index 806ddb6..18e68a0 100644 --- a/py-malef/src-base/py_malef.c +++ b/py-malef/src-base/py_malef.c @@ -44,6 +44,7 @@ *########################### F U N C T I O N S ###########################* \*###########################################################################*/ + PyDoc_STRVAR (pyMalef_initialize_doc, "This function initializes the Malef library. It must be initialized in order"\ " to run certain IO functions or functions that requiere it to be initialized"\ @@ -59,13 +60,12 @@ pyMalef_initialize ( PyObject *self, PyObject *args ) { Py_RETURN_NONE ; } } -static const PyMethodDef -pyMalef_initialize_method = { - "initialize", - pyMalef_initialize, - METH_VARARGS, - pyMalef_initialize_doc -} ; +#define pyMalef_initialize_method { \ + "initialize", \ + pyMalef_initialize, \ + METH_VARARGS, \ + pyMalef_initialize_doc \ +} PyDoc_STRVAR (pyMalef_finalize_doc, @@ -83,13 +83,12 @@ pyMalef_finalize ( PyObject *self, PyObject *args ) { Py_RETURN_NONE ; } } -static const PyMethodDef -pyMalef_finalize_method = { - "finalize", - pyMalef_finalize, - METH_VARARGS, - pyMalef_finalize_doc -} ; +#define pyMalef_finalize_method { \ + "finalize", \ + pyMalef_finalize, \ + METH_VARARGS, \ + pyMalef_finalize_doc \ +} PyDoc_STRVAR (pyMalef_isInitialized_doc, @@ -104,13 +103,12 @@ pyMalef_isInitialized ( PyObject *self, PyObject *args ) { Py_RETURN_FALSE ; } } -static const PyMethodDef -pyMalef_isInitialized_method = { - "isInitialized", - pyMalef_isInitialized, - METH_VARARGS, - pyMalef_isInitialized_doc -} ; +#define pyMalef_isInitialized_method { \ + "isInitialized", \ + pyMalef_isInitialized, \ + METH_VARARGS, \ + pyMalef_isInitialized_doc \ +} PyDoc_STRVAR (pyMalef_getHeight_doc, @@ -128,13 +126,12 @@ pyMalef_getHeight ( PyObject *self, PyObject *args ) { return PyLong_FromUnsignedLong ( height ) ; } } -static const PyMethodDef -pyMalef_getHeight_method = { - "getHeight", - pyMalef_getHeight, - METH_VARARGS, - pyMalef_getHeight_doc -} ; +#define pyMalef_getHeight_method { \ + "getHeight", \ + pyMalef_getHeight, \ + METH_VARARGS, \ + pyMalef_getHeight_doc \ +} PyDoc_STRVAR (pyMalef_getWidth_doc, @@ -152,13 +149,12 @@ pyMalef_getWidth ( PyObject *self, PyObject *args ) { return PyLong_FromUnsignedLong ( width ) ; } } -static const PyMethodDef -pyMalef_getWidth_method = { - "getWidth", - pyMalef_getWidth, - METH_VARARGS, - pyMalef_getWidth_doc -} ; +#define pyMalef_getWidth_method { \ + "getWidth", \ + pyMalef_getWidth, \ + METH_VARARGS, \ + pyMalef_getWidth_doc \ +} PyDoc_STRVAR (pyMalef_newPage_doc, @@ -176,13 +172,12 @@ pyMalef_newPage ( PyObject *self, PyObject *args ) { Py_RETURN_NONE ; } } -static const PyMethodDef -pyMalef_newPage_method = { - "newPage", - pyMalef_newPage, - METH_VARARGS, - pyMalef_newPage_doc -} ; +#define pyMalef_newPage_method { \ + "newPage", \ + pyMalef_newPage, \ + METH_VARARGS, \ + pyMalef_newPage_doc \ +} PyDoc_STRVAR (pyMalef_setTitle_doc, @@ -211,13 +206,12 @@ pyMalef_setTitle ( PyObject *self, PyObject *args, PyObject *kwargs ) { Py_RETURN_NONE ; } } -static const PyMethodDef -pyMalef_setTitle_method = { - "setTitle", - (PyCFunction)pyMalef_setTitle, - METH_VARARGS | METH_KEYWORDS, - pyMalef_setTitle_doc -} ; +#define pyMalef_setTitle_method { \ + "setTitle", \ + (PyCFunction)pyMalef_setTitle, \ + METH_VARARGS | METH_KEYWORDS, \ + pyMalef_setTitle_doc \ +} PyDoc_STRVAR (pyMalef_updateTerminalSize_doc, @@ -240,13 +234,12 @@ pyMalef_updateTerminalSize ( PyObject *self, PyObject *args ) { } } } -static const PyMethodDef -pyMalef_updateTerminalSize_method = { - "updateTerminalSize", - pyMalef_updateTerminalSize, - METH_VARARGS, - pyMalef_updateTerminalSize_doc -} ; +#define pyMalef_updateTerminalSize_method { \ + "updateTerminalSize", \ + pyMalef_updateTerminalSize, \ + METH_VARARGS, \ + pyMalef_updateTerminalSize_doc \ +} PyDoc_STRVAR (pyMalef_wrapper_doc, @@ -304,13 +297,12 @@ pyMalef_wrapper ( PyObject *self, PyObject *args, PyObject *kwargs ) { // Finally we return the value. TODO: Increase reference? return return_value ; } -static const PyMethodDef -pyMalef_wrapper_method = { - "wrapper", - (PyCFunction)pyMalef_wrapper, - METH_VARARGS | METH_KEYWORDS, - pyMalef_wrapper_doc -} ; +#define pyMalef_wrapper_method { \ + "wrapper", \ + (PyCFunction)pyMalef_wrapper, \ + METH_VARARGS | METH_KEYWORDS, \ + pyMalef_wrapper_doc \ +} diff --git a/tests/run-tests.sh b/tests/run-tests.sh index be76d34..3ad904f 100755 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -87,7 +87,7 @@ if [ ${#LANGUAGES[@]} -eq 0 ] || [ $DO_ALL_TESTS = "true" ]; then LANGUAGES=( ) for file in $(ls) do - if [ -d $file ] && [ $file != "bin" ] && [ $file != "logs" ]; then + if [ -d $file ] && [ $file != "bin" ] && [ $file != "logs" ] && [ $file != "danger_zone" ]; then LANGUAGES+=( $file ) fi done diff --git a/todo.data b/todo.data index 4fe379e..7793580 100644 --- a/todo.data +++ b/todo.data @@ -1,6 +1,6 @@ colors_sys Add colour support for different systems [TODO] colors_py Add colour support for Python3 binding [TODO] -colors_c Add colour support for C binding [TODO] +colors_c Add colour support for C binding [DONE] styles_ada Add styles to Malef [TODO] styles-doc Add documentation for styles [TODO] styles_c Add styles support for C binding [TODO] @@ -54,3 +54,5 @@ io_tests Add tests for io [TODO] encoding_tests Add tests for encoding [TODO] bug_c_null-surface Problems with surface initialization in C binding [TODO] malef_tests Add tests to Malef parent package [DONE] +bug_compile_c_bool When compiling the library in older compilers (maybe GNAT 7), the bool type declared in the C Intefaces package is defined as a unsigned char. Therefore it does not allow for expressions such as "if is_true then". Fix it! [TODO] +bug_null_colours Change the background and foreground colours from the null surface when the default palette is change or the library is initialized, that way the conversion is faster. [TODO]