/*
 *========================================================================
 *
 *   시스템명 : 녹색교통 시스템
 *   파 일 명 : make_basic.c
 *   작 성 자 : 조보용 (baarong@neighbor21.co.kr)
 *   작 성 일 : 2019.08.30
 *   수 정 일 :
 *   설    명 :
 *
 *========================================================================
*/

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <iconv.h>

#include "bas_tbl.h"
#include "dir_path.h"
#include "file_no.h"
#include "file_lb.h"
#include "lb_func_list.h"
#include "func_list.h"
#include "util.h"

#define _INCTEST_ 1
/*
 *========================================================================
 *
 *   함 수 명 : make_basic
 *   작 성 자 : 조보용 (baarong@neighbor21.co.kr)
 *   작 성 일 : 2019.08.13
 *   수 정 일 :
 *   설    명 : 기초(정수)테이블 파일 생성
 *
 *========================================================================
*/
int make_basic(char *data)
{
    char path[128], spath[128], tpath[128];
#ifdef _INCTEST_
    char cpath[128];
#endif
	char mkData[MAX_STRING_SIZE*20];
    int  isfd, isrc, errflg = 0, nResult = 0;
	size_t in_size;
	size_t out_size;
	size_t out_buf_left;
	char   orgData[MAX_STRING_SIZE*20];
	char   szCarNo[255+1];
	char* in_buf;
	char* out_buf;

	memset(mkData, 0x00, sizeof(mkData));
	snprintf(mkData, strlen(data)+1, "%s", data);

//printf("make_befmst [%d][%s][%d]\n", rcv, data, strlen(data));
//printf("make_befmst 2[%s][%d]\n", mkData, strlen(mkData));

	//WriteLog(LogType_StandardOut, LogLevel_Info, "DATA[%s][%d]\n", mkData, strlen(mkData));
    sprintf(tpath, "%s/%s/BASICTBL01_O", DIR_TCS, DIR_BASEINFO);
    unlink(tpath);

    sprintf(path, "%s/%s/BASICTBL01", DIR_TCS, DIR_BASEINFO);
    //lb_rename(path, tpath);
	sprintf(spath, "%s/%s/BASICTBL01_S", DIR_TCS, DIR_BASEINFO);
	unlink(spath);
#ifdef _INCTEST_
    // INCODING 확인 테스트
    sprintf(cpath, "%s/%s/BASICTBL01_C", DIR_TCS, DIR_BASEINFO);
    isfd=lb_build(cpath, FINOUT+FC_EXCLLOCK);
    if(isfd < 0)
    {
        WriteLog(LogType_StandardOut, LogLevel_Info, "WRKERTBL:파일생성 실패[%d]\n", isfd);
        isrc = -1;
        return(isrc);
    }
#endif
    isrc = Write_File_Char(mkData, strlen(mkData), spath);
	if(isrc == 0)
	{
		WriteLog(LogType_StandardOut, LogLevel_Info, "BASIC DATA CREATE[%d]\n", isrc);
	}

	//lb_rename(spath, path);
#if 1
	struct basic_tbl bas_tbl, bas_tbl_f;
	FILE *fp = NULL;
	int i = 0;
	fp = fopen(spath, "r+");
	WriteLog(LogType_StandardOut, LogLevel_Info, "TEST 기초파일 읽기 시작\n");
	if(fp == NULL)
	{
		WriteLog(LogType_StandardOut, LogLevel_Info, "TEST 기초파일 읽기 파일열기 실패\n");
	}else
	{
#ifdef _INCTEST_
        iconv_t ic = iconv_open("EUC-KR", "UTF-8");
        if(ic == (iconv_t) -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "###### Not Supported ICONV Code ###### \n");
        }
#endif
		fread(&bas_tbl, sizeof(struct basic_tbl), 1, fp);
#if 0
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
		memset(bas_tbl_f, 0x20, sizeof(bas_tbl_f));
		memcpy(&bas_tbl_f, &bas_tbl, sizeof(struct basic_tbl));
        snprintf(orgData, strlen(bas_tbl.plz_nm)+1, "%s", bas_tbl.plz_nm);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.plz_nm, "%.14s%c", mkData, '\0');
#endif

#ifdef _INCTEST_
        memset(&bas_tbl_f, 0x20, sizeof(bas_tbl_f));
