home *** CD-ROM | disk | FTP | other *** search
/ synchro.net / synchro.net.tar / synchro.net / main / BBS / ODOORS62.ZIP / ODMulti.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-07  |  8.2 KB  |  254 lines

  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.  */
  40.  
  41. #define BUILDING_OPENDOORS
  42.  
  43. #include <string.h>
  44. #include <ctype.h>
  45. #include <stddef.h>
  46. #include <time.h>
  47. #include <stdio.h>
  48.  
  49. #include "OpenDoor.h"
  50. #include "ODCore.h"
  51. #include "ODGen.h"
  52. #include "ODScrn.h"
  53. #include "ODInEx.h"
  54. #include "ODKrnl.h"
  55.  
  56.  
  57. /* Maximum number of personalities that may be installed at once. */
  58. #define MAX_PERSONALITIES  12
  59.  
  60.  
  61. /* Information on installed personalities. */
  62. typedef struct
  63. {
  64.    char szName[33];
  65.    INT nStatusTopLine;
  66.    INT nStatusBottomLine;
  67.    OD_PERSONALITY_PROC *pfPersonalityFunction;
  68. } tPersonalityInfo;
  69.  
  70. static tPersonalityInfo aPersonalityInfo[MAX_PERSONALITIES]=
  71. {
  72.    {"STANDARD", 1, 23, pdef_opendoors},
  73.    {"REMOTEACCESS", 1, 23, pdef_ra},
  74.    {"WILDCAT", 1, 23, pdef_wildcat},
  75.    {"PCBOARD", 1, 23, pdef_pcboard}
  76. };
  77.  
  78.  
  79. /* Private variables. */
  80. static INT nPersonalities = 5;
  81. static INT nCurrentPersonality = 255;
  82.  
  83.  
  84. /* ----------------------------------------------------------------------------
  85.  * ODMPSEnable()
  86.  *
  87.  * This function is called from within od_init() when the user enables the
  88.  * multiple personality system.
  89.  *
  90.  * Parameters: None.
  91.  *
  92.  *     Return: void
  93.  */
  94. ODAPIDEF void ODCALL ODMPSEnable(void)
  95. {
  96.    pfSetPersonality = od_set_personality;
  97. }
  98.  
  99.  
  100. /* ----------------------------------------------------------------------------
  101.  * od_set_personality()
  102.  *
  103.  * Sets the current personality to the one that is specified in pszName.
  104.  *
  105.  * Parameters: pszName - The name of the personality to switch to.
  106.  *
  107.  *     Return: TRUE on success, or FALSE on failure.
  108.  */
  109. ODAPIDEF BOOL ODCALL od_set_personality(char *pszName)
  110. {
  111. #ifdef OD_TEXTMODE
  112.    BYTE btNewPersonality;
  113.    char szNameToMatch[33];
  114.    tPersonalityInfo *pNewPersonalityInfo;
  115. #endif /* OD_TEXTMODE */
  116.  
  117.    /* Log function entry if running in trace mode */
  118.    TRACE(TRACE_API, "od_set_personality()");
  119.  
  120.    /* Initialize OpenDoors if it hasn't already been done. */
  121.    if(!bODInitialized) od_init();
  122.  
  123.    OD_API_ENTRY();
  124.    
  125. #ifdef OD_TEXTMODE
  126.    /* Check for valid parameters. */
  127.    if(strlen(pszName) == 0)
  128.    {
  129.       od_control.od_error = ERR_PARAMETER;
  130.       OD_API_EXIT();
  131.       return(FALSE);
  132.    }
  133.  
  134.    /* Build personality name to match. */
  135.    strncpy(szNameToMatch, pszName, 32);
  136.    szNameToMatch[32] = '\0';
  137.    strupr(szNameToMatch);
  138.  
  139.    /* Loop through installed personalities, checking for a match. */
  140.    for(btNewPersonality = 0; btNewPersonality < nPersonalities;
  141.       ++btNewPersonality)
  142.    {
  143.       /* If the name of this personality matches the one we are looking for. */
  144.       if(strcmp(szNameToMatch, aPersonalityInfo[btNewPersonality].szName) == 0)
  145.       {
  146.          if(btNewPersonality != nCurrentPersonality)
  147.          {
  148.             /* Remove current status line from the screen .*/
  149.             od_set_statusline(8);
  150.  
  151.             /* Initialize the new personality. */
  152.             if(nCurrentPersonality != 255)
  153.                (*(OD_PERSONALITY_CALLBACK *)pfCurrentPersonality)(22);
  154.             od_control.od_page_statusline = -1;
  155.             pNewPersonalityInfo = 
  156.                &aPersonalityInfo[nCurrentPersonality=btNewPersonality];
  157.             bRAStatus = TRUE;
  158.             (*(OD_PERSONALITY_CALLBACK *)pNewPersonalityInfo
  159.                ->pfPersonalityFunction)(20);
  160.             ODScrnSetBoundary(1, (BYTE)pNewPersonalityInfo->nStatusTopLine, 80,
  161.                (BYTE)pNewPersonalityInfo->nStatusBottomLine);
  162.             pfCurrentPersonality
  163.                = pNewPersonalityInfo->pfPersonalityFunction;
  164.             btCurrentStatusLine = 255;
  165.  
  166.             /* Update output area. */
  167.             btOutputTop = (BYTE)pNewPersonalityInfo->nStatusTopLine;
  168.             btOutputBottom = (BYTE)pNewPersonalityInfo->nStatusBottomLine;
  169.  
  170.             /* Draw the new statusline. */
  171.             od_set_statusline(0);
  172.          }
  173.  
  174.          OD_API_EXIT();
  175.          return(TRUE);
  176.       }
  177.    }
  178.  
  179.    OD_API_EXIT();
  180.    od_control.od_error = ERR_LIMIT;
  181.    return(FALSE);
  182.  
  183. #else /* !OD_TEXTMODE */
  184.  
  185.    /* The multiple personality system is not supported under this platform. */
  186.    od_control.od_error = ERR_UNSUPPORTED;
  187.  
  188.    /* Return with failure. */
  189.    OD_API_EXIT();
  190.    return(FALSE);
  191.  
  192. #endif /* !OD_TEXTMODE */
  193. }
  194.  
  195.  
  196.  
  197. /* ----------------------------------------------------------------------------
  198.  * od_add_personality()
  199.  *
  200.  * Installs a new personality into the set of available personalities.
  201.  *
  202.  * Parameters: pszName        - Pointer to string containing the name of
  203.  *                              the new personality.
  204.  *
  205.  *             btOutputTop    - Index of the top line of the status bar.
  206.  *
  207.  *             btOutputBottom - Index of the bottom line of the status bar.
  208.  *
  209.  *             pfPerFunc      - Pointer to the callback function which
  210.  *                              implements this personality.
  211.  *
  212.  *     Return: TRUE on success or FALSE on failure.
  213.  */
  214. ODAPIDEF BOOL ODCALL od_add_personality(char *pszName, BYTE btOutputTop,
  215.    BYTE btOutputBottom, OD_PERSONALITY_PROC *pfPerFunc)
  216. {
  217.    /* Log function entry if running in trace mode */
  218.    TRACE(TRACE_API, "od_add_personality()");
  219.  
  220. #ifdef OD_TEXTMODE
  221.  
  222.    /* Check that we haven't exceeded the limit on the total number of */
  223.    /* installed personalities.                                        */
  224.    if(nPersonalities == MAX_PERSONALITIES)
  225.    {
  226.       od_control.od_error = ERR_LIMIT;
  227.       return(FALSE);
  228.    }
  229.  
  230.    /* Store information on this new personality. */
  231.    strncpy(aPersonalityInfo[nPersonalities].szName, pszName, 32);
  232.    aPersonalityInfo[nPersonalities].szName[32] = '\0';
  233.    strupr(aPersonalityInfo[nPersonalities].szName);
  234.    aPersonalityInfo[nPersonalities].nStatusTopLine = btOutputTop;
  235.    aPersonalityInfo[nPersonalities].nStatusBottomLine = btOutputBottom;
  236.    aPersonalityInfo[nPersonalities].pfPersonalityFunction = pfPerFunc;
  237.  
  238.    /* Increment total number of personalities. */
  239.    ++nPersonalities;
  240.  
  241.    /* Return with success. */
  242.    return(TRUE);
  243.  
  244. #else /* !OD_TEXTMODE */
  245.  
  246.    /* The multiple personality system is not supported under this platform. */
  247.    od_control.od_error = ERR_UNSUPPORTED;
  248.  
  249.    /* Return with failure. */
  250.    return(FALSE);
  251.  
  252. #endif /* !OD_TEXTMODE */
  253. }
  254.