diff options
Diffstat (limited to 'form/frm_driver.c')
| -rw-r--r-- | form/frm_driver.c | 91 |
1 files changed, 47 insertions, 44 deletions
diff --git a/form/frm_driver.c b/form/frm_driver.c index 75656d69ea2a..276f97f4bbfd 100644 --- a/form/frm_driver.c +++ b/form/frm_driver.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2020,2021 Thomas E. Dickey * + * Copyright 2018-2021,2024 Thomas E. Dickey * * Copyright 1998-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -33,7 +33,7 @@ #include "form.priv.h" -MODULE_ID("$Id: frm_driver.c,v 1.135 2021/09/01 23:34:01 tom Exp $") +MODULE_ID("$Id: frm_driver.c,v 1.137 2024/12/07 21:57:21 tom Exp $") /*---------------------------------------------------------------------------- This is the core module of the form library. It contains the majority @@ -313,7 +313,7 @@ cell_base(WINDOW *win, int y, int x) while (LEGALYX(win, y, x)) { - cchar_t *data = &(win->_line[y].text[x]); + const cchar_t *data = &(win->_line[y].text[x]); if (isWidecBase(CHDEREF(data)) || !isWidecExt(CHDEREF(data))) { @@ -387,7 +387,7 @@ NCURSES_INLINE static FIELD_CELL * Get_Start_Of_Data(FIELD_CELL *buf, int blen) { FIELD_CELL *p = buf; - FIELD_CELL *end = &buf[blen]; + const FIELD_CELL *end = &buf[blen]; assert(buf && blen >= 0); while ((p < end) && ISBLANK(*p)) @@ -429,7 +429,7 @@ NCURSES_INLINE static FIELD_CELL * Get_First_Whitespace_Character(FIELD_CELL *buf, int blen) { FIELD_CELL *p = buf; - FIELD_CELL *end = &p[blen]; + const FIELD_CELL *end = &p[blen]; assert(buf && blen >= 0); while ((p < end) && !ISBLANK(*p)) @@ -479,7 +479,7 @@ After_Last_Whitespace_Character(FIELD_CELL *buf, int blen) NCURSES_INLINE static void Adjust_Cursor_Position(FORM *form, const FIELD_CELL *pos) { - FIELD *field; + const FIELD *field; int idx; field = form->current; @@ -716,7 +716,7 @@ Field_Grown(FIELD *field, int amount) for (i = 0; i <= field->nbuf; i++) { FIELD_CELL *new_bp = Address_Of_Nth_Buffer(field, i); - FIELD_CELL *old_bp = oldbuf + i * (1 + old_buflen); + const FIELD_CELL *old_bp = oldbuf + i * (1 + old_buflen); for (j = 0; j < old_buflen; ++j) new_bp[j] = old_bp[j]; @@ -734,7 +734,7 @@ Field_Grown(FIELD *field, int amount) { WINDOW *new_window = newpad(field->drows, field->dcols); - if (new_window != 0) + if (new_window != NULL) { assert(form != (FORM *)0); if (form->w) @@ -802,7 +802,7 @@ static int Field_encloses(FIELD *field, int ry, int rx) { T((T_CALLED("Field_encloses(%p)"), (void *)field)); - if (field != 0 + if (field != NULL && field->frow <= ry && (field->frow + field->rows) > ry && field->fcol <= rx @@ -830,7 +830,7 @@ Field_encloses(FIELD *field, int ry, int rx) FORM_EXPORT(int) _nc_Position_Form_Cursor(FORM *form) { - FIELD *field; + const FIELD *field; WINDOW *formwin; if (!form) @@ -1005,7 +1005,7 @@ _nc_Refresh_Current_Field(FORM *form) static void Perform_Justification(FIELD *field, WINDOW *win) { - FIELD_CELL *bp; + const FIELD_CELL *bp; int len; bp = (Field_Has_Option(field, O_NO_LEFT_STRIP) @@ -1053,7 +1053,7 @@ Perform_Justification(FIELD *field, WINDOW *win) static void Undo_Justification(FIELD *field, WINDOW *win) { - FIELD_CELL *bp; + const FIELD_CELL *bp; int y, x; int len; @@ -1251,7 +1251,7 @@ Synchronize_Linked_Fields(FIELD *field) return (E_SYSTEM_ERROR); for (linked_field = field->link; - (linked_field != field) && (linked_field != 0); + (linked_field != field) && (linked_field != NULL); linked_field = linked_field->link) { int syncres; @@ -1458,7 +1458,7 @@ _nc_Unset_Current_Field(FORM *form) werase(form->w); Perform_Justification(field, form->w); if (Field_Has_Option(field, O_DYNAMIC_JUSTIFY) && - (form->w->_parent == 0)) + (form->w->_parent == NULL)) { copywin(form->w, Get_Form_Window(form), @@ -1480,7 +1480,7 @@ _nc_Unset_Current_Field(FORM *form) } delwin(form->w); form->w = (WINDOW *)0; - form->current = 0; + form->current = NULL; } /*--------------------------------------------------------------------------- @@ -1702,10 +1702,10 @@ IFN_Previous_Line(FORM *form) static int IFN_Next_Word(FORM *form) { - FIELD *field = form->current; + const FIELD *field = form->current; FIELD_CELL *bp = Address_Of_Current_Position_In_Buffer(form); FIELD_CELL *s; - FIELD_CELL *t; + const FIELD_CELL *t; T((T_CALLED("IFN_Next_Word(%p)"), (void *)form)); @@ -1745,9 +1745,9 @@ static int IFN_Previous_Word(FORM *form) { FIELD *field = form->current; - FIELD_CELL *bp = Address_Of_Current_Position_In_Buffer(form); - FIELD_CELL *s; - FIELD_CELL *t; + const FIELD_CELL *bp = Address_Of_Current_Position_In_Buffer(form); + const FIELD_CELL *s; + const FIELD_CELL *t; bool again = FALSE; T((T_CALLED("IFN_Previous_Word(%p)"), (void *)form)); @@ -1845,7 +1845,7 @@ IFN_End_Of_Field(FORM *form) static int IFN_Beginning_Of_Line(FORM *form) { - FIELD *field = form->current; + const FIELD *field = form->current; T((T_CALLED("IFN_Beginning_Of_Line(%p)"), (void *)form)); Synchronize_Buffer(form); @@ -1869,7 +1869,7 @@ IFN_Beginning_Of_Line(FORM *form) static int IFN_End_Of_Line(FORM *form) { - FIELD *field = form->current; + const FIELD *field = form->current; FIELD_CELL *pos; FIELD_CELL *bp; @@ -2009,7 +2009,7 @@ IFN_Down_Character(FORM *form) static int VSC_Generic(FORM *form, int nlines) { - FIELD *field = form->current; + const FIELD *field = form->current; int res = E_REQUEST_DENIED; int rows_to_go = (nlines > 0 ? nlines : -nlines); @@ -2189,7 +2189,7 @@ VSC_Scroll_Half_Page_Backward(FORM *form) static int HSC_Generic(FORM *form, int ncolumns) { - FIELD *field = form->current; + const FIELD *field = form->current; int res = E_REQUEST_DENIED; int cols_to_go = (ncolumns > 0 ? ncolumns : -ncolumns); @@ -2365,7 +2365,8 @@ NCURSES_INLINE static bool Is_There_Room_For_A_Line(FORM *form) { FIELD *field = form->current; - FIELD_CELL *begin_of_last_line, *s; + FIELD_CELL *begin_of_last_line; + const FIELD_CELL *s; Synchronize_Buffer(form); begin_of_last_line = Address_Of_Row_In_Buffer(field, (field->drows - 1)); @@ -2419,7 +2420,7 @@ Is_There_Room_For_A_Char_In_Line(FORM *form) | E_SYSTEM_ERROR - system error +--------------------------------------------------------------------------*/ static int -Insert_String(FORM *form, int row, FIELD_CELL *txt, int len) +Insert_String(FORM *form, int row, const FIELD_CELL *txt, int len) { FIELD *field = form->current; FIELD_CELL *bp = Address_Of_Row_In_Buffer(field, row); @@ -2450,7 +2451,7 @@ Insert_String(FORM *form, int row, FIELD_CELL *txt, int len) if (row < (field->drows - 1)) { - FIELD_CELL *split; + const FIELD_CELL *split; split = After_Last_Whitespace_Character(bp, @@ -2507,7 +2508,7 @@ Wrapping_Not_Necessary_Or_Wrapping_Ok(FORM *form) (!Last_Row || Growable(field))) /* there are more lines */ { FIELD_CELL *bp; - FIELD_CELL *split; + const FIELD_CELL *split; int chars_to_be_wrapped; int chars_to_remain_on_line; @@ -2633,7 +2634,7 @@ static int FE_New_Line(FORM *form) { FIELD *field = form->current; - FIELD_CELL *bp, *t; + FIELD_CELL *bp; bool Last_Row = ((field->drows - 1) == form->currow); T((T_CALLED("FE_New_Line(%p)"), (void *)form)); @@ -2682,6 +2683,7 @@ FE_New_Line(FORM *form) } else { + const FIELD_CELL *t; bool May_Do_It = !Last_Row && Is_There_Room_For_A_Line(form); if (!(May_Do_It || Growable(field))) @@ -2810,7 +2812,7 @@ FE_Delete_Character(FORM *form) static int FE_Delete_Previous(FORM *form) { - FIELD *field = form->current; + const FIELD *field = form->current; T((T_CALLED("FE_Delete_Previous(%p)"), (void *)form)); if (First_Position_In_Current_Field(form)) @@ -2818,7 +2820,8 @@ FE_Delete_Previous(FORM *form) if ((--(form->curcol)) < 0) { - FIELD_CELL *this_line, *prev_line, *prev_end, *this_end; + FIELD_CELL *this_line, *prev_line; + const FIELD_CELL *prev_end, *this_end; int this_row = form->currow; form->curcol++; @@ -2898,9 +2901,9 @@ FE_Delete_Line(FORM *form) static int FE_Delete_Word(FORM *form) { - FIELD *field = form->current; + const FIELD *field = form->current; FIELD_CELL *bp = Address_Of_Current_Row_In_Buffer(form); - FIELD_CELL *ep = bp + field->dcols; + const FIELD_CELL *ep = bp + field->dcols; FIELD_CELL *cp = bp + form->curcol; FIELD_CELL *s; @@ -4440,7 +4443,7 @@ form_driver(FORM *form, int c) { MEVENT event; WINDOW *win = form->win ? form->win : StdScreen(Get_Form_Screen(form)); - WINDOW *sub = form->sub ? form->sub : win; + const WINDOW *sub = form->sub ? form->sub : win; getmouse(&event); if ((event.bstate & (BUTTON1_CLICKED | @@ -4641,7 +4644,7 @@ form_driver_w(FORM *form, int type, wchar_t c) { MEVENT event; WINDOW *win = form->win ? form->win : StdScreen(Get_Form_Screen(form)); - WINDOW *sub = form->sub ? form->sub : win; + const WINDOW *sub = form->sub ? form->sub : win; getmouse(&event); if ((event.bstate & (BUTTON1_CLICKED | @@ -4755,7 +4758,7 @@ set_field_buffer(FIELD *field, int buffer, const char *value) int len; #if USE_WIDEC_SUPPORT - FIELD_CELL *widevalue = 0; + FIELD_CELL *widevalue = NULL; #endif T((T_CALLED("set_field_buffer(%p,%d,%s)"), (void *)field, buffer, _nc_visbuf(value))); @@ -4804,7 +4807,7 @@ set_field_buffer(FIELD *field, int buffer, const char *value) wclear(field->working); (void)mvwaddstr(field->working, 0, 0, value); - if ((widevalue = typeCalloc(FIELD_CELL, len + 1)) == 0) + if ((widevalue = typeCalloc(FIELD_CELL, len + 1)) == NULL) { RETURN(E_SYSTEM_ERROR); } @@ -4866,7 +4869,7 @@ set_field_buffer(FIELD *field, int buffer, const char *value) FORM_EXPORT(char *) field_buffer(const FIELD *field, int buffer) { - char *result = 0; + char *result = NULL; T((T_CALLED("field_buffer(%p,%d)"), (const void *)field, buffer)); @@ -4887,14 +4890,14 @@ field_buffer(const FIELD *field, int buffer) size_t next; init_mb(state); - next = _nc_wcrtomb(0, data[n].chars[0], &state); + next = _nc_wcrtomb(NULL, data[n].chars[0], &state); if (next > 0) need += next; } } /* allocate a place to store the expanded string */ - if (field->expanded[buffer] != 0) + if (field->expanded[buffer] != NULL) free(field->expanded[buffer]); field->expanded[buffer] = typeMalloc(char, need + 1); @@ -4906,7 +4909,7 @@ field_buffer(const FIELD *field, int buffer) * contain embedded wide-character extensions). Change the null-padding * to blanks as needed. */ - if ((result = field->expanded[buffer]) != 0) + if ((result = field->expanded[buffer]) != NULL) { wclear(field->working); wmove(field->working, 0, 0); @@ -4934,8 +4937,8 @@ field_buffer(const FIELD *field, int buffer) FORM_EXPORT(wchar_t *) _nc_Widen_String(char *source, int *lengthp) { - wchar_t *result = 0; - wchar_t wch; + wchar_t *result = NULL; + wchar_t wch = 0; size_t given = strlen(source); size_t tries; int pass; @@ -4996,7 +4999,7 @@ _nc_Widen_String(char *source, int *lengthp) result = typeCalloc(wchar_t, need); *lengthp = (int)need; - if (result == 0) + if (result == NULL) break; } } |
