Home » Archimedes archive » Acorn User » AU 1996-12 B.adf » Features » PCA/Flexlib/c/FLEX

PCA/Flexlib/c/FLEX

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1996-12 B.adf » Features
Filename: PCA/Flexlib/c/FLEX
Read OK:
File size: 4F0F bytes
Load address: 0000
Exec address: 0000
File contents
/************************************************************************/
/*  Acorn Computers Ltd, 1992.                                         */
/*                                                                      */
/* This file forms part of an unsupported source release of RISC_OSLib. */
/*                                                                      */
/* It may be freely used to create executable images for saleable       */
/* products but cannot be sold in source form or as an object library   */
/* without the prior written consent of Acorn Computers Ltd.            */
/*                                                                      */
/* If this file is re-distributed (even if modified) it should retain   */
/* this copyright notice.                                               */
/*                                                                      */
/************************************************************************/

/* Title: c.flex
 * Purpose: provide memory allocation for interactive programs requiring
 *          large chunks of store.
 * History: IDJ: 06-Feb-92: prepared for source release
 *          Andy Armstrong:  21-Oct-94: modified to use dynamic areas and callbacks.
 *          David Jackson :  06-Sep-95: modified to use Virtual Memory
 *          David Jackson :  19-Apr-96: modified to use Acorn Toolbox (Ugh!)
 */

#define BOOL int
#define TRUE 1
#define FALSE 0
#define TRACE 0

#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include "kernel.h"
#include "swis.h"
#include "h.flex"
#include "wimplib.h"


/* #include "tracker.h" */

#ifndef OS_DynamicArea
#define OS_DynamicArea  0x00066
#endif

#ifndef Virtualise_Configure          
#define Virtualise_Configure           0x04b6c0
#endif
#ifndef Virtualise_Start              
#define Virtualise_Start               0x04b6c1
#endif
#ifndef Virtualise_End                
#define Virtualise_End                 0x04b6c2
#endif
#ifndef Virtualise_Lock               
#define Virtualise_Lock                0x04b6c3
#endif
#ifndef Virtualise_Unlock             
#define Virtualise_Unlock              0x04b6c4
#endif
#ifndef Virtualise_MiscOp             
#define Virtualise_MiscOp              0x04b6c5
#endif
 


static int flex__initialised = 0;
static int flex__da          = -1; /* or da number */
static BOOL flex__VM         = FALSE;  /* is VM in use? */ 
static int  _mblk;

static void werr(int fatal, char* format, ...);
static char* msgs_lookup(char* tag);


/* This implementation goes above the original value of GetEnv,
to memory specifically requested from the Wimp. The heap is kept
totally compacted all the time, with pages being given back to
the Wimp whenever possible. */

typedef struct {
  flex_ptr anchor;      /* *anchor should point back to here. */
#ifdef flex_CALLBACK
  flex_cbfunc cb;
  void *handle;
#endif    
  int size;             /* in bytes. Exact size of logical area. */
                        /* then the actual store follows. */
} flex__rec;


static void flex__fail(int i)
{
   werr(TRUE, msgs_lookup("flex1:Flex memory error (%d)"), i);
#if TRACE
   i = *(int *)-4 ;     /* go bang! */
#else
   i = i; /* avoid compiler warning. */
#endif
}


static void flex__check(void)
{
   if(flex__initialised == 0)
     werr(TRUE, msgs_lookup("flex3:Flex not initialised"));
}



/* macro to avoid stack usage */
#define roundup(n)  (0xfffffffc & (n + 3))

static char *flex__base;        /* lowest flex__rec - only for budging. */
static char *flex__freep;       /* free flex memory */
static char *flex__lim;         /* limit of flex memory */
/* From base upwards, it's divided into store blocks of
  a flex__rec
  the space
  align up to next word.
*/


static void flex__wimpslot(char **top) 
{
   /* read/write the top of available memory. *top == 0 -> just read. */
   int dud = -1;
   int slot = ((int) *top);
   _kernel_swi_regs r;
   _kernel_oserror  *err;
   int memlim, appspace, oldmemlim;

   if (slot != -1) slot -= 0x8000;

   /* read memory limit value */
    r.r[0] = 0;
    r.r[1] = 0;
    r.r[2] = 0;
    err = _kernel_swi(OS_ChangeEnvironment, &r, &r);
    oldmemlim = memlim = r.r[1];

   /* read appspace value */
    r.r[0] = 14;  /* Application space */
    r.r[1] = 0;
    r.r[2] = 0;
    err = _kernel_swi(OS_ChangeEnvironment, &r, &r);
    appspace = r.r[1];
   /* set memory limit before slot size change ... */
    if(appspace > memlim)
    {
       r.r[0] = 0;
       r.r[1] = appspace;
       r.r[2] = 0;
       err = _kernel_swi(OS_ChangeEnvironment, &r, &r);
    }

   /* set wimpslot size (or read it) */
   
   if (wimp_slot_size(slot,dud,&slot, &dud, &dud)!=NULL) werr(TRUE,msgs_lookup("fatal:Fatal Flex memory error"));

   *top = (char*) slot + 0x8000;

   /* .... and set memory limit back again */
   if (appspace > memlim)
   {
       r.r[0] = 0;
       r.r[1] = oldmemlim;
       r.r[2] = 0;
       err = _kernel_swi(OS_ChangeEnvironment, &r, &r);
    }
       
}

static BOOL flex__more(int n)
{
   /* Tries to get at least n more bytes, raising flex__lim and
   returning TRUE if it can. */
   char *prev = flex__lim;

   if (flex__da != -1)
   {  _kernel_swi_regs regs;
      _kernel_oserror *err;

      regs.r[0] = flex__da;
      regs.r[1] = n;

      err = _kernel_swi(OS_ChangeDynamicArea, &regs, &regs);
      
      if (err || regs.r[1] < n)
      {  regs.r[1] = -regs.r[1];
         _kernel_swi(OS_ChangeDynamicArea, &regs, &regs);
         return FALSE;
      }

      err = _kernel_swi(OS_ReadDynamicArea, &regs, &regs);
      flex__lim = flex__base + regs.r[1];
      return TRUE;
   }
   else
   {  flex__lim += n;
      flex__wimpslot(&flex__lim);

   
      if (flex__lim < prev + n)
      {
         flex__lim = prev;             /* restore starting state:
                                          extra memory is useless */
         flex__wimpslot(&flex__lim);
         return FALSE ;
      }
      else 
         return TRUE ;
   }
}


static void flex__give(void) 
{
   if (flex__da != -1)
   {  _kernel_swi_regs regs;
      _kernel_oserror *err;
      
      regs.r[0] = flex__da;
      regs.r[1] = flex__freep - flex__lim; /* -ve */

      err = _kernel_swi(OS_ChangeDynamicArea, &regs, &regs);
      if (!err)
      {  err = _kernel_swi(OS_ReadDynamicArea, &regs, &regs);
         flex__lim = flex__base + regs.r[1];
      }
   }
   else
   {
      /* Gives away memory, lowering flex__lim, if possible. */
#if TRACE
      int prev = (int) flex__lim;
#endif
   
      flex__lim = flex__freep;
      flex__wimpslot(&flex__lim);

   }
}


static BOOL flex__ensure(int n) 
{
   n -= flex__lim - flex__freep;

   if (n <= 0 || flex__more(n)) 
      return TRUE; 
   else return FALSE;
}

BOOL flex_alloc(flex_ptr anchor, int n)
{
   flex__rec *p;

   flex__check();

   if (n < 0 || ! flex__ensure(sizeof(flex__rec) + roundup(n))) 
   {
      *anchor = 0;
      return FALSE;
   }

   p = (flex__rec*) flex__freep;
   flex__freep += sizeof(flex__rec) + roundup(n);

   p->anchor = anchor;
   p->size = n;
#ifdef flex_CALLBACK
   p->cb = NULL;
   p->handle = NULL;
#endif      
   *anchor = p + 1; /* sizeof(flex__rec), that is */
   return TRUE;
}

static void flex__reanchor(flex__rec *p, int by) 
{
   /* Move all the anchors from p upwards. This is in anticipation
   of that block of the heap being shifted. */

   while (1) 
   {
      if ((int) p >= (int) flex__freep) break;

      if (*(p->anchor) != p + 1) flex__fail(6);
      *(p->anchor) = ((char*) (p + 1)) + by;
      p = (flex__rec*) (((char*) (p + 1)) + roundup(p->size));
   }
}

/* Notify all the blocks after and including p that the are about to move / have
 moved */

#ifdef flex_CALLBACK
#define flex__inlinenotify(b4, p)                                    \
   do                                                                \
   {  flex__rec *p2 = (p);                                           \
      for (;;)                                                       \
      {  if ((int) p2 >= (int) flex__freep) break;                   \
         if (*(p2->anchor) != p2 + 1) flex__fail(6);                 \
         if (p2->cb) p2->cb(b4, p2->handle);                         \
         p2 = (flex__rec*) (((char*) (p2 + 1)) + roundup(p2->size)); \
      }                                                              \
   } while (0)

static void flex__notify(BOOL b4, flex__rec *p)
{  flex__inlinenotify(b4, p);
}

#else
#define flex__inlinenotify(b4, p) (void) 0
#define flex__notify(b4, p) (void) 0
#endif

void flex_free(flex_ptr anchor)
{
   flex__rec *p = ((flex__rec*) *anchor) - 1;
   int roundsize = roundup(p->size);
   flex__rec *next = (flex__rec*) (((char*) (p + 1)) + roundsize);

   flex__check();

   if (p->anchor != anchor) 
   {
      flex__fail(0);
   }

   flex__notify(TRUE, next);
   flex__reanchor(next, - (sizeof(flex__rec) + roundsize));
   memmove(p, next, flex__freep - (char*) next);
   flex__freep -= sizeof(flex__rec) + roundsize;
   flex__notify(FALSE, p);

   flex__give();

   *anchor = 0;
}


int flex_size(flex_ptr anchor)
 {
   flex__rec *p = ((flex__rec*) *anchor) - 1;
   flex__check();

   if (p->anchor != anchor) 
   {
      flex__fail(4);
   }

   return(p->size);
}


int flex_extend(flex_ptr anchor, int newsize)
{
   flex__rec *p = ((flex__rec*) *anchor) - 1;
   flex__check();
   return(flex_midextend(anchor, p->size, newsize - p->size));
}


BOOL flex_midextend(flex_ptr anchor, int at, int by)
{
   flex__rec *p;
   flex__rec *next;

   flex__check();

   p = ((flex__rec*) *anchor) - 1;

   if (p->anchor != anchor) 
      flex__fail(1);

   if (at > p->size) 
      flex__fail(2);

   if (by < 0 && (-by) > at) 
      flex__fail(3);

   if (by == 0) 
   {
      /* do nothing */
   }
   else if (by > 0) 
   { 
      /* extend */

      int growth = roundup(p->size + by) - roundup(p->size);
      /* Amount by which the block will actually grow. */

      if (! flex__ensure(growth)) 
         return FALSE;

      next = (flex__rec*) (((char*) (p + 1)) + roundup(p->size));
      /* The move has to happen in two parts because the moving
      of objects above is word-aligned, while the extension within
      the object may not be. */

      flex__notify(TRUE, next);
      flex__reanchor(next, growth);

      memmove(((char*) next) + roundup(growth), next, flex__freep - (char*) next
);

      flex__freep += growth;
      flex__notify(FALSE, (flex__rec *) (((char *) next) + roundup(growth)));

      memmove(((char*) (p + 1)) + at + by, ((char*) (p + 1)) + at, p->size - at)
;

      p->size += by;

   } 
   else 
   { 
      /* The block shrinks. */
      int shrinkage;

      next = (flex__rec*) (((char*) (p + 1)) + roundup(p->size));

      by = -by; /* a positive value now */
      shrinkage = roundup(p->size) - roundup(p->size - by);
        /* a positive value */

      memmove(((char*) (p + 1)) + at - by, ((char*) (p + 1)) + at, p->size - at)
;

      p->size -= by;

      flex__notify(TRUE, next);
      flex__reanchor(next, - shrinkage);

      memmove(((char*) next) - shrinkage, next, flex__freep - (char*) next);

      flex__freep -= shrinkage;
      flex__notify(FALSE, (flex__rec *) (((char *) next) - shrinkage));

      flex__give();

   } 

   return TRUE;
}

#ifdef flex_CALLBACK
void flex_register(flex_ptr anchor, flex_cbfunc cb, void *handle)
{  flex__rec *p = ((flex__rec*) *anchor) - 1;

   flex__check();

   if (p->anchor != anchor) 
   {
      flex__fail(4);
   }

   p->cb = cb;
   p->handle = handle;
}
#endif

/* stack checking off */
#pragma -s1

/* The underlying system asks us to move all flex store up (if n +ve) or
down by n bytes. If you succeed, put the store allocated in *a and return
the size. size >= roundup(n) on successful exit, and will be a multiple of
four. If you fail, return what we can. 
If n is -ve, no result is required: success is assumed. 
*/

extern int flex_budge(int n, void **a)
{  if (flex__da != -1)
      return flex_dont_budge(n, a);

   flex__inlinenotify(TRUE, (flex__rec *) flex__base);

   if (n >= 0) /* all moving up */
   {
      int roundupn = roundup(n);
      int more = roundupn - (flex__lim - flex__freep);
      
      /* try to satisfy the request */
      if (more > 0)   /* ie we have to increase slot */
      {
         char *prev = flex__lim;
         flex__lim += more; 

         /* in-line implementation (of flex__wimpslot)  */
         /*  to reduce stack requirements               */
         {
            int slot = ((int) flex__lim);
            _kernel_swi_regs r;
            _kernel_oserror  *err;
            int memlim, appspace, oldmemlim;

            if (slot != -1) 
               slot -= 0x8000;

            /* read memory limit value */
            r.r[0] = 0;
            r.r[1] = 0;
            r.r[2] = 0;
            err = _kernel_swi(OS_ChangeEnvironment, &r, &r);
            oldmemlim = memlim = r.r[1];

            /* read appspace value */
            r.r[0] = 14;  /* Application space */
            r.r[1] = 0;
            r.r[2] = 0;
            err = _kernel_swi(OS_ChangeEnvironment, &r, &r);
            appspace = r.r[1];

            /* set memory limit before slot size change ... */
            if(appspace > memlim)
            {
               r.r[0] = 0;
               r.r[1] = appspace;
               r.r[2] = 0;
               err = _kernel_swi(OS_ChangeEnvironment, &r, &r);
            }

            /* set wimpslot size */
            r.r[0] = slot;
            r.r[1] = -1;
            err =_kernel_swi(Wimp_SlotSize, &r, &r);
            slot = r.r[0];
            
            flex__lim = (char*) slot + 0x8000;

            /* .... and set memory limit back again */
            if (appspace > memlim)
            {
               r.r[0] = 0;
               r.r[1] = oldmemlim;
               r.r[2] = 0;
               err = _kernel_swi(OS_ChangeEnvironment, &r, &r);
            }
         }

         /* if we couldn't satisfy it, still give back what we can, */
         /* _kernel_alloc may be able to use it!!!!!                */
         if (flex__lim < prev + more)
             roundupn = flex__lim - flex__freep; /*all we got*/
      }
      
      {
           flex__rec *p = (flex__rec*)flex__base;
           while (1) {
                if ((int) p >= (int) flex__freep) break;
                *(p->anchor) = ((char*) (p + 1)) + roundupn;
                p = (flex__rec*) (((char*) (p + 1)) + roundup(p->size));
           }
      }
       
      memmove(flex__base + roundupn, flex__base, flex__freep - flex__base);
      *a = flex__base;
      flex__base += roundupn;
      flex__freep += roundupn;

      flex__inlinenotify(FALSE, (flex__rec *) flex__base);
      return(roundupn);

   } 
   else 
   { 
      /* all moving down */
      int roundupn = roundup(-n); /* a +ve value */

      {
         flex__rec *p = (flex__rec*)flex__base;
         while (1) 
         {
             if ((int) p >= (int) flex__freep) break;
             *(p->anchor) = ((char*) (p + 1)) + roundupn;
             p = (flex__rec*) (((char*) (p + 1)) + roundup(p->size));
         }
      }
      memmove(flex__base - roundupn, flex__base, flex__freep - flex__base);
      flex__base -= roundupn;
      flex__freep -= roundupn;
      flex__inlinenotify(FALSE, (flex__rec *) flex__base);
   }


   return(0);
}

extern int flex_dont_budge(int n, void **a)
{  n = n;
   a = a;
   return 0;
}

/* stack checks on again */
#pragma -s0

static void flex__exit(void)
{  _kernel_swi_regs regs;

   if (flex__da != -1)
   {  regs.r[0] = 1;
      regs.r[1] = flex__da;
      _kernel_swi(OS_DynamicArea, &regs, &regs);
   }
}

void flex_initx(char *program_name, int *error_fd,int da,int maxsize,BOOL virtualise)
{  flex__lim = (char *) -1;
   _mblk=(int)error_fd;

   if (da) /* try to create a DA */
   {  _kernel_oserror *err;
      _kernel_swi_regs regs;

      regs.r[0] =    0;  /* create DA         */
      regs.r[1] =   -1;  /* area number       */
      regs.r[2] =    0;  /* initial size      */
      regs.r[3] =   -1;  /* logical address   */
      regs.r[4] = 0x80;  /* access privileges */
      regs.r[5] =   maxsize;  /* max size          */
      if (virtualise)                                       /*DJ    */
       {                                                    /*DJ    */
         regs.r[4] = regs.r[4]  | (1U <<31);                /*DJ    */
         regs.r[5]=maxsize;                                 /*DJ    */
                                                            /*DJ    */
       }                                                    /*DJ    */
      regs.r[6] =    0;  /* no routine yet    */
      regs.r[7] =    0;  /* ws pointer        */
      regs.r[8] = (int) program_name;  /* area name */

      err = _kernel_swi(OS_DynamicArea, &regs, &regs);

      if (!err)
      {  flex__da   = regs.r[1];
         flex__freep = flex__lim = flex__base = (char *) regs.r[3];
         atexit(flex__exit);   
         if (virtualise)
           {
            _kernel_swi(OS_ReadMemMapInfo,&regs,&regs);
            regs.r[0]=regs.r[0]*regs.r[1];
            regs.r[1]=regs.r[0];
            regs.r[2]=regs.r[0]*.05;
            _kernel_swi(Virtualise_Configure,&regs,&regs);
                                                       
            flex__VM=TRUE;
           }
         goto initok;
      }
   }

   flex__wimpslot(&flex__lim);  /* shrink */
   flex__freep = flex__lim;
   flex__base = flex__freep;
   _kernel_register_slotextend(flex_dont_budge);

initok:
   flex__initialised = 1;

   /* Check that we're in the Wimp environment. */
   {
      void *a;
      if (! flex_alloc(&a, 1)) 
         werr(TRUE, msgs_lookup("flex2:Not enough memory, or not within *desktop world."));

      flex_free(&a);
   }

}

/* default flex_init() disables use of DA */

void flex_init(char *program_name, int *error_fd)
{  flex_initx(program_name,error_fd,FALSE,-1,FALSE /* DJ 060995 */);
}

int flex_isdynamic(void)
{  return flex__da != -1;
}                       


BOOL flex_isVM(void)
{
 return flex__VM;
}

_kernel_oserror * flex_VMConfigure(int def,int cache,int left)

{
_kernel_swi_regs regs;

 regs.r[0]=def;
 regs.r[1]=cache;
 regs.r[2]=left;
 return _kernel_swi(Virtualise_Configure,&regs,&regs);
}



_kernel_oserror * flex_readVMConfigure(int * def ,int *cache,int *left)

{
_kernel_oserror *err;
_kernel_swi_regs regs;

 regs.r[0]=-1;
 regs.r[1]=-1;
 regs.r[2]=-1;
 err=_kernel_swi(Virtualise_Configure,&regs,&regs);

 if (!err)
 {

 *def    =regs.r[0];
 *cache  =regs.r[1];
 *left   =regs.r[2];
 regs.r[0]=2;
 regs.r[1]=flex__da;
 _kernel_swi(OS_DynamicArea,&regs,&regs);

*def=regs.r[5];
 }
  
return(err);
}


_kernel_oserror * flex_virtualstart(char * swapfile)
{
_kernel_swi_regs regs;
_kernel_oserror *err;

regs.r[0]=flex__da;
regs.r[1]=-1;
regs.r[2]=(int) swapfile;
err=_kernel_swi(Virtualise_Start,&regs,&regs);

if (!err) flex__VM=TRUE;
return(err);
 
}


_kernel_oserror * flex_virtualstop(void)
{
_kernel_swi_regs regs;
_kernel_oserror *err;

regs.r[0]=flex__da;
err=_kernel_swi(Virtualise_End,&regs,&regs);

if (!err) flex__VM=FALSE;
return(err);
 
}


_kernel_oserror * flex_lock(int start,int end)
{
_kernel_swi_regs regs;
_kernel_oserror *err=NULL;

if (flex__VM)
                        
{
   regs.r[0]=start;
   regs.r[1]=end;
   err=_kernel_swi(Virtualise_Lock,&regs,&regs);  

}

return(err);
}


_kernel_oserror * flex_unlock(int start,int end)
{
_kernel_swi_regs regs;
_kernel_oserror *err=NULL;

if (flex__VM)
                        
{
   regs.r[0]=start;
   regs.r[1]=end;
   err=_kernel_swi(Virtualise_Unlock,&regs,&regs);  

}

return(err);
}



static void werr(int fatal, char* format, ...)
{
   va_list va;
   _kernel_oserror e;

   e.errnum = 0;
   va_start(va, format);
   vsprintf(&e.errmess[0], format, va);
   va_end(va);
   wimp_report_error(&e, 0, "FlexLibrary",0,0,0);
   if (fatal) exit(1);
}

