home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / OP2DEV.ZIP / BBSEXPAN.C < prev    next >
C/C++ Source or Header  |  1990-09-24  |  4KB  |  134 lines

  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. //   Omega Point/2 Bulletin Board System
  4. //   Copyright (c) ExcelSoft Software, 1990
  5. //   Version 1.0, cab, 21-Feb-90
  6. //   
  7. //   This file may be freely modified for you own use. You will need
  8. //   the OS/2 Programmer's Toolkit to recompile this module. The .OBJ
  9. //   file has been provided so that you can create expansion programs
  10. //   even if you don't have the Toolkit.
  11. //
  12. //   This file contains several functions that are needed by OP/2
  13. //   BBS expansion programs. This file should be complied and linked
  14. //   with any OP/2 BBS expansion program. The functions in this
  15. //   module are as follows:
  16. //
  17. //     SerWritef() : Just like the 'printf()' functions. Included here
  18. //            rather then in the BBSAPI.LIB because it needs 'C' calling
  19. //            convention.
  20. //
  21. //     UseChildAppInit() : Full initialization function. Sets up the
  22. //            shared memory segments and semaphores needed for correct
  23. //            operation.
  24. //
  25. //     CleanExit() : Insures that when the program ends, for whatever
  26. //            reason, the 'program end' semaphore will be cleared and
  27. //            the main program will resume operation.
  28. //
  29. //   See EXPAND.C and EXPAND.MAK for sample code and make file.
  30. //
  31. //////////////////////////////////////////////////////////////////////////
  32.  
  33. #define INCL_DOS
  34. #define INCL_SUB
  35. #include <os2.h>
  36.  
  37. #include <stdio.h>
  38. #include <string.h>
  39. #include <stdarg.h>
  40.  
  41. #include "os2bbs.h"
  42. #include "bbsapi.h"
  43.  
  44. #define MAINMODULE
  45. #define NO_INCL_BBS                 
  46. #include "bbsexpan.h"
  47.  
  48.  
  49. //
  50. //  UseChildAppInit()
  51. //
  52. //  Intializes OP/2 BBS expansion program
  53. //
  54. UseChildAppInit(char *pstr, char *exename, PORT_REC **anchor, PORT_REC **unhand, void far **sem, int *usernum, int *instance)
  55. {
  56.    USHORT  Selector, Sel2, Sel3, Sel4;
  57.    USHORT  rc;
  58.    char    segname[40];
  59.    char    semname[30], temp[6];
  60.  
  61.    DosExitList(EXLST_ADD,(PFNEXITLIST)CleanExit);
  62.  
  63.    if( strlen(pstr) != 4 )
  64.       return(1);
  65.  
  66.    strcpy(temp,pstr);
  67.    temp[2] = '\0';
  68.    *instance = atoi(temp);
  69.    strcpy(temp,(pstr+2));
  70.    *usernum = atoi(temp);
  71.  
  72.    sprintf(segname,"\\SHAREMEM\\BPORT%02d.BBS",*instance);
  73.    rc = DosGetShrSeg(segname,&Selector);
  74.    if( rc )
  75.       return(2);
  76.  
  77.    sprintf(segname,"\\SHAREMEM\\USER%02d.BBS",*instance);
  78.    rc = DosGetShrSeg(segname,&Sel2);
  79.    if( rc ) 
  80.       return(3);
  81.  
  82.    sprintf(segname,"\\SHAREMEM\\GIS%02d.BBS",*instance);
  83.    rc = DosGetShrSeg(segname,&Sel3);
  84.    if( rc )
  85.       return(4);
  86.  
  87.    sprintf(segname,"\\SHAREMEM\\PAGE%02d.BBS",*instance);
  88.    rc = DosGetShrSeg(segname,&Sel4);
  89.    if( rc )
  90.       return(6);
  91.  
  92.    *anchor = (PORT_REC far *)( (unsigned long)Selector<<16 );
  93.    *unhand = (*anchor + (*usernum));
  94.  
  95.    sprintf(semname,"\\SEM\\PG%02d%02d.BBS",*instance,*usernum);
  96.    rc = DosOpenSem(*(&sem),semname);
  97.    if( rc )
  98.       return(5);
  99.    return(0);
  100. }
  101.  
  102.  
  103. //
  104. //  SerWritef()
  105. //
  106. //  Garden variety printf() type function. 
  107. //
  108. SerWritef(PORT_REC *unhand, char *fmt, ...)
  109. {
  110.    char buffer[255];
  111.    va_list arg_ptr;
  112.    va_start(arg_ptr,fmt);
  113.    vsprintf(buffer,fmt,arg_ptr);
  114.    va_end(arg_ptr);
  115.    return(SerWrite(buffer,unhand));
  116. }
  117.  
  118. //
  119. //  CleanExit()
  120. //
  121. //  Makes sure everything is in order before terminating
  122. //  the program.
  123. //
  124. PFNEXITLIST CleanExit(USHORT code)
  125. {
  126.    fcloseall();
  127.    if( semhand ) {
  128.       DosSemClear(semhand);
  129.       DosCloseSem(semhand);
  130.    }   
  131.    DosExitList(EXLST_EXIT,0);
  132. }
  133.  
  134.