diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-09-15 13:18:17 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-15 13:18:17 +0200 |
| commit | 8ef825d85fb4d09c32ca44c545d6eb8d995ddea4 (patch) | |
| tree | 5ab7b18797dfd5849dec7827c87ca3bb5fcb0993 /lib/extra_opts.c | |
| parent | a3cf9041af810770daf5d9b83f1906fa9bb0dd11 (diff) | |
| parent | 204cf956f0b3db90d079321ee957b3860da7e33f (diff) | |
| download | monitoring-plugins-8ef825d85fb4d09c32ca44c545d6eb8d995ddea4.tar.gz | |
Merge pull request #2149 from RincewindsHat/clang-format
Clang format
Diffstat (limited to 'lib/extra_opts.c')
| -rw-r--r-- | lib/extra_opts.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/extra_opts.c b/lib/extra_opts.c index 88787336..857b34b4 100644 --- a/lib/extra_opts.c +++ b/lib/extra_opts.c | |||
| @@ -27,12 +27,13 @@ | |||
| 27 | 27 | ||
| 28 | /* FIXME: copied from utils.h; we should move a bunch of libs! */ | 28 | /* FIXME: copied from utils.h; we should move a bunch of libs! */ |
| 29 | bool is_option2(char *str) { | 29 | bool is_option2(char *str) { |
| 30 | if (!str) | 30 | if (!str) { |
| 31 | return false; | 31 | return false; |
| 32 | else if (strspn(str, "-") == 1 || strspn(str, "-") == 2) | 32 | } else if (strspn(str, "-") == 1 || strspn(str, "-") == 2) { |
| 33 | return true; | 33 | return true; |
| 34 | else | 34 | } else { |
| 35 | return false; | 35 | return false; |
| 36 | } | ||
| 36 | } | 37 | } |
| 37 | 38 | ||
| 38 | /* this is the externally visible function used by plugins */ | 39 | /* this is the externally visible function used by plugins */ |
| @@ -56,8 +57,9 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) { | |||
| 56 | /* It is a single argument with value */ | 57 | /* It is a single argument with value */ |
| 57 | argptr = argv[i] + 13; | 58 | argptr = argv[i] + 13; |
| 58 | /* Delete the extra opts argument */ | 59 | /* Delete the extra opts argument */ |
| 59 | for (j = i; j < *argc; j++) | 60 | for (j = i; j < *argc; j++) { |
| 60 | argv[j] = argv[j + 1]; | 61 | argv[j] = argv[j + 1]; |
| 62 | } | ||
| 61 | i--; | 63 | i--; |
| 62 | *argc -= 1; | 64 | *argc -= 1; |
| 63 | } else if (strcmp(argv[i], "--extra-opts") == 0) { | 65 | } else if (strcmp(argv[i], "--extra-opts") == 0) { |
| @@ -65,8 +67,9 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) { | |||
| 65 | /* It is a argument with separate value */ | 67 | /* It is a argument with separate value */ |
| 66 | argptr = argv[i + 1]; | 68 | argptr = argv[i + 1]; |
| 67 | /* Delete the extra-opts argument/value */ | 69 | /* Delete the extra-opts argument/value */ |
| 68 | for (j = i; j < *argc - 1; j++) | 70 | for (j = i; j < *argc - 1; j++) { |
| 69 | argv[j] = argv[j + 2]; | 71 | argv[j] = argv[j + 2]; |
| 72 | } | ||
| 70 | i -= 2; | 73 | i -= 2; |
| 71 | *argc -= 2; | 74 | *argc -= 2; |
| 72 | ea_num--; | 75 | ea_num--; |
| @@ -74,8 +77,9 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) { | |||
| 74 | /* It has no value */ | 77 | /* It has no value */ |
| 75 | optfound = 1; | 78 | optfound = 1; |
| 76 | /* Delete the extra opts argument */ | 79 | /* Delete the extra opts argument */ |
| 77 | for (j = i; j < *argc; j++) | 80 | for (j = i; j < *argc; j++) { |
| 78 | argv[j] = argv[j + 1]; | 81 | argv[j] = argv[j + 1]; |
| 82 | } | ||
| 79 | i--; | 83 | i--; |
| 80 | *argc -= 1; | 84 | *argc -= 1; |
| 81 | } | 85 | } |
| @@ -94,16 +98,18 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) { | |||
| 94 | /* append the list to extra_args */ | 98 | /* append the list to extra_args */ |
| 95 | if (extra_args == NULL) { | 99 | if (extra_args == NULL) { |
| 96 | extra_args = ea1; | 100 | extra_args = ea1; |
| 97 | while ((ea1 = ea1->next)) | 101 | while ((ea1 = ea1->next)) { |
| 98 | ea_num++; | 102 | ea_num++; |
| 103 | } | ||
| 99 | } else { | 104 | } else { |
| 100 | ea_tmp = extra_args; | 105 | ea_tmp = extra_args; |
| 101 | while (ea_tmp->next) { | 106 | while (ea_tmp->next) { |
| 102 | ea_tmp = ea_tmp->next; | 107 | ea_tmp = ea_tmp->next; |
| 103 | } | 108 | } |
| 104 | ea_tmp->next = ea1; | 109 | ea_tmp->next = ea1; |
| 105 | while ((ea1 = ea1->next)) | 110 | while ((ea1 = ea1->next)) { |
| 106 | ea_num++; | 111 | ea_num++; |
| 112 | } | ||
| 107 | } | 113 | } |
| 108 | ea1 = ea_tmp = NULL; | 114 | ea1 = ea_tmp = NULL; |
| 109 | } | 115 | } |
| @@ -116,8 +122,9 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) { | |||
| 116 | 122 | ||
| 117 | /* done processing arguments. now create a new argv array... */ | 123 | /* done processing arguments. now create a new argv array... */ |
| 118 | argv_new = (char **)malloc((ea_num + 1) * sizeof(char **)); | 124 | argv_new = (char **)malloc((ea_num + 1) * sizeof(char **)); |
| 119 | if (argv_new == NULL) | 125 | if (argv_new == NULL) { |
| 120 | die(STATE_UNKNOWN, _("malloc() failed!\n")); | 126 | die(STATE_UNKNOWN, _("malloc() failed!\n")); |
| 127 | } | ||
| 121 | 128 | ||
| 122 | /* starting with program name */ | 129 | /* starting with program name */ |
| 123 | argv_new[0] = argv[0]; | 130 | argv_new[0] = argv[0]; |
| @@ -130,8 +137,9 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) { | |||
| 130 | free(ea1); | 137 | free(ea1); |
| 131 | } | 138 | } |
| 132 | /* finally the rest of the argv array */ | 139 | /* finally the rest of the argv array */ |
| 133 | for (i = 1; i < *argc; i++) | 140 | for (i = 1; i < *argc; i++) { |
| 134 | argv_new[argc_new++] = argv[i]; | 141 | argv_new[argc_new++] = argv[i]; |
| 142 | } | ||
| 135 | *argc = argc_new; | 143 | *argc = argc_new; |
| 136 | /* and terminate. */ | 144 | /* and terminate. */ |
| 137 | argv_new[argc_new] = NULL; | 145 | argv_new[argc_new] = NULL; |
