/* argv.c Test driver for Keyword Parameter Library Copyright 2004 Eric L. Michelsen. All rights reserved. This file contains the library for processing keyword cmd line parameters Author: Eric L. Michelsen Design Doc: Sadly, none. Date Created: 9/21/04 ============================================================================*/ // ---------------- Open Issues (do not remove) --------------- // ---------------- System Includes (do not remove) --------------- #include // printf() #include // strcpy() // ---------------- Local Includes (do not remove) --------------- #include "comtypes.h" #include "gi_keyparm.h" // ---------------- Constants (do not remove) --------------- // ---------------- Structures/Types (do not remove) --------------- // ---------------- Public Variables (do not remove) --------------- // Define these sparingly. // ---------------- Private Variables (do not remove) --------------- PRIVATE int32 doodle = 1; PRIVATE int16 foo = 2; PRIVATE double bar = 3; PRIVATE char string[4] = "str"; PRIVATE keyentry klist[] = { {"doodle", KP_INT, &doodle, sizeof(doodle), "doodle comment"}, {"foo", KP_INT, &foo, sizeof(foo), "foo comment"}, {"bar", KP_FLOAT, &bar, sizeof(bar), "bar comment"}, {"string", KP_STRING, string, sizeof(string), "string comment"}, {"", KP_END, 0, 0, ""} // end of list }; // ---------------- Private Prototypes/Macros (do not remove) ------------- // ---------------------------------------------------------------------------- // Good command line test case: 1 2 string=abc 3 doodle=7 bar=9 foo=8 4 5 6 int main(int argc, char* argv[]) { int i; char str[80]="x=4 bar=3.14 string='mary had a little lamb'"; const keyentry *found; char *sptr, *endptr; double x; printf("keyword_parameters()\n"); for(i = 0; i < argc; i++) printf("argv[%d]=\"%s\"\n", i, argv[i]); keyword_fprint(stdout, klist, true); // test display keyword_fprint(stdout, klist, false); // both kinds i = keyword_parameters(klist, &argc, argv); printf("Recognized %d\n", i); keyword_fprint(stdout, klist, false); for(i = 0; i < argc; i++) printf("argv[%d]=\"%s\"\n", i, argv[i]); printf("\nkeyword_scan()\n"); keyword_scan(klist, str); keyword_fprint(stdout, klist, false); printf("str='%s'\n", str); printf("\nkeyword_convert1()\n"); strcpy(str, "dood=5 foo=4"); keyword_convert1(klist, str, &found, &sptr, &endptr); printf("'%s' '%s' '%s' '%s'\n", str, found->name, sptr, endptr); // while(1) scanf("%s %lf", str, &x), printf(str, x), printf("\n"); return 0; }