home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c004 / 3.ddi / NOVELL / CTCLB2S.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-18  |  3.5 KB  |  189 lines

  1. /*
  2.  *    c-tree Low Level Library Interface
  3.  *    Novell Small Model VAP Support
  4.  *
  5.  *    This program is the CONFIDENTIAL and PROPRIETARY property 
  6.  *    of FairCom(R) Corporation. Any unauthorized use, reproduction or
  7.  *    transfer of this program is strictly prohibited.
  8.  *
  9.  *      Copyright (c) 1985, 1986, 1987, 1988, 1989 FairCom Corporation
  10.  *    (Subject to limited distribution and
  11.  *     restricted disclosure only.)
  12.  *    *** ALL RIGHTS RESERVED ***
  13.  *
  14.  *    4006 West Broadway
  15.  *    Columbia, MO 65203
  16.  *
  17.  *
  18.  *    c-tree(R)    Version 4.3
  19.  *            Release C
  20.  *            February 7, 1989 17:30
  21.  *
  22.  */
  23.  
  24. #include "ctstdr.h"        /* standard i/o header         */
  25. #include "ctoptn.h"        /* c-tree configuration options */
  26. #include "cterrc.h"        /* c-tree error codes        */
  27. #include "ctstrc.h"        /* c-tree data structures    */
  28.  
  29. extern COUNT uerr_cod;
  30.  
  31. #ifdef CTDEBUG
  32. #define ALIMIT 30
  33. LOCAL struct {
  34.     TEXT    *aadr;
  35.     UCOUNT     aamt;
  36.     } a[ALIMIT];
  37. LOCAL COUNT    acnt,anul;
  38. LOCAL UCOUNT    atot,amax,alev;
  39. #endif
  40.  
  41. #define MEMLIM 55000
  42. LOCAL TEXT   alcmem[MEMLIM];
  43. LOCAL UCOUNT ptrmem = 0;
  44.  
  45. TEXT *salloc(numobj,sizobj)
  46. unsigned int numobj,sizobj;
  47. {
  48.     sizobj *= numobj;
  49.     numobj  = ptrmem;
  50.     ptrmem += sizobj;
  51.     if (ptrmem > MEMLIM || ptrmem < numobj) {
  52.         display(
  53. "\n\rMemory Allocation Error: Used / Addt'l Rqst / Limit   ");
  54.         numdis(numobj); numdis(sizobj); numdis(MEMLIM);
  55.         return(NULL);
  56.     }
  57.     ptrmem  = (ptrmem + 1) / 2 * 2;
  58.     return(alcmem + numobj);
  59. }
  60.  
  61. TEXT *mballc(numobj,sizobj)
  62. unsigned int numobj,sizobj;
  63. {
  64.     TEXT *salloc();
  65.  
  66.     if (numobj == 0 || sizobj == 0) {
  67.         sizobj = 1; /* to avoid false NULL return */
  68.         numobj = 1;
  69.     }
  70.  
  71. #ifdef CTDEBUG
  72.     if (acnt >= ALIMIT) {
  73.         display("\n\rError ALIMIT. atot=");
  74.         numdis(atot);
  75.         killvap();
  76.     }
  77.  
  78.     atot += a[acnt].aamt = numobj * sizobj;
  79.     alev += a[acnt].aamt;
  80.     if (alev > amax)
  81.         amax = alev;
  82.     return(a[acnt++].aadr = salloc(numobj,sizobj));
  83. #else
  84.     return(salloc(numobj,sizobj));
  85. #endif
  86. }
  87.  
  88. /* ------------------------------------------------------------ */
  89.  
  90. VOID mbfree(objptr)
  91. TEXT       *objptr;
  92. {
  93.     FAST COUNT i;
  94.  
  95. #ifdef CTDEBUG
  96.     if (objptr != NULL) {
  97.         /*free(objptr);*/
  98.         for (i = acnt - 1; i >= 0; i--)
  99.             if (objptr == a[i].aadr) {
  100.                 a[i].aadr = NULL;
  101.                 alev -= a[i].aamt;
  102.                 return;
  103.             }
  104.         display("\n\rError free. objptr=");
  105.         numdis(objptr);
  106.     } else
  107.         anul++;
  108. #else
  109.     if (objptr != NULL)
  110.         free(objptr);
  111. #endif
  112. }
  113.  
  114. #ifdef CTDEBUG
  115. VOID arep(mode)
  116. COUNT      mode;
  117. {
  118.     FAST COUNT i;
  119.  
  120.     display("\n\racnt / anul / atot / amax / alev: ");
  121.     numdis(acnt); numdis(anul); numdis(atot); numdis(amax); numdis(alev);
  122. }
  123. #endif
  124.  
  125. /* --------------------------------------------------------------------
  126.    routine to copy tree buffer contents. it does not terminate on null
  127.    byte.
  128.  */
  129.  
  130. #ifndef cpybuf
  131. VOID cpybuf(dp,sp,n)
  132. PFAST TEXT *dp,*sp;
  133. PFAST UCOUNT n;
  134.  
  135. {
  136.     while (n-- != 0)
  137.         *dp++ = *sp++;
  138. }
  139. #endif
  140.  
  141. COUNT uerr(err_no)
  142. COUNT       err_no;
  143. {
  144.     return(uerr_cod = err_no);
  145. }
  146.  
  147. VOID terr(err_no)
  148. COUNT      err_no;
  149. {
  150.     display("\n\n\rc-tree fatal error #");
  151.     numdis(err_no);
  152.     display("\n\r");
  153.     killvap();
  154. }
  155.  
  156. #ifdef UNIFRMAT
  157.  
  158. VOID revbyt(tp,wrdcnt)
  159. PFAST TEXT *tp;
  160. PFAST COUNT    wrdcnt;
  161. {
  162.     TEXT ch;
  163.  
  164.     while (wrdcnt-- > 0) {
  165.         ch      = *tp++;
  166.         *(tp - 1) = *tp;
  167.         *tp++      = ch;
  168.     }
  169. }
  170.  
  171. #endif
  172.  
  173. VOID revobj(tp,len)
  174. PFAST TEXT *tp;
  175. COUNT           len;
  176. {
  177.     FAST TEXT *hp;
  178.     TEXT       ch;
  179.  
  180.     hp = tp + len - 1;
  181.     while (tp < hp) {
  182.         ch    = *tp;
  183.         *tp++ = *hp;
  184.         *hp-- = ch;
  185.     }
  186. }
  187.  
  188. /* end of ctclb2.nov */
  189.