/* spscan.c by Michael Hanson */
/* you may use this, but not for profit, and give me credit */ 
/* remove trailing blanks from stdin, write to stdout */
#include "stdio.h"

#define MAXCH 100
#define SPACE ' '
#define CR '\r'

main()
{
	char lin[MAXCH];
	int err,ind,crf;


	if(ver() < 0x200){
		error("wrong DOS version",1);
#asm
	db 'by Michael Hanson v1.0',1ah
#	
	}
	while((err = fgetlin(STDIN,lin,MAXCH)) != EOF){
		crf = FALSE;
		for(ind = strlen(lin) - 1 ; (lin[ind] == SPACE || lin[ind] == CR) 
			&& ind > 0 ; --ind)
			if(lin[ind] == CR)
				crf=TRUE; /* if ended with a cr, then be sure to output it */
		if(crf == TRUE)
			lin[++ind]=CR;
		lin[++ind] = EOS;
		fputlin(STDOUT,lin);
		}
}	

fgetlin(hdl, s, lim)   /* get line into s, return length */
FILE hdl;
char s[];
int lim;
{
	int c,i;

	for (i=0;i<lim-1 && (c=getc(hdl)) != EOF && c!='\n'; ++i)
		s[i] = c;
	s[i] = '\0';
	if (c == EOF && i == 0) i = EOF;
	return(i);
}

fputlin(hdl, s)
FILE hdl;
char s[];
{
	int i,c;

	for (i=0; s[i] != EOS ; i++)
		if ((c = putc(s[i],hdl)) == ERR) 
			break;
	putc('\n',hdl);
	if( c == ERR)
		return(c);
	else
		return(i);
}
#include "filp.c"
#include "version.c"
#include "err.c"
