From 0f3ecd8e702a3b0390163312cf358b79a3b434ff Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Fri, 10 Jun 2011 14:31:10 +0400 Subject: [PATCH] no c++ just c --HG-- rename : c/tex_parser/tex_table_class.cpp => c/tex_parser/tex_table.c rename : c/tex_parser/tex_table_class.geany => c/tex_parser/tex_table.geany rename : c/tex_parser/tex_table_class.hpp => c/tex_parser/tex_table.h rename : c/tex_parser/tex_table_class_tags.hpp => c/tex_parser/tex_table_tags.h rename : c/tex_parser/tex_table_class_test.cpp => c/tex_parser/tex_table_test.c --- c/realloc_speed_test/realloc_speed_test.geany | 2 +- c/tex_parser/Makefile | 32 +++++----- c/tex_parser/tex_table.c | 23 +++++++ ...{tex_table_class.geany => tex_table.geany} | 17 +++--- .../{tex_table_class.hpp => tex_table.h} | 60 +++++++++---------- c/tex_parser/tex_table_class.cpp | 22 ------- c/tex_parser/tex_table_class_tags.hpp | 29 --------- c/tex_parser/tex_table_tags.h | 28 +++++++++ ..._table_class_test.cpp => tex_table_test.c} | 17 +++--- 9 files changed, 114 insertions(+), 116 deletions(-) create mode 100644 c/tex_parser/tex_table.c rename c/tex_parser/{tex_table_class.geany => tex_table.geany} (50%) rename c/tex_parser/{tex_table_class.hpp => tex_table.h} (69%) delete mode 100644 c/tex_parser/tex_table_class.cpp delete mode 100644 c/tex_parser/tex_table_class_tags.hpp create mode 100644 c/tex_parser/tex_table_tags.h rename c/tex_parser/{tex_table_class_test.cpp => tex_table_test.c} (69%) diff --git a/c/realloc_speed_test/realloc_speed_test.geany b/c/realloc_speed_test/realloc_speed_test.geany index 8b47433..8e4c112 100644 --- a/c/realloc_speed_test/realloc_speed_test.geany +++ b/c/realloc_speed_test/realloc_speed_test.geany @@ -16,7 +16,7 @@ long_line_behaviour=1 long_line_column=72 [files] -current_page=1 +current_page=0 FILE_NAME_0=781;C;0;16;1;1;1;/home/kolan/dev/c/realloc_speed_test/realloc_speed_test_c.c;0 FILE_NAME_1=515;C++;0;16;1;1;1;/home/kolan/dev/c/realloc_speed_test/realloc_speed_test_cpp.cpp;0 diff --git a/c/tex_parser/Makefile b/c/tex_parser/Makefile index c3c6f8b..85243d9 100644 --- a/c/tex_parser/Makefile +++ b/c/tex_parser/Makefile @@ -10,7 +10,7 @@ ifeq ($(mode),) mode = debug endif ifeq ($(mode),debug) - CFLAGS = -O0 -g -std=c++0x -pedantic -Wextra -Wconversion + CFLAGS = -O0 -g -std=gnu99 -pedantic -Wextra -Wconversion LDFLAGS = endif ifeq ($(mode),profile) @@ -26,10 +26,12 @@ ifeq ($(mode),release) LDFLAGS += -O1 endif -CFLAGS += -Wall $(shell pkg-config --cflags liblist) -LDFLAGS += -Wall $(shell pkg-config --libs liblist) -lpthread -lexpat +CFLAGS += -Wall +#~ $(shell pkg-config --cflags liblist) +LDFLAGS += -Wall +#~ $(shell pkg-config --libs liblist) -lpthread -lexpat -all: tex_table_class_test +all: tex_table_test ifneq ($(mode),debug) ifneq ($(mode),profile) @@ -45,25 +47,27 @@ endif @echo ".........................." @echo "Building on "$(mode)" mode " @echo "CFLAGS=$(CFLAGS)" - @echo "LDLAGS=$(LDFLAGS)" + @echo "LDFLAGS=$(LDFLAGS)" @echo ".........................." %.o : - $(CXX) -c $(CFLAGS) $(LDFLAGS) $(INCLUDE) -o $@ $< + $(CC) -c $(CFLAGS) $(LDFLAGS) $(INCLUDE) -o $@ $< -tex_table_class_test_obj = tex_table_class_test.o tex_table_class.o xmalloc.o xerror.o -tex_table_class_test: $(tex_table_class_test_obj) - $(CXX) $(CFLAGS) $(LDFLAGS) $(INCLUDE) -o $@ $(tex_table_class_test_obj) +tex_table_test_obj = tex_table_test.o tex_table.o zmalloc.o xmalloc.o xerror.o +tex_table_test: $(tex_table_test_obj) + $(CC) $(CFLAGS) $(LDFLAGS) $(INCLUDE) -o $@ $(tex_table_test_obj) -tex_table_class_test.o: tex_table_class_test.cpp tex_table_class.o +tex_table_test.o: tex_table_test.c tex_table.o -tex_table_class.o: tex_table_class.[c,h]pp xmalloc.o +tex_table.o: tex_table.c tex_table.h zmalloc.o xmalloc.o -xmalloc.o: $(KOLAN_INCLUDE)/xmalloc.[c,h] xerror.o +zmalloc.o: $(KOLAN_INCLUDE)/zmalloc.c $(KOLAN_INCLUDE)/zmalloc.h xerror.o -xerror.o: $(KOLAN_INCLUDE)/xerror.[c,h] +xmalloc.o: $(KOLAN_INCLUDE)/xmalloc.c $(KOLAN_INCLUDE)/xmalloc.h xerror.o + +xerror.o: $(KOLAN_INCLUDE)/xerror.c $(KOLAN_INCLUDE)/xerror.h clean: - $(RM) *.o *.out callgrind.out.* *.gcno tex_table_class_test + $(RM) *.o *.out callgrind.out.* *.gcno tex_table_test .PHONY: all clean diff --git a/c/tex_parser/tex_table.c b/c/tex_parser/tex_table.c new file mode 100644 index 0000000..444387e --- /dev/null +++ b/c/tex_parser/tex_table.c @@ -0,0 +1,23 @@ +#include "tex_table.h" + +#include "tex_table_tags.h" + +#include + +int parse_table(const char *table_source, size_t len, struct table_s *table, struct xerror_s *error) +{ + if (!len) + len = strlen(table_source); + + for (size_t i = 0; i < len; i++) { + char c = table_source[i]; + + c = c; + } + + table->id = "Drossel1.Table1"; + + error->message = NULL; + + return 0; +} diff --git a/c/tex_parser/tex_table_class.geany b/c/tex_parser/tex_table.geany similarity index 50% rename from c/tex_parser/tex_table_class.geany rename to c/tex_parser/tex_table.geany index f247618..6d430fb 100644 --- a/c/tex_parser/tex_table_class.geany +++ b/c/tex_parser/tex_table.geany @@ -8,7 +8,7 @@ indent_mode=2 [project] name=tex_table_class -base_path=/home/kolan/dev/cpp/tex_parser/ +base_path=/home/kolan/dev/c/tex_parser/ description= [long line marker] @@ -16,15 +16,12 @@ long_line_behaviour=1 long_line_column=72 [files] -current_page=5 -FILE_NAME_0=116;C++;0;61;1;1;1;/home/kolan/dev/cpp/tex_parser/tex_table_class_test.cpp;0 -FILE_NAME_1=370;C++;0;61;1;1;1;/home/kolan/dev/cpp/tex_parser/tex_table_class.cpp;0 -FILE_NAME_2=0;C++;0;61;1;1;1;/home/kolan/dev/cpp/tex_parser/tex_table_class.hpp;0 -FILE_NAME_3=0;C++;0;61;1;1;1;/home/kolan/dev/cpp/tex_parser/tex_table_class_tags.hpp;0 -FILE_NAME_4=0;Make;0;61;1;1;1;/home/kolan/dev/cpp/tex_parser/Makefile;0 -FILE_NAME_5=314;C;0;16;1;1;1;/home/kolan/projects/include/xmalloc.c;0 -FILE_NAME_6=252;LaTeX;0;45;1;1;1;/home/kolan/dev/cpp/tex_parser/tables4.tex;0 -FILE_NAME_7=0;LaTeX;0;45;1;1;1;/home/kolan/dev/cpp/tex_parser/tables5.tex;0 +current_page=2 +FILE_NAME_0=375;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table_test.c;0 +FILE_NAME_1=53;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table.c;0 +FILE_NAME_2=2213;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table.h;0 +FILE_NAME_3=0;C;0;16;1;1;1;/home/kolan/dev/c/tex_parser/tex_table_tags.h;0 +FILE_NAME_4=1725;Make;0;16;1;1;1;/home/kolan/dev/c/tex_parser/Makefile;0 [build-menu] NF_00_LB=_Сделать diff --git a/c/tex_parser/tex_table_class.hpp b/c/tex_parser/tex_table.h similarity index 69% rename from c/tex_parser/tex_table_class.hpp rename to c/tex_parser/tex_table.h index 4e215e0..7783f16 100644 --- a/c/tex_parser/tex_table_class.hpp +++ b/c/tex_parser/tex_table.h @@ -1,8 +1,7 @@ -#ifndef TEX_TABLE_CLASS -#define TEX_TABLE_CLASS +#ifndef TEX_TABLE_H +#define TEX_TABLE_H -#include -#include +#include #include "xerror.h" @@ -11,50 +10,45 @@ * следующие n-1 ячеек в таблице пустые и при компиляции * к ним не добавляется символ & */ -class cell_c { - public: - std::string before; - std::string request; - std::string after; +struct cell_s { + char *before; + char *request; + char *after; }; /* Строка. * Заканчивается тегом "\tabularnewline" */ -class row_c { - public: - std::string before; - std::vector cells; - std::string after; +struct row_s { + char *before; + struct cell_s *cells; + char *after; }; /* \hline\multicolumn{8}{|c|}{Сводный протокол результатов испытания двигателя ТВ7-117В \textnumero{}}\tabularnewline\multicolumn{8}{|c|}{Стенд \textnumero{}18 ~~ ИУД СИК ~ Дата: ~~~~~~~~ г. Время:~~~~~~~~~ Рн = ~~~ мм рт ст~~ tвх = ~~~ $\,^{\circ}\mbox{C}$}\tabularnewline\multicolumn{8}{|c|}{Характеристика ~~~~~~~ Акт сдачи, контрольные точки}\tabularnewline\hline\endhead */ -class header_c { - public: - std::string before; - std::vector rows; - std::string after; +struct header_s { + char *before; + struct row_s *rows; + char *after; }; /* \hline\multicolumn{2}{|>{\centering}m{0.11\linewidth}|}{\centering{}Составил} & \multicolumn{2}{c|}{Инженер по испытаниям} & Начальник БТК & Начальник участка УИД СИК & \multicolumn{2}{c|}{Представитель заказчика}\tabularnewline\hline\multicolumn{2}{|>{\centering}p{0.11\linewidth}|}{\centering{}\textit{Подпись}} & \multicolumn{2}{c|}{\textit{Подпись}} & \centering{}\textit{Подпись} & \centering{}\textit{Подпись} & \multicolumn{2}{c|}{\textit{Подпись}}\tabularnewline\multicolumn{2}{|>{\centering}p{0.11\linewidth}|}{\textit{фамилия}} & \multicolumn{2}{c|}{\textit{фамилия}} & \multicolumn{1}{c|}{\textit{фамилия}} & \textit{фамилия} & \multicolumn{2}{c|}{\textit{фамилия}}\tabularnewline\hline\endfoot */ -class footer_c { - public: - std::string before; - std::vector rows; - std::string after; +struct footer_s { + char *before; + struct row_s *rows; + char *after; }; -class table_c { - public: - std::string id; // "Drossel1.Table1" - std::vector columns_scheme; // "|>{\centering}m{0.1\paperwidth}" - header_c header; - footer_c footer; - std::vector rows; +struct table_s { + char *id; // "Drossel1.Table1" + char **coumnt_scheme; // "|>{\centering}m{0.1\paperwidth}" + struct header_s header; + struct footer_s footer; + struct row_s *rows; }; -int parse_table(const char *table_source, table_c *table, struct xerror_s *error); +int parse_table(const char *table_source, size_t len, struct table_s *table, struct xerror_s *error); -#endif // TEX_TABLE_CLASS +#endif // TEX_TABLE_H diff --git a/c/tex_parser/tex_table_class.cpp b/c/tex_parser/tex_table_class.cpp deleted file mode 100644 index ba39a6c..0000000 --- a/c/tex_parser/tex_table_class.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "tex_table_class.hpp" - -#include - -#include "tex_table_class_tags.hpp" - -int parse_table(const char *table_source, table_c *table, struct xerror_s *error) -{ - size_t table_source_len = strlen(table_source); - - for (size_t i = 0; i < table_source_len; i++) { - char c = table_source[i]; - - c = c; - } - - table->id = 3; - - error->message = NULL; - - return 0; -} diff --git a/c/tex_parser/tex_table_class_tags.hpp b/c/tex_parser/tex_table_class_tags.hpp deleted file mode 100644 index 26dc214..0000000 --- a/c/tex_parser/tex_table_class_tags.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef TEX_TABLE_CLASS_TAGS_HPP -#define TEX_TABLE_CLASS_TAGS_HPP - -const char *TAG_BEGIN = "begin"; -const char *TAG_CLINE = "cline"; -const char *TAG_END = "end"; -const char *TAG_ENDFOOT = "endfoot"; -const char *TAG_ENDHEAD = "endhead"; -const char *TAG_HLINE = "hline"; -const char *TAG_HSPACE = "hspace"; -const char *TAG_MULTICOLUMN = "multicolumn"; -const char *TAG_MULTIROW = "multirow"; -const char *TAG_TABULARNEWLINE = "tabularnewline"; - -const char *ALL_TAGS[] { - TAG_BEGIN, - TAG_CLINE, - TAG_END, - TAG_ENDFOOT, - TAG_ENDHEAD, - TAG_HLINE, - TAG_HSPACE, - TAG_MULTICOLUMN, - TAG_MULTIROW, - TAG_TABULARNEWLINE -}; - - -#endif // TEX_TABLE_CLASS_TAGS_HPP diff --git a/c/tex_parser/tex_table_tags.h b/c/tex_parser/tex_table_tags.h new file mode 100644 index 0000000..9db0e3a --- /dev/null +++ b/c/tex_parser/tex_table_tags.h @@ -0,0 +1,28 @@ +#ifndef TEX_TABLE_H +#define TEX_TABLE_H + +const char *TEX_TAG_BEGIN = "begin"; +const char *TEX_TAG_CLINE = "cline"; +const char *TEX_TAG_END = "end"; +const char *TEX_TAG_ENDFOOT = "endfoot"; +const char *TEX_TAG_ENDHEAD = "endhead"; +const char *TEX_TAG_HLINE = "hline"; +const char *TEX_TAG_HSPACE = "hspace"; +const char *TEX_TAG_MULTICOLUMN = "multicolumn"; +const char *TEX_TAG_MULTIROW = "multirow"; +const char *TEX_TAG_TABULARNEWLINE = "tabularnewline"; + +const char *ALL_TAGS[] { + TEX_TAG_BEGIN, + TEX_TAG_CLINE, + TEX_TAG_END, + TEX_TAG_ENDFOOT, + TEX_TAG_ENDHEAD, + TEX_TAG_HLINE, + TEX_TAG_HSPACE, + TEX_TAG_MULTICOLUMN, + TEX_TAG_MULTIROW, + TEX_TAG_TABULARNEWLINE +}; + +#endif // TEX_TABLE_H diff --git a/c/tex_parser/tex_table_class_test.cpp b/c/tex_parser/tex_table_test.c similarity index 69% rename from c/tex_parser/tex_table_class_test.cpp rename to c/tex_parser/tex_table_test.c index 8f39822..c5746b9 100644 --- a/c/tex_parser/tex_table_class_test.cpp +++ b/c/tex_parser/tex_table_test.c @@ -1,15 +1,17 @@ #include +#include +#include +#include -#include "tex_table_class.hpp" +#include "tex_table.h" +#include "zmalloc.h" #include "xmalloc.h" #include "xerror.h" -using namespace std; - int main(int argc, char *argv[]) { if (argc != 2) - xerrx(-1, "Usage: ./tex_table_class_test /path/to/table.tex", NULL); + xerrx(-1, "Usage: ./tex_table_test /path/to/table.tex", NULL); FILE *tex_file = fopen(argv[1], "rb"); if (!tex_file) @@ -22,13 +24,14 @@ int main(int argc, char *argv[]) char *tex_buf = (char *)xmalloc((size_t)stat_buf.st_size + 1); if (fread(tex_buf, 1, (size_t)stat_buf.st_size, tex_file) != (size_t)stat_buf.st_size) xerrx(errno, "Error reading %s", argv[1]); + fclose(tex_file); tex_buf[stat_buf.st_size] = 0; struct xerror_s error; - struct table_c table; - parse_table(tex_buf, &table, &error); + struct table_s table; + parse_table(tex_buf, (size_t)stat_buf.st_size, &table, &error); - fclose(tex_file); + xfree(&tex_buf); return EXIT_SUCCESS; }