1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
/*
* Copyright (c) 2000 Andrew Ferguson <andrew@owsla.cjb.net>
* Copyright (c) 1998 Sasha Vasko <sasha at aftercode.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#define LOCAL_DEBUG
#include "../configure.h"
#include "../libAfterStep/asapp.h"
#include "../libAfterStep/afterstep.h"
#include "../libAfterStep/parser.h"
#include "../libAfterStep/hints.h"
// :sG:!! Change to ALSA:
#ifdef HAVE_RPLAY_H
#include <rplay.h>
#endif
#include "afterconf.h"
/*****************************************************************************
*
* This routine is responsible for reading and parsing the config file
*
****************************************************************************/
TermDef EventTerms[] = {
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "add_window", 10, TT_FILENAME, EVENT_WindowAdded_ID , NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "window_names", 8, TT_FILENAME, EVENT_WindowNames_ID , NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "destroy_window", 14, TT_FILENAME, EVENT_WindowDestroyed_ID , NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "focus_change", 12, TT_FILENAME, EVENT_WindowActivated_ID , NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "raise_window", 12, TT_FILENAME, EVENT_WindowRaised_ID , NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "iconify", 7, TT_FILENAME, EVENT_WindowIconified_ID , NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "deiconify", 9, TT_FILENAME, EVENT_WindowDeiconified_ID , NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "shade", 5, TT_FILENAME, EVENT_WindowShaded_ID , NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "unshade", 7, TT_FILENAME, EVENT_WindowUnshaded_ID , NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "stick", 5, TT_FILENAME, EVENT_WindowStuck_ID , NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "unstick", 7, TT_FILENAME, EVENT_WindowUnstuck_ID , NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "maximize", 8, TT_FILENAME, EVENT_WindowMaximized_ID , NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "restore", 7, TT_FILENAME, EVENT_WindowRestored_ID , NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "new_background", 14, TT_FILENAME, EVENT_BackgroundChanged_ID , NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "new_viewport", 12, TT_FILENAME, EVENT_DeskViewportChanged_ID, NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "startup", 7, TT_FILENAME, EVENT_Startup_ID , NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "shutdown", 8, TT_FILENAME, EVENT_Shutdown_ID , NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "config", 6, TT_FILENAME, EVENT_Config_ID , NULL},
{TF_DONT_SPLIT|TF_NO_MYNAME_PREPENDING, "module_config", 13, TT_FILENAME, EVENT_ModuleConfig_ID , NULL},
{0, NULL, 0, 0, 0} /* end of structure */
};
SyntaxDef AudioEventsSyntax = {
',',
'\n',
EventTerms,
0, /* use default hash size */
' ',
"",
"\t",
"Module:Audio event configuration",
"AudioEvents",
"names for different windowing events",
NULL,
0
};
TermDef AudioTerms[] = {
{TF_DONT_SPLIT, "PlayCmd", 7, TT_TEXT, AUDIO_PLAYCMD_ID, NULL},
{0, "Delay", 5, TT_INTEGER, AUDIO_DELAY_ID, NULL},
{0, "RplayHost", 9, TT_TEXT, AUDIO_RPLAY_HOST_ID, NULL},
{0, "RplayPriority", 13, TT_INTEGER, AUDIO_RPLAY_PRI_ID, NULL},
{0, "RplayVolume", 11, TT_INTEGER, AUDIO_RPLAY_VOL_ID, NULL},
{0, "", 0, TT_FLAG, AUDIO_AUDIO_ID, &AudioEventsSyntax},
{0, NULL, 0, 0, 0} /* end of structure */
};
SyntaxDef AudioSyntax = {
'\n',
'\0',
AudioTerms,
0, /* use default hash size */
' ',
"",
"\t",
"Module:Audio",
"Audio",
"AfterStep module for playing sounds when windowing event occurs",
NULL,
0
};
/************** Create/Destroy AudioConfig ***************/
AudioConfig *
CreateAudioConfig ()
{
AudioConfig *config = (AudioConfig *) safecalloc (1, sizeof (AudioConfig));
/* let's initialize Audio's config with some nice values: */
#ifdef HAVE_RPLAY_H
config->rplay_volume = RPLAY_DEFAULT_VOLUME;
config->rplay_priority = RPLAY_DEFAULT_PRIORITY;
#endif
return config;
}
void
DestroyAudioConfig (AudioConfig * config)
{
register int i ;
for( i = EVENT_ID_END-EVENT_ID_START-1 ; i >=0 ; i-- )
if( config->sounds[i] )
free( config->sounds[i] );
if (config->playcmd)
free (config->playcmd);
if (config->rplay_host)
free (config->rplay_host);
DestroyFreeStorage (&(config->more_stuff));
free (config);
}
/************ Actual Parsing **************/
AudioConfig *
ParseAudioOptions (const char *filename, char *myname)
{
ConfigData cd ;
ConfigDef *AudioConfigReader;
AudioConfig *config = CreateAudioConfig ();
FreeStorageElem *Storage = NULL, *pCurr;
ConfigItem item;
cd.filename = filename ;
AudioConfigReader = InitConfigReader (myname, &AudioSyntax, CDT_Filename, cd, NULL);
if (!AudioConfigReader)
return config;
item.memory = NULL;
PrintConfigReader (AudioConfigReader);
ParseConfig (AudioConfigReader, &Storage);
/* getting rid of all the crap first */
StorageCleanUp (&Storage, &(config->more_stuff), CF_DISABLED_OPTION);
for (pCurr = Storage; pCurr; pCurr = pCurr->next)
{
if (pCurr->term == NULL)
continue;
{
if (!ReadConfigItem (&item, pCurr))
continue;
switch (pCurr->term->id)
{
case AUDIO_AUDIO_ID:
if( pCurr->sub )
{
if( pCurr->sub->term && pCurr->sub->argv )
if( pCurr->sub->term->id >= EVENT_ID_START && pCurr->sub->term->id < EVENT_ID_END )
set_string( &(config->sounds[pCurr->sub->term->id-EVENT_ID_START]), mystrdup( pCurr->sub->argv[0] ));
}
break;
case AUDIO_PLAYCMD_ID:
set_string( &(config->playcmd), item.data.string );
break;
case AUDIO_DELAY_ID:
set_flags( config->set_flags, AUDIO_SET_DELAY );
config->delay = (int)item.data.integer;
break;
case AUDIO_RPLAY_HOST_ID:
set_string_value( &(config->rplay_host), item.data.string, &(config->set_flags), AUDIO_SET_RPLAY_HOST );
break;
case AUDIO_RPLAY_PRI_ID:
set_flags( config->set_flags, AUDIO_SET_RPLAY_PRIORITY );
config->rplay_priority = (int)item.data.integer;
break;
case AUDIO_RPLAY_VOL_ID:
set_flags( config->set_flags, AUDIO_SET_RPLAY_VOLUME );
config->rplay_volume = (int)item.data.integer;
break;
default:
item.ok_to_free = 1;
}
}
}
ReadConfigItem (&item, NULL);
DestroyConfig (AudioConfigReader);
DestroyFreeStorage (&Storage);
return config;
}
int
WriteAudioOptions (const char *filename, char *myname, AudioConfig * config, unsigned long flags)
{
ConfigDef *AudioConfigWriter = NULL;
FreeStorageElem *Storage = NULL, **tail = &Storage;
register int i ;
ConfigData cd ;
if (config == NULL)
return 1;
cd.filename = filename ;
if ((AudioConfigWriter = InitConfigWriter (myname, &AudioSyntax, CDT_Filename, cd)) == NULL)
return 2;
CopyFreeStorage (&Storage, config->more_stuff);
/* building free storage here */
/* playcmd */
if( config->playcmd )
tail = String2FreeStorage (&AudioSyntax, tail, config->playcmd, AUDIO_PLAYCMD_ID);
/* delay */
if( get_flags(config->set_flags, AUDIO_SET_DELAY) )
tail = Integer2FreeStorage (&AudioSyntax, tail, NULL, config->delay, AUDIO_DELAY_ID);
/* rplay_host */
if (get_flags(config->set_flags, AUDIO_SET_RPLAY_HOST) && config->rplay_host)
tail = String2FreeStorage (&AudioSyntax, tail, config->rplay_host, AUDIO_RPLAY_HOST_ID);
/* rplay_priority */
if (get_flags(config->set_flags, AUDIO_SET_RPLAY_PRIORITY))
tail = Integer2FreeStorage (&AudioSyntax, tail, NULL, config->rplay_priority, AUDIO_RPLAY_PRI_ID);
/* rplay_volume */
if( get_flags(config->set_flags, AUDIO_SET_RPLAY_VOLUME) )
tail = Integer2FreeStorage (&AudioSyntax, tail, NULL, config->rplay_volume, AUDIO_RPLAY_VOL_ID);
/* line structure */
for( i = EVENT_ID_END-EVENT_ID_START-1 ; i >=0 ; i-- )
if( config->sounds[i] )
{
FreeStorageElem **dtail = tail ;
tail = Flag2FreeStorage (&AudioSyntax, tail, AUDIO_AUDIO_ID);
if( *dtail )
Path2FreeStorage (&AudioEventsSyntax, &((*dtail)->sub), NULL, config->sounds[i], EVENT_ID_START + i);
}
/* writing config into the file */
WriteConfig (AudioConfigWriter, Storage, CDT_Filename, &cd, flags);
DestroyFreeStorage (&Storage);
DestroyConfig (AudioConfigWriter);
if (Storage)
{
fprintf (stderr, "\n%s:Config Writing warning: Not all Free Storage discarded! Trying again...", myname);
DestroyFreeStorage (&Storage);
fprintf (stderr, (Storage != NULL) ? " failed." : " success.");
}
return 0;
}
|