--- base/utils.c	2007-05-07 20:24:26.000000000 +0200
+++ /usr/local/src/nagios-2.9/base/utils.c	2007-05-07 20:25:07.000000000 +0200
@@ -258,6 +258,32 @@
 	printf("Buffer length: %d\n",buffer_length);
 #endif
 
+// pre-parse macros in curly braces. Eg for defining an argument of an on demand macro $HOSTSTATEID:{$HOSTNAME$}$ 
+for(temp_buffer=strstr(input_buffer,":{$"); temp_buffer!=NULL; temp_buffer=strstr(temp_buffer,":{$")) {
+        char * pre,* macro,* rest;
+        char * buf = strdup(temp_buffer);
+        char * subst_macro = strdup("");
+        pre = buf;
+        if (macro = index(buf,'{')) {
+            macro[0] = '\x0';
+            macro++;
+
+            if (rest = strstr(macro,"$}")) {
+                rest[1] = '\x0';
+                rest += 2;
+
+                buf = strcpy(buf,pre);
+                process_macros(macro,subst_macro,strlen(macro)+1,options);
+                buf = strcat(buf,subst_macro);
+                buf = strcat(buf,rest);
+                temp_buffer=strcpy(temp_buffer,buf);
+            }
+        }
+        free(buf);
+        free(subst_macro);
+    }
+
+
 	for(temp_buffer=my_strtok(input_buffer,"$");temp_buffer!=NULL;temp_buffer=my_strtok(NULL,"$")){
 
 #ifdef TEST_MACROS
