API

group error

Public function definitions and types for Yc’s error handling.

Typedefs

typedef enum y_ErrorHandlerRet y_ErrorHandlerRet

An enum for the various values an error handler can return.

typedef y_ErrorHandlerRet (*y_ErrorHandler)(void *ptr, y_Error e, y_Status *ret)

A function to call when an error happens.

Param ptr:

A pointer passed to the error handler from the function that registered the handler. This can give the handler access to any data beyond just the error that may be needed. This can be NULL.

Param e:

The error to handle.

Param ret:

A pointer to return the new status.

Return:

A value saying whether the error was handled and if a restart should happen.

Pre:

ret must not be NULL.

Enums

enum y_ErrorHandlerRet

An enum for the various values an error handler can return.

Values:

enumerator y_ERROR_HANDLER_NOT_HANDLED

The error was not handled.

enumerator y_ERROR_HANDLER_HANDLED

The error was handled, but do not restart.

enumerator y_ERROR_HANDLER_RESTART

The error was handled, and a restart can happen.

Functions

y_ErrorHandlerRet y_err_ignore_noEnvVar(void *ptr, y_Error e, y_Status *ret)

A y_ErrorHandler for ignoring y_ERROR_NO_ENV_VAR.

Parameters:
  • ptr – A pointer passed to the error handler from the function that registered the handler. This can give the handler access to any data beyond just the error that may be needed. This can be NULL.

  • e – The error to handle.

  • ret – A pointer to return the new status.

Returns:

True if the error was handled, false otherwise.

Pre:

ret must not be NULL.

y_ErrorHandlerRet y_err_ignore_elemExists(void *ptr, y_Error e, y_Status *ret)

A y_ErrorHandler for ignoring y_ERROR_ELEM_EXISTS.

Parameters:
  • ptr – A pointer passed to the error handler from the function that registered the handler. This can give the handler access to any data beyond just the error that may be needed. This can be NULL.

  • e – The error to handle.

  • ret – A pointer to return the new status.

Returns:

True if the error was handled, false otherwise.

Pre:

ret must not be NULL.

y_ErrorHandlerRet y_err_ignore_fileExists(void *ptr, y_Error e, y_Status *ret)

A y_ErrorHandler for ignoring y_ERROR_FILE_EXISTS.

Parameters:
  • ptr – A pointer passed to the error handler from the function that registered the handler. This can give the handler access to any data beyond just the error that may be needed. This can be NULL.

  • e – The error to handle.

  • ret – A pointer to return the new status.

Returns:

True if the error was handled, false otherwise.

Pre:

ret must not be NULL.

y_ErrorHandlerRet y_err_ignore_doesNotExist(void *ptr, y_Error e, y_Status *ret)

A y_ErrorHandler for ignoring y_ERROR_DOES_NOT_EXIST.

Parameters:
  • ptr – A pointer passed to the error handler from the function that registered the handler. This can give the handler access to any data beyond just the error that may be needed. This can be NULL.

  • e – The error to handle.

  • ret – A pointer to return the new status.

Returns:

True if the error was handled, false otherwise.

Pre:

ret must not be NULL.

y_ErrorHandlerRet y_err_ignore_eof(void *ptr, y_Error e, y_Status *ret)

A y_ErrorHandler for ignoring y_ERROR_EOF.

Parameters:
  • ptr – A pointer passed to the error handler from the function that registered the handler. This can give the handler access to any data beyond just the error that may be needed. This can be NULL.

  • e – The error to handle.

  • ret – A pointer to return the new status.

Returns:

True if the error was handled, false otherwise.

Pre:

ret must not be NULL.

y_ErrorHandlerRet y_err_ignore_invalidChild(void *ptr, y_Error e, y_Status *ret)

A y_ErrorHandler for ignoring y_ERROR_INVALID_CHILD.

Parameters:
  • ptr – A pointer passed to the error handler from the function that registered the handler. This can give the handler access to any data beyond just the error that may be needed. This can be NULL.

  • e – The error to handle.

  • ret – A pointer to return the new status.

Returns:

True if the error was handled, false otherwise.

Pre:

ret must not be NULL.

group types

Public function definitions and types for Yc’s runtime type info.

Defines

y_TYPE_GEN_TYPE_STR(i)

