home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c004 / 3.ddi / OS2LAN / CTDOSC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-18  |  5.1 KB  |  211 lines

  1. /*
  2.  *    OS/2 Lan Manager DOS Api calls for 
  3.  *      using named pipes version of c-tree server
  4.  *
  5.  *    This program is the CONFIDENTIAL and PROPRIETARY property 
  6.  *    of FairCom(R) Corporation. Any unauthorized use, reproduction or
  7.  *    transfer of this program is strictly prohibited.
  8.  *
  9.  *      Copyright (c) 1987, 1988, 1989 FairCom Corporation
  10.  *    (Subject to limited distribution and
  11.  *     restricted disclosure only.)
  12.  *    *** ALL RIGHTS RESERVED ***
  13.  *
  14.  *    4006 West Broadway
  15.  *    Columbia, MO 65203
  16.  *
  17.  *
  18.  *    c-tree(R)    Version 4.3
  19.  *            Release C
  20.  *            February 7, 1989 17:30
  21.  *
  22.  */
  23.  
  24. #define INCL_DOS
  25. #define INCL_DOSERRORS
  26. #include <os2def.h>       /* Common definitions */
  27. #include <bsedos.h>       /* Base definitions */
  28. #include <bseerr.h>       /* Base error code definitions */
  29.  
  30. #include <stdlib.h>
  31. #include <stdio.h>
  32. #include <string.h>
  33.  
  34. #include "ctpipes.h"
  35.  
  36. static void get_info_seg_pointers(void);
  37.  
  38. int fl_backgr_proc = 0;
  39.  
  40. int fl_infoseg_init = 0;
  41. static GINFOSEG FAR *pgs = 0L;
  42. static LINFOSEG FAR *pls = 0L;
  43.  
  44.  
  45. void set_max_file_handles(int maxfh)
  46. {
  47. int i;
  48.  
  49.    i = DosSetMaxFH(maxfh);
  50. /* if (i)
  51.      printf("SetMaxFH ERROR %d", i);   */
  52. }
  53.  
  54.  
  55. static void get_info_seg_pointers()
  56. {
  57. SEL selGlobalSeg, selLocalSeg;
  58.  
  59.    if (fl_infoseg_init)
  60.       return;
  61.    DosGetInfoSeg(&selGlobalSeg, &selLocalSeg);
  62.    pgs = MAKEPGINFOSEG(selGlobalSeg);
  63.    pls = MAKEPLINFOSEG(selLocalSeg);
  64.    fl_infoseg_init = 1;
  65. }
  66.  
  67.  
  68. int get_process_id()
  69. {
  70.    if (!fl_infoseg_init)
  71.       get_info_seg_pointers();
  72.  
  73.    return(pls->pidCurrent); /* return identifier of the current process.*/
  74. }
  75.  
  76.  
  77. /*
  78.  * Return type of process :
  79.  *        0 = Full screen
  80.  *        1 = Windowed appl
  81.  *        2 = Background
  82.  *        3 = Background OS2 1.0 (proc_id < max. screen groups)
  83.  *        9 = Other
  84.  */
  85. int get_process_type()
  86. {
  87. int proc_type = 0;
  88.  
  89.    if (!fl_infoseg_init)
  90.       get_info_seg_pointers();
  91.  
  92.   /*
  93.    * Process Type codes (local info seg typeProcess field)
  94.    * ONLY functionating in OS/2 1.1 (IBM EXTENDED EDITION)
  95.    *
  96.    * for OS/2 1.0 Process Type is always = 0 (PT_FULLSCREEN)
  97.    * 
  98.    * 
  99.    * Process Type codes (local info seg typeProcess field)
  100.    * #define PT_FULLSCREEN       0        Full screen app.
  101.    * #define PT_REALMODE         1        Real mode process
  102.    * #define PT_WINDOWABLEVIO    2        VIO windowable app.
  103.    * #define PT_PM               3        Presentation Manager app.
  104.    * #define PT_DETACHED         4        Detached app.
  105.    */
  106.    switch (pls->typeProcess) {
  107.       case PT_DETACHED:               /* Detached app. */
  108.            fl_backgr_proc = 1;
  109.            proc_type = 2;
  110.            if (pls->pidCurrent < pgs->sgMax)
  111.                /* proc_id < max. screen groups */
  112.               proc_type = 3;
  113.            break;
  114.       case PT_FULLSCREEN:             /* Full screen app. */
  115.            fl_backgr_proc = 0;
  116.            proc_type = 0;
  117.           /* if current screen group  == maximum number of screen groups,
  118.            * then background process.  NB! test ONLY valid for OS/2 1.0
  119.            */
  120.            if (pls->sgCurrent == pgs->sgMax) { 
  121.               fl_backgr_proc = 1;
  122.               proc_type = 2;
  123.               if (pls->pidCurrent < pgs->sgMax)
  124.                  /* proc_id < max. screen groups */
  125.                  proc_type = 3;
  126.            }
  127.            break;
  128.       case PT_WINDOWABLEVIO:          /* VIO windowable app. */
  129.            fl_backgr_proc = 0;
  130.            proc_type = 1;
  131.            break;
  132.       case PT_REALMODE:               /* Real mode process */
  133.       case PT_PM:                     /* Presentation Manager app. */
  134.       default:
  135.            fl_backgr_proc = 0;
  136.            proc_type = 9;
  137.            break;
  138.    }
  139.        
  140.    return(proc_type); /* return process type */
  141. }
  142.  
  143.  
  144. int get_curr_screen_group()
  145. {
  146.  
  147.    if (!fl_infoseg_init)
  148.       get_info_seg_pointers();
  149.  
  150.    return(pls->sgCurrent);     /* return current screen group */
  151.        
  152. }
  153.  
  154. /*
  155.  * Return type of OS/2 operating system:
  156.  *        0 = OS/2 1.0 med 3Com Named Pipes 
  157.  *        1 = OS/2 1.1 Standard or Extended Edition
  158.  *        9 = newer versions not supported
  159.  */
  160. int get_os2_version()
  161. {
  162. USHORT versj = 0; 
  163. unsigned major, minor;
  164.  
  165.    if (DosGetVersion(&versj))
  166.       return 9;
  167.    major = ((versj & 0xff00) >> 8);
  168.    minor =  (versj & 0x00ff);
  169.    if (major > 10)
  170.       return 9;
  171.    if (major == 10 && minor >= 10)
  172.       return 1;
  173.    return 0;
  174. }
  175.  
  176.  
  177. /*
  178.  *  Copy of memory blocks from different segments
  179.  *
  180.  *  The stfarmov function copies a number of bytes from the first
  181.  *  string into the second string's allocated space.
  182.  *  returns number of bytes copied.
  183.  * 
  184.  *  NOTE: destination must have allocated
  185.  *        at least n number of bytes
  186.  *
  187.  */
  188. unsigned stfarmov(char far *src, char far *dest, unsigned n)
  189. {
  190. unsigned count = 0;
  191.  
  192.    if (n) {
  193.       while (n-- > 0) {
  194.          *dest++ = *src++;
  195.          count++;
  196.       }
  197.    }
  198.    else
  199.      /*
  200.       * No number of bytes specified copy unit NULL character
  201.       */
  202.       while (*src) {
  203.          *dest++ = *src++;
  204.          count++;
  205.       }
  206.  
  207.    return count;
  208.  
  209. } /* end stfarmov */
  210.  
  211.