summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/UTF-8-demo.html213
-rwxr-xr-xexample/build.sh7
-rwxr-xr-xexample/examplebin0 -> 65664 bytes
-rw-r--r--example/example.c260
4 files changed, 480 insertions, 0 deletions
diff --git a/example/UTF-8-demo.html b/example/UTF-8-demo.html
new file mode 100644
index 0000000..b8157db
--- /dev/null
+++ b/example/UTF-8-demo.html
@@ -0,0 +1,213 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head><title>UTF-8 test file</title></head>
+ <body>
+ <p>Original by Markus Kuhn, adapted for HTML by Martin D&uuml;rst.</p>
+<pre>
+UTF-8 encoded sample plain-text file
+‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
+
+Markus Kuhn [ˈmaʳkʊs kuːn] &lt;mkuhn@acm.org> — 1999-08-20
+
+
+The ASCII compatible UTF-8 encoding of ISO 10646 and Unicode
+plain-text files is defined in RFC 2279 and in ISO 10646-1 Annex R.
+
+
+Using Unicode/UTF-8, you can write in emails and source code things such as
+
+Mathematics and Sciences:
+
+ ∮ E⋅da = Q, n → ∞, ∑ f(i) = ∏ g(i), ∀x∈ℝ: ⌈x⌉ = −⌊−x⌋, α ∧ ¬β = ¬(¬α ∨ β),
+
+ ℕ ⊆ ℕ₀ ⊂ ℤ ⊂ ℚ ⊂ ℝ ⊂ ℂ, ⊥ &lt; a ≠ b ≡ c ≤ d ≪ ⊤ ⇒ (A ⇔ B),
+
+ 2H₂ + O₂ ⇌ 2H₂O, R = 4.7 kΩ, ⌀ 200 mm
+
+Linguistics and dictionaries:
+
+ ði ıntəˈnæʃənəl fəˈnɛtık əsoʊsiˈeıʃn
+ Y [ˈʏpsilɔn], Yen [jɛn], Yoga [ˈjoːgɑ]
+
+APL:
+
+ ((V⍳V)=⍳⍴V)/V←,V ⌷←⍳→⍴∆∇⊃‾⍎⍕⌈
+
+Nicer typography in plain text files:
+
+ ╔══════════════════════════════════════════╗
+ ║ ║
+ ║ • ‘single’ and “double” quotes ║
+ ║ ║
+ ║ • Curly apostrophes: “We’ve been here” ║
+ ║ ║
+ ║ • Latin-1 apostrophe and accents: '´` ║
+ ║ ║
+ ║ • ‚deutsche‘ „Anführungszeichen“ ║
+ ║ ║
+ ║ • †, ‡, ‰, •, 3–4, —, −5/+5, ™, … ║
+ ║ ║
+ ║ • ASCII safety test: 1lI|, 0OD, 8B ║
+ ║ ╭─────────╮ ║
+ ║ • the euro symbol: │ 14.95 € │ ║
+ ║ ╰─────────╯ ║
+ ╚══════════════════════════════════════════╝
+
+Greek (in Polytonic):
+
+ The Greek anthem:
+
+ Σὲ γνωρίζω ἀπὸ τὴν κόψη
+ τοῦ σπαθιοῦ τὴν τρομερή,
+ σὲ γνωρίζω ἀπὸ τὴν ὄψη
+ ποὺ μὲ βία μετράει τὴ γῆ.
+
+ ᾿Απ᾿ τὰ κόκκαλα βγαλμένη
+ τῶν ῾Ελλήνων τὰ ἱερά
+ καὶ σὰν πρῶτα ἀνδρειωμένη
+ χαῖρε, ὦ χαῖρε, ᾿Ελευθεριά!
+
+ From a speech of Demosthenes in the 4th century BC:
+
+ Οὐχὶ ταὐτὰ παρίσταταί μοι γιγνώσκειν, ὦ ἄνδρες ᾿Αθηναῖοι,
+ ὅταν τ᾿ εἰς τὰ πράγματα ἀποβλέψω καὶ ὅταν πρὸς τοὺς
+ λόγους οὓς ἀκούω· τοὺς μὲν γὰρ λόγους περὶ τοῦ
+ τιμωρήσασθαι Φίλιππον ὁρῶ γιγνομένους, τὰ δὲ πράγματ᾿
+ εἰς τοῦτο προήκοντα, ὥσθ᾿ ὅπως μὴ πεισόμεθ᾿ αὐτοὶ
+ πρότερον κακῶς σκέψασθαι δέον. οὐδέν οὖν ἄλλο μοι δοκοῦσιν
+ οἱ τὰ τοιαῦτα λέγοντες ἢ τὴν ὑπόθεσιν, περὶ ἧς βουλεύεσθαι,
+ οὐχὶ τὴν οὖσαν παριστάντες ὑμῖν ἁμαρτάνειν. ἐγὼ δέ, ὅτι μέν
+ ποτ᾿ ἐξῆν τῇ πόλει καὶ τὰ αὑτῆς ἔχειν ἀσφαλῶς καὶ Φίλιππον
+ τιμωρήσασθαι, καὶ μάλ᾿ ἀκριβῶς οἶδα· ἐπ᾿ ἐμοῦ γάρ, οὐ πάλαι
+ γέγονεν ταῦτ᾿ ἀμφότερα· νῦν μέντοι πέπεισμαι τοῦθ᾿ ἱκανὸν
+ προλαβεῖν ἡμῖν εἶναι τὴν πρώτην, ὅπως τοὺς συμμάχους
+ σώσομεν. ἐὰν γὰρ τοῦτο βεβαίως ὑπάρξῃ, τότε καὶ περὶ τοῦ
+ τίνα τιμωρήσεταί τις καὶ ὃν τρόπον ἐξέσται σκοπεῖν· πρὶν δὲ
+ τὴν ἀρχὴν ὀρθῶς ὑποθέσθαι, μάταιον ἡγοῦμαι περὶ τῆς
+ τελευτῆς ὁντινοῦν ποιεῖσθαι λόγον.
+
+ Δημοσθένους, Γ´ ᾿Ολυνθιακὸς
+
+Georgian:
+
+ From a Unicode conference invitation:
+
+ გთხოვთ ახლავე გაიაროთ რეგისტრაცია Unicode-ის მეათე საერთაშორისო
+ კონფერენციაზე დასასწრებად, რომელიც გაიმართება 10-12 მარტს,
+ ქ. მაინცში, გერმანიაში. კონფერენცია შეჰკრებს ერთად მსოფლიოს
+ ექსპერტებს ისეთ დარგებში როგორიცაა ინტერნეტი და Unicode-ი,
+ ინტერნაციონალიზაცია და ლოკალიზაცია, Unicode-ის გამოყენება
+ ოპერაციულ სისტემებსა, და გამოყენებით პროგრამებში, შრიფტებში,
+ ტექსტების დამუშავებასა და მრავალენოვან კომპიუტერულ სისტემებში.
+
+Russian:
+
+ From a Unicode conference invitation:
+
+ Зарегистрируйтесь сейчас на Десятую Международную Конференцию по
+ Unicode, которая состоится 10-12 марта 1997 года в Майнце в Германии.
+ Конференция соберет широкий круг экспертов по вопросам глобального
+ Интернета и Unicode, локализации и интернационализации, воплощению и
+ применению Unicode в различных операционных системах и программных
+ приложениях, шрифтах, верстке и многоязычных компьютерных системах.
+
+Thai (UCS Level 2):
+
+ Excerpt from a poetry on The Romance of The Three Kingdoms (a Chinese
+ classic 'San Gua'):
+
+ [----------------------------|------------------------]
+ ๏ แผ่นดินฮั่นเสื่อมโทรมแสนสังเวช พระปกเกศกองบู๊กู้ขึ้นใหม่
+ สิบสองกษัตริย์ก่อนหน้าแลถัดไป สององค์ไซร้โง่เขลาเบาปัญญา
+ ทรงนับถือขันทีเป็นที่พึ่ง บ้านเมืองจึงวิปริตเป็นนักหนา
+ โฮจิ๋นเรียกทัพทั่วหัวเมืองมา หมายจะฆ่ามดชั่วตัวสำคัญ
+ เหมือนขับไสไล่เสือจากเคหา รับหมาป่าเข้ามาเลยอาสัญ
+ ฝ่ายอ้องอุ้นยุแยกให้แตกกัน ใช้สาวนั้นเป็นชนวนชื่นชวนใจ
+ พลันลิฉุยกุยกีกลับก่อเหตุ ช่างอาเพศจริงหนาฟ้าร้องไห้
+ ต้องรบราฆ่าฟันจนบรรลัย ฤๅหาใครค้ำชูกู้บรรลังก์ ฯ
+
+ (The above is a two-column text. If combining characters are handled
+ correctly, the lines of the second column should be aligned with the
+ | character above.)
+
+Ethiopian:
+
+ Proverbs in the Amharic language:
+
+ ሰማይ አይታረስ ንጉሥ አይከሰስ።
+ ብላ ካለኝ እንደአባቴ በቆመጠኝ።
+ ጌጥ ያለቤቱ ቁምጥና ነው።
+ ደሀ በሕልሙ ቅቤ ባይጠጣ ንጣት በገደለው።
+ የአፍ ወለምታ በቅቤ አይታሽም።
+ አይጥ በበላ ዳዋ ተመታ።
+ ሲተረጉሙ ይደረግሙ።
+ ቀስ በቀስ፥ ዕንቁላል በእግሩ ይሄዳል።
+ ድር ቢያብር አንበሳ ያስር።
+ ሰው እንደቤቱ እንጅ እንደ ጉረቤቱ አይተዳደርም።
+ እግዜር የከፈተውን ጉሮሮ ሳይዘጋው አይድርም።
+ የጎረቤት ሌባ፥ ቢያዩት ይስቅ ባያዩት ያጠልቅ።
+ ሥራ ከመፍታት ልጄን ላፋታት።
+ ዓባይ ማደሪያ የለው፥ ግንድ ይዞ ይዞራል።
+ የእስላም አገሩ መካ የአሞራ አገሩ ዋርካ።
+ ተንጋሎ ቢተፉ ተመልሶ ባፉ።
+ ወዳጅህ ማር ቢሆን ጨርስህ አትላሰው።
+ እግርህን በፍራሽህ ልክ ዘርጋ።
+
+Runes:
+
+ ᚻᛖ ᚳᚹᚫᚦ ᚦᚫᛏ ᚻᛖ ᛒᚢᛞᛖ ᚩᚾ ᚦᚫᛗ ᛚᚪᚾᛞᛖ ᚾᚩᚱᚦᚹᛖᚪᚱᛞᚢᛗ ᚹᛁᚦ ᚦᚪ ᚹᛖᛥᚫ
+
+ (Old English, which transcribed into Latin reads 'He cwaeth that he
+ bude thaem lande northweardum with tha Westsae.' and means 'He said
+ that he lived in the northern land near the Western Sea.')
+
+Braille:
+
+ ⡌⠁⠧⠑ ⠼⠁⠒ ⡍⠜⠇⠑⠹⠰⠎ ⡣⠕⠌
+
+ ⡍⠜⠇⠑⠹ ⠺⠁⠎ ⠙⠑⠁⠙⠒ ⠞⠕ ⠃⠑⠛⠔ ⠺⠊⠹⠲ ⡹⠻⠑ ⠊⠎ ⠝⠕ ⠙⠳⠃⠞
+ ⠱⠁⠞⠑⠧⠻ ⠁⠃⠳⠞ ⠹⠁⠞⠲ ⡹⠑ ⠗⠑⠛⠊⠌⠻ ⠕⠋ ⠙⠊⠎ ⠃⠥⠗⠊⠁⠇ ⠺⠁⠎
+ ⠎⠊⠛⠝⠫ ⠃⠹ ⠹⠑ ⠊⠇⠻⠛⠹⠍⠁⠝⠂ ⠹⠑ ⠊⠇⠻⠅⠂ ⠹⠑ ⠥⠝⠙⠻⠞⠁⠅⠻⠂
+ ⠁⠝⠙ ⠹⠑ ⠡⠊⠑⠋ ⠍⠳⠗⠝⠻⠲ ⡎⠊⠗⠕⠕⠛⠑ ⠎⠊⠛⠝⠫ ⠊⠞⠲ ⡁⠝⠙
+ ⡎⠊⠗⠕⠕⠛⠑⠰⠎ ⠝⠁⠍⠑ ⠺⠁⠎ ⠛⠕⠕⠙ ⠥⠏⠕⠝ ⠰⡡⠁⠝⠛⠑⠂ ⠋⠕⠗ ⠁⠝⠹⠹⠔⠛ ⠙⠑
+ ⠡⠕⠎⠑ ⠞⠕ ⠏⠥⠞ ⠙⠊⠎ ⠙⠁⠝⠙ ⠞⠕⠲
+
+ ⡕⠇⠙ ⡍⠜⠇⠑⠹ ⠺⠁⠎ ⠁⠎ ⠙⠑⠁⠙ ⠁⠎ ⠁ ⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲
+
+ ⡍⠔⠙⠖ ⡊ ⠙⠕⠝⠰⠞ ⠍⠑⠁⠝ ⠞⠕ ⠎⠁⠹ ⠹⠁⠞ ⡊ ⠅⠝⠪⠂ ⠕⠋ ⠍⠹
+ ⠪⠝ ⠅⠝⠪⠇⠫⠛⠑⠂ ⠱⠁⠞ ⠹⠻⠑ ⠊⠎ ⠏⠜⠞⠊⠊⠥⠇⠜⠇⠹ ⠙⠑⠁⠙ ⠁⠃⠳⠞
+ ⠁ ⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲ ⡊ ⠍⠊⠣⠞ ⠙⠁⠧⠑ ⠃⠑⠲ ⠔⠊⠇⠔⠫⠂ ⠍⠹⠎⠑⠇⠋⠂ ⠞⠕
+ ⠗⠑⠛⠜⠙ ⠁ ⠊⠕⠋⠋⠔⠤⠝⠁⠊⠇ ⠁⠎ ⠹⠑ ⠙⠑⠁⠙⠑⠌ ⠏⠊⠑⠊⠑ ⠕⠋ ⠊⠗⠕⠝⠍⠕⠝⠛⠻⠹
+ ⠔ ⠹⠑ ⠞⠗⠁⠙⠑⠲ ⡃⠥⠞ ⠹⠑ ⠺⠊⠎⠙⠕⠍ ⠕⠋ ⠳⠗ ⠁⠝⠊⠑⠌⠕⠗⠎
+ ⠊⠎ ⠔ ⠹⠑ ⠎⠊⠍⠊⠇⠑⠆ ⠁⠝⠙ ⠍⠹ ⠥⠝⠙⠁⠇⠇⠪⠫ ⠙⠁⠝⠙⠎
+ ⠩⠁⠇⠇ ⠝⠕⠞ ⠙⠊⠌⠥⠗⠃ ⠊⠞⠂ ⠕⠗ ⠹⠑ ⡊⠳⠝⠞⠗⠹⠰⠎ ⠙⠕⠝⠑ ⠋⠕⠗⠲ ⡹⠳
+ ⠺⠊⠇⠇ ⠹⠻⠑⠋⠕⠗⠑ ⠏⠻⠍⠊⠞ ⠍⠑ ⠞⠕ ⠗⠑⠏⠑⠁⠞⠂ ⠑⠍⠏⠙⠁⠞⠊⠊⠁⠇⠇⠹⠂ ⠹⠁⠞
+ ⡍⠜⠇⠑⠹ ⠺⠁⠎ ⠁⠎ ⠙⠑⠁⠙ ⠁⠎ ⠁ ⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲
+
+ (The first couple of paragraphs of "A Christmas Carol" by Dickens)
+
+Compact font selection example text:
+
+ ABCDEFGHIJKLMNOPQRSTUVWXYZ /0123456789
+ abcdefghijklmnopqrstuvwxyz £©µÀÆÖÞßéöÿ
+ –—‘“”„†•…‰™œŠŸž€ ΑΒΓΔΩαβγδω АБВГДабвгд
+ ∀∂∈ℝ∧∪≡∞ ↑↗↨↻⇣ ┐┼╔╘░►☺♀ fi�⑀₂ἠḂӥẄɐː⍎אԱა
+
+Greetings in various languages:
+
+ Hello world, Καλημέρα κόσμε, コンニチハ
+
+Box drawing alignment tests: █
+ ▉
+ ╔══╦══╗ ┌──┬──┐ ╭──┬──╮ ╭──┬──╮ ┏━━┳━━┓ ┎┒┏┑ ╷ ╻ ┏┯┓ ┌┰┐ ▊ ╱╲╱╲╳╳╳
+ ║┌─╨─┐║ │╔═╧═╗│ │╒═╪═╕│ │╓─╁─╖│ ┃┌─╂─┐┃ ┗╃╄┙ ╶┼╴╺╋╸┠┼┨ ┝╋┥ ▋ ╲╱╲╱╳╳╳
+ ║│╲ ╱│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╿ │┃ ┍╅╆┓ ╵ ╹ ┗┷┛ └┸┘ ▌ ╱╲╱╲╳╳╳
+ ╠╡ ╳ ╞╣ ├╢ ╟┤ ├┼─┼─┼┤ ├╫─╂─╫┤ ┣┿╾┼╼┿┫ ┕┛┖┚ ┌┄┄┐ ╎ ┏┅┅┓ ┋ ▍ ╲╱╲╱╳╳╳
+ ║│╱ ╲│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╽ │┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▎
+ ║└─╥─┘║ │╚═╤═╝│ │╘═╪═╛│ │╙─╀─╜│ ┃└─╂─┘┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▏
+ ╚══╩══╝ └──┴──┘ ╰──┴──╯ ╰──┴──╯ ┗━━┻━━┛ └╌╌┘ ╎ ┗╍╍┛ ┋ ▁▂▃▄▅▆▇█
+
+</pre>
+</body>
+</html>
diff --git a/example/build.sh b/example/build.sh
new file mode 100755
index 0000000..172aa69
--- /dev/null
+++ b/example/build.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+CFLAGS='-g -Wall'
+INCLUDE='-I..'
+LIBS='-lm'
+set -x
+#tcc $CFLAGS $INCLUDE $LIBS -o example example.c && ./example
+gcc $CFLAGS $INCLUDE $LIBS -o example example.c && ./example
diff --git a/example/example b/example/example
new file mode 100755
index 0000000..15b5b35
--- /dev/null
+++ b/example/example
Binary files differ
diff --git a/example/example.c b/example/example.c
new file mode 100644
index 0000000..1fa85b3
--- /dev/null
+++ b/example/example.c
@@ -0,0 +1,260 @@
+#include "prb.h"
+
+typedef struct {
+ S32 first;
+ S32 second;
+ B32 flags;
+} SomeStruct;
+
+typedef struct SLLNode {
+ S32 val;
+ struct SLLNode *next;
+} SLLNode;
+
+typedef struct DLLNode {
+ S32 val;
+ struct DLLNode *next;
+ struct DLLNode *prev;
+} DLLNode;
+
+int main(void)
+{
+ F32 verts[] = {
+ 1.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f
+ };
+
+ Assert(v3a(1.0f).y);
+ U64 memory_size = Kilobytes(4);
+ void *some_memory = malloc(memory_size);
+ *(S32 *)some_memory = 69;
+ U64 ptr_as_int = IntFromPtr(some_memory);
+ void *ptr_to_memory = PtrFromInt(ptr_as_int);
+ printf("IntFromPtr: %lu\n", ptr_as_int);
+ printf("Using PtrFromInt(%lu) to get the first element of some_memory: %d\n\n",
+ ptr_as_int, *(S32 *)ptr_to_memory);
+ free(some_memory);
+
+ printf("OffsetOfMember(SomeStruct, flags): %lld\n\n",
+ OffsetOfMember(SomeStruct, flags));
+
+ F32 range_min = 0.0f, range_max = 1.0f;
+ F32 clamped_number = 1.5f;
+ F32 another_clamped_number = -0.2f;
+ printf("ClampBottom(%f, %f): %f\n", range_min,
+ another_clamped_number, ClampBottom(another_clamped_number, range_min));
+ printf("ClampTop(%f, %f): %f\n", range_max,
+ clamped_number, ClampTop(clamped_number, range_max));
+
+ printf("Clamp(%f, %f, %f): %f\n", range_min, clamped_number, range_max,
+ Clamp(range_min, clamped_number, range_max));
+ printf("Clamp(%f, %f, %f): %f\n\n", range_min, another_clamped_number, range_max,
+ Clamp(range_min, another_clamped_number, range_max));
+
+ F32 swap_test_first = 10.0f, swap_test_second = 20.0f;
+ printf("Before Swap: swap_test_first = %f, swap_test_second = %f\n",
+ swap_test_first, swap_test_second);
+ Swap(F32, swap_test_first, swap_test_second);
+ printf("After Swap: swap_test_first = %f, swap_test_second = %f\n\n",
+ swap_test_first, swap_test_second);
+
+ SomeStruct some_stuct = { 10, 20, 30 };
+ printf("SomeStruct: first: %d, second: %d, flags: %d\n",
+ some_stuct.first, some_stuct.second, some_stuct.flags);
+ MemoryZero(&some_stuct, sizeof(SomeStruct));
+ printf("After MemoryZero(&some_stuct, sizeof(SomeStruct)):\n");
+ printf("some_stuct: first: %d, second: %d, flags: %d\n\n",
+ some_stuct.first, some_stuct.second, some_stuct.flags);
+
+ some_stuct = (SomeStruct){ 10, 20, 30 };
+ printf("some_stuct: first: %d, second: %d, flags: %d\n",
+ some_stuct.first, some_stuct.second, some_stuct.flags);
+ MemoryZeroStruct(&some_stuct);
+ printf("After MemoryZeroStruct(&some_stuct):\n");
+ printf("some_stuct: first: %d, second: %d, flags: %d\n\n",
+ some_stuct.first, some_stuct.second, some_stuct.flags);
+
+ printf("Before MemoryZeroArray:\n");
+ for (S32 i = 0; i < ArrayCount(verts); ++i)
+ printf("%f%c", verts[i], (((i+1)%4 == 0) ||
+ (i == ArrayCount(verts)-1)) ? '\n' : ' ');
+ MemoryZeroArray(verts);
+ printf("After:\n");
+ for (S32 i = 0; i < ArrayCount(verts); ++i)
+ printf("%f%c", verts[i], (((i+1)%4 == 0) ||
+ (i == ArrayCount(verts)-1)) ? '\n' : ' ');
+ printf("\n");
+
+ S32 dynamic_array_length = 10;
+ U64 dynamic_array_size = dynamic_array_length*sizeof(S32);
+ F32 *dynamic_array_first = malloc(dynamic_array_size);
+ F32 *dynamic_array_second = malloc(dynamic_array_size);
+ printf("first dynamic array:\n");
+ for (S32 i = 0; i < dynamic_array_length; ++i) {
+ F32 *element = dynamic_array_first+i;
+ *element = i+420;
+ printf("%f%c", *element, (i == dynamic_array_length-1) ? '\n' : ' ');
+ }
+ printf("second dynamic array:\n");
+ for (S32 i = 0; i < dynamic_array_length; ++i) {
+ F32 *element = dynamic_array_second+i;
+ printf("%f%c", *element, (i == dynamic_array_length-1) ? '\n' : ' ');
+ }
+ MemoryCopy(dynamic_array_second, dynamic_array_first, dynamic_array_size);
+ printf("After MemoryCopy(dynamic_array_second, dynamic_array_first, dynamic_array_size):\n");
+ printf("second dynamic array:\n");
+ for (S32 i = 0; i < dynamic_array_length; ++i) {
+ F32 *element = dynamic_array_second+i;
+ printf("%f%c", *element, (i == dynamic_array_length-1) ? '\n' : ' ');
+ }
+ S32 memory_match = MemoryMatch(dynamic_array_first, dynamic_array_second, dynamic_array_size);
+ printf("And MemoryMatch(MemoryMatch(dynamic_array_first, dynamic_array_second, dynamic_array_size): %d\n\n", memory_match);
+ free(dynamic_array_first);
+ free(dynamic_array_second);
+
+ printf("Linked Lists:\n");
+ printf("Singly linked list: ");
+ S32 list_length = 5;
+ U64 list_size = list_length*sizeof(SLLNode);
+ SLLNode *sllist = malloc(list_size);
+ SLLNode *sllfirst = 0;
+ SLLNode *slllast = 0;
+ for (S32 i = 0; i < list_length; ++i) {
+ SLLNode *new = sllist+i;
+ new->val = i;
+ SLLPush(sllfirst, slllast, new);
+ }
+ for (SLLNode *node = sllfirst; node; node = node->next)
+ printf("%d%s", node->val, ((node->next) ? " -> " : "\n"));
+ SLLPop(sllfirst, slllast);
+ printf("After SLLPop(sllfirst, slllast): ");
+ for (SLLNode *node = sllfirst; node; node = node->next)
+ printf("%d%s", node->val, ((node->next) ? " -> " : "\n"));
+ free(sllist);
+
+ printf("Doubly linked list: ");
+ list_length = 8;
+ list_size = list_length*sizeof(DLLNode);
+ DLLNode *dllist = malloc(list_size);
+ DLLNode *dllfirst = 0;
+ DLLNode *dlllast = 0;
+ for (S32 i = 0; i < list_length; ++i) {
+ DLLNode *new = dllist+i;
+ new->val = i;
+ DLLPushBack(dllfirst, dlllast, new);
+ }
+ for (DLLNode *node = dllfirst; node; node = node->next)
+ printf("%d%s", node->val, ((node->next) ? " -> " : "\n"));
+ printf("Remove odd numbers: ");
+ for (DLLNode *node = dllfirst; node; node = node->next)
+ if (node->val % 2 == 1)
+ DLLRemove(dllfirst, dlllast, node);
+ for (DLLNode *node = dllfirst; node; node = node->next)
+ printf("%d%s", node->val, ((node->next) ? " -> " : "\n"));
+ free(dllist);
+ printf("\n");
+
+ printf("I'm pretty sure the vectors are fine.\nAt least for the last few months :)\n\n");
+
+ printf("Matrices:\n");
+ printf("Identity:\n");
+ Mat4 m = MAT4_IDENTITY;
+ mat4print(m);
+ m = mat4scale(m, v3a(10.0f));
+ m = mat4translate(m, v3a(1.0f));
+ m = mat4translate(m, v3(0.0f, 68.0f, 0.0f));
+ mat4print(m);
+ printf("Determinant: %f\n", mat4det(m));
+ printf("Transpose:\n"); mat4print(mat4transpose(m));
+ printf("mat4rotate(MAT4_IDENTITY, v3(0.0f, 45.0f, 0.0f)):\n");
+ mat4print(mat4rotate(MAT4_IDENTITY, v3(0.0f, 45.0f, 0.0f)));
+
+ printf("Using Arenas:\n");
+ Arena *a = arena_alloc(0);
+ SLLNode *first = 0;
+ SLLNode *last = 0;
+ S32 node_count = 10;
+ for (S32 i = 0; i < node_count; ++i) {
+ SLLNode *new = arena_push(a, sizeof(SLLNode));
+ new->val = i;
+ SLLPush(first, last, new);
+ }
+ for (SLLNode *node = first; node; node = node->next)
+ printf("%d%s", node->val, ((node->next) ? " -> " : "\n"));
+ arena_release(a);
+
+ a = arena_alloc(sizeof(verts));
+ S32 verts_count = ArrayCount(verts);
+ F32 *dynamic_verts = arena_push(a, sizeof(verts));
+ MemoryZero(dynamic_verts, verts_count*sizeof(F32));
+ for (S32 i = 0; i < verts_count; ++i) {
+ F32 *vert = dynamic_verts+i;
+ printf("%f%c", *vert, (i == verts_count-1) ? '\n' : ' ');
+ }
+ arena_release(a);
+ printf("\n");
+
+ Arena *str_arena = arena_alloc(0);
+ printf("Strings:\n");
+ char *cstr = "This is a C str\n";
+ Str8 str = str8_from_cstr(cstr);
+ str = str8_chop_start(str, 10);
+ cstr = str8_to_cstr(a, str);
+ printf("%s", cstr);
+ str8print(str);
+ Str8 choped_str = str8_chop_end(str, 3);
+ str8print(choped_str);
+ printf("\n");
+ Str8List *list = str8_list(str_arena);
+ str8_list_push(str_arena, list, str, 0);
+ str8_list_push(str_arena, list, str8_from_cstr("test"), 0);
+ str8_list_push(str_arena, list, str8_from_cstr("and this is also a test\n"), 0);
+ str8_list_push(str_arena, list, str8_from_cstr("Kinda works!"), 1);
+ printf("Str8List: ");
+ str8_list_print(list);
+ arena_release(str_arena);
+ str8_list_print(list);
+
+ str_arena = arena_alloc(Kilobytes(10));
+ memory_size = 512;
+ U32 count = memory_size/sizeof(S32);
+ S32 *some = arena_push(str_arena, memory_size);
+ printf("str_arena(size): %ld\nMemory:\n", str_arena->cap);
+ for (S32 i = 0; i < count; i++) {
+ S32 *e = some+i;
+ *e = 69;
+ printf("%d: %d%c", i, *e, ((i == count-1) ? '\n' : ' '));
+ }
+ printf("Memory used: %lu\n", str_arena->used);
+ printf("Remaining memory: %lu\n",
+ str_arena->cap-str_arena->used);
+
+ arena_pop(str_arena, memory_size);
+
+ printf("After arena pop\n");
+ printf("Memory used: %lu\n", str_arena->used);
+ printf("Remaining memory: %lu\n",
+ str_arena->cap-str_arena->used);
+ printf("some ptr is %s\n", some ? "not null" : "null");
+ printf("str_arena(size): %lu\nMemory:\n", str_arena->cap);
+
+ Str8 new_str = str8_pushf(str_arena, "Test of the formatted string: %d\n", 69);
+ str8print(new_str);
+
+ list = str8_list(str_arena);
+ str8_list_pushf(str_arena, list, 0, "This is a list %d", 34);
+ str8_list_pushf(str_arena, list, 0, " of formatted strings: %d", 35);
+ str8_list_pushf(str_arena, list, 1, "And you can push to the start");
+ str8_list_print(list);
+
+ arena_release(str_arena);
+
+ a = arena_alloc(Megabytes(1));
+ str8print(str8lit("build.sh content:\n"));
+ Str8 file_content = str8_read_entire_file(a, str8lit("build.sh"));
+ str8print(file_content);
+ arena_release(a);
+
+ return(0);
+}