Back to index

tetex-bin  3.0
Defines | Functions | Variables
objects.c File Reference
#include "types.h"
#include <string.h>
#include <ctype.h>
#include "objects.h"
#include "spaces.h"
#include "paths.h"
#include "regions.h"
#include "fonts.h"
#include "pictures.h"
#include "strokes.h"
#include "cluts.h"

Go to the source code of this file.

Defines

#define GLOBALS   1 /* see :hdref refid=debugvar. */
#define RefRoll(obj)   (++(obj)->references > 0)
#define NAMESIZE   40

Functions

static char * TypeFmt ()
static int ObjectPostMortem (struct xobject *obj)
struct xobjectt1_Allocate (int size, struct xobject *template, int extra)
void Free (struct xobject *obj)
struct xobjectt1_Permanent (struct xobject *obj)
struct xobjectxiTemporary (struct xobject *obj)
struct xobjectt1_Dup (struct xobject *obj)
struct xobjectt1_Copy (struct xobject *obj)
struct xobjectDestroy (struct xobject *obj)
struct xobjectt1_Unique (struct xobject *obj)
void Pragmatics (char *username, int value)
void Consume (int n, struct xobject *obj1, struct xobject *obj2, struct xobject *obj3)
struct xobjectTypeErr (char *name, struct xobject *obj, int expect, struct xobject *ret)
static char * TypeFmt (int type)
static int ObjectPostMortem (register struct xobject *obj)
struct xobjectArgErr (char *str, struct xobject *obj, struct xobject *ret)
void t1_abort (char *str)
char * ErrorMsg ()
void InitImager ()
void TermImager ()
void reportusage ()

Variables

static char * ErrorMessage = NULL
static int test = 0

Define Documentation

#define GLOBALS   1 /* see :hdref refid=debugvar. */

Definition at line 47 of file objects.c.

#define NAMESIZE   40
#define RefRoll (   obj)    (++(obj)->references > 0)

Definition at line 244 of file objects.c.


Function Documentation

struct xobject* ArgErr ( char *  str,
struct xobject obj,
struct xobject ret 
) [read]

Definition at line 1055 of file objects.c.

{
       if (MustCrash)
               LineIOTrace = TRUE;
       IfTrace1(TRUE,"ARGUMENT ERROR-- %s.\n", str);
       if (obj != NULL)
               ObjectPostMortem(obj);
       if (MustCrash)
               t1_abort("Terminating because of CrashOnUserError...");
       else
               ErrorMessage = str;
       return(ret);
}

Here is the call graph for this function:

void Consume ( int  n,
struct xobject obj1,
struct xobject obj2,
struct xobject obj3 
)

Definition at line 913 of file objects.c.

{
       switch(n) {
 
           case 0:
               return;
 
           case 1:
               if (obj1 != NULL && !ISPERMANENT(obj1->flag))
                       Destroy(obj1);
               return;
 
           case 2:
               if (obj1 != NULL && !ISPERMANENT(obj1->flag))
                       Destroy(obj1);
               if (obj2 != NULL && !ISPERMANENT(obj2->flag))
                       Destroy(obj2);
               return;
 
           case 3:
               if (obj1 != NULL && !ISPERMANENT(obj1->flag))
                       Destroy(obj1);
               if (obj2 != NULL && !ISPERMANENT(obj2->flag))
                       Destroy(obj2);
               if (obj3 != NULL && !ISPERMANENT(obj3->flag))
                       Destroy(obj3);
               return;
 
           default:
               t1_abort("Consume:  too many objects");
       }
}

Here is the call graph for this function:

struct xobject* Destroy ( struct xobject obj) [read]

Definition at line 568 of file objects.c.

