#include <stdio.h>
#include <conio.h>
#include <string.h>

#define MAX_LINE_SIZE     255


static char buffer[MAX_LINE_SIZE+1]; //buffer for read lines

int Result=1;

static char *read( void )
//read a line from stdin in the buffer
{
  return fgets( buffer, MAX_LINE_SIZE, stdin );
}


static int write( char *l )
//write string to stdout
{
  return fputs( l, stdout );
}


void main( void )
{
  char msg[256], *b, *z;

  if ((read()==NULL)||(strstr(buffer,"Turbo Assembler" )!=buffer))
  {// Turbo Assembler not recognized -- exit with error code =3
	do
		write(buffer);
	while( read() != NULL );
	return;
  }

// Turbo Assembler recognized -- translate to log format
  read();
  read(); //skip copyright messages
  while( read() != NULL )
  {
	if ((*buffer==0)||(*buffer=='\n')) continue;
	if (strstr(buffer,"Error messages:")!=NULL)
		{while( read() != NULL );
		return;};
	if (!strcmp(buffer,"\n\r"))
		continue;
	if((strstr(buffer,"**Fatal**")!=NULL)||(strstr(buffer,"**Error**")!=NULL)||(strstr(buffer,"*Warning*")!=NULL))
	{
	  int flag=0;
	  int v;
	  if( ( z = strchr( buffer, '(' ) ) == NULL ) flag=1;
	  b = buffer + 10;
	  *z = 0;
	  if (strstr(buffer,"*Warning*"))
		 {Result=1; strcpy(msg,"Пpедупpеждение ");
		 v=15;}
	  else
		  {strcpy(msg,"Ошибка ");Result=2;v=7;};
	  if (!flag)
		  {strcat(msg,b);
		  strcat(msg," ");
		  b = z+1;
		  if( ( z = strchr( b, ')' ) ) != NULL );
			{*z=0;
			  strcat( msg, b );
			  strcat( msg, ": " );
			  strupr(z+2);
			  strcat( msg, z + 2 );};
			};
	  if (flag)
		strcpy(msg+v,buffer+10);
	  msg[strlen(msg)-1]=0;
	  if (Result==2)
		  {int i=strlen(msg);
		 msg[i]='\r';
		 msg[i+1]='\0';
		  write( msg );
		  }
	  else
		  {int i=strlen(msg);
		  msg[i]='\n';
		  msg[i+1]='\r';
		 msg[i+2]='\0';
		  cputs(msg);};
	}
	else
	{
	not_recognized:
	  write( buffer ); //message not recognized -- write as is
	}
  }
}
