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

  1.  
  2. /*------------------------------------------------------------------*
  3.  *                                                                  *
  4.  *  Video Toolkit For OS/2 Version 1.0                              *
  5.  *  Example PM Application No. 3.                                   *
  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.  
  31. extern  void    msg_box (UCHAR *txt, UCHAR *title, ULONG options);
  32.  
  33. UINT    Region_lowchannel;
  34. UINT    Region_highchannel;
  35. ULONG   Region_frequencies[256];
  36.  
  37. static  UINT    region_obtain_frequencies (HFILE region_file);
  38. static  LONG    get_next_numeric (HFILE region_file);
  39.  
  40. static  UCHAR   *Copyright =
  41.   "Copyright (c) Abbotsbury Software Ltd., UK. 1994-1995. All Rights Reserved";
  42.  
  43. ULONG get_region_data (PSZ filename)
  44. {
  45.     ULONG   count;
  46.     PSZ     pmmbase, penv = "MMBASE";
  47.     CHAR    name[256];
  48.     LONG    len;
  49.     APIRET  rc;
  50.     ULONG   action;
  51.     CHAR    txt[256];
  52.     HFILE   region_file;
  53.  
  54.         rc = DosOpen (filename,
  55.                       ®ion_file,
  56.                       &action,
  57.                       0L,
  58.                       FILE_NORMAL,
  59.                       OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
  60.                       OPEN_ACCESS_READONLY | OPEN_SHARE_DENYWRITE,
  61.                       0L);
  62.         if (rc)
  63.         {
  64.             sprintf (txt, "DosOpen Error %ld", rc);
  65.             msg_box (txt, "Error", MB_OK | MB_ERROR);
  66.             return 0;
  67.         }
  68.  
  69.         Region_lowchannel = (UINT) get_next_numeric (region_file);
  70.         Region_highchannel = (UINT) get_next_numeric (region_file);
  71.         count = region_obtain_frequencies (region_file);
  72.  
  73.         DosClose (region_file);
  74.  
  75.         return count;
  76. }
  77.  
  78. static LONG get_next_numeric (HFILE region_file)
  79. {
  80.     LONG value;
  81.     CHAR textval[8];
  82.     INT  pos, c;
  83.     CHAR    ch[2];
  84.     ULONG   bytes_read;
  85.     APIRET  rc;
  86.  
  87.         ch[0] = '\0';
  88.         DosRead (region_file, ch, 1L, &bytes_read);
  89.         while ((ch[0] < '0') || (ch[0] > '9'))
  90.         {
  91.             DosRead (region_file, ch, 1L, &bytes_read);
  92.             if (bytes_read == 0)
  93.                 break;
  94.         }
  95.         pos = 0;
  96.         textval[pos++] = ch[0];
  97.         while ((ch[0] >= '0') && (ch[0] <= '9') && (bytes_read != 0))
  98.         {
  99.             DosRead (region_file, ch, 1L, &bytes_read);
  100.             if (bytes_read == 0)
  101.                 break;
  102.             textval[pos++] = ch[0];
  103.         }
  104.  
  105.         value = atol (textval);
  106.  
  107.         return value;
  108. }
  109.  
  110. static UINT region_obtain_frequencies (HFILE region_file)
  111. {
  112.     UINT freq_count = 0x00;
  113.     CHAR textval[8];
  114.     INT  pos, c = 0x00;
  115.     CHAR    ch[2];
  116.     ULONG   bytes_read;
  117.  
  118.         do
  119.         {
  120.             do
  121.             {
  122.                 DosRead (region_file, ch, 1L, &bytes_read);
  123.             } while (((ch[0] < '0') || (ch[0] > '9')) && (bytes_read != 0) && (ch[0] != '-'));
  124.  
  125.             if (bytes_read == 0)
  126.                 continue;
  127.  
  128.             pos = 0;
  129.             do
  130.             {
  131.                 textval[pos++] = ch[0];
  132.                 DosRead (region_file, ch, 1L, &bytes_read);
  133.             } while ((ch[0] >= '0') && (ch[0] <= '9') && (bytes_read != 0));
  134.             textval[pos] = '\0';
  135.             Region_frequencies[freq_count++] = atol (textval);
  136.         } while (bytes_read != 0);
  137.  
  138.         return freq_count;
  139. }
  140.