v4k-git-backup/engine/split/v4k_system.h

85 lines
3.3 KiB
C
Raw Normal View History

// -----------------------------------------------------------------------------
// system framework utils
// - rlyeh, public domain.
//
// Note: Windows users add `/Zi` compilation flags, else add `-g` and/or `-ldl` flags
// Note: If you are linking your binary using GNU ld you need to add --export-dynamic
API void* thread( int (*thread_func)(void* user_data), void* user_data );
API void thread_destroy( void *thd );
API int argc();
API char* argv(int);
API int flag(const char *commalist); // --arg // app_flag?
2023-10-07 17:34:09 +00:00
API const char* option(const char *commalist, const char *defaults); // --arg=string or --arg string
API int optioni(const char *commalist, int defaults); // --arg=integer or --arg integer // argvi() ?
API float optionf(const char *commalist, float defaults); // --arg=float or --arg float // flagf() ?
API void tty_attach();
2023-08-11 19:53:24 +00:00
API void tty_detach();
2023-10-07 17:34:09 +00:00
API void tty_color(unsigned color);
API void tty_reset();
API const char* app_exec(const char *command); // returns ("%15d %s", retcode, output_last_line)
API int app_spawn(const char *command);
API int app_cores();
2023-10-07 17:34:09 +00:00
API int app_battery(); /// returns battery level [1..100]. also positive if charging (+), negative if discharging (-), and 0 if no battery is present.
API const char* app_name();
API const char* app_path();
API const char* app_cache();
API const char* app_temp();
API const char* app_cmdline();
2023-10-07 17:34:09 +00:00
API void app_beep();
API void app_hang();
API void app_crash();
API void app_singleton(const char *guid);
API bool app_open(const char *folder_file_or_url);
2023-10-13 10:59:44 +00:00
API const char* app_loadfile();
API const char* app_savefile();
API char* callstack( int traces ); // write callstack into a temporary string. <0 traces to invert order. do not free().
API int callstackf( FILE *fp, int traces ); // write callstack to file. <0 traces to invert order.
API void die(const char *message);
API void alert(const char *message);
API void hexdump( const void *ptr, unsigned len );
API void hexdumpf( FILE *fp, const void *ptr, unsigned len, int width );
2023-10-21 09:18:13 +00:00
API void breakpoint();
API bool has_debugger();
2023-10-07 17:34:09 +00:00
API void trap_install(void);
API const char *trap_name(int signal); // helper util
API void trap_on_ignore(int signal); // helper util
API void trap_on_quit(int signal); // helper util
API void trap_on_abort(int signal); // helper util
API void trap_on_debug(int signal); // helper util
2023-11-15 19:14:14 +00:00
#define PANIC(...) PANIC(va(""__VA_ARGS__), __FILE__, __LINE__) // die() ?
API int (PANIC)(const char *error, const char *file, int line);
2023-11-15 19:14:14 +00:00
#define PRINTF(...) PRINTF(va(""__VA_ARGS__), 1[""#__VA_ARGS__] == '!' ? callstack(+48) : "", __FILE__, __LINE__, __FUNCTION__)
API int (PRINTF)(const char *text, const char *stack, const char *file, int line, const char *function);
2023-10-07 17:34:09 +00:00
2023-11-15 19:14:14 +00:00
#define test(expr) test(__FILE__,__LINE__,#expr,!!(expr))
2023-10-07 17:34:09 +00:00
API int (test)(const char *file, int line, const char *expr, bool result);
2023-10-11 19:01:06 +00:00
2023-10-14 19:47:24 +00:00
#if ENABLE_AUTOTESTS
2023-10-11 19:01:06 +00:00
#define AUTOTEST AUTORUN
#else
#define AUTOTEST static void concat(concat(concat(disabled_test_, __LINE__), _), __COUNTER__)()
#endif
// AUTOTEST { test(1<2); }
2023-10-14 19:47:24 +00:00
#if ENABLE_RETAIL
#undef PRINTF
#define PRINTF(...) 0
#undef test
#define test(expr) 0
#endif