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 "util.h"
00035 #include "fontmisc.h"
00036 
00037 extern char *Xalloc();
00038 
00039 static char *vm_base = NULL;  /* Start of virtual memory area */
00040        char *vm_next = NULL;  /* Pointer to first free byte */
00041        LONG  vm_free = 0;     /* Count of free bytes */
00042        LONG  vm_size = 0;     /* Total size of memory */
00043 
00044 /*
00045  * Initialize memory.
00046  */
00047 
00048 extern char *tokenMaxP;   /* Pointer to end of VM we may use + 1 */
00049 
00050 boolean vm_init()
00051 {
00052   vm_next = vm_base = (char *) Xalloc(MAX_STRING_LEN);
00053  
00054   if (vm_base != NULL) {
00055     vm_free = MAX_STRING_LEN;
00056     vm_size = MAX_STRING_LEN;
00057     tokenMaxP = vm_next_byte() + MAX_STRING_LEN;
00058     return(TRUE);
00059   }
00060   else
00061     return(FALSE);
00062 }
00063  
00064 char *vm_alloc(bytes)
00065   unsigned int bytes;
00066 {
00067   char *answer;
00068  
00069   /* Round to next LONG multiple (32-bit) */
00070 #if defined(sun) || defined(__hpux) || defined(__alpha)
00071   bytes = (bytes + 7) & ~7;
00072 #else
00073   bytes = (bytes + 3) & ~3;
00074 #endif
00075  
00076   /* take space from what is left otherwise allocate another CHUNK */
00077   if (bytes > vm_free)
00078     if (!vm_init()) return NULL;
00079   if (bytes <= vm_free) {
00080     answer = vm_next;
00081     vm_free -= bytes;
00082     vm_next += bytes;
00083     return answer;
00084   }
00085   else {
00086     printf("Trying to allocate %d bytes (%d maximum)\n", bytes, MAX_STRING_LEN);
00087     return NULL; 
00088   }
00089 }
00090 
00091 /*
00092  * Format an Integer object
00093  */
00094 void objFormatInteger(objP,value)
00095   psobj *objP;
00096   int value;
00097 {
00098   if (objP != NULL) {
00099     objP->type         = OBJ_INTEGER;
00100     objP->len          = 0;
00101     objP->data.integer = value;
00102   }
00103 }
00104  
00105 /*
00106  * Format a Real object
00107  */
00108 #if 0
00109 void objFormatReal(objP,value)
00110   psobj *objP;
00111   float value;
00112 #else
00113 void objFormatReal(psobj *objP, float value)
00114 #endif
00115 {
00116   if (objP != NULL) {
00117     objP->type       = OBJ_REAL;
00118     objP->len        = 0;
00119     objP->data.real  = value;
00120   }
00121 }
00122  
00123 /*
00124  * Format a Boolean object
00125  */
00126 void objFormatBoolean(objP,value)
00127   psobj *objP;
00128   boolean value;
00129 {
00130   if (objP != NULL) {
00131     objP->type         = OBJ_BOOLEAN;
00132     objP->len          = 0;
00133     objP->data.boolean = value;
00134   }
00135 }
00136  
00137 /*
00138  * Format an Encoding object
00139  */
00140 void objFormatEncoding(objP,length,valueP)
00141   psobj *objP;
00142   int length;
00143   psobj *valueP;
00144 {
00145   if (objP != NULL) {
00146     objP->type        = OBJ_ENCODING;
00147     objP->len         = length;
00148     objP->data.arrayP = valueP;
00149   }
00150 }
00151  
00152 /*
00153  * Format an Array object
00154  */
00155 void objFormatArray(objP,length,valueP)
00156   psobj *objP;
00157   int length;
00158   psobj *valueP;
00159 {
00160   if (objP != NULL) {
00161     objP->type        = OBJ_ARRAY;
00162     objP->len         = length;
00163     objP->data.arrayP = valueP;
00164   }
00165 }
00166  
00167  
00168 /*
00169  * Format a String object
00170  */
00171 void objFormatString(objP,length,valueP)
00172   psobj *objP;
00173   int length;
00174   char *valueP;
00175 {
00176   if (objP != NULL) {
00177     objP->type         = OBJ_STRING;
00178     objP->len          = length;
00179     objP->data.valueP  = valueP;
00180   }
00181 }
00182  
00183 /*
00184  * Format a Name object
00185  */
00186 void objFormatName(objP,length,valueP)
00187   psobj *objP;
00188   int length;
00189   char *valueP;
00190 {
00191   if (objP != NULL) {
00192     objP->type         = OBJ_NAME;
00193     objP->len          = length;
00194     objP->data.nameP   = valueP;
00195   }
00196 }
00197  
00198 /*
00199  * Format a File object
00200  */
00201 void objFormatFile(objP,valueP)
00202   psobj *objP;
00203   FILE *valueP;
00204 {
00205   if (objP != NULL) {
00206     objP->type         = OBJ_FILE;
00207     objP->len          = 0;
00208     objP->data.fileP   = valueP;
00209   }
00210 }
00211