From dfda6b6e55f75cc0dd77b13b08d83d8ca3b3842f Mon Sep 17 00:00:00 2001 From: pryazha Date: Thu, 11 Sep 2025 19:22:37 +0500 Subject: change final build target to libprb.a that one can link with --- example/UTF-8-demo.html | 213 ------------------------------------------------ example/arena.c | 11 +-- example/build.sh | 45 ++++++---- example/macros.c | 110 +++++++------------------ example/string.c | 41 +++------- example/sys.c | 55 +++++-------- 6 files changed, 96 insertions(+), 379 deletions(-) delete mode 100644 example/UTF-8-demo.html (limited to 'example') diff --git a/example/UTF-8-demo.html b/example/UTF-8-demo.html deleted file mode 100644 index b8157db..0000000 --- a/example/UTF-8-demo.html +++ /dev/null @@ -1,213 +0,0 @@ - - - UTF-8 test file - -

Original by Markus Kuhn, adapted for HTML by Martin Dürst.

-
-UTF-8 encoded sample plain-text file
-‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
-
-Markus Kuhn [ˈmaʳkʊs kuːn] <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⌋, α ∧ ¬β = ¬(¬α ∨ β),
-
-  ℕ ⊆ ℕ₀ ⊂ ℤ ⊂ ℚ ⊂ ℝ ⊂ ℂ, ⊥ < 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:                                          █
-                                                                      ▉
-  ╔══╦══╗  ┌──┬──┐  ╭──┬──╮  ╭──┬──╮  ┏━━┳━━┓  ┎┒┏┑   ╷  ╻ ┏┯┓ ┌┰┐    ▊ ╱╲╱╲╳╳╳
-  ║┌─╨─┐║  │╔═╧═╗│  │╒═╪═╕│  │╓─╁─╖│  ┃┌─╂─┐┃  ┗╃╄┙  ╶┼╴╺╋╸┠┼┨ ┝╋┥    ▋ ╲╱╲╱╳╳╳
-  ║│╲ ╱│║  │║   ║│  ││ │ ││  │║ ┃ ║│  ┃│ ╿ │┃  ┍╅╆┓   ╵  ╹ ┗┷┛ └┸┘    ▌ ╱╲╱╲╳╳╳
-  ╠╡ ╳ ╞╣  ├╢   ╟┤  ├┼─┼─┼┤  ├╫─╂─╫┤  ┣┿╾┼╼┿┫  ┕┛┖┚     ┌┄┄┐ ╎ ┏┅┅┓ ┋ ▍ ╲╱╲╱╳╳╳
-  ║│╱ ╲│║  │║   ║│  ││ │ ││  │║ ┃ ║│  ┃│ ╽ │┃  ░░▒▒▓▓██ ┊  ┆ ╎ ╏  ┇ ┋ ▎
-  ║└─╥─┘║  │╚═╤═╝│  │╘═╪═╛│  │╙─╀─╜│  ┃└─╂─┘┃  ░░▒▒▓▓██ ┊  ┆ ╎ ╏  ┇ ┋ ▏
-  ╚══╩══╝  └──┴──┘  ╰──┴──╯  ╰──┴──╯  ┗━━┻━━┛           └╌╌┘ ╎ ┗╍╍┛ ┋  ▁▂▃▄▅▆▇█
-
-
- - diff --git a/example/arena.c b/example/arena.c index addf4ee..6579849 100644 --- a/example/arena.c +++ b/example/arena.c @@ -1,14 +1,15 @@ #include "prb.h" +#include +#include i32 main(void) { - printf("Arenas:\n"); - - arena_t arena = alloc_arena(10); + info("arenas"); + struct arena arena = alloc_arena(10); u8 *first = push_arena(&arena, 5); - prb_memset(first, 5, 5); + memset(first, 5, 5); u8 *second = push_arena(&arena, 5); - prb_memset(second, 10, 5); + memset(second, 10, 5); printf("|"); for (i32 i = 0; i < 10; i++) printf("%x%s", first[i], ((i+1) % 5 == 0) ? "|" : " "); diff --git a/example/build.sh b/example/build.sh index e6cee7c..285b072 100755 --- a/example/build.sh +++ b/example/build.sh @@ -1,22 +1,31 @@ #!/bin/sh -compiler='gcc' -path=`dirname $0` -cd $path -if [ $# -eq 1 ] ; then - if [ $1 = 'windows' ] ; then - compiler='x86_64-w64-mingw32-gcc' - fi - if [ $1 = 'clean' ] ; then - set -x - rm -f macros macros.exe arena arena.exe sys sys.exe string string.exe - exit - fi +start=`pwd` +dir=`dirname "$0"` +if [ "$1" = 'clean' ] ; then + set -x + cd "$dir" + rm -f macros macros.exe arena arena.exe sys sys.exe string string.exe + cd "$start" + exit fi +cc='tcc' +if [ "$1" = 'windows' ] ; then + cc='x86_64-w64-mingw32-gcc' +fi +libsdir='../..' +if [ ! -d "$libsdir/prb" ] ; then + echo "error: failed to get prb library path" + exit +fi +"$libsdir/prb/build.sh" cflags='-g -Wall' -include='-I..' -libs='-lm' +include="-I$libsdir/prb" +lflags="-L$libsdir/prb" +libs='-lprb' set -x -$compiler $cflags $include -o macros macros.c $libs -$compiler $cflags $include -o arena arena.c $libs -$compiler $cflags $include -o sys sys.c $libs -$compiler $cflags $include -o string string.c $libs +cd "$dir" +$cc $cflags $include $lflags -o macros macros.c $libs +$cc $cflags $include $lflags -o arena arena.c $libs +$cc $cflags $include $lflags -o sys sys.c $libs +$cc $cflags $include $lflags -o string string.c $libs +cd "$start" diff --git a/example/macros.c b/example/macros.c index 169a2ca..0e836b0 100644 --- a/example/macros.c +++ b/example/macros.c @@ -1,96 +1,44 @@ #include "prb.h" +#include -typedef struct { - i32 i32_element; - i16 i16_element; - u8 u8_element; -} type_t; +struct type { + i32 i32_element; + i16 i16_element; + u8 u8_element; +}; -#define MAX_NODES 10 +#define nodes_count 10 -typedef struct stack_node_t { - i32 value; - struct stack_node_t *next; -} stack_node_t; +struct stack_node { + i32 value; + struct stack_node *next; +}; -typedef struct { - stack_node_t *first; - stack_node_t *last; -} stack_t; +struct stack { + struct stack_node *first; + struct stack_node *last; +}; -typedef struct node_t { - i32 value; - struct node_t *next; - struct node_t *prev; -} node_t; - -typedef struct { - node_t *first; - node_t *last; -} list_t; +static void print_stack(struct stack s) +{ + for (struct stack_node *node = s.first; node; node = node->next) + printf("%d%s", node->value, ((node->next) ? " -> " : "\n")); +} i32 main(void) { - u64 offset = offsetof(type_t, u8_element); + u64 offset = offsetof(struct type, u8_element); assert(offset == 6); - printf("offsetof(type_t, u8_element) = %lu\n", offset); - i32 clamped = clamp(0, -1, 1); - assert(clamped == 0); - printf("clamp(0, -1, 1) = %d\n", clamped); - clamped = clamp(0, 2, 1); - assert(clamped == 1); - printf("clamp(0, 2, 1) = %d\n", clamped); - - i32 nums[] = {0, 1, 2, 3}; - printf("mem0: ["); - for (i32 i = 0; i < array_count(nums); ++i) - printf("%x%s", nums[i], (i == array_count(nums)-1) ? "" : ", "); - memzero(nums, sizeof(nums)); - printf("] -> ["); - for (i32 i = 0; i < array_count(nums); ++i) { - assert(!nums[i]); - printf("%x%s", nums[i], (i == array_count(nums)-1) ? "" : ", "); - } - printf("]\n\n"); - - printf("Singly linked list (stack for example):\n"); - - stack_node_t stack_nodes[MAX_NODES]; - stack_t stack = {0}; - for (i32 i = 0; i < MAX_NODES; ++i) { - stack_node_t *node = stack_nodes+i; + info("offsetof(type_t, u8_element) = %lu", offset); + info("stack:"); + struct stack_node nodes[nodes_count]; + struct stack stack = {0}; + for (i32 i = 0; i < array_count(nodes); ++i) { + struct stack_node *node = nodes + i; node->value = i; sllpush(stack.first, stack.last, node); } - - for (stack_node_t *node = stack.first; node; node = node->next) - printf("%d%s", node->value, ((node->next) ? " -> " : "\n")); - + print_stack(stack); sllpop(stack.first, stack.last); - - printf("After pop:\n"); - for (stack_node_t *node = stack.first; node; node = node->next) - printf("%d%s", node->value, ((node->next) ? " -> " : "\n")); - - node_t nodes[MAX_NODES]; - list_t list = {0}; - for (i32 i = 0; i < MAX_NODES; ++i) { - node_t *node = nodes+i; - node->value = i; - dllpushback(list.first, list.last, node); - } - - printf("Doubly linked list:\n"); - for (node_t *node = list.first; node; node = node->next) - printf("%d%s", node->value, ((node->next) ? " -> " : "\n")); - - printf("Remove odd numbers:\n"); - for (node_t *node = list.first; node; node = node->next) - if (node->value % 2 == 1) - dllremove(list.first, list.last, node); - - for (node_t *node = list.first; node; node = node->next) - printf("%d%s", node->value, ((node->next) ? " -> " : "\n")); - - printf("\n"); + print_stack(stack); } diff --git a/example/string.c b/example/string.c index fbd0943..57c460d 100644 --- a/example/string.c +++ b/example/string.c @@ -2,33 +2,18 @@ i32 main(void) { - printf("Strings:\n"); - - arena_t str_arena = alloc_arena(0); - str8_list_t strlist = {0}; - str8_list_push(&str_arena, &strlist, 0, str8lit("first ")); - str8_list_push(&str_arena, &strlist, 0, str8lit("second ")); - str8_list_push(&str_arena, &strlist, 0, str8lit("third\n")); - str8_print(str8lit("strlist: ")); - str8_list_print(&strlist); - - str8_t fstr = str8_pushf(&str_arena, "Formatted string: %d\n", 69); - str8_print(fstr); - - memzero_struct(&strlist); - str8_list_pushf(&str_arena, &strlist, 0, "first %d -> ", 34); - str8_list_pushf(&str_arena, &strlist, 0, "second: %d -> ", 35); - str8_list_pushf(&str_arena, &strlist, 0, "sum: %d\n", 34+35); - str8_list_pushf(&str_arena, &strlist, 1, "%s", "To the front -> "); - - str8_print(str8lit("Formatted string list:\n")); - str8_list_print(&strlist); - - str8_t catstr = str8_list_join(&str_arena, &strlist); - str8_print(str8lit("Concatenated string list:\n")); - str8_print(catstr); - - release_arena(&str_arena); - + struct arena arena = alloc_arena(0); + struct string fstr = push_fstring(&arena, "formatted string: %d\n", 69); + print_string(fstr); + info("string list:"); + struct string_list list = {0}; + push_fstring_to_list(&arena, &list, 0, "first %d -> ", 34); + push_fstring_to_list(&arena, &list, 0, "second: %d -> ", 35); + push_fstring_to_list(&arena, &list, 0, "sum: %d\n", 34+35); + push_fstring_to_list(&arena, &list, 1, "%s", "To the front -> "); + print_string_list(&list); + struct string catstr = join_string_list(&arena, &list); + info("Concatenated string list:"); + print_string(catstr); return(0); } diff --git a/example/sys.c b/example/sys.c index f9f5c33..881d2be 100644 --- a/example/sys.c +++ b/example/sys.c @@ -1,43 +1,30 @@ #include "prb.h" +#include +#include -i32 main(void) +i32 main(int c, char **v) { - void *mem; - arena_t arena; - char *dir, *content, *path; - const char *filename = "build.sh"; - - printf("os: "); - switch (OS) { - case OS_LINUX: - printf("linux\n"); + info("os:"); + switch (os) { + case os_linux: + info("linux"); break; - case OS_WINDOWS: - printf("windows\n"); + case os_windows: + info("windows"); break; default: - printf("unsupported\n"); + info("unsupported"); return 1; } - - mem = sys_alloc(megabytes(32)); - assert(mem); - sys_free(mem, megabytes(32)); - - arena = alloc_arena(megabytes(32)); - - dir = sys_getbindir(&arena); - printf("bin directory \"%s\"\n", dir); - - path = push_arena(&arena, MAX_PATH); - memset(path, 0, MAX_PATH); - snprintf(path, MAX_PATH, "%s/%s", dir, filename); - - if (sys_read_file(&arena, &content, path)) - printf("%s content:\n%s", path, content); - else - printf("failed to read %s\n", path); - - if (!sys_read_file(&arena, &content, filename)) - die("failed to read %s\n", filename); + char *dir = dirname(*v); + info("bin directory \"%s\"", dir); + const char *filename = "build.sh"; + char path[1024] = {0}; + snprintf(path, 1024, "%s/%s", dir, filename); + struct arena arena = alloc_arena(megabytes(32)); + char *content = 0; + if (!(content = read_entire_file(&arena, 0, path))) + die("failed to read %s", path); + info("%s content:\n%s", path, content); + return 0; } -- cgit v1.2.3-70-g09d2