From ac0fee8e64106c734f0145929bef53b73ecde4e4 Mon Sep 17 00:00:00 2001 From: Mike 'Fuzzy' Partin Date: Tue, 2 Jun 2020 22:44:44 -0700 Subject: [PATCH] repl: fix BSDs --- vlib/readline/readline_dragonfly.c.v | 71 ++++++++++++++++++++++++++++ vlib/readline/readline_freebsd.c.v | 71 ++++++++++++++++++++++++++++ vlib/readline/readline_netbsd.c.v | 71 ++++++++++++++++++++++++++++ vlib/readline/readline_openbsd.c.v | 71 ++++++++++++++++++++++++++++ vlib/v/pref/should_compile.v | 9 ++++ 5 files changed, 293 insertions(+) create mode 100644 vlib/readline/readline_dragonfly.c.v create mode 100644 vlib/readline/readline_freebsd.c.v create mode 100644 vlib/readline/readline_netbsd.c.v create mode 100644 vlib/readline/readline_openbsd.c.v diff --git a/vlib/readline/readline_dragonfly.c.v b/vlib/readline/readline_dragonfly.c.v new file mode 100644 index 0000000000..a73c1a1ce5 --- /dev/null +++ b/vlib/readline/readline_dragonfly.c.v @@ -0,0 +1,71 @@ +// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved. +// Use of this source code is governed by an MIT license +// that can be found in the LICENSE file. + +// Mac version +// Need to be implemented +// Will serve as more advanced input method +// Based on the work of https://github.com/AmokHuginnsson/replxx + +module readline + +import os + +#include + +// Only use standard os.get_line +// Need implementation for readline capabilities +pub fn (mut r Readline) read_line_utf8(prompt string) ?ustring { + r.current = ''.ustring() + r.cursor = 0 + r.prompt = prompt + r.search_index = 0 + if r.previous_lines.len <= 1 { + r.previous_lines << ''.ustring() + r.previous_lines << ''.ustring() + } + else { + r.previous_lines[0] = ''.ustring() + } + + print(r.prompt) + line := os.get_raw_line() + + if line.len >= 0 { + r.current = line.ustring() + } + r.previous_lines[0] = ''.ustring() + r.search_index = 0 + if r.current.s == '' { + return error('empty line') + } + return r.current +} + +// Returns the string from the utf8 ustring +pub fn (mut r Readline) read_line(prompt string) ?string { + s := r.read_line_utf8(prompt) or { + return error(err) + } + return s.s +} + +// Standalone function without persistent functionnalities (eg: history) +// Returns utf8 based ustring +pub fn read_line_utf8(prompt string) ?ustring { + mut r := Readline{} + s := r.read_line_utf8(prompt) or { + return error(err) + } + return s +} + +// Standalone function without persistent functionnalities (eg: history) +// Return string from utf8 ustring +pub fn read_line(prompt string) ?string { + mut r := Readline{} + s := r.read_line(prompt) or { + return error(err) + } + return s +} diff --git a/vlib/readline/readline_freebsd.c.v b/vlib/readline/readline_freebsd.c.v new file mode 100644 index 0000000000..e82e4d976d --- /dev/null +++ b/vlib/readline/readline_freebsd.c.v @@ -0,0 +1,71 @@ +// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved. +// Use of this source code is governed by an MIT license +// that can be found in the LICENSE file. + +// Mac version +// Need to be implemented +// Will serve as more advanced input method +// Based on the work of https://github.com/AmokHuginnsson/replxx + +module readline + +import os + +#include + +// Only use standard os.get_line +// Need implementation for readline capabilities +pub fn (mut r Readline) read_line_utf8(prompt string) ?ustring { + r.current = ''.ustring() + r.cursor = 0 + r.prompt = prompt + r.search_index = 0 + if r.previous_lines.len <= 1 { + r.previous_lines << ''.ustring() + r.previous_lines << ''.ustring() + } + else { + r.previous_lines[0] = ''.ustring() + } + + print(r.prompt) + line := os.get_raw_line() + + if line.len >= 0 { + r.current = line.ustring() + } + r.previous_lines[0] = ''.ustring() + r.search_index = 0 + if r.current.s == '' { + return error('empty line') + } + return r.current +} + +// Returns the string from the utf8 ustring +pub fn (mut r Readline) read_line(prompt string) ?string { + s := r.read_line_utf8(prompt) or { + return error(err) + } + return s.s +} + +// Standalone function without persistent functionnalities (eg: history) +// Returns utf8 based ustring +pub fn read_line_utf8(prompt string) ?ustring { + mut r := Readline{} + s := r.read_line_utf8(prompt) or { + return error(err) + } + return s +} + +// Standalone function without persistent functionnalities (eg: history) +// Return string from utf8 ustring +pub fn read_line(prompt string) ?string { + mut r := Readline{} + s := r.read_line(prompt) or { + return error(err) + } + return s +} diff --git a/vlib/readline/readline_netbsd.c.v b/vlib/readline/readline_netbsd.c.v new file mode 100644 index 0000000000..e82e4d976d --- /dev/null +++ b/vlib/readline/readline_netbsd.c.v @@ -0,0 +1,71 @@ +// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved. +// Use of this source code is governed by an MIT license +// that can be found in the LICENSE file. + +// Mac version +// Need to be implemented +// Will serve as more advanced input method +// Based on the work of https://github.com/AmokHuginnsson/replxx + +module readline + +import os + +#include + +// Only use standard os.get_line +// Need implementation for readline capabilities +pub fn (mut r Readline) read_line_utf8(prompt string) ?ustring { + r.current = ''.ustring() + r.cursor = 0 + r.prompt = prompt + r.search_index = 0 + if r.previous_lines.len <= 1 { + r.previous_lines << ''.ustring() + r.previous_lines << ''.ustring() + } + else { + r.previous_lines[0] = ''.ustring() + } + + print(r.prompt) + line := os.get_raw_line() + + if line.len >= 0 { + r.current = line.ustring() + } + r.previous_lines[0] = ''.ustring() + r.search_index = 0 + if r.current.s == '' { + return error('empty line') + } + return r.current +} + +// Returns the string from the utf8 ustring +pub fn (mut r Readline) read_line(prompt string) ?string { + s := r.read_line_utf8(prompt) or { + return error(err) + } + return s.s +} + +// Standalone function without persistent functionnalities (eg: history) +// Returns utf8 based ustring +pub fn read_line_utf8(prompt string) ?ustring { + mut r := Readline{} + s := r.read_line_utf8(prompt) or { + return error(err) + } + return s +} + +// Standalone function without persistent functionnalities (eg: history) +// Return string from utf8 ustring +pub fn read_line(prompt string) ?string { + mut r := Readline{} + s := r.read_line(prompt) or { + return error(err) + } + return s +} diff --git a/vlib/readline/readline_openbsd.c.v b/vlib/readline/readline_openbsd.c.v new file mode 100644 index 0000000000..e82e4d976d --- /dev/null +++ b/vlib/readline/readline_openbsd.c.v @@ -0,0 +1,71 @@ +// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved. +// Use of this source code is governed by an MIT license +// that can be found in the LICENSE file. + +// Mac version +// Need to be implemented +// Will serve as more advanced input method +// Based on the work of https://github.com/AmokHuginnsson/replxx + +module readline + +import os + +#include + +// Only use standard os.get_line +// Need implementation for readline capabilities +pub fn (mut r Readline) read_line_utf8(prompt string) ?ustring { + r.current = ''.ustring() + r.cursor = 0 + r.prompt = prompt + r.search_index = 0 + if r.previous_lines.len <= 1 { + r.previous_lines << ''.ustring() + r.previous_lines << ''.ustring() + } + else { + r.previous_lines[0] = ''.ustring() + } + + print(r.prompt) + line := os.get_raw_line() + + if line.len >= 0 { + r.current = line.ustring() + } + r.previous_lines[0] = ''.ustring() + r.search_index = 0 + if r.current.s == '' { + return error('empty line') + } + return r.current +} + +// Returns the string from the utf8 ustring +pub fn (mut r Readline) read_line(prompt string) ?string { + s := r.read_line_utf8(prompt) or { + return error(err) + } + return s.s +} + +// Standalone function without persistent functionnalities (eg: history) +// Returns utf8 based ustring +pub fn read_line_utf8(prompt string) ?ustring { + mut r := Readline{} + s := r.read_line_utf8(prompt) or { + return error(err) + } + return s +} + +// Standalone function without persistent functionnalities (eg: history) +// Return string from utf8 ustring +pub fn read_line(prompt string) ?string { + mut r := Readline{} + s := r.read_line(prompt) or { + return error(err) + } + return s +} diff --git a/vlib/v/pref/should_compile.v b/vlib/v/pref/should_compile.v index b87d344158..eb4cdf1c02 100644 --- a/vlib/v/pref/should_compile.v +++ b/vlib/v/pref/should_compile.v @@ -60,6 +60,15 @@ pub fn (prefs &Preferences) should_compile_c(file string) bool { if file.ends_with('_freebsd.c.v') && prefs.os != .freebsd { return false } + if file.ends_with('_openbsd.c.v') && prefs.os != .openbsd { + return false + } + if file.ends_with('_netbsd.c.v') && prefs.os != .netbsd { + return false + } + if file.ends_with('_dragonfly.c.v') && prefs.os != .dragonfly { + return false + } if file.ends_with('_solaris.c.v') && prefs.os != .solaris { return false }