/* retrieve data from modify parameters form */
static void modify_parameters_form_term(FORM *myform) {
  
char *temp;

  temp = field_buffer(field_items_ptr[0], 0);
  bullet.bc = atof(temp);
  temp = field_buffer(field_items_ptr[1], 0);
  bullet.weight = atof(temp);
  temp = field_buffer(field_items_ptr[2], 0);
  wind.z = atof(temp);
  temp = field_buffer(field_items_ptr[3], 0);
  firearm.v0 = atof(temp);
  temp = field_buffer(field_items_ptr[4], 0);
  firearm.height = atof(temp);
  temp = field_buffer(field_items_ptr[5], 0);
  firearm.zero = atof(temp);
  temp = field_buffer(field_items_ptr[6], 0);
  firearm.angle = atof(temp);
  temp = field_buffer(field_items_ptr[7], 0);
  printparam.start = atof(temp);
  temp = field_buffer(field_items_ptr[8], 0);
  printparam.end = atof(temp);
  temp = field_buffer(field_items_ptr[9], 0);
  printparam.step = atof(temp);

}
void AddProjectForm::eventhandle(NEvent* ev) 	//обработчик событий
{
    if ( ev->done )
	return;
    NMouseEvent* mevent = (NMouseEvent*)ev;
    if ( ev->type == NEvent::evMOUSE)
    {
	NForm::eventhandle(ev); //предок
    }
    if ( ev->type == NEvent::evKB )
    {
	ev->done = true;
        switch(ev->keycode)
	{
	    case KEY_ENTER:
	    case '\n': //ENTER
	    {
		form_driver(frm, REQ_NEXT_FIELD); //костыль чтобы текущее поле не потеряло значение
		char* email = strlowcase(rtrim(field_buffer(fields[emailfield],0)));
		char* passw = rtrim(field_buffer(fields[passwfield],0));
		kLogPrintf("AddProjectForm OK name=[%s] url=[%s] email=[%s]\n passw=[%s]\n", projname.c_str(), projurl.c_str(), email, passw);
		if (srv!=NULL)
		{
		    std::string errmsg;
		    bool success = true;
		    if (!userexist) //если аккаунта еще нет то создаем
		    {
			char* username = strlowcase(rtrim(field_buffer(fields[usernamefield],0)));
			char* teamname = rtrim(field_buffer(fields[teamfield],0));
			success = srv->createaccount(projurl.c_str(),email,passw, username, teamname, errmsg);
		    }
		    if (success)
			success = srv->projectattach(projurl.c_str(), projname.c_str(), email, passw, errmsg); //подключить проект
		    if (success)
			putevent(new TuiEvent(evADDPROJECT)); //создаем событие чтобы закрыть форму
		    else
		    {
			//СООБЩЕНИЕ ОБ ОШИБКЕ
			errmsg = " Error: " + errmsg;
			set_field_buffer(fields[errmsgfield], 0, errmsg.c_str());
			field_opts_on(fields[errmsgfield], O_VISIBLE); //делаем видимой строку ошибки
			this->refresh();
		    }
		}
		break;
	    }
	    case 27:
		putevent(new TuiEvent(evADDPROJECT)); //код закрытия окна
		break;
	    default:
		kLogPrintf("AddProjectForm::KEYCODE=%d\n", ev->keycode);
		ev->done = false;
		NForm::eventhandle(ev); //предок
		break;
	} //switch
    }
}
Exemple #3
0
/* calculate bc form term function */
static void calc_bc_form_term(FORM *myform) {
  
char *temp;

  temp = field_buffer(field_items_ptr[0], 0);
  calc_bc_param.x0 = atof(temp);
  temp = field_buffer(field_items_ptr[1], 0);
  calc_bc_param.v0 = atof(temp);
  temp = field_buffer(field_items_ptr[2], 0);
  calc_bc_param.x1 = atof(temp);
  temp = field_buffer(field_items_ptr[3], 0);
  calc_bc_param.v1 = atof(temp);

}
Exemple #4
0
/*---------------------------------------------------------------------------
|   Facility      :  libnform
|   Function      :  static bool Check_RegularExpression_Field(
|                                      FIELD * field,
|                                      const void  * argp)
|
|   Description   :  Validate buffer content to be a valid regular expression
|
|   Return Values :  TRUE  - field is valid
|                    FALSE - field is invalid
+--------------------------------------------------------------------------*/
static bool Check_RegularExpression_Field(FIELD * field, const void  * argp)
{
  bool match = FALSE;
#if HAVE_REGEX_H_FUNCS
  const RegExp_Arg *ap = (const RegExp_Arg*)argp;
  if (ap && ap->pRegExp)
    match = (regexec(ap->pRegExp,field_buffer(field,0),0,NULL,0) ? FALSE:TRUE);
#elif HAVE_REGEXP_H_FUNCS | HAVE_REGEXPR_H_FUNCS
  RegExp_Arg *ap = (RegExp_Arg *)argp;
  if (ap && ap->compiled_expression)
    match = (step(field_buffer(field,0),ap->compiled_expression) ? TRUE:FALSE);
#endif
  return match;
}
Exemple #5
0
static char const* brsh_get_input(void)
{
    /* get the field content */
    form_driver(frm_input, REQ_VALIDATION);
    char *fld_buffer = field_buffer(fld_input, 0);
    
    /* trim the left-hand side */
    while (isspace(*fld_buffer)) fld_buffer++;
    
    /* copy the buffer */
    static char *input_buffer = NULL;
    if (input_buffer) free(input_buffer);
    long size = strlen(fld_buffer);
    input_buffer = malloc(size + 1);
    if (!input_buffer)
        brain_fatal_("Not enough memory\n");
    strcpy(input_buffer, fld_buffer);
    
    /* trim the right-hand side */
    for (long i = size-1; i >= 0; i--)
    {
        if (!isspace(input_buffer[i]))
        {
            input_buffer[i+1] = 0;
            break;
        }
    }
    
    return input_buffer;
}
Exemple #6
0
/*---------------------------------------------------------------------------
|   Facility      :  libnform  
|   Function      :  static bool Check_Integer_Field(
|                                                    FIELD * field,
|                                                    const void * argp)
|   
|   Description   :  Validate buffer content to be a valid integer value
|
|   Return Values :  TRUE  - field is valid
|                    FALSE - field is invalid
+--------------------------------------------------------------------------*/
static bool Check_Integer_Field(FIELD * field, const void * argp)
{
  const integerARG *argi = (const integerARG *)argp;
  long low          = argi->low;
  long high         = argi->high;
  int prec          = argi->precision;
  unsigned char *bp = (unsigned char *)field_buffer(field,0);
  char *s           = (char *)bp;
  long val;
  char buf[100];

  while( *bp && *bp==' ') bp++;
  if (*bp)
    {
      if (*bp=='-') bp++;
      while (*bp)
	{
	  if (!isdigit(*bp)) break;
	  bp++;
	}
      while(*bp && *bp==' ') bp++;
      if (*bp=='\0')
	{
	  val = atol(s);
	  if (low<high)
	    {
	      if (val<low || val>high) return FALSE;
	    }
	  sprintf(buf,"%.*ld",(prec>0?prec:0),val);
	  set_field_buffer(field,0,buf);
	  return TRUE;
	}
    }
  return FALSE;
}
/*
 * copy the temp buffers to the real ones
 */