{
       IfTrace1((MustTraceCalls),"Destroy(%p)\n", obj);
 
       if (obj == NULL)
               return(NULL);
       if (ISIMMORTAL(obj->flag)) {
               IfTrace1(TRUE,"Destroy of immortal object %p ignored\n", obj);
               return(NULL);
       }
       if (ISPATHTYPE(obj->type))
               KillPath(obj);
       else {
               switch (obj->type) {
                   case REGIONTYPE:
                       KillRegion(obj);
                       break;
                   case SPACETYPE:
                       KillSpace(obj);
                       break;
                   case LINESTYLETYPE:
                       KillLineStyle(obj);
                       break;
                   case FONTTYPE:
                       KillFont(obj);
                       break;
                   case PICTURETYPE:
                       KillPicture(obj);
                       break;
                   case STROKEPATHTYPE:
                       KillStrokePath(obj);
                       break;
                   case CLUTTYPE:
                       KillCLUT(obj);
                       break;
                   default:
                       return(ArgErr("Destroy: invalid object", obj, NULL));
               }
       }
       return(NULL);
}
char* ErrorMsg ( )

Definition at line 1098 of file objects.c.

{
       register char *r;
 
       r = ErrorMessage;
       ErrorMessage = NULL;
       return(r);
}
void Free ( struct xobject obj)

Definition at line 357 of file objects.c.

{
       if (obj->type == INVALIDTYPE)
               t1_abort("Free of already freed object?");
       obj->type = INVALIDTYPE;
 
       if (MemoryDebug > 1) {
               register int *L;
               L = (int *) obj;
               IfTrace4(TRUE,"Freeing at %p: %x %x %x\n", L, L[-1], L[0], L[1]);
       }
 
       Xfree(obj);
}

Here is the call graph for this function:

Definition at line 1116 of file objects.c.

{
 
/* Check to see if we have been using our own malloc.  If so,*/
/* Undef malloc so that we can get to the system call. */
/* All other calls to malloc are defined to Xalloc.  */
 
       if (sizeof(SHORT) != 2 || sizeof(LONG) != 4)
          t1_abort("Fundamental TYPE1IMAGER assumptions invalid in this port");
       InitSpaces();
       InitFonts();
       InitFiles();
/*
In some environments, constants and/or exception handling need to be
*/
       LibInit();
}

Here is the call graph for this function:

static int ObjectPostMortem ( struct xobject obj) [static]
static int ObjectPostMortem ( register struct xobject obj) [static]

Definition at line 1032 of file objects.c.

{
       extern struct XYspace *USER;
 
       Pragmatics("Debug", 10);
       IfTrace2(TRUE,"Bad object is of %s type %p\n", TypeFmt(obj->type), obj);
 
       IfTrace0((obj == (struct xobject *) USER),
                  "Suspect that InitImager() was omitted.\n");
       Pragmatics("Debug", 0);

       /* NOTREACHED? */
       return 0;
}

Here is the call graph for this function:

void Pragmatics ( char *  username,
int  value 
)

Definition at line 771 of file objects.c.

