/************************************************
 *      Command for MS-DOS : more ver. 1.0      *
 *           Program made by  K,Ajima           *
 *   Copyright AJIYAN SOFT L.T.D.    1993,7,2   *
 ************************************************/



#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <bios.h>



void _fastcall _near help(void)
{
	cputs("Command for MS-DOS : more ver. 1.0\x0d\x0a");
	cputs("Program made by K,Ajima\x0d\x0a");
	cputs("Copyright AJIYAN SOFT L.T.D.   1993,7,2\x0d\x0a\x0d\x0a");

	cputs("Syntax : <ms-dos command> | more\x0d\x0a");
	cputs("         more < <file name>\x0d\x0a\x0d\x0a");

	cputs("ERRORLEVEL\x0d\x0a");
	cputs("0        正常終了\x0d\x0a");
	cputs("3        ctrl + c 発生\x0d\x0a");
	exit(0);
}



void _cdecl main(int argc,char **argv)
{
	int buff;
	int x=0,y=0;
	int i;
	struct kbd_info data;

	if(argc==2 && !strcmp(argv[1],"/?")) help();

	do {
		if((buff=getc(stdin))==-1) break;
		if(buff==0x0a) {
			cputs("\x0d\x0a");
			x=0; y++;
		}
		else {
			if(buff==0x09) {
				for(i=(x&7);i<8;i++)
					putch(' ');
				x|=7;
			}
			else putch(buff);
			if(++x==80) {
				x=0; y++;
			}
		}
		if(y==23) {
			cputs("-- more --");
			data.flag=0;
			_bios_keybrd(_KBD_CLEARBUFF,&data);
			data.flag=0;
			_bios_keybrd(_KBD_READ,&data);
			if(data.data==3) exit(3);
			cputs("\x0d\x0a\x0d\x0a");
			y=0;
		}
	} while(!feof(stdin));

	exit(0);
}
