changeset 437:e1eebc6bf25d

man: initial import
author David Demelier <markand@malikania.fr>
date Sun, 16 Oct 2022 13:21:40 +0200
parents df92d5b056ce
children 25a56ca53ac2
files GNUmakefile libmlk-core/mlk/core/action-stack.c libmlk-core/mlk/core/drawable-stack.c libmlk-core/mlk/core/err.c libmlk-core/mlk/core/err.h libmlk-core/mlk/core/font.c libmlk-core/mlk/core/image.c libmlk-core/mlk/core/script.c libmlk-core/mlk/core/sys.c libmlk-core/mlk/core/texture.c libmlk-core/mlk/core/window.c man/mlk-err.3 tests/test-action.c tests/test-drawable.c
diffstat 14 files changed, 87 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/GNUmakefile	Sun Oct 16 09:12:52 2022 +0200
+++ b/GNUmakefile	Sun Oct 16 13:21:40 2022 +0200
@@ -8,6 +8,7 @@
 PREFIX ?=               /usr/local
 LIBDIR ?=               $(PREFIX)/lib
 INCDIR ?=               $(PREFIX)/include
+MANDIR ?=               $(PREFIX)/share/man
 
 # User options.
 WITH_DEBUG ?=           no
@@ -412,6 +413,12 @@
 
 # }}}
 
+# {{{ manual pages
+
+MAN3 :=         man/mlk-err.3
+
+# }}}
+
 doc:
 	cd doc && mkdocs build
 
@@ -424,9 +431,11 @@
 	mkdir -p $(DESTDIR)$(INCDIR)/mlk/ui
 	mkdir -p $(DESTDIR)$(INCDIR)/mlk/rpg
 	cp $(LIBMLK_SQLITE) $(LIBMLK_CORE) $(LIBMLK_UI) $(LIBMLK_RPG) $(DESTDIR)$(LIBDIR)
-	cp -R src/libmlk-core/core/*.h $(DESTDIR)$(INCDIR)/mlk/core
-	cp -R src/libmlk-ui/ui/*.h $(DESTDIR)$(INCDIR)/mlk/ui
-	cp -R src/libmlk-rpg/rpg/*.h $(DESTDIR)$(INCDIR)/mlk/rpg
+	cp -R libmlk-core/mlk/core/*.h $(DESTDIR)$(INCDIR)/mlk/core
+	cp -R libmlk-ui/mlk/ui/*.h $(DESTDIR)$(INCDIR)/mlk/ui
+	cp -R libmlk-rpg/mlk/rpg/*.h $(DESTDIR)$(INCDIR)/mlk/rpg
+	mkdir -p $(DESTDIR)$(MANDIR)/man3
+	cp $(MAN3) $(DESTDIR)$(MANDIR)/man3
 
 clean:
 	rm -f $(MLK_BCC) $(MLK_MAP) $(MLK_TILESET)
--- a/libmlk-core/mlk/core/action-stack.c	Sun Oct 16 09:12:52 2022 +0200
+++ b/libmlk-core/mlk/core/action-stack.c	Sun Oct 16 13:21:40 2022 +0200
@@ -51,7 +51,7 @@
 		}
 	}
 
-	return ERR_NO_MEM;
+	return MLK_ERR_NO_MEM;
 }
 
 void
--- a/libmlk-core/mlk/core/drawable-stack.c	Sun Oct 16 09:12:52 2022 +0200
+++ b/libmlk-core/mlk/core/drawable-stack.c	Sun Oct 16 13:21:40 2022 +0200
@@ -51,7 +51,7 @@
 		}
 	}
 
-	return ERR_NO_MEM;
+	return MLK_ERR_NO_MEM;
 }
 
 int
--- a/libmlk-core/mlk/core/err.c	Sun Oct 16 09:12:52 2022 +0200
+++ b/libmlk-core/mlk/core/err.c	Sun Oct 16 13:21:40 2022 +0200
@@ -21,16 +21,16 @@
 #include "err.h"
 
 const char *
-err_string(int e)
+mlk_err_string(int e)
 {
 	switch (e) {
-	case ERR_SDL:
+	case MLK_ERR_SDL:
 		return SDL_GetError();
-	case ERR_NO_MEM:
+	case MLK_ERR_NO_MEM:
 		return "out of memory";
-	case ERR_NO_SUPPORT:
+	case MLK_ERR_NO_SUPPORT:
 		return "operation not supported";
-	case ERR_FORMAT:
+	case MLK_ERR_FORMAT:
 		return "invalid format or corrupt file";
 	default:
 		return "no error";
--- a/libmlk-core/mlk/core/err.h	Sun Oct 16 09:12:52 2022 +0200
+++ b/libmlk-core/mlk/core/err.h	Sun Oct 16 13:21:40 2022 +0200
@@ -19,13 +19,13 @@
 #ifndef MLK_ERR_H
 #define MLK_ERR_H
 
-#define ERR_NONE         0
-#define ERR_SDL         -1
-#define ERR_NO_MEM      -2
-#define ERR_NO_SUPPORT  -3
-#define ERR_FORMAT      -4
+#define MLK_ERR_NONE            0
+#define MLK_ERR_NO_MEM         -1
+#define MLK_ERR_NO_SUPPORT     -2
+#define MLK_ERR_FORMAT         -3
+#define MLK_ERR_SDL            -4
 
 const char *
-err_string(int e);
+mlk_err_string(int e);
 
 #endif /* !MLK_ERROR_H */
