/*Copyright (C) 1992, 1996 by Thomas Glen Smith. All Rights Reserved.*/
/* aplsavf APL2 V1.0.0 *************************************************
* Called from aplsave after the output file has been opened. *
***********************************************************************/
#define INCLUDES STRING+IO+STDIO+TREE
#include "includes.h"
int aplsavf(fp)
int fp; /* file descriptor handle */
{
Savfsub;
extern double fuzz;
extern int indxorg;
extern Treelist treehdr;
Treelist workhdr;
static int version = 1; /* version 1 workspace */
int i,j;
static char eof = '\0';
i = write(fp,&version,sizeof(version)); /* write version */
if (i != sizeof(int)) return(103); /* bad file */
i = write(fp,&fuzz,sizeof(fuzz));
i = write(fp,&indxorg,sizeof(indxorg));
for (workhdr = treehdr; workhdr->treenext != NULL;
workhdr = workhdr->treenext); /* save only top of stack */
savfsub(fp,workhdr->avlhdr); /* pass top of tree */
i = write(fp,&eof,1); /* indicate end of tree */
if (i != 1) return(103); /* bad file */
return(0); /* ok */
}