home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / rxwavsrc.zip / RxWavUtil.c < prev    next >
C/C++ Source or Header  |  2000-03-06  |  4KB  |  150 lines

  1. /*  RxWav
  2.    Copyright (C) 1999  Giorgio Vicario
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2 of the License, or
  7.    (at your option) any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA     */
  17.  
  18. #define INCL_REXXSAA
  19. #include <os2emx.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <regexp.h>
  24. #include <math.h>
  25. #include <float.h>
  26. #include "RxWav.h"
  27.  
  28. /***********************************************************************
  29. Altre funzioni di utilita'
  30. ***********************************************************************/
  31. BOOL
  32. string2long (PSZ string, LONG * number)
  33. {
  34.   ULONG accumulator;        /* converted number           */
  35.   INT length;            /* length of number           */
  36.   INT sign;            /* sign of number             */
  37.  
  38.   sign = 1;            /* set default sign           */
  39.   if (*string == '-')
  40.     {                /* negative?
  41.                    sign = -1;                         /* change sign                */
  42.       string++;            /* step past sign             */
  43.     }
  44.  
  45.   length = strlen (string);    /* get length of string       */
  46.   if (length == 0 ||        /* if null string             */
  47.       length > MAX_DIGITS)    /* or too long                */
  48.     return FALSE;        /* not valid                  */
  49.  
  50.   accumulator = 0;        /* start with zero            */
  51.  
  52.   while (length)
  53.     {                /* while more digits          */
  54.       if (!isdigit (*string))    /* not a digit?               */
  55.     return FALSE;        /* tell caller                */
  56.       /* add to accumulator         */
  57.       accumulator = accumulator * 10 + (*string - '0');
  58.       length--;            /* reduce length              */
  59.       string++;            /* step pointer               */
  60.     }
  61.   *number = accumulator * sign;    /* return the value           */
  62.   return TRUE;            /* good number                */
  63. }
  64.  
  65.  
  66. PSHORT
  67. AllineaCh (PSHORT pCh, ULONG nByte, ULONG func)
  68. {
  69.   PBYTE pCh8 = NULL;
  70.   ULONG pflag;
  71.   ULONG psize;
  72.   LONG p;
  73.   APIRET rc;
  74.  
  75.   psize = &nByte;
  76.   pflag = PAG_COMMIT | PAG_WRITE;
  77.  
  78.   rc = DosQueryMem (pCh, &psize, &pflag);
  79.   if (rc)
  80.     {
  81.       switch (rc)
  82.     {
  83.     case NO_ERROR:
  84.       break;
  85.     case ERROR_INVALID_ADDRESS:
  86.       SendMsg (func, ERR_TRACCIA_ERRATA);
  87.       return 0;
  88.       break;
  89.     default:
  90.       printf ("       DosQueryMem rc:%i\n", rc);
  91.       return 0;
  92.       break;
  93.     }
  94.     }
  95.  
  96.   p = (long) pCh *2;
  97.  
  98.   pCh = pCh + (nByte * 2) - 2;
  99.   psize = &nByte;
  100.   rc = DosQueryMem (pCh, &psize, &pflag);
  101.   if (rc)
  102.     {
  103.       switch (rc)
  104.     {
  105.     case NO_ERROR:
  106.       break;
  107.     case ERROR_INVALID_ADDRESS:
  108.       SendMsg (func, ERR_TRACCIA_INSUFFICIENTE);
  109.       return 0;
  110.       break;
  111.     default:
  112.       printf ("       DosQueryMem rc:%i\n", rc);
  113.       return 0;
  114.       break;
  115.     }
  116.     }
  117.  
  118.   return p;
  119. }
  120.  
  121.  
  122. int
  123. FetchStem (RXSTEMDATA stemin, float *dati)
  124. {
  125.   sprintf (stemin.varname + stemin.stemlen, "%d", stemin.count);
  126.  
  127.   stemin.shvb.shvnext = NULL;
  128.   stemin.shvb.shvvalue.strptr = stemin.ibuf;
  129.   stemin.shvb.shvvalue.strlength = MAX;
  130.   stemin.shvb.shvname.strptr = stemin.varname;
  131.   stemin.shvb.shvname.strlength = strlen (stemin.varname);
  132.   stemin.shvb.shvcode = RXSHV_FETCH;
  133.   stemin.shvb.shvret = 0;
  134.  
  135.   if (RexxVariablePool (&stemin.shvb) == RXSHV_BADN)
  136.     {
  137.       SendMsg (0, ERR_REXXPOOL);
  138.       return 0;
  139.     }
  140.  
  141.   if (stemin.shvb.shvret)
  142.     return stemin.shvb.shvret;
  143.  
  144.   strcpy (stemin.ibuf, stemin.shvb.shvvalue.strptr);
  145.  
  146.   *dati = atof (stemin.ibuf);
  147.   return 0;
  148.  
  149. }
  150.