X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=form%2Ffrm_driver.c;h=549ce8058efa5d25c33876b885fa17f51ade4dec;hp=5a8f6b08cc9df1dbd9601f38bd449a5ab328f21a;hb=ba39fbc2e0cee4681395df4079d9e61c27262132;hpb=3996fe0bf797f113d6abc4329cc869951735a4d8 diff --git a/form/frm_driver.c b/form/frm_driver.c index 5a8f6b08..549ce805 100644 --- a/form/frm_driver.c +++ b/form/frm_driver.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc. * + * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -32,7 +32,7 @@ #include "form.priv.h" -MODULE_ID("$Id: frm_driver.c,v 1.96 2009/12/12 23:19:29 tom Exp $") +MODULE_ID("$Id: frm_driver.c,v 1.100 2012/03/11 00:37:16 tom Exp $") /*---------------------------------------------------------------------------- This is the core module of the form library. It contains the majority @@ -172,7 +172,7 @@ static int FE_Delete_Previous(FORM *); instead of a derived window because it contains invisible parts. This is true for non-public fields and for scrollable fields. */ #define Has_Invisible_Parts(field) \ - (!((field)->opts & O_PUBLIC) || \ + (!((unsigned)(field)->opts & O_PUBLIC) || \ Is_Scroll_Field(field)) /* Logic to decide whether or not a field needs justification */ @@ -180,7 +180,7 @@ static int FE_Delete_Previous(FORM *); (((field)->just != NO_JUSTIFICATION) && \ (Single_Line_Field(field)) && \ (((field)->dcols == (field)->cols) && \ - ((field)->opts & O_STATIC)) ) + ((unsigned)(field)->opts & O_STATIC))) /* Logic to determine whether or not a dynamic field may still grow */ #define Growable(field) ((field)->status & _MAY_GROW) @@ -188,13 +188,13 @@ static int FE_Delete_Previous(FORM *); /* Macro to set the attributes for a fields window */ #define Set_Field_Window_Attributes(field,win) \ ( wbkgdset((win),(chtype)((field)->pad | (field)->back)), \ - (void) wattrset((win),(field)->fore) ) + (void) wattrset((win), (int)(field)->fore) ) /* Logic to decide whether or not a field really appears on the form */ #define Field_Really_Appears(field) \ ((field->form) &&\ (field->form->status & _POSTED) &&\ - (field->opts & O_VISIBLE) &&\ + ((unsigned)field->opts & O_VISIBLE) &&\ (field->page == field->form->curpage)) /* Logic to determine whether or not we are on the first position in the @@ -601,7 +601,7 @@ Synchronize_Buffer(FORM *form) { if (form->status & _WINDOW_MODIFIED) { - form->status &= ~_WINDOW_MODIFIED; + form->status &= (unsigned short) (~_WINDOW_MODIFIED); form->status |= _FCHECK_REQUIRED; Window_To_Buffer(form, form->current); wmove(form->w, form->currow, form->curcol); @@ -653,7 +653,7 @@ Field_Grown(FIELD *field, int amount) growth = Minimum(field->maxgrow - field->dcols, growth); field->dcols += growth; if (field->dcols == field->maxgrow) - field->status &= ~_MAY_GROW; + field->status &= (unsigned short) (~_MAY_GROW); } else { @@ -662,7 +662,7 @@ Field_Grown(FIELD *field, int amount) growth = Minimum(field->maxgrow - field->drows, growth); field->drows += growth; if (field->drows == field->maxgrow) - field->status &= ~_MAY_GROW; + field->status &= (unsigned short) (~_MAY_GROW); } /* drows, dcols changed, so we get really the new buffer length */ new_buflen = Buffer_Length(field); @@ -860,7 +860,7 @@ _nc_Refresh_Current_Field(FORM *form) field = form->current; formwin = Get_Form_Window(form); - if (field->opts & O_PUBLIC) + if ((unsigned)field->opts & O_PUBLIC) { if (Is_Scroll_Field(field)) { @@ -909,7 +909,7 @@ _nc_Refresh_Current_Field(FORM *form) /* means we have to copy whole range */ first_modified_row = form->toprow; first_unmodified_row = first_modified_row + field->rows; - field->status &= ~_NEWTOP; + field->status &= (unsigned short)(~_NEWTOP); } else { @@ -1111,27 +1111,27 @@ Display_Or_Erase_Field(FIELD *field, bool bEraseFlag) return E_SYSTEM_ERROR; else { - if (field->opts & O_VISIBLE) + if ((unsigned)field->opts & O_VISIBLE) { Set_Field_Window_Attributes(field, win); } else { - (void)wattrset(win, WINDOW_ATTRS(fwin)); + (void)wattrset(win, (int)WINDOW_ATTRS(fwin)); } werase(win); } if (!bEraseFlag) { - if (field->opts & O_PUBLIC) + if ((unsigned)field->opts & O_PUBLIC) { if (Justification_Allowed(field)) Perform_Justification(field, win); else Buffer_To_Window(field, win); } - field->status &= ~_NEWTOP; + field->status &= (unsigned short)(~_NEWTOP); } wsyncup(win); delwin(win); @@ -1170,7 +1170,7 @@ Synchronize_Field(FIELD *field) form->currow = form->curcol = form->toprow = form->begincol = 0; werase(form->w); - if ((field->opts & O_PUBLIC) && Justification_Allowed(field)) + if (((unsigned)field->opts & O_PUBLIC) && Justification_Allowed(field)) Undo_Justification(field, form->w); else Buffer_To_Window(field, form->w); @@ -1256,7 +1256,7 @@ _nc_Synchronize_Attributes(FIELD *field) werase(form->w); wmove(form->w, form->currow, form->curcol); - if (field->opts & O_PUBLIC) + if ((unsigned)field->opts & O_PUBLIC) { if (Justification_Allowed(field)) Undo_Justification(field, form->w); @@ -1326,34 +1326,34 @@ _nc_Synchronize_Options(FIELD *field, Field_Options newopts) field->opts = oldopts; returnCode(E_CURRENT); } - if ((form->curpage == field->page)) + if (form->curpage == field->page) { - if (changed_opts & O_VISIBLE) + if ((unsigned) changed_opts & O_VISIBLE) { - if (newopts & O_VISIBLE) + if ((unsigned) newopts & O_VISIBLE) res = Display_Field(field); else res = Erase_Field(field); } else { - if ((changed_opts & O_PUBLIC) && - (newopts & O_VISIBLE)) + if (((unsigned) changed_opts & O_PUBLIC) && + ((unsigned) newopts & O_VISIBLE)) res = Display_Field(field); } } } } - if (changed_opts & O_STATIC) + if ((unsigned) changed_opts & O_STATIC) { bool single_line_field = Single_Line_Field(field); int res2 = E_OK; - if (newopts & O_STATIC) + if ((unsigned) newopts & O_STATIC) { /* the field becomes now static */ - field->status &= ~_MAY_GROW; + field->status &= (unsigned short)(~_MAY_GROW); /* if actually we have no hidden columns, justification may occur again */ if (single_line_field && @@ -1424,16 +1424,16 @@ _nc_Set_Current_Field(FORM *form, FIELD *newfield) !(form->status & _POSTED)) { if ((form->w) && - (field->opts & O_VISIBLE) && + ((unsigned)field->opts & O_VISIBLE) && (field->form->curpage == field->page)) { _nc_Refresh_Current_Field(form); - if (field->opts & O_PUBLIC) + if ((unsigned)field->opts & O_PUBLIC) { if (field->drows > field->rows) { if (form->toprow == 0) - field->status &= ~_NEWTOP; + field->status &= (unsigned short)(~_NEWTOP); else field->status |= _NEWTOP; } @@ -1469,7 +1469,7 @@ _nc_Set_Current_Field(FORM *form, FIELD *newfield) delwin(form->w); form->w = new_window; - form->status &= ~_WINDOW_MODIFIED; + form->status &= (unsigned short)(~_WINDOW_MODIFIED); Set_Field_Window_Attributes(field, form->w); if (Has_Invisible_Parts(field)) @@ -2430,7 +2430,7 @@ Wrapping_Not_Necessary_Or_Wrapping_Ok(FORM *form) int result = E_REQUEST_DENIED; bool Last_Row = ((field->drows - 1) == form->currow); - if ((field->opts & O_WRAP) && /* wrapping wanted */ + if (((unsigned)field->opts & O_WRAP) && /* wrapping wanted */ (!Single_Line_Field(field)) && /* must be multi-line */ (There_Is_No_Room_For_A_Char_In_Line(form)) && /* line is full */ (!Last_Row || Growable(field))) /* there are more lines */ @@ -2513,7 +2513,7 @@ Field_Editing(int (*const fct) (FORM *), FORM *form) editable fields. */ if ((fct == FE_Delete_Previous) && - (form->opts & O_BS_OVERLOAD) && + ((unsigned)form->opts & O_BS_OVERLOAD) && First_Position_In_Current_Field(form)) { res = Inter_Field_Navigation(FN_Previous_Field, form); @@ -2522,7 +2522,7 @@ Field_Editing(int (*const fct) (FORM *), FORM *form) { if (fct == FE_New_Line) { - if ((form->opts & O_NL_OVERLOAD) && + if (((unsigned)form->opts & O_NL_OVERLOAD) && First_Position_In_Current_Field(form)) { res = Inter_Field_Navigation(FN_Next_Field, form); @@ -2534,7 +2534,7 @@ Field_Editing(int (*const fct) (FORM *), FORM *form) else { /* From now on, everything must be editable */ - if (form->current->opts & O_EDIT) + if ((unsigned)form->current->opts & O_EDIT) { res = fct(form); if (res == E_OK) @@ -2571,7 +2571,7 @@ FE_New_Line(FORM *form) if (Last_Row && (!(Growable(field) && !Single_Line_Field(field)))) { - if (!(form->opts & O_NL_OVERLOAD)) + if (!((unsigned)form->opts & O_NL_OVERLOAD)) returnCode(E_REQUEST_DENIED); wmove(form->w, form->currow, form->curcol); wclrtoeol(form->w); @@ -2605,7 +2605,7 @@ FE_New_Line(FORM *form) if (Last_Row && !(Growable(field) && !Single_Line_Field(field))) { - if (!(form->opts & O_NL_OVERLOAD)) + if (!((unsigned)form->opts & O_NL_OVERLOAD)) returnCode(E_REQUEST_DENIED); returnCode(Inter_Field_Navigation(FN_Next_Field, form)); } @@ -2942,7 +2942,7 @@ static int EM_Insert_Mode(FORM *form) { T((T_CALLED("EM_Insert_Mode(%p)"), (void *)form)); - form->status &= ~_OVLMODE; + form->status &= (unsigned short)(~_OVLMODE); returnCode(E_OK); } @@ -3111,7 +3111,7 @@ Check_Field(FORM *form, FIELDTYPE *typ, FIELD *field, TypeArgument *argp) { if (typ) { - if (field->opts & O_NULLOK) + if ((unsigned)field->opts & O_NULLOK) { FIELD_CELL *bp = field->buf; @@ -3168,11 +3168,11 @@ _nc_Internal_Validation(FORM *form) Synchronize_Buffer(form); if ((form->status & _FCHECK_REQUIRED) || - (!(field->opts & O_PASSOK))) + (!((unsigned)field->opts & O_PASSOK))) { if (!Check_Field(form, field->type, field, (TypeArgument *)(field->arg))) return FALSE; - form->status &= ~_FCHECK_REQUIRED; + form->status &= (unsigned short)(~_FCHECK_REQUIRED); field->status |= _CHANGED; Synchronize_Linked_Fields(field); } @@ -3273,14 +3273,15 @@ _nc_First_Active_Field(FORM *form) do { field = (field == last_on_page) ? first : field + 1; - if (((*field)->opts & O_VISIBLE)) + if (((unsigned)(*field)->opts & O_VISIBLE)) break; } while (proposed != (*field)); proposed = *field; - if ((proposed == *last_on_page) && !(proposed->opts & O_VISIBLE)) + if ((proposed == *last_on_page) && + !((unsigned)proposed->opts & O_VISIBLE)) { /* This means, there is also no visible field on the page. So we propose the first one and hope the very best... @@ -3816,11 +3817,11 @@ _nc_Set_Form_Page(FORM *form, int page, FIELD *field) FIELD *last_field, *field_on_page; werase(Get_Form_Window(form)); - form->curpage = page; + form->curpage = (short)page; last_field = field_on_page = form->field[form->page[page].smin]; do { - if (field_on_page->opts & O_VISIBLE) + if ((unsigned)field_on_page->opts & O_VISIBLE) if ((res = Display_Field(field_on_page)) != E_OK) return (res); field_on_page = field_on_page->snext; @@ -3999,13 +4000,13 @@ Data_Entry(FORM *form, int c) int result = E_REQUEST_DENIED; T((T_CALLED("Data_Entry(%p,%s)"), (void *)form, _tracechtype((chtype)c))); - if ((field->opts & O_EDIT) + if (((unsigned) field->opts & O_EDIT) #if FIX_FORM_INACTIVE_BUG - && (field->opts & O_ACTIVE) + && ((unsigned) field->opts & O_ACTIVE) #endif ) { - if ((field->opts & O_BLANK) && + if (((unsigned) field->opts & O_BLANK) && First_Position_In_Current_Field(form) && !(form->status & _FCHECK_REQUIRED) && !(form->status & _WINDOW_MODIFIED)) @@ -4036,7 +4037,7 @@ Data_Entry(FORM *form, int c) ((field->dcols - 1) == form->curcol)); form->status |= _WINDOW_MODIFIED; - if (End_Of_Field && !Growable(field) && (field->opts & O_AUTOSKIP)) + if (End_Of_Field && !Growable(field) && ((unsigned) field->opts & O_AUTOSKIP)) result = Inter_Field_Navigation(FN_Next_Field, form); else { @@ -4246,7 +4247,7 @@ form_driver(FORM *form, int c) NULL /* Choice Request is generic */ }; size_t nMethods = (sizeof(Generic_Methods) / sizeof(Generic_Methods[0])); - size_t method = (BI->keycode >> ID_Shft) & 0xffff; /* see ID_Mask */ + size_t method = (size_t)((BI->keycode >> ID_Shft) & 0xffff); /* see ID_Mask */ if ((method >= nMethods) || !(BI->cmd)) res = E_SYSTEM_ERROR; @@ -4401,14 +4402,14 @@ set_field_buffer(FIELD *field, int buffer, const char *value) if (!field || !value || ((buffer < 0) || (buffer > field->nbuf))) RETURN(E_BAD_ARGUMENT); - len = Buffer_Length(field); + len = (unsigned) Buffer_Length(field); if (Growable(field)) { /* for a growable field we must assume zero terminated strings, because somehow we have to detect the length of what should be copied. */ - unsigned int vlen = strlen(value); + unsigned vlen = (unsigned) strlen(value); if (vlen > len) { @@ -4417,7 +4418,9 @@ set_field_buffer(FIELD *field, int buffer, const char *value) * field->cols)))) RETURN(E_SYSTEM_ERROR); +#if !USE_WIDEC_SUPPORT len = vlen; +#endif } } @@ -4436,9 +4439,9 @@ set_field_buffer(FIELD *field, int buffer, const char *value) delwin(field->working); field->working = newpad(1, Buffer_Length(field) + 1); } - len = Buffer_Length(field); + len = (unsigned)Buffer_Length(field); wclear(field->working); - mvwaddstr(field->working, 0, 0, value); + (void)mvwaddstr(field->working, 0, 0, value); if ((widevalue = typeCalloc(FIELD_CELL, len + 1)) == 0) { @@ -4448,9 +4451,9 @@ set_field_buffer(FIELD *field, int buffer, const char *value) { for (i = 0; i < (unsigned)field->drows; ++i) { - mvwin_wchnstr(field->working, 0, i * field->dcols, - widevalue + (i * field->dcols), - field->dcols); + (void)mvwin_wchnstr(field->working, 0, (int)i * field->dcols, + widevalue + ((int)i * field->dcols), + field->dcols); } for (i = 0; i < len; ++i) { @@ -4510,7 +4513,7 @@ field_buffer(const FIELD *field, int buffer) { #if USE_WIDEC_SUPPORT FIELD_CELL *data = Address_Of_Nth_Buffer(field, buffer); - unsigned need = 0; + size_t need = 0; int size = Buffer_Length(field); int n; @@ -4611,7 +4614,7 @@ _nc_Widen_String(char *source, int *lengthp) { result[need] = wch; } - passed += status; + passed += (size_t) status; ++need; } else @@ -4631,7 +4634,7 @@ _nc_Widen_String(char *source, int *lengthp) break; result = typeCalloc(wchar_t, need); - *lengthp = need; + *lengthp = (int) need; if (result == 0) break; }