From: John Hodge Date: Wed, 23 Feb 2011 05:34:44 +0000 (+0800) Subject: Added `iteminfo` command to client, fixed docs X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=fa32b1c7ddbe1740122f61d55b997f639e927e62;p=tpg%2Fopendispense2.git Added `iteminfo` command to client, fixed docs --- diff --git a/src/client/main.c b/src/client/main.c index 5e131e8..80b160f 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -220,6 +220,7 @@ int main(int argc, char *argv[]) // List accounts? if( text_argc == 1 ) { Dispense_EnumUsers(sock); + close(sock); return 0; } @@ -281,6 +282,9 @@ int main(int argc, char *argv[]) return -1; Dispense_Give(sock, text_args[1], atoi(text_args[2]), text_args[3]); + + close(sock); + return 0; } // @@ -315,10 +319,10 @@ int main(int argc, char *argv[]) Dispense_AddUser(sock, text_args[2]); } // Update a user - else if( strcmp(text_args[1], "type") == 0 ) + else if( strcmp(text_args[1], "type") == 0 || strcmp(text_args[1], "flags") == 0 ) { if( text_argc != 4 ) { - fprintf(stderr, "Error: `dispense user type` requires two arguments\n"); + fprintf(stderr, "Error: `dispense user flags` requires two arguments\n"); ShowUsage(); exit(1); } @@ -331,11 +335,11 @@ int main(int argc, char *argv[]) ShowUsage(); exit(1); } + close(sock); return 0; } - // Donation! - if( strcmp(text_args[0], "donate") == 0 ) + else if( strcmp(text_args[0], "donate") == 0 ) { // Check argument count if( text_argc != 3 ) { @@ -354,11 +358,40 @@ int main(int argc, char *argv[]) // Do donation Dispense_Donate(sock, atoi(text_args[1]), text_args[2]); - + + close(sock); + + return 0; + } + // Query an item price + else if( strcmp(text_args[0], "iteminfo") == 0 ) + { + regmatch_t matches[3]; + char *type; + int id; + // Check argument count + if( text_argc != 2 ) { + fprintf(stderr, "Error: `dispense iteminfo` requires an argument\n"); + ShowUsage(); + exit(1); + } + // Parse item ID + if( RunRegex(&gUserItemIdentRegex, text_args[1], 3, matches, NULL) != 0 ) { + fprintf(stderr, "Error: Invalid item ID passed (: expected)\n"); + exit(1); + } + type = text_args[1] + matches[1].rm_so; + text_args[1][ matches[1].rm_eo ] = '\0'; + id = atoi( text_args[1] + matches[2].rm_so ); + + sock = OpenConnection(gsDispenseServer, giDispensePort); + if( sock < 0 ) return -1; + Dispense_ItemInfo(sock, type, id); + close(sock); return 0; } + // Item name / pattern else { - // Item name / pattern gsItemPattern = text_args[0]; } @@ -531,12 +564,14 @@ void ShowUsage(void) " == Everyone ==\n" " dispense\n" " Show interactive list\n" - " dispense \n" - " Dispense named item\n" + " dispense ||\n" + " Dispense named item ( matches if it is a unique prefix)\n" " dispense give \"\"\n" " Give money to another user\n" " dispense donate \"\"\n" " Donate to the club\n" + " dispense iteminfo :\n" + " Get the name and price for an item\n" " == Coke members == \n" " dispense acct []\n" " Show user balances\n"