#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 Link" )!=buffer))
  {// Turbo Assembler not recognized -- exit with error code =3
	do
		write(buffer);
	while( read() != NULL );
	return;
  }

// Turbo Assembler recognized -- translate to log format
  while( read() != NULL )
  {
	if (!strcmp(buffer,"\n\r"))
		continue;
	if (!strcmp(buffer,"Warning: No stack\n"))
		continue;
	if((strstr(buffer,"Fatal:")!=NULL)||(strstr(buffer,"Error:")!=NULL)||(strstr(buffer,"Warning:")!=NULL))
	{
	  int v,vv;
//	  *z = 0;
	  if (strstr(buffer,"Warning:"))
		 {Result=1; strcpy(msg,"Пpедупpеждение ");
		 vv=8;
		 v=15;}
	  else
		  {strcpy(msg,"Ошибка ");Result=2;v=7;vv=6;};
	  b = buffer + vv;
	  char *c;
	  if (c=strstr(b,"in module "))
		{*c='\0';
		 strupr(c+10);
		 strcat(msg,c+10);
		 msg[strlen(msg)-1]=0;
		 strcat(msg," :");
		 strcat(msg,b);
		 }
	  else
		{strcat(msg," :");
		strcat(msg,b);
		msg[strlen(msg)-1]=0;};
	  if (Result==2)
		  {int i=strlen(msg);
//		  msg[i]='\n';
		 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
	{
	  write( buffer ); //message not recognized -- write as is
	}
  }
}
