Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit 8c5fd49

Browse files
authored
Merge pull request #6 from milosz275/cli/execute_args
Add command line arguments execution
2 parents 0bd6014 + 425c606 commit 8c5fd49

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

bitlab/src/bitlab.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212

1313
bitlab_result run_bitlab(int argc, char* argv[])
1414
{
15-
// [ ] utilize the argc and argv parameters.
16-
if (argc != 1 && argv != NULL) {}
17-
1815
// init
1916
init_config_dir();
2017
init_logging(BITLAB_LOG);
@@ -26,6 +23,32 @@ bitlab_result run_bitlab(int argc, char* argv[])
2623
log_message(LOG_WARN, BITLAB_LOG, __FILE__, "CLI thread creation failed: %s", strerror(errno));
2724
log_message(LOG_INFO, BITLAB_LOG, __FILE__, "CLI thread started");
2825

26+
// execute command line arguments
27+
if (argc > 1 && argv != NULL)
28+
{
29+
int total_length = 0;
30+
for (int i = 1; i < argc; ++i)
31+
total_length += strlen(argv[i]) + 1;
32+
33+
char* line = (char*)malloc(total_length * sizeof(char));
34+
if (line == NULL)
35+
log_message(LOG_ERROR, BITLAB_LOG, __FILE__, "Failed to allocate memory for command line arguments");
36+
else
37+
{
38+
line[0] = '\0';
39+
for (int i = 1; i < argc; ++i)
40+
{
41+
strcat(line, argv[i]);
42+
if (i < argc - 1)
43+
{
44+
strcat(line, " ");
45+
}
46+
}
47+
cli_exec_line(line);
48+
free(line);
49+
}
50+
}
51+
2952
// main loop
3053
while (!get_exit_flag(&state))
3154
usleep(100000); // 100 ms

0 commit comments

Comments
 (0)