aboutsummaryrefslogtreecommitdiffstats
path: root/common.h
diff options
context:
space:
mode:
authornytpu <alex@nytpu.com>2021-05-31 15:45:37 -0600
committernytpu <alex@nytpu.com>2021-05-31 18:23:39 -0600
commit1f5d4354ad79468ca9ec776fbd7a07aeaef1764a (patch)
treeb632eb1ec79858cb7d1dfa1a171e490940dbcace /common.h
parentadd editor_deinit() (diff)
downloaded-1f5d4354ad79468ca9ec776fbd7a07aeaef1764a.tar.bz2
ed-1f5d4354ad79468ca9ec776fbd7a07aeaef1764a.zip
major refactor, struct Buffer and struct Options merged into one Editor state struct
Diffstat (limited to 'common.h')
-rw-r--r--common.h42
1 files changed, 21 insertions, 21 deletions
diff --git a/common.h b/common.h
index 01a5f11..4cfd805 100644
--- a/common.h
+++ b/common.h
@@ -8,12 +8,13 @@
#define _COMMON_H
#include <stdbool.h>
+#include <stddef.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?
+// XXX: possibly stop mandating C11/C17. AFAIK the only C11 features I'm using
+// are anonymous structs/unions and noreturn, which seem to be supported
+// in GCC's & Clang's extensions to C99?
#define _ISOC11_SOURCE
// should be set to proper number by preprocessor
@@ -27,34 +28,33 @@
typedef long RowNum;
struct Row {
- RowNum idx; // Row number (zero-based)
- int size; // Size of row (including trailing \n\0)
- char *chars; // Row content
+ RowNum idx; // Row number (zero-based)
+ size_t size; // Size of row (including trailing \n\0)
+ char *chars; // Row content -- MUST FREE
};
// 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?
-
+struct Editor {
+ /* actual buffer stuff */
+ char *filename; // -- MUST FREE
RowNum numrows;
- struct Row *rows;
+ struct Row *rows; // -- MUST FREE
- const char *last_err; // verbose error message for last error that occurred
-};
-
-struct Options {
+ /* command line options */
bool prompt_enabled;
- char *prompt;
+ char *prompt; // don't free - usually pointer to argv
bool quiet;
bool verbose;
+ bool loose;
+
+ /* misc state information */
+ bool dirty; // has the buffer been modified since last write?
+ int scols; // number of columns we can display on screen
+ RowNum crow; // current row address
+ const char *last_err; // verbose error message for previous error
};
-extern struct Buffer B;
-extern struct Options O;
+extern struct Editor E;
// print the current perror then exit failure
void die(const char *m);