/*
 * MG_UNPACK.pgc - mg 모듈 서비스 MG_UNPACK (one service = one file).
 * Split out of the former inline mg_svr.pgc; runs on the caller's XA
 * branch (no EXEC SQL CONNECT). Advertised by mg_svr at tpsvrinit.
 */
#include "MG_UNPACK.h"

/* 23. MG_UNPACK - 고정길이 전문 해체 (순수 계산). */
void MG_UNPACK(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char raw[512], mti[8], proc[8];
    long amount, n;
    gets_(b, T_STR3, raw, sizeof(raw));
    n = (long)strlen(raw);
    memset(mti, 0, sizeof(mti)); memset(proc, 0, sizeof(proc));
    if (n >= 4)  strncpy(mti, raw, 4);       else strcpy(mti, "0000");
    if (n >= 10) strncpy(proc, raw + 4, 6);  else strcpy(proc, "000000");
    amount = (n >= 22) ? atol(raw + 10) : 0;
    sets_(b, T_STR1, mti);
    sets_(b, T_STR4, proc);
    setl(b, T_AMOUNT, amount);
    OK(b);
}