#if 0
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.plz_id)+1, "%s", bas_tbl.plz_id);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.plz_id, "%.2s%c", mkData, '\0');
#endif
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
#if 1
		memcpy(&bas_tbl_f, &bas_tbl, sizeof(struct basic_tbl));
#endif
WriteLog(LogType_StandardOut, LogLevel_Info, "##### T1_PLZ_NM[%.14s]\n", bas_tbl.plz_nm);
        snprintf(orgData, strlen(bas_tbl.plz_nm)+1, "%s", bas_tbl.plz_nm);
WriteLog(LogType_StandardOut, LogLevel_Info, "##### T2_PLZ_NM[%.14s]\n", orgData);
WriteLog(LogType_StandardOut, LogLevel_Info, "##### T2_SIZE[%d]\n", strlen(orgData));

        in_size = strlen(orgData);
        out_size = 10;
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

WriteLog(LogType_StandardOut, LogLevel_Info, "##### T3_PLZ_NM[%.14s]\n", mkData);
WriteLog(LogType_StandardOut, LogLevel_Info, "##### T3_SIZE[%d]\n", strlen(mkData));
        snprintf(bas_tbl_f.plz_nm, strlen(mkData)+1, "%s", mkData);
		//sprintf((char *)bas_tbl_f.plz_nm, "%.14s%c", mkData, '\0');

WriteLog(LogType_StandardOut, LogLevel_Info, "##### PLZ_ID[%.2s]\n", bas_tbl_f.plz_id);
WriteLog(LogType_StandardOut, LogLevel_Info, "##### PLZ_NM[%.14s]\n", bas_tbl_f.plz_nm);
WriteLog(LogType_StandardOut, LogLevel_Info, "------- RVS -------\n");
		for(i = 0; i < 20; i++)
		{
#if 0
        //적용년
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.rvs_tbl_info[i].apl_year)+1, "%s", bas_tbl.rvs_tbl_info[i].apl_year);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.rvs_tbl_info[i].apl_year, "%.4s%c", mkData, '\0');
        //적용월
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.rvs_tbl_info[i].apl_mon)+1, "%s", bas_tbl.rvs_tbl_info[i].apl_mon);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.rvs_tbl_info[i].apl_mon, "%.2s%c", mkData, '\0');
        //적용일
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.rvs_tbl_info[i].apl_day)+1, "%s", bas_tbl.rvs_tbl_info[i].apl_day);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.rvs_tbl_info[i].apl_day, "%.2s%c", mkData, '\0');
        //적용시
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.rvs_tbl_info[i].apl_hr)+1, "%s", bas_tbl.rvs_tbl_info[i].apl_hr);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.rvs_tbl_info[i].apl_hr, "%.2s%c", mkData, '\0');
        //적용분
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.rvs_tbl_info[i].apl_min)+1, "%s", bas_tbl.rvs_tbl_info[i].apl_min);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.rvs_tbl_info[i].apl_min, "%.2s%c", mkData, '\0');
        //수정년
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.rvs_tbl_info[i].modf_year)+1, "%s", bas_tbl.rvs_tbl_info[i].modf_year);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.rvs_tbl_info[i].modf_year, "%.4s%c", mkData, '\0');
        //수정월
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.rvs_tbl_info[i].modf_mon)+1, "%s", bas_tbl.rvs_tbl_info[i].modf_mon);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.rvs_tbl_info[i].modf_mon, "%.2s%c", mkData, '\0');
        //수정일
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.rvs_tbl_info[i].modf_day)+1, "%s", bas_tbl.rvs_tbl_info[i].modf_day);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.rvs_tbl_info[i].modf_day, "%.2s%c", mkData, '\0');
        //수정시
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.rvs_tbl_info[i].modf_hr)+1, "%s", bas_tbl.rvs_tbl_info[i].modf_hr);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.rvs_tbl_info[i].modf_hr, "%.2s%c", mkData, '\0');
        //수정분
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.rvs_tbl_info[i].modf_min)+1, "%s", bas_tbl.rvs_tbl_info[i].modf_min);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.rvs_tbl_info[i].modf_min, "%.2s%c", mkData, '\0');
        //개정번호
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.rvs_tbl_info[i].rvs_no)+1, "%s", bas_tbl.rvs_tbl_info[i].rvs_no);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.rvs_tbl_info[i].rvs_no, "%.2s%c", mkData, '\0');

