📄 objects.c
字号:
initialize global variables; all the rest must declare the variable'extern'. This is logical, but is somewhat awkward to implement withC include files. We solve the problem by temporarily making the name'extern' a null name if GLOBALS is defined. (GLOBALS is only definedin this OBJECTS module.) Since 'externs' can't be initialized, wehave to handle that with #defines too.:i1/GLOBALS (&#define.)/*/ /*SHARED LINE(S) ORIGINATED HERE*/static char *ErrorMessage = NULL; /*:h3.Pragmatics() - Set/Reset Debug Flags We provide a controlled way for the TYPE1IMAGER user to set and resetour debugging and tracing:*/void Pragmatics(username, value) char *username; /* name of the flag */ int value; /* value to set it to */{ register char *p; /* temporary loop variable */#define NAMESIZE 40 char name[NAMESIZE]; /* buffer to store my copy of 'username' */ if (strlen(username) >= (unsigned)NAMESIZE) 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 histogramingfor performance analysis. It is only defined in the Delta cardenvironment.*/ else if (!strcmp(name, "PROFILE")) { if (value) StartProfile(); else StopProfile(); }#endif else if (!strcmp(name, "FLUSHCACHE")) {#ifdef notdef while (GimeSpace()) { ; }#endif } 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;} /*:h3.Consume() - Consume a List of Arguments This general purpose routine is provided in the case where the objecttype(s) to be consumed are unknown or not yet verified, and/or it isnot known whether the object is permanent. If the type of the argument is known, it is faster to directly consumethat type, for example, ConsumeRegion() or ConsumePath(). Furthermore,if it is already known that the object is temporary, it is faster tojust kill it rather than consume it, for example, KillSpace().*/ void Consume(n, obj1, obj2, obj3) /* non-ANSI avoids overly strict type checking */ int n; struct xobject *obj1,*obj2,*obj3;{ 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"); }}/*:h3.TypeErr() - Handles "Invalid Object Type" Errors*/ struct xobject *TypeErr(name, obj, expect, ret) /* non-ANSI avoids overly strict type checking */ char *name; /* Name of routine (for error message) */ struct xobject *obj; /* Object in error */ int expect; /* type expected */ struct xobject *ret; /* object to return to caller */{ static char typemsg[80]; if (MustCrash) LineIOTrace = TRUE; sprintf(typemsg, "Wrong object type in %s; expected %s.\n", name, TypeFmt(expect), TypeFmt(obj->type)); IfTrace0(TRUE,typemsg); ObjectPostMortem(obj); if (MustCrash) 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);} /*:h4.TypeFmt() - Returns Pointer to English Name of Object Type This is a subroutine of TypeErr().*/ static char *TypeFmt(type) int type; /* type field */{ 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);}/*:h4.ObjectPostMortem() - Prints as Much as We Can About a Bad Object This is a subroutine of TypeErr() and ArgErr().*/ /*ARGSUSED*/static ObjectPostMortem(obj) /* non-ANSI avoids overly strict type checking */ register struct xobject *obj;{ extern struct XYspace *USER; Pragmatics("Debug", 10); IfTrace2(TRUE,"Bad object is of %s type %z\n", TypeFmt(obj->type), obj); IfTrace0((obj == (struct xobject *) USER), "Suspect that InitImager() was omitted.\n"); Pragmatics("Debug", 0);} /*:h3.ArgErr() - Invalid Argument Passed to a Routine A common routine to report argument errors. It is usually calledis returned to the caller in case MustCrash is FALSE and ArgErrreturns to its caller.*/ struct xobject *ArgErr(string, obj, ret) /* non-ANSI avoids overly strict type checking */ char *string; /* description of error */ struct xobject *obj; /* object, if any, that was in error */ struct xobject *ret; /* object returned to caller or NULL */{ if (MustCrash) LineIOTrace = TRUE; IfTrace1(TRUE,"ARGUMENT ERROR-- %s.\n", string); if (obj != NULL) ObjectPostMortem(obj); if (MustCrash) abort("Terminating because of CrashOnUserError..."); else ErrorMessage = string; return(ret);} /*:h3.abort() - Crash Due to Error Defined in objects.h to be FatalError(), the server's abort routine.*/ /*:h3.REAL Miscellaneous Stuff :h4.ErrorMsg() - Return the User an Error Message*/ char *ErrorMsg(){ register char *r; r = ErrorMessage; ErrorMessage = NULL; return(r);} /*:h4.InitImager() - Initialize TYPE1IMAGER We check that a short is 16 bits and a long 32 bits; we have madethose assumptions elsewhere in the code. (This is almost a C standard,anyway.) Note that TYPE1IMAGER makes no assumptions about the size of an'int'!:i1/portability assumptions/*/ void InitImager(){ /* 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 xiMalloc. */ /* if (sizeof(short) != 2 || sizeof(INT32) != 4) abort("Fundamental TYPE1IMAGER assumptions invalid in this port");*/ InitSpaces(); InitFonts(); InitFiles();/*In some environments, constants and/or exception handling need to be*/ LibInit();}/*:h4.TermImager() - Terminate TYPE1IMAGER This only makes sense in a server environment; true TYPE1IMAGER needs donothing.*/void TermImager(){ return;}/*:h4.reportusage() - A Stub to Get a Clean Link with Portable PMP*/void reportusage(){ return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -