1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-12 23:10:51 +00:00

[terminal] exec_on_terminal and related rewritten a bit to allow const param

This commit is contained in:
Witold Filipczyk 2022-01-30 18:12:38 +01:00
parent e0e88dc5a7
commit 277f341d2b
6 changed files with 33 additions and 14 deletions

View File

@ -463,7 +463,7 @@ set_clipboard_text(char *data)
/* Set xterm-like term window's title. */
void
set_window_title(char *title, int codepage)
set_window_title(const char *ctitle, int codepage)
{
struct string filtered;
@ -472,10 +472,19 @@ set_window_title(char *title, int codepage)
if (!is_xterm()) return;
#endif
if (!init_string(&filtered)) return;
if (!init_string(&filtered)) {
return;
}
/* Copy title to filtered if different from NULL */
if (title) {
if (ctitle) {
char *title = stracpy(ctitle);
if (!title) {
done_string(&filtered);
return;
}
char *scan = title;
char *end = title + strlen(title);
@ -488,7 +497,7 @@ set_window_title(char *title, int codepage)
* potential alternative set_window_title() routines might
* want to take different precautions. */
for (;;) {
char *charbegin = scan;
const char *charbegin = scan;
unicode_val_T unicode
= cp_to_unicode(codepage, &scan, end);
int charlen = scan - charbegin;
@ -519,6 +528,7 @@ set_window_title(char *title, int codepage)
add_bytes_to_string(&filtered, charbegin, charlen);
}
mem_free(title);
}
/* Send terminal escape sequence + title string */

View File

@ -42,7 +42,7 @@ void resume_mouse(void *);
int start_thread(void (*)(void *, int), void *, int);
char *get_clipboard_text(void);
void set_clipboard_text(char *);
void set_window_title(char *, int codepage);
void set_window_title(const char *, int codepage);
char *get_window_title(int codepage);
void block_stdin(void);
void unblock_stdin(void);

View File

@ -483,15 +483,22 @@ free_itrm(struct itrm *itrm)
* @a text should look like "width,height,old-width,old-height"
* where width and height are integers. */
static inline void
resize_terminal_from_str(char *text)
resize_terminal_from_str(const char *text_)
{
enum { NEW_WIDTH = 0, NEW_HEIGHT, OLD_WIDTH, OLD_HEIGHT, NUMBERS };
int numbers[NUMBERS];
int i;
char *text2, *text;
assert(text && *text);
assert(text_ && *text_);
if_assert_failed return;
text2 = stracpy(text_);
if (!text2) {
return;
}
text = text2;
for (i = 0; i < NUMBERS; i++) {
char *p = strchr(text, ',');
@ -499,6 +506,7 @@ resize_terminal_from_str(char *text)
*p++ = '\0';
} else if (i < OLD_HEIGHT) {
mem_free(text2);
return;
}
@ -510,10 +518,11 @@ resize_terminal_from_str(char *text)
resize_window(numbers[NEW_WIDTH], numbers[NEW_HEIGHT],
numbers[OLD_WIDTH], numbers[OLD_HEIGHT]);
resize_terminal();
mem_free(text2);
}
void
dispatch_special(char *text)
dispatch_special(const char *text)
{
switch (text[0]) {
case TERM_FN_TITLE:

View File

@ -139,7 +139,7 @@ void block_itrm(void);
int unblock_itrm(void);
void free_all_itrms(void);
void resize_terminal(void);
void dispatch_special(char *);
void dispatch_special(const char *);
void kbd_ctrl_c(void);
int is_blocked(void);
void get_terminal_name(char[MAX_TERM_LEN]);

View File

@ -278,7 +278,7 @@ assert_terminal_ptr_not_dangling(const struct terminal *suspect)
static void
exec_on_master_terminal(struct terminal *term,
char *path, int plen,
char *delete_, int dlen,
const char *delete_, int dlen,
term_exec_T fg)
{
int blockh;
@ -320,8 +320,8 @@ exec_on_master_terminal(struct terminal *term,
static void
exec_on_slave_terminal( struct terminal *term,
char *path, int plen,
char *delete_, int dlen,
char *path, int plen,
const char *delete_, int dlen,
term_exec_T fg)
{
int data_size = plen + dlen + 1 /* 0 */ + 1 /* fg */ + 2 /* 2 null char */;
@ -339,7 +339,7 @@ exec_on_slave_terminal( struct terminal *term,
void
exec_on_terminal(struct terminal *term, char *path,
char *delete_, term_exec_T fg)
const char *delete_, term_exec_T fg)
{
if (path) {
if (!*path) return;

View File

@ -232,7 +232,7 @@ enum term_exec {
typedef int term_exec_T;
void exec_on_terminal(struct terminal *, char *, char *, term_exec_T);
void exec_on_terminal(struct terminal *, char *, const char *, term_exec_T);
void exec_shell(struct terminal *term);
int set_terminal_title(struct terminal *, char *);