Skip to content

Commit c4d4266

Browse files
committed
readability improvements
1 parent 7e9d11b commit c4d4266

2 files changed

Lines changed: 30 additions & 37 deletions

File tree

client/castApp/src/castinit.c

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ static void addReccasterEnvVarsCallFunc(const iocshArgBuf *args)
201201
}
202202

203203
void addReccasterExcludePattern(caster_t* self, int argc, char **argv) {
204-
size_t i;
205-
int ret = 0;
204+
// size_t i;
206205
argv++; argc--; /* skip function arg */
207206
if (argc < 1) {
208207
errlogSevPrintf(errlogMinor, "At least one argument expected for addReccasterExcludePattern\n");
@@ -221,44 +220,38 @@ void addReccasterExcludePattern(caster_t* self, int argc, char **argv) {
221220
return;
222221
}
223222

224-
for (i = 0; i < argc; i++) {
225-
if (strcmp(argv[i], "") == 0) {
226-
errlogSevPrintf(errlogMinor, "Arg is empty for addReccasterExcludePattern\n");
223+
for (int i = 0; i < argc; i++) {
224+
if (argv[i][0] == '\0') {
225+
errlogSevPrintf(errlogMajor, "Arg is empty for addReccasterExcludePattern\n");
226+
continue;
227227
}
228228
/* check duplicates */
229-
else {
230-
int dup = 0;
231-
ELLNODE *cur = ellFirst(&self->exclude_patterns);
232-
while (cur != NULL) {
233-
string_list_t *temp = (string_list_t *)cur;
234-
if (strcmp(argv[i], temp->item_str) == 0) {
235-
errlogSevPrintf(errlogMinor, "Duplicate pattern %s\n", argv[i]);
236-
dup = 1;
237-
break;
238-
}
239-
cur = ellNext(cur);
240-
}
241-
if (!dup) {
242-
string_list_t *new = malloc(sizeof(string_list_t));
243-
if (new == NULL) {
244-
errlogSevPrintf(errlogMajor, "malloc error for creating linked list node");
245-
ret = 1;
246-
break;
247-
}
248-
new->item_str = strdup(argv[i]);
249-
if (new->item_str == NULL) {
250-
errlogSevPrintf(errlogMinor, "strdup error for copying %s to new->item_str from addReccasterExcludePattern\n", argv[i]);
251-
free(new); /* frees if strdup fails */
252-
ret = 1;
253-
break;
254-
}
255-
ellAdd(&self->exclude_patterns, &new->node);
229+
int dup = 0;
230+
ELLNODE *cur = ellFirst(&self->exclude_patterns);
231+
while (cur != NULL) {
232+
string_list_t *temp = (string_list_t *)cur;
233+
if (strcmp(argv[i], temp->item_str) == 0) {
234+
dup = 1;
235+
break;
256236
}
237+
cur = ellNext(cur);
257238
}
258-
}
259-
260-
if (ret) {
261-
errlogSevPrintf(errlogMajor, "Error in addReccasterExcludePattern - exclude patterns may not be set\n");
239+
if (dup) {
240+
errlogSevPrintf(errlogMinor, "Duplicate pattern %s in addReccasterExcludePattern\n", argv[i]);
241+
continue;
242+
}
243+
string_list_t *new = malloc(sizeof(string_list_t));
244+
if (new == NULL) {
245+
errlogSevPrintf(errlogMajor, "Error in addReccasterExcludePattern - malloc error for creating linked list node");
246+
break;
247+
}
248+
new->item_str = strdup(argv[i]);
249+
if (new->item_str == NULL) {
250+
errlogSevPrintf(errlogMajor, "Error in addReccasterExcludePattern - strdup error for copying %s to new->item_str from addReccasterExcludePattern\n", argv[i]);
251+
free(new); /* frees if strdup fails */
252+
break;
253+
}
254+
ellAdd(&self->exclude_patterns, &new->node);
262255
}
263256
epicsMutexUnlock(self->lock);
264257
}

client/castApp/src/testAddExcludePattern.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static void testAddExcludePatternX(void)
2020
caster.onmsg = &testLog;
2121

2222
int argc;
23-
char *argvlist[6];
23+
char *argvlist[5];
2424
argvlist[0] = "addReccasterExcludePattern";
2525

2626
char *expectedPatterns[] =

0 commit comments

Comments
 (0)