Foenix A2650 OS/f Library
 
Loading...
Searching...
No Matches
general.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include "a2560k.h"

Go to the source code of this file.

Data Structures

struct  Coordinate
 

Functions

int32_t General_Round (double the_float)
 Round a float to the nearest integer value THINK C's and SAS/C's math.h don't include round() from: https://stackoverflow.com/questions/4572556/concise-way-to-implement-round-in-c. More...
 
bool General_StrToLower (char *the_string)
 Convert a string, in place, to lower case This overwrites the string with a lower case version of itself. More...
 
uint8_t General_ToLower (uint8_t the_char)
 Change the case of the passed character from upper to lower (if necessary) Scope is limited to characters A-Z, ascii. More...
 
char * General_StrlcpyWithAlloc (const char *src, size_t max_len)
 Allocates memory for a new string and copies up to max_len - 1 characters from the NUL-terminated string src to the new string, NUL-terminating the result This is meant to be a one stop shop for getting a copy of a string. More...
 
int16_t General_Strlcpy (char *dst, const char *src, size_t max_len)
 Copies up to max_len - 1 characters from the NUL-terminated string src to dst, NUL-terminating the result. More...
 
int16_t General_Strlcat (char *dst, const char *src, size_t max_len)
 Copies up to max_len - 1 characters from the NUL-terminated string src and appends to the end of dst, NUL-terminating the result. More...
 
int16_t General_Strncmp (const char *string_1, const char *string_2, size_t max_len)
 Makes a case sensitive comparison of the specified number of characters of the two passed strings Stops processing once max_len has been reached, or when one of the two strings has run out of characters. More...
 
int16_t General_Strncasecmp (const char *string_1, const char *string_2, size_t max_len)
 Makes a case insensitive comparison of the specified number of characters of the two passed strings Stops processing once max_len has been reached, or when one of the two strings has run out of characters. More...
 
int16_t General_Strnlen (const char *the_string, size_t max_len)
 Measure the length of a fixed-size string Safe(r) strlen function: will stop processing if no terminator found before max_len reached. More...
 
bool General_RectWithinRect (Rectangle r1, Rectangle r2)
 Test if one rectangle is entirely within the bounds of another Rectangle. More...
 
void General_CopyRect (Rectangle *r1, Rectangle *r2)
 Copy values of one rect to another. More...
 
int16_t General_CalculateRectDifference (Rectangle *r1, Rectangle *r2, Rectangle *diff_r1, Rectangle *diff_r2, Rectangle *diff_r3, Rectangle *diff_r4)
 Calculate the difference between 2 rectangles and populate 0, 1, 2, 3, or 4 new rectangles with the difference If Rect 1 is larger than Rect 2, no new rect will be populated If Rect 1 is smaller than Rect 2 in one dimension (axis) only, 1 new rect will be populated If Rect 1 is smaller than Rect 2 in two dimensions (axes), 3 new rect will be populated If Rect 1 is same size as Rect 2 and moved in one dimension (axis) only, 1 new rect will be populated If Rect 1 is same size as Rect 2 and moved in two dimensions (axes), 3 new rect will be populated. More...
 
bool General_CalculateRectIntersection (Rectangle *r1, Rectangle *r2, Rectangle *intersect_r)
 Calculate the intersection between 2 rectangles, storing result in the 3rd rect passed. More...
 
char * General_NamePart (const char *the_file_path)
 return the first char of the last part of a file path if no path part detected, returns the original string not guaranteed that this is a FILENAME, as if you passed a path to a dir, it would return the DIR name ex: General_NamePart("/hd/yyy/zzz/myfile.txt") would return a pointer to 'myfile.txt'. More...
 
char * General_PathPart (const char *the_file_path)
 Returns a pointer to the end of the next-to-last component of a path. More...
 
bool General_ExtractFileExtensionFromFilename (const char *the_file_name, char *the_extension)
 Extract file extension into the passed char pointer, as new lowercased string pointer, if any found. More...
 
bool General_ExtractCoreFilename (const char *the_file_name, char *the_core_part)
 Extract core part of the file name, not including the extension. More...
 
void General_DelayTicks (int32_t ticks)
 Wait for the specified number of ticks before returning In multi-tasking ever becomes a thing, this is not a multi-tasking-friendly operation. More...
 
void General_DelaySeconds (uint16_t seconds)
 Wait for the specified number of seconds before returning In multi-tasking ever becomes a thing, this is not a multi-tasking-friendly operation. More...
 
uint32_t General_ByteSwapLong (uint32_t long_needing_swap)
 Swap bytes big endian <> little endian, for a long NOTE: for a word, see BSWAP() macro.
 

Function Documentation

◆ General_CalculateRectDifference()

int16_t General_CalculateRectDifference ( Rectangle r1,
Rectangle r2,
Rectangle diff_r1,
Rectangle diff_r2,
Rectangle diff_r3,
Rectangle diff_r4 
)

