diff options
author | Christoph Lipka <clipka@de.adit-jv.com> | 2018-12-20 14:58:19 +0100 |
---|---|---|
committer | Christoph Lipka <clipka@de.adit-jv.com> | 2018-12-21 10:23:41 +0100 |
commit | dca8ab254aa0a687c32009079d85e4d8f960b213 (patch) | |
tree | e63b6a552fd9f61873892110a56a89ef354864cd /src/kpi/dlt-kpi-options.c | |
parent | 0d0c74640c8b792db37cb9f884f89f7561ea551f (diff) | |
download | DLT-daemon-dca8ab254aa0a687c32009079d85e4d8f960b213.tar.gz |
Code beautification using uncrustify
Signed-off-by: Christoph Lipka <clipka@de.adit-jv.com>
Diffstat (limited to 'src/kpi/dlt-kpi-options.c')
-rw-r--r-- | src/kpi/dlt-kpi-options.c | 124 |
1 files changed, 55 insertions, 69 deletions
diff --git a/src/kpi/dlt-kpi-options.c b/src/kpi/dlt-kpi-options.c index 0f6938c..14f0681 100644 --- a/src/kpi/dlt-kpi-options.c +++ b/src/kpi/dlt-kpi-options.c @@ -32,13 +32,13 @@ void usage(char *prog_name) { char version[255]; - dlt_get_version(version,255); + dlt_get_version(version, 255); printf("Usage: %s [options]\n", prog_name); printf("Application to forward information from the /proc/ file system to DLT.\n"); printf("%s\n", version); printf("Options:\n"); - //printf(" -d Daemonize. Detach from terminal and run in background.\n"); + /*printf(" -d Daemonize. Detach from terminal and run in background.\n"); */ printf(" -c filename Use configuration file. \n"); printf(" Default: %s\n", DEFAULT_CONF_FILE); printf(" -h This help message.\n"); @@ -55,48 +55,46 @@ void dlt_kpi_init_cli_options(DltKpiOptions *options) void dlt_kpi_free_cli_options(DltKpiOptions *options) { - if(options->customConfigFile) + if (options->customConfigFile) free(options->configurationFileName); } DltReturnValue dlt_kpi_read_command_line(DltKpiOptions *options, int argc, char **argv) { - if(options == NULL) - { + if (options == NULL) { fprintf(stderr, "%s: Nullpointer parameter\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } + dlt_kpi_init_cli_options(options); int opt; - while((opt = getopt(argc, argv, "c:h")) != -1) - { - switch(opt) { - case 'c': - { - if((options->configurationFileName = malloc(strlen(optarg)+1)) == 0) - { - fprintf(stderr, "Out of memory!\n"); - return DLT_RETURN_ERROR; - } - strcpy(options->configurationFileName, optarg); /* strcpy unritical here, because size matches exactly the size to be copied */ - options->customConfigFile = 1; - break; - } - case 'h': - { - usage(argv[0]); - exit(0); - return -1;//for parasoft - } - default: - { - fprintf(stderr, "Unknown option: %c\n", optopt); - usage(argv[0]); + while ((opt = getopt(argc, argv, "c:h")) != -1) + switch (opt) { + case 'c': + { + if ((options->configurationFileName = malloc(strlen(optarg) + 1)) == 0) { + fprintf(stderr, "Out of memory!\n"); return DLT_RETURN_ERROR; } + + strcpy(options->configurationFileName, optarg); /* strcpy unritical here, because size matches exactly the size to be copied */ + options->customConfigFile = 1; + break; + } + case 'h': + { + usage(argv[0]); + exit(0); + return -1; /*for parasoft */ + } + default: + { + fprintf(stderr, "Unknown option: %c\n", optopt); + usage(argv[0]); + return DLT_RETURN_ERROR; + } } - } return DLT_RETURN_OK; } @@ -123,8 +121,7 @@ DltReturnValue dlt_kpi_read_configuration_file(DltKpiConfig *config, char *file_ char *pch, *strchk; int tmp; - if(config == NULL || file_name == NULL) - { + if ((config == NULL) || (file_name == NULL)) { fprintf(stderr, "%s: Nullpointer parameter!\n", __func__); return DLT_RETURN_WRONG_PARAMETER; } @@ -133,17 +130,14 @@ DltReturnValue dlt_kpi_read_configuration_file(DltKpiConfig *config, char *file_ file = fopen(file_name, "r"); - if(file == NULL) - { + if (file == NULL) { fprintf(stderr, "%s: Could not open configuration file!\n", __func__); return DLT_RETURN_ERROR; } - if(((line = malloc(COMMAND_LINE_SIZE)) == 0) || - ((token = malloc(COMMAND_LINE_SIZE)) == 0) || - ((value = malloc(COMMAND_LINE_SIZE)) == 0)) - - { + if (((line = malloc(COMMAND_LINE_SIZE)) == 0) || + ((token = malloc(COMMAND_LINE_SIZE)) == 0) || + ((value = malloc(COMMAND_LINE_SIZE)) == 0)) { fclose(file); free(line); free(token); @@ -153,66 +147,61 @@ DltReturnValue dlt_kpi_read_configuration_file(DltKpiConfig *config, char *file_ return DLT_RETURN_ERROR; } - while(fgets(line, COMMAND_LINE_SIZE, file) != NULL) - { + while (fgets(line, COMMAND_LINE_SIZE, file) != NULL) { token[0] = '\0'; value[0] = '\0'; pch = strtok (line, " =\r\n"); - while(pch != NULL) - { - if(pch[0] == '#') + + while (pch != NULL) { + if (pch[0] == '#') break; - if(token[0] == '\0') - { - strncpy(token, pch, COMMAND_LINE_SIZE-1); - token[COMMAND_LINE_SIZE-1] = '\0'; + if (token[0] == '\0') { + strncpy(token, pch, COMMAND_LINE_SIZE - 1); + token[COMMAND_LINE_SIZE - 1] = '\0'; } - else - { - strncpy(value, pch, COMMAND_LINE_SIZE-1); - value[COMMAND_LINE_SIZE-1] = '\0'; + else { + strncpy(value, pch, COMMAND_LINE_SIZE - 1); + value[COMMAND_LINE_SIZE - 1] = '\0'; break; } pch = strtok(NULL, " =\r\n"); } - if(token[0] != '\0' && value[0] != '\0') - { - if(strcmp(token, "process_interval") == '\0') - { + if ((token[0] != '\0') && (value[0] != '\0')) { + if (strcmp(token, "process_interval") == '\0') { tmp = strtol(value, &strchk, 10); - if(strchk[0] == '\0' && tmp > 0) + if ((strchk[0] == '\0') && (tmp > 0)) config->process_log_interval = tmp; else fprintf(stderr, "Error reading configuration file: %s is not a valid value for %s\n", value, token); } - else if(strcmp(token, "irq_interval") == '\0') + else if (strcmp(token, "irq_interval") == '\0') { tmp = strtol(value, &strchk, 10); - if(strchk[0] == '\0' && tmp > 0) + if ((strchk[0] == '\0') && (tmp > 0)) config->irq_log_interval = tmp; else fprintf(stderr, "Error reading configuration file: %s is not a valid value for %s\n", value, token); } - else if(strcmp(token, "check_interval") == '\0') + else if (strcmp(token, "check_interval") == '\0') { tmp = strtol(value, &strchk, 10); - if(strchk[0] == '\0' && tmp > 0) + if ((strchk[0] == '\0') && (tmp > 0)) config->check_log_interval = tmp; else fprintf(stderr, "Error reading configuration file: %s is not a valid value for %s\n", value, token); } - else if(strcmp(token, "log_level") == '\0') + else if (strcmp(token, "log_level") == '\0') { tmp = strtol(value, &strchk, 10); - if(strchk[0] == '\0' && tmp >= -1 && tmp <= 6) + if ((strchk[0] == '\0') && (tmp >= -1) && (tmp <= 6)) config->log_level = tmp; else fprintf(stderr, "Error reading configuration file: %s is not a valid value for %s\n", value, token); @@ -234,20 +223,17 @@ DltReturnValue dlt_kpi_init(int argc, char **argv, DltKpiConfig *config) DltReturnValue ret; - if(config == NULL) - { + if (config == NULL) { fprintf(stderr, "%s: Invalid Parameter!", __func__); return DLT_RETURN_WRONG_PARAMETER; } - if((ret = dlt_kpi_read_command_line(&options, argc, argv)) < DLT_RETURN_OK) - { + if ((ret = dlt_kpi_read_command_line(&options, argc, argv)) < DLT_RETURN_OK) { fprintf(stderr, "Failed to read command line!"); return ret; } - if((ret = dlt_kpi_read_configuration_file(config, options.configurationFileName)) < DLT_RETURN_OK) - { + if ((ret = dlt_kpi_read_configuration_file(config, options.configurationFileName)) < DLT_RETURN_OK) { fprintf(stderr, "Failed to read configuration file!"); return ret; } |