1 /* $XConsortium: objects.c,v 1.11 94/03/23 14:28:05 gildea Exp $ */
2 /* Copyright International Business Machines, Corp. 1991
4 * Copyright Lexmark International, Inc. 1991
7 * License to use, copy, modify, and distribute this software and its
8 * documentation for any purpose and without fee is hereby granted,
9 * provided that the above copyright notice appear in all copies and that
10 * both that copyright notice and this permission notice appear in
11 * supporting documentation, and that the name of IBM or Lexmark not be
12 * used in advertising or publicity pertaining to distribution of the
13 * software without specific, written prior permission.
15 * IBM AND LEXMARK PROVIDE THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES OF
16 * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO ANY
17 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
18 * AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. THE ENTIRE RISK AS TO THE
19 * QUALITY AND PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
20 * OR MAINTAIN, BELONGS TO THE LICENSEE. SHOULD ANY PORTION OF THE
21 * SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM OR LEXMARK) ASSUMES THE
22 * ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION. IN NO EVENT SHALL
23 * IBM OR LEXMARK BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
24 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
25 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
26 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
29 /* OBJECTS CWEB V0025 ******** */
31 :h1.OBJECTS Module - TYPE1IMAGER Objects Common Routines
33 This module defines and implements the C structures that represent
34 objects in the TYPE1IMAGER. All common routines for manipulating these
35 objects are defined in this module. Specific routines for
36 specific objects are defined in the modules that deal with that
40 &author. Jeffrey B. Lotspiech (lotspiech@almaden.ibm.com)
45 The included files are:
47 #define GLOBALS 1 /* see :hdref refid=debugvar. */
49 The following two includes are C standards; we include them because we
50 use 'toupper' and the 'str'-type functions in this module. Potentially
51 these may be defined as macros; if these ".h" files do not exist on your
52 system it is a pretty safe bet that these are external entry points and
53 you do do not need to include these header files.
60 override incorrect system functions; for example you might define
61 a macro for "strcpy" that diverts it to "my_strcpy".
64 /* moved these includes from above the */
65 /* was included first (it contains com- */
66 /* piler defines). dsr 081291 */
75 static char *TypeFmt();
76 static ObjectPostMortem();
79 :h3.The "pointer" Macro - Define a Generic Pointer
81 Sadly, many compilers will give a warning message when a pointer to
82 one structure is assigned to a pointer to another. We've even seen
83 some that give severe errors (when the wrong pointer type is used as
84 an initializer or returned from a function). TYPE1IMAGER has routines
85 like Dup and Allocate that are perfectly willing to duplicate or
86 allocate any of a number of different types of structures. How to
87 declare them in a truely portable way?
89 Well, there is no single good answer that I've found. You can always
90 beg the question and "cast" everything. I find this distracting and the
91 resulting code ugly. On the other hand, we have found at least one
92 compiler that will accept "void *" as a generic pointer that can
93 assigned to any other pointer type without error or warning (apparently
94 this is also the ANSI standard). So, we define "void *" to be a generic
95 pointer. (You might have to change this for your compiler; the "ifndef"
96 allows the change to be made on the command line if you want.)
97 :i1/portability assumptions/
99 /*SHARED LINE(S) ORIGINATED HERE*/
101 :h3.Functions Provided to the TYPE1IMAGER User
103 This module provides the following TYPE1IMAGER entry points:
105 /*SHARED LINE(S) ORIGINATED HERE*/
107 Note that entry points that are intended for use external to TYPE1IMAGER
108 begin with the characters :q/xi/. Macros are used to make the names
113 :h3.Functions Provided to Other Modules
115 This module provides the following functions for other modules:
117 /*SHARED LINE(S) ORIGINATED HERE*/
119 Note that entry points that intended for use within TYPE1IMAGER, but
120 which must be global because they are used across module boundaries,
121 begin with the characters :q/I_/. Macros are used to make the names
124 Entry points totally within a module use mnemonic names and are
125 declared :hp2/static/. One of the compilers I used had a bug when
126 static functions were passed as addresses. Thus, some functions
127 which are logically "static" are not so declared.
129 Note also the trick of declaring routines, like Consume(), with a
130 variable number of arguments. To avoid the restrictions on variable
131 numbers of arguments in the macro processor, we just replace the
132 text 'Consume' with 'I_Consume'.
135 :h3.Macros Provided to Other Modules
137 This is the module where we define all the useful constants like
138 TRUE, FALSE, and NULL, and simple expressions like MIN(), MAX(), and ABS().
139 We might as well get to it right here:
141 /*SHARED LINE(S) ORIGINATED HERE*/
143 Notice that upper case is used for constant values and macro
144 definitions. I generally follow that convention.
146 Many more global macros are defined later in this module.
149 :h2.Basic TYPE1IMAGER Object Structure
151 All TYPE1IMAGER objects which are available to the user have a common
152 header. This header is defined below:
155 /*SHARED LINE(S) ORIGINATED HERE*/
157 The following define is an attempt to centralize the definition of the
158 common xobject data shared by structures that are derived from the
159 generic xobject structure. For example, the structure font, defined in
166 ... other data types & structs ...
169 would now be defined as:
173 ... other data types & structs ...
176 Thus we have a better-structured inheritance mechanism. 3-26-91 PNM
178 /*SHARED LINE(S) ORIGINATED HERE*/
180 :h3.Object Type Definitions
182 These constants define the values which go in the 'type' field of
183 an TYPE1IMAGER object structure:
185 /*SHARED LINE(S) ORIGINATED HERE*/
187 :h3.Flag Byte Definitions
189 Many programmers define flag bits as a mask (for example, 0x04), and
190 test, set, and reset them as follows:
193 if ((flag & PERMANENT) != 0)
196 flag &= &inv.PERMANENT;
199 I favor a style where the 'if' statement can ask a question:
202 if (ISPERMANENT(flag))
204 flag |= ISPERMANENT(ON);
205 flag &= &inv.ISPERMANENT(ON);
208 This said, we now define two bit settings of the flag byte of the
209 object. "ISPERMANENT" will be set by the user, when he calls
210 Permanent(). "ISIMMORTAL" will be used for compiled-in objects
211 that we don't want the user to ever destroy.
213 /*SHARED LINE(S) ORIGINATED HERE*/
215 Flag bit definitions that apply to all objects are assigned
216 starting with the least significant (0x01) bit. Flag bit definitions
217 specific to a certain object type are assigned starting with the
218 most significant (0x80) bit. We hope they never meet.
221 :h3 id=preserve.PRESERVE() Macro
223 Occasionally an TYPE1IMAGER operator is implemented by calling other
224 TYPE1IMAGER operators. For example, Arc2() calls Conic(). When we
225 call more than one operator as a subroutine, we have to be careful
226 of temporary objects. A temporary object will be consumed by the
227 subroutine operator and then is no longer available for the caller.
228 This can be prevented simply by bumping a temporary object's reference
231 /*SHARED LINE(S) ORIGINATED HERE*/
234 :h3.RefRoll() Macro to Detect References Count Rollover
236 The following macro is designed to check for reference count rollover.
237 A return value of TRUE means rollover has not occurred; a return value
238 of FALSE means we cannot increment the reference count. Note also that
239 those functions that use this macro must decrement the reference count
240 afterwards. 3-26-91 PNM
243 #define RefRoll(obj) (++(obj)->references > 0)
246 :h2.TYPE1IMAGER Object Functions
248 :h3.LONGCOPY() - Macro to Copy "long" Aligned Data
250 Copying arbitrary bytes in C is a bit of a problem. "strcpy" can't be
251 used, because 0 bytes are special-cased. Most environments have a
252 routine "memcopy" or "bcopy" or "bytecopy" that copies memory containing
253 zero bytes. Sadly, there is no standard on the name of such a routine,
254 which makes it impossible to write truely portable code to use it.
256 It turns out that TYPE1IMAGER, when it wants to copy data, frequently
257 knows that both the source and destination are aligned on "long"
258 boundaries. This allows us to copy by using "long *" pointers. This
259 is usually very efficient on almost all processors. Frequently, it
260 is more efficient than using general-purpose assembly language routines.
261 So, we define a macro to do this in a portable way. "dest" and "source"
262 must be long-aligned, and "bytes" must be a multiple of "sizeof(long)":
264 /*SHARED LINE(S) ORIGINATED HERE*/
266 :h3.Allocate() - Allocating a Memory Block
268 Allocate returns a pointer to memory object that is a copy of
269 the template passed (if any). In addition, extra bytes may be
270 allocated contiguously with the object. (This may be useful for
271 variable size objects such as edge lists. See :hdref refid=regions..)
273 Allocate() always returns a non-immortal object, even if the template is
274 immortal. Therefore a non-NULL template must have a "flag" byte.
276 If the template is NULL, then 'size' bytes are cleared to all NULLs.
278 If the template is non-NULL, a new object is allocated in memory.
279 It therefore seems logical that its reference count field should be
280 set to 1. So, a nun-NULL template must also have a "references" field.
284 struct xobject *t1_Allocate(size, template, extra) /* non-ANSI; type checking was too strict */
285 register int size; /* number of bytes to allocate & initialize */
286 register struct xobject *template; /* example structure to allocate */
287 register int extra; /* any extra uninitialized bytes needed contiguously */
289 extern char *xiMalloc(); /* standard C routine */
291 register struct xobject *r;
294 * round up 'size' and 'extra' to be an integer number of 'long's:
296 size = (size + sizeof(long) - 1) & -(int)sizeof(long);
297 extra = (extra + sizeof(long) - 1) & -(int)sizeof(long);
298 if (size + extra <= 0)
299 abort("Non-positive allocate?");
300 r = (struct xobject *) xiMalloc(size + extra);
304 IfTrace1(TRUE, "malloc attempted %d bytes.\n",
306 abort("We have REALLY run out of memory");
308 r = (struct xobject *) xiMalloc(size + extra);
312 * copy the template into the new memory:
314 if (template != NULL) {
315 /* Added references count decrement if template is not permanent.
316 This is for the case where Allocate is called by a Dupxxxx
317 function, which was in turn called by Unique(). (PNM) */
318 if (!ISPERMANENT(template->flag))
319 --template->references;
320 LONGCOPY(r, template, size);
321 r->flag &= ~(ISPERMANENT(ON) | ISIMMORTAL(ON));
322 /* added reference field 3-2-6-91 PNM */
328 for (p1=(char **)r; size > 0; size -= sizeof(char *))
332 if (MemoryDebug > 1) {
335 IfTrace4(TRUE, "Allocating at %x: %x %x %x\n",
336 L, L[-1], L[0], L[1]);
342 :h3.Free() - Frees an Allocated Object
344 This routine makes a sanity check to make sure the "type" field of the
345 standard object structure has not been cleared. If the object is
346 not a standard structure, then the macro "NonObjectFree" is available
347 that does not perform this check.
349 In either case, the object must not be the NULL pointer. This preserves
350 portability, as the C system xiFree() will not always accept NULL.
353 void Free(obj) /* non-ANSI to avoid overly strict type checking */
354 register struct xobject *obj; /* structure to free */
356 if (obj->type == INVALIDTYPE)
357 abort("Free of already freed object?");
358 obj->type = INVALIDTYPE;
360 if (MemoryDebug > 1) {
363 IfTrace4(TRUE,"Freeing at %x: %x %x %x\n", L, L[-1], L[0], L[1]);
370 :h3.Permanent() - Makes an Object Permanent
372 Real simple--just set a flag. Every routine that consumes its objects
373 (which is almost every user entry) must check this flag, and not consume
374 the object if it is set.
376 If a temporary object is made permanent, and there is more than one
377 reference to it, we must first Copy() it, then set the ISPERMANENT
378 flag. Note also that the reference count must be incremented when an
379 object is changed from temporary to permanent (see the ISUNIQUE macro).
381 Note that the purpose of this function is to convert an object into a
383 If it was permanent to begin with, we do nothing;
384 If it was temporary and unique, we set the PERMANENT flag and increment
386 If it was temporary and nonunique, we must make a unique Copy(), set
387 the PERMANENT flag, and set the reference count to 2. We must also
388 decrement the original object's reference count, because what we have
389 done is to change one of the old temporary handles to a permanent one.
393 struct xobject *t1_Permanent(obj) /* non-ANSI to avoid overly strict type checking */
394 register struct xobject *obj; /* object to be made permanent */
396 IfTrace1((MustTraceCalls),"Permanent(%z)\n", obj);
398 if ( (obj != NULL) && ( !(ISPERMANENT(obj->flag)) ) )
400 /* there is a non-NULL, temporary object to be made permanent.
401 If there are multiple references to this object, first get
403 Note also that we have to decrement the reference count if
404 we do a Copy() here, because we are consuming the temporary
405 argument passed, and returning a unique, permanent one.
407 if ( obj->references > 1)
411 /* now set the permanent flag, and increment the reference
412 count, since a temporary object has now become permanent. */
414 obj->flag |= ISPERMANENT(ON);
420 :h3.Temporary() - Undoes the Effect of "Permanent()"
422 This simply resets the "ISPERMANENT" flag.
424 If a permanent object is made temporary, and there is more than one reference
425 to it, we must first Copy() it, then reset the ISPERMANENT flag. However,
426 if the permanent object has obly one reference, we need only decrement the
427 reference count ( and reset the flag).
429 Note that this function, in the case of a PERMANENT argument, basically
430 converts the PERMANENT handle to a TEMPORARY one. Thus, in the case of
431 a nonunique, permanent argument passed, we not only make a Copy(),
432 we also decrement the reference count, to reflect the fact that we have
433 lost a permanent handle and gained a temporary one.
437 struct xobject *xiTemporary(obj) /* non-ANSI to avoid overly strict type checking */
438 register struct xobject *obj; /* object to be made permanent */
440 IfTrace1((MustTraceCalls),"Temporary(%z)\n", obj);
443 /* if it's already temporary, there's nothing to do. */
444 if ISPERMANENT(obj->flag)
446 /* if there are multiple references to this object, get a
447 Copy we can safely alter. Recall that the reference count
448 is incremented for permanent objects.
449 Recall further that Copy returns an object with the
450 same flag state and a reference count of 2 (for PERMANENT
452 Thus, regardless of whether or not we need to copy a
453 permanent object, we still decrement its reference
454 count and reset the flag.
456 if (obj->references != 2 || ISIMMORTAL(obj->flag))
458 /* not unique; consume handle, get a temporary Copy! */
461 /* else decrement the reference count (since it's going from
462 permanent to temporary) and clear the flag. */
465 obj->flag &= ~ISPERMANENT(ON);
473 :h3.Dup() - Duplicate an Object
475 Dup will increment the reference count of an object, only making a
477 Note that Dup() retains the state of the permanent flag.
482 struct xobject *t1_Dup(obj) /* non-ANSI avoids overly strict type checking */
483 register struct xobject *obj; /* object to be duplicated */
485 register char oldflag; /* copy of original object's flag byte */
487 IfTrace1((MustTraceCalls),"Dup(%z)\n", obj);
491 /* An immortal object must be Copy'ed, so that we get a mortal
492 copy of it, since we try not to destroy immortal objects. */
493 if (ISIMMORTAL(obj->flag))
496 /* if incrementing the reference count doesn't cause the count
497 to wrap, simply return the object with the count bumped. Note
498 that the RefRoll macro increments the count to perform the
499 rollover check, so we must decrement the count. */
503 /* that didn't work out, so put the count back and call Copy(). */
507 if (ISPERMANENT(oldflag))
508 obj = Permanent(obj);
513 :h3.Copy() - Make a New Copy of an Object
515 This is the generic Copy() where the object type is unknown. There
516 are specific Copyxxx functions for known object types.
518 Copy will create a NEW temporary object, and WILL NOT simply bump the
521 Sometimes duplicating an object is just as simple as Allocating with it
522 as a template. But other objects are complicated linked lists. So, we
523 let each module provide us a routine (or macro) that duplicates the
524 objects it knows about.
527 struct xobject *t1_Copy(obj)
528 register struct xobject *obj; /* object to be Copy'ed */
533 if (ISPATHTYPE(obj->type))
534 obj = (struct xobject *) CopyPath(obj);
538 obj = (struct xobject *) CopySpace(obj); break;
540 obj = (struct xobject *) CopyFont(obj); break;
542 obj = (struct xobject *) CopyRegion(obj); break;
544 obj = (struct xobject *) CopyPicture(obj); break;
546 obj = (struct xobject *) CopyLineStyle(obj); break;
548 obj = (struct xobject *) CopyStrokePath(obj); break;
550 obj = (struct xobject *) CopyCLUT(obj); break;
552 return(ArgErr("Copy: invalid object", obj, NULL));
559 :h3.Destroy() - Destroys an Object
561 This can get complicated. Just like with Copy(), we let the experts
564 struct xobject *Destroy(obj) /* non-ANSI avoids overly strict type checking */
565 register struct xobject *obj; /* object to be destroyed */
567 IfTrace1((MustTraceCalls),"Destroy(%z)\n", obj);
571 if (ISIMMORTAL(obj->flag)) {
572 IfTrace1(TRUE,"Destroy of immortal object %z ignored\n", obj);
575 if (ISPATHTYPE(obj->type))
601 return(ArgErr("Destroy: invalid object", obj, NULL));
607 :h2.Generally Useful Macros
609 :h3.FOLLOWING() - Macro to Point to the Data Following a Structure
611 There are several places in TYPE1IMAGER where we will allocate variable
612 data that belongs to a structure immediately after that structure.
613 This is a performance technique, because it reduces the number of
614 trips we have to take through xiMalloc() and xiFree(). It turns out C has
615 a very convenient way to point past a structure--if 'p' is a pointer
616 to a structure, 'p+1' is a pointer to the data after it. This
617 behavior of C is somewhat startling and somewhat hard to follow, if
618 you are not used to it, so we define a macro to point to the data
619 following a structure:
621 /*SHARED LINE(S) ORIGINATED HERE*/
623 :h3.TYPECHECK() - Verify the Type of an Argument
625 This macro tests the type of an argument. If the test fails, it consumes
626 any other arguments as necessary and causes the imbedding routine to
627 return the value 'whenBAD'.
629 Note that the consumeables list should be an argument list itself, for
630 example (0) or (2,A,B). See :hdref refid=consume. below.
633 /*SHARED LINE(S) ORIGINATED HERE*/
635 :h3.ARGCHECK() - Perform an Arbitrary Check on an Argument
637 This macro is a generalization of TYPECHECK to take an arbitrary
638 predicate. If the error occurs (i.e., the predicate is true), the
639 arbitrary message 'msg' is returned.
642 /*SHARED LINE(S) ORIGINATED HERE*/
644 :h3.TYPENULLCHECK() - Extension of TYPECHECK() for NULL arguments
646 Many routines allow NULLs to be passed as arguments. 'whenBAD' will
647 be returned in this case, too.
650 /*SHARED LINE(S) ORIGINATED HERE*/
652 :h3.MAKECONSUME() - Create a "Consume"-type Macro
654 Consuming an object means destroying it if it is not permanent. This
655 logic is so common to all the routines, that it is immortalized in this
656 macro. For example, ConsumePath(p) can be simply defined as
657 MAKECONSUME(p,KillPath(p)). In effect, this macro operates on a
659 :i1/consuming objects/
662 /*SHARED LINE(S) ORIGINATED HERE*/
665 :h3.MAKEUNIQUE() - Create a "Unique"-type Macro
667 Many routines are written to modify their arguments in place. Thus,
668 they want to insure that they duplicate an object if it is permanent.
669 This is called making an object "unique". For example, UniquePath(p)
670 can be simply defined as MAKEUNIQUE(p,DupPath(p)).
674 /*SHARED LINE(S) ORIGINATED HERE*/
677 An object is unique (and directly alterable) if there is only one
678 reference to it, and it is not permanent (in which case we increment
679 the reference count, so we don't have to check the permanent bit).
682 Note the rules for making a unique object:
684 IF (obj->references = 1) return(obj);
685 ELSE (references > 1)
686 IF (ISPERMANENT(obj->flag)) return(Dupxxx(obj));
687 ELSE (nonunique, temporary object!)
688 obj->references--; return(Dupxxx(obj));
690 If we must make a Copy of a nonunique, temporary object, we decrement
691 reference count of the original object!
695 :h3.Unique() - Make a Unique Object
697 Here is a generic 'Unique' function if the object type is not known.
698 Why didn't we build it with the MAKEUNIQUE macro, you ask? Well, we
699 used to, but there is at least one damn compiler in the world that
700 raises errors if the types of an "(a) ? b : c" expression do not match.
701 Also, when we changed Dup() to retain the permanent/temporary flag, we
702 wanted to make sure "Unique" always returned a temporary object.
704 Note that we cannot use Dup() to create a copy of the object in question,
705 because Dup() may simply bump the reference count, and not return a
706 unique copy to us. That is why we use t1_Copy().
708 The purpose of this function is to make sure we have a copy of an object
709 that we can safely alter:
711 :li.If we have a unique, temporary object, we simply return the argument.
712 :li.If we have a nonunique, temporary object, we have to make a new copy
713 of it, and decrement the reference count of the original object, to reflect
714 the fact that we traded temporary handles.
715 :li.If we have a permanent object, we make a temporary copy of it, but
716 we do not decrement the reference count of the original permanent object,
717 because permanent objects, by definition, are persistent. 3-2-6-91 PNM
721 struct xobject *t1_Unique(obj)
724 /* if the original object is not already unique, make a unique
725 copy...Note also that if the object was not permanent, we must
726 consume the old handle! 3-26-91 PNM
727 NOTE : consumption of the old handle moved to Allocate. 4-18-91 */
728 if (!obj || obj->references == 1)
732 /* and make sure we return a temporary object ! */
733 if (ISPERMANENT(obj->flag))
735 obj->flag &= ~ISPERMANENT(ON);
743 :h2.Initialization, Error, and Debug Routines
745 :h3 id=debugvar.Declarations for Debug Purposes
747 We declare all the debug flags here. Some link editors make the not
748 unreasonable restriction that only one module may declare and
749 initialize global variables; all the rest must declare the variable
750 'extern'. This is logical, but is somewhat awkward to implement with
751 C include files. We solve the problem by temporarily making the name
752 'extern' a null name if GLOBALS is defined. (GLOBALS is only defined
753 in this OBJECTS module.) Since 'externs' can't be initialized, we
754 have to handle that with #defines too.
755 :i1/GLOBALS (&#define.)/
758 /*SHARED LINE(S) ORIGINATED HERE*/
759 static char *ErrorMessage = NULL;
762 :h3.Pragmatics() - Set/Reset Debug Flags
764 We provide a controlled way for the TYPE1IMAGER user to set and reset
765 our debugging and tracing:
767 void Pragmatics(username, value)
768 char *username; /* name of the flag */
769 int value; /* value to set it to */
771 register char *p; /* temporary loop variable */
773 char name[NAMESIZE]; /* buffer to store my copy of 'username' */
775 if (strlen(username) >= (unsigned)NAMESIZE)
776 abort("Pragmatics name too large");
777 strcpy(name, username);
778 for (p = name; *p != '\0'; p++)
781 if (!strcmp(name, "ALL"))
782 MustTraceCalls = InternalTrace = /* MustCrash = */
785 else if (!strcmp(name, "LINEIOTRACE"))
788 else if (!strcmp(name, "TRACECALLS"))
789 MustTraceCalls = value;
791 else if (!strcmp(name, "CHECKARGS"))
792 MustCheckArgs = value;
794 else if (!strcmp(name, "PROCESSHINTS"))
795 ProcessHints = value;
797 else if (!strcmp(name, "SAVEFONTPATHS"))
798 SaveFontPaths = value;
800 else if (!strcmp(name, "CRASTERCOMPRESSIONTYPE"))
801 CRASTERCompressionType = value;
803 else if (!strcmp(name, "CRASHONUSERERROR"))
806 else if (!strcmp(name, "DEBUG"))
807 StrokeDebug = SpaceDebug = PathDebug = ConicDebug = LineDebug =
808 RegionDebug = MemoryDebug = FontDebug =
809 HintDebug = ImageDebug = OffPageDebug = value;
811 else if (!strcmp(name, "CONICDEBUG"))
814 else if (!strcmp(name, "LINEDEBUG"))
817 else if (!strcmp(name, "REGIONDEBUG"))
820 else if (!strcmp(name, "PATHDEBUG"))
823 else if (!strcmp(name, "SPACEDEBUG"))
826 else if (!strcmp(name, "STROKEDEBUG"))
829 else if (!strcmp(name, "MEMORYDEBUG"))
832 else if (!strcmp(name, "FONTDEBUG"))
835 else if (!strcmp(name, "HINTDEBUG"))
838 else if (!strcmp(name, "IMAGEDEBUG"))
841 else if (!strcmp(name, "OFFPAGEDEBUG"))
842 OffPageDebug = value;
846 The following pragmatics flag turns on or off instruction histograming
847 for performance analysis. It is only defined in the Delta card
850 else if (!strcmp(name, "PROFILE")) {
857 else if (!strcmp(name, "FLUSHCACHE")) {
859 while (GimeSpace()) { ; }
863 else if (!strcmp(name, "CACHEDCHARS"))
864 CachedChars = (value <= 0) ? 1 : value;
866 else if (!strcmp(name, "CACHEDFONTS"))
867 CachedFonts = (value <= 0) ? 1 : value;
869 else if (!strcmp(name, "CACHEBLIMIT"))
872 else if (!strcmp(name, "CONTINUITY"))
877 printf("Pragmatics flag = '%s'\n", name);
878 ArgErr("Pragmatics: flag not known", NULL, NULL);
884 :h3.Consume() - Consume a List of Arguments
886 This general purpose routine is provided in the case where the object
887 type(s) to be consumed are unknown or not yet verified, and/or it is
888 not known whether the object is permanent.
890 If the type of the argument is known, it is faster to directly consume
891 that type, for example, ConsumeRegion() or ConsumePath(). Furthermore,
892 if it is already known that the object is temporary, it is faster to
893 just kill it rather than consume it, for example, KillSpace().
896 void Consume(n, obj1, obj2, obj3) /* non-ANSI avoids overly strict type checking */
898 struct xobject *obj1,*obj2,*obj3;
906 if (obj1 != NULL && !ISPERMANENT(obj1->flag))
911 if (obj1 != NULL && !ISPERMANENT(obj1->flag))
913 if (obj2 != NULL && !ISPERMANENT(obj2->flag))
918 if (obj1 != NULL && !ISPERMANENT(obj1->flag))
920 if (obj2 != NULL && !ISPERMANENT(obj2->flag))
922 if (obj3 != NULL && !ISPERMANENT(obj3->flag))
927 abort("Consume: too many objects");
931 :h3.TypeErr() - Handles "Invalid Object Type" Errors
934 struct xobject *TypeErr(name, obj, expect, ret) /* non-ANSI avoids overly strict type checking */
935 char *name; /* Name of routine (for error message) */
936 struct xobject *obj; /* Object in error */
937 int expect; /* type expected */
938 struct xobject *ret; /* object to return to caller */
940 static char typemsg[80];
945 sprintf(typemsg, "Wrong object type in %s; expected %s.\n",
946 name, TypeFmt(expect), TypeFmt(obj->type));
947 IfTrace0(TRUE,typemsg);
949 ObjectPostMortem(obj);
952 abort("Terminating because of CrashOnUserError...");
954 ErrorMessage = typemsg;
956 /* changed ISPERMANENT to ret->references > 1 3-26-91 PNM */
957 if (ret != NULL && (ret->references > 1))
963 :h4.TypeFmt() - Returns Pointer to English Name of Object Type
965 This is a subroutine of TypeErr().
968 static char *TypeFmt(type)
969 int type; /* type field */
973 if (ISPATHTYPE(type))
974 if (type == TEXTTYPE)
975 r = "path or region (from TextPath)";
981 r = "INVALID (previously consumed?)";
999 r = "path (from StrokePath)";
1009 :h4.ObjectPostMortem() - Prints as Much as We Can About a Bad Object
1011 This is a subroutine of TypeErr() and ArgErr().
1015 static ObjectPostMortem(obj) /* non-ANSI avoids overly strict type checking */
1016 register struct xobject *obj;
1018 extern struct XYspace *USER;
1020 Pragmatics("Debug", 10);
1021 IfTrace2(TRUE,"Bad object is of %s type %z\n", TypeFmt(obj->type), obj);
1023 IfTrace0((obj == (struct xobject *) USER),
1024 "Suspect that InitImager() was omitted.\n");
1025 Pragmatics("Debug", 0);
1029 :h3.ArgErr() - Invalid Argument Passed to a Routine
1031 A common routine to report argument errors. It is usually called
1032 is returned to the caller in case MustCrash is FALSE and ArgErr
1033 returns to its caller.
1036 struct xobject *ArgErr(string, obj, ret) /* non-ANSI avoids overly strict type checking */
1037 char *string; /* description of error */
1038 struct xobject *obj; /* object, if any, that was in error */
1039 struct xobject *ret; /* object returned to caller or NULL */
1043 IfTrace1(TRUE,"ARGUMENT ERROR-- %s.\n", string);
1045 ObjectPostMortem(obj);
1047 abort("Terminating because of CrashOnUserError...");
1049 ErrorMessage = string;
1054 :h3.abort() - Crash Due to Error
1056 Defined in objects.h to be FatalError(), the server's abort routine.
1060 :h3.REAL Miscellaneous Stuff
1062 :h4.ErrorMsg() - Return the User an Error Message
1070 ErrorMessage = NULL;
1075 :h4.InitImager() - Initialize TYPE1IMAGER
1077 We check that a short is 16 bits and a long 32 bits; we have made
1078 those assumptions elsewhere in the code. (This is almost a C standard,
1079 anyway.) Note that TYPE1IMAGER makes no assumptions about the size of an
1081 :i1/portability assumptions/
1087 /* Check to see if we have been using our own malloc. If so,*/
1088 /* Undef malloc so that we can get to the system call. */
1089 /* All other calls to malloc are defined to xiMalloc. */
1092 /* if (sizeof(short) != 2 || sizeof(INT32) != 4)
1093 abort("Fundamental TYPE1IMAGER assumptions invalid in this port");
1099 In some environments, constants and/or exception handling need to be
1104 :h4.TermImager() - Terminate TYPE1IMAGER
1106 This only makes sense in a server environment; true TYPE1IMAGER needs do
1114 :h4.reportusage() - A Stub to Get a Clean Link with Portable PMP