2004-05-29 10:17:37 +00:00
|
|
|
/*
|
|
|
|
|
* Hexadecimal modes for QEmacs.
|
2007-12-03 16:10:38 +00:00
|
|
|
*
|
2014-01-04 17:26:30 +00:00
|
|
|
* Copyright (c) 2000-2001 Fabrice Bellard.
|
Remove references to global `qe_state` (#45)
* Remove references to global `qe_state`
Add `QEmacsState *qs` field in context and object structures:
- `QEditScreen`, `EditState` (renamed from `qe_state`), `QuitState`
- `WinWindow` (win32.c), `X11State` (x11.c), `QEArgs` (cmd line arguments)
- `CmdLineOptionDef::func_arg()`, `QEModeData`
- move `QEKeyContext` to `QEmacsState`
Pass `QEmacsState *qs` to configuration and state functions:
- all `module_xxx_init` and static `xxx_init` functions
- `QEDisplay::dpy_init()`, `qe_register_display()`, `screen_init()̀`
- `load_input_methods()`, `unload_input_methods()`
- `register_input_method()`, `find_input_method()`
- `find_resource_file()`, `open_resource_file()`
- `qe_find_current_binding()`, `qe_list_bindings()`
- `qe_register_mode()`, `qe_find_mode()`, `qe_find_mode_filename()`
- `qe_register_cmd_line_options()`, `set_user_option()`, `set_tty_charset()`
- `qe_register_commands()`, `qe_register_bindings()`, `qe_find_cmd()`
- `qe_register_completion()`, `qe_register_variables()`
- `eb_register_data_type()`, `parse_command_line()`
- `eb_trace_bytes()`, `qe_toggle_control_h()` (split from `do_toggle_control_h()`)
- `unget_key()`, `qe_grab_keys()`, `qe_ungrab_keys()`, `qe_key_process()`
- `eb_new()`, `eb_find()`, `eb_find_new()`, `eb_scratch()`, `eb_find_file()`
- `new_shell_buffer()` `macro_add_key()`, `clear_macro(), `stop_macro()`
- `check_window()`, `check_buffer()`, `qe_kill_buffer()`, `qe_get_history()`
- `qe_register_charset()`, `find_charset()`
Add error message handlers:
- add `QEDisplay::dpy_error()` method
- add `qe_cfg_error()`, use for all expression parsing errors
- pass opaque pointer to `css_error()`
- add `qe_put_error()` and `qe_dpy_error()`
Add context argument:
- always pass a non-null window pointer to `do_refresh()`, `new_help_buffer()`
Rename functions:
- `find_resource_file` -> `qe_find_resource_file`
- `open_resource_file` -> `qe_open_resource_file`
- `input_methods_init` -> `qe_input_methods_init`
- `load_input_methods` -> `qe_load_input_methods`
- `unload_input_methods` -> `qe_unload_input_methods`
- `find_input_methods` -> `qe_find_input_methods`
- `register_input_method` -> `qe_register_input_method`
- `parse_command_line` -> `qe_parse_command_line`
- `eb_trace_bytes` -> `qe_trace_bytes`
- `eb_init` -> `qe_data_init`
- `eb_count_buffers` -> `qe_count_buffers`
- `eb_get_buffer_from_index` -> `qe_get_buffer_from_index`
- `init_all_modules` -> `qe_init_all_modules`
- `exit_all_modules` -> `qe_exit_all_modules`
- `load_all_modules` -> `qe_load_all_modules`
- `maybe_set_mark` -> `do_maybe_set_mark`
- `unget_key` -> `qe_unget_key`
- `minibuffer_init` -> `qe_minibuffer_init`
- `edit_display` -> `qe_display`
- `new_yank_buffer` -> `qe_new_yank_buffer`
- `new_shell_buffer` -> `qe_new_shell_buffer`
- `shell_find_mode` -> `qe_shell_find_mode`
- `save_selection` -> `qe_save_selection`
- `register_emulation_bindings` -> `qe_register_emulation_bindings`
- `macro_add_key` -> `qe_macro_add_key`
- `clear_macro` -> `qe_clear_macro`
- `stop_macro` -> `qe_stop_macro`
- `eb_format_message` -> `qe_format_message`
- `screen_init` -> `qe_screen_init`
- `charset_jis_init` -> `qe_charset_jis_init`
- `charset_more_init` -> `qe_charset_more_init`
- `check_window` -> `qe_check_window`
- `check_buffer` -> `qe_check_buffer`
- `eb_find_file` -> `qe_find_buffer_file`
- `eb_find` -> `qe_find_buffer_name`
- `eb_new` -> `qe_new_buffer`
- `eb_find_new` -> `qe_new_buffer` with `BC_REUSE`
- `eb_scratch` -> `qe_new_buffer` with `BC_REUSE | BC_CLEAR`
- `find_charset` -> `qe_find_charset`
Add asan, msan and ubsan targets
Fix `qe_encode64` buffer length computation.
Add `qe_new_shell_buffer` flags `SF_REUSE_BUFFER` and `SF_ERASE_BUFFER`
Bumped version to 6.3.3
fix redundant typedef
fix compilation errors
2024-12-01 23:34:00 +01:00
|
|
|
* Copyright (c) 2002-2024 Charlie Gordon.
|
2004-05-29 10:17:37 +00:00
|
|
|
*
|
2023-03-05 02:04:02 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2004-05-29 10:17:37 +00:00
|
|
|
*
|
2023-03-05 02:04:02 +01:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
2004-05-29 10:17:37 +00:00
|
|
|
*
|
2023-03-05 02:04:02 +01:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
* THE SOFTWARE.
|
2004-05-29 10:17:37 +00:00
|
|
|
*/
|
2007-12-03 16:10:38 +00:00
|
|
|
|
2004-05-29 10:17:37 +00:00
|
|
|
#include "qe.h"
|
|
|
|
|
|
2014-04-02 12:58:12 +00:00
|
|
|
enum {
|
|
|
|
|
HEX_STYLE_OFFSET = QE_STYLE_COMMENT,
|
|
|
|
|
HEX_STYLE_DUMP = QE_STYLE_FUNCTION,
|
|
|
|
|
};
|
|
|
|
|
|
2017-04-16 21:51:19 +00:00
|
|
|
static ModeDef hex_mode;
|
|
|
|
|
|
2024-10-13 12:27:11 +02:00
|
|
|
static int bin_to_disp(int c)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
2024-10-13 12:27:11 +02:00
|
|
|
#if 0
|
2007-12-18 12:17:10 +00:00
|
|
|
/* Allow characters in range 160-255 to show as graphics */
|
2024-10-13 12:27:11 +02:00
|
|
|
// XXX: This causes alignment issues on screen remove sessions
|
|
|
|
|
// eg: C-x C-d C-s ligatures
|
2007-12-18 12:17:10 +00:00
|
|
|
if ((c & 127) < ' ' || c == 127)
|
|
|
|
|
c = '.';
|
|
|
|
|
#else
|
2004-05-29 10:17:37 +00:00
|
|
|
if (c < ' ' || c >= 127)
|
|
|
|
|
c = '.';
|
2007-12-18 12:17:10 +00:00
|
|
|
#endif
|
2004-05-29 10:17:37 +00:00
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int hex_backward_offset(EditState *s, int offset)
|
|
|
|
|
{
|
2015-08-13 23:26:59 +00:00
|
|
|
return align(offset, s->dump_width);
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
2016-12-23 15:51:51 +00:00
|
|
|
static int hex_display_line(EditState *s, DisplayState *ds, int offset)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
2008-04-05 18:16:30 +00:00
|
|
|
int j, len, ateof;
|
2008-04-22 09:04:20 +00:00
|
|
|
int offset1, offset2;
|
2004-05-29 10:17:37 +00:00
|
|
|
unsigned char b;
|
|
|
|
|
|
|
|
|
|
display_bol(ds);
|
|
|
|
|
|
2014-04-02 12:58:12 +00:00
|
|
|
ds->style = HEX_STYLE_OFFSET;
|
2026-03-14 21:21:31 +01:00
|
|
|
display_printf(ds, -1, -1, "%08x ", (unsigned)offset);
|
2008-01-09 13:41:40 +00:00
|
|
|
|
2008-04-05 18:16:30 +00:00
|
|
|
ateof = 0;
|
2004-05-29 10:17:37 +00:00
|
|
|
len = s->b->total_size - offset;
|
2015-08-13 23:26:59 +00:00
|
|
|
if (len > s->dump_width)
|
|
|
|
|
len = s->dump_width;
|
2008-04-22 09:04:20 +00:00
|
|
|
|
2004-05-29 10:17:37 +00:00
|
|
|
if (s->mode == &hex_mode) {
|
2008-04-22 09:04:20 +00:00
|
|
|
|
2014-04-02 12:58:12 +00:00
|
|
|
ds->style = HEX_STYLE_DUMP;
|
2008-04-22 09:04:20 +00:00
|
|
|
|
2015-08-13 23:26:59 +00:00
|
|
|
for (j = 0; j < s->dump_width; j++) {
|
2004-05-29 10:17:37 +00:00
|
|
|
display_char(ds, -1, -1, ' ');
|
|
|
|
|
offset1 = offset + j;
|
2008-04-22 09:04:20 +00:00
|
|
|
offset2 = offset1 + 1;
|
2004-05-29 10:17:37 +00:00
|
|
|
if (j < len) {
|
2008-04-22 09:04:20 +00:00
|
|
|
eb_read(s->b, offset1, &b, 1);
|
|
|
|
|
display_printhex(ds, offset1, offset2, b, 2);
|
2004-05-29 10:17:37 +00:00
|
|
|
} else {
|
2008-04-05 18:16:30 +00:00
|
|
|
if (!ateof) {
|
|
|
|
|
ateof = 1;
|
2004-05-29 10:17:37 +00:00
|
|
|
} else {
|
2008-04-22 09:04:20 +00:00
|
|
|
offset1 = offset2 = -1;
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
2008-04-22 09:04:20 +00:00
|
|
|
ds->cur_hex_mode = s->hex_mode;
|
|
|
|
|
display_printf(ds, offset1, offset2, " ");
|
|
|
|
|
ds->cur_hex_mode = 0;
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
2008-01-09 13:41:40 +00:00
|
|
|
if ((j & 7) == 7)
|
2004-05-29 10:17:37 +00:00
|
|
|
display_char(ds, -1, -1, ' ');
|
|
|
|
|
}
|
|
|
|
|
display_char(ds, -1, -1, ' ');
|
|
|
|
|
}
|
2008-01-09 13:41:40 +00:00
|
|
|
ds->style = 0;
|
|
|
|
|
|
2008-04-22 09:04:20 +00:00
|
|
|
display_char(ds, -1, -1, ' ');
|
|
|
|
|
|
2008-04-05 18:16:30 +00:00
|
|
|
ateof = 0;
|
2015-08-13 23:26:59 +00:00
|
|
|
for (j = 0; j < s->dump_width; j++) {
|
2004-05-29 10:17:37 +00:00
|
|
|
offset1 = offset + j;
|
2008-04-22 09:04:20 +00:00
|
|
|
offset2 = offset1 + 1;
|
2004-05-29 10:17:37 +00:00
|
|
|
if (j < len) {
|
2008-04-22 09:04:20 +00:00
|
|
|
eb_read(s->b, offset1, &b, 1);
|
2004-05-29 10:17:37 +00:00
|
|
|
} else {
|
|
|
|
|
b = ' ';
|
2008-04-05 18:16:30 +00:00
|
|
|
if (!ateof) {
|
|
|
|
|
ateof = 1;
|
2004-05-29 10:17:37 +00:00
|
|
|
} else {
|
2008-04-22 09:04:20 +00:00
|
|
|
offset1 = offset2 = -1;
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-10-13 12:27:11 +02:00
|
|
|
display_char(ds, offset1, offset2, bin_to_disp(b));
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
|
|
|
|
display_eol(ds, -1, -1);
|
|
|
|
|
|
2015-08-13 23:26:59 +00:00
|
|
|
if (len >= s->dump_width)
|
2008-04-22 09:04:20 +00:00
|
|
|
return offset + len;
|
2004-05-29 10:17:37 +00:00
|
|
|
else
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-31 19:34:00 +00:00
|
|
|
static void do_set_width(EditState *s, int w)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
|
|
|
|
if (w >= 1) {
|
2015-08-13 23:26:59 +00:00
|
|
|
s->dump_width = w;
|
2016-12-23 15:51:51 +00:00
|
|
|
s->offset_top = s->mode->backward_offset(s, s->offset_top);
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-15 14:33:30 +02:00
|
|
|
static void do_increase_width(EditState *s, int n)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
2022-08-15 14:33:30 +02:00
|
|
|
do_set_width(s, s->dump_width + n);
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
2006-12-31 19:34:00 +00:00
|
|
|
static void do_toggle_hex(EditState *s)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
|
|
|
|
s->hex_mode = !s->hex_mode;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-05 13:39:05 +01:00
|
|
|
/* common binary and hex commands */
|
2022-08-16 22:39:51 +02:00
|
|
|
static const CmdDef binary_commands[] = {
|
2023-07-08 22:54:49 +02:00
|
|
|
CMD2( "decrease-width", "C-left",
|
2022-08-19 12:13:52 +02:00
|
|
|
"Decrease the number of bytes displayed on each row",
|
2022-08-19 16:52:26 +02:00
|
|
|
do_increase_width, ESi, "q")
|
2023-07-08 22:54:49 +02:00
|
|
|
CMD2( "increase-width", "C-right",
|
2022-08-19 12:13:52 +02:00
|
|
|
"Increase the number of bytes displayed on each row",
|
2022-08-19 16:52:26 +02:00
|
|
|
do_increase_width, ESi, "p")
|
2022-08-16 22:39:51 +02:00
|
|
|
CMD2( "set-width", "",
|
2022-08-19 12:13:52 +02:00
|
|
|
"Set the number of bytes displayed on each row",
|
2022-08-16 22:39:51 +02:00
|
|
|
do_set_width, ESi,
|
2022-08-19 17:47:41 +02:00
|
|
|
"N{Width: }")
|
2022-08-16 22:39:51 +02:00
|
|
|
CMD3( "goto-byte", "M-g",
|
2022-08-19 12:13:52 +02:00
|
|
|
"Move point to a specified location",
|
|
|
|
|
do_goto, ESsi,
|
Improve command argument parsing
- add description placeholders to all CMDx definitions
- swap arguments to qe_split_window() and do_split_window()
- pass iteration count based on universal argument to
do_up_down(), do_left_right(), do_word_right(), do_kill_word(),
do_forward_paragraph(), do_kill_paragraph(), do_c_forward_conditional(),
do_forward_block(), do_kill_block(),
- remove do_backward_paragraph()
- add int eb_prev_paragraph(EditBuffer *b, int offset);
- dont call command on 0 universal prefix
2020-11-01 19:03:20 +01:00
|
|
|
"s{Goto byte: }"
|
2022-08-19 12:13:52 +02:00
|
|
|
"v", 'b')
|
2020-11-05 13:39:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* specific hex commands and bindings */
|
2022-08-16 22:39:51 +02:00
|
|
|
static const CmdDef hex_commands[] = {
|
|
|
|
|
CMD0( "toggle-hex", "TAB, S-TAB",
|
2022-08-19 12:13:52 +02:00
|
|
|
"Switch between the hex side and binary side",
|
|
|
|
|
do_toggle_hex)
|
2004-05-29 10:17:37 +00:00
|
|
|
};
|
|
|
|
|
|
2014-06-01 13:54:58 +00:00
|
|
|
static int binary_mode_init(EditState *s, EditBuffer *b, int flags)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
2014-06-01 13:54:58 +00:00
|
|
|
if (s) {
|
|
|
|
|
int num_width;
|
|
|
|
|
|
|
|
|
|
/* get typical number width */
|
2016-12-27 10:13:46 +00:00
|
|
|
num_width = get_glyph_width(s->screen, s, QE_STYLE_DEFAULT, '0');
|
2014-06-01 13:54:58 +00:00
|
|
|
|
2015-08-13 23:26:59 +00:00
|
|
|
s->dump_width = s->screen->width / num_width;
|
|
|
|
|
if (s->b->flags & BF_PREVIEW)
|
|
|
|
|
s->dump_width = s->dump_width * 4 / 5;
|
|
|
|
|
|
|
|
|
|
s->dump_width -= 10;
|
2014-06-01 13:54:58 +00:00
|
|
|
/* align on 16 byte boundary */
|
2015-08-13 23:26:59 +00:00
|
|
|
s->dump_width &= ~15;
|
|
|
|
|
if (s->dump_width < 16)
|
|
|
|
|
s->dump_width = 16;
|
2014-06-01 13:54:58 +00:00
|
|
|
s->hex_mode = 0;
|
2015-08-26 22:51:24 +00:00
|
|
|
s->unihex_mode = 0;
|
2022-08-29 18:41:29 +02:00
|
|
|
s->overwrite = 1;
|
2017-04-25 17:41:27 +00:00
|
|
|
/* XXX: should come from mode.default_wrap */
|
2014-06-01 13:54:58 +00:00
|
|
|
s->wrap = WRAP_TRUNCATE;
|
|
|
|
|
}
|
2004-05-29 10:17:37 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-01 13:54:58 +00:00
|
|
|
static int hex_mode_init(EditState *s, EditBuffer *b, int flags)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
2014-06-01 13:54:58 +00:00
|
|
|
if (s) {
|
2015-08-13 23:26:59 +00:00
|
|
|
s->dump_width = 16;
|
2014-06-01 13:54:58 +00:00
|
|
|
s->hex_mode = 1;
|
|
|
|
|
s->hex_nibble = 0;
|
2015-08-26 22:51:24 +00:00
|
|
|
s->unihex_mode = 0;
|
2022-08-29 18:41:29 +02:00
|
|
|
s->overwrite = 1;
|
2017-04-25 17:41:27 +00:00
|
|
|
/* XXX: should come from mode.default_wrap */
|
2014-06-01 13:54:58 +00:00
|
|
|
s->wrap = WRAP_TRUNCATE;
|
|
|
|
|
}
|
2004-05-29 10:17:37 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-31 19:34:00 +00:00
|
|
|
static int detect_binary(const unsigned char *buf, int size)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
2022-03-21 16:30:28 +01:00
|
|
|
const uint32_t magic = ((1U << '\b') | (1U << '\t') | (1U << '\f') |
|
|
|
|
|
(1U << '\n') | (1U << '\r') | (1U << '\033') |
|
|
|
|
|
(1U << 0x0e) | (1U << 0x0f) | (1U << 0x1a) |
|
|
|
|
|
(1U << '\a') | (1U << 0x1f));
|
2004-05-29 10:17:37 +00:00
|
|
|
int i, c;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
|
c = buf[i];
|
2017-03-15 23:17:58 +00:00
|
|
|
if (c < 32 && !(magic & (1U << c)))
|
2005-05-11 15:12:14 +00:00
|
|
|
return 1;
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-04 17:26:30 +00:00
|
|
|
static int hex_mode_probe(ModeDef *mode, ModeProbeData *p)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
|
|
|
|
if (detect_binary(p->buf, p->buf_size))
|
|
|
|
|
return 50;
|
|
|
|
|
else
|
2007-12-18 12:17:10 +00:00
|
|
|
return 10;
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
2006-12-31 19:34:00 +00:00
|
|
|
static void hex_move_bol(EditState *s)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
2015-08-13 23:26:59 +00:00
|
|
|
s->offset = align(s->offset, s->dump_width);
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
2006-12-31 19:34:00 +00:00
|
|
|
static void hex_move_eol(EditState *s)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
Various improvements for consistency
* add -Wno-packed compiler option
* add CONFIG_REGEX flag, undefined for tiny build
* disable regex commands in tiny build
* add documentation for some search commands and APIs
* reorder search tags for readability
* add isearch_yank_char
* use emacs names for:
isearch-repeat-backward, isearch-repeat-forward,
isearch-ring-advance, isearch-ring-retreat,
isearch-yank-word-or-char
* add occur alias for list-matching-lines
* add char32_to_utf8()
* restored some macros in cutils.h:
likely(x), unlikely(x), __maybe_unused, BOOL, FALSE, TRUE
* remove max(), min(), maxp(), minp(), clampp()
* add typed arithmetic functions:
min_int(), max_int(), clamp_int(), min3_int(), max3_int()
min_offset(), max_offset(), clamp_offset()
* use typed functions everywhere
* bump version to 5.4.1d
2022-11-21 00:20:18 +01:00
|
|
|
s->offset = min_offset(align(s->offset, s->dump_width) + s->dump_width - 1,
|
|
|
|
|
s->b->total_size);
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
2006-12-31 19:34:00 +00:00
|
|
|
static void hex_move_left_right(EditState *s, int dir)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
Various improvements for consistency
* add -Wno-packed compiler option
* add CONFIG_REGEX flag, undefined for tiny build
* disable regex commands in tiny build
* add documentation for some search commands and APIs
* reorder search tags for readability
* add isearch_yank_char
* use emacs names for:
isearch-repeat-backward, isearch-repeat-forward,
isearch-ring-advance, isearch-ring-retreat,
isearch-yank-word-or-char
* add occur alias for list-matching-lines
* add char32_to_utf8()
* restored some macros in cutils.h:
likely(x), unlikely(x), __maybe_unused, BOOL, FALSE, TRUE
* remove max(), min(), maxp(), minp(), clampp()
* add typed arithmetic functions:
min_int(), max_int(), clamp_int(), min3_int(), max3_int()
min_offset(), max_offset(), clamp_offset()
* use typed functions everywhere
* bump version to 5.4.1d
2022-11-21 00:20:18 +01:00
|
|
|
s->offset = clamp_offset(s->offset + dir, 0, s->b->total_size);
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
2006-12-31 19:34:00 +00:00
|
|
|
static void hex_move_up_down(EditState *s, int dir)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
Various improvements for consistency
* add -Wno-packed compiler option
* add CONFIG_REGEX flag, undefined for tiny build
* disable regex commands in tiny build
* add documentation for some search commands and APIs
* reorder search tags for readability
* add isearch_yank_char
* use emacs names for:
isearch-repeat-backward, isearch-repeat-forward,
isearch-ring-advance, isearch-ring-retreat,
isearch-yank-word-or-char
* add occur alias for list-matching-lines
* add char32_to_utf8()
* restored some macros in cutils.h:
likely(x), unlikely(x), __maybe_unused, BOOL, FALSE, TRUE
* remove max(), min(), maxp(), minp(), clampp()
* add typed arithmetic functions:
min_int(), max_int(), clamp_int(), min3_int(), max3_int()
min_offset(), max_offset(), clamp_offset()
* use typed functions everywhere
* bump version to 5.4.1d
2022-11-21 00:20:18 +01:00
|
|
|
s->offset = clamp_offset(s->offset + dir * s->dump_width, 0, s->b->total_size);
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void hex_write_char(EditState *s, int key)
|
|
|
|
|
{
|
2022-10-29 19:43:38 +02:00
|
|
|
char32_t cur_ch, ch;
|
2004-05-29 10:17:37 +00:00
|
|
|
int hsize, shift, cur_len, len, h;
|
2014-01-31 14:50:56 +00:00
|
|
|
int offset = s->offset;
|
2004-05-29 10:17:37 +00:00
|
|
|
char buf[10];
|
2008-01-03 09:51:29 +00:00
|
|
|
|
2004-05-29 10:17:37 +00:00
|
|
|
if (s->hex_mode) {
|
|
|
|
|
if (s->unihex_mode)
|
2014-01-12 01:39:10 +00:00
|
|
|
hsize = s->unihex_mode;
|
2004-05-29 10:17:37 +00:00
|
|
|
else
|
|
|
|
|
hsize = 2;
|
2019-03-27 07:43:56 +00:00
|
|
|
h = qe_digit_value(key);
|
|
|
|
|
if (h >= 16)
|
2004-05-29 10:17:37 +00:00
|
|
|
return;
|
2022-08-29 18:41:29 +02:00
|
|
|
if ((!s->overwrite || offset >= s->b->total_size) && s->hex_nibble == 0) {
|
2004-05-29 10:17:37 +00:00
|
|
|
ch = h << ((hsize - 1) * 4);
|
2014-01-06 09:40:20 +00:00
|
|
|
if (s->unihex_mode || s->b->charset->char_size > 1) {
|
2022-10-29 19:43:38 +02:00
|
|
|
len = eb_encode_char32(s->b, buf, ch);
|
2004-05-29 10:17:37 +00:00
|
|
|
} else {
|
|
|
|
|
len = 1;
|
|
|
|
|
buf[0] = ch;
|
|
|
|
|
}
|
2014-01-31 14:50:56 +00:00
|
|
|
eb_insert(s->b, offset, buf, len);
|
2004-05-29 10:17:37 +00:00
|
|
|
} else {
|
|
|
|
|
if (s->unihex_mode) {
|
2014-01-31 14:50:56 +00:00
|
|
|
cur_ch = eb_nextc(s->b, offset, &cur_len);
|
|
|
|
|
cur_len -= offset;
|
2004-05-29 10:17:37 +00:00
|
|
|
} else {
|
2014-01-31 14:50:56 +00:00
|
|
|
eb_read(s->b, offset, buf, 1);
|
2022-10-29 19:43:38 +02:00
|
|
|
cur_ch = (u8)buf[0];
|
2004-05-29 10:17:37 +00:00
|
|
|
cur_len = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shift = (hsize - s->hex_nibble - 1) * 4;
|
|
|
|
|
ch = (cur_ch & ~(0xf << shift)) | (h << shift);
|
|
|
|
|
|
|
|
|
|
if (s->unihex_mode) {
|
2022-10-29 19:43:38 +02:00
|
|
|
len = eb_encode_char32(s->b, buf, ch);
|
2004-05-29 10:17:37 +00:00
|
|
|
} else {
|
|
|
|
|
len = 1;
|
|
|
|
|
buf[0] = ch;
|
|
|
|
|
}
|
2007-12-26 11:09:34 +00:00
|
|
|
#if 1
|
2022-08-28 20:28:40 +02:00
|
|
|
// XXX: offset and mark may be udated differently
|
2014-01-31 14:50:56 +00:00
|
|
|
eb_replace(s->b, offset, cur_len, buf, len);
|
2007-12-26 11:09:34 +00:00
|
|
|
#else
|
2004-05-29 10:17:37 +00:00
|
|
|
if (cur_len == len) {
|
2014-01-31 14:50:56 +00:00
|
|
|
eb_write(s->b, offset, buf, len);
|
2004-05-29 10:17:37 +00:00
|
|
|
} else {
|
2014-01-31 14:50:56 +00:00
|
|
|
eb_delete(s->b, offset, cur_len);
|
|
|
|
|
eb_insert(s->b, offset, buf, len);
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
2007-12-26 11:09:34 +00:00
|
|
|
#endif
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
2014-01-31 14:50:56 +00:00
|
|
|
s->offset = offset;
|
2004-05-29 10:17:37 +00:00
|
|
|
if (++s->hex_nibble == hsize) {
|
|
|
|
|
s->hex_nibble = 0;
|
2014-01-31 14:50:56 +00:00
|
|
|
if (offset < s->b->total_size)
|
2004-05-29 10:17:37 +00:00
|
|
|
s->offset += len;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-08-28 20:28:40 +02:00
|
|
|
// XXX: should use overwrite mode?
|
2004-05-29 10:17:37 +00:00
|
|
|
text_write_char(s, key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-16 14:00:28 +00:00
|
|
|
static void hex_mode_line(EditState *s, buf_t *out)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
2014-01-16 14:00:28 +00:00
|
|
|
basic_mode_line(s, out, '-');
|
2026-03-14 21:21:31 +01:00
|
|
|
buf_printf(out, "--0x%x--0x%x", (unsigned)s->offset, (unsigned)s->b->total_size);
|
2014-01-16 14:00:28 +00:00
|
|
|
buf_printf(out, "--%d%%", compute_percent(s->offset, s->b->total_size));
|
2004-05-29 10:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
2015-08-13 23:26:59 +00:00
|
|
|
static int binary_mode_probe(ModeDef *mode, ModeProbeData *p)
|
|
|
|
|
{
|
|
|
|
|
return 5;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-04 17:26:30 +00:00
|
|
|
static ModeDef binary_mode = {
|
|
|
|
|
.name = "binary",
|
2015-08-13 23:26:59 +00:00
|
|
|
.mode_probe = binary_mode_probe,
|
2014-01-04 17:26:30 +00:00
|
|
|
.mode_init = binary_mode_init,
|
2016-12-23 15:51:51 +00:00
|
|
|
.display_line = hex_display_line,
|
|
|
|
|
.backward_offset = hex_backward_offset,
|
2007-12-06 17:43:47 +00:00
|
|
|
.move_up_down = hex_move_up_down,
|
|
|
|
|
.move_left_right = hex_move_left_right,
|
|
|
|
|
.move_bol = hex_move_bol,
|
|
|
|
|
.move_eol = hex_move_eol,
|
2016-12-23 15:51:51 +00:00
|
|
|
.move_bof = text_move_bof,
|
|
|
|
|
.move_eof = text_move_eof,
|
2020-11-05 13:39:05 +01:00
|
|
|
.move_word_left_right = text_move_word_left_right,
|
2007-12-06 17:43:47 +00:00
|
|
|
.scroll_up_down = text_scroll_up_down,
|
|
|
|
|
.mouse_goto = text_mouse_goto,
|
2016-06-07 08:56:39 +00:00
|
|
|
.write_char = text_write_char,
|
2008-01-18 17:03:35 +00:00
|
|
|
.get_mode_line = hex_mode_line,
|
2004-05-29 10:17:37 +00:00
|
|
|
};
|
|
|
|
|
|
2017-04-16 21:51:19 +00:00
|
|
|
static ModeDef hex_mode = {
|
2014-01-04 17:26:30 +00:00
|
|
|
.name = "hex",
|
2007-12-06 17:43:47 +00:00
|
|
|
.mode_probe = hex_mode_probe,
|
2008-01-03 09:51:29 +00:00
|
|
|
.mode_init = hex_mode_init,
|
2016-12-23 15:51:51 +00:00
|
|
|
.display_line = hex_display_line,
|
|
|
|
|
.backward_offset = hex_backward_offset,
|
2007-12-06 17:43:47 +00:00
|
|
|
.move_up_down = hex_move_up_down,
|
|
|
|
|
.move_left_right = hex_move_left_right,
|
|
|
|
|
.move_bol = hex_move_bol,
|
|
|
|
|
.move_eol = hex_move_eol,
|
2016-12-23 15:51:51 +00:00
|
|
|
.move_bof = text_move_bof,
|
|
|
|
|
.move_eof = text_move_eof,
|
2020-11-05 13:39:05 +01:00
|
|
|
.move_word_left_right = text_move_word_left_right,
|
2007-12-06 17:43:47 +00:00
|
|
|
.scroll_up_down = text_scroll_up_down,
|
|
|
|
|
.mouse_goto = text_mouse_goto,
|
2016-06-07 08:56:39 +00:00
|
|
|
.write_char = hex_write_char,
|
2008-01-18 17:03:35 +00:00
|
|
|
.get_mode_line = hex_mode_line,
|
2020-11-05 13:39:05 +01:00
|
|
|
.fallback = &binary_mode,
|
2004-05-29 10:17:37 +00:00
|
|
|
};
|
|
|
|
|
|
2024-05-19 19:15:08 +02:00
|
|
|
static int hex_init(QEmacsState *qs)
|
2004-05-29 10:17:37 +00:00
|
|
|
{
|
|
|
|
|
/* first register mode(s) */
|
Remove references to global `qe_state` (#45)
* Remove references to global `qe_state`
Add `QEmacsState *qs` field in context and object structures:
- `QEditScreen`, `EditState` (renamed from `qe_state`), `QuitState`
- `WinWindow` (win32.c), `X11State` (x11.c), `QEArgs` (cmd line arguments)
- `CmdLineOptionDef::func_arg()`, `QEModeData`
- move `QEKeyContext` to `QEmacsState`
Pass `QEmacsState *qs` to configuration and state functions:
- all `module_xxx_init` and static `xxx_init` functions
- `QEDisplay::dpy_init()`, `qe_register_display()`, `screen_init()̀`
- `load_input_methods()`, `unload_input_methods()`
- `register_input_method()`, `find_input_method()`
- `find_resource_file()`, `open_resource_file()`
- `qe_find_current_binding()`, `qe_list_bindings()`
- `qe_register_mode()`, `qe_find_mode()`, `qe_find_mode_filename()`
- `qe_register_cmd_line_options()`, `set_user_option()`, `set_tty_charset()`
- `qe_register_commands()`, `qe_register_bindings()`, `qe_find_cmd()`
- `qe_register_completion()`, `qe_register_variables()`
- `eb_register_data_type()`, `parse_command_line()`
- `eb_trace_bytes()`, `qe_toggle_control_h()` (split from `do_toggle_control_h()`)
- `unget_key()`, `qe_grab_keys()`, `qe_ungrab_keys()`, `qe_key_process()`
- `eb_new()`, `eb_find()`, `eb_find_new()`, `eb_scratch()`, `eb_find_file()`
- `new_shell_buffer()` `macro_add_key()`, `clear_macro(), `stop_macro()`
- `check_window()`, `check_buffer()`, `qe_kill_buffer()`, `qe_get_history()`
- `qe_register_charset()`, `find_charset()`
Add error message handlers:
- add `QEDisplay::dpy_error()` method
- add `qe_cfg_error()`, use for all expression parsing errors
- pass opaque pointer to `css_error()`
- add `qe_put_error()` and `qe_dpy_error()`
Add context argument:
- always pass a non-null window pointer to `do_refresh()`, `new_help_buffer()`
Rename functions:
- `find_resource_file` -> `qe_find_resource_file`
- `open_resource_file` -> `qe_open_resource_file`
- `input_methods_init` -> `qe_input_methods_init`
- `load_input_methods` -> `qe_load_input_methods`
- `unload_input_methods` -> `qe_unload_input_methods`
- `find_input_methods` -> `qe_find_input_methods`
- `register_input_method` -> `qe_register_input_method`
- `parse_command_line` -> `qe_parse_command_line`
- `eb_trace_bytes` -> `qe_trace_bytes`
- `eb_init` -> `qe_data_init`
- `eb_count_buffers` -> `qe_count_buffers`
- `eb_get_buffer_from_index` -> `qe_get_buffer_from_index`
- `init_all_modules` -> `qe_init_all_modules`
- `exit_all_modules` -> `qe_exit_all_modules`
- `load_all_modules` -> `qe_load_all_modules`
- `maybe_set_mark` -> `do_maybe_set_mark`
- `unget_key` -> `qe_unget_key`
- `minibuffer_init` -> `qe_minibuffer_init`
- `edit_display` -> `qe_display`
- `new_yank_buffer` -> `qe_new_yank_buffer`
- `new_shell_buffer` -> `qe_new_shell_buffer`
- `shell_find_mode` -> `qe_shell_find_mode`
- `save_selection` -> `qe_save_selection`
- `register_emulation_bindings` -> `qe_register_emulation_bindings`
- `macro_add_key` -> `qe_macro_add_key`
- `clear_macro` -> `qe_clear_macro`
- `stop_macro` -> `qe_stop_macro`
- `eb_format_message` -> `qe_format_message`
- `screen_init` -> `qe_screen_init`
- `charset_jis_init` -> `qe_charset_jis_init`
- `charset_more_init` -> `qe_charset_more_init`
- `check_window` -> `qe_check_window`
- `check_buffer` -> `qe_check_buffer`
- `eb_find_file` -> `qe_find_buffer_file`
- `eb_find` -> `qe_find_buffer_name`
- `eb_new` -> `qe_new_buffer`
- `eb_find_new` -> `qe_new_buffer` with `BC_REUSE`
- `eb_scratch` -> `qe_new_buffer` with `BC_REUSE | BC_CLEAR`
- `find_charset` -> `qe_find_charset`
Add asan, msan and ubsan targets
Fix `qe_encode64` buffer length computation.
Add `qe_new_shell_buffer` flags `SF_REUSE_BUFFER` and `SF_ERASE_BUFFER`
Bumped version to 6.3.3
fix redundant typedef
fix compilation errors
2024-12-01 23:34:00 +01:00
|
|
|
qe_register_mode(qs, &binary_mode, MODEF_VIEW);
|
|
|
|
|
qe_register_mode(qs, &hex_mode, MODEF_VIEW);
|
2004-05-29 10:17:37 +00:00
|
|
|
|
|
|
|
|
/* commands and default keys */
|
Remove references to global `qe_state` (#45)
* Remove references to global `qe_state`
Add `QEmacsState *qs` field in context and object structures:
- `QEditScreen`, `EditState` (renamed from `qe_state`), `QuitState`
- `WinWindow` (win32.c), `X11State` (x11.c), `QEArgs` (cmd line arguments)
- `CmdLineOptionDef::func_arg()`, `QEModeData`
- move `QEKeyContext` to `QEmacsState`
Pass `QEmacsState *qs` to configuration and state functions:
- all `module_xxx_init` and static `xxx_init` functions
- `QEDisplay::dpy_init()`, `qe_register_display()`, `screen_init()̀`
- `load_input_methods()`, `unload_input_methods()`
- `register_input_method()`, `find_input_method()`
- `find_resource_file()`, `open_resource_file()`
- `qe_find_current_binding()`, `qe_list_bindings()`
- `qe_register_mode()`, `qe_find_mode()`, `qe_find_mode_filename()`
- `qe_register_cmd_line_options()`, `set_user_option()`, `set_tty_charset()`
- `qe_register_commands()`, `qe_register_bindings()`, `qe_find_cmd()`
- `qe_register_completion()`, `qe_register_variables()`
- `eb_register_data_type()`, `parse_command_line()`
- `eb_trace_bytes()`, `qe_toggle_control_h()` (split from `do_toggle_control_h()`)
- `unget_key()`, `qe_grab_keys()`, `qe_ungrab_keys()`, `qe_key_process()`
- `eb_new()`, `eb_find()`, `eb_find_new()`, `eb_scratch()`, `eb_find_file()`
- `new_shell_buffer()` `macro_add_key()`, `clear_macro(), `stop_macro()`
- `check_window()`, `check_buffer()`, `qe_kill_buffer()`, `qe_get_history()`
- `qe_register_charset()`, `find_charset()`
Add error message handlers:
- add `QEDisplay::dpy_error()` method
- add `qe_cfg_error()`, use for all expression parsing errors
- pass opaque pointer to `css_error()`
- add `qe_put_error()` and `qe_dpy_error()`
Add context argument:
- always pass a non-null window pointer to `do_refresh()`, `new_help_buffer()`
Rename functions:
- `find_resource_file` -> `qe_find_resource_file`
- `open_resource_file` -> `qe_open_resource_file`
- `input_methods_init` -> `qe_input_methods_init`
- `load_input_methods` -> `qe_load_input_methods`
- `unload_input_methods` -> `qe_unload_input_methods`
- `find_input_methods` -> `qe_find_input_methods`
- `register_input_method` -> `qe_register_input_method`
- `parse_command_line` -> `qe_parse_command_line`
- `eb_trace_bytes` -> `qe_trace_bytes`
- `eb_init` -> `qe_data_init`
- `eb_count_buffers` -> `qe_count_buffers`
- `eb_get_buffer_from_index` -> `qe_get_buffer_from_index`
- `init_all_modules` -> `qe_init_all_modules`
- `exit_all_modules` -> `qe_exit_all_modules`
- `load_all_modules` -> `qe_load_all_modules`
- `maybe_set_mark` -> `do_maybe_set_mark`
- `unget_key` -> `qe_unget_key`
- `minibuffer_init` -> `qe_minibuffer_init`
- `edit_display` -> `qe_display`
- `new_yank_buffer` -> `qe_new_yank_buffer`
- `new_shell_buffer` -> `qe_new_shell_buffer`
- `shell_find_mode` -> `qe_shell_find_mode`
- `save_selection` -> `qe_save_selection`
- `register_emulation_bindings` -> `qe_register_emulation_bindings`
- `macro_add_key` -> `qe_macro_add_key`
- `clear_macro` -> `qe_clear_macro`
- `stop_macro` -> `qe_stop_macro`
- `eb_format_message` -> `qe_format_message`
- `screen_init` -> `qe_screen_init`
- `charset_jis_init` -> `qe_charset_jis_init`
- `charset_more_init` -> `qe_charset_more_init`
- `check_window` -> `qe_check_window`
- `check_buffer` -> `qe_check_buffer`
- `eb_find_file` -> `qe_find_buffer_file`
- `eb_find` -> `qe_find_buffer_name`
- `eb_new` -> `qe_new_buffer`
- `eb_find_new` -> `qe_new_buffer` with `BC_REUSE`
- `eb_scratch` -> `qe_new_buffer` with `BC_REUSE | BC_CLEAR`
- `find_charset` -> `qe_find_charset`
Add asan, msan and ubsan targets
Fix `qe_encode64` buffer length computation.
Add `qe_new_shell_buffer` flags `SF_REUSE_BUFFER` and `SF_ERASE_BUFFER`
Bumped version to 6.3.3
fix redundant typedef
fix compilation errors
2024-12-01 23:34:00 +01:00
|
|
|
qe_register_commands(qs, &binary_mode, binary_commands, countof(binary_commands));
|
|
|
|
|
qe_register_commands(qs, &hex_mode, hex_commands, countof(hex_commands));
|
2008-01-03 09:51:29 +00:00
|
|
|
|
2004-05-29 10:17:37 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qe_module_init(hex_init);
|