Back to index

tetex-bin  3.0
Defines | Functions | Variables
objects.c File Reference
#include "types.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <setjmp.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 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 (struct xobject *obj)
struct xobjectArgErr (char *string, struct xobject *obj, struct xobject *ret)
void abort (char *string, int no)
char * t1_get_abort_message (int number)
char * ErrorMsg ()
void InitImager ()
void TermImager ()
void reportusage (void)

Variables

struct XYspaceUSER
jmp_buf stck_state
static char * ErrorMessage = NULL

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 249 of file objects.c.


Function Documentation

void abort ( char *  string,
int  no 
)

Definition at line 1077 of file objects.c.

{
  
  LineIOTrace = TRUE;
  TraceClose();
  longjmp( stck_state, no);

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

Definition at line 1051 of file objects.c.

{
       if (MustCrash)
               LineIOTrace = TRUE;
       IfTrace1(TRUE,"ARGUMENT ERROR-- %s.\n", string);
       if (obj != NULL)
               ObjectPostMortem(obj);
       if (MustCrash)
               abort("Terminating because of CrashOnUserError...", 21);
       else
               ErrorMessage = string;
       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 909 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:
               abort("Consume:  too many objects", 19);
       }
}

Here is the call graph for this function:

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

Definition at line 575 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 macro removed from sources (RMz, 2001-04-01)
                       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 1157 of file objects.c.

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

Definition at line 364 of file objects.c.

{
       if (obj->type == INVALIDTYPE)
               abort("Free of already freed object?", 17);
       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]);
       }
 
       free(obj);
}

Here is the call graph for this function:

Definition at line 1175 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)
          abort("Fundamental TYPE1IMAGER assumptions invalid in this port", 22);
       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 ( ) [static]

Here is the caller graph for this function:

static int ObjectPostMortem ( struct xobject obj) [static]

Definition at line 1028 of file objects.c.

{
 
       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);
       /* We return a value to make ANSI-compiler happy */
       return(0);
       
}

Here is the call graph for this function:

void Pragmatics ( char *  username,
int  value 
)

Definition at line 780 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)
               abort("Pragmatics name too large", 18);
       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
       /* GimeSpace() is define as false ... */
       /*
       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 1205 of file objects.c.

{
       return;
}
struct xobject* t1_Allocate ( int  size,
struct xobject template,
int  extra 
) [read]

Definition at line 296 of file objects.c.

{
 
       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)
               abort("Non-positive allocate?", 15);
       r = (struct xobject *) malloc(size + extra);
 
       while (r == NULL) {
               if (!GimeSpace()) {
                       IfTrace1(TRUE, "malloc attempted %d bytes.\n",
                                           size + extra);
                       abort("We have REALLY run out of memory", 16);
               }
               r = (struct xobject *) malloc(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);
}
struct xobject* t1_Copy ( struct xobject obj) [read]

Definition at line 538 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 493 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);
}
char* t1_get_abort_message ( int  number)

Definition at line 1089 of file objects.c.

{
  static char *err_msgs[]={
    "DLdiv:  dividend too large", /* 1 */
    "divide algorithm error", /* 2 */
    "Beziers this big not yet supported", /* 3 */
    "ComputeHint: invalid orientation", /* 4 */
    "ComputeHint: invalid hinttype", /* 5 */
    "ComputeHint: invalid orientation", /* 6 */
    "ProcessHint: invalid label", /* 7 */
    "ProcessHint: label is not in use", /* 8  */
    "ProcessHint: invalid label", /* 9 */
    "ProcessHint: invalid adjusttype", /* 10 */
    "bad subpath chain", /* 11 */
    "ImpliedHorizontalLine:  why ask?", /* 12 */
    "disjoint subpath?", /* 13 */
    "unable to fix subpath break?", /* 14 */
    "Non-positive allocate?", /* 15 */
    "We have REALLY run out of memory", /* 16 */
    "Free of already freed object?", /* 17 */
    "Pragmatics name too large", /* 18 */
    "Consume:  too many objects", /* 19 */
    "Terminating because of CrashOnUserError...", /* 20 */
    "Terminating because of CrashOnUserError...", /* 21 */
    "Fundamental TYPE1IMAGER assumptions invalid in this port", /* 22 */
    "Reverse: bad path segment", /* 23 */
    "UnClose:  no LASTCLOSED", /* 24 */
    "PathTransform:  invalid segment", /* 25 */
    "QueryPath: unknown segment", /* 26 */
    "QueryBounds: unknown type", /* 27 */
    "KillRegion:  negative reference count", /* 28 */
    "newedge: height not positive", /* 29 */
    "Interior: path type error", /* 30 */
    "Unwind:  uneven edges", /* 31 */
    "negative sized edge?", /* 32 */
    "splitedge: above top of list", /* 33 */
    "splitedge: would be null", /* 34 */
    "null splitedge", /* 35 */
    "vertjoin not disjoint", /* 36 */
    "SwathUnion:  0 height swath?", /* 37 */
    "discard():  ran off end", /* 38 */
    "UnJumble:  unpaired edge?", /* 39 */
    "Tighten: existing edge bound was bad", /* 40  */
    "Tighten: existing region bound was bad", /* 41 */
    "EDGE ERROR: non EDGETYPE in list", /* 42 */
    "EDGE ERROR: overlapping swaths", /* 43 */
    "Context:  QueryDeviceState didn't work", /* 44 */
    "QueryDeviceState returned invalid orientation", /* 45 */
    "Context:  out of them", /* 46 */
    "MatrixInvert:  can't", /* 47 */
    "xiStub called", /* 48 */
    "Illegal access type1 abort() message" /* 49 */
  };

  /* no is valid from 1 to 48 */
  if ( (number<1)||(number>48))
    number=49;
  return( err_msgs[number-1]);
    
}

Here is the caller graph for this function:

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

Definition at line 404 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 734 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 1198 of file objects.c.

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

Definition at line 947 of file objects.c.

{
       static char typemsg[80];
 
       if (MustCrash)
               LineIOTrace = TRUE;
 
       sprintf(typemsg, "Wrong object type in %s; expected %s, found %s.\n",
                  name, TypeFmt(expect), TypeFmt(obj->type));
       IfTrace0(TRUE,typemsg);
 
       ObjectPostMortem(obj);
 
       if (MustCrash)
               abort("Terminating because of CrashOnUserError...", 20);
       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]

Here is the caller graph for this function:

static char* TypeFmt ( int  type) [static]

Definition at line 981 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 448 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 772 of file objects.c.

jmp_buf stck_state

Definition at line 114 of file t1global.h.

struct XYspace* USER

Definition at line 921 of file spaces.c.