www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/15/00:06:20

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Some qusestions
Date: Wed, 14 Jan 1998 19:40:36 -0500
Organization: Two pounds of chaos and a pinch of salt.
Lines: 77
Message-ID: <34BD5B04.C38@cs.com>
References: <34BCDB23 DOT 6A22 AT wxs DOT nl>
NNTP-Posting-Host: ppp219.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Nils van den Heuvel wrote:
> 
> Can i put a .jpg file in an allegro datafile and load it with
> load_jpeg()???? (I've got a library that works with allegro that does
> this)... Because when i did this it couldn't load the .jpg file...

Can't help you with this, but...

> And how do cut this string into little pieces:
>
> set ultrasnd=220,1,1,11,5

With getenv() and the string handling function of your choice.  Sample code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

/* reads comma-delimited numbers from specified environment
   string into an array of integers of size 'ntoread' */
/* returns number of settings found */
int get_sound_settings( const char *envname, int *settings, int ntoread )
{
    char *env, *p;
    int i;

    if ( ( env = getenv( envname ) ) == NULL )
    {
        fprintf( stderr, "get_sound_settings:  environment string '%s' not found.\n", 
                 envname );
        return 0;
    }

    /* The meat of the code:  strchr finds the next occurrence of a comma in
       the string.  At this point, env points to the start of the current
       portion of the string and p points to the comma at the end.  Read this
       item, then set env to the next part of the string (if there is one), or
       the end of the string (if not).  Also find the next part of the string 
       (if we are already at the end this won't change anything).  The test 
       shows when env reaches the end and stops the loop (or also if we run 
       out of numbers).
     */
    for ( i = 0, p = strchr( env, ',' ); 
          *env && i < ntoread;
          env = ( *p ? p + 1 : p ), p = strchr( env, ',' ), i++ )
    {
        if ( !isdigit( *env ) )
        {
            fprintf( stderr, "get_sound_settings:  invalid character '%c'.\n",
                     *env );
            return 0;
        }
        settings[i] = atoi( env );
    }

    return i;
}

This is compiled and tested; you can make whatever changes you need.

I should advise you, however, that most sound card settings use the 
format:  

  BLASTER=A220 I5 D1 H5 P330 T6 E620

This would require somewhat more advanced parsing code to read.

hth

-- 
---------------------------------------------------------------------
|      John M. Aldrich       | "Autocracy is based on the assumption|
|       aka Fighteer I       | that one man is wiser than a million |
|   mailto:fighteer AT cs DOT com   | men.  Let's play that over again,    |
| http://www.cs.com/fighteer | too.  Who decides?"   - Lazarus Long |
---------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019