Hawaii Hybrid
Loading...
Searching...
No Matches
nob.h File Reference
#include <assert.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
Include dependency graph for nob.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Nob_File_Paths
struct  Nob_String_Builder
struct  Nob_Procs
struct  Nob_Cmd
struct  Nob_Cmd_Redirect
struct  Nob_String_View

Macros

#define NOBDEF
#define NOB_ASSERT   assert
#define NOB_REALLOC   realloc
#define NOB_FREE   free
#define NOB_LINE_END   "\n"
#define NOB_PRINTF_FORMAT(STRING_INDEX, FIRST_TO_CHECK)
#define NOB_UNUSED(value)
#define NOB_TODO(message)
#define NOB_UNREACHABLE(message)
#define NOB_ARRAY_LEN(array)
#define NOB_ARRAY_GET(array, index)
#define nob_shift(xs, xs_sz)
#define nob_shift_args(argc, argv)
#define nob_return_defer(value)
#define NOB_DA_INIT_CAP   256
#define nob_da_reserve(da, expected_capacity)
#define nob_da_append(da, item)
#define nob_da_free(da)
#define nob_da_append_many(da, new_items, new_items_count)
#define nob_da_resize(da, new_size)
#define nob_da_last(da)
#define nob_da_remove_unordered(da, i)
#define nob_da_foreach(Type, it, da)
#define nob_sb_append_buf(sb, buf, size)
#define nob_sb_append_cstr(sb, cstr)
#define nob_sb_append_null(sb)
#define nob_sb_free(sb)
#define NOB_INVALID_PROC   (-1)
#define NOB_INVALID_FD   (-1)
#define nob_cmd_append(cmd, ...)
#define nob_cmd_extend(cmd, other_cmd)
#define nob_cmd_free(cmd)
#define nob_cmd_run_async(cmd)
#define NOB_TEMP_CAPACITY   (8*1024*1024)
#define nob_cc(cmd)
#define nob_cc_flags(cmd)
#define nob_cc_output(cmd, output_path)
#define nob_cc_inputs(cmd, ...)
#define NOB_REBUILD_URSELF(binary_path, source_path)
#define NOB_GO_REBUILD_URSELF(argc, argv)
#define NOB_GO_REBUILD_URSELF_PLUS(argc, argv, ...)
#define nob_sb_to_sv(sb)
#define SV_Fmt   "%.*s"
#define SV_Arg(sv)
#define NOB_STRIP_PREFIX_GUARD_

Typedefs

typedef int Nob_Proc
typedef int Nob_Fd

Enumerations

enum  Nob_Log_Level { NOB_INFO , NOB_WARNING , NOB_ERROR , NOB_NO_LOGS }
enum  Nob_File_Type { NOB_FILE_REGULAR = 0 , NOB_FILE_DIRECTORY , NOB_FILE_SYMLINK , NOB_FILE_OTHER }

Functions

