home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / videotlk.zip / SAMPLES / EX2 / REGION.C < prev    next >
Text File  |  1995-08-30  |  4KB  |  139 lines

  1.  
  2. /*------------------------------------------------------------------*
  3.  *                                                                  *
  4.  *  Video Toolkit For OS/2 Version 1.0                              *
  5.  *  Example PM Application No. 2.                                   *
  6.  *  Written by Stephen Sloan.                                       *
  7.  *  Date : 22/02/95.                                                *
  8.  *  Copyright (c) Abbotsbury Software Ltd., United Kingdom. 1995.   *
  9.  *                                                                  *
  10.  *  Filename : region.c                                             *
  11.  *                                                                  *
  12.  *------------------------------------------------------------------*/
  13.  
  14. #define     INCL_PM
  15. #define     INCL_DOS
  16. #define     INCL_SW
  17. #define     INCL_OS2MM
  18. #ifndef DIM
  19. #define DIM(a)  (sizeof(a)/sizeof(a[0]))
  20. #endif
  21.  
  22. #include    <os2.h>
  23. #include    <os2me.h>
  24. #include    <stdio.h>
  25. #include    <stdlib.h>
  26. #include    <string.h>
  27. #include    <vcadd.h>
  28. #include    <vcai.h>
  29.  
  30. static  UCHAR   *Copyright =
  31.   "Copyright (c) Abbotsbury Software Ltd., UK. 1994-1995. All Rights Reserved";
  32.  
  33. extern  void    msg_box (UCHAR *txt, UCHAR *title, ULONG options);
  34.  
  35. UINT  Region_lowchannel;
  36. UINT  Region_highchannel;
  37. ULONG Region_frequencies[256];
  38.  
  39. static UINT   region_obtain_frequencies (HFILE region_file);
  40. static LONG   get_next_numeric (HFILE region_file);
  41.  
  42. ULONG get_region_data (PSZ filename)
  43. {
  44.     ULONG   count;
  45.     PSZ     pmmbase, penv = "MMBASE";
  46.     CHAR    name[256];
  47.     LONG    len;
  48.     APIRET  rc;
  49.     ULONG   action;
  50.     CHAR    txt[256];
  51.     HFILE   region_file;
  52.  
  53.         rc = DosOpen (filename,
  54.                       ®ion_file,
  55.                       &action,
  56.                       0L,
  57.                       FILE_NORMAL,
  58.                       OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
  59.                       OPEN_ACCESS_READONLY | OPEN_SHARE_DENYWRITE,
  60.                       0L);
  61.         if (rc)
  62.         {
  63.             sprintf (txt, "DosOpen Error %ld", rc);
  64.             msg_box (txt, "Error", MB_OK | MB_ERROR);
  65.             return 0;
  66.         }
  67.  
  68.         Region_lowchannel = (UINT) get_next_numeric (region_file);
  69.         Region_highchannel = (UINT) get_next_numeric (region_file);
  70.         count = region_obtain_frequencies (region_file);
  71.  
  72.         DosClose (region_file);
  73.  
  74.         return count;
  75. }
  76.  
  77. static LONG get_next_numeric (HFILE region_file)
  78. {
  79.     LONG value;
  80.     CHAR textval[8];
  81.     INT  pos, c;
  82.     CHAR    ch[2];
  83.     ULONG   bytes_read;
  84.     APIRET  rc;
  85.  
  86.         ch[0] = '\0';
  87.         DosRead (region_file, ch, 1L, &bytes_read);
  88.         while ((ch[0] < '0') || (ch[0] > '9'))
  89.         {
  90.             DosRead (region_file, ch, 1L, &bytes_read);
  91.             if (bytes_read == 0)
  92.                 break;
  93.         }
  94.         pos = 0;
  95.         textval[pos++] = ch[0];
  96.         while ((ch[0] >= '0') && (ch[0] <= '9') && (bytes_read != 0))
  97.         {
  98.             DosRead (region_file, ch, 1L, &bytes_read);
  99.             if (bytes_read == 0)
  100.                 break;
  101.             textval[pos++] = ch[0];
  102.         }
  103.  
  104.         value = atol (textval);
  105.  
  106.         return value;
  107. }
  108.  
  109. static UINT region_obtain_frequencies (HFILE region_file)
  110. {
  111.     UINT freq_count = 0x00;
  112.     CHAR textval[8];
  113.     INT  pos, c = 0x00;
  114.     CHAR    ch[2];
  115.     ULONG   bytes_read;
  116.  
  117.         do
  118.         {
  119.             do
  120.             {
  121.                 DosRead (region_file, ch, 1L, &bytes_read);
  122.             } while (((ch[0] < '0') || (ch[0] > '9')) && (bytes_read != 0) && (ch[0] != '-'));
  123.  
  124.             if (bytes_read == 0)
  125.                 continue;
  126.  
  127.             pos = 0;
  128.             do
  129.             {
  130.                 textval[pos++] = ch[0];
  131.                 DosRead (region_file, ch, 1L, &bytes_read);
  132.             } while ((ch[0] >= '0') && (ch[0] <= '9') && (bytes_read != 0));
  133.             textval[pos] = '\0';
  134.             Region_frequencies[freq_count++] = atol (textval);
  135.         } while (bytes_read != 0);
  136.  
  137.         return freq_count;
  138. }
  139.