Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
dbg.cpp
00001 00002 /* 00003 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) 00004 00005 Permission is hereby granted, free of charge, to any person obtaining a copy 00006 of this software and associated documentation files (the "Software"), to deal 00007 in the Software without restriction, including without limitation the rights 00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 copies of the Software, and to permit persons to whom the Software is 00010 furnished to do so, subject to the following conditions: 00011 00012 The above copyright notice and this permission notice shall be included in 00013 all copies or substantial portions of the Software. 00014 00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 THE SOFTWARE. 00022 */ 00023 00024 #define __LWIP_DEBUG 00025 #define __DEBUG 00026 #include "dbg.h" 00027 #include "mbed.h" 00028 #include <cstdarg> 00029 #include "string.h" 00030 00031 //LocalFileSystem dbgfs("dbgsfs"); 00032 00033 //static FILE* m_fp = NULL; 00034 00035 static int strpos (const char *haystack, const char *seed) { 00036 int pos; 00037 const char *pos_char = haystack; 00038 const char *seed_char = seed; 00039 while (*pos_char != 0) { 00040 while (*pos_char != 0 && *seed_char != 0 && *pos_char == *seed_char) { 00041 pos_char++; 00042 seed_char++; 00043 } 00044 if (*seed_char == 0) { 00045 return pos; // We reached the end of seed and matched. 00046 } 00047 pos++; 00048 pos_char = haystack + pos; 00049 seed_char = seed; 00050 } 00051 return -1; // not found 00052 } 00053 void DebugStream::debug(const char* format, ...) 00054 { 00055 // if(!m_fp) 00056 // m_fp = fopen("/dbgsfs/dbg.txt", "a"); 00057 va_list argp; 00058 00059 va_start(argp, format); 00060 #if 0 // DEBUG_FIXLF 00061 vprintf(format, argp); 00062 //vfprintf(m_fp, format, argp); 00063 va_end(argp); 00064 #else 00065 int len; 00066 char buf[512]; 00067 len = vsprintf(buf, format, argp); 00068 if (buf[len-1] == '\n' && buf[len-2] != '\r') { 00069 // Fix CR without LF 00070 buf[len-1] = '\r'; 00071 buf[len] = '\n'; 00072 buf[len+1] = '\0'; 00073 len++; 00074 } 00075 if (len >= (sizeof(buf)/sizeof(buf[0]))) { 00076 printf("DebugStream::debug() buffer overflow (len=%d).\r\n", len); 00077 } 00078 if (WHERECHOP) { 00079 int pos = strpos(format, WHEREFMT); 00080 if (pos >= 0) { 00081 char *from = buf+pos+WHERECHOP; 00082 char *to = buf +WHERESKIP; 00083 while (*from != 0) { 00084 *(to++) = *(from++); 00085 } 00086 *(to) = 0; 00087 } 00088 } 00089 va_end(argp); 00090 printf(buf); 00091 #endif 00092 00093 // printf("\r\n"); //Flush 00094 //local("local"); // Create the local filesystem under the name "local" 00095 00096 // fclose(m_fp); 00097 } 00098 00099 void DebugStream::release() 00100 { 00101 //fclose(m_fp); 00102 } 00103 00104 /* 00105 int snprintf(char *str, int size, const char *format, ...) 00106 { 00107 va_list argp; 00108 00109 va_start(argp, format); 00110 vsprintf(str, format, argp); 00111 va_end(argp); 00112 00113 return strlen(str); 00114 } 00115 */ 00116
Generated on Tue Jul 12 2022 21:10:25 by
1.7.2