delint for clang
[AROS.git] / arch / all-pc / kernel / _displayalert.c
blob7904d870d7ed816184a46baee1736cac860da68c
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <bootconsole.h>
7 #include <inttypes.h>
9 #include <kernel_base.h>
10 #include <kernel_debug.h>
11 #include "alert_arch.h"
14 * Display alert on the screen using libbootconsole.
15 * Very useful for early alerts, while the display driver not started yet.
16 * In this case the user gets a nice GURU. Not painted in red yet. :)
19 static inline void PrintChars(char c, ULONG n, struct KernelBase *KernelBase)
21 while (n--)
22 krnPutC(c, KernelBase);
26 * This function calculates length of line.
27 * It's similar to strlen(), but stops also at LF and FF codes.
29 static inline int linelen(const char *str)
31 int l;
33 for (l = 0; str[l] && str[l] != '\n' && str[l] != 0x0F; l++);
34 return l;
37 static const char *PrintCentered(const char *str, struct KernelBase *KernelBase)
39 int len = linelen(str);
40 int i;
41 ULONG s;
43 if (len > (scr_Width - 2))
44 len = (scr_Width - 2);
46 s = scr_Width - 2 - len;
48 krnPutC(0xDB, KernelBase);
49 if (s & 1)
50 krnPutC(' ', KernelBase);
51 s >>= 1;
52 PrintChars(' ', s, KernelBase);
54 for (i = 0; i < len; i++)
55 krnPutC(*str++, KernelBase);
57 PrintChars(' ', s, KernelBase);
58 krnPutC(0xDB, KernelBase);
59 krnPutC('\n', KernelBase);
61 return str;
64 static inline void PrintFrame(char c, struct KernelBase *KernelBase)
66 krnPutC(0xDB, KernelBase);
67 PrintChars(c, scr_Width - 2, KernelBase);
68 krnPutC(0xDB, KernelBase);
69 krnPutC('\n', KernelBase);
72 void krnDisplayAlert(const char *text, struct KernelBase *KernelBase)
74 unsigned int i;
76 if (scr_Type == SCR_UNKNOWN)
78 /* Default alert width (for possible serial output). */
79 scr_Width = 80;
82 /* Make sure that the output starts from a new line */
83 krnPutC('\n', KernelBase);
85 PrintFrame(0xDF, KernelBase);
87 /* Print first three lines (title, task and error) centered */
88 for (i = 0; i < 3; i++)
90 text = PrintCentered(text, KernelBase);
91 if (*text == 0) /* Handle early NULL terminator */
92 break;
93 text++; /* Skip a newline */
96 PrintFrame(0xDC, KernelBase);
98 /* Print the rest of alert text (if any) */
99 if (*text)
101 PrintString(text, KernelBase);
103 /* Print a line in the bottom */
104 krnPutC('\n', KernelBase);
105 PrintChars(0xDC, scr_Width, KernelBase);
106 krnPutC('\n', KernelBase);