From 463593be3f6b41894e0175bf6346a13ad6074869 Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Fri, 8 Jun 2012 15:14:13 +0400 Subject: [PATCH] longtable_params.c added --- c/longtable_params/Makefile | 106 ++++++++++++++++++++++++++ c/longtable_params/longtable_params.c | 46 +++++++++++ 2 files changed, 152 insertions(+) create mode 100644 c/longtable_params/Makefile create mode 100644 c/longtable_params/longtable_params.c diff --git a/c/longtable_params/Makefile b/c/longtable_params/Makefile new file mode 100644 index 0000000..15adb40 --- /dev/null +++ b/c/longtable_params/Makefile @@ -0,0 +1,106 @@ +# Makefile generated by command: smake.sh -t longtable_params -Pglib-2.0 +# This file is generated with smake.sh. +# You can use this make file with instruction make to +# use one of build mode: debug, profile, develop, release. +# No need to call make clean if You make with other mode, +# because the Makefile containes rules for automatically clean. +# Some usage examples: +# make # default mode is debug +# CFLAGS="-O2 -march=core2 -mtune=core2 -msse4.1 -mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1" make mode=develop +# CFLAGS="-O2 -march=amdfam10 -mtune=amdfam10 -msse4a --mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1" make mode=profile +# CFLAGS="-O2 -march=k6-2 -mtune=k6-2 -m3dnow --mfpmath=387 -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1" make mode=release +# Report bugs to + +#_________________________________ +# ENVIRONMENT | +#________________________________| +TARGET0=longtable_params +TARGETS= $(TARGET0) +CC=cc +CXX=c++ +CFLAGS := $(CFLAGS) +CXXFLAGS := $(CXXFLAGS) +LDFLAGS := $(LDFLAGS) +LIBS=-lglib-2.0 +SRC= +INCLUDES=-I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include +#________________________________________ +# BUILD SCRIPT (don't change) | +#_______________________________________| +ifeq ($(mode),) + mode = debug +endif +ifeq ($(mode),debug) + CFLAGS := -O0 -g -DDEBUG -std=c99 -pedantic -Wextra -Wconversion $(CFLAGS) + LDFLAGS := $(LDFLAGS) +endif +ifeq ($(mode),profile) + CFLAGS := -O0 -g -DDEBUG -std=c99 -p -ftest-coverage -Wcoverage-mismatch $(CFLAGS) + LDFLAGS := -g -p $(LDFLAGS) +endif +ifeq ($(mode),develop) + CFLAGS := -O2 -g -DDEBUG -std=c99 $(CFLAGS) + LDFLAGS := -O1 $(LDFLAGS) +endif +ifeq ($(mode),release) + CFLAGS := -O2 -std=c99 $(CFLAGS) + LDFLAGS := -O1 $(LDFLAGS) +endif + +CFLAGS += -Wall $(INCLUDES) +LDFLAGS += -Wall + +all: + @make change_make_options &>/dev/null + +make $(TARGETS) + +ifneq ($(mode),debug) +ifneq ($(mode),profile) +ifneq ($(mode),develop) +ifneq ($(mode),release) + @echo "Invalid build mode." + @echo "Please use 'make mode=release', 'make mode=develop', 'make mode=profile' or 'make mode=debug'" + @exit 1 +endif +endif +endif +endif + @echo ".........................." + @echo "Building on "$(mode)" mode " + @echo "CFLAGS=$(CFLAGS)" + @echo "LDFLAGS=$(LDFLAGS)" + @echo ".........................." + +OLD_BUILD_MODE=$(shell grep ^MODE make_options.out 2>/dev/null | sed 's~^MODE=~~') +OLD_BUILD_CFLAGS=$(shell grep ^CFLAGS make_options.out 2>/dev/null | sed 's~^CFLAGS=~~') +OLD_BUILD_LDFLAGS=$(shell grep ^LDFLAGS make_options.out 2>/dev/null | sed 's~^LDFLAGS=~~') +change_make_options: +ifneq ($(mode)|$(CFLAGS)|$(LDFLAGS), $(OLD_BUILD_MODE)|$(OLD_BUILD_CFLAGS)|$(OLD_BUILD_LDFLAGS)) + @echo CLEANING... + @make clean + @echo "MODE=$(mode)" > make_options.out + @echo "CFLAGS=$(CFLAGS)" >> make_options.out + @echo "LDFLAGS=$(LDFLAGS)" >> make_options.out +endif + +%.o : + $(CC) -c $(CFLAGS) $(SRC) -o $@ $< + +clean: + $(RM) *.o *.out callgrind.out.* *.gcno $(TARGETS) + +.PHONY: all change_make_options clean + +#_________________________________ +# R U L E S | +#________________________________| +target_objs0 = \ + longtable_params.o + +$(TARGET0): $(target_objs0) + $(CC) $(LDFLAGS) -o $@ $(target_objs0) $(LIBS) + + +longtable_params.o: \ + longtable_params.c + diff --git a/c/longtable_params/longtable_params.c b/c/longtable_params/longtable_params.c new file mode 100644 index 0000000..b23cc88 --- /dev/null +++ b/c/longtable_params/longtable_params.c @@ -0,0 +1,46 @@ +#include +#include + +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; + 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)) + { + gchar *word = g_strreverse (g_match_info_fetch (match_info, 0)); + g_print ("Found: %s\n", word); + g_free (word); + 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); + } + + g_free (reverse_params); + + return 0; +}