A macro to generate a string for other macros.

Parameters:
  • i – The name of the thing to generate a name string for.

Returns:

A string corresponding to the name of i.

y_TYPE_GEN_ENUM_ITEM(i)

A macro meant to be used as a vararg to the y_TYPE_GEN_ENUM macro.

Generates an enum item from an enum item name.

Parameters:
  • i – The name of the enum item to generate.

Returns:

Material to be used in the y_TYPE_GEN_ENUM varargs.

y_TYPE_GEN_STRUCT_MEMBER(n, t, s)

A macro meant to be used as a vararg to the y_TYPE_GEN_STRUCT macro.

Generates a struct member.

Parameters:
  • n – The name of the member.

  • t – The type name of the member.

  • s – The parent struct of the member.

Returns:

Material to be used in the y_TYPE_GEN_STRUCT varargs.

y_TYPE_GEN_UNION_MEMBER(n, t)

A macro meant to be used as a vararg to the y_TYPE_GEN_UNION macro.

Generates a union member.

Parameters:
  • n – The name of the member.

  • t – The type name of the member.

Returns:

Material to be used in the y_TYPE_GEN_UNION varargs.

y_TYPE_GEN_PRIM(t)

A macro to generate type info for a primitive type.

Parameters:
  • t – The type name.

y_TYPE_GEN_POINTER(t, tp, dt)

A macro to generate type info for a pointer type.

Parameters:
  • t – The type name.

  • tp – The type the pointer points to.

  • dt – The destructor, if any.

y_TYPE_GEN_ENUM(t, ...)

A macro to generate type info for an enum type.

Parameters:
  • t – The type name.

y_TYPE_GEN_UNION(t, dt, cp, z, ...)

A macro to generate type info for a union type.

Parameters:
  • t – The type name.

  • dt – The destructor, if any.

  • cp – The copier function, if any.

  • z – The zero function, if any.

y_TYPE_GEN_STRUCT(t, dt, cp, z, ...)

A macro to generate type info for a struct type.

Parameters:
  • t – The type name.

  • dt – The destructor, if any.

  • cp – The copier function, if any.

  • z – The zero function, if any.

Typedefs

typedef const struct y_Type *(*y_TypeAnyFunc)(void)

A function type that will return a type’s type.

This is the function required to make a type obey the Any interface.

Return:

The type of the item the function is attached to.

Enums

enum y_TypeType

A enum listing the categories of types.

Values:

enumerator y_TYPE_PRIMITIVE

A primitive type (integers or floats).

enumerator y_TYPE_POINTER

Pointer types.

enumerator y_TYPE_STRUCT

Struct types.

enumerator y_TYPE_ENUM

Enum types.

enumerator y_TYPE_UNION

Union types.

struct y_TypeMember
#include <types.h>

Struct defining data for struct and union members.

struct y_TypeEnumItem
#include <types.h>

Struct defining data for enum items.

union y_TypeData
#include <types.h>

A union of data for types beyond the common data.

Public Members

y_TypeMember_array struct_members

An array for struct members.

y_TypeMember_array union_members

An array for union members.

y_TypeEnumItem_array enum_items

An array for enum items.

struct y_Type *pointer_subtype

The type that a pointer is a pointer to.

struct y_Type
#include <types.h>

The struct that defines information about types.

group opt

Common definitions for option parsing.

Defines

y_OPT_END

A macro for the return value that means no more arguments.

Typedefs

typedef struct y_opt *y_Opt

The public type of the non-public option parser.

Enums

enum y_OptType

Types of options.

Values:

enumerator y_OPT_NONE

Type for options with no arguments.

enumerator y_OPT_REQUIRED

Type for options with required arguments.

enumerator y_OPT_OPTIONAL

Type for options with optional arguments.

Functions

y_Opt y_opt_screate(void)

Creates and initializes the parser state.

Returns:

The newly-created option parser, or NULL on error.

y_Status y_opt_argv_main(y_Opt o, y_pchar **argv)

Puts a new argv into the parser state.

This is for parsing more than one argument set. The provided argv must be the one provided by the OS.

Parameters:
  • o – The y_Opt to initialize.

  • argv – The argument list that will be parsed.

Returns:

An error code, if any.

Pre:

o must not be NULL.

