Warning, /frameworks/syntax-highlighting/autotests/folding/test.odin.fold is written in an unsupported language. File is not indexed.
0001 // This is from Odin examples: 0002 // https://github.com/odin-lang/examples/blob/master/by_example/dir_info/main.odin 0003 0004 package main 0005 0006 import "core:fmt" 0007 import "core:os" 0008 import "core:path/filepath" 0009 import "core:strings" 0010 0011 print_file_info :: proc(fi: os.File_Info) <beginfold id='1'>{</beginfold id='1'> 0012 // Split the path into directory and filename 0013 _, filename := filepath.split(fi.fullpath) 0014 0015 SIZE_WIDTH :: 12 0016 buf: [SIZE_WIDTH]u8 0017 0018 // Print size to string backed by buf on stack, no need to free 0019 _size := "-" if fi.is_dir else fmt.bprintf(buf[:], "%v", fi.size) 0020 0021 // Right-justify size for display, heap allocated 0022 size := strings.right_justify(_size, SIZE_WIDTH, " ") 0023 defer delete(size) 0024 0025 if fi.is_dir <beginfold id='1'>{</beginfold id='1'> 0026 fmt.printf("%v [%v]\n", size, filename) 0027 <endfold id='1'>}</endfold id='1'> else <beginfold id='1'>{</beginfold id='1'> 0028 fmt.printf("%v %v\n", size, filename) 0029 <endfold id='1'>}</endfold id='1'> 0030 <endfold id='1'>}</endfold id='1'> 0031 0032 main :: proc() <beginfold id='1'>{</beginfold id='1'> 0033 cwd := os.get_current_directory() 0034 fmt.println("Current working directory:", cwd) 0035 0036 f, err := os.open(cwd) 0037 defer os.close(f) 0038 0039 if err != os.ERROR_NONE <beginfold id='1'>{</beginfold id='1'> 0040 // Print error to stderr and exit with errorcode 0041 fmt.eprintln("Could not open directory for reading", err) 0042 os.exit(1) 0043 <endfold id='1'>}</endfold id='1'> 0044 0045 fis: []os.File_Info 0046 defer os.file_info_slice_delete(fis) // fis is a slice, we need to remember to free it 0047 0048 fis, err = os.read_dir(f, -1) // -1 reads all file infos 0049 if err != os.ERROR_NONE <beginfold id='1'>{</beginfold id='1'> 0050 fmt.eprintln("Could not read directory", err) 0051 os.exit(2) 0052 <endfold id='1'>}</endfold id='1'> 0053 0054 for fi in fis <beginfold id='1'>{</beginfold id='1'> 0055 print_file_info(fi) 0056 <endfold id='1'>}</endfold id='1'> 0057 <endfold id='1'>}</endfold id='1'>