Annotation of mstools/samples/rpc/dict/play.c, revision 1.1.1.3

1.1       root        1: /*************************************************************/
                      2: /**                                                         **/
                      3: /**                 Microsoft RPC Examples                  **/
                      4: /**                 Dictionary Application                  **/
1.1.1.2   root        5: /**             Copyright(c) Microsoft Corp. 1992           **/
1.1       root        6: /**                                                         **/
                      7: /*************************************************************/
                      8: 
                      9: /*
                     10:  *************************************************************************
                     11:  * Local dictionary :play" example                                       *
                     12:  *                                                                       *
                     13:  * Created:                                 Dov Harel       7/1988       *
                     14:  * Simplified / unified interface to dict   Dov Harel      12/1990       *
                     15:  * Revived to fit remote play (replay)      Dov Harel     5/1/1991       *
                     16:  *                                                                       *
                     17:  * Description:                                                          *
                     18:  * This file contains a simple interactive loop of calls to the          *
                     19:  * dictionary.  The interface is identical to the remote dictionary      *
                     20:  * program described in the readme file.                                 *
                     21:  *************************************************************************
                     22: */
                     23: 
1.1.1.2   root       24: #define INCL_DOS
                     25: 
1.1       root       26: #include <stdio.h>
                     27: #include <malloc.h>
                     28: #include <stdlib.h>
                     29: #include <string.h>
                     30: #include <ctype.h>
1.1.1.2   root       31: 
                     32: #ifdef NTENV
1.1       root       33: #include <windows.h>
1.1.1.2   root       34: // #define printf DbgPrint
                     35: #endif // NTENV
                     36: 
                     37: // #include <rpc.h>
                     38: // #include <rpcbse.h>
                     39: // #include <rpcndr.h>
                     40: // #include <rpcnterr.h>
1.1       root       41: 
                     42: #include "dict0.h"
                     43: #include "play.h"
                     44: #include "util0.h"
                     45: 
                     46: #define TAB_STOPS 3
                     47: 
1.1.1.2   root       48: // handle_t dict_bhandle;
                     49: 