NOBDEF void nob_log (Nob_Log_Level level, const char *fmt,...) NOB_PRINTF_FORMAT(2
NOBDEF bool nob_mkdir_if_not_exists (const char *path)
NOBDEF bool nob_copy_file (const char *src_path, const char *dst_path)
NOBDEF bool nob_copy_directory_recursively (const char *src_path, const char *dst_path)
NOBDEF bool nob_read_entire_dir (const char *parent, Nob_File_Paths *children)
NOBDEF bool nob_write_entire_file (const char *path, const void *data, size_t size)
NOBDEF Nob_File_Type nob_get_file_type (const char *path)
NOBDEF bool nob_delete_file (const char *path)
NOBDEF bool nob_read_entire_file (const char *path, Nob_String_Builder *sb)
NOBDEF int nob_sb_appendf (Nob_String_Builder *sb, const char *fmt,...) NOB_PRINTF_FORMAT(2
NOBDEF Nob_Fd nob_fd_open_for_read (const char *path)
NOBDEF Nob_Fd nob_fd_open_for_write (const char *path)
NOBDEF void nob_fd_close (Nob_Fd fd)
NOBDEF bool nob_proc_wait (Nob_Proc proc)
NOBDEF bool nob_procs_wait (Nob_Procs procs)
NOBDEF bool nob_procs_wait_and_reset (Nob_Procs *procs)
NOBDEF bool nob_procs_append_with_flush (Nob_Procs *procs, Nob_Proc proc, size_t max_procs_count)
NOBDEF void nob_cmd_render (Nob_Cmd cmd, Nob_String_Builder *render)
NOBDEF Nob_Proc nob_cmd_run_async_and_reset (Nob_Cmd *cmd)
NOBDEF Nob_Proc nob_cmd_run_async_redirect (Nob_Cmd cmd, Nob_Cmd_Redirect redirect)
NOBDEF Nob_Proc nob_cmd_run_async_redirect_and_reset (Nob_Cmd *cmd, Nob_Cmd_Redirect redirect)
NOBDEF bool nob_cmd_run_sync (Nob_Cmd cmd)
NOBDEF bool nob_cmd_run_sync_and_reset (Nob_Cmd *cmd)
NOBDEF bool nob_cmd_run_sync_redirect (Nob_Cmd cmd, Nob_Cmd_Redirect redirect)
NOBDEF bool nob_cmd_run_sync_redirect_and_reset (Nob_Cmd *cmd, Nob_Cmd_Redirect redirect)
NOBDEF char * nob_temp_strdup (const char *cstr)
NOBDEF void * nob_temp_alloc (size_t size)
NOBDEF char * nob_temp_sprintf (const char *format,...) NOB_PRINTF_FORMAT(1
NOBDEF char NOBDEF void nob_temp_reset (void)
NOBDEF size_t nob_temp_save (void)
NOBDEF void nob_temp_rewind (size_t checkpoint)
NOBDEF const char * nob_path_name (const char *path)
NOBDEF bool nob_rename (const char *old_path, const char *new_path)
NOBDEF int nob_needs_rebuild (const char *output_path, const char **input_paths, size_t input_paths_count)
NOBDEF int nob_needs_rebuild1 (const char *output_path, const char *input_path)
NOBDEF int nob_file_exists (const char *file_path)
NOBDEF const char * nob_get_current_dir_temp (void)
NOBDEF bool nob_set_current_dir (const char *path)
NOBDEF void nob__go_rebuild_urself (int argc, char **argv, const char *source_path,...)
NOBDEF const char * nob_temp_sv_to_cstr (Nob_String_View sv)
NOBDEF Nob_String_View nob_sv_chop_by_delim (Nob_String_View *sv, char delim)
NOBDEF Nob_String_View nob_sv_chop_left (Nob_String_View *sv, size_t n)
NOBDEF Nob_String_View nob_sv_trim (Nob_String_View sv)
NOBDEF Nob_String_View nob_sv_trim_left (Nob_String_View sv)
NOBDEF Nob_String_View nob_sv_trim_right (Nob_String_View sv)
NOBDEF bool nob_sv_eq (Nob_String_View a, Nob_String_View b)
NOBDEF bool nob_sv_end_with (Nob_String_View sv, const char *cstr)
NOBDEF bool nob_sv_starts_with (Nob_String_View sv, Nob_String_View expected_prefix)
NOBDEF Nob_String_View nob_sv_from_cstr (const char *cstr)
NOBDEF Nob_String_View nob_sv_from_parts (const char *data, size_t count)

Variables

Nob_Log_Level nob_minimal_log_level

Macro Definition Documentation

◆ NOB_ARRAY_GET

#define NOB_ARRAY_GET ( array,
index )
Value:
(NOB_ASSERT((size_t)index < NOB_ARRAY_LEN(array)), array[(size_t)index])
#define NOB_ASSERT
Definition nob.h:181
#define NOB_ARRAY_LEN(array)
Definition nob.h:243

◆ NOB_ARRAY_LEN

#define NOB_ARRAY_LEN ( array)
Value:
(sizeof(array)/sizeof(array[0]))

◆ NOB_ASSERT

#define NOB_ASSERT   assert

◆ nob_cc

#define nob_cc ( cmd)
Value:
nob_cmd_append(cmd, "cc")
#define nob_cmd_append(cmd,...)
Definition nob.h:455

◆ nob_cc_flags

#define nob_cc_flags ( cmd)
Value:
nob_cmd_append(cmd, "-Wall", "-Wextra")

◆ nob_cc_inputs

#define nob_cc_inputs ( cmd,
... )
Value:
nob_cmd_append(cmd, __VA_ARGS__)

◆ nob_cc_output

#define nob_cc_output ( cmd,
output_path )
Value:
nob_cmd_append(cmd, "-o", (output_path))

◆ nob_cmd_append

#define nob_cmd_append ( cmd,
... )
Value:
((const char*[]){__VA_ARGS__}), \
(sizeof((const char*[]){__VA_ARGS__})/sizeof(const char*)))
#define nob_da_append_many(da, new_items, new_items_count)
Definition nob.h:320

◆ nob_cmd_extend

