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

all: unify const names to snake_case

This commit is contained in:
yuyi
2020-05-22 23:36:09 +08:00
committed by GitHub
parent aef751861d
commit dda875a9c8
58 changed files with 543 additions and 540 deletions

View File

@@ -3,17 +3,16 @@ module os
// ref: http://www.ccfit.nsu.ru/~deviv/courses/unix/unix/ng7c229.html
const (
S_IFMT = 0xF000 // type of file
S_IFDIR = 0x4000 // directory
S_IFLNK = 0xa000 // link
S_IXUSR = 0o100 // is executable by the owner
S_IXGRP = 0o010 // is executable by group
S_IXOTH = 0o001 // is executable by others
s_ifmt = 0xF000 // type of file
s_ifdir = 0x4000 // directory
s_iflnk = 0xa000 // link
s_ixusr = 0o100 // is executable by the owner
s_ixgrp = 0o010 // is executable by group
s_ixoth = 0o001 // is executable by others
)
const (
STD_INPUT_HANDLE = -10
STD_OUTPUT_HANDLE = -11
STD_ERROR_HANDLE = -12
std_input_handle = -10
std_output_handle = -11
std_error_handle = -12
)

View File

@@ -2,14 +2,14 @@ module os
// File modes
const (
O_RDONLY = 000000000 // open the file read-only.
O_WRONLY = 000000001 // open the file write-only.
O_RDWR = 000000002 // open the file read-write.
O_CREATE = 000000100 // create a new file if none exists.
O_EXCL = 000000200 // used with O_CREATE, file must not exist.
O_NOCTTY = 000000400 // if file is terminal, don't make it the controller terminal
O_TRUNC = 000001000 // truncate regular writable file when opened.
O_APPEND = 000002000 // append data to the file when writing.
O_NONBLOCK = 000004000 // prevents blocking when opening files
O_SYNC = 000010000 // open for synchronous I/O.
o_rdonly = 000000000 // open the file read-only.
o_wronly = 000000001 // open the file write-only.
o_rdwr = 000000002 // open the file read-write.
o_create = 000000100 // create a new file if none exists.
o_excl = 000000200 // used with o_create, file must not exist.
o_noctty = 000000400 // if file is terminal, don't make it the controller terminal
o_trunc = 000001000 // truncate regular writable file when opened.
o_append = 000002000 // append data to the file when writing.
o_nonblock = 000004000 // prevents blocking when opening files
o_sync = 000010000 // open for synchronous I/O.
)

View File

