% % Tango/Weevil - A WEB Tangler and Weaver % Copyright (C) 1995 Corey Minyard % % This program is free software; you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation; either version 2 of the License, or % (at your option) any later version. % % This program is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with this program; if not, write to the Free Software % Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. % % Corey Minyard - minyard@metronet.com % @includefile weevinfo.xfr \section{\LaTeX\ Output Handler Intro} Due to the large number of functions of such a trivial nature, this routine is not currently commented very well. The formatting given depends a lot on the tw.sty file that holds the \LaTeX\ macros used by this file. Note that in labels, the names are stripped of everything but periods and asterisks, so names must be unique to that level. @code <*> #include #include #include "weevinfo.h" @ @ @ @ @ @ @ @ @endcode @code typedef struct s_latex_data { int column; } t_latex_data; @endcode @code static void output_name(t_lpweevildat *lpwd, char *name) { while (*name != '\0') { if ( ((*name >= 'a') && (*name <= 'z')) || ((*name >= 'A') && (*name <= 'Z')) || ((*name >= '0') && (*name <= '9')) || ((*name == ' '))) { fputc(*name, lpwd->outfile); } else if (*name == '_') { fputs("\\_", lpwd->outfile); } else { fprintf(lpwd->outfile, "\\char%d ", *name); } name++; } } @endcode @code static void strip_name(t_lpweevildat *lpwd, char *name) { while (*name != '\0') { if ( ((*name >= 'a') && (*name <= 'z')) || ((*name >= 'A') && (*name <= 'Z')) || ((*name >= '0') && (*name <= '9'))) { fputc(*name, lpwd->outfile); } else { switch(*name) { case '.': case '*': fputc(*name, lpwd->outfile); break; } } name++; } } @endcode @code void latex_mode_init(t_lpweevildat *lpwd) { t_latex_data *ltd; ltd = malloc(sizeof(*ltd)); if (ltd == NULL) { fprintf(stderr, "Unable to allocate memory\n"); exit(1); } ltd->column = 1; lpwd->mode_data = ltd; } @endcode @code void latex_begin_macro(t_lpweevildat *lpwd, char *name) { fprintf(lpwd->outfile, "\\begin{twcodechunk}\n"); fprintf(lpwd->outfile, "\\begingroup\\medskip\n"); fprintf(lpwd->outfile, "\\twmacrodecl{"); output_name(lpwd, name); fprintf(lpwd->outfile, "}{"); strip_name(lpwd, lpwd->curr_filename); fprintf(lpwd->outfile, ":macro:"); strip_name(lpwd, name); fprintf(lpwd->outfile, "}\n"); fprintf(lpwd->outfile, "\\begin{verbatimcmd}\\twstartcode\n"); } void latex_end_macro(t_lpweevildat *lpwd) { fprintf(lpwd->outfile, "\\twendcode\\end{verbatimcmd}\n"); fprintf(lpwd->outfile, "\\endgroup"); } void latex_finalend_chunk(t_lpweevildat *lpwd) { fprintf(lpwd->outfile, "\\end{twcodechunk}\n"); } void latex_output_macro_use(t_lpweevildat *lpwd, char *macro_name) { fprintf(lpwd->outfile, "\\twmacrouse{"); output_name(lpwd, macro_name); fprintf(lpwd->outfile, "}{"); strip_name(lpwd, lpwd->curr_filename); fprintf(lpwd->outfile, ":macro:"); strip_name(lpwd, macro_name); fprintf(lpwd->outfile, "}"); } void latex_output_linenum(t_lpweevildat *lpwd) { t_latex_data *ltd; ltd = lpwd->mode_data; fprintf(lpwd->outfile, "%4d ", lpwd->code_lineno); ltd->column = 1; } void latex_output_after_xrefs(t_lpweevildat *lpwd) { fprintf(lpwd->outfile, "\\medskip\n"); } @endcode @code void latex_output_char(t_lpweevildat *lpwd, char c) { t_latex_data *ltd; ltd = lpwd->mode_data; if ((c == '{') || (c == '}')) { fputc('\\', lpwd->outfile); fputc(c, lpwd->outfile); ltd->column++; } else if (c == '\\') { fputs("\\(\\backslash\\)", lpwd->outfile); ltd->column++; } else if (c == '\t') { fputc(' ', lpwd->outfile); ltd->column++; while ((ltd->column % 8) != 1) { fputc(' ', lpwd->outfile); ltd->column++; } } else if (c == '\n') { fputc(c, lpwd->outfile); ltd->column = 1; } else { fputc(c, lpwd->outfile); ltd->column++; } } @endcode @code void latex_output_begin_uses(t_lpweevildat *lpwd) { fprintf(lpwd->outfile, "\\begin{twuses}\n"); } void latex_output_end_uses(t_lpweevildat *lpwd) { fprintf(lpwd->outfile, "\\end{twuses}\n"); } void latex_output_use_start(t_lpweevildat *lpwd, char *name) { fprintf(lpwd->outfile, "\\twuse{"); output_name(lpwd, name); fprintf(lpwd->outfile, "} "); } void latex_output_use_end(t_lpweevildat *lpwd, char *name) { fprintf(lpwd->outfile, "\\\\\n"); } void latex_output_use_ref(t_lpweevildat *lpwd, char *file, char *macro, char *name) { fputc('(', lpwd->outfile); if (file != NULL) { output_name(lpwd, file); fputc(':', lpwd->outfile); } output_name(lpwd, macro); fputc(')', lpwd->outfile); } void latex_output_between_use_refs(t_lpweevildat *lpwd, char *name) { fputc(' ', lpwd->outfile); } @endcode @code void latex_output_begin_decls(t_lpweevildat *lpwd) { fprintf(lpwd->outfile, "\\begin{twdecls}\n"); } void latex_output_end_decls(t_lpweevildat *lpwd) { fprintf(lpwd->outfile, "\\end{twdecls}\n"); } void latex_output_decl(t_lpweevildat *lpwd, char *name) { fprintf(lpwd->outfile, "\\twdecl{"); output_name(lpwd, name); fprintf(lpwd->outfile, "}\\\\\n"); } @endcode