aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/command.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-05-01 14:08:07 +0200
committerMarkus Uhlin <markus@nifty-networks.net>2024-05-01 14:08:07 +0200
commit17ab1c55b0a1dc8f3e951cc8d8967673e659467a (patch)
tree3f2afab58d1e43f9319e9926488ca8e8629f513f /FICS/command.c
parent8584cc27893a029f18fac35d635d0596e2c13107 (diff)
Reformatted get_parameters()
Diffstat (limited to 'FICS/command.c')
-rw-r--r--FICS/command.c239
1 files changed, 136 insertions, 103 deletions
diff --git a/FICS/command.c b/FICS/command.c
index 5d0c4cc..e0d65da 100644
--- a/FICS/command.c
+++ b/FICS/command.c
@@ -208,113 +208,146 @@ PRIVATE int match_command(char *comm, int p)
return -COM_FAILED;
}
-/* Gets the parameters for this command */
-PRIVATE int get_parameters(int command, char *parameters, param_list params)
+/*
+ * Gets the parameters for this command
+ */
+PRIVATE int
+get_parameters(int command, char *parameters, param_list params)
{
- int i, parlen;
- int paramLower;
- char c;
- static char punc[2];
-
- punc[1] = '\0'; /* Holds punc parameters */
- for (i = 0; i < MAXNUMPARAMS; i++)
- (params)[i].type = TYPE_NULL; /* Set all parameters to NULL */
- parlen = strlen(command_list[command].param_string);
- for (i = 0; i < parlen; i++) {
- c = command_list[command].param_string[i];
- if (isupper(c)) {
- paramLower = 0;
- c = tolower(c);
- } else {
- paramLower = 1;
- }
- switch (c) {
- case 'w':
- case 'o': /* word or optional word */
- parameters = eatwhite(parameters);
- if (!*parameters)
- return (c == 'o' ? COM_OK : COM_BADPARAMETERS);
- (params)[i].val.word = parameters;
- (params)[i].type = TYPE_WORD;
- if (ispunct(*parameters)) {
- punc[0] = *parameters;
- (params)[i].val.word = punc;
- parameters++;
- if (*parameters && iswhitespace(*parameters))
- parameters++;
- } else {
- parameters = eatword(parameters);
- if (*parameters != '\0') {
- *parameters = '\0';
- parameters++;
- }
- }
- if (paramLower)
- stolower((params)[i].val.word);
- break;
+ char c;
+ int i, parlen;
+ int paramLower;
+ static char punc[2];
- case 'd':
- case 'p': /* optional or required integer */
- parameters = eatwhite(parameters);
- if (!*parameters)
- return (c == 'p' ? COM_OK : COM_BADPARAMETERS);
- if (sscanf(parameters, "%d", &(params)[i].val.integer) != 1)
- return COM_BADPARAMETERS;
- (params)[i].type = TYPE_INT;
- parameters = eatword(parameters);
- if (*parameters != '\0') {
- *parameters = '\0';
- parameters++;
- }
- break;
+ punc[1] = '\0'; // Holds punc parameters
- case 'i':
- case 'n': /* optional or required word or integer */
- parameters = eatwhite(parameters);
- if (!*parameters)
- return (c == 'n' ? COM_OK : COM_BADPARAMETERS);
- if (sscanf(parameters, "%d", &(params)[i].val.integer) != 1) {
- (params)[i].val.word = parameters;
- (params)[i].type = TYPE_WORD;
- } else {
- (params)[i].type = TYPE_INT;
- }
- if (ispunct(*parameters)) {
- punc[0] = *parameters;
- (params)[i].val.word = punc;
- (params)[i].type = TYPE_WORD;
- parameters++;
- if (*parameters && iswhitespace(*parameters))
- parameters++;
- } else {
- parameters = eatword(parameters);
- if (*parameters != '\0') {
- *parameters = '\0';
- parameters++;
- }
- }
- if ((params)[i].type == TYPE_WORD)
- if (paramLower)
- stolower((params)[i].val.word);
- break;
+ for (i = 0; i < MAXNUMPARAMS; i++)
+ (params)[i].type = TYPE_NULL; // Set all parameters to NULL
- case 's':
- case 't': /* optional or required string to end */
- if (!*parameters)
- return (c == 't' ? COM_OK : COM_BADPARAMETERS);
- (params)[i].val.string = parameters;
- (params)[i].type = TYPE_STRING;
- while (*parameters)
- parameters = nextword(parameters);
- if (paramLower)
- stolower((params)[i].val.string);
- break;
- }
- }
- if (*parameters)
- return COM_BADPARAMETERS;
- else
- return COM_OK;
+ parlen = strlen(command_list[command].param_string);
+
+ for (i = 0; i < parlen; i++) {
+ c = command_list[command].param_string[i];
+
+ if (isupper(c)) {
+ paramLower = 0;
+ c = tolower(c);
+ } else {
+ paramLower = 1;
+ }
+
+ switch (c) {
+ case 'w':
+ case 'o': // word or optional word
+ parameters = eatwhite(parameters);
+
+ if (!*parameters)
+ return (c == 'o' ? COM_OK : COM_BADPARAMETERS);
+
+ (params)[i].val.word = parameters;
+ (params)[i].type = TYPE_WORD;
+
+ if (ispunct(*parameters)) {
+ punc[0] = *parameters;
+
+ (params)[i].val.word = punc;
+
+ parameters++;
+
+ if (*parameters && iswhitespace(*parameters))
+ parameters++;
+ } else {
+ parameters = eatword(parameters);
+
+ if (*parameters != '\0') {
+ *parameters = '\0';
+ parameters++;
+ }
+ }
+
+ if (paramLower)
+ stolower((params)[i].val.word);
+
+ break;
+ case 'd':
+ case 'p': // optional or required integer
+ parameters = eatwhite(parameters);
+
+ if (!*parameters)
+ return (c == 'p' ? COM_OK : COM_BADPARAMETERS);
+
+ if (sscanf(parameters, "%d", &(params)[i].val.integer)
+ != 1)
+ return COM_BADPARAMETERS;
+
+ (params)[i].type = TYPE_INT;
+
+ parameters = eatword(parameters);
+
+ if (*parameters != '\0') {
+ *parameters = '\0';
+ parameters++;
+ }
+
+ break;
+ case 'i':
+ case 'n': // optional or required word or integer
+ parameters = eatwhite(parameters);
+
+ if (!*parameters)
+ return (c == 'n' ? COM_OK : COM_BADPARAMETERS);
+
+ if (sscanf(parameters, "%d", &(params)[i].val.integer)
+ != 1) {
+ (params)[i].val.word = parameters;
+ (params)[i].type = TYPE_WORD;
+ } else {
+ (params)[i].type = TYPE_INT;
+ }
+
+ if (ispunct(*parameters)) {
+ punc[0] = *parameters;
+
+ (params)[i].val.word = punc;
+ (params)[i].type = TYPE_WORD;
+
+ parameters++;
+
+ if (*parameters && iswhitespace(*parameters))
+ parameters++;
+ } else {
+ parameters = eatword(parameters);
+
+ if (*parameters != '\0') {
+ *parameters = '\0';
+ parameters++;
+ }
+ }
+
+ if ((params)[i].type == TYPE_WORD)
+ if (paramLower)
+ stolower((params)[i].val.word);
+ break;
+ case 's':
+ case 't': // optional or required string to end
+ if (!*parameters)
+ return (c == 't' ? COM_OK : COM_BADPARAMETERS);
+
+ (params)[i].val.string = parameters;
+ (params)[i].type = TYPE_STRING;
+
+ while (*parameters)
+ parameters = nextword(parameters);
+ if (paramLower)
+ stolower((params)[i].val.string);
+ break;
+ } /* switch */
+ } /* for */
+
+ if (*parameters)
+ return COM_BADPARAMETERS;
+ else
+ return COM_OK;
}
PRIVATE void