Example #1
0
static void	draw_field(t_search *search)
{
	term_goto_relative(4, 0);
	term_write(MG);
	term_write("  ");
	term_write(search->buffer);
	term_show_cursor(TRUE);
}
Example #2
0
void	draw_bar(char *color, int width)
{
	int x;

	x = 0;
	term_write(color);
	while (x++ < width)
		term_write(" ");
}
Example #3
0
void
#line 307 "./cwebdir/comm-w2c.ch"
 print_prefix_name P1C(name_pointer,p)
#line 808 "./cwebdir/common.w"
{
char*s= first_chunk(p);
int l= prefix_length(p);
term_write(s,l);
if(s+l<(p+1)->byte_start)term_write("...",3);
}
Example #4
0
void get_string(void)
{ char c, delim = loc[-1]; /* what started the string */
  id_loc=id_first = &mod_text[1]; copy_char(delim);
  if (delim=='L')
    *id_loc++=delim=*loc++; /* after `\.L' comes the real delimiter */
  else if (delim=='<') delim='>'; /* for file names in \&{\#include} lines */
  do
  { if (loc>=limit)
    { err_print("! String didn't end"); loc=limit; break; }
		   
    copy_char(c=*loc++);
    if (c=='\\')
      if (loc<limit) copy_char(*loc++);
        /* record `\.\\|c|' with |c!='\n'| literally */
      else if (get_line())
        if (program==cweave) --id_loc; /* |CWEAVE| erases backslash */
	else copy_char('\n'); /* but |CTANGLE| copies escaped newline */
      else
      { loc=buffer;
        err_print("! Input ended in middle of string");
		   
        break;
      }
    else if (!including_header_file && c=='@')
      if (*loc=='@') ++loc; /* undouble \:@ */
      else err_print("! Double @ required in strings");
		      
  }
  while (c!=delim);
  if (id_loc>=mod_text_end)
  { print("\n! String too long: "); 
    term_write(mod_text+1,25); err_print("..");
  }
}
Example #5
0
mod_pointer get_module_name (void)
{ 
  { eight_bits c; char* k=mod_text; /* points to last recorded character */
    do
    { if (!find_char())
      { err_print("! Input ended in module name"); break; }
  		   
      c=*loc++;
      
      if (c=='@')
      { if ((c=*loc++)=='>') break;
        if (isspace(c) || c=='*' || c=='~')
        { err_print("! Module name didn't end"); loc-=2; break; }
      		   
        if (k<mod_text_end-1) *++k='@';
          /* record the `\.{@}', now |c==loc[-1]| again */
      }
      if (isspace(c)) c=' '; /* convert tabs, newlines etc. */
      if (k<mod_text_end-1 && !(c==' ' && *k==' ') ) *++k=c;
    } while(true);
    id_first=&mod_text[1];
    if (k>=mod_text_end-1)
  { print("\n! Module name too long: "); 
      term_write(id_first,25); err_print("..");
    }
    id_loc= *k==' ' && k>mod_text ? k : k+1;
      /* point after last non-space character */
  }
  { int l=(int)(id_loc-id_first);
    return l>=3 && strncmp(id_loc-3,"...",3)==0
    	? prefix_lookup(id_first,l-3) : mod_name_lookup(id_first,l);
  }
}
Example #6
0
void	term_mode_off(void)
{
	static char *str = NULL;

	if (!str)
		str = tgetstr("me", &str);
	term_write(str);
}
Example #7
0
void
#line 288 "./cwebdir/comm-w2c.ch"
 print_section_name P1C(name_pointer,p)
