aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sciteco.h
blob: 65b8e9a52c026f13053253fc2474a42b30068419 (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
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
/*
 * Copyright (C) 2012-2014 Robin Haberkorn
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __SCITECO_H
#define __SCITECO_H

#include <signal.h>

#include <glib.h>

#include "interface.h"

#if TECO_INTEGER == 32
typedef gint32 tecoInt;
#define TECO_INTEGER_FORMAT G_GINT32_FORMAT
#elif TECO_INTEGER == 64
typedef gint64 tecoInt;
#define TECO_INTEGER_FORMAT G_GINT64_FORMAT
#else
#error Invalid TECO integer storage size
#endif
typedef tecoInt tecoBool;

namespace Flags {
	enum {
		ED_HOOKS	= (1 << 5),
		ED_FNKEYS	= (1 << 6)
	};

	extern tecoInt ed;
}

extern sig_atomic_t sigint_occurred;

/*
 * for sentinels: NULL might not be defined as a
 * pointer type (LLVM/CLang)
 */
#define NIL		((void *)0)

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

#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))

/*
 * NOTE: compound literals are temporaries beginning with
 * g++ 4.7
 */
#define CHR2STR(X, ...) \
	({gchar str[] = {(X), ##__VA_ARGS__, '\0'}; str;})

namespace String {

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

static inline void
append(gchar *&str, gchar chr)
{
	append(str, CHR2STR(chr));
}

/* in main.cpp */
void get_coord(const gchar *str, gint pos,
	       gint &line, gint &column);

static inline gsize
diff(const gchar *a, const gchar *b)
{
	gsize len = 0;

	while (*a != '\0' && *a++ == *b++)
		len++;

	return len;
}

} /* namespace String */

namespace Validate {

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

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

} /* namespace Validate */

#endif