summaryrefslogblamecommitdiff
path: root/src/user/lib/fwik/io/Term.cpp
blob: f8f686e8a973a3df814b479e7842a7a887c0ab56 (plain) (tree)
1
2
3
4
5
6
7
8
9







                                     
                                                  

 
                                                                   
                
                                                     


                    
                              



                                       
                                       





                      





                                                                

 
                                 


                            
                                         





                                    
                                                 


                                    




                                    

 

                                                  
 
#include <IO/Term.h>

Term::Term(const Node &n) : Node(n) {
	_init();
}

Term::Term(FILE f) : Node(f) {
	_init();
	if (error E_INVALID_TYPE) libc::close(fd);
}

Term::Term(const char* filename, int mode) : Node(filename, mode) {
	_init();
	if (error == E_INVALID_TYPE) libc::close(fd);
}

void Term::_init() {
	if (error < 0) return;
	if (info.type & FT_TERMINAL) {
		w = info.size >> 16;
		h = info.size & 0xFFFF;
	} else {
		error = E_INVALID_TYPE;
	}
	hist.str = 0;
	hist.max = 12;
}

Term::~Term() {
	if (hist.str != 0) {
		for (int i = 0; i < hist.max; i++) {
			if (hist.str[i] != 0) free(hist.str[i]);
		}
		free(hist.str);
	}
}

void Term::print(const char *s) {
	libc::fprint(fd, s);
}

void Term::printf(const char* fmt, ...) {
	va_list ap;
	va_start(ap, fmt);
	libc::vfprintf(fd, fmt, ap);
	va_end(ap);
}

void Term::vprintf(const char* fmt, va_list ap) {
	libc::vfprintf(fd, fmt, ap);
}

String Term::readln() {
	char *s = libc::freadln(fd);
	String ret(s);
	free(s);
	return ret;
}

String Term::readline() {
	return String(libc::freadline(fd, &hist));
}