File: util.h

package info (click to toggle)
aoeui 1.7%2B20160302.git4e5dee9-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 532 kB
  • sloc: ansic: 6,860; makefile: 294; sh: 11
file content (76 lines) | stat: -rw-r--r-- 2,882 bytes parent folder | download | duplicates (4)
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
/* Copyright 2007, 2008 Peter Klausler.  See COPYING for license. */
#ifndef UTIL_H
#define UTIL_H

/* Utilities */

struct view;

/* find.c */
position_t find_line_start(struct view *, position_t);
position_t find_line_end(struct view *, position_t);
position_t find_paragraph_start(struct view *, position_t);
position_t find_paragraph_end(struct view *, position_t);
position_t find_line_up(struct view *, position_t);
position_t find_line_down(struct view *, position_t);
position_t find_space(struct view *, position_t);
position_t find_space_prior(struct view *, position_t);
position_t find_nonspace(struct view *, position_t);
position_t find_nonspace_prior(struct view *, position_t);
position_t find_word_start(struct view *, position_t);
position_t find_word_end(struct view *, position_t);
position_t find_id_start(struct view *, position_t);
position_t find_id_end(struct view *, position_t);
position_t find_sentence_start(struct view *, position_t);
position_t find_sentence_end(struct view *, position_t);
sposition_t find_corresponding_bracket(struct view *, position_t);
position_t find_line_number(struct view *, unsigned line);
unsigned current_line_number(struct view *, position_t);
position_t find_row_bytes(struct view *, position_t,
			unsigned column, unsigned columns);
unsigned find_column(unsigned *row, struct view *, position_t linestart,
		     position_t offset, unsigned start_column);
sposition_t find_string(struct view *, const char *, position_t);

const char *path_format(const char *);	/* file.c */

void find_tag(struct view *);	/* tags.c */

ssize_t view_vprintf(struct view *, const char *, va_list);
ssize_t view_printf(struct view *, const char *, ...);
size_t view_get_selection(struct view *, position_t *offset, Boolean_t *append);
char *view_extract(struct view *, position_t, unsigned bytes);
char *view_extract_selection(struct view *);
size_t view_delete_selection(struct view *);
struct view *view_next(struct view *);

Unicode_t view_unicode(struct view *, position_t, size_t *);
Unicode_t view_unicode_prior(struct view *, position_t, position_t *prev);
Unicode_t view_char(struct view *, position_t, size_t *);
Unicode_t view_char_prior(struct view *, position_t, position_t *prev);
Boolean_t is_open_bracket(const char *, Unicode_t);
Boolean_t is_close_bracket(const char *, Unicode_t);

void keyword_init(struct text *);			/* keyword.c */
Boolean_t is_keyword(struct view *, position_t);

INLINE Boolean_t is_wordch(Unicode_t ch)
{
	return ch > 0x100 && ch < FOLD_START || IS_CODEPOINT(ch) && isalnum(ch);
}

INLINE Boolean_t is_idch(Unicode_t ch)
{
	return ch == '_' || is_wordch(ch);
}

INLINE unsigned char_columns(Unicode_t ch, unsigned column, unsigned tabstop)
{
	if (ch == '\t')
		return tabstop - column % tabstop;
	if (ch < ' ' || ch == 0x7f || IS_FOLDED(ch))
		return 2; /* ^X or folded <> */
	return 1;
}

#endif