aboutsummaryrefslogtreecommitdiffhomepage
path: root/sciteco.h
blob: 37f1af4de15b75a19d008894fc26684528f2090d (plain)
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
#ifndef __SCITECO_H
#define __SCITECO_H

#include <stdarg.h>

#include <glib.h>
#include <gtk/gtk.h>
#include "gtk-info-popup.h"

#include <Scintilla.h>

extern gchar *cmdline;
extern bool quit_requested;

extern GtkInfoPopup *filename_popup;

void message_display(GtkMessageType type,
		     const gchar *fmt, ...) G_GNUC_PRINTF(2, 3);

void cmdline_keypress(gchar key);
void cmdline_display(const gchar *cmdline);

sptr_t editor_msg(unsigned int iMessage, uptr_t wParam = 0, sptr_t lParam = 0);

#define IS_CTL(C)	((C) < ' ')
#define CTL_ECHO(C)	((C) | 0x40)
#define CTL_KEY(C)	((C) & ~0x40)

typedef gint64 tecoBool;

#define SUCCESS		(-1)
#define FAILURE		(0)
#define TECO_BOOL(X)	((X) ? SUCCESS : FAILURE)

#define IS_SUCCESS(X)	((X) < 0)
#define IS_FAILURE(X)	(!IS_SUCCESS(X))

/* TECO uses only lower 7 bits for commands */
#define MAX_TRANSITIONS	127

namespace String {

static inline void
append(gchar *&str1, const gchar *str2)
{
	/* FIXME: optimize */
	gchar *new_str = g_strconcat(str1 ? : "", str2, NULL);
	g_free(str1);
	str1 = new_str;
}

static inline void
append(gchar *&str, gchar chr)
{
	append(str, (gchar []){chr, '\0'});
}

} /* namespace String */

namespace Validate {

static inline bool
pos(gint n)
{
	return n >= 0 && n <= editor_msg(SCI_GETLENGTH);
}

static inline bool
line(gint n)
{
	return n >= 0 && n < editor_msg(SCI_GETLINECOUNT);
}

} /* namespace Validate */

#endif