aboutsummaryrefslogtreecommitdiffstats
path: root/common.h
blob: e39cdc7dedd7796733e9c2a1655f247de892e5ce (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
/* 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

// default to 80 columns
#define DEFAULT_WIDTH 80

struct Row {
	int 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 {
	int 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?

	int numrows;
	struct Row *rows;
};

extern struct Buffer B;

// 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