#define nob_cmd_extend ( cmd,
other_cmd )
Value:
nob_da_append_many(cmd, (other_cmd)->items, (other_cmd)->count)

◆ nob_cmd_free

#define nob_cmd_free ( cmd)
Value:
NOB_FREE(cmd.items)
#define NOB_FREE
Definition nob.h:191

◆ nob_cmd_run_async

#define nob_cmd_run_async ( cmd)
Value:
NOBDEF Nob_Proc nob_cmd_run_async_redirect(Nob_Cmd cmd, Nob_Cmd_Redirect redirect)
Definition nob.h:443

◆ nob_da_append

#define nob_da_append ( da,
item )
Value:
do { \
nob_da_reserve((da), (da)->count + 1); \
(da)->items[(da)->count++] = (item); \
} while (0)

◆ nob_da_append_many

#define nob_da_append_many ( da,
new_items,
new_items_count )
Value:
do { \
nob_da_reserve((da), (da)->count + (new_items_count)); \
memcpy((da)->items + (da)->count, (new_items), (new_items_count)*sizeof(*(da)->items)); \
(da)->count += (new_items_count); \
} while (0)

◆ nob_da_foreach

#define nob_da_foreach ( Type,
it,
da )
Value:
for (Type *it = (da)->items; it < (da)->items + (da)->count; ++it)

◆ nob_da_free

#define nob_da_free ( da)
Value:
NOB_FREE((da).items)

◆ NOB_DA_INIT_CAP

#define NOB_DA_INIT_CAP   256

◆ nob_da_last

#define nob_da_last ( da)
Value:
(da)->items[(NOB_ASSERT((da)->count > 0), (da)->count-1)]

◆ nob_da_remove_unordered

#define nob_da_remove_unordered ( da,
i )
Value:
do { \
size_t j = (i); \
NOB_ASSERT(j < (da)->count); \
(da)->items[j] = (da)->items[--(da)->count]; \
} while(0)

◆ nob_da_reserve

#define nob_da_reserve ( da,
expected_capacity )
Value:
do { \
if ((expected_capacity) > (da)->capacity) { \
if ((da)->capacity == 0) { \
(da)->capacity = NOB_DA_INIT_CAP; \
} \
while ((expected_capacity) > (da)->capacity) { \
(da)->capacity *= 2; \
} \
(da)->items = NOB_REALLOC((da)->items, (da)->capacity * sizeof(*(da)->items)); \
NOB_ASSERT((da)->items != NULL && "Buy more RAM lol"); \
} \
} while (0)
#define NOB_DA_INIT_CAP
Definition nob.h:293
#define NOB_REALLOC
Definition nob.h:186

◆ nob_da_resize

#define nob_da_resize ( da,
new_size )
Value:
do { \
nob_da_reserve((da), new_size); \
(da)->count = (new_size); \
} while (0)

◆ NOB_FREE

#define NOB_FREE   free

◆ NOB_GO_REBUILD_URSELF

#define NOB_GO_REBUILD_URSELF ( argc,
argv )
Value:
nob__go_rebuild_urself(argc, argv, __FILE__, NULL)
NOBDEF void nob__go_rebuild_urself(int argc, char **argv, const char *source_path,...)

◆ NOB_GO_REBUILD_URSELF_PLUS

#define NOB_GO_REBUILD_URSELF_PLUS ( argc,
argv,
... )
Value:
nob__go_rebuild_urself(argc, argv, __FILE__, __VA_ARGS__, NULL);

◆ NOB_INVALID_FD

#define NOB_INVALID_FD   (-1)

◆ NOB_INVALID_PROC

#define NOB_INVALID_PROC   (-1)

◆ NOB_LINE_END

#define NOB_LINE_END   "\n"

◆ NOB_PRINTF_FORMAT

#define NOB_PRINTF_FORMAT ( STRING_INDEX,
FIRST_TO_CHECK )

◆ NOB_REALLOC

#define NOB_REALLOC   realloc

◆ NOB_REBUILD_URSELF

#define NOB_REBUILD_URSELF ( binary_path,
source_path )
Value:
"cc", "-o", binary_path, source_path

◆ nob_return_defer

#define nob_return_defer ( value)
Value:
do { result = (value); goto defer; } while(0)

◆ nob_sb_append_buf

#define nob_sb_append_buf ( sb,
buf,
size )
Value:
nob_da_append_many(sb, buf, size)

◆ nob_sb_append_cstr