Calculate the difference between 2 rectangles and populate 0, 1, 2, 3, or 4 new rectangles with the difference If Rect 1 is larger than Rect 2, no new rect will be populated If Rect 1 is smaller than Rect 2 in one dimension (axis) only, 1 new rect will be populated If Rect 1 is smaller than Rect 2 in two dimensions (axes), 3 new rect will be populated If Rect 1 is same size as Rect 2 and moved in one dimension (axis) only, 1 new rect will be populated If Rect 1 is same size as Rect 2 and moved in two dimensions (axes), 3 new rect will be populated.

Parameters
r1- the lead, or foreground rect. When calculating a damage rect, this would typically be the rect of the window after it is moved/resized.
r2- the secondary, or background rect. When calculating a damage rect, this would typically be the rect of the window before it is moved/resized.
diff_r1- valid pointer to a rect object that will be populated if there is 1 or 3 difference rects resulting from the operation
diff_r2- valid pointer to a rect object that will be populated if there are 2 or more difference rects resulting from the operation
diff_r3- valid pointer to a rect object that will be populated if there are 3 or more difference rects resulting from the operation
diff_r4- valid pointer to a rect object that will be populated if there are 4 difference rects resulting from the operation
Returns
Returns number of new rects that represent the difference between the passed rectangles. This indicates how many, if any, of the diff_rects need to be evaluated. Returns -1 on any error condition.

◆ General_CalculateRectIntersection()

bool General_CalculateRectIntersection ( Rectangle r1,
Rectangle r2,
Rectangle intersect_r 
)

Calculate the intersection between 2 rectangles, storing result in the 3rd rect passed.

Parameters
r1- valid pointer to a rect object
r2- valid pointer to a rect object
intersect_r- valid pointer to a rect object that will contain the intersection rectangle, if any, at end of operation
Returns
: Returns true if there is an intersecting rectangle between r1 and r2.

◆ General_CopyRect()

void General_CopyRect ( Rectangle r1,
Rectangle r2 
)

Copy values of one rect to another.

Parameters
r1- the rectangle to be overwritten (copied into)
r2- the rectangle to copy

◆ General_DelaySeconds()

void General_DelaySeconds ( uint16_t  seconds)

Wait for the specified number of seconds before returning In multi-tasking ever becomes a thing, this is not a multi-tasking-friendly operation.


◆ General_DelayTicks()

void General_DelayTicks ( int32_t  ticks)

Wait for the specified number of ticks before returning In multi-tasking ever becomes a thing, this is not a multi-tasking-friendly operation.


◆ General_ExtractCoreFilename()

bool General_ExtractCoreFilename ( const char *  the_file_name,
char *  the_core_part 
)

Extract core part of the file name, not including the extension.

Parameters
the_file_name- the file name to extract an extension from
the_core_part- a pre-allocated buffer that will contain the pre-extension part of the file name, if any is detected. Must be large enough to hold the entire file name! No bounds checking is done. If no extension is found, this will contain an empty string.
Returns
Returns false if no file extension found (because what is "core" part without an extension)

◆ General_ExtractFileExtensionFromFilename()

bool General_ExtractFileExtensionFromFilename ( const char *  the_file_name,
char *  the_extension 
)

Extract file extension into the passed char pointer, as new lowercased string pointer, if any found.

Parameters
the_file_name- the file name to extract an extension from
the_extension- a pre-allocated buffer that will contain the extension, if any is detected. Must be large enough to hold the extension! No bounds checking is done.
Returns
Returns false if no file extension found.

◆ General_NamePart()

char * General_NamePart ( const char *  the_file_path)

return the first char of the last part of a file path if no path part detected, returns the original string not guaranteed that this is a FILENAME, as if you passed a path to a dir, it would return the DIR name ex: General_NamePart("/hd/yyy/zzz/myfile.txt") would return a pointer to 'myfile.txt'.

ex: General_NamePart("myfile.txt") would return a pointer to 'myfile.txt'. amigaDOS compatibility function (see FilePart)

◆ General_PathPart()

char * General_PathPart ( const char *  the_file_path)

Returns a pointer to the end of the next-to-last component of a path.

ex: General_PathPart("/hd/yyy/zzz/myfile.txt") would return a pointer to '/myfile.txt'. ex: General_PathPart("myfile.txt") would return a pointer to 'myfile.txt'. amigaDOS compatibility function (see PathPart)

◆ General_RectWithinRect()

bool General_RectWithinRect ( Rectangle  r1,
Rectangle  r2 
)

Test if one rectangle is entirely within the bounds of another Rectangle.

Parameters
r1- the rectangle being tested
r2- the rectangle being measured to determine if r1 fits entirely within it
Returns
: returns true if r1 is within bounds of r2.

