Changeset 442 for EcnlProtoTool/trunk/ntshell
- Timestamp:
- Jul 13, 2020, 8:07:55 PM (4 years ago)
- Location:
- EcnlProtoTool/trunk/ntshell
- Files:
-
- 3 added
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/ntshell/Debug/Makefile
r441 r442 71 71 SRCLANG = c 72 72 ifeq ($(SRCLANG),c) 73 LIBS = -lm -lc -lnosys73 LIBS = -lm -lc 74 74 endif 75 75 ifeq ($(SRCLANG),c++) … … 93 93 # ï¼ã«ã¼ãã«ã©ã¤ãã©ãªãmake対象ã«ããæã¯ï¼ç©ºã«å®ç¾©ããï¼ 94 94 # 95 KERNEL_LIB = ../../asp3_dcre/Debug95 KERNEL_LIB = 96 96 97 97 # … … 99 99 # ï¼ã·ã¹ãã ãµã¼ãã¹ã³ã¼ã«ã©ã¤ãã©ãªãmake対象ã«ããæã¯ï¼ç©ºã«å®ç¾©ããï¼ 100 100 # 101 SYSSVC_LIB = ../../asp3_dcre/Debug101 SYSSVC_LIB = 102 102 103 103 # … … 209 209 # 210 210 APPLNAME = ntshell 211 APPLDIRS = ../src ../ tlsf ../fatfs ../webserver ../ntshell ../ntshell/core ../ntshell/util211 APPLDIRS = ../src ../fatfs ../webserver ../ntshell ../ntshell/core ../ntshell/util 212 212 APPL_CFG = main.cfg 213 213 APPL_CDL = main.cdl … … 217 217 ifdef USE_CXX 218 218 APPL_CXXOBJS := main.o 219 APPL_COBJS := fdtable.o stdio_stub.o pipe_stub.o io_stub.o socket_stub.o tlsf.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o base64.o http-strings.o http_parser.o httpd.o httpd-fs.o sha1.o websocket.o websocket_fbs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o mbedcall.o ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o netcmd.o219 APPL_COBJS := fdtable.o stdio_stub.o pipe_stub.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o base64.o http-strings.o http_parser.o httpd.o httpd-fs.o sha1.o websocket.o websocket_fbs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntstdio.o ntopt.o syscall.o mbedcall.o ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o netcmd.o newlib_stub.o shellif.o 220 220 else 221 APPL_COBJS := main.o fdtable.o stdio_stub.o pipe_stub.o io_stub.o socket_stub.o tlsf.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o base64.o http-strings.o http_parser.o httpd.o httpd-fs.o sha1.o websocket.o websocket_fbs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o mbedcall.o ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o netcmd.o221 APPL_COBJS := main.o fdtable.o stdio_stub.o pipe_stub.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o base64.o http-strings.o http_parser.o httpd.o httpd-fs.o sha1.o websocket.o websocket_fbs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntstdio.o ntopt.o syscall.o mbedcall.o ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o netcmd.o newlib_stub.o shellif.o 222 222 endif 223 223 APPL_COBJS := $(APPL_COBJS) log_output.o vasyslog.o t_perror.o strerror.o mbed_stub.o … … 269 269 $(INIT_TECS_COBJ) $(CXXRTS) 270 270 SYSSVC_CFLAGS := $(SYSSVC_CFLAGS) 271 INCLUDES := $(INCLUDES) -I$(TECSGENDIR) -I$(SRCDIR)/tecs_kernel -I../../musl-1.1.18/include271 INCLUDES := $(INCLUDES) -I$(TECSGENDIR) -I$(SRCDIR)/tecs_kernel 272 272 273 273 # -
EcnlProtoTool/trunk/ntshell/fatfs/ff.c
r435 r442 20 20 #include "ff.h" /* Declarations of FatFs API */ 21 21 #include "diskio.h" /* Declarations of disk I/O functions */ 22 #include "util/ntstdio.h"23 22 24 23 /*-------------------------------------------------------------------------- … … 3910 3909 if (dir[DIR_Attr] & AM_DIR) { /* The new object is a directory */ 3911 3910 temp_new_path = (TCHAR *)ff_memalloc((FF_MAX_LFN + 1) * sizeof(WCHAR)); 3912 ntstdio_snprintf(temp_new_path, FF_MAX_LFN, "%s/%s", path_new, basename((char *)path_old));3911 snprintf(temp_new_path, FF_MAX_LFN, "%s/%s", path_new, basename((char *)path_old)); 3913 3912 res = follow_path(&djn, temp_new_path); 3914 3913 } -
EcnlProtoTool/trunk/ntshell/fatfs/sdfs.c
r435 r442 118 118 //#include "mbed_debug.h" 119 119 #include "mbed_wait_api.h" 120 #include "util/ntstdio.h"121 120 122 121 void sdfs_debug(const char *fmt, ...); -
EcnlProtoTool/trunk/ntshell/ntshell/core/ntshell.c
r331 r442 108 108 * @param HANDLE A pointer of the handle. 109 109 */ 110 #define PROMPT_WRITE(HANDLE) SERIAL_WRITE((HANDLE), (HANDLE)->prompt, ntlibc_strlen((HANDLE)->prompt))110 #define PROMPT_WRITE(HANDLE) SERIAL_WRITE((HANDLE), (HANDLE)->prompt, strlen((HANDLE)->prompt)) 111 111 112 112 /** … … 115 115 * @param HANDLE A pointer of the handle. 116 116 */ 117 #define PROMPT_NEWLINE(HANDLE) SERIAL_WRITE((HANDLE), NTSHELL_PROMPT_NEWLINE, ntlibc_strlen(NTSHELL_PROMPT_NEWLINE))117 #define PROMPT_NEWLINE(HANDLE) SERIAL_WRITE((HANDLE), NTSHELL_PROMPT_NEWLINE, strlen(NTSHELL_PROMPT_NEWLINE)) 118 118 119 119 /** … … 400 400 * Found the suggestion. 401 401 */ 402 int n = ntlibc_strlen((const char *)buf);402 int n = strlen((const char *)buf); 403 403 VTSEND_ERASE_LINE(ntshell); 404 404 VTSEND_CURSOR_HEAD(ntshell); … … 430 430 * Found the suggestion. 431 431 */ 432 int n = ntlibc_strlen((const char *)buf);432 int n = strlen((const char *)buf); 433 433 VTSEND_ERASE_LINE(ntshell); 434 434 VTSEND_CURSOR_HEAD(ntshell); … … 442 442 * Recall the previous input text string. 443 443 */ 444 int n = ntlibc_strlen(SUGGEST_SOURCE(ntshell));444 int n = strlen(SUGGEST_SOURCE(ntshell)); 445 445 VTSEND_ERASE_LINE(ntshell); 446 446 VTSEND_CURSOR_HEAD(ntshell); … … 485 485 UNUSED_VARIABLE(ch); 486 486 text_editor_get_text(GET_EDITOR(ntshell), buf, sizeof(buf)); 487 len = ntlibc_strlen((const char *)buf);487 len = strlen((const char *)buf); 488 488 VTSEND_CURSOR_HEAD(ntshell); 489 489 PROMPT_WRITE(ntshell); … … 607 607 p->func_callback = func_callback; 608 608 p->extobj = extobj; 609 ntlibc_strcpy(p->prompt, NTSHELL_PROMPT_DEFAULT);609 strcpy(p->prompt, NTSHELL_PROMPT_DEFAULT); 610 610 611 611 p->vtrecv.user_data = p; … … 667 667 } 668 668 669 ntlibc_strcpy(p->prompt, prompt);669 strcpy(p->prompt, prompt); 670 670 } 671 671 -
EcnlProtoTool/trunk/ntshell/ntshell/core/text_history.c
r331 r442 146 146 char *buf, const int siz) 147 147 { 148 const int text_len = ntlibc_strlen((const char *)text);148 const int text_len = strlen((const char *)text); 149 149 int found = 0; 150 150 int i; … … 152 152 int target = (p->rp + i) % TEXTHISTORY_DEPTH; 153 153 char *txtp = p->history + (TEXTHISTORY_MAXLEN * target); 154 const int target_len = ntlibc_strlen((const char *)txtp);154 const int target_len = strlen((const char *)txtp); 155 155 int comp_len = (target_len < text_len) ? target_len : text_len; 156 if (( ntlibc_strncmp(156 if ((strncmp( 157 157 (const char *)txtp, 158 158 (const char *)text, comp_len) == 0) && (comp_len > 0)) { 159 159 if (found == index) { 160 if (siz <= ntlibc_strlen(txtp)) {160 if (siz <= strlen(txtp)) { 161 161 return -1; 162 162 } 163 ntlibc_strcpy((char *)buf, (char *)txtp);163 strcpy((char *)buf, (char *)txtp); 164 164 return 0; 165 165 } -
EcnlProtoTool/trunk/ntshell/ntshell/usrcmd.c
r441 r442 32 32 33 33 #include "shellif.h" 34 #include <getopt.h> 34 35 #include <kernel.h> 35 36 #include <t_syslog.h> … … 45 46 #include "core/ntshell.h" 46 47 #include "core/ntlibc.h" 47 #include "util/ntstdio.h" 48 49 extern ntstdio_t *ntstdio; 48 50 49 extern int ntshell_exit; 51 52 /* musl_getopt from msul */53 char *optarg;54 int /*optind=1, opterr=1, */optopt, optpos, optreset=0;55 extern int optind, opterr;56 57 static void ntstdio_write(ntstdio_t *handle, const char *str, int l)58 {59 for (; *str && l >= 0; l--) {60 ntstdio_putc(handle, *str++);61 }62 }63 64 static void __getopt_msg(const char *a, const char *b, const char *c, size_t l)65 {66 ntstdio_puts(&ntstdio, a);67 ntstdio_write(&ntstdio, b, ntlibc_strlen(b));68 ntstdio_write(&ntstdio, c, l);69 ntstdio_putc(&ntstdio, '\n');70 }71 72 static int musl_getopt(int argc, char * const argv[], const char *optstring)73 {74 int i;75 wchar_t c, d;76 int k, l;77 char *optchar;78 79 if (!optind || optreset) {80 optreset = 0;81 optpos = 0;82 optind = 1;83 }84 85 if (optind >= argc || !argv[optind])86 return -1;87 88 if (argv[optind][0] != '-') {89 if (optstring[0] == '-') {90 optarg = argv[optind++];91 return 1;92 }93 return -1;94 }95 96 if (!argv[optind][1])97 return -1;98 99 if (argv[optind][1] == '-' && !argv[optind][2])100 return optind++, -1;101 102 if (!optpos) optpos++;103 if ((k = mbtowc(&c, argv[optind]+optpos, MB_LEN_MAX)) < 0) {104 k = 1;105 c = 0xfffd; /* replacement char */106 }107 optchar = argv[optind]+optpos;108 optopt = c;109 optpos += k;110 111 if (!argv[optind][optpos]) {112 optind++;113 optpos = 0;114 }115 116 if (optstring[0] == '-' || optstring[0] == '+')117 optstring++;118 119 i = 0;120 d = 0;121 do {122 l = mbtowc(&d, optstring+i, MB_LEN_MAX);123 if (l>0) i+=l; else i++;124 } while (l && d != c);125 126 if (d != c) {127 if (optstring[0] != ':' && opterr)128 __getopt_msg(argv[0], ": unrecognized option: ", optchar, k);129 return '?';130 }131 if (optstring[i] == ':') {132 if (optstring[i+1] == ':') optarg = 0;133 else if (optind >= argc) {134 if (optstring[0] == ':') return ':';135 if (opterr) __getopt_msg(argv[0],136 ": option requires an argument: ",137 optchar, k);138 return '?';139 }140 if (optstring[i+1] != ':' || optpos) {141 optarg = argv[optind++] + optpos;142 optpos = 0;143 }144 }145 return c;146 }147 50 148 51 void put_rc(const char *func, FRESULT rc) … … 158 61 while (*p++); 159 62 } 160 ntstdio_printf(ntstdio,"%s() =>%u FR_%s\n", func, (UINT)rc, p);63 printf("%s() =>%u FR_%s\n", func, (UINT)rc, p); 161 64 } 162 65 … … 170 73 while (*p++); 171 74 } 172 ntstdio_printf(ntstdio,"%s() =>%u %s\n", func, (UINT)rc, p);75 printf("%s() =>%u %s\n", func, (UINT)rc, p); 173 76 } 174 77 … … 177 80 size_t i, j; 178 81 if (!s || !*s) return "."; 179 i = ntlibc_strlen(s) - 1;82 i = strlen(s) - 1; 180 83 for (j = 0; j <= i; j++) if (s[j] == ':') { s = &s[j + 1]; i -= j; break; } 181 84 for (; i&&s[i] == '/'; i--) s[i] = 0; … … 189 92 size_t i, j; 190 93 if (!s || !*s) return "."; 191 i = ntlibc_strlen(s) - 1;94 i = strlen(s) - 1; 192 95 for (j = 0; j <= i; j++) if (s[j] == ':') { s = &s[j + 1]; i -= j; break; } 193 96 for (; s[i] == '/'; i--) if (!i) return (s == _s) ? "/" : _s; … … 219 122 } 220 123 221 ntlibc_strlcat(path, "\n", sizeof(path));222 ntstdio_printf(ntstdio,path);124 strlcat(path, "\n", sizeof(path)); 125 printf(path); 223 126 224 127 return 0; … … 243 146 244 147 if (list_option & LS_LONG) { 245 ntstdio_printf(ntstdio,"%c%c%c%c%c %04d/%02d/%02d %02d:%02d:%02d ",148 printf("%c%c%c%c%c %04d/%02d/%02d %02d:%02d:%02d ", 246 149 (fno->fattrib & AM_DIR) ? 'd' : '-', 247 150 (fno->fattrib & AM_RDO) ? 'r' : '-', … … 257 160 258 161 if (fno->fattrib & AM_DIR) { /* It is a directory */ 259 ntstdio_printf(ntstdio,"%10s ", " ");162 printf("%10s ", " "); 260 163 } 261 164 else { 262 ntstdio_printf(ntstdio,"%10lu ", fno->fsize);165 printf("%10lu ", fno->fsize); 263 166 } 264 167 } 265 168 266 169 if (fno->fattrib & AM_DIR) { /* It is a directory */ 267 ntstdio_printf(ntstdio,"\x1B[32m%s\x1B[0m\n", fn);170 printf("\x1B[32m%s\x1B[0m\n", fn); 268 171 } 269 172 else { 270 ntstdio_printf(ntstdio,"%s\n", fn);173 printf("%s\n", fn); 271 174 } 272 175 } … … 287 190 path_backup = ff_memalloc(LFN_BUF_SIZE); 288 191 if (path_backup == NULL) { 289 ntstdio_printf(ntstdio,"ff_memalloc err.\n");192 printf("ff_memalloc err.\n"); 290 193 return; 291 194 } … … 295 198 lfn = ff_memalloc(LFN_BUF_SIZE); 296 199 if (lfn == NULL) { 297 ntstdio_printf(ntstdio,"ff_memalloc err.\n");200 printf("ff_memalloc err.\n"); 298 201 ff_memfree(path_backup); 299 202 return; … … 317 220 fn = *fno.lfname ? fno.lfname : fno.fname; 318 221 #else 319 fn = fno ->fname;222 fn = fno.fname; 320 223 #endif 321 224 if ((res = f_getcwd(path_backup, LFN_BUF_SIZE)) != FR_OK) { … … 331 234 } 332 235 333 ntstdio_printf(ntstdio,"\n%s/%s:\n", path_p, fn);236 printf("\n%s/%s:\n", path_p, fn); 334 237 335 238 print_ls(fn, NULL, list_option); 336 239 337 ntstdio_printf(ntstdio,"\n");240 printf("\n"); 338 241 339 242 if ((res = f_chdrive(path_backup)) != FR_OK) { … … 370 273 BYTE list_option = 0; 371 274 372 while ((c = musl_getopt(argc, argv, "al")) != -1) {275 while ((c = getopt(argc, argv, "al")) != -1) { 373 276 switch (c) { 374 277 case 'a': … … 385 288 386 289 if (pattern_p != NULL) 387 ntlibc_strlcpy(default_pattern, pattern_p, sizeof(default_pattern));290 strlcpy(default_pattern, pattern_p, sizeof(default_pattern)); 388 291 basename_p = basename(pattern_p); 389 292 dirname_p = dirname(default_pattern); 390 293 if (((dirname_p[0] == '/') && (basename_p[0] == '/')) || 391 (! ntlibc_strncmp(dirname_p, ".", ntlibc_strlen(dirname_p)) && !ntlibc_strncmp(basename_p, ".", ntlibc_strlen(basename_p))))294 (!strncmp(dirname_p, ".", strlen(dirname_p)) && !strncmp(basename_p, ".", strlen(basename_p)))) 392 295 { 393 296 basename_p = NULL; … … 432 335 lfn = ff_memalloc(LFN_BUF_SIZE); 433 336 if (lfn == NULL) { 434 ntstdio_printf(ntstdio,"alloc err.\n");337 printf("alloc err.\n"); 435 338 goto cp_end; 436 339 } … … 442 345 local_buff = ff_memalloc(64); 443 346 if (local_buff == NULL) { 444 ntstdio_printf(ntstdio,"alloc err.\n");347 printf("alloc err.\n"); 445 348 goto cp_end; 446 349 } … … 452 355 if (res != FR_OK) { 453 356 if (res == FR_NO_FILE) 454 ntstdio_printf(ntstdio,"src no file.\n");357 printf("src no file.\n"); 455 358 else 456 ntstdio_printf(ntstdio,"src stat err(%d).\n", res);359 printf("src stat err(%d).\n", res); 457 360 goto cp_end; 458 361 } … … 463 366 res = f_open(&src_fp, src_str_p, (FA_OPEN_EXISTING | FA_READ)); 464 367 if (res != FR_OK) { 465 ntstdio_printf(ntstdio,"src open err(%d).\n", res);368 printf("src open err(%d).\n", res); 466 369 goto cp_end; 467 370 } … … 478 381 dst_mod_str_p = ff_memalloc(LFN_BUF_SIZE); 479 382 if (dst_mod_str_p == NULL) { 480 ntstdio_printf(ntstdio,"alloc err.\n");383 printf("alloc err.\n"); 481 384 goto cp_end; 482 385 } 483 ntstdio_snprintf(dst_mod_str_p, LFN_BUF_SIZE, "%s/%s\0", dst_str_p, src_basename_p);386 snprintf(dst_mod_str_p, LFN_BUF_SIZE, "%s/%s\0", dst_str_p, src_basename_p); 484 387 dst_str_p = dst_mod_str_p; 485 388 } 486 389 else { 487 ntstdio_printf(ntstdio,"dst file exists.\n");390 printf("dst file exists.\n"); 488 391 goto cp_end_1; 489 392 } 490 393 } 491 394 else { 492 ntstdio_printf(ntstdio,"src stat err(%d).\n", res);395 printf("src stat err(%d).\n", res); 493 396 goto cp_end_1; 494 397 } … … 496 399 res = f_open(&dst_fp, dst_str_p, (FA_CREATE_NEW | FA_WRITE)); 497 400 if (res != FR_OK) { 498 ntstdio_printf(ntstdio,"dst open err(%d).\n", res);401 printf("dst open err(%d).\n", res); 499 402 goto cp_end_1; 500 403 } … … 507 410 res = f_read(&src_fp, local_buff, sizeof(local_buff), &read_size); 508 411 if (res != FR_OK) { 509 ntstdio_printf(ntstdio,"src read err(%d).\n", res);412 printf("src read err(%d).\n", res); 510 413 goto cp_end_2; 511 414 } … … 514 417 res = f_write(&dst_fp, local_buff, read_size, &write_size); 515 418 if (res != FR_OK) { 516 ntstdio_printf(ntstdio,"dst write err(%d).\n", res);419 printf("dst write err(%d).\n", res); 517 420 goto cp_end_2; 518 421 } 519 422 if (read_size != write_size) { 520 ntstdio_printf(ntstdio,"dst write err(disk full).\n");423 printf("dst write err(disk full).\n"); 521 424 goto cp_end_2; 522 425 } … … 604 507 unsigned int op_offset = 0, op_size = 0, op_end = 0; 605 508 606 while ((op = musl_getopt(argc, argv, "hduos0123456789xX")) != -1) {509 while ((op = getopt(argc, argv, "hduos0123456789xX")) != -1) { 607 510 switch (op) { 608 511 case 'h': /* help */ 609 ntstdio_printf(ntstdio," hexdump [OPTION] file\n");610 ntstdio_printf(ntstdio," -h : help\n");611 ntstdio_printf(ntstdio," -d : print all byte with convert and color [in character area] (default)\n");612 ntstdio_printf(ntstdio," -u : try print UTF-8 code [in character area]\n");613 ntstdio_printf(ntstdio," -oOFFSET : print start offset address from top\n");614 ntstdio_printf(ntstdio," -sSIZE : print size\n");512 printf(" hexdump [OPTION] file\n"); 513 printf(" -h : help\n"); 514 printf(" -d : print all byte with convert and color [in character area] (default)\n"); 515 printf(" -u : try print UTF-8 code [in character area]\n"); 516 printf(" -oOFFSET : print start offset address from top\n"); 517 printf(" -sSIZE : print size\n"); 615 518 break; 616 519 case 'd': /* print one byte character [in character area] (default) */ … … 622 525 case 'o': /* print start offset address from top */ 623 526 option_ptr = *(argv + optind); 624 op_offset = ntlibc_strtoul(&option_ptr[2], &option_endptr, 0);527 op_offset = strtoul(&option_ptr[2], &option_endptr, 0); 625 528 break; 626 529 case 's': /* print size */ 627 530 option_ptr = *(argv + optind); 628 op_size = ntlibc_strtoul(&option_ptr[2], &option_endptr, 0);531 op_size = strtoul(&option_ptr[2], &option_endptr, 0); 629 532 break; 630 533 default: … … 643 546 /* position adjusting */ 644 547 if (op_offset >= fsrc.fsize) { 645 ntstdio_printf(ntstdio,"error : input offset is bigger than file size(0x%lX).\n", fsrc.fsize);548 printf("error : input offset is bigger than file size(0x%lX).\n", fsrc.fsize); 646 549 return 0; 647 550 } … … 656 559 char *pos = line; 657 560 int rst = sizeof(line); 658 int len = ntstdio_snprintf(pos, rst, "%08X: ", i);561 int len = snprintf(pos, rst, "%08X: ", i); 659 562 pos += len; 660 563 rst -= len; … … 675 578 unsigned char c = data[j]; 676 579 if (j != 7) 677 len = ntstdio_snprintf(pos, rst, "%02X ", c);580 len = snprintf(pos, rst, "%02X ", c); 678 581 else 679 len = ntstdio_snprintf(pos, rst, "%02X-", c);582 len = snprintf(pos, rst, "%02X-", c); 680 583 pos += len; 681 584 rst -= len; … … 705 608 break; 706 609 if (j + k != 7) 707 len = ntstdio_snprintf(pos, rst, "%02X ", data[j + k]);610 len = snprintf(pos, rst, "%02X ", data[j + k]); 708 611 else 709 len = ntstdio_snprintf(pos, rst, "%02X-", data[j + k]);612 len = snprintf(pos, rst, "%02X-", data[j + k]); 710 613 pos += len; 711 614 rst -= len; … … 725 628 apos += len; 726 629 arst -= len; 727 len = ntstdio_snprintf(apos, arst, "\x1B[%dm%c\x1B[0m", CCOLOR_RESET, ' ');630 len = snprintf(apos, arst, "\x1B[%dm%c\x1B[0m", CCOLOR_RESET, ' '); 728 631 utf8_odd_bytes--; 729 632 } … … 745 648 c = '?'; 746 649 } 747 len = ntstdio_snprintf(apos, arst, "\x1B[%dm%c\x1B[0m", ccolor, c);650 len = snprintf(apos, arst, "\x1B[%dm%c\x1B[0m", ccolor, c); 748 651 } 749 652 … … 754 657 for (int j = br; j < 16; j++) { 755 658 if (j != 7) 756 len = ntstdio_snprintf(pos, rst, " ");659 len = snprintf(pos, rst, " "); 757 660 else 758 len = ntstdio_snprintf(pos, rst, " -");661 len = snprintf(pos, rst, " -"); 759 662 pos += len; 760 663 rst -= len; 761 664 } 762 665 763 len = ntstdio_snprintf(pos, rst, ": %s\n", ascii);666 len = snprintf(pos, rst, ": %s\n", ascii); 764 667 pos += len; 765 668 rst -= len; 766 669 767 ntstdio_puts(ntstdio,line);670 printf(line); 768 671 } 769 672 … … 780 683 ret = shell_clock_gettime(CLOCK_REALTIME, &tp); 781 684 if (ret != 0) { 782 ntstdio_printf(ntstdio,"clock_gettime error %d", ret);685 printf("clock_gettime error %d", ret); 783 686 return 0; 784 687 } … … 786 689 memset(buf, 0, sizeof(buf)); 787 690 if (ctime_r(&tp.tv_sec, buf) == NULL) { 788 ntstdio_printf(ntstdio,"ctime_r error");691 printf("ctime_r error"); 789 692 return 0; 790 693 } 791 694 792 695 /* 改行コードの削除 */ 793 ret = ntlibc_strlen(buf);696 ret = strlen(buf); 794 697 buf[ret - 1] = '\0'; 795 698 796 ntstdio_printf(ntstdio,"%s .%09ld\n", buf, tp.tv_nsec);699 printf("%s .%09ld\n", buf, tp.tv_nsec); 797 700 return 0; 798 701 } … … 801 704 { 802 705 if (argc != 2) { 803 ntstdio_printf(ntstdio,"info sys\n");804 ntstdio_printf(ntstdio,"info ver\n");805 return 0; 806 } 807 if ( ntlibc_strcmp(argv[1], "sys") == 0) {808 ntstdio_printf(ntstdio,TARGET_NAME" Monitor\n");809 return 0; 810 } 811 if ( ntlibc_strcmp(argv[1], "ver") == 0) {706 printf("info sys\n"); 707 printf("info ver\n"); 708 return 0; 709 } 710 if (strcmp(argv[1], "sys") == 0) { 711 printf(TARGET_NAME" Monitor\n"); 712 return 0; 713 } 714 if (strcmp(argv[1], "ver") == 0) { 812 715 int mj, mn, bd; 813 716 ntshell_version(&mj, &mn, &bd); 814 ntstdio_printf(ntstdio,"Version %d.%d.%d\n", mj, mn, bd);815 return 0; 816 } 817 ntstdio_printf(ntstdio,"Unknown sub command found\n");717 printf("Version %d.%d.%d\n", mj, mn, bd); 718 return 0; 719 } 720 printf("Unknown sub command found\n"); 818 721 return -1; 819 722 } -
EcnlProtoTool/trunk/ntshell/src/fdtable.c
r441 r442 36 36 */ 37 37 #include "shellif.h" 38 #include <stdint.h>39 38 #include <kernel.h> 40 39 #include <t_syslog.h> … … 46 45 #include "fdtable.h" 47 46 #include "kernel_cfg.h" 48 #include <string.h>49 #include "util/ntstdio.h"50 47 #include "hal/serial_api.h" 51 48 -
EcnlProtoTool/trunk/ntshell/src/io_stub.c
r441 r442 36 36 */ 37 37 #include "shellif.h" 38 #include <stdint.h>39 38 #include "ff.h" 40 39 #include <kernel.h> … … 42 41 #include <t_stdlib.h> 43 42 #include <sil.h> 44 #include <string.h>45 43 #include "syssvc/serial.h" 46 44 #include "syssvc/syslog.h" 47 45 #include "fdtable.h" 48 #include "util/ntstdio.h"49 46 #include "usrcmd.h" 50 47 #include "core/ntlibc.h" … … 305 302 fi.lfsize = sizeof lfn; 306 303 #endif 307 if ( ntlibc_strcmp(path, ".") == 0) {304 if (strcmp(path, ".") == 0) { 308 305 char cwd[FF_MAX_LFN]; 309 306 if ((ret = f_getcwd(cwd, sizeof(cwd))) != FR_OK) { 310 307 return fresult2errno(ret); 311 308 } 312 int l = ntlibc_strlen(cwd);309 int l = strlen(cwd); 313 310 // ルートディレクトリの場合 314 311 if (cwd[l - 2] == ':' && cwd[l - 1] == '/') { … … 485 482 memset(de, 0, sizeof(*de)); 486 483 #if FF_USE_LFN 487 ntlibc_strlcpy(de->d_name, *fno.lfname ? fno.lfname : fno.fname, sizeof(de->d_name));484 strlcpy(de->d_name, *fno.lfname ? fno.lfname : fno.fname, sizeof(de->d_name)); 488 485 #else 489 ntlibc_strlcpy(de->d_name, fno.fname, sizeof(de->d_name));486 strlcpy(de->d_name, fno.fname, sizeof(de->d_name)); 490 487 #endif 491 488 … … 559 556 pid_t shell_getpid(void) 560 557 { 561 return 1;558 return 2; 562 559 } 563 560 -
EcnlProtoTool/trunk/ntshell/src/main.c
r441 r442 40 40 */ 41 41 42 #include "shellif.h"43 42 #include <kernel.h> 44 43 #include <t_stdlib.h> … … 51 50 #include "kernel_cfg.h" 52 51 #include "main.h" 52 #include "mbed_retarget.h" 53 53 #include "fdtable.h" 54 54 #ifndef NTSHELL_NO_SOCKET … … 69 69 #include "core/ntshell.h" 70 70 #include "core/ntlibc.h" 71 #include "util/ntstdio.h"72 71 #include "usrcmd.h" 73 72 #include "util/ntopt.h" … … 79 78 ID ws_api_mailboxid = MAIN_DATAQUEUE; 80 79 ID ws_mempoolid = MPF_NET_BUF_256; 81 extern ntstdio_t *ntstdio;82 80 83 81 char command[NTOPT_TEXT_MAXLEN]; 84 82 85 83 const uint8_t mac_addr[6] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC}; 86 const struct utsname host_name = {87 "TOPPERS/ASP3",88 TARGET_NAME,89 "3.5.0",90 "3.5.0",91 TARGET_NAME,92 "toppers.jp"93 };94 95 int shell_uname(struct utsname *uts)96 {97 memcpy(uts, &host_name, sizeof(host_name));98 return 0;99 }100 84 101 85 enum main_state_t { … … 220 204 { 221 205 if (text != NULL) { 222 ntlibc_strlcpy(command, text, sizeof(command));206 strlcpy(command, text, sizeof(command)); 223 207 } 224 208 ER ret; … … 552 536 return result; 553 537 554 if (ntlibc_strcmp((const char *)args[1], "help") == 0) { 555 found = 1; 538 if (strcmp((const char *)args[1], "help") == 0) { 556 539 result = usrcmd_help(args[0], (char **)&args[1]); 557 540 } 558 541 else for (int i = 0; i < cmd_table_info.count; i++) { 559 if ( ntlibc_strcmp((const char *)args[1], p->cmd) == 0) {542 if (strcmp((const char *)args[1], p->cmd) == 0) { 560 543 found = 1; 561 544 result = p->func(args[0], (char **)&args[1]); … … 571 554 572 555 if ((found == 0) && (((const char *)args[1])[0] != '\0')) 573 ntstdio_printf(ntstdio,"Unknown command found. %s \n", (const char *)args[1]);556 printf("Unknown command found. %s \n", (const char *)args[1]); 574 557 575 558 return result; … … 580 563 const cmd_table_t *p = cmd_table_info.table; 581 564 for (int i = 0; i < cmd_table_info.count; i++) { 582 ntstdio_puts(ntstdio, p->cmd); 583 ntstdio_puts(ntstdio, "\t:"); 584 ntstdio_puts(ntstdio, p->desc); 585 ntstdio_puts(ntstdio, "\n"); 565 printf(p->cmd); 566 printf("\t:"); 567 puts(p->desc); 586 568 p++; 587 569 } … … 599 581 /* shellcmdタスクの優先度に戻す */ 600 582 chg_pri(SHELLCMD_PRIORITY, SHELLCMD_PRIORITY); 601 }602 603 void shell_abort()604 {605 shellcmd_exit_code = -1;606 longjmp(shellcmd_exit, 1);607 }608 609 void shell_exit(int exitcd)610 {611 shellcmd_exit_code = exitcd;612 longjmp(shellcmd_exit, 1);613 }614 615 void shell_exit_group(int exitcd)616 {617 shellcmd_exit_code = exitcd;618 longjmp(shellcmd_exit, 1);619 583 } 620 584 … … 679 643 } 680 644 681 int shell_clock_getres(clockid_t clk_id, struct timespec *res)682 {683 if ((clk_id != CLOCK_REALTIME) && (clk_id != CLOCK_MONOTONIC))684 return -EINVAL;685 686 memset(&res->tv_sec, 0xFF, sizeof(res->tv_sec));687 res->tv_nsec = 0;688 689 return 0;690 }691 692 int shell_clock_gettime(clockid_t clk_id, struct timespec *tp)693 {694 SYSTIM now = 0;695 696 if ((clk_id != CLOCK_REALTIME) && (clk_id != CLOCK_MONOTONIC))697 return -EINVAL;698 699 get_tim(&now);700 tp->tv_sec = now / 1000000;701 tp->tv_nsec = (now % 1000000) * 1000;702 703 return 0;704 }705 706 int shell_clock_settime(clockid_t clk_id, const struct timespec *tp)707 {708 if ((clk_id != CLOCK_REALTIME) && (clk_id != CLOCK_MONOTONIC))709 return -EINVAL;710 711 SYSTIM time;712 ER ret;713 714 time = (tp->tv_sec * 1000000ll) + (tp->tv_nsec / 1000ll);715 716 ret = set_tim(time);717 if (ret != E_OK) {718 return -EPERM;719 }720 721 return 0;722 }723 724 sigset_t g_sigmask;725 726 int shell_sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old)727 {728 if (old != NULL)729 memcpy(old, &g_sigmask, sizeof(sigset_t));730 731 switch (how) {732 case SIG_BLOCK:733 for (int i = 0; i < sizeof(g_sigmask.__bits) / sizeof(g_sigmask.__bits[0]); i++) {734 g_sigmask.__bits[i] |= set->__bits[i];735 }736 break;737 case SIG_UNBLOCK:738 for (int i = 0; i < sizeof(g_sigmask.__bits) / sizeof(g_sigmask.__bits[0]); i++) {739 g_sigmask.__bits[i] &= ~set->__bits[i];740 }741 break;742 case SIG_SETMASK:743 memcpy(&g_sigmask, set, sizeof(sigset_t));744 break;745 default:746 return -EINVAL;747 }748 749 return 0;750 }751 752 // musl-1.1.18\src\internal\ksigaction.h753 struct k_sigaction {754 void(*handler)(int);755 unsigned long flags;756 void(*restorer)(void);757 unsigned mask[2];758 };759 760 struct k_sigaction sigtable[7];761 762 int shell_sigaction(int sig, const struct k_sigaction *restrict sa,763 struct k_sigaction *restrict old, size_t size)764 {765 struct k_sigaction *sat;766 767 switch(sig){768 case SIGALRM:769 sat = &sigtable[0];770 break;771 case SIGFPE:772 sat = &sigtable[1];773 break;774 case SIGILL:775 sat = &sigtable[2];776 break;777 case SIGSEGV:778 sat = &sigtable[3];779 break;780 case SIGBUS:781 sat = &sigtable[4];782 break;783 case SIGABRT:784 sat = &sigtable[5];785 break;786 case SIGPIPE:787 sat = &sigtable[6];788 break;789 default:790 return -EINVAL;791 }792 793 if (old != NULL)794 memcpy(old, sat, offsetof(struct k_sigaction, mask) + size);795 796 memcpy(sat, sa, offsetof(struct k_sigaction, mask) + size);797 798 return 0;799 }800 801 int shell_madvise(void *a, size_t b, int c)802 {803 return 0;804 }805 806 int shell_gettid()807 {808 ID tskid;809 ER ret;810 811 ret = get_tid(&tskid);812 if (ret != E_OK)813 return -1;814 815 return tskid;816 }817 818 int shell_tkill(int tid, int sig)819 {820 if ((tid == SHELLCMD_TASK) && (sig == SIGABRT)) {821 shell_abort();822 }823 824 no_implement("tkill");825 return -1;826 }827 828 int shell_kill(int pid, int sig)829 {830 DebugBreak();831 return -1;832 }833 834 int shell_gettimeofday(struct timeval *tv, void *tzvp)835 {836 SYSTIM time;837 if (!tv) return 0;838 get_tim(&time);839 tv->tv_sec = time / 1000000;840 tv->tv_usec = time - (tv->tv_sec * 1000000);841 return 0;842 }843 844 int shell_nanosleep(const struct timespec *req, struct timespec *rem)845 {846 ER ret;847 TMO tmo;848 SYSTIM prev, now, diff;849 850 if ((req == NULL) || (req->tv_nsec < 0) || (req->tv_nsec >= 1000000000))851 return -EINVAL;852 853 get_tim(&prev);854 855 tmo = req->tv_sec * 1000000 + req->tv_nsec / 1000;856 ret = tslp_tsk(tmo);857 if (ret == E_OK) {858 if (rem != NULL) {859 get_tim(&now);860 diff = now - prev;861 rem->tv_sec = diff / 1000000ll;862 rem->tv_nsec = (diff - (rem->tv_sec * 1000000ll)) * 1000ll;863 }864 return 0;865 }866 else if (ret == E_TMOUT) {867 if (rem != NULL) {868 rem->tv_sec = 0;869 rem->tv_nsec = 0;870 }871 return 0;872 }873 874 return -EFAULT;875 }876 877 ssize_t shell_getrandom(void *buf, size_t buflen, unsigned int flags)878 {879 SYSTIM now;880 int32_t i;881 int *output = (int *)buf;882 size_t sz = buflen / 4;883 884 get_tim(&now);885 srand(now);886 887 for (i = 0; i < sz; i++)888 output[i] = rand();889 890 for (i = 4 * sz; i < buflen; i++)891 ((char *)buf)[i] = rand();892 893 return buflen;894 }895 896 extern uint32_t __CmdBase;897 extern uint32_t __CmdLimit;898 899 void *shell_brk(void *addr)900 {901 if (addr == 0) {902 return (void *)((intptr_t)&__CmdBase + 0x40000);903 }904 if ((addr >= (intptr_t)&__CmdBase + 0x40000) && (addr < &__CmdLimit)) {905 return addr;906 }907 return (void *)-1;908 }909 910 void *shell_mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset)911 {912 if (fd != -1)913 return -EINVAL;914 915 if ((length >= 0) && (length <= (intptr_t)&__CmdLimit - ((intptr_t)&__CmdBase + 0x40000))) {916 return &__CmdBase + 0x40000;917 }918 return (void *)-1;919 }920 921 int shell_mprotect(void *addr, size_t len, int prot)922 {923 //if ((addr >= (intptr_t)&__CmdBase + 0x40000) && ((intptr_t)addr + len < &__CmdLimit)) {924 return 0;925 //}926 //return -1;927 } -
EcnlProtoTool/trunk/ntshell/src/netcmd.c
r441 r442 40 40 #include <t_stdlib.h> 41 41 #include <sil.h> 42 #include <string.h>43 42 #include "syssvc/serial.h" 44 43 #include "syssvc/syslog.h" … … 59 58 #include <netapp/resolver.h> 60 59 #include "core/ntlibc.h" 61 #include "util/ntstdio.h"62 #include <stdio.h>63 60 #include "ntp_cli.h" 64 61 #include "kernel_cfg.h" … … 71 68 extern void ping6(T_IN6_ADDR *addr, uint_t tmo, uint_t len); 72 69 extern void ping4(T_IN4_ADDR *addr, uint_t tmo, uint_t len); 73 extern ntstdio_t *ntstdio;74 70 75 71 /* … … 255 251 256 252 if (apip == '1') 257 ntlibc_strcpy(line, i6rlp_pmtu_str1);253 strcpy(line, i6rlp_pmtu_str1); 258 254 else if (apip == '2') 259 ntlibc_strcpy(line, i6rlp_pmtu_str2);255 strcpy(line, i6rlp_pmtu_str2); 260 256 else if (apip == '3') 261 ntlibc_strcpy(line, i6rlp_pmtu_str3);257 strcpy(line, i6rlp_pmtu_str3); 262 258 263 259 #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) … … 280 276 281 277 if ((line = lookup_ipaddr(&addr, line, apip)) == NULL) { 282 ntstdio_printf(ntstdio,"[PING] unknown host.\n");278 printf("[PING] unknown host.\n"); 283 279 return 0; 284 280 } … … 299 295 #if defined(SUPPORT_INET4) 300 296 if (apip == API_PROTO_IPV6) { 301 ntstdio_printf(ntstdio,"[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));297 printf("[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr)); 302 298 ping6(&addr, (uint_t)tmo, (uint_t)size); 303 299 } 304 300 else { 305 301 addr4 = ntohl(addr.s6_addr32[3]); 306 ntstdio_printf(ntstdio,"[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr4));302 printf("[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr4)); 307 303 ping4(&addr4, (uint_t)tmo, (uint_t)size); 308 304 } 309 305 #else /* of #if defined(SUPPORT_INET4) */ 310 ntstdio_printf(ntstdio,"[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));306 printf("[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr)); 311 307 ping6(&addr, (uint_t)tmo, (uint_t)size); 312 308 #endif /* of #if defined(SUPPORT_INET4) */ 313 309 #else /* of #if defined(SUPPORT_INET6) */ 314 ntstdio_printf(ntstdio,"[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr));310 printf("[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr)); 315 311 ping4(&addr, (uint_t)tmo, (uint_t)size); 316 312 #endif /* of #if defined(SUPPORT_INET6) */ … … 331 327 pos = str_ipv4addr(temp, sizeof(temp), &svaddr, 0); 332 328 temp[pos] = '\0'; 333 ntstdio_printf(ntstdio,"DHCPv4 server: %s,\n", temp);334 ntstdio_printf(ntstdio," Renew: %u:%02u:%02u,\n",329 printf("DHCPv4 server: %s,\n", temp); 330 printf(" Renew: %u:%02u:%02u,\n", 335 331 renew / 3600, (renew / 60) % 60, renew % 60); 336 ntstdio_printf(ntstdio," Rebind: %u:%02u:%02u, Expire: %u:%02u:%02u.\n",332 printf(" Rebind: %u:%02u:%02u, Expire: %u:%02u:%02u.\n", 337 333 rebind / 3600, (rebind / 60) % 60, rebind % 60, 338 334 expire / 3600, (expire / 60) % 60, expire % 60); 339 335 } 340 336 else if (ret == E_OBJ) 341 ntstdio_printf(ntstdio,"DHCPv4 server: not available.\n");337 printf("DHCPv4 server: not available.\n"); 342 338 } 343 339 … … 349 345 return 0; 350 346 351 if ( ntlibc_strcmp(argv[1], "rel") == 0) {347 if (strcmp(argv[1], "rel") == 0) { 352 348 ret = dhcp4c_rel_info(); 353 ntstdio_printf(ntstdio,"dhcp4c_rel_info %d\n", ret);354 } 355 else if ( ntlibc_strcmp(argv[1], "renew") == 0) {349 printf("dhcp4c_rel_info %d\n", ret); 350 } 351 else if (strcmp(argv[1], "renew") == 0) { 356 352 ret = dhcp4c_renew_info(); 357 ntstdio_printf(ntstdio,"dhcp4c_renew_info %d\n", ret);353 printf("dhcp4c_renew_info %d\n", ret); 358 354 } 359 355 else { … … 383 379 else { 384 380 for (c = 1; c <= *ptr; c++) 385 ntstdio_printf(ntstdio,"%c", *(ptr + c));381 printf("%c", *(ptr + c)); 386 382 ptr += *ptr + 1; 387 383 if (*ptr) 388 ntstdio_printf(ntstdio,".");384 printf("."); 389 385 } 390 386 } … … 406 402 return error; 407 403 408 ntstdio_printf(ntstdio," mname: ");404 printf(" mname: "); 409 405 rn_offset = s_show_dns_domain_name(msg, offset); 410 406 putchar('\n'); 411 ntstdio_printf(ntstdio," rname: ");407 printf(" rname: "); 412 408 s_show_dns_domain_name(msg, rn_offset); 413 409 putchar('\n'); 414 410 415 ntstdio_printf(ntstdio," serial: %d\n", soa.serial);416 ntstdio_printf(ntstdio," refresh: %d\n", soa.refresh);417 ntstdio_printf(ntstdio," retry: %d\n", soa.retry);418 ntstdio_printf(ntstdio," expirel: %d\n", soa.expire);419 ntstdio_printf(ntstdio," minimum: %d\n", soa.minimum);411 printf(" serial: %d\n", soa.serial); 412 printf(" refresh: %d\n", soa.refresh); 413 printf(" retry: %d\n", soa.retry); 414 printf(" expirel: %d\n", soa.expire); 415 printf(" minimum: %d\n", soa.minimum); 420 416 421 417 return E_OK; … … 433 429 int scount; 434 430 435 ntstdio_printf(ntstdio,"question section: %d\n", rslv->dns_hdr.qdcount);431 printf("question section: %d\n", rslv->dns_hdr.qdcount); 436 432 offset = rslv->qd_offset; 437 433 for (scount = 1; scount <= rslv->dns_hdr.qdcount; scount++) { … … 439 435 return error; 440 436 441 ntstdio_printf(ntstdio,"%2d: ", scount);437 printf("%2d: ", scount); 442 438 s_show_dns_domain_name(msg, offset); 443 ntstdio_printf(ntstdio,"\n type: %-4s, class: %2s\n", dns_strtype(qd.type), dns_strclass(qd.class));439 printf("\n type: %-4s, class: %2s\n", dns_strtype(qd.type), dns_strclass(qd.class)); 444 440 offset = error; 445 441 } … … 463 459 int pos; 464 460 465 ntstdio_printf(ntstdio,"%10s section: %d\n", title, scount);461 printf("%10s section: %d\n", title, scount); 466 462 for (count = 1; count <= scount; count++) { 467 463 if ((error = dns_analyze_rr(&rr, offset, msg, length)) < 0) 468 464 return error; 469 465 470 ntstdio_printf(ntstdio,"%2d: ", count);466 printf("%2d: ", count); 471 467 s_show_dns_domain_name(msg, offset); 472 ntstdio_printf(ntstdio,"\n type: %-4s, class: %2s, TTL: %2d, len: %3d, offset: 0x%02x\n",468 printf("\n type: %-4s, class: %2s, TTL: %2d, len: %3d, offset: 0x%02x\n", 473 469 dns_strtype(rr.type), dns_strclass(rr.class), rr.ttl, rr.rdlength, rr.rdata_offset); 474 470 … … 479 475 pos = str_ipv4addr(temp, sizeof(temp), &in4_addr, 0); 480 476 temp[pos] = '\0'; 481 ntstdio_printf(ntstdio," IPv4 addr: %s\n", temp);477 printf(" IPv4 addr: %s\n", temp); 482 478 break; 483 479 case DNS_TYPE_NS: 484 ntstdio_printf(ntstdio," host: ");480 printf(" host: "); 485 481 s_show_dns_domain_name(msg, rr.rdata_offset); 486 482 putchar('\n'); 487 483 break; 488 484 case DNS_TYPE_CNAME: 489 ntstdio_printf(ntstdio," host: ");485 printf(" host: "); 490 486 s_show_dns_domain_name(msg, rr.rdata_offset); 491 487 putchar('\n'); … … 495 491 break; 496 492 case DNS_TYPE_PTR: 497 ntstdio_printf(ntstdio," PTR: ");493 printf(" PTR: "); 498 494 s_show_dns_domain_name(msg, rr.rdata_offset); 499 495 putchar('\n'); … … 503 499 pos = str_ipv6addr(temp, sizeof(temp), &in6_addr, 0); 504 500 temp[pos] = '\0'; 505 ntstdio_printf(ntstdio," IPv6 addr: %s\n", temp);501 printf(" IPv6 addr: %s\n", temp); 506 502 break; 507 503 default: 508 ntstdio_printf(ntstdio," data: ");504 printf(" data: "); 509 505 col = 32; 510 506 for (dcount = 0; dcount < rr.rdlength; dcount++) { 511 ntstdio_printf(ntstdio,"%02x", *(msg + rr.rdata_offset + dcount));507 printf("%02x", *(msg + rr.rdata_offset + dcount)); 512 508 if (--col == 0) { 513 ntstdio_printf(ntstdio,"\n ");509 printf("\n "); 514 510 col = 32; 515 511 } … … 539 535 #if defined(SUPPORT_INET6) 540 536 541 ntstdio_printf(ntstdio,"domain name: %s\n", dns_in6_get_dname());537 printf("domain name: %s\n", dns_in6_get_dname()); 542 538 543 539 #else /* of #if defined(SUPPORT_INET6) */ 544 540 545 ntstdio_printf(ntstdio,"domain name: %s\n", dns_in4_get_dname());541 printf("domain name: %s\n", dns_in4_get_dname()); 546 542 547 543 #endif /* of #if defined(SUPPORT_INET6) */ … … 549 545 #if defined(SUPPORT_INET6) 550 546 dns_in6_get_addr(&in6_addr); 551 ntstdio_printf(ntstdio,"IPv6 DNS server: ");547 printf("IPv6 DNS server: "); 552 548 if (IN6_IS_ADDR_UNSPECIFIED(&in6_addr)) 553 ntstdio_printf(ntstdio,"not available.\n");549 printf("not available.\n"); 554 550 else { 555 551 pos = str_ipv6addr(temp, sizeof(temp), &in6_addr, 0); 556 552 temp[pos] = '\0'; 557 ntstdio_printf(ntstdio,"%s.\n", temp);553 printf("%s.\n", temp); 558 554 } 559 555 #endif /* of #if defined(SUPPORT_INET6) */ … … 561 557 #if defined(SUPPORT_INET4) 562 558 dns_in4_get_addr(&in4_addr); 563 ntstdio_printf(ntstdio,"IPv4 DNS server: ");559 printf("IPv4 DNS server: "); 564 560 if (in4_addr == IPV4_ADDRANY) 565 ntstdio_printf(ntstdio,"not available.\n");561 printf("not available.\n"); 566 562 else { 567 563 pos = str_ipv4addr(temp, sizeof(temp), &in4_addr, 0); 568 564 temp[pos] = '\0'; 569 ntstdio_printf(ntstdio,"%s.\n", temp);565 printf("%s.\n", temp); 570 566 } 571 567 #endif /* of #if defined(SUPPORT_INET4) */ … … 596 592 uint8_t *msg; 597 593 598 if ( ntlibc_strcmp(line, "info") == 0) {594 if (strcmp(line, "info") == 0) { 599 595 dns_info(); 600 596 return 0; … … 604 600 line = skip_blanks(resolv_options(&flags, line, DEFAULT_API_PROTO)); 605 601 if ((flags & (DNS_LUP_FLAGS_PROTO_IPV6 | DNS_LUP_FLAGS_PROTO_IPV4)) == 0) { 606 ntstdio_printf(ntstdio,"DNS server not available.\n");602 printf("DNS server not available.\n"); 607 603 return 0; 608 604 } … … 620 616 621 617 if ((error = tget_mpf(MPF_RSLV_SRBUF, (void*)&msg, TMO_FEVR)) != E_OK) { 622 ntstdio_printf(ntstdio,"get buffer error: %s.\n", itron_strerror(error));618 printf("get buffer error: %s.\n", itron_strerror(error)); 623 619 return 0; 624 620 } 625 621 626 622 if ((length = dns_lookup_host(flags | DNS_LUP_FLAGS_MSG, line, msg, DNS_UDP_MSG_LENGTH, &rslv)) < 0) { 627 // ntstdio_printf(ntstdio,"error: %s.\n", itron_strerror(length));623 //printf("error: %s.\n", itron_strerror(length)); 628 624 goto err_ret; 629 625 } 630 626 631 627 dly_tsk(1 * 1000); 632 ntstdio_printf(ntstdio,"DNS header: flags: ");628 printf("DNS header: flags: "); 633 629 if (rslv.dns_hdr.code & (DNS_QR_RESPONSE | DNS_AUTHORITATIVE | 634 630 DNS_TRUN_CATION | DNS_RECURSION_DESIRED | DNS_RECURSION_AVAILABLE)) { 635 ntstdio_printf(ntstdio,(rslv.dns_hdr.code & DNS_QR_RESPONSE) ? "QR," : "");636 ntstdio_printf(ntstdio,(rslv.dns_hdr.code & DNS_AUTHORITATIVE) ? "AA," : "");637 ntstdio_printf(ntstdio,(rslv.dns_hdr.code & DNS_TRUN_CATION) ? "TC," : "");638 ntstdio_printf(ntstdio,(rslv.dns_hdr.code & DNS_RECURSION_DESIRED) ? "RD," : "");639 ntstdio_printf(ntstdio,(rslv.dns_hdr.code & DNS_RECURSION_AVAILABLE) ? "RA," : "");640 ntstdio_printf(ntstdio," ");641 } 642 ntstdio_printf(ntstdio,"opcode: ");643 ntstdio_printf(ntstdio,(rslv.dns_hdr.code & DNS_OPCODE_REVERSE) ? "RV" : "FW");644 ntstdio_printf(ntstdio,(rslv.dns_hdr.code & DNS_OPCODE_STATUS) ? ",ST" : "");645 ntstdio_printf(ntstdio,", rcode: %s.\n",631 printf((rslv.dns_hdr.code & DNS_QR_RESPONSE) ? "QR," : ""); 632 printf((rslv.dns_hdr.code & DNS_AUTHORITATIVE) ? "AA," : ""); 633 printf((rslv.dns_hdr.code & DNS_TRUN_CATION) ? "TC," : ""); 634 printf((rslv.dns_hdr.code & DNS_RECURSION_DESIRED) ? "RD," : ""); 635 printf((rslv.dns_hdr.code & DNS_RECURSION_AVAILABLE) ? "RA," : ""); 636 printf(" "); 637 } 638 printf("opcode: "); 639 printf((rslv.dns_hdr.code & DNS_OPCODE_REVERSE) ? "RV" : "FW"); 640 printf((rslv.dns_hdr.code & DNS_OPCODE_STATUS) ? ",ST" : ""); 641 printf(", rcode: %s.\n", 646 642 (rslv.dns_hdr.code & DNS_RCODE_MASK) > DNS_RCODE_REFUSED 647 643 ? "6" : rcode_str[rslv.dns_hdr.code & DNS_RCODE_MASK]); 648 644 649 645 if ((offset = show_dns_qdsection(msg, length, &rslv)) < 0) { 650 ntstdio_printf(ntstdio,"msg error: %s.\n", itron_strerror(offset));646 printf("msg error: %s.\n", itron_strerror(offset)); 651 647 } 652 648 if ((offset = show_dns_section(msg, length, rslv.dns_hdr.ancount, rslv.an_offset, "answer")) < 0) { 653 ntstdio_printf(ntstdio,"msg error: %s.\n", itron_strerror(offset));649 printf("msg error: %s.\n", itron_strerror(offset)); 654 650 } 655 651 if ((offset = show_dns_section(msg, length, rslv.dns_hdr.nscount, rslv.ns_offset, "authority")) < 0) { 656 ntstdio_printf(ntstdio,"msg error: %s.\n", itron_strerror(offset));652 printf("msg error: %s.\n", itron_strerror(offset)); 657 653 } 658 654 if ((offset = show_dns_section(msg, length, rslv.dns_hdr.arcount, rslv.ar_offset, "additional")) < 0) { 659 ntstdio_printf(ntstdio,"msg error: %s.\n", itron_strerror(offset));655 printf("msg error: %s.\n", itron_strerror(offset)); 660 656 } 661 657 662 658 err_ret: 663 659 if ((error = rel_mpf(MPF_RSLV_SRBUF, msg)) != E_OK) 664 ntstdio_printf(ntstdio,"release buffer error: %s.\n", itron_strerror(error));660 printf("release buffer error: %s.\n", itron_strerror(error)); 665 661 return 0; 666 662 } -
EcnlProtoTool/trunk/ntshell/src/ntp_cli.c
r441 r442 271 271 272 272 nc->buf[0] = '\0'; 273 #ifdef _ _NEED_struct_timespec273 #ifdef _TIME_H_ 274 274 if (ctime_r(&tp.tv_sec, nc->buf) != NULL) 275 275 #else -
EcnlProtoTool/trunk/ntshell/src/pipe_stub.c
r441 r442 36 36 */ 37 37 #include "shellif.h" 38 #include <stdint.h>39 38 #include <kernel.h> 40 39 #include <t_syslog.h> … … 46 45 #include "fdtable.h" 47 46 #include "kernel_cfg.h" 48 #include <string.h>49 #include "util/ntstdio.h"50 47 #include "hal/serial_api.h" 51 48 -
EcnlProtoTool/trunk/ntshell/src/shellif.h
r441 r442 88 88 #define NCCS 32 89 89 90 #include "../musl-1.1.18/include/stdint.h" 91 #include "../musl-1.1.18/include/strings.h" 92 #define _STRINGS_H_ // newlibã®strings.hã®includeãææ¢ 93 #include "../musl-1.1.18/include/string.h" 94 #define _STRING_H_ // newlibã®string.hã®includeãææ¢ 90 95 #include "../musl-1.1.18/include/bits/fcntl.h" 91 96 #include "../musl-1.1.18/include/bits/termios.h" … … 93 98 #include "../musl-1.1.18/include/sys/select.h" 94 99 #include "../musl-1.1.18/include/time.h" 100 #define _TIME_H_ // newlibã®time.hã®includeãææ¢ 95 101 #include "../musl-1.1.18/include/signal.h" 96 102 #include "../musl-1.1.18/include/stdio.h" 103 #define _STDIO_H_ // newlibã®stdio.hã®includeãææ¢ 97 104 #include "../musl-1.1.18/include/sys/utsname.h" 98 105 #include "../musl-1.1.18/include/dirent.h" … … 104 111 #include <stddef.h> 105 112 #include <stdarg.h> 113 #include <setjmp.h> 106 114 107 115 #define DebugBreak() asm("bkpt #0") -
EcnlProtoTool/trunk/ntshell/src/socket_stub.c
r441 r442 39 39 #include <t_syslog.h> 40 40 #include <t_stdlib.h> 41 #include <string.h>42 41 #include <sil.h> 43 42 #include "syssvc/syslog.h" -
EcnlProtoTool/trunk/ntshell/src/stdio_stub.c
r441 r442 36 36 */ 37 37 #include "shellif.h" 38 #include <stdint.h>39 38 #include <kernel.h> 40 39 #include <t_syslog.h> … … 46 45 #include "fdtable.h" 47 46 #include "kernel_cfg.h" 48 #include <string.h>49 #include <errno.h>50 47 #include "util/ntstdio.h" 51 48 #include "hal/serial_api.h" … … 58 55 #endif 59 56 60 int shell_errno; 57 #undef errno 58 extern int errno; 61 59 62 60 extern bool_t sio_isr_snd(ID siopid); … … 105 103 106 104 stdio_sio_t stdio_sio; 107 ntstdio_t *ntstdio = &stdio_sio.ntstdio;108 105 109 106 void sys_init(intptr_t exinf) … … 573 570 struct SHELL_FILE *fp = fd_to_fp(fd); 574 571 if ((fp == NULL) || (fp->type != &IO_TYPE_SIO)) { 575 shell_errno = EBADF;572 errno = EBADF; 576 573 return -1; 577 574 } 578 575 579 shell_errno = sio_close(fp);580 if ( shell_errno != 0)576 errno = sio_close(fp); 577 if (errno != 0) 581 578 return 1; 582 579 return 0; … … 587 584 struct SHELL_FILE *fp = fd_to_fp(fd); 588 585 if ((fp == NULL) || ((fp->type != &IO_TYPE_STDIN) && (fp->type != &IO_TYPE_SIO))) { 589 shell_errno = EBADF;586 errno = EBADF; 590 587 return -1; 591 588 } … … 604 601 if ((fp == NULL) || ((fp->type != &IO_TYPE_STDOUT) && (fp->type != &IO_TYPE_STDERR) 605 602 && (fp->type != &IO_TYPE_SIO))) { 606 shell_errno = EBADF;603 errno = EBADF; 607 604 return -1; 608 605 } … … 621 618 if ((fp == NULL) || ((fp->type != &IO_TYPE_STDIN) && (fp->type != &IO_TYPE_STDOUT) 622 619 && (fp->type != &IO_TYPE_STDERR) && (fp->type != &IO_TYPE_SIO))) { 623 shell_errno = EBADF;620 errno = EBADF; 624 621 return -1; 625 622 } 626 623 627 shell_errno = sio_tcsetattr(fp, act, tio);628 if ( shell_errno != 0)624 errno = sio_tcsetattr(fp, act, tio); 625 if (errno != 0) 629 626 return 1; 630 627 return 0; … … 636 633 if ((fp == NULL) || ((fp->type != &IO_TYPE_STDIN) && (fp->type != &IO_TYPE_STDOUT) 637 634 && (fp->type != &IO_TYPE_STDERR) && (fp->type != &IO_TYPE_SIO))) { 638 shell_errno = EBADF;635 errno = EBADF; 639 636 return -1; 640 637 } 641 638 642 shell_errno = sio_tcgetattr(fp, tio);643 if ( shell_errno != 0)639 errno = sio_tcgetattr(fp, tio); 640 if (errno != 0) 644 641 return 1; 645 642 return 0; … … 651 648 if ((fp == NULL) || ((fp->type != &IO_TYPE_STDIN) && (fp->type != &IO_TYPE_STDOUT) 652 649 && (fp->type != &IO_TYPE_STDERR) && (fp->type != &IO_TYPE_SIO))) { 653 shell_errno = EBADF;650 errno = EBADF; 654 651 return -1; 655 652 } … … 660 657 va_end(ap); 661 658 662 shell_errno = sio_ioctl(fp, cmd, arg);663 if ( shell_errno != 0)659 errno = sio_ioctl(fp, cmd, arg); 660 if (errno != 0) 664 661 return 1; 665 662 return 0; -
EcnlProtoTool/trunk/ntshell/src/syscall.c
r441 r442 102 102 case SYS__llseek: 103 103 ret = shell_llseek(r->a, (((off_t)r->b) << 32) + (off_t)r->c, (off_t *)r->d, r->e); 104 break; 104 105 case SYS__newselect: 105 106 ret = shell_select(r->a, (fd_set *)r->b, (fd_set *)r->c, (fd_set *)r->d, (struct timeval *)r->e); -
EcnlProtoTool/trunk/ntshell/src/tSIOPortNTShell.cdl
r441 r442 49 49 * NTShell に関する定義 50 50 */ 51 import_C(" termios.h");51 import_C("mbed_retarget.h"); 52 52 53 53 /* -
EcnlProtoTool/trunk/ntshell/src/tSIOPortNTShellMain.c
r441 r442 46 46 #include <t_syslog.h> 47 47 #include <errno.h> 48 #include <termios.h>49 #include <unistd.h>50 #include <fcntl.h>51 48 #include "tSIOPortNTShellMain_tecsgen.h" 52 49 #include "syssvc/siofd.h" 53 50 54 extern int shell_errno; 51 #undef errno 52 extern int errno; 55 53 56 54 /* … … 130 128 } 131 129 else { 132 assert(n < 0 && shell_errno == EAGAIN);130 assert(n < 0 && errno == EAGAIN); 133 131 VAR_snd_flag = true; 134 132 VAR_snd_buf = c; … … 159 157 } 160 158 else { 161 assert(n < 0 && shell_errno == EAGAIN);159 assert(n < 0 && errno == EAGAIN); 162 160 return(-1); 163 161 } -
EcnlProtoTool/trunk/ntshell/webserver/base64.c
r331 r442 86 86 unsigned char *pdst; 87 87 int i, j = 0, k = 0; 88 size_t srcsiz = ntlibc_strlen((const char *)src);88 size_t srcsiz = strlen((const char *)src); 89 89 90 90 if ((srcsiz % 4) != 0) { -
EcnlProtoTool/trunk/ntshell/webserver/http_parser.c
r331 r442 2372 2372 if (u->field_set & (1 << UF_PORT)) { 2373 2373 /* Don't bother with endp; we've already validated the string */ 2374 unsigned long v = ntlibc_strtoul(buf + u->field_data[UF_PORT].off, NULL, 10);2374 unsigned long v = strtoul(buf + u->field_data[UF_PORT].off, NULL, 10); 2375 2375 2376 2376 /* Ports have a max value of 2^16 */ -
EcnlProtoTool/trunk/ntshell/webserver/httpd-fs.c
r441 r442 45 45 #include "kernel_cfg.h" 46 46 #include "syssvc/syslog.h" 47 #include "util/ntstdio.h"48 47 49 48 #ifndef _MSC_VER 50 49 #ifndef strcat_s 51 #define strcat_s(dst, dsz, src) ntlibc_strcat(dst, src)50 #define strcat_s(dst, dsz, src) strcat(dst, src) 52 51 #endif 53 52 #endif … … 62 61 #define NULL 0 63 62 #endif /* NULL */ 64 65 extern ntstdio_t *ntstdio;66 63 67 64 /*-----------------------------------------------------------------------------------*/ … … 77 74 res = f_opendir(&dir, path); 78 75 if (res == FR_OK) { 79 i = ntlibc_strlen(path);76 i = strlen(path); 80 77 for (;;) { 81 78 res = f_readdir(&dir, &fno); … … 83 80 fn = fno.fname; 84 81 if (fno.fattrib & AM_DIR) { 85 ntstdio_sprintf(&path[i], "0:/%s", fn);82 sprintf(&path[i], "0:/%s", fn); 86 83 res = scan_files(path, size); 87 84 if (res != FR_OK) break; … … 89 86 } 90 87 else { 91 ntstdio_printf(ntstdio,"%s/%s\n", path, fn);88 printf("%s/%s\n", path, fn); 92 89 } 93 90 } … … 114 111 if ((res = f_open(fd, name, FA_OPEN_EXISTING | FA_READ)) != FR_OK) { 115 112 if ((res = f_opendir(&dir, name)) != FR_OK) { 116 ntstdio_printf(ntstdio,"f_opendir(%s) => %d\n", name, res);113 printf("f_opendir(%s) => %d\n", name, res); 117 114 return 0; 118 115 } 119 116 120 117 if ((res = f_readdir(&dir, &fno)) != FR_OK) { 121 ntstdio_printf(ntstdio,"f_readdir(%s) => %d\n", name, res);118 printf("f_readdir(%s) => %d\n", name, res); 122 119 return 0; 123 120 } … … 132 129 133 130 if (res != FR_OK) { 134 ntstdio_printf(ntstdio,"f_open(%s) => %d %x\n", name, res, fno.fattrib);131 printf("f_open(%s) => %d %x\n", name, res, fno.fattrib); 135 132 return 0; 136 133 } … … 139 136 file->len = fd->fsize; 140 137 141 // ntstdio_printf(ntstdio,"httpd_fs_open(%s) %d\n", name, file->len);138 //printf("httpd_fs_open(%s) %d\n", name, file->len); 142 139 143 140 return 1; … … 158 155 159 156 if ((res = f_open(fd, name, FA_CREATE_ALWAYS | FA_WRITE)) != FR_OK) { 160 ntstdio_printf(ntstdio,"f_open(%s) => %d\n", name, res);157 printf("f_open(%s) => %d\n", name, res); 161 158 return 0; 162 159 } … … 165 162 file->len = 0; 166 163 167 // ntstdio_printf(ntstdio,"httpd_fs_create(%s) %d\n", file->name, file->len);164 //printf("httpd_fs_create(%s) %d\n", file->name, file->len); 168 165 169 166 return 1; … … 179 176 180 177 if ((ret = f_lseek(fd, file->pos)) != FR_OK) { 181 ntstdio_printf(ntstdio,"f_lseek(%s, %d) => %d\n", file->name, file->pos, ret);178 printf("f_lseek(%s, %d) => %d\n", file->name, file->pos, ret); 182 179 return 0; 183 180 } 184 181 185 182 if (file->pos != fd->fptr) { 186 ntstdio_printf(ntstdio,"f_lseek(%s, %d) != %d\n", file->name, file->pos, fd->fptr);183 printf("f_lseek(%s, %d) != %d\n", file->name, file->pos, fd->fptr); 187 184 } 188 185 189 186 if ((ret = f_read(fd, dst, len, &rlen)) != FR_OK) { 190 ntstdio_printf(ntstdio,"f_read(%s, 0x%p, %d) => %d\n", file->name, dst, len, ret);191 return 0; 192 } 193 194 // ntstdio_printf(ntstdio,"httpd_fs_read(%s, %d, %d) => %d\n", file->name, file->pos, len, rlen);187 printf("f_read(%s, 0x%p, %d) => %d\n", file->name, dst, len, ret); 188 return 0; 189 } 190 191 //printf("httpd_fs_read(%s, %d, %d) => %d\n", file->name, file->pos, len, rlen); 195 192 196 193 return rlen; … … 206 203 207 204 if ((ret = f_lseek(fd, file->pos)) != FR_OK) { 208 ntstdio_printf(ntstdio,"f_lseek(%s, %d) => %d\n", file->name, file->pos, ret);205 printf("f_lseek(%s, %d) => %d\n", file->name, file->pos, ret); 209 206 return 0; 210 207 } 211 208 212 209 if (file->pos != fd->fptr) { 213 ntstdio_printf(ntstdio,"f_lseek(%s, %d) != %d\n", file->name, file->pos, fd->fptr);210 printf("f_lseek(%s, %d) != %d\n", file->name, file->pos, fd->fptr); 214 211 } 215 212 216 213 if ((ret = f_write(fd, src, len, &rlen)) != FR_OK) { 217 ntstdio_printf(ntstdio,"f_write(%s, 0x%p, %d) => %d\n", file->name, src, len, ret);214 printf("f_write(%s, 0x%p, %d) => %d\n", file->name, src, len, ret); 218 215 return 0; 219 216 } … … 222 219 file->len += rlen; 223 220 224 // ntstdio_printf(ntstdio,"httpd_fs_write(%s, %d, %d) => %d\n", file->name, file->pos, len, rlen);221 //printf("httpd_fs_write(%s, %d, %d) => %d\n", file->name, file->pos, len, rlen); 225 222 226 223 return rlen; … … 234 231 235 232 if ((ret = f_close(fd)) != FR_OK) { 236 ntstdio_printf(ntstdio,"f_close(%s) => %d\n", file->name, ret);233 printf("f_close(%s) => %d\n", file->name, ret); 237 234 return 0; 238 235 } -
EcnlProtoTool/trunk/ntshell/webserver/httpd.c
r441 r442 53 53 #include "base64.h" 54 54 #include "sha1.h" 55 #include "util/ntstdio.h"56 55 #include "core/ntlibc.h" 57 56 … … 59 58 #define FALSE 0 60 59 61 extern ntstdio_t *ntstdio;62 60 SYSTIM httpd_time; 63 61 struct httpd_state *uploding; … … 111 109 void strcpy_s(char *dst, int size, const char *src) 112 110 { 113 int slen = ntlibc_strlen(src);111 int slen = strlen(src); 114 112 if (slen >= size) 115 113 slen = size - 1; … … 120 118 void strcat_s(char *dst, int size, const char *src) 121 119 { 122 int dlen = ntlibc_strlen(dst);123 int slen = ntlibc_strlen(src);120 int dlen = strlen(dst); 121 int slen = strlen(src); 124 122 if (dlen + slen >= size) 125 123 slen = size - 1 - dlen; … … 235 233 struct message *m = &s->message; 236 234 237 if ( ntlibc_strncmp("Referer", buf, len) == 0) {235 if (strncmp("Referer", buf, len) == 0) { 238 236 m->num_headers = 1; 239 237 } 240 else if ( ntlibc_strncmp("Host", buf, len) == 0) {238 else if (strncmp("Host", buf, len) == 0) { 241 239 m->num_headers = 2; 242 240 } 243 else if ( ntlibc_strncmp("Upgrade", buf, len) == 0) {241 else if (strncmp("Upgrade", buf, len) == 0) { 244 242 m->num_headers = 3; 245 243 } 246 else if ( ntlibc_strncmp("Connection", buf, len) == 0) {244 else if (strncmp("Connection", buf, len) == 0) { 247 245 m->num_headers = 4; 248 246 } 249 else if ( ntlibc_strncmp("Sec-WebSocket-Key", buf, len) == 0) {247 else if (strncmp("Sec-WebSocket-Key", buf, len) == 0) { 250 248 m->num_headers = 5; 251 249 } 252 else if ( ntlibc_strncmp("Origin", buf, len) == 0) {250 else if (strncmp("Origin", buf, len) == 0) { 253 251 m->num_headers = 6; 254 252 } 255 else if ( ntlibc_strncmp("Sec-WebSocket-Protocol", buf, len) == 0) {253 else if (strncmp("Sec-WebSocket-Protocol", buf, len) == 0) { 256 254 m->num_headers = 7; 257 255 } 258 else if ( ntlibc_strncmp("Sec-WebSocket-Version", buf, len) == 0) {256 else if (strncmp("Sec-WebSocket-Version", buf, len) == 0) { 259 257 m->num_headers = 8; 260 258 } … … 334 332 // アップロード先はSDカード 335 333 s->filename[0] = '1'; 336 ntstdio_printf(ntstdio,"create: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);334 printf("create: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 337 335 if (!httpd_fs_create(s->filename, &s->file)) { 338 336 goto error; … … 341 339 s->in.state = IN_STATE_UPLOAD; 342 340 } 343 else if ( ntlibc_strcmp(s->filename, uploding->filename) == 0) {344 ntstdio_printf(ntstdio,"collision: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);341 else if (strcmp(s->filename, uploding->filename) == 0) { 342 printf("collision: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 345 343 goto error; 346 344 } … … 374 372 375 373 if (s->message.body_is_final) { 376 ntstdio_printf(ntstdio,"\n\n *** Error http_body_is_final() should return 1 \n"374 printf("\n\n *** Error http_body_is_final() should return 1 \n" 377 375 "on last on_body callback call " 378 376 "but it doesn't! ***\n\n"); … … 387 385 388 386 if (s->message.body_is_final) { 389 ntstdio_printf(ntstdio,"close: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);387 printf("close: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 390 388 httpd_fs_close(&s->file); 391 389 memset(&s->file, 0, sizeof(s->file)); … … 412 410 struct httpd_state *s = get_context(p); 413 411 if (s->message.should_keep_alive != http_should_keep_alive(p)) { 414 ntstdio_printf(ntstdio,"\n\n *** Error http_should_keep_alive() should have same \n"412 printf("\n\n *** Error http_should_keep_alive() should have same \n" 415 413 "value in both on_message_complete and on_headers_complete " 416 414 "but it doesn't! ***\n\n"); … … 421 419 http_body_is_final(p) && 422 420 !s->message.body_is_final) { 423 ntstdio_printf(ntstdio,"\n\n *** Error http_body_is_final() should return 1 \n"421 printf("\n\n *** Error http_body_is_final() should return 1 \n" 424 422 "on last on_body callback call " 425 423 "but it doesn't! ***\n\n"); … … 493 491 slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR); 494 492 if (slen < 0) { 495 ntstdio_printf(ntstdio,"send_file#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);493 printf("send_file#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 496 494 s->state = STATE_CLOSING; 497 495 break; … … 506 504 len = httpd_fs_read(&s->file, buf, len); 507 505 if (len <= 0) { 508 ntstdio_printf(ntstdio,"send_file#httpd_fs_read(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, len);506 printf("send_file#httpd_fs_read(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, len); 509 507 break; 510 508 } … … 514 512 515 513 if ((slen = tcp_snd_buf(s->cepid, len)) != E_OK) { 516 ntstdio_printf(ntstdio,"send_file#tcp_snd_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);514 printf("send_file#tcp_snd_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 517 515 s->state = STATE_CLOSING; 518 516 break; … … 520 518 } 521 519 522 ntstdio_printf(ntstdio,"close: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);520 printf("close: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 523 521 httpd_fs_close(&s->file); 524 522 s->file.len = 0; … … 536 534 slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR); 537 535 if (slen < 0) { 538 ntstdio_printf(ntstdio,"send_data#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);536 printf("send_data#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 539 537 s->state = STATE_CLOSING; 540 538 break; … … 553 551 554 552 if ((slen = tcp_snd_buf(s->cepid, len)) != E_OK) { 555 ntstdio_printf(ntstdio,"send_data#tcp_snd_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);553 printf("send_data#tcp_snd_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 556 554 s->state = STATE_CLOSING; 557 555 break; … … 571 569 char *ptr; 572 570 573 len = ntlibc_strlen(statushdr);571 len = strlen(statushdr); 574 572 tcp_snd_dat(s->cepid, (void *)statushdr, len, TMO_FEVR); 575 573 … … 586 584 tcp_snd_dat(s->cepid, "/~", len, TMO_FEVR); 587 585 } 588 len = ntlibc_strlen(s->filename);586 len = strlen(s->filename); 589 587 tcp_snd_dat(s->cepid, s->filename, len, TMO_FEVR); 590 588 if (s->query != NULL) { 591 589 tcp_snd_dat(s->cepid, "?", 1, TMO_FEVR); 592 len = ntlibc_strlen(s->query);590 len = strlen(s->query); 593 591 tcp_snd_dat(s->cepid, s->query, len, TMO_FEVR); 594 592 } … … 602 600 tcp_snd_dat(s->cepid, (void *)http_content_type_binary, len, TMO_FEVR); 603 601 } 604 else if ( ntlibc_strncmp(http_html, ptr, sizeof(http_html) - 1) == 0 ||605 ntlibc_strncmp(http_htm, ptr, sizeof(http_htm) - 1) == 0) {602 else if (strncmp(http_html, ptr, sizeof(http_html) - 1) == 0 || 603 strncmp(http_htm, ptr, sizeof(http_htm) - 1) == 0) { 606 604 len = sizeof(http_content_type_html) - 1; 607 605 tcp_snd_dat(s->cepid, (void *)http_content_type_html, len, TMO_FEVR); 608 606 } 609 else if ( ntlibc_strncmp(http_css, ptr, sizeof(http_css) - 1) == 0) {607 else if (strncmp(http_css, ptr, sizeof(http_css) - 1) == 0) { 610 608 len = sizeof(http_content_type_css) - 1; 611 609 tcp_snd_dat(s->cepid, (void *)http_content_type_css, len, TMO_FEVR); 612 610 } 613 else if ( ntlibc_strncmp(http_js, ptr, sizeof(http_js) - 1) == 0) {611 else if (strncmp(http_js, ptr, sizeof(http_js) - 1) == 0) { 614 612 len = sizeof(http_content_type_js) - 1; 615 613 tcp_snd_dat(s->cepid, (void *)http_content_type_js, len, TMO_FEVR); 616 614 } 617 else if ( ntlibc_strncmp(http_json, ptr, sizeof(http_json) - 1) == 0) {615 else if (strncmp(http_json, ptr, sizeof(http_json) - 1) == 0) { 618 616 len = sizeof(http_content_type_json) - 1; 619 617 tcp_snd_dat(s->cepid, (void *)http_content_type_json, len, TMO_FEVR); 620 618 } 621 else if ( ntlibc_strncmp(http_png, ptr, sizeof(http_png) - 1) == 0) {619 else if (strncmp(http_png, ptr, sizeof(http_png) - 1) == 0) { 622 620 len = sizeof(http_content_type_png) - 1; 623 621 tcp_snd_dat(s->cepid, (void *)http_content_type_png, len, TMO_FEVR); 624 622 } 625 else if ( ntlibc_strncmp(http_gif, ptr, sizeof(http_gif) - 1) == 0) {623 else if (strncmp(http_gif, ptr, sizeof(http_gif) - 1) == 0) { 626 624 len = sizeof(http_content_type_gif) - 1; 627 625 tcp_snd_dat(s->cepid, (void *)http_content_type_gif, len, TMO_FEVR); 628 626 } 629 else if ( ntlibc_strncmp(http_jpg, ptr, sizeof(http_jpg) - 1) == 0) {627 else if (strncmp(http_jpg, ptr, sizeof(http_jpg) - 1) == 0) { 630 628 len = sizeof(http_content_type_jpg) - 1; 631 629 tcp_snd_dat(s->cepid, (void *)http_content_type_jpg, len, TMO_FEVR); 632 630 } 633 else if ( ntlibc_strncmp(http_svg, ptr, sizeof(http_svg) - 1) == 0) {631 else if (strncmp(http_svg, ptr, sizeof(http_svg) - 1) == 0) { 634 632 len = sizeof(http_content_type_svg) - 1; 635 633 tcp_snd_dat(s->cepid, (void *)http_content_type_svg, len, TMO_FEVR); 636 634 } 637 else if ( ntlibc_strncmp(http_text, ptr, sizeof(http_text) - 1) == 0) {635 else if (strncmp(http_text, ptr, sizeof(http_text) - 1) == 0) { 638 636 len = sizeof(http_content_type_text) - 1; 639 637 tcp_snd_dat(s->cepid, (void *)http_content_type_text, len, TMO_FEVR); 640 638 } 641 else if ( ntlibc_strncmp(http_eot, ptr, sizeof(http_eot) - 1) == 0) {639 else if (strncmp(http_eot, ptr, sizeof(http_eot) - 1) == 0) { 642 640 len = sizeof(http_content_type_eot) - 1; 643 641 tcp_snd_dat(s->cepid, (void *)http_content_type_eot, len, TMO_FEVR); 644 642 } 645 else if ( ntlibc_strncmp(http_ttf, ptr, sizeof(http_ttf) - 1) == 0) {643 else if (strncmp(http_ttf, ptr, sizeof(http_ttf) - 1) == 0) { 646 644 len = sizeof(http_content_type_ttf) - 1; 647 645 tcp_snd_dat(s->cepid, (void *)http_content_type_ttf, len, TMO_FEVR); 648 646 } 649 else if ( ntlibc_strncmp(http_woff, ptr, sizeof(http_woff) - 1) == 0) {647 else if (strncmp(http_woff, ptr, sizeof(http_woff) - 1) == 0) { 650 648 len = sizeof(http_content_type_woff) - 1; 651 649 tcp_snd_dat(s->cepid, (void *)http_content_type_woff, len, TMO_FEVR); 652 650 } 653 else if ( ntlibc_strncmp(http_woff2, ptr, sizeof(http_woff2) - 1) == 0) {651 else if (strncmp(http_woff2, ptr, sizeof(http_woff2) - 1) == 0) { 654 652 len = sizeof(http_content_type_woff2) - 1; 655 653 tcp_snd_dat(s->cepid, (void *)http_content_type_woff2, len, TMO_FEVR); 656 654 } 657 else if ( ntlibc_strncmp(http_ico, ptr, sizeof(http_ico) - 1) == 0) {655 else if (strncmp(http_ico, ptr, sizeof(http_ico) - 1) == 0) { 658 656 len = sizeof(http_content_type_ico) - 1; 659 657 tcp_snd_dat(s->cepid, (void *)http_content_type_ico, len, TMO_FEVR); … … 667 665 len = sizeof(http_content_length) - 1; 668 666 tcp_snd_dat(s->cepid, (void *)http_content_length, len, TMO_FEVR); 669 len = ntstdio_snprintf(s->temp, sizeof(s->temp), "%d\r\n", s->file.len);667 len = snprintf(s->temp, sizeof(s->temp), "%d\r\n", s->file.len); 670 668 tcp_snd_dat(s->cepid, (void *)s->temp, len, TMO_FEVR); 671 669 } … … 699 697 break; 700 698 case OUT_STATE_OPEN_GET_FILE: 701 ntstdio_printf(ntstdio,"open: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);699 printf("open: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 702 700 if (!httpd_fs_open(s->filename, sizeof(s->message.request_url), &s->file)) { 703 701 s->filename = NULL; … … 713 711 break; 714 712 case OUT_STATE_WAIT_POST_BODY: 715 // ntstdio_printf(ntstdio,"wait post body\n");713 //printf("wait post body\n"); 716 714 s->out.wait = true; 717 715 break; 718 716 case OUT_STATE_BODY_RECEIVED: 719 // ntstdio_printf(ntstdio,"body received\n");717 //printf("body received\n"); 720 718 s->out.statushdr = http_header_200; 721 719 s->out.state = OUT_STATE_SEND_HEADER; 722 720 break; 723 721 case OUT_STATE_SEND_HEADER: 724 // ntstdio_printf(ntstdio,"send header\n");722 //printf("send header\n"); 725 723 send_headers(s, s->out.statushdr); 726 724 break; 727 725 case OUT_STATE_SEND_FILE: 728 // ntstdio_printf(ntstdio,"send file %d\n", s->file.len);726 //printf("send file %d\n", s->file.len); 729 727 send_file(s); 730 728 break; 731 729 case OUT_STATE_SEND_DATA: 732 // ntstdio_printf(ntstdio,"send data %d\n", s->response_len);730 //printf("send data %d\n", s->response_len); 733 731 send_data(s); 734 732 break; 735 733 case OUT_STATE_SEND_END: 736 // ntstdio_printf(ntstdio,"send end\n");734 //printf("send end\n"); 737 735 s->out.wait = true; 738 736 if (s->message.should_keep_alive && s->reset == 0) { … … 750 748 int len; 751 749 752 len = ntlibc_strlen(statushdr);750 len = strlen(statushdr); 753 751 tcp_snd_dat(s->cepid, (void *)statushdr, len, TMO_FEVR); 754 752 755 753 len = sizeof(http_upgrade) - 1; 756 754 tcp_snd_dat(s->cepid, (void *)http_upgrade, len, TMO_FEVR); 757 len = ntlibc_strlen(s->message.upgrade);755 len = strlen(s->message.upgrade); 758 756 tcp_snd_dat(s->cepid, s->message.upgrade, len, TMO_FEVR); 759 757 len = sizeof(http_crnl) - 1; … … 762 760 len = sizeof(http_connection) - 1; 763 761 tcp_snd_dat(s->cepid, (void *)http_connection, len, TMO_FEVR); 764 len = ntlibc_strlen(s->message.connection);762 len = strlen(s->message.connection); 765 763 tcp_snd_dat(s->cepid, s->message.connection, len, TMO_FEVR); 766 764 len = sizeof(http_crnl) - 1; … … 769 767 len = sizeof(http_sec_websocket_accept) - 1; 770 768 tcp_snd_dat(s->cepid, (void *)http_sec_websocket_accept, len, TMO_FEVR); 771 len = ntlibc_strlen(s->message.response_key);769 len = strlen(s->message.response_key); 772 770 tcp_snd_dat(s->cepid, s->message.response_key, len, TMO_FEVR); 773 771 len = sizeof(http_crnl) - 1; … … 776 774 len = sizeof(http_sec_websocket_protocol) - 1; 777 775 tcp_snd_dat(s->cepid, (void *)http_sec_websocket_protocol, len, TMO_FEVR); 778 len = ntlibc_strlen(s->message.sec_websocket_protocol);776 len = strlen(s->message.sec_websocket_protocol); 779 777 tcp_snd_dat(s->cepid, s->message.sec_websocket_protocol, len, TMO_FEVR); 780 778 len = sizeof(http_crnl) - 1; … … 792 790 slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR); 793 791 if (slen < 0) { 794 ntstdio_printf(ntstdio,"send_ws_data#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);792 printf("send_ws_data#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 795 793 return; 796 794 } … … 856 854 //} 857 855 } 858 ntstdio_printf(ntstdio,"handle_input#tcp_rcv_buf#%d(%s.%d) => %d\n", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len);856 printf("handle_input#tcp_rcv_buf#%d(%s.%d) => %d\n", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len); 859 857 uploding = NULL; 860 858 s->state = STATE_CLOSING; … … 864 862 tcp_rel_buf(s->cepid, done); 865 863 if (s->parser.http_errno != HPE_OK) { 866 ntstdio_printf(ntstdio,"http_parser error %s.%d => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->parser.http_errno);864 printf("http_parser error %s.%d => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->parser.http_errno); 867 865 uploding = NULL; 868 866 s->state = STATE_CLOSING; … … 889 887 break; 890 888 } 891 ntstdio_printf(ntstdio,"handle_input#tcp_rcv_buf#%d(%s.%d) => %d\n", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len);889 printf("handle_input#tcp_rcv_buf#%d(%s.%d) => %d\n", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len); 892 890 s->state = STATE_CLOSING; 893 891 break; … … 927 925 928 926 if (s == NULL) 929 ntstdio_printf(ntstdio,"callback_nblk_tcp(%d, %d)\n", fncd, cepid);927 printf("callback_nblk_tcp(%d, %d)\n", fncd, cepid); 930 928 else 931 ntstdio_printf(ntstdio,"callback_nblk_tcp(%d, %s.%d)\n", fncd, s->addr, ((T_IPV4EP *)s->dst)->portno);929 printf("callback_nblk_tcp(%d, %s.%d)\n", fncd, s->addr, ((T_IPV4EP *)s->dst)->portno); 932 930 933 931 return E_PAR; … … 945 943 ret2 = get_tim(&httpd_time); 946 944 if (ret2 != E_OK) { 947 ntstdio_printf(ntstdio,"get_tim\n");945 printf("get_tim\n"); 948 946 return; 949 947 } … … 953 951 memset(&s->dst, 0, sizeof(s->dst)); 954 952 if ((ret = tcp_acp_cep(s->cepid, TCP_REPID, (T_IPV4EP *)s->dst, TMO_FEVR)) != E_OK) { 955 ntstdio_printf(ntstdio,"tcp_acp_cep(%d) => %d\n", s->cepid, ret);953 printf("tcp_acp_cep(%d) => %d\n", s->cepid, ret); 956 954 tslp_tsk(100 * 1000); // TODO 957 955 s->state = STATE_CLOSING; … … 959 957 } 960 958 IP2STR(s->addr, &((T_IPV4EP *)s->dst)->ipaddr); 961 ntstdio_printf(ntstdio,"connected: %s.%d\n", s->addr, ((T_IPV4EP *)s->dst)->portno);959 printf("connected: %s.%d\n", s->addr, ((T_IPV4EP *)s->dst)->portno); 962 960 memset(&s->in, 0, sizeof(s->in)); 963 961 memset(&s->out, 0, sizeof(s->out)); … … 974 972 break; 975 973 case STATE_CLOSING: 976 ntstdio_printf(ntstdio,"close: %s.%d\n", s->addr, ((T_IPV4EP *)s->dst)->portno);974 printf("close: %s.%d\n", s->addr, ((T_IPV4EP *)s->dst)->portno); 977 975 tcp_sht_cep(s->cepid); 978 976 tcp_cls_cep(s->cepid, TMO_FEVR);
Note:
See TracChangeset
for help on using the changeset viewer.