1
0

frm_req_name.c 5.5 KB

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