home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c004 / 3.ddi / NOVELL / CTCLB2C.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-24  |  3.4 KB  |  190 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. #define CTDEBUG
  32. #ifdef CTDEBUG
  33. #define ALIMIT 30
  34. LOCAL struct {
  35.     TEXT    *aadr;
  36.     UCOUNT     aamt;
  37.     } a[ALIMIT] = {0};
  38. LOCAL COUNT    acnt = 0;
  39. LOCAL COUNT    anul = 0;
  40. LOCAL UCOUNT    atot = 0;
  41. LOCAL UCOUNT    amax = 0;
  42. LOCAL UCOUNT    alev = 0;
  43. #endif
  44.  
  45. TEXT *lalloc(numobj,sizobj)
  46. unsigned int numobj,sizobj;
  47. {
  48.     TEXT *valloc();
  49.  
  50.     sizobj  = (sizobj * numobj + 15) / 16;
  51.     return(valloc(sizobj));
  52. }
  53.  
  54. TEXT *mballc(numobj,sizobj)
  55. unsigned int numobj,sizobj;
  56. {
  57.     TEXT *lalloc(),*sp;
  58.     FAST TEXT *tp;
  59.  
  60.     if (numobj == 0 || sizobj == 0) {
  61.         sizobj = 1; /* to avoid false NULL return */
  62.         numobj = 1;
  63.     }
  64.  
  65. #ifdef CTDEBUG
  66.     if (acnt >= ALIMIT) {
  67.         display("\n\rError ALIMIT. atot,acnt,ALIMIT ");
  68.         numdis(atot);numdis(acnt);numdis(ALIMIT);
  69.         display("\n\r");
  70.         killvap();
  71.     }
  72.  
  73.     atot += a[acnt].aamt = numobj * sizobj;
  74.     alev += a[acnt].aamt;
  75.     if (alev > amax)
  76.         amax = alev;
  77.     sp = tp = a[acnt++].aadr = lalloc(numobj,sizobj);
  78. #else
  79.     sp = tp = lalloc(numobj,sizobj);
  80. #endif
  81.     if (sp) {
  82.         numobj *= sizobj;
  83.         while (numobj--)
  84.             *tp++ = '\0';
  85.     }
  86.     return(sp);
  87. }
  88.  
  89. /* ------------------------------------------------------------ */
  90.  
  91. VOID mbfree(objptr)
  92. TEXT       *objptr;
  93. {
  94.     FAST COUNT i;
  95.  
  96. #ifdef CTDEBUG
  97.     if (objptr != NULL) {
  98.         /*free(objptr);*/
  99.         for (i = acnt - 1; i >= 0; i--)
  100.             if (objptr == a[i].aadr) {
  101.                 a[i].aadr = NULL;
  102.                 alev -= a[i].aamt;
  103.                 return;
  104.             }
  105.         display("\n\rError free. objptr=");
  106.         numdis(objptr);
  107.     } else
  108.         anul++;
  109. #else
  110.     if (objptr != NULL)
  111.         free(objptr);
  112. #endif
  113. }
  114.  
  115. #ifdef CTDEBUG
  116. VOID arep(mode)
  117. COUNT      mode;
  118. {
  119.     FAST COUNT i;
  120.  
  121.     display("\n\racnt / anul / atot / amax / alev: ");
  122.     numdis(acnt); numdis(anul); numdis(atot); numdis(amax); numdis(alev);
  123. }
  124. #endif
  125.  
  126. /* --------------------------------------------------------------------
  127.    routine to copy tree buffer contents. it does not terminate on null
  128.    byte.
  129.  */
  130.  
  131. #ifndef cpybuf
  132. VOID cpybuf(dp,sp,n)
  133. PFAST TEXT *dp,*sp;
  134. PFAST UCOUNT n;
  135.  
  136. {
  137.     while (n-- != 0)
  138.         *dp++ = *sp++;
  139. }
  140. #endif
  141.  
  142. COUNT uerr(err_no)
  143. COUNT       err_no;
  144. {
  145.     return(uerr_cod = err_no);
  146. }
  147.  
  148. VOID terr(err_no)
  149. COUNT      err_no;
  150. {
  151.     display("\n\n\rc-tree fatal error #");
  152.     numdis(err_no);
  153.     display("\n\r");
  154.     killvap();
  155. }
  156.  
  157. #ifdef UNIFRMAT
  158.  
  159. VOID revbyt(tp,wrdcnt)
  160. PFAST TEXT *tp;
  161. PFAST COUNT    wrdcnt;
  162. {
  163.     TEXT ch;
  164.  
  165.     while (wrdcnt-- > 0) {
  166.         ch      = *tp++;
  167.         *(tp - 1) = *tp;
  168.         *tp++      = ch;
  169.     }
  170. }
  171.  
  172. #endif
  173.  
  174. VOID revobj(tp,len)
  175. PFAST TEXT *tp;
  176. COUNT           len;
  177. {
  178.     FAST TEXT *hp;
  179.     TEXT       ch;
  180.  
  181.     hp = tp + len - 1;
  182.     while (tp < hp) {
  183.         ch    = *tp;
  184.         *tp++ = *hp;
  185.         *hp-- = ch;
  186.     }
  187. }
  188.  
  189. /* end of ctclb2c.nov */
  190.