Changeset 441 for EcnlProtoTool/trunk/ntshell/ntshell/usrcmd.c
- Timestamp:
- Jul 10, 2020, 9:09:25 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/ntshell/ntshell/usrcmd.c
r435 r441 33 33 #include "shellif.h" 34 34 #include <kernel.h> 35 //#include <string.h>36 35 #include <t_syslog.h> 37 36 #include <t_stdlib.h> 38 37 #include <sil.h> 39 38 #include "syssvc/syslog.h" 39 #include "target_syssvc.h" 40 40 #include "kernel_cfg.h" 41 41 #include "main.h" 42 #include "rza1.h"43 42 #include "ffarch.h" 44 43 #include "ff.h" … … 48 47 #include "util/ntstdio.h" 49 48 50 extern ntstdio_t ntstdio;49 extern ntstdio_t *ntstdio; 51 50 extern int ntshell_exit; 52 51 … … 147 146 } 148 147 149 int shell_kill(int pid, int sig)150 {151 asm("bkpt #0");152 return -1;153 }154 155 int shell_gettimeofday(struct timeval *tv, void *tzvp)156 {157 SYSTIM time;158 if (!tv) return 0;159 get_tim(&time);160 tv->tv_sec = time / 1000000;161 tv->tv_usec = time - (tv->tv_sec * 1000000);162 return 0;163 }164 165 148 void put_rc(const char *func, FRESULT rc) 166 149 { … … 175 158 while (*p++); 176 159 } 177 ntstdio_printf( &ntstdio, "%s() =>%u FR_%s\n", func, (UINT)rc, p);160 ntstdio_printf(ntstdio, "%s() =>%u FR_%s\n", func, (UINT)rc, p); 178 161 } 179 162 … … 187 170 while (*p++); 188 171 } 189 ntstdio_printf( &ntstdio, "%s() =>%u %s\n", func, (UINT)rc, p);172 ntstdio_printf(ntstdio, "%s() =>%u %s\n", func, (UINT)rc, p); 190 173 } 191 174 … … 210 193 for (; s[i] == '/'; i--) if (!i) return (s == _s) ? "/" : _s; 211 194 for (; s[i] != '/'; i--) if (!i) return (s == _s) ? "." : _s; 212 for (; s[i] == '/'; i--) if (!i) if (s == _s) return "/"; else break;195 for (; s[i] == '/'; i--) if (!i) { if (s == _s) return "/"; else break; } 213 196 s[i + 1] = 0; 214 197 return _s; … … 237 220 238 221 ntlibc_strlcat(path, "\n", sizeof(path)); 239 ntstdio_printf( &ntstdio, path);222 ntstdio_printf(ntstdio, path); 240 223 241 224 return 0; … … 260 243 261 244 if (list_option & LS_LONG) { 262 ntstdio_printf( &ntstdio, "%c%c%c%c%c %04d/%02d/%02d %02d:%02d:%02d ",245 ntstdio_printf(ntstdio, "%c%c%c%c%c %04d/%02d/%02d %02d:%02d:%02d ", 263 246 (fno->fattrib & AM_DIR) ? 'd' : '-', 264 247 (fno->fattrib & AM_RDO) ? 'r' : '-', … … 274 257 275 258 if (fno->fattrib & AM_DIR) { /* It is a directory */ 276 ntstdio_printf( &ntstdio, "%10S", " ");259 ntstdio_printf(ntstdio, "%10s ", " "); 277 260 } 278 261 else { 279 ntstdio_printf( &ntstdio, "%10d", fno->fsize);262 ntstdio_printf(ntstdio, "%10lu ", fno->fsize); 280 263 } 281 264 } 282 265 283 266 if (fno->fattrib & AM_DIR) { /* It is a directory */ 284 ntstdio_printf( &ntstdio, "\x1B[32m%s\x1B[0m\n", fn);267 ntstdio_printf(ntstdio, "\x1B[32m%s\x1B[0m\n", fn); 285 268 } 286 269 else { 287 ntstdio_printf( &ntstdio, "%s\n", fn);270 ntstdio_printf(ntstdio, "%s\n", fn); 288 271 } 289 272 } … … 304 287 path_backup = ff_memalloc(LFN_BUF_SIZE); 305 288 if (path_backup == NULL) { 306 ntstdio_printf( &ntstdio, "ff_memalloc err.\n");289 ntstdio_printf(ntstdio, "ff_memalloc err.\n"); 307 290 return; 308 291 } … … 312 295 lfn = ff_memalloc(LFN_BUF_SIZE); 313 296 if (lfn == NULL) { 314 ntstdio_printf( &ntstdio, "ff_memalloc err.\n");297 ntstdio_printf(ntstdio, "ff_memalloc err.\n"); 315 298 ff_memfree(path_backup); 316 299 return; … … 340 323 } 341 324 342 if ((res = f_chdrive(path_p)) != RES_OK) {325 if ((res = f_chdrive(path_p)) != FR_OK) { 343 326 put_rc("f_chdrive", res); 344 327 } 345 328 346 if ((res = f_chdir(path_p)) != RES_OK) {329 if ((res = f_chdir(path_p)) != FR_OK) { 347 330 put_rc("f_chdir", res); 348 331 } 349 332 350 ntstdio_printf( &ntstdio, "\n%s/%s:\n", path_p, fn);333 ntstdio_printf(ntstdio, "\n%s/%s:\n", path_p, fn); 351 334 352 335 print_ls(fn, NULL, list_option); 353 336 354 ntstdio_printf( &ntstdio, "\n");355 356 if ((res = f_chdrive(path_backup)) != RES_OK) {337 ntstdio_printf(ntstdio, "\n"); 338 339 if ((res = f_chdrive(path_backup)) != FR_OK) { 357 340 put_rc("f_chdrive", res); 358 341 } 359 342 360 if ((res = f_chdir(path_backup)) != RES_OK) {343 if ((res = f_chdir(path_backup)) != FR_OK) { 361 344 put_rc("f_chdir", res); 362 345 } … … 449 432 lfn = ff_memalloc(LFN_BUF_SIZE); 450 433 if (lfn == NULL) { 451 ntstdio_printf( &ntstdio, "alloc err.\n");434 ntstdio_printf(ntstdio, "alloc err.\n"); 452 435 goto cp_end; 453 436 } … … 459 442 local_buff = ff_memalloc(64); 460 443 if (local_buff == NULL) { 461 ntstdio_printf( &ntstdio, "alloc err.\n");444 ntstdio_printf(ntstdio, "alloc err.\n"); 462 445 goto cp_end; 463 446 } … … 469 452 if (res != FR_OK) { 470 453 if (res == FR_NO_FILE) 471 ntstdio_printf( &ntstdio, "src no file.\n", res);454 ntstdio_printf(ntstdio, "src no file.\n"); 472 455 else 473 ntstdio_printf( &ntstdio, "src stat err(%d).\n", res);456 ntstdio_printf(ntstdio, "src stat err(%d).\n", res); 474 457 goto cp_end; 475 458 } … … 480 463 res = f_open(&src_fp, src_str_p, (FA_OPEN_EXISTING | FA_READ)); 481 464 if (res != FR_OK) { 482 ntstdio_printf( &ntstdio, "src open err(%d).\n", res);465 ntstdio_printf(ntstdio, "src open err(%d).\n", res); 483 466 goto cp_end; 484 467 } … … 495 478 dst_mod_str_p = ff_memalloc(LFN_BUF_SIZE); 496 479 if (dst_mod_str_p == NULL) { 497 ntstdio_printf( &ntstdio, "alloc err.\n");480 ntstdio_printf(ntstdio, "alloc err.\n"); 498 481 goto cp_end; 499 482 } … … 502 485 } 503 486 else { 504 ntstdio_printf( &ntstdio, "dst file exists.\n");487 ntstdio_printf(ntstdio, "dst file exists.\n"); 505 488 goto cp_end_1; 506 489 } 507 490 } 508 491 else { 509 ntstdio_printf( &ntstdio, "src stat err(%d).\n", res);492 ntstdio_printf(ntstdio, "src stat err(%d).\n", res); 510 493 goto cp_end_1; 511 494 } … … 513 496 res = f_open(&dst_fp, dst_str_p, (FA_CREATE_NEW | FA_WRITE)); 514 497 if (res != FR_OK) { 515 ntstdio_printf( &ntstdio, "dst open err(%d).\n", res);498 ntstdio_printf(ntstdio, "dst open err(%d).\n", res); 516 499 goto cp_end_1; 517 500 } … … 524 507 res = f_read(&src_fp, local_buff, sizeof(local_buff), &read_size); 525 508 if (res != FR_OK) { 526 ntstdio_printf( &ntstdio, "src read err(%d).\n", res);509 ntstdio_printf(ntstdio, "src read err(%d).\n", res); 527 510 goto cp_end_2; 528 511 } … … 531 514 res = f_write(&dst_fp, local_buff, read_size, &write_size); 532 515 if (res != FR_OK) { 533 ntstdio_printf( &ntstdio, "dst write err(%d).\n", res);516 ntstdio_printf(ntstdio, "dst write err(%d).\n", res); 534 517 goto cp_end_2; 535 518 } 536 519 if (read_size != write_size) { 537 ntstdio_printf( &ntstdio, "dst write err(disk full).\n", res);520 ntstdio_printf(ntstdio, "dst write err(disk full).\n"); 538 521 goto cp_end_2; 539 522 } … … 594 577 } 595 578 596 extern WCHAR Utf8_to_Utf16(const char *, int *); /* in ff.c */597 extern void Utf16_to_Utf8(unsigned char *, int *, UINT); /* in ff.c */598 579 #define HEXDUMP_EXTRA_FOR_UTF8 3 /* need extra buffer size */ 599 580 #define CCOLOR_RESET 0 … … 626 607 switch (op) { 627 608 case 'h': /* help */ 628 ntstdio_printf( &ntstdio, " hexdump [OPTION] file\n");629 ntstdio_printf( &ntstdio, " -h : help\n");630 ntstdio_printf( &ntstdio, " -d : print all byte with convert and color [in character area] (default)\n");631 ntstdio_printf( &ntstdio, " -u : try print UTF-8 code [in character area]\n");632 ntstdio_printf( &ntstdio, " -oOFFSET : print start offset address from top\n");633 ntstdio_printf( &ntstdio, " -sSIZE : print size\n");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"); 634 615 break; 635 616 case 'd': /* print one byte character [in character area] (default) */ … … 662 643 /* position adjusting */ 663 644 if (op_offset >= fsrc.fsize) { 664 ntstdio_printf( &ntstdio, "error : input offset is bigger than file size(0x%X).\n", fsrc.fsize);645 ntstdio_printf(ntstdio, "error : input offset is bigger than file size(0x%lX).\n", fsrc.fsize); 665 646 return 0; 666 647 } … … 689 670 if (br > 16) br = 16; 690 671 691 char *apos = ascii;672 unsigned char *apos = ascii; 692 673 int arst = sizeof(ascii); 693 674 for (int j = 0; j < br; j++) { … … 784 765 rst -= len; 785 766 786 ntstdio_puts( &ntstdio, line);767 ntstdio_puts(ntstdio, line); 787 768 } 788 769 … … 799 780 ret = shell_clock_gettime(CLOCK_REALTIME, &tp); 800 781 if (ret != 0) { 801 ntstdio_printf( &ntstdio, "clock_gettime error %d", ret);782 ntstdio_printf(ntstdio, "clock_gettime error %d", ret); 802 783 return 0; 803 784 } … … 805 786 memset(buf, 0, sizeof(buf)); 806 787 if (ctime_r(&tp.tv_sec, buf) == NULL) { 807 ntstdio_printf( &ntstdio, "ctime_r error");788 ntstdio_printf(ntstdio, "ctime_r error"); 808 789 return 0; 809 790 } … … 813 794 buf[ret - 1] = '\0'; 814 795 815 ntstdio_printf( &ntstdio, "%s .%09ld\n", buf, tp.tv_nsec);796 ntstdio_printf(ntstdio, "%s .%09ld\n", buf, tp.tv_nsec); 816 797 return 0; 817 798 } … … 820 801 { 821 802 if (argc != 2) { 822 ntstdio_printf( &ntstdio, "info sys\n");823 ntstdio_printf( &ntstdio, "info ver\n");803 ntstdio_printf(ntstdio, "info sys\n"); 804 ntstdio_printf(ntstdio, "info ver\n"); 824 805 return 0; 825 806 } 826 807 if (ntlibc_strcmp(argv[1], "sys") == 0) { 827 ntstdio_printf( &ntstdio, "GR-PEACHMonitor\n");808 ntstdio_printf(ntstdio, TARGET_NAME" Monitor\n"); 828 809 return 0; 829 810 } … … 831 812 int mj, mn, bd; 832 813 ntshell_version(&mj, &mn, &bd); 833 ntstdio_printf( &ntstdio, "Version %d.%d.%d\n", mj, mn, bd);834 return 0; 835 } 836 ntstdio_printf( &ntstdio, "Unknown sub command found\n");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"); 837 818 return -1; 838 819 }
Note:
See TracChangeset
for help on using the changeset viewer.