- Commit
- e66ed4bdeed76da576a024fd8500a674f46b9ecb
- Parent
- 3239af26fd1dcd6cc5fbfb6ab2e36beb88392be3
- Author
- Pablo <pablo-pie@riseup.net>
- Date
Cleanup
Simple interface to set PulseAudio's volume, with graphical feedback! 🔊
Cleanup
2 files changed, 44 insertions, 28 deletions
| Status | Name | Changes | Insertions | Deletions |
| Modified | nob.c | 2 files changed | 11 | 1 |
| Modified | src/configure.c | 2 files changed | 33 | 27 |
diff --git a/nob.c b/nob.c @@ -42,9 +42,19 @@ i32 main(i32 argc, char** argv) da_append(&srcs, "nob.c"); assert(walk_dir(SRC_DIR, append_all_srcs, .data = &srcs)); + + bool needs_build = needs_rebuild(OUTPUT_PATH, srcs.items, srcs.count); + if (needs_build) { + cmd_append(&cmd, "ctags"); + for (u64 i = 0; i < srcs.count; i++) cmd_append(&cmd, srcs.items[i]); + if (!cmd_run(&cmd)) return EXIT_FAILURE; + } + + srcs.count = 0; assert(walk_dir(ASSETS_DIR, append_all_srcs, .data = &srcs)); + needs_build |= needs_rebuild(OUTPUT_PATH, srcs.items, srcs.count); - if (needs_rebuild(OUTPUT_PATH, srcs.items, srcs.count)) { + if (needs_build) { cmd_append(&cmd, "cc", CONFIGURE_SRC_PATH); cmd_append(&cmd, "-o", CONFIGURE_OUTPUT_PATH); cmd_append(&cmd, OPTS);
diff --git a/src/configure.c b/src/configure.c @@ -119,17 +119,22 @@ u64 log_floor(u64 n) // = vorbis parsing =========================================================== #define VORBIS_READ_CHUNK 4096 -// TODO: verify this +// NOTE: https://xiph.org/vorbis/doc/vorbisfile/ov_fopen.html const char* ov_error_str(i32 e) { + static char unknown_err[256]; + switch(e){ case 0: return "OK"; - case OV_EREAD: return "read error"; - case OV_ENOTVORBIS: return "not a Vorbis bitstream"; + case OV_EREAD: return "Read error"; + case OV_ENOTVORBIS: return "Not a Vorbis bitstream"; case OV_EVERSION: return "Vorbis version mismatch"; - case OV_EBADHEADER: return "invalid Vorbis header"; - case OV_EFAULT: return "internal fault"; - default: return "unknown error"; + case OV_EBADHEADER: return "Invalid Vorbis header"; + case OV_EFAULT: return "Internal fault"; + case OV_FALSE: return strerror(errno); + default: + sprintf(unknown_err, "Unknown error (%d)", e); + return (const char*)unknown_err; } } @@ -182,7 +187,7 @@ b8 parse_sample(const char* path, PCM* pcm) } assert(buff); - pcm->samples = buff; + pcm->samples = buff; pcm->samples_count = buff_count; return true; @@ -248,7 +253,7 @@ typedef struct { u64 current_line_start; SB sb; - Arena* allocator; + Arena* str_store; } Lexer; typedef enum { @@ -346,8 +351,8 @@ b8 parse_int(SV text, Location loc, i64* val) } if (sv_starts_with(text, "0x") || sv_starts_with(text, "0X")) { - text.data += 2; - text.count -= 2; + text.data += 2; + text.count -= 2; for (u64 i = 0; i < text.count; i++) { char c = text.data[i]; @@ -416,11 +421,11 @@ void lexer_skip_whitespace(Lexer* l) } } -b8 lexer_new(const char* path, Lexer* l, Arena* a) +b8 lexer_new(const char* path, Lexer* l, Arena* str_store) { memset(l, 0, sizeof(*l)); l->src_path = path; - l->allocator = a; + l->str_store = str_store; i32 fd = open(path, O_RDONLY); if (fd < 0) { @@ -438,7 +443,7 @@ b8 lexer_new(const char* path, Lexer* l, Arena* a) u64 count = st.st_size; if (count == 0) return true; - const char* buff = malloc(count); + const char* buff = arena_alloc(str_store, count); assert(buff && "buy more RAM!"); if (read(fd, (void*)buff, count) != (i64)count) { @@ -560,7 +565,7 @@ b8 lexer_next(Lexer* l, Token* token) char c = l->data[l->cursor]; switch (c) { case '"': - char* str = arena_alloc(l->allocator, l->sb.count + 1); + char* str = arena_alloc(l->str_store, l->sb.count + 1); assert(str && "buy more RAM!"); memcpy(str, l->sb.data, l->sb.count); @@ -630,9 +635,10 @@ b8 lexer_next(Lexer* l, Token* token) } else if (c == '+' || c == '-' || isdigit(c)) { SV text; u64 count = 0; text.data = l->data + l->cursor; - char c = l->data[l->cursor]; - for (; l->cursor < l->count; c = l->data[++l->cursor]) { + while (l->cursor < l->count) { + char c = l->data[l->cursor]; if (!(isalnum(c) || c == '+' || c == '-')) break; + l->cursor++; count++; } text.count = count; @@ -670,7 +676,7 @@ typedef enum { KEY_COLOR_ACCENT, KEY_COLOR_WARNING, - KEYS_COUNT, + KEY_COUNT, } Key; typedef struct { @@ -683,8 +689,8 @@ typedef struct { u64 max_val; } KeyInfo; -static_assert(KEYS_COUNT == 13); -KeyInfo key_infos[KEYS_COUNT] = { +static_assert(KEY_COUNT == 13); +KeyInfo key_infos[KEY_COUNT] = { [KEY_WINDOW_WIDTH] = { "width", "window", offsetof(Config, window_width), TOKEN_INT, }, [KEY_WINDOW_HEIGHT] = { "height", "window", offsetof(Config, window_height), TOKEN_INT, }, [KEY_WINDOW_PROGRESS_HEIGHT] = { "progress_height", "window", offsetof(Config, window_progress_height), TOKEN_INT, }, @@ -728,8 +734,8 @@ b8 check_bounds(const char* path, Key k, Config* config, i64 min, i64 max) b8 parse_config(const char* path, Config* config) { - Arena allocator = {0}; Lexer l; - if (!lexer_new(path, &l, &allocator)) return false; + Arena str_store = {0}; Lexer l; + if (!lexer_new(path, &l, &str_store)) return false; // = parsing ================================================================ Token token; u16 key_set_flag = 0; @@ -761,7 +767,7 @@ b8 parse_config(const char* path, Config* config) } b8 key_found = false; - for (u64 k = 0; k < KEYS_COUNT; k++) { + for (u64 k = 0; k < KEY_COUNT; k++) { KeyInfo info = key_infos[k]; if (!sv_equals(key, info.name)) continue; @@ -790,7 +796,7 @@ b8 parse_config(const char* path, Config* config) } // = validation ============================================================= - for (u64 k = 0; k < KEYS_COUNT; k++) { + for (u64 k = 0; k < KEY_COUNT; k++) { KeyInfo info = key_infos[k]; if (!(key_set_flag & (1 << k))) { @@ -816,9 +822,9 @@ b8 parse_config(const char* path, Config* config) if (!check_bounds(path, KEY_VOLUME_INC, config, 1, U8_MAX)) return false; if (!check_bounds(path, KEY_VOLUME_CAP, config, 1, U8_MAX)) return false; - for (u64 k = KEY_COLOR_BACKGROUND; k <= KEY_COLOR_WARNING; k++) { - if (!check_bounds(path, k, config, 0, 0xFFFFFF)) return false; - } - + if (!check_bounds(path, KEY_COLOR_BACKGROUND, config, 0, 0xFFFFFF)) return false; + if (!check_bounds(path, KEY_COLOR_LIGHT_BACKGROUND, config, 0, 0xFFFFFF)) return false; + if (!check_bounds(path, KEY_COLOR_ACCENT, config, 0, 0xFFFFFF)) return false; + if (!check_bounds(path, KEY_COLOR_WARNING, config, 0, 0xFFFFFF)) return false; return true; }