const flattened_tensor& CovariantRiemannB3Cache::get()
   {
     if(this->B3) return *this->B3;
 
     auto args = res.generate_cache_arguments(printer);
 
     this->B3 = std::make_unique<flattened_tensor>(res.fl.get_flattened_size<field_index>(RESOURCE_INDICES::RIEMANN_B3_INDICES));
 
     const auto max = res.share.get_max_field_index(variance::covariant);
     const auto max_l = res.share.get_max_field_index(variance::contravariant);
 
     SubstitutionMapCache subs_cache(res, printer);
     DerivativeSymbolsCache deriv_cache(res, res.share, printer);
 
     for(field_index i = field_index(0, variance::covariant); i < max; ++i)
       {
         for(field_index j = field_index(0, variance::covariant); j < max; ++j)
           {
             for(field_index k = field_index(0, variance::covariant); k < max; ++k)
               {
                 unsigned int index = res.fl.flatten(i,j,k);
 
                 GiNaC::ex subs_expr = 0;
 
                 if(!res.cache.query(expression_item_types::Riemann_B3_item, index, args, subs_expr))
                   {
                     timing_instrument timer(res.compute_timer);
 
                     auto& deriv_syms = deriv_cache.get();
                     GiNaC::ex expr = 0;
 
                     for(field_index l = field_index(0, variance::contravariant); l < max_l; ++l)
                       {
                         auto Rie_ijk = (*res.Rie_T)(static_cast<unsigned int>(k), static_cast<unsigned int>(i),
                                                     static_cast<unsigned int>(j), static_cast<unsigned int>(l));
                         auto Rie_ikj = (*res.Rie_T)(static_cast<unsigned int>(k), static_cast<unsigned int>(j),
                                                     static_cast<unsigned int>(i), static_cast<unsigned int>(l));
                         
                         auto Rie_sym = (Rie_ijk + Rie_ikj) / 2;
                         
                         expr += Rie_sym * deriv_syms[res.fl.flatten(l)];
                       }
 
                     // get substitution map
                     GiNaC::exmap& subs_map = subs_cache.get();
                     subs_expr = expr.subs(subs_map, GiNaC::subs_options::no_pattern);
                     
                     res.cache.store(expression_item_types::Riemann_B3_item, index, args, subs_expr);
                   }
                 
                 (*this->B3)[index] = subs_expr;
               }
           }
       }
 
     return *this->B3;
   }
示例#2
0
    std::unique_ptr<flattened_tensor> coordinates::compute(const index_literal_list& indices)
      {
        if(indices.size() != COORDINATE_TENSOR_INDICES) throw tensor_exception("coordinate indices");
        
        auto result = std::make_unique<flattened_tensor>(this->fl.get_flattened_size<phase_index>(COORDINATE_TENSOR_INDICES));
        
        const field_index max_i = this->shared.get_max_field_index(indices[0]->get_variance());

        unsigned deriv_offset = result->size()/2;

        // set up a TensorJanitor to manage use of cache
        TensorJanitor J(*this, indices);

        for(field_index i = field_index(0, indices[0]->get_variance()); i < max_i; ++i)
          {
            GiNaC::ex f;
            GiNaC::ex d;
            
            std::tie(f, d) = this->compute_component(i);
            
            (*result)[this->fl.flatten(i)] = f;
            (*result)[this->fl.flatten(i) + deriv_offset] = d;
          }
        
        return result;
      }
示例#3
0
文件: M.cpp 项目: ds283/CppTransport
    std::unique_ptr<flattened_tensor> M::compute(const index_literal_list& indices)
      {
        if(indices.size() != M_TENSOR_INDICES) throw tensor_exception("M indices");

        auto result = std::make_unique<flattened_tensor>(this->fl.get_flattened_size<field_index>(M_TENSOR_INDICES));
    
        const field_index max_i = this->shared.get_max_field_index(indices[0]->get_variance());
        const field_index max_j = this->shared.get_max_field_index(indices[1]->get_variance());

        // set up a TensorJanitor to manage use of cache
        TensorJanitor J(*this, indices);

        for(field_index i = field_index(0, indices[0]->get_variance()); i < max_i; ++i)
          {
            for(field_index j = field_index(0, indices[1]->get_variance()); j < max_j; ++j)
              {
                (*result)[this->fl.flatten(i, j)] = this->compute_component(i, j);
              }
          }

        return(result);
      }
