Пример #1
0
void printchar(unsigned char c)
{
  
		if(isprintable(c))
		printk("%c",c);
		
		else
			printk(".");
 
}
Пример #2
0
/**
 * Keyhandler callback for processing player keystrokes while collecting the
 * query string. This stores typed characters into the conv_query buffer.
 *
 * @param kh is the keyhandler pushed for input handling.
 * @param key is the key the player just typed.
 * @returns 1 if the player is done entering the query, else 0.
 */
static int conv_get_player_query(struct KeyHandler *kh, int key, int keymod)
{
        int done = 0;

        if (console_handle_key(key, keymod)) {
                return 0;
        }

        switch (key) {
	case CANCEL:
                console_end();
		while (conv_ptr > conv_query) {
			conv_ptr--;
			*conv_ptr = 0;
			cmdwin_pop();
			conv_room++;
		}
                done = 1;
                break;
        case '\n':
                console_end();
                done = 1;
                break;
        case '\b':
                console_end();
		if (conv_ptr != conv_query) {
			conv_ptr--;
			*conv_ptr = 0;
			conv_room++;
			cmdwin_pop();
		}
                break;
        default:
                if (isprintable(key) 
                    && conv_room) {
                        console_end();
                        /* Print user input in console rather than cmdwin */
                        cmdwin_toggle_showcmd();
                        cmdwin_push("%c", key);
                        cmdwin_toggle_showcmd();
                        console_print("%c", key);
                        *conv_ptr++ = key;
                        conv_room--;
                }
                break;
        }

        return done;
}
Пример #3
0
void* console_device(void * arg) {

    uint32_t scancode;
    iorq_t iorq;
    int i;
    char c;
    char * aux;
    
    memset(&keybd_device, 0, sizeof(device_t));
    strcpy(keybd_device.ln_link.name, "org.era.dev.console");
    keybd_device.iorq_queue = create_queue(10, sizeof(iorq_t));

    keybd_queue = create_queue(1, sizeof(uint32_t));
    register_interrupt_handler(IRQ1, &keypress_isr);
    monitor_writexy(0,24, " 1", 7, 0);
    
    for(;;) {
        queue_recv(keybd_device.iorq_queue, &iorq, QM_BLOCKING);
        if(iorq.io_desc == DC_READ) {
            i = 0;
            aux = (char *) iorq.io_dptr;
            memset(aux, 0, iorq.io_sz);
            
            while(1) {
                queue_recv(keybd_queue, &scancode, QM_BLOCKING);
                c = kbdus[scancode];
                if (c == '\n')
                    break;
                if ((c == '\b') && (i > 0)) {
                    aux[i] = '\0';
                    i--;
                    monitor_put('\b');
                    continue;
                }
                if (c == 0 || c == '\t' || i == (iorq.io_sz - 1))
                    continue;
                if(isprintable(c) ) {
                    aux[i++] = c;
                    monitor_put(c);
                }
            }
            monitor_put('\n');
            aux[i] = '\0';

            queue_send(iorq.io_response, NULL, QM_NONBLOCKING);
        }
    }
}
Пример #4
0
void CONSOLE::dump( const void* address, size_t length )
{
	unsigned char* begin = (unsigned char*)address;
	unsigned char* end = begin + length - 1;

	uintptr_t first_addr = ((uintptr_t)begin) & ~0xF;
	uintptr_t last_addr = ((uintptr_t)end) & ~0xF;	

	for( uintptr_t line_addr = first_addr; line_addr <= last_addr; line_addr += 16 )
	{
		printf( "%p ", line_addr );

		unsigned char* ptr = (unsigned char*)line_addr;
		for( unsigned int i = 0; i < 16; ++i )
		{
			if( ptr >= begin && ptr <= end )
				printf( "%2x ", *ptr );
			else
				printf( "?? ", *ptr );

			ptr++;
		}

		printf( "  " );

		ptr = (unsigned char*)line_addr;
		for( unsigned int i = 0; i < 16; ++i )
		{
			if( ptr >= begin && ptr <= end )
				if( isprintable( *ptr ) )
					printf( "%c", *ptr );
				else
					printf( ".", *ptr );
			else
				printf( " ", *ptr );

			ptr++;
		}

		printf( "\n" );
	}
}
Пример #5
0
static void disassemble(machine_t &m)
{
  int32_t end = m.size();

  while ( m.pos() <= end ) {
    Op op = static_cast<Op>(m.cur());
    printf("0x%x %s", m.pos(), to_s(op));

    if ( (op==PUSH || op==PUSHIP) && m.pos()<=end ) {
        m.next();
        printf(" 0x%x", m.cur());

        if ( isprintable(m.cur()) )
          printf(" ('%s')", to_s(m.cur()));
    }

    printf("\n");
    m.next();
  }
}
Пример #6
0
static int op_bgdot(int k, int *pos)
{
	const char *items[3] = {"dot", "bullet", "blank"};
	int n = 3;
	int i = 0;
	int j;
	if (isprintable(k)) {
		if (k == '0')
			bgdot = ' ';
		else if (k == '~')
			bgdot = BULLET;
		else
			bgdot = k;
		save_bgdot();
		k = 0;
	}
	if (_ASCII) {
		items[1] = items[2];
		n--;
	} else if (bgdot == BULLET)
		i = 1;
	if (bgdot == ' ')
		i = n-1;
	j = i;
	k = selectitem(items, n, &i, k);
	if (i != j) {
		if (i == 0)
			bgdot = '.';
		else if (i == n-1)
			bgdot = ' ';
		else
			bgdot = BULLET;
		save_bgdot();
	}
	if (k != 1)
		return k;
	putch(bgdot);
	putch(' ');
	return 1;
}
Пример #7
0
void
mesgload(Message *m, char *rootdir, char *file, Window *w)
{
	char *s, *subdir, *name, *dir;
	Message *mp, *thisone;
	int n;

	dir = estrstrdup(rootdir, file);

	if(strcmp(m->type, "message/rfc822") != 0){	/* suppress headers of envelopes */
		if(strlen(m->from) > 0){
			Bprint(w->body, "From: %s\n", m->from);
			mesgline(m, "Date", m->date);
			mesgline(m, "To", m->to);
			mesgline(m, "CC", m->cc);
			mesgline(m, "Subject", m->subject);
			printheader(dir, w->body, extraheaders);
		}else{
			printheader(dir, w->body, okheaders);
			printheader(dir, w->body, extraheaders);
		}
		Bprint(w->body, "\n");
	}

	if(m->level == 1 && m->recursed == 0){
		m->recursed = 1;
		readmbox(m, rootdir, m->name);
	}
	if(m->head == nil){	/* single part message */
		if(strcmp(m->type, "text")==0 || strncmp(m->type, "text/", 5)==0){
			mimedisplay(m, m->name, rootdir, w, 1);
			s = readbody(m->type, dir, &n);
			winwritebody(w, s, n);
			free(s);
		}else
			mimedisplay(m, m->name, rootdir, w, 0);
	}else{
		/* multi-part message, either multipart or message/rfc822 */
		thisone = nil;
		if(strcmp(m->type, "multipart/alternative") == 0){
			thisone = bestalt(m, dir);
			if(thisone == nil){
				thisone = m->head; /* in case we can't find a good one */
				for(mp=m->head; mp!=nil; mp=mp->next)
					if(isprintable(mp->type)){
						thisone = mp;
						break;
					}
			}
		}
		for(mp=m->head; mp!=nil; mp=mp->next){
			if(thisone!=nil && mp!=thisone)
				continue;
			subdir = estrstrdup(dir, mp->name);
			name = estrstrdup(file, mp->name);
			/* skip first element in name because it's already in window name */
			if(mp != m->head)
				Bprint(w->body, "\n===> %s (%s) [%s]\n",
					strchr(name, '/')+1, mp->type,
					mp->disposition);
			if(strcmp(mp->type, "text")==0 ||
			    strncmp(mp->type, "text/", 5)==0){
				mimedisplay(mp, name, rootdir, w, 1);
				printheader(subdir, w->body, okheaders);
				printheader(subdir, w->body, extraheaders);
				winwritebody(w, "\n", 1);
				s = readbody(mp->type, subdir, &n);
				winwritebody(w, s, n);
				free(s);
			}else{
				if(strncmp(mp->type, "multipart/", 10)==0 ||
				    strcmp(mp->type, "message/rfc822")==0){
					mp->w = w;
					mesgload(mp, rootdir, name, w);
					mp->w = nil;
				}else
					mimedisplay(mp, name, rootdir, w, 0);
			}
			free(name);
			free(subdir);
		}
	}
	free(dir);
}
Пример #8
0
int lex (char **input)
{
    short comma;
    int state;
    int ret;

    comma = 0;
    state = STATE_START;
    ret = INVALIDSYM;

    if (!**input) return END;

    lp1 = *input;
    while (state != STATE_END && **input) {
        switch (state) {
            case STATE_START:
                if (**input == DEREF_SYM) {
                    state = STATE_DEREF;
                    *input += 1;

                } else if (**input == CHARC_OPEN_SYM) {
                    state = trans(literal, input, CHARC_OPEN, STATE_END, &ret);
                    if (!literal) literal = 1;
                } else if (**input == CHARC_CLOSE_SYM) {
                    state = STATE_END;
                    ret = CHARC_CLOSE;
                    literal = 0;
                    *input += 1;

                } else if (**input == REP_OPEN_SYM) {
                    state = trans(literal, input, 0, STATE_REP, NULL);
                } else if (**input == REP_CLOSE_SYM) {
                    state = trans(literal, input, RXVM_BADREP, STATE_END, &ret);
                } else if (**input == LPAREN_SYM) {
                    state = trans(literal, input, LPAREN, STATE_END, &ret);
                } else if (**input == RPAREN_SYM) {
                    state = trans(literal, input, RPAREN, STATE_END, &ret);
                } else if (**input == ONE_SYM) {
                    state = trans(literal, input, ONE, STATE_END, &ret);
                } else if (**input == ONEZERO_SYM) {
                    state = trans(literal, input, ONEZERO, STATE_END, &ret);
                } else if (**input == ZERO_SYM) {
                    state = trans(literal, input, ZERO, STATE_END, &ret);
                } else if (**input == ANY_SYM) {
                    state = trans(literal, input, ANY, STATE_END, &ret);
                } else if (**input == SOL_SYM) {
                    state = trans(literal, input, SOL, STATE_END, &ret);
                } else if (**input == EOL_SYM) {
                    state = trans(literal, input, EOL, STATE_END, &ret);
                } else if (**input == ALT_SYM) {
                    state = trans(literal, input, ALT, STATE_END, &ret);
                } else if (isprintable(**input)) {
                    state = STATE_LITERAL;
                } else {
                    return RXVM_EINVAL;
                }

            break;
            case STATE_LITERAL:
                if (**input == RANGE_SEP_SYM && literal) {
                    return RXVM_EINVAL;
                } else if (*(*input + 1) == RANGE_SEP_SYM && literal) {
                    state = STATE_RANGE;
                    *input += 2;
                } else {
                    state = STATE_END;
                    ret = LITERAL;
                    *input += 1;
                }

            break;
            case STATE_DEREF:
                if (!**input) {
                    return RXVM_EINVAL;
                } else {
                    ret = LITERAL;
                    lp1 += 1;
                }

                *input += 1;
                state = STATE_END;
            break;
            case STATE_RANGE:
                if (isprintable(**input) &&
                        !isreserved(**input)) {
                    state = STATE_END;
                    ret = CHAR_RANGE;
                    *input += 1;
                } else {
                    return RXVM_EINVAL;
                }

            break;
            case STATE_REP:
                if (**input == REP_CLOSE_SYM) {
                    if (!isdigit(*(*input - 1)) &&
                            !isdigit(*(lp1 + 1))) {
                        return RXVM_MREP;
                    }

                    state = STATE_END;
                    ret = REP;
                } else if (**input == ',') {
                    if (comma)
                        return RXVM_EINVAL;

                    comma = 1;
                } else if (!isdigit(**input)) {
                    return RXVM_EINVAL;
                }

                *input += 1;
            break;
        }
    }

    if (state == STATE_DEREF) {
        ret = RXVM_ETRAIL;
    } else if (state == STATE_REP) {
        ret = RXVM_EREP;
    }

    lpn = *input;
    return ret;
}
Пример #9
0
void parseconsole(void)
{
  static char console_escape_seq[maxtextlengthshort];
  
  unsigned char tempbuffa[INPUT_BUFFER_LENGTH];
  int length;
  unsigned int linelength;
  userinput ui;
  unsigned int i, j;
  
  updatecontext();
  
  bzero(console_escape_seq, sizeof(console_escape_seq));
  if (is_fd_readable(fileno(stdin)))
    {
      memset(tempbuffa, 0, INPUT_BUFFER_LENGTH);
      length = read (fileno(stdin), &tempbuffa, INPUT_BUFFER_LENGTH);
      
      if (length < 1)
        {
          outerror(OUTERROR_TYPE_CRASH,"read from stdin failed: %s",(length<0) ? strerror(errno) : "EOF!");
        }
      
      linelength = strlen(gdata.console_input_line);
      for (i=0; i<(unsigned int)length; i++)
        {
          if (console_escape_seq[0] != '\0')
            {
              size_t esc_len = strlen(console_escape_seq);
              
              if (esc_len < (maxtextlengthshort-2))
                {
                  console_escape_seq[esc_len]=tempbuffa[i];
                  esc_len++;
                  if (((tempbuffa[i] >= 'a') && (tempbuffa[i] <= 'z')) ||
                      ((tempbuffa[i] >= 'A') && (tempbuffa[i] <= 'Z')))
                    {
                      /* process sequence */
                      if (console_escape_seq[1] == '[')
                        {
                          if (console_escape_seq[esc_len-1] == 'A')
                            {
                              /* up */
                              int count;
                              if (esc_len > 3)
                                {
                                  count=atoi(&console_escape_seq[2]);
                                }
                              else
                                {
                                  count=1;
                                }
                              
                              while(count--)
                                {
                                  if (gdata.console_history_offset)
                                    {
                                      gdata.console_history_offset--;
                                      strncpy(gdata.console_input_line,
                                              irlist_get_nth(&gdata.console_history,
                                                             gdata.console_history_offset),
                                              INPUT_BUFFER_LENGTH-1);
                                      linelength = strlen(gdata.console_input_line);
                                      gdata.curcol = linelength;
                                    }
                                }
                              
                            }
                          else if (console_escape_seq[esc_len-1] == 'B')
                            {
                              /* down */
                              int count;
                              if (esc_len > 3)
                                {
                                  count=atoi(&console_escape_seq[2]);
                                }
                              else
                                {
                                  count=1;
                                }
                              
                              while(count--)
                                {
                                  gdata.console_history_offset++;
                                  if (gdata.console_history_offset < irlist_size(&gdata.console_history))
                                    {
                                      strncpy(gdata.console_input_line,
                                              irlist_get_nth(&gdata.console_history,
                                                             gdata.console_history_offset),
                                              INPUT_BUFFER_LENGTH-1);
                                      linelength = strlen(gdata.console_input_line);
                                      gdata.curcol = linelength;
                                    }
                                  else
                                    {
                                      memset(gdata.console_input_line, 0,
                                             INPUT_BUFFER_LENGTH);
                                      linelength = 0;
                                      gdata.curcol = 0;
                                    }
                                  
                                  gdata.console_history_offset = min2(gdata.console_history_offset,irlist_size(&gdata.console_history));
                                }
                            }
                          else if (console_escape_seq[esc_len-1] == 'C')
                            {
                              /* right */
                              int count;
                              if (esc_len > 3)
                                {
                                  count=atoi(&console_escape_seq[2]);
                                }
                              else
                                {
                                  count=1;
                                }
                              gdata.curcol += count;
                              if (gdata.curcol > linelength)
                                gdata.curcol = linelength;
                            }
                          else if (console_escape_seq[esc_len-1] == 'D')
                            {
                              /* left */
                              unsigned int count;
                              if (esc_len > 3)
                                {
                                  count=atoi(&console_escape_seq[2]);
                                }
                              else
                                {
                                  count=1;
                                }
                              if (count <= gdata.curcol)
                                gdata.curcol -= count;
                            }
                          /* else ignore */
                        }
                      /* else ignore */
                      
                      memset(console_escape_seq, 0, maxtextlengthshort);
                    }
                }
              else
                {
                  /* sequence is too long, ignore */
                  memset(console_escape_seq, 0, maxtextlengthshort);
                }
            }
          else if (tempbuffa[i] == '\x1b')
            {
              console_escape_seq[0]=tempbuffa[i];
            }
          else if ((tempbuffa[i] == '\t') && gdata.console_input_line[0])
            {
              if (!gdata.attop) gototop();
              j = u_expand_command();
              gdata.curcol += j;
              linelength += j;
            }
          else if (tempbuffa[i] == '\n')
            {
              char *hist;
              
              hist = irlist_get_tail(&gdata.console_history);
              
              if ((!hist || strcmp(hist,gdata.console_input_line)) && gdata.console_input_line[0])
                {
                  hist = irlist_add(&gdata.console_history, linelength+1);
                  strncpy(hist, gdata.console_input_line, linelength);
                }
              
              if (irlist_size(&gdata.console_history) > MAX_HISTORY_SIZE)
                {
                  irlist_delete(&gdata.console_history, irlist_get_head(&gdata.console_history));
                }
              
              gdata.console_history_offset = irlist_size(&gdata.console_history);
              
              if (!gdata.attop) gototop();
              
              u_fillwith_console(&ui,gdata.console_input_line);
              u_parseit(&ui);
              
              gdata.curcol=0;
              memset(gdata.console_input_line, 0, INPUT_BUFFER_LENGTH);
            }
          else if (isprintable(tempbuffa[i]))
            {
              if (linelength < (INPUT_BUFFER_LENGTH-2))
                {
                  for (j=linelength; j>gdata.curcol; j--)
                    {
                      gdata.console_input_line[j] = gdata.console_input_line[j-1];
                    }
                  gdata.console_input_line[gdata.curcol]=tempbuffa[i];
                  gdata.curcol++;
                  linelength++;
                }
            }
          else if (tempbuffa[i] == gdata.startup_tio.c_cc[VINTR])
            {
            }
          else if (tempbuffa[i] == gdata.startup_tio.c_cc[VQUIT])
            {
            }
          else if (tempbuffa[i] == gdata.startup_tio.c_cc[VERASE])
            {
              if (gdata.curcol)
                {
                  for (j=gdata.curcol-1; j<linelength; j++)
                    {
                      gdata.console_input_line[j] = gdata.console_input_line[j+1];
                    }
                  linelength--;
                  gdata.console_input_line[linelength] = '\0';
                  gdata.curcol--;
                }
            }
          else if (tempbuffa[i] == gdata.startup_tio.c_cc[VWERASE])
            {
              while (gdata.curcol && (gdata.console_input_line[gdata.curcol-1] == ' '))
                {
                  for (j=gdata.curcol-1; j<linelength; j++)
                    {
                      gdata.console_input_line[j] = gdata.console_input_line[j+1];
                    }
                  linelength--;
                  gdata.console_input_line[linelength] = '\0';
                  gdata.curcol--;
                }
              while (gdata.curcol && (gdata.console_input_line[gdata.curcol-1] != ' '))
                {
                  for (j=gdata.curcol-1; j<linelength; j++)
                    {
                      gdata.console_input_line[j] = gdata.console_input_line[j+1];
                    }
                  linelength--;
                  gdata.console_input_line[linelength] = '\0';
                  gdata.curcol--;
                }
              while (gdata.curcol && (gdata.console_input_line[gdata.curcol-1] == ' '))
                {
                  for (j=gdata.curcol-1; j<linelength; j++)
                    {
                      gdata.console_input_line[j] = gdata.console_input_line[j+1];
                    }
                  linelength--;
                  gdata.console_input_line[linelength] = '\0';
                  gdata.curcol--;
                }
            }
          else if (tempbuffa[i] == gdata.startup_tio.c_cc[VKILL])
            {
            }
          else if (tempbuffa[i] == gdata.startup_tio.c_cc[VEOF])
            {
            }
          else if (tempbuffa[i] == gdata.startup_tio.c_cc[VSTART])
            {
            }
          else if (tempbuffa[i] == gdata.startup_tio.c_cc[VSTOP])
            {
            }
          else if (tempbuffa[i] == gdata.startup_tio.c_cc[VSUSP])
            {
            }
          else if (tempbuffa[i] == gdata.startup_tio.c_cc[VLNEXT])
            {
            }
          else if (tempbuffa[i] == gdata.startup_tio.c_cc[VREPRINT])
            {
            }
          else if (tempbuffa[i] == gdata.startup_tio.c_cc[VDISCARD])
            {
            }
          else if (tempbuffa[i] == '\x01') /* Ctrl-A */
            {
              gdata.curcol = 0;
            }
          else if (tempbuffa[i] == '\x05') /* Ctrl-E */
            {
              gdata.curcol = linelength;
            }
        }
      
      drawbot();
    }
}