diff --git a/man/tio.1.in b/man/tio.1.in index 108bd3b..e4cd066 100644 --- a/man/tio.1.in +++ b/man/tio.1.in @@ -165,7 +165,7 @@ Default value is 200. .TP .BR \-l ", " \-\-list -List available serial devices. +List available targets (serial devices, TIDs, configuration profiles). .TP .BR \-L ", " \-\-log @@ -173,7 +173,8 @@ List available serial devices. Enable log to file. The log file will be automatically named using the following format -tio_DEVICE_YYYY-MM-DDTHH:MM:SS.log. +tio_TARGET_YYYY-MM-DDTHH:MM:SS.log. Target being the command line target such +as tty-device, tid, or configuration profile. The filename can be manually set using the \-\-log-file option. diff --git a/src/configfile.c b/src/configfile.c index 9572852..db45146 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -603,3 +603,58 @@ void config_file_print(void) } } } + +void config_list_targets(void) +{ + memset(&config, 0, sizeof(struct config_t)); + + // Find config file + if (config_file_resolve() != 0) + { + // None found + return; + } + + GKeyFile *keyfile; + GError *error = NULL; + + keyfile = g_key_file_new(); + + if (!g_key_file_load_from_file(keyfile, config.path, G_KEY_FILE_NONE, &error)) + { + tio_error_print("Failure loading file: %s", error->message); + g_error_free(error); + return; + } + + // Get all group names + gsize num_groups; + gchar **group = g_key_file_get_groups(keyfile, &num_groups); + + if (num_groups == 0) + { + return; + } + + printf("\nConfiguration profiles\n"); + printf("--------------------------------------------------------------------------------\n"); + + int j = 1; + for (gsize i = 0; i < num_groups; i++) + { + // Skip default group + if (strcmp(group[i], CONFIG_GROUP_NAME_DEFAULT) == 0) + { + continue; + } + printf("%-20s ", group[i]); + if (j++ % 4 == 0) + { + putchar('\n'); + } + } + putchar('\n'); + + g_strfreev(group); + g_key_file_free(keyfile); +} diff --git a/src/configfile.h b/src/configfile.h index 7b7a3a9..2cb9f15 100644 --- a/src/configfile.h +++ b/src/configfile.h @@ -35,3 +35,4 @@ void config_file_print(void); void config_file_parse(void); void config_exit(void); void config_file_show_profiles(void); +void config_list_targets(void); diff --git a/src/options.c b/src/options.c index 15bacb9..c0316ce 100644 --- a/src/options.c +++ b/src/options.c @@ -42,6 +42,7 @@ #include "alert.h" #include "log.h" #include "script.h" +#include "configfile.h" #define HEX_N_VALUE_MAX 4096 @@ -150,7 +151,7 @@ void option_print_help(char *argv[]) printf(" -t, --timestamp Enable line timestamp\n"); printf(" --timestamp-format Set timestamp format (default: 24hour)\n"); printf(" --timestamp-timeout Set timestamp timeout (default: 200)\n"); - printf(" -l, --list List available serial devices\n"); + printf(" -l, --list List available serial devices, TIDs, and profiles\n"); printf(" -L, --log Enable log to file\n"); printf(" --log-file Set log filename\n"); printf(" --log-directory Set log directory path for automatic named logs\n"); @@ -916,6 +917,7 @@ void options_parse(int argc, char *argv[]) case 'l': list_serial_devices(); + config_list_targets(); exit(EXIT_SUCCESS); break;