aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2020-05-29 15:40:35 +0200
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2020-05-29 15:40:35 +0200
commit65b351b5fcb93d9c10ef63067fdb77b3551baf8b (patch)
tree55e1979893906a80aebb6c98076f125eda3ee5af
parent1635b4b1f201c7673ddce45c8d5f6bdaafc61cf8 (diff)
downloadembedlog-65b351b5fcb93d9c10ef63067fdb77b3551baf8b.tar.gz
embedlog-65b351b5fcb93d9c10ef63067fdb77b3551baf8b.tar.bz2
embedlog-65b351b5fcb93d9c10ef63067fdb77b3551baf8b.zip
src: move el_basename() from el-print.c to el-utils.c
el_basename() can be used by other modules and not only el-print, and it's better for it to reside in separate file. Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
-rw-r--r--embedlog-sources.mk1
l---------examples/el-utils.c1
l---------examples/el-utils.h1
-rw-r--r--src/Makefile.am1
-rw-r--r--src/el-print.c37
-rw-r--r--src/el-utils.c73
-rw-r--r--src/el-utils.h15
l---------tst/el-utils.c1
l---------tst/el-utils.h1
9 files changed, 95 insertions, 36 deletions
diff --git a/embedlog-sources.mk b/embedlog-sources.mk
index bb65d6c..f238661 100644
--- a/embedlog-sources.mk
+++ b/embedlog-sources.mk
@@ -5,6 +5,7 @@ embedlog_sources = el-options.c \
el-puts.c \
el-ts.c \
el-flush.c \
+ el-utils.c \
snprintf.c
if ENABLE_OUT_FILE
diff --git a/examples/el-utils.c b/examples/el-utils.c
new file mode 120000
index 0000000..822a39d
--- /dev/null
+++ b/examples/el-utils.c
@@ -0,0 +1 @@
+../src/el-utils.c \ No newline at end of file
diff --git a/examples/el-utils.h b/examples/el-utils.h
new file mode 120000
index 0000000..2315c63
--- /dev/null
+++ b/examples/el-utils.h
@@ -0,0 +1 @@
+../src/el-utils.h \ No newline at end of file
diff --git a/src/Makefile.am b/src/Makefile.am
index 98ddf66..27d86a5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,6 +4,7 @@ lib_LTLIBRARIES = libembedlog.la
libembedlog_la_SOURCES = $(embedlog_sources)
libembedlog_la_SOURCES += el-private.h \
+ el-utils.h \
valid.h
libembedlog_la_LDFLAGS = -version-info 9999:0:0
libembedlog_la_CFLAGS = -I$(top_builddir)/include
diff --git a/src/el-print.c b/src/el-print.c
index 530ae60..5f0e6e2 100644
--- a/src/el-print.c
+++ b/src/el-print.c
@@ -41,6 +41,7 @@
#include "el-private.h"
+#include "el-utils.h"
#include <errno.h>
#include <stdarg.h>
@@ -166,42 +167,6 @@ static size_t el_color
/* ==========================================================================
- returns pointer to where basename of 's' starts
-
- Examples:
- path basename
- /path/to/file.c file.c
- path/to/file.c file.c
- /file.c file.c
- file.c file.c
- "" ""
- NULL segmentation fault
- ========================================================================== */
-
-
-static const char *el_basename
-(
- const char *s /* string to basename */
-)
-{
- const char *base; /* pointer to base name of path */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- base = s;
-
- for (; *s; ++s)
- {
- if (s[0] == '/' && s[1] != '\0')
- {
- base = s + 1;
- }
- }
-
- return base;
-}
-
-
-/* ==========================================================================
stores file and line information in 'buf'. Number of bytes stored in
'buf' is returned. If file info is disabled during compilation or in
runtime, value 0 is returned
diff --git a/src/el-utils.c b/src/el-utils.c
new file mode 100644
index 0000000..503c35b
--- /dev/null
+++ b/src/el-utils.c
@@ -0,0 +1,73 @@
+/* ==========================================================================
+ Licensed under BSD 2clause license See LICENSE file for more information
+ Author: Michał Łyszczek <michal.lyszczek@bofc.pl>
+ ==========================================================================
+ -------------------------------------------------------------
+ / This file contains functions that can be used by any of the \
+ | functions in the project but do not fit into already |
+ \ existing modules /
+ -------------------------------------------------------------
+ \ \_______
+ v__v \ \ O )
+ (oo) ||----w |
+ (__) || || \/\
+ ==========================================================================
+ _ __ __ ____ _ __
+ (_)____ _____ / /__ __ ____/ /___ / __/(_)/ /___ _____
+ / // __ \ / ___// // / / // __ // _ \ / /_ / // // _ \ / ___/
+ / // / / // /__ / // /_/ // /_/ // __/ / __// // // __/(__ )
+ /_//_/ /_/ \___//_/ \__,_/ \__,_/ \___/ /_/ /_//_/ \___//____/
+
+ ========================================================================== */
+
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+#include "el-private.h"
+
+
+/* ==========================================================================
+ __ __ _ ____
+ ____ __ __ / /_ / /(_)_____ / __/__ __ ____ _____ _____
+ / __ \ / / / // __ \ / // // ___/ / /_ / / / // __ \ / ___// ___/
+ / /_/ // /_/ // /_/ // // // /__ / __// /_/ // / / // /__ (__ )
+ / .___/ \__,_//_.___//_//_/ \___/ /_/ \__,_//_/ /_/ \___//____/
+ /_/
+ ========================================================================== */
+
+
+/* ==========================================================================
+ returns pointer to where basename of 's' starts
+
+ Examples:
+ path basename
+ /path/to/file.c file.c
+ path/to/file.c file.c
+ /file.c file.c
+ file.c file.c
+ "" ""
+ NULL segmentation fault
+ ========================================================================== */
+
+
+const char *el_basename
+(
+ const char *s /* string to basename */
+)
+{
+ const char *base; /* pointer to base name of path */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+ base = s;
+
+ for (; *s; ++s)
+ {
+ if (s[0] == '/' && s[1] != '\0')
+ {
+ base = s + 1;
+ }
+ }
+
+ return base;
+}
diff --git a/src/el-utils.h b/src/el-utils.h
new file mode 100644
index 0000000..2fac6bc
--- /dev/null
+++ b/src/el-utils.h
@@ -0,0 +1,15 @@
+/* ==========================================================================
+ Licensed under BSD 2clause license See LICENSE file for more information
+ Author: Michał Łyszczek <michal.lyszczek@bofc.pl>
+ ========================================================================== */
+
+#ifndef EL_UTILS_H
+#define EL_UTILS_H 1
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+const char *el_basename(const char *s);
+
+#endif
diff --git a/tst/el-utils.c b/tst/el-utils.c
new file mode 120000
index 0000000..822a39d
--- /dev/null
+++ b/tst/el-utils.c
@@ -0,0 +1 @@
+../src/el-utils.c \ No newline at end of file
diff --git a/tst/el-utils.h b/tst/el-utils.h
new file mode 120000
index 0000000..2315c63
--- /dev/null
+++ b/tst/el-utils.h
@@ -0,0 +1 @@
+../src/el-utils.h \ No newline at end of file