示例#4
0
static void cpy(dcomplex *entire, dcomplex *region, int dx, int dy, int dz)
{
    //sub領域のregionをentireにコピー
    //SUB_N_PXとかは, 全プロセスで共通(なはず)なので, subInfo_sの値をそのまま使う
    //オフセットはプロセスごとに違うので外部から与える.
    SubFieldInfo_S subInfo_s = field_getSubFieldInfo_S();
    for(int i=1; i<subInfo_s.SUB_N_PX-1; i++)
        for(int j=1; j<subInfo_s.SUB_N_PY-1; j++)
            for(int k=1; k<subInfo_s.SUB_N_PZ-1; k++)
            {
                int w = field_index(i+dx,j+dy,k+dz);
                entire[w] = region[field_subIndex(i,j,k)];
            }
}
示例#5
0
int
column_select_handle_key_form(ui_t *ui, int key)
{
    int field_idx, new_field_idx;
    char field_value[48];
    int action = -1;

    // Get panel information
    column_select_info_t *info = column_select_info(ui);

    // Get current field id
    field_idx = field_index(current_field(info->form));

    // Get current field value.
    memset(field_value, 0, sizeof(field_value));
    strcpy(field_value, field_buffer(current_field(info->form), 0));
    strtrim(field_value);

    // Check actions for this key
    while ((action = key_find_action(key, action)) != ERR) {
        // Check if we handle this action
        switch (action) {
            case ACTION_RIGHT:
            case ACTION_NEXT_FIELD:
                form_driver(info->form, REQ_NEXT_FIELD);
                break;
            case ACTION_LEFT:
            case ACTION_PREV_FIELD:
                form_driver(info->form, REQ_PREV_FIELD);
                break;
            case ACTION_SELECT:
            case ACTION_CONFIRM:
                switch(field_idx) {
                    case FLD_COLUMNS_ACCEPT:
                        column_select_update_columns(ui);
                        ui_destroy(ui);
                        return KEY_HANDLED;
                    case FLD_COLUMNS_CANCEL:
                        ui_destroy(ui);
                        return KEY_HANDLED;
                    case FLD_COLUMNS_SAVE:
                        column_select_update_columns(ui);
                        column_select_save_columns(ui);
                        ui_destroy(ui);
                        return KEY_HANDLED;
                }
                break;
            default:
                // Parse next action
                continue;
        }

        // This panel has handled the key successfully
        break;
    }

    // Validate all input data
    form_driver(info->form, REQ_VALIDATION);

    // Change background and cursor of "button fields"
    set_field_back(info->fields[FLD_COLUMNS_ACCEPT], A_NORMAL);
    set_field_back(info->fields[FLD_COLUMNS_SAVE],   A_NORMAL);
    set_field_back(info->fields[FLD_COLUMNS_CANCEL], A_NORMAL);

    // Get current selected field
    new_field_idx = field_index(current_field(info->form));

    // Swap between menu and form
    if (field_idx == FLD_COLUMNS_CANCEL && new_field_idx == FLD_COLUMNS_ACCEPT) {
        set_menu_fore(info->menu, COLOR_PAIR(CP_DEF_ON_BLUE));
        info->form_active = 0;
    } else {
        // Change current field background
        set_field_back(info->fields[new_field_idx], A_REVERSE);
    }

    // Return if this panel has handled or not the key
    return (action == ERR) ? KEY_NOT_HANDLED : KEY_HANDLED;
}
示例#6
0
static void
show_current_field(WINDOW *win, FORM * form)
{
    FIELD *field;
    FIELDTYPE *type;
    char *buffer;
    int nbuf;
    int field_rows, field_cols, field_max;
    int currow, curcol;

    if (has_colors()) {
	wbkgd(win, (chtype) COLOR_PAIR(1));
    }
    werase(win);
    form_getyx(form, currow, curcol);
    wprintw(win, "Cursor: %d,%d", currow, curcol);
    if (data_ahead(form))
	waddstr(win, " ahead");
    if (data_behind(form))
	waddstr(win, " behind");
    waddch(win, '\n');
    if ((field = current_field(form)) != 0) {
	wprintw(win, "Page %d%s, Field %d/%d%s:",
		form_page(form),
		new_page(field) ? "*" : "",
		field_index(field), field_count(form),
		field_arg(field) ? "(arg)" : "");
	if ((type = field_type(field)) != 0) {
	    if (type == TYPE_ALNUM)
		waddstr(win, "ALNUM");
	    else if (type == TYPE_ALPHA)
		waddstr(win, "ALPHA");
	    else if (type == TYPE_ENUM)
		waddstr(win, "ENUM");
	    else if (type == TYPE_INTEGER)
		waddstr(win, "INTEGER");
#ifdef NCURSES_VERSION
	    else if (type == TYPE_IPV4)
		waddstr(win, "IPV4");
#endif
	    else if (type == TYPE_NUMERIC)
		waddstr(win, "NUMERIC");
	    else if (type == TYPE_REGEXP)
		waddstr(win, "REGEXP");
	    else
		waddstr(win, "other");
	}

	if ((unsigned) field_opts(field) & O_EDIT)
	    waddstr(win, " editable");
	else
	    waddstr(win, " readonly");

	if (field_status(field))
	    waddstr(win, " modified");

	if (dynamic_field_info(field, &field_rows, &field_cols, &field_max)
	    != ERR) {
	    wprintw(win, " size %dx%d (max %d)",
		    field_rows, field_cols, field_max);
	}

	waddch(win, ' ');
	(void) wattrset(win, (int) field_fore(field));
	waddstr(win, "fore");
	wattroff(win, (int) field_fore(field));

	waddch(win, '/');

	(void) wattrset(win, (int) field_back(field));
	waddstr(win, "back");
	wattroff(win, (int) field_back(field));

	wprintw(win, ", pad '%c'",
		field_pad(field));

	waddstr(win, "\n");
	for (nbuf = 0; nbuf <= 2; ++nbuf) {
	    if ((buffer = field_buffer(field, nbuf)) != 0) {
		wprintw(win, "buffer %d:", nbuf);
		(void) wattrset(win, A_REVERSE);
		waddstr(win, buffer);
		wattroff(win, A_REVERSE);
		waddstr(win, "\n");
	    }
	}
    }
    wrefresh(win);
}
示例#7
0
static VALUE rbncurs_c_field_index(VALUE rb_field) {
  FIELD* field = get_field(rb_field);
  return INT2NUM(field_index(field));
}
示例#8
0
int main(void)
{
  int ch, i;

  initscr();
  atexit(quit);
  clear();
  noecho();
  cbreak();
  keypad(stdscr, TRUE);
  start_color();

  init_pair(1, COLOR_YELLOW, COLOR_BLUE);
  init_pair(2, COLOR_BLACK, COLOR_WHITE);

  bkgd(COLOR_PAIR(1));

  fi = (FIELD **)calloc(4, sizeof(FIELD *));
  fi[0] = new_field(1, 10, 2, 3, 0, 0);
  fi[1] = new_field(1, 10, 2, 18, 0, 0);
  fi[2] = new_field(1, 15, 2, 33, 0, 0);
  fi[3] = 0;

  for(i=0; i<3; i++)
  {
    set_field_fore(fi[i], COLOR_PAIR(2));
    set_field_back(fi[i], COLOR_PAIR(2));
  }

  fo = new_form(fi);
  post_form(fo);        

  mvaddstr(2, 15, "+");
  mvaddstr(2, 30, "=");
  mvaddstr(5, 3, "Programm mittels F1-Funktionstaste beenden");

  refresh();
 
  while((ch=getch()) != KEY_F(1))
  {
    switch(ch)
    {
      case KEY_RIGHT:
      { 
        char str[20];
                                                        
        form_driver(fo, REQ_NEXT_FIELD);

        if(field_index(current_field(fo)) == 2)
        {
          snprintf(str, 20, "%s%s", field_buffer(fi[0], 0), field_buffer(fi[1], 0));
          set_field_buffer(fi[2], 0, str);
          refresh();
        }
        break;
      }
      case KEY_LEFT:
        form_driver(fo, REQ_PREV_FIELD);
        break;
      default: /* Feldeingabe */        
        form_driver(fo, ch);
    }
  }   
  return (0);  
}
示例#9
0
文件: eq.c 项目: dsheeler/krad_radio
int eq_run (kr_client_t *client, char *sysname) {

	WINDOW *eq_win,*tmpw;
	PANEL  *eq_mainpan,*eq_subpan,*ctrl_subp;
	FORM *eq_form;
	FIELD **field;
	FIELD **ctrl_field;
	FORM *ctrl_form;


  /* Panels Structs */
  ctrls_show_t *ctrls;
  eq_port_t *eqport;

  db_show_t *db;
  hz_show_t *hz;
  bw_show_t *bw;

  eq_saved_val_t *vals;

	int i;
	int max_co,subx,suby,gap;
	int offs = 0;
	int field_idx;
	int in_ctrl = 0;
  int nbands = KRAD_EQ_MAX_BANDS;
  int showed_bands = 1;
  int idx;
  char num[3];

	int ch;
	int res;
  int bandn;

	clear ();

	char *fieldname[3] = {"Power","Frequency","Bandwidth"}; 
  int nctrls = 3;

	eq_win = newwin (0,0,0,0);

	field = calloc (nbands+1,sizeof (FIELD*));

  ctrl_field = calloc (nctrls+1,sizeof (FIELD*));

	max_co = getmaxx (eq_win);

	gap = floor ((max_co) / nbands);

  vals = NULL;
  bandn = 0;
  ch = 0;


  for (i=0;i<nbands;i++) {

    field[i] = new_field (1,2,1, offs, 0, 0);
    set_field_just (field[i], JUSTIFY_CENTER);
    itoa (i,num,digits (i) + 1 );
    set_field_buffer (field[i], 0, num);
    field_opts_off (field[i], O_AUTOSKIP | O_EDIT); 
    offs += gap;

  }

  field[nbands] = NULL;

  offs = 0;
  gap = floor ((max_co ) / nctrls);

  for (i=0;i<nctrls;i++) {

    ctrl_field[i] = new_field (1,strlen (fieldname[i]),1, offs, 0, 0);
    set_field_just (ctrl_field[i], JUSTIFY_CENTER);
    set_field_buffer (ctrl_field[i], 0, fieldname[i]);
    field_opts_off (ctrl_field[i], O_AUTOSKIP | O_EDIT); 
    offs += gap;

  }


  /* Controls generation */
  ctrls = eq_ctrls_gen (eq_win,showed_bands);

  vals = calloc (1,sizeof (eq_saved_val_t));

  eqport = calloc (1,sizeof (eq_port_t));

  db = ctrls->db;
  hz = ctrls->hz;
  bw = ctrls->bw;

  eqport->name = sysname;
  eqport->vals = vals;
  eqport->ctrls = ctrls;


  /* Eq form init */
  eq_form = new_form (field);

  wattron (eq_win,COLOR_PAIR (2) | A_BOLD);
  mvwprintw (eq_win,getmaxy (eq_win) * 0.05,floor ((max_co/2)-((strlen (sysname)+14)/2)),"Equalizer for %s",sysname); 
  wattroff (eq_win,COLOR_PAIR (2) | A_BOLD);

  set_form_win (eq_form, eq_win);
  scale_form (eq_form, &suby, &subx);
  set_form_sub (eq_form, derwin (eq_win,suby, subx , getmaxy (eq_win) * 0.10 , (max_co - subx) / 2 ));

  eq_mainpan = new_panel (eq_win);
  eq_subpan = new_panel (form_sub (eq_form));

  top_panel (eq_mainpan);
  top_panel (eq_subpan);

  post_form (eq_form);

  keypad (eq_win, TRUE);

  set_current_field (eq_form,field[0]);
  set_field_fore (current_field (eq_form),A_BOLD | COLOR_PAIR (3)); 


  /* Eq ctrls form init */

  ctrl_form = new_form (ctrl_field);

  set_form_win (ctrl_form, eq_win);
  scale_form (ctrl_form, &suby, &subx);
  set_form_sub (ctrl_form, derwin (eq_win,suby, subx , getmaxy (eq_win) * 0.90 , (max_co - subx) / 2 ));

  ctrl_subp = new_panel (form_sub (ctrl_form));

  top_panel (ctrl_subp);

  post_form (ctrl_form);


  field_idx = field_index (current_field (eq_form));


  /* Let's show controls! */
  kr_mixer_portgroups (client);
  show_all_panels (ctrls,showed_bands);


	update_panels ();
	doupdate ();

	while (ch != 'q') { 


    res = krm_poll (client,-1); 

    switch (res) {
      case 0:
        continue;
      case 1:
        ch = getch ();
        break;
      case 2:
        eqport->band = bandn;
        kr_delivery_recv (client);
        eq_delivery_handler (client,eqport);
        continue;
      case -1:
        continue;
    }

    switch (ch) { 

      case KEY_LEFT:

      	if (in_ctrl) {
          set_field_fore (current_field (ctrl_form),A_NORMAL); 
          form_driver (ctrl_form, REQ_PREV_FIELD);
          set_field_fore (current_field (ctrl_form),A_BOLD | COLOR_PAIR (1)); 
          idx = field_index (current_field (ctrl_form));
      	}
      	else {
      		set_field_fore (current_field (eq_form),A_NORMAL); 
      		form_driver (eq_form, REQ_PREV_FIELD);
      		set_field_fore (current_field (eq_form),A_BOLD | COLOR_PAIR (3)); 
          bandn = field_index (current_field (eq_form));
          kr_mixer_portgroups (client); 
      	}
        break;
      case KEY_RIGHT:
      	if (in_ctrl) {
          set_field_fore (current_field (ctrl_form),A_NORMAL); 
          form_driver (ctrl_form, REQ_NEXT_FIELD);
          set_field_fore (current_field (ctrl_form),A_BOLD | COLOR_PAIR (1)); 
          idx = field_index (current_field (ctrl_form));
          
        }
      	else {
          set_field_fore (current_field (eq_form),A_NORMAL); 
          form_driver (eq_form, REQ_NEXT_FIELD);
          set_field_fore (current_field (eq_form),A_BOLD | COLOR_PAIR (3));
          bandn = field_index (current_field (eq_form));
          kr_mixer_portgroups (client); 
      	}
        break;
      case KEY_UP:
        if (in_ctrl) {
          switch (idx) {
            case 0:
              vals->db += 0.50;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "db", vals->db, 0, 0);
              break;
            case 1:
              vals->hz += 5;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "hz", vals->hz, 0, 0);
              break;
            case 2:
              vals->bw += 0.10;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "bw", vals->bw, 0, 0);
              break;
          }

        }
        break;
      case KEY_DOWN:
        if (in_ctrl) {
          switch (idx) {
            case 0:
              vals->db -= 0.5;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "db", vals->db, 0, 0);
              break;
            case 1:
              vals->hz -= 5;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "hz", vals->hz, 0, 0);
              break;
            case 2:
              vals->bw -= 0.10;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "bw", vals->bw, 0, 0);
              break;

          }
   
        }
        break;
      case 'w':
        if (in_ctrl) {
          switch (idx) {
            case 0:
              vals->db += 0.10;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "db", vals->db, 0, 0);
              break;
            case 1:
              vals->hz += 1;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "hz", vals->hz, 0, 0);
              break;
            case 2:
              break;

          }

        }
        break;
      case 's':
        if (in_ctrl) {
          switch (idx) {
            case 0:
              vals->db -= 0.10;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "db", vals->db, 0, 0);
              break;
            case 1:
              vals->hz -= 1;
              kr_mixer_set_effect_control (client, sysname, 0, bandn, "hz", vals->hz, 0, 0);
              break;
            case 2:
              break;

          }
   
        }
        break;
      case 9:
        if (in_ctrl) {
          idx = field_index (current_field (ctrl_form));
          set_field_fore (ctrl_field[idx],A_NORMAL);
          /* ncurses bug I suppose */
          form_driver (ctrl_form, REQ_NEXT_FIELD);
          form_driver (ctrl_form, REQ_PREV_FIELD);
          set_current_field (eq_form,field[field_idx]); 
          in_ctrl = 0;
        }
        else {
          field_idx = field_index (current_field (eq_form));
          set_current_field (ctrl_form,ctrl_field[0]); 
          set_field_fore (ctrl_field[0],A_BOLD | COLOR_PAIR (1));  
          /* ncurses bug I suppose */
          form_driver (ctrl_form, REQ_NEXT_FIELD);
          form_driver (ctrl_form, REQ_PREV_FIELD);
          idx = 0;
          in_ctrl = 1;
        }
        break;
      default:
        break;
    }

    update_panels ();
    doupdate ();
  }
 	

  /* CLEANUP */


  for (i=0;i<showed_bands;i++) {

    tmpw = panel_window (db->slider_p[i]);
    del_panel (db->slider_p[i]);
    delwin (tmpw);

    tmpw = panel_window (db->bar_p[i]);
    del_panel (db->bar_p[i]);
    delwin (tmpw);    

    tmpw = panel_window (hz->cell_p[i]);
    del_panel (hz->cell_p[i]);
    delwin (tmpw);

    tmpw = panel_window (bw->bar_p[i]);
    del_panel (bw->bar_p[i]);
    delwin (tmpw);

    tmpw = panel_window (bw->slider_p[i]);
    del_panel (bw->slider_p[i]);
    delwin (tmpw);

    tmpw = panel_window (bw->cell_p[i]);
    del_panel (bw->cell_p[i]);
    delwin (tmpw);

  }


  free (db->bar_w);
  free (db->slider_w);
  free (hz->cell_w);
  free (bw->bar_w);
  free (bw->slider_w);
  free (bw->cell_w);
  free (db->bar_p);
  free (db->slider_p);
  free (hz->cell_p);
  free (bw->bar_p);
  free (bw->slider_p);
  free (bw->cell_p);

  tmpw = panel_window (db->pan);
  del_panel (db->pan);
  delwin (tmpw);

  tmpw = panel_window (hz->pan);
  del_panel (hz->pan);
  delwin (tmpw);

  tmpw = panel_window (bw->pan);
  del_panel (bw->pan);
  delwin (tmpw);

  free (ctrls);
  free (db);
  free (hz);
  free (bw);
  free (vals);
  free (eqport);


  tmpw = form_sub (ctrl_form);

  unpost_form (ctrl_form);
  free_form (ctrl_form);

  for (i=0;i<nctrls;i++) {
    free_field (ctrl_field[i]);
  }

  free (ctrl_field);

  del_panel (ctrl_subp);
  delwin (tmpw);

  tmpw = form_sub (eq_form);

  unpost_form (eq_form);
  free_form (eq_form);

  
  for (i=0;i<nbands;i++) {
    free_field (field[i]);
  }

  free (field);


  del_panel (eq_subpan);
  del_panel (eq_mainpan);

  delwin (tmpw);
  delwin (eq_win);




	return 0;
}
示例#10
0
int
save_raw_handle_key(PANEL *panel, int key)
{
    int field_idx;
    char field_value[48];
    int action = -1;

    // Get panel information
    save_raw_info_t *info = (save_raw_info_t*) panel_userptr(panel);

    // Get current field id
    field_idx = field_index(current_field(info->form));

    // Get current field value.
    // We trim spaces with sscanf because and empty field is stored as
    // space characters
    memset(field_value, 0, sizeof(field_value));
    sscanf(field_buffer(current_field(info->form), 0), "%[^ ]", field_value);

    // Check actions for this key
    while ((action = key_find_action(key, action)) != ERR) {
        // Check if we handle this action
        switch (action) {
            case ACTION_PRINTABLE:
                if (field_idx == FLD_SAVE_RAW_SAVE)
                    form_driver(info->form, key);
                break;
            case ACTION_NEXT_FIELD:
                form_driver(info->form, REQ_NEXT_FIELD);
                form_driver(info->form, REQ_END_LINE);
                break;
            case ACTION_PREV_FIELD:
                form_driver(info->form, REQ_PREV_FIELD);
                form_driver(info->form, REQ_END_LINE);
                break;
            case ACTION_RIGHT:
                form_driver(info->form, REQ_RIGHT_CHAR);
                break;
            case ACTION_LEFT:
                form_driver(info->form, REQ_LEFT_CHAR);
                break;
            case ACTION_BEGIN:
                form_driver(info->form, REQ_BEG_LINE);
                break;
            case ACTION_END:
                form_driver(info->form, REQ_END_LINE);
                break;
            case ACTION_DELETE:
                form_driver(info->form, REQ_DEL_CHAR);
                break;
            case ACTION_BACKSPACE:
                if (strlen(field_value) > 0)
                    form_driver(info->form, REQ_DEL_PREV);
                break;
            case ACTION_CLEAR:
                form_driver(info->form, REQ_CLR_FIELD);
                break;
            case ACTION_CONFIRM:
                if (field_idx != FLD_SAVE_RAW_CANCEL) {
                    if (!strcasecmp(field_value, "")) {
                        save_raw_error_message(panel, "Invalid filename");
                        return 0;
                    }
                    return save_raw_to_file(panel);
                }
                return 27;
            default:
                // Parse next action
                continue;
        }

        // We've handled this key, stop checking actions
        break;
    }

    // Validate all input data
    form_driver(info->form, REQ_VALIDATION);

    // Change background and cursor of "button fields"
    set_field_back(info->fields[FLD_SAVE_RAW_SAVE], A_NORMAL);
    set_field_back(info->fields[FLD_SAVE_RAW_CANCEL], A_NORMAL);
    curs_set(1);

    // Change current field background
    field_idx = field_index(current_field(info->form));
    if (field_idx == FLD_SAVE_RAW_SAVE || field_idx == FLD_SAVE_RAW_CANCEL) {
        set_field_back(info->fields[field_idx], A_REVERSE);
        curs_set(0);
    }

    // Return if this panel has handled or not the key
    return (action == ERR) ? key : 0;
}
示例#11
0
int
call_list_handle_form_key(PANEL *panel, int key)
{
    int field_idx;
    char dfilter[256];
    int action = -1;

    // Get panel information
    call_list_info_t *info = call_list_info(panel);

    // Get current field id
    field_idx = field_index(current_field(info->form));

    // Check actions for this key
    while ((action = key_find_action(key, action)) != ERR) {
        // Check if we handle this action
        switch (action) {
            case ACTION_PRINTABLE:
                // If this is a normal character on input field, print it
                form_driver(info->form, key);
                break;
            case ACTION_PREV_SCREEN:
            case ACTION_NEXT_FIELD:
            case ACTION_CONFIRM:
            case ACTION_SELECT:
            case ACTION_UP:
            case ACTION_DOWN:
                // Activate list
                call_list_form_activate(panel, 0);
                break;
            case ACTION_RIGHT:
                form_driver(info->form, REQ_RIGHT_CHAR);
                break;
            case ACTION_LEFT:
                form_driver(info->form, REQ_LEFT_CHAR);
                break;
            case ACTION_BEGIN:
                form_driver(info->form, REQ_BEG_LINE);
                break;
            case ACTION_END:
                form_driver(info->form, REQ_END_LINE);
                break;
            case ACTION_CLEAR:
                form_driver(info->form, REQ_BEG_LINE);
                form_driver(info->form, REQ_CLR_EOL);
                break;
            case ACTION_DELETE:
                form_driver(info->form, REQ_DEL_CHAR);
                break;
            case ACTION_BACKSPACE:
                form_driver(info->form, REQ_DEL_PREV);
                break;
            default:
                // Parse next action
                continue;
        }

        // We've handled this key, stop checking actions
        break;
    }

    // Filter has changed, re-apply filter to displayed calls
    if (action == ACTION_PRINTABLE || action == ACTION_BACKSPACE ||
            action == ACTION_DELETE || action == ACTION_CLEAR) {
        // Updated displayed results
         call_list_clear(panel);
         // Reset filters on each key stroke
         filter_reset_calls();
    }

    // Validate all input data
    form_driver(info->form, REQ_VALIDATION);

    // Store dfilter input
    // We trim spaces with sscanf because and empty field is stored as space characters
    memset(dfilter, 0, sizeof(dfilter));
    strcpy(dfilter, field_buffer(info->fields[FLD_LIST_FILTER], 0));
    strtrim(dfilter);

    // Set display filter
    filter_set(FILTER_CALL_LIST, strlen(dfilter) ? dfilter : NULL);

    // Return if this panel has handled or not the key
    return (action == ERR) ? key : 0;
}
示例#12
0
int
filter_handle_key(PANEL *panel, int key)
{
    int field_idx;
    char field_value[30];
    int action = -1;

    // Get panel information
    filter_info_t *info = filter_info(panel);

    // Get current field id
    field_idx = field_index(current_field(info->form));

    // Get current field value.
    // We trim spaces with sscanf because and empty field is stored as
    // space characters
    memset(field_value, 0, sizeof(field_value));
    strcpy(field_value, field_buffer(current_field(info->form), 0));
    strtrim(field_value);

    // Check actions for this key
    while ((action = key_find_action(key, action)) != ERR) {
        // Check if we handle this action
        switch (action) {
            case ACTION_PRINTABLE:
                // If this is a normal character on input field, print it
                if (field_idx == FLD_FILTER_SIPFROM || field_idx == FLD_FILTER_SIPTO
                    || field_idx == FLD_FILTER_SRC || field_idx == FLD_FILTER_DST
                    || field_idx == FLD_FILTER_PAYLOAD) {
                    form_driver(info->form, key);
                    break;
                }
                continue;
            case ACTION_NEXT_FIELD:
                form_driver(info->form, REQ_NEXT_FIELD);
                form_driver(info->form, REQ_END_LINE);
                break;
            case ACTION_PREV_FIELD:
                form_driver(info->form, REQ_PREV_FIELD);
                form_driver(info->form, REQ_END_LINE);
                break;
            case ACTION_RIGHT:
                form_driver(info->form, REQ_RIGHT_CHAR);
                break;
            case ACTION_LEFT:
                form_driver(info->form, REQ_LEFT_CHAR);
                break;
            case ACTION_BEGIN:
                form_driver(info->form, REQ_BEG_LINE);
                break;
            case ACTION_END:
                form_driver(info->form, REQ_END_LINE);
                break;
            case ACTION_CLEAR:
                form_driver(info->form, REQ_CLR_FIELD);
                break;
            case KEY_DC:
                form_driver(info->form, REQ_DEL_CHAR);
                break;
            case ACTION_DELETE:
                form_driver(info->form, REQ_DEL_CHAR);
                break;
            case ACTION_BACKSPACE:
                if (strlen(field_value) > 0)
                    form_driver(info->form, REQ_DEL_PREV);
                break;
            case ACTION_SELECT:
                switch (field_idx) {
                    case FLD_FILTER_REGISTER:
                    case FLD_FILTER_INVITE:
                    case FLD_FILTER_SUBSCRIBE:
                    case FLD_FILTER_NOTIFY:
                    case FLD_FILTER_OPTIONS:
                    case FLD_FILTER_PUBLISH:
                    case FLD_FILTER_MESSAGE:
                        if (field_value[0] == '*') {
                            form_driver(info->form, REQ_DEL_CHAR);
                        } else {
                            form_driver(info->form, '*');
                        }
                        break;
                    case FLD_FILTER_CANCEL:
                        return KEY_ESC;
                    case FLD_FILTER_FILTER:
                        filter_save_options(panel);
                        return KEY_ESC;
                }
                break;
            case ACTION_CONFIRM:
                if (field_idx != FLD_FILTER_CANCEL)
                    filter_save_options(panel);
                return KEY_ESC;
            default:
                // Parse next action
                continue;
        }

        // This panel has handled the key successfully
        break;
    }

    // Validate all input data
    form_driver(info->form, REQ_VALIDATION);

    // Change background and cursor of "button fields"
    set_field_back(info->fields[FLD_FILTER_FILTER], A_NORMAL);
    set_field_back(info->fields[FLD_FILTER_CANCEL], A_NORMAL);
    curs_set(1);

    // Change current field background
    field_idx = field_index(current_field(info->form));
    if (field_idx == FLD_FILTER_FILTER || field_idx == FLD_FILTER_CANCEL) {
        set_field_back(info->fields[field_idx], A_REVERSE);
        curs_set(0);
    }

    // Return if this panel has handled or not the key
    return (action == ERR) ? key : 0;
}
示例#13
0
文件: ui_save.c 项目: cruzccl/sngrep
int
save_handle_key(ui_t *ui, int key)
{
    int field_idx;
    int action = -1;

    // Get panel information
    save_info_t *info = save_info(ui);

    // Get current field id
    field_idx = field_index(current_field(info->form));

    // Check actions for this key
    while ((action = key_find_action(key, action)) != ERR) {
        // Check if we handle this action
        switch (action) {
            case ACTION_PRINTABLE:
                if (field_idx == FLD_SAVE_PATH || field_idx == FLD_SAVE_FILE) {
                    form_driver(info->form, key);
                    break;
                }
                continue;
            case ACTION_NEXT_FIELD:
                form_driver(info->form, REQ_NEXT_FIELD);
                form_driver(info->form, REQ_END_LINE);
                break;
            case ACTION_PREV_FIELD:
                form_driver(info->form, REQ_PREV_FIELD);
                form_driver(info->form, REQ_END_LINE);
                break;
            case ACTION_RIGHT:
                form_driver(info->form, REQ_RIGHT_CHAR);
                break;
            case ACTION_LEFT:
                form_driver(info->form, REQ_LEFT_CHAR);
                break;
            case ACTION_BEGIN:
                form_driver(info->form, REQ_BEG_LINE);
                break;
            case ACTION_END:
                form_driver(info->form, REQ_END_LINE);
                break;
            case ACTION_DELETE:
                form_driver(info->form, REQ_DEL_CHAR);
                break;
            case ACTION_BACKSPACE:
                form_driver(info->form, REQ_DEL_PREV);
                break;
            case ACTION_CLEAR:
                form_driver(info->form, REQ_CLR_FIELD);
                break;
            case ACTION_SELECT:
                switch (field_idx) {
                    case FLD_SAVE_ALL:
                        info->savemode = SAVE_ALL;
                        break;
                    case FLD_SAVE_SELECTED:
                        info->savemode = SAVE_SELECTED;
                        break;
                    case FLD_SAVE_DISPLAYED:
                        info->savemode = SAVE_DISPLAYED;
                        break;
                    case FLD_SAVE_MESSAGE:
                        info->savemode = SAVE_MESSAGE;
                        break;
                    case FLD_SAVE_PCAP:
                        info->saveformat = SAVE_PCAP;
                        break;
                    case FLD_SAVE_PCAP_RTP:
                        info->saveformat = SAVE_PCAP_RTP;
                        break;
                    case FLD_SAVE_TXT:
                        info->saveformat = SAVE_TXT;
                        break;
                    case FLD_SAVE_FILE:
                        form_driver(info->form, key);
                        break;
                    default:
                        break;
                }
                break;
            case ACTION_CONFIRM:
                if (field_idx != FLD_SAVE_CANCEL) {
                    save_to_file(ui);
                }
                ui_destroy(ui);
                return KEY_HANDLED;
            default:
                // Parse next action
                continue;
        }

        // This panel has handled the key successfully
        break;
    }

    // Validate all input data
    form_driver(info->form, REQ_VALIDATION);

    // Change background and cursor of "button fields"
    set_field_back(info->fields[FLD_SAVE_SAVE], A_NORMAL);
    set_field_back(info->fields[FLD_SAVE_CANCEL], A_NORMAL);
    curs_set(1);

    // Change current field background
    field_idx = field_index(current_field(info->form));
    if (field_idx == FLD_SAVE_SAVE || field_idx == FLD_SAVE_CANCEL) {
        set_field_back(info->fields[field_idx], A_REVERSE);
        curs_set(0);
    }

    // Return if this panel has handled or not the key
    return (action == ERR) ? KEY_NOT_HANDLED : KEY_HANDLED;
}