@@ -3,102 +3,102 @@ module os
// Ref - winnt.h
const (
success = 0 // ERROR_SUCCESS
ERROR_INSUFFICIENT_BUFFER = 130
error_insufficient_buffer = 130
)
const (
FILE_SHARE_READ = 1
FILE_SHARE_WRITE = 2
FILE_SHARE_DELETE = 4
file_share_read = 1
file_share_write = 2
file_share_delete = 4
)
const (
FILE_NOTIFY_CHANGE_FILE_NAME = 1
FILE_NOTIFY_CHANGE_DIR_NAME = 2
FILE_NOTIFY_CHANGE_ATTRIBUTES = 4
FILE_NOTIFY_CHANGE_SIZE = 8
FILE_NOTIFY_CHANGE_LAST_WRITE = 16
FILE_NOTIFY_CHANGE_LAST_ACCESS = 32
FILE_NOTIFY_CHANGE_CREATION = 64
FILE_NOTIFY_CHANGE_SECURITY = 128
file_notify_change_file_name = 1
file_notify_change_dir_name = 2
file_notify_change_attributes = 4
file_notify_change_size = 8
file_notify_change_last_write = 16
file_notify_change_last_access = 32
file_notify_change_creation = 64
file_notify_change_security = 128
)
const (
FILE_ACTION_ADDED = 1
FILE_ACTION_REMOVED = 2
FILE_ACTION_MODIFIED = 3
FILE_ACTION_RENAMED_OLD_NAME = 4
FILE_ACTION_RENAMED_NEW_NAME = 5
file_action_added = 1
file_action_removed = 2
file_action_modified = 3
file_action_renamed_old_name = 4
file_action_renamed_new_name = 5
)
const (
FILE_ATTR_READONLY = 0x1
FILE_ATTR_HIDDEN = 0x2
FILE_ATTR_SYSTEM = 0x4
FILE_ATTR_DIRECTORY = 0x10
FILE_ATTR_ARCHIVE = 0x20
FILE_ATTR_DEVICE = 0x40
FILE_ATTR_NORMAL = 0x80
FILE_ATTR_TEMPORARY = 0x100
FILE_ATTR_SPARSE_FILE = 0x200
FILE_ATTR_REPARSE_POINT = 0x400
FILE_ATTR_COMPRESSED = 0x800
FILE_ATTR_OFFLINE = 0x1000
FILE_ATTR_NOT_CONTENT_INDEXED = 0x2000
FILE_ATTR_ENCRYPTED = 0x4000
FILE_ATTR_INTEGRITY_STREAM = 0x8000
FILE_ATTR_VIRTUAL = 0x10000
FILE_ATTR_NO_SCRUB_DATA = 0x20000
// FILE_ATTR_RECALL_ON_OPEN = u32(0x...)
// FILE_ATTR_RECALL_ON_DATA_ACCESS = u32(0x...)
file_attr_readonly = 0x1
file_attr_hidden = 0x2
file_attr_system = 0x4
file_attr_directory = 0x10
file_attr_archive = 0x20
file_attr_device = 0x40
file_attr_normal = 0x80
file_attr_temporary = 0x100
file_attr_sparse_file = 0x200
file_attr_reparse_point = 0x400
file_attr_compressed = 0x800
file_attr_offline = 0x1000
file_attr_not_content_indexed = 0x2000
file_attr_encrypted = 0x4000
file_attr_integrity_stream = 0x8000
file_attr_virtual = 0x10000
file_attr_no_scrub_data = 0x20000
// file_attr_recall_on_open = u32(0x...)
// file_attr_recall_on_data_access = u32(0x...)
)
const (
FILE_TYPE_DISK = 0x1
FILE_TYPE_CHAR = 0x2
FILE_TYPE_PIPE = 0x3
file_type_disk = 0x1
file_type_char = 0x2
file_type_pipe = 0x3
FILE_TYPE_UNKNOWN = 0x0
file_type_unknown = 0x0
)
const (
FILE_INVALID_FILE_ID = (-1)
file_invalid_file_id = (-1)
)
const(
INVALID_HANDLE_VALUE = voidptr(-1)
invalid_handle_value = voidptr(-1)
)
// https://docs.microsoft.com/en-us/windows/console/setconsolemode
const (
// Input Buffer
ENABLE_ECHO_INPUT = 0x0004
ENABLE_EXTENDED_FLAGS = 0x0080
ENABLE_INSERT_MODE = 0x0020
ENABLE_LINE_INPUT = 0x0002
ENABLE_MOUSE_INPUT = 0x0010
ENABLE_PROCESSED_INPUT = 0x0001
ENABLE_QUICK_EDIT_MODE = 0x0040
ENABLE_WINDOW_INPUT = 0x0008
ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200
enable_echo_input = 0x0004
enable_extended_flags = 0x0080
enable_insert_mode = 0x0020
enable_line_input = 0x0002
enable_mouse_input = 0x0010
enable_processed_input = 0x0001
enable_quick_edit_mode = 0x0040
enable_window_input = 0x0008
enable_virtual_terminal_input = 0x0200
// Output Screen Buffer
ENABLE_PROCESSED_OUTPUT = 0x0001
ENABLE_WRAP_AT_EOL_OUTPUT = 0x0002
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004
DISABLE_NEWLINE_AUTO_RETURN = 0x0008
ENABLE_LVB_GRID_WORLDWIDE = 0x0010
enable_processed_output = 0x0001
enable_wrap_at_eol_output = 0x0002
enable_virtual_terminal_processing = 0x0004
disable_newline_auto_return = 0x0008
enable_lvb_grid_worldwide = 0x0010
)
// File modes
const (
O_RDONLY = 0 // open the file read-only.
O_WRONLY = 1 // open the file write-only.
O_RDWR = 2 // open the file read-write.
O_APPEND = 0x0008 // append data to the file when writing.
O_CREATE = 0x0100 // create a new file if none exists.
O_TRUNC = 0x0200 // truncate regular writable file when opened.
O_EXCL = 0x0400 // used with O_CREATE, file must not exist.
O_SYNC = 0 // open for synchronous I/O (ignored on Windows)
O_NOCTTY = 0 // make file non-controlling tty (ignored on Windows)
O_NONBLOCK = 0 // don't block on opening file (ignored on Windows)
o_rdonly = 0 // open the file read-only.
o_wronly = 1 // open the file write-only.
o_rdwr = 2 // open the file read-write.
o_append = 0x0008 // append data to the file when writing.
o_create = 0x0100 // create a new file if none exists.
o_trunc = 0x0200 // truncate regular writable file when opened.
o_excl = 0x0400 // used with o_create, file must not exist.
o_sync = 0 // open for synchronous I/O (ignored on Windows)
o_noctty = 0 // make file non-controlling tty (ignored on Windows)
o_nonblock = 0 // don't block on opening file (ignored on Windows)
)

