LCOV - code coverage report
Current view: top level - lib/cmdline - cmdline_vt100.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 23 42 54.8 %
Date: 2025-05-01 17:49:45 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 13 24 54.2 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2014 Intel Corporation.
       3                 :            :  * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org>
       4                 :            :  * All rights reserved.
       5                 :            :  */
       6                 :            : 
       7                 :            : #include <stdint.h>
       8                 :            : #include <stdio.h>
       9                 :            : #include <string.h>
      10                 :            : 
      11                 :            : #include "cmdline_vt100.h"
      12                 :            : 
      13                 :            : #include <eal_export.h>
      14                 :            : 
      15                 :            : const char *cmdline_vt100_commands[] = {
      16                 :            :         vt100_up_arr,
      17                 :            :         vt100_down_arr,
      18                 :            :         vt100_right_arr,
      19                 :            :         vt100_left_arr,
      20                 :            :         "\177",
      21                 :            :         "\n",
      22                 :            :         "\001",
      23                 :            :         "\005",
      24                 :            :         "\013",
      25                 :            :         "\031",
      26                 :            :         "\003",
      27                 :            :         "\006",
      28                 :            :         "\002",
      29                 :            :         vt100_suppr,
      30                 :            :         vt100_tab,
      31                 :            :         "\004",
      32                 :            :         "\014",
      33                 :            :         "\r",
      34                 :            :         "\033\177",
      35                 :            :         vt100_word_left,
      36                 :            :         vt100_word_right,
      37                 :            :         "?",
      38                 :            :         "\027",
      39                 :            :         "\020",
      40                 :            :         "\016",
      41                 :            :         "\033\144",
      42                 :            :         vt100_bs,
      43                 :            : };
      44                 :            : 
      45                 :            : RTE_EXPORT_SYMBOL(vt100_init)
      46                 :            : void
      47                 :        250 : vt100_init(struct cmdline_vt100 *vt)
      48                 :            : {
      49         [ +  + ]:        250 :         if (!vt)
      50                 :            :                 return;
      51                 :        249 :         vt->state = CMDLINE_VT100_INIT;
      52                 :            : }
      53                 :            : 
      54                 :            : 
      55                 :            : static int
      56                 :       2305 : match_command(char *buf, unsigned int size)
      57                 :            : {
      58                 :            :         const char *cmd;
      59                 :            :         size_t cmdlen;
      60                 :            :         unsigned int i = 0;
      61                 :            : 
      62         [ +  + ]:      61768 :         for (i=0 ; i<sizeof(cmdline_vt100_commands)/sizeof(const char *) ; i++) {
      63                 :      59589 :                 cmd = *(cmdline_vt100_commands + i);
      64                 :            : 
      65                 :      59589 :                 cmdlen = strnlen(cmd, CMDLINE_VT100_BUF_SIZE);
      66         [ +  + ]:      59589 :                 if (size == cmdlen &&
      67         [ +  + ]:      39474 :                     !strncmp(buf, cmd, cmdlen)) {
      68                 :        126 :                         return i;
      69                 :            :                 }
      70                 :            :         }
      71                 :            : 
      72                 :            :         return -1;
      73                 :            : }
      74                 :            : 
      75                 :            : RTE_EXPORT_SYMBOL(vt100_parser)
      76                 :            : int
      77                 :       2306 : vt100_parser(struct cmdline_vt100 *vt, char ch)
      78                 :            : {
      79                 :            :         unsigned int size;
      80                 :       2306 :         uint8_t c = (uint8_t) ch;
      81                 :            : 
      82         [ +  + ]:       2306 :         if (!vt)
      83                 :            :                 return -1;
      84                 :            : 
      85         [ -  + ]:       2305 :         if (vt->bufpos >= CMDLINE_VT100_BUF_SIZE) {
      86                 :          0 :                 vt->state = CMDLINE_VT100_INIT;
      87                 :          0 :                 vt->bufpos = 0;
      88                 :            :         }
      89                 :            : 
      90                 :       2305 :         vt->buf[vt->bufpos++] = c;
      91                 :       2305 :         size = vt->bufpos;
      92                 :            : 
      93   [ +  -  -  - ]:       2305 :         switch (vt->state) {
      94                 :       2305 :         case CMDLINE_VT100_INIT:
      95         [ -  + ]:       2305 :                 if (c == 033) {
      96                 :          0 :                         vt->state = CMDLINE_VT100_ESCAPE;
      97                 :            :                 }
      98                 :            :                 else {
      99                 :       2305 :                         vt->bufpos = 0;
     100                 :       2305 :                         goto match_command;
     101                 :            :                 }
     102                 :          0 :                 break;
     103                 :            : 
     104                 :          0 :         case CMDLINE_VT100_ESCAPE:
     105         [ #  # ]:          0 :                 if (c == 0133) {
     106                 :          0 :                         vt->state = CMDLINE_VT100_ESCAPE_CSI;
     107                 :            :                 }
     108         [ #  # ]:          0 :                 else if (c >= 060 && c <= 0177) { /* XXX 0177 ? */
     109                 :          0 :                         vt->bufpos = 0;
     110                 :          0 :                         vt->state = CMDLINE_VT100_INIT;
     111                 :          0 :                         goto match_command;
     112                 :            :                 }
     113                 :            :                 break;
     114                 :            : 
     115                 :          0 :         case CMDLINE_VT100_ESCAPE_CSI:
     116         [ #  # ]:          0 :                 if (c >= 0100 && c <= 0176) {
     117                 :          0 :                         vt->bufpos = 0;
     118                 :          0 :                         vt->state = CMDLINE_VT100_INIT;
     119                 :          0 :                         goto match_command;
     120                 :            :                 }
     121                 :            :                 break;
     122                 :            : 
     123                 :          0 :         default:
     124                 :          0 :                 vt->bufpos = 0;
     125                 :          0 :                 break;
     126                 :            :         }
     127                 :            : 
     128                 :            :         return -2;
     129                 :            : 
     130                 :       2305 :  match_command:
     131                 :       2305 :         return match_command(vt->buf, size);
     132                 :            : }

Generated by: LCOV version 1.14