diff options
| -rw-r--r-- | src/cmdline.c | 79 | ||||
| -rw-r--r-- | src/core-commands.c | 14 | ||||
| -rw-r--r-- | src/core-commands.h | 4 | ||||
| -rw-r--r-- | src/file-utils.c | 6 | ||||
| -rw-r--r-- | src/glob.c | 14 | ||||
| -rw-r--r-- | src/glob.h | 5 | ||||
| -rw-r--r-- | src/goto-commands.c | 14 | ||||
| -rw-r--r-- | src/help.c | 6 | ||||
| -rw-r--r-- | src/interface-curses/curses-info-popup.c | 4 | ||||
| -rw-r--r-- | src/interface-curses/interface.c | 11 | ||||
| -rw-r--r-- | src/interface-gtk/gtk-info-popup.c | 4 | ||||
| -rw-r--r-- | src/interface-gtk/gtk-label.c | 4 | ||||
| -rw-r--r-- | src/interface-gtk/gtk-label.h | 2 | ||||
| -rw-r--r-- | src/interface-gtk/interface.c | 7 | ||||
| -rw-r--r-- | src/move-commands.c | 4 | ||||
| -rw-r--r-- | src/parser.c | 22 | ||||
| -rw-r--r-- | src/parser.h | 14 | ||||
| -rw-r--r-- | src/qreg-commands.c | 20 | ||||
| -rw-r--r-- | src/qreg-commands.h | 2 | ||||
| -rw-r--r-- | src/qreg.c | 16 | ||||
| -rw-r--r-- | src/rb3str.c | 10 | ||||
| -rw-r--r-- | src/ring.c | 18 | ||||
| -rw-r--r-- | src/search.c | 43 | ||||
| -rw-r--r-- | src/spawn.c | 8 | ||||
| -rw-r--r-- | src/stdio-commands.c | 4 | ||||
| -rw-r--r-- | src/string-utils.c | 42 | ||||
| -rw-r--r-- | src/string-utils.h | 33 | ||||
| -rw-r--r-- | src/symbols.c | 40 |
28 files changed, 226 insertions, 224 deletions
diff --git a/src/cmdline.c b/src/cmdline.c index d06b8c2..673eab0 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -128,7 +128,7 @@ teco_cmdline_insert(const gchar *data, gsize len, GError **error) gsize macro_len = teco_cmdline_ssm(SCI_GETLENGTH, 0, 0); if (len <= macro_len - effective_len && - !teco_string_cmp(&src, macro + effective_len, len)) { + !teco_string_cmp(src, macro + effective_len, len)) { /* extend effective command line from rubbed out part */ teco_cmdline_ssm(SCI_GOTOPOS, effective_len+len, 0); } else { @@ -174,7 +174,7 @@ teco_cmdline_insert(const gchar *data, gsize len, GError **error) * new command line. This avoids unnecessary rubouts * and insertions when the command line is updated. */ - teco_cmdline.pc = teco_string_diff(&new_cmdline, macro, effective_len); + teco_cmdline.pc = teco_string_diff(new_cmdline, macro, effective_len); teco_undo_pop(teco_cmdline.pc); @@ -275,10 +275,9 @@ teco_cmdline_rubin(GError **error) gboolean teco_cmdline_keypress(const gchar *data, gsize len, GError **error) { - const teco_string_t str = {(gchar *)data, len}; teco_machine_t *machine = &teco_cmdline.machine.parent; - if (!teco_string_validate_utf8(&str)) { + if (!teco_string_validate_utf8((teco_string_t){(gchar *)data, len})) { g_set_error_literal(error, TECO_ERROR, TECO_ERROR_CODEPOINT, "Invalid UTF-8 sequence"); return FALSE; @@ -694,14 +693,14 @@ teco_state_stringbuilding_start_process_edit_cmd(teco_machine_stringbuilding_t * /* reinsert word chars */ while (ctx->parent.current == current && teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0) < macro_len && - teco_string_contains(&wchars, macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)])) + teco_string_contains(wchars, macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)])) if (!teco_cmdline_rubin(error)) return FALSE; /* reinsert non-word chars */ while (ctx->parent.current == current && teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0) < macro_len && - !teco_string_contains(&wchars, macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)])) + !teco_string_contains(wchars, macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)])) if (!teco_cmdline_rubin(error)) return FALSE; @@ -715,7 +714,7 @@ teco_state_stringbuilding_start_process_edit_cmd(teco_machine_stringbuilding_t * * a result string even in parse-only mode. */ if (ctx->result && ctx->result->len > 0) { - gboolean is_wordchar = teco_string_contains(&wchars, macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)-1]); + gboolean is_wordchar = teco_string_contains(wchars, macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)-1]); teco_cmdline_rubout(); if (ctx->parent.current != current) { /* rub out string building command */ @@ -731,13 +730,13 @@ teco_state_stringbuilding_start_process_edit_cmd(teco_machine_stringbuilding_t * */ if (!is_wordchar) { while (ctx->result->len > 0 && - !teco_string_contains(&wchars, macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)-1])) + !teco_string_contains(wchars, macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)-1])) teco_cmdline_rubout(); } /* rubout word chars */ while (ctx->result->len > 0 && - teco_string_contains(&wchars, macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)-1])) + teco_string_contains(wchars, macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)-1])) teco_cmdline_rubout(); return TRUE; @@ -792,7 +791,7 @@ teco_state_stringbuilding_start_process_edit_cmd(teco_machine_stringbuilding_t * return TRUE; } - const gchar *filename = teco_string_last_occurrence(ctx->result, + const gchar *filename = teco_string_last_occurrence(*ctx->result, TECO_DEFAULT_BREAK_CHARS); g_auto(teco_string_t) new_chars, new_chars_escaped; gboolean unambiguous = teco_file_auto_complete(filename, G_FILE_TEST_EXISTS, &new_chars); @@ -823,11 +822,11 @@ teco_state_stringbuilding_start_process_edit_cmd(teco_machine_stringbuilding_t * } gboolean -teco_state_stringbuilding_insert_completion(teco_machine_stringbuilding_t *ctx, const teco_string_t *str, GError **error) +teco_state_stringbuilding_insert_completion(teco_machine_stringbuilding_t *ctx, teco_string_t str, GError **error) { g_auto(teco_string_t) str_escaped; - teco_machine_stringbuilding_escape(ctx, str->data, str->len, &str_escaped); - if (!str->len || !G_IS_DIR_SEPARATOR(str->data[str->len-1])) + teco_machine_stringbuilding_escape(ctx, str.data, str.len, &str_escaped); + if (!str.len || !G_IS_DIR_SEPARATOR(str.data[str.len-1])) teco_string_append_c(&str_escaped, ' '); return teco_cmdline_insert(str_escaped.data, str_escaped.len, error); } @@ -872,7 +871,7 @@ teco_state_expectstring_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_ } gboolean -teco_state_expectstring_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_expectstring_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error) { teco_machine_stringbuilding_t *stringbuilding_ctx = &ctx->expectstring.machine; teco_state_t *stringbuilding_current = stringbuilding_ctx->parent.current; @@ -981,7 +980,7 @@ teco_state_expectfile_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t return TRUE; } - if (teco_string_contains(&ctx->expectstring.string, '\0')) + if (teco_string_contains(ctx->expectstring.string, '\0')) /* null-byte not allowed in file names */ return TRUE; @@ -1000,13 +999,13 @@ teco_state_expectfile_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t } gboolean -teco_state_expectfile_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_expectfile_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error) { teco_machine_stringbuilding_t *stringbuilding_ctx = &ctx->expectstring.machine; g_auto(teco_string_t) str_escaped; - teco_machine_stringbuilding_escape(stringbuilding_ctx, str->data, str->len, &str_escaped); - if ((!str->len || !G_IS_DIR_SEPARATOR(str->data[str->len-1])) && + teco_machine_stringbuilding_escape(stringbuilding_ctx, str.data, str.len, &str_escaped); + if ((!str.len || !G_IS_DIR_SEPARATOR(str.data[str.len-1])) && ctx->expectstring.nesting == 1) teco_string_append_wc(&str_escaped, ctx->expectstring.machine.escape_char == '{' ? '}' : ctx->expectstring.machine.escape_char); @@ -1037,7 +1036,7 @@ teco_state_expectglob_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t return TRUE; } - if (teco_string_contains(&ctx->expectstring.string, '\0')) + if (teco_string_contains(ctx->expectstring.string, '\0')) /* null-byte not allowed in file names */ return TRUE; @@ -1068,14 +1067,14 @@ teco_state_expectglob_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t } gboolean -teco_state_expectglob_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_expectglob_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error) { teco_machine_stringbuilding_t *stringbuilding_ctx = &ctx->expectstring.machine; - g_autofree gchar *pattern_escaped = teco_globber_escape_pattern(str->data); + g_autofree gchar *pattern_escaped = teco_globber_escape_pattern(str.data); g_auto(teco_string_t) str_escaped; teco_machine_stringbuilding_escape(stringbuilding_ctx, pattern_escaped, strlen(pattern_escaped), &str_escaped); - if ((!str->len || !G_IS_DIR_SEPARATOR(str->data[str->len-1])) && + if ((!str.len || !G_IS_DIR_SEPARATOR(str.data[str.len-1])) && ctx->expectstring.nesting == 1) teco_string_append_wc(&str_escaped, ctx->expectstring.machine.escape_char == '{' ? '}' : ctx->expectstring.machine.escape_char); @@ -1106,7 +1105,7 @@ teco_state_expectdir_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t * return TRUE; } - if (teco_string_contains(&ctx->expectstring.string, '\0')) + if (teco_string_contains(ctx->expectstring.string, '\0')) /* null-byte not allowed in file names */ return TRUE; @@ -1126,7 +1125,7 @@ teco_state_expectdir_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t * } gboolean -teco_state_expectdir_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_expectdir_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error) { teco_machine_stringbuilding_t *stringbuilding_ctx = &ctx->expectstring.machine; @@ -1134,7 +1133,7 @@ teco_state_expectdir_insert_completion(teco_machine_main_t *ctx, const teco_stri * FIXME: We might terminate the command in case of leaf directories. */ g_auto(teco_string_t) str_escaped; - teco_machine_stringbuilding_escape(stringbuilding_ctx, str->data, str->len, &str_escaped); + teco_machine_stringbuilding_escape(stringbuilding_ctx, str.data, str.len, &str_escaped); return teco_cmdline_insert(str_escaped.data, str_escaped.len, error); } @@ -1151,7 +1150,7 @@ teco_state_expectqreg_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t } gboolean -teco_state_expectqreg_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_expectqreg_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error) { g_assert(ctx->expectqreg != NULL); /* @@ -1202,9 +1201,9 @@ teco_state_qregspec_process_edit_cmd(teco_machine_qregspec_t *ctx, teco_machine_ } gboolean -teco_state_qregspec_insert_completion(teco_machine_qregspec_t *ctx, const teco_string_t *str, GError **error) +teco_state_qregspec_insert_completion(teco_machine_qregspec_t *ctx, teco_string_t str, GError **error) { - return teco_cmdline_insert(str->data, str->len, error); + return teco_cmdline_insert(str.data, str.len, error); } gboolean @@ -1248,12 +1247,12 @@ teco_state_qregspec_string_process_edit_cmd(teco_machine_qregspec_t *ctx, teco_m } gboolean -teco_state_qregspec_string_insert_completion(teco_machine_qregspec_t *ctx, const teco_string_t *str, GError **error) +teco_state_qregspec_string_insert_completion(teco_machine_qregspec_t *ctx, teco_string_t str, GError **error) { teco_machine_stringbuilding_t *stringbuilding_ctx = teco_machine_qregspec_get_stringbuilding(ctx); g_auto(teco_string_t) str_escaped; - teco_machine_stringbuilding_escape(stringbuilding_ctx, str->data, str->len, &str_escaped); + teco_machine_stringbuilding_escape(stringbuilding_ctx, str.data, str.len, &str_escaped); teco_string_append_c(&str_escaped, ']'); return teco_cmdline_insert(str_escaped.data, str_escaped.len, error); } @@ -1288,7 +1287,7 @@ teco_state_execute_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *pa return TRUE; } - const gchar *filename = teco_string_last_occurrence(&ctx->expectstring.string, + const gchar *filename = teco_string_last_occurrence(ctx->expectstring.string, TECO_DEFAULT_BREAK_CHARS); g_auto(teco_string_t) new_chars, new_chars_escaped; gboolean unambiguous = teco_file_auto_complete(filename, G_FILE_TEST_EXISTS, &new_chars); @@ -1327,7 +1326,7 @@ teco_state_scintilla_symbols_process_edit_cmd(teco_machine_main_t *ctx, teco_mac return TRUE; } - const gchar *symbol = teco_string_last_occurrence(&ctx->expectstring.string, ","); + const gchar *symbol = teco_string_last_occurrence(ctx->expectstring.string, ","); teco_symbol_list_t *list = symbol == ctx->expectstring.string.data ? &teco_symbol_list_scintilla : &teco_symbol_list_scilexer; @@ -1349,12 +1348,12 @@ teco_state_scintilla_symbols_process_edit_cmd(teco_machine_main_t *ctx, teco_mac } gboolean -teco_state_scintilla_symbols_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_scintilla_symbols_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error) { teco_machine_stringbuilding_t *stringbuilding_ctx = &ctx->expectstring.machine; g_auto(teco_string_t) str_escaped; - teco_machine_stringbuilding_escape(stringbuilding_ctx, str->data, str->len, &str_escaped); + teco_machine_stringbuilding_escape(stringbuilding_ctx, str.data, str.len, &str_escaped); teco_string_append_c(&str_escaped, ','); return teco_cmdline_insert(str_escaped.data, str_escaped.len, error); } @@ -1384,7 +1383,7 @@ teco_state_goto_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *paren } teco_string_t label = ctx->expectstring.string; - gint i = teco_string_rindex(&label, ','); + gint i = teco_string_rindex(label, ','); if (i >= 0) { label.data += i+1; label.len -= i+1; @@ -1407,12 +1406,12 @@ teco_state_goto_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *paren } gboolean -teco_state_goto_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_goto_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error) { teco_machine_stringbuilding_t *stringbuilding_ctx = &ctx->expectstring.machine; g_auto(teco_string_t) str_escaped; - teco_machine_stringbuilding_escape(stringbuilding_ctx, str->data, str->len, &str_escaped); + teco_machine_stringbuilding_escape(stringbuilding_ctx, str.data, str.len, &str_escaped); /* * FIXME: This does not escape `,`. Cannot be escaped via ^Q currently? */ @@ -1444,7 +1443,7 @@ teco_state_help_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *paren return TRUE; } - if (teco_string_contains(&ctx->expectstring.string, '\0')) + if (teco_string_contains(ctx->expectstring.string, '\0')) /* help term must not contain null-byte */ return TRUE; @@ -1463,12 +1462,12 @@ teco_state_help_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *paren } gboolean -teco_state_help_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_help_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error) { teco_machine_stringbuilding_t *stringbuilding_ctx = &ctx->expectstring.machine; g_auto(teco_string_t) str_escaped; - teco_machine_stringbuilding_escape(stringbuilding_ctx, str->data, str->len, &str_escaped); + teco_machine_stringbuilding_escape(stringbuilding_ctx, str.data, str.len, &str_escaped); if (ctx->expectstring.nesting == 1) teco_string_append_wc(&str_escaped, ctx->expectstring.machine.escape_char == '{' ? '}' : ctx->expectstring.machine.escape_char); diff --git a/src/core-commands.c b/src/core-commands.c index 86a4b85..949952e 100644 --- a/src/core-commands.c +++ b/src/core-commands.c @@ -1108,12 +1108,12 @@ teco_undo_change_dir_to_current(void) } static teco_state_t * -teco_state_changedir_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_changedir_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; - g_autofree gchar *dir = teco_file_expand_path(str->data); + g_autofree gchar *dir = teco_file_expand_path(str.data); if (!*dir) { teco_qreg_t *qreg = teco_qreg_table_find(&teco_qreg_table_globals, "$HOME", 5); g_assert(qreg != NULL); @@ -1124,7 +1124,7 @@ teco_state_changedir_done(teco_machine_main_t *ctx, const teco_string_t *str, GE /* * Null-characters must not occur in file names. */ - if (teco_string_contains(&home, '\0')) { + if (teco_string_contains(home, '\0')) { teco_string_clear(&home); g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED, "Null-character not allowed in filenames"); @@ -1796,7 +1796,7 @@ teco_return(teco_machine_main_t *ctx, GError **error) * command line with `}` after command-line termination. */ if (G_UNLIKELY(ctx == &teco_cmdline.machine && - teco_qreg_current && !teco_string_cmp(&teco_qreg_current->head.name, "\e", 1))) { + teco_qreg_current && !teco_string_cmp(teco_qreg_current->head.name, "\e", 1))) { g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED, "Not allowed to terminate command-line while " "editing command-line replacement register"); @@ -2930,14 +2930,14 @@ teco_state_insert_initial(teco_machine_main_t *ctx, GError **error) } gboolean -teco_state_insert_process(teco_machine_main_t *ctx, const teco_string_t *str, +teco_state_insert_process(teco_machine_main_t *ctx, teco_string_t str, gsize new_chars, GError **error) { g_assert(new_chars > 0); teco_interface_ssm(SCI_BEGINUNDOACTION, 0, 0); teco_interface_ssm(SCI_ADDTEXT, new_chars, - (sptr_t)(str->data + str->len - new_chars)); + (sptr_t)(str.data + str.len - new_chars)); teco_interface_ssm(SCI_ENDUNDOACTION, 0, 0); teco_ring_dirtify(); @@ -2948,7 +2948,7 @@ teco_state_insert_process(teco_machine_main_t *ctx, const teco_string_t *str, } teco_state_t * -teco_state_insert_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_insert_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; diff --git a/src/core-commands.h b/src/core-commands.h index 425379e..782cb89 100644 --- a/src/core-commands.h +++ b/src/core-commands.h @@ -74,9 +74,9 @@ extern guint teco_ranges_count; extern teco_range_t *teco_ranges; gboolean teco_state_insert_initial(teco_machine_main_t *ctx, GError **error); -gboolean teco_state_insert_process(teco_machine_main_t *ctx, const teco_string_t *str, +gboolean teco_state_insert_process(teco_machine_main_t *ctx, teco_string_t str, gsize new_chars, GError **error); -teco_state_t *teco_state_insert_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error); +teco_state_t *teco_state_insert_done(teco_machine_main_t *ctx, teco_string_t str, GError **error); /* in cmdline.c */ gboolean teco_state_insert_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *parent_ctx, diff --git a/src/file-utils.c b/src/file-utils.c index db06ff3..1171afe 100644 --- a/src/file-utils.c +++ b/src/file-utils.c @@ -360,7 +360,7 @@ teco_file_expand_path(const gchar *path) */ g_auto(teco_string_t) home = {NULL, 0}; if (!qreg->vtable->get_string(qreg, &home.data, &home.len, NULL, NULL) || - teco_string_contains(&home, '\0')) + teco_string_contains(home, '\0')) return g_strdup(path); g_assert(home.data != NULL); @@ -426,7 +426,7 @@ teco_file_auto_complete(const gchar *filename, GFileTest file_test, teco_string_ while ((cur_basename.data = (gchar *)g_dir_read_name(dir))) { cur_basename.len = strlen(cur_basename.data); - if (string_diff(&cur_basename, basename, basename_len) != basename_len) + if (string_diff(cur_basename, basename, basename_len) != basename_len) /* basename is not a prefix of cur_basename */ continue; @@ -460,7 +460,7 @@ teco_file_auto_complete(const gchar *filename, GFileTest file_test, teco_string_ other_file.data = (gchar *)g_slist_next(files)->data + filename_len; other_file.len = strlen(other_file.data); - gsize len = string_diff(&other_file, cur_filename + filename_len, + gsize len = string_diff(other_file, cur_filename + filename_len, strlen(cur_filename) - filename_len); if (len < prefix_len) prefix_len = len; @@ -305,13 +305,13 @@ teco_globber_compile_pattern(const gchar *pattern) */ static teco_state_t * -teco_state_glob_pattern_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_glob_pattern_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_glob_filename; - if (str->len > 0) { - g_autofree gchar *filename = teco_file_expand_path(str->data); + if (str.len > 0) { + g_autofree gchar *filename = teco_file_expand_path(str.data); teco_qreg_t *glob_reg = teco_qreg_table_find(&teco_qreg_table_globals, "_", 1); g_assert(glob_reg != NULL); @@ -456,7 +456,7 @@ TECO_DEFINE_STATE_EXPECTGLOB(teco_state_glob_pattern, ); static teco_state_t * -teco_state_glob_filename_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_glob_filename_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; @@ -495,16 +495,16 @@ teco_state_glob_filename_done(teco_machine_main_t *ctx, const teco_string_t *str if (!glob_reg->vtable->get_string(glob_reg, &pattern_str.data, &pattern_str.len, NULL, error)) return NULL; - if (teco_string_contains(&pattern_str, '\0')) { + if (teco_string_contains(pattern_str, '\0')) { teco_error_qregcontainsnull_set(error, "_", 1, FALSE); return NULL; } - if (str->len > 0) { + if (str.len > 0) { /* * Match pattern against provided file name */ - g_autofree gchar *filename = teco_file_expand_path(str->data); + g_autofree gchar *filename = teco_file_expand_path(str.data); g_autoptr(GRegex) pattern = teco_globber_compile_pattern(pattern_str.data); if (g_regex_match(pattern, filename, 0, NULL) && @@ -47,8 +47,9 @@ gchar *teco_globber_escape_pattern(const gchar *pattern); GRegex *teco_globber_compile_pattern(const gchar *pattern); /* in cmdline.c */ -gboolean teco_state_expectglob_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *parent_ctx, gunichar key, GError **error); -gboolean teco_state_expectglob_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error); +gboolean teco_state_expectglob_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *parent_ctx, + gunichar key, GError **error); +gboolean teco_state_expectglob_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error); /** * @interface TECO_DEFINE_STATE_EXPECTGLOB diff --git a/src/goto-commands.c b/src/goto-commands.c index 6fdaffc..aad3668 100644 --- a/src/goto-commands.c +++ b/src/goto-commands.c @@ -75,7 +75,7 @@ teco_state_label_input(teco_machine_main_t *ctx, gunichar chr, GError **error) teco_goto_table_undo_remove(&ctx->goto_table, ctx->goto_label.data, ctx->goto_label.len); if (teco_goto_skip_label.len > 0 && - !teco_string_cmp(&ctx->goto_label, teco_goto_skip_label.data, teco_goto_skip_label.len)) { + !teco_string_cmp(ctx->goto_label, teco_goto_skip_label.data, teco_goto_skip_label.len)) { teco_undo_string_own(teco_goto_skip_label); memset(&teco_goto_skip_label, 0, sizeof(teco_goto_skip_label)); teco_undo_gssize(teco_goto_backup_pc) = -1; @@ -118,12 +118,12 @@ TECO_DEFINE_STATE(teco_state_label, ); static teco_state_t * -teco_state_goto_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_goto_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; - if (!str->len) { + if (!str.len) { /* you can still write @O/,/, though... */ g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED, "No labels given for <O>"); @@ -141,9 +141,9 @@ teco_state_goto_done(teco_machine_main_t *ctx, const teco_string_t *str, GError */ teco_string_t label = {NULL, 0}; while (value >= 0) { - label.data = label.data ? label.data+label.len+1 : str->data; - const gchar *p = label.data ? memchr(label.data, ',', str->len - (label.data - str->data)) : NULL; - label.len = p ? p - label.data : str->len - (label.data - str->data); + label.data = label.data ? label.data+label.len+1 : str.data; + const gchar *p = label.data ? memchr(label.data, ',', str.len - (label.data - str.data)) : NULL; + label.len = p ? p - label.data : str.len - (label.data - str.data); value--; @@ -178,7 +178,7 @@ teco_state_goto_done(teco_machine_main_t *ctx, const teco_string_t *str, GError /* in cmdline.c */ gboolean teco_state_goto_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *parent_ctx, gunichar chr, GError **error); -gboolean teco_state_goto_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, +gboolean teco_state_goto_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error); /*$ "O" ":O" goto @@ -271,7 +271,7 @@ teco_state_help_initial(teco_machine_main_t *ctx, GError **error) } static teco_state_t * -teco_state_help_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_help_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; @@ -281,7 +281,7 @@ teco_state_help_done(teco_machine_main_t *ctx, const teco_string_t *str, GError "Help topic must not contain null-byte"); return NULL; } - const gchar *topic_name = str->data ? : ""; + const gchar *topic_name = str.data ? : ""; teco_help_topic_t *topic = teco_help_find(topic_name); if (!topic) { g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, @@ -316,7 +316,7 @@ teco_state_help_done(teco_machine_main_t *ctx, const teco_string_t *str, GError /* in cmdline.c */ gboolean teco_state_help_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *parent_ctx, gunichar chr, GError **error); -gboolean teco_state_help_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, +gboolean teco_state_help_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error); /*$ "?" help diff --git a/src/interface-curses/curses-info-popup.c b/src/interface-curses/curses-info-popup.c index 8da6fbb..825555e 100644 --- a/src/interface-curses/curses-info-popup.c +++ b/src/interface-curses/curses-info-popup.c @@ -133,7 +133,7 @@ teco_curses_info_popup_init_pad(teco_curses_info_popup_t *ctx, attr_t attr) switch (entry->type) { case TECO_POPUP_FILE: - g_assert(!teco_string_contains(&name, '\0')); + g_assert(!teco_string_contains(name, '\0')); if (teco_ed & TECO_ED_ICONS) { /* "(Unnamed)" buffer is looked up as "" */ teco_curses_add_wc(ctx->pad, teco_curses_icons_lookup_file(entry->name.data)); @@ -142,7 +142,7 @@ teco_curses_info_popup_init_pad(teco_curses_info_popup_t *ctx, attr_t attr) teco_curses_format_filename(ctx->pad, name.data, -1); break; case TECO_POPUP_DIRECTORY: - g_assert(!teco_string_contains(&name, '\0')); + g_assert(!teco_string_contains(name, '\0')); if (teco_ed & TECO_ED_ICONS) { teco_curses_add_wc(ctx->pad, teco_curses_icons_lookup_dir(entry->name.data)); waddch(ctx->pad, ' '); diff --git a/src/interface-curses/interface.c b/src/interface-curses/interface.c index 93a5bd5..5110bc8 100644 --- a/src/interface-curses/interface.c +++ b/src/interface-curses/interface.c @@ -236,6 +236,9 @@ static struct { * Instead we allocate color pairs beginnig at 128 on demand * (similar to what Scinterm does). * + * @note Scinterm now also has scintilla_set_color_offsets(), + * so we could use the lower 127 color pairs as well. + * * @param fg curses foreground color * @param bg curses background color * @return curses color pair number @@ -1169,7 +1172,7 @@ teco_interface_draw_info(void) case TECO_INFO_TYPE_BUFFER: info_type_str = PACKAGE_NAME " - <Buffer> "; - g_assert(!teco_string_contains(&info_current, '\0')); + g_assert(!teco_string_contains(info_current, '\0')); /* "(Unnamed)" buffer has to be looked up as "" */ teco_curses_add_wc(teco_interface.info_window, teco_ed & TECO_ED_ICONS ? teco_curses_icons_lookup_file(teco_interface.info_current.data) : '-'); @@ -1540,7 +1543,7 @@ teco_interface_set_clipboard(const gchar *name, const gchar *str, gsize str_len, g_auto(teco_string_t) command; if (!reg->vtable->get_string(reg, &command.data, &command.len, NULL, error)) return FALSE; - if (teco_string_contains(&command, '\0')) { + if (teco_string_contains(command, '\0')) { teco_error_qregcontainsnull_set(error, reg_name, strlen(reg_name), FALSE); return FALSE; } @@ -1601,7 +1604,7 @@ teco_interface_get_clipboard(const gchar *name, gchar **str, gsize *len, GError g_auto(teco_string_t) command; if (!reg->vtable->get_string(reg, &command.data, &command.len, NULL, error)) return FALSE; - if (teco_string_contains(&command, '\0')) { + if (teco_string_contains(command, '\0')) { teco_error_qregcontainsnull_set(error, reg_name, strlen(reg_name), FALSE); return FALSE; } @@ -1864,7 +1867,7 @@ teco_interface_process_mevent(MEVENT *event, GError **error) */ const teco_string_t insert_suffix = {insert->data + teco_interface.popup_prefix_len, insert->len - teco_interface.popup_prefix_len}; - if (!machine->current->insert_completion_cb(machine, &insert_suffix, error)) + if (!machine->current->insert_completion_cb(machine, insert_suffix, error)) return FALSE; teco_interface_popup_clear(); diff --git a/src/interface-gtk/gtk-info-popup.c b/src/interface-gtk/gtk-info-popup.c index 3ddd10a..20ede5b 100644 --- a/src/interface-gtk/gtk-info-popup.c +++ b/src/interface-gtk/gtk-info-popup.c @@ -110,10 +110,10 @@ teco_gtk_info_popup_activated_cb(GtkFlowBox *box, GtkFlowBoxChild *child, gpoint GList *entry; for (entry = child_list; entry != NULL && !TECO_IS_GTK_LABEL(entry->data); entry = g_list_next(entry)); g_assert(entry != NULL); - const teco_string_t *str = teco_gtk_label_get_text(TECO_GTK_LABEL(entry->data)); + teco_string_t str = teco_gtk_label_get_text(TECO_GTK_LABEL(entry->data)); g_signal_emit(popup, teco_gtk_info_popup_clicked_signal, 0, - str->data, (gulong)str->len); + str.data, (gulong)str.len); } static void diff --git a/src/interface-gtk/gtk-label.c b/src/interface-gtk/gtk-label.c index e148652..3ac51a9 100644 --- a/src/interface-gtk/gtk-label.c +++ b/src/interface-gtk/gtk-label.c @@ -274,10 +274,10 @@ teco_gtk_label_set_text(TecoGtkLabel *self, const gchar *str, gssize len) gtk_label_set_text(GTK_LABEL(self), plaintext); } -const teco_string_t * +teco_string_t teco_gtk_label_get_text(TecoGtkLabel *self) { - return &self->string; + return self->string; } /** diff --git a/src/interface-gtk/gtk-label.h b/src/interface-gtk/gtk-label.h index 3cd4cb9..86d71d8 100644 --- a/src/interface-gtk/gtk-label.h +++ b/src/interface-gtk/gtk-label.h @@ -27,7 +27,7 @@ G_DECLARE_FINAL_TYPE(TecoGtkLabel, teco_gtk_label, TECO, GTK_LABEL, GtkLabel) GtkWidget *teco_gtk_label_new(const gchar *str, gssize len); void teco_gtk_label_set_text(TecoGtkLabel *self, const gchar *str, gssize len); -const teco_string_t *teco_gtk_label_get_text(TecoGtkLabel *self); +teco_string_t teco_gtk_label_get_text(TecoGtkLabel *self); void teco_gtk_label_parse_string(const gchar *str, gssize len, PangoColor *fg, guint16 fg_alpha, diff --git a/src/interface-gtk/interface.c b/src/interface-gtk/interface.c index 2b292a3..a86e3fd 100644 --- a/src/interface-gtk/interface.c +++ b/src/interface-gtk/interface.c @@ -1134,7 +1134,7 @@ teco_interface_event_loop(GError **error) if (!scitecoconfig_reg->vtable->get_string(scitecoconfig_reg, &scitecoconfig.data, &scitecoconfig.len, NULL, error)) return FALSE; - if (teco_string_contains(&scitecoconfig, '\0')) { + if (teco_string_contains(scitecoconfig, '\0')) { g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED, "Null-character not allowed in filenames"); return FALSE; @@ -1478,7 +1478,8 @@ teco_interface_popup_clicked_cb(GtkWidget *popup, gchar *str, gulong len, gpoint { g_assert(len >= teco_interface.popup_prefix_len); /* str is an empty string for the "(Unnamed)" buffer */ - const teco_string_t insert = {str+teco_interface.popup_prefix_len, len-teco_interface.popup_prefix_len}; + const teco_string_t insert = {str+teco_interface.popup_prefix_len, + len-teco_interface.popup_prefix_len}; teco_machine_t *machine = &teco_cmdline.machine.parent; const teco_view_t *last_view = teco_interface_current_view; @@ -1488,7 +1489,7 @@ teco_interface_popup_clicked_cb(GtkWidget *popup, gchar *str, gulong len, gpoint * A auto completion should never result in program termination. */ if (machine->current->insert_completion_cb && - !machine->current->insert_completion_cb(machine, &insert, NULL)) + !machine->current->insert_completion_cb(machine, insert, NULL)) return; teco_interface_popup_clear(); teco_cmdline_update(); diff --git a/src/move-commands.c b/src/move-commands.c index cf5d6b0..57007b6 100644 --- a/src/move-commands.c +++ b/src/move-commands.c @@ -276,7 +276,7 @@ teco_find_words(gsize *pos, teco_int_t n, gboolean end_of_word) /* * FIXME: Is this safe or do we have to look up Unicode code points? */ - if ((!teco_string_contains(&wchars, *p)) == skip_word) { + if ((!teco_string_contains(wchars, *p)) == skip_word) { if (skip_word == end_of_word) break; skip_word = !skip_word; @@ -314,7 +314,7 @@ teco_find_words(gsize *pos, teco_int_t n, gboolean end_of_word) /* * FIXME: Is this safe or do we have to look up Unicode code points? */ - if ((!teco_string_contains(&wchars, p[-1])) == skip_word) { + if ((!teco_string_contains(wchars, p[-1])) == skip_word) { if (skip_word != end_of_word) break; skip_word = !skip_word; diff --git a/src/parser.c b/src/parser.c index 0cf6031..3683cca 100644 --- a/src/parser.c +++ b/src/parser.c @@ -162,9 +162,7 @@ gboolean teco_execute_macro(const gchar *macro, gsize macro_len, teco_qreg_table_t *qreg_table_locals, GError **error) { - const teco_string_t str = {(gchar *)macro, macro_len}; - - if (!teco_string_validate_utf8(&str)) { + if (!teco_string_validate_utf8((teco_string_t){(gchar *)macro, macro_len})) { g_set_error_literal(error, TECO_ERROR, TECO_ERROR_CODEPOINT, "Invalid UTF-8 byte sequence in macro"); return FALSE; @@ -521,7 +519,7 @@ teco_state_stringbuilding_start_input(teco_machine_stringbuilding_t *ctx, gunich /* in cmdline.c */ gboolean teco_state_stringbuilding_start_process_edit_cmd(teco_machine_stringbuilding_t *ctx, teco_machine_t *parent_ctx, gunichar key, GError **error); -gboolean teco_state_stringbuilding_insert_completion(teco_machine_stringbuilding_t *ctx, const teco_string_t *str, GError **error); +gboolean teco_state_stringbuilding_insert_completion(teco_machine_stringbuilding_t *ctx, teco_string_t str, GError **error); static TECO_DEFINE_STATE(teco_state_stringbuilding_start, .is_start = TRUE, @@ -948,7 +946,7 @@ teco_state_stringbuilding_ctle_quote_input(teco_machine_stringbuilding_t *ctx, g * in command line arguments anyway. * Otherwise, we'd have to implement our own POSIX shell escape function. */ - if (teco_string_contains(&str, '\0')) { + if (teco_string_contains(str, '\0')) { teco_error_qregcontainsnull_set(error, qreg->head.name.data, qreg->head.name.len, table != &teco_qreg_table_globals); return NULL; @@ -986,7 +984,7 @@ teco_state_stringbuilding_ctle_n_input(teco_machine_stringbuilding_t *ctx, gunic g_auto(teco_string_t) str = {NULL, 0}; if (!qreg->vtable->get_string(qreg, &str.data, &str.len, NULL, error)) return NULL; - if (teco_string_contains(&str, '\0')) { + if (teco_string_contains(str, '\0')) { teco_error_qregcontainsnull_set(error, qreg->head.name.data, qreg->head.name.len, table != &teco_qreg_table_globals); return NULL; @@ -1138,11 +1136,11 @@ teco_state_expectstring_input(teco_machine_main_t *ctx, gunichar chr, GError **e * so they may do their main activity in process_cb(). */ if (ctx->expectstring.insert_len && current->expectstring.process_cb && - !current->expectstring.process_cb(ctx, &ctx->expectstring.string, + !current->expectstring.process_cb(ctx, ctx->expectstring.string, ctx->expectstring.insert_len, error)) return NULL; - teco_state_t *next = current->expectstring.done_cb(ctx, &ctx->expectstring.string, error); + teco_state_t *next = current->expectstring.done_cb(ctx, ctx->expectstring.string, error); if (ctx->parent.must_undo) teco_undo_string_own(ctx->expectstring.string); @@ -1217,7 +1215,7 @@ teco_state_expectstring_refresh(teco_machine_main_t *ctx, GError **error) /* never calls process_cb() in parse-only mode */ if (ctx->expectstring.insert_len && current->expectstring.process_cb && - !current->expectstring.process_cb(ctx, &ctx->expectstring.string, + !current->expectstring.process_cb(ctx, ctx->expectstring.string, ctx->expectstring.insert_len, error)) return FALSE; @@ -1229,10 +1227,10 @@ teco_state_expectstring_refresh(teco_machine_main_t *ctx, GError **error) } gboolean -teco_state_expectfile_process(teco_machine_main_t *ctx, const teco_string_t *str, +teco_state_expectfile_process(teco_machine_main_t *ctx, teco_string_t str, gsize new_chars, GError **error) { - g_assert(str->data != NULL); + g_assert(str.data != NULL); /* * Null-chars must not occur in filename/path strings and at some point @@ -1241,7 +1239,7 @@ teco_state_expectfile_process(teco_machine_main_t *ctx, const teco_string_t *str * Doing it here ensures that teco_file_expand_path() can be safely called * from the done_cb(). */ - if (memchr(str->data + str->len - new_chars, '\0', new_chars)) { + if (memchr(str.data + str.len - new_chars, '\0', new_chars)) { g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED, "Null-character not allowed in filenames"); return FALSE; diff --git a/src/parser.h b/src/parser.h index 4ab4d25..98548b1 100644 --- a/src/parser.h +++ b/src/parser.h @@ -85,7 +85,7 @@ typedef const struct { * * Can be NULL if no interactive feedback is required. */ - gboolean (*process_cb)(teco_machine_main_t *ctx, const teco_string_t *str, + gboolean (*process_cb)(teco_machine_main_t *ctx, teco_string_t str, gsize new_chars, GError **error); /** @@ -93,7 +93,7 @@ typedef const struct { * Commands that don't give interactive feedback can use this callback * to perform their main processing. */ - teco_state_t *(*done_cb)(teco_machine_main_t *ctx, const teco_string_t *str, GError **error); + teco_state_t *(*done_cb)(teco_machine_main_t *ctx, teco_string_t str, GError **error); } teco_state_expectstring_t; typedef const struct { @@ -110,7 +110,7 @@ typedef gboolean (*teco_state_refresh_cb_t)(teco_machine_t *ctx, GError **error) typedef gboolean (*teco_state_end_of_macro_cb_t)(teco_machine_t *ctx, GError **error); typedef gboolean (*teco_state_process_edit_cmd_cb_t)(teco_machine_t *ctx, teco_machine_t *parent_ctx, gunichar key, GError **error); -typedef gboolean (*teco_state_insert_completion_cb_t)(teco_machine_t *ctx, const teco_string_t *str, GError **error); +typedef gboolean (*teco_state_insert_completion_cb_t)(teco_machine_t *ctx, teco_string_t str, GError **error); typedef enum { TECO_KEYMACRO_MASK_START = (1 << 0), @@ -599,7 +599,7 @@ gboolean teco_state_expectstring_refresh(teco_machine_main_t *ctx, GError **erro /* in cmdline.c */ gboolean teco_state_expectstring_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *parent_ctx, gunichar key, GError **error); -gboolean teco_state_expectstring_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, +gboolean teco_state_expectstring_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error); /** @@ -629,12 +629,12 @@ gboolean teco_state_expectstring_insert_completion(teco_machine_main_t *ctx, con ); \ TECO_ASSERT_SAFE(NAME.expectstring.done_cb != NULL) -gboolean teco_state_expectfile_process(teco_machine_main_t *ctx, const teco_string_t *str, +gboolean teco_state_expectfile_process(teco_machine_main_t *ctx, teco_string_t str, gsize new_chars, GError **error); /* in cmdline.c */ gboolean teco_state_expectfile_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *parent_ctx, gunichar key, GError **error); -gboolean teco_state_expectfile_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error); +gboolean teco_state_expectfile_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error); /** * @interface TECO_DEFINE_STATE_EXPECTFILE @@ -653,7 +653,7 @@ gboolean teco_state_expectfile_insert_completion(teco_machine_main_t *ctx, const /* in cmdline.c */ gboolean teco_state_expectdir_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *parent_ctx, gunichar key, GError **error); -gboolean teco_state_expectdir_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error); +gboolean teco_state_expectdir_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error); /** * @interface TECO_DEFINE_STATE_EXPECTDIR diff --git a/src/qreg-commands.c b/src/qreg-commands.c index 5efb140..304ff49 100644 --- a/src/qreg-commands.c +++ b/src/qreg-commands.c @@ -150,7 +150,7 @@ TECO_DEFINE_STATE_EXPECTQREG(teco_state_eqcommand, ); static teco_state_t * -teco_state_loadqreg_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_loadqreg_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { teco_qreg_t *qreg; teco_qreg_table_t *table; @@ -161,9 +161,9 @@ teco_state_loadqreg_done(teco_machine_main_t *ctx, const teco_string_t *str, GEr if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; - if (str->len > 0) { + if (str.len > 0) { /* Load file into Q-Register */ - g_autofree gchar *filename = teco_file_expand_path(str->data); + g_autofree gchar *filename = teco_file_expand_path(str.data); if (!qreg->vtable->load(qreg, filename, error)) return NULL; } else { @@ -210,7 +210,7 @@ TECO_DEFINE_STATE_EXPECTQREG(teco_state_epctcommand, ); static teco_state_t * -teco_state_saveqreg_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_saveqreg_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { teco_qreg_t *qreg; @@ -220,7 +220,7 @@ teco_state_saveqreg_done(teco_machine_main_t *ctx, const teco_string_t *str, GEr if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; - g_autofree gchar *filename = teco_file_expand_path(str->data); + g_autofree gchar *filename = teco_file_expand_path(str.data); return qreg->vtable->save(qreg, filename, error) ? &teco_state_start : NULL; } @@ -377,7 +377,7 @@ TECO_DEFINE_STATE_EXPECTQREG(teco_state_ctlucommand, static teco_state_t * teco_state_setqregstring_nobuilding_done(teco_machine_main_t *ctx, - const teco_string_t *str, GError **error) + teco_string_t str, GError **error) { teco_qreg_t *qreg; @@ -446,12 +446,12 @@ teco_state_setqregstring_nobuilding_done(teco_machine_main_t *ctx, if (args > 0 || colon_modified) { /* append to register */ - if (!qreg->vtable->append_string(qreg, str->data, str->len, error)) + if (!qreg->vtable->append_string(qreg, str.data, str.len, error)) return NULL; } else { /* set register */ if (!qreg->vtable->undo_set_string(qreg, error) || - !qreg->vtable->set_string(qreg, str->data, str->len, + !qreg->vtable->set_string(qreg, str.data, str.len, teco_default_codepage(), error)) return NULL; } @@ -742,12 +742,12 @@ TECO_DEFINE_STATE_EXPECTQREG(teco_state_macro, ); static teco_state_t * -teco_state_indirect_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_indirect_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; - g_autofree gchar *filename = teco_file_expand_path(str->data); + g_autofree gchar *filename = teco_file_expand_path(str.data); if (teco_machine_main_eval_colon(ctx) > 0) { /* don't create new local Q-Registers if colon modifier is given */ diff --git a/src/qreg-commands.h b/src/qreg-commands.h index d0f6990..9aed55c 100644 --- a/src/qreg-commands.h +++ b/src/qreg-commands.h @@ -40,7 +40,7 @@ teco_state_t *teco_state_expectqreg_input(teco_machine_main_t *ctx, gunichar chr /* in cmdline.c */ gboolean teco_state_expectqreg_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *parent_ctx, gunichar key, GError **error); -gboolean teco_state_expectqreg_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, +gboolean teco_state_expectqreg_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error); /** @@ -732,7 +732,7 @@ teco_qreg_workingdir_set_string(teco_qreg_t *qreg, const gchar *str, gsize len, g_auto(teco_string_t) dir; teco_string_init(&dir, str, len); - if (teco_string_contains(&dir, '\0')) { + if (teco_string_contains(dir, '\0')) { g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED, "Directory contains null-character"); return FALSE; @@ -1107,7 +1107,7 @@ teco_qreg_table_get_environ(teco_qreg_table_t *table, GError **error) for (teco_qreg_t *cur = first; cur && cur->head.name.data[0] == '$'; cur = (teco_qreg_t *)teco_rb3str_get_next(&cur->head)) { - const teco_string_t *name = &cur->head.name; + const teco_string_t name = cur->head.name; /* * Ignore the "$" register (not an environment @@ -1115,7 +1115,7 @@ teco_qreg_table_get_environ(teco_qreg_table_t *table, GError **error) * name contains "=" or null (not allowed in environment * variable names). */ - if (name->len == 1 || + if (name.len == 1 || teco_string_contains(name, '=') || teco_string_contains(name, '\0')) continue; @@ -1124,16 +1124,16 @@ teco_qreg_table_get_environ(teco_qreg_table_t *table, GError **error) g_strfreev(envp); return NULL; } - if (teco_string_contains(&value, '\0')) { + if (teco_string_contains(value, '\0')) { g_strfreev(envp); g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, "Environment register \"%s\" must not contain null characters", - name->data); + name.data); return NULL; } /* more efficient than g_environ_setenv() */ - *p++ = g_strconcat(name->data+1, "=", value.data, NULL); + *p++ = g_strconcat(name.data+1, "=", value.data, NULL); } *p = NULL; @@ -1439,7 +1439,7 @@ teco_state_qregspec_start_input(teco_machine_qregspec_t *ctx, gunichar chr, GErr /* in cmdline.c */ gboolean teco_state_qregspec_process_edit_cmd(teco_machine_qregspec_t *ctx, teco_machine_t *parent_ctx, gunichar key, GError **error); -gboolean teco_state_qregspec_insert_completion(teco_machine_qregspec_t *ctx, const teco_string_t *str, +gboolean teco_state_qregspec_insert_completion(teco_machine_qregspec_t *ctx, teco_string_t str, GError **error); static TECO_DEFINE_STATE(teco_state_qregspec_start, @@ -1587,7 +1587,7 @@ teco_state_qregspec_string_input(teco_machine_qregspec_t *ctx, gunichar chr, GEr /* in cmdline.c */ gboolean teco_state_qregspec_string_process_edit_cmd(teco_machine_qregspec_t *ctx, teco_machine_t *parent_ctx, gunichar key, GError **error); -gboolean teco_state_qregspec_string_insert_completion(teco_machine_qregspec_t *ctx, const teco_string_t *str, +gboolean teco_state_qregspec_string_insert_completion(teco_machine_qregspec_t *ctx, teco_string_t str, GError **error); static TECO_DEFINE_STATE(teco_state_qregspec_string, diff --git a/src/rb3str.c b/src/rb3str.c index 276b624..94072d9 100644 --- a/src/rb3str.c +++ b/src/rb3str.c @@ -34,13 +34,13 @@ static gint teco_rb3str_cmp(const teco_rb3str_head_t *head, const teco_string_t *data) { - return teco_string_cmp(&head->key, data->data, data->len); + return teco_string_cmp(head->key, data->data, data->len); } static gint teco_rb3str_casecmp(const teco_rb3str_head_t *head, const teco_string_t *data) { - return teco_string_casecmp(&head->key, data->data, data->len); + return teco_string_casecmp(head->key, data->data, data->len); } /** @memberof teco_rb3str_tree_t */ @@ -113,7 +113,7 @@ teco_rb3str_auto_complete(teco_rb3str_tree_t *tree, gboolean case_sensitive, guint prefixed_entries = 0; for (teco_rb3str_head_t *cur = teco_rb3str_nfind(tree, case_sensitive, str, str_len); - cur && cur->key.len >= str_len && diff(&cur->key, str, str_len) == str_len; + cur && cur->key.len >= str_len && diff(cur->key, str, str_len) == str_len; cur = teco_rb3str_get_next(cur)) { if (restrict_len && g_utf8_strlen(cur->key.data, cur->key.len) != restrict_len) continue; @@ -122,7 +122,7 @@ teco_rb3str_auto_complete(teco_rb3str_tree_t *tree, gboolean case_sensitive, first = cur; prefix_len = cur->key.len - str_len; } else { - gsize len = diff(&cur->key, first->key.data, first->key.len) - str_len; + gsize len = diff(cur->key, first->key.data, first->key.len) - str_len; if (len < prefix_len) prefix_len = len; } @@ -134,7 +134,7 @@ teco_rb3str_auto_complete(teco_rb3str_tree_t *tree, gboolean case_sensitive, teco_string_init(insert, first->key.data + str_len, prefix_len); } else if (prefixed_entries > 1) { for (teco_rb3str_head_t *cur = first; - cur && cur->key.len >= str_len && diff(&cur->key, str, str_len) == str_len; + cur && cur->key.len >= str_len && diff(cur->key, str, str_len) == str_len; cur = teco_rb3str_get_next(cur)) { if (restrict_len && g_utf8_strlen(cur->key.data, cur->key.len) != restrict_len) continue; @@ -534,7 +534,7 @@ teco_state_edit_file_initial(teco_machine_main_t *ctx, GError **error) } gboolean -teco_state_edit_file_process(teco_machine_main_t *ctx, const teco_string_t *str, +teco_state_edit_file_process(teco_machine_main_t *ctx, teco_string_t str, gsize new_chars, GError **error) { g_assert(new_chars > 0); @@ -550,18 +550,18 @@ teco_state_edit_file_process(teco_machine_main_t *ctx, const teco_string_t *str, } static teco_state_t * -teco_state_edit_file_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_edit_file_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; if (!ctx->flags.allow_filename) { - /* process_cb() already throws error if str->len > 0 */ - g_assert(str->len == 0); + /* process_cb() already throws error if str.len > 0 */ + g_assert(str.len == 0); return &teco_state_start; } - g_autofree gchar *filename = teco_file_expand_path(str->data); + g_autofree gchar *filename = teco_file_expand_path(str.data); if (teco_globber_is_pattern(filename)) { g_auto(teco_globber_t) globber; teco_globber_init(&globber, filename, G_FILE_TEST_IS_REGULAR); @@ -644,7 +644,7 @@ TECO_DEFINE_STATE_EXPECTGLOB(teco_state_edit_file, ); static teco_state_t * -teco_state_save_file_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_save_file_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; @@ -652,7 +652,7 @@ teco_state_save_file_done(teco_machine_main_t *ctx, const teco_string_t *str, GE if (!teco_expressions_eval(FALSE, error)) return NULL; - g_autofree gchar *filename = teco_file_expand_path(str->data); + g_autofree gchar *filename = teco_file_expand_path(str.data); /* * This is like implying teco_ring_get_id(teco_ring_current) @@ -720,14 +720,14 @@ TECO_DEFINE_STATE_EXPECTFILE(teco_state_save_file, ); static teco_state_t * -teco_state_read_file_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_read_file_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; sptr_t pos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); - g_autofree gchar *filename = teco_file_expand_path(str->data); + g_autofree gchar *filename = teco_file_expand_path(str.data); /* FIXME: Add wrapper to interface.h? */ if (!teco_view_load(teco_interface_current_view, filename, FALSE, error)) return NULL; diff --git a/src/search.c b/src/search.c index 2a39b59..d6601ae 100644 --- a/src/search.c +++ b/src/search.c @@ -537,7 +537,7 @@ teco_pattern2regexp(teco_string_t *pattern, teco_machine_qregspec_t *qreg_machin if (state == TECO_SEARCH_STATE_ALT) teco_string_append_c(&re, ')'); - g_assert(!teco_string_contains(&re, '\0')); + g_assert(!teco_string_contains(re, '\0')); return g_steal_pointer(&re.data) ? : g_strdup(""); } @@ -696,7 +696,7 @@ teco_do_search(GRegex *re, gsize from, gsize to, gint *count, GError **error) } static gboolean -teco_state_search_process(teco_machine_main_t *ctx, const teco_string_t *str, gsize new_chars, GError **error) +teco_state_search_process(teco_machine_main_t *ctx, teco_string_t str, gsize new_chars, GError **error) { /* FIXME: Should G_REGEX_OPTIMIZE be added under certain circumstances? */ GRegexCompileFlags flags = G_REGEX_MULTILINE | G_REGEX_DOTALL; @@ -741,10 +741,9 @@ teco_state_search_process(teco_machine_main_t *ctx, const teco_string_t *str, gs qreg_machine = teco_machine_qregspec_new(TECO_QREG_REQUIRED, ctx->qreg_table_locals, FALSE); g_autoptr(GRegex) re = NULL; - teco_string_t pattern = *str; g_autofree gchar *re_pattern; /* NOTE: teco_pattern2regexp() modifies str pointer */ - re_pattern = teco_pattern2regexp(&pattern, qreg_machine, + re_pattern = teco_pattern2regexp(&str, qreg_machine, ctx->expectstring.machine.codepage, FALSE, error); if (!re_pattern) return FALSE; @@ -829,7 +828,7 @@ failure: } static teco_state_t * -teco_state_search_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_search_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; @@ -837,14 +836,14 @@ teco_state_search_done(teco_machine_main_t *ctx, const teco_string_t *str, GErro teco_qreg_t *search_reg = teco_qreg_table_find(&teco_qreg_table_globals, "_", 1); g_assert(search_reg != NULL); - if (str->len > 0) { + if (str.len > 0) { /* workaround: preserve selection (also on rubout) */ gint anchor = teco_interface_ssm(SCI_GETANCHOR, 0, 0); if (teco_current_doc_must_undo()) undo__teco_interface_ssm(SCI_SETANCHOR, anchor, 0); if (!search_reg->vtable->undo_set_string(search_reg, error) || - !search_reg->vtable->set_string(search_reg, str->data, str->len, + !search_reg->vtable->set_string(search_reg, str.data, str.len, teco_default_codepage(), error)) return NULL; @@ -853,7 +852,7 @@ teco_state_search_done(teco_machine_main_t *ctx, const teco_string_t *str, GErro g_auto(teco_string_t) search_str = {NULL, 0}; if (!search_reg->vtable->get_string(search_reg, &search_str.data, &search_str.len, NULL, error) || - !teco_state_search_process(ctx, &search_str, search_str.len, error)) + !teco_state_search_process(ctx, search_str, search_str.len, error)) return NULL; } @@ -1016,7 +1015,7 @@ teco_state_search_all_initial(teco_machine_main_t *ctx, GError **error) } static teco_state_t * -teco_state_search_all_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_search_all_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; @@ -1080,7 +1079,7 @@ TECO_DEFINE_STATE_SEARCH(teco_state_search_all, ); static teco_state_t * -teco_state_search_kill_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_search_kill_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; @@ -1164,7 +1163,7 @@ TECO_DEFINE_STATE_SEARCH(teco_state_search_kill, ); static teco_state_t * -teco_state_search_delete_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_search_delete_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; @@ -1237,7 +1236,7 @@ static TECO_DEFINE_STATE_INSERT(teco_state_replace_insert, ); static teco_state_t * -teco_state_replace_ignore_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_replace_ignore_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { return &teco_state_start; } @@ -1247,7 +1246,7 @@ static TECO_DEFINE_STATE_EXPECTSTRING(teco_state_replace_ignore, ); static teco_state_t * -teco_state_replace_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_replace_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_replace_ignore; @@ -1292,7 +1291,7 @@ TECO_DEFINE_STATE_SEARCH(teco_state_replace, ); static teco_state_t * -teco_state_replace_default_insert_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_replace_default_insert_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; @@ -1300,16 +1299,16 @@ teco_state_replace_default_insert_done(teco_machine_main_t *ctx, const teco_stri teco_qreg_t *replace_reg = teco_qreg_table_find(&teco_qreg_table_globals, "-", 1); g_assert(replace_reg != NULL); - if (str->len > 0) { + if (str.len > 0) { if (!replace_reg->vtable->undo_set_string(replace_reg, error) || - !replace_reg->vtable->set_string(replace_reg, str->data, str->len, + !replace_reg->vtable->set_string(replace_reg, str.data, str.len, teco_default_codepage(), error)) return NULL; } else { g_auto(teco_string_t) replace_str = {NULL, 0}; if (!replace_reg->vtable->get_string(replace_reg, &replace_str.data, &replace_str.len, NULL, error) || - (replace_str.len > 0 && !teco_state_insert_process(ctx, &replace_str, replace_str.len, error))) + (replace_str.len > 0 && !teco_state_insert_process(ctx, replace_str, replace_str.len, error))) return NULL; } @@ -1324,17 +1323,17 @@ static TECO_DEFINE_STATE_INSERT(teco_state_replace_default_insert, ); static teco_state_t * -teco_state_replace_default_ignore_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_replace_default_ignore_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL || - !str->len) + !str.len) return &teco_state_start; teco_qreg_t *replace_reg = teco_qreg_table_find(&teco_qreg_table_globals, "-", 1); g_assert(replace_reg != NULL); if (!replace_reg->vtable->undo_set_string(replace_reg, error) || - !replace_reg->vtable->set_string(replace_reg, str->data, str->len, + !replace_reg->vtable->set_string(replace_reg, str.data, str.len, teco_default_codepage(), error)) return NULL; @@ -1346,7 +1345,7 @@ static TECO_DEFINE_STATE_EXPECTSTRING(teco_state_replace_default_ignore, ); static teco_state_t * -teco_state_replace_default_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_replace_default_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_replace_default_ignore; @@ -1390,7 +1389,7 @@ TECO_DEFINE_STATE_SEARCH(teco_state_replace_default, ); static teco_state_t * -teco_state_replace_default_all_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_replace_default_all_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_replace_default_ignore; diff --git a/src/spawn.c b/src/spawn.c index 6745b4f..43dac15 100644 --- a/src/spawn.c +++ b/src/spawn.c @@ -150,7 +150,7 @@ teco_parse_shell_command_line(const gchar *cmdline, GError **error) teco_string_t shell; if (!reg->vtable->get_string(reg, &shell.data, &shell.len, NULL, error)) return NULL; - if (teco_string_contains(&shell, '\0')) { + if (teco_string_contains(shell, '\0')) { teco_string_clear(&shell); teco_error_qregcontainsnull_set(error, "$SHELL", 6, FALSE); return NULL; @@ -242,7 +242,7 @@ teco_state_execute_initial(teco_machine_main_t *ctx, GError **error) } static teco_state_t * -teco_state_execute_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_execute_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { /* * NOTE: With G_SPAWN_LEAVE_DESCRIPTORS_OPEN and without G_SPAWN_SEARCH_PATH_FROM_ENVP, @@ -285,13 +285,13 @@ teco_state_execute_done(teco_machine_main_t *ctx, const teco_string_t *str, GErr } #endif - if (!str->len || teco_string_contains(str, '\0')) { + if (!str.len || teco_string_contains(str, '\0')) { g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, "Command line must not be empty or contain null-bytes"); goto gerror; } - argv = teco_parse_shell_command_line(str->data, error); + argv = teco_parse_shell_command_line(str.data, error); if (!argv) goto gerror; diff --git a/src/stdio-commands.c b/src/stdio-commands.c index bd28049..a1e3a30 100644 --- a/src/stdio-commands.c +++ b/src/stdio-commands.c @@ -253,9 +253,9 @@ teco_state_print_string_initial(teco_machine_main_t *ctx, GError **error) } static teco_state_t * -teco_state_print_string_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_print_string_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { - teco_interface_msg_literal(TECO_MSG_USER, str->data, str->len); + teco_interface_msg_literal(TECO_MSG_USER, str.data, str.len); return &teco_state_start; } diff --git a/src/string-utils.c b/src/string-utils.c index 10e34a8..573a17b 100644 --- a/src/string-utils.c +++ b/src/string-utils.c @@ -98,12 +98,12 @@ teco_string_get_coord(const gchar *str, gsize off, guint *pos, guint *line, guin * @memberof teco_string_t */ gsize -teco_string_diff(const teco_string_t *a, const gchar *b, gsize b_len) +teco_string_diff(teco_string_t a, const gchar *b, gsize b_len) { gsize len = 0; - while (len < a->len && len < b_len && - a->data[len] == b[len]) + while (len < a.len && len < b_len && + a.data[len] == b[len]) len++; return len; @@ -124,12 +124,12 @@ teco_string_diff(const teco_string_t *a, const gchar *b, gsize b_len) * @memberof teco_string_t */ gsize -teco_string_casediff(const teco_string_t *a, const gchar *b, gsize b_len) +teco_string_casediff(teco_string_t a, const gchar *b, gsize b_len) { gsize len = 0; - while (len < a->len && len < b_len) { - gunichar a_chr = g_utf8_get_char(a->data+len); + while (len < a.len && len < b_len) { + gunichar a_chr = g_utf8_get_char(a.data+len); gunichar b_chr = g_utf8_get_char(b+len); if (g_unichar_tolower(a_chr) != g_unichar_tolower(b_chr)) break; @@ -141,36 +141,36 @@ teco_string_casediff(const teco_string_t *a, const gchar *b, gsize b_len) /** @memberof teco_string_t */ gint -teco_string_cmp(const teco_string_t *a, const gchar *b, gsize b_len) +teco_string_cmp(teco_string_t a, const gchar *b, gsize b_len) { - for (guint i = 0; i < a->len; i++) { + for (guint i = 0; i < a.len; i++) { if (i == b_len) /* b is a prefix of a */ return 1; - gint ret = (gint)a->data[i] - (gint)b[i]; + gint ret = (gint)a.data[i] - (gint)b[i]; if (ret != 0) /* a and b have a common prefix of length i */ return ret; } - return a->len == b_len ? 0 : -1; + return a.len == b_len ? 0 : -1; } /** @memberof teco_string_t */ gint -teco_string_casecmp(const teco_string_t *a, const gchar *b, gsize b_len) +teco_string_casecmp(teco_string_t a, const gchar *b, gsize b_len) { - for (guint i = 0; i < a->len; i++) { + for (guint i = 0; i < a.len; i++) { if (i == b_len) /* b is a prefix of a */ return 1; - gint ret = (gint)g_ascii_tolower(a->data[i]) - (gint)g_ascii_tolower(b[i]); + gint ret = (gint)g_ascii_tolower(a.data[i]) - (gint)g_ascii_tolower(b[i]); if (ret != 0) /* a and b have a common prefix of length i */ return ret; } - return a->len == b_len ? 0 : -1; + return a.len == b_len ? 0 : -1; } /** @@ -184,22 +184,20 @@ teco_string_casecmp(const teco_string_t *a, const gchar *b, gsize b_len) * @memberof teco_string_t */ const gchar * -teco_string_last_occurrence(const teco_string_t *str, const gchar *chars) +teco_string_last_occurrence(teco_string_t str, const gchar *chars) { - teco_string_t ret = *str; - - if (!ret.len) + if (!str.len) return NULL; do { - gint i = teco_string_rindex(&ret, *chars); + gint i = teco_string_rindex(str, *chars); if (i >= 0) { - ret.data += i+1; - ret.len -= i+1; + str.data += i+1; + str.len -= i+1; } } while (*chars++); - return ret.data; + return str.data; } TECO_DEFINE_UNDO_CALL(teco_string_truncate, teco_string_t *, gsize); diff --git a/src/string-utils.h b/src/string-utils.h index af2c8a1..359329f 100644 --- a/src/string-utils.h +++ b/src/string-utils.h @@ -63,6 +63,9 @@ teco_strv_remove(gchar **strv, guint i) * to functions expecting traditional null-terminated C strings if you can * guarantee that it contains no null-character other than the trailing one. * + * Since string objects are just two words, they can and should be passed by + * value if the callee doesn't have to modify it. + * * @warning For consistency with C idioms the underlying character type is * `char`, which might be signed! * Accessing individual characters may yield signed integers and that sign @@ -164,19 +167,19 @@ gchar *teco_string_echo(const gchar *str, gsize len); void teco_string_get_coord(const gchar *str, gsize off, guint *pos, guint *line, guint *column); -typedef gsize (*teco_string_diff_t)(const teco_string_t *a, const gchar *b, gsize b_len); -gsize teco_string_diff(const teco_string_t *a, const gchar *b, gsize b_len); -gsize teco_string_casediff(const teco_string_t *a, const gchar *b, gsize b_len); +typedef gsize (*teco_string_diff_t)(teco_string_t a, const gchar *b, gsize b_len); +gsize teco_string_diff(teco_string_t a, const gchar *b, gsize b_len); +gsize teco_string_casediff(teco_string_t a, const gchar *b, gsize b_len); -typedef gint (*teco_string_cmp_t)(const teco_string_t *a, const gchar *b, gsize b_len); -gint teco_string_cmp(const teco_string_t *a, const gchar *b, gsize b_len); -gint teco_string_casecmp(const teco_string_t *a, const gchar *b, gsize b_len); +typedef gint (*teco_string_cmp_t)(teco_string_t a, const gchar *b, gsize b_len); +gint teco_string_cmp(teco_string_t a, const gchar *b, gsize b_len); +gint teco_string_casecmp(teco_string_t a, const gchar *b, gsize b_len); /** @memberof teco_string_t */ static inline gboolean -teco_string_contains(const teco_string_t *str, gchar chr) +teco_string_contains(teco_string_t str, gchar chr) { - return str->data && memchr(str->data, chr, str->len); + return str.data && memchr(str.data, chr, str.len); } /** @@ -188,26 +191,26 @@ teco_string_contains(const teco_string_t *str, gchar chr) * @memberof teco_string_t */ static inline gint -teco_string_rindex(const teco_string_t *str, gchar chr) +teco_string_rindex(teco_string_t str, gchar chr) { gint i; - for (i = str->len-1; i >= 0 && str->data[i] != chr; i--); + for (i = str.len-1; i >= 0 && str.data[i] != chr; i--); return i; } -const gchar *teco_string_last_occurrence(const teco_string_t *str, const gchar *chars); +const gchar *teco_string_last_occurrence(teco_string_t str, const gchar *chars); /** * Validate whether string consists exclusively of valid UTF-8, but accept null bytes. * @note there is g_utf8_validate_len() in Glib 2.60 */ static inline gboolean -teco_string_validate_utf8(const teco_string_t *str) +teco_string_validate_utf8(teco_string_t str) { - const gchar *p = str->data; - while (!g_utf8_validate(p, str->len - (p - str->data), &p) && !*p) + const gchar *p = str.data; + while (!g_utf8_validate(p, str.len - (p - str.data), &p) && !*p) p++; - return p - str->data == str->len; + return p - str.data == str.len; } /** @memberof teco_string_t */ diff --git a/src/symbols.c b/src/symbols.c index caae09a..9c76183 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -139,7 +139,7 @@ teco_symbol_list_auto_complete(teco_symbol_list_t *ctx, const gchar *symbol, tec glist_str.data = (gchar *)glist->data + symbol_len; glist_str.len = strlen(glist_str.data); - gsize len = teco_string_casediff(&glist_str, (gchar *)entry->data + symbol_len, + gsize len = teco_string_casediff(glist_str, (gchar *)entry->data + symbol_len, strlen(entry->data) - symbol_len); if (!prefix_len || len < prefix_len) prefix_len = len; @@ -177,7 +177,7 @@ teco_scintilla_ssm(unsigned int iMessage, uptr_t wParam, sptr_t lParam) static teco_state_t teco_state_scintilla_lparam; static gboolean -teco_scintilla_parse_symbols(teco_machine_scintilla_t *scintilla, const teco_string_t *str, GError **error) +teco_scintilla_parse_symbols(teco_machine_scintilla_t *scintilla, teco_string_t str, GError **error) { if (teco_string_contains(str, '\0')) { g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED, @@ -185,7 +185,7 @@ teco_scintilla_parse_symbols(teco_machine_scintilla_t *scintilla, const teco_str return FALSE; } - g_auto(GStrv) symbols = g_strsplit(str->data, ",", -1); + g_auto(GStrv) symbols = g_strsplit(str.data, ",", -1); if (!symbols[0]) return TRUE; @@ -217,7 +217,7 @@ teco_scintilla_parse_symbols(teco_machine_scintilla_t *scintilla, const teco_str } static teco_state_t * -teco_state_scintilla_symbols_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_scintilla_symbols_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_scintilla_lparam; @@ -231,7 +231,7 @@ teco_state_scintilla_symbols_done(teco_machine_main_t *ctx, const teco_string_t teco_undo_scintilla_message(ctx->scintilla); memset(&ctx->scintilla, 0, sizeof(ctx->scintilla)); - if ((str->len > 0 && !teco_scintilla_parse_symbols(&ctx->scintilla, str, error)) || + if ((str.len > 0 && !teco_scintilla_parse_symbols(&ctx->scintilla, str, error)) || !teco_expressions_eval(FALSE, error)) return NULL; @@ -251,7 +251,7 @@ teco_state_scintilla_symbols_done(teco_machine_main_t *ctx, const teco_string_t /* in cmdline.c */ gboolean teco_state_scintilla_symbols_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *parent_ctx, gunichar key, GError **error); -gboolean teco_state_scintilla_symbols_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, +gboolean teco_state_scintilla_symbols_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error); /*$ ES scintilla message @@ -359,11 +359,11 @@ TECO_DEFINE_STATE_EXPECTSTRING(teco_state_scintilla_symbols, #ifdef HAVE_LEXILLA static gpointer -teco_create_lexer(const teco_string_t *str, GError **error) +teco_create_lexer(teco_string_t str, GError **error) { CreateLexerFn CreateLexerFn = CreateLexer; - const gchar *lexer = memchr(str->data ? : "", '\0', str->len); + const gchar *lexer = memchr(str.data ? : "", '\0', str.len); if (lexer) { /* external lexer */ lexer++; @@ -372,7 +372,7 @@ teco_create_lexer(const teco_string_t *str, GError **error) * NOTE: The same module can be opened multiple times. * They are internally reference counted. */ - GModule *module = g_module_open(str->data, G_MODULE_BIND_LAZY); + GModule *module = g_module_open(str.data, G_MODULE_BIND_LAZY); if (!module) { teco_error_module_set(error, "Error opening lexer module"); return NULL; @@ -394,7 +394,7 @@ teco_create_lexer(const teco_string_t *str, GError **error) * * FIXME: In Scintillua distributions, the lexers are usually contained in the * same directory as the prebuilt shared libraries. - * Perhaps we should default scintillua.lexers to the dirname in str->data? + * Perhaps we should default scintillua.lexers to the dirname in str.data? */ teco_qreg_t *reg = teco_qreg_table_find(&teco_qreg_table_globals, "$SCITECO_SCINTILLUA_LEXERS", 26); if (reg) { @@ -406,7 +406,7 @@ teco_create_lexer(const teco_string_t *str, GError **error) } } else { /* Lexilla lexer */ - lexer = str->data ? : ""; + lexer = str.data ? : ""; } ILexer5 *ret = CreateLexerFn(lexer); @@ -422,9 +422,9 @@ teco_create_lexer(const teco_string_t *str, GError **error) #else /* !HAVE_LEXILLA */ static gpointer -teco_create_lexer(const teco_string_t *str, GError **error) +teco_create_lexer(teco_string_t str, GError **error) { - g_autofree gchar *str_printable = teco_string_echo(str->data, str->len); + g_autofree gchar *str_printable = teco_string_echo(str.data, str.len); g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, "Cannot load lexer \"%s\": Lexilla disabled", str_printable); return NULL; @@ -433,7 +433,7 @@ teco_create_lexer(const teco_string_t *str, GError **error) #endif static teco_state_t * -teco_state_scintilla_lparam_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) +teco_state_scintilla_lparam_done(teco_machine_main_t *ctx, teco_string_t str, GError **error) { if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; @@ -466,13 +466,13 @@ teco_state_scintilla_lparam_done(teco_machine_main_t *ctx, const teco_string_t * } g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Style name \"%s\" not found.", str->data ? : ""); + "Style name \"%s\" not found.", str.data ? : ""); return NULL; } else if (ctx->scintilla.iMessage == SCI_SETILEXER) { lParam = (sptr_t)teco_create_lexer(str, error); if (!lParam) return NULL; - } else if (str->len > 0) { + } else if (str.len > 0) { /* * Theoretically, Scintilla could use null bytes from the string specified. * This could only be the case for messages where the string length is @@ -482,13 +482,13 @@ teco_state_scintilla_lparam_done(teco_machine_main_t *ctx, const teco_string_t * * which unlocks useful messages like * SCI_SETREPRESENTATIONS and SCI_SETPROPERTY. */ - const gchar *p = memchr(str->data, '\0', str->len); + const gchar *p = memchr(str.data, '\0', str.len); if (p) { - ctx->scintilla.wParam = (uptr_t)str->data; - if (str->len > p - str->data + 1) + ctx->scintilla.wParam = (uptr_t)str.data; + if (str.len > p - str.data + 1) lParam = (sptr_t)(p+1); } else { - lParam = (sptr_t)str->data; + lParam = (sptr_t)str.data; } } |