--- a/libmlk-core/mlk/core/font.c	Sun Oct 16 09:12:52 2022 +0200
+++ b/libmlk-core/mlk/core/font.c	Sun Oct 16 13:21:40 2022 +0200
@@ -35,7 +35,7 @@
 	assert(path);
 
 	if (!(font->handle = TTF_OpenFont(path, size)))
-		return ERR_SDL;
+		return MLK_ERR_SDL;
 
 	return 0;
 }
@@ -50,7 +50,7 @@
 
 	if (!(ops = SDL_RWFromConstMem(buffer, buflen)) ||
 	   (!(font->handle = TTF_OpenFontRW(ops, 1, size))))
-		return ERR_SDL;
+		return MLK_ERR_SDL;
 
 	return 0;
 }
@@ -86,7 +86,7 @@
 	}
 
 	if (!(surface = func(font->handle, text, fg)))
-		return ERR_SDL;
+		return MLK_ERR_SDL;
 
 	return texture_from_surface(tex, surface);
 }
@@ -111,7 +111,7 @@
 		*h = 0;
 
 	if (TTF_SizeUTF8(font->handle, text, (int *)w, (int *)h) != 0)
-		return ERR_SDL;
+		return MLK_ERR_SDL;
 
 	return 0;
 }
--- a/libmlk-core/mlk/core/image.c	Sun Oct 16 09:12:52 2022 +0200
+++ b/libmlk-core/mlk/core/image.c	Sun Oct 16 13:21:40 2022 +0200
@@ -45,7 +45,7 @@
 	assert(path);
 
 	if (!(tex->handle = IMG_LoadTexture(RENDERER(), path)))
-		return ERR_SDL;
+		return MLK_ERR_SDL;
 
 	dimensions(tex);
 
@@ -60,7 +60,7 @@
 	SDL_RWops *ops = SDL_RWFromConstMem(buffer, size);
 
 	if (!ops || !(tex->handle = IMG_LoadTexture_RW(RENDERER(), ops, 1)))
-		return ERR_SDL;
+		return MLK_ERR_SDL;
 
 	dimensions(tex);
 
--- a/libmlk-core/mlk/core/script.c	Sun Oct 16 09:12:52 2022 +0200
+++ b/libmlk-core/mlk/core/script.c	Sun Oct 16 13:21:40 2022 +0200
@@ -72,7 +72,7 @@
 	assert(a);
 
 	if (s->actionsz >= SCRIPT_ACTION_MAX)
-		return ERR_NO_MEM;
+		return MLK_ERR_NO_MEM;
 
 	s->actions[s->actionsz++] = a;
 
--- a/libmlk-core/mlk/core/sys.c	Sun Oct 16 09:12:52 2022 +0200
+++ b/libmlk-core/mlk/core/sys.c	Sun Oct 16 13:21:40 2022 +0200
@@ -164,9 +164,9 @@
 	case SF_ERR_UNRECOGNISED_FORMAT:
 	case SF_ERR_MALFORMED_FILE:
 	case SF_ERR_UNSUPPORTED_ENCODING:
