Skip to content

Commit 12f5f9f

Browse files
authored
Merge pull request #23 from openmainframeproject/release-5.0.1
Release 5.0.1
2 parents ffeae55 + 664267d commit 12f5f9f

33 files changed

+1653
-50
lines changed

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,11 @@ buildNumber.properties
109109
.mvn/wrapper/maven-wrapper.jar
110110
.flattened-pom.xml
111111

112-
# End of https://www.gitignore.io/api/java,maven,eclipse
112+
# End of https://www.gitignore.io/api/java,maven,eclipse
113+
114+
.vscode
115+
116+
cpp/obj
117+
cpp/bin
118+
.vs
119+
/cpp/packages

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ IBM Mainframe files on any workstation or laptop etc. that supports Java.
1515

1616
## Updates ##
1717

18+
**Version 5.0.1: July 2023 -- September 2025**
19+
20+
- Updated pom.xml to have Maven compile using Java 21
21+
- Allow user to specify only <input file> for text files. Resulting <output file> will be <input file>.txt
22+
- Added C++ port
23+
- Added commit id to the version
24+
1825
**Version 5: March 2021**
1926

2027
- Support for variable length binary records. Variable length records processed in binary mode will be prefixed with a 4 byte field in the same format as the IBM RDW i.e. 2 byte record length field (including RDW length, big-endian) followed by 2 bytes of zeros.
@@ -25,7 +32,7 @@ For execution, TerseDecompress needs a JVM runtime environment.
2532

2633
Usage:
2734

28-
```java -jar tersedecompress-5.0.0.jar [-b] tersed-file output-file```
35+
```java -jar tersedecompress.jar [-b] tersed-file output-file```
2936

3037
Default mode is text mode, which will attempt EBCDIC -> ASCII conversion.
3138

cpp/.clang-format

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
BasedOnStyle: Microsoft
3+
AlignEscapedNewlines: Left
4+
AllowShortFunctionsOnASingleLine: All
5+
AlwaysBreakAfterReturnType: None
6+
AlwaysBreakTemplateDeclarations: 'Yes'
7+
ColumnLimit: '125'
8+
IndentCaseLabels: 'true'
9+
IndentPPDirectives: BeforeHash
10+
IndentWidth: '2'
11+
Language: Cpp
12+
MaxEmptyLinesToKeep: '1'
13+
NamespaceIndentation: All
14+
PenaltyBreakAssignment: '50'
15+
SortUsingDeclarations: 'true'
16+
SpaceBeforeCtorInitializerColon: 'false'
17+
SpaceBeforeInheritanceColon: 'false'
18+
SpacesInAngles: 'true'
19+
TabWidth: '2'
20+
UseTab: Never
21+
22+
...

cpp/Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.SECONDARY:
2+
.SUFIXES:
3+
.PHONY: all src tests clean
4+
5+
UNAME:=$(shell uname)
6+
7+
ifneq ($(filter $(UNAME),Linux Darwin),)
8+
MAKE_FLAGS := -j8
9+
endif
10+
11+
default: all
12+
13+
src:
14+
$(MAKE) $(MAKE_FLAGS) -C src
15+
tests: src
16+
$(MAKE) $(MAKE_FLAGS) -C tests
17+
check: tests
18+
$(MAKE) $(MAKE_FLAGS) -C tests check
19+
20+
all: src
21+
22+
clean:
23+
$(MAKE) $(MAKE_FLAGS) -C src clean
24+
$(MAKE) $(MAKE_FLAGS) -C tests clean

cpp/envdef.mak

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
ROOT_DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
2+
OBJ_DIR:=$(ROOT_DIR)obj
3+
BIN_DIR:=$(ROOT_DIR)bin
4+
5+
UNAME:=$(shell uname)
6+
PREFIX?=$(HOME)/local
7+
CXXFLAGS = -std=c++17 -O2
8+
CCFLAGS_DLL += -fPIC -fvisibility=default
9+
AR=ar
10+
11+
ifneq ($(filter $(UNAME),Linux Darwin),)
12+
INSTALL_CMD:=install -m 644
13+
INSTALL_CMD_BIN:=install -m 755
14+
CC:=clang
15+
CXX:=clang++
16+
LD:=clang++
17+
else
18+
INSTALL_CMD:=cp
19+
INSTALL_CMD_BIN:=cp
20+
CC:=ibm-clang
21+
CXX:=ibm-clang++
22+
LD:=ibm-clang++
23+
CXXFLAGS +=-m64 -mzos-float-kind=ieee -D_UNIX03_SOURCE -D_UNIX03_THREADS -D_POSIX_SOURCE -D_POSIX_THREADS \
24+
-D_OPEN_SYS_SOCK_IPV6=1 -D_XOPEN_SOURCE_EXTENDED=1 -DOE_SOCKETS -D_OPEN_SYS_IF_EXT=1
25+
LDFLAGS +=-m64
26+
endif
27+
28+
GIT_TAG := $(shell git rev-parse --short HEAD)

