#include #include #include gchar * find_decimal_dot_double_decimal (const gchar *string) { GRegex *regex = NULL; GMatchInfo *match_info; GString *lilyversion = g_string_new (""); regex = g_regex_new("\\d.\\d\\d", 0, 0, NULL); g_regex_match(regex, string, 0, &match_info); if (g_match_info_matches (match_info)) { g_string_append(lilyversion, g_match_info_fetch (match_info, 0)); } g_match_info_free (match_info); g_regex_unref (regex); return g_string_free(lilyversion, FALSE); } double get_lily_version (void) { GError *error = NULL; gchar *endp, *version_string; double d; int standard_output; gchar buf[30]; gchar *arguments[] = { "lilypond", "-v", NULL }; g_spawn_async_with_pipes (NULL, /* dir */ arguments, NULL, /* env */ G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, /* child setup func */ NULL, /* user data */ NULL, /*pid*/ NULL, /*standard_input*/ &standard_output, /*standard output*/ NULL, /*standard error*/ &error); read(standard_output, buf, 30); version_string = find_decimal_dot_double_decimal(buf); if (!version_string) return -1; d = strtod(version_string, &endp); if (version_string != endp && *endp == '\0') return d; else return -1; } int main() { double version; version = get_lily_version(); if (version != -1) g_print("\nlilypond version = %g\n",version); else g_print("\nerror finding lilypond version\n"); }