Anonymous avatar Anonymous committed 489f18d

os.Errno -> syscall.Errno

Comments (0)

Files changed (1)

  #include <string.h>
  #include <readline/readline.h>
  #include <readline/history.h>
- */
+
+ char* _go_readline_strarray_at(char **strarray, int idx) 
+ {
+   return strarray[idx];
+ }
+
+ int _go_readline_strarray_len(char **strarray)
+ {
+   int sz = 0;
+   while (strarray[sz] != NULL) {
+     sz += 1;
+   }
+   return sz;
+ }
+*/
 import "C"
 import "unsafe"
-import "os"
+import "syscall"
 
 func ReadLine(prompt *string) *string {
-	var p *C.char;
+	var p *C.char
 
 	//readline allows an empty prompt(NULL)
-	if prompt != nil { p = C.CString(*prompt) }
+	if prompt != nil {
+		p = C.CString(*prompt)
+	}
 
-	ret := C.readline(p);
+	ret := C.readline(p)
 
-	if p != nil { C.free(unsafe.Pointer(p)) }
+	if p != nil {
+		C.free(unsafe.Pointer(p))
+	}
 
-	if ret == nil { return nil } //EOF
+	if ret == nil {
+		return nil
+	} //EOF
 
-	s := C.GoString(ret);
-	C.free(unsafe.Pointer(ret));
+	s := C.GoString(ret)
+	C.free(unsafe.Pointer(ret))
 	return &s
 }
 
 func AddHistory(s string) {
-	p := C.CString(s);
+	p := C.CString(s)
 	defer C.free(unsafe.Pointer(p))
-	C.add_history(p);	
+	C.add_history(p)
 }
 
 // Parse and execute single line of a readline init file.
 
 // Parse a readline initialization file.
 // The default filename is the last filename used.
-func ReadInitFile(s string) os.Errno {
+func ReadInitFile(s string) error {
 	p := C.CString(s)
 	defer C.free(unsafe.Pointer(p))
 	errno := C.rl_read_init_file(p)
-	return os.Errno(errno)
+	if errno == 0 {
+		return nil
+	}
+	return syscall.Errno(errno)
 }
 
 // Load a readline history file.
 // The default filename is ~/.history.
-func ReadHistoryFile(s string) os.Errno {
+func ReadHistoryFile(s string) error {
 	p := C.CString(s)
 	defer C.free(unsafe.Pointer(p))
 	errno := C.read_history(p)
-	return os.Errno(errno)
+	if errno == 0 {
+		return nil
+	}
+	return syscall.Errno(errno)
 }
 
 var (
 
 // Save a readline history file.
 // The default filename is ~/.history.
-func WriteHistoryFile(s string) os.Errno {
+func WriteHistoryFile(s string) error {
 	p := C.CString(s)
 	defer C.free(unsafe.Pointer(p))
 	errno := C.write_history(p)
-	if errno==0 && HistoryLength >= 0 {
+	if errno == 0 && HistoryLength >= 0 {
 		errno = C.history_truncate_file(p, C.int(HistoryLength))
 	}
-	return os.Errno(errno)
+	if errno == 0 {
+		return nil
+	}
+	return syscall.Errno(errno)
 }
 
 // Set the readline word delimiters for tab-completion
 	delims := C.GoString(cstr)
 	return delims
 }
+
+// 
+func CompletionMatches(text string, cbk func(text string, state int) string) []string {
+	c_text := C.CString(text)
+	defer C.free(unsafe.Pointer(c_text))
+	c_cbk := (*C.rl_compentry_func_t)(unsafe.Pointer(&cbk))
+	c_matches := C.rl_completion_matches(c_text, c_cbk)
+	n_matches := int(C._go_readline_strarray_len(c_matches))
+	matches := make([]string, n_matches)
+	for i := 0; i < n_matches; i++ {
+		matches[i] = C.GoString(C._go_readline_strarray_at(c_matches, C.int(i)))
+	}
+	return matches
+}
+
+//
+func SetAttemptedCompletionFunction(cbk func(text string, start, end int) []string) {
+	c_cbk := (*C.rl_completion_func_t)(unsafe.Pointer(&cbk))
+	C.rl_attempted_completion_function = c_cbk
+}
 /* EOF */
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.