static char* msgs_lookup(char* tag)
{

 _kernel_swi_regs regs;
  char* p=tag;
  while (*p++!=':') NULL;
  p--;
  *p++=0;

    regs.r[0] = _mblk;
    regs.r[1] = (int) tag;
    regs.r[2] = 0;

    if (_kernel_swi(MessageTrans_Lookup,&regs,&regs))
     return p;
    else return (char *) regs.r[2];




}





/* end */

00000000  0a 2f 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |./**************|
00000010  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
00000040  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2f 0a 2f 2a 20 20  |**********/./*  |
00000050  41 63 6f 72 6e 20 43 6f  6d 70 75 74 65 72 73 20  |Acorn Computers |
00000060  4c 74 64 2c 20 31 39 39  32 2e 20 20 20 20 20 20  |Ltd, 1992.      |
00000070  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000090  20 20 20 2a 2f 0a 2f 2a  20 20 20 20 20 20 20 20  |   */./*        |
000000a0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000000d0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 2a 2f  |              */|
000000e0  0a 2f 2a 20 54 68 69 73  20 66 69 6c 65 20 66 6f  |./* This file fo|
000000f0  72 6d 73 20 70 61 72 74  20 6f 66 20 61 6e 20 75  |rms part of an u|
00000100  6e 73 75 70 70 6f 72 74  65 64 20 73 6f 75 72 63  |nsupported sourc|
00000110  65 20 72 65 6c 65 61 73  65 20 6f 66 20 52 49 53  |e release of RIS|
00000120  43 5f 4f 53 4c 69 62 2e  20 2a 2f 0a 2f 2a 20 20  |C_OSLib. */./*  |
00000130  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000170  20 20 20 20 2a 2f 0a 2f  2a 20 49 74 20 6d 61 79  |    */./* It may|
00000180  20 62 65 20 66 72 65 65  6c 79 20 75 73 65 64 20  | be freely used |
00000190  74 6f 20 63 72 65 61 74  65 20 65 78 65 63 75 74  |to create execut|
000001a0  61 62 6c 65 20 69 6d 61  67 65 73 20 66 6f 72 20  |able images for |
000001b0  73 61 6c 65 61 62 6c 65  20 20 20 20 20 20 20 2a  |saleable       *|
000001c0  2f 0a 2f 2a 20 70 72 6f  64 75 63 74 73 20 62 75  |/./* products bu|
000001d0  74 20 63 61 6e 6e 6f 74  20 62 65 20 73 6f 6c 64  |t cannot be sold|
000001e0  20 69 6e 20 73 6f 75 72  63 65 20 66 6f 72 6d 20  | in source form |
000001f0  6f 72 20 61 73 20 61 6e  20 6f 62 6a 65 63 74 20  |or as an object |
00000200  6c 69 62 72 61 72 79 20  20 20 2a 2f 0a 2f 2a 20  |library   */./* |
00000210  77 69 74 68 6f 75 74 20  74 68 65 20 70 72 69 6f  |without the prio|
00000220  72 20 77 72 69 74 74 65  6e 20 63 6f 6e 73 65 6e  |r written consen|
00000230  74 20 6f 66 20 41 63 6f  72 6e 20 43 6f 6d 70 75  |t of Acorn Compu|
00000240  74 65 72 73 20 4c 74 64  2e 20 20 20 20 20 20 20  |ters Ltd.       |
00000250  20 20 20 20 20 2a 2f 0a  2f 2a 20 20 20 20 20 20  |     */./*      |
00000260  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000002a0  2a 2f 0a 2f 2a 20 49 66  20 74 68 69 73 20 66 69  |*/./* If this fi|
000002b0  6c 65 20 69 73 20 72 65  2d 64 69 73 74 72 69 62  |le is re-distrib|
000002c0  75 74 65 64 20 28 65 76  65 6e 20 69 66 20 6d 6f  |uted (even if mo|
000002d0  64 69 66 69 65 64 29 20  69 74 20 73 68 6f 75 6c  |dified) it shoul|
000002e0  64 20 72 65 74 61 69 6e  20 20 20 2a 2f 0a 2f 2a  |d retain   */./*|
000002f0  20 74 68 69 73 20 63 6f  70 79 72 69 67 68 74 20  | this copyright |
00000300  6e 6f 74 69 63 65 2e 20  20 20 20 20 20 20 20 20  |notice.         |
00000310  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000330  20 20 20 20 20 20 2a 2f  0a 2f 2a 20 20 20 20 20  |      */./*     |
00000340  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00000380  20 2a 2f 0a 2f 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  | */./***********|
00000390  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2a 2a 2a  |****************|
*
000003c0  2a 2a 2a 2a 2a 2a 2a 2a  2a 2a 2a 2a 2a 2f 0a 0a  |*************/..|
000003d0  2f 2a 20 54 69 74 6c 65  3a 20 63 2e 66 6c 65 78  |/* Title: c.flex|
000003e0  0a 20 2a 20 50 75 72 70  6f 73 65 3a 20 70 72 6f  |. * Purpose: pro|
000003f0  76 69 64 65 20 6d 65 6d  6f 72 79 20 61 6c 6c 6f  |vide memory allo|
00000400  63 61 74 69 6f 6e 20 66  6f 72 20 69 6e 74 65 72  |cation for inter|
00000410  61 63 74 69 76 65 20 70  72 6f 67 72 61 6d 73 20  |active programs |
00000420  72 65 71 75 69 72 69 6e  67 0a 20 2a 20 20 20 20  |requiring. *    |
00000430  20 20 20 20 20 20 6c 61  72 67 65 20 63 68 75 6e  |      large chun|
00000440  6b 73 20 6f 66 20 73 74  6f 72 65 2e 0a 20 2a 20  |ks of store.. * |
00000450  48 69 73 74 6f 72 79 3a  20 49 44 4a 3a 20 30 36  |History: IDJ: 06|
00000460  2d 46 65 62 2d 39 32 3a  20 70 72 65 70 61 72 65  |-Feb-92: prepare|
00000470  64 20 66 6f 72 20 73 6f  75 72 63 65 20 72 65 6c  |d for source rel|
00000480  65 61 73 65 0a 20 2a 20  20 20 20 20 20 20 20 20  |ease. *         |
00000490  20 41 6e 64 79 20 41 72  6d 73 74 72 6f 6e 67 3a  | Andy Armstrong:|
000004a0  20 20 32 31 2d 4f 63 74  2d 39 34 3a 20 6d 6f 64  |  21-Oct-94: mod|
000004b0  69 66 69 65 64 20 74 6f  20 75 73 65 20 64 79 6e  |ified to use dyn|
000004c0  61 6d 69 63 20 61 72 65  61 73 20 61 6e 64 20 63  |amic areas and c|
000004d0  61 6c 6c 62 61 63 6b 73  2e 0a 20 2a 20 20 20 20  |allbacks.. *    |
000004e0  20 20 20 20 20 20 44 61  76 69 64 20 4a 61 63 6b  |      David Jack|
000004f0  73 6f 6e 20 3a 20 20 30  36 2d 53 65 70 2d 39 35  |son :  06-Sep-95|
00000500  3a 20 6d 6f 64 69 66 69  65 64 20 74 6f 20 75 73  |: modified to us|
00000510  65 20 56 69 72 74 75 61  6c 20 4d 65 6d 6f 72 79  |e Virtual Memory|
00000520  0a 20 2a 20 20 20 20 20  20 20 20 20 20 44 61 76  |. *          Dav|
00000530  69 64 20 4a 61 63 6b 73  6f 6e 20 3a 20 20 31 39  |id Jackson :  19|
00000540  2d 41 70 72 2d 39 36 3a  20 6d 6f 64 69 66 69 65  |-Apr-96: modifie|
00000550  64 20 74 6f 20 75 73 65  20 41 63 6f 72 6e 20 54  |d to use Acorn T|
00000560  6f 6f 6c 62 6f 78 20 28  55 67 68 21 29 0a 20 2a  |oolbox (Ugh!). *|
00000570  2f 0a 0a 23 64 65 66 69  6e 65 20 42 4f 4f 4c 20  |/..#define BOOL |
00000580  69 6e 74 0a 23 64 65 66  69 6e 65 20 54 52 55 45  |int.#define TRUE|
00000590  20 31 0a 23 64 65 66 69  6e 65 20 46 41 4c 53 45  | 1.#define FALSE|
000005a0  20 30 0a 23 64 65 66 69  6e 65 20 54 52 41 43 45  | 0.#define TRACE|
000005b0  20 30 0a 0a 23 69 6e 63  6c 75 64 65 20 3c 73 74  | 0..#include <st|
000005c0  64 6c 69 62 2e 68 3e 0a  23 69 6e 63 6c 75 64 65  |dlib.h>.#include|
000005d0  20 3c 73 74 64 61 72 67  2e 68 3e 0a 23 69 6e 63  | <stdarg.h>.#inc|
000005e0  6c 75 64 65 20 3c 73 74  72 69 6e 67 2e 68 3e 0a  |lude <string.h>.|
000005f0  23 69 6e 63 6c 75 64 65  20 3c 73 74 64 69 6f 2e  |#include <stdio.|
00000600  68 3e 0a 23 69 6e 63 6c  75 64 65 20 22 6b 65 72  |h>.#include "ker|
00000610  6e 65 6c 2e 68 22 0a 23  69 6e 63 6c 75 64 65 20  |nel.h".#include |
00000620  22 73 77 69 73 2e 68 22  0a 23 69 6e 63 6c 75 64  |"swis.h".#includ|
00000630  65 20 22 68 2e 66 6c 65  78 22 0a 23 69 6e 63 6c  |e "h.flex".#incl|
00000640  75 64 65 20 22 77 69 6d  70 6c 69 62 2e 68 22 0a  |ude "wimplib.h".|
00000650  0a 0a 2f 2a 20 23 69 6e  63 6c 75 64 65 20 22 74  |../* #include "t|
00000660  72 61 63 6b 65 72 2e 68  22 20 2a 2f 0a 0a 23 69  |racker.h" */..#i|
00000670  66 6e 64 65 66 20 4f 53  5f 44 79 6e 61 6d 69 63  |fndef OS_Dynamic|
00000680  41 72 65 61 0a 23 64 65  66 69 6e 65 20 4f 53 5f  |Area.#define OS_|
00000690  44 79 6e 61 6d 69 63 41  72 65 61 20 20 30 78 30  |DynamicArea  0x0|
000006a0  30 30 36 36 0a 23 65 6e  64 69 66 0a 0a 23 69 66  |0066.#endif..#if|
000006b0  6e 64 65 66 20 56 69 72  74 75 61 6c 69 73 65 5f  |ndef Virtualise_|
000006c0  43 6f 6e 66 69 67 75 72  65 20 20 20 20 20 20 20  |Configure       |
000006d0  20 20 20 0a 23 64 65 66  69 6e 65 20 56 69 72 74  |   .#define Virt|
000006e0  75 61 6c 69 73 65 5f 43  6f 6e 66 69 67 75 72 65  |ualise_Configure|
000006f0  20 20 20 20 20 20 20 20  20 20 20 30 78 30 34 62  |           0x04b|
00000700  36 63 30 0a 23 65 6e 64  69 66 0a 23 69 66 6e 64  |6c0.#endif.#ifnd|
00000710  65 66 20 56 69 72 74 75  61 6c 69 73 65 5f 53 74  |ef Virtualise_St|
00000720  61 72 74 20 20 20 20 20  20 20 20 20 20 20 20 20  |art             |
00000730  20 0a 23 64 65 66 69 6e  65 20 56 69 72 74 75 61  | .#define Virtua|
00000740  6c 69 73 65 5f 53 74 61  72 74 20 20 20 20 20 20  |lise_Start      |
00000750  20 20 20 20 20 20 20 20  20 30 78 30 34 62 36 63  |         0x04b6c|
00000760  31 0a 23 65 6e 64 69 66  0a 23 69 66 6e 64 65 66  |1.#endif.#ifndef|
00000770  20 56 69 72 74 75 61 6c  69 73 65 5f 45 6e 64 20  | Virtualise_End |
00000780  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 0a  |               .|
00000790  23 64 65 66 69 6e 65 20  56 69 72 74 75 61 6c 69  |#define Virtuali|
000007a0  73 65 5f 45 6e 64 20 20  20 20 20 20 20 20 20 20  |se_End          |
000007b0  20 20 20 20 20 20 20 30  78 30 34 62 36 63 32 0a  |       0x04b6c2.|
000007c0  23 65 6e 64 69 66 0a 23  69 66 6e 64 65 66 20 56  |#endif.#ifndef V|
000007d0  69 72 74 75 61 6c 69 73  65 5f 4c 6f 63 6b 20 20  |irtualise_Lock  |
000007e0  20 20 20 20 20 20 20 20  20 20 20 20 20 0a 23 64  |             .#d|
000007f0  65 66 69 6e 65 20 56 69  72 74 75 61 6c 69 73 65  |efine Virtualise|
00000800  5f 4c 6f 63 6b 20 20 20  20 20 20 20 20 20 20 20  |_Lock           |
00000810  20 20 20 20 20 30 78 30  34 62 36 63 33 0a 23 65  |     0x04b6c3.#e|
00000820  6e 64 69 66 0a 23 69 66  6e 64 65 66 20 56 69 72  |ndif.#ifndef Vir|
00000830  74 75 61 6c 69 73 65 5f  55 6e 6c 6f 63 6b 20 20  |tualise_Unlock  |
00000840  20 20 20 20 20 20 20 20  20 20 20 0a 23 64 65 66  |           .#def|
00000850  69 6e 65 20 56 69 72 74  75 61 6c 69 73 65 5f 55  |ine Virtualise_U|
00000860  6e 6c 6f 63 6b 20 20 20  20 20 20 20 20 20 20 20  |nlock           |
00000870  20 20 20 30 78 30 34 62  36 63 34 0a 23 65 6e 64  |   0x04b6c4.#end|
00000880  69 66 0a 23 69 66 6e 64  65 66 20 56 69 72 74 75  |if.#ifndef Virtu|
00000890  61 6c 69 73 65 5f 4d 69  73 63 4f 70 20 20 20 20  |alise_MiscOp    |
000008a0  20 20 20 20 20 20 20 20  20 0a 23 64 65 66 69 6e  |         .#defin|
000008b0  65 20 56 69 72 74 75 61  6c 69 73 65 5f 4d 69 73  |e Virtualise_Mis|
000008c0  63 4f 70 20 20 20 20 20  20 20 20 20 20 20 20 20  |cOp             |
000008d0  20 30 78 30 34 62 36 63  35 0a 23 65 6e 64 69 66  | 0x04b6c5.#endif|
000008e0  0a 20 0a 0a 0a 73 74 61  74 69 63 20 69 6e 74 20  |. ...static int |
000008f0  66 6c 65 78 5f 5f 69 6e  69 74 69 61 6c 69 73 65  |flex__initialise|
00000900  64 20 3d 20 30 3b 0a 73  74 61 74 69 63 20 69 6e  |d = 0;.static in|
00000910  74 20 66 6c 65 78 5f 5f  64 61 20 20 20 20 20 20  |t flex__da      |
00000920  20 20 20 20 3d 20 2d 31  3b 20 2f 2a 20 6f 72 20  |    = -1; /* or |
00000930  64 61 20 6e 75 6d 62 65  72 20 2a 2f 0a 73 74 61  |da number */.sta|
00000940  74 69 63 20 42 4f 4f 4c  20 66 6c 65 78 5f 5f 56  |tic BOOL flex__V|
00000950  4d 20 20 20 20 20 20 20  20 20 3d 20 46 41 4c 53  |M         = FALS|
00000960  45 3b 20 20 2f 2a 20 69  73 20 56 4d 20 69 6e 20  |E;  /* is VM in |
00000970  75 73 65 3f 20 2a 2f 20  0a 73 74 61 74 69 63 20  |use? */ .static |
00000980  69 6e 74 20 20 5f 6d 62  6c 6b 3b 0a 0a 73 74 61  |int  _mblk;..sta|
00000990  74 69 63 20 76 6f 69 64  20 77 65 72 72 28 69 6e  |tic void werr(in|
000009a0  74 20 66 61 74 61 6c 2c  20 63 68 61 72 2a 20 66  |t fatal, char* f|
000009b0  6f 72 6d 61 74 2c 20 2e  2e 2e 29 3b 0a 73 74 61  |ormat, ...);.sta|
000009c0  74 69 63 20 63 68 61 72  2a 20 6d 73 67 73 5f 6c  |tic char* msgs_l|
000009d0  6f 6f 6b 75 70 28 63 68  61 72 2a 20 74 61 67 29  |ookup(char* tag)|
000009e0  3b 0a 0a 0a 2f 2a 20 54  68 69 73 20 69 6d 70 6c  |;.../* This impl|
000009f0  65 6d 65 6e 74 61 74 69  6f 6e 20 67 6f 65 73 20  |ementation goes |
00000a00  61 62 6f 76 65 20 74 68  65 20 6f 72 69 67 69 6e  |above the origin|
00000a10  61 6c 20 76 61 6c 75 65  20 6f 66 20 47 65 74 45  |al value of GetE|
00000a20  6e 76 2c 0a 74 6f 20 6d  65 6d 6f 72 79 20 73 70  |nv,.to memory sp|
00000a30  65 63 69 66 69 63 61 6c  6c 79 20 72 65 71 75 65  |ecifically reque|
00000a40  73 74 65 64 20 66 72 6f  6d 20 74 68 65 20 57 69  |sted from the Wi|
00000a50  6d 70 2e 20 54 68 65 20  68 65 61 70 20 69 73 20  |mp. The heap is |
00000a60  6b 65 70 74 0a 74 6f 74  61 6c 6c 79 20 63 6f 6d  |kept.totally com|
00000a70  70 61 63 74 65 64 20 61  6c 6c 20 74 68 65 20 74  |pacted all the t|
00000a80  69 6d 65 2c 20 77 69 74  68 20 70 61 67 65 73 20  |ime, with pages |
00000a90  62 65 69 6e 67 20 67 69  76 65 6e 20 62 61 63 6b  |being given back|
00000aa0  20 74 6f 0a 74 68 65 20  57 69 6d 70 20 77 68 65  | to.the Wimp whe|
00000ab0  6e 65 76 65 72 20 70 6f  73 73 69 62 6c 65 2e 20  |never possible. |
00000ac0  2a 2f 0a 0a 74 79 70 65  64 65 66 20 73 74 72 75  |*/..typedef stru|
00000ad0  63 74 20 7b 0a 20 20 66  6c 65 78 5f 70 74 72 20  |ct {.  flex_ptr |
00000ae0  61 6e 63 68 6f 72 3b 20  20 20 20 20 20 2f 2a 20  |anchor;      /* |
00000af0  2a 61 6e 63 68 6f 72 20  73 68 6f 75 6c 64 20 70  |*anchor should p|
00000b00  6f 69 6e 74 20 62 61 63  6b 20 74 6f 20 68 65 72  |oint back to her|
00000b10  65 2e 20 2a 2f 0a 23 69  66 64 65 66 20 66 6c 65  |e. */.#ifdef fle|
00000b20  78 5f 43 41 4c 4c 42 41  43 4b 0a 20 20 66 6c 65  |x_CALLBACK.  fle|
00000b30  78 5f 63 62 66 75 6e 63  20 63 62 3b 0a 20 20 76  |x_cbfunc cb;.  v|
00000b40  6f 69 64 20 2a 68 61 6e  64 6c 65 3b 0a 23 65 6e  |oid *handle;.#en|
00000b50  64 69 66 20 20 20 20 0a  20 20 69 6e 74 20 73 69  |dif    .  int si|
00000b60  7a 65 3b 20 20 20 20 20  20 20 20 20 20 20 20 20  |ze;             |
00000b70  2f 2a 20 69 6e 20 62 79  74 65 73 2e 20 45 78 61  |/* in bytes. Exa|
00000b80  63 74 20 73 69 7a 65 20  6f 66 20 6c 6f 67 69 63  |ct size of logic|
00000b90  61 6c 20 61 72 65 61 2e  20 2a 2f 0a 20 20 20 20  |al area. */.    |
00000ba0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000bb0  20 20 20 20 2f 2a 20 74  68 65 6e 20 74 68 65 20  |    /* then the |
00000bc0  61 63 74 75 61 6c 20 73  74 6f 72 65 20 66 6f 6c  |actual store fol|
00000bd0  6c 6f 77 73 2e 20 2a 2f  0a 7d 20 66 6c 65 78 5f  |lows. */.} flex_|
00000be0  5f 72 65 63 3b 0a 0a 0a  73 74 61 74 69 63 20 76  |_rec;...static v|
00000bf0  6f 69 64 20 66 6c 65 78  5f 5f 66 61 69 6c 28 69  |oid flex__fail(i|
00000c00  6e 74 20 69 29 0a 7b 0a  20 20 20 77 65 72 72 28  |nt i).{.   werr(|
00000c10  54 52 55 45 2c 20 6d 73  67 73 5f 6c 6f 6f 6b 75  |TRUE, msgs_looku|
00000c20  70 28 22 66 6c 65 78 31  3a 46 6c 65 78 20 6d 65  |p("flex1:Flex me|
00000c30  6d 6f 72 79 20 65 72 72  6f 72 20 28 25 64 29 22  |mory error (%d)"|
00000c40  29 2c 20 69 29 3b 0a 23  69 66 20 54 52 41 43 45  |), i);.#if TRACE|
00000c50  0a 20 20 20 69 20 3d 20  2a 28 69 6e 74 20 2a 29  |.   i = *(int *)|
00000c60  2d 34 20 3b 20 20 20 20  20 2f 2a 20 67 6f 20 62  |-4 ;     /* go b|
00000c70  61 6e 67 21 20 2a 2f 0a  23 65 6c 73 65 0a 20 20  |ang! */.#else.  |
00000c80  20 69 20 3d 20 69 3b 20  2f 2a 20 61 76 6f 69 64  | i = i; /* avoid|
00000c90  20 63 6f 6d 70 69 6c 65  72 20 77 61 72 6e 69 6e  | compiler warnin|
00000ca0  67 2e 20 2a 2f 0a 23 65  6e 64 69 66 0a 7d 0a 0a  |g. */.#endif.}..|
00000cb0  0a 73 74 61 74 69 63 20  76 6f 69 64 20 66 6c 65  |.static void fle|
00000cc0  78 5f 5f 63 68 65 63 6b  28 76 6f 69 64 29 0a 7b  |x__check(void).{|
00000cd0  0a 20 20 20 69 66 28 66  6c 65 78 5f 5f 69 6e 69  |.   if(flex__ini|
00000ce0  74 69 61 6c 69 73 65 64  20 3d 3d 20 30 29 0a 20  |tialised == 0). |
00000cf0  20 20 20 20 77 65 72 72  28 54 52 55 45 2c 20 6d  |    werr(TRUE, m|
00000d00  73 67 73 5f 6c 6f 6f 6b  75 70 28 22 66 6c 65 78  |sgs_lookup("flex|
00000d10  33 3a 46 6c 65 78 20 6e  6f 74 20 69 6e 69 74 69  |3:Flex not initi|
00000d20  61 6c 69 73 65 64 22 29  29 3b 0a 7d 0a 0a 0a 0a  |alised"));.}....|
00000d30  2f 2a 20 6d 61 63 72 6f  20 74 6f 20 61 76 6f 69  |/* macro to avoi|
00000d40  64 20 73 74 61 63 6b 20  75 73 61 67 65 20 2a 2f  |d stack usage */|
00000d50  0a 23 64 65 66 69 6e 65  20 72 6f 75 6e 64 75 70  |.#define roundup|
00000d60  28 6e 29 20 20 28 30 78  66 66 66 66 66 66 66 63  |(n)  (0xfffffffc|
00000d70  20 26 20 28 6e 20 2b 20  33 29 29 0a 0a 73 74 61  | & (n + 3))..sta|
00000d80  74 69 63 20 63 68 61 72  20 2a 66 6c 65 78 5f 5f  |tic char *flex__|
00000d90  62 61 73 65 3b 20 20 20  20 20 20 20 20 2f 2a 20  |base;        /* |
00000da0  6c 6f 77 65 73 74 20 66  6c 65 78 5f 5f 72 65 63  |lowest flex__rec|
00000db0  20 2d 20 6f 6e 6c 79 20  66 6f 72 20 62 75 64 67  | - only for budg|
00000dc0  69 6e 67 2e 20 2a 2f 0a  73 74 61 74 69 63 20 63  |ing. */.static c|
00000dd0  68 61 72 20 2a 66 6c 65  78 5f 5f 66 72 65 65 70  |har *flex__freep|
00000de0  3b 20 20 20 20 20 20 20  2f 2a 20 66 72 65 65 20  |;       /* free |
00000df0  66 6c 65 78 20 6d 65 6d  6f 72 79 20 2a 2f 0a 73  |flex memory */.s|
00000e00  74 61 74 69 63 20 63 68  61 72 20 2a 66 6c 65 78  |tatic char *flex|
00000e10  5f 5f 6c 69 6d 3b 20 20  20 20 20 20 20 20 20 2f  |__lim;         /|
00000e20  2a 20 6c 69 6d 69 74 20  6f 66 20 66 6c 65 78 20  |* limit of flex |
00000e30  6d 65 6d 6f 72 79 20 2a  2f 0a 2f 2a 20 46 72 6f  |memory */./* Fro|
00000e40  6d 20 62 61 73 65 20 75  70 77 61 72 64 73 2c 20  |m base upwards, |
00000e50  69 74 27 73 20 64 69 76  69 64 65 64 20 69 6e 74  |it's divided int|
00000e60  6f 20 73 74 6f 72 65 20  62 6c 6f 63 6b 73 20 6f  |o store blocks o|
00000e70  66 0a 20 20 61 20 66 6c  65 78 5f 5f 72 65 63 0a  |f.  a flex__rec.|
00000e80  20 20 74 68 65 20 73 70  61 63 65 0a 20 20 61 6c  |  the space.  al|
00000e90  69 67 6e 20 75 70 20 74  6f 20 6e 65 78 74 20 77  |ign up to next w|
00000ea0  6f 72 64 2e 0a 2a 2f 0a  0a 0a 73 74 61 74 69 63  |ord..*/...static|
00000eb0  20 76 6f 69 64 20 66 6c  65 78 5f 5f 77 69 6d 70  | void flex__wimp|
00000ec0  73 6c 6f 74 28 63 68 61  72 20 2a 2a 74 6f 70 29  |slot(char **top)|
00000ed0  20 0a 7b 0a 20 20 20 2f  2a 20 72 65 61 64 2f 77  | .{.   /* read/w|
00000ee0  72 69 74 65 20 74 68 65  20 74 6f 70 20 6f 66 20  |rite the top of |
00000ef0  61 76 61 69 6c 61 62 6c  65 20 6d 65 6d 6f 72 79  |available memory|
00000f00  2e 20 2a 74 6f 70 20 3d  3d 20 30 20 2d 3e 20 6a  |. *top == 0 -> j|
00000f10  75 73 74 20 72 65 61 64  2e 20 2a 2f 0a 20 20 20  |ust read. */.   |
00000f20  69 6e 74 20 64 75 64 20  3d 20 2d 31 3b 0a 20 20  |int dud = -1;.  |
00000f30  20 69 6e 74 20 73 6c 6f  74 20 3d 20 28 28 69 6e  | int slot = ((in|
00000f40  74 29 20 2a 74 6f 70 29  3b 0a 20 20 20 5f 6b 65  |t) *top);.   _ke|
00000f50  72 6e 65 6c 5f 73 77 69  5f 72 65 67 73 20 72 3b  |rnel_swi_regs r;|
00000f60  0a 20 20 20 5f 6b 65 72  6e 65 6c 5f 6f 73 65 72  |.   _kernel_oser|
00000f70  72 6f 72 20 20 2a 65 72  72 3b 0a 20 20 20 69 6e  |ror  *err;.   in|
00000f80  74 20 6d 65 6d 6c 69 6d  2c 20 61 70 70 73 70 61  |t memlim, appspa|
00000f90  63 65 2c 20 6f 6c 64 6d  65 6d 6c 69 6d 3b 0a 0a  |ce, oldmemlim;..|
00000fa0  20 20 20 69 66 20 28 73  6c 6f 74 20 21 3d 20 2d  |   if (slot != -|
00000fb0  31 29 20 73 6c 6f 74 20  2d 3d 20 30 78 38 30 30  |1) slot -= 0x800|
00000fc0  30 3b 0a 0a 20 20 20 2f  2a 20 72 65 61 64 20 6d  |0;..   /* read m|
00000fd0  65 6d 6f 72 79 20 6c 69  6d 69 74 20 76 61 6c 75  |emory limit valu|
00000fe0  65 20 2a 2f 0a 20 20 20  20 72 2e 72 5b 30 5d 20  |e */.    r.r[0] |
00000ff0  3d 20 30 3b 0a 20 20 20  20 72 2e 72 5b 31 5d 20  |= 0;.    r.r[1] |
00001000  3d 20 30 3b 0a 20 20 20  20 72 2e 72 5b 32 5d 20  |= 0;.    r.r[2] |
00001010  3d 20 30 3b 0a 20 20 20  20 65 72 72 20 3d 20 5f  |= 0;.    err = _|
00001020  6b 65 72 6e 65 6c 5f 73  77 69 28 4f 53 5f 43 68  |kernel_swi(OS_Ch|
00001030  61 6e 67 65 45 6e 76 69  72 6f 6e 6d 65 6e 74 2c  |angeEnvironment,|
00001040  20 26 72 2c 20 26 72 29  3b 0a 20 20 20 20 6f 6c  | &r, &r);.    ol|
00001050  64 6d 65 6d 6c 69 6d 20  3d 20 6d 65 6d 6c 69 6d  |dmemlim = memlim|
00001060  20 3d 20 72 2e 72 5b 31  5d 3b 0a 0a 20 20 20 2f  | = r.r[1];..   /|
00001070  2a 20 72 65 61 64 20 61  70 70 73 70 61 63 65 20  |* read appspace |
00001080  76 61 6c 75 65 20 2a 2f  0a 20 20 20 20 72 2e 72  |value */.    r.r|
00001090  5b 30 5d 20 3d 20 31 34  3b 20 20 2f 2a 20 41 70  |[0] = 14;  /* Ap|
000010a0  70 6c 69 63 61 74 69 6f  6e 20 73 70 61 63 65 20  |plication space |
000010b0  2a 2f 0a 20 20 20 20 72  2e 72 5b 31 5d 20 3d 20  |*/.    r.r[1] = |
000010c0  30 3b 0a 20 20 20 20 72  2e 72 5b 32 5d 20 3d 20  |0;.    r.r[2] = |
000010d0  30 3b 0a 20 20 20 20 65  72 72 20 3d 20 5f 6b 65  |0;.    err = _ke|
000010e0  72 6e 65 6c 5f 73 77 69  28 4f 53 5f 43 68 61 6e  |rnel_swi(OS_Chan|
000010f0  67 65 45 6e 76 69 72 6f  6e 6d 65 6e 74 2c 20 26  |geEnvironment, &|
00001100  72 2c 20 26 72 29 3b 0a  20 20 20 20 61 70 70 73  |r, &r);.    apps|
00001110  70 61 63 65 20 3d 20 72  2e 72 5b 31 5d 3b 0a 20  |pace = r.r[1];. |
00001120  20 20 2f 2a 20 73 65 74  20 6d 65 6d 6f 72 79 20  |  /* set memory |
00001130  6c 69 6d 69 74 20 62 65  66 6f 72 65 20 73 6c 6f  |limit before slo|
00001140  74 20 73 69 7a 65 20 63  68 61 6e 67 65 20 2e 2e  |t size change ..|
00001150  2e 20 2a 2f 0a 20 20 20  20 69 66 28 61 70 70 73  |. */.    if(apps|
00001160  70 61 63 65 20 3e 20 6d  65 6d 6c 69 6d 29 0a 20  |pace > memlim). |
00001170  20 20 20 7b 0a 20 20 20  20 20 20 20 72 2e 72 5b  |   {.       r.r[|
00001180  30 5d 20 3d 20 30 3b 0a  20 20 20 20 20 20 20 72  |0] = 0;.       r|
00001190  2e 72 5b 31 5d 20 3d 20  61 70 70 73 70 61 63 65  |.r[1] = appspace|
000011a0  3b 0a 20 20 20 20 20 20  20 72 2e 72 5b 32 5d 20  |;.       r.r[2] |
000011b0  3d 20 30 3b 0a 20 20 20  20 20 20 20 65 72 72 20  |= 0;.       err |
000011c0  3d 20 5f 6b 65 72 6e 65  6c 5f 73 77 69 28 4f 53  |= _kernel_swi(OS|
000011d0  5f 43 68 61 6e 67 65 45  6e 76 69 72 6f 6e 6d 65  |_ChangeEnvironme|
000011e0  6e 74 2c 20 26 72 2c 20  26 72 29 3b 0a 20 20 20  |nt, &r, &r);.   |
000011f0  20 7d 0a 0a 20 20 20 2f  2a 20 73 65 74 20 77 69  | }..   /* set wi|
00001200  6d 70 73 6c 6f 74 20 73  69 7a 65 20 28 6f 72 20  |mpslot size (or |
00001210  72 65 61 64 20 69 74 29  20 2a 2f 0a 20 20 20 0a  |read it) */.   .|
00001220  20 20 20 69 66 20 28 77  69 6d 70 5f 73 6c 6f 74  |   if (wimp_slot|
00001230  5f 73 69 7a 65 28 73 6c  6f 74 2c 64 75 64 2c 26  |_size(slot,dud,&|
00001240  73 6c 6f 74 2c 20 26 64  75 64 2c 20 26 64 75 64  |slot, &dud, &dud|
00001250  29 21 3d 4e 55 4c 4c 29  20 77 65 72 72 28 54 52  |)!=NULL) werr(TR|
00001260  55 45 2c 6d 73 67 73 5f  6c 6f 6f 6b 75 70 28 22  |UE,msgs_lookup("|
00001270  66 61 74 61 6c 3a 46 61  74 61 6c 20 46 6c 65 78  |fatal:Fatal Flex|
00001280  20 6d 65 6d 6f 72 79 20  65 72 72 6f 72 22 29 29  | memory error"))|
00001290  3b 0a 0a 20 20 20 2a 74  6f 70 20 3d 20 28 63 68  |;..   *top = (ch|
000012a0  61 72 2a 29 20 73 6c 6f  74 20 2b 20 30 78 38 30  |ar*) slot + 0x80|
000012b0  30 30 3b 0a 0a 20 20 20  2f 2a 20 2e 2e 2e 2e 20  |00;..   /* .... |
000012c0  61 6e 64 20 73 65 74 20  6d 65 6d 6f 72 79 20 6c  |and set memory l|
000012d0  69 6d 69 74 20 62 61 63  6b 20 61 67 61 69 6e 20  |imit back again |
000012e0  2a 2f 0a 20 20 20 69 66  20 28 61 70 70 73 70 61  |*/.   if (appspa|
000012f0  63 65 20 3e 20 6d 65 6d  6c 69 6d 29 0a 20 20 20  |ce > memlim).   |
00001300  7b 0a 20 20 20 20 20 20  20 72 2e 72 5b 30 5d 20  |{.       r.r[0] |
00001310  3d 20 30 3b 0a 20 20 20  20 20 20 20 72 2e 72 5b  |= 0;.       r.r[|
00001320  31 5d 20 3d 20 6f 6c 64  6d 65 6d 6c 69 6d 3b 0a  |1] = oldmemlim;.|
00001330  20 20 20 20 20 20 20 72  2e 72 5b 32 5d 20 3d 20  |       r.r[2] = |
00001340  30 3b 0a 20 20 20 20 20  20 20 65 72 72 20 3d 20  |0;.       err = |
00001350  5f 6b 65 72 6e 65 6c 5f  73 77 69 28 4f 53 5f 43  |_kernel_swi(OS_C|
00001360  68 61 6e 67 65 45 6e 76  69 72 6f 6e 6d 65 6e 74  |hangeEnvironment|
00001370  2c 20 26 72 2c 20 26 72  29 3b 0a 20 20 20 20 7d  |, &r, &r);.    }|
00001380  0a 20 20 20 20 20 20 20  0a 7d 0a 0a 73 74 61 74  |.       .}..stat|
00001390  69 63 20 42 4f 4f 4c 20  66 6c 65 78 5f 5f 6d 6f  |ic BOOL flex__mo|
000013a0  72 65 28 69 6e 74 20 6e  29 0a 7b 0a 20 20 20 2f  |re(int n).{.   /|
000013b0  2a 20 54 72 69 65 73 20  74 6f 20 67 65 74 20 61  |* Tries to get a|
000013c0  74 20 6c 65 61 73 74 20  6e 20 6d 6f 72 65 20 62  |t least n more b|
000013d0  79 74 65 73 2c 20 72 61  69 73 69 6e 67 20 66 6c  |ytes, raising fl|
000013e0  65 78 5f 5f 6c 69 6d 20  61 6e 64 0a 20 20 20 72  |ex__lim and.   r|
000013f0  65 74 75 72 6e 69 6e 67  20 54 52 55 45 20 69 66  |eturning TRUE if|
00001400  20 69 74 20 63 61 6e 2e  20 2a 2f 0a 20 20 20 63  | it can. */.   c|
00001410  68 61 72 20 2a 70 72 65  76 20 3d 20 66 6c 65 78  |har *prev = flex|
00001420  5f 5f 6c 69 6d 3b 0a 0a  20 20 20 69 66 20 28 66  |__lim;..   if (f|
00001430  6c 65 78 5f 5f 64 61 20  21 3d 20 2d 31 29 0a 20  |lex__da != -1). |
00001440  20 20 7b 20 20 5f 6b 65  72 6e 65 6c 5f 73 77 69  |  {  _kernel_swi|
00001450  5f 72 65 67 73 20 72 65  67 73 3b 0a 20 20 20 20  |_regs regs;.    |
00001460  20 20 5f 6b 65 72 6e 65  6c 5f 6f 73 65 72 72 6f  |  _kernel_oserro|
00001470  72 20 2a 65 72 72 3b 0a  0a 20 20 20 20 20 20 72  |r *err;..      r|
00001480  65 67 73 2e 72 5b 30 5d  20 3d 20 66 6c 65 78 5f  |egs.r[0] = flex_|
00001490  5f 64 61 3b 0a 20 20 20  20 20 20 72 65 67 73 2e  |_da;.      regs.|
000014a0  72 5b 31 5d 20 3d 20 6e  3b 0a 0a 20 20 20 20 20  |r[1] = n;..     |
000014b0  20 65 72 72 20 3d 20 5f  6b 65 72 6e 65 6c 5f 73  | err = _kernel_s|
000014c0  77 69 28 4f 53 5f 43 68  61 6e 67 65 44 79 6e 61  |wi(OS_ChangeDyna|
000014d0  6d 69 63 41 72 65 61 2c  20 26 72 65 67 73 2c 20  |micArea, &regs, |
000014e0  26 72 65 67 73 29 3b 0a  20 20 20 20 20 20 0a 20  |&regs);.      . |
000014f0  20 20 20 20 20 69 66 20  28 65 72 72 20 7c 7c 20  |     if (err || |
00001500  72 65 67 73 2e 72 5b 31  5d 20 3c 20 6e 29 0a 20  |regs.r[1] < n). |
00001510  20 20 20 20 20 7b 20 20  72 65 67 73 2e 72 5b 31  |     {  regs.r[1|
00001520  5d 20 3d 20 2d 72 65 67  73 2e 72 5b 31 5d 3b 0a  |] = -regs.r[1];.|
00001530  20 20 20 20 20 20 20 20  20 5f 6b 65 72 6e 65 6c  |         _kernel|
00001540  5f 73 77 69 28 4f 53 5f  43 68 61 6e 67 65 44 79  |_swi(OS_ChangeDy|
00001550  6e 61 6d 69 63 41 72 65  61 2c 20 26 72 65 67 73  |namicArea, &regs|
00001560  2c 20 26 72 65 67 73 29  3b 0a 20 20 20 20 20 20  |, &regs);.      |
00001570  20 20 20 72 65 74 75 72  6e 20 46 41 4c 53 45 3b  |   return FALSE;|
00001580  0a 20 20 20 20 20 20 7d  0a 0a 20 20 20 20 20 20  |.      }..      |
00001590  65 72 72 20 3d 20 5f 6b  65 72 6e 65 6c 5f 73 77  |err = _kernel_sw|
000015a0  69 28 4f 53 5f 52 65 61  64 44 79 6e 61 6d 69 63  |i(OS_ReadDynamic|
000015b0  41 72 65 61 2c 20 26 72  65 67 73 2c 20 26 72 65  |Area, &regs, &re|
000015c0  67 73 29 3b 0a 20 20 20  20 20 20 66 6c 65 78 5f  |gs);.      flex_|
000015d0  5f 6c 69 6d 20 3d 20 66  6c 65 78 5f 5f 62 61 73  |_lim = flex__bas|
000015e0  65 20 2b 20 72 65 67 73  2e 72 5b 31 5d 3b 0a 20  |e + regs.r[1];. |
000015f0  20 20 20 20 20 72 65 74  75 72 6e 20 54 52 55 45  |     return TRUE|
00001600  3b 0a 20 20 20 7d 0a 20  20 20 65 6c 73 65 0a 20  |;.   }.   else. |
00001610  20 20 7b 20 20 66 6c 65  78 5f 5f 6c 69 6d 20 2b  |  {  flex__lim +|
00001620  3d 20 6e 3b 0a 20 20 20  20 20 20 66 6c 65 78 5f  |= n;.      flex_|
00001630  5f 77 69 6d 70 73 6c 6f  74 28 26 66 6c 65 78 5f  |_wimpslot(&flex_|
00001640  5f 6c 69 6d 29 3b 0a 0a  20 20 20 0a 20 20 20 20  |_lim);..   .    |
00001650  20 20 69 66 20 28 66 6c  65 78 5f 5f 6c 69 6d 20  |  if (flex__lim |
00001660  3c 20 70 72 65 76 20 2b  20 6e 29 0a 20 20 20 20  |< prev + n).    |
00001670  20 20 7b 0a 20 20 20 20  20 20 20 20 20 66 6c 65  |  {.         fle|
00001680  78 5f 5f 6c 69 6d 20 3d  20 70 72 65 76 3b 20 20  |x__lim = prev;  |
00001690  20 20 20 20 20 20 20 20  20 20 20 2f 2a 20 72 65  |           /* re|
000016a0  73 74 6f 72 65 20 73 74  61 72 74 69 6e 67 20 73  |store starting s|
000016b0  74 61 74 65 3a 0a 20 20  20 20 20 20 20 20 20 20  |tate:.          |
000016c0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000016e0  65 78 74 72 61 20 6d 65  6d 6f 72 79 20 69 73 20  |extra memory is |
000016f0  75 73 65 6c 65 73 73 20  2a 2f 0a 20 20 20 20 20  |useless */.     |
00001700  20 20 20 20 66 6c 65 78  5f 5f 77 69 6d 70 73 6c  |    flex__wimpsl|
00001710  6f 74 28 26 66 6c 65 78  5f 5f 6c 69 6d 29 3b 0a  |ot(&flex__lim);.|
00001720  20 20 20 20 20 20 20 20  20 72 65 74 75 72 6e 20  |         return |
00001730  46 41 4c 53 45 20 3b 0a  20 20 20 20 20 20 7d 0a  |FALSE ;.      }.|
00001740  20 20 20 20 20 20 65 6c  73 65 20 0a 20 20 20 20  |      else .    |
00001750  20 20 20 20 20 72 65 74  75 72 6e 20 54 52 55 45  |     return TRUE|
00001760  20 3b 0a 20 20 20 7d 0a  7d 0a 0a 0a 73 74 61 74  | ;.   }.}...stat|
00001770  69 63 20 76 6f 69 64 20  66 6c 65 78 5f 5f 67 69  |ic void flex__gi|
00001780  76 65 28 76 6f 69 64 29  20 0a 7b 0a 20 20 20 69  |ve(void) .{.   i|
00001790  66 20 28 66 6c 65 78 5f  5f 64 61 20 21 3d 20 2d  |f (flex__da != -|
000017a0  31 29 0a 20 20 20 7b 20  20 5f 6b 65 72 6e 65 6c  |1).   {  _kernel|
000017b0  5f 73 77 69 5f 72 65 67  73 20 72 65 67 73 3b 0a  |_swi_regs regs;.|
000017c0  20 20 20 20 20 20 5f 6b  65 72 6e 65 6c 5f 6f 73  |      _kernel_os|
000017d0  65 72 72 6f 72 20 2a 65  72 72 3b 0a 20 20 20 20  |error *err;.    |
000017e0  20 20 0a 20 20 20 20 20  20 72 65 67 73 2e 72 5b  |  .      regs.r[|
000017f0  30 5d 20 3d 20 66 6c 65  78 5f 5f 64 61 3b 0a 20  |0] = flex__da;. |
00001800  20 20 20 20 20 72 65 67  73 2e 72 5b 31 5d 20 3d  |     regs.r[1] =|
00001810  20 66 6c 65 78 5f 5f 66  72 65 65 70 20 2d 20 66  | flex__freep - f|
00001820  6c 65 78 5f 5f 6c 69 6d  3b 20 2f 2a 20 2d 76 65  |lex__lim; /* -ve|
00001830  20 2a 2f 0a 0a 20 20 20  20 20 20 65 72 72 20 3d  | */..      err =|
00001840  20 5f 6b 65 72 6e 65 6c  5f 73 77 69 28 4f 53 5f  | _kernel_swi(OS_|
00001850  43 68 61 6e 67 65 44 79  6e 61 6d 69 63 41 72 65  |ChangeDynamicAre|
00001860  61 2c 20 26 72 65 67 73  2c 20 26 72 65 67 73 29  |a, &regs, &regs)|
00001870  3b 0a 20 20 20 20 20 20  69 66 20 28 21 65 72 72  |;.      if (!err|
00001880  29 0a 20 20 20 20 20 20  7b 20 20 65 72 72 20 3d  |).      {  err =|
00001890  20 5f 6b 65 72 6e 65 6c  5f 73 77 69 28 4f 53 5f  | _kernel_swi(OS_|
000018a0  52 65 61 64 44 79 6e 61  6d 69 63 41 72 65 61 2c  |ReadDynamicArea,|
000018b0  20 26 72 65 67 73 2c 20  26 72 65 67 73 29 3b 0a  | &regs, &regs);.|
000018c0  20 20 20 20 20 20 20 20  20 66 6c 65 78 5f 5f 6c  |         flex__l|
000018d0  69 6d 20 3d 20 66 6c 65  78 5f 5f 62 61 73 65 20  |im = flex__base |
000018e0  2b 20 72 65 67 73 2e 72  5b 31 5d 3b 0a 20 20 20  |+ regs.r[1];.   |
000018f0  20 20 20 7d 0a 20 20 20  7d 0a 20 20 20 65 6c 73  |   }.   }.   els|
00001900  65 0a 20 20 20 7b 0a 20  20 20 20 20 20 2f 2a 20  |e.   {.      /* |
00001910  47 69 76 65 73 20 61 77  61 79 20 6d 65 6d 6f 72  |Gives away memor|
00001920  79 2c 20 6c 6f 77 65 72  69 6e 67 20 66 6c 65 78  |y, lowering flex|
00001930  5f 5f 6c 69 6d 2c 20 69  66 20 70 6f 73 73 69 62  |__lim, if possib|
00001940  6c 65 2e 20 2a 2f 0a 23  69 66 20 54 52 41 43 45  |le. */.#if TRACE|
00001950  0a 20 20 20 20 20 20 69  6e 74 20 70 72 65 76 20  |.      int prev |
00001960  3d 20 28 69 6e 74 29 20  66 6c 65 78 5f 5f 6c 69  |= (int) flex__li|
00001970  6d 3b 0a 23 65 6e 64 69  66 0a 20 20 20 0a 20 20  |m;.#endif.   .  |
00001980  20 20 20 20 66 6c 65 78  5f 5f 6c 69 6d 20 3d 20  |    flex__lim = |
00001990  66 6c 65 78 5f 5f 66 72  65 65 70 3b 0a 20 20 20  |flex__freep;.   |
000019a0  20 20 20 66 6c 65 78 5f  5f 77 69 6d 70 73 6c 6f  |   flex__wimpslo|
000019b0  74 28 26 66 6c 65 78 5f  5f 6c 69 6d 29 3b 0a 0a  |t(&flex__lim);..|
000019c0  20 20 20 7d 0a 7d 0a 0a  0a 73 74 61 74 69 63 20  |   }.}...static |
000019d0  42 4f 4f 4c 20 66 6c 65  78 5f 5f 65 6e 73 75 72  |BOOL flex__ensur|
000019e0  65 28 69 6e 74 20 6e 29  20 0a 7b 0a 20 20 20 6e  |e(int n) .{.   n|
000019f0  20 2d 3d 20 66 6c 65 78  5f 5f 6c 69 6d 20 2d 20  | -= flex__lim - |
00001a00  66 6c 65 78 5f 5f 66 72  65 65 70 3b 0a 0a 20 20  |flex__freep;..  |
00001a10  20 69 66 20 28 6e 20 3c  3d 20 30 20 7c 7c 20 66  | if (n <= 0 || f|
00001a20  6c 65 78 5f 5f 6d 6f 72  65 28 6e 29 29 20 0a 20  |lex__more(n)) . |
00001a30  20 20 20 20 20 72 65 74  75 72 6e 20 54 52 55 45  |     return TRUE|
00001a40  3b 20 0a 20 20 20 65 6c  73 65 20 72 65 74 75 72  |; .   else retur|
00001a50  6e 20 46 41 4c 53 45 3b  0a 7d 0a 0a 42 4f 4f 4c  |n FALSE;.}..BOOL|
00001a60  20 66 6c 65 78 5f 61 6c  6c 6f 63 28 66 6c 65 78  | flex_alloc(flex|
00001a70  5f 70 74 72 20 61 6e 63  68 6f 72 2c 20 69 6e 74  |_ptr anchor, int|
00001a80  20 6e 29 0a 7b 0a 20 20  20 66 6c 65 78 5f 5f 72  | n).{.   flex__r|
00001a90  65 63 20 2a 70 3b 0a 0a  20 20 20 66 6c 65 78 5f  |ec *p;..   flex_|
00001aa0  5f 63 68 65 63 6b 28 29  3b 0a 0a 20 20 20 69 66  |_check();..   if|
00001ab0  20 28 6e 20 3c 20 30 20  7c 7c 20 21 20 66 6c 65  | (n < 0 || ! fle|
00001ac0  78 5f 5f 65 6e 73 75 72  65 28 73 69 7a 65 6f 66  |x__ensure(sizeof|
00001ad0  28 66 6c 65 78 5f 5f 72  65 63 29 20 2b 20 72 6f  |(flex__rec) + ro|
00001ae0  75 6e 64 75 70 28 6e 29  29 29 20 0a 20 20 20 7b  |undup(n))) .   {|
00001af0  0a 20 20 20 20 20 20 2a  61 6e 63 68 6f 72 20 3d  |.      *anchor =|
00001b00  20 30 3b 0a 20 20 20 20  20 20 72 65 74 75 72 6e  | 0;.      return|
00001b10  20 46 41 4c 53 45 3b 0a  20 20 20 7d 0a 0a 20 20  | FALSE;.   }..  |
00001b20  20 70 20 3d 20 28 66 6c  65 78 5f 5f 72 65 63 2a  | p = (flex__rec*|
00001b30  29 20 66 6c 65 78 5f 5f  66 72 65 65 70 3b 0a 20  |) flex__freep;. |
00001b40  20 20 66 6c 65 78 5f 5f  66 72 65 65 70 20 2b 3d  |  flex__freep +=|
00001b50  20 73 69 7a 65 6f 66 28  66 6c 65 78 5f 5f 72 65  | sizeof(flex__re|
00001b60  63 29 20 2b 20 72 6f 75  6e 64 75 70 28 6e 29 3b  |c) + roundup(n);|
00001b70  0a 0a 20 20 20 70 2d 3e  61 6e 63 68 6f 72 20 3d  |..   p->anchor =|
00001b80  20 61 6e 63 68 6f 72 3b  0a 20 20 20 70 2d 3e 73  | anchor;.   p->s|
00001b90  69 7a 65 20 3d 20 6e 3b  0a 23 69 66 64 65 66 20  |ize = n;.#ifdef |
00001ba0  66 6c 65 78 5f 43 41 4c  4c 42 41 43 4b 0a 20 20  |flex_CALLBACK.  |
00001bb0  20 70 2d 3e 63 62 20 3d  20 4e 55 4c 4c 3b 0a 20  | p->cb = NULL;. |
00001bc0  20 20 70 2d 3e 68 61 6e  64 6c 65 20 3d 20 4e 55  |  p->handle = NU|
00001bd0  4c 4c 3b 0a 23 65 6e 64  69 66 20 20 20 20 20 20  |LL;.#endif      |
00001be0  0a 20 20 20 2a 61 6e 63  68 6f 72 20 3d 20 70 20  |.   *anchor = p |
00001bf0  2b 20 31 3b 20 2f 2a 20  73 69 7a 65 6f 66 28 66  |+ 1; /* sizeof(f|
00001c00  6c 65 78 5f 5f 72 65 63  29 2c 20 74 68 61 74 20  |lex__rec), that |
00001c10  69 73 20 2a 2f 0a 20 20  20 72 65 74 75 72 6e 20  |is */.   return |
00001c20  54 52 55 45 3b 0a 7d 0a  0a 73 74 61 74 69 63 20  |TRUE;.}..static |
00001c30  76 6f 69 64 20 66 6c 65  78 5f 5f 72 65 61 6e 63  |void flex__reanc|
00001c40  68 6f 72 28 66 6c 65 78  5f 5f 72 65 63 20 2a 70  |hor(flex__rec *p|
00001c50  2c 20 69 6e 74 20 62 79  29 20 0a 7b 0a 20 20 20  |, int by) .{.   |
00001c60  2f 2a 20 4d 6f 76 65 20  61 6c 6c 20 74 68 65 20  |/* Move all the |
00001c70  61 6e 63 68 6f 72 73 20  66 72 6f 6d 20 70 20 75  |anchors from p u|
00001c80  70 77 61 72 64 73 2e 20  54 68 69 73 20 69 73 20  |pwards. This is |
00001c90  69 6e 20 61 6e 74 69 63  69 70 61 74 69 6f 6e 0a  |in anticipation.|
00001ca0  20 20 20 6f 66 20 74 68  61 74 20 62 6c 6f 63 6b  |   of that block|
00001cb0  20 6f 66 20 74 68 65 20  68 65 61 70 20 62 65 69  | of the heap bei|
00001cc0  6e 67 20 73 68 69 66 74  65 64 2e 20 2a 2f 0a 0a  |ng shifted. */..|
00001cd0  20 20 20 77 68 69 6c 65  20 28 31 29 20 0a 20 20  |   while (1) .  |
00001ce0  20 7b 0a 20 20 20 20 20  20 69 66 20 28 28 69 6e  | {.      if ((in|
00001cf0  74 29 20 70 20 3e 3d 20  28 69 6e 74 29 20 66 6c  |t) p >= (int) fl|
00001d00  65 78 5f 5f 66 72 65 65  70 29 20 62 72 65 61 6b  |ex__freep) break|
00001d10  3b 0a 0a 20 20 20 20 20  20 69 66 20 28 2a 28 70  |;..      if (*(p|
00001d20  2d 3e 61 6e 63 68 6f 72  29 20 21 3d 20 70 20 2b  |->anchor) != p +|
00001d30  20 31 29 20 66 6c 65 78  5f 5f 66 61 69 6c 28 36  | 1) flex__fail(6|
00001d40  29 3b 0a 20 20 20 20 20  20 2a 28 70 2d 3e 61 6e  |);.      *(p->an|
00001d50  63 68 6f 72 29 20 3d 20  28 28 63 68 61 72 2a 29  |chor) = ((char*)|
00001d60  20 28 70 20 2b 20 31 29  29 20 2b 20 62 79 3b 0a  | (p + 1)) + by;.|
00001d70  20 20 20 20 20 20 70 20  3d 20 28 66 6c 65 78 5f  |      p = (flex_|
00001d80  5f 72 65 63 2a 29 20 28  28 28 63 68 61 72 2a 29  |_rec*) (((char*)|
00001d90  20 28 70 20 2b 20 31 29  29 20 2b 20 72 6f 75 6e  | (p + 1)) + roun|
00001da0  64 75 70 28 70 2d 3e 73  69 7a 65 29 29 3b 0a 20  |dup(p->size));. |
00001db0  20 20 7d 0a 7d 0a 0a 2f  2a 20 4e 6f 74 69 66 79  |  }.}../* Notify|
00001dc0  20 61 6c 6c 20 74 68 65  20 62 6c 6f 63 6b 73 20  | all the blocks |
00001dd0  61 66 74 65 72 20 61 6e  64 20 69 6e 63 6c 75 64  |after and includ|
00001de0  69 6e 67 20 70 20 74 68  61 74 20 74 68 65 20 61  |ing p that the a|
00001df0  72 65 20 61 62 6f 75 74  20 74 6f 20 6d 6f 76 65  |re about to move|
00001e00  20 2f 20 68 61 76 65 0a  20 6d 6f 76 65 64 20 2a  | / have. moved *|
00001e10  2f 0a 0a 23 69 66 64 65  66 20 66 6c 65 78 5f 43  |/..#ifdef flex_C|
00001e20  41 4c 4c 42 41 43 4b 0a  23 64 65 66 69 6e 65 20  |ALLBACK.#define |
00001e30  66 6c 65 78 5f 5f 69 6e  6c 69 6e 65 6e 6f 74 69  |flex__inlinenoti|
00001e40  66 79 28 62 34 2c 20 70  29 20 20 20 20 20 20 20  |fy(b4, p)       |
00001e50  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001e60  20 20 20 20 20 20 20 20  20 20 20 20 20 5c 0a 20  |             \. |
00001e70  20 20 64 6f 20 20 20 20  20 20 20 20 20 20 20 20  |  do            |
00001e80  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00001eb0  20 20 20 20 5c 0a 20 20  20 7b 20 20 66 6c 65 78  |    \.   {  flex|
00001ec0  5f 5f 72 65 63 20 2a 70  32 20 3d 20 28 70 29 3b  |__rec *p2 = (p);|
00001ed0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00001ef0  20 20 20 20 20 20 20 20  20 20 20 5c 0a 20 20 20  |           \.   |
00001f00  20 20 20 66 6f 72 20 28  3b 3b 29 20 20 20 20 20  |   for (;;)     |
00001f10  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00001f40  20 20 5c 0a 20 20 20 20  20 20 7b 20 20 69 66 20  |  \.      {  if |
00001f50  28 28 69 6e 74 29 20 70  32 20 3e 3d 20 28 69 6e  |((int) p2 >= (in|
00001f60  74 29 20 66 6c 65 78 5f  5f 66 72 65 65 70 29 20  |t) flex__freep) |
00001f70  62 72 65 61 6b 3b 20 20  20 20 20 20 20 20 20 20  |break;          |
00001f80  20 20 20 20 20 20 20 20  20 5c 0a 20 20 20 20 20  |         \.     |
00001f90  20 20 20 20 69 66 20 28  2a 28 70 32 2d 3e 61 6e  |    if (*(p2->an|
00001fa0  63 68 6f 72 29 20 21 3d  20 70 32 20 2b 20 31 29  |chor) != p2 + 1)|
00001fb0  20 66 6c 65 78 5f 5f 66  61 69 6c 28 36 29 3b 20  | flex__fail(6); |
00001fc0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00001fd0  5c 0a 20 20 20 20 20 20  20 20 20 69 66 20 28 70  |\.         if (p|
00001fe0  32 2d 3e 63 62 29 20 70  32 2d 3e 63 62 28 62 34  |2->cb) p2->cb(b4|
00001ff0  2c 20 70 32 2d 3e 68 61  6e 64 6c 65 29 3b 20 20  |, p2->handle);  |
00002000  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002010  20 20 20 20 20 20 20 5c  0a 20 20 20 20 20 20 20  |       \.       |
00002020  20 20 70 32 20 3d 20 28  66 6c 65 78 5f 5f 72 65  |  p2 = (flex__re|
00002030  63 2a 29 20 28 28 28 63  68 61 72 2a 29 20 28 70  |c*) (((char*) (p|
00002040  32 20 2b 20 31 29 29 20  2b 20 72 6f 75 6e 64 75  |2 + 1)) + roundu|
00002050  70 28 70 32 2d 3e 73 69  7a 65 29 29 3b 20 5c 0a  |p(p2->size)); \.|
00002060  20 20 20 20 20 20 7d 20  20 20 20 20 20 20 20 20  |      }         |
00002070  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000020a0  20 20 20 20 20 5c 0a 20  20 20 7d 20 77 68 69 6c  |     \.   } whil|
000020b0  65 20 28 30 29 0a 0a 73  74 61 74 69 63 20 76 6f  |e (0)..static vo|
000020c0  69 64 20 66 6c 65 78 5f  5f 6e 6f 74 69 66 79 28  |id flex__notify(|
000020d0  42 4f 4f 4c 20 62 34 2c  20 66 6c 65 78 5f 5f 72  |BOOL b4, flex__r|
000020e0  65 63 20 2a 70 29 0a 7b  20 20 66 6c 65 78 5f 5f  |ec *p).{  flex__|
000020f0  69 6e 6c 69 6e 65 6e 6f  74 69 66 79 28 62 34 2c  |inlinenotify(b4,|
00002100  20 70 29 3b 0a 7d 0a 0a  23 65 6c 73 65 0a 23 64  | p);.}..#else.#d|
00002110  65 66 69 6e 65 20 66 6c  65 78 5f 5f 69 6e 6c 69  |efine flex__inli|
00002120  6e 65 6e 6f 74 69 66 79  28 62 34 2c 20 70 29 20  |nenotify(b4, p) |
00002130  28 76 6f 69 64 29 20 30  0a 23 64 65 66 69 6e 65  |(void) 0.#define|
00002140  20 66 6c 65 78 5f 5f 6e  6f 74 69 66 79 28 62 34  | flex__notify(b4|
00002150  2c 20 70 29 20 28 76 6f  69 64 29 20 30 0a 23 65  |, p) (void) 0.#e|
00002160  6e 64 69 66 0a 0a 76 6f  69 64 20 66 6c 65 78 5f  |ndif..void flex_|
00002170  66 72 65 65 28 66 6c 65  78 5f 70 74 72 20 61 6e  |free(flex_ptr an|
00002180  63 68 6f 72 29 0a 7b 0a  20 20 20 66 6c 65 78 5f  |chor).{.   flex_|
00002190  5f 72 65 63 20 2a 70 20  3d 20 28 28 66 6c 65 78  |_rec *p = ((flex|
000021a0  5f 5f 72 65 63 2a 29 20  2a 61 6e 63 68 6f 72 29  |__rec*) *anchor)|
000021b0  20 2d 20 31 3b 0a 20 20  20 69 6e 74 20 72 6f 75  | - 1;.   int rou|
000021c0  6e 64 73 69 7a 65 20 3d  20 72 6f 75 6e 64 75 70  |ndsize = roundup|
000021d0  28 70 2d 3e 73 69 7a 65  29 3b 0a 20 20 20 66 6c  |(p->size);.   fl|
000021e0  65 78 5f 5f 72 65 63 20  2a 6e 65 78 74 20 3d 20  |ex__rec *next = |
000021f0  28 66 6c 65 78 5f 5f 72  65 63 2a 29 20 28 28 28  |(flex__rec*) (((|
00002200  63 68 61 72 2a 29 20 28  70 20 2b 20 31 29 29 20  |char*) (p + 1)) |
00002210  2b 20 72 6f 75 6e 64 73  69 7a 65 29 3b 0a 0a 20  |+ roundsize);.. |
00002220  20 20 66 6c 65 78 5f 5f  63 68 65 63 6b 28 29 3b  |  flex__check();|
00002230  0a 0a 20 20 20 69 66 20  28 70 2d 3e 61 6e 63 68  |..   if (p->anch|
00002240  6f 72 20 21 3d 20 61 6e  63 68 6f 72 29 20 0a 20  |or != anchor) . |
00002250  20 20 7b 0a 20 20 20 20  20 20 66 6c 65 78 5f 5f  |  {.      flex__|
00002260  66 61 69 6c 28 30 29 3b  0a 20 20 20 7d 0a 0a 20  |fail(0);.   }.. |
00002270  20 20 66 6c 65 78 5f 5f  6e 6f 74 69 66 79 28 54  |  flex__notify(T|
00002280  52 55 45 2c 20 6e 65 78  74 29 3b 0a 20 20 20 66  |RUE, next);.   f|
00002290  6c 65 78 5f 5f 72 65 61  6e 63 68 6f 72 28 6e 65  |lex__reanchor(ne|
000022a0  78 74 2c 20 2d 20 28 73  69 7a 65 6f 66 28 66 6c  |xt, - (sizeof(fl|
000022b0  65 78 5f 5f 72 65 63 29  20 2b 20 72 6f 75 6e 64  |ex__rec) + round|
000022c0  73 69 7a 65 29 29 3b 0a  20 20 20 6d 65 6d 6d 6f  |size));.   memmo|
000022d0  76 65 28 70 2c 20 6e 65  78 74 2c 20 66 6c 65 78  |ve(p, next, flex|
000022e0  5f 5f 66 72 65 65 70 20  2d 20 28 63 68 61 72 2a  |__freep - (char*|
000022f0  29 20 6e 65 78 74 29 3b  0a 20 20 20 66 6c 65 78  |) next);.   flex|
00002300  5f 5f 66 72 65 65 70 20  2d 3d 20 73 69 7a 65 6f  |__freep -= sizeo|
00002310  66 28 66 6c 65 78 5f 5f  72 65 63 29 20 2b 20 72  |f(flex__rec) + r|
00002320  6f 75 6e 64 73 69 7a 65  3b 0a 20 20 20 66 6c 65  |oundsize;.   fle|
00002330  78 5f 5f 6e 6f 74 69 66  79 28 46 41 4c 53 45 2c  |x__notify(FALSE,|
00002340  20 70 29 3b 0a 0a 20 20  20 66 6c 65 78 5f 5f 67  | p);..   flex__g|
00002350  69 76 65 28 29 3b 0a 0a  20 20 20 2a 61 6e 63 68  |ive();..   *anch|
00002360  6f 72 20 3d 20 30 3b 0a  7d 0a 0a 0a 69 6e 74 20  |or = 0;.}...int |
00002370  66 6c 65 78 5f 73 69 7a  65 28 66 6c 65 78 5f 70  |flex_size(flex_p|
00002380  74 72 20 61 6e 63 68 6f  72 29 0a 20 7b 0a 20 20  |tr anchor). {.  |
00002390  20 66 6c 65 78 5f 5f 72  65 63 20 2a 70 20 3d 20  | flex__rec *p = |
000023a0  28 28 66 6c 65 78 5f 5f  72 65 63 2a 29 20 2a 61  |((flex__rec*) *a|
000023b0  6e 63 68 6f 72 29 20 2d  20 31 3b 0a 20 20 20 66  |nchor) - 1;.   f|
000023c0  6c 65 78 5f 5f 63 68 65  63 6b 28 29 3b 0a 0a 20  |lex__check();.. |
000023d0  20 20 69 66 20 28 70 2d  3e 61 6e 63 68 6f 72 20  |  if (p->anchor |
000023e0  21 3d 20 61 6e 63 68 6f  72 29 20 0a 20 20 20 7b  |!= anchor) .   {|
000023f0  0a 20 20 20 20 20 20 66  6c 65 78 5f 5f 66 61 69  |.      flex__fai|
00002400  6c 28 34 29 3b 0a 20 20  20 7d 0a 0a 20 20 20 72  |l(4);.   }..   r|
00002410  65 74 75 72 6e 28 70 2d  3e 73 69 7a 65 29 3b 0a  |eturn(p->size);.|
00002420  7d 0a 0a 0a 69 6e 74 20  66 6c 65 78 5f 65 78 74  |}...int flex_ext|
00002430  65 6e 64 28 66 6c 65 78  5f 70 74 72 20 61 6e 63  |end(flex_ptr anc|
00002440  68 6f 72 2c 20 69 6e 74  20 6e 65 77 73 69 7a 65  |hor, int newsize|
00002450  29 0a 7b 0a 20 20 20 66  6c 65 78 5f 5f 72 65 63  |).{.   flex__rec|
00002460  20 2a 70 20 3d 20 28 28  66 6c 65 78 5f 5f 72 65  | *p = ((flex__re|
00002470  63 2a 29 20 2a 61 6e 63  68 6f 72 29 20 2d 20 31  |c*) *anchor) - 1|
00002480  3b 0a 20 20 20 66 6c 65  78 5f 5f 63 68 65 63 6b  |;.   flex__check|
00002490  28 29 3b 0a 20 20 20 72  65 74 75 72 6e 28 66 6c  |();.   return(fl|
000024a0  65 78 5f 6d 69 64 65 78  74 65 6e 64 28 61 6e 63  |ex_midextend(anc|
000024b0  68 6f 72 2c 20 70 2d 3e  73 69 7a 65 2c 20 6e 65  |hor, p->size, ne|
000024c0  77 73 69 7a 65 20 2d 20  70 2d 3e 73 69 7a 65 29  |wsize - p->size)|
000024d0  29 3b 0a 7d 0a 0a 0a 42  4f 4f 4c 20 66 6c 65 78  |);.}...BOOL flex|
000024e0  5f 6d 69 64 65 78 74 65  6e 64 28 66 6c 65 78 5f  |_midextend(flex_|
000024f0  70 74 72 20 61 6e 63 68  6f 72 2c 20 69 6e 74 20  |ptr anchor, int |
00002500  61 74 2c 20 69 6e 74 20  62 79 29 0a 7b 0a 20 20  |at, int by).{.  |
00002510  20 66 6c 65 78 5f 5f 72  65 63 20 2a 70 3b 0a 20  | flex__rec *p;. |
00002520  20 20 66 6c 65 78 5f 5f  72 65 63 20 2a 6e 65 78  |  flex__rec *nex|
00002530  74 3b 0a 0a 20 20 20 66  6c 65 78 5f 5f 63 68 65  |t;..   flex__che|
00002540  63 6b 28 29 3b 0a 0a 20  20 20 70 20 3d 20 28 28  |ck();..   p = ((|
00002550  66 6c 65 78 5f 5f 72 65  63 2a 29 20 2a 61 6e 63  |flex__rec*) *anc|
00002560  68 6f 72 29 20 2d 20 31  3b 0a 0a 20 20 20 69 66  |hor) - 1;..   if|
00002570  20 28 70 2d 3e 61 6e 63  68 6f 72 20 21 3d 20 61  | (p->anchor != a|
00002580  6e 63 68 6f 72 29 20 0a  20 20 20 20 20 20 66 6c  |nchor) .      fl|
00002590  65 78 5f 5f 66 61 69 6c  28 31 29 3b 0a 0a 20 20  |ex__fail(1);..  |
000025a0  20 69 66 20 28 61 74 20  3e 20 70 2d 3e 73 69 7a  | if (at > p->siz|
000025b0  65 29 20 0a 20 20 20 20  20 20 66 6c 65 78 5f 5f  |e) .      flex__|
000025c0  66 61 69 6c 28 32 29 3b  0a 0a 20 20 20 69 66 20  |fail(2);..   if |
000025d0  28 62 79 20 3c 20 30 20  26 26 20 28 2d 62 79 29  |(by < 0 && (-by)|
000025e0  20 3e 20 61 74 29 20 0a  20 20 20 20 20 20 66 6c  | > at) .      fl|
000025f0  65 78 5f 5f 66 61 69 6c  28 33 29 3b 0a 0a 20 20  |ex__fail(3);..  |
00002600  20 69 66 20 28 62 79 20  3d 3d 20 30 29 20 0a 20  | if (by == 0) . |
00002610  20 20 7b 0a 20 20 20 20  20 20 2f 2a 20 64 6f 20  |  {.      /* do |
00002620  6e 6f 74 68 69 6e 67 20  2a 2f 0a 20 20 20 7d 0a  |nothing */.   }.|
00002630  20 20 20 65 6c 73 65 20  69 66 20 28 62 79 20 3e  |   else if (by >|
00002640  20 30 29 20 0a 20 20 20  7b 20 0a 20 20 20 20 20  | 0) .   { .     |
00002650  20 2f 2a 20 65 78 74 65  6e 64 20 2a 2f 0a 0a 20  | /* extend */.. |
00002660  20 20 20 20 20 69 6e 74  20 67 72 6f 77 74 68 20  |     int growth |
00002670  3d 20 72 6f 75 6e 64 75  70 28 70 2d 3e 73 69 7a  |= roundup(p->siz|
00002680  65 20 2b 20 62 79 29 20  2d 20 72 6f 75 6e 64 75  |e + by) - roundu|
00002690  70 28 70 2d 3e 73 69 7a  65 29 3b 0a 20 20 20 20  |p(p->size);.    |
000026a0  20 20 2f 2a 20 41 6d 6f  75 6e 74 20 62 79 20 77  |  /* Amount by w|
000026b0  68 69 63 68 20 74 68 65  20 62 6c 6f 63 6b 20 77  |hich the block w|
000026c0  69 6c 6c 20 61 63 74 75  61 6c 6c 79 20 67 72 6f  |ill actually gro|
000026d0  77 2e 20 2a 2f 0a 0a 20  20 20 20 20 20 69 66 20  |w. */..      if |
000026e0  28 21 20 66 6c 65 78 5f  5f 65 6e 73 75 72 65 28  |(! flex__ensure(|
000026f0  67 72 6f 77 74 68 29 29  20 0a 20 20 20 20 20 20  |growth)) .      |
00002700  20 20 20 72 65 74 75 72  6e 20 46 41 4c 53 45 3b  |   return FALSE;|
00002710  0a 0a 20 20 20 20 20 20  6e 65 78 74 20 3d 20 28  |..      next = (|
00002720  66 6c 65 78 5f 5f 72 65  63 2a 29 20 28 28 28 63  |flex__rec*) (((c|
00002730  68 61 72 2a 29 20 28 70  20 2b 20 31 29 29 20 2b  |har*) (p + 1)) +|
00002740  20 72 6f 75 6e 64 75 70  28 70 2d 3e 73 69 7a 65  | roundup(p->size|
00002750  29 29 3b 0a 20 20 20 20  20 20 2f 2a 20 54 68 65  |));.      /* The|
00002760  20 6d 6f 76 65 20 68 61  73 20 74 6f 20 68 61 70  | move has to hap|
00002770  70 65 6e 20 69 6e 20 74  77 6f 20 70 61 72 74 73  |pen in two parts|
00002780  20 62 65 63 61 75 73 65  20 74 68 65 20 6d 6f 76  | because the mov|
00002790  69 6e 67 0a 20 20 20 20  20 20 6f 66 20 6f 62 6a  |ing.      of obj|
000027a0  65 63 74 73 20 61 62 6f  76 65 20 69 73 20 77 6f  |ects above is wo|
000027b0  72 64 2d 61 6c 69 67 6e  65 64 2c 20 77 68 69 6c  |rd-aligned, whil|
000027c0  65 20 74 68 65 20 65 78  74 65 6e 73 69 6f 6e 20  |e the extension |
000027d0  77 69 74 68 69 6e 0a 20  20 20 20 20 20 74 68 65  |within.      the|
000027e0  20 6f 62 6a 65 63 74 20  6d 61 79 20 6e 6f 74 20  | object may not |
000027f0  62 65 2e 20 2a 2f 0a 0a  20 20 20 20 20 20 66 6c  |be. */..      fl|
00002800  65 78 5f 5f 6e 6f 74 69  66 79 28 54 52 55 45 2c  |ex__notify(TRUE,|
00002810  20 6e 65 78 74 29 3b 0a  20 20 20 20 20 20 66 6c  | next);.      fl|
00002820  65 78 5f 5f 72 65 61 6e  63 68 6f 72 28 6e 65 78  |ex__reanchor(nex|
00002830  74 2c 20 67 72 6f 77 74  68 29 3b 0a 0a 20 20 20  |t, growth);..   |
00002840  20 20 20 6d 65 6d 6d 6f  76 65 28 28 28 63 68 61  |   memmove(((cha|
00002850  72 2a 29 20 6e 65 78 74  29 20 2b 20 72 6f 75 6e  |r*) next) + roun|
00002860  64 75 70 28 67 72 6f 77  74 68 29 2c 20 6e 65 78  |dup(growth), nex|
00002870  74 2c 20 66 6c 65 78 5f  5f 66 72 65 65 70 20 2d  |t, flex__freep -|
00002880  20 28 63 68 61 72 2a 29  20 6e 65 78 74 0a 29 3b  | (char*) next.);|
00002890  0a 0a 20 20 20 20 20 20  66 6c 65 78 5f 5f 66 72  |..      flex__fr|
000028a0  65 65 70 20 2b 3d 20 67  72 6f 77 74 68 3b 0a 20  |eep += growth;. |
000028b0  20 20 20 20 20 66 6c 65  78 5f 5f 6e 6f 74 69 66  |     flex__notif|
000028c0  79 28 46 41 4c 53 45 2c  20 28 66 6c 65 78 5f 5f  |y(FALSE, (flex__|
000028d0  72 65 63 20 2a 29 20 28  28 28 63 68 61 72 20 2a  |rec *) (((char *|
000028e0  29 20 6e 65 78 74 29 20  2b 20 72 6f 75 6e 64 75  |) next) + roundu|
000028f0  70 28 67 72 6f 77 74 68  29 29 29 3b 0a 0a 20 20  |p(growth)));..  |
00002900  20 20 20 20 6d 65 6d 6d  6f 76 65 28 28 28 63 68  |    memmove(((ch|
00002910  61 72 2a 29 20 28 70 20  2b 20 31 29 29 20 2b 20  |ar*) (p + 1)) + |
00002920  61 74 20 2b 20 62 79 2c  20 28 28 63 68 61 72 2a  |at + by, ((char*|
00002930  29 20 28 70 20 2b 20 31  29 29 20 2b 20 61 74 2c  |) (p + 1)) + at,|
00002940  20 70 2d 3e 73 69 7a 65  20 2d 20 61 74 29 0a 3b  | p->size - at).;|
00002950  0a 0a 20 20 20 20 20 20  70 2d 3e 73 69 7a 65 20  |..      p->size |
00002960  2b 3d 20 62 79 3b 0a 0a  20 20 20 7d 20 0a 20 20  |+= by;..   } .  |
00002970  20 65 6c 73 65 20 0a 20  20 20 7b 20 0a 20 20 20  | else .   { .   |
00002980  20 20 20 2f 2a 20 54 68  65 20 62 6c 6f 63 6b 20  |   /* The block |
00002990  73 68 72 69 6e 6b 73 2e  20 2a 2f 0a 20 20 20 20  |shrinks. */.    |
000029a0  20 20 69 6e 74 20 73 68  72 69 6e 6b 61 67 65 3b  |  int shrinkage;|
000029b0  0a 0a 20 20 20 20 20 20  6e 65 78 74 20 3d 20 28  |..      next = (|
000029c0  66 6c 65 78 5f 5f 72 65  63 2a 29 20 28 28 28 63  |flex__rec*) (((c|
000029d0  68 61 72 2a 29 20 28 70  20 2b 20 31 29 29 20 2b  |har*) (p + 1)) +|
000029e0  20 72 6f 75 6e 64 75 70  28 70 2d 3e 73 69 7a 65  | roundup(p->size|
000029f0  29 29 3b 0a 0a 20 20 20  20 20 20 62 79 20 3d 20  |));..      by = |
00002a00  2d 62 79 3b 20 2f 2a 20  61 20 70 6f 73 69 74 69  |-by; /* a positi|
00002a10  76 65 20 76 61 6c 75 65  20 6e 6f 77 20 2a 2f 0a  |ve value now */.|
00002a20  20 20 20 20 20 20 73 68  72 69 6e 6b 61 67 65 20  |      shrinkage |
00002a30  3d 20 72 6f 75 6e 64 75  70 28 70 2d 3e 73 69 7a  |= roundup(p->siz|
00002a40  65 29 20 2d 20 72 6f 75  6e 64 75 70 28 70 2d 3e  |e) - roundup(p->|
00002a50  73 69 7a 65 20 2d 20 62  79 29 3b 0a 20 20 20 20  |size - by);.    |
00002a60  20 20 20 20 2f 2a 20 61  20 70 6f 73 69 74 69 76  |    /* a positiv|
00002a70  65 20 76 61 6c 75 65 20  2a 2f 0a 0a 20 20 20 20  |e value */..    |
00002a80  20 20 6d 65 6d 6d 6f 76  65 28 28 28 63 68 61 72  |  memmove(((char|
00002a90  2a 29 20 28 70 20 2b 20  31 29 29 20 2b 20 61 74  |*) (p + 1)) + at|
00002aa0  20 2d 20 62 79 2c 20 28  28 63 68 61 72 2a 29 20  | - by, ((char*) |
00002ab0  28 70 20 2b 20 31 29 29  20 2b 20 61 74 2c 20 70  |(p + 1)) + at, p|
00002ac0  2d 3e 73 69 7a 65 20 2d  20 61 74 29 0a 3b 0a 0a  |->size - at).;..|
00002ad0  20 20 20 20 20 20 70 2d  3e 73 69 7a 65 20 2d 3d  |      p->size -=|
00002ae0  20 62 79 3b 0a 0a 20 20  20 20 20 20 66 6c 65 78  | by;..      flex|
00002af0  5f 5f 6e 6f 74 69 66 79  28 54 52 55 45 2c 20 6e  |__notify(TRUE, n|
00002b00  65 78 74 29 3b 0a 20 20  20 20 20 20 66 6c 65 78  |ext);.      flex|
00002b10  5f 5f 72 65 61 6e 63 68  6f 72 28 6e 65 78 74 2c  |__reanchor(next,|
00002b20  20 2d 20 73 68 72 69 6e  6b 61 67 65 29 3b 0a 0a  | - shrinkage);..|
00002b30  20 20 20 20 20 20 6d 65  6d 6d 6f 76 65 28 28 28  |      memmove(((|
00002b40  63 68 61 72 2a 29 20 6e  65 78 74 29 20 2d 20 73  |char*) next) - s|
00002b50  68 72 69 6e 6b 61 67 65  2c 20 6e 65 78 74 2c 20  |hrinkage, next, |
00002b60  66 6c 65 78 5f 5f 66 72  65 65 70 20 2d 20 28 63  |flex__freep - (c|
00002b70  68 61 72 2a 29 20 6e 65  78 74 29 3b 0a 0a 20 20  |har*) next);..  |
00002b80  20 20 20 20 66 6c 65 78  5f 5f 66 72 65 65 70 20  |    flex__freep |
00002b90  2d 3d 20 73 68 72 69 6e  6b 61 67 65 3b 0a 20 20  |-= shrinkage;.  |
00002ba0  20 20 20 20 66 6c 65 78  5f 5f 6e 6f 74 69 66 79  |    flex__notify|
00002bb0  28 46 41 4c 53 45 2c 20  28 66 6c 65 78 5f 5f 72  |(FALSE, (flex__r|
00002bc0  65 63 20 2a 29 20 28 28  28 63 68 61 72 20 2a 29  |ec *) (((char *)|
00002bd0  20 6e 65 78 74 29 20 2d  20 73 68 72 69 6e 6b 61  | next) - shrinka|
00002be0  67 65 29 29 3b 0a 0a 20  20 20 20 20 20 66 6c 65  |ge));..      fle|
00002bf0  78 5f 5f 67 69 76 65 28  29 3b 0a 0a 20 20 20 7d  |x__give();..   }|
00002c00  20 0a 0a 20 20 20 72 65  74 75 72 6e 20 54 52 55  | ..   return TRU|
00002c10  45 3b 0a 7d 0a 0a 23 69  66 64 65 66 20 66 6c 65  |E;.}..#ifdef fle|
00002c20  78 5f 43 41 4c 4c 42 41  43 4b 0a 76 6f 69 64 20  |x_CALLBACK.void |
00002c30  66 6c 65 78 5f 72 65 67  69 73 74 65 72 28 66 6c  |flex_register(fl|
00002c40  65 78 5f 70 74 72 20 61  6e 63 68 6f 72 2c 20 66  |ex_ptr anchor, f|
00002c50  6c 65 78 5f 63 62 66 75  6e 63 20 63 62 2c 20 76  |lex_cbfunc cb, v|
00002c60  6f 69 64 20 2a 68 61 6e  64 6c 65 29 0a 7b 20 20  |oid *handle).{  |
00002c70  66 6c 65 78 5f 5f 72 65  63 20 2a 70 20 3d 20 28  |flex__rec *p = (|
00002c80  28 66 6c 65 78 5f 5f 72  65 63 2a 29 20 2a 61 6e  |(flex__rec*) *an|
00002c90  63 68 6f 72 29 20 2d 20  31 3b 0a 0a 20 20 20 66  |chor) - 1;..   f|
00002ca0  6c 65 78 5f 5f 63 68 65  63 6b 28 29 3b 0a 0a 20  |lex__check();.. |
00002cb0  20 20 69 66 20 28 70 2d  3e 61 6e 63 68 6f 72 20  |  if (p->anchor |
00002cc0  21 3d 20 61 6e 63 68 6f  72 29 20 0a 20 20 20 7b  |!= anchor) .   {|
00002cd0  0a 20 20 20 20 20 20 66  6c 65 78 5f 5f 66 61 69  |.      flex__fai|
00002ce0  6c 28 34 29 3b 0a 20 20  20 7d 0a 0a 20 20 20 70  |l(4);.   }..   p|
00002cf0  2d 3e 63 62 20 3d 20 63  62 3b 0a 20 20 20 70 2d  |->cb = cb;.   p-|
00002d00  3e 68 61 6e 64 6c 65 20  3d 20 68 61 6e 64 6c 65  |>handle = handle|
00002d10  3b 0a 7d 0a 23 65 6e 64  69 66 0a 0a 2f 2a 20 73  |;.}.#endif../* s|
00002d20  74 61 63 6b 20 63 68 65  63 6b 69 6e 67 20 6f 66  |tack checking of|
00002d30  66 20 2a 2f 0a 23 70 72  61 67 6d 61 20 2d 73 31  |f */.#pragma -s1|
00002d40  0a 0a 2f 2a 20 54 68 65  20 75 6e 64 65 72 6c 79  |../* The underly|
00002d50  69 6e 67 20 73 79 73 74  65 6d 20 61 73 6b 73 20  |ing system asks |
00002d60  75 73 20 74 6f 20 6d 6f  76 65 20 61 6c 6c 20 66  |us to move all f|
00002d70  6c 65 78 20 73 74 6f 72  65 20 75 70 20 28 69 66  |lex store up (if|
00002d80  20 6e 20 2b 76 65 29 20  6f 72 0a 64 6f 77 6e 20  | n +ve) or.down |
00002d90  62 79 20 6e 20 62 79 74  65 73 2e 20 49 66 20 79  |by n bytes. If y|
00002da0  6f 75 20 73 75 63 63 65  65 64 2c 20 70 75 74 20  |ou succeed, put |
00002db0  74 68 65 20 73 74 6f 72  65 20 61 6c 6c 6f 63 61  |the store alloca|
00002dc0  74 65 64 20 69 6e 20 2a  61 20 61 6e 64 20 72 65  |ted in *a and re|
00002dd0  74 75 72 6e 0a 74 68 65  20 73 69 7a 65 2e 20 73  |turn.the size. s|
00002de0  69 7a 65 20 3e 3d 20 72  6f 75 6e 64 75 70 28 6e  |ize >= roundup(n|
00002df0  29 20 6f 6e 20 73 75 63  63 65 73 73 66 75 6c 20  |) on successful |
00002e00  65 78 69 74 2c 20 61 6e  64 20 77 69 6c 6c 20 62  |exit, and will b|
00002e10  65 20 61 20 6d 75 6c 74  69 70 6c 65 20 6f 66 0a  |e a multiple of.|
00002e20  66 6f 75 72 2e 20 49 66  20 79 6f 75 20 66 61 69  |four. If you fai|
00002e30  6c 2c 20 72 65 74 75 72  6e 20 77 68 61 74 20 77  |l, return what w|
00002e40  65 20 63 61 6e 2e 20 0a  49 66 20 6e 20 69 73 20  |e can. .If n is |
00002e50  2d 76 65 2c 20 6e 6f 20  72 65 73 75 6c 74 20 69  |-ve, no result i|
00002e60  73 20 72 65 71 75 69 72  65 64 3a 20 73 75 63 63  |s required: succ|
00002e70  65 73 73 20 69 73 20 61  73 73 75 6d 65 64 2e 20  |ess is assumed. |
00002e80  0a 2a 2f 0a 0a 65 78 74  65 72 6e 20 69 6e 74 20  |.*/..extern int |
00002e90  66 6c 65 78 5f 62 75 64  67 65 28 69 6e 74 20 6e  |flex_budge(int n|
00002ea0  2c 20 76 6f 69 64 20 2a  2a 61 29 0a 7b 20 20 69  |, void **a).{  i|
00002eb0  66 20 28 66 6c 65 78 5f  5f 64 61 20 21 3d 20 2d  |f (flex__da != -|
00002ec0  31 29 0a 20 20 20 20 20  20 72 65 74 75 72 6e 20  |1).      return |
00002ed0  66 6c 65 78 5f 64 6f 6e  74 5f 62 75 64 67 65 28  |flex_dont_budge(|
00002ee0  6e 2c 20 61 29 3b 0a 0a  20 20 20 66 6c 65 78 5f  |n, a);..   flex_|
00002ef0  5f 69 6e 6c 69 6e 65 6e  6f 74 69 66 79 28 54 52  |_inlinenotify(TR|
00002f00  55 45 2c 20 28 66 6c 65  78 5f 5f 72 65 63 20 2a  |UE, (flex__rec *|
00002f10  29 20 66 6c 65 78 5f 5f  62 61 73 65 29 3b 0a 0a  |) flex__base);..|
00002f20  20 20 20 69 66 20 28 6e  20 3e 3d 20 30 29 20 2f  |   if (n >= 0) /|
00002f30  2a 20 61 6c 6c 20 6d 6f  76 69 6e 67 20 75 70 20  |* all moving up |
00002f40  2a 2f 0a 20 20 20 7b 0a  20 20 20 20 20 20 69 6e  |*/.   {.      in|
00002f50  74 20 72 6f 75 6e 64 75  70 6e 20 3d 20 72 6f 75  |t roundupn = rou|
00002f60  6e 64 75 70 28 6e 29 3b  0a 20 20 20 20 20 20 69  |ndup(n);.      i|
00002f70  6e 74 20 6d 6f 72 65 20  3d 20 72 6f 75 6e 64 75  |nt more = roundu|
00002f80  70 6e 20 2d 20 28 66 6c  65 78 5f 5f 6c 69 6d 20  |pn - (flex__lim |
00002f90  2d 20 66 6c 65 78 5f 5f  66 72 65 65 70 29 3b 0a  |- flex__freep);.|
00002fa0  20 20 20 20 20 20 0a 20  20 20 20 20 20 2f 2a 20  |      .      /* |
00002fb0  74 72 79 20 74 6f 20 73  61 74 69 73 66 79 20 74  |try to satisfy t|
00002fc0  68 65 20 72 65 71 75 65  73 74 20 2a 2f 0a 20 20  |he request */.  |
00002fd0  20 20 20 20 69 66 20 28  6d 6f 72 65 20 3e 20 30  |    if (more > 0|
00002fe0  29 20 20 20 2f 2a 20 69  65 20 77 65 20 68 61 76  |)   /* ie we hav|
00002ff0  65 20 74 6f 20 69 6e 63  72 65 61 73 65 20 73 6c  |e to increase sl|
00003000  6f 74 20 2a 2f 0a 20 20  20 20 20 20 7b 0a 20 20  |ot */.      {.  |
00003010  20 20 20 20 20 20 20 63  68 61 72 20 2a 70 72 65  |       char *pre|
00003020  76 20 3d 20 66 6c 65 78  5f 5f 6c 69 6d 3b 0a 20  |v = flex__lim;. |
00003030  20 20 20 20 20 20 20 20  66 6c 65 78 5f 5f 6c 69  |        flex__li|
00003040  6d 20 2b 3d 20 6d 6f 72  65 3b 20 0a 0a 20 20 20  |m += more; ..   |
00003050  20 20 20 20 20 20 2f 2a  20 69 6e 2d 6c 69 6e 65  |      /* in-line|
00003060  20 69 6d 70 6c 65 6d 65  6e 74 61 74 69 6f 6e 20  | implementation |
00003070  28 6f 66 20 66 6c 65 78  5f 5f 77 69 6d 70 73 6c  |(of flex__wimpsl|
00003080  6f 74 29 20 20 2a 2f 0a  20 20 20 20 20 20 20 20  |ot)  */.        |
00003090  20 2f 2a 20 20 74 6f 20  72 65 64 75 63 65 20 73  | /*  to reduce s|
000030a0  74 61 63 6b 20 72 65 71  75 69 72 65 6d 65 6e 74  |tack requirement|
000030b0  73 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |s               |
000030c0  2a 2f 0a 20 20 20 20 20  20 20 20 20 7b 0a 20 20  |*/.         {.  |
000030d0  20 20 20 20 20 20 20 20  20 20 69 6e 74 20 73 6c  |          int sl|
000030e0  6f 74 20 3d 20 28 28 69  6e 74 29 20 66 6c 65 78  |ot = ((int) flex|
000030f0  5f 5f 6c 69 6d 29 3b 0a  20 20 20 20 20 20 20 20  |__lim);.        |
00003100  20 20 20 20 5f 6b 65 72  6e 65 6c 5f 73 77 69 5f  |    _kernel_swi_|
00003110  72 65 67 73 20 72 3b 0a  20 20 20 20 20 20 20 20  |regs r;.        |
00003120  20 20 20 20 5f 6b 65 72  6e 65 6c 5f 6f 73 65 72  |    _kernel_oser|
00003130  72 6f 72 20 20 2a 65 72  72 3b 0a 20 20 20 20 20  |ror  *err;.     |
00003140  20 20 20 20 20 20 20 69  6e 74 20 6d 65 6d 6c 69  |       int memli|
00003150  6d 2c 20 61 70 70 73 70  61 63 65 2c 20 6f 6c 64  |m, appspace, old|
00003160  6d 65 6d 6c 69 6d 3b 0a  0a 20 20 20 20 20 20 20  |memlim;..       |
00003170  20 20 20 20 20 69 66 20  28 73 6c 6f 74 20 21 3d  |     if (slot !=|
00003180  20 2d 31 29 20 0a 20 20  20 20 20 20 20 20 20 20  | -1) .          |
00003190  20 20 20 20 20 73 6c 6f  74 20 2d 3d 20 30 78 38  |     slot -= 0x8|
000031a0  30 30 30 3b 0a 0a 20 20  20 20 20 20 20 20 20 20  |000;..          |
000031b0  20 20 2f 2a 20 72 65 61  64 20 6d 65 6d 6f 72 79  |  /* read memory|
000031c0  20 6c 69 6d 69 74 20 76  61 6c 75 65 20 2a 2f 0a  | limit value */.|
000031d0  20 20 20 20 20 20 20 20  20 20 20 20 72 2e 72 5b  |            r.r[|
000031e0  30 5d 20 3d 20 30 3b 0a  20 20 20 20 20 20 20 20  |0] = 0;.        |
000031f0  20 20 20 20 72 2e 72 5b  31 5d 20 3d 20 30 3b 0a  |    r.r[1] = 0;.|
00003200  20 20 20 20 20 20 20 20  20 20 20 20 72 2e 72 5b  |            r.r[|
00003210  32 5d 20 3d 20 30 3b 0a  20 20 20 20 20 20 20 20  |2] = 0;.        |
00003220  20 20 20 20 65 72 72 20  3d 20 5f 6b 65 72 6e 65  |    err = _kerne|
00003230  6c 5f 73 77 69 28 4f 53  5f 43 68 61 6e 67 65 45  |l_swi(OS_ChangeE|
00003240  6e 76 69 72 6f 6e 6d 65  6e 74 2c 20 26 72 2c 20  |nvironment, &r, |
00003250  26 72 29 3b 0a 20 20 20  20 20 20 20 20 20 20 20  |&r);.           |
00003260  20 6f 6c 64 6d 65 6d 6c  69 6d 20 3d 20 6d 65 6d  | oldmemlim = mem|
00003270  6c 69 6d 20 3d 20 72 2e  72 5b 31 5d 3b 0a 0a 20  |lim = r.r[1];.. |
00003280  20 20 20 20 20 20 20 20  20 20 20 2f 2a 20 72 65  |           /* re|
00003290  61 64 20 61 70 70 73 70  61 63 65 20 76 61 6c 75  |ad appspace valu|
000032a0  65 20 2a 2f 0a 20 20 20  20 20 20 20 20 20 20 20  |e */.           |
000032b0  20 72 2e 72 5b 30 5d 20  3d 20 31 34 3b 20 20 2f  | r.r[0] = 14;  /|
000032c0  2a 20 41 70 70 6c 69 63  61 74 69 6f 6e 20 73 70  |* Application sp|
000032d0  61 63 65 20 2a 2f 0a 20  20 20 20 20 20 20 20 20  |ace */.         |
000032e0  20 20 20 72 2e 72 5b 31  5d 20 3d 20 30 3b 0a 20  |   r.r[1] = 0;. |
000032f0  20 20 20 20 20 20 20 20  20 20 20 72 2e 72 5b 32  |           r.r[2|
00003300  5d 20 3d 20 30 3b 0a 20  20 20 20 20 20 20 20 20  |] = 0;.         |
00003310  20 20 20 65 72 72 20 3d  20 5f 6b 65 72 6e 65 6c  |   err = _kernel|
00003320  5f 73 77 69 28 4f 53 5f  43 68 61 6e 67 65 45 6e  |_swi(OS_ChangeEn|
00003330  76 69 72 6f 6e 6d 65 6e  74 2c 20 26 72 2c 20 26  |vironment, &r, &|
00003340  72 29 3b 0a 20 20 20 20  20 20 20 20 20 20 20 20  |r);.            |
00003350  61 70 70 73 70 61 63 65  20 3d 20 72 2e 72 5b 31  |appspace = r.r[1|
00003360  5d 3b 0a 0a 20 20 20 20  20 20 20 20 20 20 20 20  |];..            |
00003370  2f 2a 20 73 65 74 20 6d  65 6d 6f 72 79 20 6c 69  |/* set memory li|
00003380  6d 69 74 20 62 65 66 6f  72 65 20 73 6c 6f 74 20  |mit before slot |
00003390  73 69 7a 65 20 63 68 61  6e 67 65 20 2e 2e 2e 20  |size change ... |
000033a0  2a 2f 0a 20 20 20 20 20  20 20 20 20 20 20 20 69  |*/.            i|
000033b0  66 28 61 70 70 73 70 61  63 65 20 3e 20 6d 65 6d  |f(appspace > mem|
000033c0  6c 69 6d 29 0a 20 20 20  20 20 20 20 20 20 20 20  |lim).           |
000033d0  20 7b 0a 20 20 20 20 20  20 20 20 20 20 20 20 20  | {.             |
000033e0  20 20 72 2e 72 5b 30 5d  20 3d 20 30 3b 0a 20 20  |  r.r[0] = 0;.  |
000033f0  20 20 20 20 20 20 20 20  20 20 20 20 20 72 2e 72  |             r.r|
00003400  5b 31 5d 20 3d 20 61 70  70 73 70 61 63 65 3b 0a  |[1] = appspace;.|
00003410  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 72  |               r|
00003420  2e 72 5b 32 5d 20 3d 20  30 3b 0a 20 20 20 20 20  |.r[2] = 0;.     |
00003430  20 20 20 20 20 20 20 20  20 20 65 72 72 20 3d 20  |          err = |
00003440  5f 6b 65 72 6e 65 6c 5f  73 77 69 28 4f 53 5f 43  |_kernel_swi(OS_C|
00003450  68 61 6e 67 65 45 6e 76  69 72 6f 6e 6d 65 6e 74  |hangeEnvironment|
00003460  2c 20 26 72 2c 20 26 72  29 3b 0a 20 20 20 20 20  |, &r, &r);.     |
00003470  20 20 20 20 20 20 20 7d  0a 0a 20 20 20 20 20 20  |       }..      |
00003480  20 20 20 20 20 20 2f 2a  20 73 65 74 20 77 69 6d  |      /* set wim|
00003490  70 73 6c 6f 74 20 73 69  7a 65 20 2a 2f 0a 20 20  |pslot size */.  |
000034a0  20 20 20 20 20 20 20 20  20 20 72 2e 72 5b 30 5d  |          r.r[0]|
000034b0  20 3d 20 73 6c 6f 74 3b  0a 20 20 20 20 20 20 20  | = slot;.       |
000034c0  20 20 20 20 20 72 2e 72  5b 31 5d 20 3d 20 2d 31  |     r.r[1] = -1|
000034d0  3b 0a 20 20 20 20 20 20  20 20 20 20 20 20 65 72  |;.            er|
000034e0  72 20 3d 5f 6b 65 72 6e  65 6c 5f 73 77 69 28 57  |r =_kernel_swi(W|
000034f0  69 6d 70 5f 53 6c 6f 74  53 69 7a 65 2c 20 26 72  |imp_SlotSize, &r|
00003500  2c 20 26 72 29 3b 0a 20  20 20 20 20 20 20 20 20  |, &r);.         |
00003510  20 20 20 73 6c 6f 74 20  3d 20 72 2e 72 5b 30 5d  |   slot = r.r[0]|
00003520  3b 0a 20 20 20 20 20 20  20 20 20 20 20 20 0a 20  |;.            . |
00003530  20 20 20 20 20 20 20 20  20 20 20 66 6c 65 78 5f  |           flex_|
00003540  5f 6c 69 6d 20 3d 20 28  63 68 61 72 2a 29 20 73  |_lim = (char*) s|
00003550  6c 6f 74 20 2b 20 30 78  38 30 30 30 3b 0a 0a 20  |lot + 0x8000;.. |
00003560  20 20 20 20 20 20 20 20  20 20 20 2f 2a 20 2e 2e  |           /* ..|
00003570  2e 2e 20 61 6e 64 20 73  65 74 20 6d 65 6d 6f 72  |.. and set memor|
00003580  79 20 6c 69 6d 69 74 20  62 61 63 6b 20 61 67 61  |y limit back aga|
00003590  69 6e 20 2a 2f 0a 20 20  20 20 20 20 20 20 20 20  |in */.          |
000035a0  20 20 69 66 20 28 61 70  70 73 70 61 63 65 20 3e  |  if (appspace >|
000035b0  20 6d 65 6d 6c 69 6d 29  0a 20 20 20 20 20 20 20  | memlim).       |
000035c0  20 20 20 20 20 7b 0a 20  20 20 20 20 20 20 20 20  |     {.         |
000035d0  20 20 20 20 20 20 72 2e  72 5b 30 5d 20 3d 20 30  |      r.r[0] = 0|
000035e0  3b 0a 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |;.              |
000035f0  20 72 2e 72 5b 31 5d 20  3d 20 6f 6c 64 6d 65 6d  | r.r[1] = oldmem|
00003600  6c 69 6d 3b 0a 20 20 20  20 20 20 20 20 20 20 20  |lim;.           |
00003610  20 20 20 20 72 2e 72 5b  32 5d 20 3d 20 30 3b 0a  |    r.r[2] = 0;.|
00003620  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 65  |               e|
00003630  72 72 20 3d 20 5f 6b 65  72 6e 65 6c 5f 73 77 69  |rr = _kernel_swi|
00003640  28 4f 53 5f 43 68 61 6e  67 65 45 6e 76 69 72 6f  |(OS_ChangeEnviro|
00003650  6e 6d 65 6e 74 2c 20 26  72 2c 20 26 72 29 3b 0a  |nment, &r, &r);.|
00003660  20 20 20 20 20 20 20 20  20 20 20 20 7d 0a 20 20  |            }.  |
00003670  20 20 20 20 20 20 20 7d  0a 0a 20 20 20 20 20 20  |       }..      |
00003680  20 20 20 2f 2a 20 69 66  20 77 65 20 63 6f 75 6c  |   /* if we coul|
00003690  64 6e 27 74 20 73 61 74  69 73 66 79 20 69 74 2c  |dn't satisfy it,|
000036a0  20 73 74 69 6c 6c 20 67  69 76 65 20 62 61 63 6b  | still give back|
000036b0  20 77 68 61 74 20 77 65  20 63 61 6e 2c 20 2a 2f  | what we can, */|
000036c0  0a 20 20 20 20 20 20 20  20 20 2f 2a 20 5f 6b 65  |.         /* _ke|
000036d0  72 6e 65 6c 5f 61 6c 6c  6f 63 20 6d 61 79 20 62  |rnel_alloc may b|
000036e0  65 20 61 62 6c 65 20 74  6f 20 75 73 65 20 69 74  |e able to use it|
000036f0  21 21 21 21 21 20 20 20  20 20 20 20 20 20 20 20  |!!!!!           |
00003700  20 20 20 20 20 2a 2f 0a  20 20 20 20 20 20 20 20  |     */.        |
00003710  20 69 66 20 28 66 6c 65  78 5f 5f 6c 69 6d 20 3c  | if (flex__lim <|
00003720  20 70 72 65 76 20 2b 20  6d 6f 72 65 29 0a 20 20  | prev + more).  |
00003730  20 20 20 20 20 20 20 20  20 20 20 72 6f 75 6e 64  |           round|
00003740  75 70 6e 20 3d 20 66 6c  65 78 5f 5f 6c 69 6d 20  |upn = flex__lim |
00003750  2d 20 66 6c 65 78 5f 5f  66 72 65 65 70 3b 20 2f  |- flex__freep; /|
00003760  2a 61 6c 6c 20 77 65 20  67 6f 74 2a 2f 0a 20 20  |*all we got*/.  |
00003770  20 20 20 20 7d 0a 20 20  20 20 20 20 0a 20 20 20  |    }.      .   |
00003780  20 20 20 7b 0a 20 20 20  20 20 20 20 20 20 20 20  |   {.           |
00003790  66 6c 65 78 5f 5f 72 65  63 20 2a 70 20 3d 20 28  |flex__rec *p = (|
000037a0  66 6c 65 78 5f 5f 72 65  63 2a 29 66 6c 65 78 5f  |flex__rec*)flex_|
000037b0  5f 62 61 73 65 3b 0a 20  20 20 20 20 20 20 20 20  |_base;.         |
000037c0  20 20 77 68 69 6c 65 20  28 31 29 20 7b 0a 20 20  |  while (1) {.  |
000037d0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 69 66  |              if|
000037e0  20 28 28 69 6e 74 29 20  70 20 3e 3d 20 28 69 6e  | ((int) p >= (in|
000037f0  74 29 20 66 6c 65 78 5f  5f 66 72 65 65 70 29 20  |t) flex__freep) |
00003800  62 72 65 61 6b 3b 0a 20  20 20 20 20 20 20 20 20  |break;.         |
00003810  20 20 20 20 20 20 20 2a  28 70 2d 3e 61 6e 63 68  |       *(p->anch|
00003820  6f 72 29 20 3d 20 28 28  63 68 61 72 2a 29 20 28  |or) = ((char*) (|
00003830  70 20 2b 20 31 29 29 20  2b 20 72 6f 75 6e 64 75  |p + 1)) + roundu|
00003840  70 6e 3b 0a 20 20 20 20  20 20 20 20 20 20 20 20  |pn;.            |
00003850  20 20 20 20 70 20 3d 20  28 66 6c 65 78 5f 5f 72  |    p = (flex__r|
00003860  65 63 2a 29 20 28 28 28  63 68 61 72 2a 29 20 28  |ec*) (((char*) (|
00003870  70 20 2b 20 31 29 29 20  2b 20 72 6f 75 6e 64 75  |p + 1)) + roundu|
00003880  70 28 70 2d 3e 73 69 7a  65 29 29 3b 0a 20 20 20  |p(p->size));.   |
00003890  20 20 20 20 20 20 20 20  7d 0a 20 20 20 20 20 20  |        }.      |
000038a0  7d 0a 20 20 20 20 20 20  20 0a 20 20 20 20 20 20  |}.       .      |
000038b0  6d 65 6d 6d 6f 76 65 28  66 6c 65 78 5f 5f 62 61  |memmove(flex__ba|
000038c0  73 65 20 2b 20 72 6f 75  6e 64 75 70 6e 2c 20 66  |se + roundupn, f|
000038d0  6c 65 78 5f 5f 62 61 73  65 2c 20 66 6c 65 78 5f  |lex__base, flex_|
000038e0  5f 66 72 65 65 70 20 2d  20 66 6c 65 78 5f 5f 62  |_freep - flex__b|
000038f0  61 73 65 29 3b 0a 20 20  20 20 20 20 2a 61 20 3d  |ase);.      *a =|
00003900  20 66 6c 65 78 5f 5f 62  61 73 65 3b 0a 20 20 20  | flex__base;.   |
00003910  20 20 20 66 6c 65 78 5f  5f 62 61 73 65 20 2b 3d  |   flex__base +=|
00003920  20 72 6f 75 6e 64 75 70  6e 3b 0a 20 20 20 20 20  | roundupn;.     |
00003930  20 66 6c 65 78 5f 5f 66  72 65 65 70 20 2b 3d 20  | flex__freep += |
00003940  72 6f 75 6e 64 75 70 6e  3b 0a 0a 20 20 20 20 20  |roundupn;..     |
00003950  20 66 6c 65 78 5f 5f 69  6e 6c 69 6e 65 6e 6f 74  | flex__inlinenot|
00003960  69 66 79 28 46 41 4c 53  45 2c 20 28 66 6c 65 78  |ify(FALSE, (flex|
00003970  5f 5f 72 65 63 20 2a 29  20 66 6c 65 78 5f 5f 62  |__rec *) flex__b|
00003980  61 73 65 29 3b 0a 20 20  20 20 20 20 72 65 74 75  |ase);.      retu|
00003990  72 6e 28 72 6f 75 6e 64  75 70 6e 29 3b 0a 0a 20  |rn(roundupn);.. |
000039a0  20 20 7d 20 0a 20 20 20  65 6c 73 65 20 0a 20 20  |  } .   else .  |
000039b0  20 7b 20 0a 20 20 20 20  20 20 2f 2a 20 61 6c 6c  | { .      /* all|
000039c0  20 6d 6f 76 69 6e 67 20  64 6f 77 6e 20 2a 2f 0a  | moving down */.|
000039d0  20 20 20 20 20 20 69 6e  74 20 72 6f 75 6e 64 75  |      int roundu|
000039e0  70 6e 20 3d 20 72 6f 75  6e 64 75 70 28 2d 6e 29  |pn = roundup(-n)|
000039f0  3b 20 2f 2a 20 61 20 2b  76 65 20 76 61 6c 75 65  |; /* a +ve value|
00003a00  20 2a 2f 0a 0a 20 20 20  20 20 20 7b 0a 20 20 20  | */..      {.   |
00003a10  20 20 20 20 20 20 66 6c  65 78 5f 5f 72 65 63 20  |      flex__rec |
00003a20  2a 70 20 3d 20 28 66 6c  65 78 5f 5f 72 65 63 2a  |*p = (flex__rec*|
00003a30  29 66 6c 65 78 5f 5f 62  61 73 65 3b 0a 20 20 20  |)flex__base;.   |
00003a40  20 20 20 20 20 20 77 68  69 6c 65 20 28 31 29 20  |      while (1) |
00003a50  0a 20 20 20 20 20 20 20  20 20 7b 0a 20 20 20 20  |.         {.    |
00003a60  20 20 20 20 20 20 20 20  20 69 66 20 28 28 69 6e  |         if ((in|
00003a70  74 29 20 70 20 3e 3d 20  28 69 6e 74 29 20 66 6c  |t) p >= (int) fl|
00003a80  65 78 5f 5f 66 72 65 65  70 29 20 62 72 65 61 6b  |ex__freep) break|
00003a90  3b 0a 20 20 20 20 20 20  20 20 20 20 20 20 20 2a  |;.             *|
00003aa0  28 70 2d 3e 61 6e 63 68  6f 72 29 20 3d 20 28 28  |(p->anchor) = ((|
00003ab0  63 68 61 72 2a 29 20 28  70 20 2b 20 31 29 29 20  |char*) (p + 1)) |
00003ac0  2b 20 72 6f 75 6e 64 75  70 6e 3b 0a 20 20 20 20  |+ roundupn;.    |
00003ad0  20 20 20 20 20 20 20 20  20 70 20 3d 20 28 66 6c  |         p = (fl|
00003ae0  65 78 5f 5f 72 65 63 2a  29 20 28 28 28 63 68 61  |ex__rec*) (((cha|
00003af0  72 2a 29 20 28 70 20 2b  20 31 29 29 20 2b 20 72  |r*) (p + 1)) + r|
00003b00  6f 75 6e 64 75 70 28 70  2d 3e 73 69 7a 65 29 29  |oundup(p->size))|
00003b10  3b 0a 20 20 20 20 20 20  20 20 20 7d 0a 20 20 20  |;.         }.   |
00003b20  20 20 20 7d 0a 20 20 20  20 20 20 6d 65 6d 6d 6f  |   }.      memmo|
00003b30  76 65 28 66 6c 65 78 5f  5f 62 61 73 65 20 2d 20  |ve(flex__base - |
00003b40  72 6f 75 6e 64 75 70 6e  2c 20 66 6c 65 78 5f 5f  |roundupn, flex__|
00003b50  62 61 73 65 2c 20 66 6c  65 78 5f 5f 66 72 65 65  |base, flex__free|
00003b60  70 20 2d 20 66 6c 65 78  5f 5f 62 61 73 65 29 3b  |p - flex__base);|
00003b70  0a 20 20 20 20 20 20 66  6c 65 78 5f 5f 62 61 73  |.      flex__bas|
00003b80  65 20 2d 3d 20 72 6f 75  6e 64 75 70 6e 3b 0a 20  |e -= roundupn;. |
00003b90  20 20 20 20 20 66 6c 65  78 5f 5f 66 72 65 65 70  |     flex__freep|
00003ba0  20 2d 3d 20 72 6f 75 6e  64 75 70 6e 3b 0a 20 20  | -= roundupn;.  |
00003bb0  20 20 20 20 66 6c 65 78  5f 5f 69 6e 6c 69 6e 65  |    flex__inline|
00003bc0  6e 6f 74 69 66 79 28 46  41 4c 53 45 2c 20 28 66  |notify(FALSE, (f|
00003bd0  6c 65 78 5f 5f 72 65 63  20 2a 29 20 66 6c 65 78  |lex__rec *) flex|
00003be0  5f 5f 62 61 73 65 29 3b  0a 20 20 20 7d 0a 0a 0a  |__base);.   }...|
00003bf0  20 20 20 72 65 74 75 72  6e 28 30 29 3b 0a 7d 0a  |   return(0);.}.|
00003c00  0a 65 78 74 65 72 6e 20  69 6e 74 20 66 6c 65 78  |.extern int flex|
00003c10  5f 64 6f 6e 74 5f 62 75  64 67 65 28 69 6e 74 20  |_dont_budge(int |
00003c20  6e 2c 20 76 6f 69 64 20  2a 2a 61 29 0a 7b 20 20  |n, void **a).{  |
00003c30  6e 20 3d 20 6e 3b 0a 20  20 20 61 20 3d 20 61 3b  |n = n;.   a = a;|
00003c40  0a 20 20 20 72 65 74 75  72 6e 20 30 3b 0a 7d 0a  |.   return 0;.}.|
00003c50  0a 2f 2a 20 73 74 61 63  6b 20 63 68 65 63 6b 73  |./* stack checks|
00003c60  20 6f 6e 20 61 67 61 69  6e 20 2a 2f 0a 23 70 72  | on again */.#pr|
00003c70  61 67 6d 61 20 2d 73 30  0a 0a 73 74 61 74 69 63  |agma -s0..static|
00003c80  20 76 6f 69 64 20 66 6c  65 78 5f 5f 65 78 69 74  | void flex__exit|
00003c90  28 76 6f 69 64 29 0a 7b  20 20 5f 6b 65 72 6e 65  |(void).{  _kerne|
00003ca0  6c 5f 73 77 69 5f 72 65  67 73 20 72 65 67 73 3b  |l_swi_regs regs;|
00003cb0  0a 0a 20 20 20 69 66 20  28 66 6c 65 78 5f 5f 64  |..   if (flex__d|
00003cc0  61 20 21 3d 20 2d 31 29  0a 20 20 20 7b 20 20 72  |a != -1).   {  r|
00003cd0  65 67 73 2e 72 5b 30 5d  20 3d 20 31 3b 0a 20 20  |egs.r[0] = 1;.  |
00003ce0  20 20 20 20 72 65 67 73  2e 72 5b 31 5d 20 3d 20  |    regs.r[1] = |
00003cf0  66 6c 65 78 5f 5f 64 61  3b 0a 20 20 20 20 20 20  |flex__da;.      |
00003d00  5f 6b 65 72 6e 65 6c 5f  73 77 69 28 4f 53 5f 44  |_kernel_swi(OS_D|
00003d10  79 6e 61 6d 69 63 41 72  65 61 2c 20 26 72 65 67  |ynamicArea, &reg|
00003d20  73 2c 20 26 72 65 67 73  29 3b 0a 20 20 20 7d 0a  |s, &regs);.   }.|
00003d30  7d 0a 0a 76 6f 69 64 20  66 6c 65 78 5f 69 6e 69  |}..void flex_ini|
00003d40  74 78 28 63 68 61 72 20  2a 70 72 6f 67 72 61 6d  |tx(char *program|
00003d50  5f 6e 61 6d 65 2c 20 69  6e 74 20 2a 65 72 72 6f  |_name, int *erro|
00003d60  72 5f 66 64 2c 69 6e 74  20 64 61 2c 69 6e 74 20  |r_fd,int da,int |
00003d70  6d 61 78 73 69 7a 65 2c  42 4f 4f 4c 20 76 69 72  |maxsize,BOOL vir|
00003d80  74 75 61 6c 69 73 65 29  0a 7b 20 20 66 6c 65 78  |tualise).{  flex|
00003d90  5f 5f 6c 69 6d 20 3d 20  28 63 68 61 72 20 2a 29  |__lim = (char *)|
00003da0  20 2d 31 3b 0a 20 20 20  5f 6d 62 6c 6b 3d 28 69  | -1;.   _mblk=(i|
00003db0  6e 74 29 65 72 72 6f 72  5f 66 64 3b 0a 0a 20 20  |nt)error_fd;..  |
00003dc0  20 69 66 20 28 64 61 29  20 2f 2a 20 74 72 79 20  | if (da) /* try |
00003dd0  74 6f 20 63 72 65 61 74  65 20 61 20 44 41 20 2a  |to create a DA *|
00003de0  2f 0a 20 20 20 7b 20 20  5f 6b 65 72 6e 65 6c 5f  |/.   {  _kernel_|
00003df0  6f 73 65 72 72 6f 72 20  2a 65 72 72 3b 0a 20 20  |oserror *err;.  |
00003e00  20 20 20 20 5f 6b 65 72  6e 65 6c 5f 73 77 69 5f  |    _kernel_swi_|
00003e10  72 65 67 73 20 72 65 67  73 3b 0a 0a 20 20 20 20  |regs regs;..    |
00003e20  20 20 72 65 67 73 2e 72  5b 30 5d 20 3d 20 20 20  |  regs.r[0] =   |
00003e30  20 30 3b 20 20 2f 2a 20  63 72 65 61 74 65 20 44  | 0;  /* create D|
00003e40  41 20 20 20 20 20 20 20  20 20 2a 2f 0a 20 20 20  |A         */.   |
00003e50  20 20 20 72 65 67 73 2e  72 5b 31 5d 20 3d 20 20  |   regs.r[1] =  |
00003e60  20 2d 31 3b 20 20 2f 2a  20 61 72 65 61 20 6e 75  | -1;  /* area nu|
00003e70  6d 62 65 72 20 20 20 20  20 20 20 2a 2f 0a 20 20  |mber       */.  |
00003e80  20 20 20 20 72 65 67 73  2e 72 5b 32 5d 20 3d 20  |    regs.r[2] = |
00003e90  20 20 20 30 3b 20 20 2f  2a 20 69 6e 69 74 69 61  |   0;  /* initia|
00003ea0  6c 20 73 69 7a 65 20 20  20 20 20 20 2a 2f 0a 20  |l size      */. |
00003eb0  20 20 20 20 20 72 65 67  73 2e 72 5b 33 5d 20 3d  |     regs.r[3] =|
00003ec0  20 20 20 2d 31 3b 20 20  2f 2a 20 6c 6f 67 69 63  |   -1;  /* logic|
00003ed0  61 6c 20 61 64 64 72 65  73 73 20 20 20 2a 2f 0a  |al address   */.|
00003ee0  20 20 20 20 20 20 72 65  67 73 2e 72 5b 34 5d 20  |      regs.r[4] |
00003ef0  3d 20 30 78 38 30 3b 20  20 2f 2a 20 61 63 63 65  |= 0x80;  /* acce|
00003f00  73 73 20 70 72 69 76 69  6c 65 67 65 73 20 2a 2f  |ss privileges */|
00003f10  0a 20 20 20 20 20 20 72  65 67 73 2e 72 5b 35 5d  |.      regs.r[5]|
00003f20  20 3d 20 20 20 6d 61 78  73 69 7a 65 3b 20 20 2f  | =   maxsize;  /|
00003f30  2a 20 6d 61 78 20 73 69  7a 65 20 20 20 20 20 20  |* max size      |
00003f40  20 20 20 20 2a 2f 0a 20  20 20 20 20 20 69 66 20  |    */.      if |
00003f50  28 76 69 72 74 75 61 6c  69 73 65 29 20 20 20 20  |(virtualise)    |
00003f60  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00003f80  20 20 20 2f 2a 44 4a 20  20 20 20 2a 2f 0a 20 20  |   /*DJ    */.  |
00003f90  20 20 20 20 20 7b 20 20  20 20 20 20 20 20 20 20  |     {          |
00003fa0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00003fc0  20 20 20 20 20 20 20 20  20 20 2f 2a 44 4a 20 20  |          /*DJ  |
00003fd0  20 20 2a 2f 0a 20 20 20  20 20 20 20 20 20 72 65  |  */.         re|
00003fe0  67 73 2e 72 5b 34 5d 20  3d 20 72 65 67 73 2e 72  |gs.r[4] = regs.r|
00003ff0  5b 34 5d 20 20 7c 20 28  31 55 20 3c 3c 33 31 29  |[4]  | (1U <<31)|
00004000  3b 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |;               |
00004010  20 2f 2a 44 4a 20 20 20  20 2a 2f 0a 20 20 20 20  | /*DJ    */.    |
00004020  20 20 20 20 20 72 65 67  73 2e 72 5b 35 5d 3d 6d  |     regs.r[5]=m|
00004030  61 78 73 69 7a 65 3b 20  20 20 20 20 20 20 20 20  |axsize;         |
00004040  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00004050  20 20 20 20 20 20 20 20  2f 2a 44 4a 20 20 20 20  |        /*DJ    |
00004060  2a 2f 0a 20 20 20 20 20  20 20 20 20 20 20 20 20  |*/.             |
00004070  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00004090  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 2f  |               /|
000040a0  2a 44 4a 20 20 20 20 2a  2f 0a 20 20 20 20 20 20  |*DJ    */.      |
000040b0  20 7d 20 20 20 20 20 20  20 20 20 20 20 20 20 20  | }              |
000040c0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
000040e0  20 20 20 20 20 20 2f 2a  44 4a 20 20 20 20 2a 2f  |      /*DJ    */|
000040f0  0a 20 20 20 20 20 20 72  65 67 73 2e 72 5b 36 5d  |.      regs.r[6]|
00004100  20 3d 20 20 20 20 30 3b  20 20 2f 2a 20 6e 6f 20  | =    0;  /* no |
00004110  72 6f 75 74 69 6e 65 20  79 65 74 20 20 20 20 2a  |routine yet    *|
00004120  2f 0a 20 20 20 20 20 20  72 65 67 73 2e 72 5b 37  |/.      regs.r[7|
00004130  5d 20 3d 20 20 20 20 30  3b 20 20 2f 2a 20 77 73  |] =    0;  /* ws|
00004140  20 70 6f 69 6e 74 65 72  20 20 20 20 20 20 20 20  | pointer        |
00004150  2a 2f 0a 20 20 20 20 20  20 72 65 67 73 2e 72 5b  |*/.      regs.r[|
00004160  38 5d 20 3d 20 28 69 6e  74 29 20 70 72 6f 67 72  |8] = (int) progr|
00004170  61 6d 5f 6e 61 6d 65 3b  20 20 2f 2a 20 61 72 65  |am_name;  /* are|
00004180  61 20 6e 61 6d 65 20 2a  2f 0a 0a 20 20 20 20 20  |a name */..     |
00004190  20 65 72 72 20 3d 20 5f  6b 65 72 6e 65 6c 5f 73  | err = _kernel_s|
000041a0  77 69 28 4f 53 5f 44 79  6e 61 6d 69 63 41 72 65  |wi(OS_DynamicAre|
000041b0  61 2c 20 26 72 65 67 73  2c 20 26 72 65 67 73 29  |a, &regs, &regs)|
000041c0  3b 0a 0a 20 20 20 20 20  20 69 66 20 28 21 65 72  |;..      if (!er|
000041d0  72 29 0a 20 20 20 20 20  20 7b 20 20 66 6c 65 78  |r).      {  flex|
000041e0  5f 5f 64 61 20 20 20 3d  20 72 65 67 73 2e 72 5b  |__da   = regs.r[|
000041f0  31 5d 3b 0a 20 20 20 20  20 20 20 20 20 66 6c 65  |1];.         fle|
00004200  78 5f 5f 66 72 65 65 70  20 3d 20 66 6c 65 78 5f  |x__freep = flex_|
00004210  5f 6c 69 6d 20 3d 20 66  6c 65 78 5f 5f 62 61 73  |_lim = flex__bas|
00004220  65 20 3d 20 28 63 68 61  72 20 2a 29 20 72 65 67  |e = (char *) reg|
00004230  73 2e 72 5b 33 5d 3b 0a  20 20 20 20 20 20 20 20  |s.r[3];.        |
00004240  20 61 74 65 78 69 74 28  66 6c 65 78 5f 5f 65 78  | atexit(flex__ex|
00004250  69 74 29 3b 20 20 20 0a  20 20 20 20 20 20 20 20  |it);   .        |
00004260  20 69 66 20 28 76 69 72  74 75 61 6c 69 73 65 29  | if (virtualise)|
00004270  0a 20 20 20 20 20 20 20  20 20 20 20 7b 0a 20 20  |.           {.  |
00004280  20 20 20 20 20 20 20 20  20 20 5f 6b 65 72 6e 65  |          _kerne|
00004290  6c 5f 73 77 69 28 4f 53  5f 52 65 61 64 4d 65 6d  |l_swi(OS_ReadMem|
000042a0  4d 61 70 49 6e 66 6f 2c  26 72 65 67 73 2c 26 72  |MapInfo,&regs,&r|
000042b0  65 67 73 29 3b 0a 20 20  20 20 20 20 20 20 20 20  |egs);.          |
000042c0  20 20 72 65 67 73 2e 72  5b 30 5d 3d 72 65 67 73  |  regs.r[0]=regs|
000042d0  2e 72 5b 30 5d 2a 72 65  67 73 2e 72 5b 31 5d 3b  |.r[0]*regs.r[1];|
000042e0  0a 20 20 20 20 20 20 20  20 20 20 20 20 72 65 67  |.            reg|
000042f0  73 2e 72 5b 31 5d 3d 72  65 67 73 2e 72 5b 30 5d  |s.r[1]=regs.r[0]|
00004300  3b 0a 20 20 20 20 20 20  20 20 20 20 20 20 72 65  |;.            re|
00004310  67 73 2e 72 5b 32 5d 3d  72 65 67 73 2e 72 5b 30  |gs.r[2]=regs.r[0|
00004320  5d 2a 2e 30 35 3b 0a 20  20 20 20 20 20 20 20 20  |]*.05;.         |
00004330  20 20 20 5f 6b 65 72 6e  65 6c 5f 73 77 69 28 56  |   _kernel_swi(V|
00004340  69 72 74 75 61 6c 69 73  65 5f 43 6f 6e 66 69 67  |irtualise_Config|
00004350  75 72 65 2c 26 72 65 67  73 2c 26 72 65 67 73 29  |ure,&regs,&regs)|
00004360  3b 0a 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |;.              |
00004370  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00004390  20 20 20 20 20 20 20 20  20 0a 20 20 20 20 20 20  |         .      |
000043a0  20 20 20 20 20 20 66 6c  65 78 5f 5f 56 4d 3d 54  |      flex__VM=T|
000043b0  52 55 45 3b 0a 20 20 20  20 20 20 20 20 20 20 20  |RUE;.           |
000043c0  7d 0a 20 20 20 20 20 20  20 20 20 67 6f 74 6f 20  |}.         goto |
000043d0  69 6e 69 74 6f 6b 3b 0a  20 20 20 20 20 20 7d 0a  |initok;.      }.|
000043e0  20 20 20 7d 0a 0a 20 20  20 66 6c 65 78 5f 5f 77  |   }..   flex__w|
000043f0  69 6d 70 73 6c 6f 74 28  26 66 6c 65 78 5f 5f 6c  |impslot(&flex__l|
00004400  69 6d 29 3b 20 20 2f 2a  20 73 68 72 69 6e 6b 20  |im);  /* shrink |
00004410  2a 2f 0a 20 20 20 66 6c  65 78 5f 5f 66 72 65 65  |*/.   flex__free|
00004420  70 20 3d 20 66 6c 65 78  5f 5f 6c 69 6d 3b 0a 20  |p = flex__lim;. |
00004430  20 20 66 6c 65 78 5f 5f  62 61 73 65 20 3d 20 66  |  flex__base = f|
00004440  6c 65 78 5f 5f 66 72 65  65 70 3b 0a 20 20 20 5f  |lex__freep;.   _|
00004450  6b 65 72 6e 65 6c 5f 72  65 67 69 73 74 65 72 5f  |kernel_register_|
00004460  73 6c 6f 74 65 78 74 65  6e 64 28 66 6c 65 78 5f  |slotextend(flex_|
00004470  64 6f 6e 74 5f 62 75 64  67 65 29 3b 0a 0a 69 6e  |dont_budge);..in|
00004480  69 74 6f 6b 3a 0a 20 20  20 66 6c 65 78 5f 5f 69  |itok:.   flex__i|
00004490  6e 69 74 69 61 6c 69 73  65 64 20 3d 20 31 3b 0a  |nitialised = 1;.|
000044a0  0a 20 20 20 2f 2a 20 43  68 65 63 6b 20 74 68 61  |.   /* Check tha|
000044b0  74 20 77 65 27 72 65 20  69 6e 20 74 68 65 20 57  |t we're in the W|
000044c0  69 6d 70 20 65 6e 76 69  72 6f 6e 6d 65 6e 74 2e  |imp environment.|
000044d0  20 2a 2f 0a 20 20 20 7b  0a 20 20 20 20 20 20 76  | */.   {.      v|
000044e0  6f 69 64 20 2a 61 3b 0a  20 20 20 20 20 20 69 66  |oid *a;.      if|
000044f0  20 28 21 20 66 6c 65 78  5f 61 6c 6c 6f 63 28 26  | (! flex_alloc(&|
00004500  61 2c 20 31 29 29 20 0a  20 20 20 20 20 20 20 20  |a, 1)) .        |
00004510  20 77 65 72 72 28 54 52  55 45 2c 20 6d 73 67 73  | werr(TRUE, msgs|
00004520  5f 6c 6f 6f 6b 75 70 28  22 66 6c 65 78 32 3a 4e  |_lookup("flex2:N|
00004530  6f 74 20 65 6e 6f 75 67  68 20 6d 65 6d 6f 72 79  |ot enough memory|
00004540  2c 20 6f 72 20 6e 6f 74  20 77 69 74 68 69 6e 20  |, or not within |
00004550  2a 64 65 73 6b 74 6f 70  20 77 6f 72 6c 64 2e 22  |*desktop world."|
00004560  29 29 3b 0a 0a 20 20 20  20 20 20 66 6c 65 78 5f  |));..      flex_|
00004570  66 72 65 65 28 26 61 29  3b 0a 20 20 20 7d 0a 0a  |free(&a);.   }..|
00004580  7d 0a 0a 2f 2a 20 64 65  66 61 75 6c 74 20 66 6c  |}../* default fl|
00004590  65 78 5f 69 6e 69 74 28  29 20 64 69 73 61 62 6c  |ex_init() disabl|
000045a0  65 73 20 75 73 65 20 6f  66 20 44 41 20 2a 2f 0a  |es use of DA */.|
000045b0  0a 76 6f 69 64 20 66 6c  65 78 5f 69 6e 69 74 28  |.void flex_init(|
000045c0  63 68 61 72 20 2a 70 72  6f 67 72 61 6d 5f 6e 61  |char *program_na|
000045d0  6d 65 2c 20 69 6e 74 20  2a 65 72 72 6f 72 5f 66  |me, int *error_f|
000045e0  64 29 0a 7b 20 20 66 6c  65 78 5f 69 6e 69 74 78  |d).{  flex_initx|
000045f0  28 70 72 6f 67 72 61 6d  5f 6e 61 6d 65 2c 65 72  |(program_name,er|
00004600  72 6f 72 5f 66 64 2c 46  41 4c 53 45 2c 2d 31 2c  |ror_fd,FALSE,-1,|
00004610  46 41 4c 53 45 20 2f 2a  20 44 4a 20 30 36 30 39  |FALSE /* DJ 0609|
00004620  39 35 20 2a 2f 29 3b 0a  7d 0a 0a 69 6e 74 20 66  |95 */);.}..int f|
00004630  6c 65 78 5f 69 73 64 79  6e 61 6d 69 63 28 76 6f  |lex_isdynamic(vo|
00004640  69 64 29 0a 7b 20 20 72  65 74 75 72 6e 20 66 6c  |id).{  return fl|
00004650  65 78 5f 5f 64 61 20 21  3d 20 2d 31 3b 0a 7d 20  |ex__da != -1;.} |
00004660  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00004670  20 20 20 20 20 20 0a 0a  0a 42 4f 4f 4c 20 66 6c  |      ...BOOL fl|
00004680  65 78 5f 69 73 56 4d 28  76 6f 69 64 29 0a 7b 0a  |ex_isVM(void).{.|
00004690  20 72 65 74 75 72 6e 20  66 6c 65 78 5f 5f 56 4d  | return flex__VM|
000046a0  3b 0a 7d 0a 0a 5f 6b 65  72 6e 65 6c 5f 6f 73 65  |;.}.._kernel_ose|
000046b0  72 72 6f 72 20 2a 20 66  6c 65 78 5f 56 4d 43 6f  |rror * flex_VMCo|
000046c0  6e 66 69 67 75 72 65 28  69 6e 74 20 64 65 66 2c  |nfigure(int def,|
000046d0  69 6e 74 20 63 61 63 68  65 2c 69 6e 74 20 6c 65  |int cache,int le|
000046e0  66 74 29 0a 0a 7b 0a 5f  6b 65 72 6e 65 6c 5f 73  |ft)..{._kernel_s|
000046f0  77 69 5f 72 65 67 73 20  72 65 67 73 3b 0a 0a 20  |wi_regs regs;.. |
00004700  72 65 67 73 2e 72 5b 30  5d 3d 64 65 66 3b 0a 20  |regs.r[0]=def;. |
00004710  72 65 67 73 2e 72 5b 31  5d 3d 63 61 63 68 65 3b  |regs.r[1]=cache;|
00004720  0a 20 72 65 67 73 2e 72  5b 32 5d 3d 6c 65 66 74  |. regs.r[2]=left|
00004730  3b 0a 20 72 65 74 75 72  6e 20 5f 6b 65 72 6e 65  |;. return _kerne|
00004740  6c 5f 73 77 69 28 56 69  72 74 75 61 6c 69 73 65  |l_swi(Virtualise|
00004750  5f 43 6f 6e 66 69 67 75  72 65 2c 26 72 65 67 73  |_Configure,&regs|
00004760  2c 26 72 65 67 73 29 3b  0a 7d 0a 0a 0a 0a 5f 6b  |,&regs);.}...._k|
00004770  65 72 6e 65 6c 5f 6f 73  65 72 72 6f 72 20 2a 20  |ernel_oserror * |
00004780  66 6c 65 78 5f 72 65 61  64 56 4d 43 6f 6e 66 69  |flex_readVMConfi|
00004790  67 75 72 65 28 69 6e 74  20 2a 20 64 65 66 20 2c  |gure(int * def ,|
000047a0  69 6e 74 20 2a 63 61 63  68 65 2c 69 6e 74 20 2a  |int *cache,int *|
000047b0  6c 65 66 74 29 0a 0a 7b  0a 5f 6b 65 72 6e 65 6c  |left)..{._kernel|
000047c0  5f 6f 73 65 72 72 6f 72  20 2a 65 72 72 3b 0a 5f  |_oserror *err;._|
000047d0  6b 65 72 6e 65 6c 5f 73  77 69 5f 72 65 67 73 20  |kernel_swi_regs |
000047e0  72 65 67 73 3b 0a 0a 20  72 65 67 73 2e 72 5b 30  |regs;.. regs.r[0|
000047f0  5d 3d 2d 31 3b 0a 20 72  65 67 73 2e 72 5b 31 5d  |]=-1;. regs.r[1]|
00004800  3d 2d 31 3b 0a 20 72 65  67 73 2e 72 5b 32 5d 3d  |=-1;. regs.r[2]=|
00004810  2d 31 3b 0a 20 65 72 72  3d 5f 6b 65 72 6e 65 6c  |-1;. err=_kernel|
00004820  5f 73 77 69 28 56 69 72  74 75 61 6c 69 73 65 5f  |_swi(Virtualise_|
00004830  43 6f 6e 66 69 67 75 72  65 2c 26 72 65 67 73 2c  |Configure,&regs,|
00004840  26 72 65 67 73 29 3b 0a  0a 20 69 66 20 28 21 65  |&regs);.. if (!e|
00004850  72 72 29 0a 20 7b 0a 0a  20 2a 64 65 66 20 20 20  |rr). {.. *def   |
00004860  20 3d 72 65 67 73 2e 72  5b 30 5d 3b 0a 20 2a 63  | =regs.r[0];. *c|
00004870  61 63 68 65 20 20 3d 72  65 67 73 2e 72 5b 31 5d  |ache  =regs.r[1]|
00004880  3b 0a 20 2a 6c 65 66 74  20 20 20 3d 72 65 67 73  |;. *left   =regs|
00004890  2e 72 5b 32 5d 3b 0a 20  72 65 67 73 2e 72 5b 30  |.r[2];. regs.r[0|
000048a0  5d 3d 32 3b 0a 20 72 65  67 73 2e 72 5b 31 5d 3d  |]=2;. regs.r[1]=|
000048b0  66 6c 65 78 5f 5f 64 61  3b 0a 20 5f 6b 65 72 6e  |flex__da;. _kern|
000048c0  65 6c 5f 73 77 69 28 4f  53 5f 44 79 6e 61 6d 69  |el_swi(OS_Dynami|
000048d0  63 41 72 65 61 2c 26 72  65 67 73 2c 26 72 65 67  |cArea,&regs,&reg|
000048e0  73 29 3b 0a 0a 2a 64 65  66 3d 72 65 67 73 2e 72  |s);..*def=regs.r|
000048f0  5b 35 5d 3b 0a 20 7d 0a  20 20 0a 72 65 74 75 72  |[5];. }.  .retur|
00004900  6e 28 65 72 72 29 3b 0a  7d 0a 0a 0a 5f 6b 65 72  |n(err);.}..._ker|
00004910  6e 65 6c 5f 6f 73 65 72  72 6f 72 20 2a 20 66 6c  |nel_oserror * fl|
00004920  65 78 5f 76 69 72 74 75  61 6c 73 74 61 72 74 28  |ex_virtualstart(|
00004930  63 68 61 72 20 2a 20 73  77 61 70 66 69 6c 65 29  |char * swapfile)|
00004940  0a 7b 0a 5f 6b 65 72 6e  65 6c 5f 73 77 69 5f 72  |.{._kernel_swi_r|
00004950  65 67 73 20 72 65 67 73  3b 0a 5f 6b 65 72 6e 65  |egs regs;._kerne|
00004960  6c 5f 6f 73 65 72 72 6f  72 20 2a 65 72 72 3b 0a  |l_oserror *err;.|
00004970  0a 72 65 67 73 2e 72 5b  30 5d 3d 66 6c 65 78 5f  |.regs.r[0]=flex_|
00004980  5f 64 61 3b 0a 72 65 67  73 2e 72 5b 31 5d 3d 2d  |_da;.regs.r[1]=-|
00004990  31 3b 0a 72 65 67 73 2e  72 5b 32 5d 3d 28 69 6e  |1;.regs.r[2]=(in|
000049a0  74 29 20 73 77 61 70 66  69 6c 65 3b 0a 65 72 72  |t) swapfile;.err|
000049b0  3d 5f 6b 65 72 6e 65 6c  5f 73 77 69 28 56 69 72  |=_kernel_swi(Vir|
000049c0  74 75 61 6c 69 73 65 5f  53 74 61 72 74 2c 26 72  |tualise_Start,&r|
000049d0  65 67 73 2c 26 72 65 67  73 29 3b 0a 0a 69 66 20  |egs,&regs);..if |
000049e0  28 21 65 72 72 29 20 66  6c 65 78 5f 5f 56 4d 3d  |(!err) flex__VM=|
000049f0  54 52 55 45 3b 0a 72 65  74 75 72 6e 28 65 72 72  |TRUE;.return(err|
00004a00  29 3b 0a 20 0a 7d 0a 0a  0a 5f 6b 65 72 6e 65 6c  |);. .}..._kernel|
00004a10  5f 6f 73 65 72 72 6f 72  20 2a 20 66 6c 65 78 5f  |_oserror * flex_|
00004a20  76 69 72 74 75 61 6c 73  74 6f 70 28 76 6f 69 64  |virtualstop(void|
00004a30  29 0a 7b 0a 5f 6b 65 72  6e 65 6c 5f 73 77 69 5f  |).{._kernel_swi_|
00004a40  72 65 67 73 20 72 65 67  73 3b 0a 5f 6b 65 72 6e  |regs regs;._kern|
00004a50  65 6c 5f 6f 73 65 72 72  6f 72 20 2a 65 72 72 3b  |el_oserror *err;|
00004a60  0a 0a 72 65 67 73 2e 72  5b 30 5d 3d 66 6c 65 78  |..regs.r[0]=flex|
00004a70  5f 5f 64 61 3b 0a 65 72  72 3d 5f 6b 65 72 6e 65  |__da;.err=_kerne|
00004a80  6c 5f 73 77 69 28 56 69  72 74 75 61 6c 69 73 65  |l_swi(Virtualise|
00004a90  5f 45 6e 64 2c 26 72 65  67 73 2c 26 72 65 67 73  |_End,&regs,&regs|
00004aa0  29 3b 0a 0a 69 66 20 28  21 65 72 72 29 20 66 6c  |);..if (!err) fl|
00004ab0  65 78 5f 5f 56 4d 3d 46  41 4c 53 45 3b 0a 72 65  |ex__VM=FALSE;.re|
00004ac0  74 75 72 6e 28 65 72 72  29 3b 0a 20 0a 7d 0a 0a  |turn(err);. .}..|
00004ad0  0a 5f 6b 65 72 6e 65 6c  5f 6f 73 65 72 72 6f 72  |._kernel_oserror|
00004ae0  20 2a 20 66 6c 65 78 5f  6c 6f 63 6b 28 69 6e 74  | * flex_lock(int|
00004af0  20 73 74 61 72 74 2c 69  6e 74 20 65 6e 64 29 0a  | start,int end).|
00004b00  7b 0a 5f 6b 65 72 6e 65  6c 5f 73 77 69 5f 72 65  |{._kernel_swi_re|
00004b10  67 73 20 72 65 67 73 3b  0a 5f 6b 65 72 6e 65 6c  |gs regs;._kernel|
00004b20  5f 6f 73 65 72 72 6f 72  20 2a 65 72 72 3d 4e 55  |_oserror *err=NU|
00004b30  4c 4c 3b 0a 0a 69 66 20  28 66 6c 65 78 5f 5f 56  |LL;..if (flex__V|
00004b40  4d 29 0a 20 20 20 20 20  20 20 20 20 20 20 20 20  |M).             |
00004b50  20 20 20 20 20 20 20 20  20 20 20 0a 7b 0a 20 20  |           .{.  |
00004b60  20 72 65 67 73 2e 72 5b  30 5d 3d 73 74 61 72 74  | regs.r[0]=start|
00004b70  3b 0a 20 20 20 72 65 67  73 2e 72 5b 31 5d 3d 65  |;.   regs.r[1]=e|
00004b80  6e 64 3b 0a 20 20 20 65  72 72 3d 5f 6b 65 72 6e  |nd;.   err=_kern|
00004b90  65 6c 5f 73 77 69 28 56  69 72 74 75 61 6c 69 73  |el_swi(Virtualis|
00004ba0  65 5f 4c 6f 63 6b 2c 26  72 65 67 73 2c 26 72 65  |e_Lock,&regs,&re|
00004bb0  67 73 29 3b 20 20 0a 0a  7d 0a 0a 72 65 74 75 72  |gs);  ..}..retur|
00004bc0  6e 28 65 72 72 29 3b 0a  7d 0a 0a 0a 5f 6b 65 72  |n(err);.}..._ker|
00004bd0  6e 65 6c 5f 6f 73 65 72  72 6f 72 20 2a 20 66 6c  |nel_oserror * fl|
00004be0  65 78 5f 75 6e 6c 6f 63  6b 28 69 6e 74 20 73 74  |ex_unlock(int st|
00004bf0  61 72 74 2c 69 6e 74 20  65 6e 64 29 0a 7b 0a 5f  |art,int end).{._|
00004c00  6b 65 72 6e 65 6c 5f 73  77 69 5f 72 65 67 73 20  |kernel_swi_regs |
00004c10  72 65 67 73 3b 0a 5f 6b  65 72 6e 65 6c 5f 6f 73  |regs;._kernel_os|
00004c20  65 72 72 6f 72 20 2a 65  72 72 3d 4e 55 4c 4c 3b  |error *err=NULL;|
00004c30  0a 0a 69 66 20 28 66 6c  65 78 5f 5f 56 4d 29 0a  |..if (flex__VM).|
00004c40  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00004c50  20 20 20 20 20 20 20 20  0a 7b 0a 20 20 20 72 65  |        .{.   re|
00004c60  67 73 2e 72 5b 30 5d 3d  73 74 61 72 74 3b 0a 20  |gs.r[0]=start;. |
00004c70  20 20 72 65 67 73 2e 72  5b 31 5d 3d 65 6e 64 3b  |  regs.r[1]=end;|
00004c80  0a 20 20 20 65 72 72 3d  5f 6b 65 72 6e 65 6c 5f  |.   err=_kernel_|
00004c90  73 77 69 28 56 69 72 74  75 61 6c 69 73 65 5f 55  |swi(Virtualise_U|
00004ca0  6e 6c 6f 63 6b 2c 26 72  65 67 73 2c 26 72 65 67  |nlock,&regs,&reg|
00004cb0  73 29 3b 20 20 0a 0a 7d  0a 0a 72 65 74 75 72 6e  |s);  ..}..return|
00004cc0  28 65 72 72 29 3b 0a 7d  0a 0a 0a 0a 73 74 61 74  |(err);.}....stat|
00004cd0  69 63 20 76 6f 69 64 20  77 65 72 72 28 69 6e 74  |ic void werr(int|
00004ce0  20 66 61 74 61 6c 2c 20  63 68 61 72 2a 20 66 6f  | fatal, char* fo|
00004cf0  72 6d 61 74 2c 20 2e 2e  2e 29 0a 7b 0a 20 20 20  |rmat, ...).{.   |
00004d00  76 61 5f 6c 69 73 74 20  76 61 3b 0a 20 20 20 5f  |va_list va;.   _|
00004d10  6b 65 72 6e 65 6c 5f 6f  73 65 72 72 6f 72 20 65  |kernel_oserror e|
00004d20  3b 0a 0a 20 20 20 65 2e  65 72 72 6e 75 6d 20 3d  |;..   e.errnum =|
00004d30  20 30 3b 0a 20 20 20 76  61 5f 73 74 61 72 74 28  | 0;.   va_start(|
00004d40  76 61 2c 20 66 6f 72 6d  61 74 29 3b 0a 20 20 20  |va, format);.   |
00004d50  76 73 70 72 69 6e 74 66  28 26 65 2e 65 72 72 6d  |vsprintf(&e.errm|
00004d60  65 73 73 5b 30 5d 2c 20  66 6f 72 6d 61 74 2c 20  |ess[0], format, |
00004d70  76 61 29 3b 0a 20 20 20  76 61 5f 65 6e 64 28 76  |va);.   va_end(v|
00004d80  61 29 3b 0a 20 20 20 77  69 6d 70 5f 72 65 70 6f  |a);.   wimp_repo|
00004d90  72 74 5f 65 72 72 6f 72  28 26 65 2c 20 30 2c 20  |rt_error(&e, 0, |
00004da0  22 46 6c 65 78 4c 69 62  72 61 72 79 22 2c 30 2c  |"FlexLibrary",0,|
00004db0  30 2c 30 29 3b 0a 20 20  20 69 66 20 28 66 61 74  |0,0);.   if (fat|
00004dc0  61 6c 29 20 65 78 69 74  28 31 29 3b 0a 7d 0a 0a  |al) exit(1);.}..|
00004dd0  73 74 61 74 69 63 20 63  68 61 72 2a 20 6d 73 67  |static char* msg|
00004de0  73 5f 6c 6f 6f 6b 75 70  28 63 68 61 72 2a 20 74  |s_lookup(char* t|
00004df0  61 67 29 0a 7b 0a 0a 20  5f 6b 65 72 6e 65 6c 5f  |ag).{.. _kernel_|
00004e00  73 77 69 5f 72 65 67 73  20 72 65 67 73 3b 0a 20  |swi_regs regs;. |
00004e10  20 63 68 61 72 2a 20 70  3d 74 61 67 3b 0a 20 20  | char* p=tag;.  |
00004e20  77 68 69 6c 65 20 28 2a  70 2b 2b 21 3d 27 3a 27  |while (*p++!=':'|
00004e30  29 20 4e 55 4c 4c 3b 0a  20 20 70 2d 2d 3b 0a 20  |) NULL;.  p--;. |
00004e40  20 2a 70 2b 2b 3d 30 3b  0a 0a 20 20 20 20 72 65  | *p++=0;..    re|
00004e50  67 73 2e 72 5b 30 5d 20  3d 20 5f 6d 62 6c 6b 3b  |gs.r[0] = _mblk;|
00004e60  0a 20 20 20 20 72 65 67  73 2e 72 5b 31 5d 20 3d  |.    regs.r[1] =|
00004e70  20 28 69 6e 74 29 20 74  61 67 3b 0a 20 20 20 20  | (int) tag;.    |
00004e80  72 65 67 73 2e 72 5b 32  5d 20 3d 20 30 3b 0a 0a  |regs.r[2] = 0;..|
00004e90  20 20 20 20 69 66 20 28  5f 6b 65 72 6e 65 6c 5f  |    if (_kernel_|
00004ea0  73 77 69 28 4d 65 73 73  61 67 65 54 72 61 6e 73  |swi(MessageTrans|
00004eb0  5f 4c 6f 6f 6b 75 70 2c  26 72 65 67 73 2c 26 72  |_Lookup,&regs,&r|
00004ec0  65 67 73 29 29 0a 20 20  20 20 20 72 65 74 75 72  |egs)).     retur|
00004ed0  6e 20 70 3b 0a 20 20 20  20 65 6c 73 65 20 72 65  |n p;.    else re|
00004ee0  74 75 72 6e 20 28 63 68  61 72 20 2a 29 20 72 65  |turn (char *) re|
00004ef0  67 73 2e 72 5b 32 5d 3b  0a 0a 0a 0a 0a 7d 0a 0a  |gs.r[2];.....}..|
00004f00  0a 0a 0a 0a 2f 2a 20 65  6e 64 20 2a 2f 0a 0a     |..../* end */..|
00004f0f