{
       register char *p;     /* temporary loop variable                      */
#define    NAMESIZE   40
       char name[NAMESIZE];  /* buffer to store my copy of 'username'        */
 
       if (strlen(username) >= NAMESIZE)
               t1_abort("Pragmatics name too large");
       strcpy(name, username);
       for (p = name; *p != '\0'; p++)
               *p = toupper(*p);
 
       if (!strcmp(name, "ALL"))
               MustTraceCalls = InternalTrace = /* MustCrash = */
                    LineIOTrace = value;
 
       else if (!strcmp(name, "LINEIOTRACE"))
               LineIOTrace = value;
 
       else if (!strcmp(name, "TRACECALLS"))
               MustTraceCalls = value;
 
       else if (!strcmp(name, "CHECKARGS"))
               MustCheckArgs = value;
 
       else if (!strcmp(name, "PROCESSHINTS"))
               ProcessHints = value;
 
       else if (!strcmp(name, "SAVEFONTPATHS"))
               SaveFontPaths = value;
 
       else if (!strcmp(name, "CRASTERCOMPRESSIONTYPE"))
               CRASTERCompressionType = value;
 
       else if (!strcmp(name, "CRASHONUSERERROR"))
               MustCrash = value;
 
       else if (!strcmp(name, "DEBUG"))
               StrokeDebug = SpaceDebug = PathDebug = ConicDebug = LineDebug =
                          RegionDebug = MemoryDebug = FontDebug =
                          HintDebug = ImageDebug = OffPageDebug = value;
 
       else if (!strcmp(name, "CONICDEBUG"))
               ConicDebug = value;
 
       else if (!strcmp(name, "LINEDEBUG"))
               LineDebug = value;
 
       else if (!strcmp(name, "REGIONDEBUG"))
               RegionDebug = value;
 
       else if (!strcmp(name, "PATHDEBUG"))
               PathDebug = value;
 
       else if (!strcmp(name, "SPACEDEBUG"))
               SpaceDebug = value;
 
       else if (!strcmp(name, "STROKEDEBUG"))
               StrokeDebug = value;
 
       else if (!strcmp(name, "MEMORYDEBUG"))
               MemoryDebug = value;
 
       else if (!strcmp(name, "FONTDEBUG"))
               FontDebug = value;
 
       else if (!strcmp(name, "HINTDEBUG"))
               HintDebug = value;
 
       else if (!strcmp(name, "IMAGEDEBUG"))
               ImageDebug = value;
 
       else if (!strcmp(name, "OFFPAGEDEBUG"))
               OffPageDebug = value;
 
#ifdef  MC68000
/*
The following pragmatics flag turns on or off instruction histograming
for performance analysis.  It is only defined in the Delta card
environment.
*/
       else if (!strcmp(name, "PROFILE")) {
               if (value)
                       StartProfile();
               else
                       StopProfile();
       }
#endif
       else if (!strcmp(name, "FLUSHCACHE")) {
               while (GimeSpace()) { ; }
       }
 
       else if (!strcmp(name, "CACHEDCHARS"))
               CachedChars = (value <= 0) ? 1 : value;
 
       else if (!strcmp(name, "CACHEDFONTS"))
               CachedFonts = (value <= 0) ? 1 : value;
 
       else if (!strcmp(name, "CACHEBLIMIT"))
               CacheBLimit = value;
 
       else if (!strcmp(name, "CONTINUITY"))
               Continuity = value;
 
 
       else {
               printf("Pragmatics flag = '%s'\n", name);
               ArgErr("Pragmatics:  flag not known", NULL, NULL);
       }
       return;
}

Here is the call graph for this function:

Definition at line 1146 of file objects.c.

{
       return;
}
void t1_abort ( char *  str)

Definition at line 1082 of file objects.c.

{
       LineIOTrace = TRUE;
       IfTrace1(TRUE,"\nABORT: reason='%s'\n", str);
       TraceClose();
       test = 1/test;
       exit(99);
}

Here is the call graph for this function:

struct xobject* t1_Allocate ( int  size,
struct xobject template,
int  extra 
) [read]

Definition at line 285 of file objects.c.