-		return ERR_FORMAT;
+		return MLK_ERR_FORMAT;
 	default:
-		return ERR_NO_MEM;
+		return MLK_ERR_NO_MEM;
 	}
 }
 
--- a/libmlk-core/mlk/core/texture.c	Sun Oct 16 09:12:52 2022 +0200
+++ b/libmlk-core/mlk/core/texture.c	Sun Oct 16 13:21:40 2022 +0200
@@ -39,7 +39,7 @@
 
 	if (!tex->handle) {
 		tex->w = tex->h = 0;
-		return ERR_SDL;
+		return MLK_ERR_SDL;
 	}
 
 	tex->w = w;
@@ -166,7 +166,7 @@
 
 	if (!(tex->handle = SDL_CreateTextureFromSurface(RENDERER(), surface))) {
 		tex->w = tex->h = 0;
-		return ERR_SDL;
+		return MLK_ERR_SDL;
 	}
 
 	tex->w = surface->w;
--- a/libmlk-core/mlk/core/window.c	Sun Oct 16 09:12:52 2022 +0200
+++ b/libmlk-core/mlk/core/window.c	Sun Oct 16 13:21:40 2022 +0200
@@ -84,7 +84,7 @@
 	assert(title);
 
 	if (!load_window(title, w, h) || !load_renderer())
-		return ERR_SDL;
+		return MLK_ERR_SDL;
 
 	window.w = w;
 	window.h = h;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/man/mlk-err.3	Sun Oct 16 13:21:40 2022 +0200
@@ -0,0 +1,48 @@
+.Dd $Mdocdate$
+.Dt MLK-ERR 3
+.Os
+.Sh NAME
+.Nm mlk-err
+.Nd error management in mlk library
+.Sh LIBRARY
+.Lb libmlk-core
+.Sh SYNOPSIS
+.In mlk/core/err.h
+.Ft "const char *"
+.Fn mlk_err_string "int e"
+.Sh DESCRIPTION
+This manual page describes error codes that may occur within the molko
+framework. All errors are defined with negative numbers the only exception
+being
+.Er MLK_ERR_NONE
+which is equal to 0.
+.Pp
+The following macro constants are defined:
+.Bl -tag -width Ds
+.It Er MLK_ERR_NONE
+Equal to 0, no error.
+.It Er MLK_ERR_NO_MEM
+No more memory available.
+.It Er MLK_ERR_NO_SUPPORT
+The file format or function is not supported.
+.It Er MLK_ERR_FORMAT
+The file is corrupt or invalid.
+.El
+.Pp
+There are other private error codes that are internal to the framework and not
+listed as they may change over time, if the caller inspects individual error
+codes it should also be took in account which in this case the function
+.Fn mlk_err_string
+may comes handy.
+.Pp
+The function
+.Fn mlk_err_string
+returns a constant string description of the error
+.Ar e .
+.Sh SEE ALSO
+.Xr mlk-panic 3
+.Sh AUTHORS
+The
+.Nm
+library was written by
+.An David Demelier Aq Mt markand@malikania.fr .
--- a/tests/test-action.c	Sun Oct 16 09:12:52 2022 +0200
+++ b/tests/test-action.c	Sun Oct 16 13:21:40 2022 +0200
@@ -192,7 +192,7 @@
 		DT_EQ_INT(action_stack_add(&st, &act), 0);
 
 	/* This one should not fit in. */
-	DT_EQ_INT(action_stack_add(&st, &act), ERR_NO_MEM);
+	DT_EQ_INT(action_stack_add(&st, &act), MLK_ERR_NO_MEM);
 }
 
 static void
--- a/tests/test-drawable.c	Sun Oct 16 09:12:52 2022 +0200
+++ b/tests/test-drawable.c	Sun Oct 16 13:21:40 2022 +0200
@@ -160,7 +160,7 @@
 		DT_EQ_INT(drawable_stack_add(&st, &dw), 0);
 
 	/* This one should not fit in. */
-	DT_EQ_INT(drawable_stack_add(&st, &dw), ERR_NO_MEM);
+	DT_EQ_INT(drawable_stack_add(&st, &dw), MLK_ERR_NO_MEM);
 }
 
 static void