94400d50d4
作为子目录纳入系统,与核心测试管道协同 Co-Authored-By: Claude <noreply@anthropic.com>
71 lines
2.6 KiB
Markdown
71 lines
2.6 KiB
Markdown
# 29-ascii-ebcdic: ASCII to EBCDIC Encoding Conversion
|
|
|
|
## 电信业务场景
|
|
|
|
ASCII→EBCDIC主机编码转换。通过内建转换表将ASCII编码的CDR数据转换为EBCDIC编码,用于与大型主机系统交换数据。
|
|
|
|
## Description
|
|
|
|
Reads an ASCII-encoded sequential file and converts each byte to its
|
|
EBCDIC equivalent using an internal conversion table defined via
|
|
REDEFINES. The output file contains the EBCDIC-encoded data.
|
|
|
|
**Note:** GnuCOBOL internally uses ASCII encoding. This program
|
|
demonstrates a manual encoding conversion algorithm for scenarios
|
|
where EBCDIC output is required for legacy system compatibility.
|
|
|
|
## Conversion Table
|
|
|
|
The 128-entry ASCII-to-EBCDIC table is initialized from REDEFINES
|
|
data at program start. It covers:
|
|
|
|
- Control characters (X'00'-X'3F') mapped to their EBCDIC equivalents
|
|
- Printable characters (X'20'-X'7F') mapped per standard conversion
|
|
- Characters >= X'80' are passed through unchanged
|
|
|
|
## Record Layout
|
|
|
|
### Input / Output (80 bytes fixed-length)
|
|
|
|
| Structure | Type | Description |
|
|
|-----------|----------|--------------------------------------|
|
|
| IN-BYTE | OCCURS | Individual bytes for conversion |
|
|
|
|
## Files
|
|
|
|
| File | Purpose |
|
|
|-------------------------|--------------------------------|
|
|
| main-29-ascii-ebcdic.cbl | Main COBOL program |
|
|
| data-gen.sh | Generate ASCII test data |
|
|
| run.sh | Compile, run, verify |
|
|
| README.md | This file |
|
|
|
|
## Tests
|
|
|
|
| Test Case | Description |
|
|
|----------------------------|------------------------------------|
|
|
| Uppercase A-Z | Letters mapped to EBCDIC |
|
|
| Lowercase a-z | Lowercase mapped to EBCDIC |
|
|
| Digits 0-9 | Numeric characters converted |
|
|
| Printable symbols | Symbols like !@#$% converted |
|
|
| Mixed content | Combination of letters/numbers |
|
|
| Control characters | Preserved through conversion |
|
|
| Space-padded record | Padding character handling |
|
|
| All printable chars | Full ASCII printable range test |
|
|
|
|
## Usage
|
|
|
|
```bash
|
|
cd 29-ascii-ebcdic
|
|
bash data-gen.sh
|
|
bash run.sh
|
|
```
|
|
|
|
## Expected Behavior
|
|
|
|
- Input and output are the same size (8 records x 80 bytes each).
|
|
- ASCII character 'A' (X'41') maps to EBCDIC X'C1'.
|
|
- ASCII character '0' (X'30') maps to EBCDIC X'F0'.
|
|
- Control characters (X'00'-X'1F') are converted per EBCDIC mapping.
|
|
- Non-ASCII bytes (>= X'80') pass through unchanged.
|