#define nob_sb_append_cstr ( sb,
cstr )
Value:
do { \
const char *s = (cstr); \
size_t n = strlen(s); \
nob_da_append_many(sb, s, n); \
} while (0)

◆ nob_sb_append_null

#define nob_sb_append_null ( sb)
Value:

◆ nob_sb_free

#define nob_sb_free ( sb)
Value:
NOB_FREE((sb).items)

◆ nob_sb_to_sv

#define nob_sb_to_sv ( sb)
Value:
nob_sv_from_parts((sb).items, (sb).count)
NOBDEF Nob_String_View nob_sv_from_parts(const char *data, size_t count)

◆ nob_shift

#define nob_shift ( xs,
xs_sz )
Value:
(NOB_ASSERT((xs_sz) > 0), (xs_sz)--, *(xs)++)

◆ nob_shift_args

#define nob_shift_args ( argc,
argv )
Value:
nob_shift(*argv, *argc)
#define nob_shift(xs, xs_sz)
Definition nob.h:261

◆ NOB_STRIP_PREFIX_GUARD_

#define NOB_STRIP_PREFIX_GUARD_

◆ NOB_TEMP_CAPACITY

#define NOB_TEMP_CAPACITY   (8*1024*1024)

◆ NOB_TODO

#define NOB_TODO ( message)
Value:
do { fprintf(stderr, "%s:%d: TODO: %s\n", __FILE__, __LINE__, message); abort(); } while(0)

◆ NOB_UNREACHABLE

#define NOB_UNREACHABLE ( message)
Value:
do { fprintf(stderr, "%s:%d: UNREACHABLE: %s\n", __FILE__, __LINE__, message); abort(); } while(0)

◆ NOB_UNUSED

#define NOB_UNUSED ( value)
Value:
(void)(value)

◆ NOBDEF

#define NOBDEF

◆ SV_Arg

#define SV_Arg ( sv)
Value:
(int) (sv).count, (sv).data

◆ SV_Fmt

#define SV_Fmt   "%.*s"

Typedef Documentation

◆ Nob_Fd

typedef int Nob_Fd

◆ Nob_Proc

typedef int Nob_Proc

Enumeration Type Documentation

◆ Nob_File_Type

Enumerator
NOB_FILE_REGULAR 
NOB_FILE_DIRECTORY 
NOB_FILE_SYMLINK 
NOB_FILE_OTHER 

◆ Nob_Log_Level

Enumerator
NOB_INFO 
NOB_WARNING 
NOB_ERROR 
NOB_NO_LOGS 

Function Documentation

◆ nob__go_rebuild_urself()

NOBDEF void nob__go_rebuild_urself ( int argc,
char ** argv,
const char * source_path,
... )

◆ nob_cmd_render()

NOBDEF void nob_cmd_render ( Nob_Cmd cmd,
Nob_String_Builder * render )

◆ nob_cmd_run_async_and_reset()

NOBDEF Nob_Proc nob_cmd_run_async_and_reset ( Nob_Cmd * cmd)

◆ nob_cmd_run_async_redirect()

NOBDEF Nob_Proc nob_cmd_run_async_redirect ( Nob_Cmd cmd,
Nob_Cmd_Redirect redirect )

◆ nob_cmd_run_async_redirect_and_reset()

NOBDEF Nob_Proc nob_cmd_run_async_redirect_and_reset ( Nob_Cmd * cmd,
Nob_Cmd_Redirect redirect )

◆ nob_cmd_run_sync()

NOBDEF bool nob_cmd_run_sync ( Nob_Cmd cmd)

◆ nob_cmd_run_sync_and_reset()

NOBDEF bool nob_cmd_run_sync_and_reset ( Nob_Cmd * cmd)

◆ nob_cmd_run_sync_redirect()

NOBDEF bool nob_cmd_run_sync_redirect ( Nob_Cmd cmd,
Nob_Cmd_Redirect redirect )

◆ nob_cmd_run_sync_redirect_and_reset()

NOBDEF bool nob_cmd_run_sync_redirect_and_reset ( Nob_Cmd * cmd,
Nob_Cmd_Redirect redirect )

◆ nob_copy_directory_recursively()

NOBDEF bool nob_copy_directory_recursively ( const char * src_path,
const char * dst_path )

◆ nob_copy_file()

NOBDEF bool nob_copy_file ( const char * src_path,
const char * dst_path )

◆ nob_delete_file()

NOBDEF bool nob_delete_file ( const char * path)

◆ nob_fd_close()

NOBDEF void nob_fd_close ( Nob_Fd fd)

◆ nob_fd_open_for_read()

