aboutsummaryrefslogtreecommitdiffstats
path: root/common.h
blob: 535ae6b7543e313ad93c9a85ae37390fc2de57b3 (plain) (blame)
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
/* Copyright (c) 2021 nytpu <alex@nytpu.com>
 * SPDX-License-Identifier: GPL-3.0-only
 * For more license details, see LICENSE or <https://www.gnu.org/licenses/gpl-3.0.html>.
 */

#pragma once
#ifndef _COMMON_H
#define _COMMON_H

#include <stdbool.h>

// ensure that regex.h and other headers follow POSIX 2008/2017
#define _POSIX_C_SOURCE 200809L
// XXX: possibly stop mandating C11/C17.  AFAIK the only C11 feature I'm using
//      is anonymous structs/unions, which seem to be supported in GCC's &
//      Clang's extensions to C99?
#define _ISOC11_SOURCE

// should be set to proper number by preprocessor
#ifndef VERSION
#define VERSION " Unknown"
#endif // VERSION

// default to 80 columns
#define DEFAULT_WIDTH 80

typedef long RowNum;

struct Row {
	RowNum idx;      // Row number (zero-based)
	int size;      // Size of row (including trailing \n\0)
	char *chars;   // Row content
};

// doubles as an editor state/editor config struct as well
struct Buffer {
	RowNum crow; // current row address
	int scols; // number of columns we can display on screen

	char *filename;
	bool dirty; // has the buffer been modified since last write?

	RowNum numrows;
	struct Row *rows;

	const char *last_err; // verbose error message for last error that occurred
};

struct Options {
	bool prompt_enabled;
	char *prompt;
	bool quiet;
	bool verbose;
};

extern struct Buffer B;
extern struct Options O;

// print the current perror then exit failure
void die(const char *m);

// initialize global struct Buffer to null/zero values
void editor_init(void);

#endif // _COMMON_H