mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
parent
7c92435f8f
commit
f766acad62
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -7,5 +7,4 @@
|
||||
src/etc/pkg/rust-logo.ico binary
|
||||
src/rt/msvc/* -whitespace
|
||||
src/rt/vg/* -whitespace
|
||||
src/rt/linenoise/* -whitespace
|
||||
src/rt/jemalloc/**/* -whitespace
|
||||
|
2
configure
vendored
2
configure
vendored
@ -686,7 +686,7 @@ do
|
||||
make_dir $t/rt/libuv/src/ev
|
||||
make_dir $t/rt/jemalloc
|
||||
for i in \
|
||||
isaac linenoise sync test \
|
||||
isaac sync test \
|
||||
arch/i386 arch/x86_64 arch/arm arch/mips \
|
||||
sundown/src sundown/html
|
||||
do
|
||||
|
@ -29,7 +29,7 @@ $(foreach t,$(CFG_TARGET_TRIPLES),$(info cfg: os for $(t) is $(OSTYPE_$(t))))
|
||||
# FIXME: no-omit-frame-pointer is just so that task_start_wrapper
|
||||
# has a frame pointer and the stack walker can understand it. Turning off
|
||||
# frame pointers everywhere is overkill
|
||||
CFG_GCCISH_CFLAGS += -fno-omit-frame-pointer -DUSE_UTF8
|
||||
CFG_GCCISH_CFLAGS += -fno-omit-frame-pointer
|
||||
|
||||
# On Darwin, we need to run dsymutil so the debugging information ends
|
||||
# up in the right place. On other platforms, it automatically gets
|
||||
|
5
mk/rt.mk
5
mk/rt.mk
@ -96,9 +96,7 @@ RUNTIME_CXXS_$(1)_$(2) := \
|
||||
rt/rust_android_dummy.cpp \
|
||||
rt/rust_test_helpers.cpp
|
||||
|
||||
RUNTIME_CS_$(1)_$(2) := rt/linenoise/linenoise.c \
|
||||
rt/linenoise/utf8.c \
|
||||
rt/sundown/src/autolink.c \
|
||||
RUNTIME_CS_$(1)_$(2) := rt/sundown/src/autolink.c \
|
||||
rt/sundown/src/buffer.c \
|
||||
rt/sundown/src/stack.c \
|
||||
rt/sundown/src/markdown.c \
|
||||
@ -116,7 +114,6 @@ RT_BUILD_DIR_$(1)_$(2) := $$(RT_OUTPUT_DIR_$(1))/stage$(2)
|
||||
RUNTIME_DEF_$(1)_$(2) := $$(RT_OUTPUT_DIR_$(1))/rustrt$$(CFG_DEF_SUFFIX_$(1))
|
||||
RUNTIME_INCS_$(1)_$(2) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \
|
||||
-I $$(S)src/rt/arch/$$(HOST_$(1)) \
|
||||
-I $$(S)src/rt/linenoise \
|
||||
-I $$(S)src/rt/sundown/src \
|
||||
-I $$(S)src/rt/sundown/html \
|
||||
-I $$(S)src/libuv/include
|
||||
|
@ -227,7 +227,6 @@ ALL_CS := $(wildcard $(S)src/rt/*.cpp \
|
||||
$(S)src/rt/*/*/*.cpp \
|
||||
$(S)src/rustllvm/*.cpp)
|
||||
ALL_CS := $(filter-out $(S)src/rt/miniz.cpp \
|
||||
$(wildcard $(S)src/rt/linenoise/*.c) \
|
||||
$(wildcard $(S)src/rt/sundown/src/*.c) \
|
||||
$(wildcard $(S)src/rt/sundown/html/*.c) \
|
||||
,$(ALL_CS))
|
||||
@ -240,8 +239,6 @@ ALL_HS := $(filter-out $(S)src/rt/vg/valgrind.h \
|
||||
$(S)src/rt/msvc/typeof.h \
|
||||
$(S)src/rt/msvc/stdint.h \
|
||||
$(S)src/rt/msvc/inttypes.h \
|
||||
$(S)src/rt/linenoise/linenoise.h \
|
||||
$(S)src/rt/linenoise/utf8.h \
|
||||
$(wildcard $(S)src/rt/sundown/src/*.h) \
|
||||
$(wildcard $(S)src/rt/sundown/html/*.h) \
|
||||
,$(ALL_HS))
|
||||
|
@ -17,7 +17,6 @@ rt/sync - Concurrency utils
|
||||
rt/util - Small utility classes for the runtime.
|
||||
rt/vg - Valgrind headers
|
||||
rt/msvc - MSVC support
|
||||
rt/linenoise - a readline-like line editing library
|
||||
|
||||
test/ Testsuite
|
||||
test/compile-fail - Tests that should fail to compile
|
||||
|
@ -94,7 +94,6 @@ pub mod term;
|
||||
pub mod time;
|
||||
pub mod arena;
|
||||
pub mod base64;
|
||||
pub mod rl;
|
||||
pub mod workcache;
|
||||
pub mod enum_set;
|
||||
#[path="num/bigint.rs"]
|
||||
|
@ -1,143 +0,0 @@
|
||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//! Bindings for the ability to read lines of input from the console
|
||||
|
||||
use std::c_str::ToCStr;
|
||||
use std::libc::{c_char, c_int};
|
||||
use std::{local_data, str, rt};
|
||||
use std::unstable::finally::Finally;
|
||||
|
||||
mod rustrt {
|
||||
use std::libc::{c_char, c_int};
|
||||
|
||||
externfn!(fn linenoise(prompt: *c_char) -> *c_char)
|
||||
externfn!(fn linenoiseHistoryAdd(line: *c_char) -> c_int)
|
||||
externfn!(fn linenoiseHistorySetMaxLen(len: c_int) -> c_int)
|
||||
externfn!(fn linenoiseHistorySave(file: *c_char) -> c_int)
|
||||
externfn!(fn linenoiseHistoryLoad(file: *c_char) -> c_int)
|
||||
externfn!(fn linenoiseSetCompletionCallback(callback: extern "C" fn(*i8, *())))
|
||||
externfn!(fn linenoiseAddCompletion(completions: *(), line: *c_char))
|
||||
|
||||
externfn!(fn rust_take_linenoise_lock())
|
||||
externfn!(fn rust_drop_linenoise_lock())
|
||||
}
|
||||
|
||||
macro_rules! locked {
|
||||
($expr:expr) => {
|
||||
{
|
||||
// FIXME #9105: can't use a static mutex in pure Rust yet.
|
||||
rustrt::rust_take_linenoise_lock();
|
||||
let x = $expr;
|
||||
rustrt::rust_drop_linenoise_lock();
|
||||
x
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Add a line to history
|
||||
pub fn add_history(line: &str) -> bool {
|
||||
do line.with_c_str |buf| {
|
||||
unsafe {
|
||||
(locked!(rustrt::linenoiseHistoryAdd(buf))) == 1 as c_int
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the maximum amount of lines stored
|
||||
pub fn set_history_max_len(len: int) -> bool {
|
||||
unsafe {
|
||||
(locked!(rustrt::linenoiseHistorySetMaxLen(len as c_int))) == 1
|
||||
as c_int
|
||||
}
|
||||
}
|
||||
|
||||
/// Save line history to a file
|
||||
pub fn save_history(file: &str) -> bool {
|
||||
do file.with_c_str |buf| {
|
||||
// 0 on success, -1 on failure
|
||||
unsafe {
|
||||
(locked!(rustrt::linenoiseHistorySave(buf))) == 0 as c_int
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Load line history from a file
|
||||
pub fn load_history(file: &str) -> bool {
|
||||
do file.with_c_str |buf| {
|
||||
// 0 on success, -1 on failure
|
||||
unsafe {
|
||||
(locked!(rustrt::linenoiseHistoryLoad(buf))) == 0 as c_int
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Print out a prompt and then wait for input and return it
|
||||
pub fn read(prompt: &str) -> Option<~str> {
|
||||
do prompt.with_c_str |buf| {
|
||||
let line = unsafe {
|
||||
locked!(rustrt::linenoise(buf))
|
||||
};
|
||||
|
||||
if line.is_null() { None }
|
||||
else {
|
||||
unsafe {
|
||||
do (|| {
|
||||
Some(str::raw::from_c_str(line))
|
||||
}).finally {
|
||||
// linenoise's return value is from strdup, so we
|
||||
// better not leak it.
|
||||
rt::global_heap::exchange_free(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The callback used to perform completions.
|
||||
pub trait CompletionCb {
|
||||
/// Performs a completion.
|
||||
fn complete(&self, line: ~str, suggestion: &fn(~str));
|
||||
}
|
||||
|
||||
local_data_key!(complete_key: @CompletionCb)
|
||||
|
||||
/// Bind to the main completion callback in the current task.
|
||||
///
|
||||
/// The completion callback should not call any `extra::rl` functions
|
||||
/// other than the closure that it receives as its second
|
||||
/// argument. Calling such a function will deadlock on the mutex used
|
||||
/// to ensure that the calls are thread-safe.
|
||||
pub unsafe fn complete(cb: @CompletionCb) {
|
||||
local_data::set(complete_key, cb);
|
||||
|
||||
extern fn callback(line: *c_char, completions: *()) {
|
||||
do local_data::get(complete_key) |opt_cb| {
|
||||
// only fetch completions if a completion handler has been
|
||||
// registered in the current task.
|
||||
match opt_cb {
|
||||
None => {}
|
||||
Some(cb) => {
|
||||
unsafe {
|
||||
do cb.complete(str::raw::from_c_str(line))
|
||||
|suggestion| {
|
||||
do suggestion.with_c_str |buf| {
|
||||
rustrt::linenoiseAddCompletion(completions,
|
||||
buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
locked!(rustrt::linenoiseSetCompletionCallback(callback));
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
# Linenoise
|
||||
|
||||
A minimal, zero-config, BSD licensed, readline replacement.
|
||||
|
||||
News: linenoise now includes minimal completion support, thanks to Pieter Noordhuis (@pnoordhuis).
|
||||
|
||||
News: linenoise is now part of [Android](http://android.git.kernel.org/?p=platform/system/core.git;a=tree;f=liblinenoise;h=56450eaed7f783760e5e6a5993ef75cde2e29dea;hb=HEAD Android)!
|
||||
|
||||
## Can a line editing library be 20k lines of code?
|
||||
|
||||
Line editing with some support for history is a really important feature for command line utilities. Instead of retyping almost the same stuff again and again it's just much better to hit the up arrow and edit on syntax errors, or in order to try a slightly different command. But apparently code dealing with terminals is some sort of Black Magic: readline is 30k lines of code, libedit 20k. Is it reasonable to link small utilities to huge libraries just to get a minimal support for line editing?
|
||||
|
||||
So what usually happens is either:
|
||||
|
||||
* Large programs with configure scripts disabling line editing if readline is not present in the system, or not supporting it at all since readline is GPL licensed and libedit (the BSD clone) is not as known and available as readline is (Real world example of this problem: Tclsh).
|
||||
* Smaller programs not using a configure script not supporting line editing at all (A problem we had with Redis-cli for instance).
|
||||
|
||||
The result is a pollution of binaries without line editing support.
|
||||
|
||||
So I spent more or less two hours doing a reality check resulting in this little library: is it *really* needed for a line editing library to be 20k lines of code? Apparently not, it is possibe to get a very small, zero configuration, trivial to embed library, that solves the problem. Smaller programs will just include this, supporing line editing out of the box. Larger programs may use this little library or just checking with configure if readline/libedit is available and resorting to linenoise if not.
|
||||
|
||||
## Terminals, in 2010.
|
||||
|
||||
Apparently almost every terminal you can happen to use today has some kind of support for VT100 alike escape sequences. So I tried to write a lib using just very basic VT100 features. The resulting library appears to work everywhere I tried to use it.
|
||||
|
||||
Since it's so young I guess there are a few bugs, or the lib may not compile or work with some operating system, but it's a matter of a few weeks and eventually we'll get it right, and there will be no excuses for not shipping command line tools without built-in line editing support.
|
||||
|
||||
The library is currently less than 400 lines of code. In order to use it in your project just look at the *example.c* file in the source distribution, it is trivial. Linenoise is BSD code, so you can use both in free software and commercial software.
|
||||
|
||||
## Tested with...
|
||||
|
||||
* Linux text only console ($TERM = linux)
|
||||
* Linux KDE terminal application ($TERM = xterm)
|
||||
* Linux xterm ($TERM = xterm)
|
||||
* Mac OS X iTerm ($TERM = xterm)
|
||||
* Mac OS X default Terminal.app ($TERM = xterm)
|
||||
* OpenBSD 4.5 through an OSX Terminal.app ($TERM = screen)
|
||||
* IBM AIX 6.1
|
||||
* FreeBSD xterm ($TERM = xterm)
|
||||
|
||||
Please test it everywhere you can and report back!
|
||||
|
||||
## Let's push this forward!
|
||||
|
||||
Please fork it and add something interesting and send me a pull request. What's especially interesting are fixes, new key bindings, completion.
|
||||
|
||||
Send feedbacks to antirez at gmail
|
@ -1,30 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "linenoise.h"
|
||||
|
||||
#ifndef NO_COMPLETION
|
||||
void completion(const char *buf, linenoiseCompletions *lc) {
|
||||
if (buf[0] == 'h') {
|
||||
linenoiseAddCompletion(lc,"hello");
|
||||
linenoiseAddCompletion(lc,"hello there");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(void) {
|
||||
char *line;
|
||||
|
||||
#ifndef NO_COMPLETION
|
||||
linenoiseSetCompletionCallback(completion);
|
||||
#endif
|
||||
linenoiseHistoryLoad("history.txt"); /* Load the history at startup */
|
||||
while((line = linenoise("hello> ")) != NULL) {
|
||||
if (line[0] != '\0') {
|
||||
printf("echo: '%s'\n", line);
|
||||
linenoiseHistoryAdd(line);
|
||||
linenoiseHistorySave("history.txt"); /* Save every new entry */
|
||||
}
|
||||
free(line);
|
||||
}
|
||||
return 0;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,61 +0,0 @@
|
||||
/* linenoise.h -- guerrilla line editing library against the idea that a
|
||||
* line editing lib needs to be 20,000 lines of C code.
|
||||
*
|
||||
* See linenoise.c for more information.
|
||||
*
|
||||
* ------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com>
|
||||
* Copyright (c) 2010, Pieter Noordhuis <pcnoordhuis at gmail dot com>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __LINENOISE_H
|
||||
#define __LINENOISE_H
|
||||
|
||||
#ifndef NO_COMPLETION
|
||||
typedef struct linenoiseCompletions {
|
||||
size_t len;
|
||||
char **cvec;
|
||||
} linenoiseCompletions;
|
||||
|
||||
typedef void(linenoiseCompletionCallback)(const char *, linenoiseCompletions *);
|
||||
void linenoiseSetCompletionCallback(linenoiseCompletionCallback *);
|
||||
void linenoiseAddCompletion(linenoiseCompletions *, const char *);
|
||||
#endif
|
||||
|
||||
char *linenoise(const char *prompt);
|
||||
int linenoiseHistoryAdd(const char *line);
|
||||
int linenoiseHistorySetMaxLen(int len);
|
||||
int linenoiseHistoryGetMaxLen(void);
|
||||
int linenoiseHistorySave(const char *filename);
|
||||
int linenoiseHistoryLoad(const char *filename);
|
||||
void linenoiseHistoryFree(void);
|
||||
char **linenoiseHistory(int *len);
|
||||
int linenoiseColumns(void);
|
||||
|
||||
#endif /* __LINENOISE_H */
|
@ -1,115 +0,0 @@
|
||||
/**
|
||||
* UTF-8 utility functions
|
||||
*
|
||||
* (c) 2010 Steve Bennett <steveb@workware.net.au>
|
||||
*
|
||||
* See LICENCE for licence details.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "utf8.h"
|
||||
|
||||
#ifdef USE_UTF8
|
||||
int utf8_fromunicode(char *p, unsigned short uc)
|
||||
{
|
||||
if (uc <= 0x7f) {
|
||||
*p = uc;
|
||||
return 1;
|
||||
}
|
||||
else if (uc <= 0x7ff) {
|
||||
*p++ = 0xc0 | ((uc & 0x7c0) >> 6);
|
||||
*p = 0x80 | (uc & 0x3f);
|
||||
return 2;
|
||||
}
|
||||
else {
|
||||
*p++ = 0xe0 | ((uc & 0xf000) >> 12);
|
||||
*p++ = 0x80 | ((uc & 0xfc0) >> 6);
|
||||
*p = 0x80 | (uc & 0x3f);
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
int utf8_charlen(int c)
|
||||
{
|
||||
if ((c & 0x80) == 0) {
|
||||
return 1;
|
||||
}
|
||||
if ((c & 0xe0) == 0xc0) {
|
||||
return 2;
|
||||
}
|
||||
if ((c & 0xf0) == 0xe0) {
|
||||
return 3;
|
||||
}
|
||||
if ((c & 0xf8) == 0xf0) {
|
||||
return 4;
|
||||
}
|
||||
/* Invalid sequence */
|
||||
return -1;
|
||||
}
|
||||
|
||||
int utf8_strlen(const char *str, int bytelen)
|
||||
{
|
||||
int charlen = 0;
|
||||
if (bytelen < 0) {
|
||||
bytelen = strlen(str);
|
||||
}
|
||||
while (bytelen) {
|
||||
int c;
|
||||
int l = utf8_tounicode(str, &c);
|
||||
charlen++;
|
||||
str += l;
|
||||
bytelen -= l;
|
||||
}
|
||||
return charlen;
|
||||
}
|
||||
|
||||
int utf8_index(const char *str, int index)
|
||||
{
|
||||
const char *s = str;
|
||||
while (index--) {
|
||||
int c;
|
||||
s += utf8_tounicode(s, &c);
|
||||
}
|
||||
return s - str;
|
||||
}
|
||||
|
||||
int utf8_charequal(const char *s1, const char *s2)
|
||||
{
|
||||
int c1, c2;
|
||||
|
||||
utf8_tounicode(s1, &c1);
|
||||
utf8_tounicode(s2, &c2);
|
||||
|
||||
return c1 == c2;
|
||||
}
|
||||
|
||||
int utf8_tounicode(const char *str, int *uc)
|
||||
{
|
||||
unsigned const char *s = (unsigned const char *)str;
|
||||
|
||||
if (s[0] < 0xc0) {
|
||||
*uc = s[0];
|
||||
return 1;
|
||||
}
|
||||
if (s[0] < 0xe0) {
|
||||
if ((s[1] & 0xc0) == 0x80) {
|
||||
*uc = ((s[0] & ~0xc0) << 6) | (s[1] & ~0x80);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
else if (s[0] < 0xf0) {
|
||||
if (((str[1] & 0xc0) == 0x80) && ((str[2] & 0xc0) == 0x80)) {
|
||||
*uc = ((s[0] & ~0xe0) << 12) | ((s[1] & ~0x80) << 6) | (s[2] & ~0x80);
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
/* Invalid sequence, so just return the byte */
|
||||
*uc = *s;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,79 +0,0 @@
|
||||
#ifndef UTF8_UTIL_H
|
||||
#define UTF8_UTIL_H
|
||||
/**
|
||||
* UTF-8 utility functions
|
||||
*
|
||||
* (c) 2010 Steve Bennett <steveb@workware.net.au>
|
||||
*
|
||||
* See LICENCE for licence details.
|
||||
*/
|
||||
|
||||
#ifndef USE_UTF8
|
||||
#include <ctype.h>
|
||||
|
||||
/* No utf-8 support. 1 byte = 1 char */
|
||||
#define utf8_strlen(S, B) ((B) < 0 ? (int)strlen(S) : (B))
|
||||
#define utf8_tounicode(S, CP) (*(CP) = (unsigned char)*(S), 1)
|
||||
#define utf8_index(C, I) (I)
|
||||
#define utf8_charlen(C) 1
|
||||
|
||||
#else
|
||||
/**
|
||||
* Converts the given unicode codepoint (0 - 0xffff) to utf-8
|
||||
* and stores the result at 'p'.
|
||||
*
|
||||
* Returns the number of utf-8 characters (1-3).
|
||||
*/
|
||||
int utf8_fromunicode(char *p, unsigned short uc);
|
||||
|
||||
/**
|
||||
* Returns the length of the utf-8 sequence starting with 'c'.
|
||||
*
|
||||
* Returns 1-4, or -1 if this is not a valid start byte.
|
||||
*
|
||||
* Note that charlen=4 is not supported by the rest of the API.
|
||||
*/
|
||||
int utf8_charlen(int c);
|
||||
|
||||
/**
|
||||
* Returns the number of characters in the utf-8
|
||||
* string of the given byte length.
|
||||
*
|
||||
* Any bytes which are not part of an valid utf-8
|
||||
* sequence are treated as individual characters.
|
||||
*
|
||||
* The string *must* be null terminated.
|
||||
*
|
||||
* Does not support unicode code points > \uffff
|
||||
*/
|
||||
int utf8_strlen(const char *str, int bytelen);
|
||||
|
||||
/**
|
||||
* Returns the byte index of the given character in the utf-8 string.
|
||||
*
|
||||
* The string *must* be null terminated.
|
||||
*
|
||||
* This will return the byte length of a utf-8 string
|
||||
* if given the char length.
|
||||
*/
|
||||
int utf8_index(const char *str, int charindex);
|
||||
|
||||
/**
|
||||
* Returns the unicode codepoint corresponding to the
|
||||
* utf-8 sequence 'str'.
|
||||
*
|
||||
* Stores the result in *uc and returns the number of bytes
|
||||
* consumed.
|
||||
*
|
||||
* If 'str' is null terminated, then an invalid utf-8 sequence
|
||||
* at the end of the string will be returned as individual bytes.
|
||||
*
|
||||
* If it is not null terminated, the length *must* be checked first.
|
||||
*
|
||||
* Does not support unicode code points > \uffff
|
||||
*/
|
||||
int utf8_tounicode(const char *str, int *uc);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
@ -570,18 +570,6 @@ rust_drop_env_lock() {
|
||||
env_lock.unlock();
|
||||
}
|
||||
|
||||
static lock_and_signal linenoise_lock;
|
||||
|
||||
extern "C" CDECL void
|
||||
rust_take_linenoise_lock() {
|
||||
linenoise_lock.lock();
|
||||
}
|
||||
|
||||
extern "C" CDECL void
|
||||
rust_drop_linenoise_lock() {
|
||||
linenoise_lock.unlock();
|
||||
}
|
||||
|
||||
static lock_and_signal dlerror_lock;
|
||||
|
||||
extern "C" CDECL void
|
||||
|
@ -133,13 +133,6 @@ tinfl_decompress_mem_to_heap
|
||||
rust_uv_ip4_port
|
||||
rust_uv_ip6_port
|
||||
rust_uv_tcp_getpeername
|
||||
linenoise
|
||||
linenoiseSetCompletionCallback
|
||||
linenoiseAddCompletion
|
||||
linenoiseHistoryAdd
|
||||
linenoiseHistorySetMaxLen
|
||||
linenoiseHistorySave
|
||||
linenoiseHistoryLoad
|
||||
rust_raw_thread_start
|
||||
rust_raw_thread_join
|
||||
rust_raw_thread_delete
|
||||
@ -187,8 +180,6 @@ rust_get_num_cpus
|
||||
rust_get_global_args_ptr
|
||||
rust_take_global_args_lock
|
||||
rust_drop_global_args_lock
|
||||
rust_take_linenoise_lock
|
||||
rust_drop_linenoise_lock
|
||||
rust_get_test_int
|
||||
rust_get_task
|
||||
rust_uv_get_loop_from_getaddrinfo_req
|
||||
|
@ -1,15 +0,0 @@
|
||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[link(name = "linenoise",
|
||||
vers = "0.1")];
|
||||
#[crate_type = "lib"];
|
||||
|
||||
pub mod issue_3882;
|
@ -1,21 +0,0 @@
|
||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
mod issue_3882 {
|
||||
struct Completions {
|
||||
len: libc::size_t,
|
||||
}
|
||||
|
||||
mod c {
|
||||
extern {
|
||||
fn linenoiseAddCompletion(lc: *mut Completions);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// xfail-test
|
||||
// aux-build:issue_3882.rc
|
||||
extern mod linenoise;
|
||||
use linenoise::issue_3882::*;
|
||||
|
||||
pub fn main() {}
|
@ -1,83 +0,0 @@
|
||||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// xfail-fast no compile flags for check-fast
|
||||
|
||||
// we want this to be compiled to avoid bitrot, but the actual test
|
||||
//has to be conducted by a human, i.e. someone (you?) compiling this
|
||||
//file with a plain rustc invocation and running it and checking it
|
||||
//works.
|
||||
|
||||
// compile-flags: --cfg robot_mode
|
||||
|
||||
extern mod extra;
|
||||
use extra::rl;
|
||||
|
||||
static HISTORY_FILE: &'static str = "rl-human-test-history.txt";
|
||||
|
||||
struct TestCompleter;
|
||||
|
||||
impl rl::CompletionCb for TestCompleter {
|
||||
fn complete(&self, line: ~str, suggest: &fn(~str)) {
|
||||
if line.is_empty() {
|
||||
suggest(~"empty")
|
||||
} else {
|
||||
for c in line.rev_iter().take(3) {
|
||||
suggest(format!("{0}{1}{1}{1}", line, c))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// don't run this in robot mode, but still typecheck it.
|
||||
if !cfg!(robot_mode) {
|
||||
println("~~ Welcome to the rl test \"suite\". ~~");
|
||||
println!("Operations:
|
||||
- restrict the history to 2 lines,
|
||||
- set the tab-completion to suggest three copies of each of the last 3 letters (or 'empty'),
|
||||
- add 'one' and 'two' to the history,
|
||||
- save it to `{0}`,
|
||||
- add 'three',
|
||||
- prompt & save input (check the history & completion work and contains only 'two', 'three'),
|
||||
- load from `{0}`
|
||||
- prompt & save input (history should be 'one', 'two' again),
|
||||
- prompt once more.
|
||||
|
||||
The bool return values of each step are printed.",
|
||||
HISTORY_FILE);
|
||||
|
||||
println!("restricting history length: {}", rl::set_history_max_len(3));
|
||||
|
||||
unsafe {
|
||||
rl::complete(@TestCompleter as @rl::CompletionCb);
|
||||
}
|
||||
|
||||
println!("adding 'one': {}", rl::add_history("one"));
|
||||
println!("adding 'two': {}", rl::add_history("two"));
|
||||
|
||||
println!("saving history: {}", rl::save_history(HISTORY_FILE));
|
||||
|
||||
println!("adding 'three': {}", rl::add_history("three"));
|
||||
|
||||
match rl::read("> ") {
|
||||
Some(s) => println!("saving input: {}", rl::add_history(s)),
|
||||
None => return
|
||||
}
|
||||
println!("loading history: {}", rl::load_history(HISTORY_FILE));
|
||||
|
||||
match rl::read("> ") {
|
||||
Some(s) => println!("saving input: {}", rl::add_history(s)),
|
||||
None => return
|
||||
}
|
||||
|
||||
rl::read("> ");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user