1
0

frm_req_name.c 5.4 KB

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