{
#ifdef WIN32
       extern char *Xalloc(int); /* standard C routine */
#else
       extern char *Xalloc();  /* standard C routine                         */
#endif 
       register struct xobject *r;
 
       /*
       * round up 'size' and 'extra' to be an integer number of 'long's:
       */
       size = (size + sizeof(LONG) - 1) & -sizeof(LONG);
       extra = (extra + sizeof(LONG) - 1) & -sizeof(LONG);
       if (size + extra <= 0)
               t1_abort("Non-positive allocate?");
       r = (struct xobject *) Xalloc(size + extra);
 
       while (r == NULL) {
               if (!GimeSpace()) {
                       IfTrace1(TRUE, "malloc attempted %d bytes.\n",
                                           size + extra);
                       t1_abort("We have REALLY run out of memory");
               }
               r = (struct xobject *) Xalloc(size + extra);
       }
 
       /*
       * copy the template into the new memory:
       */
       if (template != NULL) {
       /* Added references count decrement if template is not permanent.
          This is for the case where Allocate is called by a Dupxxxx
          function, which was in turn called by Unique(). (PNM)        */
               if (!ISPERMANENT(template->flag))
                   --template->references;
               LONGCOPY(r, template, size);
               r->flag &= ~(ISPERMANENT(ON) | ISIMMORTAL(ON));
       /* added reference field 3-2-6-91 PNM */
               r->references = 1;
       }
       else {
               register char **p1;
 
               for (p1=(char **)r; size > 0; size -= sizeof(char *))
                       *p1++ = NULL;
       }
 
       if (MemoryDebug > 1) {
               register int *L;
               L = (int *) r;
               IfTrace4(TRUE, "Allocating at %p: %x %x %x\n",
                                           L, L[-1], L[0], L[1]);
       }
       return(r);
}

Here is the call graph for this function:

struct xobject* t1_Copy ( struct xobject obj) [read]

Definition at line 531 of file objects.c.

{
       if (obj == NULL)
               return(NULL);
 
       if (ISPATHTYPE(obj->type))
               obj = (struct xobject *) CopyPath(obj);
       else
               switch (obj->type) {
                   case SPACETYPE:
                       obj = (struct xobject *) CopySpace(obj); break;
                   case FONTTYPE:
                       obj = (struct xobject *) CopyFont(obj); break;
                   case REGIONTYPE:
                       obj = (struct xobject *) CopyRegion(obj); break;
                   case PICTURETYPE:
                       obj = (struct xobject *) CopyPicture(obj); break;
                   case LINESTYLETYPE:
                       obj = (struct xobject *) CopyLineStyle(obj); break;
                   case STROKEPATHTYPE:
                       obj = (struct xobject *) CopyStrokePath(obj); break;
                   case CLUTTYPE:
                       obj = (struct xobject *) CopyCLUT(obj); break;
                   default:
                       return(ArgErr("Copy: invalid object", obj, NULL));
               }
 
        return(obj);
}
struct xobject* t1_Dup ( struct xobject obj) [read]

Definition at line 486 of file objects.c.

{
       register char oldflag;   /* copy of original object's flag byte */
 
       IfTrace1((MustTraceCalls),"Dup(%p)\n", obj);
 
       if (obj == NULL)
               return(NULL);
       /* An immortal object must be Copy'ed, so that we get a mortal
          copy of it, since we try not to destroy immortal objects. */
       if (ISIMMORTAL(obj->flag))
           return(Copy(obj));
 
       /* if incrementing the reference count doesn't cause the count
          to wrap, simply return the object with the count bumped. Note
          that the RefRoll macro increments the count to perform the
          rollover check, so we must decrement the count. */
       if (RefRoll(obj))
           return(obj);
 
       /* that didn't work out, so put the count back and call Copy(). */
       --obj->references;
       oldflag = obj->flag;
       obj = Copy(obj);
       if (ISPERMANENT(oldflag))
               obj = Permanent(obj);
       return(obj);
}
struct xobject* t1_Permanent ( struct xobject obj) [read]

Definition at line 397 of file objects.c.

{
       IfTrace1((MustTraceCalls),"Permanent(%p)\n", obj);
 
       if ( (obj != NULL) && ( !(ISPERMANENT(obj->flag)) ) )
       {
       /* there is a non-NULL, temporary object to be made permanent.
          If there are multiple references to this object, first get
          a new COPY().
          Note also that we have to decrement the reference count if
          we do a Copy() here, because we are consuming the temporary
          argument passed, and returning a unique, permanent one.
       */
           if ( obj->references > 1)
           {
               obj = Copy(obj);
           }
           /* now set the permanent flag, and increment the reference
              count, since a temporary object has now become permanent. */
           obj->references++;
           obj->flag |= ISPERMANENT(ON);
       }
       return(obj);
}
struct xobject* t1_Unique ( struct xobject obj) [read]

