auto: 2026-11-14 13:24 (EOMSANGDON-HOME)
This commit is contained in:
@@ -2,13 +2,16 @@
|
||||
|
||||
근거: 지식DB STmate/old/20_분석 02(QCODE 15필드 CODE·NAME·BQCODE·QTY0~9·IFORM·XCODE) ·
|
||||
28 §2(기본수량변수 ↔ 확장수량변수) · REA 30 quantity_variable_resolution(QTY0~9 직접 · XCODE 이름=값) ·
|
||||
SIxMemo_구조(메모 칸 10바이트 <HII: 태그 · 길이 · 블록번호>).
|
||||
SIxMemo_구조(메모 칸 10바이트 <HII: 태그 · 길이 · 블록번호>) ·
|
||||
REA 35(IFORM = 수량산출서 파일 바이트 VTS·XLS 그대로 · XCODE = 「이름=값」CRLF 글).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import struct
|
||||
|
||||
from qty_sheetfile import kind_of
|
||||
from smt_parser import build_dbf_bytes, parse_dbf_bytes
|
||||
|
||||
MEMO_FIELDS = ("IFORM", "XCODE")
|
||||
@@ -24,7 +27,7 @@ DEFAULT_FIELDS = [
|
||||
]
|
||||
|
||||
|
||||
def _memo_text(hex_ptr: str, smt: bytes) -> str:
|
||||
def _memo_bytes(hex_ptr: str, smt: bytes) -> bytes:
|
||||
raw = bytes.fromhex(hex_ptr or "")
|
||||
if (
|
||||
len(raw) < 10
|
||||
@@ -32,17 +35,21 @@ def _memo_text(hex_ptr: str, smt: bytes) -> str:
|
||||
or smt[8:15] != b"SIxMemo"
|
||||
or not any(b not in (0, 0x20) for b in raw)
|
||||
):
|
||||
return ""
|
||||
return b""
|
||||
_tag, length, block = struct.unpack("<HII", raw[:10])
|
||||
size = struct.unpack("<I", smt[4:8])[0] or 64
|
||||
start = block * size
|
||||
if length <= 0 or start >= len(smt):
|
||||
return ""
|
||||
return smt[start : start + length].rstrip(b"\x00").decode("cp949", "replace")
|
||||
return b""
|
||||
return smt[start : start + length]
|
||||
|
||||
|
||||
def _memo_text(hex_ptr: str, smt: bytes) -> str:
|
||||
return _memo_bytes(hex_ptr, smt).rstrip(b"\x00").decode("cp949", "replace")
|
||||
|
||||
|
||||
def read_qcode(files: dict[str, bytes]) -> dict:
|
||||
"""STC 파일 묶음 → {fields, rows} · 메모 칸(IFORM · XCODE)은 본문 글자로."""
|
||||
"""STC 파일 묶음 → {fields, rows} · XCODE 는 글자 · IFORM 은 파일 바이트(IFORM_B64 · 종류 · 크기)."""
|
||||
dbf = files.get("QCODE.DBF", b"")
|
||||
if len(dbf) < 32:
|
||||
return {"fields": DEFAULT_FIELDS, "rows": [], "present": False}
|
||||
@@ -51,9 +58,15 @@ def read_qcode(files: dict[str, bytes]) -> dict:
|
||||
out = []
|
||||
for r in rows:
|
||||
row = {f["name"]: r.get(f["name"], "") for f in fields}
|
||||
for m in MEMO_FIELDS:
|
||||
if m in row:
|
||||
row[m] = _memo_text(r.get(f"{m}_HEX", ""), smt)
|
||||
if "XCODE" in row:
|
||||
row["XCODE"] = _memo_text(r.get("XCODE_HEX", ""), smt)
|
||||
if "IFORM" in row:
|
||||
# IFORM = 수량산출서 파일(VTS·XLS) 바이트 그대로 — 글자로 풀지 않음
|
||||
data = _memo_bytes(r.get("IFORM_HEX", ""), smt)
|
||||
row["IFORM"] = ""
|
||||
row["IFORM_B64"] = base64.b64encode(data).decode("ascii") if data else ""
|
||||
row["IFORM_KIND"] = kind_of(data)
|
||||
row["IFORM_SIZE"] = len(data)
|
||||
out.append(row)
|
||||
return {
|
||||
"fields": [{k: f[k] for k in ("name", "type", "len", "dec")} for f in fields],
|
||||
@@ -76,8 +89,11 @@ def build_qcode(rows: list[dict], files: dict[str, bytes] | None = None) -> tupl
|
||||
for f in fields:
|
||||
name, val = f["name"], r.get(f["name"], "")
|
||||
if f.get("type") == "M" or name in MEMO_FIELDS:
|
||||
text = str(val or "").replace("\r\n", "\n").replace("\n", "\r\n")
|
||||
data = text.encode("cp949", "replace")
|
||||
if name == "IFORM" and r.get("IFORM_B64"):
|
||||
data = base64.b64decode(r["IFORM_B64"]) # 수량산출서 파일 바이트 그대로
|
||||
else:
|
||||
text = str(val or "").replace("\r\n", "\n").replace("\n", "\r\n")
|
||||
data = text.encode("cp949", "replace")
|
||||
if not data:
|
||||
rec[f"{name}_HEX"] = (b" " * int(f["len"])).hex()
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user