Changeset 331 for EcnlProtoTool/trunk/ntshell/ntshell/core
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- Location:
- EcnlProtoTool/trunk/ntshell/ntshell/core
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/ntshell/ntshell/core/ntlibc.c
r321 r331 57 57 } 58 58 59 int ntlibc_strlcpy(char *des, const char *src, int n) 60 { 61 char *d = des, *e = &des[n]; 62 const char *s = src; 63 while (*s && d < e) { 64 *d = *s; 65 d++; 66 s++; 67 } 68 *d++ = '\0'; 69 return (int)d - (int)des; 70 } 71 59 72 char *ntlibc_strcat(char *des, const char *src) 60 73 { … … 71 84 *d = '\0'; 72 85 return des; 86 } 87 88 int ntlibc_strlcat(char *des, const char *src, int n) 89 { 90 char *d = des, *e = &des[n]; 91 const char *s = src; 92 while (*d && d < e) { 93 d++; 94 } 95 while (*s && d < e) { 96 *d = *s; 97 d++; 98 s++; 99 } 100 *d++ = '\0'; 101 return (int)d - (int)des; 73 102 } 74 103 … … 223 252 } 224 253 254 unsigned long ntlibc_strtoul(const char *restrict nptr, char **restrict endptr, int base) 255 { 256 int cnt; 257 int num = 0; 258 int ofs = 0; 259 int sign = 0; 260 int scnt = 0; 261 char *p = (char *)nptr; 262 while (*p != '\0') { 263 if (!ntlibc_isdigit(*p)) { 264 if (*p == ' ') { 265 ofs++; 266 } 267 if (*p == '+') { 268 sign = 0; 269 ofs++; 270 if (scnt++ > 0) { 271 *endptr = p; 272 break; 273 } 274 } 275 if (*p == '-') { 276 sign = 1; 277 ofs++; 278 if (scnt++ > 0) { 279 *endptr = p; 280 break; 281 } 282 } 283 *endptr = p; 284 break; 285 } 286 p++; 287 } 288 for (cnt = ofs; (nptr[cnt] >= '0') && (nptr[cnt] <= '9'); cnt++) { 289 num = 10 * num + (nptr[cnt] - '0'); 290 } 291 if (sign) { 292 return -num; 293 } 294 else { 295 return num; 296 } 297 } 298 225 299 char *ntlibc_strchr(const char *s, int c) 226 300 { -
EcnlProtoTool/trunk/ntshell/ntshell/core/ntlibc.h
r321 r331 40 40 int ntlibc_strlen(const char *s); 41 41 char *ntlibc_strcpy(char *des, const char *src); 42 int ntlibc_strlcpy(char *des, const char *src, int n); 42 43 char *ntlibc_strcat(char *des, const char *src); 44 int ntlibc_strlcat(char *des, const char *src, int n); 43 45 int ntlibc_strcmp(const char *s1, const char *s2); 44 46 int ntlibc_stricmp(const char *s1, const char *s2); … … 50 52 int ntlibc_tolower(int c); 51 53 int ntlibc_atoi(const char *nptr); 54 unsigned long ntlibc_strtoul(const char *__restrict nptr, char **__restrict endptr, int base); 52 55 char *ntlibc_strchr(const char *s, int c); 53 56 char *ntlibc_utoa(unsigned int value, char *s, int radix); -
EcnlProtoTool/trunk/ntshell/ntshell/core/ntshell.c
r321 r331 33 33 #include <string.h> 34 34 #include "ntshell.h" 35 #include "core/ntlibc.h" 35 36 36 37 int ntshell_exit; … … 107 108 * @param HANDLE A pointer of the handle. 108 109 */ 109 #define PROMPT_WRITE(HANDLE) SERIAL_WRITE((HANDLE), (HANDLE)->prompt, strlen((HANDLE)->prompt))110 #define PROMPT_WRITE(HANDLE) SERIAL_WRITE((HANDLE), (HANDLE)->prompt, ntlibc_strlen((HANDLE)->prompt)) 110 111 111 112 /** … … 114 115 * @param HANDLE A pointer of the handle. 115 116 */ 116 #define PROMPT_NEWLINE(HANDLE) SERIAL_WRITE((HANDLE), NTSHELL_PROMPT_NEWLINE, strlen(NTSHELL_PROMPT_NEWLINE))117 #define PROMPT_NEWLINE(HANDLE) SERIAL_WRITE((HANDLE), NTSHELL_PROMPT_NEWLINE, ntlibc_strlen(NTSHELL_PROMPT_NEWLINE)) 117 118 118 119 /** … … 399 400 * Found the suggestion. 400 401 */ 401 int n = strlen((const char *)buf);402 int n = ntlibc_strlen((const char *)buf); 402 403 VTSEND_ERASE_LINE(ntshell); 403 404 VTSEND_CURSOR_HEAD(ntshell); … … 429 430 * Found the suggestion. 430 431 */ 431 int n = strlen((const char *)buf);432 int n = ntlibc_strlen((const char *)buf); 432 433 VTSEND_ERASE_LINE(ntshell); 433 434 VTSEND_CURSOR_HEAD(ntshell); … … 441 442 * Recall the previous input text string. 442 443 */ 443 int n = strlen(SUGGEST_SOURCE(ntshell));444 int n = ntlibc_strlen(SUGGEST_SOURCE(ntshell)); 444 445 VTSEND_ERASE_LINE(ntshell); 445 446 VTSEND_CURSOR_HEAD(ntshell); … … 484 485 UNUSED_VARIABLE(ch); 485 486 text_editor_get_text(GET_EDITOR(ntshell), buf, sizeof(buf)); 486 len = strlen((const char *)buf);487 len = ntlibc_strlen((const char *)buf); 487 488 VTSEND_CURSOR_HEAD(ntshell); 488 489 PROMPT_WRITE(ntshell); … … 606 607 p->func_callback = func_callback; 607 608 p->extobj = extobj; 608 strcpy(p->prompt, NTSHELL_PROMPT_DEFAULT);609 ntlibc_strcpy(p->prompt, NTSHELL_PROMPT_DEFAULT); 609 610 610 611 p->vtrecv.user_data = p; … … 666 667 } 667 668 668 strcpy(p->prompt, prompt);669 ntlibc_strcpy(p->prompt, prompt); 669 670 } 670 671 -
EcnlProtoTool/trunk/ntshell/ntshell/core/text_history.c
r321 r331 33 33 #include <string.h> 34 34 #include "text_history.h" 35 #include "core/ntlibc.h" 35 36 36 37 /** … … 145 146 char *buf, const int siz) 146 147 { 147 const int text_len = strlen((const char *)text);148 const int text_len = ntlibc_strlen((const char *)text); 148 149 int found = 0; 149 150 int i; … … 151 152 int target = (p->rp + i) % TEXTHISTORY_DEPTH; 152 153 char *txtp = p->history + (TEXTHISTORY_MAXLEN * target); 153 const int target_len = strlen((const char *)txtp);154 const int target_len = ntlibc_strlen((const char *)txtp); 154 155 int comp_len = (target_len < text_len) ? target_len : text_len; 155 if (( strncmp(156 if ((ntlibc_strncmp( 156 157 (const char *)txtp, 157 158 (const char *)text, comp_len) == 0) && (comp_len > 0)) { 158 159 if (found == index) { 159 if (siz <= strlen(txtp)) {160 if (siz <= ntlibc_strlen(txtp)) { 160 161 return -1; 161 162 } 162 strcpy((char *)buf, (char *)txtp);163 ntlibc_strcpy((char *)buf, (char *)txtp); 163 164 return 0; 164 165 }
Note:
See TracChangeset
for help on using the changeset viewer.