diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-05-01 14:18:06 +0200 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-05-01 14:18:06 +0200 |
commit | 5ada04f17aee2f11a82f24d6b527680dbc58df3c (patch) | |
tree | 2ef06ca61298653eb4cdc740e2c18c6f243bd4c0 | |
parent | aa44835c3f8330b4ce2f3b120d601c687a6f3115 (diff) |
Reformatted alias_substitute()
-rw-r--r-- | FICS/command.c | 100 |
1 files changed, 56 insertions, 44 deletions
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); + } + } } /* |