dev/c/longtable_params/longtable_params.c

52 lines
1.6 KiB
C
Raw Permalink Normal View History

2012-06-08 15:33:48 +04:00
//#include <stdio.h>
2012-06-08 15:14:13 +04:00
#include <glib.h>
const gchar *params = "{lcrr@{...}l>{...}p{...}|l|c|r|r@{...}l|>{...}p{...}l|c|r|r@{...}l|>{...}p{...}||l||c||r||r@{...}l||>{...}p{...}|}";
int main (int argc, char *argv[])
{
/* Print all uppercase-only words. */
GRegex *regex;
GMatchInfo *match_info;
GError *error = NULL;
2012-06-08 15:21:41 +04:00
GList *list_params = NULL,
*it = NULL;
2012-06-08 15:14:13 +04:00
gchar *reverse_params = g_strdup (params);
reverse_params = g_strreverse (reverse_params);
regex = g_regex_new ("("
"(\\||)}[^{}]+{p}[^{}]+{>(\\||)"
"|"
"(\\||)l}[^{}]+{@r(\\||)"
"|"
"(\\||)r(\\||)"
"|"
"(\\||)c(\\||)"
"|"
"(\\||)l(\\||)"
")",
0, 0, NULL);
g_regex_match_full (regex, reverse_params, -1, 0, 0, &match_info, &error);
while (g_match_info_matches (match_info))
{
2012-06-08 15:21:41 +04:00
list_params = g_list_prepend (list_params, g_strreverse (g_match_info_fetch (match_info, 0)));
2012-06-08 15:14:13 +04:00
g_match_info_next (match_info, &error);
}
g_match_info_free (match_info);
g_regex_unref (regex);
if (error != NULL)
{
g_printerr ("Error while matching: %s\n", error->message);
g_error_free (error);
}
2012-06-08 15:33:48 +04:00
g_print ("%s\n", params);
2012-06-08 15:21:41 +04:00
for (it = g_list_first (list_params); it; it = g_list_next (it))
2012-06-08 15:33:48 +04:00
g_print ("Found: %s\n", (const gchar *) it->data);
2012-06-08 15:21:41 +04:00
2012-06-08 15:14:13 +04:00
g_free (reverse_params);
2012-06-08 15:21:41 +04:00
g_list_free_full (list_params, g_free);
2012-06-08 15:14:13 +04:00
return 0;
}