/*
 *========================================================================
 *
 *   시스템명 : 요금징수 시스템
 *   파 일 명 : ft_ptagcng.pc
 *   작 성 자 : 조보용 (catacath@neighbor21.co.kr)
 *   작 성 일 : 2012.10.10
 *   수 정 일 :
 *   설    명 :
 *
 *========================================================================
*/

#include <stdio.h>
#include <stdlib.h>
#ifdef _SQLCA_
#include <sqlca.h>
#endif
#include <unistd.h> 
#include <dirent.h>

#include "pl_chg.h"
#include "chg_struc.h"
#include "ora_sql.h"
#include "file_no.h"
#include "dir_path.h"
#include "file_lb.h"
#include "lb_func_list.h"
#include "func_list.h"

#include "tcs_db_def.h"
static    struct     pl_chg_tbl    pl_chg_tbl_f;
static    int    errflg=0;
char     msg[128];

/*
 *========================================================================
 *
 *   함 수 명 : chng_t2f_plchg
 *   작 성 자 : 조보용 (catacath@neighbor21.co.kr)
 *   작 성 일 : 2012.10.10
 *   수 정 일 :
 *   설    명 : 유효TAG 변경분 (oprc_perd_tag_pl) 테이블을 유효TAG 변경분 파일로 변환처리 한다.
 *
 *========================================================================
*/
int chng_t2f_plchg()
{
    char   path[128], spath[128], tpath[128];
    int    isfd, isrc, ret;
    int    ii, jj, chk_cnt;
    int    size, limit = 0;;
    unsigned char buff[2];
    unsigned char buff2[2];
    char tmp_ali[8];
    char tmp_alli[8];
    FILE *fp;
    FILE *ofp;
	DIR  *rd;
    struct stat file_info;
	struct dirent *dir;

    sprintf(path, "%s/%s/PLTPCARDMST", DIR_TCS, DIR_BASEINFO);
    ofp = fopen(path, "r+");
    sprintf(spath, "%s/FILE/RECV", DIR_TCS);
	if((rd = opendir(spath)) == NULL)
	{
		proc_log("수신폴더 열기 실패");
		return(-1);
	}
	
	while((dir=readdir(rd)) != NULL)
	{
		if(strncmp("WSSF", dir->d_name, 4) == 0)
		{
	        sprintf(spath, "%s/FILE/RECV/%s", DIR_TCS, dir->d_name);
            fp = fopen(spath, "r+");
            
            if(fp == NULL)
            {
                proc_log("후불 PL[WSSF] File Not Found!(%s)\n", spath);
            }
            
            if( 0 > stat(spath, &file_info))
            {
                proc_log("후불 PL[WSSF]\n");
            }else
            {
                size = file_info.st_size;
	        	chk_cnt = 0;
                limit = 30000001;
                for(ii = 0; ii < size; ii++)
                {
                    fseek(fp, ii, SEEK_SET);
                    fread(buff, 1, 1, fp);
                    fseek(ofp, (ii*8)+limit, SEEK_SET);
                    fread(tmp_ali, 1, 8, ofp);
            
                    buff2[0] = strtoul(tmp_ali, NULL, 2);
            
                    if((ret = memcmp(buff, buff2, 1)) < 0)
                    {
                        printf("후불 PL[WSSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                        //break;
                    }
            
	        		chk_cnt++;
                    if(chk_cnt > 7499999)
	        		{
	        			proc_log("후불 PL[WSSF] MAX 검증완료\n");
	        			break;
	        		}
                }
                fclose(fp);
            }
proc_log("후불 PL 완료[%d]", ret);			
		}
		
		if(strncmp("WTSF", dir->d_name, 4) == 0)
		{
            sprintf(spath, "%s/FILE/RECV/%s", DIR_TCS, dir->d_name);
            fp = fopen(spath, "r+");
            
            if(fp == NULL)
            {
                proc_log("신선불 PL[WTSF] File Not Found!(%s)\n", spath);
            }
            
            if( 0 > stat(spath, &file_info))
            {
                proc_log("신선불 PL[WTSF]\n");
            }else
            {
                size = file_info.st_size;
	        	chk_cnt = 0;
                limit = 90000001;
                for(ii = 0; ii < size; ii++)
                {
                    fseek(fp, ii, SEEK_SET);
                    fread(buff, 1, 1, fp);
                    fseek(ofp, (ii*8)+limit, SEEK_SET);
                    fread(tmp_ali, 1, 8, ofp);
            
                    buff2[0] = strtoul(tmp_ali, NULL, 2);
            
                    if((ret = memcmp(buff, buff2, 1)) < 0)
                    {
                        printf("신선불 PL[WTSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                        //break;
                    }
            
	        		chk_cnt++;
                    if(chk_cnt == 3750000)
	        		{
	        			proc_log("신선불 PL[WTSF] MAX 검증완료\n");
	        			break;
	        		}
                }
                fclose(fp);
            }
proc_log("신선불 PL 완료[%d]", ret);
		}

		if(strncmp("WTSF", dir->d_name, 4) == 0)
		{
            sprintf(spath, "%s/FILE/RECV/WXSF0000", DIR_TCS);
            fp = fopen(spath, "r+");
            
            if(fp == NULL)
            {
                proc_log("확장신선불 PL[WXSF] File Not Found!(%s)\n", spath);
            }
            
            if( 0 > stat(spath, &file_info))
	        {
                proc_log("확장신선불 PL[WXSF]\n");
	        }else
	        {
                size = file_info.st_size;
	        	chk_cnt = 0;
                limit = 120000001;
                for(ii = 0; ii < size; ii++)
                {
                    fseek(fp, ii, SEEK_SET);
                    fread(buff, 1, 1, fp);
                    fseek(ofp, (ii*8)+limit, SEEK_SET);
                    fread(tmp_ali, 1, 8, ofp);
            
                    buff2[0] = strtoul(tmp_ali, NULL, 2);
            
                    if((ret = memcmp(buff, buff2, 1)) < 0)
                    {
                        proc_log("확장신선불 PL[WXSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                        //break;
                    }
                
                    chk_cnt++;
                    if(chk_cnt == 2500000) 
	        		{
	        			limit = 170000001;
	        			chk_cnt = 0;
	        		}
            
	        		if(limit == 170000001 && chk_cnt == 1062500)
	        		{
	        			proc_log("확장신선불 PL[WXSF] MAX 검증완료\n");
	        			break;
	        		}
                }
                fclose(fp);
	        }
proc_log("확장신선불 PL 완료[%d]", ret);
		}
	}

    sprintf(spath, "%s/FILE/RECV/WYSF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("확장EB PL[WYSF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("확장EB PL[WYSF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 140000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("확장EB PL[WYSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 2500000)
			{
				proc_log("확장EB PL[WYSF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("확장EB PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/WBSF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("확장조합 PL[WBSF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("확장조합 PL[WBSF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 160000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("확장조합 PL[WBSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

            chk_cnt++;
            if(chk_cnt == 1250000) 
			{
				limit = 178500001;
				chk_cnt = 0;
			}

			if(limit == 178500001 && chk_cnt == 187500)
			{
				proc_log("확장조합 PL[WBSF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("확장조합 PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/WZSF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("확장후불 PL[WZSF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("확장후불 PL[WZSF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 180000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("확장후불 PL[WZSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 7500000)
			{
				proc_log("확장후불 PL[WZSF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("확장후불 PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/VWSF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("추가확장후불 PL[VWSF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("추가확장후불 PL[VWSF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 240000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("추가확장후불 PL[VWSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 2500000)
			{
				proc_log("추가확장후불 PL[VWSF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("추가확장후불 PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/VXSF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("추가확장선불 PL[VXSF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("추가확장선불 PL[VXSF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 260000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("추가확장선불 PL[VXSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 3750000)
			{
				proc_log("추가확장선불 PL[VXSF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("추가확장선불 PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/WASF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("추가확장후불2 PL[WASF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("추가확장후불2 PL[WASF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 340000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("추가확장후불2 PL[WASF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 5000000)
			{
				proc_log("추가확장후불 PL[WASF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("추가확장후불 PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/NVSF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("선불A PL[NVSF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("선불A PL[NVSF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 290000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("선불A PL[NVSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 3750000)
			{
				proc_log("선불A PL[NVSF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("선불A PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/NUSF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("선불B PL[NUSF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("선불B PL[NUSF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 320000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("선불B PL[NUSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 2500000)
			{
				proc_log("선불B PL[NUSF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("선불B PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/NTSF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("후불A PL[NTSF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("후불A PL[NTSF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 380000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("후불A PL[NTSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 6250000)
			{
				proc_log("후불A PL[NTSF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("후불A PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/NSSF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("선불C PL[NSSF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("선불C PL[NSSF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 490000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("선불C PL[NSSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 1250000)
			{
				proc_log("선불C PL[NSSF] MAX 검증완료\n");
				break;
			}
        }
        
        fclose(fp);
	}
proc_log("선불C PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/NRSF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("선불D PL[NRSF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("선불D PL[NRSF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 500000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("선불D PL[NRSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 3750000)
			{
				proc_log("선불D PL[NRSF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("선불D PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/NQSF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("선불E PL[NQSF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("선불E PL[NQSF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 530000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("선불E PL[NQSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 2500000)
			{
				proc_log("선불E PL[NQSF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("선불E PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/NPSF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("선불F PL[NPSF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("선불F PL[NPSF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 560000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("선불F PL[NPSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 3750000)
			{
				proc_log("선불F PL[NPSF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("선불F PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/NOSF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("선불G PL[NOSF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("선불G PL[NOSF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 590000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("선불G PL[NOSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 1250000)
			{
				proc_log("선불G PL[NOSF] MAX 처리완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("선불G PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/BHSF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("후불B PL[BHSF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("후불B PL[BHSF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 430000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("후불B PL[BHSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 7500000)
			{
				proc_log("후불B PL[BHSF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("후불B PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/EPSF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("후불C PL[EPSF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("후불C PL[EPSF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 600000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("후불C PL[EPSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 6250000)
			{
				proc_log("후불C PL[EPSF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("후불C PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/EQSF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("후불D PL[EQSF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("후불D PL[EQSF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 650000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);
       
            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("후불D PL[EQSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 6250000)
			{
				proc_log("후불D PL[EQSF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("후불D PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/HLSF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("선불H PL[HLSF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("선불H PL[HLSF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 550000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("선불H PL[HLSF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 1250000)
			{
				proc_log("선불H PL[HLSF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("선불H PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/V3SF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("후불E PL[V3SF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("후불E PL[V3SF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 700000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("후불E PL[V3SF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 6250000)
			{
				proc_log("후불E PL[V3SF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("후불E PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/V4SF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("후불F PL[V4SF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("후불F PL[V4SF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 750000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("후불F PL[V4SF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 6250000)
			{
				proc_log("후불F PL[V4SF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("후불F PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/V5SF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("선불I PL[V5SF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("선불I PL[V5SF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 800000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("선불I PL[V5SF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 3125000)
			{
				proc_log("선불I PL[V5SF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("선불I PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/V6SF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("선불J PL[V6SF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("선불J PL[V6SF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 825000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("선불J PL[V6SF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            if(chk_cnt == 3750000)
			{
				proc_log("선불J PL[V6SF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("선불J PL 완료[%d]", ret);
    sprintf(spath, "%s/FILE/RECV/V7SF0000", DIR_TCS);
    fp = fopen(spath, "r+");

    if(fp == NULL)
    {
        proc_log("선불K PL[V7SF] File Not Found!(%s)\n", spath);
    }

    if( 0 > stat(spath, &file_info))
	{
        proc_log("선불K PL[V7SF]\n");
	}else
	{
        size = file_info.st_size;
		chk_cnt = 0;
        limit = 855000001;
        for(ii = 0; ii < size; ii++)
        {
            fseek(fp, ii, SEEK_SET);
            fread(buff, 1, 1, fp);
            fseek(ofp, (ii*8)+limit, SEEK_SET);
            fread(tmp_ali, 1, 8, ofp);

            buff2[0] = strtoul(tmp_ali, NULL, 2);

            if((ret = memcmp(buff, buff2, 1)) < 0)
            {
                proc_log("선불K PL[V7SF] Value Fail[%x][%x]\n", buff[0], buff2[0]);
                //break;
            }

			chk_cnt++;
            //if(chk_cnt == 5625000)
			if(chk_cnt == 5624999)
			{
				proc_log("선불K PL[V7SF] MAX 검증완료\n");
				break;
			}
        }
        fclose(fp);
	}
proc_log("선불K PL 완료[%d]", ret);
    ///*------------------------------------------------------*/
    ///* NEW    PTAGCNG_O ==>  PTAGCNGR                   */
    ///*------------------------------------------------------*/
    //sprintf(path, "%s/%s/PTAGCNG_O", DIR_TCS, DIR_BASEINFO);
    //unlink(path);
    //
    //sprintf(spath, "%s/%s/PTAGCNG", DIR_TCS, DIR_BASEINFO);
    //sprintf(tpath, "%s/%s/PTAGCNG_O", DIR_TCS, DIR_BASEINFO);
    //lb_rename(spath, tpath);
    //
    ///*------------------------------------------------------*/
    ///* NEW    PTAGCNG_S ==>  PTAGCNGR                   */
    ///*------------------------------------------------------*/
    //sprintf(path, "%s/%s/PTAGCNG", DIR_TCS, DIR_BASEINFO);
    //unlink(path);
    //
    //sprintf(spath, "%s/%s/PTAGCNG_S", DIR_TCS, DIR_BASEINFO);
    //sprintf(tpath, "%s/%s/PTAGCNG", DIR_TCS, DIR_BASEINFO);
    //lb_rename(spath, tpath);
//    sprintf(cmd, "cp %s %s", spath, tpath);
//    system(cmd);
//    proc_log("%s\n", cmd);

    return(0);
}
