summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--base.h2
-rw-r--r--buffer.c50
-rw-r--r--build.c6
-rw-r--r--command.c8
-rw-r--r--config.c28
-rw-r--r--find.c26
-rw-r--r--gl.c12
-rw-r--r--ide-autocomplete.c6
-rw-r--r--main.c12
-rw-r--r--menu.c30
-rw-r--r--node.c12
-rw-r--r--os-posix.c18
-rw-r--r--os-win.c16
-rw-r--r--os.h16
-rw-r--r--session.c6
-rw-r--r--syntax.c18
-rw-r--r--tags.c28
-rw-r--r--ted.c16
-rw-r--r--ted.h10
-rw-r--r--text.c32
-rw-r--r--text.h14
-rw-r--r--ui.c56
-rw-r--r--util.c14
-rw-r--r--util.h8
24 files changed, 222 insertions, 222 deletions
diff --git a/base.h b/base.h
index 1ef6333..92ea4ae 100644
--- a/base.h
+++ b/base.h
@@ -150,7 +150,7 @@ typedef unsigned long long ullong;
#endif
#if _WIN32
-static void print(char const *fmt, ...) {
+static void print(const char *fmt, ...) {
char buf[2048];
buf[2047] = '\0';
va_list args;
diff --git a/buffer.c b/buffer.c
index c7d5087..2b5145c 100644
--- a/buffer.c
+++ b/buffer.c
@@ -11,7 +11,7 @@ bool buffer_haserr(TextBuffer *buffer) {
}
// returns the buffer's last error
-char const *buffer_geterr(TextBuffer *buffer) {
+const char *buffer_geterr(TextBuffer *buffer) {
return buffer->error;
}
@@ -56,7 +56,7 @@ bool buffer_empty(TextBuffer *buffer) {
return buffer->nlines == 1 && buffer->lines[0].len == 0;
}
-char const *buffer_get_filename(TextBuffer *buffer) {
+const char *buffer_get_filename(TextBuffer *buffer) {
return buffer->filename;
}
@@ -104,7 +104,7 @@ static void *buffer_realloc(TextBuffer *buffer, void *p, size_t new_size) {
return ret;
}
-static char *buffer_strdup(TextBuffer *buffer, char const *src) {
+static char *buffer_strdup(TextBuffer *buffer, const char *src) {
char *dup = str_dup(src);
if (!dup) buffer_out_of_mem(buffer);
return dup;
@@ -238,8 +238,8 @@ Language buffer_language(TextBuffer *buffer) {
// (we're calling buffer_lsp on every edit and that calls this)
if (buffer->manual_language >= 1 && buffer->manual_language <= LANG_COUNT)
return (Language)(buffer->manual_language - 1);
- Settings const *settings = buffer->ted->default_settings; // important we don't use buffer_settings here since that would cause a loop!
- char const *filename = buffer->filename;
+ const Settings *settings = buffer->ted->default_settings; // important we don't use buffer_settings here since that would cause a loop!
+ const char *filename = buffer->filename;
if (!filename)
return LANG_NONE;
size_t filename_len = strlen(filename);
@@ -248,12 +248,12 @@ Language buffer_language(TextBuffer *buffer) {
Language match = LANG_NONE;
for (u16 l = 0; l < LANG_COUNT; ++l) {
- char const *extensions = settings->language_extensions[l];
+ const char *extensions = settings->language_extensions[l];
if (extensions) {
// extensions is a string with commas separating each extension.
size_t len = 0;
- for (char const *p = extensions; *p; p += len) {
+ for (const char *p = extensions; *p; p += len) {
if (*p == ',') ++p; // move past comma
len = strcspn(p, ",");
if (filename_len >= len && strncmp(&filename[filename_len - len], p, len) == 0) {
@@ -1006,7 +1006,7 @@ static bool buffer_clip_rect(TextBuffer *buffer, Rect *r) {
void buffer_scroll_to_pos(TextBuffer *buffer, BufferPos pos) {
- Settings const *settings = buffer_settings(buffer);
+ const Settings *settings = buffer_settings(buffer);
double line = pos.line;
double col = buffer_index_to_column(buffer, pos.line, pos.index);
double display_lines = buffer_display_lines(buffer);
@@ -1967,7 +1967,7 @@ void buffer_insert_char_at_cursor(TextBuffer *buffer, char32_t c) {
buffer_insert_text_at_cursor(buffer, s);
}
-void buffer_insert_utf8_at_cursor(TextBuffer *buffer, char const *utf8) {
+void buffer_insert_utf8_at_cursor(TextBuffer *buffer, const char *utf8) {
String32 s32 = str32_from_utf8(utf8);
if (s32.str) {
buffer_insert_text_at_cursor(buffer, s32);
@@ -1976,7 +1976,7 @@ void buffer_insert_utf8_at_cursor(TextBuffer *buffer, char const *utf8) {
}
void buffer_insert_tab_at_cursor(TextBuffer *buffer) {
- Settings const *settings = buffer_settings(buffer);
+ const Settings *settings = buffer_settings(buffer);
if (settings->indent_with_spaces) {
for (int i = 0; i < settings->tab_width; ++i)
@@ -1992,7 +1992,7 @@ void buffer_newline(TextBuffer *buffer) {
buffer->line_buffer_submitted = true;
return;
}
- Settings const *settings = buffer_settings(buffer);
+ const Settings *settings = buffer_settings(buffer);
BufferPos cursor_pos = buffer->cursor_pos;
String32 line = buffer_get_line(buffer, cursor_pos.line);
u32 whitespace_len;
@@ -2211,7 +2211,7 @@ void buffer_paste(TextBuffer *buffer) {
}
// if an error occurs, buffer is left untouched (except for the error field) and the function returns false.
-Status buffer_load_file(TextBuffer *buffer, char const *filename) {
+Status buffer_load_file(TextBuffer *buffer, const char *filename) {
FILE *fp = fopen(filename, "rb");
bool success = true;
Line *lines = NULL;
@@ -2351,7 +2351,7 @@ bool buffer_externally_changed(TextBuffer *buffer) {
return buffer->last_write_time != timespec_to_seconds(time_last_modified(buffer->filename));
}
-void buffer_new_file(TextBuffer *buffer, char const *filename) {
+void buffer_new_file(TextBuffer *buffer, const char *filename) {
buffer_clear(buffer);
if (filename)
@@ -2364,7 +2364,7 @@ void buffer_new_file(TextBuffer *buffer, char const *filename) {
// Save the buffer to its current filename. This will rewrite the entire file, regardless of
// whether there are any unsaved changes.
bool buffer_save(TextBuffer *buffer) {
- Settings const *settings = buffer_settings(buffer);
+ const Settings *settings = buffer_settings(buffer);
if (!buffer->is_line_buffer && buffer->filename) {
if (buffer->view_only) {
@@ -2412,7 +2412,7 @@ bool buffer_save(TextBuffer *buffer) {
bool success = !buffer_haserr(buffer);
if (success) {
buffer->undo_history_write_pos = arr_len(buffer->undo_history);
- char const *name = buffer->filename ? path_filename(buffer->filename) : TED_UNTITLED;
+ const char *name = buffer->filename ? path_filename(buffer->filename) : TED_UNTITLED;
if (streq(name, "ted.cfg") && buffer_settings(buffer)->auto_reload_config) {
ted_load_configs(buffer->ted, true);
}
@@ -2429,7 +2429,7 @@ bool buffer_save(TextBuffer *buffer) {
}
// save, but with a different file name
-bool buffer_save_as(TextBuffer *buffer, char const *new_filename) {
+bool buffer_save_as(TextBuffer *buffer, const char *new_filename) {
LSP *lsp = buffer_lsp(buffer);
char *prev_filename = buffer->filename;
buffer->filename = buffer_strdup(buffer, new_filename);
@@ -2542,10 +2542,10 @@ void buffer_render(TextBuffer *buffer, Rect r) {
char_height = text_font_char_height(font);
Ted *ted = buffer->ted;
- Settings const *settings = buffer_settings(buffer);
- u32 const *colors = settings->colors;
- float const padding = settings->padding;
- float const border_thickness = settings->border_thickness;
+ const Settings *settings = buffer_settings(buffer);
+ const u32 *colors = settings->colors;
+ const float padding = settings->padding;
+ const float border_thickness = settings->border_thickness;
u32 start_line = buffer_first_rendered_line(buffer); // line to start rendering from
@@ -2838,7 +2838,7 @@ void buffer_render(TextBuffer *buffer, Rect r) {
void buffer_indent_lines(TextBuffer *buffer, u32 first_line, u32 last_line) {
assert(first_line <= last_line);
- Settings const *settings = buffer_settings(buffer);
+ const Settings *settings = buffer_settings(buffer);
buffer_start_edit_chain(buffer);
for (u32 l = first_line; l <= last_line; ++l) {
@@ -2859,8 +2859,8 @@ void buffer_dedent_lines(TextBuffer *buffer, u32 first_line, u32 last_line) {
buffer_validate_line(buffer, &last_line);
buffer_start_edit_chain(buffer);
- Settings const *settings = buffer_settings(buffer);
- u8 const tab_width = settings->tab_width;
+ const Settings *settings = buffer_settings(buffer);
+ const u8 tab_width = settings->tab_width;
for (u32 line_idx = first_line; line_idx <= last_line; ++line_idx) {
Line *line = &buffer->lines[line_idx];
@@ -2939,7 +2939,7 @@ void buffer_comment_lines(TextBuffer *buffer, u32 first_line, u32 last_line) {
buffer_end_edit_chain(buffer);
}
-static bool buffer_line_starts_with_ascii(TextBuffer *buffer, u32 line_idx, char const *prefix) {
+static bool buffer_line_starts_with_ascii(TextBuffer *buffer, u32 line_idx, const char *prefix) {
buffer_validate_line(buffer, &line_idx);
Line *line = &buffer->lines[line_idx];
size_t prefix_len = strlen(prefix);
@@ -2952,7 +2952,7 @@ static bool buffer_line_starts_with_ascii(TextBuffer *buffer, u32 line_idx, char
}
return true;
}
-static bool buffer_line_ends_with_ascii(TextBuffer *buffer, u32 line_idx, char const *suffix) {
+static bool buffer_line_ends_with_ascii(TextBuffer *buffer, u32 line_idx, const char *suffix) {
buffer_validate_line(buffer, &line_idx);
Line *line = &buffer->lines[line_idx];
size_t suffix_len = strlen(suffix), line_len = line->len;
diff --git a/build.c b/build.c
index 04a9488..5865daf 100644
--- a/build.c
+++ b/build.c
@@ -24,7 +24,7 @@ static void build_queue_start(Ted *ted) {
}
// add a command to the build queue
-static void build_queue_command(Ted *ted, char const *command) {
+static void build_queue_command(Ted *ted, const char *command) {
char *copy = str_dup(command);
if (copy)
arr_add(ted->build_queue, copy);
@@ -75,7 +75,7 @@ static void build_queue_finish(Ted *ted) {
}
// make sure you set ted->build_dir before running this!
-static void build_start_with_command(Ted *ted, char const *command) {
+static void build_start_with_command(Ted *ted, const char *command) {
build_queue_start(ted);
build_queue_command(ted, command);
build_queue_finish(ted);
@@ -159,7 +159,7 @@ static int parse_nonnegative_integer(char32_t **str, char32_t *end) {
// could this character (reasonably) appear in a source file path?
static bool is_source_path(char32_t c) {
- char const *allowed_ascii_symbols_in_path = "./\\-_:";
+ const char *allowed_ascii_symbols_in_path = "./\\-_:";
return c > CHAR_MAX || isalnum((char)c)
|| strchr(allowed_ascii_symbols_in_path, (char)c);
}
diff --git a/command.c b/command.c
index 7180921..4900c07 100644
--- a/command.c
+++ b/command.c
@@ -1,5 +1,5 @@
typedef struct {
- char const *name;
+ const char *name;
Command cmd;
} CommandName;
static CommandName const command_names[] = {
@@ -87,7 +87,7 @@ static CommandName const command_names[] = {
static_assert_if_possible(arr_count(command_names) == CMD_COUNT)
-Command command_from_str(char const *str) {
+Command command_from_str(const char *str) {
// @TODO(optimize): sort command_names, do a binary search
for (int i = 0; i < CMD_COUNT; ++i) {
if (streq(command_names[i].name, str))
@@ -106,7 +106,7 @@ const char *command_to_str(Command c) {
}
// get the string corresponding to this argument; returns NULL if it's not a string argument
-char const *arg_get_string(Ted *ted, i64 argument) {
+const char *arg_get_string(Ted *ted, i64 argument) {
if (argument < 0) return NULL;
if (argument & ARG_STRING) {
argument -= ARG_STRING;
@@ -524,7 +524,7 @@ void command_execute(Ted *ted, Command c, i64 argument) {
build_prev_error(ted);
break;
case CMD_SHELL: {
- char const *str = arg_get_string(ted, argument);
+ const char *str = arg_get_string(ted, argument);
if (str) {
strbuf_cpy(ted->build_dir, ted->cwd);
build_start_with_command(ted, str);
diff --git a/config.c b/config.c
index 9081a70..7f43b24 100644
--- a/config.c
+++ b/config.c
@@ -9,36 +9,36 @@
// all the "control" pointers here are relative to a NULL Settings object.
typedef struct {
- char const *name;
+ const char *name;
const bool *control;
bool per_language; // allow per-language control
} SettingBool;
typedef struct {
- char const *name;
+ const char *name;
const u8 *control;
u8 min, max;
bool per_language;
} SettingU8;
typedef struct {
- char const *name;
+ const char *name;
const float *control;
float min, max;
bool per_language;
} SettingFloat;
typedef struct {
- char const *name;
+ const char *name;
const u16 *control;
u16 min, max;
bool per_language;
} SettingU16;
typedef struct {
- char const *name;
+ const char *name;
const u32 *control;
u32 min, max;
bool per_language;
} SettingU32;
typedef struct {
- char const *name;
+ const char *name;
const char *control;
size_t buf_size;
bool per_language;
@@ -67,7 +67,7 @@ typedef struct {
} SettingAny;
// core settings
-static Settings const settings_zero = {0};
+static const Settings settings_zero = {0};
static SettingBool const settings_bool[] = {
{"auto-indent", &settings_zero.auto_indent, true},
{"auto-add-newline", &settings_zero.auto_add_newline, true},
@@ -157,7 +157,7 @@ static void setting_string_set(Settings *settings, const SettingString *set, con
typedef struct {
Ted *ted;
- char const *filename;
+ const char *filename;
u32 line_number; // currently processing this line number
bool error;
} ConfigReader;
@@ -209,7 +209,7 @@ static void config_part_free(ConfigPart *part) {
}
// Returns the key combination described by str.
-static u32 config_parse_key_combo(ConfigReader *cfg, char const *str) {
+static u32 config_parse_key_combo(ConfigReader *cfg, const char *str) {
u32 modifier = 0;
// read modifier
while (true) {
@@ -241,8 +241,8 @@ static u32 config_parse_key_combo(ConfigReader *cfg, char const *str) {
SDL_Scancode scancode = SDL_GetScancodeFromName(str);
if (scancode == SDL_SCANCODE_UNKNOWN) {
typedef struct {
- char const *keyname1;
- char const *keyname2; // alternate key name
+ const char *keyname1;
+ const char *keyname2; // alternate key name
SDL_Scancode scancode;
bool shift;
} KeyName;
@@ -440,7 +440,7 @@ static void config_init_settings(void) {
settings_initialized = true;
}
-void config_read(Ted *ted, ConfigPart **parts, char const *filename) {
+void config_read(Ted *ted, ConfigPart **parts, const char *filename) {
FILE *fp = fopen(filename, "rb");
if (!fp) {
ted_seterr(ted, "Couldn't open config file %s: %s.", filename, strerror(errno));
@@ -795,7 +795,7 @@ static void config_parse_line(ConfigReader *cfg, Settings *settings, const Confi
} else {
char *dst = new_str;
// get rid of whitespace in extension list
- for (char const *src = value; *src; ++src)
+ for (const char *src = value; *src; ++src)
if (!isspace(*src))
*dst++ = *src;
*dst = 0;
@@ -806,7 +806,7 @@ static void config_parse_line(ConfigReader *cfg, Settings *settings, const Confi
}
} break;
case SECTION_CORE: {
- char const *endptr;
+ const char *endptr;
long long const integer = strtoll(value, (char **)&endptr, 10);
bool const is_integer = *endptr == '\0';
double const floating = strtod(value, (char **)&endptr);
diff --git a/find.c b/find.c
index 13d1a24..fc53f95 100644
--- a/find.c
+++ b/find.c
@@ -70,10 +70,10 @@ static void find_free_pattern(Ted *ted) {
static float find_menu_height(Ted *ted) {
Font *font = ted->font;
float char_height = text_font_char_height(font);
- Settings const *settings = ted_active_settings(ted);
- float const padding = settings->padding;
- float const border_thickness = settings->border_thickness;
- float const line_buffer_height = ted_line_buffer_height(ted);
+ const Settings *settings = ted_active_settings(ted);
+ const float padding = settings->padding;
+ const float border_thickness = settings->border_thickness;
+ const float line_buffer_height = ted_line_buffer_height(ted);
return 3 * char_height + 4 * border_thickness + (padding + line_buffer_height) * ted->replace + 6 * padding;
}
@@ -313,14 +313,14 @@ static void find_replace_all(Ted *ted) {
static void find_menu_frame(Ted *ted, Rect menu_bounds) {
Font *font = ted->font, *font_bold = ted->font_bold;
- float const char_height = text_font_char_height(font);
+ const float char_height = text_font_char_height(font);
- Settings const *settings = ted_active_settings(ted);
- float const padding = settings->padding;
- float const border_thickness = settings->border_thickness;
- u32 const *colors = settings->colors;
+ const Settings *settings = ted_active_settings(ted);
+ const float padding = settings->padding;
+ const float border_thickness = settings->border_thickness;
+ const u32 *colors = settings->colors;
bool const replace = ted->replace;
- float const line_buffer_height = ted_line_buffer_height(ted);
+ const float line_buffer_height = ted_line_buffer_height(ted);
TextBuffer *buffer = find_search_buffer(ted), *find_buffer = &ted->find_buffer, *replace_buffer = &ted->replace_buffer;
if (!buffer) return;
@@ -341,8 +341,8 @@ static void find_menu_frame(Ted *ted, Rect menu_bounds) {
x2 -= padding;
y2 -= padding;
- char const *prev_text = "Previous", *next_text = "Next";
- char const *replace_text = "Replace", *replace_find_text = "Replace+find", *replace_all_text = "Replace all";
+ const char *prev_text = "Previous", *next_text = "Next";
+ const char *replace_text = "Replace", *replace_find_text = "Replace+find", *replace_all_text = "Replace all";
v2 prev_size = button_get_size(ted, prev_text);
v2 next_size = button_get_size(ted, next_text);
v2 replace_size = button_get_size(ted, replace_text);
@@ -390,7 +390,7 @@ static void find_menu_frame(Ted *ted, Rect menu_bounds) {
}
}
- char const *find_text = "Find...", *replace_with_text = "Replace with";
+ const char *find_text = "Find...", *replace_with_text = "Replace with";
float text_width = 0;
text_get_size(font_bold, replace ? replace_with_text : find_text, &text_width, NULL);
diff --git a/gl.c b/gl.c
index 2465d58..6c66709 100644
--- a/gl.c
+++ b/gl.c
@@ -143,7 +143,7 @@ static int glsl_version(void) {
}
// compile a GLSL shader
-GLuint gl_compile_shader(char error_buf[256], char const *code, GLenum shader_type) {
+GLuint gl_compile_shader(char error_buf[256], const char *code, GLenum shader_type) {
GLuint shader = glCreateShader(shader_type);
char header[128];
int glsl = glsl_version();
@@ -201,7 +201,7 @@ GLuint gl_link_program(char error_buf[256], GLuint *shaders, size_t count) {
return program;
}
-GLuint gl_compile_and_link_shaders(char error_buf[256], char const *vshader_code, char const *fshader_code) {
+GLuint gl_compile_and_link_shaders(char error_buf[256], const char *vshader_code, const char *fshader_code) {
GLuint shaders[2];
shaders[0] = gl_compile_shader(error_buf, vshader_code, GL_VERTEX_SHADER);
shaders[1] = gl_compile_shader(error_buf, fshader_code, GL_FRAGMENT_SHADER);
@@ -214,7 +214,7 @@ GLuint gl_compile_and_link_shaders(char error_buf[256], char const *vshader_code
return program;
}
-GLuint gl_attrib_loc(GLuint program, char const *attrib) {
+GLuint gl_attrib_loc(GLuint program, const char *attrib) {
GLint loc = glGetAttribLocation(program, attrib);
if (loc == -1) {
debug_print("Couldn't find vertex attribute %s.\n", attrib);
@@ -223,7 +223,7 @@ GLuint gl_attrib_loc(GLuint program, char const *attrib) {
return (GLuint)loc;
}
-GLint gl_uniform_loc(GLuint program, char const *uniform) {
+GLint gl_uniform_loc(GLuint program, const char *uniform) {
GLint loc = glGetUniformLocation(program, uniform);
if (loc == -1) {
debug_print("Couldn't find uniform: %s.\n", uniform);
@@ -248,7 +248,7 @@ static GLint gl_geometry_u_window_size;
static GLuint gl_geometry_vbo, gl_geometry_vao;
void gl_geometry_init(void) {
- char const *vshader_code = "attribute vec2 v_pos;\n\
+ const char *vshader_code = "attribute vec2 v_pos;\n\
attribute vec4 v_color;\n\
uniform vec2 u_window_size;\n\
OUT vec4 color;\n\
@@ -258,7 +258,7 @@ void gl_geometry_init(void) {
color = v_color;\n\
}\n\
";
- char const *fshader_code = "IN vec4 color;\n\
+ const char *fshader_code = "IN vec4 color;\n\
void main() {\n\
gl_FragColor = color;\n\
}\n\
diff --git a/ide-autocomplete.c b/ide-autocomplete.c
index 1b38816..bec2112 100644
--- a/ide-autocomplete.c
+++ b/ide-autocomplete.c
@@ -347,9 +347,9 @@ static void autocomplete_frame(Ted *ted) {
TextBuffer *buffer = ted->active_buffer;
Font *font = ted->font;
float char_height = text_font_char_height(font);
- Settings const *settings = buffer_settings(buffer);
- u32 const *colors = settings->colors;
- float const padding = settings->padding;
+ const Settings *settings = buffer_settings(buffer);
+ const u32 *colors = settings->colors;
+ const float padding = settings->padding;
autocomplete_find_completions(ted, TRIGGER_INCOMPLETE);
diff --git a/main.c b/main.c
index bbe7aea..dc23bec 100644
--- a/main.c
+++ b/main.c
@@ -129,7 +129,7 @@ no_warn_end
static Rect error_box_rect(Ted *ted) {
Font *font = ted->font;
- Settings const *settings = ted_active_settings(ted);
+ const Settings *settings = ted_active_settings(ted);
float padding = settings->padding;
float window_width = ted->window_width, window_height = ted->window_height;
float char_height = text_font_char_height(font);
@@ -191,7 +191,7 @@ static void error_signal_handler(int signum, siginfo_t *info, void *context) {
}
}
#elif _WIN32
-static char const *windows_exception_to_str(DWORD exception_code) {
+static const char *windows_exception_to_str(DWORD exception_code) {
switch (exception_code) {
case EXCEPTION_ACCESS_VIOLATION: return "Access violation";
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: return "Array out of bounds";
@@ -322,7 +322,7 @@ int main(int argc, char **argv) {
#endif
// read command-line arguments
- char const *starting_filename = NULL;
+ const char *starting_filename = NULL;
switch (argc) {
case 0: case 1: break;
case 2:
@@ -421,7 +421,7 @@ int main(int argc, char **argv) {
// never search cwd; we'll search the executable directory anyways
#else
char executable_path[TED_PATH_MAX] = {0};
- char const *cwd = ted->cwd;
+ const char *cwd = ted->cwd;
ssize_t len = readlink("/proc/self/exe", executable_path, sizeof executable_path - 1);
if (len == -1) {
// some posix systems don't have /proc/self/exe. oh well.
@@ -792,7 +792,7 @@ int main(int argc, char **argv) {
{ // ted->cwd should be the directory containing the last active buffer
TextBuffer *buffer = ted->active_buffer;
if (buffer) {
- char const *buffer_path = buffer_get_filename(buffer);
+ const char *buffer_path = buffer_get_filename(buffer);
if (buffer_path && !buffer_is_untitled(buffer)) {
assert(*buffer_path);
char *last_sep = strrchr(buffer_path, PATH_SEPARATOR);
@@ -942,7 +942,7 @@ int main(int argc, char **argv) {
strcpy(ted->window_title, "ted");
{
- float const padding = ted_active_settings(ted)->padding;
+ const float padding = ted_active_settings(ted)->padding;
float x1 = padding, y = window_height-padding, x2 = window_width-padding;
Node *node = &ted->nodes[0];
if (ted->find) {
diff --git a/menu.c b/menu.c
index 2d55e0b..bdcaa23 100644
--- a/menu.c
+++ b/menu.c
@@ -107,7 +107,7 @@ static void menu_escape(Ted *ted) {
}
static float menu_get_width(Ted *ted) {
- Settings const *settings = ted_active_settings(ted);
+ const Settings *settings = ted_active_settings(ted);
return minf(settings->max_menu_width, ted->window_width - 2.0f * settings->padding);
}
@@ -125,8 +125,8 @@ static Rect menu_rect(Ted *ted) {
static void menu_update(Ted *ted) {
Menu menu = ted->menu;
- Settings const *settings = ted_active_settings(ted);
- u32 const *colors = settings->colors;
+ const Settings *settings = ted_active_settings(ted);
+ const u32 *colors = settings->colors;
TextBuffer *line_buffer = &ted->line_buffer;
assert(menu);
@@ -270,7 +270,7 @@ static void menu_update(Ted *ted) {
if (entries) {
SelectorEntry *entry = entries;
for (Command c = 0; c < CMD_COUNT; ++c) {
- char const *name = command_to_str(c);
+ const char *name = command_to_str(c);
if (c != CMD_UNKNOWN && *name && strstr_case_insensitive(name, search_term)) {
entry->name = name;
entry->color = colors[COLOR_TEXT];
@@ -317,21 +317,21 @@ static void menu_update(Ted *ted) {
static void menu_render(Ted *ted) {
Menu menu = ted->menu;
assert(menu);
- Settings const *settings = ted_active_settings(ted);
- u32 const *colors = settings->colors;
- float const window_width = ted->window_width, window_height = ted->window_height;
+ const Settings *settings = ted_active_settings(ted);
+ const u32 *colors = settings->colors;
+ const float window_width = ted->window_width, window_height = ted->window_height;
Font *font_bold = ted->font_bold, *font = ted->font;
- float const char_height = text_font_char_height(font);
- float const char_height_bold = text_font_char_height(font_bold);
- float const line_buffer_height = ted_line_buffer_height(ted);
+ const float char_height = text_font_char_height(font);
+ const float char_height_bold = text_font_char_height(font_bold);
+ const float line_buffer_height = ted_line_buffer_height(ted);
// render backdrop
gl_geometry_rect(rect(V2(0, 0), V2(window_width, window_height)), colors[COLOR_MENU_BACKDROP]);
gl_geometry_draw();
if (*ted->warn_overwrite) {
- char const *path = ted->warn_overwrite;
- char const *filename = path_filename(path);
+ const char *path = ted->warn_overwrite;
+ const char *filename = path_filename(path);
char title[64] = {0}, body[1024] = {0};
strbuf_printf(title, "Overwrite %s?", filename);
strbuf_printf(body, "Are you sure you want to overwrite %s?", path);
@@ -396,7 +396,7 @@ static void menu_render(Ted *ted) {
Rect r = rect(V2(padding, window_height - menu_height - padding), V2(window_width - 2 * padding, menu_height));
gl_geometry_rect(r, colors[COLOR_MENU_BG]);
gl_geometry_rect_border(r, settings->border_thickness, colors[COLOR_BORDER]);
- char const *text = "Go to line...";
+ const char *text = "Go to line...";
v2 text_size = text_get_size_v2(font_bold, text);
rect_coords(r, &x1, &y1, &x2, &y2);
x1 += padding;
@@ -414,7 +414,7 @@ static void menu_render(Ted *ted) {
} break;
case MENU_COMMAND_SELECTOR: {
// argument field
- char const *text = "Argument";
+ const char *text = "Argument";
text_utf8(font_bold, text, x1, y1, colors[COLOR_TEXT]);
float x = x1 + text_get_size_v2(font_bold, text).x + padding;
buffer_render(&ted->argument_buffer, rect4(x, y1, x2, y1 + line_buffer_height));
@@ -440,7 +440,7 @@ static void menu_render(Ted *ted) {
x2 -= padding;
y2 -= padding;
- char const *text = "Run";
+ const char *text = "Run";
text_utf8(font_bold, text, x1, y1, colors[COLOR_TEXT]);
x1 += text_get_size_v2(font_bold, text).x + padding;
text_render(font_bold);
diff --git a/node.c b/node.c
index 47cfb19..413600f 100644
--- a/node.c
+++ b/node.c
@@ -187,13 +187,13 @@ static bool node_tab_close(Ted *ted, Node *node, u16 index) {
}
static void node_frame(Ted *ted, Node *node, Rect r) {
- Settings const *settings = ted_active_settings(ted);
+ const Settings *settings = ted_active_settings(ted);
if (node->tabs) {
bool is_active = node == ted->active_node;
- u32 const *colors = settings->colors;
+ const u32 *colors = settings->colors;
Font *font = ted->font;
- float const border_thickness = settings->border_thickness;
- float const char_height = text_font_char_height(font);
+ const float border_thickness = settings->border_thickness;
+ const float char_height = text_font_char_height(font);
float tab_bar_height = char_height + 2 * border_thickness;
Rect tab_bar_rect = r;
@@ -281,8 +281,8 @@ static void node_frame(Ted *ted, Node *node, Rect r) {
for (u16 i = 0; i < ntabs; ++i) {
TextBuffer *buffer = &ted->buffers[node->tabs[i]];
char tab_title[256];
- char const *path = buffer_get_filename(buffer);
- char const *filename = path ? path_filename(path) : TED_UNTITLED;
+ const char *path = buffer_get_filename(buffer);
+ const char *filename = path ? path_filename(path) : TED_UNTITLED;
Rect tab_rect = rect(V2(r.pos.x + tab_width * i, r.pos.y), V2(tab_width, tab_bar_height));
if (i > 0) {
diff --git a/os-posix.c b/os-posix.c
index 193897a..4e9e402 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -17,25 +17,25 @@ static FsType statbuf_path_type(const struct stat *statbuf) {
return FS_OTHER;
}
-FsType fs_path_type(char const *path) {
+FsType fs_path_type(const char *path) {
struct stat statbuf = {0};
if (stat(path, &statbuf) != 0)
return FS_NON_EXISTENT;
return statbuf_path_type(&statbuf);
}
-FsPermission fs_path_permission(char const *path) {
+FsPermission fs_path_permission(const char *path) {
FsPermission perm = 0;
if (access(path, R_OK) == 0) perm |= FS_PERMISSION_READ;
if (access(path, W_OK) == 0) perm |= FS_PERMISSION_WRITE;
return perm;
}
-bool fs_file_exists(char const *path) {
+bool fs_file_exists(const char *path) {
return fs_path_type(path) == FS_FILE;
}
-FsDirectoryEntry **fs_list_directory(char const *dirname) {
+FsDirectoryEntry **fs_list_directory(const char *dirname) {
FsDirectoryEntry **entries = NULL;
DIR *dir = opendir(dirname);
if (dir) {
@@ -49,7 +49,7 @@ FsDirectoryEntry **fs_list_directory(char const *dirname) {
if (entries) {
size_t idx = 0;
while ((ent = readdir(dir))) {
- char const *filename = ent->d_name;
+ const char *filename = ent->d_name;
size_t len = strlen(filename);
FsDirectoryEntry *entry = (FsDirectoryEntry *)calloc(1, sizeof *entry + len + 1);
if (!entry) break;
@@ -80,7 +80,7 @@ FsDirectoryEntry **fs_list_directory(char const *dirname) {
return entries;
}
-int fs_mkdir(char const *path) {
+int fs_mkdir(const char *path) {
if (mkdir(path, 0755) == 0) {
// directory created successfully
return 1;
@@ -113,7 +113,7 @@ int fs_get_cwd(char *buf, size_t buflen) {
}
}
-struct timespec time_last_modified(char const *filename) {
+struct timespec time_last_modified(const char *filename) {
struct stat statbuf = {0};
stat(filename, &statbuf);
return statbuf.st_mtim;
@@ -237,13 +237,13 @@ bool process_run_ex(Process *proc, const char *command, const ProcessSettings *s
return success;
}
-bool process_run(Process *proc, char const *command) {
+bool process_run(Process *proc, const char *command) {
const ProcessSettings settings = {0};
return process_run_ex(proc, command, &settings);
}
-char const *process_geterr(Process *p) {
+const char *process_geterr(Process *p) {
return *p->error ? p->error : NULL;
}
diff --git a/os-win.c b/os-win.c
index ff29359..d22ae40 100644
--- a/os-win.c
+++ b/os-win.c
@@ -13,7 +13,7 @@ static FsType windows_file_attributes_to_type(DWORD attrs) {
return FS_FILE;
}
-FsType fs_path_type(char const *path) {
+FsType fs_path_type(const char *path) {
WCHAR wide_path[4100];
if (MultiByteToWideChar(CP_UTF8, 0, path, -1, wide_path, sizeof wide_path) == 0) {
return FS_NON_EXISTENT;
@@ -21,18 +21,18 @@ FsType fs_path_type(char const *path) {
return windows_file_attributes_to_type(GetFileAttributesW(wide_path));
}
-FsPermission fs_path_permission(char const *path) {
+FsPermission fs_path_permission(const char *path) {
FsPermission permission = 0;
if (_access(path, 04) == 0) permission |= FS_PERMISSION_READ;
if (_access(path, 02) == 0) permission |= FS_PERMISSION_WRITE;
return permission;
}
-bool fs_file_exists(char const *path) {
+bool fs_file_exists(const char *path) {
return fs_path_type(path) == FS_FILE;
}
-FsDirectoryEntry **fs_list_directory(char const *dirname) {
+FsDirectoryEntry **fs_list_directory(const char *dirname) {
char file_pattern[1000] = {0};
FsDirectoryEntry **files = NULL;
WIN32_FIND_DATAW find_data;
@@ -80,7 +80,7 @@ FsDirectoryEntry **fs_list_directory(char const *dirname) {
return files;
}
-int fs_mkdir(char const *path) {
+int fs_mkdir(const char *path) {
WCHAR wide_path[4100];
if (MultiByteToWideChar(CP_UTF8, 0, path, -1, wide_path, sizeof wide_path) == 0)
return -1;
@@ -106,7 +106,7 @@ int fs_get_cwd(char *buf, size_t buflen) {
return 1;
}
-struct timespec time_last_modified(char const *filename) {
+struct timespec time_last_modified(const char *filename) {
// windows' _stat does not have st_mtim
struct _stat statbuf = {0};
struct timespec ts = {0};
@@ -146,7 +146,7 @@ static void get_last_error_str(char *out, size_t out_sz) {
if (cr) *cr = '\0'; // get rid of carriage return+newline at end of error
}
-bool process_run(Process *process, char const *command) {
+bool process_run(Process *process, const char *command) {
// thanks to https://stackoverflow.com/a/35658917 for the pipe code
// thanks to https://devblogs.microsoft.com/oldnewthing/20131209-00/?p=2433 for the job code
@@ -212,7 +212,7 @@ bool process_run(Process *process, char const *command) {
return success;
}
-char const *process_geterr(Process *p) {
+const char *process_geterr(Process *p) {
return *p->error ? p->error : NULL;
}
diff --git a/os.h b/os.h
index 4e49057..6b1e3a5 100644
--- a/os.h
+++ b/os.h
@@ -21,27 +21,27 @@ typedef struct {
} FsDirectoryEntry;
// returns what kind of thing this is.
-FsType fs_path_type(char const *path);
-FsPermission fs_path_permission(char const *path);
+FsType fs_path_type(const char *path);
+FsPermission fs_path_permission(const char *path);
// Does this file exist? Returns false for directories.
-bool fs_file_exists(char const *path);
+bool fs_file_exists(const char *path);
// Returns a NULL-terminated array of the files/directories in this directory, or NULL if the directory does not exist/out of memory.
// When you're done with the entries, call fs_dir_entries_free (or call free on each entry, then on the whole array).
// NOTE: The files/directories aren't returned in any particular order!
-FsDirectoryEntry **fs_list_directory(char const *dirname);
+FsDirectoryEntry **fs_list_directory(const char *dirname);
// Create the directory specified by `path`
// Returns:
// 1 if the directory was created successfully
// 0 if the directory already exists
// -1 if the path already exists, but it's not a directory, or if there's another error (e.g. don't have permission to create directory).
-int fs_mkdir(char const *path);
+int fs_mkdir(const char *path);
// Puts the current working directory into buf, including a null-terminator, writing at most buflen bytes.
// Returns:
// 1 if the working directory was inserted into buf successfully
// 0 if buf is too short to hold the cwd
// -1 if we can't get the cwd for whatever reason.
int fs_get_cwd(char *buf, size_t buflen);
-struct timespec time_last_modified(char const *filename);
+struct timespec time_last_modified(const char *filename);
struct timespec time_get(void);
// sleep for a certain number of nanoseconds
void time_sleep_ns(u64 ns);
@@ -93,9 +93,9 @@ int process_get_id(void);
// returns false on failure
bool process_run_ex(Process *proc, const char *command, const ProcessSettings *props);
// like process_run_ex, but with the default settings
-bool process_run(Process *process, char const *command);
+bool process_run(Process *process, const char *command);
// returns the error last error produced, or NULL if there was no error.
-char const *process_geterr(Process *process);
+const char *process_geterr(Process *process);
// write to stdin
// returns:
// -2 on error
diff --git a/session.c b/session.c
index c15985f..4dfbefa 100644
--- a/session.c
+++ b/session.c
@@ -117,7 +117,7 @@ static bool read_bool(FILE *fp) {
return (bool)getc(fp);
}
-static void write_cstr(FILE *fp, char const *cstr) {
+static void write_cstr(FILE *fp, const char *cstr) {
fwrite(cstr, 1, strlen(cstr) + 1, fp);
}
@@ -321,7 +321,7 @@ static void session_read_file(Ted *ted, FILE *fp) {
}
static void session_write(Ted *ted) {
- Settings const *settings = ted_active_settings(ted);
+ const Settings *settings = ted_active_settings(ted);
if (!settings->restore_session)
return;
// first we write to a prefixed file so in case something goes wrong we still have the old session.
@@ -342,7 +342,7 @@ static void session_write(Ted *ted) {
}
static void session_read(Ted *ted) {
- Settings const *settings = ted_active_settings(ted);
+ const Settings *settings = ted_active_settings(ted);
if (settings->restore_session) {
char filename[TED_PATH_MAX];
strbuf_printf(filename, "%s/" SESSION_FILENAME, ted->local_data_dir);
diff --git a/syntax.c b/syntax.c
index cddebc2..5f957ea 100644
--- a/syntax.c
+++ b/syntax.c
@@ -5,7 +5,7 @@
typedef struct {
Language lang;
- char const *name;
+ const char *name;
} LanguageName;
static const LanguageName language_names[] = {
@@ -32,7 +32,7 @@ static_assert_if_possible(arr_count(language_names) == LANG_COUNT)
// returns the language this string is referring to, or LANG_NONE if it's invalid.
-Language language_from_str(char const *str) {
+Language language_from_str(const char *str) {
for (int i = 0; i < LANG_COUNT; ++i) {
if (strcmp_case_insensitive(language_names[i].name, str) == 0)
return language_names[i].lang;
@@ -50,7 +50,7 @@ const char *language_to_str(Language language) {
}
// start of single line comment for language l -- used for comment/uncomment selection
-char const *language_comment_start(Language l) {
+const char *language_comment_start(Language l) {
switch (l) {
case LANG_C:
case LANG_RUST:
@@ -80,7 +80,7 @@ char const *language_comment_start(Language l) {
}
// end of single line comment for language l
-char const *language_comment_end(Language l) {
+const char *language_comment_end(Language l) {
switch (l) {
case LANG_HTML:
return " -->";
@@ -104,12 +104,12 @@ ColorSetting syntax_char_type_to_color(SyntaxCharType t) {
return COLOR_TEXT;
}
-static inline bool syntax_keyword_matches(char32_t const *text, size_t len, char const *keyword) {
+static inline bool syntax_keyword_matches(char32_t const *text, size_t len, const char *keyword) {
if (len == strlen(keyword)) {
bool matches = true;
char32_t const *p = text;
// check if `p` starts with `keyword`
- for (char const *q = keyword; *q; ++p, ++q) {
+ for (const char *q = keyword; *q; ++p, ++q) {
if (*p != (char32_t)*q) {
matches = false;
break;
@@ -853,7 +853,7 @@ static void syntax_highlight_markdown(SyntaxState *state, char32_t const *line,
bool start_of_line = true; // is this the start of the line (not counting whitespace)
int backslashes = 0;
- char const *format_ending = NULL; // "**" if we are inside **bold**, etc.
+ const char *format_ending = NULL; // "**" if we are inside **bold**, etc.
for (u32 i = 0; i < line_len; ++i) {
char32_t c = line[i];
@@ -908,7 +908,7 @@ static void syntax_highlight_markdown(SyntaxState *state, char32_t const *line,
// \* or \_
} else if (has_1_char && line[i+1] == c) {
// **bold** or __bold__
- char const *end = c == '*' ? "**" : "__";
+ const char *end = c == '*' ? "**" : "__";
if (format_ending) {
if (streq(format_ending, end)) {
char_types[i++] = SYNTAX_STRING;
@@ -922,7 +922,7 @@ static void syntax_highlight_markdown(SyntaxState *state, char32_t const *line,
}
} else {
// *italics* or _italics_
- char const *end = c == '*' ? "*" : "_";
+ const char *end = c == '*' ? "*" : "_";
if (format_ending) {
if (streq(format_ending, end))
format_ending = NULL;
diff --git a/tags.c b/tags.c
index 1d62f00..df1fa60 100644
--- a/tags.c
+++ b/tags.c
@@ -19,9 +19,9 @@ static const char *tags_filename(Ted *ted, bool error_if_does_not_exist) {
}
// is this a file we can generate tags for?
-static bool is_source_file(char const *filename) {
- char const *dot = strchr(filename, '.');
- char const *const extensions[] = {
+static bool is_source_file(const char *filename) {
+ const char *dot = strchr(filename, '.');
+ const char *const extensions[] = {
"py", "c", "h", "cpp", "hpp", "cc", "hh", "cxx", "hxx", "C", "H",
"rb", "rs", "go", "lua", "s", "asm", "js", "pl", "cs", "sh", "java", "php"
};
@@ -36,7 +36,7 @@ static bool is_source_file(char const *filename) {
static void tags_generate_at_dir(Ted *ted, bool run_in_build_window, const char *dir, int depth) {
- Settings const *settings = ted_active_settings(ted);
+ const Settings *settings = ted_active_settings(ted);
if (depth >= settings->tags_max_depth) {
return;
}
@@ -47,9 +47,9 @@ static void tags_generate_at_dir(Ted *ted, bool run_in_build_window, const char
#if __unix__
// ctags.emacs's sorting depends on the locale
// (ctags-universal doesn't)
- char const *cmd_prefix = "LC_ALL=C ctags --append";
+ const char *cmd_prefix = "LC_ALL=C ctags --append";
#else
- char const *cmd_prefix = "ctags --append";
+ const char *cmd_prefix = "ctags --append";
#endif
bool any_files = false;
strcpy(command, cmd_prefix);
@@ -94,7 +94,7 @@ static void tags_generate_at_dir(Ted *ted, bool run_in_build_window, const char
// generate/re-generate tags.
static void tags_generate(Ted *ted, bool run_in_build_window) {
- char const *filename = tags_filename(ted, false);
+ const char *filename = tags_filename(ted, false);
if (!filename) {
strcpy(ted->tags_dir, ted->cwd);
}
@@ -107,7 +107,7 @@ static void tags_generate(Ted *ted, bool run_in_build_window) {
change_directory(ted->cwd);
}
-static int tag_try(FILE *fp, char const *tag) {
+static int tag_try(FILE *fp, const char *tag) {
if (ftell(fp) != 0) {
while (1) {
int c = getc(fp);
@@ -134,9 +134,9 @@ static int tag_try(FILE *fp, char const *tag) {
// finds all tags beginning with the given prefix, returning them into *out, writing at most out_size entries.
// you may pass NULL for out, in which case just the number of matching tags is returned (still maxing out at out_size)
// each element in out should be freed when you're done with them
-size_t tags_beginning_with(Ted *ted, char const *prefix, char **out, size_t out_size) {
+size_t tags_beginning_with(Ted *ted, const char *prefix, char **out, size_t out_size) {
assert(out_size);
- char const *tags_name = tags_filename(ted, true);
+ const char *tags_name = tags_filename(ted, true);
if (!tags_name) return 0;
FILE *file = fopen(tags_name, "rb");
if (!file) return 0;
@@ -195,13 +195,13 @@ size_t tags_beginning_with(Ted *ted, char const *prefix, char **out, size_t out_
}
// returns true if the tag exists.
-bool tag_goto(Ted *ted, char const *tag) {
+bool tag_goto(Ted *ted, const char *tag) {
bool already_regenerated_tags;
already_regenerated_tags = false;
top:;
- Settings const *settings = ted_active_settings(ted);
+ const Settings *settings = ted_active_settings(ted);
- char const *tags_name = tags_filename(ted, true);
+ const char *tags_name = tags_filename(ted, true);
if (!tags_name) return false;
FILE *file = fopen(tags_name, "rb");
if (!file) return false;
@@ -349,7 +349,7 @@ top:;
SymbolInfo *tags_get_symbols(Ted *ted) {
// read tags file and extract tag names
- char const *filename = tags_filename(ted, true);
+ const char *filename = tags_filename(ted, true);
if (!filename) return NULL;
FILE *file = fopen(filename, "rb");
if (!file) return NULL;
diff --git a/ted.c b/ted.c
index 4580f9a..3aaec75 100644
--- a/ted.c
+++ b/ted.c
@@ -2,7 +2,7 @@
#define ted_seterr(ted, ...) \
snprintf((ted)->error, sizeof (ted)->error - 1, __VA_ARGS__)
-static void die(char const *fmt, ...) {
+static void die(const char *fmt, ...) {
char buf[256] = {0};
va_list args;
@@ -28,7 +28,7 @@ bool ted_haserr(Ted *ted) {
return ted->error[0] != '\0';
}
-char const *ted_geterr(Ted *ted) {
+const char *ted_geterr(Ted *ted) {
return ted->error;
}
@@ -177,7 +177,7 @@ u32 ted_color(Ted *ted, ColorSetting color) {
return ted_active_settings(ted)->colors[color];
}
-static void ted_path_full(Ted *ted, char const *relpath, char *abspath, size_t abspath_size) {
+static void ted_path_full(Ted *ted, const char *relpath, char *abspath, size_t abspath_size) {
path_full(ted->cwd, relpath, abspath, abspath_size);
}
@@ -186,7 +186,7 @@ static bool ted_is_regular_buffer(Ted *ted, TextBuffer *buffer) {
}
// Check the various places a file could be, and return the full path.
-static Status ted_get_file(Ted const *ted, char const *name, char *out, size_t outsz) {
+static Status ted_get_file(Ted const *ted, const char *name, char *out, size_t outsz) {
if (ted->search_start_cwd && fs_file_exists(name)) {
// check in start_cwd
path_full(ted->start_cwd, name, out, outsz);
@@ -207,7 +207,7 @@ static Status ted_get_file(Ted const *ted, char const *name, char *out, size_t o
// Loads font from filename into *out, freeing any font that was previously there.
// *out is left unchanged on failure.
-static void ted_load_font(Ted *ted, char const *filename, Font **out) {
+static void ted_load_font(Ted *ted, const char *filename, Font **out) {
char font_filename[TED_PATH_MAX];
if (ted_get_file(ted, filename, font_filename, sizeof font_filename)) {
Font *font = text_font_load(font_filename, ted_active_settings(ted)->text_size);
@@ -330,7 +330,7 @@ static i32 ted_new_node(Ted *ted) {
// how tall is a line buffer?
static float ted_line_buffer_height(Ted *ted) {
- float const char_height = text_font_char_height(ted->font);
+ const float char_height = text_font_char_height(ted->font);
return char_height + 2 * ted_active_settings(ted)->border_thickness;
}
@@ -393,7 +393,7 @@ static TextBuffer *ted_get_buffer_with_file(Ted *ted, const char *path) {
// Returns true on success
-static bool ted_open_file(Ted *ted, char const *filename) {
+static bool ted_open_file(Ted *ted, const char *filename) {
char path[TED_PATH_MAX];
ted_path_full(ted, filename, path, sizeof path);
@@ -424,7 +424,7 @@ static bool ted_open_file(Ted *ted, char const *filename) {
}
}
-static bool ted_new_file(Ted *ted, char const *filename) {
+static bool ted_new_file(Ted *ted, const char *filename) {
u16 buffer_idx, tab_idx;
char path[TED_PATH_MAX];
if (filename)
diff --git a/ted.h b/ted.h
index f649bff..448b0b1 100644
--- a/ted.h
+++ b/ted.h
@@ -593,7 +593,7 @@ typedef struct Ted {
} Ted;
// === colors.c ===
-ColorSetting color_setting_from_str(char const *str);
+ColorSetting color_setting_from_str(const char *str);
const char *color_setting_to_str(ColorSetting s);
Status color_from_str(const char *str, u32 *color);
ColorSetting color_for_symbol_kind(SymbolKind kind);
@@ -604,13 +604,13 @@ void gl_rc_sab_decref(GlRcSAB **ps);
GlRcTexture *gl_rc_texture_new(GLuint texture);
void gl_rc_texture_incref(GlRcTexture *t);
void gl_rc_texture_decref(GlRcTexture **pt);
-GLuint gl_compile_shader(char error_buf[256], char const *code, GLenum shader_type);
+GLuint gl_compile_shader(char error_buf[256], const char *code, GLenum shader_type);
GLuint gl_link_program(char error_buf[256], GLuint *shaders, size_t count);
-GLuint gl_compile_and_link_shaders(char error_buf[256], char const *vshader_code, char const *fshader_code);
+GLuint gl_compile_and_link_shaders(char error_buf[256], const char *vshader_code, const char *fshader_code);
// prints a debug message if `attrib` is not found
-GLuint gl_attrib_location(GLuint program, char const *attrib);
+GLuint gl_attrib_location(GLuint program, const char *attrib);
// prints a debug message if `uniform` is not found
-GLint gl_uniform_location(GLuint program, char const *uniform);
+GLint gl_uniform_location(GLuint program, const char *uniform);
void gl_geometry_init(void);
void gl_geometry_rect(Rect r, u32 color_rgba);
void gl_geometry_rect_border(Rect r, float border_thickness, u32 color);
diff --git a/text.c b/text.c
index 8c31c2c..4d04f56 100644
--- a/text.c
+++ b/text.c
@@ -71,11 +71,11 @@ bool text_has_err(void) {
return text_err[0] != '\0';
}
-char const *text_get_err(void) {
+const char *text_get_err(void) {
return text_err;
}
-static void text_set_err(char const *fmt, ...) {
+static void text_set_err(const char *fmt, ...) {
if (!text_has_err()) {
va_list args;
va_start(args, fmt);
@@ -91,7 +91,7 @@ static GLint text_u_sampler;
static GLint text_u_window_size;
static bool text_init(void) {
- char const *vshader_code = "attribute vec4 v_color;\n\
+ const char *vshader_code = "attribute vec4 v_color;\n\
attribute vec2 v_pos;\n\
attribute vec2 v_tex_coord;\n\
uniform vec2 u_window_size;\n\
@@ -104,7 +104,7 @@ void main() {\n\
gl_Position = vec4(p.x - 1.0, 1.0 - p.y, 0.0, 1.0);\n\
}\n\
";
- char const *fshader_code = "IN vec4 color;\n\
+ const char *fshader_code = "IN vec4 color;\n\
IN vec2 tex_coord;\n\
uniform sampler2D sampler;\n\
void main() {\n\
@@ -179,7 +179,7 @@ static Status text_load_char_page(Font *font, int page) {
return true;
}
-Font *text_font_load(char const *ttf_filename, float font_size) {
+Font *text_font_load(const char *ttf_filename, float font_size) {
Font *font = NULL;
FILE *ttf_file = fopen(ttf_filename, "rb");
@@ -284,8 +284,8 @@ top:
return;
}
stbtt_bakedchar *char_data = font->char_pages[page];
- float const char_height = font->char_height;
- float const char_width = font->char_width;
+ const float char_height = font->char_height;
+ const float char_width = font->char_width;
if (char_data) { // if page was successfully loaded
stbtt_aligned_quad q = {0};
@@ -322,8 +322,8 @@ top:
float s1 = q.s1, t1 = q.t1;
float x0 = q.x0, y0 = q.y0;
float x1 = q.x1, y1 = q.y1;
- float const min_x = state->min_x, max_x = state->max_x;
- float const min_y = state->min_y, max_y = state->max_y;
+ const float min_x = state->min_x, max_x = state->max_x;
+ const float min_y = state->min_y, max_y = state->max_y;
if (state->wrap && x1 >= max_x) {
state->x = min_x;
@@ -372,8 +372,8 @@ top:
state->y_largest = state->y;
}
-void text_utf8_with_state(Font *font, TextRenderState *state, char const *str) {
- char const *end = str + strlen(str);
+void text_utf8_with_state(Font *font, TextRenderState *state, const char *str) {
+ const char *end = str + strlen(str);
while (str != end) {
char32_t c = 0;
size_t ret = unicode_utf8_to_utf32(&c, str, (size_t)(end - str));
@@ -390,7 +390,7 @@ void text_utf8_with_state(Font *font, TextRenderState *state, char const *str) {
}
}
-static v2 text_render_utf8_internal(Font *font, char const *text, double x, double y, u32 color, bool render) {
+static v2 text_render_utf8_internal(Font *font, const char *text, double x, double y, u32 color, bool render) {
TextRenderState render_state = text_render_state_default;
render_state.render = render;
render_state.x = x;
@@ -403,11 +403,11 @@ static v2 text_render_utf8_internal(Font *font, char const *text, double x, doub
);
}
-void text_utf8(Font *font, char const *text, double x, double y, u32 color) {
+void text_utf8(Font *font, const char *text, double x, double y, u32 color) {
text_render_utf8_internal(font, text, x, y, color, true);
}
-void text_utf8_anchored(Font *font, char const *text, double x, double y, u32 color, Anchor anchor) {
+void text_utf8_anchored(Font *font, const char *text, double x, double y, u32 color, Anchor anchor) {
float w = 0, h = 0; // width, height of text
text_get_size(font, text, &w, &h);
float hw = w * 0.5f, hh = h * 0.5f; // half-width, half-height
@@ -425,14 +425,14 @@ void text_utf8_anchored(Font *font, char const *text, double x, double y, u32 co
text_utf8(font, text, x, y, color);
}
-void text_get_size(Font *font, char const *text, float *width, float *height) {
+void text_get_size(Font *font, const char *text, float *width, float *height) {
double x = 0, y = 0;
v2 size = text_render_utf8_internal(font, text, x, y, 0, false);
if (width) *width = size.x;
if (height) *height = size.y + font->char_height;
}
-v2 text_get_size_v2(Font *font, char const *text) {
+v2 text_get_size_v2(Font *font, const char *text) {
v2 v;
text_get_size(font, text, &v.x, &v.y);
return v;
diff --git a/text.h b/text.h
index 2c59f5b..8f7db58 100644
--- a/text.h
+++ b/text.h
@@ -43,11 +43,11 @@ typedef enum {
bool text_has_err(void);
// Get the current error. Errors will NOT be overwritten with newer errors.
-char const *text_get_err(void);
+const char *text_get_err(void);
// Clear the current error.
void text_clear_err(void);
// Load a TTF font found in ttf_filename with the given font size (character pixel height)
-Font *text_font_load(char const *ttf_filename, float font_size);
+Font *text_font_load(const char *ttf_filename, float font_size);
// Height of a character of this font in pixels.
float text_font_char_height(Font *font);
// Width of the character 'a' of this font in pixels.
@@ -56,13 +56,13 @@ float text_font_char_width(Font *font);
// Force text to advance by text_font_char_width(font) pixels per character (actually, per code point).
void text_font_set_force_monospace(Font *font, bool force);
// Get the dimensions of some text.
-void text_get_size(Font *font, char const *text, float *width, float *height);
-v2 text_get_size_v2(Font *font, char const *text);
+void text_get_size(Font *font, const char *text, float *width, float *height);
+v2 text_get_size_v2(Font *font, const char *text);
void text_get_size32(Font *font, char32_t const *text, u64 len, float *width, float *height);
-void text_utf8(Font *font, char const *text, double x, double y, u32 color);
-void text_utf8_anchored(Font *font, char const *text, double x, double y, u32 color, Anchor anchor);
+void text_utf8(Font *font, const char *text, double x, double y, u32 color);
+void text_utf8_anchored(Font *font, const char *text, double x, double y, u32 color, Anchor anchor);
void text_char_with_state(Font *font, TextRenderState *state, char32_t c);
-void text_utf8_with_state(Font *font, TextRenderState *state, char const *str);
+void text_utf8_with_state(Font *font, TextRenderState *state, const char *str);
// Free memory used by font.
void text_font_free(Font *font);
void text_render(Font *font);
diff --git a/ui.c b/ui.c
index 01e8b47..c75a11b 100644
--- a/ui.c
+++ b/ui.c
@@ -2,7 +2,7 @@
#include <fcntl.h>
#endif
-static float selector_entries_start_y(Ted *ted, Selector const *s) {
+static float selector_entries_start_y(Ted *ted, const Selector *s) {
float padding = ted_active_settings(ted)->padding;
return s->bounds.pos.y
@@ -10,7 +10,7 @@ static float selector_entries_start_y(Ted *ted, Selector const *s) {
}
// number of entries that can be displayed on the screen
-static u32 selector_n_display_entries(Ted *ted, Selector const *s) {
+static u32 selector_n_display_entries(Ted *ted, const Selector *s) {
float char_height = text_font_char_height(ted->font);
float entries_h = rect_y2(s->bounds) - selector_entries_start_y(ted, s);
return (u32)(entries_h / char_height);
@@ -33,7 +33,7 @@ static void selector_scroll_to_cursor(Ted *ted, Selector *s) {
// where is the ith entry in the selector on the screen?
// returns false if it's completely offscreen
-static bool selector_entry_pos(Ted *ted, Selector const *s, u32 i, Rect *r) {
+static bool selector_entry_pos(Ted *ted, const Selector *s, u32 i, Rect *r) {
Rect bounds = s->bounds;
float char_height = text_font_char_height(ted->font);
*r = rect(V2(bounds.pos.x, selector_entries_start_y(ted, s)
@@ -56,7 +56,7 @@ static void selector_down(Ted *ted, Selector *s, i64 n) {
selector_up(ted, s, -n);
}
-static int selectory_entry_cmp_name(void const *av, void const *bv) {
+static int selectory_entry_cmp_name(const void *av, const void *bv) {
SelectorEntry const *a = av, *b = bv;
return strcmp(a->name, b->name);
}
@@ -186,8 +186,8 @@ static void file_selector_clear_entries(FileSelector *fs) {
}
// returns true if there are any directory entries
-static bool file_selector_any_directories(FileSelector const *fs) {
- FileEntry const *entries = fs->entries;
+static bool file_selector_any_directories(const FileSelector *fs) {
+ const FileEntry *entries = fs->entries;
for (u32 i = 0, n_entries = fs->n_entries; i < n_entries; ++i) {
if (entries[i].type == FS_DIRECTORY)
return true;
@@ -200,9 +200,9 @@ static void file_selector_free(FileSelector *fs) {
memset(fs, 0, sizeof *fs);
}
-static int qsort_file_entry_cmp(void *search_termv, void const *av, void const *bv) {
- char const *search_term = search_termv;
- FileEntry const *a = av, *b = bv;
+static int qsort_file_entry_cmp(void *search_termv, const void *av, const void *bv) {
+ const char *search_term = search_termv;
+ const FileEntry *a = av, *b = bv;
// put directories first
if (a->type == FS_DIRECTORY && b->type != FS_DIRECTORY) {
return -1;
@@ -224,10 +224,10 @@ static int qsort_file_entry_cmp(void *search_termv, void const *av, void const *
return strcmp_case_insensitive(a->name, b->name);
}
-static Status file_selector_cd_(Ted *ted, FileSelector *fs, char const *path, int symlink_depth);
+static Status file_selector_cd_(Ted *ted, FileSelector *fs, const char *path, int symlink_depth);
// cd to the directory `name`. `name` cannot include any path separators.
-static Status file_selector_cd1(Ted *ted, FileSelector *fs, char const *name, size_t name_len, int symlink_depth) {
+static Status file_selector_cd1(Ted *ted, FileSelector *fs, const char *name, size_t name_len, int symlink_depth) {
char *const cwd = fs->cwd;
if (name_len == 0 || (name_len == 1 && name[0] == '.')) {
@@ -297,7 +297,7 @@ static Status file_selector_cd1(Ted *ted, FileSelector *fs, char const *name, si
}
-static Status file_selector_cd_(Ted *ted, FileSelector *fs, char const *path, int symlink_depth) {
+static Status file_selector_cd_(Ted *ted, FileSelector *fs, const char *path, int symlink_depth) {
char *const cwd = fs->cwd;
if (path[0] == '\0') return true;
@@ -320,7 +320,7 @@ static Status file_selector_cd_(Ted *ted, FileSelector *fs, char const *path, in
#endif
}
- char const *p = path;
+ const char *p = path;
while (*p) {
size_t len = strcspn(p, PATH_SEPARATOR_STR);
@@ -336,7 +336,7 @@ static Status file_selector_cd_(Ted *ted, FileSelector *fs, char const *path, in
// go to the directory `path`. make sure `path` only contains path separators like PATH_SEPARATOR, not any
// other members of ALL_PATH_SEPARATORS
// returns false if this path doesn't exist or isn't a directory
-static bool file_selector_cd(Ted *ted, FileSelector *fs, char const *path) {
+static bool file_selector_cd(Ted *ted, FileSelector *fs, const char *path) {
fs->sel.cursor = 0;
fs->sel.scroll = 0;
return file_selector_cd_(ted, fs, path, 0);
@@ -499,8 +499,8 @@ static char *file_selector_update(Ted *ted, FileSelector *fs) {
}
static void file_selector_render(Ted *ted, FileSelector *fs) {
- Settings const *settings = ted_active_settings(ted);
- u32 const *colors = settings->colors;
+ const Settings *settings = ted_active_settings(ted);
+ const u32 *colors = settings->colors;
Rect bounds = fs->bounds;
Font *font = ted->font;
float padding = settings->padding;
@@ -538,13 +538,13 @@ static void file_selector_render(Ted *ted, FileSelector *fs) {
selector_render(ted, sel);
}
-static v2 button_get_size(Ted *ted, char const *text) {
+static v2 button_get_size(Ted *ted, const char *text) {
float border_thickness = ted_active_settings(ted)->border_thickness;
return v2_add_const(text_get_size_v2(ted->font, text), 2 * border_thickness);
}
-static void button_render(Ted *ted, Rect button, char const *text, u32 color) {
- u32 const *colors = ted_active_settings(ted)->colors;
+static void button_render(Ted *ted, Rect button, const char *text, u32 color) {
+ const u32 *colors = ted_active_settings(ted)->colors;
if (rect_contains_point(button, ted->mouse_pos)) {
// highlight button when hovering over it
@@ -615,16 +615,16 @@ static PopupOption popup_update(Ted *ted, u32 options) {
return POPUP_NONE;
}
-static void popup_render(Ted *ted, u32 options, char const *title, char const *body) {
+static void popup_render(Ted *ted, u32 options, const char *title, const char *body) {
float window_width = ted->window_width;
Font *font = ted->font;
Font *font_bold = ted->font_bold;
Rect r, button_yes, button_no, button_cancel;
- Settings const *settings = ted_active_settings(ted);
- u32 const *colors = settings->colors;
- float const char_height_bold = text_font_char_height(font_bold);
- float const padding = settings->padding;
- float const border_thickness = settings->border_thickness;
+ const Settings *settings = ted_active_settings(ted);
+ const u32 *colors = settings->colors;
+ const float char_height_bold = text_font_char_height(font_bold);
+ const float padding = settings->padding;
+ const float border_thickness = settings->border_thickness;
popup_get_rects(ted, options, &r, &button_yes, &button_no, &button_cancel);
@@ -665,12 +665,12 @@ static void popup_render(Ted *ted, u32 options, char const *title, char const *b
}
// returns the size of the checkbox, including the label
-static v2 checkbox_frame(Ted *ted, bool *value, char const *label, v2 pos) {
+static v2 checkbox_frame(Ted *ted, bool *value, const char *label, v2 pos) {
Font *font = ted->font;
float char_height = text_font_char_height(font);
float checkbox_size = char_height;
- Settings const *settings = ted_active_settings(ted);
- u32 const *colors = settings->colors;
+ const Settings *settings = ted_active_settings(ted);
+ const u32 *colors = settings->colors;
float padding = settings->padding;
float border_thickness = settings->border_thickness;
diff --git a/util.c b/util.c
index 6751a72..d02954e 100644
--- a/util.c
+++ b/util.c
@@ -1282,7 +1282,7 @@ void str32_free(String32 *s) {
// the string returned should be str32_free'd.
// this will return an empty string if the allocation failed or the string is invalid UTF-8
-String32 str32_from_utf8(char const *utf8) {
+String32 str32_from_utf8(const char *utf8) {
String32 string = {NULL, 0};
size_t len = strlen(utf8);
if (len) {
@@ -1290,8 +1290,8 @@ String32 str32_from_utf8(char const *utf8) {
char32_t *widestr = calloc(len, sizeof *widestr);
if (widestr) {
char32_t *wide_p = widestr;
- char const *utf8_p = utf8;
- char const *utf8_end = utf8_p + len;
+ const char *utf8_p = utf8;
+ const char *utf8_end = utf8_p + len;
while (utf8_p < utf8_end) {
char32_t c = 0;
size_t n = unicode_utf8_to_utf32(&c, utf8_p, (size_t)(utf8_end - utf8_p));
@@ -1337,7 +1337,7 @@ char *str32_to_utf8_cstr(String32 s) {
}
// compare s to the ASCII string `ascii`
-int str32_cmp_ascii(String32 s, char const *ascii) {
+int str32_cmp_ascii(String32 s, const char *ascii) {
for (size_t i = 0; i < s.len; ++i) {
assert((char32_t)ascii[i] < 128);
if ((char32_t)ascii[i] == '\0')
@@ -1355,7 +1355,7 @@ int str32_cmp_ascii(String32 s, char const *ascii) {
}
// check if s starts with the ASCII string `ascii`
-bool str32_has_ascii_prefix(String32 s, char const *ascii) {
+bool str32_has_ascii_prefix(String32 s, const char *ascii) {
for (size_t i = 0; i < s.len; ++i) {
assert((char32_t)ascii[i] < 128);
if ((char32_t)ascii[i] == '\0')
@@ -1410,12 +1410,12 @@ size_t str32_remove_all_instances_of_char(String32 *s, char32_t c) {
// returns the length of the longest prefix of `s` containing only
// ASCII characters in the C-string `charset`.
-size_t str32_ascii_spn(String32 s, char const *charset) {
+size_t str32_ascii_spn(String32 s, const char *charset) {
for (u32 i = 0; i < s.len; ++i) {
if (s.str[i] >= 128)
return i; // non-ASCII character in s, so that can't be in charset.
bool found = false;
- for (char const *p = charset; *p; ++p) {
+ for (const char *p = charset; *p; ++p) {
assert((char32_t)*p < 128);
if ((char32_t)*p == s.str[i]) {
found = true;
diff --git a/util.h b/util.h
index 7437c9d..a71a961 100644
--- a/util.h
+++ b/util.h
@@ -425,13 +425,13 @@ double timespec_to_seconds(struct timespec ts);
String32 str32(char32_t *str, size_t len);
String32 str32_substr(String32 s, size_t from, size_t len);
void str32_free(String32 *s);
-String32 str32_from_utf8(char const *utf8);
+String32 str32_from_utf8(const char *utf8);
char *str32_to_utf8_cstr(String32 s);
-int str32_cmp_ascii(String32 s, char const *ascii);
-bool str32_has_ascii_prefix(String32 s, char const *ascii);
+int str32_cmp_ascii(String32 s, const char *ascii);
+bool str32_has_ascii_prefix(String32 s, const char *ascii);
size_t str32chr(String32 s, char32_t c);
size_t str32_count_char(String32 s, char32_t c);
size_t str32_remove_all_instances_of_char(String32 *s, char32_t c);
-size_t str32_ascii_spn(String32 s, char const *charset);
+size_t str32_ascii_spn(String32 s, const char *charset);
#endif // UTIL_H_