summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsystemcoder <systemcoder@protonmail.com>2020-03-15 08:34:44 +0000
committersystemcoder <systemcoder@protonmail.com>2020-03-15 08:34:44 +0000
commit784076d51c3d95443b53416e593c38c612c14bbe (patch)
treefdbe7e3870f7c5a17c3a9ce6b5f9fb4706b84804
parent0184655779b6e72449db0b711ee591b6cd991652 (diff)
downloadH64D-2-784076d51c3d95443b53416e593c38c612c14bbe.tar.gz
H64D-2-784076d51c3d95443b53416e593c38c612c14bbe.zip
Output as hex works, first version that produces results.
-rw-r--r--H64E-2.xcodeproj/project.pbxproj312
-rw-r--r--H64E-2.xcodeproj/project.xcworkspace/contents.xcworkspacedata7
-rw-r--r--H64E-2.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist8
-rw-r--r--H64E-2.xcodeproj/xcuserdata/dianshi.xcuserdatad/xcschemes/xcschememanagement.plist14
-rw-r--r--H64E-2/h64e-model.c81
-rw-r--r--H64E-2/h64e-model.h27
-rw-r--r--H64E-2/h64e.c83
-rw-r--r--H64E-2/h64e.h37
-rw-r--r--H64E-2/main.c70
-rw-r--r--Tests/files/test_011
-rw-r--r--Tests/files/test_0210
-rw-r--r--Tests/files/test_038
12 files changed, 610 insertions, 48 deletions
diff --git a/H64E-2.xcodeproj/project.pbxproj b/H64E-2.xcodeproj/project.pbxproj
new file mode 100644
index 0000000..05aae75
--- /dev/null
+++ b/H64E-2.xcodeproj/project.pbxproj
@@ -0,0 +1,312 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 50;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ A927BD95241C279000DC8519 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = A927BD94241C279000DC8519 /* main.c */; };
+ A927BD9D241C344C00DC8519 /* h64e.c in Sources */ = {isa = PBXBuildFile; fileRef = A927BD9C241C344C00DC8519 /* h64e.c */; };
+ A927BDA0241C350A00DC8519 /* h64e-model.c in Sources */ = {isa = PBXBuildFile; fileRef = A927BD9F241C350A00DC8519 /* h64e-model.c */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+ A927BD8F241C279000DC8519 /* CopyFiles */ = {
+ isa = PBXCopyFilesBuildPhase;
+ buildActionMask = 2147483647;
+ dstPath = /usr/share/man/man1/;
+ dstSubfolderSpec = 0;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 1;
+ };
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+ A927BD91241C279000DC8519 /* H64E-2 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "H64E-2"; sourceTree = BUILT_PRODUCTS_DIR; };
+ A927BD94241C279000DC8519 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
+ A927BD9B241C344C00DC8519 /* h64e.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = h64e.h; sourceTree = "<group>"; };
+ A927BD9C241C344C00DC8519 /* h64e.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = h64e.c; sourceTree = "<group>"; };
+ A927BD9E241C350A00DC8519 /* h64e-model.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "h64e-model.h"; sourceTree = "<group>"; };
+ A927BD9F241C350A00DC8519 /* h64e-model.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = "h64e-model.c"; sourceTree = "<group>"; };
+ A927BDA3241C534700DC8519 /* test_01 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = test_01; sourceTree = "<group>"; };
+ A927BDA5241D0B4900DC8519 /* test_02 */ = {isa = PBXFileReference; lastKnownFileType = text; path = test_02; sourceTree = "<group>"; };
+ A927BDA6241D0B7700DC8519 /* test_03 */ = {isa = PBXFileReference; lastKnownFileType = text; path = test_03; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ A927BD8E241C279000DC8519 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ A927BD88241C279000DC8519 = {
+ isa = PBXGroup;
+ children = (
+ A927BDA1241C530300DC8519 /* Tests */,
+ A927BD93241C279000DC8519 /* H64E-2 */,
+ A927BD92241C279000DC8519 /* Products */,
+ );
+ sourceTree = "<group>";
+ };
+ A927BD92241C279000DC8519 /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ A927BD91241C279000DC8519 /* H64E-2 */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ A927BD93241C279000DC8519 /* H64E-2 */ = {
+ isa = PBXGroup;
+ children = (
+ A927BD94241C279000DC8519 /* main.c */,
+ A927BD9B241C344C00DC8519 /* h64e.h */,
+ A927BD9E241C350A00DC8519 /* h64e-model.h */,
+ A927BD9F241C350A00DC8519 /* h64e-model.c */,
+ A927BD9C241C344C00DC8519 /* h64e.c */,
+ );
+ path = "H64E-2";
+ sourceTree = "<group>";
+ };
+ A927BDA1241C530300DC8519 /* Tests */ = {
+ isa = PBXGroup;
+ children = (
+ A927BDA2241C530D00DC8519 /* files */,
+ );
+ path = Tests;
+ sourceTree = "<group>";
+ };
+ A927BDA2241C530D00DC8519 /* files */ = {
+ isa = PBXGroup;
+ children = (
+ A927BDA3241C534700DC8519 /* test_01 */,
+ A927BDA5241D0B4900DC8519 /* test_02 */,
+ A927BDA6241D0B7700DC8519 /* test_03 */,
+ );
+ path = files;
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ A927BD90241C279000DC8519 /* H64E-2 */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = A927BD98241C279000DC8519 /* Build configuration list for PBXNativeTarget "H64E-2" */;
+ buildPhases = (
+ A927BD8D241C279000DC8519 /* Sources */,
+ A927BD8E241C279000DC8519 /* Frameworks */,
+ A927BD8F241C279000DC8519 /* CopyFiles */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = "H64E-2";
+ productName = "H64E-2";
+ productReference = A927BD91241C279000DC8519 /* H64E-2 */;
+ productType = "com.apple.product-type.tool";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ A927BD89241C279000DC8519 /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 1130;
+ ORGANIZATIONNAME = dianshi;
+ TargetAttributes = {
+ A927BD90241C279000DC8519 = {
+ CreatedOnToolsVersion = 11.3.1;
+ };
+ };
+ };
+ buildConfigurationList = A927BD8C241C279000DC8519 /* Build configuration list for PBXProject "H64E-2" */;
+ compatibilityVersion = "Xcode 9.3";
+ developmentRegion = en;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ Base,
+ );
+ mainGroup = A927BD88241C279000DC8519;
+ productRefGroup = A927BD92241C279000DC8519 /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ A927BD90241C279000DC8519 /* H64E-2 */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXSourcesBuildPhase section */
+ A927BD8D241C279000DC8519 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ A927BD9D241C344C00DC8519 /* h64e.c in Sources */,
+ A927BDA0241C350A00DC8519 /* h64e-model.c in Sources */,
+ A927BD95241C279000DC8519 /* main.c in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+ A927BD96241C279000DC8519 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_ENABLE_OBJC_WEAK = YES;
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_COMMA = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = NO;
+ DEBUG_INFORMATION_FORMAT = dwarf;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_TESTABILITY = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu11;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.15;
+ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
+ MTL_FAST_MATH = YES;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = macosx;
+ };
+ name = Debug;
+ };
+ A927BD97241C279000DC8519 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_ENABLE_OBJC_WEAK = YES;
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_COMMA = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = NO;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ ENABLE_NS_ASSERTIONS = NO;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu11;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.15;
+ MTL_ENABLE_DEBUG_INFO = NO;
+ MTL_FAST_MATH = YES;
+ SDKROOT = macosx;
+ };
+ name = Release;
+ };
+ A927BD99241C279000DC8519 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CODE_SIGN_STYLE = Automatic;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Debug;
+ };
+ A927BD9A241C279000DC8519 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CODE_SIGN_STYLE = Automatic;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ A927BD8C241C279000DC8519 /* Build configuration list for PBXProject "H64E-2" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ A927BD96241C279000DC8519 /* Debug */,
+ A927BD97241C279000DC8519 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ A927BD98241C279000DC8519 /* Build configuration list for PBXNativeTarget "H64E-2" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ A927BD99241C279000DC8519 /* Debug */,
+ A927BD9A241C279000DC8519 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = A927BD89241C279000DC8519 /* Project object */;
+}
diff --git a/H64E-2.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/H64E-2.xcodeproj/project.xcworkspace/contents.xcworkspacedata
new file mode 100644
index 0000000..0fedac4
--- /dev/null
+++ b/H64E-2.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+ version = "1.0">
+ <FileRef
+ location = "self:H64E-2.xcodeproj">
+ </FileRef>
+</Workspace>
diff --git a/H64E-2.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/H64E-2.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
new file mode 100644
index 0000000..18d9810
--- /dev/null
+++ b/H64E-2.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>IDEDidComputeMac32BitWarning</key>
+ <true/>
+</dict>
+</plist>
diff --git a/H64E-2.xcodeproj/xcuserdata/dianshi.xcuserdatad/xcschemes/xcschememanagement.plist b/H64E-2.xcodeproj/xcuserdata/dianshi.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 0000000..c3bc962
--- /dev/null
+++ b/H64E-2.xcodeproj/xcuserdata/dianshi.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>SchemeUserState</key>
+ <dict>
+ <key>H64E-2.xcscheme_^#shared#^_</key>
+ <dict>
+ <key>orderHint</key>
+ <integer>0</integer>
+ </dict>
+ </dict>
+</dict>
+</plist>
diff --git a/H64E-2/h64e-model.c b/H64E-2/h64e-model.c
index b794f52..3bd0d1f 100644
--- a/H64E-2/h64e-model.c
+++ b/H64E-2/h64e-model.c
@@ -8,7 +8,7 @@
#include "h64e-model.h"
-int h64e_si_init(H64E_stream_in *in, ssize_t size)
+int h64e_si_init(H64E_stream_in *in, int32_t size)
{
in->size = size;
in->cur_size = 0;
@@ -17,42 +17,53 @@ int h64e_si_init(H64E_stream_in *in, ssize_t size)
}
//return amount of copied bytes
-int h64e_si_data_in(H64E_stream_in *in, uint8_t *data, size_t size)
+int h64e_si_data_in(H64E_stream_in *in, uint8_t *data, int32_t size)
{
- ssize_t start = in->cur_size;
- ssize_t end = start+size;
- ssize_t len = 0;
+ int32_t start = in->cur_size;
+ int32_t end = start+size;
+ int32_t len = 0;
+
if (end > in->size)
{
end = in->size;
}
len = end-start;
-
- memcpy(in->buf, data, len);
-
+ memcpy(&in->buf[start], data, len);
+ in->cur_size += len;
return (int)len;
}
-int h64e_si_data_out(H64E_stream_in *in, uint8_t *data, size_t size)
+int h64e_si_data_out(H64E_stream_in *in, uint8_t *data, int32_t size)
{
- ssize_t len=0;
+ int32_t len=0;
+ int32_t i=0;
- if (size<in->cur_size)
+ if (size < in->cur_size)
{
len = size;
} else {
len = in->cur_size;
}
- memcpy(data,in->buf,len);
- memmove(in->buf,in->buf[len],len);
+ //memcpy(data,&in->buf[0],len);
+ for (i=0;i<len;i++)
+ {
+ data[i] = in->buf[i];
+ }
+
+ memmove(&in->buf[0],&in->buf[len],len);
in->cur_size -= len;
return len;
}
-int h64e_so_init(H64E_stream_out *out, ssize_t size)
+int h64e_si_len(H64E_stream_in *in)
+{
+ return in->cur_size;
+}
+
+int h64e_so_init(H64E_stream_out *out, int32_t size)
{
out->size = size;
out->cur_size = 0;
@@ -60,37 +71,55 @@ int h64e_so_init(H64E_stream_out *out, ssize_t size)
return 0;
}
-int h64e_so_data_in(H64E_stream_in *out, uint8_t *data, size_t size)
+int h64e_so_data_in(H64E_stream_out *out, uint8_t *data, int32_t size)
{
- ssize_t start = out->cur_size;
- ssize_t end = start+size;
- ssize_t len = 0;
+ int32_t start = out->cur_size;
+ int32_t end = start+size;
+ int32_t len = 0;
+
if (end > out->size)
{
end = out->size;
}
len = end-start;
-
- memcpy(out->buf, data, len);
-
+ memcpy(&out->buf[start], data, len);
+ out->cur_size += len;
return (int)len;
}
-int h64e_so_data_out(H64E_stream_in *out, uint8_t *data, size_t size)
+int h64e_so_data_out(H64E_stream_out *out, uint8_t *data, int32_t size)
{
- ssize_t len=0;
+ int32_t len=0;
+ int32_t i=0;
- if (size<out->cur_size)
+ if (size < out->cur_size)
{
len = size;
} else {
len = out->cur_size;
}
- memcpy(data,out->buf,len);
- memmove(out->buf,out->buf[len],len);
+ //memcpy(data,&in->buf[0],len);
+ for (i=0;i<len;i++)
+ {
+ data[i] = out->buf[i];
+ }
+
+ memmove(&out->buf[0],&out->buf[len],len);
out->cur_size -= len;
return len;
}
+
+int h64e_so_ready(H64E_stream_out *out)
+{
+ int ret = 0;
+
+ return ret;
+}
+
+int h64e_so_len(H64E_stream_out *out)
+{
+ return out->cur_size;
+}
diff --git a/H64E-2/h64e-model.h b/H64E-2/h64e-model.h
index 516f8dc..761d327 100644
--- a/H64E-2/h64e-model.h
+++ b/H64E-2/h64e-model.h
@@ -10,30 +10,37 @@
#define h64e_model_h
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
typedef int (*trnf_clb)(char*);
typedef struct H64E_stream_in {
- int cur_size;
- int size;
+ int32_t cur_size;
+ int32_t size;
uint8_t *buf;
} H64E_stream_in;
//used to get collected data
-int h64e_si_init(H64E_stream_in *in, ssize_t size);
-int h64e_si_data_in(H64E_stream_in *in, uint8_t *data, size_t size);
-int h64e_si_data_out(H64E_stream_in *in, uint8_t *data, size_t size);
+int h64e_si_init(H64E_stream_in *in, int32_t size);
+int h64e_si_data_in(H64E_stream_in *in, uint8_t *data, int32_t size);
+int h64e_si_data_out(H64E_stream_in *in, uint8_t *data, int32_t size);
+int h64e_si_len(H64E_stream_in *in);
typedef struct H64E_stream_out {
- int cur_size;
- int size;
+ int32_t cur_size;
+ int32_t size;
uint8_t *buf;
} H64E_stream_out;
//using to collect output formated data
-int h64e_so_init(H64E_stream_out *out, ssize_t size);
-int h64e_so_data_in(H64E_stream_in *out, uint8_t *data, size_t size);
-int h64e_so_data_out(H64E_stream_in *out, uint8_t *data, size_t size);
+int h64e_so_init(H64E_stream_out *out, int32_t size);
+int h64e_so_data_in(H64E_stream_out *out, uint8_t *data, int32_t size);
+int h64e_so_data_out(H64E_stream_out *out, uint8_t *data, int32_t size);
+/*
+ * Trigger that buffer is full, or trigger new line in buffer
+ */
+int h64e_so_ready(H64E_stream_out *out);
+int h64e_so_len(H64E_stream_out *out);
#endif /* h64e_model_h */
diff --git a/H64E-2/h64e.c b/H64E-2/h64e.c
index 0072030..1e0662c 100644
--- a/H64E-2/h64e.c
+++ b/H64E-2/h64e.c
@@ -49,3 +49,86 @@ int h64e_destroy(H64E_t *s)
{
return 0;
}
+
+int h64e_fmt_init( H64E_format *fs)
+{
+ memset(fs,0,sizeof(H64E_format));
+
+ return 0;
+}
+
+/*
+ * out_size - allways give enought data to buffer otherwise it will partially write data, or flush data out more often
+ */
+int h64e_fmt_byte(H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size)
+{
+ //printf("h64e_fmt_byte in %d out %d\n",in_size,out_size);
+ int ret=0;
+ int cur_size=0;
+ int i,j=0;
+ const int SZ=16;
+ uint8_t buf[SZ];
+ int buf_sz=0;
+ int trail_size=0;
+
+ for (i=0; i<in_size; i++)
+ {
+ buf_sz = snprintf(&buf[0], SZ, "%02x",in_data[i]);
+ //count converted chars per line
+ fs->cur_pos += 1;
+ //add space if configured
+ if (fs->f_space)
+ {
+ if (buf_sz+1<SZ)
+ {
+ buf[buf_sz] = ' ';
+ buf_sz += 1;
+ }
+ }
+
+ if (fs->cur_pos == fs->column_size)
+ {
+ if (fs->f_new_line) {
+ //set triger to newline
+ fs->t_new_line = 1;
+ fs->cur_pos = 0;
+ //set new line to buffer
+ if (buf_sz+1<SZ)
+ {
+ buf[buf_sz] = '\n';
+ buf_sz += 1;
+ }
+ }
+ }
+ //printf("D: %s",buf);
+ if (trail_size+buf_sz<out_size)
+ {
+ for(j=0;j<buf_sz;j++)
+ {
+ out_data[trail_size+j] = buf[j];
+ }
+ ret = buf_sz;
+
+ } else {
+ //not enought output to handle data
+ ret=-1;
+ }
+ }
+#if 0
+ printf("D:[");
+ for (i=0;i<ret;i++)
+ {
+ printf("%c",(unsigned char)out_data[i]);
+ }
+ printf("]\n");
+#endif
+
+ return ret;
+}
+
+int h64e_fmt_finish(H64E_format *fs)
+{
+
+
+ return 0;
+}
diff --git a/H64E-2/h64e.h b/H64E-2/h64e.h
index 397a36b..d8a95cd 100644
--- a/H64E-2/h64e.h
+++ b/H64E-2/h64e.h
@@ -13,16 +13,13 @@
#include "h64e-model.h"
/*
Set data structure from arguments and use to handle data
-
- */
-
+*/
#define H64E_G_NONE 0
#define H64E_G_BYTE 1
#define H64E_G_WORD 2
#define H64E_G_DWORD 3
#define H64E_G_QWORD 4
-
#define H64E_O_START 0
#define H64E_O_NONE 0
#define H64E_O_STRING 1
@@ -36,7 +33,7 @@
#define H64E_O_UINT64 9
#define H64E_O_END H64E_O_UINT64
-typedef struct H64E_format
+typedef struct H64E_params
{
int flag_offset; /* output offset */
@@ -46,11 +43,11 @@ typedef struct H64E_format
uint8_t group; /* if there is need transdorm to specific type */
int flag_output; /* output convereted types */
uint8_t output_type; /* output in many different ways */
-} H64E_format;
+} H64E_params;
typedef struct H64E_t
{
- H64E_format fmt;
+ H64E_params fmt;
H64E_stream_in *sin;
H64E_stream_out *sout;
int fd_in;
@@ -65,4 +62,30 @@ int h64e_convert(H64E_t *s);
int h64e_destroy(H64E_t *s);
+#define H64E_FMT_STATE_NONE 0
+#define H64E_FMT_STATE_INIT 1
+#define H64E_FMT_STATE_CNV 2
+#define H64E_FMT_STATE_FINISH 3
+
+typedef struct H64E_format {
+ int group_fmt;
+ int output_fmt;
+ int min_input;
+ int max_output;
+ int column_size;
+ int f_space;
+ int cur_pos; //position where output stoped
+ int end_pos; //end postion before new line
+ int f_new_line; //should be new line set after
+ int start_offset; //start position of offset
+ int slide_offset; //offset since stream start
+ int state;
+ int t_new_line; // if new line or buffer full
+ int f_nw_pos; // if new line then save place where new line is
+} H64E_format;
+
+int h64e_fmt_init( H64E_format *fs);
+int h64e_fmt_byte( H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size);
+int h64e_fmt_finish(H64E_format *fs);
+
#endif /* h64e_h */
diff --git a/H64E-2/main.c b/H64E-2/main.c
index e1d3d7b..bd1910e 100644
--- a/H64E-2/main.c
+++ b/H64E-2/main.c
@@ -161,8 +161,10 @@ int main(int argc, const char * argv[]) {
int param_offset = -1;
char *fname = NULL;
int fd;
- int in_bytes = 0;
- uint8_t buf[128];
+ int in_bytes = 0, out_bytes=0, cnv_bytes=0;
+ int in_total = 0, out_total=0, cnv_total=0;
+ uint8_t buf_in[128+1],buf_cnv_in[128+1],buf_cnv_out[256+1],buf_out[512+1];
+ int i=0;
printf("H64E-2 Project started 1\n");
@@ -172,10 +174,14 @@ int main(int argc, const char * argv[]) {
H64E_stream_out sout;
h64e_init(&h64e);
h64e_si_init(&sin, 128);
- h64e_so_init(&sout, 128);
+ h64e_so_init(&sout, 512);
h64e_set_input(&h64e, &sin);
h64e_set_output(&h64e, &sout);
+ H64E_format int8_fmt;
+
+ h64e_fmt_init(&int8_fmt);
+
//set all params from arguments
/*get cmd args and set options */
@@ -244,13 +250,67 @@ int main(int argc, const char * argv[]) {
}
//register formats
+ //configure format of u8 to terminate on new line and have space between types
+ int8_fmt.f_space = 1;
+ int8_fmt.f_new_line = 1;
+ int8_fmt.column_size = 16;
//do conversation, reading input and outputing
- while ((in_bytes = file_read(fd,(char *)&buf,128)) != -1)
+ while ((in_bytes = file_read(fd,(char *)&buf_in,1)) != -1)
{
- printf("Reading %d bytes\n",in_bytes);
+ if (in_bytes == 0)
+ {
+ //printf("Stream ended\n");
+ break;
+ }
+
+ //write to input stream, connect all streams in a pipe
+ in_total += in_bytes;
+ //printf("Read from file %d bytes %d bytes total\n",in_bytes,in_total);
+ h64e_si_data_in(&sin, &buf_in[0], in_bytes);
+
+ //if buffer have enought data then convert it
+ if (h64e_si_len(&sin)>1)
+ {
+ int cnv_num=-1;
+ //printf("Input Out\n");
+ cnv_bytes = h64e_si_data_out(&sin, &buf_cnv_in[0], 1);
+ //cnv_total += cnv_bytes;
+
+
+ //Convert output data to desired format
+ //printf("Start converting to byte8\n");
+ cnv_num = h64e_fmt_byte(&int8_fmt, &buf_cnv_in[0], cnv_bytes, buf_cnv_out, 512);
+ //printf("Conversation amount\n");
+ //Push all data ot output buffer
+ //printf("Write to output stream data %d bytes\n",cnv_bytes);
+ cnv_bytes = h64e_so_data_in(&sout, &buf_cnv_out[0], cnv_num);
+ cnv_total += cnv_num;
+ //printf("Written bytes to output steam %d bytes %d bytes total\n",cnv_bytes,cnv_total);
+ }
+
+ //Get data out of buffer
+ if ((out_bytes = h64e_so_len(&sout)) > 0)
+ {
+ out_bytes = h64e_so_data_out(&sout, &buf_out[0],512);
+ buf_out[out_bytes] = 0x00;
+ printf("%s",buf_out);
+ }
+ /*
+ out_bytes = h64e_so_data_out(&sout, &buf_out[0],512);
+ printf("Output out\n");
+ out_total += out_bytes;
+ buf_out[out_bytes] = 0x00;
+ printf("%s\n",buf_out);
+ printf("Read converted data %d bytes %d total bytes\n",out_bytes,out_total);
+ */
+ //printf("Total: in %d cnv %d out %d\n",in_total,cnv_total,out_total);
+
+ //printf("Reading %d bytes\n",in_bytes);
}
+ //check and empty all buffers
+
//deinit all structures
h64e_destroy(&h64e);
file_close(fd);
diff --git a/Tests/files/test_01 b/Tests/files/test_01
new file mode 100644
index 0000000..720691a
--- /dev/null
+++ b/Tests/files/test_01
@@ -0,0 +1 @@
+Hello this is me
diff --git a/Tests/files/test_02 b/Tests/files/test_02
new file mode 100644
index 0000000..57d07c3
--- /dev/null
+++ b/Tests/files/test_02
@@ -0,0 +1,10 @@
+LINE01
+LINE02
+LINE03
+LINE04
+LINE05
+LINE06
+LINE07
+LINE08
+LINE09
+LINE10
diff --git a/Tests/files/test_03 b/Tests/files/test_03
new file mode 100644
index 0000000..6b1a644
--- /dev/null
+++ b/Tests/files/test_03
@@ -0,0 +1,8 @@
+AAAAAAAAAA
+BBBBBBBBBB
+CCCCCCCCCC
+DDDDDDDDDD
+EEEEEEEEEE
+FFFFFFFFFF
+GGGGGGGGGG
+HHHHHHHHHH