2 * Copyright (c) 2003-2004 Greg Parker. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY GREG PARKER ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "rsrc/rsrc.h"
32 uint8_t *memchr(uint8_t *buf, uint8_t ch, uint16_t bufLen)
34 uint8_t *end = buf + bufLen;
35 for ( ; buf < end; buf++) {
36 if (*buf == ch) return buf;
42 char *strsep(char **stringp, const char *delim)
46 if (!str) return NULL;
48 // GrP only implemented for single-character delim
49 assert(strlen(delim) == 1);
51 pos = strchr(str, *delim);
62 int strcasecmp(const char *s1, const char *s2)
64 return StrCaselessCompare(s1, s2);
68 char *strcasestr(const char *big, const char *little)
70 int littlelen = strlen(little);
73 for (s = big; *s != '\0'; s++) {
74 if (0 == memcmp(s, little, littlelen)) return (char *)s;
80 void printf(const char *format, ...)
85 struct ssh_session_t *ss = ssh_get_current();
87 va_start(args, format);
88 vsnprintf(buf, sizeof(buf), format, args);
91 // Filter out nonprintable chars
92 for (c = buf; *c != '\0'; c++) {
93 if (!isprint(*c) && !isspace(*c)) *c = '?';
96 if (ss) ssh_receive_bytes(ss, buf, strlen(buf));
98 // DON'T update here - it can cause a crash
101 void debug_printf(const char *format, ...)
105 RectangleType r = {{0, 0}, {160, 14}};
106 WinHandle drawWindow;
109 len = snprintf(buf, sizeof(buf), "%lu ", TimGetTicks());
111 va_start(args, format);
112 vsnprintf(buf+len, sizeof(buf)-len, format, args);
115 // print on top of program title box
116 // will be visible even with vt100 problems and alerts
117 // fixme this causes problems with hi-res drawing
118 // drawWindow = WinSetDrawWindow(NULL);
120 WinEraseRectangle(&r, 0);
121 WinDrawChars(buf, strlen(buf), 0, 0);
123 // WinSetDrawWindow(drawWindow);
126 int fatal(const char *format, ...)
131 va_start(args, format);
132 vsnprintf(buf, sizeof(buf), format, args);
135 // release version: display alert, then kill program
136 FrmCustomAlert(FatalAlertID, buf, " ", " ");
137 SysReset(); // fixme don't see a better way to kill the program cleanly
139 // development version: don't obscure debug_printf output or vt100
142 struct ssh_session_t *ss = ssh_get_current();
144 ssh_receive_bytes(ss, "\nFATAL:", 7);
145 ssh_receive_bytes(ss, buf, strlen(buf));
147 debug_printf("%s", buf);
157 void assert_failed(uint32_t which)
160 FrmCustomAlert(AlertFormID, "arm assert failed!", StrIToA(intbuf, which), " ");