예제 #1
0
/**
 * \brief   Init of input history buffer
 *
 * \param   ihb            ... input history buffer
 * \param   lines          ... number of lines
 * \param   lenght         ... number of characters per line
 *          
 * This is the init-function of the input history buffer. It allocates the
 * history buffer.
 */
int
contxt_ihb_init(contxt_ihb_t *ihb, int lines, int length)
{  
  if (lines < 2)
    lines = 2;
  if (length < 2)
    length = 2;

  /* consider terminating '\0' */
  length++;
  
  ihb->lines  = lines;
  ihb->first  = 0;
  ihb->last   = 0;
  ihb->length = length;
 
  /* allocate history buffer */
  if (!(ihb->buffer = malloc(lines*length)))
    {
      LOGl("no mem for ihb->head");
      return -L4_ENOMEM;
    }

  /* empty whole history buffer */
  memset(ihb->buffer, 0, lines*length);
  
  return 0;
}
예제 #2
0
파일: init.c 프로젝트: ErisBlastar/osfree
/* init. a termstate, does not malloc term->spec,
 * but term->text and term->attrib.
 */
int init_termstate(termstate_t * term, int w, int h, int hist)
{
    term->w                 = w;
    term->echo              = 1;
    term->autorepeat        = 1;
    term->autowrap          = 1;
    term->term_mode         = VT100MODE_COOKED;
    term->origin_mode       = VT100_ORIGIN_GLOBAL;
    term->insert_mode       = 0;
    term->keylist_next_write= 0;
    term->keylist_next_read = 0;
//    term->key_pending       = 0;
//    term->__key_init        = 0;
    term->keysem            = L4SEMAPHORE_LOCKED;
    term->keybufsem         = L4SEMAPHORE_UNLOCKED;
    term->__shift           = 0;
    term->__alt             = 0;
    term->__altgr           = 0;
    term->__ctrl            = 0;
    term->__keydown         = 0;
    term->returns           = 0;
    term->hist_len          = 0;
    term->phys_h            = h;
    term->virt_h            = term->phys_h + hist;
    term->phys_off          = 0;
    term->vis_off           = 0;
    term->cur_x             = 0;
    term->cur_y             = 0;
    term->attrib_mode       = pack_attribs(DEFAULT_FG, DEFAULT_BG, 1);
    term->inverse           = 0;
    term->decscnm           = 0;
    term->esc_state         = ESnormal;
    term->used_par          = 0;
    term->cursor_vis        = 1;
    term->cur_stored_x      = 0;
    term->cur_stored_y      = 0;
    term->cur_stored_attr   = term->attrib_mode;
    term->newline           = 1;
    term->ques              = 0;
    term->scroll_top        = 0;
    term->scroll_bottom     = term->phys_h - 1;
    term->tab_last          = -1;
    term->select_list       = NULL;

    LOG("cols:%d, lines:%d, hist:%d", term->w, term->phys_h, hist);

    free(term->text);
    term->text = malloc(term->w * term->virt_h);
    if (! term->text)
    {
        LOGl("no mem for text (%d)", term->w * term->virt_h);
        return -1;
    }
    memset(term->text, ' ', term->w * term->virt_h);

    free(term->attrib);
    term->attrib = malloc(term->w * term->virt_h);
    if (! term->attrib)
    {
        LOGl("no mem for attrib (%d)", term->w * term->virt_h);
        free(term->text);
        return -2;
    }
    memset(term->attrib, term->attrib_mode, term->w * term->virt_h);

    return 0;
}