#line 768 "./cwebdir/common.w"
{
char*ss,*s= first_chunk(p);
name_pointer q= p+1;
while(p!=name_dir){
ss= (p+1)->byte_start-1;
if(*ss==' '&&ss>=s){
term_write(s,ss-s);p= q->link;q= p;
}else{
term_write(s,ss+1-s);p= name_dir;q= NULL;
}
s= p->byte_start;
}
if(q)term_write("...",3);
}
Example #8
0
// -----------------------------------------------------------------------
int cchar_term_write(struct cchar_unit_proto_t *unit, uint16_t *r_arg)
{
	char data = *r_arg & 255;
#ifdef WITH_DEBUGGER
	if (data >= 32) {
		LOG(L_TERM, 50, "Term write: %i (%c)", data, data);
	} else {
		LOG(L_TERM, 50, "Term write: %i (#%02x)", data, data);
	}
#endif
	term_write(UNIT->term, &data, 1);
	return IO_OK;
}
Example #9
0
// -----------------------------------------------------------------------
int cchar_term_write(struct cchar_unit_proto_t *unit, uint16_t *r_arg)
{
	char data = *r_arg & 255;
	if (LOG_ENABLED) {
		if (data >= 32) {
			LOG(L_TERM, "%i (%c)", data, data);
		} else {
			LOG(L_TERM, "%i (#%02x)", data, data);
		}
	}
	term_write(UNIT->term, &data, 1);
	return IO_OK;
}
Example #10
0
void		search_render(t_search *search)
{
	t_select *select;

	if (!search->i)
	{
		term_show_cursor(FALSE);
		return ;
	}
	select = search->select;
	term_go_home();
	term_mode_off();
	draw_bar(CGREY, select->size.ws_col);
	draw_field(search);
	term_write(EOC);
}
Example #11
0
eight_bits
#line 317 "./cwebdir/ctang-w2c.ch"
 get_next P1H(void)
