Back to index

tetex-bin  3.0
util.c
Go to the documentation of this file.
00001 /* $XConsortium: util.c,v 1.6 92/03/26 16:42:26 eswu Exp $ */
00002 /* Copyright International Business Machines,Corp. 1991
00003  * All Rights Reserved
00004  *
00005  * License to use, copy, modify, and distribute this software
00006  * and its documentation for any purpose and without fee is
00007  * hereby granted, provided that the above copyright notice
00008  * appear in all copies and that both that copyright notice and
00009  * this permission notice appear in supporting documentation,
00010  * and that the name of IBM not be used in advertising or
00011  * publicity pertaining to distribution of the software without
00012  * specific, written prior permission.
00013  *
00014  * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
00015  * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
00016  * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
00018  * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
00019  * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
00020  * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
00021  * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
00022  * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
00023  * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
00024  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
00025  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
00026  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
00027  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
00028  * SOFTWARE.
00029  */
00030 /* Author: Katherine A. Hitchcock    IBM Almaden Research Laboratory */
00031  
00032 #include "types.h"
00033 #include <stdio.h>
00034 #include <stdlib.h>
00035 #include "util.h"
00036 #include "fontmisc.h"
00037 
00038 static char *vm_base = NULL;  /* Start of virtual memory area */
00039        char *vm_next = NULL;  /* Pointer to first free byte */
00040        LONG  vm_free = 0;     /* Count of free bytes */
00041        LONG  vm_size = 0;     /* Total size of memory */
00042 
00043 /* The following global variable is for detecting a trial to
00044    allocate a second chunk---not to be done with the t1lib, since
00045    a later reallocation would lead to segmentation faults!
00046    */
00047 int vm_init_count;
00048 /* This is the amount of VM, the font is tried to be loaded in. */
00049 int vm_init_amount;
00050 
00051 
00052 /*
00053  * Initialize memory.
00054  */
00055 
00056 extern char *tokenMaxP;   /* Pointer to end of VM we may use + 1 */
00057 
00058 boolean vm_init()
00059 {
00060   /* Check whether it is the first piece of memory for the
00061      current font or not. If so, simulate lacking memory to
00062      indicate that the font should be tried to load with a
00063      vitual memory twice as large!
00064      */
00065   if (vm_init_count>0){
00066     vm_init_count++;
00067     return(FALSE);
00068   }
00069   vm_init_count++;
00070   
00071   vm_next = vm_base = (char *) calloc( vm_init_amount, sizeof(char));
00072 
00073   if (vm_base != NULL) {
00074     vm_free = vm_init_amount;
00075     vm_size = vm_init_amount;
00076     tokenMaxP = vm_next_byte() + vm_init_amount;
00077     return(TRUE);
00078   }
00079   else
00080     return(FALSE);
00081 }
00082  
00083 char *vm_alloc(bytes)
00084   unsigned int bytes;
00085 {
00086   char *answer;
00087  
00088   /* Align returned bytes to 64-bit boundary */
00089   bytes = (bytes + 7) & ~7;
00090   
00091   
00092   /* take space from what is left otherwise allocate another CHUNK */
00093   if (bytes > vm_free){
00094     if (!vm_init()) return NULL;
00095   }
00096   else{
00097     answer = vm_next;
00098     vm_free -= bytes;
00099     vm_next += bytes;
00100     return answer;
00101   }
00102 
00103   /* Never reached, but compiler is happy: */
00104   return NULL;
00105   
00106 }
00107 
00108 /*
00109  * Format an Integer object
00110  */
00111 void objFormatInteger( psobj *objP, int value)
00112 {
00113   if (objP != NULL) {
00114     objP->type         = OBJ_INTEGER;
00115     objP->len          = 0;
00116     objP->data.integer = value;
00117   }
00118 }
00119  
00120 /*
00121  * Format a Real object
00122  */
00123 void objFormatReal(psobj *objP, float value)
00124 {
00125   if (objP != NULL) {
00126     objP->type       = OBJ_REAL;
00127     objP->len        = 0;
00128     objP->data.real  = value;
00129   }
00130 }
00131  
00132 /*
00133  * Format a Boolean object
00134  */
00135 void objFormatBoolean(psobj *objP, boolean value)
00136 {
00137   if (objP != NULL) {
00138     objP->type         = OBJ_BOOLEAN;
00139     objP->len          = 0;
00140     objP->data.boolean = value;
00141   }
00142 }
00143  
00144 /*
00145  * Format an Encoding object
00146  */
00147 void objFormatEncoding(psobj *objP, int length, psobj *valueP)
00148 {
00149   if (objP != NULL) {
00150     objP->type        = OBJ_ENCODING;
00151     objP->len         = length;
00152     objP->data.arrayP = valueP;
00153   }
00154 }
00155  
00156 /*
00157  * Format an Array object
00158  */
00159 void objFormatArray(psobj *objP, int length, psobj *valueP)
00160 {
00161   if (objP != NULL) {
00162     objP->type        = OBJ_ARRAY;
00163     objP->len         = length;
00164     objP->data.arrayP = valueP;
00165   }
00166 }
00167  
00168  
00169 /*
00170  * Format a String object
00171  */
00172 void objFormatString(psobj *objP, int length, char *valueP)
00173 {
00174   if (objP != NULL) {
00175     objP->type         = OBJ_STRING;
00176     objP->len          = length;
00177     objP->data.valueP  = valueP;
00178   }
00179 }
00180  
00181 /*
00182  * Format a Name object
00183  */
00184 void objFormatName( psobj *objP, int length, char *valueP)
00185 {
00186   if (objP != NULL) {
00187     objP->type         = OBJ_NAME;
00188     objP->len          = length;
00189     objP->data.nameP   = valueP;
00190   }
00191 }
00192  
00193 /*
00194  * Format a File object
00195  */
00196 void objFormatFile(psobj *objP, FILE *valueP)
00197 {
00198   if (objP != NULL) {
00199     objP->type         = OBJ_FILE;
00200     objP->len          = 0;
00201     objP->data.fileP   = valueP;
00202   }
00203 }
00204