mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os.read_file(): replace C code with V, return ?string
, handle errors
everywhere
This commit is contained in:
@@ -762,13 +762,19 @@ fn new_v(args[]string) *V {
|
||||
// Location of all vlib files
|
||||
mut lang_dir = ''
|
||||
// First try fetching it from VROOT if it's defined
|
||||
for { // TODO tmp hack for optionals
|
||||
vroot_path := TmpPath + '/VROOT'
|
||||
if os.file_exists(vroot_path) {
|
||||
vroot := os.read_file(vroot_path).trim_space()
|
||||
mut vroot := os.read_file(vroot_path) or {
|
||||
break
|
||||
}
|
||||
vroot=vroot.trim_space()
|
||||
if os.dir_exists(vroot) && os.dir_exists(vroot + '/builtin') {
|
||||
lang_dir = vroot
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
// no "~/.vlang/VROOT" file, so the user must be running V for the first
|
||||
// time.
|
||||
if lang_dir == '' {
|
||||
|
@@ -32,9 +32,13 @@ fn new_scanner(file_path string) *Scanner {
|
||||
if !os.file_exists(file_path) {
|
||||
panic('"$file_path" doesn\'t exist')
|
||||
}
|
||||
text := os.read_file(file_path) or {
|
||||
panic('scanner: failed to open "$file_path"')
|
||||
return &Scanner{}
|
||||
}
|
||||
scanner := &Scanner {
|
||||
file_path: file_path
|
||||
text: os.read_file(file_path)
|
||||
text: text
|
||||
fmt_out: new_string_builder(1000)
|
||||
}
|
||||
// println('new scanner "$file_path" txt.len=$scanner.text.len')
|
||||
|
Reference in New Issue
Block a user