// dll_dll.cpp: определяет точку входа для консольного приложения.
//

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <direct.h> // _getcwd
#include <io.h>

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

#include <math.h>

int _tmain(int argc, _TCHAR* argv[])
{
  /*unsigned long Kernel32Addr;      // kernel32.dll address
  unsigned long ExitProcessAddr;   // ExitProcess address
  unsigned long WinExecAddr;       // WinExec address

  Kernel32Addr = (unsigned long)GetModuleHandle("kernel32.dll");
  printf("KERNEL32 address in memory: 0x%08p\n", Kernel32Addr);

  ExitProcessAddr = (unsigned long)GetProcAddress((HMODULE)Kernel32Addr, "ExitProcess");
  printf("ExitProcess address in memory is: 0x%08p\n", ExitProcessAddr);

  WinExecAddr = (unsigned long)GetProcAddress((HMODULE)Kernel32Addr, "WinExec");
  printf("WinExec address in memory is: 0x%08p\n", WinExecAddr);*/

	//C:\Games\VF_Project\Logs
	//TimerGetElapsed[11].txt
	//TimerGetElapsed[10].txt

	char FullPath[100];
	char Path2[100];
	char szBuffer[100];
	char szBuffer2[100];
	int vLen;
	FILE * pFile;
	FILE * pFile2;
	char FullPath2[100];
	int vSize;
	int vSize2;
	int vIndex1;
	int vIndex2;
	int vIndex12;
	int vIndex22;
	int vvl;
	sprintf(Path2,"%s\0","C:\\Games\\VF_Project\\Logs");
	sprintf(FullPath,"%s\\TimerGetElapsed[%d].txt",Path2,10);
	sprintf(FullPath2,"%s\\TimerGetElapsed[%d].txt",Path2,11);
	pFile = fopen(FullPath,"rb");// открываем файл
	if (pFile==NULL)
		return 0;
	pFile2 = fopen(FullPath2,"rb");// открываем файл
	if (pFile2==NULL)
		return 0;

	ZeroMemory(&szBuffer,sizeof(szBuffer));
	ZeroMemory(&szBuffer2,sizeof(szBuffer2));
	vSize = filelength(fileno(pFile));
	vSize2 = filelength(fileno(pFile2));
	if (vSize > vSize2)
	{
		vSize = vSize2;
	}
	char * buffer = (char*) malloc(sizeof(char) * vSize); // выделить память для хранения содержимого файла
	char * buffer2 = (char*) malloc(sizeof(char) * vSize); // выделить память для хранения содержимого файла

	size_t result = fread(buffer, 1, vSize, pFile);       // считываем файл в буфер
	size_t result2 = fread(buffer2, 1, vSize, pFile2);       // считываем файл в буфер
	
	fclose(pFile);
	fclose(pFile2);
	vIndex1 = -1;
	vIndex2 = -1;

	int vvu;
	for (int vvi = 0; vvi < vSize; vvi++)
	{
		szBuffer[0] = buffer[vvi];
		szBuffer2[0] = buffer2[vvi];
		if (szBuffer[0] != szBuffer2[0])
		{
			vIndex1 = -1;
			vIndex12 = -1;
			for (int vvj = vvi; vvj >= 0; vvj--)
			{
				szBuffer[0] = buffer[vvj];
				if (szBuffer[0] == 0 || szBuffer[0] == '\n' || szBuffer[0] == 0xd || szBuffer[0] == 0xe)
				{
					vvl = 0;
					vvu = 0;
					for (int vvz = vIndex1; vvz < vSize; vvz++)
					{
						szBuffer[vvl] = buffer[vvz];
						vvl++;
						if (buffer[vvz] == 0 || buffer[vvz] == '\n' || buffer[vvz] == 0xd || buffer[vvz] == 0xe)
						{
							vvu++;
							if (vvu > 2)
							{
								szBuffer[vvl] = 0; 
								goto m1;
							}
						}
						vIndex12 = vvz;
					}
				}
				vIndex1 = vvj;
			}
m1:
			vIndex2 = -1;
			vIndex22 = -1;
			for (int vvj = vvi; vvj >= 0; vvj--)
			{
				szBuffer2[0] = buffer2[vvj];
				if (szBuffer2[0] == 0 || szBuffer2[0] == '\n' || szBuffer2[0] == 0xd || szBuffer2[0] == 0xe)
				{
					vvl = 0;
					vvu = 0;
					for (int vvz = vIndex2; vvz < vSize; vvz++)
					{
						szBuffer2[vvl] = buffer2[vvz];
						vvl++;
						if (buffer2[vvz] == 0 || buffer2[vvz] == '\n' || buffer2[vvz] == 0xd || buffer2[vvz] == 0xe)
						{
							vvu++;
							if (vvu > 2)
							{
								szBuffer2[vvl] = 0; 
								goto m2;
							}
						}
						vIndex22 = vvz;
					}
				}
				vIndex2 = vvj;
			}
m2:
			break;
		}
	}
	free(buffer);
	free(buffer2);
	if (vIndex1 == -1 || vIndex2 == -1)
	{
		sprintf(szBuffer,"%s\0","NO");
		sprintf(szBuffer2,"%s\0","NO");
	}
	printf("%s\n",szBuffer);
	printf("%s\n",szBuffer2);
  getchar();
  return 0;
}
