DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ T g

⟦eda390660⟧ TextFile

    Length: 2500 (0x9c4)
    Types: TextFile
    Names: »gpa.c«

Derivation

└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
    └─ ⟦this⟧ »EUUGD11/euug-87hel/sec8/mcp/src/gpa.c« 

TextFile

/***************************************************************************\
* 									    *
* 	gpa.c								    *
* 									    *
* These are the support routines for the global_pointer_array that all	    *
* routines that get input from the tty use, excluding main().		    *
* 									    *
* Routines needing an argv like array to store pointers call get_gpa()	    *
* which returns a pointer to chunk of the global_pointer_array of the	    *
* requested size.  Such a central array is needed to insure that all	    *
* allocations via savestr() in get_line() are freed by a call to	    *
* free_gpa().  This is insured even from interrupts by always calling	    *
* free_gpa() in main() before getting the next command line.		    *
* 									    *
* clear_gpa() is used by routines that already have made a call to	    *
* get_gpa() and want to reuse the space provided, but need to be sure that  *
* any leftover pointers freed before they are overwritten.		    *
* 									    *
* ----------								    *
* 									    *
* get_gpa()	get a chunk of the global_pointer_array			    *
* 									    *
* clear_gpa()	free the pointers stored in a certian part		    *
* 		of the array for reuse.					    *
* 									    *
* free_gpa()	free all pointers in the global_pointer_array		    *
* 		and reset the array index to zero.			    *
* 									    *
* pop_gpa()	used to free last allocated part of the			    *
* 		global_pointer_array.  Designed for use by routines	    *
* 		in yesno.c.  No other routines should need call this.	    *
* 									    *
\***************************************************************************/

#include "sysdep.h"
#include "mem.h"
#include "gpa.h"

static	addr global_pointer_array[G_P_A__SIZE];
static	int gpaindex;

addr *
get_gpa(n)
int n;

{
	gpaindex += n;
	return &global_pointer_array[gpaindex-n];
}

free_gpa()

{
	int i;

	critical();
	for (i=0; i<G_P_A__SIZE; i++)
		if (global_pointer_array[i]) {
			FREEMEM((char *)global_pointer_array[i]);
			global_pointer_array[i] = NIL;
		}
	gpaindex = 0;
	non_critical();
	return;
}

int clear_gpa(p, n)
addr *p;
int n;

{
	register int i;

	for (i=0; i<n; i++)
		if (p[i]) {
			/*
			 * Can't let user interrupt between the FREEMEM
			 * and zeroing the pointer.
			 */
			critical();
			FREEMEM((char *)p[i]);
			p[i] = NIL;
			non_critical();
		}
	return 1;	/* used as do-while constant */
}

pop_gpa(n)
int n;

{
	(void) clear_gpa(&global_pointer_array[gpaindex-n], n);
	gpaindex -= n;
	return;
}