cpp/src/Constants.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef TERSE_CONSTANTS_H
2+
#define TERSE_CONSTANTS_H
3+
4+
#include <array>
5+
#include <cstdint>
6+
7+
namespace Tersedecompress
8+
{
9+
static constexpr int BUFFERSIZE = 0x07FF; // 2047 (not directly used in our code)
10+
static constexpr int HASHSIZE = 0x0FFF; // 4095 (not directly used in decode)
11+
static constexpr int TREESIZE = 0x1000; // 4096
12+
static constexpr int RECORDMARK = 257; // used in putChar logic
13+
static constexpr char ENDOFFILE = 0; // used to indicate EOF in blockReader
14+
static constexpr int BASE = 0;
15+
static constexpr int CODESIZE = 257; // 256 codepoints + EOF/recordmark
16+
17+
static constexpr std::array< int, 256 > EbcToAsc = {
18+
0x00, 0x01, 0x02, 0x03, 0xCF, 0x09, 0xD3, 0x7F, 0xD4, 0xD5, 0xC3, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13,
19+
0xC7, 0xB4, 0x08, 0xC9, 0x18, 0x19, 0xCC, 0xCD, 0x83, 0x1D, 0xD2, 0x1F, 0x81, 0x82, 0x1C, 0x84, 0x86, 0x0A, 0x17, 0x1B,
20+
0x89, 0x91, 0x92, 0x95, 0xA2, 0x05, 0x06, 0x07, 0xE0, 0xEE, 0x16, 0xE5, 0xD0, 0x1E, 0xEA, 0x04, 0x8A, 0xF6, 0xC6, 0xC2,
21+
0x14, 0x15, 0xC1, 0x1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0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0xB3, 0xF7, 0xF0, 0xFA, 0xA7, 0xFF};
31+
32+
} // namespace Tersedecompress
33+
34+
#endif // TERSE_CONSTANTS_H

cpp/src/Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.SECONDARY:
2+
.SUFIXES:
3+
.PHONY: all clean
4+
default: all
5+
6+
include ../envdef.mak
7+
8+
OBJ_LIB_DIR=$(OBJ_DIR)/lib
9+
LIBTERSEDECOMPRESS = $(BIN_DIR)/libtersedecompress.a
10+
TERSEDECOMPRESS = $(BIN_DIR)/tersedecompress++
11+
SRC_LIB=\
12+
NonSpackDecompresser.cpp \
13+
SpackDecompresser.cpp \
14+
TerseBlockReader.cpp \
15+
TerseDecompresser.cpp \
16+
TerseHeader.cpp
17+
SRC_APP=\
18+
main.cpp \
19+
argumentParser.cpp
20+
21+
OBJS_LIB += $(addprefix $(OBJ_LIB_DIR)/, $(addsuffix .o, $(basename $(SRC_LIB))))
22+
OBJS += $(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(basename $(SRC_APP))))
23+
DEPS += $(addsuffix .d, $(basename $(OBJS)))
24+
25+
$(OBJ_DIR)/%.o: %.cpp | $(OBJ_DIR)
26+
$(CXX) $(CXXFLAGS) -DGIT_TAG=\"$(GIT_TAG)\" -MMD -MF $(OBJ_DIR)/$*.d -MP -c $< -o $@
27+
28+
$(OBJ_LIB_DIR)/%.o: %.cpp | $(OBJ_DIR) $(OBJ_LIB_DIR)
29+
$(CXX) $(CXXFLAGS) $(CCFLAGS_DLL) -MMD -MF $(OBJ_LIB_DIR)/$*.d -MP -c $< -o $@
30+
31+
$(LIBTERSEDECOMPRESS): $(OBJS_LIB) | $(BIN_DIR)
32+
$(AR) rcs $(LIBTERSEDECOMPRESS) $(OBJS_LIB)
33+
34+
$(TERSEDECOMPRESS): $(OBJS) $(LIBTERSEDECOMPRESS) | $(BIN_DIR)
35+
$(LD) $(LDFLAGS) -L$(BIN_DIR) -o $(TERSEDECOMPRESS) $(OBJS) -ltersedecompress
36+
37+
$(OBJ_DIR) $(OBJ_LIB_DIR) $(BIN_DIR):
38+
-mkdir -p $@
39+
40+
all: $(TERSEDECOMPRESS)
41+
42+
clean:
43+
rm -rf $(OBJ_DIR) $(OBJS_LIB) $(BIN_DIR) $(OBJS) $(DEPS) $(LIBTERSEDECOMPRESS) $(TERSEDECOMPRESS)
44+
45+
-include $(OBJS:%.o=%.d)

