Ignore:
Timestamp:
Jul 10, 2020, 9:09:25 PM (4 years ago)
Author:
coas-nagasima
Message:

NTShellタスクを更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/ntshell/ntshell/usrcmd.c

    r435 r441  
    3333#include "shellif.h"
    3434#include <kernel.h>
    35 //#include <string.h>
    3635#include <t_syslog.h>
    3736#include <t_stdlib.h>
    3837#include <sil.h>
    3938#include "syssvc/syslog.h"
     39#include "target_syssvc.h"
    4040#include "kernel_cfg.h"
    4141#include "main.h"
    42 #include "rza1.h"
    4342#include "ffarch.h"
    4443#include "ff.h"
     
    4847#include "util/ntstdio.h"
    4948
    50 extern ntstdio_t ntstdio;
     49extern ntstdio_t *ntstdio;
    5150extern int ntshell_exit;
    5251
     
    147146}
    148147
    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 
    165148void put_rc(const char *func, FRESULT rc)
    166149{
     
    175158                while (*p++);
    176159        }
    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);
    178161}
    179162
     
    187170                while (*p++);
    188171        }
    189         ntstdio_printf(&ntstdio, "%s() =>%u %s\n", func, (UINT)rc, p);
     172        ntstdio_printf(ntstdio, "%s() =>%u %s\n", func, (UINT)rc, p);
    190173}
    191174
     
    210193        for (; s[i] == '/'; i--) if (!i) return (s == _s) ? "/" : _s;
    211194        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; }
    213196        s[i + 1] = 0;
    214197        return _s;
     
    237220
    238221        ntlibc_strlcat(path, "\n", sizeof(path));
    239         ntstdio_printf(&ntstdio, path);
     222        ntstdio_printf(ntstdio, path);
    240223
    241224        return 0;
     
    260243
    261244        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 ",
    263246                        (fno->fattrib & AM_DIR) ? 'd' : '-',
    264247                        (fno->fattrib & AM_RDO) ? 'r' : '-',
     
    274257
    275258                if (fno->fattrib & AM_DIR) {                    /* It is a directory */
    276                         ntstdio_printf(&ntstdio, "%10S ", " ");
     259                        ntstdio_printf(ntstdio, "%10s ", " ");
    277260                }
    278261                else {
    279                         ntstdio_printf(&ntstdio, "%10d ", fno->fsize);
     262                        ntstdio_printf(ntstdio, "%10lu ", fno->fsize);
    280263                }
    281264        }
    282265
    283266        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);
    285268        }
    286269        else {
    287                 ntstdio_printf(&ntstdio, "%s\n", fn);
     270                ntstdio_printf(ntstdio, "%s\n", fn);
    288271        }
    289272}
     
    304287        path_backup = ff_memalloc(LFN_BUF_SIZE);
    305288        if (path_backup == NULL) {
    306                 ntstdio_printf(&ntstdio, "ff_memalloc err.\n");
     289                ntstdio_printf(ntstdio, "ff_memalloc err.\n");
    307290                return;
    308291        }
     
    312295        lfn = ff_memalloc(LFN_BUF_SIZE);
    313296        if (lfn == NULL) {
    314                 ntstdio_printf(&ntstdio, "ff_memalloc err.\n");
     297                ntstdio_printf(ntstdio, "ff_memalloc err.\n");
    315298                ff_memfree(path_backup);
    316299                return;
     
    340323                        }
    341324
    342                         if ((res = f_chdrive(path_p)) != RES_OK) {
     325                        if ((res = f_chdrive(path_p)) != FR_OK) {
    343326                                put_rc("f_chdrive", res);
    344327                        }
    345328
    346                         if ((res = f_chdir(path_p)) != RES_OK) {
     329                        if ((res = f_chdir(path_p)) != FR_OK) {
    347330                                put_rc("f_chdir", res);
    348331                        }
    349332
    350                         ntstdio_printf(&ntstdio, "\n%s/%s:\n", path_p, fn);
     333                        ntstdio_printf(ntstdio, "\n%s/%s:\n", path_p, fn);
    351334
    352335                        print_ls(fn, NULL, list_option);
    353336
    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) {
    357340                                put_rc("f_chdrive", res);
    358341                        }
    359342
    360                         if ((res = f_chdir(path_backup)) != RES_OK) {
     343                        if ((res = f_chdir(path_backup)) != FR_OK) {
    361344                                put_rc("f_chdir", res);
    362345                        }
     
    449432        lfn = ff_memalloc(LFN_BUF_SIZE);
    450433        if (lfn == NULL) {
    451                 ntstdio_printf(&ntstdio, "alloc err.\n");
     434                ntstdio_printf(ntstdio, "alloc err.\n");
    452435                goto cp_end;
    453436        }
     
    459442        local_buff = ff_memalloc(64);
    460443        if (local_buff == NULL) {
    461                 ntstdio_printf(&ntstdio, "alloc err.\n");
     444                ntstdio_printf(ntstdio, "alloc err.\n");
    462445                goto cp_end;
    463446        }
     
    469452        if (res != FR_OK) {
    470453                if (res == FR_NO_FILE)
    471                         ntstdio_printf(&ntstdio, "src no file.\n", res);
     454                        ntstdio_printf(ntstdio, "src no file.\n");
    472455                else
    473                         ntstdio_printf(&ntstdio, "src stat err(%d).\n", res);
     456                        ntstdio_printf(ntstdio, "src stat err(%d).\n", res);
    474457                goto cp_end;
    475458        }
     
    480463                res = f_open(&src_fp, src_str_p, (FA_OPEN_EXISTING | FA_READ));
    481464                if (res != FR_OK) {
    482                         ntstdio_printf(&ntstdio, "src open err(%d).\n", res);
     465                        ntstdio_printf(ntstdio, "src open err(%d).\n", res);
    483466                        goto cp_end;
    484467                }
     
    495478                                dst_mod_str_p = ff_memalloc(LFN_BUF_SIZE);
    496479                                if (dst_mod_str_p == NULL) {
    497                                         ntstdio_printf(&ntstdio, "alloc err.\n");
     480                                        ntstdio_printf(ntstdio, "alloc err.\n");
    498481                                        goto cp_end;
    499482                                }
     
    502485                        }
    503486                        else {
    504                                 ntstdio_printf(&ntstdio, "dst file exists.\n");
     487                                ntstdio_printf(ntstdio, "dst file exists.\n");
    505488                                goto cp_end_1;
    506489                        }
    507490                }
    508491                else {
    509                         ntstdio_printf(&ntstdio, "src stat err(%d).\n", res);
     492                        ntstdio_printf(ntstdio, "src stat err(%d).\n", res);
    510493                        goto cp_end_1;
    511494                }
     
    513496        res = f_open(&dst_fp, dst_str_p, (FA_CREATE_NEW | FA_WRITE));
    514497        if (res != FR_OK) {
    515                 ntstdio_printf(&ntstdio, "dst open err(%d).\n", res);
     498                ntstdio_printf(ntstdio, "dst open err(%d).\n", res);
    516499                goto cp_end_1;
    517500        }
     
    524507                res = f_read(&src_fp, local_buff, sizeof(local_buff), &read_size);
    525508                if (res != FR_OK) {
    526                         ntstdio_printf(&ntstdio, "src read err(%d).\n", res);
     509                        ntstdio_printf(ntstdio, "src read err(%d).\n", res);
    527510                        goto cp_end_2;
    528511                }
     
    531514                res = f_write(&dst_fp, local_buff, read_size, &write_size);
    532515                if (res != FR_OK) {
    533                         ntstdio_printf(&ntstdio, "dst write err(%d).\n", res);
     516                        ntstdio_printf(ntstdio, "dst write err(%d).\n", res);
    534517                        goto cp_end_2;
    535518                }
    536519                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");
    538521                        goto cp_end_2;
    539522                }
     
    594577}
    595578
    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 */
    598579#define HEXDUMP_EXTRA_FOR_UTF8 3 /* need extra buffer size */
    599580#define CCOLOR_RESET    0
     
    626607                switch (op) {
    627608                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");
    634615                        break;
    635616                case 'd': /* print one byte character [in character area] (default) */
     
    662643        /* position adjusting */
    663644        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);
    665646                return 0;
    666647        }
     
    689670                if (br > 16) br = 16;
    690671
    691                 char *apos = ascii;
     672                unsigned char *apos = ascii;
    692673                int arst = sizeof(ascii);
    693674                for (int j = 0; j < br; j++) {
     
    784765                rst -= len;
    785766
    786                 ntstdio_puts(&ntstdio, line);
     767                ntstdio_puts(ntstdio, line);
    787768        }
    788769
     
    799780        ret = shell_clock_gettime(CLOCK_REALTIME, &tp);
    800781        if (ret != 0) {
    801                 ntstdio_printf(&ntstdio, "clock_gettime error %d", ret);
     782                ntstdio_printf(ntstdio, "clock_gettime error %d", ret);
    802783                return 0;
    803784        }
     
    805786        memset(buf, 0, sizeof(buf));
    806787        if (ctime_r(&tp.tv_sec, buf) == NULL) {
    807                 ntstdio_printf(&ntstdio, "ctime_r error");
     788                ntstdio_printf(ntstdio, "ctime_r error");
    808789                return 0;
    809790        }
     
    813794        buf[ret - 1] = '\0';
    814795
    815         ntstdio_printf(&ntstdio, "%s .%09ld\n", buf, tp.tv_nsec);
     796        ntstdio_printf(ntstdio, "%s .%09ld\n", buf, tp.tv_nsec);
    816797        return 0;
    817798}
     
    820801{
    821802        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");
    824805                return 0;
    825806        }
    826807        if (ntlibc_strcmp(argv[1], "sys") == 0) {
    827                 ntstdio_printf(&ntstdio, "GR-PEACH Monitor\n");
     808                ntstdio_printf(ntstdio, TARGET_NAME" Monitor\n");
    828809                return 0;
    829810        }
     
    831812                int mj, mn, bd;
    832813                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");
    837818        return -1;
    838819}
Note: See TracChangeset for help on using the changeset viewer.