Pre:

argv must not be NULL.

Pre:

argv must be the argv provided by the OS.

y_Status y_opt_argv_other(y_Opt o, char **argv)

Puts a new argv into the parser state.

This is for parsing more than one argument set. The provided argv must not be the one provided by the OS.

Parameters:
  • o – The y_Opt to initialize.

  • argv – The argument list that will be parsed.

Returns:

An error code, if any.

Pre:

o must not be NULL.

Pre:

argv must not be NULL.

Pre:

argv must not be the argv provided by the OS.

void y_opt_destroy(void *options)

Frees the parser state.

Parameters:

options – The y_Opt to free.

Pre:

options must not be NULL.

y_u32 y_opt_parse(y_Opt o, const char *optstring)

Reads the next option in the argv array.

Just like getopt(), a character followed by no colons means no argument. One colon means the option has a required argument. Two colons means the option takes an optional argument.

Parameters:
  • o – The parse state.

  • optstring – A getopt()-formatted option string.

Returns:

The next option character or shortname, y_OPT_END for done, or ‘?’ for error.

Pre:

opts must not be NULL.

Pre:

optstring must not be NULL.

y_u32 y_opt_parse_long(y_Opt o, const y_OptLong *longopts, y_usize *longidx)

Handles GNU-style long options in addition to getopt() options.

This works a lot like GNU’s getopt_long(). The last option in longopts must be all zeros, marking the end of the array. The longindex argument may be NULL.

Parameters:
  • o – The parse state.

  • longopts – The long options.

  • longidx – The index of the found long option in longopts.

Returns:

The next option character or shortname, y_OPT_END for done, or ‘?’ for error.

Pre:

o must not be NULL.

Pre:

longopts must not be NULL.

y_u32 y_opt_parse_long_only(y_Opt o, const y_OptLong *longopts, y_usize *longidx)

Works a lot like GNU’s getopt_long_only().

Parameters:
  • o – The parse state.

  • longopts – The long options.

  • longidx – The index of the found long option in longopts.

Returns:

The next option character or shortname, y_OPT_END for done, or ‘?’ for error.

Pre:

o must not be NULL.

Pre:

longopts must not be NULL.

const char *y_opt_optarg(y_Opt o)

Returns the current optarg, which is the argument given to the current option.

Parameters:

o – The parse state.

Returns:

The current optarg, or NULL, if none.

Pre:

o must not be NULL.

y_uint y_opt_optind(y_Opt o)

Returns the current optind, which is the index of the next argument.

Parameters:

o – The parse state.

Returns:

The current optind.

Pre:

o must not be NULL.

const char *y_opt_arg(y_Opt o)

Steps over non-option arguments.

Argument parsing can continue with optparse() after using this function. That would be used to parse the options for the subcommand returned by optparse_arg(). This function allows you to ignore the value of optind.

Parameters:

o – The parse state.

Returns:

The next non-option argument, or NULL for no more arguments.

Pre:

o must not be NULL.

const char *y_opt_errmsg(y_Opt o)

Returns the error message contained in the parse state.

Parameters:

o – The parse state.

Returns:

The error message in the parse state.

Pre:

o must not be NULL.

struct y_OptLong
#include <opt.h>

Information about valid long options.

group simd

Public function definitions and types for Yc’s SIMD.

Functions

y_simd128 y_simd128l(const y_simd128 *addr)

Loads a 128-bit type from an address.

Parameters:

addr – The address to load from.

Returns:

The 128-bit SIMD data at addr.

Pre:

addr must not be NULL.

void y_simd128s(y_simd128 *addr, const y_simd128 d)

Stores 128 bits of SIMD data to memory.

Parameters:
  • addr – The address of the location the data will be stored at.

  • d – The data to store.

Pre:

addr must not be NULL.

y_simd256 y_simd256l(const y_simd256 *addr)

Loads a 256-bit type from an address.

Parameters:

addr – The address to load from.

Returns:

The 256-bit SIMD data at addr.

Pre:

addr must not be NULL.

void y_simd256s(y_simd256 *addr, const y_simd256 d)

Stores 256 bits of SIMD data to memory.

Parameters:
  • addr – The address of the location the data will be stored at.

  • d – The data to store.

Pre:

addr must not be NULL.