--- mstools/samples/rpc/dict/play.c 2018/08/09 18:20:57 1.1.1.2 +++ mstools/samples/rpc/dict/play.c 2018/08/09 18:24:21 1.1.1.4 @@ -8,44 +8,27 @@ /* ************************************************************************* - * 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. * + * * ************************************************************************* */ -#define INCL_DOS - -#include -#include #include -#include +#include #include -#ifdef NTENV -#include -// #define printf DbgPrint -#endif // NTENV - -// #include -// #include -// #include -// #include - #include "dict0.h" #include "play.h" #include "util0.h" #define TAB_STOPS 3 -// handle_t dict_bhandle; void Usage() { @@ -90,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; @@ -100,22 +80,14 @@ TestLoop( Dictionary * pdict ) Record r, currRecord; Record *pcurrRecord = &currRecord; - Record * pnew; Record *pr = &r; - Record * pNullRecord = NULL; Dict_Status status; - void * pitem; 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' ) { @@ -132,89 +104,84 @@ 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': @@ -241,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; @@ -259,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; @@ -307,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 +void _CRTAPI1 main(int argc, char *argv[]) { - main_dict (); + main_dict(); }