Skip to content

Commit

Permalink
update formatting with latest V
Browse files Browse the repository at this point in the history
  • Loading branch information
JalonSolov committed Dec 18, 2023
1 parent 1f9dbb8 commit e3c0e3b
Show file tree
Hide file tree
Showing 33 changed files with 138 additions and 195 deletions.
26 changes: 12 additions & 14 deletions build.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@

import os // v has a bug that you can't use args

const (
ignore_dirs = $if windows {
[
// avoid *nix-dependent utils
'nohup',
// avoid utmp-dependent utils (WinOS has no utmp support)
'uptime',
'users',
'who',
]
} $else {
[]string{}
}
)
const ignore_dirs = $if windows {
[
// avoid *nix-dependent utils
'nohup',
// avoid utmp-dependent utils (WinOS has no utmp support)
'uptime',
'users',
'who',
]
} $else {
[]string{}
}

vargs := if os.args.len > 1 { os.args[1..] } else { []string{} }

Expand Down
4 changes: 2 additions & 2 deletions common/common.v
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn flag_parser(args []string) &flag.FlagParser {

// exit_on_errors will exit with a code of either 0 or 1,
// depending on the passed `errors` counter.
[noreturn]
@[noreturn]
pub fn exit_on_errors(errors int) {
if errors != 0 {
exit(1)
Expand All @@ -38,7 +38,7 @@ pub fn exit_on_errors(errors int) {
// exit_with_error_message will exit with error code 1,
// showing the passed error message, and directing the
// user to use --help
[noreturn]
@[noreturn]
pub fn exit_with_error_message(tool_name string, error string) {
if error.len > 0 {
eprintln('${tool_name}: ${error}')
Expand Down
4 changes: 2 additions & 2 deletions src/[/left_bracket.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const binarys = [
'-ge',
]

[noreturn]
@[noreturn]
fn my_panic(s string) {
eprintln(s)
exit(2)
Expand Down Expand Up @@ -206,7 +206,7 @@ fn (mut p Parser) term() bool {
return is_neg != (tok != '') // this means is_neg ^ (tok != '')
}

[inline]
@[inline]
fn (p Parser) get() ?string {
if p.idx < p.tokens.len {
return p.tokens[p.idx]
Expand Down
25 changes: 11 additions & 14 deletions src/base32/helper.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ import bitfield
import strings
import common

const (
name = 'base32'
block_size = 5
group_size = 5
bits_in_byte = 8
init_builder_size = 1024
end_byte = `=`
char_set = [`A`, `B`, `C`, `D`, `E`, `F`, `G`, `H`, `I`, `J`, `K`, `L`, `M`, `N`,
`O`, `P`, `Q`, `R`, `S`, `T`, `U`, `V`, `W`, `X`, `Y`, `Z`, `2`, `3`, `4`, `5`, `6`, `7`,
`=`]
invalid = 'invalid input'
)
const name = 'base32'
const block_size = 5
const group_size = 5
const bits_in_byte = 8
const init_builder_size = 1024
const end_byte = `=`
const char_set = [`A`, `B`, `C`, `D`, `E`, `F`, `G`, `H`, `I`, `J`, `K`, `L`, `M`, `N`, `O`, `P`,
`Q`, `R`, `S`, `T`, `U`, `V`, `W`, `X`, `Y`, `Z`, `2`, `3`, `4`, `5`, `6`, `7`, `=`]
const invalid = 'invalid input'

fn get_blocks(groups []u8) []u8 {
mut full_block := bitfield.new(block_size * bits_in_byte)
Expand Down Expand Up @@ -153,13 +150,13 @@ fn run_base32(args []string) {
// println(args)
}

[noreturn]
@[noreturn]
fn success_exit(msg string) {
println(msg)
exit(0)
}

[noreturn]
@[noreturn]
fn error_exit(msg string) {
eprintln(msg)
exit(1)
Expand Down
22 changes: 10 additions & 12 deletions src/base64/base64.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ import os
import common
import encoding.base64

const (
application_name = 'base64'
const application_name = 'base64'

// multiple of 3 so we can encode the data in chunks and concatenate
chunk_size_encode = 15 * 1024
// multiple of 3 so we can encode the data in chunks and concatenate
const chunk_size_encode = 15 * 1024

// 4/3 of chunk_size_encode
buffer_size_encode = 4 * (15 / 3) * 1024
// 4/3 of chunk_size_encode
const buffer_size_encode = 4 * (15 / 3) * 1024

// multiple of 4 so we can decode the data in chunks and concatenate
chunk_size_decode = 16 * 1024
// multiple of 4 so we can decode the data in chunks and concatenate
const chunk_size_decode = 16 * 1024

// more than 3/4 of chunk_size_decode
buffer_size_decode = 16 * 1024
// more than 3/4 of chunk_size_decode
const buffer_size_decode = 16 * 1024

newline = []u8{len: 1, init: `\n`}
)
const newline = []u8{len: 1, init: `\n`}

fn get_file(args []string) os.File {
if args.len == 0 || args[0] == '-' {
Expand Down
6 changes: 2 additions & 4 deletions src/cat/cat.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import common
import os
import io

const (
app_name = 'cat'
app_description = 'concatenate files and print on the standard output'
)
const app_name = 'cat'
const app_description = 'concatenate files and print on the standard output'

struct Settings {
number_nonblanks bool // both number_nonblank, and number_all can never be true together
Expand Down
12 changes: 5 additions & 7 deletions src/cp/helper.v
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import os
import common

const (
name = 'cp'
interactive_yes = ['y']
combine_t_no_t = 'cannot combine --target-directory (-t) and --no-target-directory (-T)'
)
const name = 'cp'
const interactive_yes = ['y']
const combine_t_no_t = 'cannot combine --target-directory (-t) and --no-target-directory (-T)'

fn prompt_file(path string) string {
return "overwrite '${path}'? "
Expand Down Expand Up @@ -54,7 +52,7 @@ fn not_recursive(path string) string {
}

// Print messages and exit with error
[noreturn]
@[noreturn]
fn error_exit(messages ...string) {
for message in messages {
eprintln(message)
Expand All @@ -63,7 +61,7 @@ fn error_exit(messages ...string) {
}

// Print messages and exit
[noreturn]
@[noreturn]
fn success_exit(messages ...string) {
for message in messages {
println(message)
Expand Down
8 changes: 3 additions & 5 deletions src/expand/expand.v
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import os { File }
import common

const (
name = 'expand'
bufsiz = 4096
nl = '\n'
)
const name = 'expand'
const bufsiz = 4096
const nl = '\n'

fn process_line(line string, initial bool, tabs int) {
mut sp := ''
Expand Down
4 changes: 2 additions & 2 deletions src/expr/expr.v
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mut:
idx u64
}

[noreturn]
@[noreturn]
fn my_panic(err string, code int) {
eprintln(err)
exit(code)
Expand Down Expand Up @@ -333,7 +333,7 @@ fn (mut p Parser) primary() Value {
}
}

[inline]
@[inline]
fn (p Parser) get() ?string {
if p.idx < p.tokens.len {
return p.tokens[p.idx]
Expand Down
4 changes: 1 addition & 3 deletions src/false/false.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ module main
import common
import os

const (
app_name = 'false'
)
const app_name = 'false'

fn false_fn() ! {
mut fp := common.flag_parser(os.args)
Expand Down
22 changes: 10 additions & 12 deletions src/fold/fold.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ import strings
import common
import io

const (
name = 'fold'
buf_size = 256
newline_char = `\n`
nul_char = `\0`
back_char = `\b`
return_char = `\r`
tab_char = `\t`
space_char = u8(32)
tab_width = 8
)
const name = 'fold'
const buf_size = 256
const newline_char = `\n`
const nul_char = `\0`
const back_char = `\b`
const return_char = `\r`
const tab_char = `\t`
const space_char = u8(32)
const tab_width = 8

struct Folder {
max_width int
Expand Down Expand Up @@ -158,7 +156,7 @@ fn (c FoldCommand) run(mut files []InputFile) {
}

// Print messages and exit
[noreturn]
@[noreturn]
fn success_exit(messages ...string) {
for message in messages {
println(message)
Expand Down
6 changes: 2 additions & 4 deletions src/groups/groups.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import os
import common
import encoding.csv

const (
tool_name = 'groups'
group_file = '/etc/group'
)
const tool_name = 'groups'
const group_file = '/etc/group'

fn main() {
mut fp := common.flag_parser(os.args)
Expand Down
18 changes: 8 additions & 10 deletions src/head/head.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import common
import strings
import io

const (
name = 'head'
buf_size = 256
newline_char = u8(10)
nul_char = u8(0)
space_char = u8(32)
)
const name = 'head'
const buf_size = 256
const newline_char = u8(10)
const nul_char = u8(0)
const space_char = u8(32)

struct HeadCommand {
bytes_to_read int
Expand All @@ -24,7 +22,7 @@ fn write_header(name string, first_file bool) {
print('${prefix}==> ${name} <==\n')
}

[direct_array_access]
@[direct_array_access]
fn write_bytes(file_ptr os.File, num_bytes int) {
mut m_bytes_to_write := num_bytes
adj_buf_size := if num_bytes < buf_size { num_bytes } else { buf_size }
Expand Down Expand Up @@ -86,7 +84,7 @@ fn write_bytes_upto_max(file_ptr os.File, num_bytes int) {
print(output_buf.str())
}

[direct_array_access]
@[direct_array_access]
fn write_lines(file os.File, num_lines int, delim_char u8) {
mut m_lines_to_write := num_lines
mut f_reader := io.new_buffered_reader(reader: file)
Expand Down Expand Up @@ -223,7 +221,7 @@ fn (c HeadCommand) run(mut files []InputFile) {
}

// Print messages and exit
[noreturn]
@[noreturn]
fn success_exit(messages ...string) {
for message in messages {
println(message)
Expand Down
6 changes: 2 additions & 4 deletions src/hostid/hostid.v
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import common
import os

const (
app_name = 'hostid'
app_description = 'Print the numeric identifier (in hexadecimal) of the current host.'
)
const app_name = 'hostid'
const app_description = 'Print the numeric identifier (in hexadecimal) of the current host.'

/*
** hostid clone written in V
Expand Down
6 changes: 2 additions & 4 deletions src/hostname/hostname.v
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import os
import common

const (
app_name = 'hostname'
app_description = 'Prints or set the name of the current host system.'
)
const app_name = 'hostname'
const app_description = 'Prints or set the name of the current host system.'

/*
** GNU Coreutils Hostname clone made in V
Expand Down
4 changes: 1 addition & 3 deletions src/ln/helper.v
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import common

const (
name = 'ln'
)
const name = 'ln'

fn success_exit(messages ...string) {
for message in messages {
Expand Down
4 changes: 1 addition & 3 deletions src/logname/logname.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import flag
The following block has been created in this file, but should be extracted to a common module for use by all utils
*/

const (
version_str = 'V Coreutils 0.0.1'
)
const version_str = 'V Coreutils 0.0.1'

// A default error exit, when code is not important
fn error_exit(errors ...string) {
Expand Down
Loading

0 comments on commit e3c0e3b

Please sign in to comment.