===================================================================
RCS file: /home/oper/ac/.CVSROOT/src/backend.c,v
retrieving revision 3.1.2.2
diff -c -r3.1.2.2 backend.c
*** 3.1.2.2	1994/03/10 06:04:24
--- backend.c	1994/03/10 06:11:19
***************
*** 20,26 ****
  
  jmp_buf error_recovery_context;
  int error_recovery_context_exists = 0;
- int change_memory_limit = 0;
  /*
   * The 'current_time' is updated at every heart beat.
   */
--- 20,25 ----
***************
*** 39,45 ****
      shutdowngame(), ed_cmd (char *),
      print_prompt(), call_out(),
      destruct2 (struct object *),
!     try_to_swap(int);
  
  extern int get_message (char *, int), player_parser (char *),
      call_function_interactive (struct interactive *, char *),
--- 38,44 ----
      shutdowngame(), ed_cmd (char *),
      print_prompt(), call_out(),
      destruct2 (struct object *),
!     try_to_swap(volatile int *);
  
  extern int get_message (char *, int), player_parser (char *),
      call_function_interactive (struct interactive *, char *),
***************
*** 183,189 ****
      extern int tot_alloc_object, tot_alloc_dest_object;
      extern void init_call_out();
      extern int allocated_swap, last_address;
!     
  
      read_snoop_file();
      (void) printf("Setting up ipc.\n");
--- 182,188 ----
      extern int tot_alloc_object, tot_alloc_dest_object;
      extern void init_call_out();
      extern int allocated_swap, last_address;
!     int zero = 0;
  
      read_snoop_file();
      (void) printf("Setting up ipc.\n");
***************
*** 217,236 ****
  	interupted = 0;
  	remove_destructed_objects(); /* marion - before ref checks! */
  
!         /*
!          * Check if the memory limit has changed, this is an asynchronous
!          * call, the reason for this coding.
!          */
!         if (change_memory_limit != 0)
!         {
!             if (change_memory_limit == 1)
!                 push_number(1);
!             else
!                 push_number(0);
!             (void) apply_master_ob(M_MEMORY_RECONFIGURE, 1);
!             change_memory_limit = 0;
!         }
! 
  #ifdef DEBUG
  	if (d_flag & DEBUG_CHK_REF)
  	    check_a_lot_ref_counts(0);
--- 216,222 ----
  	interupted = 0;
  	remove_destructed_objects(); /* marion - before ref checks! */
  
! 	deliver_signals();
  #ifdef DEBUG
  	if (d_flag & DEBUG_CHK_REF)
  	    check_a_lot_ref_counts(0);
***************
*** 297,306 ****
  	}
  	flush_all_player_mess();
  #ifdef USE_SWAP
! 	try_to_swap(last_address - 4 - allocated_swap > 
! 		    0x100000); /* If the swap file is this much larger than the
! 				  used part of the file, we make a compaction
! 				  */
  #endif
  	if (interupted)
  	{
--- 283,289 ----
  	}
  	flush_all_player_mess();
  #ifdef USE_SWAP
! 	try_to_swap(&interupted);
  #endif
  	if (interupted)
  	{
***************
*** 308,345 ****
  	    continue;
  	}
  	pause();
-     }
- }
- 
- /*
-  * sig_alert is used to control the amount of memory that is
-  * available. They check with the locally defined variables in the mudlib
-  * for the space to set.  
-  */
- #if defined(_SEQUENT_)
- void 
- sig_alert(sig)
-     int sig;
- #else
- void 
- sig_alert(sig, code, scp, addr)
-     int sig, code;
-     struct sigcontext *scp;
-     char *addr;
- #endif
- {
-     switch(sig)
-     {
-     case SIGUSR1:
-         change_memory_limit = -1;
-         break;
- 
-     case SIGUSR2:
-         change_memory_limit = 1;
-         break;
- 
-     default:
-         break;
      }
  }
  
--- 291,296 ----
===================================================================
RCS file: /home/oper/ac/.CVSROOT/src/call_out.c,v
retrieving revision 3.1
diff -c -r3.1 call_out.c
*** 3.1	1994/01/23 01:08:43
--- call_out.c	1994/02/16 23:55:49
***************
*** 22,27 ****
--- 22,39 ----
  extern int error_recovery_context_exists, eval_cost, s_flag;
  extern struct svalue *sp;
  
+ struct call
+ {
+     unsigned short fun;
+     unsigned short inherit;
+     int reload;
+     unsigned int when;
+     int id;
+     struct call *next;
+     struct object *command_giver;
+     struct vector *v;
+ };
+ 
  static struct object *call_outs[NUM_SLOTS];
  unsigned int now;
  unsigned int last;
***************
*** 103,109 ****
      signal(SIGALRM, timer_alarm);
      ualarm(1000000/TIME_RES, 1000000/TIME_RES);
  }
! 	
  void
  call_out_swap_objects(struct object *ob1, struct object *ob2)
  {
--- 115,132 ----
      signal(SIGALRM, timer_alarm);
      ualarm(1000000/TIME_RES, 1000000/TIME_RES);
  }
