LCOV - code coverage report
Current view: top level - src/command - run.h Hit Total Coverage
Test: dte Lines: 4 4 100.0 %
Date: 2023-03-25 22:04:15

          Line data    Source code
       1             : #ifndef COMMAND_RUN_H
       2             : #define COMMAND_RUN_H
       3             : 
       4             : #include <stdbool.h>
       5             : #include <stddef.h>
       6             : #include <stdint.h>
       7             : #include <string.h>
       8             : #include "util/macros.h"
       9             : #include "util/string-view.h"
      10             : 
      11             : typedef struct {
      12             :     char **args; // Positional args, with flag args moved to the front
      13             :     size_t nr_args; // Number of args (not including flag args)
      14             :     uint_least64_t flag_set; // Bitset of used flags
      15             :     char flags[10]; // Flags in parsed order
      16             :     uint8_t nr_flags; // Number of parsed flags
      17             :     uint8_t nr_flag_args; // Number of flag args
      18             : } CommandArgs;
      19             : 
      20             : typedef bool (*CommandFunc)(void *userdata, const CommandArgs *args);
      21             : 
      22             : typedef struct {
      23             :     const char name[15];
      24             :     const char flags[14];
      25             :     bool allow_in_rc;
      26             :     uint8_t min_args;
      27             :     uint8_t max_args; // 0xFF here means "no limit" (effectively SIZE_MAX)
      28             :     CommandFunc cmd;
      29             : } Command;
      30             : 
      31             : typedef struct {
      32             :     const Command* (*lookup)(const char *name);
      33             :     void (*macro_record)(const Command *cmd, char **args, void *userdata);
      34             :     bool (*expand_variable)(const char *name, char **value, const void *userdata);
      35             :     bool expand_env_vars;
      36             : } CommandSet;
      37             : 
      38             : typedef struct {
      39             :     const CommandSet *cmds;
      40             :     const char* (*lookup_alias)(const char *name, void *userdata);
      41             :     const StringView *home_dir;
      42             :     void *userdata;
      43             :     unsigned int recursion_count;
      44             :     bool allow_recording;
      45             : } CommandRunner;
      46             : 
      47             : extern const Command *current_command;
      48             : 
      49       20656 : static inline int command_cmp(const void *key, const void *elem)
      50             : {
      51       20656 :     const char *name = key;
      52       20656 :     const Command *cmd = elem;
      53       20656 :     return strcmp(name, cmd->name);
      54             : }
      55             : 
      56             : bool handle_command(CommandRunner *runner, const char *cmd) NONNULL_ARGS;
      57             : 
      58             : #endif

Generated by: LCOV version 1.14