View File

@@ -24,7 +24,7 @@ fn C.readdir(voidptr) C.dirent
pub const (
args = []string{}
MAX_PATH = 4096
max_path_len = 4096
)
pub struct File {
@@ -352,13 +352,13 @@ pub fn open_file(path string, mode string, options ...int) ?File {
mut flags := 0
for m in mode {
match m {
`r` { flags |= O_RDONLY }
`w` { flags |= O_CREATE | O_TRUNC }
`a` { flags |= O_CREATE | O_APPEND }
`s` { flags |= O_SYNC }
`n` { flags |= O_NONBLOCK }
`c` { flags |= O_NOCTTY }
`+` { flags |= O_RDWR }
`r` { flags |= o_rdonly }
`w` { flags |= o_create | o_trunc }
`a` { flags |= o_create | o_append }
`s` { flags |= o_sync }
`n` { flags |= o_nonblock }
`c` { flags |= o_noctty }
`+` { flags |= o_rdwr }
else {}
}
}
@@ -570,19 +570,19 @@ pub fn sigint_to_signal_name(si int) string {
}
const (
F_OK = 0
X_OK = 1
W_OK = 2
R_OK = 4
f_ok = 0
x_ok = 1
w_ok = 2
r_ok = 4
)
// exists returns true if `path` exists.
pub fn exists(path string) bool {
$if windows {
p := path.replace('/', '\\')
return C._waccess(p.to_wide(), F_OK) != -1
return C._waccess(p.to_wide(), f_ok) != -1
} $else {
return C.access(path.str, F_OK) != -1
return C.access(path.str, f_ok) != -1
}
}
@@ -603,9 +603,9 @@ pub fn is_executable(path string) bool {
if C.stat(path.str, &statbuf) != 0 {
return false
}
return (int(statbuf.st_mode) & ( S_IXUSR | S_IXGRP | S_IXOTH )) != 0
return (int(statbuf.st_mode) & ( s_ixusr | s_ixgrp | s_ixoth )) != 0
}
return C.access(path.str, X_OK) != -1
return C.access(path.str, x_ok) != -1
}
// `is_writable_folder` - `folder` exists and is writable to the process
@@ -629,9 +629,9 @@ pub fn is_writable_folder(folder string) ?bool {
pub fn is_writable(path string) bool {
$if windows {
p := path.replace('/', '\\')
return C._waccess(p.to_wide(), W_OK) != -1
return C._waccess(p.to_wide(), w_ok) != -1
} $else {
return C.access(path.str, W_OK) != -1
return C.access(path.str, w_ok) != -1
}
}
@@ -639,9 +639,9 @@ pub fn is_writable(path string) bool {
pub fn is_readable(path string) bool {
$if windows {
p := path.replace('/', '\\')
return C._waccess(p.to_wide(), R_OK) != -1
return C._waccess(p.to_wide(), r_ok) != -1
} $else {
return C.access(path.str, R_OK) != -1
return C.access(path.str, r_ok) != -1
}
}
@@ -748,7 +748,7 @@ pub fn get_raw_line() string {
unsafe {
max_line_chars := 256
buf := malloc(max_line_chars * 2)
h_input := C.GetStdHandle(STD_INPUT_HANDLE)
h_input := C.GetStdHandle(std_input_handle)
mut bytes_read := 0
if is_atty(0) > 0 {
C.ReadConsole(h_input, buf, max_line_chars * 2, &bytes_read, 0)
@@ -903,8 +903,8 @@ fn C.readlink() int
// process.
pub fn executable() string {
$if linux {
mut result := vcalloc(MAX_PATH)
count := C.readlink('/proc/self/exe', result, MAX_PATH)
mut result := vcalloc(max_path_len)
count := C.readlink('/proc/self/exe', result, max_path_len)
if count < 0 {
eprintln('os.executable() failed at reading /proc/self/exe to get exe path')
return executable_fallback()
@@ -913,14 +913,14 @@ pub fn executable() string {
}
$if windows {
max := 512
mut result := &u16(vcalloc(max * 2)) // MAX_PATH * sizeof(wchar_t)
mut result := &u16(vcalloc(max * 2)) // max_path_len * sizeof(wchar_t)
len := C.GetModuleFileName(0, result, max)
return string_from_wide2(result, len)
}
$if macos {
mut result := vcalloc(MAX_PATH)
mut result := vcalloc(max_path_len)
pid := C.getpid()
ret := proc_pidpath(pid, result, MAX_PATH)
ret := proc_pidpath(pid, result, max_path_len)
if ret <= 0 {
eprintln('os.executable() failed at calling proc_pidpath with pid: $pid . proc_pidpath returned $ret ')
return executable_fallback()
@@ -928,9 +928,9 @@ pub fn executable() string {
return string(result)
}
$if freebsd {
mut result := vcalloc(MAX_PATH)
mut result := vcalloc(max_path_len)
mib := [1/* CTL_KERN */, 14/* KERN_PROC */, 12/* KERN_PROC_PATHNAME */, -1]
size := MAX_PATH
size := max_path_len
C.sysctl(mib.data, 4, result, &size, 0, 0)
return string(result)
}
@@ -939,8 +939,8 @@ pub fn executable() string {
$if solaris {}
$if haiku {}
$if netbsd {
mut result := vcalloc(MAX_PATH)
count := C.readlink('/proc/curproc/exe', result, MAX_PATH)
mut result := vcalloc(max_path_len)
count := C.readlink('/proc/curproc/exe', result, max_path_len)
if count < 0 {
eprintln('os.executable() failed at reading /proc/curproc/exe to get exe path')
return executable_fallback()
@@ -948,8 +948,8 @@ pub fn executable() string {
return string(result,count)
}
$if dragonfly {
mut result := vcalloc(MAX_PATH)
count := C.readlink('/proc/curproc/file', result, MAX_PATH)
mut result := vcalloc(max_path_len)
count := C.readlink('/proc/curproc/file', result, max_path_len)
if count < 0 {
eprintln('os.executable() failed at reading /proc/curproc/file to get exe path')
return executable_fallback()
@@ -1036,8 +1036,8 @@ pub fn is_dir(path string) bool {
return false
}
// ref: https://code.woboq.org/gcc/include/sys/stat.h.html
val:= int(statbuf.st_mode) & S_IFMT
return val == S_IFDIR
val:= int(statbuf.st_mode) & os.s_ifmt
return val == s_ifdir
}
}
@@ -1050,7 +1050,7 @@ pub fn is_link(path string) bool {
if C.lstat(path.str, &statbuf) != 0 {
return false
}
return int(statbuf.st_mode) & S_IFMT == S_IFLNK
return int(statbuf.st_mode) & s_ifmt == s_iflnk
}
}
@@ -1066,7 +1066,7 @@ pub fn chdir(path string) {
// getwd returns the absolute path name of the current directory.
pub fn getwd() string {
$if windows {
max := 512 // MAX_PATH * sizeof(wchar_t)
max := 512 // max_path_len * sizeof(wchar_t)
buf := &u16(vcalloc(max * 2))
if C._wgetcwd(buf, max) == 0 {
return ''
@@ -1087,10 +1087,10 @@ pub fn getwd() string {
// and https://insanecoding.blogspot.com/2007/11/implementing-realpath-in-c.html
// NB: this particular rabbit hole is *deep* ...
pub fn real_path(fpath string) string {
mut fullpath := vcalloc(MAX_PATH)
mut fullpath := vcalloc(max_path_len)
mut ret := charptr(0)
$if windows {
ret = C._fullpath(fullpath, fpath.str, MAX_PATH)
ret = C._fullpath(fullpath, fpath.str, max_path_len)
if ret == 0 {
return fpath
}

View File

@@ -5,11 +5,11 @@
module os
const (
PROT_READ = 1
PROT_WRITE = 2
prot_read = 1
prot_write = 2
MAP_PRIVATE = 0x02
MAP_ANONYMOUS = 0x20
map_private = 0x02
map_anonymous = 0x20
)
pub const (
@@ -45,13 +45,11 @@ fn mmap(start voidptr, len, prot, flags, fd, off int) byteptr {
pub fn malloc(n int) byteptr {
println('malloc($n)')
return mmap(0, n, 3, 4098, //PROT_READ|PROT_WRITE,
-1,0) //MAP_PRIVATE|MAP_ANONYMOUS,
return mmap(0, n, 3, 4098, //prot_read|prot_write,
-1,0) //map_private|map_anonymous,
}
pub fn free(b byteptr) {
}
*/

View File

@@ -32,7 +32,7 @@ mut:
n_file_size_low u32
dw_reserved0 u32
dw_reserved1 u32
c_file_name [260]u16 // MAX_PATH = 260
c_file_name [260]u16 // max_path_len = 260
c_alternate_file_name [14]u16 // 14
dw_file_type u32
dw_creator_type u32
@@ -89,7 +89,7 @@ pub fn ls(path string) ?[]string {
mut dir_files := []string{}
// We can also check if the handle is valid. but using is_dir instead
// h_find_dir := C.FindFirstFile(path.str, &find_file_data)
// if (INVALID_HANDLE_VALUE == h_find_dir) {
// if (invalid_handle_value == h_find_dir) {
// return dir_files
// }
// C.FindClose(h_find_dir)
@@ -146,7 +146,7 @@ pub fn mkdir(path string) ?bool {
pub fn get_file_handle(path string) HANDLE {
cfile := vfopen(path, 'rb')
if cfile == 0 {
return HANDLE(INVALID_HANDLE_VALUE)
return HANDLE(invalid_handle_value)
}
handle := HANDLE(C._get_osfhandle(fileno(cfile))) // CreateFile? - hah, no -_-
return handle
@@ -177,24 +177,24 @@ pub fn get_module_filename(handle HANDLE) ?string {
// Ref - https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-formatmessagea#parameters
const (
FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100
FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000
FORMAT_MESSAGE_FROM_HMODULE = 0x00000800
FORMAT_MESSAGE_FROM_STRING = 0x00000400
FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000
FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200
format_message_allocate_buffer = 0x00000100
format_message_argument_array = 0x00002000
format_message_from_hmodule = 0x00000800
format_message_from_string = 0x00000400
format_message_from_system = 0x00001000
format_message_ignore_inserts = 0x00000200
)
// Ref - winnt.h
const (
SUBLANG_NEUTRAL = 0x00
SUBLANG_DEFAULT = 0x01
LANG_NEUTRAL = (SUBLANG_NEUTRAL)
sublang_neutral = 0x00
sublang_default = 0x01
lang_neutral = (sublang_neutral)
)
// Ref - https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--12000-15999-
const (
MAX_ERROR_CODE = 15841 // ERROR_API_UNAVAILABLE
max_error_code = 15841 // ERROR_API_UNAVAILABLE
)
// ptr_win_get_error_msg return string (voidptr)
@@ -202,14 +202,14 @@ const (
fn ptr_win_get_error_msg(code u32) voidptr {
mut buf := voidptr(0)
// Check for code overflow
if code > u32(MAX_ERROR_CODE) {
if code > u32(max_error_code) {
return buf
}
C.FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS,
0, code, C.MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), voidptr(&buf), 0, 0)
format_message_allocate_buffer
| format_message_from_system
| format_message_ignore_inserts,
0, code, C.MAKELANGID(lang_neutral, sublang_default), voidptr(&buf), 0, 0)
return buf
}