/* (c) Copyright 1987 Michael Goetz								*/
/*																			*/
/*				File:		  	write										*/
/*				Returns:	  	void										*/
/*				Parameters:	 int iokey [2]							*/
/*								 char *ztext							*/
/*																			*/

#include <string.h>
#include <stdio.h>

#include "advm.h"
#include "units.h"
#include "doubls.h"
#include "txtbuf.h"
#include "txtlen.h"
#include "snapit.h"
#include "puttxt.h"



void write_text (iokey, ztext)
int iokey[2];
char *ztext;

{
	int l,i;
	int pad = 0;

	if (ztext[0] != '*' && strncmp(ztext, ">$<", 3) != 0)
		{
		if ((l = strlen(ztext)) > 72)
			{
			snapit();
			printf("--String too long.\n");
			}
		k1[kptr] = iokey[0];
		k2[kptr] = iokey[1];
		krec[kptr] = record;
		kbyte[kptr] = bptr+1;
		if (++kptr == 18)
			{
			if (fwrite((char *)k1,1,sizeof(k1),textkeyfi) != sizeof(k1) ||
				 fwrite((char *)k2,1,sizeof(k2),textkeyfi) != sizeof(k2) ||
				 fwrite((char *)krec,1,sizeof(krec),textkeyfi) != sizeof(krec) ||
				 fwrite(kbyte,1,sizeof(kbyte),textkeyfi) != sizeof(kbyte) ||
					/* write out 0x0000 to be compatible with CPM 128 byte sectors */
				 fwrite((char *)&pad,2,1,textkeyfi) != 1)
				{
				printf ("\n\n**** Output error while writing text keys\n\n");
				exit(1);
				}
			else
				kptr = 0;
			}
		for (; *ztext; ztext++)
			puttxt (*ztext);
		puttxt(0);
		texthw += l+1;
		textdw++;
		}
	/* 20 */
	outkey = iokey[1] + (iokey[0] / 1000.0);
}
