From 3e92e0c8eb0f7c015b214b439ad71613bff9ca51 Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Sat, 7 Mar 2009 11:43:35 +0330 Subject: [PATCH] tex: move tex fmt_ops to tex.c --- Makefile | 2 +- ctxt.c | 165 ++++++++------------------------------------------------ ctxt.h | 1 + ctxt.c => tex.c | 21 -------- 4 files changed, 24 insertions(+), 165 deletions(-) rewrite ctxt.c (83%) copy ctxt.c => tex.c (83%) diff --git a/Makefile b/Makefile index 88bf7e5..e6d6da4 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ LDFLAGS = all: ctxt .c.o: $(CC) -c $(CFLAGS) $< -ctxt: ctxt.o util.o txt.o fmt.o +ctxt: ctxt.o util.o txt.o fmt.o tex.o $(CC) $(LDFLAGS) -o $@ $^ clean: rm -f *.o ctxt diff --git a/ctxt.c b/ctxt.c dissimilarity index 83% index 57947cd..da6afe1 100644 --- a/ctxt.c +++ b/ctxt.c @@ -1,143 +1,22 @@ -#include -#include -#include -#include "ctxt.h" -#include "util.h" - -void file_put(int fd, char *s) -{ - int c = 0; - int n = 0; - size_t size = strlen(s); - while (size > n && (c = write(fd, s + n, size - n)) >= 0) - n += c; -} - -static void latex_doc_beg(int fd) -{ - file_put(fd, "\\begin{document}\n"); -} - -static void latex_doc_end(int fd) -{ - file_put(fd, "\\end{document}\n"); -} - -static void latex_head_beg(int fd, int level) -{ - switch (level) { - case 0: - file_put(fd, "\\section*{"); - break; - case 1: - file_put(fd, "\\subsection*{"); - break; - default: - file_put(fd, "\\subsection*{"); - } -} - -static void latex_head_end(int fd) -{ - file_put(fd, "}\n"); -} - -static void latex_par_beg(int fd) -{ -} - -static void latex_par_end(int fd) -{ -} - -static void latex_put(int fd, char *s) -{ - file_put(fd, s); -} - -static void latex_list_beg(int fd) -{ - file_put(fd, "\\begin{itemize}\n"); -} - -static void latex_list_end(int fd) -{ - file_put(fd, "\\end{itemize}\n"); -} - -static void latex_item_beg(int fd) -{ - file_put(fd, "\\item "); -} - -static void latex_item_end(int fd) -{ - file_put(fd, ""); -} - -static void latex_pre_beg(int fd) -{ - file_put(fd, "\\begin{verbatim}\n"); -} - -static void latex_pre_end(int fd) -{ - file_put(fd, "\\end{verbatim}\n"); -} - -static void latex_formula_beg(int fd) -{ - file_put(fd, "\\[ "); -} - -static void latex_formula_end(int fd) -{ - file_put(fd, " \\]\n"); -} - -static void latex_put_emph(int fd, char *s) -{ - file_put(fd, "\\emph{"); - file_put(fd, s); - file_put(fd, "}"); -} - -static void latex_put_raw(int fd, char *s) -{ - file_put(fd, s); -} - -static void latex_put_ref(int fd, char *s) -{ - file_put(fd, "\\cite{"); - file_put(fd, s); - file_put(fd, "}"); -} - -struct fmt_ops latex_ops = { - .doc_beg = latex_doc_beg, - .doc_end = latex_doc_end, - .head_beg = latex_head_beg, - .head_end = latex_head_end, - .par_beg = latex_par_beg, - .par_end = latex_par_end, - .list_beg = latex_list_beg, - .list_end = latex_list_end, - .item_beg = latex_item_beg, - .item_end = latex_item_end, - .pre_beg = latex_pre_beg, - .pre_end = latex_pre_end, - .formula_beg = latex_formula_beg, - .formula_end = latex_formula_end, - .put_emph = latex_put_emph, - .put_raw = latex_put_raw, - .put_ref = latex_put_ref, - .put = latex_put}; - -int main(int argc, char **argv) -{ - struct txt *txt = txt_alloc(STDIN_FILENO); - fmt(STDOUT_FILENO, txt, &latex_ops); - txt_free(txt); - return 0; -} +#include +#include +#include +#include "ctxt.h" +#include "util.h" + +void file_put(int fd, char *s) +{ + int c = 0; + int n = 0; + size_t size = strlen(s); + while (size > n && (c = write(fd, s + n, size - n)) >= 0) + n += c; +} + +int main(int argc, char **argv) +{ + struct txt *txt = txt_alloc(STDIN_FILENO); + fmt(STDOUT_FILENO, txt, &latex_ops); + txt_free(txt); + return 0; +} diff --git a/ctxt.h b/ctxt.h index 19f432b..3c32ac8 100644 --- a/ctxt.h +++ b/ctxt.h @@ -36,5 +36,6 @@ void txt_free(struct txt *txt); void fmt(int fd, struct txt *txt, struct fmt_ops *ops); +extern struct fmt_ops latex_ops; #endif diff --git a/ctxt.c b/tex.c similarity index 83% copy from ctxt.c copy to tex.c index 57947cd..7b82703 100644 --- a/ctxt.c +++ b/tex.c @@ -1,17 +1,4 @@ -#include -#include -#include #include "ctxt.h" -#include "util.h" - -void file_put(int fd, char *s) -{ - int c = 0; - int n = 0; - size_t size = strlen(s); - while (size > n && (c = write(fd, s + n, size - n)) >= 0) - n += c; -} static void latex_doc_beg(int fd) { @@ -133,11 +120,3 @@ struct fmt_ops latex_ops = { .put_raw = latex_put_raw, .put_ref = latex_put_ref, .put = latex_put}; - -int main(int argc, char **argv) -{ - struct txt *txt = txt_alloc(STDIN_FILENO); - fmt(STDOUT_FILENO, txt, &latex_ops); - txt_free(txt); - return 0; -} -- 2.11.4.GIT