home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1996 October / PCO_10.ISO / filesbbs / bsrc_260.arj / SRC.ZIP / dosfuncs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-23  |  10.0 KB  |  454 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*              (C) Copyright 1987-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*                This module was written by Vince Perriello                */
  13. /*                   OS/2 code contributed by Bill Andrus                   */
  14. /*             DOS and OS/2 kernel routines used by BinkleyTerm             */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. /* Include this file before any other includes or defines! */
  45.  
  46. #include "includes.h"
  47.  
  48. #ifdef DOS16                    /* Here's the DOS stuff */
  49.  
  50. void 
  51. dostime (int *hour, int *min, int *sec, int *hdths)
  52. {
  53.     union REGS r;
  54.  
  55.     r.h.ah = 0x2c;
  56.  
  57.     (void) intdos (&r, &r);
  58.  
  59.     *hour = r.h.ch;
  60.     *min = r.h.cl;
  61.     *sec = r.h.dh;
  62.     *hdths = r.h.dl;
  63. }
  64.  
  65. void 
  66. dos_break_off (void)
  67. {
  68.     union REGS r;
  69.  
  70.     r.x.ax = 0x3301;
  71.     r.h.dl = 0x00;
  72.  
  73.     (void) intdos (&r, &r);
  74. }
  75.  
  76. void 
  77. mtask_find ()
  78. {
  79.     char *p, *q;
  80.  
  81.     for (;;)
  82.     {
  83.         if (have_ml)
  84.         {
  85.             if ((have_ml = ml_active ()) != 0)
  86.             {
  87.                 p = "MultiLink";
  88.                 mtask_idle = ml_pause;
  89.                 break;
  90.             }
  91.         }
  92.  
  93.         if (have_tv)
  94.         {
  95.             if ((have_tv = tv_get_version ()) != 0)
  96.             {
  97.                 p = "T-View";
  98.                 mtask_idle = tv_pause;
  99.                 break;
  100.             }
  101.         }
  102.  
  103.         if ((have_dv = dv_get_version ()) != 0)
  104.         {
  105.             p = "DESQview";
  106.             mtask_idle = dv_pause;
  107.             break;
  108.         }
  109.  
  110.         if ((have_mos = mos_active ()) != 0)
  111.         {
  112.             p = "PC-MOS";
  113.             mtask_idle = mos_pause;
  114.             break;
  115.         }
  116.  
  117.         if ((have_ddos = ddos_active ()) != 0)
  118.         {
  119.             p = "DoubleDOS";
  120.             mtask_idle = ddos_pause;
  121.             break;
  122.         }
  123.  
  124.         if (_osmajor >= 10)
  125.         {
  126.             p = "OS/2-DOS";
  127.             mtask_idle = windows_pause;    /* OS/2 weenies will love this! */
  128.             break;
  129.         }
  130.  
  131.         if ((have_windows = windows_active ()) != 0)
  132.         {
  133.             p = "Windows";
  134.             if (winslice)
  135.                 mtask_idle = windows_pause;
  136.             else
  137.                 mtask_idle = msdos_pause;
  138.             break;
  139.         }
  140.         /* else */
  141.         {
  142.             p = "None";
  143.             mtask_idle = msdos_pause;
  144.             break;
  145.         }
  146.     }
  147.  
  148.     if ((q = calloc (1, 1 + strlen (p))) == NULL)
  149.         exit (254);
  150.  
  151.     (void) strcpy (mtask_name = q, p);
  152. }
  153.  
  154. void 
  155. set_prior (int pclass)
  156. {
  157.     happy_compiler = pclass;    /* This makes compilers happy! */
  158.     return;
  159. }
  160.  
  161. #endif
  162. #ifdef OS_2                        /* here's the OS/2 stuff */
  163. #ifdef Snoop
  164. #include "snserver.h"
  165. HSNOOP hsnoop = (HSNOOP) 0L;
  166.  
  167. #endif
  168.  
  169. void 
  170. dostime (int *hour, int *min, int *sec, int *hdths)
  171. {
  172.     DATETIME dt;
  173.  
  174.     DosGetDateTime (&dt);
  175.     *hour = dt.hours;            /* current hour */
  176.     *min = dt.minutes;            /* current minute */
  177.     *sec = dt.seconds;            /* current second */
  178.     *hdths = dt.hundredths;        /* current hundredths of a second */
  179. }
  180.  
  181. void 
  182. dos_break_off (void)
  183. {
  184.     /*
  185.   * The problem which dos_break_off was trying to address
  186.   * was a funny with computers like the Sanyo and the DEC
  187.   * Rainbow, where ^C checking in DOS would screw up the
  188.   * FOSSIL's ability to get keystrokes. So while we could
  189.   * emulate the functionality of the DOS side, there is no
  190.   * need to do so. So we won't.
  191.   */
  192. }
  193.  
  194. void _cdecl 
  195. os2_pause (void)
  196. {
  197.     DosSleep (1L);
  198. }
  199.  
  200. void 
  201. mtask_find ()
  202. {
  203.     char *p, *q;
  204.  
  205.     if (_osmode == DOS_MODE)
  206.         p = "None";
  207.     else
  208.         p = "OS/2";
  209.     mtask_idle = os2_pause;
  210.  
  211.     if ((q = calloc (1, 1 + strlen (p))) == NULL)
  212.         exit (254);
  213.  
  214.     (void) strcpy (mtask_name = q, p);
  215. }
  216.  
  217. #ifdef NEED_WRITE_ANSI
  218. void 
  219. WRITE_ANSI (char c)
  220. {
  221.     static char s[] =
  222.     {'\0', '\0'};
  223.  
  224.     *s = c;
  225.  
  226.     (void) VioWrtTTY (s, 1, (HVIO) 0L);
  227. }
  228.  
  229. #endif
  230.  
  231. void 
  232. set_prior (int pclass)
  233. {
  234. #ifdef NEED_SET_PRIOR
  235.     char *s;
  236.     static USHORT regular = 0;
  237.     static USHORT janus = 0;
  238.     static USHORT modem = 0;
  239.     USHORT priority;
  240.  
  241.     switch (pclass)
  242.     {
  243.     case 2:
  244.         if (regular)
  245.             priority = regular;
  246.         else
  247.         {
  248.             s = getenv ("REGULARPRIORITY");
  249.             if (s)
  250.                 priority = regular = atoi (s);
  251.             else
  252.                 priority = regular = 2;
  253.         }
  254.         break;
  255.  
  256.     case 3:
  257.         if (janus)
  258.             priority = janus;
  259.         else
  260.         {
  261.             s = getenv ("JANUSPRIORITY");
  262.             if (s)
  263.                 priority = janus = atoi (s);
  264.             else
  265.                 priority = janus = 3;
  266.         }
  267.         break;
  268.  
  269.     case 4:
  270.         if (modem)
  271.             priority = modem;
  272.         else
  273.         {
  274.             s = getenv ("MODEMPRIORITY");
  275.             if (s)
  276.                 priority = modem = atoi (s);
  277.             else
  278.                 priority = modem = 4;
  279.         }
  280.         break;
  281.  
  282.     default:
  283.         priority = 2;
  284.         break;
  285.     }
  286.  
  287.     (void) DosSetPrty ((USHORT) 1, priority, (SHORT) 31, (USHORT) 0);
  288. #else
  289.     happy_compiler = pclass;    /* This makes compilers happy! */
  290. #endif
  291. }
  292.  
  293. #ifdef Snoop
  294. #ifdef __32BIT__                    /* MB 93-11-27 */
  295. static short _Far16 _Pascal
  296. mesgfunc (short error, char * _Seg16 _Far16 mesg)
  297. {
  298.     if (!error)
  299.     {
  300.         if (debugging_log)
  301.             status_line (">%s", (char *) mesg);
  302.     }
  303.     else
  304.         status_line ("!SYS%04hd : %s", error, (char *) mesg);
  305.     return (0);
  306. }
  307.  
  308. #else    /* #ifdef __32BIT__  */
  309.  
  310. #pragma check_stack(off)
  311. static int far pascal _loadds 
  312. mesgfunc (int error, char far * mesg)
  313. {
  314.     if (!error)
  315.         status_line (":%Fs", mesg);
  316.     else
  317.         status_line ("!SYS%04u : %Fs", error, mesg);
  318.     return (0);
  319. }
  320.  
  321. #pragma check_stack()
  322. #endif    /* #ifdef __32BIT__  */ 
  323.  
  324. void 
  325. snoop_open (char *callpipename)
  326. {
  327.     static char *pipe = NULL;
  328.  
  329.     if (pipe != NULL)
  330.         free (pipe);
  331.     /* if((*callpipename != '\0') && (callpipename != NULL) && (hsnoop == (HSNOOP)0L)) */
  332.     pipe = strdup (callpipename);
  333.     SnoopOpen ((PSZ) pipe, &hsnoop, (PSZ) xfer_id, (PFNSN) mesgfunc);
  334. }
  335.  
  336. void 
  337. snoop_close (void)
  338. {
  339.     if (hsnoop != (HSNOOP) 0L)
  340.         SnoopClose (hsnoop);
  341.     hsnoop = (HSNOOP) 0L;
  342. }
  343.  
  344. #endif                            /* Snoop */
  345. #endif                            /* OS_2 */
  346.  
  347. #ifdef _WIN32
  348.  
  349. /* From header files */
  350.  
  351. typedef struct _SYSTEMTIME {
  352.     unsigned short wYear;
  353.     unsigned short wMonth;
  354.     unsigned short wDayOfWeek;
  355.     unsigned short wDay;
  356.     unsigned short wHour;
  357.     unsigned short wMinute;
  358.     unsigned short wSecond;
  359.     unsigned short wMilliseconds;
  360. } SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
  361.  
  362. void WINAPI
  363. GetLocalTime (LPSYSTEMTIME lpSystemTime);
  364. void WINAPI
  365. Sleep (long dwMilliseconds);
  366.  
  367. void 
  368. dostime (int *hour, int *min, int *sec, int *hdths)
  369. {
  370.     SYSTEMTIME st;
  371.  
  372.     GetLocalTime (&st);
  373.  
  374.     *hdths = st.wMilliseconds / 10;
  375.     *hour = st.wHour;
  376.     *min = st.wMinute;
  377.     *sec = st.wSecond;
  378. }
  379.  
  380. void 
  381. dos_break_off (void)
  382. {
  383.     /*
  384.   * The problem which dos_break_off was trying to address
  385.   * was a funny with computers like the Sanyo and the DEC
  386.   * Rainbow, where ^C checking in DOS would screw up the
  387.   * FOSSIL's ability to get keystrokes. So while we could
  388.   * emulate the functionality of the DOS side, there is no
  389.   * need to do so. So we won't.
  390.   */
  391. }
  392.  
  393. void _cdecl 
  394. Win32_pause (void)
  395. {
  396.     (void) Sleep (1L);
  397. }
  398.  
  399. extern char *SzVersionString();
  400.  
  401. void 
  402. mtask_find ()
  403. {
  404.     char *p, *q;
  405.  
  406.     p = SzVersionString();
  407.  
  408.     mtask_idle = Win32_pause;
  409.  
  410.     if ((q = calloc (1, 1 + strlen (p))) == NULL)
  411.         exit (254);
  412.  
  413.     (void) strcpy (mtask_name = q, p);
  414. }
  415.  
  416. void 
  417. set_prior (int pclass)
  418. {
  419.     happy_compiler = pclass;    /* This makes compilers happy! */
  420. }
  421.  
  422. #endif                            /* _WIN32 */
  423.  
  424. #ifdef NEED_CPUTS
  425. int _cdecl 
  426. cputs (const char *str)
  427. {
  428.     printf ("%s", str);
  429.     return 0;
  430. }
  431.  
  432. #endif
  433.  
  434. #ifdef NEED_PUTCH
  435. int _cdecl 
  436. putch (int ch)
  437. {
  438.     return putchar (ch);
  439. }
  440.  
  441. #endif
  442.  
  443. #ifdef NEED_CPRINTF
  444. int _cdecl 
  445. cprintf (const char *format,...)
  446. {
  447.     va_list arg_ptr;
  448.  
  449.     va_start (arg_ptr, format);
  450.     return vprintf (format, arg_ptr);
  451. }
  452.  
  453. #endif
  454.