--- mstools/samples/rpc/dict/replay.c 2018/08/09 18:20:01 1.1 +++ mstools/samples/rpc/dict/replay.c 2018/08/09 18:24:21 1.1.1.3 @@ -2,36 +2,22 @@ /** **/ /** Microsoft RPC Examples **/ /** Dictionary Application **/ -/** Copyright(c) Microsoft Corp. 1991 **/ +/** Copyright(c) Microsoft Corp. 1992 **/ /** **/ /*************************************************************/ /*************************************************************************/ -/*** Example dictionary using splay trees: ***/ -/*** Created: 12/88 - Dov Harel ***/ -/*** ***/ -/*** Modified: ***/ /*** ***/ -/*** Dov Harel - 11/10/90, Use "strong types" for remoting ***/ -/*** Dov Harel - 11/14/90, Changed interface to demonstrate local vs. ***/ -/*** remote iterators. Modified allocation and ***/ -/*** deallocation for remoting the dictionary. ***/ -/*** Dov Harel - 5/91, Made it work again. Changed iterators, ***/ -/*** duplicate nodes and trees. Added state, ***/ -/*** ref counts, and a -s switch for optional ***/ -/*** sharing of dictionaries. ***/ -/*** (not yet serialized!) ***/ +/*** Example dictionary using splay trees: ***/ /*** ***/ /*************************************************************************/ -#include -#include #include +#include #include -#include "rpc.h" +#include "replay.h" // header file generated by MIDL compiler #include "dict0.h" -#include "replay.h" #include "util0.h" #define TAB_STOPS 3 @@ -69,8 +55,7 @@ typedef enum { DICT_LAST_ITEM, DICT_EMPTY_DICTIONARY, DICT_NULL_ITEM -} -VDict_Status; +} VDict_Status; typedef struct _DictState { short ref_count; // for shared dictionaries @@ -84,9 +69,9 @@ typedef struct _DictState { #define RDICT_CURR_RECORD(dict) (((DictState*)dict->state)->curr_record) -#define RDICT_REF_COUNT(dict) (((DictState*)dict->state)->ref_count) +#define RDICT_REF_COUNT(dict) (((DictState*)dict->state)->ref_count) -#define RDICT_STATE(dict) (((RDict*)dict)->state) +#define RDICT_STATE(dict) (((RDict*)dict)->state) static int active_dictionary = 0; @@ -127,24 +112,24 @@ static int active_dictionary = 0; /*** context rundown routine ***/ /*************************************************************************/ -void VDict_rundown (VDict v_dict) +void __RPC_USER VDict_rundown (VDict v_dict) { Dictionary * pdict = (Dictionary*) v_dict; short count = --RDICT_REF_COUNT(pdict); printf("# of remaining users of context: %d\n\n", - RDICT_REF_COUNT(pdict) ); + RDICT_REF_COUNT(pdict) ); - if ( RDICT_REF_COUNT(pdict) <= 0) { + if (RDICT_REF_COUNT(pdict) <= 0) { printf("CLOSING CONTEXT\n\n"); // free the splay tree RDict_Free_Dict(v_dict); // free the dictionary object - free_state( (DictState*) pdict->state ); - MIDL_user_free( v_dict ); - if ( count == 0) + free_state((DictState*) pdict->state); + MIDL_user_free(v_dict); + if (count == 0) active_dictionary = 0; } } @@ -177,12 +162,12 @@ VDict_New( static Dictionary * pdict; if (!active_dictionary || !shared_dict) { - /* server side dictionary initialization */ + // server side dictionary initialization pdict0 = Dict_New(comp, tdSplay, printRecord); + // Initializes RDICT_CURR_RECORD(pdict0) to + // "minus infinity" in the order ((RDict*)pdict0)->state = allocate_state(); - // The above assignment initializes RDICT_CURR_RECORD(pdict0) - // to "minus infinity" in the order Init_dict(pdict0); *v_dict = (VDict)pdict0; @@ -214,7 +199,8 @@ VDict_Find( status = Dict_Find(pdict, *item); if ( (pdict == NULL) || DICT_EMPTY(pdict) ) { - *item = NULL; } + *item = NULL; + } else { *item = DICT_CURR_ITEM(pdict); *item = ItemDuplicate(*item); @@ -234,7 +220,8 @@ VDict_Next( status = Dict_Next(pdict, *item); if ( (pdict == NULL) || DICT_EMPTY(pdict) ) { - *item = NULL; } + *item = NULL; + } else { if (*item == NULL) ItemCopy(DICT_CURR_ITEM(pdict), RDICT_CURR_RECORD(pdict)); @@ -252,12 +239,12 @@ VDict_Prev( // get predecessor of *item, and update *item to point to it { Dictionary * pdict = (Dictionary*) (v_dict); - RDict * prdict = (RDict*)pdict; // debug... Dict_Status status; status = Dict_Prev(pdict, *item); if ( (pdict == NULL) || DICT_EMPTY(pdict) ) { - *item = NULL; } + *item = NULL; + } else { if (*item == NULL) ItemCopy(DICT_CURR_ITEM(pdict), RDICT_CURR_RECORD(pdict)); @@ -276,18 +263,13 @@ VDict_Curr_Next( // and update *item to point to it (global iterator prev) { Dictionary * pdict = (Dictionary*) (v_dict); - RDict * prdict = (RDict*) pdict; // for debug ease... Dict_Status status; if ( (pdict == NULL) || DICT_EMPTY(pdict) ) { status = EMPTY_DICTIONARY; - *item = NULL; } + *item = NULL; + } else { - // old code uses DICT_CURR_ITEM as iterator state - // status = Dict_Next(pdict, DICT_CURR_ITEM(pdict)); - // *item = DICT_CURR_ITEM(pdict); - - // update RDICT_CURR_RECORD(pdict) status = Dict_Next(pdict, RDICT_CURR_RECORD(pdict)); ItemCopy(DICT_CURR_ITEM(pdict), RDICT_CURR_RECORD(pdict)); *item = DICT_CURR_ITEM(pdict); @@ -305,12 +287,12 @@ VDict_Curr_Prev( // and update *item to point to it (global iterator prev) { Dictionary * pdict = (Dictionary*) (v_dict); - RDict * prdict = (RDict*) pdict; // for debug ease... Dict_Status status; if ( (pdict == NULL) || DICT_EMPTY(pdict) ) { status = EMPTY_DICTIONARY; - *item = NULL; } + *item = NULL; + } else { // update RDICT_CURR_RECORD(pdict) status = Dict_Prev(pdict, RDICT_CURR_RECORD(pdict)); @@ -344,9 +326,8 @@ VDict_Delete( Dictionary * pdict = (Dictionary*) (v_dict); Dict_Status status; - status = Dict_Delete(pdict, (void **)item); // (*item) is returned by Dict_Delete! - // *item = ItemDuplicate(*item); - // no need to duplicate *item: deleted items need to be deallocated. + status = Dict_Delete(pdict, (void **)item); + // (*item) is returned by Dict_Delete! return( (VDict_Status)status ); } @@ -361,7 +342,8 @@ VDict_Curr_Item( if ( (pdict == NULL) || DICT_EMPTY(pdict) ) { status = EMPTY_DICTIONARY; - *item = NULL; } + *item = NULL; + } else { status = SUCCESS; *item = DICT_CURR_ITEM(pdict); @@ -381,13 +363,12 @@ VDict_Curr_Delete( if ( (pdict == NULL) || DICT_EMPTY(pdict) ) { status = EMPTY_DICTIONARY; - *item = NULL; } + *item = NULL; + } else { *item = DICT_CURR_ITEM(pdict); - status = Dict_Delete( pdict, (void **)item ); + status = Dict_Delete( pdict, (void **)item ); } - // *item = ItemDuplicate(*item); - // no need to duplicate *item: deleted items need to be deallocated. return( (VDict_Status)status ); } @@ -400,11 +381,12 @@ VDict_Get_Dict( // (In this demo program - for printing on the client side) { Dictionary * pdict = (Dictionary*) (v_dict); - RDict * prdict = (RDict*)pdict; // debug... - if (pdict == NULL) return(DICT_EMPTY_DICTIONARY); + if (pdict == NULL) { + return(DICT_EMPTY_DICTIONARY); + } else { - prinTree (0, 3, pdict->root, printRecord); + prinTree(0, 3, pdict->root, printRecord); *r_dict = RDict_Duplicate((RDict*)pdict); // Duplication is done to avoid freeing the tree by @@ -424,23 +406,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, "steve_johnson"); Dict_Insert(dp, rp); - rp = makeRecord(2, "debbie_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(1, "james_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, "dianne_jackson"); 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, "steve_johnson"); Dict_Insert(dp, rp); + rp = makeRecord((short)2, "debbie_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)1, "james_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, "dianne_jackson"); Dict_Insert(dp, rp); + rp = makeRecord((short)0, "jacob_jacobson"); Dict_Insert(dp, rp); Dict_Print(dp, TAB_STOPS); } @@ -456,7 +434,6 @@ VDict_X_Dict( ) // Empty the dictionary { - // Dictionary * pdict = (Dictionary*) (v_dict); RDict * prdict = (RDict*)v_dict; if (DICT_EMPTY(prdict)) @@ -464,7 +441,7 @@ VDict_X_Dict( RecordTreeNodeFree(prdict->root); prdict->root = NULL; - return(DICT_SUCCESS); + return(DICT_SUCCESS); } VDict_Status @@ -474,18 +451,14 @@ VDict_I_Dict( ) // Insert integers from 3 to a specified upper bound into the tree { - // Dictionary * pdict = (Dictionary*) (v_dict); RDict * prdict = (RDict*)v_dict; Dict_Status status; short i; // Insert (, "") for all num' s.t. 3 < num' < num - for (i=3; i < size; i++) { - status = VDict_Insert( - prdict, - makeRecord(i, "") - ); - } + status = VDict_Insert(prdict, + makeRecord(i, "<")); + } return( (VDict_Status)status ); }