--- mstools/samples/rpc/dict/util0.c 2018/08/09 18:20:57 1.1.1.2 +++ mstools/samples/rpc/dict/util0.c 2018/08/09 18:24:21 1.1.1.3 @@ -6,34 +6,20 @@ /** **/ /*************************************************************/ -#include -#include #include +#include #include #include -#ifdef NTENV -#include -// #define printf DbgPrint -#endif // NTENV - -#include -// #include -// #include -// #include - -#include "dict0.h" - #ifndef _LOCAL #include "replay.h" #else #include "play.h" #endif // _LOCAL +#include "dict0.h" #include "util0.h" -#define SIZE 2000 -#define TAB_STOPS 3 /*************************************************************************/ /*** RecordNode / RecordTree free routines ***/ @@ -44,7 +30,8 @@ RecordTreeNodeFree( IN RecordTreeNode * node ) { - if(node == NULL) return; + if (node == NULL) + return; MIDL_user_free( node->item->name ); MIDL_user_free( node->item ); @@ -58,12 +45,15 @@ RecordTreeFree( IN RecordTreeNode * node ) { - if(node == NULL) return; + if (node == NULL) + return; if (node->left != NULL) { - RecordTreeFree(node->left); } + RecordTreeFree(node->left); + } if (node->right != NULL) { - RecordTreeFree(node->right); } + RecordTreeFree(node->right); + } RecordTreeNodeFree( node ); } @@ -73,6 +63,7 @@ RDict_Free_Dict( ) { RecordTreeFree( r_dict->root ); + return(DICT_SUCCESS); } @@ -111,18 +102,18 @@ void free_state(DictState * state) /*** Rdict Duplicate utilities ***/ /*************************************************************************/ - RDict * RDict_Duplicate( IN RDict * src ) { - RDict * dst = (RDict*)MIDL_user_allocate(sizeof(RDict)); + RDict * dst = (RDict*) MIDL_user_allocate(sizeof(RDict)); - dst->root = (RecordTreeNode*)Tree_Duplicate((TreeNode*)src->root); + dst->root = (RecordTreeNode*) Tree_Duplicate((TreeNode*)src->root); dst->size = src->size; dst->state = DictState_Duplicate(src->state); - return( dst ); + + return(dst); } DictState * @@ -131,6 +122,7 @@ DictState_Duplicate( ) { DictState * dst = (DictState*) MIDL_user_allocate(sizeof(DictState)); + dst->curr_record = ItemDuplicate(src->curr_record); dst->ref_count = src->ref_count; @@ -146,7 +138,8 @@ TreeNode_Duplicate( pnode->left = pnode->right = NULL; pnode->item = ItemDuplicate(src->item); - return ( pnode ); + + return(pnode); } TreeNode * @@ -156,89 +149,29 @@ Tree_Duplicate( { TreeNode * dst; - if (src == NULL) return((TreeNode*)NULL); + if (src == NULL) + return((TreeNode*)NULL); dst = TreeNode_Duplicate(src); dst->left = Tree_Duplicate(src->left); dst->right = Tree_Duplicate(src->right); - return ( dst ); + return(dst); } /*************************************************************************/ /*** MIDL_user_allocate / MIDL_user_free ***/ /*************************************************************************/ -void * -MIDL_user_allocate(size_t count) +void __RPC_FAR * __RPC_API MIDL_user_allocate(size_t count) { - - unsigned char * ptr; - ptr = malloc( count ); - return ( ptr ); - + return(malloc(count)); } -void -MIDL_user_free(void * p) +void __RPC_API MIDL_user_free(void __RPC_FAR * p) { - free (p); + free(p); } -/* - -void * -MIDL_user_allocate(size_t count) -{ - - unsigned char *ptr, *old; - unsigned long delta = 0; - - ptr = old = malloc( (size_t)(count+7) ); - - // Normalize: modify ptr to the next (0 mod 4) address - ptr += 3; - *(unsigned long *)&ptr &= 0xfffffffc; - - // ptr is now aligned on a (0 mod 4) boundary, and we have at least - // 4 extra bytes, for the decrement (delta) and count values - - // delta = 4 - the remainder of ptr mod 4 - // decrement to restore the original pointer value - // delta = 4LU - ((unsigned long)ptr - (unsigned long)old); - delta = 4 - ((unsigned long) ptr) & 0x00000003; - - // correct for the exception case: - if (delta == 4) delta = 0; - - // store the count in the first two bytes: - *(short*)ptr = (short)count; - ptr += 2; - - // store the difference between the count point and the original - // pointer in the next two bytes: - *(short*)ptr = (short)delta; - ptr += 2; - return( ptr ); - - // return(malloc(count)); -} - -void -MIDL_user_free(void * p) -{ - - short * pdelta = ((short*)p-1); - short * pcount = ((short*)p-2); - char * ptr = (char*)pcount - (*pdelta); - int i; - - for(i = *pcount; i; ptr[--i] = '\0') - ; - free (ptr); -} - -*/ - /*************************************************************************/ /*** Utility functions ***/ /*************************************************************************/ @@ -268,12 +201,10 @@ ItemDuplicate( Record * item ) { - // Record * pR; - // pR = makeRecord( item->key, item->name ); - // return(pR); + if (item == NULL) + return(NULL); - if (item == NULL) return(NULL); - return ( makeRecord( item->key, item->name ) ); + return( makeRecord( item->key, item->name ) ); } Record * @@ -290,6 +221,7 @@ makeRecord( pr->name = (char*) MIDL_user_allocate(strlen(name)+1); strcpy(pr->name, name); pr->key = key; + return(pr); } @@ -304,14 +236,17 @@ freeRecord( MIDL_user_free(pr); } } + void ItemCopy( IN Record * src, OUT Record * dest ) -{ int i; +{ + int i; dest->key = src->key; + // copy name, trubcated to 80 characters for(i=0 ; (src->name[i] != '\0') && (i<80) ; i++) dest->name[i]=src->name[i]; @@ -338,21 +273,17 @@ Dict_Print( /* prints the bi char spaces[] = " "; - - - - - void -prinTree(int lmargin, /* indentation of the root of the tree */ +prinTree( + int lmargin, /* indentation of the root of the tree */ int indent, /* indentation of subsequent levels */ TreeNode *np, /* pointer to the root node */ PrintFun print) /* short, one line, record print routine */ { - int i; - if (np == NULL) return; + if (np == NULL) + return; - prinTree(lmargin+indent, indent, np->right, print); + prinTree(lmargin+indent, indent, np->right, print); if (lmargin > sizeof(spaces)) lmargin = sizeof(spaces);; @@ -363,7 +294,7 @@ prinTree(int lmargin, /* indentat (*print)(np->item); - prinTree(lmargin+indent, indent, np->left, print); + prinTree(lmargin+indent, indent, np->left, print); } @@ -371,8 +302,10 @@ TreeNode* makeNode(void * item) { TreeNode* tp; + tp = (TreeNode*)MIDL_user_allocate(sizeof(TreeNode)); tp->item = item; tp->left = tp->right = NULL; + return(tp); }