aboutsummaryrefslogtreecommitdiff
path: root/dlog.h
diff options
context:
space:
mode:
Diffstat (limited to 'dlog.h')
-rw-r--r--dlog.h82
1 files changed, 59 insertions, 23 deletions
diff --git a/dlog.h b/dlog.h
index dfa346d..67f430a 100644
--- a/dlog.h
+++ b/dlog.h
@@ -1,3 +1,22 @@
+/*
+ * VBMouse - printf & logging routines
+ * Copyright (C) 2022 Javier S. Pedro
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
#ifndef DLOG_H
#define DLOG_H
@@ -10,12 +29,10 @@
#define dlog_putc vbox_log_putc
#endif
-static inline void dlog_endline(void)
-{
- dlog_putc('\n');
-}
+#define dlog_endline() dlog_putc('\n')
-static inline void dlog_print(const char *s)
+/** Print string to log */
+static void dlog_print(const char *s)
{
char c;
while (c = *s++) {
@@ -23,9 +40,17 @@ static inline void dlog_print(const char *s)
}
}
-static inline void dlog_printu(unsigned int num, int base)
+/** Print + newline */
+static void dlog_puts(const char *s)
{
- char buf[4];
+ dlog_print(s);
+ dlog_endline();
+}
+
+/** Print unsigned number with base */
+static void dlog_printub(unsigned int num, int base)
+{
+ char buf[8];
int i = 0;
do {
@@ -39,19 +64,15 @@ static inline void dlog_printu(unsigned int num, int base)
i++;
num /= base;
- } while (num > 0);
+ } while (num > 0 && i < sizeof(buf));
while (i--) {
dlog_putc(buf[i]);
}
}
-static inline void dlog_printx(unsigned int num)
-{
- dlog_printu(num, 16);
-}
-
-static inline void dlog_printd(int num, int base)
+/** Print signed number with base */
+static void dlog_printdb(int num, int base)
{
unsigned int unum;
@@ -63,13 +84,25 @@ static inline void dlog_printd(int num, int base)
unum = num;
}
- dlog_printu(unum, base);
+ dlog_printub(unum, base);
}
-static inline void dlog_puts(const char *s)
+/** Print unsigned number in base 16. */
+static void dlog_printu(unsigned int num)
{
- dlog_print(s);
- dlog_endline();
+ dlog_printub(num, 10);
+}
+
+/** Print unsigned number in base 10. */
+static void dlog_printx(unsigned int num)
+{
+ dlog_printub(num, 16);
+}
+
+/** Print signed number in base 10. */
+static void dlog_printd(int num)
+{
+ dlog_printdb(num, 10);
}
#else
@@ -77,11 +110,14 @@ static inline void dlog_puts(const char *s)
#define dlog_putc(c)
#define dlog_endline()
#define dlog_print(s)
-#define dlog_printu(n)
-#define dlog_printx(n)
-#define dlog_printd(n,b)
#define dlog_puts(s)
+#define dlog_printub(n,b)
+#define dlog_printdb(n,b)
+#define dlog_printx(n)
+#define dlog_printu(n)
+#define dlog_printd(n)
-#endif
-#endif
+#endif /* ENABLE_DLOG */
+
+#endif /* DLOG_H */