Definition at line 725 of file objects.c.

{
    /* if the original object is not already unique, make a unique
       copy...Note also that if the object was not permanent, we must
       consume the old handle! 3-26-91 PNM
       NOTE : consumption of the old handle moved to Allocate. 4-18-91 */
    if (!obj || obj->references == 1)
        return(obj);
 
    obj = Copy(obj);
    /* and make sure we return a temporary object ! */
    if (ISPERMANENT(obj->flag))
    {
        obj->flag &= ~ISPERMANENT(ON);
        obj->references--;
    }
    return(obj);
}

Definition at line 1139 of file objects.c.

{
       return;
}
struct xobject* TypeErr ( char *  name,
struct xobject obj,
int  expect,
struct xobject ret 
) [read]

Definition at line 952 of file objects.c.

{
       static char typemsg[80];
 
       if (MustCrash)
               LineIOTrace = TRUE;
 
       sprintf(typemsg, "Wrong object type in %s; expected %s seen %s\n",
                  name, TypeFmt(expect), TypeFmt(obj->type));
       IfTrace0(TRUE,typemsg);
 
       ObjectPostMortem(obj);
 
       if (MustCrash)
               t1_abort("Terminating because of CrashOnUserError...");
       else
               ErrorMessage = typemsg;
 
/* changed ISPERMANENT to ret->references > 1 3-26-91 PNM */
       if (ret != NULL && (ret->references > 1))
               ret = Dup(ret);
       return(ret);
}

Here is the call graph for this function:

static char* TypeFmt ( ) [static]
static char* TypeFmt ( int  type) [static]

Definition at line 986 of file objects.c.

{
       char *r;
 
       if (ISPATHTYPE(type))
               if (type == TEXTTYPE)
                       r = "path or region (from TextPath)";
               else
                       r = "path";
       else {
               switch (type) {
                   case INVALIDTYPE:
                       r = "INVALID (previously consumed?)";
                       break;
                   case REGIONTYPE:
                       r = "region";
                       break;
                   case SPACETYPE:
                       r = "XYspace";
                       break;
                   case LINESTYLETYPE:
                       r = "linestyle";
                       break;
                   case FONTTYPE:
                       r = "font";
                       break;
                   case PICTURETYPE:
                       r = "picture";
                       break;
                   case STROKEPATHTYPE:
                       r = "path (from StrokePath)";
                       break;
                   default:
                       r = "UNKNOWN";
                       break;
               }
       }
       return(r);
}
struct xobject* xiTemporary ( struct xobject obj) [read]

Definition at line 441 of file objects.c.

{
       IfTrace1((MustTraceCalls),"Temporary(%p)\n", obj);
 
       if (obj != NULL) {
               /* if it's already temporary, there's nothing to do. */
               if ISPERMANENT(obj->flag)
               {
               /* if there are multiple references to this object, get a
                  Copy we can safely alter. Recall that the reference count
                  is incremented for permanent objects.
                  Recall further that Copy returns an object with the
                  same flag state and a reference count of 2 (for PERMANENT
                  objects).
                  Thus, regardless of whether or not we need to copy a
                  permanent object, we still decrement its reference
                  count and reset the flag.
               */
                   if (obj->references != 2 || ISIMMORTAL(obj->flag))
                   {
               /* not unique; consume handle, get a temporary Copy! */
                       obj = Copy(obj);
                   }
               /* else decrement the reference count (since it's going from
                  permanent to temporary) and clear the flag. */
                   else {
                       obj->references--;
                       obj->flag &= ~ISPERMANENT(ON);
                   }
               }
       }
       return(obj);
}

Variable Documentation

char* ErrorMessage = NULL [static]

Definition at line 763 of file objects.c.

int test = 0 [static]

Definition at line 1079 of file objects.c.