frm_data.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /****************************************************************************
  2. * Copyright (c) 1998 Free Software Foundation, Inc. *
  3. * *
  4. * Permission is hereby granted, free of charge, to any person obtaining a *
  5. * copy of this software and associated documentation files (the *
  6. * "Software"), to deal in the Software without restriction, including *
  7. * without limitation the rights to use, copy, modify, merge, publish, *
  8. * distribute, distribute with modifications, sublicense, and/or sell *
  9. * copies of the Software, and to permit persons to whom the Software is *
  10. * furnished to do so, subject to the following conditions: *
  11. * *
  12. * The above copyright notice and this permission notice shall be included *
  13. * in all copies or substantial portions of the Software. *
  14. * *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
  16. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
  18. * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
  19. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
  20. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
  21. * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
  22. * *
  23. * Except as contained in this notice, the name(s) of the above copyright *
  24. * holders shall not be used in advertising or otherwise to promote the *
  25. * sale, use or other dealings in this Software without prior written *
  26. * authorization. *
  27. ****************************************************************************/
  28. /****************************************************************************
  29. * Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997 *
  30. ****************************************************************************/
  31. #include "form.priv.h"
  32. MODULE_ID("$Id$")
  33. extern int winnstr(WINDOW *, char *, int);
  34. /*---------------------------------------------------------------------------
  35. | Facility : libnform
  36. | Function : bool data_behind(const FORM *form)
  37. |
  38. | Description : Check for off-screen data behind. This is nearly trivial
  39. | becose the begin of a field is fixed.
  40. |
  41. | Return Values : TRUE - there are off-screen data behind
  42. | FALSE - there are no off-screen data behind
  43. +--------------------------------------------------------------------------*/
  44. bool data_behind(const FORM *form)
  45. {
  46. bool result = FALSE;
  47. if (form && (form->status & _POSTED) && form->current)
  48. {
  49. FIELD *field;
  50. field = form->current;
  51. if (!Single_Line_Field(field))
  52. {
  53. result = (form->toprow==0) ? FALSE : TRUE;
  54. }
  55. else
  56. {
  57. result = (form->begincol==0) ? FALSE : TRUE;
  58. }
  59. }
  60. return(result);
  61. }
  62. /*---------------------------------------------------------------------------
  63. | Facility : libnform
  64. | Function : static char * After_Last_Non_Pad_Position(
  65. | char *buffer,
  66. | int len,
  67. | int pad)
  68. |
  69. | Description : Find the last position in the buffer that doesn't
  70. | contain a padding character.
  71. |
  72. | Return Values : The pointer to this position
  73. +--------------------------------------------------------------------------*/
  74. INLINE
  75. static char * After_Last_Non_Pad_Position(char *buffer, int len, int pad)
  76. {
  77. char *end = buffer + len;
  78. assert(buffer && len>=0);
  79. while ( (buffer < end) && (*(end-1)==pad) )
  80. end--;
  81. return end;
  82. }
  83. #define SMALL_BUFFER_SIZE (80)
  84. /*---------------------------------------------------------------------------
  85. | Facility : libnform
  86. | Function : bool data_ahead(const FORM *form)
  87. |
  88. | Description : Check for off-screen data ahead. This is more difficult
  89. | because a dynamic field has a variable end.
  90. |
  91. | Return Values : TRUE - there are off-screen data ahead
  92. | FALSE - there are no off-screen data ahead
  93. +--------------------------------------------------------------------------*/
  94. bool data_ahead(const FORM *form)
  95. {
  96. bool result = FALSE;
  97. if (form && (form->status & _POSTED) && form->current)
  98. {
  99. static char buffer[SMALL_BUFFER_SIZE + 1];
  100. FIELD *field;
  101. bool large_buffer;
  102. bool cursor_moved = FALSE;
  103. char *bp;
  104. char *found_content;
  105. int pos;
  106. field = form->current;
  107. assert(form->w != 0);
  108. large_buffer = (field->cols > SMALL_BUFFER_SIZE);
  109. if (large_buffer)
  110. bp = (char *)malloc((size_t)(field->cols) + 1);
  111. else
  112. bp = buffer;
  113. assert(bp != 0);
  114. if (Single_Line_Field(field))
  115. {
  116. int check_len;
  117. pos = form->begincol + field->cols;
  118. while (pos < field->dcols)
  119. {
  120. check_len = field->dcols - pos;
  121. if ( check_len >= field->cols )
  122. check_len = field->cols;
  123. cursor_moved = TRUE;
  124. wmove(form->w,0,pos);
  125. winnstr(form->w,bp,check_len);
  126. found_content =
  127. After_Last_Non_Pad_Position(bp,check_len,field->pad);
  128. if (found_content==bp)
  129. pos += field->cols;
  130. else
  131. {
  132. result = TRUE;
  133. break;
  134. }
  135. }
  136. }
  137. else
  138. {
  139. pos = form->toprow + field->rows;
  140. while (pos < field->drows)
  141. {
  142. cursor_moved = TRUE;
  143. wmove(form->w,pos,0);
  144. pos++;
  145. winnstr(form->w,bp,field->cols);
  146. found_content =
  147. After_Last_Non_Pad_Position(bp,field->cols,field->pad);
  148. if (found_content!=bp)
  149. {
  150. result = TRUE;
  151. break;
  152. }
  153. }
  154. }
  155. if (large_buffer)
  156. free(bp);
  157. if (cursor_moved)
  158. wmove(form->w,form->currow,form->curcol);
  159. }
  160. return(result);
  161. }
  162. /* frm_data.c ends here */