#line 903 "./cwebdir/ctangle.w"
{
static int preprocessing= 0;
eight_bits c;
while(1){
if(loc> limit){
if(preprocessing&&*(limit-1)!='\\')preprocessing= 0;
if(get_line()==0)return(new_section);
else if(print_where&&!no_where){
print_where= 0;
/*76:*/
#line 1225 "./cwebdir/ctangle.w"

store_two_bytes(0150000);
if(changing)id_first= change_file_name;
else id_first= cur_file_name;
id_loc= id_first+strlen(id_first);
if(changing)store_two_bytes((sixteen_bits)change_line);
else store_two_bytes((sixteen_bits)cur_line);
{int a= id_lookup(id_first,id_loc,0)-name_dir;app_repl((a/0400)+0200);
app_repl(a%0400);}

/*:76*/
#line 912 "./cwebdir/ctangle.w"
;
}
else return('\n');
}
c= *loc;
if(comment_continues||(c=='/'&&(*(loc+1)=='*'||*(loc+1)=='/'))){
skip_comment(comment_continues||*(loc+1)=='*');

if(comment_continues)return('\n');
else continue;
}
loc++;
if(xisdigit(c)||c=='.')/*65:*/
#line 978 "./cwebdir/ctangle.w"
{
id_first= loc-1;
if(*id_first=='.'&&!xisdigit(*loc))goto mistake;
if(*id_first=='0'){
if(*loc=='x'||*loc=='X'){
loc++;while(xisxdigit(*loc))loc++;goto found;
}
}
while(xisdigit(*loc))loc++;
if(*loc=='.'){
loc++;
while(xisdigit(*loc))loc++;
}
if(*loc=='e'||*loc=='E'){
if(*++loc=='+'||*loc=='-')loc++;
while(xisdigit(*loc))loc++;
}
found:while(*loc=='u'||*loc=='U'||*loc=='l'||*loc=='L'
||*loc=='f'||*loc=='F')loc++;
id_loc= loc;
return(constant);
}

/*:65*/
#line 924 "./cwebdir/ctangle.w"

else if(c=='\''||c=='"'||(c=='L'&&(*loc=='\''||*loc=='"')))
/*66:*/
#line 1006 "./cwebdir/ctangle.w"
{
char delim= c;
id_first= section_text+1;
id_loc= section_text;*++id_loc= delim;
if(delim=='L'){
delim= *loc++;*++id_loc= delim;
}
while(1){
if(loc>=limit){
if(*(limit-1)!='\\'){
err_print("! String didn't end");loc= limit;break;

}
if(get_line()==0){
err_print("! Input ended in middle of string");loc= buffer;break;

}
else if(++id_loc<=section_text_end)*id_loc= '\n';

}
if((c= *loc++)==delim){
if(++id_loc<=section_text_end)*id_loc= c;
break;
}
if(c=='\\'){
if(loc>=limit)continue;
if(++id_loc<=section_text_end)*id_loc= '\\';
c= *loc++;
}
if(++id_loc<=section_text_end)*id_loc= c;
}
if(id_loc>=section_text_end){
printf("\n! String too long: ");

term_write(section_text+1,25);
err_print("...");
}
id_loc++;
return(string);
}

/*:66*/
#line 926 "./cwebdir/ctangle.w"

else if(isalpha(c)||isxalpha(c)||ishigh(c))
/*64:*/
#line 972 "./cwebdir/ctangle.w"
{
id_first= --loc;
while(isalpha(*++loc)||isdigit(*loc)||isxalpha(*loc)||ishigh(*loc));
id_loc= loc;return(identifier);
}

/*:64*/
#line 928 "./cwebdir/ctangle.w"

else if(c=='@')/*67:*/
#line 1050 "./cwebdir/ctangle.w"
{
c= ccode[(eight_bits)*loc++];
switch(c){
case ignore:continue;
case translit_code:err_print("! Use @l in limbo only");continue;

case control_text:while((c= skip_ahead())=='@');

if(*(loc-1)!='>')
err_print("! Double @ should be used in control text");

continue;
case section_name:
cur_section_name_char= *(loc-1);
/*69:*/
#line 1098 "./cwebdir/ctangle.w"
{
char*k;
/*71:*/
#line 1118 "./cwebdir/ctangle.w"

k= section_text;
while(1){
if(loc> limit&&get_line()==0){
err_print("! Input ended in section name");

loc= buffer+1;break;
}
c= *loc;
/*72:*/
#line 1142 "./cwebdir/ctangle.w"

if(c=='@'){
c= *(loc+1);
if(c=='>'){
loc+= 2;break;
}
if(ccode[(eight_bits)c]==new_section){
err_print("! Section name didn't end");break;

}
if(ccode[(eight_bits)c]==section_name){
err_print("! Nesting of section names not allowed");break;

}
*(++k)= '@';loc++;
}

/*:72*/
#line 1127 "./cwebdir/ctangle.w"
;
loc++;if(k<section_text_end)k++;
if(xisspace(c)){
c= ' ';if(*(k-1)==' ')k--;
}
*k= c;
}
if(k>=section_text_end){
printf("\n! Section name too long: ");

term_write(section_text+1,25);
printf("...");mark_harmless;
}
if(*k==' '&&k> section_text)k--;

/*:71*/
#line 1100 "./cwebdir/ctangle.w"
;
if(k-section_text> 3&&strncmp(k-2,"...",3)==0)
cur_section_name= section_lookup(section_text+1,k-3,1);
else cur_section_name= section_lookup(section_text+1,k,0);
if(cur_section_name_char=='(')
/*39:*/
#line 516 "./cwebdir/ctangle.w"

{
for(an_output_file= cur_out_file;
an_output_file<end_output_files;an_output_file++)
if(*an_output_file==cur_section_name)break;
if(an_output_file==end_output_files){
if(cur_out_file> output_files)
*--cur_out_file= cur_section_name;
else{
overflow("output files");
}
}
}

/*:39*/
#line 1106 "./cwebdir/ctangle.w"
;
return(section_name);
}

/*:69*/
#line 1064 "./cwebdir/ctangle.w"
;
case string:/*73:*/
#line 1164 "./cwebdir/ctangle.w"
{
id_first= loc++;*(limit+1)= '@';*(limit+2)= '>';
while(*loc!='@'||*(loc+1)!='>')loc++;
if(loc>=limit)err_print("! Verbatim string didn't end");

id_loc= loc;loc+= 2;
return(string);
}

/*:73*/
#line 1065 "./cwebdir/ctangle.w"
;
case ord:/*68:*/
#line 1077 "./cwebdir/ctangle.w"

id_first= loc;
if(*loc=='\\'){
if(*++loc=='\'')loc++;
}
while(*loc!='\''){
if(*loc=='@'){
if(*(loc+1)!='@')
err_print("! Double @ should be used in ASCII constant");

else loc++;
}
loc++;
if(loc> limit){
err_print("! String didn't end");loc= limit-1;break;

}
}
loc++;
return(ord);

/*:68*/
#line 1066 "./cwebdir/ctangle.w"
;
default:return(c);
}
}

/*:67*/
#line 929 "./cwebdir/ctangle.w"

else if(xisspace(c)){
if(!preprocessing||loc> limit)continue;

else return(' ');
}
else if(c=='#'&&loc==buffer+1)preprocessing= 1;
mistake:/*63:*/
#line 950 "./cwebdir/ctangle.w"

switch(c){
case'+':if(*loc=='+')compress(plus_plus);break;
case'-':if(*loc=='-'){compress(minus_minus);}
else if(*loc=='>')if(*(loc+1)=='*'){loc++;compress(minus_gt_ast);}
else compress(minus_gt);break;
case'.':if(*loc=='*'){compress(period_ast);}
else if(*loc=='.'&&*(loc+1)=='.'){
loc++;compress(dot_dot_dot);
}
break;
case':':if(*loc==':')compress(colon_colon);break;
case'=':if(*loc=='=')compress(eq_eq);break;
case'>':if(*loc=='='){compress(gt_eq);}
else if(*loc=='>')compress(gt_gt);break;
case'<':if(*loc=='='){compress(lt_eq);}
else if(*loc=='<')compress(lt_lt);break;
case'&':if(*loc=='&')compress(and_and);break;
case'|':if(*loc=='|')compress(or_or);break;
case'!':if(*loc=='=')compress(not_eq);break;
}

/*:63*/
#line 936 "./cwebdir/ctangle.w"

return(c);
}
}
Example #12
0
File: term.c Project: dlageist42/42
int			term_start(char *tty)
{
	g_fd = open(tty, O_WRONLY);
	term_write(tgetstr("ti", NULL));
	return (g_fd);
}
Example #13
0
void serial_terminal_device::rcv_complete()
{
	receive_register_extract();
	term_write(get_received_char());
}
Example #14
0
int
main(int argc, char *argv[])
{
	int cc;
	struct termios rtt, stt;
	struct winsize win;
	int ch, n;
	struct timeval tv, *tvp;
	time_t tvec, start;
	char obuf[BUFSIZ];
	char ibuf[BUFSIZ];

	fd_set rfd;
	int flushtime = 30;
	int readstdin;
	int nfds=0;

	while ((ch = getopt(argc, argv, "hnw")) != -1)
		switch(ch) {
		case 'n':
			ambi_width=1;
			break;
		case 'w':
			ambi_width=2;
			break;
		case 'h':
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if(getenv("TERMIM")!=NULL)
		err(1, "already in termim");

	if(pipe(tube)==-1)
		err(1, "pipe");

	sprintf(obuf, "%d", tube[1]);
	setenv("TERMIM", obuf, 1);

	if ((ttyflg = isatty(STDIN_FILENO)) != 0) {
		if (tcgetattr(STDIN_FILENO, &tt) == -1)
			err(1, "tcgetattr");
		if (ioctl(STDIN_FILENO, TIOCGWINSZ, &win) == -1)
			err(1, "ioctl");
		win.ws_row-=2;
		term=term_create();
		term_assoc_output(term, STDOUT_FILENO);
		term_set_size(term, win.ws_row, win.ws_col);
		term_set_offset(term, 0, 0);
		if (openpty(&master, &slave, NULL, &tt, &win) == -1)
			err(1, "openpty");
		term2=term_create();
		term_assoc_output(term2, STDOUT_FILENO);
		term_set_size(term2, 2, win.ws_col);
		term_set_offset(term2, win.ws_row, 0);
		win.ws_row=2;
		if (openpty(&master2, &slave2, NULL, &tt, &win) == -1)
			err(1, "openpty");
	} else {
		if (openpty(&master, &slave, NULL, NULL, NULL) == -1)
			err(1, "openpty");
		if (openpty(&master2, &slave2, NULL, NULL, NULL) == -1)
			err(1, "openpty");
	}

	if (!qflg) {
		tvec = time(NULL);
	}
	if (ttyflg) {
		rtt = tt;
		cfmakeraw(&rtt);
		rtt.c_lflag &= ~ECHO;
		(void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &rtt);
	}

	tcgetattr(master2, &rtt);
	cfmakeraw(&rtt);
	rtt.c_lflag &= ~ECHO;
	tcsetattr(master2, TCSAFLUSH, &rtt);

	signal(SIGCHLD, &sigchild);

	child = fork();
	if (child < 0) {
		warn("fork");
		done(1);
	}
	if (child == 0)
		doshell(argv);
	close(slave);

	child2 = fork();
	if (child2 < 0) {
		warn("fork");
		done(1);
	}
	if (child2 == 0)
		dodock();
	close(tube[1]);

	fcntl(tube[0], F_SETFL, O_NONBLOCK);
	fcntl(master, F_SETFL, O_NONBLOCK);

	signal(SIGINT, &sigforwarder);
	signal(SIGQUIT, &sigforwarder);
	signal(SIGPIPE, &sigforwarder);
#ifndef __linux
	signal(SIGINFO, &sigforwarder);
#endif
	signal(SIGUSR1, &sigforwarder);
	signal(SIGUSR2, &sigforwarder);
	signal(SIGWINCH, &winchforwarder);

#define RESET "\033[m\033[2J\033[H"
	term_write(term, RESET, sizeof(RESET));
	term_write(term2, RESET, sizeof(RESET));

	start = tvec = time(0);
	readstdin = 1;
	if(master2 > tube[0]) nfds = tube[0];
	if(master > nfds) nfds = master;
	if(master2 > nfds) nfds = master2;
	if(STDIN_FILENO > nfds) nfds = STDIN_FILENO;
	nfds+=1;
	for (;;) {
		FD_ZERO(&rfd);
		FD_SET(tube[0], &rfd);
		FD_SET(master, &rfd);
		FD_SET(master2, &rfd);
		if (readstdin)
			FD_SET(STDIN_FILENO, &rfd);

		if (!readstdin && ttyflg) {
			tv.tv_sec = 1;
			tv.tv_usec = 0;
			tvp = &tv;
			readstdin = 1;
		} else if (flushtime > 0) {
			tv.tv_sec = flushtime - (tvec - start);
			tv.tv_usec = 0;
			tvp = &tv;
		} else {
			tvp = NULL;
		}
		n = select(nfds, &rfd, 0, 0, tvp);
		if (n < 0 && errno != EINTR)
			break;
		if (n > 0 && FD_ISSET(STDIN_FILENO, &rfd)) {
			cc = read(STDIN_FILENO, ibuf, sizeof (ibuf));
			if (cc < 0)
				break;
			if (cc == 0) {
				if (tcgetattr(master, &stt) == 0 && (stt.c_lflag & ICANON) != 0) {
					(void)write(master, &stt.c_cc[VEOF], 1);
				}
				readstdin = 0;
			}
			write(master2, ibuf, cc);
		}
		if (n > 0 && FD_ISSET(master, &rfd)) {
			while(1){
				cc = read(master, obuf, sizeof (obuf));
				if (cc <= 0)
					break;
				term_write(term, obuf, cc);
			}
		}
		if (n > 0 && FD_ISSET(master2, &rfd)) {
			cc = read(master2, obuf, sizeof (obuf));
			if (cc <= 0)
				break;
			term_write(term2, obuf, cc);
		}
		if (n > 0 && FD_ISSET(tube[0], &rfd)) {
			cc = read(tube[0], ibuf, sizeof (ibuf));
			if(cc < 0 && errno!=EAGAIN)
				break;
			write(master, ibuf, cc);
		}
		tvec = time(0);
		if (tvec - start >= flushtime) {
			start = tvec;
		}
	}
	finish();
	done(0);
}
Example #15
0
void generic_terminal_device::kbd_put(u8 data)
{
	if (m_io_term_conf->read() & 0x100) term_write(data);
	send_key(data);
}
Example #16
0
void serial_terminal_device::received_byte(uint8_t byte)
{
	term_write(byte);
}
Example #17
0
File: term.c Project: dlageist42/42
void		term_end(void)
{
	term_write(tgetstr("te", NULL));
	close(g_fd);
}