1.1       root       50: void Usage()
                     51: {
                     52:   printf("Usage : play \n\n");
                     53:   exit(1);
                     54: }
                     55: 
                     56: /*************************************************************************/
                     57: /***                     Remote Dictionary Test Loop                   ***/
                     58: /*************************************************************************/
                     59: 
                     60: void
                     61: Usage_Msg()
                     62: {
1.1.1.2   root       63:     printf("\nUsage: \nType a single character, followed by an optional key as follows:\n\n");
                     64:     printf("    i <key> :: Insert <key> into dictionary\n");
                     65:     printf("    d <key> :: Delete <key> from dictionary\n");
                     66:     printf("    f <key> :: Find <key> in dictionary\n");
                     67:     printf("    n       :: Next of local current item in dictionary\n");
                     68:     printf("    p       :: Previous of local current item in dictionary\n");
                     69:     printf("    h       :: Head (first item) of dictionary\n");
                     70:     printf("    t       :: Tail (last item) of dictionary\n");
                     71:     printf("    ?       :: Print this message\n");
                     72:     printf("    q       :: Quit\n\n");
                     73:     printf("where <key> is <integer> <string>\n");
1.1       root       74: }
                     75: 
                     76: /*************************************************************************/
                     77: /***    Minimal Dictionary Operations:                                 ***/
                     78: /***                                                                   ***/
                     79: /***    Dictionary *Dict_New(Cmp_rec*, Splay*, print_rec*)             ***/
                     80: /***                                                                   ***/
                     81: /***    Dict_Status Dict_Find(Dictionary*, Item*)                      ***/
                     82: /***    Dict_Status Dict_Next(Dictionary*, Item*)                      ***/
                     83: /***    Dict_Status Dict_Prev(Dictionary*, Item*)                      ***/
                     84: /***    Dict_Status Dict_Insert(Dictionary*, Item*)                    ***/
                     85: /***    Dict_Status Dict_Delete(Dictionary*, Item**)                   ***/
                     86: /***                                                                   ***/
                     87: /***    Item* DICT_CURR_ITEM(Dict*)                                    ***/
                     88: /*************************************************************************/
                     89: 
                     90: void
                     91: TestLoop( Dictionary * pdict )
                     92: {
                     93: // reconstructed from the test loop in client.c...
                     94: // local variables need substantial clean up...
                     95: 
                     96:     char currName[80];
                     97:     char name[80];
                     98:     char op = 0;
                     99:     char buffer[80];
                    100: 
                    101:     Record r, currRecord;
                    102:     Record *pcurrRecord = &currRecord;
1.1.1.2   root      103:     Record * pnew;
1.1       root      104:     Record *pr = &r;
                    105:     Record * pNullRecord = NULL;
                    106: 
                    107:     Dict_Status status;
1.1.1.2   root      108:     void * pitem;
1.1       root      109:     short i;
                    110: 
                    111:     // Dictionary * pdict = *pvd;
                    112: 
                    113:     pcurrRecord->name = currName;
                    114:     pr->name = name;
                    115: 
                    116:     // VDict_Curr_Item(*pvd, &pcurrRecord);
                    117: 
                    118:     // Dict_Print(pdict, TAB_STOPS);
                    119:     Usage_Msg();
                    120: 
                    121:     while ( op != 'q' ) {
                    122: 
1.1.1.2   root      123:         printf("\nnext op (i d x f n p h t ? q): ");
1.1       root      124:         gets(buffer);
                    125:         op = buffer[0];
                    126: 
                    127:         if (op == 'i' || op == 'd' || op == 'f' ||
                    128:             op == '+' || op == '-' || op == 'I')
                    129:               sscanf(buffer+1, "%d %s", &pr->key, pr->name);
                    130: 
                    131:         switch (op) {
                    132:             case 'h':
                    133:                 // get Head of list (first record);
                    134: 
                    135:                 status = Dict_Next( pdict, NULL );
                    136:                 ItemCopy( DICT_CURR_ITEM(pdict), pcurrRecord);
                    137:                 ItemCopy( DICT_CURR_ITEM(pdict), pr);
                    138:                 break;
                    139: 
                    140:             case 't':
                    141:                 // get Tail of list (last record)
                    142: 
                    143:                 status = Dict_Prev( pdict, NULL );
                    144:                 ItemCopy( DICT_CURR_ITEM(pdict), pcurrRecord);
                    145:                 ItemCopy( DICT_CURR_ITEM(pdict), pr);
                    146:                 break;
                    147: 
                    148:            case 'f':
                    149:                 // Find <key>
                    150: 
                    151:                 status = Dict_Find(pdict, pr);
                    152:                 break;
                    153: 
                    154:             case 'n':
                    155:                 // get Next record
                    156: 
                    157:                 status = Dict_Next( pdict, pcurrRecord );
                    158:                 ItemCopy( DICT_CURR_ITEM(pdict), pcurrRecord);
                    159:                 break;
                    160: 
                    161:             case 'p':
                    162:                 // get Previous record
                    163: 
                    164:                 status = Dict_Prev( pdict, pcurrRecord );
                    165:                 ItemCopy( DICT_CURR_ITEM(pdict), pcurrRecord);
                    166:                 break;
                    167: 
                    168:             case 'N':
                    169:                 // get Next record
                    170: 
                    171:                 status = Dict_Next( pdict, pr );
                    172:                 ItemCopy( DICT_CURR_ITEM(pdict), pr);
                    173:                 break;
                    174: 
                    175:             case 'P':
                    176:                 // get Previous record
                    177: 
                    178:                 status = Dict_Prev( pdict, pr );
                    179:                 ItemCopy( DICT_CURR_ITEM(pdict), pr);
                    180:                 break;
                    181: 
                    182:             case 'r':
                    183:                 ItemCopy( DICT_CURR_ITEM(pdict), pcurrRecord);
                    184:                 break;
                    185: 
                    186: 
                    187:             case '+':
                    188:                 // get Next record
                    189: 
                    190:                 status = Dict_Next( pdict, pr );
                    191:                 break;
                    192: 
                    193:             case '-':
                    194:                 // get Previous record
                    195:                 // break;
                    196: 
                    197:                 status = Dict_Prev( pdict, pr );
                    198:                 break;
                    199: 
                    200:             case 'i':
                    201:                 // Insert <key>
                    202: 
                    203:                 status = Dict_Insert(
                    204:                     pdict,
                    205:                     makeRecord(pr->key, pr->name)
                    206:                     );
                    207:                 break;
                    208: 
                    209:             case 'I':
                    210:                 // Insert (<num'>,<name>) for all num': 3 < num' < num
                    211: 
                    212:                 for (i=3; i < pr->key; i++) {
                    213:                     status = Dict_Insert(
                    214:                         pdict,
                    215:                         makeRecord(i, pr->name)
                    216:                         );
                    217:                     }
                    218:                 break;
                    219: 
                    220:             case 'd':
                    221:                 // Delete <key>
                    222: 
                    223:                 if (pdict != NULL) {
1.1.1.2   root      224:                     status = Dict_Delete(pdict, (void **)&pr);
1.1       root      225:                     freeRecord(pr);
                    226:                     pr = &r;
                    227:                 }
                    228:                 break;
                    229: 
                    230:             case 'x':
                    231:                 // Delete DICT_CURR_ITEM
                    232: 
                    233:                 if ((pdict != NULL) && (pdict->root != NULL)) {
                    234:                     pr = DICT_CURR_ITEM(pdict);
1.1.1.2   root      235:                     status = Dict_Delete(pdict, (void **) &pr);
1.1       root      236:                     freeRecord(pr);
                    237:                     pr = &r;
                    238:                 }
                    239:                 break;
                    240: 
                    241:             case 'X':
                    242:                 // Empty the whole dictionary
                    243: 
                    244:                 /*
                    245:                 while (pdict->root != NULL) {
                    246:                     pr = DICT_CURR_ITEM(pdict);
1.1.1.2   root      247:                     status = Dict_Delete(pdict, (void **)&pr);
1.1       root      248:                     freeRecord(pr);
                    249:                     pr = &r;
                    250:                 }
                    251:                 */
                    252: 
                    253:                 RecordTreeNodeFree((RecordTreeNode*)pdict->root);
                    254:                 pdict->root = NULL;
                    255:                 pr = &r;
                    256:                 break;
                    257: 
                    258:             case '?':
                    259:                 Usage_Msg();
                    260:                 break;
                    261:         }
                    262:         if (op != '?' && op != 'q') Dict_Print(pdict, TAB_STOPS);
                    263:     }
                    264: }
                    265: 
                    266: Dict_Status
                    267: Dict_New_Dict( OUT Dictionary ** ppdict )
                    268: {
                    269:     static Dictionary * pdict;
                    270: 
                    271:     pdict = Dict_New(comp, tdSplay, printRecord);
                    272:     Init_dict(pdict);
                    273: 
                    274:     *ppdict = pdict;
                    275:     return(DICT_SUCCESS);
                    276: }
                    277: 
                    278: void
                    279: Init_dict(Dictionary * dp)
                    280: {
                    281:     Record* rp;
                    282: 
1.1.1.2   root      283:     rp = makeRecord((short)0, "jack_smith"); Dict_Insert(dp, rp);
                    284:     rp = makeRecord((short)0, "john_doe"); Dict_Insert(dp, rp);
                    285:     rp = makeRecord((short)1, "jean_doe"); Dict_Insert(dp, rp);
                    286:     rp = makeRecord((short)0, "joana_smith"); Dict_Insert(dp, rp);
                    287:     rp = makeRecord((short)1, "michael_jones"); Dict_Insert(dp, rp);
                    288:     rp = makeRecord((short)0, "mike_jacobs"); Dict_Insert(dp, rp);
                    289:     rp = makeRecord((short)2, "bill_jackson"); Dict_Insert(dp, rp);
                    290:     rp = makeRecord((short)0, "jane_doe"); Dict_Insert(dp, rp);
                    291:     rp = makeRecord((short)0, "dianne_jackson"); Dict_Insert(dp, rp);
                    292:     rp = makeRecord((short)1, "james_doe"); Dict_Insert(dp, rp);
                    293:     rp = makeRecord((short)1, "steve_johnson"); Dict_Insert(dp, rp);
                    294:     rp = makeRecord((short)2, "debbie_jones"); Dict_Insert(dp, rp);
                    295:     rp = makeRecord((short)0, "jacob_jacobson"); Dict_Insert(dp, rp);
1.1       root      296: 
                    297:     Dict_Print(dp, TAB_STOPS);
                    298: }
                    299: 
                    300: /*************************************************************************/
                    301: /***                             Main Loop                             ***/
                    302: /*************************************************************************/
                    303: 
                    304: void
                    305: main_dict ()
                    306: {
                    307:     Dictionary * pdict;
                    308:     Dictionary ** ppdict = &pdict;
                    309: 
                    310:     printf ("getting a new dict\n");
                    311:     Dict_New_Dict( ppdict );
                    312:     printf ("gotten a new dict in main_dict\n");
                    313:     TestLoop(pdict);
                    314: }
                    315: 
1.1.1.3 ! root      316: void _CRTAPI1
1.1.1.2   root      317: main(int argc, char *argv[])
1.1       root      318: {
                    319:     main_dict ();
                    320: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.