! 
! int
! num_call_outs(struct object *ob)
! {
!     struct call *c;
!     int num_co;
! 
!     for (num_co = 0, c = ob->call_outs; c;
! 	 num_co++, c = c->next) ;
!     return num_co;
! }
! 
  void
  call_out_swap_objects(struct object *ob1, struct object *ob2)
  {
***************
*** 197,203 ****
  static void
  free_call(struct call *cop)
  {
!     free_svalue(&cop->v);
      if (cop->command_giver)
  	free_object(cop->command_giver, "free_call");
      free((char *)cop);
--- 220,226 ----
  static void
  free_call(struct call *cop)
  {
!     free_vector(cop->v);
      if (cop->command_giver)
  	free_object(cop->command_giver, "free_call");
      free((char *)cop);
***************
*** 207,230 ****
  
  int
  new_call_out(struct object *ob, unsigned int func, unsigned int inh,
! 	     int delay, struct svalue *arg)
  {
      struct call *cop;
  
!     if (delay == 0)
  	delay = 1;
!     
      cop = (struct call *)xalloc(sizeof(struct call));
      num_call++;
      call_out_size += sizeof(struct call);
  
      cop->fun = func;
      cop->inherit = inh;
!     cop->delay = delay;
!     if (delay >= 0)
! 	cop->when = now + delay;
!     else
! 	cop->when = now - delay;
      
      if (cop->when < last)
  	fatal("Error in callout!\n");
--- 230,253 ----
  
  int
  new_call_out(struct object *ob, unsigned int func, unsigned int inh,
! 	     int delay, int reload, struct vector *arg)
  {
      struct call *cop;
  
!     if (delay <= 0)
  	delay = 1;
! 
!     if (reload <= 0)
! 	reload = 0;
! 
      cop = (struct call *)xalloc(sizeof(struct call));
      num_call++;
      call_out_size += sizeof(struct call);
  
      cop->fun = func;
      cop->inherit = inh;
!     cop->reload = reload;
!     cop->when = now + delay;
      
      if (cop->when < last)
  	fatal("Error in callout!\n");
***************
*** 233,243 ****
      if (command_giver)
  	command_giver->ref++;
      if (arg)
! 	assign_svalue_no_free(&cop->v, arg);
      else
      {
! 	cop->v.type = T_NUMBER;
! 	cop->v.u.number = cop->id;
      }
      insert_call_out(ob, cop);
      return cop->id;
--- 256,270 ----
      if (command_giver)
  	command_giver->ref++;
      if (arg)
!     {
! 	cop->v = arg;
! 	arg->ref++;
!     }
      else
      {
! 	cop->v = allocate_array(1);
! 	cop->v->item[0].type = T_NUMBER;
! 	cop->v->item[0].u.number = cop->id;
      }
      insert_call_out(ob, cop);
      return cop->id;
***************
*** 311,317 ****
    0 : call id;
    1 : function;
    2 : time left;
!   3 : asked delay;
    4 : argument;
  */
  struct vector *
--- 338,344 ----
    0 : call id;
    1 : function;
    2 : time left;
!   3 : reload time;
    4 : argument;
  */
  struct vector *
***************
*** 336,347 ****
      
      val->item[2].type = T_FLOAT;
      val->item[2].u.real = ((double)cop->when - now) / TIME_RES;
! /*    if (val->item[2].u.real < 0.0)
! 	val->item[2].u.real = 0.0; */
      val->item[3].type = T_FLOAT;
!     val->item[3].u.real = ((double)cop->delay) / TIME_RES;
      
!     assign_svalue(&val->item[4], &cop->v);
      
      return val;
  }
--- 363,376 ----
      
      val->item[2].type = T_FLOAT;
      val->item[2].u.real = ((double)cop->when - now) / TIME_RES;
!     if (val->item[2].u.real < 0.0)
! 	val->item[2].u.real = 0.0;
      val->item[3].type = T_FLOAT;
!     val->item[3].u.real = ((double)cop->reload) / TIME_RES;
      
!     val->item[4].type = T_POINTER;
!     val->item[4].u.vec = cop->v;
!     cop->v->ref++;
      
      return val;
  }
***************
*** 350,356 ****
    0 : call id;
    1 : function;
    2 : time left;
!   3 : asked delay;
    4 : argument;
  */
  struct vector *
--- 379,385 ----
    0 : call id;
    1 : function;
    2 : time left;
!   3 : reload time;
    4 : argument;
  */
  struct vector *
***************
*** 378,390 ****
  	
  	val->item[2].type = T_FLOAT ;
  	val->item[2].u.real = ((double)cop->when - now) / TIME_RES;
! /*	if (val->item[2].u.real < 0.0)
! 	    val->item[2].u.real = 0.0; */
  	
  	val->item[3].type = T_FLOAT;
! 	val->item[3].u.real = ((double)cop->delay) / TIME_RES;
  	
! 	assign_svalue(&val->item[4], &cop->v);
  	
  	ret->item[i].type = T_POINTER;
  	ret->item[i].u.vec = val;
--- 407,421 ----
  	
  	val->item[2].type = T_FLOAT ;
  	val->item[2].u.real = ((double)cop->when - now) / TIME_RES;
! 	if (val->item[2].u.real < 0.0)
! 	    val->item[2].u.real = 0.0;
  	
  	val->item[3].type = T_FLOAT;
! 	val->item[3].u.real = ((double)cop->reload) / TIME_RES;
  	
! 	val->item[4].type = T_POINTER;
! 	val->item[4].u.vec = cop->v;
! 	cop->v->ref++;
  	
  	ret->item[i].type = T_POINTER;
  	ret->item[i].u.vec = val;
***************
*** 401,407 ****
      static struct call *cop, **copp;
      struct object *ob, **obp;
      jmp_buf save_error_recovery_context;
!     int save_rec_exists;
      extern struct object *command_giver;
      extern struct object *current_interactive;
      int sum_eval = 0;
--- 432,438 ----
      static struct call *cop, **copp;
      struct object *ob, **obp;
      jmp_buf save_error_recovery_context;
!     int save_rec_exists, i;
      extern struct object *command_giver;
      extern struct object *current_interactive;
      int sum_eval = 0;
***************
*** 409,415 ****
      int sum_ptime = 0;
      int num_done = 0;
      char caodesc[100];
!     
      if (last >= now)
  	return;
  
--- 440,447 ----
      int sum_ptime = 0;
      int num_done = 0;
      char caodesc[100];
!     int num_args;
! 
      if (last >= now)
  	return;
  
***************
*** 440,449 ****
  	    cop = ob->call_outs;
  	    ob->call_outs = cop->next;
  	    
! 	    if (cop->delay < 0) /* Reschedule the callout */
  	    {
  		current_call_out_id = cop->id;
! 		cop->when = now - cop->delay;
  		if (cop->when < last)
  		    fatal("Error in callouts!\n");
  		
--- 472,481 ----
  	    cop = ob->call_outs;
  	    ob->call_outs = cop->next;
  	    
! 	    if (cop->reload > 0) /* Reschedule the callout */
  	    {
  		current_call_out_id = cop->id;
! 		cop->when = now + cop->reload;
  		if (cop->when < last)
  		    fatal("Error in callouts!\n");
  		
***************
*** 482,501 ****
  		command_giver = ob;
  	    else
  		command_giver = 0;
- 	    if (cop->v.type == T_OBJECT &&
- 		cop->v.u.ob->flags & O_DESTRUCTED)
- 		free_svalue(&cop->v);
- 	    
  	    if (s_flag)
  		reset_mudstatus();
  	    eval_cost = 0;
! 	    push_svalue(&cop->v);
  	    current_call_out_object = current_object = ob;
  	    current_call_out_object->ref++;
  	    
  	    inh = cop->inherit;
  	    fun = cop->fun;
! 	    if (cop->delay > 0)
  	    {
  		free_call(cop);
  	    }
--- 514,536 ----
  		command_giver = ob;
  	    else
  		command_giver = 0;
  	    if (s_flag)
  		reset_mudstatus();
  	    eval_cost = 0;
! 	    num_args = cop->v->size;
! 	    for (i = 0; i < num_args; i++)
! 	    {
! 		if (cop->v->item[i].type == T_OBJECT &&
! 		    cop->v->item[i].u.ob->flags & O_DESTRUCTED)
! 		    free_svalue(&cop->v->item[i]);
! 		push_svalue(&cop->v->item[i]);
! 	    }
  	    current_call_out_object = current_object = ob;
  	    current_call_out_object->ref++;
  	    
  	    inh = cop->inherit;
  	    fun = cop->fun;
! 	    if (cop->reload <= 0)
  	    {
  		free_call(cop);
  	    }
***************
*** 518,524 ****
  	    }
  	    else
  	    {
! 		call_function(ob, inh, fun, 1);
  		pop_stack();
  		
  		if (s_flag)
--- 553,559 ----
  	    }
  	    else
  	    {
! 		call_function(ob, inh, fun, num_args);
  		pop_stack();
  		
  		if (s_flag)
===================================================================
RCS file: /home/oper/ac/.CVSROOT/src/debug.c,v
retrieving revision 3.1.2.1
diff -c -r3.1.2.1 debug.c
*** 3.1.2.1	1994/03/10 04:33:29
--- debug.c	1994/03/10 04:55:31
***************
*** 765,776 ****
  	{
  	    if (ob)
  	    {
  		int num_co, num_inv;
- 		struct call *c;
  		struct object *o;
  
! 		for (num_co = 0, c = ob->call_outs; c;
! 		     num_co++, c = c->next) ;
  
  		for (num_inv = 0, o = ob->contains; o;
  		     num_inv++, o = o->next_inv) ;
--- 765,775 ----
  	{
  	    if (ob)
  	    {
+ 		extern int num_call_outs(struct object *);
  		int num_co, num_inv;
  		struct object *o;
  
! 		num_co = num_call_outs(ob);
  
  		for (num_inv = 0, o = ob->contains; o;
  		     num_inv++, o = o->next_inv) ;
***************
*** 826,832 ****
  		break;
  	    
  	    if (v->item[2].type != T_NUMBER ||
! 		v->item[2].u.number < 2)
  		break;
  	    
  	    if (v->item[3].type != T_NUMBER ||
--- 825,831 ----
  		break;
  	    
  	    if (v->item[2].type != T_NUMBER ||
! 		v->item[2].u.number < 0)
  		break;
  	    
  	    if (v->item[3].type != T_NUMBER ||
===================================================================
RCS file: /home/oper/ac/.CVSROOT/src/func_spec.c,v
retrieving revision 3.1
diff -c -r3.1 func_spec.c
*** 3.1	1994/01/23 01:09:25
--- func_spec.c	1994/02/21 03:14:36
***************
*** 33,39 ****
  string	ctime(int);
  mixed	debug(string, ...);
  object	*deep_inventory(int|object default: F_THIS_OBJECT);
- void    delete_call_out(int);
  void	destruct();
  void	disable_commands();
  void	ed(void|string, void|string);
--- 33,38 ----
***************
*** 51,58 ****
  int     floatp(mixed);
  string	function_exists(string, object default: F_THIS_OBJECT);
  string	*get_dir(string);
! mixed   *get_all_call_outs();
! mixed   *get_call_out(int);
  string	implode(int|string *, string);
  void	input_to(string, ...);
  int	intp(mixed);
--- 50,57 ----
  int     floatp(mixed);
  string	function_exists(string, object default: F_THIS_OBJECT);
  string	*get_dir(string);
! mixed   *get_all_alarms();
! mixed   *get_alarm(int);
  string	implode(int|string *, string);
  void	input_to(string, ...);
  int	intp(mixed);
***************
*** 93,98 ****
--- 92,98 ----
  string	read_file(string, void|int, void|int); 
  string  readable_string(string);
  string	*regexp(string *, string);
+ void    remove_alarm(int);
  int	rename(string, string);
  int	restore_object(string);
  mapping	restore_map(string);
***************
*** 100,105 ****
--- 100,107 ----
  void	rmdir(string);
  void	save_object(string);
  void	save_map(mapping, string);
+ int     set_alarm(float, float, string, ...);
+ int     set_alarmv(float, float, string, mixed *);
  void	set_auth(object,mixed);
  string	set_bit(string, int);
  void	set_living_name(string);
===================================================================
RCS file: /home/oper/ac/.CVSROOT/src/interface.h,v
retrieving revision 3.1
diff -c -r3.1 interface.h
*** 3.1	1994/01/23 01:10:05
--- interface.h	1994/02/21 01:45:33
***************
*** 5,13 ****
  
  #define VAR(i) (current_object->variables[\
  		current_object->prog->inherit[inh_offset +\
! 		current_prog->cfun[(i).num].inh].\
  		variable_index_offset	+\
! 		current_prog->cfun[(i).num].idx])
  
  typedef struct var_info
  {
--- 5,13 ----
  
  #define VAR(i) (current_object->variables[\
  		current_object->prog->inherit[inh_offset +\
! 		current_prog->cfuns[(i).num].inh].\
  		variable_index_offset	+\
! 		current_prog->cfuns[(i).num].idx])
  
  typedef struct var_info
  {
===================================================================
RCS file: /home/oper/ac/.CVSROOT/src/interpret.c,v
retrieving revision 3.1.2.1
diff -c -r3.1.2.1 interpret.c
*** 3.1.2.1	1994/03/10 04:33:36
--- interpret.c	1994/03/10 06:50:58
***************
*** 3847,3869 ****
  }
  
  static void
! f_call_out(int num_arg)
  {
      struct svalue *arg = sp - num_arg + 1;
!     int delay = 0, ret = 0;
      
      if (arg[1].type == T_FLOAT)
      {
  	delay = (int) (arg[1].u.real * TIME_RES +
  		       (arg[1].u.real < 0.0 ? -0.5: 0.5));
  	if (delay == 0 && arg[1].u.real < 0.0)
! 	    delay = -1;
      }
      else
      {
  	delay = arg[1].u.number * TIME_RES;
      }
  
      if (*(arg[0].u.string) == '.')
      {
  	pop_n_elems(num_arg);
--- 3847,3959 ----
  }
  
  static void
! f_set_alarm(int num_arg)
  {
      struct svalue *arg = sp - num_arg + 1;
!     int delay, reload, ret;
!     struct vector *v;
! 
!     if (arg[2].type != T_STRING)
! 	error("Wrong argument 3 to set_alarm.\n");
      
+     if (*(arg[2].u.string) == '.')
+     {
+ 	pop_n_elems(num_arg);
+ 	push_number(0);
+ 	return;
+     }
+ 
+     v = allocate_array(num_arg - 3);
+     memcpy(&v->item[0], &arg[3],
+ 	   (num_arg - 3) * sizeof(struct svalue));
+     sp = &arg[2];
+ 
+     if (!(current_object->flags & O_DESTRUCTED) &&
+ 	search_for_function(arg[2].u.string, current_object->prog))
+     {
+ 	if (function_type_mod_found & TYPE_MOD_PRIVATE &&
+ 	    inh_offset < function_inherit_found -
+ 	    function_prog_found->num_inherited + 1)
+ 	    error("Atempted callout of private function.\n");
+ 	
+ 	delay = (int) (arg[0].u.real * TIME_RES + 0.5);
+ 	
+ 	reload = (int) (arg[1].u.real * TIME_RES + 0.5);
+ 	
+ 	ret = new_call_out(current_object, function_index_found,
+ 			   function_inherit_found,
+ 			   delay, reload, v);
+     }
+     free_vector(v);
+     pop_n_elems(3);
+     push_number(ret);
+ }
+ 
+ static void
+ f_set_alarmv(int num_arg)
+ {
+     struct svalue *arg = sp - 3;
+     int delay, reload, ret;
+     struct vector *v;
+ 
+     if (arg[2].type != T_STRING)
+ 	error("Wrong argument 3 to set_alarm.\n");
+     if (arg[3].type != T_POINTER)
+ 	error("Wrong argument 4 to set_alarm.\n");
+ 
+     if (*(arg[2].u.string) == '.')
+     {
+ 	pop_n_elems(num_arg);
+ 	push_number(0);
+ 	return;
+     }
+ 
+     v = sp->u.vec;
+     sp--;
+ 
+     if (!(current_object->flags & O_DESTRUCTED) &&
+ 	search_for_function(arg[2].u.string, current_object->prog))
+     {
+ 	if (function_type_mod_found & TYPE_MOD_PRIVATE &&
+ 	    inh_offset < function_inherit_found -
+ 	    function_prog_found->num_inherited + 1)
+ 	    error("Atempted callout of private function.\n");
+ 	
+ 	delay = (int) (arg[0].u.real * TIME_RES + 0.5);
+ 	
+ 	reload = (int) (arg[1].u.real * TIME_RES + 0.5);
+ 	
+ 	ret = new_call_out(current_object, function_index_found,
+ 			   function_inherit_found,
+ 			   delay, reload, v);
+     }
+     free_vector(v);
+     pop_n_elems(3);
+     push_number(ret);
+ }
+ 
+ static void
+ f_call_out(int num_arg)
+ {
+     struct svalue *arg = sp - num_arg + 1;
+     int delay = 0, ret = 0, reload = 0;
+     struct vector *v = NULL;
+ 
      if (arg[1].type == T_FLOAT)
      {
  	delay = (int) (arg[1].u.real * TIME_RES +
  		       (arg[1].u.real < 0.0 ? -0.5: 0.5));
  	if (delay == 0 && arg[1].u.real < 0.0)
! 	    reload = 1;
      }
      else
      {
  	delay = arg[1].u.number * TIME_RES;
      }
  
+     if (delay < 0)
+ 	reload = delay = -delay;
+     
      if (*(arg[0].u.string) == '.')
      {
  	pop_n_elems(num_arg);
***************
*** 3871,3876 ****
--- 3961,3972 ----
  	return;
      }
  
+     if (num_arg == 3)
+     {
+ 	v = allocate_array(1);
+ 	assign_svalue_no_free(&v->item[0], sp);
+     }
+     
      if (!(current_object->flags & O_DESTRUCTED))
  	if (search_for_function(arg[0].u.string, current_object->prog))
  	{
***************
*** 3878,3895 ****
  		inh_offset < function_inherit_found -
  		function_prog_found->num_inherited + 1)
  		error("Atempted callout of private function.\n");
!     
  	    ret = new_call_out(current_object, function_index_found,
  			       function_inherit_found,
! 			       delay, num_arg == 3 ? sp : 0);
  	}
!     
      pop_n_elems(num_arg);
      push_number(ret);
  }
  
  static void
! f_delete_call_out(int num_arg)
  {
      extern void delete_call(struct object *, int);
      
--- 3974,3992 ----
  		inh_offset < function_inherit_found -
  		function_prog_found->num_inherited + 1)
  		error("Atempted callout of private function.\n");
! 		
  	    ret = new_call_out(current_object, function_index_found,
  			       function_inherit_found,
! 			       delay, reload, v);
  	}
!     if (v)
! 	free_vector(v);
      pop_n_elems(num_arg);
      push_number(ret);
  }
  
  static void
! f_remove_alarm(int num_arg)
  {
      extern void delete_call(struct object *, int);
      
***************
*** 3897,3903 ****
  }
  
  static void
! f_get_all_call_outs(int num_arg)
  {
      struct vector *ret;
      extern struct vector *get_calls(struct object *);
--- 3994,4000 ----
  }
  
  static void
! f_get_all_alarms(int num_arg)
  {
      struct vector *ret;
      extern struct vector *get_calls(struct object *);
***************
*** 3911,3917 ****
  	push_number(0);
  }
  static void
! f_get_call_out(int num_arg)
  {
      struct vector *ret;
      extern struct vector *get_call(struct object *, int);
--- 4008,4014 ----
  	push_number(0);
  }
  static void
! f_get_alarm(int num_arg)
  {
      struct vector *ret;
      extern struct vector *get_call(struct object *, int);
===================================================================
RCS file: /home/oper/ac/.CVSROOT/src/lint.h,v
retrieving revision 3.1.2.3
diff -c -r3.1.2.3 lint.h
*** 3.1.2.3	1994/03/10 06:04:26
--- lint.h	1994/03/10 06:05:43
***************
*** 33,38 ****
--- 33,39 ----
  struct reloc;
  struct object;
  struct mapping;
+ struct vector;
  
  #if (!defined(HAS_MEMMOVE))
  #define memmove bcopy
***************
*** 153,159 ****
  void debug_message();
  void debug_message_value (struct svalue *);
  int new_call_out (struct object *, unsigned int, unsigned int,
! 		  int, struct svalue *);
  int add_action (struct svalue *, struct svalue *, int);
  
  void list_files (char *),
--- 154,160 ----
  void debug_message();
  void debug_message_value (struct svalue *);
  int new_call_out (struct object *, unsigned int, unsigned int,
! 		  int, int, struct vector *);
  int add_action (struct svalue *, struct svalue *, int);
  
  void list_files (char *),
===================================================================
RCS file: /home/oper/ac/.CVSROOT/src/main.c,v
retrieving revision 3.1.2.2
diff -c -r3.1.2.2 main.c
*** 3.1.2.2	1994/03/10 04:33:40
--- main.c	1994/03/10 04:55:46
***************
*** 56,62 ****
  extern struct object *master_ob;
  
  static void start_ip_demon();
- extern void sig_alert();
  static void
  update_current_time()
  {
--- 56,61 ----
***************
*** 131,136 ****
--- 130,137 ----
      current_time = get_current_time();;
      signal(SIGALRM, update_current_time);
      ualarm(1000000/TIME_RES, 1000000/TIME_RES);
+ 
+ 
      if (RESERVED_SIZE > 0)
  	reserved_area = malloc(RESERVED_SIZE);
      for (i=0; i < sizeof consts / sizeof consts[0]; i++)
***************
*** 138,143 ****
--- 139,150 ----
      init_num_args();
      reset_machine(1);
      init_cfuns();
+ 
+     /*
+      * Set up the signal handling.
+      */
+     init_signals();
+ 
  #ifdef BINARIES
      /*
       * Find the modification time of the driver. For reasons of binary
***************
*** 207,212 ****
--- 214,222 ----
  	exit(1);
      }
  
+     /* Initialize swap */
+     init_swap();
+ 
  #ifndef NO_IP_DEMON
      if (!no_ip_demon)
  	start_ip_demon();
***************
*** 359,370 ****
      preload_objects(e_flag);
      apply_master_ob(M_FINAL_BOOT, 0);
      
-     /*
-      * Set up the signal handling.
-      */
-     signal(SIGUSR1, sig_alert);
-     signal(SIGUSR2, sig_alert);
- 
      backend();
      return 0;
  }
--- 369,374 ----
===================================================================
RCS file: /home/oper/ac/.CVSROOT/src/master.n,v
retrieving revision 3.1
diff -c -r3.1 master.n
*** 3.1	1994/01/23 01:10:51
--- master.n	1994/03/08 05:26:29
***************
*** 41,47 ****
  # Error admin.
  #######
  log_error
! query_player_level
  #
  # Authority admin.
  #######
--- 41,47 ----
  # Error admin.
  #######
  log_error
! runtime_error
  #
  # Authority admin.
  #######
***************
*** 57,63 ****
  define_include_dirs
  predef_defines
  memory_failure
! memory_reconfigure
  #
  # ed()
  #######
--- 57,63 ----
  define_include_dirs
  predef_defines
  memory_failure
! external_signal
  #
  # ed()
  #######
===================================================================
RCS file: /home/oper/ac/.CVSROOT/src/object.c,v
retrieving revision 3.1.2.1
diff -c -r3.1.2.1 object.c
*** 3.1.2.1	1994/01/23 08:56:30
--- object.c	1994/02/15 03:39:44
***************
*** 442,456 ****
  	} 
  	else
  	{
! 	    if (i > nmax)
  	    {
  		struct svalue *ntmp;
  
! 		nmax *= 2;
! 		ntmp = (struct svalue *)xalloc(nmax * sizeof(struct svalue));
  		memcpy((char *)ntmp, (char *)tmp, sizeof(struct svalue) * nmax);
  		free((char *)tmp);
  		tmp = ntmp;
  		for(k = i; k < nmax; k++)
  		    tmp[k] = const0;
  	    }
--- 442,456 ----
  	} 
  	else
  	{
! 	    if (i >= nmax)
  	    {
  		struct svalue *ntmp;
  
! 		ntmp = (struct svalue *)xalloc(nmax * 2 * sizeof(struct svalue));
  		memcpy((char *)ntmp, (char *)tmp, sizeof(struct svalue) * nmax);
  		free((char *)tmp);
  		tmp = ntmp;
+ 		nmax *= 2;
  		for(k = i; k < nmax; k++)
  		    tmp[k] = const0;
  	    }
***************
*** 485,511 ****
  	}
  	else
  	{
! 	    struct svalue arg, val;
  	    arg = const0;
- 	    val = const0;
  	    if (!restore_one(&arg, str))
  		break;
        	    if (*(*str)++ != ':')
  	    {
  		free_svalue(&arg);
- 		free_svalue(&val);
- 		break;
- 	    }
- 	    if (!restore_one(&val, str))
- 	    {
- 		free_svalue(&arg);
- 		free_svalue(&val);
  		break;
  	    }
! 	    assign_svalue(get_map_lvalue(m, &arg, 1), &val);
  	    free_svalue(&arg);
! 	    free_svalue(&val);
! 	    if (*(*str)++ != ',')
  		break;
  	}
      }
--- 485,504 ----
  	}
  	else
  	{
! 	    struct svalue arg, *val;
  	    arg = const0;
  	    if (!restore_one(&arg, str))
  		break;
        	    if (*(*str)++ != ':')
  	    {
  		free_svalue(&arg);
  		break;
  	    }
! 	    val = get_map_lvalue(m, &arg, 1);
  	    free_svalue(&arg);
! 
! 	    if (!restore_one(val, str) ||
! 		*(*str)++ != ',')
  		break;
  	}
      }
***************
*** 597,612 ****
              if (sscanf(s,"$%d@%[^$ \n\t]$",&ct,name) != 2)
                  return 0;
              ob = find_object2(name);
              if (ob && ob->created == ct)
              {
-                 free_svalue(v);
                  v->type = T_OBJECT;
                  v->u.ob = ob;
                  add_ref(ob,"restore_one");
              }
              else
              {
-                 free_svalue(v);
                  v->type = T_NUMBER;
                  v->u.number = 0;
              }
--- 590,604 ----
              if (sscanf(s,"$%d@%[^$ \n\t]$",&ct,name) != 2)
                  return 0;
              ob = find_object2(name);
+ 	    free_svalue(v);
              if (ob && ob->created == ct)
              {
                  v->type = T_OBJECT;
                  v->u.ob = ob;
                  add_ref(ob,"restore_one");
              }
              else
              {
                  v->type = T_NUMBER;
                  v->u.number = 0;
              }
===================================================================
RCS file: /home/oper/ac/.CVSROOT/src/object.h,v
retrieving revision 3.1
diff -c -r3.1 object.h
*** 3.1	1994/01/23 01:11:14
--- object.h	1994/02/15 06:11:22
***************
*** 18,34 ****
  #define O_SWAPPED		0x20  /* Is it swapped to file */
  #define O_ONCE_INTERACTIVE	0x40  /* Has it ever been interactive ? */
  
! struct call
! {
!     unsigned short fun;
!     unsigned short inherit;
!     int delay;
!     unsigned int when;
!     int id;
!     struct call *next;
!     struct object *command_giver;
!     struct svalue v;
! };
  
  struct object {
      unsigned short flags;	/* Bits or'ed together from above */
--- 18,24 ----
  #define O_SWAPPED		0x20  /* Is it swapped to file */
  #define O_ONCE_INTERACTIVE	0x40  /* Has it ever been interactive ? */
  
! struct call;
  
  struct object {
      unsigned short flags;	/* Bits or'ed together from above */
===================================================================
RCS file: /home/oper/ac/.CVSROOT/src/patchlevel.h,v
retrieving revision 3.1.2.2
diff -c -r3.1.2.2 patchlevel.h
*** 3.1.2.2	1994/03/10 06:04:27
--- patchlevel.h	1994/03/10 06:11:01
***************
*** 1 ****
! #define PATCH_LEVEL	25
--- 1 ----
! #define PATCH_LEVEL	31
===================================================================
RCS file: /home/oper/ac/.CVSROOT/src/postlang.y,v
retrieving revision 3.1.2.2
diff -c -r3.1.2.2 postlang.y
*** 3.1.2.2	1994/03/10 06:04:28
--- postlang.y	1994/03/10 06:10:42
***************
*** 1260,1266 ****
  	      else if (exact_types)
  		  type_error("Bad type of argument used for range", $1);
  	  };
! 	| expr4 '[' F_RANGE { ins_f_byte(F_CONST0) } comma_expr ']'
  	  {
  	      ins_f_byte(F_RANGE);
  	      last_push_indexed = 0;
--- 1260,1266 ----
  	      else if (exact_types)
  		  type_error("Bad type of argument used for range", $1);
  	  };
! 	| expr4 '[' F_RANGE { ins_f_byte(F_CONST0); } comma_expr ']'
  	  {
  	      ins_f_byte(F_RANGE);
  	      last_push_indexed = 0;
***************
*** 2553,2559 ****
      if (!(num_parse_error || inherit_file))
      {
  	link_C_functions(current_file);
! 
  	link_errors = 0;
  	process_reloc((struct reloc *)mem_block[A_RELOC].block,
  		      mem_block[A_RELOC].current_size / sizeof(struct reloc),
--- 2553,2559 ----
      if (!(num_parse_error || inherit_file))
      {
  	link_C_functions(current_file);
! 	
  	link_errors = 0;
  	process_reloc((struct reloc *)mem_block[A_RELOC].block,
  		      mem_block[A_RELOC].current_size / sizeof(struct reloc),
***************
*** 2659,2670 ****
      total_program_size += prog->exec_size;
      total_prog_block_size += prog->total_size;
      total_num_prog_blocks += 1;
-     swap_lineno(prog);
  
      for (i=0; i < A_NUM; i++)
          free((char *)mem_block[i].block);
  
!     if (num_parse_error)
      {
          free_prog(prog, 0);
          prog = 0;
--- 2659,2669 ----
      total_program_size += prog->exec_size;
      total_prog_block_size += prog->total_size;
      total_num_prog_blocks += 1;
  
      for (i=0; i < A_NUM; i++)
          free((char *)mem_block[i].block);
  
!     if (num_parse_error || inherit_file)
      {
          free_prog(prog, 0);
          prog = 0;
===================================================================
RCS file: /home/oper/ac/.CVSROOT/src/simulate.c,v
retrieving revision 3.1.2.3
diff -c -r3.1.2.3 simulate.c
*** 3.1.2.3	1994/03/10 06:04:29
--- simulate.c	1994/03/10 06:05:53
***************
*** 400,406 ****
  	strcat(ob->name, "#0");
      }
      ob->prog = prog;
!     
      if (obj_list)
      {
  	ob->next_all = obj_list;
--- 400,414 ----
  	strcat(ob->name, "#0");
      }
      ob->prog = prog;
! #ifdef BINARIES
!     if (pragma_save_binary)
!     {
! 	save_binary(ob->prog);
! 	pragma_save_binary = 0;
!     }
! #endif /* BINARIES */
!     swap_lineno(ob->prog);
! 
      if (obj_list)
      {
  	ob->next_all = obj_list;
***************
*** 444,457 ****
  	so it can be removed if the following code causes an LPC error
       */
  
- #ifdef BINARIES
-     if (pragma_save_binary)
- 	{
- 	    save_binary(ob->prog);
- 	}
-     pragma_save_binary = 0;
- #endif /* BINARIES */
- 
      if (master_ob)
      {
  	push_object(current_object);
--- 452,457 ----
***************
*** 2443,2481 ****
  	    struct object *ob;
  	    ob = find_object2(object_name);
  	    if (!ob) {
- 		if (command_giver)
- 		    add_message("error when executing program in destroyed object %s\n",
- 				object_name);
  		debug_message("error when executing program in destroyed object %s\n",
  			      object_name);
  	    }
  	}
! 	if (command_giver && command_giver->interactive) {
! 	    struct svalue *v = 0;
! 	    
! 	    /* 
! 	     * The stack must be brought in a usable state. After the
! 	     * call to reset_machine(), all arguments to error() are invalid,
! 	     * and may not be used any more. The reason is that some strings
! 	     * may have been on the stack machine stack, and has been deallocated.
! 	     */
! 	    reset_machine (0);
! 	    push_constant_string("error messages");
! 	    v = apply_master_ob(M_QUERY_PLAYER_LEVEL, 1);
! 	    if (v && v->u.number != 0)
! 	    {
! 		add_message("%s", emsg_buf+1);
! 		if (current_object)
! 		    add_message("program: %s, object: %s File: %s\n",
! 				current_prog ? current_prog->name : "",
! 				current_object->name,
! 				get_srccode_position_if_any());
! 	    }
  	    else
! 	    {
! 		add_message("Your sensitive mind notices a wrongness in the fabric of space.\n");
! 	    }
  	}
      }
      else
      {
--- 2443,2478 ----
  	    struct object *ob;
  	    ob = find_object2(object_name);
  	    if (!ob) {
  		debug_message("error when executing program in destroyed object %s\n",
  			      object_name);
  	    }
  	}
! 	/* 
! 	 * The stack must be brought in a usable state. After the
! 	 * call to reset_machine(), all arguments to error() are invalid,
! 	 * and may not be used any more. The reason is that some strings
! 	 * may have been on the stack machine stack, and has been deallocated.
! 	 */
! 	reset_machine (0);
! 	push_string(emsg_buf, STRING_MALLOC);
! 	if (current_object)
! 	{
! 	    push_object(current_object);
! 
! 	    if (current_prog)
! 		push_string(current_prog->name, STRING_MALLOC);
  	    else
! 		push_constant_string("<???>");
! 
! 	    push_string(get_srccode_position_if_any(), STRING_MALLOC);
! 	}
! 	else
! 	{
! 	    push_number(0);
! 	    push_constant_string("<???>");
! 	    push_constant_string("");
  	}
+ 	apply_master_ob(M_RUNTIME_ERROR, 4);
      }
      else
      {
===================================================================
RCS file: /home/oper/ac/.CVSROOT/src/swap.c,v
retrieving revision 3.1.2.2
diff -c -r3.1.2.2 swap.c
*** 3.1.2.2	1994/03/10 06:04:29
--- swap.c	1994/03/10 06:08:11
***************
*** 5,15 ****
  
  #include <sys/types.h>
  #include <sys/stat.h>
- #include <stdio.h>
  #include <fcntl.h>
! #ifdef __STDC__
! #include <memory.h>
! #endif
  
  #include "config.h"
  #include "lint.h"
--- 5,12 ----
  
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <fcntl.h>
! #include <stdio.h>
  
  #include "config.h"
  #include "lint.h"
***************
*** 20,478 ****
  #include "mapping.h"
  #include <alloca.h>
  
! #define align(x) ( ((x) + (sizeof(void*)-1) )  &  ~(sizeof(void*)-1) )
! 
! #if defined(__NetBSD__) || defined(__bsdi__) || defined(_SEQUENT_)
! #define	tell(fd)	lseek(fd, 0L, SEEK_CUR)
! #endif
! 
! #define NEW_SWAP
! 
! struct object *swap_ob = 0;
! struct program *swap_prog = 0;
! int max_swap_memory = 0x40000001;
! int min_swap_memory = 0x40000000;
! int min_swap_time =   0x40000000;
! int max_swap_time =   0x40000001;
! 
! extern struct program *prog_list;
! extern struct object *obj_list;
! extern int current_time;
! int used_memory;
! int first_block = 0;
! static int missed_hole = 0;
! 
! extern int tot_alloc_object_size;
! int total_lineno_swapped = 0;
! int obj_swapped = 0;
! int obj_bytes_swapped = 0;
! 
! int num_swapped;
! int total_bytes_swapped;
! 
! FILE *swap_file = 0;
  
  
! int total_num_prog_blocks = 0, total_prog_block_size = 0;
! int prog_code_size = 0, prog_func_size = 0, prog_var_size = 0,
! prog_inherit_size = 0, prog_string_size = 0, prog_line_size = 0;
! int program_bytes_swapped = 0, total_program_size = 0, programs_swapped = 0;
! int last_address = 0, first_hole = 0, allocated_swap = 0, allocated_swap_blocks = 0, current_hole = 0;
! int tot_alloc_variable_size = 0;
! int swap_out_prog, swap_out_obj;
! int swap_in_prog, swap_in_obj;
! int swap_out = 0, swap_in = 0;
  
! extern volatile int interupted;
  
! extern int errno;
  
! extern int d_flag;
! static char file[80];
  
! static int 
! assert_swap_file()
  {
!     int file_num;
!     
!     if (!swap_file)
!     {
!       char hn[80];
  
!       gethostname(hn, sizeof(hn));
!       sprintf(file, "%s.%s.%d", SWAP_FILE, hn, getpid());
  
!       file_num = open(file, O_RDWR | O_CREAT,0600);
!       swap_file = fopen(file, "w+b");
!       if (!swap_file)
!           return 0;
!       fwrite("SWAPSWAPSWAPSWAP", align(4), 1, swap_file);
!       last_address = first_hole = ftell(swap_file);
!     }
!     
!     return 1;
  }
  
! #define swap_read(buf, len) ((len) * fread((buf), (len), 1, swap_file))
! #define swap_write(buf, len) ((len) * fwrite((buf), (len), 1, swap_file))
! #define swap_tell() ftell(swap_file)
! #define swap_seek(where) fseek(swap_file, (where), SEEK_SET)
! #define swap_flush() fseek(swap_file, 0, SEEK_CUR)
! 
! 
! static int start_of_current_block;
! 
! static int start_block(int *address)
  {
!     int dummy = 0;
! 
!     if (!assert_swap_file())
! 	return;
! 
!     start_of_current_block = *address = last_address;
!     if (swap_seek(*address) == -1)
! 	fatal("Couldn't seek the swap file, errno %d, offset %d.\n",
! 	      errno, *address);
!     
!     if (swap_write((char *)&address, sizeof(long *)) != sizeof(long *))
!     {
! 	debug_message("I/O error in swap.\n");
! 	*address = -1;
! 	return;
!     }
!     if (swap_write((char *)&dummy, sizeof(unsigned int))
! 	!= sizeof(unsigned int))
!     {
! 	debug_message("I/O error in swap.\n");
! 	*address = -1;
! 	return;
!     }
  }
  
! static int end_block()
  {
!     int end_of_current_block;
!     int rsize;
!     int nlast_address;
      
!     end_of_current_block = swap_tell();
!     if (start_of_current_block != last_address)
! 	fatal("Error in swaping out!\n");
!     
!     rsize = align(end_of_current_block - start_of_current_block);
  	
!     swap_seek(start_of_current_block + sizeof(long *));
!     if (swap_write((char *)&rsize, sizeof(unsigned int)) != sizeof(unsigned int))
      {
! 	debug_message("I/O error in swap.\n");
! 	return;
      }
! 
!     nlast_address = last_address + rsize;
!     if (first_hole == last_address)
! 	first_hole = nlast_address;
!     last_address = nlast_address;
!     
!     allocated_swap += rsize;
!     allocated_swap_blocks++;
!     swap_out++;
!     if (last_address < end_of_current_block)
! 	fatal("Wrong value of last_address.\n");
!     
!     return;
  }
  
! static void
! swap_block(int *address, char *block, unsigned int size)
  {
!     unsigned rsize = align(size + sizeof(char *) + sizeof(int)), osize = 0;
!     int *oaddress = 0;
!     int nlast_address, chsum, i;
!     char *tst;
!     
!     if (*address == -1)
! 	return;
!     
!     if (!assert_swap_file())
  	return;
  
!     if (*address == 0)
! 	{
! 	    *address = last_address;
! 	    if (swap_seek(*address) == -1)
! 		fatal("Couldn't seek the swap file, errno %d, offset %d.\n",
! 		      errno, *address);
! 	    if (swap_write((char *)&address, sizeof(long *)) != sizeof(long *))
! 		{
! 		    debug_message("I/O error in swap.\n");
! 		    *address = -1;
! 		    return;
! 		}
! 	    if (swap_write((char *)&rsize, sizeof(unsigned int)) != sizeof(unsigned int))
! 		{
! 		    debug_message("I/O error in swap.\n");
! 		    *address = -1;
! 		    return;
! 		}
! 	    if (swap_write(block, size) != size)
! 		{
! 		    debug_message("I/O error in swap.\n");
! 		    *address = -1;
! 		    return;
! 		}
! 	    nlast_address = last_address + rsize;
! 	    if (first_hole == last_address)
! 		first_hole = nlast_address;
! 	    last_address = nlast_address;
! 	    
! 	    allocated_swap += rsize;
! 	    allocated_swap_blocks++;
! 	    swap_out++;
! 	    return;
! 	}
!     if (swap_seek(*address) == -1)
! 	fatal("Couldn't seek the swap file, errno %d, offset %d.\n",
! 	      errno, *address);
!     
!     swap_read((char *)&oaddress, sizeof(unsigned *));
!     swap_read((char *)&osize, sizeof(int));
!     if (oaddress != address)
! 	fatal("Wrong address in swap file (%d should be %d).\n",
! 	      oaddress, address);
! 
!     if (osize != rsize)
! 	fatal("Wrong size in swap file (%d should be %d).\n",
! 	      osize, rsize);
! 
!     swap_flush();
!         
!     if (swap_write(block, size) != size)
  	{
! 	    debug_message("I/O error in swap.\n");
! 	    *address = -1;
! 	    return;
  	}
!     swap_out++;
!     return;
  }
! 
! static void
! delete_block(int *address)
  {
!     unsigned rsize;
!     int *oaddress;
      
!     void *i = 0;
!     if (swap_seek(*address) == -1)
! 	fatal("Couldn't seek the swap file, errno %d, offset %d.\n",
! 	      errno, *address);
!     swap_read((char *)&oaddress, sizeof(int *));
!     swap_read((char *)&rsize, sizeof(unsigned));
!     if (oaddress != address)
! 	fatal("Wrong address in swap file (%d should be %d).\n",
! 	      oaddress, address);
! 
!     if (swap_seek(*address) == -1)
! 	fatal("Couldn't seek the swap file, errno %d, offset %d.\n",
! 	      errno, *address);
! 
!     if (swap_write((char *)&i, sizeof(int *)) != sizeof(int *))
! 	debug_message("I/O error in swap.\n");
  
!     if (*address + rsize == last_address)
! 	last_address = *address;
!     
!     if (first_hole > *address)
! 	first_hole = *address;
!     if (current_hole > *address)
! 	missed_hole = 1;
!     *address = 0;
!     allocated_swap -= rsize;
!     allocated_swap_blocks--;
!     return;
  }
  
! static int current_read_end;
! 
! static void
! start_read(int *address)
  {
!     int *oaddress, osize;
!     
!     if (swap_seek(*address) == -1)
! 	fatal("Couldn't seek the swap file, errno %d, offset %d.\n",
! 	      errno, *address);
!     
!     swap_read((char *)&oaddress, sizeof(long *));
!     swap_read((char *)&osize, sizeof(unsigned int));
!     
!     if (oaddress != address)
! 	fatal("Wrong address in swap file (%d should be %d).\n",
! 	      oaddress, address);
  
!     current_read_end = osize + *address;
  }
  
! static int
! end_read()
  {
!     if (align(swap_tell()) != current_read_end)
!     {
! 	debug_message("Error reading swapped svalues\n");
! 	return 1;
!     }
!     return 0;
  }
! 
! static void
! read_block(int *address, char **block, int size)
  {
!     int *oaddress = 0, *baddress;
!     int i, ochsum,chsum;
!     
!     unsigned rsize = align(size + sizeof(char *) + sizeof(int)), osize = 0;
!     
!     if (swap_seek(*address) == -1)
! 	fatal("Couldn't seek the swap file, errno %d, offset %d.\n",
! 	      errno, *address);
!     
!     swap_read((char *)&oaddress, sizeof(unsigned *));
!     swap_read((char *)&osize, sizeof(int));
!     
!     if (oaddress != address)
! 	fatal("Wrong address in swap file (%d should be %d).\n",
! 	      oaddress, address);
!     if (osize != rsize)
! 	fatal("Wrong size in swap file (%d should be %d).\n",
! 	      osize, rsize);
!     if (size)
! 	*block = xalloc(size);
!     else
! 	*block = xalloc(1);
  
!     swap_read(*block, size);
  
!     swap_in++;
!     
!     return;
! }
  
- #define BUFFER_SIZE 0x10000
- static int block_tail = 0, block_head = 0;
- static char *block = 0;
  
! static void
! init_block_move(int block_start)
! {
!     block_tail = block_start;
!     block_head = 0;
!     block = xalloc(BUFFER_SIZE);
!     return;
  }
  
! static void
! add_block_move(int *address, int rsize)
  {
!     unsigned size = rsize - sizeof(char *) - sizeof(int);
! 
  
!     if (block_tail == *address)
      {
! 	block_tail += rsize;
! 	return;
!     }
!     
!     *address = block_tail + block_head;
!     *(int **)(block + block_head) = address;
!     block_head += sizeof(char *);
!     *(int *)(block + block_head) = rsize;
!     block_head += sizeof(int);
!     
!     while (size > 0)
!     {
! 	int chunk_size = (BUFFER_SIZE - block_head - 8 > size) ? size : (BUFFER_SIZE - block_head - 8);
! 	if (chunk_size <= 0)
! 	    fatal("Negative read!");
! 	
! 	swap_read(block + block_head, chunk_size);
! 	size -= chunk_size;
! 	block_head += chunk_size;
! 	if (block_head >= BUFFER_SIZE - sizeof(char *) - sizeof(int) - 0x100)
! 	{
! 	    int l = swap_tell();
! 	    swap_seek(block_tail);
! 	    swap_write(block, block_head);
! 	    block_tail += block_head;
! 	    block_head = 0;
! 	    swap_seek(l);
! 	}
      }
!     return;
  }
  
! static int
! flush_block_move(int end)
  {
!     int r = 0;
!     int l;
!     void *p = 0;
!     
!     
!     if (block_tail == end)
!     {
! 	free(block);
! 	return end;
!     }
!     
!     
!     swap_seek(block_tail);
!     swap_write(block, block_head);
!     l = end - (r = swap_tell());
!     
!     swap_write((char *)&p, sizeof(char *));
!     swap_write((char *)&l, sizeof(int));
!     free(block);
!     block = 0;
!     block_head = block_tail = 0;
      
!     return r;
  }
  
  
! static int
! move_block(int force)
! {
!     int *address;
!     int size;
!     int current;
!     int is_last = current_hole == first_hole;
!     
!     extern struct object *master_ob;
!     extern void flush_all_player_mess();
  
!     if (first_hole == last_address)
! 	return 0;
!     if (!current_hole)
!     {
! 	current_hole = first_hole;
! 	is_last = 1;
!     }
!     
!     current = current_hole;
!     
!     init_block_move(current);
  
!     while(current != last_address)
!     {
! 	swap_seek(current);
! 	swap_read((char *)&address, sizeof(int *));
! 	swap_read((char *)&size, sizeof(int));
! 	if (address)
! 	    add_block_move(address, size);
! 	current += size;
! 	if (interupted && !force)
! 	{
! 	    current_hole = flush_block_move(current);
! 	    if (is_last)
! 		first_hole = current_hole;
! 	    
! 	    return 1;
! 	}
!     }
!     last_address = flush_block_move(current);
!     current_hole = 0;
  
!     if (is_last)
! 	first_hole = last_address;
!     else if (missed_hole)
!     {
! 	missed_hole = 0;
! 	return move_block(force);
!     }
!     return 0;
!     
! }
  
  
  int num_swapped_arrays, size_swapped_arrays;
  int num_swapped_mappings, size_swapped_mappings;
--- 17,361 ----
  #include "mapping.h"
  #include <alloca.h>
  
! #define SWAP_FILE "LP_SWAP.3"
  
+ #define BUFFER_DATA_SIZE 256
+ #define BUFFER_PTR_SIZE (BUFFER_DATA_SIZE / sizeof(unsigned int))
+ #define NUM_FREE 8
+ #define HAS_PREAD
  
! static struct buffer
! {
!     unsigned int bufnum;
!     unsigned short offset;
!     unsigned short flags;
! #define B_DIRTY 1
! #define B_INUSE 2
  
!     union
!     {
! 	char data[BUFFER_DATA_SIZE];
! 	unsigned int addr[BUFFER_PTR_SIZE];
!     } u;
! } free_blocks[NUM_FREE], zero;
  
! static unsigned short cur_free;
  
! static unsigned int maxblock = 0;
! static int swap_fd;
! static char swap_file[80];
  
! void
! init_swap()
  {
!     char hn[80];
!     static int initialized = 0;
!     int i;
!     if (initialized)
! 	return;
  
!     initialized = 1;
!     gethostname(hn, sizeof(hn));
!     sprintf(swap_file, "%s.%s.%d", SWAP_FILE, hn, getpid());
!     
!     swap_fd = open(swap_file, O_RDWR | O_CREAT | O_TRUNC, 0600);
!     if (swap_fd < 0)
! 	fatal("Can't create swapfile.\n");
!     for (i = 0; i < NUM_FREE; i++)
! 	free_blocks[i].flags = 0;
! #ifdef HAS_PREAD
!     pwrite(swap_fd, zero.u.data, BUFFER_DATA_SIZE,
! 	   maxblock * BUFFER_DATA_SIZE);
! #else
!     lseek(swap_fd, maxblock * BUFFER_DATA_SIZE,
! 	  SEEK_SET);
!     write(swap_fd, zero.u.data, BUFFER_DATA_SIZE);
! #endif
  
!     cur_free = 0;
!     free_blocks[0].flags |= B_INUSE;
!     free_blocks[0].u.addr[0] = 0;
!     free_blocks[0].offset = 1;
  }
  
! void
! unlink_swap_file()
  {
!     unlink(swap_file);
  }
  
! unsigned int
! alloc_swap(void)
  {
!     unsigned int ret;
      
!     if (free_blocks[cur_free].offset > 1) /* Blocks exists in free list */
! 	ret = free_blocks[cur_free].u.addr[--free_blocks[cur_free].offset];
!     else if (free_blocks[cur_free].u.addr[0]) /* End of current block */
!     {
! 	ret = free_blocks[cur_free].u.addr[0];
! 	free_blocks[cur_free].flags &= ~B_INUSE;
! 	cur_free = (cur_free + (NUM_FREE - 1)) % NUM_FREE;
! 
! 	if ((free_blocks[cur_free].flags & B_INUSE) == 0)
! 	{
! 	    /* Read next block of free list */
! #ifdef HAS_PREAD
! 	    pread(swap_fd, free_blocks[cur_free].u.data, BUFFER_DATA_SIZE,
! 		  ret * BUFFER_DATA_SIZE);
! #else
! 	    lseek(swap_fd, ret * BUFFER_DATA_SIZE, SEEK_SET);
! 	    read(swap_fd, free_blocks[cur_free].u.data, BUFFER_DATA_SIZE);
! #endif
! 	    free_blocks[cur_free].flags |= B_INUSE;
! 	}
  	
! 	free_blocks[cur_free].offset = BUFFER_PTR_SIZE;
!     }
!     else
      {
! 	
! 	/* End of blocks */
! 	/* Extend the file */
! 	maxblock++;
! #ifdef HAS_PREAD
! 	pwrite(swap_fd, zero.u.data, BUFFER_DATA_SIZE,
! 	       maxblock * BUFFER_DATA_SIZE);
! #else
! 	lseek(swap_fd, maxblock * BUFFER_DATA_SIZE,
! 	      SEEK_SET);
! 	write(swap_fd, zero.u.data, BUFFER_DATA_SIZE);
! #endif
! 	ret = maxblock;
      }
!     return ret;
  }
  
! void
! free_swap(unsigned int addr)
  {
!     if (addr == 0)
  	return;
  
!     if (free_blocks[cur_free].offset >= BUFFER_PTR_SIZE)
!     {
! 	free_blocks[cur_free].bufnum = addr;
! 	cur_free = (cur_free + 1) % NUM_FREE;
! 	if (free_blocks[cur_free].flags & B_INUSE)
  	{
! #ifdef HAS_PREAD
! 	    pwrite(swap_fd, free_blocks[cur_free].u.data, BUFFER_DATA_SIZE,
! 		   free_blocks[cur_free].bufnum * BUFFER_DATA_SIZE);
! #else
! 	    lseek(swap_fd, free_blocks[cur_free].bufnum * BUFFER_DATA_SIZE,
! 		  SEEK_SET);
! 	    write(swap_fd, free_blocks[cur_free].u.data, BUFFER_DATA_SIZE);
! #endif
  	}
! 	free_blocks[cur_free].flags |= B_INUSE;
! 	free_blocks[cur_free].offset = 0;
!     }
!     free_blocks[cur_free].u.addr[free_blocks[cur_free].offset++] = addr;
  }
! 
! struct buffer *
! start_read(unsigned int addr)
  {
!     struct buffer *ret;
      
!     /* Allocate a buffer */
!     ret = (struct buffer *)xalloc(sizeof(struct buffer));
!     ret->flags = 0;
!     ret->bufnum = addr;
  
!     /* Read first block */
! #ifdef HAS_PREAD
!     pread(swap_fd, ret->u.data, BUFFER_DATA_SIZE, addr * BUFFER_DATA_SIZE);
! #else
!     lseek(swap_fd, addr * BUFFER_DATA_SIZE, SEEK_SET);
!     read(swap_fd, ret->u.data, BUFFER_DATA_SIZE);
! #endif
!     ret->offset = sizeof(unsigned int);
!     return ret;
  }
  
! int
! swap_read(struct buffer *buf, char *dest, unsigned int size)
  {
!     unsigned int csize, len;
!     char *cdest;
! 
!     csize = size;
!     cdest = dest;
!     while (csize > (len = BUFFER_DATA_SIZE - buf->offset))
!     {
! 	/* Empty buffer */
! 	memcpy(cdest, buf->u.data + buf->offset, len);
! 	cdest += len;
! 	csize -= len;
! 	buf->offset += len;
! 	if (buf->u.addr[0] == 0) /* Return if end of blocks */
! 	    return size - csize;
! 
! 	/* Read next block */
! 	buf->bufnum = buf->u.addr[0];
! #ifdef HAS_PREAD
! 	pread(swap_fd, buf->u.data, BUFFER_DATA_SIZE,
! 	      buf->bufnum * BUFFER_DATA_SIZE);
! #else
! 	lseek(swap_fd, buf->bufnum * BUFFER_DATA_SIZE, SEEK_SET);
! 	read(swap_fd, buf->u.data, BUFFER_DATA_SIZE);
! #endif
! 	buf->offset = sizeof(unsigned int);
!     }
  
!     /* Get the last needed from the buffer */
!     memcpy(cdest, buf->u.data + buf->offset, csize);
!     buf->offset += csize;
!     return size;
  }
  
! void
! end_read(struct buffer *buf)
  {
!     /* Free the buffer */
!     free((char *)buf);
  }
! 
! struct buffer *
! start_write(unsigned int *addrp)
  {
!     struct buffer *ret;
  
!     /* Allocate a buffer */
!     ret = (struct buffer *)xalloc(sizeof(struct buffer));
  
!     if (*addrp == 0)
!     {
! 	/* Allocate a new blocks */
! 	*addrp = alloc_swap();
!     }
  
  
!     ret->bufnum = *addrp;
!     ret->flags = 0;
! 
!     /* Read next pointer from first block */
! #ifdef HAS_PREAD
!     pread(swap_fd, ret->u.data, sizeof(unsigned int),
! 	  ret->bufnum * BUFFER_DATA_SIZE);
! #else
!     lseek(swap_fd, ret->bufnum * BUFFER_DATA_SIZE, SEEK_SET);
!     read(swap_fd, ret->u.data, sizeof(unsigned int));
! #endif
! 
!     ret->offset = sizeof(unsigned int);
!     return ret;
  }
  
! int
! swap_write(struct buffer *buf, char *dest, unsigned int size)
  {
!     unsigned int csize, len;
!     char *cdest;
  
!     csize = size;
!     cdest = dest;
!     while (csize > (len = BUFFER_DATA_SIZE - buf->offset))
      {
! 	/* Fill the buffer with data */
! 	memcpy(buf->u.data + buf->offset, cdest, len);
! 	cdest += len;
! 	csize -= len;
! 
! 	/* Allocate new blocks if we need to */
! 	if (buf->u.addr[0] == 0)
! 	    buf->u.addr[0] = alloc_swap();
! 
! 	/* Flush the block to disk */
! #ifdef HAS_PREAD
! 	pwrite(swap_fd, buf->u.data, BUFFER_DATA_SIZE,
! 	       buf->bufnum * BUFFER_DATA_SIZE);
! #else
! 	lseek(swap_fd, buf->bufnum * BUFFER_DATA_SIZE, SEEK_SET);
! 	write(swap_fd, buf->u.data, BUFFER_DATA_SIZE);
! #endif
! 
! 	/* Read in next pointer from next block */
! 	buf->bufnum = buf->u.addr[0];
! #ifdef HAS_PREAD
! 	pread(swap_fd, buf->u.data, sizeof(unsigned int),
! 	      buf->bufnum * BUFFER_DATA_SIZE);
! #else
! 	lseek(swap_fd, buf->bufnum * BUFFER_DATA_SIZE, SEEK_SET);
! 	read(swap_fd, buf->u.data, sizeof(unsigned int));
! #endif
! 	buf->offset = sizeof(unsigned int);
      }
! 
!     /* Copy the remaining data to the buffer */
!     memcpy(buf->u.data + buf->offset, cdest, csize);
!     buf->offset += csize;
!     return size;
  }
  
! void
! end_write(struct buffer *buf)
  {
!     /* Truncate the block list */
!     free_swap(buf->u.addr[0]);
!     buf->u.addr[0] = 0;
!     
!     /* Flush current buffer to disk */
! #ifdef HAS_PREAD
!     pwrite(swap_fd, buf->u.data, buf->offset,
! 	   buf->bufnum * BUFFER_DATA_SIZE);
! #else
!     lseek(swap_fd, buf->bufnum * BUFFER_DATA_SIZE, SEEK_SET);
!     write(swap_fd, buf->u.data, buf->offset);
! #endif
      
!     /* Free the buffer */
!     free((char *)buf);
!     return;
  }
+ 
  
+ #define align(x) ( ((x) + (sizeof(void *)-1) )  &  ~(sizeof(void *)-1) )
  
! struct object *swap_ob = 0;
! struct program *swap_prog = 0;
! int max_swap_memory = 0x40000001;
! int min_swap_memory = 0x40000000;
! int min_swap_time =   0x40000000;
! int max_swap_time =   0x40000001;
  
! extern struct program *prog_list;
! extern struct object *obj_list;
! extern int current_time;
! int used_memory;
! extern int tot_alloc_object_size;
! int total_lineno_swapped = 0;
! int obj_swapped = 0;
! int obj_bytes_swapped = 0;
  
! int num_swapped;
! int total_bytes_swapped;
  
! 
! 
! int total_num_prog_blocks = 0, total_prog_block_size = 0;
! int prog_code_size = 0, prog_func_size = 0, prog_var_size = 0,
! prog_inherit_size = 0, prog_string_size = 0, prog_line_size = 0;
! int program_bytes_swapped = 0, total_program_size = 0, programs_swapped = 0;
! int last_address = 0, first_hole = 0, allocated_swap = 0, allocated_swap_blocks = 0, current_hole = 0;
  
+ int tot_alloc_variable_size = 0;
+ int swap_out_prog, swap_out_obj;
+ int swap_in_prog, swap_in_obj;
+ int swap_out = 0, swap_in = 0;
+ 
+ extern int d_flag;
  
  int num_swapped_arrays, size_swapped_arrays;
  int num_swapped_mappings, size_swapped_mappings;
***************
*** 481,487 ****
  extern struct svalue const0;
  
  static void
! swap_svalue(struct svalue *arg)
  {
      switch(arg->type)
      {
--- 364,370 ----
  extern struct svalue const0;
  
  static void
! swap_svalue(struct buffer *buf, struct svalue *arg)
  {
      switch(arg->type)
      {
***************
*** 491,497 ****
      case T_NUMBER:
      case T_FLOAT:
  	arg->type |= T_LVALUE;
! 	swap_write((char *)arg, sizeof(struct svalue));
  	*arg = const0;
  	break;
      case T_STRING:
--- 374,380 ----
      case T_NUMBER:
      case T_FLOAT:
  	arg->type |= T_LVALUE;
! 	swap_write(buf, (char *)arg, sizeof(struct svalue));
  	*arg = const0;
  	break;
      case T_STRING:
***************
*** 501,508 ****
  	    
  	    str = arg->u.string;
  	    len = arg->u.number = strlen(str) + 1;
! 	    swap_write((char *)arg, sizeof(struct svalue));
! 	    swap_write(str, len);
  	    num_strings_swapped++;
  	    size_strings_swapped += len;
  	    switch(arg->string_type)
--- 384,391 ----
  	    
  	    str = arg->u.string;
  	    len = arg->u.number = strlen(str) + 1;
! 	    swap_write(buf, (char *)arg, sizeof(struct svalue));
! 	    swap_write(buf, str, len);
  	    num_strings_swapped++;
  	    size_strings_swapped += len;
  	    switch(arg->string_type)
***************
*** 530,536 ****
  	    if (v->ref != 1)
  	    {
  		arg->type |= T_LVALUE;
! 		swap_write((char *)arg, sizeof(struct svalue));
  		*arg = const0;
  	    }    
  	    else
--- 413,419 ----
  	    if (v->ref != 1)
  	    {
  		arg->type |= T_LVALUE;
! 		swap_write(buf, (char *)arg, sizeof(struct svalue));
  		*arg = const0;
  	    }    
  	    else
***************
*** 538,546 ****
  		int i;
  		
  		arg->u.number = v->size;
! 		swap_write((char *)arg, sizeof(struct svalue));
  		for (i = 0; i < v->size; i++)
! 		    swap_svalue(&v->item[i]);
  		*arg = const0;
  		num_swapped_arrays++;
  		size_swapped_arrays += sizeof(struct vector) +
--- 421,429 ----
  		int i;
  		
  		arg->u.number = v->size;
! 		swap_write(buf, (char *)arg, sizeof(struct svalue));
  		for (i = 0; i < v->size; i++)
! 		    swap_svalue(buf, &v->item[i]);
  		*arg = const0;
  		num_swapped_arrays++;
  		size_swapped_arrays += sizeof(struct vector) +
***************
*** 560,566 ****
  	    if (m->ref != 1)
  	    {
  		arg->type |= T_LVALUE;
! 		swap_write((char *)arg, sizeof(struct svalue));
  		*arg = const0;
  	    }    
  	    else
--- 443,449 ----
  	    if (m->ref != 1)
  	    {
  		arg->type |= T_LVALUE;
! 		swap_write(buf, (char *)arg, sizeof(struct svalue));
  		*arg = const0;
  	    }    
  	    else
***************
*** 570,582 ****
  		size = arg->u.number = m->card;
  		arg->string_type = m->size;
  		
! 		swap_write((char *)arg, sizeof(struct svalue));
  
  		for (i = j = 0; i < m->size; i++)
  		    for(pair = m->pairs[i]; pair; pair = pair->next)
  		    {
! 			swap_svalue(&pair->arg);
! 			swap_svalue(&pair->val);
  			j++;
  		    }
  		if (j != size)
--- 453,465 ----
  		size = arg->u.number = m->card;
  		arg->string_type = m->size;
  		
! 		swap_write(buf, (char *)arg, sizeof(struct svalue));
  
  		for (i = j = 0; i < m->size; i++)
  		    for(pair = m->pairs[i]; pair; pair = pair->next)
  		    {
! 			swap_svalue(buf, &pair->arg);
! 			swap_svalue(buf, &pair->val);
  			j++;
  		    }
  		if (j != size)
***************
*** 599,607 ****
  }
  
  static void
! unswap_svalue(struct svalue *arg)
  {
!     swap_read((char *)arg, sizeof(struct svalue));
      if (arg->type & T_LVALUE)
      {
  	arg->type &= ~T_LVALUE;
--- 482,490 ----
  }
  
  static void
! unswap_svalue(struct buffer *buf, struct svalue *arg)
  {
!     swap_read(buf, (char *)arg, sizeof(struct svalue));
      if (arg->type & T_LVALUE)
      {
  	arg->type &= ~T_LVALUE;
***************
*** 624,630 ****
  #else
  	    arg->u.string = xalloc(len);
  #endif
! 	    swap_read((char *)arg->u.string, len);
  #ifdef ALWAYS_SHARE
  	    arg->string_type = STRING_SHARED;
  	    arg->u.string = make_shared_string(arg->u.string);
--- 507,513 ----
  #else
  	    arg->u.string = xalloc(len);
  #endif
! 	    swap_read(buf, (char *)arg->u.string, len);
  #ifdef ALWAYS_SHARE
  	    arg->string_type = STRING_SHARED;
  	    arg->u.string = make_shared_string(arg->u.string);
***************
*** 644,650 ****
  	    size = arg->u.number;
  	    v = allocate_array(size);
  	    for (i = 0; i < size; i++)
! 		unswap_svalue(&v->item[i]);
  	    
  	    arg->u.vec = v;
  	    num_swapped_arrays--;
--- 527,533 ----
  	    size = arg->u.number;
  	    v = allocate_array(size);
  	    for (i = 0; i < size; i++)
! 		unswap_svalue(buf, &v->item[i]);
  	    
  	    arg->u.vec = v;
  	    num_swapped_arrays--;
***************
*** 662,670 ****
  	    arg->u.map = allocate_map(size);
  	    for (i = 0; i < size; i++)
  	    {
! 		unswap_svalue(&marg);
  		mval = get_map_lvalue(arg->u.map, &marg, 1);
! 		unswap_svalue(mval);
  		free_svalue(&marg);
  	    }
  	    
--- 545,553 ----
  	    arg->u.map = allocate_map(size);
  	    for (i = 0; i < size; i++)
  	    {
! 		unswap_svalue(buf, &marg);
  		mval = get_map_lvalue(arg->u.map, &marg, 1);
! 		unswap_svalue(buf, mval);
  		free_svalue(&marg);
  	    }
  	    
***************
*** 687,707 ****
  int 
  swap_object(struct object *ob)
  {
-     extern struct object *master_ob;
-     extern struct program *simul_efunp;
-     extern int errno;
-     extern struct svalue *sp, start_of_stack[];
      int size;
      int num_vars, i;
!     extern struct svalue const0;
!     
      if (ob->flags & (O_DESTRUCTED | O_SWAPPED))
  	return 0;
      
      if (d_flag & DEBUG_SWAP)
! 	{
! 	    fprintf(stderr, "Swap object %s (ref %d) from 0x%x\n", ob->name, ob->ref, ob->variables);
! 	}
      if (!ob->variables)
      {
  	return 0;
--- 570,587 ----
  int 
  swap_object(struct object *ob)
  {
      int size;
      int num_vars, i;
!     struct buffer *buf;
! 
      if (ob->flags & (O_DESTRUCTED | O_SWAPPED))
  	return 0;
      
      if (d_flag & DEBUG_SWAP)
!     {
! 	fprintf(stderr, "Swap object %s (ref %d) from 0x%x\n",
! 		ob->name, ob->ref, ob->variables);
!     }
      if (!ob->variables)
      {
  	return 0;
***************
*** 712,728 ****
  	variable_index_offset +	ob->prog->num_variables + 1;
      size = num_vars * sizeof(struct svalue);
      
!     start_block(&ob->swap_num);
!     
!     for (i = 0; i < num_vars; i++)
! 	swap_svalue(&ob->variables[i]);
!     end_block();
! 
      if (ob->swap_num == -1)
      {
  	ob->variables++;
! 	return;
      }
      free((char *)ob->variables);
      ob->variables = (struct svalue *)-1;
      obj_bytes_swapped += size;
--- 592,609 ----
  	variable_index_offset +	ob->prog->num_variables + 1;
      size = num_vars * sizeof(struct svalue);
      
!     buf = start_write(&ob->swap_num);
      if (ob->swap_num == -1)
      {
  	ob->variables++;
! 	end_write(buf);
! 	return 0;
      }
+     
+     for (i = 0; i < num_vars; i++)
+ 	swap_svalue(buf, &ob->variables[i]);
+     end_write(buf);
+ 
      free((char *)ob->variables);
      ob->variables = (struct svalue *)-1;
      obj_bytes_swapped += size;
***************
*** 739,750 ****
  void
  load_ob_from_swap(struct object *ob)
  {
!     extern int errno;
!     int l, i, size;
!     char *vars;
      int num_var;
!     struct svalue *baddress;
!     
  
      if (!(ob->flags & O_SWAPPED))
  	fatal("Swapping in not swapped out object!\n");
--- 620,628 ----
  void
  load_ob_from_swap(struct object *ob)
  {
!     int i, size;
      int num_var;
!     struct buffer *buf;
  
      if (!(ob->flags & O_SWAPPED))
  	fatal("Swapping in not swapped out object!\n");
***************
*** 758,770 ****
  	    ob->prog->num_variables + 1) * sizeof(struct svalue);
  
      ob->variables = (struct svalue *)xalloc(size);
!     start_read(&ob->swap_num);
      
      for (i = 0; i < num_var; i++)
! 	unswap_svalue(&ob->variables[i]);
!     if (end_read())
! 	debug_message("Object \"%s\"\n", ob->name);
!     delete_block(&ob->swap_num);
  
      ob->flags &= ~O_SWAPPED;
      obj_bytes_swapped -= size;
--- 636,646 ----
  	    ob->prog->num_variables + 1) * sizeof(struct svalue);
  
      ob->variables = (struct svalue *)xalloc(size);
!     buf = start_read(ob->swap_num);
      
      for (i = 0; i < num_var; i++)
! 	unswap_svalue(buf, &ob->variables[i]);
!     end_read(buf);
  
      ob->flags &= ~O_SWAPPED;
      obj_bytes_swapped -= size;
***************
*** 776,799 ****
      ob->variables++;
  }
  
- void 
- remove_swap_file(struct object *ob)
- {
- }
- 
- /*
-  * This one is called at shutdown. Remove the swap file.
-  */
- 
- void 
- unlink_swap_file() 
- {
-     if (!swap_file)
- 	return;
-     fclose(swap_file);
-     unlink(file);
- }
- 
  static int
  swap_segment(char *hdr, struct segment_desc *seg)
  {
--- 652,657 ----
***************
*** 802,810 ****
      int i;
  
      if (*(int *)(hdr + seg->swap_idx_offset) == 0)
! 	swap_block((int *)(hdr + seg->swap_idx_offset),
! 		   block,
! 		   *(int *)(hdr + seg->size_offset));
  
      if (*(int *)(hdr + seg->swap_idx_offset) == -1)
  	fatal("error while swapping segment.\n");
--- 660,672 ----
      int i;
  
      if (*(int *)(hdr + seg->swap_idx_offset) == 0)
!     {
! 	struct buffer *buf;
! 
! 	buf = start_write((int *)(hdr + seg->swap_idx_offset));
! 	swap_write(buf, block, *(int *)(hdr + seg->size_offset));
! 	end_write(buf);
!     }
  
      if (*(int *)(hdr + seg->swap_idx_offset) == -1)
  	fatal("error while swapping segment.\n");
***************
*** 825,834 ****
      struct section_desc *sect;
      char *block;
      int i;
  
!     read_block((int *)(hdr + seg->swap_idx_offset),
! 	       &block,
! 	       *(int *)(hdr + seg->size_offset));
      for (sect = seg->sections, i = 0; sect->section != -1; sect++, i++)
  	if (sect->ptr_offset != -1)
  	    *(char **)(hdr + sect->ptr_offset) =
--- 687,699 ----
      struct section_desc *sect;
      char *block;
      int i;
+     struct buffer *buf;
  
!     block = xalloc(*(int *)(hdr + seg->size_offset));
!     buf = start_read(*(int *)(hdr + seg->swap_idx_offset));
!     swap_read(buf, block, *(int *)(hdr + seg->size_offset));
!     end_read(buf);
! 
      for (sect = seg->sections, i = 0; sect->section != -1; sect++, i++)
  	if (sect->ptr_offset != -1)
  	    *(char **)(hdr + sect->ptr_offset) =
***************
*** 853,895 ****
  
      if (!prog->line_numbers)
  	return 1;
- #ifdef NEW_SWAP
      size = swap_segment((char *)prog, segm_desc + S_DBG);
      total_bytes_swapped += size;
      total_lineno_swapped += size;
      num_swapped++;
      return 1;
- #else
-     size = align(prog->sizeof_line_numbers) +
- 	align(prog->num_relocs * sizeof(struct reloc));
- 
-     if (prog->swap_lineno_index > 0 || !prog->line_numbers) 
-     {
-         if (prog->line_numbers)
-         {
- 	    total_bytes_swapped += size;
- 	    total_lineno_swapped += size;
- 	    num_swapped++;
-             free((char*)prog->line_numbers);
- 	    prog->reloc = 0;
- 	    prog->line_numbers = 0;
- 	}
- 	return 1;
-     }
- 
-     
-     swap_block(&prog->swap_lineno_index, (char *)prog->line_numbers, size);
-     if (prog->swap_lineno_index == -1)
- 	return;
-     
-     total_lineno_swapped += size;
-     total_bytes_swapped += size;
-     num_swapped++;
-     free((char*)prog->line_numbers);
-     prog->line_numbers = 0;
-     prog->reloc = 0;
-     return 1;
- #endif
  }
  
  /*
--- 718,728 ----
***************
*** 898,923 ****
  void 
  load_lineno_from_swap(struct program *prog)
  {
-     extern int errno;
-     extern int s_flag;
      int size;
      
      if (prog->line_numbers)
  	return;
-     if (s_flag)
- 	num_fileread++;
  
      if (prog->swap_lineno_index == 0)
  	fatal("Loading not swapped linenoinfo.\n");
! #ifdef NEW_SWAP
      size = unswap_segment((char *)prog, segm_desc + S_DBG);
- #else
-     size = align(prog->sizeof_line_numbers) +
- 	align(prog->num_relocs * sizeof(struct reloc));
-     
-     read_block(&prog->swap_lineno_index, (char **)&prog->line_numbers, size);
-     prog->reloc = (struct reloc *)((char *)prog->line_numbers + prog->sizeof_line_numbers);
- #endif
      total_lineno_swapped -= size;
      total_bytes_swapped -= size;
      num_swapped--;
--- 731,745 ----
  void 
  load_lineno_from_swap(struct program *prog)
  {
      int size;
      
      if (prog->line_numbers)
  	return;
  
      if (prog->swap_lineno_index == 0)
  	fatal("Loading not swapped linenoinfo.\n");
! 
      size = unswap_segment((char *)prog, segm_desc + S_DBG);
      total_lineno_swapped -= size;
      total_bytes_swapped -= size;
      num_swapped--;
***************
*** 927,985 ****
  static int
  swap_program(struct program *prog)
  {
-     extern int errno;
      int size;
  
      if (prog->line_numbers)
  	swap_lineno(prog);
      if (prog->program == (char *)0)
! 	return;
      if (d_flag & DEBUG_SWAP) { /* marion */
  	debug_message("Swap program %s (ref %d)\n", prog->name, prog->ref);
      }
! #ifdef NEW_SWAP
      size = swap_segment((char *)prog, segm_desc + S_EXEC);
- #else
-     size = align(prog->program_size) +
- 	align(prog->num_strings * sizeof(char *));
-     if (prog->swap_num == 0)
- 	{
- 	    swap_block(&prog->swap_num, prog->program, size);
- 	    if (prog->swap_num == -1)
- 		fatal("error while swapping program %d.\n", prog->name);
- 	}
-     free(prog->program);
-     prog->program = (char *)-1;
-     prog->strings = (char **)-1;
- #endif
      total_program_size -= size;
      program_bytes_swapped += size;
      programs_swapped++;
      swap_out_prog++;
      total_bytes_swapped += size;
      num_swapped++;
!     return 0;
  }
  
  void
  load_prog_from_swap(struct program *prog)
  {
!     extern int errno;
!     int l, size;
      
      if (prog->program != (char *)0 || prog->swap_num == -1)
  	return;
      if (d_flag & DEBUG_SWAP) { /* marion */
  	debug_message("Unswap program %s (ref %d)\n", prog->name, prog->ref);
      }
! #ifdef NEW_SWAP
      size = unswap_segment((char *)prog, segm_desc + S_EXEC);
- #else
-     size = align(prog->program_size) +
- 	align(prog->num_strings * sizeof(char *));
-     read_block(&prog->swap_num, &prog->program, size);
-     prog->strings = (char **)(prog->program + align(prog->program_size));
- #endif
      swap_in_prog++;
      total_program_size += size;
      program_bytes_swapped -= size;
--- 749,786 ----
  static int
  swap_program(struct program *prog)
  {
      int size;
  
      if (prog->line_numbers)
  	swap_lineno(prog);
      if (prog->program == (char *)0)
! 	return 0;
      if (d_flag & DEBUG_SWAP) { /* marion */
  	debug_message("Swap program %s (ref %d)\n", prog->name, prog->ref);
      }
! 
      size = swap_segment((char *)prog, segm_desc + S_EXEC);
      total_program_size -= size;
      program_bytes_swapped += size;
      programs_swapped++;
      swap_out_prog++;
      total_bytes_swapped += size;
      num_swapped++;
!     return 1;
  }
  
  void
  load_prog_from_swap(struct program *prog)
  {
!     int size;
      
      if (prog->program != (char *)0 || prog->swap_num == -1)
  	return;
      if (d_flag & DEBUG_SWAP) { /* marion */
  	debug_message("Unswap program %s (ref %d)\n", prog->name, prog->ref);
      }
! 
      size = unswap_segment((char *)prog, segm_desc + S_EXEC);
      swap_in_prog++;
      total_program_size += size;
      program_bytes_swapped -= size;
***************
*** 995,1001 ****
      if (ob->flags & O_SWAPPED)
  	load_ob_from_swap(ob);
      if (ob->swap_num > 0)
! 	delete_block(&ob->swap_num);
      return;
  }
  
--- 796,805 ----
      if (ob->flags & O_SWAPPED)
  	load_ob_from_swap(ob);
      if (ob->swap_num > 0)
!     {
! 	free_swap(ob->swap_num);
! 	ob->swap_num = 0;
!     }
      return;
  }
  
***************
*** 1004,1028 ****
  {
      
      if (prog->swap_num > 0)
! 	{
! 	    if (prog->program == (char *)0)
! 		load_prog_from_swap(prog);
! 	    
! 	    delete_block(&prog->swap_num);
! 	}
      if (prog->swap_lineno_index > 0)
! 	{
! 	    if (prog->line_numbers == 0)
! 		load_lineno_from_swap(prog);
! 	    delete_block(&prog->swap_lineno_index);
! 	}
      
      return;
  }
  
  
  void
! try_to_swap(int force)
  {
      int swap_time;
      
--- 808,832 ----
  {
      
      if (prog->swap_num > 0)
!     {
! 	if (prog->program == (char *)0)
! 	    load_prog_from_swap(prog);
! 	
! 	free_swap(prog->swap_num);
! 	prog->swap_num = 0;
!     }
      if (prog->swap_lineno_index > 0)
!     {
! 	free_swap(prog->swap_lineno_index);
! 	prog->swap_lineno_index = 0;
!     }
      
      return;
  }
  
  
  void
! try_to_swap(volatile int *interupted)
  {
      int swap_time;
      
***************
*** 1046,1053 ****
  		swap_object(swap_ob);
  		swap_ob = swap_ob->prev_all;
  	    }
! 	    if (!force && interupted)
  		return;
  	}	
-     move_block(force);
  }
--- 850,856 ----
  		swap_object(swap_ob);
  		swap_ob = swap_ob->prev_all;
  	    }
! 	    if (*interupted)
  		return;
  	}	
  }