◆ General_Round()

int32_t General_Round ( double  the_float)

Round a float to the nearest integer value THINK C's and SAS/C's math.h don't include round() from: https://stackoverflow.com/questions/4572556/concise-way-to-implement-round-in-c.

Parameters
the_float- a double value to round up/down
Returns
Returns an int with the rounded value

◆ General_Strlcat()

int16_t General_Strlcat ( char *  dst,
const char *  src,
size_t  max_len 
)

Copies up to max_len - 1 characters from the NUL-terminated string src and appends to the end of dst, NUL-terminating the result.

Parameters
src- The string to copy
dst- The string to append to. Calling function is responsible for ensuring this string is allocated, and has at least as much storage as max_len.
max_len- The maximum number of bytes to use in the destination string, including the terminator. If this is shorter than the length of src + length of dst + 1, the resulting copy string will be capped at max_len - 1.
Returns
Returns the length of the attempted concatenated string: initial length of dst plus the length of src.

◆ General_Strlcpy()

int16_t General_Strlcpy ( char *  dst,
const char *  src,
size_t  max_len 
)

Copies up to max_len - 1 characters from the NUL-terminated string src to dst, NUL-terminating the result.

Parameters
src- The string to copy
dst- The string to copy into. Calling function is responsible for ensuring this string is allocated, and has at least as much storage as max_len.
max_len- The maximum number of bytes to use in the destination string, including the terminator. If this is shorter than the length of the source string + 1, the resulting copy string will be capped at max_len - 1.
Returns
Returns the length of the source string, or -1 on any error condition

◆ General_StrlcpyWithAlloc()

char * General_StrlcpyWithAlloc ( const char *  src,
size_t  max_len 
)

Allocates memory for a new string and copies up to max_len - 1 characters from the NUL-terminated string src to the new string, NUL-terminating the result This is meant to be a one stop shop for getting a copy of a string.

Parameters
src- The string to copy
max_len- The maximum number of bytes to use in the destination string, including the terminator. If this is shorter than the length of the source string + 1, the resulting copy string will be capped at max_len - 1.
Returns
a copy of the source string to max_len, or NULL on any error condition

◆ General_Strncasecmp()

int16_t General_Strncasecmp ( const char *  string_1,
const char *  string_2,
size_t  max_len 
)

Makes a case insensitive comparison of the specified number of characters of the two passed strings Stops processing once max_len has been reached, or when one of the two strings has run out of characters.

Inspired by code from slashdot and apple open source https://stackoverflow.com/questions/5820810/case-insensitive-string-comparison-in-c https://opensource.apple.com/source/tcl/tcl-10/tcl/compat/strncasecmp.c.auto.html

Parameters
string_1- the first string to compare.
string_2- the second string to compare.
max_len- the maximum number of characters to compare. Even if both strings are larger than this number, only this many characters will be compared.
Returns
Returns 0 if the strings are equivalent (at least up to max_len). Returns a negative or positive if the strings are different.

◆ General_Strncmp()

int16_t General_Strncmp ( const char *  string_1,
const char *  string_2,
size_t  max_len 
)

Makes a case sensitive comparison of the specified number of characters of the two passed strings Stops processing once max_len has been reached, or when one of the two strings has run out of characters.

http://home.snafu.de/kdschem/c.dir/strings.dir/strncmp.c TODO: compare this to other implementations, see which is faster. eg, https://opensource.apple.com/source/Libc/Libc-167/gen.subproj/i386.subproj/strncmp.c.auto.html

Parameters
string_1- the first string to compare.
string_2- the second string to compare.
max_len- the maximum number of characters to compare. Even if both strings are larger than this number, only this many characters will be compared.
Returns
Returns 0 if the strings are equivalent (at least up to max_len). Returns a negative or positive if the strings are different.

◆ General_Strnlen()

int16_t General_Strnlen ( const char *  the_string,
size_t  max_len 
)

Measure the length of a fixed-size string Safe(r) strlen function: will stop processing if no terminator found before max_len reached.

Returns
Returns strlen(the_string), if that is less than max_len, or max_len if there is no null terminating ('\0') among the first max_len characters pointed to by the_string.

◆ General_StrToLower()

bool General_StrToLower ( char *  the_string)

Convert a string, in place, to lower case This overwrites the string with a lower case version of itself.

Warning: no length check is in place. Calling function must verify string is well-formed (terminated).

Parameters
the_string- the string to convert to lower case.
Returns
Returns true if the string was modified by the process.

◆ General_ToLower()

uint8_t General_ToLower ( uint8_t  the_char)

Change the case of the passed character from upper to lower (if necessary) Scope is limited to characters A-Z, ascii.

replacement for tolower() in c library, which doesn't seem to work [in Amiga WB2K] for some reason.

Returns
a character containing the lowercase version of the passed character.