|  | @@ -11,26 +11,69 @@ import (
 | 
	
		
			
				|  |  |  // This assumes that d.writerMutex is locked.
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  type OSWriter struct {
 | 
	
		
			
				|  |  | -	Mutex  sync.Mutex // Writer mutex
 | 
	
		
			
				|  |  | -	Closed bool
 | 
	
		
			
				|  |  | -	Handle int
 | 
	
		
			
				|  |  | +	Mutex              sync.Mutex // Writer mutex
 | 
	
		
			
				|  |  | +	Closed             bool
 | 
	
		
			
				|  |  | +	Handle             int
 | 
	
		
			
				|  |  | +	TranslateNL        bool
 | 
	
		
			
				|  |  | +	TranslateToUnicode bool
 | 
	
		
			
				|  |  | +	nlBuffer           *bytes.Buffer
 | 
	
		
			
				|  |  | +	uniBuffer          *bytes.Buffer
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  func (ow *OSWriter) Init(d *Door) {
 | 
	
		
			
				|  |  |  	ow.Closed = false
 | 
	
		
			
				|  |  |  	ow.Handle = d.Config.Comm_handle
 | 
	
		
			
				|  |  | +	ow.TranslateNL = true // Yes, translate NL => CR+NL
 | 
	
		
			
				|  |  | +	ow.nlBuffer = &bytes.Buffer{}
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +func (ow *OSWriter) CP437toUnicode(output []byte) []byte {
 | 
	
		
			
				|  |  | +	if ow.uniBuffer == nil {
 | 
	
		
			
				|  |  | +		ow.uniBuffer = &bytes.Buffer{}
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	return ow.uniBuffer.Bytes()
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +func (ow *OSWriter) NewLines(output []byte) []byte {
 | 
	
		
			
				|  |  | +	var pos, nextpos int
 | 
	
		
			
				|  |  | +	ow.nlBuffer.Reset()
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	for pos != -1 {
 | 
	
		
			
				|  |  | +		nextpos = bytes.Index(output[pos:], []byte{'\n'})
 | 
	
		
			
				|  |  | +		if nextpos != -1 {
 | 
	
		
			
				|  |  | +			nextpos += pos
 | 
	
		
			
				|  |  | +			// Something to do
 | 
	
		
			
				|  |  | +			ow.nlBuffer.Write(output[pos:nextpos])
 | 
	
		
			
				|  |  | +			nextpos++
 | 
	
		
			
				|  |  | +			pos = nextpos
 | 
	
		
			
				|  |  | +			ow.nlBuffer.Write([]byte("\r\n"))
 | 
	
		
			
				|  |  | +		} else {
 | 
	
		
			
				|  |  | +			ow.nlBuffer.Write(output[pos:])
 | 
	
		
			
				|  |  | +			pos = nextpos // -1
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +	// log.Printf(">> %q\n", ow.nlBuffer.Bytes())
 | 
	
		
			
				|  |  | +	return ow.nlBuffer.Bytes()
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // The low-lever writer function
 | 
	
		
			
				|  |  |  func (ow *OSWriter) OSWrite(buffer []byte) (int, error) {
 | 
	
		
			
				|  |  | +	var buff []byte = buffer
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	if DEBUG_DOOR {
 | 
	
		
			
				|  |  |  		if ow.Mutex.TryLock() {
 | 
	
		
			
				|  |  |  			log.Panic("OSWrite: mutex was NOT locked.")
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	n, err := syscall.Write(ow.Handle, buffer)
 | 
	
		
			
				|  |  | -	if (err != nil) || (n != len(buffer)) {
 | 
	
		
			
				|  |  | +	// Filters (!)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	if ow.TranslateNL {
 | 
	
		
			
				|  |  | +		buff = ow.NewLines(buff)
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	n, err := syscall.Write(ow.Handle, buff)
 | 
	
		
			
				|  |  | +	if (err != nil) || (n != len(buff)) {
 | 
	
		
			
				|  |  |  		if !ow.Closed {
 | 
	
		
			
				|  |  |  			ow.Closed = true
 | 
	
		
			
				|  |  |  			// Don't need to close reader, it will close itself.
 | 
	
	
		
			
				|  | @@ -47,8 +90,8 @@ func (ow *OSWriter) Write(buffer []byte) (int, error) {
 | 
	
		
			
				|  |  |  		return 0, ErrDisconnected
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -	var output bytes.Buffer
 | 
	
		
			
				|  |  | -	output.Write(buffer)
 | 
	
		
			
				|  |  | +	// var output bytes.Buffer
 | 
	
		
			
				|  |  | +	// output.Write(buffer)
 | 
	
		
			
				|  |  |  	// Where should this be done?  (I think in here)
 | 
	
		
			
				|  |  |  	// TO FIX: TO DO:
 | 
	
		
			
				|  |  |  	/*
 | 
	
	
		
			
				|  | @@ -59,7 +102,7 @@ func (ow *OSWriter) Write(buffer []byte) (int, error) {
 | 
	
		
			
				|  |  |  			d.UpdateLastColor(output, &d.LastColor)
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  |  	*/
 | 
	
		
			
				|  |  | -	return ow.OSWrite(output.Bytes())
 | 
	
		
			
				|  |  | +	return ow.OSWrite(buffer)
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  func (ow *OSWriter) Stop() {
 |