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

vfmt: it can now be used for _platform.v files too, no matter the host os

This commit is contained in:
Delyan Angelov
2019-12-27 18:59:04 +02:00
committed by Alexander Medvednikov
parent 84fbd5b3d0
commit 6c16bac908
12 changed files with 253 additions and 175 deletions

View File

@@ -148,7 +148,7 @@ fn C.toupper() int
fn C.getchar() int
fn C.strerror() charptr
fn C.strerror(int) charptr
fn C.snprintf() int
@@ -397,4 +397,3 @@ fn C.WaitForSingleObject(voidptr, int) int
fn C.ReleaseMutex(voidptr) bool

View File

@@ -34,12 +34,3 @@ pub fn (cb Clipboard) check_ownership() bool {
pub fn (cb &Clipboard) is_available() bool {
return cb.check_availability()
}
// create a new PRIMARY clipboard (only supported on Linux)
pub fn new_primary() &Clipboard {
$if linux {
return new_x11_clipboard(.primary)
} $else {
panic("Primary clipboard is not supported on non-Linux systems.")
}
}

View File

@@ -72,3 +72,7 @@ fn (cb mut Clipboard) get_text() string {
#utf8_clip = [ns_clip UTF8String];
return string(utf8_clip)
}
pub fn new_primary() &Clipboard {
panic('Primary clipboard is not supported on non-Linux systems.')
}

View File

@@ -423,3 +423,7 @@ fn new_display() &Display {
return XOpenDisplay(C.NULL)
}
// create a new PRIMARY clipboard (only supported on Linux)
pub fn new_primary() &Clipboard {
return new_x11_clipboard(.primary)
}

View File

@@ -4,6 +4,8 @@ import time
#include <windows.h>
type HANDLE voidptr
struct C.HWND
struct C.WPARAM
struct C.LPARAM
@@ -153,3 +155,7 @@ fn (cb mut Clipboard) get_text() string {
GlobalUnlock(h_data)
return str
}
pub fn new_primary() &Clipboard {
panic('Primary clipboard is not supported on non-Linux systems.')
}

View File

@@ -1102,7 +1102,7 @@ pub fn new_v(args []string) &V {
build_mode: build_mode
cflags: cflags
ccompiler: find_c_compiler()
building_v: !is_repl && (rdir_name == 'compiler' || rdir_name == 'v.v' || dir.contains('vlib'))
building_v: !is_repl && (rdir_name == 'compiler' || rdir_name == 'v.v' || rdir_name == 'vfmt.v' || dir.contains('vlib'))
// is_fmt: comptime_define == 'vfmt'
user_mod_path: user_mod_path

View File

@@ -46,8 +46,7 @@ struct C.stat {
st_mtime int
}
struct C.DIR {
}
struct C.DIR {}
// struct C.dirent {
// d_name byteptr
@@ -123,8 +122,7 @@ pub fn read_file(path string) ?string {
// file_size returns the size of the file located in `path`.
pub fn file_size(path string) int {
mut s := C.stat{
}
mut s := C.stat{}
$if windows {
C._wstat(path.to_wide(), voidptr(&s))
} $else {
@@ -272,8 +270,7 @@ fn read_ulines(path string) ?[]ustring {
}
pub fn open(path string) ?File {
mut file := File{
}
mut file := File{}
$if windows {
wpath := path.to_wide()
mode := 'rb'
@@ -295,8 +292,7 @@ pub fn open(path string) ?File {
// create creates a file at a specified location and returns a writable `File` object.
pub fn create(path string) ?File {
mut file := File{
}
mut file := File{}
$if windows {
wpath := path.replace('/', '\\').to_wide()
mode := 'wb'
@@ -317,8 +313,7 @@ pub fn create(path string) ?File {
}
pub fn open_append(path string) ?File {
mut file := File{
}
mut file := File{}
$if windows {
wpath := path.replace('/', '\\').to_wide()
mode := 'ab'
@@ -493,8 +488,8 @@ pub fn sigint_to_signal_name(si int) string {
15 {
return 'SIGTERM'
}
else {
}}
else {}
}
$if linux {
// From `man 7 signal` on linux:
match si {
@@ -529,8 +524,8 @@ pub fn sigint_to_signal_name(si int) string {
7 {
return 'SIGBUS'
}
else {
}}
else {}
}
}
return 'unknown'
}
@@ -608,7 +603,9 @@ pub fn rmdir(path string) {
}
fn print_c_errno() {
// C.printf('errno=%d err="%s"\n', C.errno, C.strerror(C.errno))
e := C.errno
se := tos_clone(byteptr(C.strerror(C.errno)))
println('errno=$e err=$se')
}
[deprecated]
@@ -776,8 +773,7 @@ pub fn on_segfault(f voidptr) {
return
}
$if macos {
mut sa := C.sigaction{
}
mut sa := C.sigaction{}
C.memset(&sa, 0, sizeof(sigaction))
C.sigemptyset(&sa.sa_mask)
sa.sa_sigaction = f
@@ -833,10 +829,8 @@ pub fn executable() string {
// lol
return os.args[0]
}
$if solaris {
}
$if haiku {
}
$if solaris {}
$if haiku {}
$if netbsd {
mut result := calloc(MAX_PATH)
count := int(C.readlink('/proc/curproc/exe', result, MAX_PATH))
@@ -876,8 +870,7 @@ pub fn is_dir(path string) bool {
}
return false
} $else {
statbuf := C.stat{
}
statbuf := C.stat{}
if C.stat(path.str, &statbuf) != 0 {
return false
}
@@ -891,8 +884,7 @@ pub fn is_link(path string) bool {
$if windows {
return false // TODO
} $else {
statbuf := C.stat{
}
statbuf := C.stat{}
if C.lstat(path.str, &statbuf) != 0 {
return false
}
@@ -1028,8 +1020,7 @@ pub fn wait() int {
}
pub fn file_last_mod_unix(path string) int {
attr := C.stat{
}
attr := C.stat{}
// # struct stat attr;
C.stat(path.str, &attr)
// # stat(path.str, &attr);
@@ -1045,16 +1036,6 @@ pub fn flush_stdout() {
C.fflush(stdout)
}
pub fn print_backtrace() {
/*
# void *buffer[100];
nptrs := 0
# nptrs = backtrace(buffer, 100);
# printf("%d!!\n", nptrs);
# backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO) ;
*/
}
pub fn mkdir_all(path string) {
mut p := if path.starts_with(os.path_separator) { os.path_separator } else { '' }
for subdir in path.split(os.path_separator) {
@@ -1120,4 +1101,3 @@ pub fn chmod(path string, mode int) {
pub const (
wd_at_startup = getwd()
)

View File

@@ -1,22 +1,31 @@
module os2
#include <fcntl.h>
struct File {
fd int
}
}
fn C.perror(charptr)
fn C.open(byteptr, int, int) int
fn C.write(voidptr, byteptr, int) int
fn C.close(int) int
pub fn create(path string) ?File {
fd := C.creat(path.str, 0644)//511)
fd := C.open(path.str, C.O_CREAT | C.O_TRUNC | C.O_WRONLY, 0644) // 511
if fd == -1 {
return error('failed to create "$path":')
//os.print_c_errno()
// os.print_c_errno()
}
return File{fd}
}
return File{
fd}
}
pub fn (f File) writeln(s string) {
ss := s + '\n'
@@ -29,4 +38,3 @@ pub fn (f File) writeln(s string) {
pub fn (f File) close() {
C.close(f.fd)
}