File: mono-debugger-readline.c

package info (click to toggle)
mono-debugger 0.60%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 9,556 kB
  • ctags: 22,787
  • sloc: ansic: 99,407; cs: 42,429; sh: 9,192; makefile: 376
file content (125 lines) | stat: -rw-r--r-- 2,181 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "config.h"
#include <mono-debugger-readline.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

extern int rl_catch_signals;
extern int rl_attempted_completion_over;

static gboolean in_readline = FALSE;

void
mono_debugger_readline_static_init (void)
{
	rl_catch_signals = 1;
	// rl_set_signals ();

	rl_readline_name = "mdb";
	rl_terminal_name = getenv ("TERM");
}

int
mono_debugger_readline_is_a_tty (int fd)
{
	return isatty (fd);
}

char *
mono_debugger_readline_readline (const char *prompt)
{
	char *line;
	char *retval = NULL;

	g_assert (!in_readline);
	in_readline = TRUE;

	line = readline (prompt);
	retval = g_strdup (line);
	if (line)
		free (line);

	in_readline = FALSE;
	return retval;
}

void
mono_debugger_readline_add_history (const char *line)
{
	add_history (line);
}

char*
mono_debugger_readline_current_line_buffer (void)
{
	return g_strdup (rl_line_buffer);
}

extern int
mono_debugger_readline_get_columns (void)
{
	int cols = 80;

#if 0 /* FIXME */
	rl_get_screen_size (NULL, &cols);
#endif

	return cols;
}


/* Completion stuff */

int
mono_debugger_readline_get_filename_completion_desired (void)
{
	return rl_filename_completion_desired;
}
    
void
mono_debugger_readline_set_filename_completion_desired (int v)
{
	rl_filename_completion_desired = v;
}

static CompletionDelegate completion_cb;
static char **my_completion_matches = NULL;

void
mono_debugger_readline_set_completion_matches (char **matches, int count)
{
	int i;

	rl_attempted_completion_over = 1;

	if (count == 0){
		my_completion_matches = NULL;
		return;
	}

	my_completion_matches = (char**)malloc (count * sizeof (char*));
	  
	for (i = 0; i < count; i ++)
		my_completion_matches[i] = matches[i] ? strdup (matches[i]) : NULL;
}

static char**
mono_debugger_readline_completion_function (const char *text, int start, int end)
{
	my_completion_matches = NULL;

	if (completion_cb) {
		completion_cb (text, start, end);
	}
	return my_completion_matches;
}

void
mono_debugger_readline_enable_completion (CompletionDelegate cb)
{
	rl_attempted_completion_function = mono_debugger_readline_completion_function;

	completion_cb = cb;
}