cpp/src/NonSpackDecompresser.cpp

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include "NonSpackDecompresser.h"
2+
#include "Constants.h"
3+
4+
#include <stdexcept>
5+
#include <vector>
6+
7+
NonSpackDecompresser::NonSpackDecompresser(std::istream &in, std::ostream &out, std::unique_ptr< TerseBlockReader > reader,
8+
const TerseHeader &header)
9+
: TerseDecompresser(in, out)
10+
{
11+
blockReader_ = std::move(reader);
12+
hostFlag_ = header.hostFlag;
13+
variableFlag_ = header.recfmV;
14+
recordLength_ = header.recordLength;
15+
}
16+
17+
void NonSpackDecompresser::decode()
18+
{
19+
std::vector< int > Father(Tersedecompress::TREESIZE, 0);
20+
std::vector< int > CharExt(Tersedecompress::TREESIZE, 0);
21+
std::vector< int > Backward(Tersedecompress::TREESIZE, 0);
22+
std::vector< int > Forward(Tersedecompress::TREESIZE, 0);
23+
24+
int H1 = 0, H2 = 0;
25+
int x = 0, d = 0, y = 0;
26+
int q = 0, r = 0, e = 0, p = 0, h = 0;
27+
28+
H2 = 65;
29+
30+
for (H1 = 258; H1 < Tersedecompress::TREESIZE; ++H1)
31+
{
32+
Father[H1] = H2;
33+
CharExt[H1] = 65;
34+
H2 = H1;
35+
}
36+
37+
for (H1 = 258; H1 < (Tersedecompress::TREESIZE - 1); ++H1)
38+
{
39+
Backward[H1 + 1] = H1;
40+
Forward[H1] = H1 + 1;
41+
}
42+
43+
Backward[0] = Tersedecompress::TREESIZE - 1;
44+
Forward[0] = 258;
45+
Backward[258] = 0;
46+
Forward[Tersedecompress::TREESIZE - 1] = 0;
47+
48+
x = 0;
49+
d = blockReader_->getBlok();
50+
51+
while (d != Tersedecompress::ENDOFFILE)
52+
{
53+
h = 0;
54+
y = Backward[0];
55+
q = Backward[y];
56+
Backward[0] = q;
57+
Forward[q] = 0;
58+
h = y;
59+
p = 0;
60+
61+
while (d > 257)
62+
{
63+
q = Forward[d];
64+
r = Backward[d];
65+
Forward[r] = q;
66+
Backward[q] = r;
67+
Forward[d] = h;
68+
Backward[h] = d;
69+
h = d;
70+
e = Father[d];
71+
Father[d] = p;
72+
p = d;
73+
d = e;
74+
}
75+
76+
q = Forward[0];
77+
Forward[y] = q;
78+
Backward[q] = y;
79+
Forward[0] = h;
80+
Backward[h] = 0;
81+
82+
CharExt[x] = d;
83+
putChar(d);
84+
85+
x = y;
86+
87+
while (p != 0)
88+
{
89+
e = Father[p];
90+
putChar(CharExt[p]);
91+
Father[p] = d;
92+
d = p;
93+
p = e;
94+
}
95+
96+
Father[y] = d;
97+
d = blockReader_->getBlok();
98+
}
99+
close();
100+
}

cpp/src/NonSpackDecompresser.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef NONSPACKDECOMPRESSER_H
2+
#define NONSPACKDECOMPRESSER_H
3+
4+
#include "TerseBlockReader.h"
5+
#include "TerseDecompresser.h"
6+
#include "TerseHeader.h"
7+
#include <memory>
8+
9+
class NonSpackDecompresser: public TerseDecompresser
10+
{
11+
public:
12+
NonSpackDecompresser(std::istream &in, std::ostream &out, std::unique_ptr< TerseBlockReader > reader,
13+
const TerseHeader &header);
14+
void decode() override;
15+
};
16+
17+
#endif // NONSPACKDECOMPRESSER_H

0 commit comments

Comments
 (0)