Creating goats from another program

You can create new goats by modifying the file ~/.gnome/goats_new . Goats scans this file once a minute to check for new goats. The format is the same as the ~/.gnome/goats file & is best edited using the gnome_config functions although if this isn't possible you can edit it manually. It looks something like this:
 

[goats]
num_goats=3
lock=false

[goat1]
title=Goat TItle
text=Goat Text
..
.
.
[goat3]
..
.
 

You can control the size, colour, position etc of the goats using other arguments (look in ~/.gnome/goats to see the arguments), but mostly it should be easiest to just use title= and text=. There is a very simple locking system, first you should read the 'lock' argument (gnome-config path /goats_new/goats/lock), and wait until it is false. Then, set it to true, modify the file, and set it to false again afterwards. This isn't a perfect system of course. You should add a timeout in case another program leaves lock set to true, Goats itself just overrides the lock if it stays at true for more than 5 seconds. Before modifying the file, read the num_goats argument, and append your new goats, then increase num_goats as required.

A little sample C code to do this all this:
 

thetime = time(NULL);
lock = TRUE;

while (lock == TRUE) {
lock = gnome_config_get_bool("/goats_new/goats/lock");
if (time(NULL) - thetime > 5) lock = FALSE; /* override after 5 seconds */
}

gnome_config_set_bool("/goats_new/goats/lock",TRUE);
gnome_config_sync(); /* make sure changes are on disk */

num_goats = gnome_config_get_int("/goats_new/goats/num_goats");
section = g_strdup_printf("goats_new/new_goat%i",num_goats+1);

key = g_strdup_printf("%s%s",section,"title");
gnome_config_set_char(key,title);
g_free(key);
key = g_strdup_printf("%s%s",section,"text");
gnome_config_set_char(key,text);
g_free(key);
g_free(section);

gnome_config_set_int("/goats_new/new_goats/num_goats",num_goats+1);
gnome_config_set_bool("/goats_new/new_goats/lock",FALSE);
gnome_config_sync();
 

If you actually use this in a program, please let me know!