Ignore:
Timestamp:
Jul 5, 2002, 9:13:36 AM (23 years ago)
Author:
umoeller
Message:

Second round of fixes for 0.9.19.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/syssound.c

    r167 r184  
    2121 *      These are the general flags in the "MMPM2_AlarmSoundsData"
    2222 *      application:
     23 *
    2324 *      --  If "EnableSounds" is FALSE, all system sounds are disabled.
    2425 *          This defaults to TRUE (tested).
     26 *
    2527 *      --  If "ApplyVolumeToAll" is TRUE, the same volume is used for
    2628 *          all sounds. This defaults to FALSE (tested).
     29 *
    2730 *      --  If ApplyVolumeToAll is TRUE, "Volume" is used for the
    2831 *          global volume. Otherwise, the individual sound volumes
     
    3437 *
    3538 *      Each sound data block in there consists of three elements:
     39 *
    3640 +          soundfile#description#volume
     41 *
    3742 *      where "description" is what is listed in the "Sound" object.
    3843 *      "volume" is only used when "ApplyVolumeToAll" (above) is FALSE.
     
    114119 *
    115120 *@@added V0.9.0 [umoeller]
    116  */
    117 
    118 ULONG sndParseSoundData(PSZ pszSoundData,  // in: INI data from MMPM.INI
     121 *@@changed V0.9.20 (2002-07-03) [umoeller]: optimized
     122 */
     123
     124ULONG sndParseSoundData(PCSZ pszSoundData,  // in: INI data from MMPM.INI
    119125                        PSZ pszDescr,    // out: sound description, as displayed
    120126                               // in the "Sound" object (ptr may be NULL)
     
    124130                               // even if "Global volume" is set in MMPM.INI.
    125131{
    126     PSZ         p1 = pszSoundData, p2;
     132    PCSZ        p1 = pszSoundData, p2;
    127133    ULONG       ulrc = 0;
    128134    // get sound file
    129     p2 = strchr(p1, '#');
    130     if (p2)
     135    if (p2 = strchr(p1, '#'))
    131136    {
    132137        ulrc++;
    133138        if (pszFile)
    134139        {
    135             strncpy(pszFile, p1, p2-p1);
     140            strncpy(pszFile, p1, p2 - p1);
    136141            pszFile[p2-p1] = '\0';
    137142        }
     
    139144
    140145        // get sound description
    141         p2 = strchr(p1, '#');
    142         if (p2)
     146        if (p2 = strchr(p1, '#'))
    143147        {
    144148            ulrc++;
     
    154158            {
    155159                // individual volume settings per sound
    156                 sscanf(p1, "%lu", pulVolume);
     160                *pulVolume = atoi(p1);      // V0.9.20 (2002-07-03) [umoeller]
     161                // sscanf(p1, "%lu", pulVolume);
    157162                ulrc++;
    158163            }
     
    160165    }
    161166
    162     return (ulrc);
     167    return ulrc;
    163168}
    164169
     
    173178VOID sndQueryMmpmIniPath(PSZ pszMMPM)       // out: fully q'fied MMPM.INI
    174179{
    175     PSZ     pszMMPMPath = getenv("MMBASE"); // V0.9.6 (2000-10-16) [umoeller]
    176     if (pszMMPMPath)
     180    PSZ pszMMPMPath;
     181    if (pszMMPMPath = getenv("MMBASE"))  // V0.9.6 (2000-10-16) [umoeller]
    177182    {
    178183        // variable set:
     
    182187
    183188        // kill semicolon if present
    184         p = strchr(pszMMPM, ';');
    185         if (p)
     189        if (p = strchr(pszMMPM, ';'))
    186190           *p = 0;
    187191
     
    211215    HAB     habDesktop = WinQueryAnchorBlock(HWND_DESKTOP);
    212216    CHAR    szMMPM[CCHMAXPATH];
    213     HINI    hini = NULLHANDLE;
    214217
    215218    sndQueryMmpmIniPath(szMMPM);
    216219
    217     hini = PrfOpenProfile(habDesktop, szMMPM);
    218     return (hini);
     220    return PrfOpenProfile(habDesktop, szMMPM);
    219221}
    220222
     
    324326    }
    325327
    326     return (rc);
     328    return rc;
    327329}
    328330
     
    345347BOOL sndWriteSoundData(HINI hiniMMPM,       // in: MMPM.INI handle (from sndOpenMmpmIni)
    346348                       USHORT usIndex,      // in: sound index
    347                        PSZ pszDescr,        // in: sound name or NULL for removal
    348                        PSZ pszFile,         // in: sound file
     349                       PCSZ pszDescr,       // in: sound name or NULL for removal
     350                       PCSZ pszFile,        // in: sound file
    349351                       ULONG ulVolume)      // in: sound volume
    350352{
     
    359361        sprintf(szData, "%s#%s#%lu", pszFile, pszDescr, ulVolume);
    360362        brc = PrfWriteProfileString(hiniMMPM,
    361                                     MMINIKEY_SYSSOUNDS, szKey,
     363                                    MMINIKEY_SYSSOUNDS,
     364                                    szKey,
    362365                                    szData);
    363366    }
     
    366369        // delete entry
    367370        brc = PrfWriteProfileString(hiniMMPM,
    368                                     MMINIKEY_SYSSOUNDS, szKey,
     371                                    MMINIKEY_SYSSOUNDS,
     372                                    szKey,
    369373                                    NULL);
    370374
     
    396400BOOL sndSetSystemSound(HAB hab,
    397401                       USHORT usIndex,
    398                        PSZ pszDescr,
    399                        PSZ pszFile,
     402                       PCSZ pszDescr,
     403                       PCSZ pszFile,
    400404                       ULONG ulVolume)
    401405{
    402406    BOOL    brc = FALSE;
    403     HINI    hiniMMPM = sndOpenMmpmIni(hab);
    404     if (hiniMMPM)
     407    HINI    hiniMMPM;
     408    if (hiniMMPM = sndOpenMmpmIni(hab))
    405409    {
    406410        brc = sndWriteSoundData(hiniMMPM, usIndex, pszDescr, pszFile, ulVolume);
    407411        PrfCloseProfile(hiniMMPM);
    408412    }
     413
    409414    return brc;
    410415}
     
    415420 *      in OS2SYS.INI.
    416421 *
     422 *      If so, and *ppszRealScheme is != NULL, it
     423 *      is set to the key name found. Since the
     424 *      scheme names are case-insensitive, this
     425 *      check is necessary to delete the original
     426 *      scheme for overwrites. The caller is
     427 *      responsible for free()ing *ppszRealScheme
     428 *      then.
     429 *
    417430 *@@added V0.9.0 [umoeller]
    418  */
    419 
    420 BOOL sndDoesSchemeExist(PSZ pszScheme)
    421 {
     431 *@@changed V0.9.20 (2002-07-03) [umoeller]: check has to be case-insensitive, fixed; changed prototype
     432 */
     433
     434BOOL sndDoesSchemeExist(PCSZ pcszScheme,
     435                        PSZ *ppszRealScheme)    // out: actual key name (ptr can be NULL)
     436{
     437    BOOL fExists = FALSE;
     438    PSZ pszKeysList;
     439    if (!prfhQueryKeysForApp(HINI_SYSTEM,
     440                             MMINIKEY_SOUNDSCHEMES,  // "PM_SOUND_SCHEMES_LIST"
     441                             &pszKeysList))
     442    {
     443        PSZ pKey2 = pszKeysList;
     444        while (*pKey2)
     445        {
     446            if (!stricmp(pKey2, pcszScheme))
     447            {
     448                fExists = TRUE;
     449
     450                if (ppszRealScheme)
     451                    *ppszRealScheme = strdup(pKey2);
     452
     453                break;
     454            }
     455
     456            pKey2 += strlen(pKey2)+1; // next key
     457        }
     458
     459        free(pszKeysList);
     460    }
     461
     462    return fExists;
     463
     464    /* old code V0.9.20 (2002-07-03) [umoeller]
    422465    // check in OS2SYS.INI's scheme list whether that
    423466    // scheme exists already
     
    433476
    434477    return (FALSE);
     478    */
     479
    435480}
    436481
     
    453498
    454499APIRET sndCreateSoundScheme(HINI hiniMMPM,      // in: MMPM.INI handle (from sndOpenMmpmIni)
    455                             PSZ pszNewScheme)   // in: name of new scheme
     500                            PCSZ pszNewScheme)  // in: name of new scheme
    456501{
    457502    APIRET  arc = NO_ERROR;
     
    489534                // file name and append the volume...
    490535
    491                 PSZ pSoundData = prfhQueryProfileData(hiniMMPM,
     536                PSZ pSoundData;
     537                if (pSoundData = prfhQueryProfileData(hiniMMPM,
    492538                                                      MMINIKEY_SYSSOUNDS, // "MMPM2_AlarmSounds"
    493539                                                      pKey2,
    494                                                       NULL);
    495                 if (pSoundData)
     540                                                      NULL))
    496541                {
    497542                    sndParseSoundData(pSoundData,
     
    521566            PrfWriteProfileString(HINI_SYSTEM,
    522567                                  MMINIKEY_SOUNDSCHEMES,  // "PM_SOUND_SCHEMES_LIST"
    523                                   pszNewScheme,      // key is scheme name
     568                                  (PSZ)pszNewScheme,      // key is scheme name
    524569                                  szNewAppName);    // data is new OS2SYS.INI application
    525570        }
     
    562607
    563608APIRET sndLoadSoundScheme(HINI hiniMMPM,      // in: HINI of ?:\MMOS2\MMPM.INI (PrfOpenProfile)
    564                           PSZ pszScheme)      // in: scheme name
     609                          PCSZ pszScheme)     // in: scheme name
    565610{
    566611    APIRET arc = NO_ERROR;
     
    702747 */
    703748
    704 APIRET sndDestroySoundScheme(PSZ pszScheme)
     749APIRET sndDestroySoundScheme(PCSZ pszScheme)
    705750{
    706751    APIRET arc = NO_ERROR;
    707752
    708753    // check in OS2SYS.INI's scheme list whether that
    709     // scheme exists already
    710     PSZ pszExisting = prfhQueryProfileData(HINI_SYSTEM,
     754    // scheme exists
     755    PSZ pszExisting;
     756    if (pszExisting = prfhQueryProfileData(HINI_SYSTEM,
    711757                                           MMINIKEY_SOUNDSCHEMES,  // "PM_SOUND_SCHEMES_LIST"
    712758                                           pszScheme,
    713                                            NULL);
    714     if (pszExisting)
     759                                           NULL))
    715760    {
    716761        // delete whole existing PM_SOUNDS_BLAHBLAH application
     
    722767        PrfWriteProfileString(HINI_SYSTEM,
    723768                              MMINIKEY_SOUNDSCHEMES,  // "PM_SOUND_SCHEMES_LIST"
    724                               pszScheme,
     769                              (PSZ)pszScheme,
    725770                              NULL);
    726771        free(pszExisting);
Note: See TracChangeset for help on using the changeset viewer.