static void wdg_input_consolidate(struct wdg_object *wo)
{
   WDG_WO_EXT(struct wdg_input_handle, ww);
   char *buf;
   int i = 0, j;
   size_t buflen;
   void (*callback)(void);
   
   WDG_DEBUG_MSG("wdg_input_consolidate");
   
   while(ww->fields[i] != NULL) {
      /* get the buffer */
      buf = field_buffer(ww->fields[i+1], 0);
      buflen = strlen(buf);

      /* trim out the trailing spaces */
      for (j = buflen - 1; j >= 0; j--)
         if (buf[j] == ' ')
            buf[j] = 0;
         else
            break;
      
      /* copy the buffer in the real one */
      strcpy(ww->buffers[i/2], buf);
      
      /* skip the label */
      i += 2;
   }

   /* execute the callback */
   callback = ww->callback;
   wdg_destroy_object(&wo);
   wdg_redraw_all();
   WDG_EXECUTE(callback);
}
/*
 * Delete the popup allocated memory.
 * This *won't* free popup_btn_action.
 */
void popup_delete(void)
{
	int i;

	if (popup_form) {
		unpost_form(popup_form);

		for (i = 0; popup_fields[i] != NULL; i++) {
			free(field_buffer(popup_fields[i], 0));
			free_field(popup_fields[i]);
		}

		free_form(popup_form);
		free(popup_fields);
	}

	unpost_menu(popup_menu);
	free_menu(popup_menu);

	for (i = 0; popup_items[i] != NULL; i++)
		free_item(popup_items[i]);

	free(popup_items);
	delwin(win_form);
	delwin(win_menu);
	delwin(win_body);
	win_body = NULL;
	popup_btn_action = NULL;
	popup_menu = NULL;
}
Exemple #9
0
int
save_raw_to_file(PANEL *panel)
{
    char field_value[48];
    FILE *f;
    sip_msg_t *msg = NULL;

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

    // 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(info->fields[FLD_SAVE_RAW_FILE], 0), "%[^ ]", field_value);

    if (!(f = fopen(field_value, "w"))) {
        save_raw_error_message(panel, "Unable to open save file for writing");
        return 0;
    }

    // Print the call group messages into the pad
    while ((msg = call_group_get_next_msg(info->group, msg))) {
        fprintf(f, "%s %s %s -> %s\n%s\n\n", msg_get_attribute(msg, SIP_ATTR_DATE),
                msg_get_attribute(msg, SIP_ATTR_TIME), msg_get_attribute(msg, SIP_ATTR_SRC),
                msg_get_attribute(msg, SIP_ATTR_DST), msg->payload);
    }

    fclose(f);
    return 27;
}
Exemple #10
0
int
save_draw(ui_t *ui)
{
    char field_value[80];

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

    // Get filter stats
    sip_stats_t stats = sip_calls_stats();

    mvwprintw(ui->win, 7, 3, "( ) all dialogs ");
    mvwprintw(ui->win, 8, 3, "( ) selected dialogs [%d]", call_group_count(info->group));
    mvwprintw(ui->win, 9, 3, "( ) filtered dialogs [%d]", stats.displayed);

    // Print 'current SIP message' field label if required
    if (info->msg != NULL)
        mvwprintw(ui->win, 10, 3, "( ) current SIP message");

    mvwprintw(ui->win, 7, 35, "( ) .pcap (SIP)");
    mvwprintw(ui->win, 8, 35, "( ) .pcap (SIP + RTP)");
    mvwprintw(ui->win, 9, 35, "( ) .txt");

    // Get filename field value.
    memset(field_value, 0, sizeof(field_value));
    strcpy(field_value, field_buffer(info->fields[FLD_SAVE_FILE], 0));
    strtrim(field_value);

    mvwprintw(ui->win, 4, 60, "     ");
    if (strstr(field_value, ".pcap")) {
        info->saveformat = (setting_enabled(SETTING_CAPTURE_RTP))? SAVE_PCAP_RTP : SAVE_PCAP;
    } else if (strstr(field_value, ".txt")) {
        info->saveformat = SAVE_TXT;
    } else {
        if (info->saveformat == SAVE_PCAP || info->saveformat == SAVE_PCAP_RTP)
            mvwprintw(ui->win, 4, 60, ".pcap");
        else
            mvwprintw(ui->win, 4, 60, ".txt ");
    }

    set_field_buffer(info->fields[FLD_SAVE_ALL], 0, (info->savemode == SAVE_ALL) ? "*" : " ");
    set_field_buffer(info->fields[FLD_SAVE_SELECTED], 0,
                     (info->savemode == SAVE_SELECTED) ? "*" : " ");
    set_field_buffer(info->fields[FLD_SAVE_DISPLAYED], 0,
                     (info->savemode == SAVE_DISPLAYED) ? "*" : " ");
    set_field_buffer(info->fields[FLD_SAVE_MESSAGE], 0,
                     (info->savemode == SAVE_MESSAGE) ? "*" : " ");
    set_field_buffer(info->fields[FLD_SAVE_PCAP], 0, (info->saveformat == SAVE_PCAP) ? "*" : " ");
    set_field_buffer(info->fields[FLD_SAVE_PCAP_RTP], 0, (info->saveformat == SAVE_PCAP_RTP) ? "*" : " ");
    set_field_buffer(info->fields[FLD_SAVE_TXT], 0, (info->saveformat == SAVE_TXT) ? "*" : " ");

    // Show disabled options with makers
    if (!setting_enabled(SETTING_CAPTURE_RTP))
        set_field_buffer(info->fields[FLD_SAVE_PCAP_RTP], 0, "-");

    set_current_field(info->form, current_field(info->form));
    form_driver(info->form, REQ_VALIDATION);

    return 0;
}
Exemple #11
0
/*---------------------------------------------------------------------------
|   Facility      :  libnform  
|   Function      :  static bool Previous_Enum(
|                                          FIELD * field,
|                                          const void * argp)
|   
|   Description   :  Check for the previous enumeration value
|
|   Return Values :  TRUE  - previous value found and loaded
|                    FALSE - no previous value loaded
+--------------------------------------------------------------------------*/
static bool
Previous_Enum(FIELD *field, const void *argp)
{
  const enumARG *args = (const enumARG *)argp;
  int cnt = args->count;
  char **kwds = &args->kwds[cnt - 1];
  bool ccase = args->checkcase;
  unsigned char *bp = (unsigned char *)field_buffer(field, 0);

  if (kwds)
    {
      while (cnt--)
	{
	  if (Compare((unsigned char *)(*kwds--), bp, ccase) == EXACT)
	    break;
	}

      if (cnt <= 0)
	kwds = &args->kwds[args->count - 1];

      if ((cnt >= 0) || (Compare((const unsigned char *)dummy, bp, ccase) == EXACT))
	{
	  set_field_buffer(field, 0, *kwds);
	  return TRUE;
	}
    }
  return FALSE;
}
Exemple #12
0
bool DialogForm::isDataValid() {
    for (int i = 0; i < m_numFields; i++) {
        std::string str = field_buffer(m_pFields[i], 0);
        StringUtil::trimEnd(str);
        if (!isFieldValid() || (!allowEmptyFields && str.compare("") == 0)) {
            return false;
        }
    }
    return true;
}
Exemple #13
0
void get_input(FORM *my_form, FIELD **field){
    int ch;
    int contLoop=1;
    char *temp = (char*)malloc(50*sizeof(char));
    while(contLoop)
    {   ch = getch();
        switch(ch)
        {   case KEY_BACKSPACE:
                form_driver(my_form, REQ_DEL_PREV);
                break;
            case KEY_DC:
                form_driver(my_form, REQ_DEL_CHAR);
                break;
            case KEY_LEFT:
                if (form_driver(my_form, REQ_LEFT_CHAR)==E_REQUEST_DENIED){
                    form_driver(my_form, REQ_PREV_FIELD);
                }
                break;
            case KEY_RIGHT:
                if (form_driver(my_form, REQ_RIGHT_CHAR)==E_REQUEST_DENIED){
                    form_driver(my_form, REQ_NEXT_FIELD);
                }
                break;
            case KEY_UP:
                if (form_driver(my_form, REQ_PREV_LINE)==E_REQUEST_DENIED){
                    form_driver(my_form, REQ_PREV_FIELD);
                }
                break;
            case KEY_DOWN:
                if (form_driver(my_form, REQ_NEXT_LINE)==E_REQUEST_DENIED){
                    form_driver(my_form, REQ_NEXT_FIELD);
                }
                break;
            case '\n':
                if (form_driver(my_form,REQ_VALIDATION)==E_OK){
                    int i;
                    int valid=1;
                    for(i=0;i<5;i++){
                        strcpy(temp,field_buffer(field[i],0));
                        trimTrailingWhitespace(temp);
                        if (strlen(temp)==0) valid=0;
                    }
                    
                    if (valid==1) contLoop=0;
                }
            default:
                form_driver(my_form, ch);
                break;
        }
    }
}
static char *dup_current_name(void)
{
	int rows, cols, max, i;
	char *s;

	if (form_driver(form, REQ_VALIDATION) == E_OK) {
		dynamic_field_info(fields[1], &rows, &cols, &max);
		s = ccalloc(1, cols + 1);
		memcpy(s, field_buffer(fields[1], 0), cols);
		for (i = strlen(s) - 1; i >= 0 && s[i] == ' '; --i)
			s[i] = '\0';
		return s;
	} else {
		return cstrdup("");
	}
}
Exemple #15
0
bool DialogForm::getFormData(std::string **pData) {
    if (getReturnState() != STATE_SUCCESS || pData == 0 || *pData != 0) {
        return false;
    }
#ifdef DEBUG
    dout << "Form " << getTitle() << " data: " << std::endl;
#endif //DEBUG
    std::string* data = new std::string[m_numFields];
    for (int i = 0; i < m_numFields; i++) {
        std::string str = field_buffer(m_pFields[i], 0);
        StringUtil::trimEnd(str);
        data[i] = str;
#ifdef DEBUG
        dout << "   " << i << str << std::endl;
#endif //DEBUG
    }
    *pData = data;
    return true;
}
Exemple #16
0
static int
fcheck_alpha(FIELD *f, char *arg)
{
	int	width	= *((int *) arg);
	int	n	= 0;
	char *	v	= field_buffer(f, 0);

	while (*v && *v == ' ')
		++v;
	if (*v) {
		char * vbeg = v;
		while (*v && isalpha(*v))
			++v;
		n = v - vbeg;
		while (*v && *v == ' ')
			++v;
	}
	return (*v || n < width ? FALSE : TRUE);
}
Exemple #17
0
/*---------------------------------------------------------------------------
|   Facility      :  libnform  
|   Function      :  static bool Check_Enum_Field(
|                                      FIELD * field,
|                                      const void  * argp)
|   
|   Description   :  Validate buffer content to be a valid enumeration value
|
|   Return Values :  TRUE  - field is valid
|                    FALSE - field is invalid
+--------------------------------------------------------------------------*/
static bool
Check_Enum_Field(FIELD *field, const void *argp)
{
  char **kwds = ((const enumARG *)argp)->kwds;
  bool ccase = ((const enumARG *)argp)->checkcase;
  bool unique = ((const enumARG *)argp)->checkunique;
  unsigned char *bp = (unsigned char *)field_buffer(field, 0);
  char *s, *t, *p;
  int res;

  while (kwds && (s = (*kwds++)))
    {
      if ((res = Compare((unsigned char *)s, bp, ccase)) != NOMATCH)
	{
	  p = t = s;		/* t is at least a partial match */
	  if ((unique && res != EXACT))
	    {
	      while (kwds && (p = *kwds++))
		{
		  if ((res = Compare((unsigned char *)p, bp, ccase)) != NOMATCH)
		    {
		      if (res == EXACT)
			{
			  t = p;
			  break;
			}
		      else
			t = (char *)0;
		    }
		}
	    }
	  if (t)
	    {
	      set_field_buffer(field, 0, t);
	      return TRUE;
	    }
	  if (!p)
	    break;
	}
    }
  return FALSE;
}
/*---------------------------------------------------------------------------
|   Facility      :  libnform  
|   Function      :  static bool Check_AlphaNumeric_Field(
|                                      FIELD *field,
|                                      const void *argp)
|   
|   Description   :  Validate buffer content to be a valid alphanumeric value
|
|   Return Values :  TRUE  - field is valid
|                    FALSE - field is invalid
+--------------------------------------------------------------------------*/
static bool Check_AlphaNumeric_Field(FIELD * field, const void * argp)
{
  int width = ((const alnumARG *)argp)->width;
  unsigned char *bp  = (unsigned char *)field_buffer(field,0);
  int  l = -1;
  unsigned char *s;

  while(*bp && *bp==' ') 
    bp++;
  if (*bp)
    {
      s = bp;
      while(*bp && isalnum(*bp)) 
	bp++;
      l = (int)(bp-s);
      while(*bp && *bp==' ') 
	bp++;
    }
  return ((*bp || (l < width)) ? FALSE : TRUE);
}
Exemple #19
0
/*---------------------------------------------------------------------------
|   Facility      :  libnform
|   Function      :  static bool Check_IPV4_Field(
|                                      FIELD * field,
|                                      const void * argp)
|
|   Description   :  Validate buffer content to be a valid IP number (Ver. 4)
|
|   Return Values :  TRUE  - field is valid
|                    FALSE - field is invalid
+--------------------------------------------------------------------------*/
static bool Check_IPV4_Field(FIELD * field, const void * argp)
{
    char *bp = field_buffer(field,0);
    int num = 0, len;
    unsigned int d1=256, d2=256, d3=256, d4=256;

    argp=0; /* Silence unused parameter warning.  */

    if(isdigit((int)(*bp)))              /* Must start with digit */
    {
        num = sscanf(bp, "%u.%u.%u.%u%n", &d1, &d2, &d3, &d4, &len);
        if (num == 4)
        {
            bp += len;            /* Make bp point to what sscanf() left */
            while (*bp && isspace((int)(*bp)))
                bp++;               /* Allow trailing whitespace */
        }
    }
    return ((num != 4 || *bp || d1 > 255 || d2 > 255
             || d3 > 255 || d4 > 255) ? FALSE : TRUE);
}
Exemple #20
0
static int
fcheck_num(FIELD *f, char *arg)
{
	NUMERIC *	n = (NUMERIC *) arg;
	double		vmin = n -> vmin;
	double		vmax = n -> vmax;
	int		prec = n -> prec;
	char *		x = field_buffer(f, 0);
	char		buf[80];

	while (*x && *x == ' ')
		++x;
	if (*x) {
		char * t = x;

		if (*x == '-')
			++x;
		while (*x && isdigit(*x))
			++x;
		if (*x == '.') {
			++x;
			while (*x && isdigit(*x))
				++x;
		}
		while (*x && *x == ' ')
			++x;
		if (! *x) {
			double v = atof(t);

			if (vmin >= vmax || (v >= vmin && v <= vmax)) {
				(void) sprintf(buf, "%.*f", prec, v);
				(void) set_field_buffer(f, 0, buf);
				return (TRUE);
			}
		}
	}
	return (FALSE);
}
Exemple #21
0
void exec_action_context_service_config(int ch)
{
	FIELD *field;
	int cur_page = form_page(my_form);

	switch (ch) {
		case KEY_DOWN:
			form_driver(my_form, REQ_NEXT_FIELD);
			form_driver(my_form, REQ_END_LINE);
			break;

		case KEY_UP:
			form_driver(my_form, REQ_PREV_FIELD);
			form_driver(my_form, REQ_END_LINE);
			break;

		case KEY_NPAGE:
			form_driver(my_form, REQ_NEXT_PAGE);
			set_form_page(my_form, ++cur_page);
			__renderers_services_config_paging();
			break;

		case KEY_PPAGE:
			form_driver(my_form, REQ_PREV_PAGE);
			set_form_page(my_form, --cur_page);
			__renderers_services_config_paging();
			break;

		case KEY_ENTER:
		case 10:
			field = current_field(my_form);
			__ncurses_print_info_in_footer(false,
					field_buffer(field, 0));
			break;
	}
}
Exemple #22
0
void getbuf()
{ 
	ptr=field_buffer(f1[0],0);
}
Exemple #23
0
/*---------------------------------------------------------------------------
|   Facility      :  libnform
|   Function      :  static bool Check_This_Field(FIELD * field,
|                                                 const void * argp)
|
|   Description   :  Validate buffer content to be a valid numeric value
|
|   Return Values :  TRUE  - field is valid
|                    FALSE - field is invalid
+--------------------------------------------------------------------------*/
static bool
Check_This_Field(FIELD *field, const void *argp)
{
  const thisARG *argn = (const thisARG *)argp;
  double low = argn->low;
  double high = argn->high;
  int prec = argn->precision;
  unsigned char *bp = (unsigned char *)field_buffer(field, 0);
  char *s = (char *)bp;
  double val = 0.0;
  struct lconv *L = argn->L;
  char buf[64];
  bool result = FALSE;

  while (*bp && *bp == ' ')
    bp++;
  if (*bp)
    {
      if (*bp == '-' || *bp == '+')
	bp++;
#if USE_WIDEC_SUPPORT
      if (*bp)
	{
	  bool blank = FALSE;
	  int state = 0;
	  int len;
	  int n;
	  wchar_t *list = _nc_Widen_String((char *)bp, &len);

	  if (list != 0)
	    {
	      result = TRUE;
	      for (n = 0; n < len; ++n)
		{
		  if (blank)
		    {
		      if (list[n] != ' ')
			{
			  result = FALSE;
			  break;
			}
		    }
		  else if (list[n] == ' ')
		    {
		      blank = TRUE;
		    }
		  else if (isDecimalPoint(list[n]))
		    {
		      if (++state > 1)
			{
			  result = FALSE;
			  break;
			}
		    }
		  else if (!isDigit(list[n]))
		    {
		      result = FALSE;
		      break;
		    }
		}
	      free(list);
	    }
	}
#else
      while (*bp)
	{
	  if (!isdigit(UChar(*bp)))
	    break;
	  bp++;
	}
      if (isDecimalPoint(*bp))
	{
	  bp++;
	  while (*bp)
	    {
	      if (!isdigit(UChar(*bp)))
		break;
	      bp++;
	    }
	}
      while (*bp && *bp == ' ')
	bp++;
      result = (*bp == '\0');
#endif
      if (result)
	{
	  val = atof(s);
	  if (low < high)
	    {
	      if (val < low || val > high)
		result = FALSE;
	    }
	  if (result)
	    {
	      sprintf(buf, "%.*f", (prec > 0 ? prec : 0), val);
	      set_field_buffer(field, 0, buf);
	    }
	}
    }
  return (result);
}
Exemple #24
0
int kullanici_onayla()
{
	FIELD *field[3];
	FORM  *my_form;
	int ch;

	touchwin(ana_win);
	wrefresh(ana_win);
			
	init_pair(1, COLOR_WHITE, COLOR_BLUE);
	init_pair(2, COLOR_WHITE, COLOR_BLUE);
		
/*calisma yili 4 karakter*/
	field[0] = new_field(1, 10, 18, 42, 0, 0);
/*firma 2 karakter*/
	field[1] = new_field(1, 10, 20, 42, 0, 0);
	field[2] = NULL;

	set_field_fore(field[0], COLOR_PAIR(1));
	set_field_fore(field[1], COLOR_PAIR(1));
/*geri plan rengi olsun*/
	set_field_back(field[0], COLOR_PAIR(2));
	set_field_back(field[1], COLOR_PAIR(2));
/*
	set_field_type(field[0], TYPE_INTEGER);
	set_field_type(field[1], TYPE_INTEGER);
*/
	field_opts_off(field[0], O_AUTOSKIP); 
	field_opts_off(field[1], O_AUTOSKIP); 

/*sifre alani olan ikinci field password biçiminde olmali/
	field_opts_off(field[1], O_PUBLIC);

	/*geri plan rengi olmasin*/
/*	set_field_back(field[0], A_UNDERLINE); 
	set_field_back(field[1], A_UNDERLINE); 
*/
	my_form = new_form(field);
	post_form(my_form);
	refresh();
	
	set_current_field(my_form, field[0]); 

	mvprintw(18, 25, _("User name :") );
	mvprintw(20, 25, _("Password  :"******"This application under GPL license.") );
attroff(A_BLINK);
attroff(A_BOLD);

attron(A_BOLD);
mvprintw(LINES-3, 5, _("F2-> Begin                                               ESC-> Cancel") );
mvprintw(18, 5, _("F5-> Settings") );
attroff(A_BOLD);

mvprintw(7,3, _("                               Acik                          "));
mvprintw(8,3,"  _|              _|                _|                                  ");
mvprintw(9,3,"         _|_|_|   _|     _|_|     _|_|_|_|   _|_|_|  _|_|       _|_|    ");
mvprintw(10,3,"  _|   _|_|       _|   _|_|_|_|     _|       _|    _|    _|   _|_|_|_|  ");
mvprintw(11,3,"  _|       _|_|   _|   _|           _|       _|    _|    _|   _|        ");
mvprintw(12,3,"  _|   _|_|_|     _|     _|_|_|       _|_|   _|    _|    _|     _|_|_|  ");
refresh();
    while((ch = getch()) )
	{	switch(ch)
		{	
		case 8: /*KEY_BACKSPACE hatali kod vermekte 8 dogru olandir konsolda 8 xterm key_backspace*/
    		form_driver(my_form, REQ_PREV_CHAR);
			form_driver(my_form, REQ_DEL_CHAR);
			break;
		case KEY_BACKSPACE: 
    		form_driver(my_form, REQ_PREV_CHAR);
			form_driver(my_form, REQ_DEL_CHAR);
			break;		
		case 9: /*TAB tusuna basýlmasý durumunda sonraki field konumlan*/
			form_driver(my_form, REQ_NEXT_FIELD);
			form_driver(my_form, REQ_END_LINE);
			break;		
		case 10: /*ENTER tuþuna basýlmasý durumunda sonraki feild gececek*/
			form_driver(my_form, REQ_NEXT_FIELD);
			form_driver(my_form, REQ_END_LINE);
			break;		
		case KEY_DC:	/*del tusu*/		
    		form_driver(my_form,REQ_DEL_CHAR);
			break;			
		case KEY_HOME:
			form_driver(my_form,REQ_BEG_LINE);
			break;						
		case KEY_END:
			form_driver(my_form,REQ_END_LINE);
			break;
		case KEY_DOWN:
			form_driver(my_form, REQ_NEXT_FIELD);
			form_driver(my_form, REQ_END_LINE);
			break;
		case KEY_UP:
			form_driver(my_form, REQ_PREV_FIELD);
			form_driver(my_form, REQ_END_LINE);
			break;
		case KEY_LEFT:
    			form_driver(my_form,REQ_LEFT_CHAR);
			break;
		case KEY_RIGHT:
    			form_driver(my_form,REQ_RIGHT_CHAR);
			break;
		case 27: /*esc durumunda*/
				unpost_form(my_form);
				free_form(my_form);
				free_field(field[0]);
				free_field(field[1]); 
				endwin();
				exit(0);	
				break;
		
		case KEY_F(5): 	/*ayarlara gecis*/
				ayarlar();
				
				unpost_form(my_form);
				free_form(my_form);
				free_field(field[0]);
				free_field(field[1]);
				
				endwin();
		
				exit (0);
				break;
				case KEY_F(2): 	/*f2 durumunda*/
				form_driver(my_form, REQ_PREV_FIELD);
				strcpy(query, "select kullanici, sifre, haklar from kullanicilar");
		
				if ( pgsql_sorgula(query) ==1 ) { mesaj(sql_sorgulama_hatasi); return 1;}
	
				for (i=0;i<pgsql_row_miktar;i++)
					{						
					sprintf(kullanici,"%s", pgsql_kayit_field() );
					sprintf(sifre,"%s", pgsql_kayit_field() );
					sprintf(haklar,"%s", pgsql_kayit_field() );

					if ( strcmp(g_strstrip(field_buffer(field[0],0)), kullanici) ==NULL )
						{
						if  ( (sifre_kripto_coz( g_strstrip(field_buffer(field[1],0)) , sifre) == 0) || (strcmp(g_strstrip(field_buffer(field[1],0)), sifre) == NULL ) )
							{
							//kullanýcý root ise haklar full olmalý 
							//databaseden degistirme ihtimali olabilir								
							if ( strstr( kullanici, "root") ) 
							{sprintf(haklar,"%s", "1111111111111111111111111111111111111111111111111111111111111111");}
												
							beep();
						
							unpost_form(my_form);
							free_form(my_form);
							free_field(field[0]);
							free_field(field[1]);
							touchwin(ana_win);
							wrefresh(ana_win);							
															
							return;
								
							}
							else
							{							
							set_field_buffer(field[0],0," ");
							set_field_buffer(field[1],0," ");
							refresh();	
							//beep sesi							
							beep();
							
							}
						}
					}
			
													
				break;
			
			default:
				form_driver(my_form, ch);
				break;

		}
	}

return 0;
/*son*/
}
Exemple #25
0
/*---------------------------------------------------------------------------
|   Facility      :  libnform  
|   Function      :  static bool Check_This_Field(
|                                                 FIELD * field,
|                                                 const void * argp)
|   
|   Description   :  Validate buffer content to be a valid integer value
|
|   Return Values :  TRUE  - field is valid
|                    FALSE - field is invalid
+--------------------------------------------------------------------------*/
static bool
Check_This_Field(FIELD *field, const void *argp)
{
  const thisARG *argi = (const thisARG *)argp;
  long low = argi->low;
  long high = argi->high;
  int prec = argi->precision;
  unsigned char *bp = (unsigned char *)field_buffer(field, 0);
  char *s = (char *)bp;
  long val;
  char buf[100];
  bool result = FALSE;

  while (*bp && *bp == ' ')
    bp++;
  if (*bp)
    {
      if (*bp == '-')
	bp++;
#if USE_WIDEC_SUPPORT
      if (*bp)
	{
	  bool blank = FALSE;
	  int len;
	  int n;
	  wchar_t *list = _nc_Widen_String((char *)bp, &len);

	  if (list != 0)
	    {
	      result = TRUE;
	      for (n = 0; n < len; ++n)
		{
		  if (blank)
		    {
		      if (list[n] != ' ')
			{
			  result = FALSE;
			  break;
			}
		    }
		  else if (list[n] == ' ')
		    {
		      blank = TRUE;
		    }
		  else if (!isDigit(list[n]))
		    {
		      result = FALSE;
		      break;
		    }
		}
	      free(list);
	    }
	}
#else
      while (*bp)
	{
	  if (!isdigit(UChar(*bp)))
	    break;
	  bp++;
	}
      while (*bp && *bp == ' ')
	bp++;
      result = (*bp == '\0');
#endif
      if (result)
	{
	  val = atol(s);
	  if (low < high)
	    {
	      if (val < low || val > high)
		result = FALSE;
	    }
	  if (result)
	    {
	      snprintf(buf, sizeof(buf), "%.*ld", (prec > 0 ? prec : 0), val);
	      set_field_buffer(field, 0, buf);
	    }
	}
    }
  return (result);
}
Exemple #26
0
char *input_box(size_t length, const char *title, const char *description)
{
    WINDOW *ib_win = NULL;
    PANEL *my_panels[1];
    FIELD **fields;
    FORM *my_form = NULL;
    int height, width, startx, starty, max_height, max_width, ch = 0, rows,
                                                              cols, quit = 0, i;
    char *result_ptr = NULL, *temp_ptr = NULL;

    /* create a buffer with the size of 'length' */
    if (!(temp_ptr = malloc(length))) {
        vrmr_error(-1, VR_ERR, gettext("malloc failed: %s"), strerror(errno));
        return (NULL);
    }

    // set the window size
    getmaxyx(stdscr, max_height, max_width);
    height = 8;
    if (length < 16) {
        width = 37; // minimum TODO: why 37?
    } else if ((int)length + 8 > max_width) {
        free(temp_ptr);
        return NULL;
    } else {
        width = (int)length + 8;
        if ((int)StrLen(title) + 8 > width)
            width = (int)StrLen(title) + 8;
        if ((int)StrLen(description) + 8 > width)
            width = (int)StrLen(description) + 8;
    }
    // print on the centre of the screen
    starty = (max_height - height) / 2;
    startx = (max_width - width) / 2;

    // create window
    ib_win = create_newwin(
            height, width, starty, startx, title, vccnf.color_win);
    my_panels[0] = new_panel(ib_win);
    fields = (FIELD **)calloc(1 + 1, sizeof(FIELD *));
    fields[0] = new_field_wrap(
            1, (int)length - 1, 3, (int)(((width - length) / 2) - 2), 0, 0);
    set_field_back(fields[0], vccnf.color_win_rev);
    field_opts_off(fields[0], O_AUTOSKIP);
    set_field_status(fields[0], FALSE);
    my_form = new_form(fields);
    scale_form(my_form, &rows, &cols);
    keypad(ib_win, TRUE);
    set_form_win(my_form, ib_win);
    set_form_sub(my_form, derwin(ib_win, rows, cols, 1, 2));
    post_form(my_form);

    mvwprintw(ib_win, 2, 4, "%s", description);
    mvwprintw(ib_win, 6, 4, gettext("Note: whitespaces not allowed."));

    update_panels();
    doupdate();

    while (quit == 0) {
        ch = wgetch(ib_win);
        switch (ch) {
            case 27:
            case KEY_F(10):
            case 10: // enter
                // Go to next field
                form_driver_wrap(my_form, REQ_NEXT_FIELD);
                form_driver_wrap(my_form, REQ_END_LINE);
                quit = 1;
                break;
            case KEY_BACKSPACE:
            case 127:
                form_driver_wrap(my_form, REQ_PREV_CHAR);
                form_driver_wrap(my_form, REQ_DEL_CHAR);
                form_driver_wrap(my_form, REQ_END_LINE);
                break;
            case KEY_DC:
                form_driver_wrap(my_form, REQ_PREV_CHAR);
                form_driver_wrap(my_form, REQ_DEL_CHAR);
                form_driver_wrap(my_form, REQ_END_LINE);
                break;
            default:
                // If this is a normal character, it gets printed
                form_driver_wrap(my_form, ch);
                break;
        }
    }

    // status_print(status_win, "data: '%s' (%d)", field_buffer(fields[0], 0),
    // length);
    (void)strlcpy(temp_ptr, field_buffer(fields[0], 0), length);

    // get the length of the entry
    i = strlen(temp_ptr);
    while (i--) {
        if (isspace(temp_ptr[i]))
            temp_ptr[i] = '\0';
        else
            break;
    }

    if (!(result_ptr = strdup(temp_ptr))) {
        vrmr_error(-1, VR_ERR, gettext("malloc failed: %s"), strerror(errno));
        goto end;
    }

    if (result_ptr[0] == '\0') {
        free(result_ptr);
        result_ptr = NULL;
    }

end:
    free(temp_ptr);
    unpost_form(my_form);
    free_form(my_form);
    free_field(fields[0]);
    free(fields);
    del_panel(my_panels[0]);
    destroy_win(ib_win);
    update_panels();
    doupdate();
    return (result_ptr);
}
int
edit_field(FORM * form, int *result)
{
    int ch = wgetch(form_win(form));
    int status;
    FIELD *before;
    unsigned n;
    char lengths[80];
    int length;
    char *buffer;
    int before_row;
    int before_col;
    int before_off = offset_in_field(form);

    form_getyx(form, before_row, before_col);
    before = current_field(form);
    set_field_back(before, A_NORMAL);
    if (ch <= KEY_MAX) {
	set_field_back(before, A_REVERSE);
    } else if (ch <= MAX_FORM_COMMAND) {
	inactive_field(before);
    }

    *result = ch;
    for (n = 0; n < SIZEOF(commands); ++n) {
	if (commands[n].code == ch) {
	    *result = commands[n].result;
	    break;
	}
    }

    status = form_driver(form, *result);

    if (status == E_OK) {
	bool modified = TRUE;

	length = 0;
	if ((buffer = field_buffer(before, 1)) != 0)
	    length = atoi(buffer);
	if (length < before_off)
	    length = before_off;
	switch (*result) {
	case REQ_CLR_EOF:
	    length = before_off;
	    break;
	case REQ_CLR_EOL:
	    if (before_row + 1 == before->rows)
		length = before_off;
	    break;
	case REQ_CLR_FIELD:
	    length = 0;
	    break;
	case REQ_DEL_CHAR:
	    if (length > before_off)
		--length;
	    break;
	case REQ_DEL_PREV:
	    if (length > 0) {
		if (before_col > 0) {
		    --length;
		} else if (before_row > 0) {
		    length -= before->cols + before_col;
		}
	    }
	    break;
	case REQ_NEW_LINE:
	    length += before->cols;
	    break;
#if 0
	    /* FIXME: finish these */
	case REQ_DEL_LINE:	/* delete line */
	case REQ_DEL_WORD:	/* delete word at cursor */
	case REQ_INS_CHAR:	/* insert blank char at cursor */
	case REQ_INS_LINE:	/* insert blank line at cursor */
	case REQ_INS_MODE:	/* begin insert mode */
	case REQ_OVL_MODE:	/* begin overlay mode */
#endif
	    /* ignore all of the motion commands */
	case REQ_SCR_BCHAR:	/* FALLTHRU */
	case REQ_SCR_BHPAGE:	/* FALLTHRU */
	case REQ_SCR_BLINE:	/* FALLTHRU */
	case REQ_SCR_BPAGE:	/* FALLTHRU */
	case REQ_SCR_FCHAR:	/* FALLTHRU */
	case REQ_SCR_FHPAGE:	/* FALLTHRU */
	case REQ_SCR_FLINE:	/* FALLTHRU */
	case REQ_SCR_FPAGE:	/* FALLTHRU */
	case REQ_SCR_HBHALF:	/* FALLTHRU */
	case REQ_SCR_HBLINE:	/* FALLTHRU */
	case REQ_SCR_HFHALF:	/* FALLTHRU */
	case REQ_SCR_HFLINE:	/* FALLTHRU */
	case REQ_BEG_FIELD:	/* FALLTHRU */
	case REQ_BEG_LINE:	/* FALLTHRU */
	case REQ_DOWN_CHAR:	/* FALLTHRU */
	case REQ_DOWN_FIELD:	/* FALLTHRU */
	case REQ_END_FIELD:	/* FALLTHRU */
	case REQ_END_LINE:	/* FALLTHRU */
	case REQ_FIRST_FIELD:	/* FALLTHRU */
	case REQ_FIRST_PAGE:	/* FALLTHRU */
	case REQ_LAST_FIELD:	/* FALLTHRU */
	case REQ_LAST_PAGE:	/* FALLTHRU */
	case REQ_LEFT_CHAR:	/* FALLTHRU */
	case REQ_LEFT_FIELD:	/* FALLTHRU */
	case REQ_NEXT_CHAR:	/* FALLTHRU */
	case REQ_NEXT_CHOICE:	/* FALLTHRU */
	case REQ_NEXT_FIELD:	/* FALLTHRU */
	case REQ_NEXT_LINE:	/* FALLTHRU */
	case REQ_NEXT_PAGE:	/* FALLTHRU */
	case REQ_NEXT_WORD:	/* FALLTHRU */
	case REQ_PREV_CHAR:	/* FALLTHRU */
	case REQ_PREV_CHOICE:	/* FALLTHRU */
	case REQ_PREV_FIELD:	/* FALLTHRU */
	case REQ_PREV_LINE:	/* FALLTHRU */
	case REQ_PREV_PAGE:	/* FALLTHRU */
	case REQ_PREV_WORD:	/* FALLTHRU */
	case REQ_RIGHT_CHAR:	/* FALLTHRU */
	case REQ_RIGHT_FIELD:	/* FALLTHRU */
	case REQ_SFIRST_FIELD:	/* FALLTHRU */
	case REQ_SLAST_FIELD:	/* FALLTHRU */
	case REQ_SNEXT_FIELD:	/* FALLTHRU */
	case REQ_SPREV_FIELD:	/* FALLTHRU */
	case REQ_UP_CHAR:	/* FALLTHRU */
	case REQ_UP_FIELD:	/* FALLTHRU */
	case REQ_VALIDATION:	/* FALLTHRU */
	    modified = FALSE;
	    break;

	default:
	    modified = FALSE;
	    if (ch >= MIN_FORM_COMMAND) {
		beep();
	    } else if (isprint(ch)) {
		modified = TRUE;
	    }
	    break;
	}

	/*
	 * If we do not force a re-validation, then field_buffer 0 will
	 * be lagging by one character.
	 */
	if (modified && form_driver(form, REQ_VALIDATION) == E_OK && *result
	    < MIN_FORM_COMMAND)
	    ++length;

	sprintf(lengths, "%d", length);
	set_field_buffer(before, 1, lengths);
    }

    if (current_field(form) != before)
	inactive_field(before);
    return status;
}
Exemple #28
0
void viewNewPlayer(FootBallGame::TeamNumber teamNumber) {
  const char *itemName;
  const ITEM *currentItem;

  const int window_nlines = 10,
            window_ncols  = 90;

  char *choices[] = {
    "Add",
    "Cancel",
  };


  for (;;) {
    // Create new window.
    WINDOW *window = newwin(window_nlines, 
        window_ncols, 
        headerWindow_begin_y + headerWindow_nlines + 1,
        0);
    // Set new window options.
    keypad(window, TRUE);


    // Create the form fields
    FIELD *field[6];
    for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++)
      field[i] = new_field(1, 26, i+2, 23, 0, 0);
    field[ARRAY_SIZE(field)-1] = NULL;
    // Set feild options 
    for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) {
      set_field_back(field[i], A_UNDERLINE);
      field_opts_off(field[i], O_AUTOSKIP);
    }
    // Set the field types
    set_field_type(field[0], TYPE_REGEXP, "^[A-Za-z ]*$");
    set_field_type(field[1], TYPE_INTEGER, 0, 1, 999);
    set_field_type(field[2], TYPE_REGEXP, "^[A-Za-z ]*$");
    set_field_type(field[3], TYPE_NUMERIC, 2, 1.00, 1500.00);
    set_field_type(field[4], TYPE_NUMERIC, 2, 1.00, 300.00);
    // Create the form
    FORM *form = new_form(field);
    set_form_win(form, window);
    set_form_sub(form, derwin(window, 10, 90, 0, 0));

    // Setup the menu items
    int nChoices = ARRAY_SIZE(choices)+1;
    ITEM **items = new ITEM* [nChoices];
    for (int i = 0; i < nChoices-1; i++)
      items[i] = new_item(choices[i], NULL);
    items[nChoices-1] = NULL;
    // Create the menu
    MENU *menu = new_menu(items);
    // Menu options
    set_menu_format(menu, 1, 2);
    set_menu_mark(menu, NULL);
    // Attach the menu to the window
    set_menu_win(menu, window);
    set_menu_sub(menu, derwin(window, 1, 20, 8, 17));

    // Make window and menu visible;
    post_form(form);
    post_menu(menu);
    mvwprintw(window, 0, 10, "Player Properties: ");
    mvwprintw(window, 2, 10, "Name: ");
    mvwprintw(window, 3, 10, "Number: ");
    mvwprintw(window, 4, 10, "Position: ");
    mvwprintw(window, 5, 10, "weight (kg): ");
    mvwprintw(window, 6, 10, "height (cm): ");
    wrefresh(window);
    refresh();

    // Start user interaction loop.
    int c;
    // The restart variable is used to tell the function to rebuild the
    // menu by starting at the top of the for(;;) loop above.
    bool restart = false;
    while (!restart && (c = wgetch(window))) {
      mvprintw(LINES-1, 0, "                                         ");
      refresh();
      switch(c) {
        case KEY_DOWN:
        case 0x09:
          // Go to next field
          form_driver(form, REQ_NEXT_FIELD);
          // GO to the end of the presend buffer
          // Leaves nicely at the last character
          form_driver(form, REQ_END_LINE);
          break;
        case KEY_UP:
          // Go to previous field
          form_driver(form, REQ_PREV_FIELD);
          form_driver(form, REQ_END_LINE);
          break;
        case 0x7F:
          form_driver(form, REQ_DEL_PREV);
          break;
        case KEY_LEFT:
          menu_driver(menu, REQ_LEFT_ITEM);
          break;
        case KEY_RIGHT:
          menu_driver(menu, REQ_RIGHT_ITEM);
          break;
        case 10:
          // When the user hits enter determine the currently selected
          // item and do nessary actions. 
          currentItem = current_item(menu);
          itemName = item_name(currentItem);
          // Cancel
          if (strncmp(itemName, choices[1], strlen(choices[1])) == 0) {
            // Delete allocated data
            unpost_form(form); 
            unpost_menu(menu); 
            free_form(form); 
            free_menu(menu); 
            for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) 
              free_field(field[i]); 
            for (int i = 0; i < nChoices; i++)
              free_item(items[i]);
            delete [] items; 
            delwin(window);
            return;
          } else if (strncmp(itemName, choices[0], strlen(choices[0])) == 0) {
            form_driver(form, REQ_VALIDATION);
            bool invalid = false;
            for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++)
              if (field_status(field[i])==false)
                invalid = true;;
            if (invalid == false) {
              FootBallPlayer *player = new FootBallPlayer;
              player->setName(field_buffer(field[0], 0));
              player->setNumber(atoi(field_buffer(field[1], 0)));
              player->setPosition(field_buffer(field[2], 0));
              player->setWeight(strtof(field_buffer(field[3], 0), NULL));
              player->setHeight(strtof(field_buffer(field[4], 0), NULL));
              FootBallTeam *team = game.getFootBallTeam(teamNumber);
              if (team == NULL) {
                team = new FootBallTeam;
                game.setFootBallTeam(teamNumber, team);
              }
              team->addFootBallPlayer(player);
              // Delete allocated data
              unpost_form(form); 
              unpost_menu(menu); 
              free_form(form); 
              free_menu(menu); 
              for (unsigned i = 0; i < ARRAY_SIZE(field)-1; i++) 
                free_field(field[i]); 
              for (int i = 0; i < nChoices; i++)
                free_item(items[i]);
              delete [] items; 
              delwin(window);
              return;
            } else {
              mvprintw(LINES-1, 0, "Fill out the form correctly!!");
              refresh();
            }
          }
          break;
        default:
          // If this is a normal character, it gets
          // printed
          form_driver(form, c);
          break;
      }
    }
  }
}
Exemple #29
0
void viewEditTeamProperties(FootBallGame::TeamNumber teamNumber) {
  const char *fieldBuffer;
  const ITEM *currentItem;
  const char *itemName;
  ITEM **items;

  const int window_nlines = 10,
            window_ncols  = 90;
  
  char *choices[] = {
    "Ok",
    "Cancel",
  };

  for(;;) {
    // Create new window.
    WINDOW *window = newwin(window_nlines, 
                            window_ncols, 
                            headerWindow_begin_y + headerWindow_nlines + 1,
                            0);
    // Set new window options.
    keypad(window, TRUE);
  
    // Team the team
    FootBallTeam *team = game.getFootBallTeam(teamNumber);

    // Create the form fields
    FIELD *field[2];
    field[0] = new_field(1, 20, 2, 22, 0, 0);
    field[1] = NULL;
  
    // Set feild options 
    set_field_back(field[0], A_UNDERLINE);
    field_opts_off(field[0], O_AUTOSKIP);
    set_field_type(field[0], TYPE_REGEXP, "^[A-Za-z ]*$");
    if (team) {
      String teamName = team->getTeamName();
      set_field_buffer(field[0], 0, teamName.c_str());
    }
    
    // Create the form
    FORM *form = new_form(field);

    // Attach the form to the window
    set_form_win(form, window);
    set_form_sub(form, derwin(window, 4, 90, 0, 0));

    // Setup the menu
    int nChoices = ARRAY_SIZE(choices)+1;
    items = new ITEM* [nChoices];
    for (int i = 0; i < nChoices-1; i++)
      items[i] = new_item(choices[i], NULL);
    items[nChoices-1] = NULL;
  
    // Create the menu
    MENU *menu = new_menu(items);
    // Menu options
    set_menu_format(menu, 1, 2);
    set_menu_mark(menu, NULL);
    // Attach the menu to the window
    set_menu_win(menu, window);
    set_menu_sub(menu, derwin(window, 1, 20, 4, 17));

    // Make window and menu visible;
    post_form(form);
    post_menu(menu);
    mvwprintw(window, 0, 10, "Team Properties: ");
    mvwprintw(window, 2, 10, "Team Name: ");
    wrefresh(window);
    refresh();
    
    // Start user interaction loop.
    int c;
    // The restart variable is used to tell the function to rebuild the
    // menu by starting at the top of the for(;;) loop above.
    bool restart = false;
    while (!restart && (c = wgetch(window))) {
      switch(c) {
        case KEY_DOWN:
        case 0x09:
          // Go to next field
          form_driver(form, REQ_NEXT_FIELD);
          // GO to the end of the presend buffer
          // Leaves nicely at the last character
          form_driver(form, REQ_END_LINE);
          break;
        case KEY_UP:
          // Go to previous field
          form_driver(form, REQ_PREV_FIELD);
          form_driver(form, REQ_END_LINE);
          break;
        case 0x7F:
          form_driver(form, REQ_DEL_PREV);
          break;
        case KEY_LEFT:
          menu_driver(menu, REQ_LEFT_ITEM);
          break;
        case KEY_RIGHT:
          menu_driver(menu, REQ_RIGHT_ITEM);
          break;
        case 10: // Enter
          // When the user hits enter determine the currently selected
          // item and do nessary actions. 
          currentItem = current_item(menu);
          itemName = item_name(currentItem);
          if (strcmp(itemName, choices[0]) == 0) {
            form_driver(form, REQ_VALIDATION);
            fieldBuffer = field_buffer(field[0], 0);
            if (fieldBuffer != NULL && strcmp(fieldBuffer, "") != 0) {
              if (team == NULL) {
                team = new FootBallTeam;
                game.setFootBallTeam(teamNumber, team);
              }
              team->setTeamName(fieldBuffer);
            }
          }
          // Delete allocated data
          delwin(window);
          unpost_form(form); 
          free_form(form); 
          unpost_menu(menu); 
          free_menu(menu); 
          for (unsigned i = 0; i < ARRAY_SIZE(field); i++) 
            free_field(field[i]); 
          for (int i = 0; i < nChoices-1; i++) 
            free_item(items[i]); 
          delete[] items;
          return;
        default:
          // If this is a normal character, it gets printed.
          form_driver(form, c);
          break;
      }
    }
  }
}
Exemple #30
0
void actions_dataentry_scr(const char *curr_path, const char *case_num) {
  const size_t n_fields = 4;
  const size_t starty = 6;
  const size_t startx = 25;
  FIELD *field[n_fields];
  FORM *my_form;
  Action_t record;
  int width[] = {  MAX_ACT_DATE - 1, MAX_ACT_TYPE, MAX_ACT_NOTE - 200 };
  int height[] = { 1, 1, 4 };
 
  for ( size_t i = 0; i < n_fields - 1; ++i )
    field[i] = new_field(height[i], width[i], starty + i * 2, startx, 0, 0);
  field[n_fields - 1] = NULL;

  set_field_back( field[0], A_UNDERLINE  );
  field_opts_off( field[0], O_AUTOSKIP   );
  set_field_back( field[1], A_UNDERLINE  );
  field_opts_off( field[1], O_AUTOSKIP   );
  set_field_back( field[2], A_UNDERLINE  );
  field_opts_off( field[2], O_AUTOSKIP   );
  field_opts_off( field[2], O_STATIC     );
  set_max_field(  field[2], MAX_ACT_NOTE );

  my_form = new_form(field);
  post_form(my_form);
  refresh();

  int note_count = MAX_ACT_NOTE;
  char note_msg[4];
  char date_str[MAX_ACT_DATE];
  get_curr_date( date_str );
  mvprintw( 0, 0,   curr_path );
  mvprintw( 4, 10,  "Case Number:   %s", case_num );
  mvprintw( 6, 10,  "Entry Date:    " );
  mvprintw( 8, 10,  "Type:          " );
  mvprintw( 10, 10, "Note:          " );
  mvprintw( 15, 77, "%d", note_count );
  mvprintw( 16, 10, "(F2) = Add | (ESC) = Previous Screen" );
  set_visible_fields( field, 1, 3 );
  size_t actions_count = actions_list( case_num );
  move( 6, 25 );
  set_field_buffer( field[0], 0, date_str );
  set_current_field( my_form, field[0] );

  record.id = 0;
  int ch;

  do {
 
    ch = getch();

    switch ( ch ) {
      case KEY_UP:
        form_driver(my_form, REQ_PREV_FIELD);
        form_driver(my_form, REQ_END_LINE);
        break;
      case KEY_LEFT:
        form_driver(my_form, REQ_LEFT_CHAR);
        break;
      case KEY_RIGHT:
        form_driver(my_form, REQ_RIGHT_CHAR);
        break;
      case KEY_BACKSPACE:
        {
          FIELD * curr_fld = current_field( my_form );

          if ( curr_fld == field[2] ) {
            snprintf( note_msg, 4, "%d", ++note_count );
            display_msg( 15, 77, my_form, curr_fld, note_msg );
          }
        }
        form_driver(my_form, REQ_PREV_CHAR);
        form_driver(my_form, REQ_DEL_CHAR);
        break;
     case DEL:
        {
          FIELD * curr_fld = current_field( my_form );

          if ( curr_fld == field[2] ) {
            snprintf( note_msg, 4, "%d", ++note_count );
            display_msg( 15, 77, my_form, curr_fld, note_msg );
          }
        }
        form_driver( my_form, REQ_DEL_CHAR );
        break;
      case ENTER:
        form_driver( my_form, REQ_NEXT_FIELD );
        form_driver( my_form, REQ_END_LINE );
        break;
      case KEY_F(1):
        {
          FIELD * curr_fld = current_field( my_form );

          if ( curr_fld == field[1] ) {
            if ( query_select_all_codes_from_action_types()  ) {
              clear_line(18, 10);
              mvprintw( 18, 10, db_get_error_msg() );
            } else {
              const Code_t const * code_ptr;
              size_t count = 0;
              
              mvprintw( 8, 75, "Type Options:" );
              while ( ( code_ptr = get_code_from_result() ) != NULL )      
                mvprintw( 9 + count++, 81, "[%d] %s", code_ptr->code, code_ptr->desc );
              free_code_result();

              int row, col;
              get_cursor_pos( curr_fld, &row, &col );
              move( row, col );
              set_current_field( my_form, curr_fld );
            }
          }
        }
        break;
      case KEY_F(2):
        {
          clear_line( 18, 10 );
          strncpy( record.case_num, case_num, MAX_CANUM );
          strncpy( record.entry_date, compress_str( field_buffer(field[0], 0) ), MAX_ACT_DATE );
          record.type = atoi( compress_str( field_buffer(field[1], 0) ) );
          strncpy( record.note, field_buffer(field[2], 0), MAX_ACT_NOTE );
          
          if ( is_empty_str( record.note, MAX_ACT_NOTE ) ) {
            mvprintw( 18, 10, "[!] Action must at least have a note." ); 
            move( 10, 25 );
            set_current_field( my_form, field[2] );
            break;
          }

          if ( query_add_action( &record ) ) {
            mvprintw( 18, 10, db_get_error_msg() );
          } else {
            clear_fields( field, 0, 2 );
            actions_count++;
            print_action( &record, actions_count );
            note_count = MAX_ACT_NOTE;
            mvprintw( 15, 77, "%d", note_count );
          }
          move( 6, 25 );
          set_current_field( my_form, field[0] );
        }
        break;
      default:
        {
          FIELD * curr_fld = current_field( my_form );

          if ( ch == '\'' )
            break;
          if ( curr_fld == field[1] ) {
            if ( !isdigit( ch ) )
              break;
          } else if ( curr_fld == field[2] ) {
            snprintf( note_msg, 4, "%d", --note_count );
            display_msg( 15, 77, my_form, curr_fld, note_msg );
          }
        }
        form_driver( my_form, ch );
        break;
    }
  } while ( ch != ESC );

  unpost_form( my_form );
  free_form( my_form );
  for ( size_t i = 0; i < n_fields - 1; ++i )
    free_field( field[i] );
  return;
}