aboutsummaryrefslogtreecommitdiff
path: root/core/compress
diff options
context:
space:
mode:
authorLaytan Laats <laytanlaats@hotmail.com>2024-09-03 19:59:04 +0200
committerLaytan Laats <laytanlaats@hotmail.com>2024-09-03 19:59:04 +0200
commit288312a8126d71fae26c9d62a8cd342d830e1c5f (patch)
treeaa56a083e0222975888a24cf8d755b7d0a4f1bc0 /core/compress
parent0e6109e171d24b3bb17289219ae3b482c24f2460 (diff)
core: improve package doc comments for the documentation generator
Diffstat (limited to 'core/compress')
-rw-r--r--core/compress/gzip/doc.odin90
-rw-r--r--core/compress/gzip/example.odin89
-rw-r--r--core/compress/shoco/model.odin3
-rw-r--r--core/compress/shoco/shoco.odin4
-rw-r--r--core/compress/zlib/doc.odin50
-rw-r--r--core/compress/zlib/example.odin47
6 files changed, 143 insertions, 140 deletions
diff --git a/core/compress/gzip/doc.odin b/core/compress/gzip/doc.odin
new file mode 100644
index 000000000..fd7ef5a19
--- /dev/null
+++ b/core/compress/gzip/doc.odin
@@ -0,0 +1,90 @@
+/*
+ Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
+ Made available under Odin's BSD-3 license.
+
+ List of contributors:
+ Jeroen van Rijn: Initial implementation.
+ Ginger Bill: Cosmetic changes.
+
+ A small GZIP implementation as an example.
+*/
+
+/*
+Example:
+ import "core:bytes"
+ import "core:os"
+ import "core:compress"
+ import "core:fmt"
+
+ // Small GZIP file with fextra, fname and fcomment present.
+ @private
+ TEST: []u8 = {
+ 0x1f, 0x8b, 0x08, 0x1c, 0xcb, 0x3b, 0x3a, 0x5a,
+ 0x02, 0x03, 0x07, 0x00, 0x61, 0x62, 0x03, 0x00,
+ 0x63, 0x64, 0x65, 0x66, 0x69, 0x6c, 0x65, 0x6e,
+ 0x61, 0x6d, 0x65, 0x00, 0x54, 0x68, 0x69, 0x73,
+ 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x63, 0x6f,
+ 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x2b, 0x48,
+ 0xac, 0xcc, 0xc9, 0x4f, 0x4c, 0x01, 0x00, 0x15,
+ 0x6a, 0x2c, 0x42, 0x07, 0x00, 0x00, 0x00,
+ }
+
+ main :: proc() {
+ // Set up output buffer.
+ buf := bytes.Buffer{}
+
+ stdout :: proc(s: string) {
+ os.write_string(os.stdout, s)
+ }
+ stderr :: proc(s: string) {
+ os.write_string(os.stderr, s)
+ }
+
+ args := os.args
+
+ if len(args) < 2 {
+ stderr("No input file specified.\n")
+ err := load(data=TEST, buf=&buf, known_gzip_size=len(TEST))
+ if err == nil {
+ stdout("Displaying test vector: ")
+ stdout(bytes.buffer_to_string(&buf))
+ stdout("\n")
+ } else {
+ fmt.printf("gzip.load returned %v\n", err)
+ }
+ bytes.buffer_destroy(&buf)
+ os.exit(0)
+ }
+
+ // The rest are all files.
+ args = args[1:]
+ err: Error
+
+ for file in args {
+ if file == "-" {
+ // Read from stdin
+ s := os.stream_from_handle(os.stdin)
+ ctx := &compress.Context_Stream_Input{
+ input = s,
+ }
+ err = load(ctx, &buf)
+ } else {
+ err = load(file, &buf)
+ }
+ if err != nil {
+ if err != E_General.File_Not_Found {
+ stderr("File not found: ")
+ stderr(file)
+ stderr("\n")
+ os.exit(1)
+ }
+ stderr("GZIP returned an error.\n")
+ bytes.buffer_destroy(&buf)
+ os.exit(2)
+ }
+ stdout(bytes.buffer_to_string(&buf))
+ }
+ bytes.buffer_destroy(&buf)
+ }
+*/
+package compress_gzip
diff --git a/core/compress/gzip/example.odin b/core/compress/gzip/example.odin
deleted file mode 100644
index 09540aafc..000000000
--- a/core/compress/gzip/example.odin
+++ /dev/null
@@ -1,89 +0,0 @@
-//+build ignore
-package compress_gzip
-
-/*
- Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
- Made available under Odin's BSD-3 license.
-
- List of contributors:
- Jeroen van Rijn: Initial implementation.
- Ginger Bill: Cosmetic changes.
-
- A small GZIP implementation as an example.
-*/
-
-import "core:bytes"
-import "core:os"
-import "core:compress"
-import "core:fmt"
-
-// Small GZIP file with fextra, fname and fcomment present.
-@private
-TEST: []u8 = {
- 0x1f, 0x8b, 0x08, 0x1c, 0xcb, 0x3b, 0x3a, 0x5a,
- 0x02, 0x03, 0x07, 0x00, 0x61, 0x62, 0x03, 0x00,
- 0x63, 0x64, 0x65, 0x66, 0x69, 0x6c, 0x65, 0x6e,
- 0x61, 0x6d, 0x65, 0x00, 0x54, 0x68, 0x69, 0x73,
- 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x63, 0x6f,
- 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x2b, 0x48,
- 0xac, 0xcc, 0xc9, 0x4f, 0x4c, 0x01, 0x00, 0x15,
- 0x6a, 0x2c, 0x42, 0x07, 0x00, 0x00, 0x00,
-}
-
-main :: proc() {
- // Set up output buffer.
- buf := bytes.Buffer{}
-
- stdout :: proc(s: string) {
- os.write_string(os.stdout, s)
- }
- stderr :: proc(s: string) {
- os.write_string(os.stderr, s)
- }
-
- args := os.args
-
- if len(args) < 2 {
- stderr("No input file specified.\n")
- err := load(data=TEST, buf=&buf, known_gzip_size=len(TEST))
- if err == nil {
- stdout("Displaying test vector: ")
- stdout(bytes.buffer_to_string(&buf))
- stdout("\n")
- } else {
- fmt.printf("gzip.load returned %v\n", err)
- }
- bytes.buffer_destroy(&buf)
- os.exit(0)
- }
-
- // The rest are all files.
- args = args[1:]
- err: Error
-
- for file in args {
- if file == "-" {
- // Read from stdin
- s := os.stream_from_handle(os.stdin)
- ctx := &compress.Context_Stream_Input{
- input = s,
- }
- err = load(ctx, &buf)
- } else {
- err = load(file, &buf)
- }
- if err != nil {
- if err != E_General.File_Not_Found {
- stderr("File not found: ")
- stderr(file)
- stderr("\n")
- os.exit(1)
- }
- stderr("GZIP returned an error.\n")
- bytes.buffer_destroy(&buf)
- os.exit(2)
- }
- stdout(bytes.buffer_to_string(&buf))
- }
- bytes.buffer_destroy(&buf)
-}
diff --git a/core/compress/shoco/model.odin b/core/compress/shoco/model.odin
index f62236c00..919563441 100644
--- a/core/compress/shoco/model.odin
+++ b/core/compress/shoco/model.odin
@@ -4,7 +4,6 @@
which is an English word model.
*/
-// package shoco is an implementation of the shoco short string compressor
package compress_shoco
DEFAULT_MODEL :: Shoco_Model {
@@ -145,4 +144,4 @@ DEFAULT_MODEL :: Shoco_Model {
{ 0xc0000000, 2, 4, { 25, 22, 19, 16, 16, 16, 16, 16 }, { 15, 7, 7, 7, 0, 0, 0, 0 }, 0xe0, 0xc0 },
{ 0xe0000000, 4, 8, { 23, 19, 15, 11, 8, 5, 2, 0 }, { 31, 15, 15, 15, 7, 7, 7, 3 }, 0xf0, 0xe0 },
},
-} \ No newline at end of file
+}
diff --git a/core/compress/shoco/shoco.odin b/core/compress/shoco/shoco.odin
index 269dd8875..b393b8356 100644
--- a/core/compress/shoco/shoco.odin
+++ b/core/compress/shoco/shoco.odin
@@ -8,7 +8,7 @@
An implementation of [shoco](https://github.com/Ed-von-Schleck/shoco) by Christian Schramm.
*/
-// package shoco is an implementation of the shoco short string compressor
+// package shoco is an implementation of the shoco short string compressor.
package compress_shoco
import "base:intrinsics"
@@ -308,4 +308,4 @@ compress_string :: proc(input: string, model := DEFAULT_MODEL, allocator := cont
resize(&buf, length) or_return
return buf[:length], result
}
-compress :: proc{compress_string_to_buffer, compress_string} \ No newline at end of file
+compress :: proc{compress_string_to_buffer, compress_string}
diff --git a/core/compress/zlib/doc.odin b/core/compress/zlib/doc.odin
new file mode 100644
index 000000000..0a5b4eb40
--- /dev/null
+++ b/core/compress/zlib/doc.odin
@@ -0,0 +1,50 @@
+/*
+ Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
+ Made available under Odin's BSD-3 license.
+
+ List of contributors:
+ Jeroen van Rijn: Initial implementation.
+
+ An example of how to use `zlib.inflate`.
+*/
+
+/*
+Example:
+ package main
+
+ import "core:bytes"
+ import "core:fmt"
+
+ main :: proc() {
+ ODIN_DEMO := []u8{
+ 120, 218, 101, 144, 65, 110, 131, 48, 16, 69, 215, 246, 41, 190, 44, 69, 73, 32, 148, 182,
+ 75, 75, 28, 32, 251, 46, 217, 88, 238, 0, 86, 192, 32, 219, 36, 170, 170, 172, 122, 137,
+ 238, 122, 197, 30, 161, 70, 162, 20, 81, 203, 139, 25, 191, 255, 191, 60, 51, 40, 125, 81,
+ 53, 33, 144, 15, 156, 155, 110, 232, 93, 128, 208, 189, 35, 89, 117, 65, 112, 222, 41, 99,
+ 33, 37, 6, 215, 235, 195, 17, 239, 156, 197, 170, 118, 170, 131, 44, 32, 82, 164, 72, 240,
+ 253, 245, 249, 129, 12, 185, 224, 76, 105, 61, 118, 99, 171, 66, 239, 38, 193, 35, 103, 85,
+ 172, 66, 127, 33, 139, 24, 244, 235, 141, 49, 204, 223, 76, 208, 205, 204, 166, 7, 173, 60,
+ 97, 159, 238, 37, 214, 41, 105, 129, 167, 5, 102, 27, 152, 173, 97, 178, 129, 73, 129, 231,
+ 5, 230, 27, 152, 175, 225, 52, 192, 127, 243, 170, 157, 149, 18, 121, 142, 115, 109, 227, 122,
+ 64, 87, 114, 111, 161, 49, 182, 6, 181, 158, 162, 226, 206, 167, 27, 215, 246, 48, 56, 99,
+ 67, 117, 16, 47, 13, 45, 35, 151, 98, 231, 75, 1, 173, 90, 61, 101, 146, 71, 136, 244,
+ 170, 218, 145, 176, 123, 45, 173, 56, 113, 134, 191, 51, 219, 78, 235, 95, 28, 249, 253, 7,
+ 159, 150, 133, 125,
+ }
+ OUTPUT_SIZE :: 432
+
+ buf: bytes.Buffer
+
+ // We can pass ", true" to inflate a raw DEFLATE stream instead of a ZLIB wrapped one.
+ err := inflate(input=ODIN_DEMO, buf=&buf, expected_output_size=OUTPUT_SIZE)
+ defer bytes.buffer_destroy(&buf)
+
+ if err != nil {
+ fmt.printf("\nError: %v\n", err)
+ }
+ s := bytes.buffer_to_string(&buf)
+ fmt.printf("Input: %v bytes, output (%v bytes):\n%v\n", len(ODIN_DEMO), len(s), s)
+ assert(len(s) == OUTPUT_SIZE)
+ }
+*/
+package compress_zlib
diff --git a/core/compress/zlib/example.odin b/core/compress/zlib/example.odin
deleted file mode 100644
index fedd6671d..000000000
--- a/core/compress/zlib/example.odin
+++ /dev/null
@@ -1,47 +0,0 @@
-//+build ignore
-package compress_zlib
-
-/*
- Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
- Made available under Odin's BSD-3 license.
-
- List of contributors:
- Jeroen van Rijn: Initial implementation.
-
- An example of how to use `zlib.inflate`.
-*/
-
-import "core:bytes"
-import "core:fmt"
-
-main :: proc() {
- ODIN_DEMO := []u8{
- 120, 218, 101, 144, 65, 110, 131, 48, 16, 69, 215, 246, 41, 190, 44, 69, 73, 32, 148, 182,
- 75, 75, 28, 32, 251, 46, 217, 88, 238, 0, 86, 192, 32, 219, 36, 170, 170, 172, 122, 137,
- 238, 122, 197, 30, 161, 70, 162, 20, 81, 203, 139, 25, 191, 255, 191, 60, 51, 40, 125, 81,
- 53, 33, 144, 15, 156, 155, 110, 232, 93, 128, 208, 189, 35, 89, 117, 65, 112, 222, 41, 99,
- 33, 37, 6, 215, 235, 195, 17, 239, 156, 197, 170, 118, 170, 131, 44, 32, 82, 164, 72, 240,
- 253, 245, 249, 129, 12, 185, 224, 76, 105, 61, 118, 99, 171, 66, 239, 38, 193, 35, 103, 85,
- 172, 66, 127, 33, 139, 24, 244, 235, 141, 49, 204, 223, 76, 208, 205, 204, 166, 7, 173, 60,
- 97, 159, 238, 37, 214, 41, 105, 129, 167, 5, 102, 27, 152, 173, 97, 178, 129, 73, 129, 231,
- 5, 230, 27, 152, 175, 225, 52, 192, 127, 243, 170, 157, 149, 18, 121, 142, 115, 109, 227, 122,
- 64, 87, 114, 111, 161, 49, 182, 6, 181, 158, 162, 226, 206, 167, 27, 215, 246, 48, 56, 99,
- 67, 117, 16, 47, 13, 45, 35, 151, 98, 231, 75, 1, 173, 90, 61, 101, 146, 71, 136, 244,
- 170, 218, 145, 176, 123, 45, 173, 56, 113, 134, 191, 51, 219, 78, 235, 95, 28, 249, 253, 7,
- 159, 150, 133, 125,
- }
- OUTPUT_SIZE :: 432
-
- buf: bytes.Buffer
-
- // We can pass ", true" to inflate a raw DEFLATE stream instead of a ZLIB wrapped one.
- err := inflate(input=ODIN_DEMO, buf=&buf, expected_output_size=OUTPUT_SIZE)
- defer bytes.buffer_destroy(&buf)
-
- if err != nil {
- fmt.printf("\nError: %v\n", err)
- }
- s := bytes.buffer_to_string(&buf)
- fmt.printf("Input: %v bytes, output (%v bytes):\n%v\n", len(ODIN_DEMO), len(s), s)
- assert(len(s) == OUTPUT_SIZE)
-}