Changeset 8565a42 in mainline for kernel/generic/src/console


Ignore:
Timestamp:
2018-03-02T20:34:50Z (8 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a1a81f69, d5e5fd1
Parents:
3061bc1 (diff), 34e1206 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:34:50)
git-committer:
GitHub <noreply@…> (2018-03-02 20:34:50)
Message:

Remove all trailing whitespace, everywhere.

See individual commit messages for details.

Location:
kernel/generic/src/console
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/chardev.c

    r3061bc1 r8565a42  
    6868{
    6969        assert(indev);
    70        
     70
    7171        irq_spinlock_lock(&indev->lock, true);
    7272        if (indev->counter == INDEV_BUFLEN - 1) {
     
    7575                return;
    7676        }
    77        
     77
    7878        indev->counter++;
    7979        indev->buffer[indev->index++] = ch;
    80        
     80
    8181        /* Index modulo size of buffer */
    8282        indev->index = indev->index % INDEV_BUFLEN;
     
    102102                if (check_poll(indev))
    103103                        return indev->op->poll(indev);
    104                
     104
    105105                /* No other way of interacting with user */
    106106                interrupts_disable();
    107                
     107
    108108                if (CPU)
    109109                        printf("cpu%u: ", CPU->id);
    110110                else
    111111                        printf("cpu: ");
    112                
     112
    113113                printf("halted (no polling input)\n");
    114114                cpu_halt();
    115115        }
    116        
     116
    117117        waitq_sleep(&indev->wq);
    118118        irq_spinlock_lock(&indev->lock, true);
     
    121121        indev->counter--;
    122122        irq_spinlock_unlock(&indev->lock, true);
    123        
     123
    124124        return ch;
    125125}
     
    158158        if (indev == NULL)
    159159                return false;
    160        
     160
    161161        if (indev->op == NULL)
    162162                return false;
    163        
     163
    164164        return (indev->op->poll != NULL);
    165165}
  • kernel/generic/src/console/cmd.c

    r3061bc1 r8565a42  
    686686{
    687687        spinlock_lock(&cmd_lock);
    688        
     688
    689689        size_t len = 0;
    690690        list_foreach(cmd_list, link, cmd_info_t, hlp) {
     
    694694                spinlock_unlock(&hlp->lock);
    695695        }
    696        
     696
    697697        unsigned int _len = (unsigned int) len;
    698698        if ((_len != len) || (((int) _len) < 0)) {
     
    700700                return 1;
    701701        }
    702        
     702
    703703        list_foreach(cmd_list, link, cmd_info_t, hlp) {
    704704                spinlock_lock(&hlp->lock);
     
    706706                spinlock_unlock(&hlp->lock);
    707707        }
    708        
     708
    709709        spinlock_unlock(&cmd_lock);
    710        
     710
    711711        return 1;
    712712}
     
    721721{
    722722        uint8_t *ptr = NULL;
    723        
     723
    724724#ifdef IO_SPACE_BOUNDARY
    725725        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
     
    729729                ptr = (uint8_t *) km_map(argv[0].intval, sizeof(uint8_t),
    730730                    PAGE_NOT_CACHEABLE);
    731        
     731
    732732        const uint8_t val = pio_read_8(ptr);
    733733        printf("read %" PRIxn ": %" PRIx8 "\n", argv[0].intval, val);
    734        
     734
    735735#ifdef IO_SPACE_BOUNDARY
    736736        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
    737737                return 1;
    738738#endif
    739        
     739
    740740        km_unmap((uintptr_t) ptr, sizeof(uint8_t));
    741741        return 1;
     
    751751{
    752752        uint16_t *ptr = NULL;
    753        
     753
    754754#ifdef IO_SPACE_BOUNDARY
    755755        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
     
    759759                ptr = (uint16_t *) km_map(argv[0].intval, sizeof(uint16_t),
    760760                    PAGE_NOT_CACHEABLE);
    761        
     761
    762762        const uint16_t val = pio_read_16(ptr);
    763763        printf("read %" PRIxn ": %" PRIx16 "\n", argv[0].intval, val);
    764        
     764
    765765#ifdef IO_SPACE_BOUNDARY
    766766        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
    767767                return 1;
    768768#endif
    769        
     769
    770770        km_unmap((uintptr_t) ptr, sizeof(uint16_t));
    771771        return 1;
     
    781781{
    782782        uint32_t *ptr = NULL;
    783        
     783
    784784#ifdef IO_SPACE_BOUNDARY
    785785        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
     
    789789                ptr = (uint32_t *) km_map(argv[0].intval, sizeof(uint32_t),
    790790                    PAGE_NOT_CACHEABLE);
    791        
     791
    792792        const uint32_t val = pio_read_32(ptr);
    793793        printf("read %" PRIxn ": %" PRIx32 "\n", argv[0].intval, val);
    794        
     794
    795795#ifdef IO_SPACE_BOUNDARY
    796796        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
    797797                return 1;
    798798#endif
    799        
     799
    800800        km_unmap((uintptr_t) ptr, sizeof(uint32_t));
    801801        return 1;
     
    811811{
    812812        uint8_t *ptr = NULL;
    813        
     813
    814814#ifdef IO_SPACE_BOUNDARY
    815815        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
     
    819819                ptr = (uint8_t *) km_map(argv[0].intval, sizeof(uint8_t),
    820820                    PAGE_NOT_CACHEABLE);
    821        
     821
    822822        printf("write %" PRIxn ": %" PRIx8 "\n", argv[0].intval,
    823823            (uint8_t) argv[1].intval);
    824824        pio_write_8(ptr, (uint8_t) argv[1].intval);
    825        
     825
    826826#ifdef IO_SPACE_BOUNDARY
    827827        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
    828828                return 1;
    829829#endif
    830        
     830
    831831        km_unmap((uintptr_t) ptr, sizeof(uint8_t));
    832832        return 1;
     
    842842{
    843843        uint16_t *ptr = NULL;
    844        
     844
    845845#ifdef IO_SPACE_BOUNDARY
    846846        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
     
    850850                ptr = (uint16_t *) km_map(argv[0].intval, sizeof(uint16_t),
    851851                    PAGE_NOT_CACHEABLE);
    852        
     852
    853853        printf("write %" PRIxn ": %" PRIx16 "\n", argv[0].intval,
    854854            (uint16_t) argv[1].intval);
    855855        pio_write_16(ptr, (uint16_t) argv[1].intval);
    856        
     856
    857857#ifdef IO_SPACE_BOUNDARY
    858858        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
    859859                return 1;
    860860#endif
    861        
     861
    862862        km_unmap((uintptr_t) ptr, sizeof(uint16_t));
    863863        return 1;
     
    873873{
    874874        uint32_t *ptr = NULL;
    875        
     875
    876876#ifdef IO_SPACE_BOUNDARY
    877877        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
     
    881881                ptr = (uint32_t *) km_map(argv[0].intval, sizeof(uint32_t),
    882882                    PAGE_NOT_CACHEABLE);
    883        
     883
    884884        printf("write %" PRIxn ": %" PRIx32 "\n", argv[0].intval,
    885885            (uint32_t) argv[1].intval);
    886886        pio_write_32(ptr, (uint32_t) argv[1].intval);
    887        
     887
    888888#ifdef IO_SPACE_BOUNDARY
    889889        if ((void *) argv->intval < IO_SPACE_BOUNDARY)
    890890                return 1;
    891891#endif
    892        
     892
    893893        km_unmap((uintptr_t) ptr, sizeof(uint32_t));
    894894        return 1;
     
    904904{
    905905        reboot();
    906        
     906
    907907        /* Not reached */
    908908        return 1;
     
    918918{
    919919        assert(uptime);
    920        
     920
    921921        /* This doesn't have to be very accurate */
    922922        sysarg_t sec = uptime->seconds1;
    923        
     923
    924924        printf("Up %" PRIun " days, %" PRIun " hours, %" PRIun " minutes, %" PRIun " seconds\n",
    925925                sec / 86400, (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60);
    926        
     926
    927927        return 1;
    928928}
     
    937937{
    938938        spinlock_lock(&cmd_lock);
    939        
     939
    940940        list_foreach(cmd_list, link, cmd_info_t, hlp) {
    941941                spinlock_lock(&hlp->lock);
    942                
     942
    943943                if (str_lcmp(hlp->name, (const char *) argv->buffer, str_length(hlp->name)) == 0) {
    944944                        printf("%s - %s\n", hlp->name, hlp->description);
     
    948948                        break;
    949949                }
    950                
     950
    951951                spinlock_unlock(&hlp->lock);
    952952        }
    953        
     953
    954954        spinlock_unlock(&cmd_lock);
    955        
     955
    956956        return 1;
    957957}
     
    961961{
    962962        symtab_print_search((char *) argv->buffer);
    963        
     963
    964964        return 1;
    965965}
     
    10041004         * call the function.
    10051005         */
    1006        
     1006
    10071007        unsigned int i;
    10081008        for (i = 0; i < config.cpu_count; i++) {
    10091009                if (!cpus[i].active)
    10101010                        continue;
    1011                
     1011
    10121012                thread_t *thread;
    10131013                if ((thread = thread_create((void (*)(void *)) cmd_call0,
     
    10211021                        printf("Unable to create thread for cpu%u\n", i);
    10221022        }
    1023        
     1023
    10241024        return 1;
    10251025}
     
    11081108        fncptr_t fptr;
    11091109        errno_t rc;
    1110        
     1110
    11111111        symbol = (char *) argv->buffer;
    11121112        rc = symtab_addr_lookup(symbol, &symaddr);
     
    11831183        bool pointer = false;
    11841184        errno_t rc;
    1185        
     1185
    11861186        if (((char *) argv->buffer)[0] == '*') {
    11871187                rc = symtab_addr_lookup((char *) argv->buffer + 1, &addr);
     
    11951195        } else
    11961196                rc = symtab_addr_lookup((char *) argv->buffer, &addr);
    1197        
     1197
    11981198        if (rc == ENOENT)
    11991199                printf("Symbol %s not found.\n", (char *) argv->buffer);
     
    12101210        } else
    12111211                printf("No symbol information available.\n");
    1212        
     1212
    12131213        return 1;
    12141214}
     
    12521252        else
    12531253                printf("Unknown argument \"%s\".\n", flag_buf);
    1254        
     1254
    12551255        return 1;
    12561256}
     
    12701270        else
    12711271                printf("Unknown argument \"%s\".\n", flag_buf);
    1272        
     1272
    12731273        return 1;
    12741274}
     
    14121412        release_console();
    14131413        indev_pop_character(stdin);
    1414        
     1414
    14151415        return 1;
    14161416}
     
    14201420{
    14211421        printf("%s (%s)\n", test->name, test->desc);
    1422        
     1422
    14231423        /* Update and read thread accounting
    14241424           for benchmarking */
     
    14271427        task_get_accounting(TASK, &ucycles0, &kcycles0);
    14281428        irq_spinlock_unlock(&TASK->lock, true);
    1429        
     1429
    14301430        /* Execute the test */
    14311431        test_quiet = false;
    14321432        const char *ret = test->entry();
    1433        
     1433
    14341434        /* Update and read thread accounting */
    14351435        uint64_t ucycles1, kcycles1;
     
    14371437        task_get_accounting(TASK, &ucycles1, &kcycles1);
    14381438        irq_spinlock_unlock(&TASK->lock, true);
    1439        
     1439
    14401440        uint64_t ucycles, kcycles;
    14411441        char usuffix, ksuffix;
    14421442        order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix);
    14431443        order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix);
    1444        
     1444
    14451445        printf("Time: %" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles\n",
    14461446            ucycles, usuffix, kcycles, ksuffix);
    1447        
     1447
    14481448        if (ret == NULL) {
    14491449                printf("Test passed\n");
    14501450                return true;
    14511451        }
    1452        
     1452
    14531453        printf("%s\n", ret);
    14541454        return false;
     
    14611461        uint64_t ucycles, kcycles;
    14621462        char usuffix, ksuffix;
    1463        
     1463
    14641464        if (cnt < 1)
    14651465                return true;
    1466        
     1466
    14671467        uint64_t *data = (uint64_t *) malloc(sizeof(uint64_t) * cnt, 0);
    14681468        if (data == NULL) {
     
    14701470                return false;
    14711471        }
    1472        
     1472
    14731473        for (i = 0; i < cnt; i++) {
    14741474                printf("%s (%u/%u) ... ", test->name, i + 1, cnt);
    1475                
     1475
    14761476                /* Update and read thread accounting
    14771477                   for benchmarking */
     
    14801480                task_get_accounting(TASK, &ucycles0, &kcycles0);
    14811481                irq_spinlock_unlock(&TASK->lock, true);
    1482                
     1482
    14831483                /* Execute the test */
    14841484                test_quiet = true;
    14851485                const char *test_ret = test->entry();
    1486                
     1486
    14871487                /* Update and read thread accounting */
    14881488                irq_spinlock_lock(&TASK->lock, true);
     
    14901490                task_get_accounting(TASK, &ucycles1, &kcycles1);
    14911491                irq_spinlock_unlock(&TASK->lock, true);
    1492                
     1492
    14931493                if (test_ret != NULL) {
    14941494                        printf("%s\n", test_ret);
     
    14961496                        break;
    14971497                }
    1498                
     1498
    14991499                data[i] = ucycles1 - ucycles0 + kcycles1 - kcycles0;
    15001500                order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix);
     
    15031503                    ucycles, usuffix, kcycles, ksuffix);
    15041504        }
    1505        
     1505
    15061506        if (ret) {
    15071507                printf("\n");
    1508                
     1508
    15091509                uint64_t sum = 0;
    1510                
     1510
    15111511                for (i = 0; i < cnt; i++) {
    15121512                        sum += data[i];
    15131513                }
    1514                
     1514
    15151515                order_suffix(sum / (uint64_t) cnt, &ucycles, &usuffix);
    15161516                printf("Average\t\t%" PRIu64 "%c\n", ucycles, usuffix);
    15171517        }
    1518        
     1518
    15191519        free(data);
    1520        
     1520
    15211521        return ret;
    15221522}
     
    15261526        size_t len = 0;
    15271527        test_t *test;
    1528        
     1528
    15291529        for (test = tests; test->name != NULL; test++) {
    15301530                if (str_length(test->name) > len)
    15311531                        len = str_length(test->name);
    15321532        }
    1533        
     1533
    15341534        unsigned int _len = (unsigned int) len;
    15351535        if ((_len != len) || (((int) _len) < 0)) {
     
    15371537                return;
    15381538        }
    1539        
     1539
    15401540        for (test = tests; test->name != NULL; test++)
    15411541                printf("%-*s %s%s\n", _len, test->name, test->desc,
    15421542                    (test->safe ? "" : " (unsafe)"));
    1543        
     1543
    15441544        printf("%-*s Run all safe tests\n", _len, "*");
    15451545}
     
    15551555{
    15561556        test_t *test;
    1557        
     1557
    15581558        if (str_cmp((char *) argv->buffer, "*") == 0) {
    15591559                for (test = tests; test->name != NULL; test++) {
     
    15661566        } else if (str_cmp((char *) argv->buffer, "") != 0) {
    15671567                bool fnd = false;
    1568                
     1568
    15691569                for (test = tests; test->name != NULL; test++) {
    15701570                        if (str_cmp(test->name, (char *) argv->buffer) == 0) {
     
    15741574                        }
    15751575                }
    1576                
     1576
    15771577                if (!fnd)
    15781578                        printf("Unknown test\n");
    15791579        } else
    15801580                list_tests();
    1581        
     1581
    15821582        return 1;
    15831583}
     
    15931593        test_t *test;
    15941594        uint32_t cnt = argv[1].intval;
    1595        
     1595
    15961596        if (str_cmp((char *) argv->buffer, "*") == 0) {
    15971597                for (test = tests; test->name != NULL; test++) {
     
    16031603        } else {
    16041604                bool fnd = false;
    1605                
     1605
    16061606                for (test = tests; test->name != NULL; test++) {
    16071607                        if (str_cmp(test->name, (char *) argv->buffer) == 0) {
    16081608                                fnd = true;
    1609                                
     1609
    16101610                                if (test->safe)
    16111611                                        run_bench(test, cnt);
    16121612                                else
    16131613                                        printf("Unsafe test\n");
    1614                                
     1614
    16151615                                break;
    16161616                        }
    16171617                }
    1618                
     1618
    16191619                if (!fnd)
    16201620                        printf("Unknown test\n");
    16211621        }
    1622        
     1622
    16231623        return 1;
    16241624}
  • kernel/generic/src/console/console.c

    r3061bc1 r8565a42  
    119119                stdin = &stdin_sink;
    120120        }
    121        
     121
    122122        return stdin;
    123123}
     
    143143                stdout = &stdout_source;
    144144        }
    145        
     145
    146146        list_append(&outdev->link, &stdout->list);
    147147}
     
    189189{
    190190        void *faddr = (void *) KA2PA(kio);
    191        
     191
    192192        assert((uintptr_t) faddr % FRAME_SIZE == 0);
    193        
     193
    194194        kio_parea.pbase = (uintptr_t) faddr;
    195195        kio_parea.frames = SIZE2FRAMES(sizeof(kio));
     
    197197        kio_parea.mapped = false;
    198198        ddi_parea_register(&kio_parea);
    199        
     199
    200200        sysinfo_set_item_val("kio.faddr", NULL, (sysarg_t) faddr);
    201201        sysinfo_set_item_val("kio.pages", NULL, KIO_PAGES);
    202        
     202
    203203        event_set_unmask_callback(EVENT_KIO, kio_update);
    204204        atomic_set(&kio_inited, true);
     
    209209        event_notify_1(EVENT_KCONSOLE, false, true);
    210210        bool prev = console_override;
    211        
     211
    212212        console_override = true;
    213213        if ((stdout) && (stdout->op->redraw))
    214214                stdout->op->redraw(stdout);
    215        
     215
    216216        if ((stdin) && (!prev)) {
    217217                /*
     
    256256        size_t count = 0;
    257257        buf[offset] = 0;
    258        
     258
    259259        wchar_t ch;
    260260        while ((ch = indev_pop_character(indev)) != '\n') {
     
    265265                                putchar(' ');
    266266                                putchar('\b');
    267                                
     267
    268268                                count--;
    269269                                offset = str_lsize(buf, count);
     
    271271                        }
    272272                }
    273                
     273
    274274                if (chr_encode(ch, buf, &offset, buflen - 1) == EOK) {
    275275                        putchar(ch);
     
    278278                }
    279279        }
    280        
     280
    281281        return count;
    282282}
     
    294294        if (!atomic_get(&kio_inited))
    295295                return;
    296        
     296
    297297        spinlock_lock(&kio_lock);
    298        
     298
    299299        if (kio_uspace > 0) {
    300300                if (event_notify_3(EVENT_KIO, true, kio_start, kio_len,
     
    302302                        kio_uspace = 0;
    303303        }
    304        
     304
    305305        spinlock_unlock(&kio_lock);
    306306}
     
    312312{
    313313        bool ordy = ((stdout) && (stdout->op->write));
    314        
     314
    315315        if (!ordy)
    316316                return;
     
    347347        else
    348348                kio_start = (kio_start + 1) % KIO_LENGTH;
    349        
     349
    350350        if (kio_stored < kio_len)
    351351                kio_stored++;
    352        
     352
    353353        /* The character is stored for uspace */
    354354        if (kio_uspace < kio_len)
     
    359359{
    360360        bool ordy = ((stdout) && (stdout->op->write));
    361        
     361
    362362        spinlock_lock(&kio_lock);
    363363        kio_push_char(ch);
    364364        spinlock_unlock(&kio_lock);
    365        
     365
    366366        /* Output stored characters */
    367367        kio_flush();
    368        
     368
    369369        if (!ordy) {
    370370                /*
     
    380380                early_putchar(ch);
    381381        }
    382        
     382
    383383        /* Force notification on newline */
    384384        if (ch == '\n')
     
    409409        if (size > PAGE_SIZE)
    410410                return (sys_errno_t) ELIMIT;
    411        
     411
    412412        if (size > 0) {
    413413                data = (char *) malloc(size + 1, 0);
    414414                if (!data)
    415415                        return (sys_errno_t) ENOMEM;
    416                
     416
    417417                rc = copy_from_uspace(data, buf, size);
    418418                if (rc) {
     
    421421                }
    422422                data[size] = 0;
    423                
     423
    424424                switch (cmd) {
    425425                case KIO_WRITE:
  • kernel/generic/src/console/kconsole.c

    r3061bc1 r8565a42  
    9898{
    9999        unsigned int i;
    100        
     100
    101101        cmd_init();
    102102        for (i = 0; i < KCONSOLE_HISTORY; i++)
     
    114114{
    115115        spinlock_lock(&cmd_lock);
    116        
     116
    117117        /*
    118118         * Make sure the command is not already listed.
     
    124124                        return false;
    125125                }
    126                
     126
    127127                /* Avoid deadlock. */
    128128                if (hlp < cmd) {
     
    133133                        spinlock_lock(&hlp->lock);
    134134                }
    135                
     135
    136136                if (str_cmp(hlp->name, cmd->name) == 0) {
    137137                        /* The command is already there. */
     
    141141                        return false;
    142142                }
    143                
     143
    144144                spinlock_unlock(&hlp->lock);
    145145                spinlock_unlock(&cmd->lock);
    146146        }
    147        
     147
    148148        /*
    149149         * Now the command can be added.
    150150         */
    151151        list_append(&cmd->link, &cmd_list);
    152        
     152
    153153        spinlock_unlock(&cmd_lock);
    154154        return true;
     
    168168        link_t **startpos = (link_t**) ctx;
    169169        size_t namelen = str_length(name);
    170        
     170
    171171        spinlock_lock(&cmd_lock);
    172        
     172
    173173        if (*startpos == NULL)
    174174                *startpos = cmd_list.head.next;
    175        
     175
    176176        for (; *startpos != &cmd_list.head; *startpos = (*startpos)->next) {
    177177                cmd_info_t *hlp = list_get_instance(*startpos, cmd_info_t, link);
    178                
     178
    179179                const char *curname = hlp->name;
    180180                if (str_length(curname) < namelen)
    181181                        continue;
    182                
     182
    183183                if (str_lcmp(curname, name, namelen) == 0) {
    184184                        *startpos = (*startpos)->next;
    185185                        if (h)
    186186                                *h = hlp->description;
    187                        
     187
    188188                        spinlock_unlock(&cmd_lock);
    189189                        return (curname + str_lsize(curname, namelen));
    190190                }
    191191        }
    192        
     192
    193193        spinlock_unlock(&cmd_lock);
    194194        return NULL;
     
    207207{
    208208        const char *name = input;
    209        
     209
    210210        size_t found = 0;
    211        
     211
    212212        /*
    213213         * Maximum Match Length: Length of longest matching common
     
    223223        size_t total_hints_shown = 0;
    224224        bool continue_showing_hints = true;
    225        
     225
    226226        output[0] = 0;
    227        
     227
    228228        while ((hint = hints_enum(name, NULL, &pos))) {
    229229                if ((found == 0) || (str_length(hint) > str_length(output)))
    230230                        str_cpy(output, MAX_CMDLINE, hint);
    231                
     231
    232232                found++;
    233233        }
    234        
     234
    235235        /*
    236236         * If the number of possible completions is more than MAX_TAB_HINTS,
     
    242242                    console_prompt_display_all_hints(indev, found);
    243243        }
    244        
     244
    245245        if ((found > 1) && (str_length(output) != 0)) {
    246246                printf("\n");
    247247                pos = NULL;
    248248                while ((hint = hints_enum(name, &help, &pos))) {
    249                        
     249
    250250                        if (continue_showing_hints) {
    251251                                if (help)
     
    253253                                else
    254254                                        printf("%s%s\n", name, hint);
    255                                
     255
    256256                                --hints_to_show;
    257257                                ++total_hints_shown;
    258                                
     258
    259259                                if ((hints_to_show == 0) && (total_hints_shown != found)) {
    260260                                        /* Ask user to continue */
     
    263263                                }
    264264                        }
    265                        
     265
    266266                        for (max_match_len_tmp = 0;
    267267                            (output[max_match_len_tmp] ==
    268268                            hint[max_match_len_tmp]) &&
    269269                            (max_match_len_tmp < max_match_len); ++max_match_len_tmp);
    270                        
     270
    271271                        max_match_len = max_match_len_tmp;
    272272                }
    273                
     273
    274274                /* Keep only the characters common in all completions */
    275275                output[max_match_len] = 0;
    276276        }
    277        
     277
    278278        if (found > 0)
    279279                str_cpy(input, size, output);
    280        
     280
    281281        free(output);
    282282        return found;
     
    288288        size_t end;
    289289        char *tmp;
    290        
     290
    291291        while (isspace(cmdline[start]))
    292292                start++;
    293        
     293
    294294        end = start + 1;
    295        
     295
    296296        while (!isspace(cmdline[end]))
    297297                end++;
    298        
     298
    299299        tmp = malloc(STR_BOUNDS(end - start + 1), 0);
    300        
     300
    301301        wstr_to_str(tmp, end - start + 1, &cmdline[start]);
    302        
     302
    303303        spinlock_lock(&cmd_lock);
    304        
     304
    305305        list_foreach(cmd_list, link, cmd_info_t, hlp) {
    306306                spinlock_lock(&hlp->lock);
    307                
     307
    308308                if (str_cmp(hlp->name, tmp) == 0) {
    309309                        spinlock_unlock(&hlp->lock);
     
    312312                        return hlp;
    313313                }
    314                
     314
    315315                spinlock_unlock(&hlp->lock);
    316316        }
    317        
     317
    318318        free(tmp);
    319319        spinlock_unlock(&cmd_lock);
    320        
     320
    321321        return NULL;
    322322}
     
    325325{
    326326        printf("%s> ", prompt);
    327        
     327
    328328        size_t position = 0;
    329329        wchar_t *current = history[history_pos];
    330330        current[0] = 0;
    331331        char *tmp = malloc(STR_BOUNDS(MAX_CMDLINE), 0);
    332        
     332
    333333        while (true) {
    334334                wchar_t ch = indev_pop_character(indev);
    335                
     335
    336336                if (ch == '\n') {
    337337                        /* Enter */
     
    339339                        break;
    340340                }
    341                
     341
    342342                if (ch == '\b') {
    343343                        /* Backspace */
    344344                        if (position == 0)
    345345                                continue;
    346                        
     346
    347347                        if (wstr_remove(current, position - 1)) {
    348348                                position--;
     
    353353                        }
    354354                }
    355                
     355
    356356                if (ch == '\t') {
    357357                        /* Tab completion */
    358                        
     358
    359359                        /* Move to the end of the word */
    360360                        for (; (current[position] != 0) && (!isspace(current[position]));
    361361                            position++)
    362362                                putchar(current[position]);
    363                        
    364                        
     363
     364
    365365                        /*
    366366                         * Find the beginning of the word
     
    376376                                    (beg > 0) && (!isspace(current[beg]));
    377377                                    beg--);
    378                                
     378
    379379                                if (isspace(current[beg]))
    380380                                        beg++;
    381                                
     381
    382382                                wstr_to_str(tmp, position - beg + 1, current + beg);
    383383                        }
    384                        
     384
    385385                        /* Count which argument number are we tabbing (narg=0 is cmd) */
    386386                        bool sp = false;
     
    394394                                        sp = false;
    395395                        }
    396                        
     396
    397397                        if (narg && isspace(current[0]))
    398398                                narg--;
    399                        
     399
    400400                        int found;
    401401                        if (narg == 0) {
     
    411411                                    cmd->hints_enum);
    412412                        }
    413                        
     413
    414414                        if (found == 0)
    415415                                continue;
     
    424424                                if (!wstr_linsert(current, ch, position + i, MAX_CMDLINE))
    425425                                        break;
    426                                
     426
    427427                                i++;
    428428                        }
    429                        
     429
    430430                        if (found > 1) {
    431431                                /* No unique hint, list was printed */
     
    436436                                continue;
    437437                        }
    438                        
     438
    439439                        /* We have a hint */
    440                        
     440
    441441                        printf("%ls", current + position);
    442442                        position += str_length(tmp);
    443443                        print_cc('\b', wstr_length(current) - position);
    444                        
     444
    445445                        if (position == wstr_length(current)) {
    446446                                /* Insert a space after the last completed argument */
     
    452452                        continue;
    453453                }
    454                
     454
    455455                if (ch == U_LEFT_ARROW) {
    456456                        /* Left */
     
    461461                        continue;
    462462                }
    463                
     463
    464464                if (ch == U_RIGHT_ARROW) {
    465465                        /* Right */
     
    470470                        continue;
    471471                }
    472                
     472
    473473                if ((ch == U_UP_ARROW) || (ch == U_DOWN_ARROW)) {
    474474                        /* Up, down */
     
    476476                        print_cc(' ', wstr_length(current));
    477477                        print_cc('\b', wstr_length(current));
    478                        
     478
    479479                        if (ch == U_UP_ARROW) {
    480480                                /* Up */
     
    493493                        continue;
    494494                }
    495                
     495
    496496                if (ch == U_HOME_ARROW) {
    497497                        /* Home */
     
    500500                        continue;
    501501                }
    502                
     502
    503503                if (ch == U_END_ARROW) {
    504504                        /* End */
     
    507507                        continue;
    508508                }
    509                
     509
    510510                if (ch == U_DELETE) {
    511511                        /* Delete */
    512512                        if (position == wstr_length(current))
    513513                                continue;
    514                        
     514
    515515                        if (wstr_remove(current, position)) {
    516516                                printf("%ls ", current + position);
     
    519519                        continue;
    520520                }
    521                
     521
    522522                if (wstr_linsert(current, ch, position, MAX_CMDLINE)) {
    523523                        printf("%ls", current + position);
     
    526526                }
    527527        }
    528        
     528
    529529        if (wstr_length(current) > 0) {
    530530                history_pos++;
    531531                history_pos = history_pos % KCONSOLE_HISTORY;
    532532        }
    533        
     533
    534534        free(tmp);
    535535        return current;
     
    546546        bool isaddr = false;
    547547        bool isptr = false;
    548        
     548
    549549        /* If we get a name, try to find it in symbol table */
    550550        if (text[0] == '&') {
     
    557557                len--;
    558558        }
    559        
     559
    560560        if ((text[0] < '0') || (text[0] > '9')) {
    561561                char symname[MAX_SYMBOL_NAME];
    562562                str_ncpy(symname, MAX_SYMBOL_NAME, text, len + 1);
    563                
     563
    564564                uintptr_t symaddr;
    565565                errno_t rc = symtab_addr_lookup(symname, &symaddr);
     
    611611                }
    612612        }
    613        
     613
    614614        return true;
    615615}
     
    635635        assert(start != NULL);
    636636        assert(end != NULL);
    637        
     637
    638638        bool found_start = false;
    639639        size_t offset = *start;
    640640        size_t prev = *start;
    641641        wchar_t ch;
    642        
     642
    643643        while ((ch = str_decode(cmdline, &offset, size)) != 0) {
    644644                if (!found_start) {
     
    651651                                break;
    652652                }
    653                
     653
    654654                prev = offset;
    655655        }
    656656        *end = prev;
    657        
     657
    658658        return found_start;
    659659}
     
    676676        }
    677677        spinlock_lock(&cmd_lock);
    678        
     678
    679679        cmd_info_t *cmd = NULL;
    680        
     680
    681681        list_foreach(cmd_list, link, cmd_info_t, hlp) {
    682682                spinlock_lock(&hlp->lock);
    683                
     683
    684684                if (str_lcmp(hlp->name, cmdline + start,
    685685                    max(str_length(hlp->name),
     
    688688                        break;
    689689                }
    690                
     690
    691691                spinlock_unlock(&hlp->lock);
    692692        }
    693        
     693
    694694        spinlock_unlock(&cmd_lock);
    695        
     695
    696696        if (!cmd) {
    697697                /* Unknown command. */
     
    699699                return NULL;
    700700        }
    701        
     701
    702702        /* cmd == hlp is locked */
    703        
     703
    704704        /*
    705705         * The command line must be further analyzed and
     
    708708         * structure.
    709709         */
    710        
     710
    711711        bool error = false;
    712712        size_t i;
    713713        for (i = 0; i < cmd->argc; i++) {
    714714                char *buf;
    715                
     715
    716716                start = end;
    717717                if (!parse_argument(cmdline, size, &start, &end)) {
     
    721721                                continue;
    722722                        }
    723                        
     723
    724724                        printf("Too few arguments.\n");
    725725                        spinlock_unlock(&cmd->lock);
    726726                        return NULL;
    727727                }
    728                
     728
    729729                switch (cmd->argv[i].type) {
    730730                case ARG_TYPE_STRING:
     
    767767                }
    768768        }
    769        
     769
    770770        if (error) {
    771771                spinlock_unlock(&cmd->lock);
    772772                return NULL;
    773773        }
    774        
     774
    775775        start = end;
    776776        if (parse_argument(cmdline, size, &start, &end)) {
     
    779779                return NULL;
    780780        }
    781        
     781
    782782        spinlock_unlock(&cmd->lock);
    783783        return cmd;
     
    798798                return;
    799799        }
    800        
     800
    801801        if (msg)
    802802                printf("%s", msg);
    803        
     803
    804804        if (kcon)
    805805                indev_pop_character(stdin);
    806806        else
    807807                printf("Type \"exit\" to leave the console.\n");
    808        
     808
    809809        char *cmdline = malloc(STR_BOUNDS(MAX_CMDLINE), 0);
    810810        while (true) {
     
    813813                if (!len)
    814814                        continue;
    815                
     815
    816816                wstr_to_str(cmdline, STR_BOUNDS(MAX_CMDLINE), tmp);
    817                
     817
    818818                if ((!kcon) && (len == 4) && (str_lcmp(cmdline, "exit", 4) == 0))
    819819                        break;
    820                
     820
    821821                cmd_info_t *cmd_info = parse_cmdline(cmdline, STR_BOUNDS(MAX_CMDLINE));
    822822                if (!cmd_info)
    823823                        continue;
    824                
     824
    825825                (void) cmd_info->func(cmd_info->argv);
    826826        }
  • kernel/generic/src/console/prompt.c

    r3061bc1 r8565a42  
    5252        assert(indev);
    5353        assert(hints > 0);
    54        
     54
    5555        printf("Display all %zu possibilities? (y or n) ", hints);
    56        
     56
    5757        while (true) {
    5858                wchar_t answer = indev_pop_character(indev);
    59                
     59
    6060                if ((answer == 'y') || (answer == 'Y')) {
    6161                        printf("y");
    6262                        return true;
    6363                }
    64                
     64
    6565                if ((answer == 'n') || (answer == 'N')) {
    6666                        printf("n");
     
    8484        assert(indev);
    8585        assert(display_hints != NULL);
    86        
     86
    8787        printf("--More--");
    8888        while (true) {
     
    9595                        break;
    9696                }
    97                
     97
    9898                /* Stop displaying hints? */
    9999                if ((continue_showing_hints == 'n') ||
     
    104104                        break;
    105105                }
    106                
     106
    107107                /* Show one more hint? */
    108108                if (continue_showing_hints == '\n') {
     
    111111                }
    112112        }
    113        
     113
    114114        /* Delete the --More-- option */
    115115        printf("\r         \r");
    116        
     116
    117117        return *display_hints > 0;
    118118}
Note: See TracChangeset for help on using the changeset viewer.