- Commit
- 3c432b50bbbf93bd95320221dbcec5943abf7fa3
- Parent
- c88e368b14682071e899b552ae30c7457b2fb1ad
- Author
- Pablo <pablo-pie@riseup.net>
- Date
Small naming refactor
Simple interface to set PulseAudio's volume, with graphical feedback! 🔊
Small naming refactor
2 files changed, 67 insertions, 67 deletions
| Status | Name | Changes | Insertions | Deletions |
| Modified | src/configure.c | 2 files changed | 62 | 62 |
| Modified | src/main.c | 2 files changed | 5 | 5 |
diff --git a/src/configure.c b/src/configure.c @@ -87,8 +87,8 @@ i32 main(i32 argc, char** argv) fprintf(f, "#define COLOR_WARNING 0xFF%lX\n\n", config.color_warning); fprintf(f, "int16_t volume_change_samples_buff[%zu] = {", - sample.samples_len); - for (u64 i = 0; i < sample.samples_len; i++) { + sample.samples_count); + for (u64 i = 0; i < sample.samples_count; i++) { if (i % 8 == 0) fprintf(f, "\n "); else fprintf(f, " "); if (sample.samples[i] >= 0) fprintf(f, " 0x%04X,", sample.samples[i]); @@ -99,9 +99,9 @@ i32 main(i32 argc, char** argv) fprintf(f, "PCM volume_change_sample = {\n"); fprintf(f, " .samples = volume_change_samples_buff,\n"); - fprintf(f, " .samples_len = %zu,\n", sample.samples_len); - fprintf(f, " .sample_rate = %zu,\n", sample.sample_rate); - fprintf(f, " .channels = %u,\n", sample.channels); + fprintf(f, " .samples_count = %zu,\n", sample.samples_count); + fprintf(f, " .sample_rate = %zu,\n", sample.sample_rate); + fprintf(f, " .channels = %u,\n", sample.channels); fprintf(f, "};"); return EXIT_SUCCESS; @@ -156,8 +156,8 @@ b8 parse_sample(const char* path, PCM* pcm) pcm->sample_rate = (u64)sample_rate; pcm->channels = (u8)channels; - i16* buff = malloc(5 * VORBIS_READ_CHUNK); - u64 buff_len = 0; + i16* buff = malloc(5 * VORBIS_READ_CHUNK); + u64 buff_count = 0; i32 section; char read_buff[VORBIS_READ_CHUNK]; @@ -172,16 +172,16 @@ b8 parse_sample(const char* path, PCM* pcm) u64 new_samples = ret / sizeof(buff[0]); - buff = realloc(buff, (buff_len + new_samples) * sizeof(buff[0])); + buff = realloc(buff, (buff_count + new_samples) * sizeof(buff[0])); assert(buff && "buy more RAM!"); - memcpy(buff + buff_len, read_buff, ret); - buff_len += new_samples; + memcpy(buff + buff_count, read_buff, ret); + buff_count += new_samples; } assert(buff); pcm->samples = buff; - pcm->samples_len = buff_len; + pcm->samples_count = buff_count; return true; } @@ -189,12 +189,12 @@ b8 parse_sample(const char* path, PCM* pcm) // = string view & string builder ============================================= typedef struct { const char* data; - u64 len; + u64 count; } SV; typedef struct { char* data; - u64 len; + u64 count; u64 capacity; } SB; @@ -202,22 +202,22 @@ typedef struct { b8 sv_equals(SV str1, const char* str2) { - if (str1.len != strlen(str2)) return false; - return memcmp(str1.data, str2, str1.len) == 0; + if (str1.count != strlen(str2)) return false; + return memcmp(str1.data, str2, str1.count) == 0; } b8 sv_starts_with(SV str, const char* prefix) { u64 prefix_len = strlen(prefix); - if (str.len < prefix_len) return false; + if (str.count < prefix_len) return false; return memcmp(str.data, prefix, prefix_len) == 0; } void sb_append(SB *sb, char c) { - assert(sb->len <= sb->capacity); - if (sb->len + 1 > sb->capacity) { + assert(sb->count <= sb->capacity); + if (sb->count + 1 > sb->capacity) { sb->capacity += SB_CHUNCK_CAP; char* new_data = realloc(sb->data, sb->capacity); @@ -225,13 +225,13 @@ void sb_append(SB *sb, char c) sb->data = new_data; } - sb->data[sb->len] = c; - sb->len++; + sb->data[sb->count] = c; + sb->count++; } void sb_clear(SB *sb) { - sb->len = 0; + sb->count = 0; } // = minimal DOS-INI lexer/parser ============================================= @@ -240,7 +240,7 @@ typedef struct { const char* data; u64 cursor; - u64 len; + u64 count; u64 current_line; u64 current_line_start; @@ -316,10 +316,10 @@ void location_report_end(Location loc, LogLevel level) { SV text = loc.text_start; - i32 len; - for (len = 0; len < (i32)text.len && text.data[len] != '\n'; len++); + i32 count = 0; + for (; count < (i32)text.count && text.data[count] != '\n'; count++); - fprintf(stderr, " %zu | %.*s\n ", loc.line, len, text.data); + fprintf(stderr, " %zu | %.*s\n ", loc.line, count, text.data); for (u64 i = 0; i < log_floor(loc.line); i++) fprintf(stderr, " "); fprintf(stderr, " | "); for (u64 i = 0; i < loc.offset; i++) fprintf(stderr, " "); @@ -338,9 +338,9 @@ b8 parse_int(SV text, Location loc, u64* val) if (sv_starts_with(text, "0x") || sv_starts_with(text, "0X")) { text.data += 2; - text.len -= 2; + text.count -= 2; - for (u64 i = 0; i < text.len; i++) { + for (u64 i = 0; i < text.count; i++) { char c = text.data[i]; *val *= 16; @@ -356,7 +356,7 @@ b8 parse_int(SV text, Location loc, u64* val) loc.offset += i + 2; location_report(loc, LOG_ERROR, "Could not parse integer value \"%.*s\"", - (i32)text.len, text.data); + (i32)text.count, text.data); return false; } } @@ -364,7 +364,7 @@ b8 parse_int(SV text, Location loc, u64* val) return true; } - for (u64 i = 0; i < text.len; i++) { + for (u64 i = 0; i < text.count; i++) { char c = text.data[i]; if (c == '_') continue; @@ -372,7 +372,7 @@ b8 parse_int(SV text, Location loc, u64* val) loc.offset += i; location_report(loc, LOG_ERROR, "Could not parse integer value \"%.*s\"", - (i32)text.len, text.data); + (i32)text.count, text.data); return false; } @@ -385,12 +385,12 @@ b8 parse_int(SV text, Location loc, u64* val) void lexer_skip_whitespace(Lexer* l) { - for (; l->cursor < l->len; l->cursor++) { + for (; l->cursor < l->count; l->cursor++) { char c = l->data[l->cursor]; if (c == ';' || c == '#') { // comment - for (; l->cursor < l->len && l->data[l->cursor] != '\n'; l->cursor++); - if (l->cursor >= l->len) return; + for (; l->cursor < l->count && l->data[l->cursor] != '\n'; l->cursor++); + if (l->cursor >= l->count) return; l->cursor++; l->current_line++; @@ -424,13 +424,13 @@ b8 lexer_new(const char* path, Lexer* l, Arena* a) return false; } - u64 len = st.st_size; - if (len == 0) return true; + u64 count = st.st_size; + if (count == 0) return true; - const char* buff = malloc(len); + const char* buff = malloc(count); assert(buff && "buy more RAM!"); - if (read(fd, (void*)buff, len) != (i64)len) { + if (read(fd, (void*)buff, count) != (i64)count) { report("Could not read \"%s\"", path); free((char*)buff); close(fd); @@ -438,7 +438,7 @@ b8 lexer_new(const char* path, Lexer* l, Arena* a) } l->data = buff; - l->len = (u64)len; + l->count = (u64)count; close(fd); // NOTE: need to clear whitespaces at startup since @@ -449,7 +449,7 @@ b8 lexer_new(const char* path, Lexer* l, Arena* a) b8 lexer_finished(Lexer* l) { - return l->cursor >= l->len; + return l->cursor >= l->count; } b8 lexer_next(Lexer* l, Token* token) @@ -459,7 +459,7 @@ b8 lexer_next(Lexer* l, Token* token) loc.line = l->current_line + 1; loc.offset = l->cursor - l->current_line_start; loc.text_start.data = l->data + l->current_line_start; - loc.text_start.len = l->len - l->current_line_start; + loc.text_start.count = l->count - l->current_line_start; if (lexer_finished(l)) { location_report(loc, LOG_ERROR, "Expected token, got EOF"); @@ -474,31 +474,31 @@ b8 lexer_next(Lexer* l, Token* token) SV text = {0}; text.data = l->data + l->cursor; - for (; l->cursor < l->len; l->cursor++) { + for (; l->cursor < l->count; l->cursor++) { char c = l->data[l->cursor]; if (c == ']') break; if (c == '\n') { - loc.offset += text.len; + loc.offset += text.count; location_report(loc, LOG_ERROR, "Reached end of line before matching ']'"); return false; } - text.len++; + text.count++; } - for (u64 i = 0; i < text.len; i++) { + for (u64 i = 0; i < text.count; i++) { char c = text.data[i]; if (!(isalnum(c) || c == ' ' || c == '.')) { loc.offset += i + 1; location_report(loc, LOG_ERROR, "Invalid section header \"%.*s\"", - (i32)text.len, text.data); + (i32)text.count, text.data); return false; } } - if (l->cursor >= l->len) { + if (l->cursor >= l->count) { location_report(loc, LOG_ERROR, "Expected ']', got EOF"); return false; } @@ -510,7 +510,7 @@ b8 lexer_next(Lexer* l, Token* token) } else if (c == '=') { token->kind = TOKEN_EQUALS; token->as_text.data = l->data + l->cursor; - token->as_text.len = 1; + token->as_text.count = 1; l->cursor++; } else if (c == '"') { token->kind = TOKEN_STR; @@ -526,7 +526,7 @@ b8 lexer_next(Lexer* l, Token* token) b8 loop = true; while (loop) { if (lexer_finished(l)) { - loc.offset += l->sb.len; + loc.offset += l->sb.count; location_report(loc, LOG_ERROR, "Expected '\"', got EOF"); return false; } @@ -534,23 +534,23 @@ b8 lexer_next(Lexer* l, Token* token) char c = l->data[l->cursor]; switch (c) { case '"': - char* str = arena_alloc(l->allocator, l->sb.len + 1); + char* str = arena_alloc(l->allocator, l->sb.count + 1); assert(str && "buy more RAM!"); - memcpy(str, l->sb.data, l->sb.len); - str[l->sb.len] = '\0'; + memcpy(str, l->sb.data, l->sb.count); + str[l->sb.count] = '\0'; token->as_str = str; loop = false; break; case '\n': - loc.offset += l->sb.len; + loc.offset += l->sb.count; location_report(loc, LOG_ERROR, "Expected '\"', got '\\n'"); return false; case '\\': l->cursor++; if (lexer_finished(l)) { - loc.offset += l->sb.len; + loc.offset += l->sb.count; location_report(loc, LOG_ERROR, "Expected escape code, got EOF"); return false; } @@ -593,22 +593,22 @@ b8 lexer_next(Lexer* l, Token* token) token->kind = TOKEN_KEY; token->as_text.data = l->data + l->cursor; - u64 len = 0; - for (; l->cursor < l->len; l->cursor++) { + u64 count = 0; + for (; l->cursor < l->count; l->cursor++) { char c = l->data[l->cursor]; if (!(isalnum(c) || c == '_')) break; - len++; + count++; } - token->as_text.len = len; + token->as_text.count = count; } else if (isdigit(c)) { - SV text; u64 len = 0; + SV text; u64 count = 0; text.data = l->data + l->cursor; - for (; l->cursor < l->len; l->cursor++) { + for (; l->cursor < l->count; l->cursor++) { if (!isalnum(l->data[l->cursor])) break; - len++; + count++; } - text.len = len; + text.count = count; u64 val; if (!parse_int(text, loc, &val)) return false; @@ -758,7 +758,7 @@ b8 parse_config(const char* path, Config* config) if (!key_found) { location_report(loc, LOG_WARNING, "Ignoring unknown field \"%.*s\"", - (i32)key.len, key.data); + (i32)key.count, key.data); } }
diff --git a/src/main.c b/src/main.c @@ -316,7 +316,7 @@ b8 pa_run_cmd(Cmd cmd) b8 pa_play_sample(PCM sample) { assert(sample.channels); - if (!sample.samples_len) return true; + if (!sample.samples_count) return true; pa_sample_spec ss; ss.format = PA_SAMPLE_S16LE; @@ -332,8 +332,8 @@ b8 pa_play_sample(PCM sample) return false; } - u64 bytes = sample.samples_len * sizeof(sample.samples[0]); - u64 written = 0; + u64 bytes = sample.samples_count * sizeof(sample.samples[0]); + u64 written = 0; const u8* ptr = (const u8 *)sample.samples; while (written < bytes) { u64 chunk = bytes - written; @@ -365,10 +365,10 @@ void ctx_drain_complete(pa_context* ctx, void* data) pa_context_disconnect(ctx); } -void mainloop_quit(i32 ret_value) +void mainloop_quit(i32 ret) { assert(mainloop_api); - mainloop_api->quit(mainloop_api, ret_value); + mainloop_api->quit(mainloop_api, ret); } void pa_complete_cmd(void)