Skip to content

Commit

Permalink
Cleaned Python3 implementation code!
Browse files Browse the repository at this point in the history
  • Loading branch information
joseaverde committed Jan 6, 2021
1 parent 72a2810 commit 677c86f
Show file tree
Hide file tree
Showing 8 changed files with 484 additions and 240 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.2.1] - 2021-01-06
### Fixed
- Fixed format in C header
- Fixed format in Python3 implementation

## [0.2.0] - 2021-01-05
### Added
- Added C binding for the functions declared in version **0.0.X**.
Expand All @@ -15,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added documentation for the C binding and C header file.
- Added more tests (all working).


## [0.1.2] - 2021-01-02
### Added
- Added documentation for the Malef.Colors package.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.0
0.2.1
32 changes: 16 additions & 16 deletions c-malef/include/malef.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ typedef struct _malef_surface_t {
* function will return true.
*/
extern void
malef_catchError (void);
malef_catchError ( void );

/*
* This function checks whether an error has been `thrown' and is flying
Expand All @@ -266,7 +266,7 @@ malef_catchError (void);
* It returns whether a an error has been thrown.
*/
extern bool
malef_isFlyingError (void);
malef_isFlyingError ( void );

/*
* This function gets the last error name and returns it. Keep in mind you
Expand All @@ -276,7 +276,7 @@ malef_isFlyingError (void);
* A pointer to an allocated string with the name of the error.
*/
extern char*
malef_getErrorName (void);
malef_getErrorName ( void );

/*
* This function gets the last error message describing the `thrown' error and
Expand All @@ -286,7 +286,7 @@ malef_getErrorName (void);
* A pointer to an allocated string with the message of the error.
*/
extern char*
malef_getErrorMessage (void);
malef_getErrorMessage ( void );



Expand All @@ -307,7 +307,7 @@ malef_getErrorMessage (void);
* already initialized.
*/
extern malef_error_t
malef_initialize (void);
malef_initialize ( void );

/*
* This function finalizes the library and everything. It must have been
Expand All @@ -319,7 +319,7 @@ malef_initialize (void);
* initialized before calling the function.
*/
extern malef_error_t
malef_finalize (void);
malef_finalize ( void );

/*
* This function doesn't raise any error and doesn't requiere the library to be
Expand All @@ -329,7 +329,7 @@ malef_finalize (void);
* Whether it has been initialized or not.
*/
extern bool
malef_isInitialized (void);
malef_isInitialized ( void );

/*
* This function returns (to the parameter) the height of the current terminal
Expand All @@ -344,7 +344,7 @@ malef_isInitialized (void);
* not initialized.
*/
extern malef_error_t
malef_getHeight (malef_row_t out height);
malef_getHeight ( malef_row_t out height );

/*
* This function returns (to the parameter) the width of the current terminal
Expand All @@ -359,7 +359,7 @@ malef_getHeight (malef_row_t out height);
* not initialized.
*/
extern malef_error_t
malef_getWidth (malef_col_t out width);
malef_getWidth ( malef_col_t out width );

/*
* This function moves everything there was on the terminal before execution
Expand All @@ -370,7 +370,7 @@ malef_getWidth (malef_col_t out width);
* not initialized.
*/
extern malef_error_t
malef_newPage (void);
malef_newPage ( void );

/*
* This function changes the title of the terminal, it's imposible to retrieve
Expand All @@ -382,7 +382,7 @@ malef_newPage (void);
* not initialized.
*/
extern malef_error_t
malef_setTitle (const char* in titleName);
malef_setTitle ( const char* in titleName );

/*
* This function updates the terminal size and returns whether it has changed,
Expand All @@ -398,7 +398,7 @@ malef_setTitle (const char* in titleName);
* function.
*/
extern malef_error_t
malef_updateTerminalSize (bool out is_updated);
malef_updateTerminalSize ( bool out is_updated );

/*
* This is a wrapper, you can give your function and parameters and be sure
Expand All @@ -420,9 +420,9 @@ malef_updateTerminalSize (bool out is_updated);
* nothing just return NULL.
*/
extern malef_error_t
malef_wrapper (void* (*function)(void*),
void* in params,
void out ret_val);
malef_wrapper ( void* (*function)(void*),
void* in params,
void out ret_val );

/*
* This function returns a null surface, remember to initialize all your
Expand All @@ -432,7 +432,7 @@ malef_wrapper (void* (*function)(void*),
* A null surface.
*/
extern malef_surface_t
malef_getNullSurface (void);
malef_getNullSurface ( void );

/*
* This is basically a short-cut so you don't remember to initialize always a
Expand Down
67 changes: 66 additions & 1 deletion dev-tools/do.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import sys


dirs = ["ada-malef"]
dirs = ["ada-malef", "c-malef", "py-malef"]
temp = dirs.copy()

while len(temp) != 0:
Expand All @@ -51,6 +51,70 @@

del temp

def _lines():
sources = []
for d in dirs:
sources += filter(lambda f: os.path.isfile(f) and
f.split('.')[-1] in ["ads", "adb", "c",
"h", "py", "gpr"],
[os.path.join(d, f) for f in os.listdir(d)])

data = {}
max_size = 0
max_lines = 0
max_len = 0
for source in sources:
size = os.stat(source).st_size
file = open(source, 'r')
lines = file.read().count('\n')
file.close()
del file
data.update({source: (size, lines)})

if size > max_size:
max_size = size
if lines > max_lines:
max_lines = lines
if len(source) > max_len:
max_len = len(source)

total_size = 0
total_lines = 0
_max_size = len(str(max_size)) + 1
_max_lines = len(str(max_lines)) + 1
_max_len = max_len + 1
for source in data:
size, lines = data[source]
total_size += size
total_lines += lines

source = source + (_max_len - len(source)) * ' '
print("\033[36;1m%s\033[0m: " % source, end="")

size = str(size)
lines = str(lines)
size = (_max_size - len(size)) * ' ' + size
lines = (_max_lines - len(lines)) * ' ' + lines
print("size =\033[31m%s\033[0mB "\
"lines=\033[32m%s\033[0m" % (size, lines))

print()
print("\033[36;1mTOTAL\033[0m:")

def get_size (size):
n = 0
while size / (1024**n) > 1:
n += 1
if n != 0:
n -= 1

units = ["B", "KiB", "MiB", "GiB"]
return (size / (1024 ** n), units[n])

print("\tSIZE = \033[31m%d\033[0m%s" % get_size(total_size))
print("\tLINES = \033[32m%d\033[0m" % total_lines)


def _todo():
TODO = {}
files = []
Expand Down Expand Up @@ -154,6 +218,7 @@ def status (filename, status, description=""):
"docs": "gnatdoc -bplwPmalef --enable-build",
"todo": _todo,
"commit": _commit,
"lines": _lines,
}


Expand Down
15 changes: 9 additions & 6 deletions py-malef/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,20 @@ def _get_version () -> str:


def main ():
src_base = Extension(name = "malef",
sources = ["src-base/py_malef.c"],
include_dirs = ["../c-malef/include"],
#define_macros = [(name, value)]
#undef_macros = []
library_dirs = ["../alire/build/lib-linux"],
libraries = ["Malef"],
runtime_library_dirs = ["../alire/build/lib-linux"])
setup(name = "malef",
version = _get_version(),
description = "MALEF",
author = "José Antonio Verde Jiménez",
author_email = "[email protected]",
ext_modules = [Extension(name = "malef",
sources = ["src-base/py_malef.c"],
include_dirs = ["../c-malef/include"],
library_dirs = ["../alire/build/lib-linux"],
libraries = ["Malef"])
])
ext_modules = [src_base])


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 677c86f

Please sign in to comment.