init commit
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,6 +3,8 @@
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
buildj
|
||||
*.tmp.c
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
26
buildj.v
Normal file
26
buildj.v
Normal file
@@ -0,0 +1,26 @@
|
||||
module main
|
||||
|
||||
// import http
|
||||
// import os
|
||||
// import time
|
||||
// import json
|
||||
import buildj_util
|
||||
//import termcolor
|
||||
|
||||
// https://bitbucket.org/hatterjiang/archived-study_v/src/master/buildjs.v
|
||||
const (
|
||||
BUILDJ_NAME = 'buildj.v'
|
||||
BUILDJ_VERSION = '0.1'
|
||||
BUILD_JSON = 'build.json'
|
||||
)
|
||||
|
||||
fn main() {
|
||||
buildj_util.check_os()
|
||||
show_buildjs_head()
|
||||
println(buildj_util.get_readable_size(1000000))
|
||||
}
|
||||
|
||||
fn show_buildjs_head() {
|
||||
println('${BUILDJ_NAME} - version: ${BUILDJ_VERSION}')
|
||||
}
|
||||
|
||||
38
buildj_util/buildj_util.v
Normal file
38
buildj_util/buildj_util.v
Normal file
@@ -0,0 +1,38 @@
|
||||
module buildj_util
|
||||
|
||||
const (
|
||||
ZERO = 0
|
||||
KB = 1024
|
||||
MB = KB * KB
|
||||
)
|
||||
|
||||
pub fn check_os() {
|
||||
$if linux {
|
||||
return
|
||||
}
|
||||
$if mac {
|
||||
return
|
||||
}
|
||||
println('[ERROR] Not supported OS.')
|
||||
exit(1)
|
||||
}
|
||||
|
||||
pub fn get_readable_size(size int) string {
|
||||
if size <= ZERO {
|
||||
return '${size} Byte'
|
||||
} else if size < KB {
|
||||
return '${size} Bytes'
|
||||
} else if size < MB {
|
||||
size_in_kb := f64_str_2f(f64(size) / f64(KB))
|
||||
return '${size_in_kb} KB'
|
||||
} else {
|
||||
size_in_mb := f64_str_2f(f64(size) / f64(MB))
|
||||
return '${size_in_mb} MB'
|
||||
}
|
||||
}
|
||||
|
||||
fn f64_str_2f(d f64) string {
|
||||
buf := malloc(sizeof(f64) * 5 + 1)
|
||||
C.sprintf(buf, '%.2f', d)
|
||||
return tos(buf, C.strlen(buf))
|
||||
}
|
||||
Reference in New Issue
Block a user