1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen_test: skip empty lines; os: make vc_gen compile

This commit is contained in:
Alexander Medvednikov 2020-01-01 12:50:25 +01:00
parent 78c706ab71
commit 47908c22df
6 changed files with 50 additions and 28 deletions

View File

@ -293,16 +293,6 @@ pub fn open_append(path string) ?File {
return file return file
} }
// convert any value to []byte (LittleEndian) and write it
// for example if we have write(7, 4), "07 00 00 00" gets written
// write(0x1234, 2) => "34 12"
pub fn (f mut File) write_bytes(data voidptr, size int) {
$if linux {
C.syscall(sys_write, f.fd, data, 1)
} $else {
C.fwrite(data, 1, size, f.cfile)
}
}
/* /*
pub fn (f mut File) write_bytes_at(data voidptr, size, pos int) { pub fn (f mut File) write_bytes_at(data voidptr, size, pos int) {
@ -324,20 +314,6 @@ pub fn (f mut File) flush() {
C.fflush(f.cfile) C.fflush(f.cfile)
} }
pub fn (f mut File) close() {
if !f.opened {
return
}
f.opened = false
$if linux {
//$if linux_or_macos {
C.syscall(sys_close, f.fd)
return
}
C.fflush(f.cfile)
C.fclose(f.cfile)
}
// system starts the specified command, waits for it to complete, and returns its code. // system starts the specified command, waits for it to complete, and returns its code.
fn vpopen(path string) voidptr { fn vpopen(path string) voidptr {
// *C.FILE { // *C.FILE {

View File

@ -216,3 +216,29 @@ pub fn symlink(origin, target string) ?bool {
if res == 0 { return true } if res == 0 { return true }
return error(get_error_msg(C.errno)) return error(get_error_msg(C.errno))
} }
// convert any value to []byte (LittleEndian) and write it
// for example if we have write(7, 4), "07 00 00 00" gets written
// write(0x1234, 2) => "34 12"
pub fn (f mut File) write_bytes(data voidptr, size int) {
$if linux {
C.syscall(sys_write, f.fd, data, 1)
} $else {
C.fwrite(data, 1, size, f.cfile)
}
}
pub fn (f mut File) close() {
if !f.opened {
return
}
f.opened = false
$if linux {
//$if linux_or_macos {
C.syscall(sys_close, f.fd)
return
}
C.fflush(f.cfile)
C.fclose(f.cfile)
}

View File

@ -340,3 +340,16 @@ pub fn symlink(origin, target string) ?bool {
} }
return error(get_error_msg(int(C.GetLastError()))) return error(get_error_msg(int(C.GetLastError())))
} }
pub fn (f mut File) write_bytes(data voidptr, size int) {
C.fwrite(data, 1, size, f.cfile)
}
pub fn (f mut File) close() {
if !f.opened {
return
}
f.opened = false
C.fflush(f.cfile)
C.fclose(f.cfile)
}

View File

@ -35,8 +35,10 @@ fn test_c_files() {
} }
fn compare_texts(a, b string) bool { fn compare_texts(a, b string) bool {
lines_a := a.trim_space().split_into_lines() lines_a_ := a.trim_space().split_into_lines()
lines_b := b.trim_space().split_into_lines() lines_b_ := b.trim_space().split_into_lines()
lines_a := lines_a_.filter(it != '')
lines_b := lines_b_.filter(it != '')
if lines_a.len != lines_b.len { if lines_a.len != lines_b.len {
println(term.red('different len')) println(term.red('different len'))
// return false // return false
@ -44,7 +46,8 @@ fn compare_texts(a, b string) bool {
for i, line_a in lines_a { for i, line_a in lines_a {
line_b := lines_b[i] line_b := lines_b[i]
if line_a.trim_space() != line_b.trim_space() { if line_a.trim_space() != line_b.trim_space() {
println(term.red('!' + line_a)) println(term.red('i=$i a="$line_a" b="$line_b"'))
// exit(1)
return false return false
} }
} }

View File

@ -54,6 +54,11 @@ void init_array() {
}); });
} }
void end() {
}
int main() { int main() {
return 0; return 0;
} }

View File

@ -53,7 +53,6 @@ fn function2() {
j := 0 j := 0
} }
fn init_array() { fn init_array() {
nums := [1,2,3] nums := [1,2,3]