init commit

This commit is contained in:
2019-11-24 16:30:35 +08:00
parent 16fd6ee5e3
commit caaae36f72
3 changed files with 66 additions and 0 deletions

2
.gitignore vendored
View File

@@ -3,6 +3,8 @@
.DS_Store
.AppleDouble
.LSOverride
buildj
*.tmp.c
# Icon must end with two \r
Icon

26
buildj.v Normal file
View 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
View 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))
}