чување c47cf92fdd1197b20e583a1648f943d8be445d4f
родитељ ef9e7169a5e49c44d590f1014add89112846e33e
Аутор: Страхиња Радић <sr@strahinja.org>
Датум: Wed, 31 Dec 2025 10:20:36 +0100
patch/syntax.patch: Fix literals containing \\
Diffstat:
| M | patch/syntax.patch | | | 105 | +++++++++++++++++++++++++++++++++++++++++-------------------------------------- |
измењених датотека: 1, додавања: 55(+), брисања: 50(-)
diff --git a/patch/syntax.patch b/patch/syntax.patch
@@ -1,6 +1,6 @@
-From 24ed247577196fa2d7075ea0bd4395d909b8f942 Mon Sep 17 00:00:00 2001
+From 37ca32661192c22cd2a68abe93a27333802f8e4e Mon Sep 17 00:00:00 2001
From: Страхиња Радић <sr@strahinja.org>
-Date: Sat Nov 2 09:46:14 2024 UTC
+Date: Wed Dec 31 09:17:44 2025 UTC
Subject: [PATCH] Add syntax highlighting
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
@@ -8,13 +8,13 @@ Content-Transfer-Encoding: 8bit
---
config.def.h | 7+ 0-
- draw.c | 613+ 31-
+ draw.c | 618+ 31-
draw.h | 76+ 6-
sled.c | 82+ 15-
- 4 files changed, 778 insertions(+), 52 deletions(-)
+ 4 files changed, 783 insertions(+), 52 deletions(-)
diff --git a/config.def.h b/config.def.h
-index 61d59a63a..24ed24757 100644
+index ef9e7169a..37ca32661 100644
--- a/config.def.h
+++ b/config.def.h
@@ -234,6 +234,13 @@ static const struct Key command_keys[] = {
@@ -32,7 +32,7 @@ index 61d59a63a..24ed24757 100644
{.format = "%s%s",
.callback = format_filename,
diff --git a/draw.c b/draw.c
-index 61d59a63a..24ed24757 100644
+index ef9e7169a..37ca32661 100644
--- a/draw.c
+++ b/draw.c
@@ -3,6 +3,7 @@
@@ -69,7 +69,7 @@ index 61d59a63a..24ed24757 100644
enum {
UNKNOWN_MODE,
COMMAND_MODE,
-@@ -86,6 +106,95 @@ static const struct {
+@@ -87,6 +107,95 @@ static const struct {
{ .boundary = 99, .width = 3 },
{ .boundary = 9, .width = 2 }
};
@@ -165,7 +165,7 @@ index 61d59a63a..24ed24757 100644
const char* go_to_dialog_title = "Go to line";
const char* prompt_dirty = "File changed, save [y/n/ESC]?";
const char* prompt_overwrite = "Not empty, overwrite? [y/n/ESC]?";
-@@ -94,6 +203,46 @@ const char* replace_dialog_title = "Replace with";
+@@ -95,6 +204,46 @@ const char* replace_dialog_title = "Replace with";
const char* search_dialog_title = "Search text";
/* clang-format on */
@@ -212,7 +212,7 @@ index 61d59a63a..24ed24757 100644
void get_selection(int* ssr, int* ssc, int* ser, int* sec,
const struct DrawState* state);
-@@ -267,14 +416,14 @@ draw_help(const struct DrawState* state)
+@@ -268,14 +417,14 @@ draw_help(const struct DrawState* state)
draw_box(startx, endx, starty, endy, colors[C_DLG].fg, colors[C_DLG].bg);
if (draw_string(startx, starty, colors[C_TITLE].fg, colors[C_TITLE].bg,
@@ -231,7 +231,7 @@ index 61d59a63a..24ed24757 100644
return 1;
row++;
}
-@@ -310,16 +459,16 @@ draw_input_dialog(const struct DrawState* state)
+@@ -311,16 +460,16 @@ draw_input_dialog(const struct DrawState* state)
colors[C_INPUT_EDIT].fg, colors[C_INPUT_EDIT].bg);
if (state->input_title)
if (draw_string(startx, starty, colors[C_TITLE].fg,
@@ -252,7 +252,7 @@ index 61d59a63a..24ed24757 100644
tb_set_cursor(startx + 2 + state->input_display_column
- state->input_first_shown_column,
starty + 1);
-@@ -341,7 +490,7 @@ draw_line_number(const struct DrawState* state, const
+@@ -342,7 +491,7 @@ draw_line_number(const struct DrawState* state, const
? numbuf_end - state->line_numbers_width
: numbuf;
draw_string(0, cy, colors[C_LINENO].fg, colors[C_LINENO].bg,
@@ -261,7 +261,7 @@ index 61d59a63a..24ed24757 100644
state->line_numbers_width, 0, 0, RIGHT, 0, 1, NULL, 0,
0, 0, 0, 0, 0);
}
-@@ -422,8 +571,9 @@ draw_screen(const struct DrawState* state)
+@@ -423,8 +572,9 @@ draw_screen(const struct DrawState* state)
? state->line_numbers_width + 2
: 0,
cy, colors[C_TEXT].fg, colors[C_TEXT].bg,
@@ -273,7 +273,7 @@ index 61d59a63a..24ed24757 100644
colors[C_SEARCH].bg, ssi, sei, colors[C_SEL].fg,
colors[C_SEL].bg);
i++;
-@@ -455,7 +605,7 @@ draw_status(const struct DrawState* state)
+@@ -456,7 +606,7 @@ draw_status(const struct DrawState* state)
if (IN(state->mode, M_PROMPT) && *state->prompt)
{
if (draw_string(0, state->maxy - 1, colors[C_PROMPT].fg,
@@ -282,7 +282,7 @@ index 61d59a63a..24ed24757 100644
strlen(state->prompt) + 2, maxx, 1, 1, CENTER, 0, 1,
NULL, 0, 0, 0, 0, 0, 0))
return 1;
-@@ -463,15 +613,15 @@ draw_status(const struct DrawState* state)
+@@ -464,15 +614,15 @@ draw_status(const struct DrawState* state)
else if (state->action)
{
if (draw_string(0, state->maxy - 1, colors[C_ACTION].fg,
@@ -301,7 +301,7 @@ index 61d59a63a..24ed24757 100644
strlen(errors[state->error]) + 2, maxx, 1, 1,
CENTER, 0, 1, NULL, 0, 0, 0, 0, 0, 0))
return 1;
-@@ -497,7 +647,7 @@ draw_status(const struct DrawState* state)
+@@ -498,7 +648,7 @@ draw_status(const struct DrawState* state)
seg_size = maxx - 1 - current_start;
if (draw_string(current_start, state->maxy - 1,
colors[pseg->color_index].fg,
@@ -310,7 +310,7 @@ index 61d59a63a..24ed24757 100644
MIN(seg_size, (ssize_t)(strlen(buf) + 2)),
last ? seg_size + 1 : seg_size, 1, 1,
pseg->alignment, 0, 1, NULL, 0, 0, 0, 0, 0,
-@@ -532,8 +682,9 @@ draw_status(const struct DrawState* state)
+@@ -533,8 +683,9 @@ draw_status(const struct DrawState* state)
* */
int
draw_string(const int x, const int y, const uint16_t fg, const uint16_t bg,
@@ -322,7 +322,7 @@ index 61d59a63a..24ed24757 100644
const uint32_t* srch, const uint16_t sfg, const uint16_t sbg,
const int ssi, const int sei, const uint16_t slfg, const uint16_t slbg)
{
-@@ -543,8 +694,8 @@ draw_string(const int x, const int y, const uint16_t f
+@@ -544,8 +695,8 @@ draw_string(const int x, const int y, const uint16_t f
if (!us)
return 1;
u8_string_to_unicode(us, s, mc);
@@ -333,7 +333,7 @@ index 61d59a63a..24ed24757 100644
free(us);
return 0;
}
-@@ -650,12 +801,15 @@ free_bufferline(struct BufferLine* bl)
+@@ -651,12 +802,15 @@ free_bufferline(struct BufferLine* bl)
bl->length = 0;
bl->fg = 0;
bl->bg = 0;
@@ -349,7 +349,7 @@ index 61d59a63a..24ed24757 100644
assert(state != NULL);
for (row = 0; row < state->buffer_size; row++)
free_bufferline(state->buffer + row);
-@@ -669,11 +823,13 @@ init_bufferline(struct BufferLine* bl)
+@@ -670,11 +824,13 @@ init_bufferline(struct BufferLine* bl)
{
if (!bl)
return;
@@ -368,7 +368,7 @@ index 61d59a63a..24ed24757 100644
}
void
-@@ -698,6 +854,14 @@ init_drawstate(struct DrawState* state, char* filename
+@@ -699,6 +855,14 @@ init_drawstate(struct DrawState* state, char* filename
state->orig_real_filename = NULL;
state->backup_filename = NULL;
state->rfn_len = 0;
@@ -383,7 +383,7 @@ index 61d59a63a..24ed24757 100644
}
state->input = NULL;
state->search = NULL;
-@@ -756,7 +920,402 @@ recalculate_size(struct DrawState* state)
+@@ -757,7 +921,407 @@ recalculate_size(struct DrawState* state)
recalculate_line_numbers(state);
}
@@ -673,8 +673,10 @@ index 61d59a63a..24ed24757 100644
+ if (quote)
+ {
+ while ((ti < curline->length)
-+ && (((ti > 0) && (curline->text[ti - 1] == L'\\'))
-+ || (curline->text[ti] != quote)))
++ && (((ti == 1 && curline->text[ti - 1] == '\\')
++ || (ti > 1 && curline->text[ti - 2] != '\\'
++ && curline->text[ti - 1] == '\\'))
++ || curline->text[ti] != quote))
+ ti++;
+ if (curline->text[ti] == quote)
+ {
@@ -694,7 +696,10 @@ index 61d59a63a..24ed24757 100644
+ }
+
+ assert(quote == 0);
-+ if (((ti == 0) || ((ti > 0) && (curline->text[ti - 1] != L'\\')))
++ if ((ti == 0 || (ti == 1 && curline->text[ti - 1] != '\\')
++ || (ti > 1
++ && (curline->text[ti - 2] == '\\'
++ || curline->text[ti - 1] != '\\')))
+ && ((curline->text[ti] == '"') || (curline->text[ti] == '\'')))
+ {
+ quote = curline->text[ti];
@@ -786,7 +791,7 @@ index 61d59a63a..24ed24757 100644
redraw_status(struct DrawState* state)
{
assert(state != NULL);
-@@ -787,7 +1346,8 @@ redraw_status(struct DrawState* state)
+@@ -788,7 +1352,8 @@ redraw_status(struct DrawState* state)
* */
void
u32_draw_string(const int x, const int y, const uint16_t fg, const uint16_t bg,
@@ -796,7 +801,7 @@ index 61d59a63a..24ed24757 100644
const int p_r, const Alignment align, const int ds, const int fill,
const uint32_t* srch, const uint16_t sfg, const uint16_t sbg,
const int ssi, const int sei, const uint16_t slfg, const uint16_t slbg)
-@@ -825,6 +1385,8 @@ u32_draw_string(const int x, const int y, const uint16
+@@ -826,6 +1391,8 @@ u32_draw_string(const int x, const int y, const uint16
int w = 0; /* actual on-screen rune width */
@@ -805,7 +810,7 @@ index 61d59a63a..24ed24757 100644
const int ts = TAB_SIZE;
const uint32_t* ps = s; /* pointer to current character in
-@@ -833,11 +1395,23 @@ u32_draw_string(const int x, const int y, const uint16
+@@ -834,11 +1401,23 @@ u32_draw_string(const int x, const int y, const uint16
uint16_t cfg = fg; /* current fg */
uint16_t cbg = bg; /* current bg */
@@ -829,7 +834,7 @@ index 61d59a63a..24ed24757 100644
c = mc - p_l - p_r;
if (align == LEFT)
-@@ -869,7 +1443,12 @@ u32_draw_string(const int x, const int y, const uint16
+@@ -870,7 +1449,12 @@ u32_draw_string(const int x, const int y, const uint16
*/
while (*ps && sc < c)
{
@@ -843,7 +848,7 @@ index 61d59a63a..24ed24757 100644
{
cfg = slfg;
cbg = slbg;
-@@ -886,6 +1465,9 @@ u32_draw_string(const int x, const int y, const uint16
+@@ -887,6 +1471,9 @@ u32_draw_string(const int x, const int y, const uint16
}
}
@@ -853,7 +858,7 @@ index 61d59a63a..24ed24757 100644
if (*ps == '\t')
{
if (ssc < ds)
-@@ -1001,11 +1583,11 @@ u32_draw_string(const int x, const int y, const uint16
+@@ -1002,11 +1589,11 @@ u32_draw_string(const int x, const int y, const uint16
}
ssc += w;
}
@@ -870,7 +875,7 @@ index 61d59a63a..24ed24757 100644
}
diff --git a/draw.h b/draw.h
-index 61d59a63a..24ed24757 100644
+index ef9e7169a..37ca32661 100644
--- a/draw.h
+++ b/draw.h
@@ -63,17 +63,69 @@ struct Color {
@@ -1007,7 +1012,7 @@ index 61d59a63a..24ed24757 100644
+ const uint16_t sbg, const int ssi, const int sei, const uint16_t slfg,
+ const uint16_t slbg);
diff --git a/sled.c b/sled.c
-index 61d59a63a..24ed24757 100644
+index ef9e7169a..37ca32661 100644
--- a/sled.c
+++ b/sled.c
@@ -50,6 +50,18 @@ extern const char* prompt_reread_dirty;
@@ -1029,7 +1034,7 @@ index 61d59a63a..24ed24757 100644
static int
cancel_close(struct DrawState* state)
{
-@@ -175,8 +187,9 @@ create_file(struct DrawState* state)
+@@ -178,8 +190,9 @@ create_file(struct DrawState* state)
state->buffer_size = ALLOC_DELTA;
state->rows_count = 1;
recalculate_line_numbers(state);
@@ -1041,7 +1046,7 @@ index 61d59a63a..24ed24757 100644
return 0;
}
-@@ -307,6 +320,7 @@ do_search_replace(struct DrawState* state)
+@@ -310,6 +323,7 @@ do_search_replace(struct DrawState* state)
state->buffer[row].length = buflen;
}
free(buf);
@@ -1049,7 +1054,7 @@ index 61d59a63a..24ed24757 100644
return 0;
do_search_replace_alloc_error:
-@@ -357,7 +371,8 @@ erase_backwards(struct DrawState* state)
+@@ -360,7 +374,8 @@ erase_backwards(struct DrawState* state)
buffer_line->text[i - 1] = 0;
buffer_line->length--;
position_to(state, state->coord.row, state->coord.col - 1);
@@ -1059,7 +1064,7 @@ index 61d59a63a..24ed24757 100644
}
else if (state->coord.row > 0)
{
-@@ -394,7 +409,8 @@ erase_forward(struct DrawState* state)
+@@ -397,7 +412,8 @@ erase_forward(struct DrawState* state)
}
buffer_line->text[i] = 0;
buffer_line->length--;
@@ -1069,7 +1074,7 @@ index 61d59a63a..24ed24757 100644
}
else if ((state->coord.row + 1) < state->rows_count)
simple_join_lines(state);
-@@ -428,7 +444,8 @@ erase_line(struct DrawState* state)
+@@ -431,7 +447,8 @@ erase_line(struct DrawState* state)
state->coord.row--;
position_to(state, state->coord.row, 0);
state->rows_count--;
@@ -1079,7 +1084,7 @@ index 61d59a63a..24ed24757 100644
recalculate_line_numbers(state);
return 0;
-@@ -467,6 +484,7 @@ erase_prev_word(struct DrawState* state)
+@@ -470,6 +487,7 @@ erase_prev_word(struct DrawState* state)
state->coord.col = i;
state->display_column = display_length(current->text, state->coord.col);
state->dirty = 1;
@@ -1087,7 +1092,7 @@ index 61d59a63a..24ed24757 100644
return 0;
}
-@@ -522,7 +540,8 @@ erase_selection(struct DrawState* state)
+@@ -525,7 +543,8 @@ erase_selection(struct DrawState* state)
recalculate_line_numbers(state);
}
free(buf);
@@ -1097,7 +1102,7 @@ index 61d59a63a..24ed24757 100644
}
return 0;
}
-@@ -547,7 +566,8 @@ erase_to_end(struct DrawState* state)
+@@ -550,7 +569,8 @@ erase_to_end(struct DrawState* state)
buffer_line->text[state->coord.col] = 0;
buffer_line->length = state->coord.col;
move_end(state);
@@ -1107,7 +1112,7 @@ index 61d59a63a..24ed24757 100644
return 0;
}
-@@ -581,7 +601,8 @@ erase_to_start(struct DrawState* state)
+@@ -584,7 +604,8 @@ erase_to_start(struct DrawState* state)
buffer_line->text[len - state->coord.col] = 0;
buffer_line->length = len - state->coord.col;
move_start(state);
@@ -1117,7 +1122,7 @@ index 61d59a63a..24ed24757 100644
return 0;
}
-@@ -1130,8 +1151,8 @@ insert_char(struct DrawState* state, uint32_t ch)
+@@ -1146,8 +1167,8 @@ insert_char(struct DrawState* state, uint32_t ch)
}
insert_skip_wrap:
@@ -1128,7 +1133,7 @@ index 61d59a63a..24ed24757 100644
return 0;
insert_char_error:
-@@ -1182,7 +1203,8 @@ insert_skip_wrap:
+@@ -1198,7 +1219,8 @@ insert_skip_wrap:
simple_insert_line(state);
state->saved_column = -1;
position_to(state, state->coord.row + 1, 0);
@@ -1138,7 +1143,7 @@ index 61d59a63a..24ed24757 100644
return 0;
}
-@@ -1704,7 +1726,8 @@ paste_from_paste(struct DrawState* state)
+@@ -1731,7 +1753,8 @@ paste_from_paste(struct DrawState* state)
}
position_to(state, newpos.row, newpos.col);
@@ -1148,7 +1153,7 @@ index 61d59a63a..24ed24757 100644
paste_from_paste_cleanup:
free(rest);
-@@ -1970,6 +1993,7 @@ reread_file(struct DrawState* state)
+@@ -1997,6 +2020,7 @@ reread_file(struct DrawState* state)
}
recalculate_line_numbers(state);
@@ -1156,7 +1161,7 @@ index 61d59a63a..24ed24757 100644
return 0;
}
-@@ -2357,6 +2381,7 @@ simple_join_lines(struct DrawState* state)
+@@ -2394,6 +2418,7 @@ simple_join_lines(struct DrawState* state)
state->rows_count--;
state->dirty = 1;
recalculate_line_numbers(state);
@@ -1164,7 +1169,7 @@ index 61d59a63a..24ed24757 100644
return;
simple_join_lines_error:
-@@ -2831,6 +2856,8 @@ main(int argc, char** argv)
+@@ -2868,6 +2893,8 @@ main(int argc, char** argv)
int dir_access;
int dir_access_errno;
int saved_errno;
@@ -1173,7 +1178,7 @@ index 61d59a63a..24ed24757 100644
*prompt = 0;
-@@ -2913,6 +2940,40 @@ main(int argc, char** argv)
+@@ -2950,6 +2977,40 @@ main(int argc, char** argv)
init_drawstate(&state, filename, prompt, 0, 0);
@@ -1214,7 +1219,7 @@ index 61d59a63a..24ed24757 100644
#ifdef __OpenBSD__
if (unveil(state.filename, "rwc") < 0)
{
-@@ -3122,9 +3183,10 @@ main_skip_backups:
+@@ -3158,9 +3219,10 @@ main_skip_backups:
init_termbox:
if (tb_init())
goto main_done;
@@ -1228,7 +1233,7 @@ index 61d59a63a..24ed24757 100644
while (state.running)
{
-@@ -3136,6 +3198,11 @@ init_termbox:
+@@ -3172,6 +3234,11 @@ init_termbox:
recalculate_size(&state);
state.recalculate_size = 0;
}