#endif
WriteLog(LogType_StandardOut, LogLevel_Info, "[%02d] APL_DATE[%.4s%.2s%.2s%.2s%.2s]\n", i, 
		bas_tbl_f.rvs_tbl_info[i].apl_year, bas_tbl_f.rvs_tbl_info[i].apl_mon,
		bas_tbl_f.rvs_tbl_info[i].apl_day, bas_tbl_f.rvs_tbl_info[i].apl_hr, bas_tbl_f.rvs_tbl_info[i].apl_min);
WriteLog(LogType_StandardOut, LogLevel_Info, "[%02d] MODF_DATE[%.4s%.2s%.2s%.2s%.2s]\n", i,
		bas_tbl_f.rvs_tbl_info[i].modf_year, bas_tbl_f.rvs_tbl_info[i].modf_mon,
		bas_tbl_f.rvs_tbl_info[i].modf_day, bas_tbl_f.rvs_tbl_info[i].modf_hr, bas_tbl_f.rvs_tbl_info[i].modf_min);
WriteLog(LogType_StandardOut, LogLevel_Info, "[%02d] RVS_NO[%.2s]\n", i, bas_tbl_f.rvs_tbl_info[i].rvs_no);
		}
WriteLog(LogType_StandardOut, LogLevel_Info, "------- LANE -------\n");
		for(i = 0; i < MAX_LANE; i++)
		{
#if 0
        //물리차로번호
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.lane_info[i].phgc_lane_no)+1, "%s", bas_tbl.lane_info[i].phgc_lane_no);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.lane_info[i].phgc_lane_no, "%.2s%c", mkData, '\0');
        //차로이름
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.lane_info[i].lane_nm)+1, "%s", bas_tbl.lane_info[i].lane_nm);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.lane_info[i].lane_nm, "%.20s%c", mkData, '\0');
        //입출구구분
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.lane_info[i].io_div)+1, "%s", bas_tbl.lane_info[i].io_div);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.lane_info[i].io_div, "%.2s%c", mkData, '\0');
        //IP
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.lane_info[i].ip_addr)+1, "%s", bas_tbl.lane_info[i].ip_addr);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.lane_info[i].ip_addr, "%.16s%c", mkData, '\0');
        //포트
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.lane_info[i].port)+1, "%s", bas_tbl.lane_info[i].port);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.lane_info[i].port, "%.8s%c", mkData, '\0');
        //서브포트1
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.lane_info[i].sub_port1)+1, "%s", bas_tbl.lane_info[i].sub_port1);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.lane_info[i].sub_port1, "%.8s%c", mkData, '\0');
        //서브포트2
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.lane_info[i].sub_port2)+1, "%s", bas_tbl.lane_info[i].sub_port2);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.lane_info[i].sub_port2, "%.8s%c", mkData, '\0');
#endif
WriteLog(LogType_StandardOut, LogLevel_Info, "[%02d] LANE_NO[%.2s]\n", i, bas_tbl_f.lane_info[i].phgc_lane_no);
WriteLog(LogType_StandardOut, LogLevel_Info, "[%02d] LANE_NM[%.20s]\n", i, bas_tbl_f.lane_info[i].lane_nm);
WriteLog(LogType_StandardOut, LogLevel_Info, "[%02d] IO_DIV[%.2s]\n", i, bas_tbl_f.lane_info[i].io_div);
WriteLog(LogType_StandardOut, LogLevel_Info, "[%02d] IP_ADDR[%.16s]\n", i, bas_tbl_f.lane_info[i].ip_addr);
WriteLog(LogType_StandardOut, LogLevel_Info, "[%02d] PORT[%.8s]\n", i, bas_tbl_f.lane_info[i].port);
WriteLog(LogType_StandardOut, LogLevel_Info, "[%02d] SUBPORT1[%.8s]\n", i, bas_tbl_f.lane_info[i].sub_port1);
WriteLog(LogType_StandardOut, LogLevel_Info, "[%02d] SUBPORT2[%.8s]\n", i, bas_tbl_f.lane_info[i].sub_port2);
		}
