ODMulti.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /* OpenDoors Online Software Programming Toolkit
  2. * (C) Copyright 1991 - 1999 by Brian Pirie.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. *
  19. * File: ODMulti.c
  20. *
  21. * Description: Code for multiple personality system, which allows
  22. * a status line / function key personality to be dynamically
  23. * selected at run-time.
  24. *
  25. * Revisions: Date Ver Who Change
  26. * ---------------------------------------------------------------
  27. * Oct 13, 1994 6.00 BP New file header format.
  28. * Dec 09, 1994 6.00 BP Standardized coding style.
  29. * Aug 19, 1995 6.00 BP 32-bit portability.
  30. * Nov 11, 1995 6.00 BP Removed register keyword.
  31. * Nov 14, 1995 6.00 BP Added include of odscrn.h.
  32. * Nov 16, 1995 6.00 BP Removed oddoor.h, added odcore.h.
  33. * Dec 12, 1995 6.00 BP Added entry, exit and kernel macros.
  34. * Dec 30, 1995 6.00 BP Added ODCALL for calling convention.
  35. * Jan 23, 1996 6.00 BP Disable MPS under Win32 version.
  36. * Feb 19, 1996 6.00 BP Changed version number to 6.00.
  37. * Mar 03, 1996 6.10 BP Begin version 6.10.
  38. * Sep 01, 1996 6.10 BP Update output area on od_set_per...().
  39. * Aug 10, 2003 6.23 SH *nix support
  40. */
  41. #define BUILDING_OPENDOORS
  42. #include <string.h>
  43. #include <ctype.h>
  44. #include <stddef.h>
  45. #include <time.h>
  46. #include <stdio.h>
  47. #include "OpenDoor.h"
  48. #include "ODStr.h"
  49. #include "ODCore.h"
  50. #include "ODGen.h"
  51. #include "ODScrn.h"
  52. #include "ODInEx.h"
  53. #include "ODKrnl.h"
  54. /* Maximum number of personalities that may be installed at once. */
  55. #define MAX_PERSONALITIES 12
  56. /* Information on installed personalities. */
  57. typedef struct
  58. {
  59. char szName[33];
  60. INT nStatusTopLine;
  61. INT nStatusBottomLine;
  62. OD_PERSONALITY_PROC *pfPersonalityFunction;
  63. } tPersonalityInfo;
  64. static tPersonalityInfo aPersonalityInfo[MAX_PERSONALITIES]=
  65. {
  66. {"STANDARD", 1, 23, pdef_opendoors},
  67. {"REMOTEACCESS", 1, 23, pdef_ra},
  68. {"WILDCAT", 1, 23, pdef_wildcat},
  69. {"PCBOARD", 1, 23, pdef_pcboard}
  70. };
  71. /* Private variables. */
  72. static INT nPersonalities = 5;
  73. static INT nCurrentPersonality = 255;
  74. /* ----------------------------------------------------------------------------
  75. * ODMPSEnable()
  76. *
  77. * This function is called from within od_init() when the user enables the
  78. * multiple personality system.
  79. *
  80. * Parameters: None.
  81. *
  82. * Return: void
  83. */
  84. ODAPIDEF void ODCALL ODMPSEnable(void)
  85. {
  86. pfSetPersonality = od_set_personality;
  87. }
  88. /* ----------------------------------------------------------------------------
  89. * od_set_personality()
  90. *
  91. * Sets the current personality to the one that is specified in pszName.
  92. *
  93. * Parameters: pszName - The name of the personality to switch to.
  94. *
  95. * Return: TRUE on success, or FALSE on failure.
  96. */
  97. ODAPIDEF BOOL ODCALL od_set_personality(const char *pszName)
  98. {
  99. #ifdef OD_TEXTMODE
  100. BYTE btNewPersonality;
  101. char szNameToMatch[33];
  102. tPersonalityInfo *pNewPersonalityInfo;
  103. #endif /* OD_TEXTMODE */
  104. /* Log function entry if running in trace mode */
  105. TRACE(TRACE_API, "od_set_personality()");
  106. /* Initialize OpenDoors if it hasn't already been done. */
  107. if(!bODInitialized) od_init();
  108. OD_API_ENTRY();
  109. #ifdef OD_TEXTMODE
  110. /* Check for valid parameters. */
  111. if(strlen(pszName) == 0)
  112. {
  113. od_control.od_error = ERR_PARAMETER;
  114. OD_API_EXIT();
  115. return(FALSE);
  116. }
  117. /* Build personality name to match. */
  118. strncpy(szNameToMatch, pszName, 32);
  119. szNameToMatch[32] = '\0';
  120. strupr(szNameToMatch);
  121. /* Loop through installed personalities, checking for a match. */
  122. for(btNewPersonality = 0; btNewPersonality < nPersonalities;
  123. ++btNewPersonality)
  124. {
  125. /* If the name of this personality matches the one we are looking for. */
  126. if(strcmp(szNameToMatch, aPersonalityInfo[btNewPersonality].szName) == 0)
  127. {
  128. if(btNewPersonality != nCurrentPersonality)
  129. {
  130. /* Remove current status line from the screen .*/
  131. od_set_statusline(8);
  132. /* Initialize the new personality. */
  133. if(nCurrentPersonality != 255)
  134. (*(OD_PERSONALITY_CALLBACK *)pfCurrentPersonality)(22);
  135. od_control.od_page_statusline = -1;
  136. pNewPersonalityInfo =
  137. &aPersonalityInfo[nCurrentPersonality=btNewPersonality];
  138. bRAStatus = TRUE;
  139. (*(OD_PERSONALITY_CALLBACK *)pNewPersonalityInfo
  140. ->pfPersonalityFunction)(20);
  141. ODScrnSetBoundary(1, (BYTE)pNewPersonalityInfo->nStatusTopLine, 80,
  142. (BYTE)pNewPersonalityInfo->nStatusBottomLine);
  143. pfCurrentPersonality
  144. = pNewPersonalityInfo->pfPersonalityFunction;
  145. btCurrentStatusLine = 255;
  146. /* Update output area. */
  147. btOutputTop = (BYTE)pNewPersonalityInfo->nStatusTopLine;
  148. btOutputBottom = (BYTE)pNewPersonalityInfo->nStatusBottomLine;
  149. /* Draw the new statusline. */
  150. od_set_statusline(0);
  151. }
  152. OD_API_EXIT();
  153. return(TRUE);
  154. }
  155. }
  156. OD_API_EXIT();
  157. od_control.od_error = ERR_LIMIT;
  158. return(FALSE);
  159. #else /* !OD_TEXTMODE */
  160. /* The multiple personality system is not supported under this platform. */
  161. od_control.od_error = ERR_UNSUPPORTED;
  162. /* Return with failure. */
  163. OD_API_EXIT();
  164. return(FALSE);
  165. #endif /* !OD_TEXTMODE */
  166. }
  167. /* ----------------------------------------------------------------------------
  168. * od_add_personality()
  169. *
  170. * Installs a new personality into the set of available personalities.
  171. *
  172. * Parameters: pszName - Pointer to string containing the name of
  173. * the new personality.
  174. *
  175. * btOutputTop - Index of the top line of the status bar.
  176. *
  177. * btOutputBottom - Index of the bottom line of the status bar.
  178. *
  179. * pfPerFunc - Pointer to the callback function which
  180. * implements this personality.
  181. *
  182. * Return: TRUE on success or FALSE on failure.
  183. */
  184. ODAPIDEF BOOL ODCALL od_add_personality(const char *pszName, BYTE btOutputTop,
  185. BYTE btOutputBottom, OD_PERSONALITY_PROC *pfPerFunc)
  186. {
  187. /* Log function entry if running in trace mode */
  188. TRACE(TRACE_API, "od_add_personality()");
  189. #ifdef OD_TEXTMODE
  190. /* Check that we haven't exceeded the limit on the total number of */
  191. /* installed personalities. */
  192. if(nPersonalities == MAX_PERSONALITIES)
  193. {
  194. od_control.od_error = ERR_LIMIT;
  195. return(FALSE);
  196. }
  197. /* Store information on this new personality. */
  198. strncpy(aPersonalityInfo[nPersonalities].szName, pszName, 32);
  199. aPersonalityInfo[nPersonalities].szName[32] = '\0';
  200. strupr(aPersonalityInfo[nPersonalities].szName);
  201. aPersonalityInfo[nPersonalities].nStatusTopLine = btOutputTop;
  202. aPersonalityInfo[nPersonalities].nStatusBottomLine = btOutputBottom;
  203. aPersonalityInfo[nPersonalities].pfPersonalityFunction = pfPerFunc;
  204. /* Increment total number of personalities. */
  205. ++nPersonalities;
  206. /* Return with success. */
  207. return(TRUE);
  208. #else /* !OD_TEXTMODE */
  209. /* The multiple personality system is not supported under this platform. */
  210. od_control.od_error = ERR_UNSUPPORTED;
  211. /* Return with failure. */
  212. return(FALSE);
  213. #endif /* !OD_TEXTMODE */
  214. }