Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. /*=============================================================================
  3.    GNU UnRTF, a command-line program to convert RTF documents to other formats.
  4.    Copyright (C) 2000,2001 Zachary Thayer Smith
  5.  
  6.    This program is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2 of the License, or
  9.    (at your option) any later version.
  10.  
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  
  20.    The author is reachable by electronic mail at tuorfa@yahoo.com.
  21. =============================================================================*/
  22.  
  23.  
  24. /*----------------------------------------------------------------------
  25.  * Module name:    latex
  26.  * Author name:    Zach Smith
  27.  * Create date:    18 Sep 01
  28.  * Purpose:        LaTeX-specific output module
  29.  *----------------------------------------------------------------------
  30.  * Changes:
  31.  * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks
  32.  * 23 Sep 01, tuorfa@yahoo.com: fixed accented characters
  33.  *--------------------------------------------------------------------*/
  34.  
  35.  
  36.  
  37.  
  38. #include <stdio.h>
  39. #include <string.h>
  40. #include "malloc.h"
  41. #include "defs.h"
  42. #include "error.h"
  43. #include "main.h"
  44. #include "output.h"
  45.  
  46.  
  47.  
  48. static char* ascii [96] = {
  49. /* 0x20 */ " ", "!", "''", "\\#", "{\\$}", "\\%", "\\&", "'",
  50. /* 0x28 */ "(", ")", "{\ast}", "+", ",", "-", ".", "/",
  51. /* 0x30 */ "0", "1", "2", "3", "4", "5", "6", "7",
  52. /* 0x38 */ "8", "9", ":", ";", "<", "=", ">", "?",
  53. /* 0x40 */ "@", "A", "B", "C", "D", "E", "F", "G",
  54. /* 0x48 */ "H", "I", "J", "K", "L", "M", "N", "O",
  55. /* 0x50 */ "P", "Q", "R", "S", "T", "U", "V", "W",
  56. /* 0x58 */ "X", "Y", "Z", "[", "{\\slash}", "]", "{\\caret}", "\\_",
  57. /* 0x60 */ "`", "a", "b", "c", "d", "e", "f", "g",
  58. /* 0x68 */ "h", "i", "j", "k", "l", "m", "n", "o",
  59. /* 0x70 */ "p", "q", "r", "s", "t", "u", "v", "w",
  60. /* 0x78 */ "x", "y", "z", "\\{", "$\\mid$", "\\}", "\\~{ }", "",
  61. };
  62.  
  63.  
  64. static char* ansi [] = {
  65. /* 0x82 */ "?", "?",
  66.         "?", "{\\ldots}", "{\\dag}", "{\\ddag}",
  67.         "?", "?", "?", "?",
  68.         "{\\OE}", NULL, NULL, NULL,
  69. /* 0x90 */ NULL,"`","'","``","''","{\\bullet}","--","---",
  70. /* 0x98 */ NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  71. /* 0xa0 */ "\\:","?","?","{\\pounds}","?","\\Y","?","?",
  72. /* 0xa8 */ "?","{\\copyright}","?","?","?","?","?","?",
  73. /* 0xb0 */ "\\o ", "\\+- ","$^{2}$","$^{3}$","?","?","\\P ","?",
  74. /* 0xb8 */ "?","$^{1}$", "?","?", "\\frac{1}{4}", "\\frac{1}{2}","\\frac{3}{4}",
  75.         "?",
  76. /* 0xc0 */ "\\`{A}","\\'{A}","\\o{A}",
  77.         "\\~{A}","\\\"{A}","?","\\AE ","\\c{C}",
  78. /* 0xc8 */ "\\`{E}","\\'{E}","\\o{E}","\\\"{E}",
  79.         "\\`{I}","\\'{I}","\\o{I}","\\\"{I}",
  80. /* 0xd0 */ "\\ETH ","\\~{N}","\\`{O}","\\'{O}",
  81.         "\\o{O}","\\~{O}","\\\"{O}","\\mult ",
  82. /* 0xd8 */ "?","\\`{U}","\\'{U}","\\o{U}",
  83.         "\\\"{U}","\\'{Y}","\\THORN","?",
  84. /* 0xe0 */ "\\`{a}","\\'{a}","\\o{a}",
  85.         "\\~{a}","\\\"{a}","?","\\ae ","\\c{c}",
  86. /* 0xe8 */ "\\`{e}","\\'{e}","\\o{e}","\\\"{e}",
  87.         "\\`{i}","\\'{i}","\\o{i}","\\\"{i}",
  88. /* 0xf0 */ "\\eth ","\\~{n}","\\`{o}","\\'{o}",
  89.         "\\o{o}","\\~{o}","\\\"{o}","\\div ",
  90. /* 0xf8 */ "\\slash{o}","\\`{u}","\\'{u}","\\o{u}",
  91.         "\\\"{u}","\\'{y}","\\thorn ","\\\"{y}",
  92. };
  93.  
  94. static char* mac [] = {
  95.         "?",
  96. };
  97.  
  98. static char* cp437 [] = {
  99.         "?",
  100. };
  101.  
  102. static char* cp850 [] = {
  103.         "?",
  104. };
  105.  
  106.  
  107.  
  108.  
  109. /*========================================================================
  110.  * Name:        latex_init
  111.  * Purpose:     Generates the output personality for LaTeX.
  112.  * Args:        None.
  113.  * Returns:     OutputPersonality.
  114.  *=======================================================================*/
  115.  
  116. OutputPersonality *
  117. latex_init (void)
  118. {
  119.         OutputPersonality* op;
  120.  
  121.         op = op_create();
  122.  
  123.         op->comment_begin = "%% ";
  124.         op->comment_end = "\n";
  125.  
  126.         op->document_begin = "\\documentclass[11pt]{article}\n";
  127.         op->document_end = "\\end{document}";
  128.  
  129.         op->header_begin = "";
  130.         op->header_end = "";
  131.  
  132.         op->document_title_begin = "\\title{";
  133.         op->document_title_end = "}\n";
  134.  
  135.         op->document_author_begin = "\\author{";
  136.         op->document_author_end = "}\n";
  137.  
  138.         op->document_changedate_begin = "\\date{";
  139.         op->document_changedate_end = "}\n";
  140.  
  141.         op->body_begin = "\n\n\\begin{document}\n\\maketitle\n";
  142.         op->body_end = "\\end{document}\n";
  143.  
  144.         op->paragraph_begin = "\\par\n";
  145.         op->paragraph_end = "";
  146.  
  147.         op->center_begin = "\\center{\n";
  148.         op->center_end = "}\n";
  149.  
  150.         op->justify_begin = "";
  151.         op->justify_end = "";
  152.  
  153.         op->align_left_begin = "\\begin{sloppy}\n";
  154.         op->align_left_end = "\\end{sloppy}\n";
  155.  
  156.         op->align_right_begin = "";
  157.         op->align_right_end = "";
  158.  
  159.         op->forced_space = "";
  160.         op->line_break = "\\par\n";
  161.         op->page_break = "\\pagebreak ";
  162.  
  163.         op->hyperlink_begin = "";
  164.         op->hyperlink_end = "";
  165.  
  166.         op->imagelink_begin = "";
  167.         op->imagelink_end = "";
  168.  
  169.         op->table_begin = "\\begin{tabular}{|lllll}\n";
  170.         op->table_end = "\n\\end{tabular}\n";
  171.  
  172.         op->table_row_begin = "";
  173.         op->table_row_end = "\\hline \\\\\n";
  174.  
  175.         op->table_cell_begin = "";
  176.         op->table_cell_end = " & ";
  177.  
  178.         /* Character attributes */
  179.         op->font_begin = "";
  180.         op->font_end = "";
  181.  
  182.         op->fontsize_begin = "";
  183.         op->fontsize_end = "";
  184.  
  185.         op->fontsize8_begin = "\\tiny{";
  186.         op->fontsize8_end = "}";
  187.         op->fontsize10_begin = "\\small{";
  188.         op->fontsize10_end = "}";
  189.         op->fontsize12_begin = "\\normalsize{";
  190.         op->fontsize12_end = "}";
  191.         op->fontsize14_begin = "{\\large ";
  192.         op->fontsize14_end = "}";
  193.         op->fontsize18_begin = "{\\Large ";
  194.         op->fontsize18_end = "}";
  195.         op->fontsize24_begin = "{\\LARGE ";
  196.         op->fontsize24_end = "}";
  197.         op->fontsize36_begin = "{\\huge ";
  198.         op->fontsize36_end = "}";
  199.         op->fontsize48_begin = "{\\Huge ";
  200.         op->fontsize48_end = "}";
  201.  
  202.         op->smaller_begin = "";
  203.         op->smaller_end = "";
  204.  
  205.         op->bigger_begin = "";
  206.         op->bigger_end = "";
  207.  
  208.         op->foreground_begin = "";
  209.         op->foreground_end = "";
  210.  
  211.         op->background_begin = "";
  212.         op->background_end = "";
  213.  
  214.         op->bold_begin = "{\\bf ";
  215.         op->bold_end = "}";
  216.  
  217.         op->italic_begin = "{\\it ";
  218.         op->italic_end = "}";
  219.  
  220.         op->underline_begin = "";
  221.         op->underline_end = "\n";
  222.  
  223.         op->dbl_underline_begin = "{\\ul ";
  224.         op->dbl_underline_end = "}";
  225.  
  226.         op->pointlist_begin = "\\begin{itemize}\n";
  227.         op->pointlist_end = "\\end{itemize}\n";
  228.         op->pointlist_item_begin = "\\item ";
  229.         op->pointlist_item_end = "";
  230.  
  231.         op->numericlist_begin = "\\begin{enumerate}\n";
  232.         op->numericlist_end = "\\end{enumerate}\n";
  233.         op->numericlist_item_begin = "\\item ";
  234.         op->numericlist_item_end = "";
  235.  
  236.         op->superscript_begin = "$^{";
  237.         op->superscript_end = "}$";
  238.  
  239.         op->subscript_begin = "$_{";
  240.         op->subscript_end = "}$";
  241.  
  242.         op->strikethru_begin = "{";
  243.         op->strikethru_end = "}";
  244.  
  245.         op->dbl_strikethru_begin = "{";
  246.         op->dbl_strikethru_end = "}";
  247.  
  248.         op->emboss_begin="";
  249.         op->emboss_end = "";
  250.  
  251.         op->engrave_begin = "";
  252.         op->engrave_end = "";
  253.  
  254.         op->shadow_begin= "";
  255.         op->shadow_end= "";
  256.  
  257.         op->small_caps_begin= "\\textsc{";
  258.         op->small_caps_end= "}";
  259.  
  260.         op->outline_begin= "";
  261.         op->outline_end= "";
  262.  
  263.         op->expand_begin = "";
  264.         op->expand_end = "";
  265.  
  266.         op->simulate_small_caps = FALSE;
  267.         op->simulate_all_caps = TRUE;
  268.         op->simulate_word_underline = TRUE;
  269.  
  270.         op->ascii_translation_table = ascii;
  271.  
  272.         op->ansi_translation_table = ansi;
  273.         op->ansi_first_char = 0x80;
  274.         op->ansi_last_char = 0x80;
  275.  
  276.         op->cp437_translation_table = cp437;
  277.         op->cp437_first_char = 0x80;
  278.         op->cp437_last_char = 0x80;
  279.  
  280.         op->cp850_translation_table = cp850;
  281.         op->cp850_first_char = 0x80;
  282.         op->cp850_last_char = 0x80;
  283.  
  284.         op->mac_translation_table = mac;
  285.         op->mac_first_char = 0x80;
  286.         op->mac_last_char = 0x80;
  287.  
  288.         op->chars.right_quote = "'";
  289.         op->chars.left_quote = "`";
  290.         op->chars.right_dbl_quote = "''";
  291.         op->chars.left_dbl_quote = "``";
  292.  
  293.         return op;
  294. }
  295.  
  296.  
  297.