Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "core:fmt"
- import "core:os"
- import s "core:strings"
- main::proc(){
- switch len(os.args) {
- case 1:
- fmt.print(man)
- case 2, 3:
- err : os.Error
- odin_source : s.Builder
- defer s.builder_destroy(&odin_source)
- odin_file : s.Builder
- defer s.builder_destroy(&odin_file)
- s.write_string(&odin_file, os.args[1])
- s.write_string(&odin_file, ".odin")
- if err = os.make_directory(os.args[1]); err != os.ERROR_NONE {
- fmt.println(os.error_string(err))
- break
- }
- os.change_directory(os.args[1])
- s.write_string(&odin_source, "package ")
- s.write_string(&odin_source, os.args[1])
- s.write_string(&odin_source, "\n\n")
- if len(os.args) == 2 {
- s.write_string(&odin_source, hello_world)
- } else {
- if os.args[2] == "hello-world" do s.write_string(&odin_source, hello_world)
- if os.args[2] == "track-alloc" do s.write_string(&odin_source, track_alloc)
- if os.args[2] == "raylib" do s.write_string(&odin_source, raylib_template)
- }
- os.write_entire_file( s.to_string(odin_file), odin_source.buf[:] )
- case:
- fmt.println("Too many arguments")
- fmt.println("\n", man)
- }
- }
- man :string = `
- odininit a tool for quickly starting new odin programs
- usage:
- odininit program_name [program_template]
- If no program_template is provided, a hello world
- program is created.
- program_name:
- creates a folder of program_name, if one does not exist
- changes directory to that folder and creates necessary
- template files there.
- program_templates:
- hello-world
- track-alloc
- raylib
- `
- hello_world :string = `
- import "core:fmt"
- main :: proc() {
- fmt.println("Hellope")
- }`
- track_alloc : string = `
- import "core:mem"
- import "core:fmt"
- _main :: proc() {
- fmt.println("Hellope")
- }
- main :: proc() {
- track: mem.Tracking_Allocator
- mem.tracking_allocator_init(&track, context.allocator)
- defer mem.tracking_allocator_destroy(&track)
- context.allocator = mem.tracking_allocator(&track)
- _main()
- for _, leak in track.allocation_map {
- fmt.printf("%v leaked %m\n", leak.location, leak.size)
- }
- for bad_free in track.bad_free_array {
- fmt.printf("%v allocation %p was freed badly\n", bad_free.location, bad_free.memory)
- }
- }
- `
- raylib_template : string = `
- import rl "vendor:raylib"
- main :: proc() {
- rl.InitWindow(800, 400, "Raylib Basic Window")
- for !rl.WindowShouldClose() {
- rl.BeginDrawing()
- rl.ClearBackground(rl.LIGHTGRAY)
- rl.DrawText("Hellope!", 190, 200, 40, rl.DARKGRAY)
- rl.EndDrawing()
- }
- rl.CloseWindow()
- }`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement