fty_alpha.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /****************************************************************************
  2. * Copyright (c) 1998-2006,2007 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. * *
  30. * Author : Juergen Pfeifer *
  31. * *
  32. ***************************************************************************/
  33. #include "form.priv.h"
  34. MODULE_ID("$Id: fty_alpha.c,v 1.23 2007/10/13 19:32:09 tom Exp $")
  35. #define thisARG alphaARG
  36. typedef struct
  37. {
  38. int width;
  39. }
  40. thisARG;
  41. /*---------------------------------------------------------------------------
  42. | Facility : libnform
  43. | Function : static void *Make_This_Type(va_list *ap)
  44. |
  45. | Description : Allocate structure for alpha type argument.
  46. |
  47. | Return Values : Pointer to argument structure or NULL on error
  48. +--------------------------------------------------------------------------*/
  49. static void *
  50. Make_This_Type(va_list *ap)
  51. {
  52. thisARG *argp = typeMalloc(thisARG, 1);
  53. if (argp)
  54. {
  55. T((T_CREATE("thisARG %p"), argp));
  56. argp->width = va_arg(*ap, int);
  57. }
  58. return ((void *)argp);
  59. }
  60. /*---------------------------------------------------------------------------
  61. | Facility : libnform
  62. | Function : static void *Copy_This_Type(const void * argp)
  63. |
  64. | Description : Copy structure for alpha type argument.
  65. |
  66. | Return Values : Pointer to argument structure or NULL on error.
  67. +--------------------------------------------------------------------------*/
  68. static void *
  69. Copy_This_Type(const void *argp)
  70. {
  71. const thisARG *ap = (const thisARG *)argp;
  72. thisARG *result = typeMalloc(thisARG, 1);
  73. if (result)
  74. {
  75. T((T_CREATE("thisARG %p"), result));
  76. *result = *ap;
  77. }
  78. return ((void *)result);
  79. }
  80. /*---------------------------------------------------------------------------
  81. | Facility : libnform
  82. | Function : static void Free_This_Type(void *argp)
  83. |
  84. | Description : Free structure for alpha type argument.
  85. |
  86. | Return Values : -
  87. +--------------------------------------------------------------------------*/
  88. static void
  89. Free_This_Type(void *argp)
  90. {
  91. if (argp)
  92. free(argp);
  93. }
  94. /*---------------------------------------------------------------------------
  95. | Facility : libnform
  96. | Function : static bool Check_This_Character(
  97. | int c,
  98. | const void *argp)
  99. |
  100. | Description : Check a character for the alpha type.
  101. |
  102. | Return Values : TRUE - character is valid
  103. | FALSE - character is invalid
  104. +--------------------------------------------------------------------------*/
  105. static bool
  106. Check_This_Character(int c, const void *argp GCC_UNUSED)
  107. {
  108. #if USE_WIDEC_SUPPORT
  109. if (iswalpha((wint_t) c))
  110. return TRUE;
  111. #endif
  112. return (isalpha(UChar(c)) ? TRUE : FALSE);
  113. }
  114. /*---------------------------------------------------------------------------
  115. | Facility : libnform
  116. | Function : static bool Check_This_Field(
  117. | FIELD *field,
  118. | const void *argp)
  119. |
  120. | Description : Validate buffer content to be a valid alpha value
  121. |
  122. | Return Values : TRUE - field is valid
  123. | FALSE - field is invalid
  124. +--------------------------------------------------------------------------*/
  125. static bool
  126. Check_This_Field(FIELD *field, const void *argp)
  127. {
  128. int width = ((const thisARG *)argp)->width;
  129. unsigned char *bp = (unsigned char *)field_buffer(field, 0);
  130. bool result = (width < 0);
  131. Check_CTYPE_Field(result, bp, width, Check_This_Character);
  132. return (result);
  133. }
  134. static FIELDTYPE typeTHIS =
  135. {
  136. _HAS_ARGS | _RESIDENT,
  137. 1, /* this is mutable, so we can't be const */
  138. (FIELDTYPE *)0,
  139. (FIELDTYPE *)0,
  140. Make_This_Type,
  141. Copy_This_Type,
  142. Free_This_Type,
  143. Check_This_Field,
  144. Check_This_Character,
  145. NULL,
  146. NULL
  147. };
  148. NCURSES_EXPORT_VAR(FIELDTYPE*) TYPE_ALPHA = &typeTHIS;
  149. /* fty_alpha.c ends here */