--- mstools/samples/rpc/dict/play.c 2018/08/09 18:20:01 1.1 +++ mstools/samples/rpc/dict/play.c 2018/08/09 18:24:21 1.1.1.4 @@ -2,31 +2,26 @@ /** **/ /** Microsoft RPC Examples **/ /** Dictionary Application **/ -/** Copyright(c) Microsoft Corp. 1991 **/ +/** Copyright(c) Microsoft Corp. 1992 **/ /** **/ /*************************************************************/ /* ************************************************************************* - * Local dictionary :play" example * * * - * Created: Dov Harel 7/1988 * - * Simplified / unified interface to dict Dov Harel 12/1990 * - * Revived to fit remote play (replay) Dov Harel 5/1/1991 * + * Local dictionary :play" example * * * * Description: * * This file contains a simple interactive loop of calls to the * * dictionary. The interface is identical to the remote dictionary * * program described in the readme file. * + * * ************************************************************************* */ -#include -#include #include -#include +#include #include -#include #include "dict0.h" #include "play.h" @@ -34,6 +29,7 @@ #define TAB_STOPS 3 + void Usage() { printf("Usage : play \n\n"); @@ -47,17 +43,17 @@ void Usage() void Usage_Msg() { - printf("Usage: \nType a single character, followed by an optional key as follows:\n\n"); - printf("i :: Insert into dictionary\n"); - printf("d :: Delete from dictionary\n"); - printf("f :: Find in dictionary\n"); - printf("n :: Next of local current item in dictionary\n"); - printf("p :: Previous of local current item in dictionary\n"); - printf("h :: Head (first item) of dictionary\n"); - printf("t :: Tail (last item) of dictionary\n"); - printf("? :: Print this message\n"); - printf("q :: Quit\n\n"); - printf(" is "); + printf("\nUsage: \nType a single character, followed by an optional key as follows:\n\n"); + printf(" i :: Insert into dictionary\n"); + printf(" d :: Delete from dictionary\n"); + printf(" f :: Find in dictionary\n"); + printf(" n :: Next of local current item in dictionary\n"); + printf(" p :: Previous of local current item in dictionary\n"); + printf(" h :: Head (first item) of dictionary\n"); + printf(" t :: Tail (last item) of dictionary\n"); + printf(" ? :: Print this message\n"); + printf(" q :: Quit\n\n"); + printf("where is \n"); } /*************************************************************************/ @@ -77,9 +73,6 @@ Usage_Msg() void TestLoop( Dictionary * pdict ) { -// reconstructed from the test loop in client.c... -// local variables need substantial clean up... - char currName[80]; char name[80]; char op = 0; @@ -88,24 +81,18 @@ TestLoop( Dictionary * pdict ) Record r, currRecord; Record *pcurrRecord = &currRecord; Record *pr = &r; - Record * pNullRecord = NULL; Dict_Status status; short i; - // Dictionary * pdict = *pvd; - pcurrRecord->name = currName; pr->name = name; - // VDict_Curr_Item(*pvd, &pcurrRecord); - - // Dict_Print(pdict, TAB_STOPS); Usage_Msg(); while ( op != 'q' ) { - printf("\nnext op (i d x f n N p P h t ? q): "); + printf("\nnext op (i d x f n p h t ? q): "); gets(buffer); op = buffer[0]; @@ -117,96 +104,91 @@ TestLoop( Dictionary * pdict ) case 'h': // get Head of list (first record); - status = Dict_Next( pdict, NULL ); - ItemCopy( DICT_CURR_ITEM(pdict), pcurrRecord); - ItemCopy( DICT_CURR_ITEM(pdict), pr); + status = Dict_Next(pdict, NULL); + ItemCopy(DICT_CURR_ITEM(pdict), pcurrRecord); + ItemCopy(DICT_CURR_ITEM(pdict), pr); break; case 't': // get Tail of list (last record) - status = Dict_Prev( pdict, NULL ); - ItemCopy( DICT_CURR_ITEM(pdict), pcurrRecord); - ItemCopy( DICT_CURR_ITEM(pdict), pr); - break; - - case 'f': - // Find - - status = Dict_Find(pdict, pr); + status = Dict_Prev(pdict, NULL); + ItemCopy(DICT_CURR_ITEM(pdict), pcurrRecord); + ItemCopy(DICT_CURR_ITEM(pdict), pr); break; case 'n': // get Next record - status = Dict_Next( pdict, pcurrRecord ); - ItemCopy( DICT_CURR_ITEM(pdict), pcurrRecord); + status = Dict_Next(pdict, pcurrRecord); + ItemCopy(DICT_CURR_ITEM(pdict), pcurrRecord); break; case 'p': // get Previous record - status = Dict_Prev( pdict, pcurrRecord ); - ItemCopy( DICT_CURR_ITEM(pdict), pcurrRecord); + status = Dict_Prev(pdict, pcurrRecord); + ItemCopy(DICT_CURR_ITEM(pdict), pcurrRecord); break; case 'N': // get Next record - status = Dict_Next( pdict, pr ); - ItemCopy( DICT_CURR_ITEM(pdict), pr); + status = Dict_Next(pdict, pr); + ItemCopy(DICT_CURR_ITEM(pdict), pr); break; case 'P': // get Previous record - status = Dict_Prev( pdict, pr ); - ItemCopy( DICT_CURR_ITEM(pdict), pr); + status = Dict_Prev(pdict, pr); + ItemCopy(DICT_CURR_ITEM(pdict), pr); break; case 'r': - ItemCopy( DICT_CURR_ITEM(pdict), pcurrRecord); + ItemCopy(DICT_CURR_ITEM(pdict), pcurrRecord); break; case '+': // get Next record - status = Dict_Next( pdict, pr ); + status = Dict_Next(pdict, pr); break; case '-': // get Previous record - // break; - status = Dict_Prev( pdict, pr ); + status = Dict_Prev(pdict, pr); + break; + + case 'f': + // Find + + status = Dict_Find(pdict, pr); break; case 'i': // Insert - status = Dict_Insert( - pdict, - makeRecord(pr->key, pr->name) - ); + status = Dict_Insert(pdict, + makeRecord(pr->key, pr->name) ); break; case 'I': // Insert (,) for all num': 3 < num' < num - for (i=3; i < pr->key; i++) { - status = Dict_Insert( - pdict, - makeRecord(i, pr->name) - ); - } + for (i = 3; i < pr->key; i++) { + status = Dict_Insert(pdict, + makeRecord(i, pr->name) ); + } break; case 'd': // Delete if (pdict != NULL) { - status = Dict_Delete(pdict, (void **)&pr); + status = Dict_Delete(pdict, (void **)&pr); freeRecord(pr); pr = &r; } @@ -217,7 +199,7 @@ TestLoop( Dictionary * pdict ) if ((pdict != NULL) && (pdict->root != NULL)) { pr = DICT_CURR_ITEM(pdict); - status = Dict_Delete(pdict, (void **) &pr); + status = Dict_Delete(pdict, (void **) &pr); freeRecord(pr); pr = &r; } @@ -226,15 +208,6 @@ TestLoop( Dictionary * pdict ) case 'X': // Empty the whole dictionary - /* - while (pdict->root != NULL) { - pr = DICT_CURR_ITEM(pdict); - status = Dict_Delete(pdict, (void **)&pr); - freeRecord(pr); - pr = &r; - } - */ - RecordTreeNodeFree((RecordTreeNode*)pdict->root); pdict->root = NULL; pr = &r; @@ -244,12 +217,14 @@ TestLoop( Dictionary * pdict ) Usage_Msg(); break; } - if (op != '?' && op != 'q') Dict_Print(pdict, TAB_STOPS); + + if (op != '?' && op != 'q') + Dict_Print(pdict, TAB_STOPS); } } Dict_Status -Dict_New_Dict( OUT Dictionary ** ppdict ) +Dict_New_Dict(OUT Dictionary ** ppdict) { static Dictionary * pdict; @@ -265,23 +240,19 @@ Init_dict(Dictionary * dp) { Record* rp; - printf ("in Init_dict\n"); - -/* -*/ - rp = makeRecord(0, "jack_smith"); Dict_Insert(dp, rp); - rp = makeRecord(0, "john_doe"); Dict_Insert(dp, rp); - rp = makeRecord(1, "jean_doe"); Dict_Insert(dp, rp); - rp = makeRecord(0, "joana_smith"); Dict_Insert(dp, rp); - rp = makeRecord(1, "michael_jones"); Dict_Insert(dp, rp); - rp = makeRecord(0, "mike_jacobs"); Dict_Insert(dp, rp); - rp = makeRecord(2, "bill_jackson"); Dict_Insert(dp, rp); - rp = makeRecord(0, "jane_doe"); Dict_Insert(dp, rp); - rp = makeRecord(0, "dianne_jackson"); Dict_Insert(dp, rp); - rp = makeRecord(1, "james_doe"); Dict_Insert(dp, rp); - rp = makeRecord(1, "steve_johnson"); Dict_Insert(dp, rp); - rp = makeRecord(2, "debbie_jones"); Dict_Insert(dp, rp); - rp = makeRecord(0, "jacob_jacobson"); Dict_Insert(dp, rp); + rp = makeRecord((short)0, "jack_smith"); Dict_Insert(dp, rp); + rp = makeRecord((short)0, "john_doe"); Dict_Insert(dp, rp); + rp = makeRecord((short)1, "jean_doe"); Dict_Insert(dp, rp); + rp = makeRecord((short)0, "joana_smith"); Dict_Insert(dp, rp); + rp = makeRecord((short)1, "michael_jones"); Dict_Insert(dp, rp); + rp = makeRecord((short)0, "mike_jacobs"); Dict_Insert(dp, rp); + rp = makeRecord((short)2, "bill_jackson"); Dict_Insert(dp, rp); + rp = makeRecord((short)0, "jane_doe"); Dict_Insert(dp, rp); + rp = makeRecord((short)0, "dianne_jackson"); Dict_Insert(dp, rp); + rp = makeRecord((short)1, "james_doe"); Dict_Insert(dp, rp); + rp = makeRecord((short)1, "steve_johnson"); Dict_Insert(dp, rp); + rp = makeRecord((short)2, "debbie_jones"); Dict_Insert(dp, rp); + rp = makeRecord((short)0, "jacob_jacobson"); Dict_Insert(dp, rp); Dict_Print(dp, TAB_STOPS); } @@ -296,14 +267,14 @@ main_dict () Dictionary * pdict; Dictionary ** ppdict = &pdict; - printf ("getting a new dict\n"); - Dict_New_Dict( ppdict ); - printf ("gotten a new dict in main_dict\n"); + printf("getting a new dict\n"); + Dict_New_Dict(ppdict); + printf("gotten a new dict in main_dict\n"); TestLoop(pdict); } -void -main(void) +void _CRTAPI1 +main(int argc, char *argv[]) { - main_dict (); + main_dict(); }