From 5ada04f17aee2f11a82f24d6b527680dbc58df3c Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Wed, 1 May 2024 14:18:06 +0200 Subject: Reformatted alias_substitute() --- FICS/command.c | 100 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 56 insertions(+), 44 deletions(-) (limited to 'FICS/command.c') diff --git a/FICS/command.c b/FICS/command.c index a8a0390..3c99d20 100644 --- a/FICS/command.c +++ b/FICS/command.c @@ -134,51 +134,63 @@ alias_count(alias_type *alias_list) return i; } -/* Puts alias substitution into alias_string */ -PRIVATE void alias_substitute(alias_type *alias_list, int num_alias, - char *com_str, char outalias[]) +/* + * Puts alias substitution into alias_string + */ +PRIVATE void +alias_substitute(alias_type *alias_list, int num_alias, char *com_str, + char outalias[]) { - char *s = com_str; - char name[MAX_COM_LENGTH]; - char *t = name; - int i = 0; - char *atpos, *aliasval; - - /* Get first word of command, terminated by whitespace or by containing - punctuation */ - while (*s && !iswhitespace(*s)) { - if (i++ >= MAX_COM_LENGTH) { - strcpy(outalias, com_str); - return; - } - if (ispunct(*t++ = *s++)) - break; - } - *t = '\0'; - if (*s && iswhitespace(*s)) - s++; - - i = alias_lookup(name, alias_list, num_alias); - if (i < 0) { - strcpy(outalias, com_str); - return; - } - aliasval = alias_list[i].alias; - - /* See if alias contains an @ */ - atpos = strchr(aliasval, '@'); - if (atpos != NULL) { - strncpy(outalias, aliasval, atpos - aliasval); - outalias[atpos - aliasval] = '\0'; - strcat(outalias, s); - strcat(outalias, atpos + 1); - } else { - strcpy(outalias, aliasval); - if (*s) { - strcat(outalias, " "); - strcat(outalias, s); - } - } + char *atpos, *aliasval; + char *s = com_str; + char *t = name; + char name[MAX_COM_LENGTH] = { '\0' }; + int i = 0; + + /* + * Get first word of command, terminated by whitespace or by + * containing punctuation. + */ + while (*s && !iswhitespace(*s)) { + if (i++ >= MAX_COM_LENGTH) { + strcpy(outalias, com_str); + return; + } + + if (ispunct(*t++ = *s++)) + break; + } + + *t = '\0'; + + if (*s && iswhitespace(*s)) + s++; + + i = alias_lookup(name, alias_list, num_alias); + + if (i < 0) { + strcpy(outalias, com_str); + return; + } + + aliasval = alias_list[i].alias; + + // See if alias contains an @ + atpos = strchr(aliasval, '@'); + + if (atpos != NULL) { + strncpy(outalias, aliasval, atpos - aliasval); + outalias[atpos - aliasval] = '\0'; + strcat(outalias, s); + strcat(outalias, atpos + 1); + } else { + strcpy(outalias, aliasval); + + if (*s) { + strcat(outalias, " "); + strcat(outalias, s); + } + } } /* -- cgit v1.2.3