/* PUTIL.C Miscellaneous useful functions for PARSE Copyright (C) 1982 by The Loglan Institute, Inc. Created 82.2.16 Gyro This file contains a non-freeing allocator and miscellaneous useful functions for both IBM and MAC LIP versions. */ #include "extval.h" void AInit (void) /* Initialize the space */ /* This is a simple dynamic memory allocator. It is intended for applications in which, instead of objects being freed one at a time, all existing objects are thrown away in one swell foop.(RAM'90.*/ { #ifdef MACDOS Aspace = malloc(Asize); #else Aspace = NewPtr(Asize); #endif if (!Aspace) alert(0,12); Acap = Aspace; Aend = Aspace + Asize; } char *AAlloc (unsigned short size) /* This routine allocates an object of bytes */ { char *tobj; if (Acap + size > Aend) return (NULL); tobj = Acap; Acap += size; #ifdef WORD_ALIGN Acap += (long)Acap & 1L; #endif #ifdef DWORD_ALIGN Acap += 3 - (((long)Acap - 1L) & 3L); #endif return (tobj); } short ARoom(void) /* Determine how much space is left */ { return (Aend - Acap); } void arydel (char *ary, short len,short eltsize, short dello, short delhi) /* This deletes elements in the array , which consists of elements of bytes; elements from through - 1 are deleted. */ { memmove (ary + dello * eltsize, ary + delhi * eltsize, (size_t)(len - delhi) * eltsize); } void upcase (char *str) /* converts a string str to upper case */ { for (;*str; ++str) *str = toupper (*str); } /* RAM Jul 88 A number of routines which were here such as fgets, nfgets, ngets, getchar, puts, putchar, putch, nfputc, and nfputs have been removed or replaced by a more standard C version. Qsort and match have been placed in putil from elsewhere. Qsort is a standard C routine, so has been removed. */ void ngets (char *str,short ) /* This ngets gets a str with the C routine gets, sets a global pointer to the beginning, and skips some miscellaneous white space and punctuation that might precede it. It writes it to the output, if that flag is on. The parameter len seems not currently to have been used */ { if (!gets (str)) *str = NUL; ic = str; ISkipMsc(); if (wallp==1) { fputs (ic, obuf); fputs ("\n", obuf); } } Boolean match (char *s1,char *s2) /* This routine is used for matching strong quotation start and terminator only. It is a case-independent null-term compare of strings s1 and s2.*/ { do if (toupper (*s1) != toupper (*s2)) return (FALSE); while ((s1++, *s2++)); return (TRUE); } /* End of PUTIL.C */