LCOV - code coverage report
Current view: top level - src - main.c (source / functions) Hit Total Coverage
Test: report.info Lines: 18 30 60.0 %
Date: 2024-01-02 12:43:31 Functions: 3 4 75.0 %

          Line data    Source code
       1             : #include "main.h"
       2             : 
       3          20 : void handle_input(char *input)
       4             : {
       5          20 :     if (input == NULL || is_all_whitespace(input))
       6           0 :         return;
       7             : 
       8          20 :     add_to_command_history(input);
       9          20 :     preprocess_input(input);
      10          20 :     command_sequence_init(input);
      11             : }
      12             : 
      13          20 : void run_interactive_mode()
      14             : {
      15             :     while (1)
      16          18 :     {
      17          20 :         print_prompt();
      18             : 
      19          20 :         char *input = calloc(MAX_INPUT_LENGTH, sizeof(char));
      20          20 :         read_input(input);
      21          20 :         handle_input(input);
      22          18 :         free(input);
      23             :     }
      24             : }
      25             : 
      26           0 : void run_batch_mode(char *argv[], int argc)
      27             : {
      28           0 :     char *input = argv[2];
      29           0 :     for (int i = 3; i < argc; i++)
      30             :     {
      31           0 :         input = strcat(input, " ");
      32           0 :         input = strcat(input, argv[i]);
      33             :     }
      34           0 :     handle_input(input);
      35           0 : }
      36             : 
      37           2 : int main(int argc, char *argv[])
      38             : {
      39           2 :     init_command_history();
      40           2 :     init_aliases();
      41             : 
      42           2 :     if (argc > 2 && (strcmp(argv[1], "-c") && strcmp(argv[1], "--command")) == 0)
      43             :     {
      44           0 :         run_batch_mode(argv, argc);
      45             :     }
      46           2 :     else if (argc > 1 && (strcmp(argv[1], "-h") && strcmp(argv[1], "--help") == 0))
      47             :     {
      48           0 :         print_info("Usage: %s [-c \"command\"]", argv[0]);
      49           0 :         return EXIT_FAILURE;
      50             :     }
      51             :     else
      52             :     {
      53           2 :         run_interactive_mode();
      54             :     }
      55             : 
      56           0 :     return exit_shell(NULL, EXIT_SUCCESS);
      57             : }

Generated by: LCOV version 1.14