Example #1
0
func Newterm(s string, out, in *os.File) (*Screen, error) {
	cs := C.CString(s)
	defer C.free(unsafe.Pointer(cs))
	oFile, iFile := C.fdopen(C.int(out.Fd()), C._wplus_), C.fdopen(C.int(in.Fd()), C._rplus_)
	screen := (*Screen)(C.newterm(cs, oFile, iFile))
	if screen == nil {
		return nil, CursesError{"Failed to create term"}
	}
	return screen, nil
}
Example #2
0
// DebugOut wraps Unbound's ub_ctx_debugout.
func (u *Unbound) DebugOut(out *os.File) error {
	cmode := C.CString("a+")
	defer C.free(unsafe.Pointer(cmode))
	file := C.fdopen(C.int(out.Fd()), cmode)
	i := C.ub_ctx_debugout(u.ctx, unsafe.Pointer(file))
	return newError(int(i))
}
Example #3
0
// file2py opens a stdC file from a Go os.File.  Note the returned file has
// been newly opened: the caller must close it with C.fclose(retval).
func file2py(f *os.File, mode string) *C.FILE {
	cmode := C.CString(mode)
	defer C.free(unsafe.Pointer(cmode))
	fd := f.Fd()
	file := C.fdopen(C.int(fd), cmode)
	return file
}
func (s *Serializer) StartStream(file *os.File, base_uri string) (err error) {
	var buri *C.raptor_uri

	s.mutex.Lock()
	defer s.mutex.Unlock()

	if s.running {
		err = errors.New("serializer already running")
		return
	}
	s.running = true

	if len(base_uri) > 0 {
		cbase_uri := C.CString(base_uri)
		buri = C.raptor_new_uri(s.world, (*C.uchar)(unsafe.Pointer(cbase_uri)))
		C.free(unsafe.Pointer(cbase_uri))
		// XXX LEAK defer C.raptor_free_uri(buri)
	}

	cwb := C.CString("wb")
	fh, err := C.fdopen(C.int(file.Fd()), cwb)
	C.free(unsafe.Pointer(cwb))
	if fh == nil {
		err = errors.New("fdopen: ...")
		return
	}
	s.fh = fh

	if C.raptor_serializer_start_to_file_handle(s.serializer, buri, s.fh) != 0 {
		err = errors.New("raptor_serializer_start_to_file_handle failed")
		return
	}

	return
}
func (s *Serializer) SetFile(fp *os.File, base_uri string) (err error) {
	s.mutex.Lock()
	defer s.mutex.Unlock()

	mode := C.CString("w")
	fh, err := C.fdopen(C.int(fp.Fd()), mode) // do something better with mode?
	C.free(unsafe.Pointer(mode))
	if err != nil {
		return
	}
	s.fh = fh

	var buri *C.raptor_uri
	if len(base_uri) > 0 {
		cbase_uri := C.CString(base_uri)
		buri = C.raptor_new_uri(s.world, (*C.uchar)(unsafe.Pointer(cbase_uri)))
		C.free(unsafe.Pointer(cbase_uri))
		defer C.raptor_free_uri(buri)
	}
	if C.raptor_serializer_start_to_file_handle(s.serializer, buri, s.fh) != 0 {
		err = errors.New("C.raptor_serializer_start_to_file_handle failed")
		return
	}

	s.running = true

	return
}
Example #6
0
// AddFile compiles rules from a file. Rules are added to the
// specified namespace.
func (c *Compiler) AddFile(file *os.File, namespace string) (err error) {
	fd := C.dup(C.int(file.Fd()))
	fh, err := C.fdopen(fd, C.CString("r"))
	if err != nil {
		return err
	}
	defer C.fclose(fh)
	var ns *C.char
	if namespace != "" {
		ns = C.CString(namespace)
		defer C.free(unsafe.Pointer(ns))
	}
	filename := C.CString(file.Name())
	defer C.free(unsafe.Pointer(filename))
	id := callbackData.Put(c)
	defer callbackData.Delete(id)
	C.yr_compiler_set_callback(c.cptr, C.YR_COMPILER_CALLBACK_FUNC(C.compilerCallback), unsafe.Pointer(id))
	numErrors := int(C.yr_compiler_add_file(c.cptr, fh, ns, filename))
	if numErrors > 0 {
		var buf [1024]C.char
		msg := C.GoString(C.yr_compiler_get_error_message(
			c.cptr, (*C.char)(unsafe.Pointer(&buf[0])), 1024))
		err = errors.New(msg)
	}
	return
}
Example #7
0
func Fprintf(stream *os.File, c *GslCombination, format string) int32 {
	_file_0 := C.fdopen(C.dup(C.int(stream.Fd())), (*C.char)(unsafe.Pointer(gogsl.APPEND_ONLY.Ptr())))
	_string_2 := C.CString(format)
	_result := int32(C.gsl_combination_fprintf(_file_0, (*C.gsl_combination)(unsafe.Pointer(c.Ptr())), _string_2))
	C.fclose(_file_0)
	C.free(unsafe.Pointer(_string_2))
	return _result
}
Example #8
0
func VegasParamsSet(s *GslMonteVegasState, params *GslMonteVegasParams) {
	C.set_vegas_params((*C.gsl_monte_vegas_state)(unsafe.Pointer(s.Ptr())),
		C.double(params.Alpha), C.int(params.Iterations),
		C.int(params.Stage), C.int(params.Mode),
		C.int(params.Verbose),
		C.fdopen(C.dup(C.int(params.Ostream.Fd())),
			(*C.char)(unsafe.Pointer(gogsl.APPEND_ONLY.Ptr()))))
}
Example #9
0
func BlockComplexFloatFprintf(stream *os.File, b *GslBlockComplexFloat, format string) int32 {
	_file_0 := C.fdopen(C.dup(C.int(stream.Fd())), (*C.char)(unsafe.Pointer(gogsl.APPEND_ONLY.Ptr())))
	_string_2 := C.CString(format)
	_result := int32(C.gsl_block_complex_float_fprintf(_file_0, (*C.gsl_block_complex_float)(unsafe.Pointer(b.Ptr())), _string_2))
	C.fclose(_file_0)
	C.free(unsafe.Pointer(_string_2))
	return _result
}
Example #10
0
// NewTerm returns a new Screen, representing a physical terminal. If using
// this function to generate a new Screen you should not call Init().
// Unlike Init(), NewTerm does not call Refresh() to clear the screen so this
// will need to be done manually. When finished with a terminal, you must
// call End() in reverse order that each terminal was created in. After you
// are finished with the screen you must call Delete to free the memory
// allocated to it. This function is usually only useful for programs using
// multiple terminals or test for terminal capabilites. The argument termType
// is the type of terminal to be used ($TERM is used if value is "" which also
// has the same effect of using os.Getenv("TERM"))
func NewTerm(termType string, out, in *os.File) (*Screen, error) {
	var tt, wr, rd *C.char
	if termType == "" {
		tt, wr, rd = (*C.char)(nil), C.CString("w"), C.CString("r")
	} else {
		tt, wr, rd = C.CString(termType), C.CString("w"), C.CString("r")
		defer C.free(unsafe.Pointer(tt))
	}
	defer C.free(unsafe.Pointer(wr))
	defer C.free(unsafe.Pointer(rd))

	cout, cin := C.fdopen(C.int(out.Fd()), wr), C.fdopen(C.int(in.Fd()), rd)
	screen := C.newterm(tt, cout, cin)
	if screen == nil {
		return nil, errors.New("Failed to create new screen")
	}
	return &Screen{screen}, nil
}
Example #11
0
func Histogram2dFprintf(stream *os.File, h *GslHistogram2d, rangeFormat string, binFormat string) int32 {
	_file_0 := C.fdopen(C.dup(C.int(stream.Fd())), (*C.char)(unsafe.Pointer(gogsl.APPEND_ONLY.Ptr())))
	_string_2 := C.CString(rangeFormat)
	_string_3 := C.CString(binFormat)
	_result := int32(C.gsl_histogram2d_fprintf(_file_0, (*C.gsl_histogram2d)(unsafe.Pointer(h.Ptr())), _string_2, _string_3))
	C.fclose(_file_0)
	C.free(unsafe.Pointer(_string_2))
	C.free(unsafe.Pointer(_string_3))
	return _result
}
Example #12
0
// Causes 'SIGNONE: no trap'. Not sure why...
func RWFromFP(fp *os.File, ac bool) *RWops {
	acArg := C.int(0)
	if ac {
		acArg = 1
	}

	cmode := C.CString("r+") // Doesn't really matter, anyways. I hope.
	defer C.free(unsafe.Pointer(cmode))
	cfp := C.fdopen(C.int(fp.Fd()), cmode)

	return (*RWops)(C.SDL_RWFromFP(cfp, acArg))
}
Example #13
0
// cfdopen returns a C-level FILE*. mode should be as described in fdopen(3).
func cfdopen(file *os.File, mode string) (*C.FILE, error) {
	cmode := C.CString(mode)
	defer C.free(unsafe.Pointer(cmode))
	// FILE * fdopen(int fildes, const char *mode);
	cfile, err := C.fdopen(C.int(file.Fd()), cmode)
	if err != nil {
		return nil, err
	}
	if cfile == nil {
		return nil, syscall.EINVAL
	}
	return cfile, nil
}
Example #14
0
// write particle information
func PrintParticle(idx int, f *os.File) {
	if f == nil {
		f = os.Stdout
	}
	c_fd := C.int(f.Fd())
	_ = f.Sync()
	c_mode := C.CString("a")
	defer C.free(unsafe.Pointer(c_mode))
	c_f := C.fdopen(c_fd, c_mode)
	C.fflush(c_f)
	C.hepevt_print_particle(C.int(idx+1), c_f)
	C.fflush(c_f)
	_ = f.Sync()
}
Example #15
0
File: c.go Project: h12w/go-zip
func (z *Zip) AddFd(name string, fd uintptr) error {
	z.lock()
	defer z.unlock()
	mode := [...]C.char{'r', 0}
	file := C.fdopen(C.int(fd), &mode[0])
	s, err := z.sourceFileP(file, 0, -1)
	if s == nil {
		return err
	}
	index, err := z.add(name, s)
	if index < 0 {
		s.free()
		return err
	}
	return nil
}
Example #16
0
// cfdopen returns a C-level FILE*. mode should be as described in fdopen(3).
func cfdopen(file *os.File, mode string) (*C.FILE, error) {
	cmode := C.CString(mode)
	defer C.free(unsafe.Pointer(cmode))
	// FILE * fdopen(int fildes, const char *mode);
	cfile, err := C.fdopen(C.int(file.Fd()), cmode)
	// Sometimes err != nil even after successful call because fdopen caught an
	// error but didn't clear errno. See
	// http://comp.unix.programmer.narkive.com/g4gxgYP4/fdopen-cause-illegal-seek
	if cfile == nil {
		if err == nil {
			err = syscall.EINVAL
		}
		return nil, err
	}
	return cfile, nil
}
Example #17
0
// check for problems with HEPEVT common block
func CheckHepevtConsistency(f *os.File) bool {

	if f == nil {
		f = os.Stdout
	}
	c_fd := C.int(f.Fd())
	_ = f.Sync()
	c_mode := C.CString("a")
	defer C.free(unsafe.Pointer(c_mode))
	c_f := C.fdopen(c_fd, c_mode)
	C.fflush(c_f)

	o := C.hepevt_check_hepevt_consistency(c_f)
	C.fflush(c_f)
	_ = f.Sync()

	if o != C.int(0) {
		return true
	}
	return false
}
Example #18
0
func BlockComplexFscanf(stream *os.File, b *GslBlockComplex) int32 {
	_file_0 := C.fdopen(C.dup(C.int(stream.Fd())), (*C.char)(unsafe.Pointer(gogsl.APPEND_ONLY.Ptr())))
	_result := int32(C.gsl_block_complex_fscanf(_file_0, (*C.gsl_block_complex)(unsafe.Pointer(b.Ptr()))))
	C.fclose(_file_0)
	return _result
}
Example #19
0
func BlockUcharFwrite(stream *os.File, b *GslBlockUchar) int32 {
	_file_0 := C.fdopen(C.dup(C.int(stream.Fd())), (*C.char)(unsafe.Pointer(gogsl.APPEND_ONLY.Ptr())))
	_result := int32(C.gsl_block_uchar_fwrite(_file_0, (*C.gsl_block_uchar)(unsafe.Pointer(b.Ptr()))))
	C.fclose(_file_0)
	return _result
}
Example #20
0
File: rng.go Project: postfix/gsl-1
func Fread(stream *os.File, r *GslRng) int32 {
	_file_0 := C.fdopen(C.dup(C.int(stream.Fd())), (*C.char)(unsafe.Pointer(gogsl.APPEND_ONLY.Ptr())))
	_result := int32(C.gsl_rng_fread(_file_0, (*C.gsl_rng)(unsafe.Pointer(r.Ptr()))))
	C.fclose(_file_0)
	return _result
}
Example #21
0
func Fscanf(stream *os.File, c *GslCombination) int32 {
	_file_0 := C.fdopen(C.dup(C.int(stream.Fd())), (*C.char)(unsafe.Pointer(gogsl.APPEND_ONLY.Ptr())))
	_result := int32(C.gsl_combination_fscanf(_file_0, (*C.gsl_combination)(unsafe.Pointer(c.Ptr()))))
	C.fclose(_file_0)
	return _result
}
Example #22
0
func Fwrite(stream *os.File, c *GslMultiset) int32 {
	_file_0 := C.fdopen(C.dup(C.int(stream.Fd())), (*C.char)(unsafe.Pointer(gogsl.APPEND_ONLY.Ptr())))
	_result := int32(C.gsl_multiset_fwrite(_file_0, (*C.gsl_multiset)(unsafe.Pointer(c.Ptr()))))
	C.fclose(_file_0)
	return _result
}
Example #23
0
func Histogram2dFscanf(stream *os.File, h *GslHistogram2d) int32 {
	_file_0 := C.fdopen(C.dup(C.int(stream.Fd())), (*C.char)(unsafe.Pointer(gogsl.APPEND_ONLY.Ptr())))
	_result := int32(C.gsl_histogram2d_fscanf(_file_0, (*C.gsl_histogram2d)(unsafe.Pointer(h.Ptr()))))
	C.fclose(_file_0)
	return _result
}
Example #24
0
func BlockFloatFread(stream *os.File, b *GslBlockFloat) int32 {
	_file_0 := C.fdopen(C.dup(C.int(stream.Fd())), (*C.char)(unsafe.Pointer(gogsl.APPEND_ONLY.Ptr())))
	_result := int32(C.gsl_block_float_fread(_file_0, (*C.gsl_block_float)(unsafe.Pointer(b.Ptr()))))
	C.fclose(_file_0)
	return _result
}
Example #25
0
func Fread(stream *os.File, p *GslPermutation) int32 {
	_file_0 := C.fdopen(C.dup(C.int(stream.Fd())), (*C.char)(unsafe.Pointer(gogsl.APPEND_ONLY.Ptr())))
	_result := int32(C.gsl_permutation_fread(_file_0, (*C.gsl_permutation)(unsafe.Pointer(p.Ptr()))))
	C.fclose(_file_0)
	return _result
}