White space fixes, detab.
[AROS.git] / rom / kernel / _displayalert.c
blob53a67bbdf7744569b058bc7d9864c3ba992e6e62
1 #include <kernel_base.h>
2 #include <kernel_debug.h>
4 #define ALERT_WIDTH 80
6 static inline void PrintChars(char c, ULONG n, struct KernelBase *KernelBase)
8 while (n--)
9 krnPutC(c, KernelBase);
13 * This function calculates length of line.
14 * It's similar to strlen(), but stops also at LF and FF codes.
16 static inline int linelen(const char *str)
18 int l;
20 for (l = 0; str[l] && str[l] != '\n' && str[l] != 0x0F; l++);
21 return l;
24 static const char *PrintCentered(const char *str, struct KernelBase *KernelBase)
26 int len = linelen(str);
27 int i;
28 ULONG s;
30 if (len > (ALERT_WIDTH - 2))
31 len = (ALERT_WIDTH - 2);
33 s = ALERT_WIDTH - 2 - len;
35 krnPutC('#', KernelBase);
36 if (s & 1)
37 krnPutC(' ', KernelBase);
38 s >>= 1;
39 PrintChars(' ', s, KernelBase);
41 for (i = 0; i < len; i++)
42 krnPutC(*str++, KernelBase);
44 PrintChars(' ', s, KernelBase);
45 krnPutC('#', KernelBase);
46 krnPutC('\n', KernelBase);
48 return str;
51 static inline void PrintFrame(struct KernelBase *KernelBase)
53 PrintChars('#', ALERT_WIDTH, KernelBase);
54 krnPutC('\n', KernelBase);
58 * This entry point just displays the message. It doesn't make any decisions
59 * what to do next.
60 * Because of this it misses 'code' argument.
61 * The kernel can use it internally, for displaying messages about
62 * critical startup failures.
64 void krnDisplayAlert(const char *text, struct KernelBase *KernelBase)
66 unsigned int i;
68 /* Make sure that the output starts from a new line */
69 krnPutC('\n', KernelBase);
71 PrintFrame(KernelBase);
73 /* Print first three lines (title, task and error) centered */
74 for (i = 0; i < 3; i++)
76 text = PrintCentered(text, KernelBase);
78 if (*text == 0) /* Handle early NULL terminator */
79 break;
81 text++; /* Skip a newline */
84 PrintFrame(KernelBase);
86 /* Print the rest of alert text (if any) */
87 if (*text)
89 while (*text)
90 krnPutC(*text++, KernelBase);
92 krnPutC('\n', KernelBase);
93 PrintFrame(KernelBase);