/*************************************************
 *    Command for MS-DOS : mosmore.c 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 <pad.h>



void _fastcall _near help(void)
{
	cputs("Command for MS-DOS : mosmore 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("1        強制中断\x0d\x0a");

	exit(0);
}



void _cdecl main(int argc,char **argv)
{
	int buff;
	int x=0,y=0;
	int i;

	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("-- mouse more --");
			while(	epad_check_trig(pad_get_stat(PAD_PORT_1),PAD_A) || 
					epad_check_trig(pad_get_stat(PAD_PORT_2),PAD_A));
			for(;;) {
				if(	epad_check_trig(pad_get_stat(PAD_PORT_1),PAD_A) ||
					epad_check_trig(pad_get_stat(PAD_PORT_2),PAD_A)) break;
				if(	epad_check_trig(pad_get_stat(PAD_PORT_1),PAD_B) ||
					epad_check_trig(pad_get_stat(PAD_PORT_2),PAD_B)) exit(1);
			}
			cputs("\x0d\x0a\x0d\x0a");
			y=0;
		}
	} while(!feof(stdin));

	exit(0);
}