NOBDEF Nob_Fd nob_fd_open_for_read ( const char * path)

◆ nob_fd_open_for_write()

NOBDEF Nob_Fd nob_fd_open_for_write ( const char * path)

◆ nob_file_exists()

NOBDEF int nob_file_exists ( const char * file_path)

◆ nob_get_current_dir_temp()

NOBDEF const char * nob_get_current_dir_temp ( void )

◆ nob_get_file_type()

NOBDEF Nob_File_Type nob_get_file_type ( const char * path)

◆ nob_log()

NOBDEF void nob_log ( Nob_Log_Level level,
const char * fmt,
... )

◆ nob_mkdir_if_not_exists()

NOBDEF bool nob_mkdir_if_not_exists ( const char * path)

◆ nob_needs_rebuild()

NOBDEF int nob_needs_rebuild ( const char * output_path,
const char ** input_paths,
size_t input_paths_count )

◆ nob_needs_rebuild1()

NOBDEF int nob_needs_rebuild1 ( const char * output_path,
const char * input_path )

◆ nob_path_name()

NOBDEF const char * nob_path_name ( const char * path)

◆ nob_proc_wait()

NOBDEF bool nob_proc_wait ( Nob_Proc proc)

◆ nob_procs_append_with_flush()

NOBDEF bool nob_procs_append_with_flush ( Nob_Procs * procs,
Nob_Proc proc,
size_t max_procs_count )

◆ nob_procs_wait()

NOBDEF bool nob_procs_wait ( Nob_Procs procs)

◆ nob_procs_wait_and_reset()

NOBDEF bool nob_procs_wait_and_reset ( Nob_Procs * procs)

◆ nob_read_entire_dir()

NOBDEF bool nob_read_entire_dir ( const char * parent,
Nob_File_Paths * children )

◆ nob_read_entire_file()

NOBDEF bool nob_read_entire_file ( const char * path,
Nob_String_Builder * sb )

◆ nob_rename()

NOBDEF bool nob_rename ( const char * old_path,
const char * new_path )

◆ nob_sb_appendf()

NOBDEF int nob_sb_appendf ( Nob_String_Builder * sb,
const char * fmt,
... )

◆ nob_set_current_dir()

NOBDEF bool nob_set_current_dir ( const char * path)

◆ nob_sv_chop_by_delim()

NOBDEF Nob_String_View nob_sv_chop_by_delim ( Nob_String_View * sv,
char delim )

◆ nob_sv_chop_left()

NOBDEF Nob_String_View nob_sv_chop_left ( Nob_String_View * sv,
size_t n )

◆ nob_sv_end_with()

NOBDEF bool nob_sv_end_with ( Nob_String_View sv,
const char * cstr )

◆ nob_sv_eq()

NOBDEF bool nob_sv_eq ( Nob_String_View a,
Nob_String_View b )

◆ nob_sv_from_cstr()

NOBDEF Nob_String_View nob_sv_from_cstr ( const char * cstr)

◆ nob_sv_from_parts()

NOBDEF Nob_String_View nob_sv_from_parts ( const char * data,
size_t count )

◆ nob_sv_starts_with()

NOBDEF bool nob_sv_starts_with ( Nob_String_View sv,
Nob_String_View expected_prefix )

◆ nob_sv_trim()

◆ nob_sv_trim_left()

NOBDEF Nob_String_View nob_sv_trim_left ( Nob_String_View sv)

◆ nob_sv_trim_right()

NOBDEF Nob_String_View nob_sv_trim_right ( Nob_String_View sv)

◆ nob_temp_alloc()

NOBDEF void * nob_temp_alloc ( size_t size)

◆ nob_temp_reset()

NOBDEF char NOBDEF void nob_temp_reset ( void )

◆ nob_temp_rewind()

NOBDEF void nob_temp_rewind ( size_t checkpoint)

◆ nob_temp_save()

NOBDEF size_t nob_temp_save ( void )

◆ nob_temp_sprintf()

NOBDEF char * nob_temp_sprintf ( const char * format,
... )

◆ nob_temp_strdup()

NOBDEF char * nob_temp_strdup ( const char * cstr)

◆ nob_temp_sv_to_cstr()

NOBDEF const char * nob_temp_sv_to_cstr ( Nob_String_View sv)

◆ nob_write_entire_file()

NOBDEF bool nob_write_entire_file ( const char * path,
const void * data,
size_t size )

Variable Documentation

◆ nob_minimal_log_level

Nob_Log_Level nob_minimal_log_level
extern