/*
	tab=4;
	ＤＯＳ汎用（だと思う）「ＬＯＧＯＮ」プログラム
											program : Y.Gotoh (Gori)
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>

/* fputs( *str , stderr ) の代わり */
void txt_puts( char *str ){
	do{
		if( *str == '\n' ){
			putch( '\x0d' );
			putch( '\x0a' );
		}
		else	putch( *str );
	}while( *(++str) );
}

int main( int argc , char **argv ){
	char password[9] = "        ";
	char hit[9] = "";
	int i = 0;
	char ch = '';
	union REGS regs;
	
	txt_puts( 	"-< logon >-\n\n" );
	
	if( argc == 2 )	strcpy( password , argv[1] );
	else	strcpy( password , "logon" );
	
	txt_puts( "  PASSWORD  ---> " );
	
	for( i = 0 ; i < 8 ; i++ ){
		while( !kbhit() );
		
		ch = getch();
		if( ch == '\x0d' ){
			hit[i] = '\0';
			break;
		}
		else{
			putch( '*' );
			hit[i] = ch;
		}
	}
	
	txt_puts( "\n\n"  );
	
	strlwr( hit );
	if( !strcmp( password , hit )){
		txt_puts( " いらっしゃいませご主人様\n" );
		exit(0);
	}
	else{
		txt_puts( " あなた私のご主人様じゃありませんね？\n" );
		txt_puts( "     暴走します｡ (~_~)\n" );
		regs.h.ah = 0xff;
		int86( 0xff , &regs , &regs );
		exit(1);
	}
}
