frm_req_name.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 <[email protected]> 1995,1997 *
  30. ****************************************************************************/
  31. /***************************************************************************
  32. * Module form_request_name *
  33. * Routines to handle external names of menu requests *
  34. ***************************************************************************/
  35. #ifdef __hpux
  36. #define _XOPEN_SOURCE_EXTENDED
  37. #endif /* __hpux */
  38. #include "form.priv.h"
  39. MODULE_ID("$Id$")
  40. static const char *request_names[ MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1 ] = {
  41. "NEXT_PAGE" ,
  42. "PREV_PAGE" ,
  43. "FIRST_PAGE" ,
  44. "LAST_PAGE" ,
  45. "NEXT_FIELD" ,
  46. "PREV_FIELD" ,
  47. "FIRST_FIELD" ,
  48. "LAST_FIELD" ,
  49. "SNEXT_FIELD" ,
  50. "SPREV_FIELD" ,
  51. "SFIRST_FIELD" ,
  52. "SLAST_FIELD" ,
  53. "LEFT_FIELD" ,
  54. "RIGHT_FIELD" ,
  55. "UP_FIELD" ,
  56. "DOWN_FIELD" ,
  57. "NEXT_CHAR" ,
  58. "PREV_CHAR" ,
  59. "NEXT_LINE" ,
  60. "PREV_LINE" ,
  61. "NEXT_WORD" ,
  62. "PREV_WORD" ,
  63. "BEG_FIELD" ,
  64. "END_FIELD" ,
  65. "BEG_LINE" ,
  66. "END_LINE" ,
  67. "LEFT_CHAR" ,
  68. "RIGHT_CHAR" ,
  69. "UP_CHAR" ,
  70. "DOWN_CHAR" ,
  71. "NEW_LINE" ,
  72. "INS_CHAR" ,
  73. "INS_LINE" ,
  74. "DEL_CHAR" ,
  75. "DEL_PREV" ,
  76. "DEL_LINE" ,
  77. "DEL_WORD" ,
  78. "CLR_EOL" ,
  79. "CLR_EOF" ,
  80. "CLR_FIELD" ,
  81. "OVL_MODE" ,
  82. "INS_MODE" ,
  83. "SCR_FLINE" ,
  84. "SCR_BLINE" ,
  85. "SCR_FPAGE" ,
  86. "SCR_BPAGE" ,
  87. "SCR_FHPAGE" ,
  88. "SCR_BHPAGE" ,
  89. "SCR_FCHAR" ,
  90. "SCR_BCHAR" ,
  91. "SCR_HFLINE" ,
  92. "SCR_HBLINE" ,
  93. "SCR_HFHALF" ,
  94. "SCR_HBHALF" ,
  95. "VALIDATION" ,
  96. "NEXT_CHOICE" ,
  97. "PREV_CHOICE"
  98. };
  99. #define A_SIZE (sizeof(request_names)/sizeof(request_names[0]))
  100. /*---------------------------------------------------------------------------
  101. | Facility : libnform
  102. | Function : const char * form_request_name (int request);
  103. |
  104. | Description : Get the external name of a form request.
  105. |
  106. | Return Values : Pointer to name - on success
  107. | NULL - on invalid request code
  108. +--------------------------------------------------------------------------*/
  109. const char *form_request_name( int request )
  110. {
  111. if ( (request < MIN_FORM_COMMAND) || (request > MAX_FORM_COMMAND) )
  112. {
  113. SET_ERROR (E_BAD_ARGUMENT);
  114. return (const char *)0;
  115. }
  116. else
  117. return request_names[ request - MIN_FORM_COMMAND ];
  118. }
  119. /*---------------------------------------------------------------------------
  120. | Facility : libnform
  121. | Function : int form_request_by_name (const char *str);
  122. |
  123. | Description : Search for a request with this name.
  124. |
  125. | Return Values : Request Id - on success
  126. | E_NO_MATCH - request not found
  127. +--------------------------------------------------------------------------*/
  128. int form_request_by_name( const char *str )
  129. {
  130. /* because the table is so small, it doesn't really hurt
  131. to run sequentially through it.
  132. */
  133. unsigned int i = 0;
  134. char buf[16];
  135. if (str)
  136. {
  137. strncpy(buf,str,sizeof(buf));
  138. while( (i<sizeof(buf)) && (buf[i] != '\0') )
  139. {
  140. buf[i] = toupper(buf[i]);
  141. i++;
  142. }
  143. for (i=0; i < A_SIZE; i++)
  144. {
  145. if (strncmp(request_names[i],buf,sizeof(buf))==0)
  146. return MIN_FORM_COMMAND + i;
  147. }
  148. }
  149. RETURN(E_NO_MATCH);
  150. }
  151. /* frm_req_name.c ends here */