WriteLog(LogType_StandardOut, LogLevel_Info, "------- FARE -------\n");
		for(i = 0; i < 50; i++)
		{
#if 0
        //요금구분
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.fare_info[i].fare_div)+1, "%s", bas_tbl.fare_info[i].fare_div);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.fare_info[i].fare_div, "%.2s%c", mkData, '\0');
        //할인구분
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.fare_info[i].dc_typ)+1, "%s", bas_tbl.fare_info[i].dc_typ);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.fare_info[i].dc_typ, "%.1s%c", mkData, '\0');
        //요금
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.fare_info[i].fare)+1, "%s", bas_tbl.fare_info[i].fare);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.fare_info[i].fare, "%.6s%c", mkData, '\0');
        //시작일
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.fare_info[i].start_dt)+1, "%s", bas_tbl.fare_info[i].start_dt);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.fare_info[i].start_dt, "%.8s%c", mkData, '\0');
        //종료일
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.fare_info[i].end_dt)+1, "%s", bas_tbl.fare_info[i].end_dt);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.fare_info[i].end_dt, "%.8s%c", mkData, '\0');
        //할인율
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.fare_info[i].fare_dc)+1, "%s", bas_tbl.fare_info[i].fare_dc);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.fare_info[i].fare_dc, "%.6s%c", mkData, '\0');
        //과태료
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.fare_info[i].penalty)+1, "%s", bas_tbl.fare_info[i].penalty);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.fare_info[i].penalty, "%.6s%c", mkData, '\0');
#endif
WriteLog(LogType_StandardOut, LogLevel_Info, "[%02d] FARE_DIV[%.2s]\n", i, bas_tbl_f.fare_info[i].fare_div);
WriteLog(LogType_StandardOut, LogLevel_Info, "[%02d] DC[%c]\n", i, bas_tbl_f.fare_info[i].dc_typ);
WriteLog(LogType_StandardOut, LogLevel_Info, "[%02d] FARE[%.6s]\n", i, bas_tbl_f.fare_info[i].fare);
WriteLog(LogType_StandardOut, LogLevel_Info, "[%02d] START_DT[%.8s]\n", i, bas_tbl_f.fare_info[i].start_dt);
WriteLog(LogType_StandardOut, LogLevel_Info, "[%02d] END_DT[%.8s]\n", i, bas_tbl_f.fare_info[i].end_dt);
WriteLog(LogType_StandardOut, LogLevel_Info, "[%02d] FARE_DC[%.6s]\n", i, bas_tbl_f.fare_info[i].fare_dc);
WriteLog(LogType_StandardOut, LogLevel_Info, "[%02d] PENALTY[%.6s]\n", i, bas_tbl_f.fare_info[i].penalty);
		}
WriteLog(LogType_StandardOut, LogLevel_Info, "------- END -------\n");
#if 0
        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.fare_cnt)+1, "%s", bas_tbl.fare_cnt);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.fare_cnt, "%.2s%c", mkData, '\0');

        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.rcv_str_dt)+1, "%s", bas_tbl.rcv_str_dt);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.rcv_str_dt, "%.2s%c", mkData, '\0');

        memset(mkData, 0x00, sizeof(mkData));
		memset(orgData, 0x00, sizeof(orgData));
        snprintf(orgData, strlen(bas_tbl.rcv_end_dt)+1, "%s", bas_tbl.rcv_end_dt);

        in_size = strlen(orgData);
        out_size = sizeof(orgData);
        in_buf = orgData;
        out_buf = mkData;
        out_buf_left = out_size;

        nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);

        if(nResult == -1)
        {
            WriteLog(LogType_StandardOut, LogLevel_Info, "ICONV FAILED [%d][%d]\n", nResult, errno);
        }

		sprintf((char *)bas_tbl_f.rcv_end_dt, "%.2s%c", mkData, '\0');
#endif
WriteLog(LogType_StandardOut, LogLevel_Info, "##### FARE_CNT[%.2s]\n", bas_tbl_f.fare_cnt);
WriteLog(LogType_StandardOut, LogLevel_Info, "##### RCV_STR_DT[%.4s]\n", bas_tbl_f.rcv_str_dt);
WriteLog(LogType_StandardOut, LogLevel_Info, "##### RCV_END_DT[%.4s]\n", bas_tbl_f.rcv_end_dt);

        isrc = lb_writel(isfd, &bas_tbl_f, sizeof(bas_tbl_f));
#endif
	}
    fclose(fp);
	lb_rename(cpath, path);
	lb_close(isfd);
#endif

    return(isrc);
}
