libc8
CHIP-8 utility library
Loading...
Searching...
No Matches
util.h File Reference

Go to the source code of this file.

Macros

#define VERBOSE_PRINT(a, ...)   if (a & ARG_VERBOSE) { printf(__VA_ARGS__); }
 

Functions

int hex_to_int (char)
 Get the integer value of hexadecimal ASCII representation.
 
int parse_int (const char *)
 Parse decimal or hexadecimal integer from s
 
char * trim (char *)
 Trim leading and trailing whitespace from s
 

Detailed Description

Note
NOT EXPORTED

Miscellaneous useful functions.

Macro Definition Documentation

◆ VERBOSE_PRINT

#define VERBOSE_PRINT (   a,
  ... 
)    if (a & ARG_VERBOSE) { printf(__VA_ARGS__); }

Function Documentation

◆ hex_to_int()

int hex_to_int ( char  c)

Get the integer value of hexadecimal ASCII representation.

Parameters
cthe char to convert
Returns
-1 if failed, otherwise 0-15

◆ parse_int()

int parse_int ( const char *  s)

Parse decimal or hexadecimal integer from s

Converts string s to an integer. Assumes decimal unless the first character is ‘’$'or'x'`.

Parameters
sThe string to convert.
Returns
-1 if failed, otherwise whatever the value is

◆ trim()

char * trim ( char *  s)

Trim leading and trailing whitespace from s

Puts a NULL character after the last non-whitespace character and returns a pointer to the first non-whitespace character.

Parameters
sstring to trim
Returns
pointer to first non-whitespace character after s.