be

based editor
git clone git://git.kocotian.pl/be.git
Log | Files | Refs | README | LICENSE

commit 885ebd203160a99fa83952eb1af62258294d50e3
parent 8e0afe82f30dc8dce4b50d54f0d5b17936fdf78e
Author: kocotian <kocotian@kocotian.pl>
Date:   Mon, 19 Apr 2021 13:35:16 +0200

Language enums

Diffstat:
Mbe.c | 13+++++++------
Alang.h | 13+++++++++++++
Mlang/en_US.h | 14+++++++-------
3 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/be.c b/be.c @@ -38,6 +38,7 @@ #endif #include <arg.h> +#include <lang.h> #include <str.h> #include <util.h> @@ -190,7 +191,7 @@ getws(int *r, int *c) if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0) die("ioctl:"); if (ws.ws_col < 20 || ws.ws_row < 3) - die(lang_err[1], 20, 3); + die(lang_err[ErrScreenTooSmall], 20, 3); *c = ws.ws_col; *r = ws.ws_row; } @@ -434,7 +435,7 @@ writeBuffer(Buffer *buf, char *filename) size_t i; if (filename == NULL) { if (buf->anonymous) - return minibufferError(lang_err[3]); + return minibufferError(lang_err[ErrWriteAnon]); else filename = buf->path; } @@ -521,7 +522,7 @@ setup(char *filename) else editBuffer(NULL, filename); editor.curbuf = 1; - minibufferPrint(lang_base[2]); + minibufferPrint(lang_base[ErrDirty]); } static void @@ -535,7 +536,7 @@ finish(void) static void usage(void) { - die("%s: %s [-hLv] [FILE]", lang_err[0], argv0); + die("%s: %s [-hLv] [FILE]", lang_err[ErrUsage], argv0); } /* editor functions */ @@ -718,7 +719,7 @@ bufclose(const Arg *arg) { (void)arg; if (CURBUF(editor).dirty) { - minibufferError(lang_err[2]); + minibufferError(lang_err[ErrDirty]); return; } freeBuffer(editor.bufs.data + editor.curbuf); @@ -746,7 +747,7 @@ main(int argc, char *argv[]) usage(); break; case 'L': - die("%s, %s", lang_base[0], lang_base[1]); + die("%s, %s", lang_base[LangCode], lang_base[LangName]); break; case 'v': die("be-" VERSION); diff --git a/lang.h b/lang.h @@ -0,0 +1,13 @@ +#ifndef _LANG_H +#define _LANG_H + +typedef enum { + LangCode = 0, LangName, LangWelcome, +} Lang; + +typedef enum { + ErrUsage = 0, ErrScreenTooSmall, + ErrDirty, ErrWriteAnon, +} Errno; + +#endif diff --git a/lang/en_US.h b/lang/en_US.h @@ -1,8 +1,8 @@ static char *lang_base[] = { - [0] = "en_US", - [1] = "English (US)", - [2] = "welcome to be, version " VERSION, + [LangCode] = "en_US", + [LangName] = "English (US)", + [LangWelcome] = "welcome to be, version " VERSION, }, *lang_modes[] = { [ModeNormal] = "Normal", @@ -12,8 +12,8 @@ static char [SubModeMovement] = "Movement", }, *lang_err[] = { - [0] = "usage", - [1] = "screen is too small (min. %dx%d)", - [2] = "buffer have unsaved changes", - [3] = "cannot write anonymous buffer without filename", + [ErrUsage] = "usage", + [ErrScreenTooSmall] = "screen is too small (min. %dx%d)", + [ErrDirty] = "buffer have unsaved changes", + [ErrWriteAnon] = "cannot write anonymous buffer without filename", };