shithub: dumb

Download patch

ref: 756ecf2ac0a2b70639193aca55627b64dac8d8d5
parent: d2575fcc80abf2f04e702adb60a6265cef0fcabb
author: Chris Moeller <kode54@gmail.com>
date: Sun Dec 9 14:53:45 EST 2012

Added interface for inserting extra DUH signals, and fixed searching for IT sigdata when more than one signal is present

--- a/dumb/include/dumb.h
+++ b/dumb/include/dumb.h
@@ -217,7 +217,6 @@
 
 const char *duh_get_tag(DUH *duh, const char *key);
 
-
 /* Signal Rendering Functions */
 
 typedef struct DUH_SIGRENDERER DUH_SIGRENDERER;
@@ -589,6 +588,8 @@
 DUH_SIGTYPE_DESC;
 
 void dumb_register_sigtype(DUH_SIGTYPE_DESC *desc);
+
+int duh_add_signal(DUH *duh, DUH_SIGTYPE_DESC *desc, sigdata_t *sigdata);
 
 
 // Decide where to put these functions; new heading?
--- a/dumb/src/core/makeduh.c
+++ b/dumb/src/core/makeduh.c
@@ -130,3 +130,22 @@
 
 	return duh;
 }
+
+int duh_add_signal(DUH *duh, DUH_SIGTYPE_DESC *desc, sigdata_t *sigdata)
+{
+	DUH_SIGNAL **signal;
+
+	if ( !duh || !desc || !sigdata ) return -1;
+
+	signal = ( DUH_SIGNAL ** ) realloc( duh->signal, ( duh->n_signals + 1 ) * sizeof( *duh->signal ) );
+	if ( !signal ) return -1;
+	duh->signal = signal;
+
+	memmove( signal + 1, signal, duh->n_signals * sizeof( *signal ) );
+	duh->n_signals++;
+
+	signal[ 0 ] = make_signal( desc, sigdata );
+	if ( !signal[ 0 ] ) return -1;
+
+	return 0;
+}
--- a/dumb/src/core/rawsig.c
+++ b/dumb/src/core/rawsig.c
@@ -29,16 +29,30 @@
  */
 sigdata_t *duh_get_raw_sigdata(DUH *duh, int sig, long type)
 {
+	int i;
 	DUH_SIGNAL *signal;
 
 	if (!duh) return NULL;
 
-	if ((unsigned int)sig >= (unsigned int)duh->n_signals) return NULL;
+	if ( sig >= 0 )
+	{
+		if ((unsigned int)sig >= (unsigned int)duh->n_signals) return NULL;
 
-	signal = duh->signal[sig];
+		signal = duh->signal[sig];
 
-	if (signal && signal->desc->type == type)
-		return signal->sigdata;
+		if (signal && signal->desc->type == type)
+			return signal->sigdata;
+	}
+	else
+	{
+		for ( i = 0; i < duh->n_signals; i++ )
+		{
+			signal = duh->signal[i];
+
+			if (signal && signal->desc->type == type)
+				return signal->sigdata;
+		}
+	}
 
 	return NULL;
 }
--- a/dumb/src/it/itmisc.c
+++ b/dumb/src/it/itmisc.c
@@ -24,7 +24,7 @@
 
 DUMB_IT_SIGDATA *duh_get_it_sigdata(DUH *duh)
 {
-	return duh_get_raw_sigdata(duh, 0, SIGTYPE_IT);
+	return duh_get_raw_sigdata(duh, -1, SIGTYPE_IT);
 }