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:    convert
  26.  * Author name:    Zach Smith
  27.  * Create date:    24 Jul 01
  28.  * Purpose:        Performs conversion from RTF to other formats.
  29.  *----------------------------------------------------------------------
  30.  * Changes:
  31.  * 24 Jul 01, tuorfa@yahoo.com: moved code over from word.c
  32.  * 24 Jul 01, tuorfa@yahoo.com: fixed color table reference numbering.
  33.  * 30 Jul 01, tuorfa@yahoo.com: moved hex convert to util.c
  34.  * 30 Jul 01, tuorfa@yahoo.com: moved special expr tables to special.c
  35.  * 30 Jul 01, tuorfa@yahoo.com: moved attribute stack to attr.c
  36.  * 31 Jul 01, tuorfa@yahoo.com: began addition of hash of rtf commands
  37.  * 01 Aug 01, tuorfa@yahoo.com: finished bulk of rtf command hash
  38.  * 03 Aug 01, tuorfa@yahoo.com: removed no-op hash entries to save space
  39.  * 03 Aug 01, tuorfa@yahoo.com: code to ignore rest of groups for \*, etc
  40.  * 03 Aug 01, tuorfa@yahoo.com: fixed para-alignnot being cleared by \pard
  41.  * 03 Aug 01, tuorfa@yahoo.com: added support for \keywords group
  42.  * 03 Aug 01, tuorfa@yahoo.com: added dummy funcs for header/footer
  43.  * 03 Aug 01, tuorfa@yahoo.com: began addition of hyperlink support
  44.  * 04 Aug 01, tuorfa@yahoo.com: fixed debug string printing
  45.  * 05 Aug 01, tuorfa@yahoo.com: added support for hyperlink data with \field
  46.  * 06 Aug 01, tuorfa@yahoo.com: added support for several font attributes
  47.  * 08 Aug 01, gommer@gmx.net: bugfix for picture storing mechanism
  48.  * 08 Sep 01, tuorfa@yahoo.com: added use of PROGRAM_NAME
  49.  * 11 Sep 01, tuorfa@yahoo.com: added support for JPEG and PNG pictures
  50.  * 19 Sep 01, tuorfa@yahoo.com: added output personality support
  51.  * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks
  52.  * 23 Sep 01, tuorfa@yahoo.com: fixed translation of \'XX expressions
  53.  *--------------------------------------------------------------------*/
  54.  
  55. #include <stdio.h>
  56. #include <stdlib.h>
  57. #include <ctype.h>
  58. #include <string.h>
  59.  
  60. #include "defs.h"
  61. #include "parse.h"
  62. #include "util.h"
  63. #include "malloc.h"
  64. #include "main.h"
  65. #include "error.h"
  66. #include "word.h"
  67. #include "hash.h"
  68. #include "convert.h"
  69. #include "attr.h"
  70.  
  71.  
  72. /*
  73. #define BINARY_ATTRS
  74. */
  75.  
  76.  
  77. static int charset_type=CHARSET_ANSI;
  78.  
  79.  
  80. /* Nested tables aren't supported.
  81.  */
  82. static int coming_pars_that_are_tabular = 0;
  83. static int within_table = FALSE;
  84. static int have_printed_row_begin=FALSE;
  85. static int have_printed_cell_begin=FALSE;
  86. static int have_printed_row_end=FALSE;
  87. static int have_printed_cell_end=FALSE;
  88.  
  89.  
  90. /* Previously in word_print_core function
  91.  */
  92. static int total_chars_this_line=0; /* for simulating \tab */
  93.  
  94.  
  95. /* Paragraph alignment (kludge)
  96.  */
  97. enum {
  98.         ALIGN_LEFT=0,
  99.         ALIGN_RIGHT,
  100.         ALIGN_CENTER,
  101.         ALIGN_JUSTIFY
  102. };
  103.  
  104.  
  105.  
  106. /* This value is set by attr_push and attr_pop
  107.  */
  108. int simulate_smallcaps;
  109. int simulate_allcaps;
  110.  
  111.  
  112. /* Most pictures must be written to files. */
  113. enum {
  114.         PICT_UNKNOWN=0,
  115.         PICT_WM,
  116.         PICT_MAC,
  117.         PICT_PM,
  118.         PICT_DI,
  119.         PICT_WB,
  120.         PICT_JPEG,
  121.         PICT_PNG,
  122. };
  123. static int within_picture=FALSE;
  124. static int picture_file_number=1;
  125. static char picture_path[255];
  126. static int picture_width;
  127. static int picture_height;
  128. static int picture_bits_per_pixel=1;
  129. static int picture_type=PICT_UNKNOWN;
  130. static int picture_wmetafile_type;
  131. static char *picture_wmetafile_type_str;
  132.  
  133.  
  134. static int have_printed_body=FALSE;
  135. static int within_header=TRUE;
  136.  
  137.  
  138.  
  139. static char *hyperlink_base = NULL;
  140.  
  141.  
  142.  
  143. void starting_body();
  144. void starting_text();
  145.  
  146.  
  147. static int banner_printed=FALSE;
  148.  
  149.  
  150.  
  151. /*========================================================================
  152.  * Name:        print_banner
  153.  * Purpose:     Writes program-identifying text to the output stream.
  154.  * Args:        None.
  155.  * Returns:     None.
  156.  *=======================================================================*/
  157.  
  158. void
  159. print_banner () {
  160.         if (!banner_printed) {
  161.                 printf (op->comment_begin);
  162.                 printf ("Translation from RTF performed by ");
  163.                 printf ("%s, version ", PROGRAM_NAME);
  164.                 printf ("%s", PROGRAM_VERSION);
  165.                 printf (op->comment_end);
  166.  
  167.                 printf (op->comment_begin);
  168.                 printf ("For information about this marvellous program,");
  169.                 printf (op->comment_end);
  170.  
  171.                 printf (op->comment_begin);
  172.                 printf ("please go to %s", PROGRAM_WEBSITE);
  173.                 printf (op->comment_end);
  174.         }
  175.         banner_printed=TRUE;
  176. }
  177.  
  178.  
  179. /*========================================================================
  180.  * Name:        starting_body
  181.  * Purpose:     Switches output stream for writing document contents.
  182.  * Args:        None.
  183.  * Returns:     None.
  184.  *=======================================================================*/
  185.  
  186. void
  187. starting_body ()
  188. {
  189.         if (!have_printed_body) {
  190.                 if (!inline_mode) {
  191.                         printf (op->header_end);
  192.                         printf (op->body_begin);
  193.                 }
  194.                 within_header=FALSE;
  195.                 have_printed_body=TRUE;
  196.         }
  197. }
  198.  
  199.  
  200. /*-------------------------------------------------------------------*/
  201. /*-------------------------------------------------------------------*/
  202. /*-------------------------------------------------------------------*/
  203.  
  204.  
  205. static char *month_strings[12]= {
  206. #ifdef ENGLISH
  207.   "January","February","March","April","May","June","July","August",
  208.   "September","October","November","December"
  209. #endif
  210. #ifdef FRANCAIS
  211.   "Janvier","Fevrier","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre",
  212.   "Octobre","Novembre","Decembre"
  213. #endif
  214. #ifdef ITALIANO
  215.   "Ianuario","Febbraio","Marzo","Aprile","Maggio","Iuno",
  216.   "Luglio","Agusto","Settembre","Ottobre","Novembre","Dicembre"
  217. #endif
  218. #ifdef ESPANOL
  219.   "?","Febraio","Marzo","Abril","Mayo","?","?","Agosto",
  220.   "Septiembre","Octubre","Noviembre","Diciembre"
  221. #endif
  222. #ifdef DEUTCH
  223.   "?","?","?","?","?","?","?","?",
  224.   "?","?","?","?"
  225. #endif
  226. };
  227.  
  228.  
  229. /*========================================================================
  230.  * Name:        word_dump_date
  231.  * Purpose:     Extracts date from an RTF input stream, writes it to
  232.  *              output stream.
  233.  * Args:        Word*, buffered RTF stream
  234.  * Returns:     None.
  235.  *=======================================================================*/
  236.  
  237. void
  238. word_dump_date (Word *w)
  239. {
  240.         int year=0, month=0, day=0, hour=0, minute=0;
  241.         CHECK_PARAM_NOT_NULL(w);
  242.         while (w) {
  243.                 char *s = word_string (w);
  244.                 if (*s == '\\') {
  245.                         ++s;
  246.                         if (!strncmp (s, "yr", 2) && isdigit(s[2])) {
  247.                                 year = atoi (&s[2]);
  248.                         }
  249.                         else if (!strncmp (s, "mo", 2) && isdigit(s[2])) {
  250.                                 month= atoi (&s[2]);
  251.                         }
  252.                         else if (!strncmp (s, "dy", 2) && isdigit(s[2])) {
  253.                                 day= atoi (&s[2]);
  254.                         }
  255.                         else if (!strncmp (s, "min", 3) && isdigit(s[3])) {
  256.                                 minute= atoi (&s[3]);
  257.                         }
  258.                         else if (!strncmp (s, "hr", 2) && isdigit(s[2])) {
  259.                                 hour= atoi (&s[2]);
  260.                         }
  261.                 }
  262.                 w=w->next;
  263.         }
  264.         if (year && month && day) {
  265.                 printf ("%d %s %d ", day, month_strings[month-1], year);
  266.         }
  267.         if (hour && minute) {
  268.                 printf ("%02d:%02d ", hour, minute);
  269.         }
  270. }
  271.  
  272.  
  273.  
  274. /*-------------------------------------------------------------------*/
  275.  
  276. typedef struct {
  277.         int num;
  278.         char *name;
  279. } FontEntry;
  280.  
  281. #define MAX_FONTS (256)
  282. static FontEntry font_table[MAX_FONTS];
  283. static int total_fonts=0;
  284.  
  285.  
  286.  
  287. /*========================================================================
  288.  * Name:        lookup_fontname
  289.  * Purpose:     Fetches the name of a font from the already-read font table.
  290.  * Args:        Font#.
  291.  * Returns:     Font name.
  292.  *=======================================================================*/
  293.  
  294. char*
  295. lookup_fontname (int num) {
  296.         int i;
  297.         if (total_fonts)
  298.         for(i=0;i<total_fonts;i++) {
  299.                 if (font_table[i].num==num)
  300.                         return font_table[i].name;
  301.         }
  302.         return NULL;
  303. }
  304.  
  305.  
  306. /*========================================================================
  307.  * Name:        process_font_table
  308.  * Purpose:     Processes the font table of an RTF file.
  309.  * Args:        Tree of words.
  310.  * Returns:     None.
  311.  *=======================================================================*/
  312.  
  313. void
  314. process_font_table (Word *w)
  315. {
  316.         Word *w2;
  317.  
  318.         CHECK_PARAM_NOT_NULL(w);
  319.  
  320.         while(w) {
  321.                 int num;
  322.                 char name[255];
  323.                 char *tmp;
  324.  
  325.                 if ((w2=w->child)) {
  326.                         tmp = word_string (w2);
  327.                         if (!strncmp("\\f",tmp,2)) {
  328.                                 num = atoi (&tmp[2]);
  329.                                 name[0]=0;
  330.  
  331.                                 w2=w2->next;
  332.                                 while(w2) {
  333.                                         tmp = word_string (w2);
  334.                                         if (tmp && tmp[0] != '\\')
  335.                                                 strcat(name,tmp);
  336.  
  337.                                         w2=w2->next;
  338.                                 }
  339.  
  340.                                 /* Chop the gall-derned semicolon. */
  341.                                 if ((tmp=strchr(name,';')))
  342.                                         *tmp=0;
  343.  
  344.                                 font_table[total_fonts].num=num;
  345.                                 font_table[total_fonts].name=my_strdup(name);
  346.                                 total_fonts++;
  347.                         }
  348.                 }
  349.                 w=w->next;
  350.         }
  351.  
  352.         printf (op->comment_begin);
  353.         printf ("font table contains %d fonts total",total_fonts);
  354.         printf (op->comment_end);
  355.  
  356.         if (debug_mode) {
  357.                 int i;
  358.  
  359.                 printf (op->comment_begin);
  360.                 printf ("font table dump: \n");
  361.                 for (i=0; i<total_fonts; i++) {
  362.                         printf (" font %d = %s\n", font_table[i].num,
  363.                                 font_table[i].name);
  364.                 }
  365.                 printf (op->comment_end);
  366.         }
  367. }
  368.  
  369.  
  370. /*========================================================================
  371.  * Name:        process_index_entry
  372.  * Purpose:     Processes an index entry of an RTF file.
  373.  * Args:        Tree of words.
  374.  * Returns:     None.
  375.  *=======================================================================*/
  376.  
  377. void
  378. process_index_entry (Word *w)
  379. {
  380.         Word *w2;
  381.  
  382.         CHECK_PARAM_NOT_NULL(w);
  383.  
  384.         while(w) {
  385.                 if ((w2=w->child)) {
  386.                         char *str = word_string (w2);
  387.  
  388.                         if (debug_mode && str) {
  389.                                 printf (op->comment_begin);
  390.                                 printf ("index entry word: %s ", str);
  391.                                 printf (op->comment_end);
  392.                         }
  393.                 }
  394.                 w=w->next;
  395.         }
  396. }
  397.  
  398.  
  399. /*========================================================================
  400.  * Name:        process_toc_entry
  401.  * Purpose:     Processes an index entry of an RTF file.
  402.  * Args:        Tree of words, flag to say whether to include a page#.
  403.  * Returns:     None.
  404.  *=======================================================================*/
  405.  
  406. void
  407. process_toc_entry (Word *w, int include_page_num)
  408. {
  409.         Word *w2;
  410.  
  411.         CHECK_PARAM_NOT_NULL(w);
  412.  
  413.         while(w) {
  414.                 if ((w2=w->child)) {
  415.                         char *str = word_string (w2);
  416.  
  417.                         if (debug_mode && str) {
  418.                                 printf (op->comment_begin);
  419.                                 printf ("toc %s entry word: %s ",
  420.                                         include_page_num ? "page#":"no page#",
  421.                                         str);
  422.                                 printf (op->comment_end);
  423.                         }
  424.                 }
  425.                 w=w->next;
  426.         }
  427. }
  428.  
  429.  
  430. /*========================================================================
  431.  * Name:        process_info_group
  432.  * Purpose:     Processes the \info group of an RTF file.
  433.  * Args:        Tree of words.
  434.  * Returns:     None.
  435.  *=======================================================================*/
  436.  
  437. void
  438. process_info_group (Word *w)
  439. {
  440.         Word *child;
  441.  
  442.         CHECK_PARAM_NOT_NULL(w);
  443.  
  444.         while(w) {
  445.                 child = w->child;
  446.                 if (child) {
  447.                         Word *w2;
  448.                         char *s;
  449.  
  450.                         s = word_string(child);
  451.  
  452.                         if (!inline_mode) {
  453.                                 if (!strcmp("\\title", s)) {
  454.                                         printf (op->document_title_begin);
  455.                                         w2=child->next;
  456.                                         while (w2) {
  457.                                                 char *s2 = word_string(w2);
  458.                                                 if (s2[0] != '\\')
  459.                                                         printf ("%s", s2);
  460.                                                 w2=w2->next;
  461.                                         }
  462.                                         printf (op->document_title_end);
  463.                                 }
  464.                                 else if (!strcmp("\\keywords", s)) {
  465.                                         printf (op->document_keywords_begin);
  466.                                         w2=child->next;
  467.                                         while (w2) {
  468.                                                 char *s2 = word_string(w2);
  469.                                                 if (s2[0] != '\\')
  470.                                                         printf ("%s,", s2);
  471.                                                 w2=w2->next;
  472.                                         }
  473.                                         printf (op->document_keywords_end);
  474.                                 }
  475.                                 else if (!strcmp("\\author", s)) {
  476.                                         printf (op->document_author_begin);
  477.                                         w2=child->next;
  478.                                         while (w2) {
  479.                                                 char *s2 = word_string(w2);
  480.                                                 if (s2[0] != '\\')
  481.                                                         printf ("%s", s2);
  482.                                                 w2=w2->next;
  483.                                         }
  484.                                         printf (op->document_author_end);
  485.                                 }
  486.                                 else if (!strcmp("\\comment", s)) {
  487.                                         printf (op->comment_begin);
  488.                                         printf ("comments: ");
  489.                                         w2=child->next;
  490.                                         while (w2) {
  491.                                                 char *s2 = word_string(w2);
  492.                                                 if (s2[0] != '\\')
  493.                                                         printf ("%s", s2);
  494.                                                 w2=w2->next;
  495.                                         }
  496.                                         printf (op->comment_end);
  497.                                 }
  498.                                 else if (!strncmp("\\nofpages", s, 9)) {
  499.                                         printf (op->comment_begin);
  500.                                         printf ("total pages: %s",&s[9]);
  501.                                         printf (op->comment_end);
  502.                                 }
  503.                                 else if (!strncmp("\\nofwords", s, 9)) {
  504.                                         printf (op->comment_begin);
  505.                                         printf ("total words: %s",&s[9]);
  506.                                         printf (op->comment_end);
  507.                                 }
  508.                                 else if (!strncmp("\\nofchars", s, 9) && isdigit(s[9])) {
  509.                                         printf (op->comment_begin);
  510.                                         printf ("total chars: %s",&s[9]);
  511.                                         printf (op->comment_end);
  512.                                 }
  513.                                 else if (!strcmp("\\creatim", s)) {
  514.                                         printf (op->comment_begin);
  515.                                         printf ("creaton date: ");
  516.                                         if (child->next) word_dump_date (child->next);
  517.                                         printf (op->comment_end);
  518.                                 }
  519.                                 else if (!strcmp("\\printim", s)) {
  520.                                         printf (op->comment_begin);
  521.                                         printf ("last printed: ");
  522.                                         if (child->next) word_dump_date (child->next);
  523.                                         printf (op->comment_end);
  524.                                 }
  525.                                 else if (!strcmp("\\buptim", s)) {
  526.                                         printf (op->comment_begin);
  527.                                         printf ("last backup: ");
  528.                                         if (child->next) word_dump_date (child->next);
  529.                                         printf (op->comment_end);
  530.                                 }
  531.                                 else if (!strcmp("\\revtim", s)) {
  532.                                         printf (op->comment_begin);
  533.                                         printf ("revision date: ");
  534.                                         if (child->next) word_dump_date (child->next);
  535.                                         printf (op->comment_end);
  536.                                 }
  537.                         }
  538.  
  539.                         /* Irregardless of whether we're in inline mode,
  540.                          * we want to process the following.
  541.                          */
  542.                         if (!strcmp("\\hlinkbase", s)) {
  543.                                 char *linkstr = NULL;
  544.  
  545.                                 printf (op->comment_begin);
  546.                                 printf ("hyperlink base: ");
  547.                                 if (child->next) {
  548.                                         Word *nextword = child->next;
  549.  
  550.                                         if (nextword)
  551.                                                 linkstr=word_string (nextword);
  552.                                 }
  553.  
  554.                                 if (linkstr)
  555.                                         printf ("%s", linkstr);
  556.                                 else
  557.                                         printf ("(none)");
  558.                                 printf (op->comment_end);
  559.  
  560.                                 /* Store the pointer, it will remain good. */
  561.                                 hyperlink_base = linkstr;
  562.                         }
  563.                 }
  564.                 w = w->next;
  565.         }
  566. }
  567.  
  568. /*-------------------------------------------------------------------*/
  569.  
  570. /* RTF color table colors are RGB */
  571.  
  572. typedef struct {
  573.         unsigned char r,g,b;
  574. } Color;
  575.  
  576. #define MAX_COLORS (256)
  577. static Color color_table[MAX_COLORS];
  578. static int total_colors=0;
  579.  
  580.  
  581. /*========================================================================
  582.  * Name:        process_color_table
  583.  * Purpose:     Processes the color table of an RTF file.
  584.  * Args:        Tree of words.
  585.  * Returns:     None.
  586.  *=======================================================================*/
  587.  
  588. void
  589. process_color_table (Word *w)
  590. {
  591.         int r,g,b;
  592.  
  593.         CHECK_PARAM_NOT_NULL(w);
  594.  
  595.         /* Sometimes, RTF color tables begin with a semicolon,
  596.          * i.e. an empty color entry. This seems to indicate that color 0
  597.          * will not be used, so here I set it to black.
  598.          */
  599.         r=g=b=0;
  600.  
  601.         while(w) {
  602.                 char *s = word_string (w);
  603.  
  604. #if 0
  605.                 printf (op->comment_begin);
  606.                 printf ("found this color table word: %s", word_string(w));
  607.                 printf (op->comment_end);
  608. #endif
  609.  
  610.                 if(!strncmp("\\red",s,4)) {
  611.                         r = atoi(&s[4]);
  612.                         while(r>255) r>>=8;
  613.                 }
  614.                 else if(!strncmp("\\green",s,6)) {
  615.                         g = atoi(&s[6]);
  616.                         while(g>255) g>>=8;
  617.                 }
  618.                 else if(!strncmp("\\blue",s,5)) {
  619.                         b = atoi(&s[5]);
  620.                         while(b>255) b>>=8;
  621.                 }
  622.                 else
  623.                 /* If we find the semicolon which denotes the end of
  624.                  * a color entry then store the color, even if we don't
  625.                  * have all of it.
  626.                  */
  627.                 if (!strcmp (";", s)) {
  628.                         color_table[total_colors].r = r;
  629.                         color_table[total_colors].g = g;
  630.                         color_table[total_colors++].b = b;
  631.                         if (debug_mode) {
  632.                                 printf (op->comment_begin);
  633.                                 printf ("storing color entry %d: %02x%02x%02x",
  634.                                         total_colors-1, r,g,b);
  635.                                 printf (op->comment_end);
  636.                         }
  637.                         r=g=b=0;
  638.                 }
  639.  
  640.                 w=w->next;
  641.         }
  642.  
  643.         if (debug_mode) {
  644.                 printf (op->comment_begin);
  645.                 printf ("color table had %d entries -->\n", total_colors);
  646.                 printf (op->comment_end);
  647.         }
  648. }
  649.  
  650. /*========================================================================
  651.  * Name:        cmd_cf
  652.  * Purpose:     Executes the \cf command.
  653.  * Args:        Word, paragraph align info, and numeric param if any.
  654.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  655.  *=======================================================================*/
  656.  
  657. static int
  658. cmd_cf (Word *w, int align, char has_param, short num) {
  659.         char str[40];
  660.  
  661.         if (!has_param || num>=total_colors) {
  662.                 warning_handler ("font color change attempted is invalid");
  663.         }
  664.         else
  665.         {
  666.                 sprintf (str,"#%02x%02x%02x",
  667.                         color_table[num].r,
  668.                         color_table[num].g,
  669.                         color_table[num].b);
  670.                 attr_push(ATTR_FOREGROUND,str);
  671.         }
  672.         return FALSE;
  673. }
  674.  
  675.  
  676.  
  677. /*========================================================================
  678.  * Name:        cmd_cb
  679.  * Purpose:     Executes the \cb command.
  680.  * Args:        Word, paragraph align info, and numeric param if any.
  681.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  682.  *=======================================================================*/
  683.  
  684. static int
  685. cmd_cb (Word *w, int align, char has_param, short num) {
  686.         char str[40];
  687.  
  688.         if (!has_param || num>=total_colors) {
  689.                 warning_handler ("font color change attempted is invalid");
  690.         }
  691.         else
  692.         {
  693.                 sprintf (str,"#%02x%02x%02x",
  694.                         color_table[num].r,
  695.                         color_table[num].g,
  696.                         color_table[num].b);
  697.                 attr_push(ATTR_BACKGROUND,str);
  698.         }
  699.         return FALSE;
  700. }
  701.  
  702.  
  703. /*========================================================================
  704.  * Name:        cmd_fs
  705.  * Purpose:     Executes the \fs command.
  706.  * Args:        Word, paragraph align info, and numeric param if any.
  707.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  708.  *=======================================================================*/
  709. static int
  710. cmd_fs (Word *w, int align, char has_param, short points) {
  711.         char str[20];
  712.  
  713.         if (!has_param) return FALSE;
  714.  
  715.         /* Note, fs20 means 10pt */
  716.         points /= 2;
  717.  
  718.         sprintf (str,"%d",points);
  719.         attr_push(ATTR_FONTSIZE,str);
  720.  
  721.         return FALSE;
  722. }
  723.  
  724.  
  725. /*========================================================================
  726.  * Name:        cmd_field
  727.  * Purpose:     Interprets fields looking for hyperlinks.
  728.  * Comment:     Because hyperlinks are put in \field groups,
  729.  *              we must interpret all \field groups, which is
  730.  *              slow and laborious.
  731.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  732.  *=======================================================================*/
  733.  
  734. static int
  735. cmd_field (Word *w, int align, char has_param, short num) {
  736.         Word *child;
  737.  
  738.         CHECK_PARAM_NOT_NULL(w);
  739.  
  740.         while(w) {
  741.                 child = w->child;
  742.                 if (child) {
  743.                         Word *w2;
  744.                         char *s;
  745.  
  746.                         s = word_string(child);
  747.  
  748.                         if (!strcmp("\\*", s)) {
  749.                                 w2=child->next;
  750.                                 while (w2) {
  751.                                         char *s2 = word_string(w2);
  752.                                         if (s2 && !strcmp("\\fldinst", s2)) {
  753.                                                 Word *w3;
  754.                                                 w3=w2->next;
  755.                                                 while (w3 && !w3->child) {
  756.                                                         w3=w3->next;
  757.                                                 }
  758.                                                 if (w3) w3=w3->child;
  759.                                                 while (w3) {
  760.                                                         char *s3=word_string(w3);
  761.                                                         if (s3 && !strcmp("HYPERLINK",s3)) {
  762.                                                                 Word *w4;
  763.                                                                 char *s4;
  764.                                                                 w4=w3->next;
  765.                                                                 while (w4 && !strcmp(" ", word_string(w4)))
  766.                                                                         w4=w4->next;
  767.                                                                 if (w4) {
  768.                                                                         s4=word_string(w4);
  769.                                                                         printf (op->hyperlink_begin);
  770.                                                                         printf ("%s", s4);
  771.                                                                         printf (op->hyperlink_end);
  772.                                                                         return TRUE;
  773.                                                                 }
  774.                                                                
  775.                                                         }
  776.                                                         w3=w3->next;
  777.                                                 }
  778.                                         }
  779.                                         w2=w2->next;
  780.                                 }
  781.                                
  782.                         }
  783.                 }
  784.                 w=w->next;
  785.         }
  786.         return TRUE;
  787. }
  788.  
  789.  
  790.  
  791. /*========================================================================
  792.  * Name:        cmd_f
  793.  * Purpose:     Executes the \f command.
  794.  * Args:        Word, paragraph align info, and numeric param if any.
  795.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  796.  *=======================================================================*/
  797. static int
  798. cmd_f (Word *w, int align, char has_param, short num) {
  799.         char *name;
  800.  
  801.         /* no param exit early XX */
  802.         if (!has_param)
  803.                 return FALSE;
  804.  
  805.         name = lookup_fontname(num);
  806.         if(!name) {
  807.                 printf (op->comment_begin);
  808.                 printf ("invalid font number %d",num);
  809.                 printf (op->comment_end);
  810.         } else {
  811.                 attr_push(ATTR_FONTFACE,name);
  812.         }
  813.  
  814.         return FALSE;
  815. }
  816.  
  817.  
  818. /*========================================================================
  819.  * Name:        cmd_highlight
  820.  * Purpose:     Executes the \cf command.
  821.  * Args:        Word, paragraph align info, and numeric param if any.
  822.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  823.  *=======================================================================*/
  824.  
  825. static int
  826. cmd_highlight (Word *w, int align, char has_param, short num)
  827. {
  828.         char str[40];
  829.  
  830.         if (!has_param || num>=total_colors) {
  831.                 warning_handler ("font background color change attempted is invalid");
  832.         }
  833.         else
  834.         {
  835.                 sprintf (str,"#%02x%02x%02x",
  836.                         color_table[num].r,
  837.                         color_table[num].g,
  838.                         color_table[num].b);
  839.                 attr_push(ATTR_BACKGROUND,str);
  840.         }
  841.         return FALSE;
  842. }
  843.  
  844.  
  845.  
  846. /*========================================================================
  847.  * Name:        cmd_tab
  848.  * Purpose:     Executes the \tab command.
  849.  * Args:        Word, paragraph align info, and numeric param if any.
  850.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  851.  *=======================================================================*/
  852.  
  853. static int
  854. cmd_tab (Word *w, int align, char has_param, short param)
  855. {
  856.         /* Tab presents a genuine problem
  857.          * since some output formats don't have
  858.          * an equivalent. As a kludge fix, I shall
  859.          * assume the font is fixed width and that
  860.          * the tabstops are 8 characters apart.
  861.          */
  862.         int need= 8-(total_chars_this_line%8);
  863.         total_chars_this_line += need;
  864.         while(need>0) {
  865.                 printf (op->forced_space);
  866.                 need--;
  867.         }
  868.         printf ("\n");
  869.         return FALSE;
  870. }
  871.  
  872.  
  873. /*========================================================================
  874.  * Name:        cmd_plain
  875.  * Purpose:     Executes the \plain command.
  876.  * Args:        Word, paragraph align info, and numeric param if any.
  877.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  878.  *=======================================================================*/
  879.  
  880. static int
  881. cmd_plain (Word *w, int align, char has_param, short param) {
  882.         attr_pop_all();
  883.         return FALSE;
  884. }
  885.  
  886.  
  887. /*========================================================================
  888.  * Name:        cmd_fnil
  889.  * Purpose:     Executes the \fnil command.
  890.  * Args:        Word, paragraph align info, and numeric param if any.
  891.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  892.  *=======================================================================*/
  893. static int
  894. cmd_fnil (Word *w, int align, char has_param, short param) {
  895.         attr_push(ATTR_FONTFACE,FONTNIL_STR);
  896.         return FALSE;
  897. }
  898.  
  899.  
  900.  
  901. /*========================================================================
  902.  * Name:        cmd_froman
  903.  * Purpose:     Executes the \froman command.
  904.  * Args:        Word, paragraph align info, and numeric param if any.
  905.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  906.  *=======================================================================*/
  907. static int
  908. cmd_froman (Word *w, int align, char has_param, short param) {
  909.         attr_push(ATTR_FONTFACE,FONTROMAN_STR);
  910.         return FALSE;
  911. }
  912.  
  913.  
  914. /*========================================================================
  915.  * Name:        cmd_fswiss
  916.  * Purpose:     Executes the \fswiss command.
  917.  * Args:        Word, paragraph align info, and numeric param if any.
  918.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  919.  *=======================================================================*/
  920.  
  921. static int
  922. cmd_fswiss (Word *w, int align, char has_param, short param) {
  923.         attr_push(ATTR_FONTFACE,FONTSWISS_STR);
  924.         return FALSE;
  925. }
  926.  
  927.  
  928. /*========================================================================
  929.  * Name:        cmd_fmodern
  930.  * Purpose:     Executes the \fmodern command.
  931.  * Args:        Word, paragraph align info, and numeric param if any.
  932.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  933.  *=======================================================================*/
  934.  
  935. static int
  936. cmd_fmodern (Word *w, int align, char has_param, short param) {
  937.         attr_push(ATTR_FONTFACE,FONTMODERN_STR);
  938.         return FALSE;
  939. }
  940.  
  941.  
  942. /*========================================================================
  943.  * Name:        cmd_fscript
  944.  * Purpose:     Executes the \fscript command.
  945.  * Args:        Word, paragraph align info, and numeric param if any.
  946.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  947.  *=======================================================================*/
  948.  
  949. static int
  950. cmd_fscript (Word *w, int align, char has_param, short param) {
  951.         attr_push(ATTR_FONTFACE,FONTSCRIPT_STR);
  952.         return FALSE;
  953. }
  954.  
  955. /*========================================================================
  956.  * Name:        cmd_fdecor
  957.  * Purpose:     Executes the \fdecor command.
  958.  * Args:        Word, paragraph align info, and numeric param if any.
  959.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  960.  *=======================================================================*/
  961.  
  962. static int
  963. cmd_fdecor (Word *w, int align, char has_param, short param) {
  964.         attr_push(ATTR_FONTFACE,FONTDECOR_STR);
  965.         return FALSE;
  966. }
  967.  
  968. /*========================================================================
  969.  * Name:        cmd_ftech
  970.  * Purpose:     Executes the \ftech command.
  971.  * Args:        Word, paragraph align info, and numeric param if any.
  972.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  973.  *=======================================================================*/
  974.  
  975. static int
  976. cmd_ftech (Word *w, int align, char has_param, short param) {
  977.         attr_push(ATTR_FONTFACE,FONTTECH_STR);
  978.         return FALSE;
  979. }
  980.  
  981. /*========================================================================
  982.  * Name:        cmd_expand
  983.  * Purpose:     Executes the \expand command.
  984.  * Args:        Word, paragraph align info, and numeric param if any.
  985.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  986.  *=======================================================================*/
  987.  
  988. static int
  989. cmd_expand (Word *w, int align, char has_param, short param) {
  990.         char str[10];
  991.         if (has_param) {
  992.                 sprintf (str, "%d", param/4);
  993.                 if (!param)
  994.                         attr_pop(ATTR_EXPAND);
  995.                 else
  996.                         attr_push(ATTR_EXPAND, str);
  997.         }
  998.         return FALSE;
  999. }
  1000.  
  1001.  
  1002. /*========================================================================
  1003.  * Name:        cmd_emboss
  1004.  * Purpose:     Executes the \embo command.
  1005.  * Args:        Word, paragraph align info, and numeric param if any.
  1006.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1007.  *=======================================================================*/
  1008.  
  1009. static int
  1010. cmd_emboss (Word *w, int align, char has_param, short param) {
  1011.         char str[10];
  1012.         if (has_param && !param)
  1013.                 attr_pop(ATTR_EMBOSS);
  1014.         else
  1015.         {
  1016.                 sprintf (str, "%d", param);
  1017.                 attr_push(ATTR_EMBOSS, str);
  1018.         }
  1019.         return FALSE;
  1020. }
  1021.  
  1022.  
  1023. /*========================================================================
  1024.  * Name:        cmd_engrave
  1025.  * Purpose:     Executes the \impr command.
  1026.  * Args:        Word, paragraph align info, and numeric param if any.
  1027.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1028.  *=======================================================================*/
  1029.  
  1030. static int
  1031. cmd_engrave (Word *w, int align, char has_param, short param) {
  1032.         char str[10];
  1033.         if (has_param && !param)
  1034.                 attr_pop(ATTR_ENGRAVE);
  1035.         else
  1036.         {
  1037.                 sprintf (str, "%d", param);
  1038.                 attr_push(ATTR_ENGRAVE, str);
  1039.         }
  1040.         return FALSE;
  1041. }
  1042.  
  1043. /*========================================================================
  1044.  * Name:        cmd_caps
  1045.  * Purpose:     Executes the \caps command.
  1046.  * Args:        Word, paragraph align info, and numeric param if any.
  1047.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1048.  *=======================================================================*/
  1049.  
  1050. static int
  1051. cmd_caps (Word *w, int align, char has_param, short param) {
  1052.         if (has_param && !param)
  1053.                 attr_pop(ATTR_CAPS);
  1054.         else
  1055.                 attr_push(ATTR_CAPS,NULL);
  1056.         return FALSE;
  1057. }
  1058.  
  1059.  
  1060. /*========================================================================
  1061.  * Name:        cmd_scaps
  1062.  * Purpose:     Executes the \scaps command.
  1063.  * Args:        Word, paragraph align info, and numeric param if any.
  1064.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1065.  *=======================================================================*/
  1066. static int
  1067. cmd_scaps (Word *w, int align, char has_param, short param) {
  1068.         if (has_param && !param)
  1069.                 attr_pop(ATTR_SMALLCAPS);
  1070.         else
  1071.                 attr_push(ATTR_SMALLCAPS,NULL);
  1072.         return FALSE;
  1073. }
  1074.  
  1075.  
  1076. /*========================================================================
  1077.  * Name:        cmd_bullet
  1078.  * Purpose:     Executes the \bullet command.
  1079.  * Args:        Word, paragraph align info, and numeric param if any.
  1080.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1081.  *=======================================================================*/
  1082. static int
  1083. cmd_bullet (Word *w, int align, char has_param, short param) {
  1084.         printf (op->chars.bullet);
  1085.         ++total_chars_this_line; /* \tab */
  1086.         return FALSE;
  1087. }
  1088.  
  1089. /*========================================================================
  1090.  * Name:        cmd_ldblquote
  1091.  * Purpose:     Executes the \ldblquote command.
  1092.  * Args:        Word, paragraph align info, and numeric param if any.
  1093.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1094.  *=======================================================================*/
  1095. static int
  1096. cmd_ldblquote (Word *w, int align, char has_param, short param) {
  1097.         printf (op->chars.left_dbl_quote);
  1098.         ++total_chars_this_line; /* \tab */
  1099.         return FALSE;
  1100. }
  1101.  
  1102.  
  1103. /*========================================================================
  1104.  * Name:        cmd_rdblquote
  1105.  * Purpose:     Executes the \rdblquote command.
  1106.  * Args:        Word, paragraph align info, and numeric param if any.
  1107.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1108.  *=======================================================================*/
  1109.  
  1110. static int
  1111. cmd_rdblquote (Word *w, int align, char has_param, short param) {
  1112.         printf (op->chars.right_dbl_quote);
  1113.         ++total_chars_this_line; /* \tab */
  1114.         return FALSE;
  1115. }
  1116.  
  1117.  
  1118. /*========================================================================
  1119.  * Name:        cmd_lquote
  1120.  * Purpose:     Executes the \lquote command.
  1121.  * Args:        Word, paragraph align info, and numeric param if any.
  1122.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1123.  *=======================================================================*/
  1124. static int
  1125. cmd_lquote (Word *w, int align, char has_param, short param) {
  1126.         printf (op->chars.left_quote);
  1127.         ++total_chars_this_line; /* \tab */
  1128.         return FALSE;
  1129. }
  1130.  
  1131.  
  1132. /*========================================================================
  1133.  * Name:        cmd_nonbreaking_space
  1134.  * Purpose:     Executes the nonbreaking space command.
  1135.  * Args:        Word, paragraph align info, and numeric param if any.
  1136.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1137.  *=======================================================================*/
  1138.  
  1139. static int
  1140. cmd_nonbreaking_space (Word *w, int align, char has_param, short param) {
  1141.         printf (op->chars.nonbreaking_space);
  1142.         ++total_chars_this_line; /* \tab */
  1143.         return FALSE;
  1144. }
  1145.  
  1146.  
  1147. /*========================================================================
  1148.  * Name:        cmd_nonbreaking_hyphen
  1149.  * Purpose:     Executes the nonbreaking hyphen command.
  1150.  * Args:        Word, paragraph align info, and numeric param if any.
  1151.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1152.  *=======================================================================*/
  1153.  
  1154. static int
  1155. cmd_nonbreaking_hyphen (Word *w, int align, char has_param, short param) {
  1156.         printf (op->chars.nonbreaking_hyphen);
  1157.         ++total_chars_this_line; /* \tab */
  1158.         return FALSE;
  1159. }
  1160.  
  1161.  
  1162. /*========================================================================
  1163.  * Name:        cmd_optional_hyphen
  1164.  * Purpose:     Executes the optional hyphen command.
  1165.  * Args:        Word, paragraph align info, and numeric param if any.
  1166.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1167.  *=======================================================================*/
  1168.  
  1169. static int
  1170. cmd_optional_hyphen (Word *w, int align, char has_param, short param) {
  1171.         printf (op->chars.optional_hyphen);
  1172.         ++total_chars_this_line; /* \tab */
  1173.         return FALSE;
  1174. }
  1175.  
  1176.  
  1177. /*========================================================================
  1178.  * Name:        cmd_emdash
  1179.  * Purpose:     Executes the \emdash command.
  1180.  * Args:        Word, paragraph align info, and numeric param if any.
  1181.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1182.  *=======================================================================*/
  1183. static int
  1184. cmd_emdash (Word *w, int align, char has_param, short param) {
  1185.         printf (op->chars.emdash);
  1186.         ++total_chars_this_line; /* \tab */
  1187.         return FALSE;
  1188. }
  1189.  
  1190.  
  1191. /*========================================================================
  1192.  * Name:        cmd_endash
  1193.  * Purpose:     Executes the \endash command.
  1194.  * Args:        Word, paragraph align info, and numeric param if any.
  1195.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1196.  *=======================================================================*/
  1197.  
  1198. static int
  1199. cmd_endash (Word *w, int align, char has_param, short param) {
  1200.         printf (op->chars.endash);
  1201.         ++total_chars_this_line; /* \tab */
  1202.         return FALSE;
  1203. }
  1204.  
  1205.  
  1206. /*========================================================================
  1207.  * Name:        cmd_rquote
  1208.  * Purpose:     Executes the \rquote command.
  1209.  * Args:        Word, paragraph align info, and numeric param if any.
  1210.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1211.  *=======================================================================*/
  1212.  
  1213. static int
  1214. cmd_rquote (Word *w, int align, char has_param, short param) {
  1215.         printf (op->chars.right_quote);
  1216.         ++total_chars_this_line; /* \tab */
  1217.         return FALSE;
  1218. }
  1219.  
  1220.  
  1221. /*========================================================================
  1222.  * Name:        cmd_par
  1223.  * Purpose:     Executes the \par command.
  1224.  * Args:        Word, paragraph align info, and numeric param if any.
  1225.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1226.  *=======================================================================*/
  1227. static int
  1228. cmd_par (Word *w, int align, char has_param, short param) {
  1229.         printf (op->line_break);
  1230.         total_chars_this_line = 0; /* \tab */
  1231.         return FALSE;
  1232. }
  1233.  
  1234.  
  1235. /*========================================================================
  1236.  * Name:        cmd_line
  1237.  * Purpose:     Executes the \line command.
  1238.  * Args:        Word, paragraph align info, and numeric param if any.
  1239.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1240.  *=======================================================================*/
  1241.  
  1242. static int
  1243. cmd_line (Word *w, int align, char has_param, short param) {
  1244.         printf (op->line_break);
  1245.         total_chars_this_line = 0; /* \tab */
  1246.         return FALSE;
  1247. }
  1248.  
  1249.  
  1250. /*========================================================================
  1251.  * Name:        cmd_page
  1252.  * Purpose:     Executes the \page command.
  1253.  * Args:        Word, paragraph align info, and numeric param if any.
  1254.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1255.  *=======================================================================*/
  1256.  
  1257. static int cmd_page (Word *w, int align, char has_param, short param) {
  1258.         printf (op->page_break);
  1259.         total_chars_this_line = 0; /* \tab */
  1260.         return FALSE;
  1261. }
  1262.  
  1263.  
  1264. /*========================================================================
  1265.  * Name:        cmd_intbl
  1266.  * Purpose:     Executes the \intbl command.
  1267.  * Args:        Word, paragraph align info, and numeric param if any.
  1268.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1269.  *=======================================================================*/
  1270.  
  1271. static int cmd_intbl (Word *w, int align, char has_param, short param) {
  1272.         ++coming_pars_that_are_tabular;
  1273.         return FALSE;
  1274. }
  1275.  
  1276.  
  1277. /*========================================================================
  1278.  * Name:        cmd_ulnone
  1279.  * Purpose:     Executes the \ulnone command.
  1280.  * Args:        Word, paragraph align info, and numeric param if any.
  1281.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1282.  *=======================================================================*/
  1283.  
  1284. static int cmd_ulnone (Word *w, int align, char has_param, short param) {
  1285.         int attr, more=TRUE;
  1286. #ifdef BINARY_ATTRS
  1287.         attr_remove_underlining();
  1288. #else
  1289.         do {
  1290.                 attr = attr_read();
  1291.                 if (attr==ATTR_UNDERLINE ||
  1292.                     attr==ATTR_DOT_UL ||
  1293.                     attr==ATTR_DASH_UL ||
  1294.                     attr==ATTR_DOT_DASH_UL ||
  1295.                     attr==ATTR_2DOT_DASH_UL ||
  1296.                     attr==ATTR_WORD_UL ||
  1297.                     attr==ATTR_WAVE_UL ||
  1298.                     attr==ATTR_THICK_UL ||
  1299.                     attr==ATTR_DOUBLE_UL)
  1300.                 {
  1301.                   if (!attr_pop(ATTR_UNDERLINE))
  1302.                     ;
  1303.                 } else
  1304.                   more=FALSE;
  1305.         } while(more);
  1306. #endif
  1307.         return FALSE;
  1308. }
  1309.  
  1310. /*========================================================================
  1311.  * Name:        cmd_ul
  1312.  * Purpose:     Executes the \ul command.
  1313.  * Args:        Word, paragraph align info, and numeric param if any.
  1314.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1315.  *=======================================================================*/
  1316.  
  1317. static int cmd_ul (Word *w, int align, char has_param, short param) {
  1318.         if (has_param && param == 0) {
  1319.                 cmd_ulnone (w, align, has_param, param);
  1320.         } else {
  1321.                 attr_push (ATTR_UNDERLINE,NULL);
  1322.         }
  1323.         return FALSE;
  1324. }
  1325.  
  1326. /*========================================================================
  1327.  * Name:        cmd_uld
  1328.  * Purpose:     Executes the \uld command.
  1329.  * Args:        Word, paragraph align info, and numeric param if any.
  1330.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1331.  *=======================================================================*/
  1332.  
  1333. static int cmd_uld (Word *w, int align, char has_param, short param) {
  1334.         attr_push(ATTR_DOUBLE_UL,NULL);
  1335.         return FALSE;
  1336. }
  1337.  
  1338. /*========================================================================
  1339.  * Name:        cmd_uldb
  1340.  * Purpose:     Executes the \uldb command.
  1341.  * Args:        Word, paragraph align info, and numeric param if any.
  1342.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1343.  *=======================================================================*/
  1344.  
  1345. static int cmd_uldb (Word *w, int align, char has_param, short param) {
  1346.         attr_push(ATTR_DOT_UL,NULL);
  1347.         return FALSE;
  1348. }
  1349.  
  1350.  
  1351. /*========================================================================
  1352.  * Name:        cmd_uldash
  1353.  * Purpose:     Executes the \uldash command.
  1354.  * Args:        Word, paragraph align info, and numeric param if any.
  1355.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1356.  *=======================================================================*/
  1357.  
  1358. static int cmd_uldash (Word *w, int align, char has_param, short param) {
  1359.         attr_push(ATTR_DASH_UL,NULL);
  1360.         return FALSE;
  1361. }
  1362.  
  1363.  
  1364. /*========================================================================
  1365.  * Name:        cmd_uldashd
  1366.  * Purpose:     Executes the \cmd_uldashd command.
  1367.  * Args:        Word, paragraph align info, and numeric param if any.
  1368.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1369.  *=======================================================================*/
  1370.  
  1371. static int cmd_uldashd (Word *w, int align, char has_param, short param) {
  1372.         attr_push(ATTR_DOT_DASH_UL,NULL);
  1373.         return FALSE;
  1374. }
  1375.  
  1376.  
  1377. /*========================================================================
  1378.  * Name:        cmd_uldashdd
  1379.  * Purpose:     Executes the \uldashdd command.
  1380.  * Args:        Word, paragraph align info, and numeric param if any.
  1381.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1382.  *=======================================================================*/
  1383.  
  1384. static int cmd_uldashdd (Word *w, int align, char has_param, short param) {
  1385.         attr_push(ATTR_2DOT_DASH_UL,NULL);
  1386.         return FALSE;
  1387. }
  1388.  
  1389.  
  1390. /*========================================================================
  1391.  * Name:        cmd_ulw
  1392.  * Purpose:     Executes the \ulw command.
  1393.  * Args:        Word, paragraph align info, and numeric param if any.
  1394.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1395.  *=======================================================================*/
  1396.  
  1397. static int cmd_ulw (Word *w, int align, char has_param, short param) {
  1398.         attr_push(ATTR_WORD_UL,NULL);
  1399.         return FALSE;
  1400. }
  1401.  
  1402.  
  1403. /*========================================================================
  1404.  * Name:        cmd_ulth
  1405.  * Purpose:     Executes the \ulth command.
  1406.  * Args:        Word, paragraph align info, and numeric param if any.
  1407.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1408.  *=======================================================================*/
  1409.  
  1410. static int cmd_ulth (Word *w, int align, char has_param, short param) {
  1411.         attr_push(ATTR_THICK_UL,NULL);
  1412.         return FALSE;
  1413. }
  1414.  
  1415.  
  1416. /*========================================================================
  1417.  * Name:        cmd_ulwave
  1418.  * Purpose:     Executes the \ulwave command.
  1419.  * Args:        Word, paragraph align info, and numeric param if any.
  1420.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1421.  *=======================================================================*/
  1422.  
  1423. static int cmd_ulwave (Word *w, int align, char has_param, short param) {
  1424.         attr_push(ATTR_WAVE_UL,NULL);
  1425.         return FALSE;
  1426. }
  1427.  
  1428.  
  1429. /*========================================================================
  1430.  * Name:        cmd_strike
  1431.  * Purpose:     Executes the \strike command.
  1432.  * Args:        Word, paragraph align info, and numeric param if any.
  1433.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1434.  *=======================================================================*/
  1435.  
  1436. static int cmd_strike (Word *w, int align, char has_param, short param) {
  1437.         if (has_param && param==0)
  1438.                 attr_pop(ATTR_STRIKE);
  1439.         else
  1440.                 attr_push(ATTR_STRIKE,NULL);
  1441.         return FALSE;
  1442. }
  1443.  
  1444. /*========================================================================
  1445.  * Name:        cmd_strikedl
  1446.  * Purpose:     Executes the \strikedl command.
  1447.  * Args:        Word, paragraph align info, and numeric param if any.
  1448.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1449.  *=======================================================================*/
  1450.  
  1451. static int cmd_strikedl (Word *w, int align, char has_param, short param) {
  1452.         if (has_param && param==0)
  1453.                 attr_pop(ATTR_DBL_STRIKE);
  1454.         else
  1455.                 attr_push(ATTR_DBL_STRIKE,NULL);
  1456.         return FALSE;
  1457. }
  1458.  
  1459.  
  1460. /*========================================================================
  1461.  * Name:        cmd_striked
  1462.  * Purpose:     Executes the \striked command.
  1463.  * Args:        Word, paragraph align info, and numeric param if any.
  1464.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1465.  *=======================================================================*/
  1466.  
  1467. static int cmd_striked (Word *w, int align, char has_param, short param) {
  1468.         if (has_param && param==0)
  1469.                 attr_pop(ATTR_DBL_STRIKE);
  1470.         else
  1471.                 attr_push(ATTR_DBL_STRIKE,NULL);
  1472.         return FALSE;
  1473. }
  1474.  
  1475.  
  1476. /*========================================================================
  1477.  * Name:        cmd_rtf
  1478.  * Purpose:     Executes the \rtf command.
  1479.  * Args:        Word, paragraph align info, and numeric param if any.
  1480.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1481.  *=======================================================================*/
  1482.  
  1483. static int cmd_rtf (Word *w, int align, char has_param, short param) {
  1484.         return FALSE;
  1485. }
  1486.  
  1487.  
  1488. /*========================================================================
  1489.  * Name:        cmd_up
  1490.  * Purpose:     Executes the \up command.
  1491.  * Args:        Word, paragraph align info, and numeric param if any.
  1492.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1493.  *=======================================================================*/
  1494.  
  1495. static int cmd_up (Word *w, int align, char has_param, short param) {
  1496.         if (has_param && param==0)
  1497.                 attr_pop(ATTR_SUPER);
  1498.         else
  1499.                 attr_push(ATTR_SUPER,NULL);
  1500.         return FALSE;
  1501. }
  1502.  
  1503.  
  1504. /*========================================================================
  1505.  * Name:        cmd_dn
  1506.  * Purpose:     Executes the \dn command.
  1507.  * Args:        Word, paragraph align info, and numeric param if any.
  1508.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1509.  *=======================================================================*/
  1510.  
  1511. static int cmd_dn (Word *w, int align, char has_param, short param) {
  1512.         if (has_param && param==0)
  1513.                 attr_pop(ATTR_SUB);
  1514.         else
  1515.                 attr_push(ATTR_SUB,NULL);
  1516.         return FALSE;
  1517. }
  1518.  
  1519. /*========================================================================
  1520.  * Name:        cmd_nosupersub
  1521.  * Purpose:     Executes the \nosupersub command.
  1522.  * Args:        Word, paragraph align info, and numeric param if any.
  1523.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1524.  *=======================================================================*/
  1525.  
  1526. static int cmd_nosupersub (Word *w, int align, char has_param, short param) {
  1527.         attr_pop(ATTR_SUPER);
  1528.         attr_pop(ATTR_SUB);
  1529.         return FALSE;
  1530. }
  1531.  
  1532. /*========================================================================
  1533.  * Name:        cmd_super
  1534.  * Purpose:     Executes the \super command.
  1535.  * Args:        Word, paragraph align info, and numeric param if any.
  1536.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1537.  *=======================================================================*/
  1538.  
  1539. static int cmd_super (Word *w, int align, char has_param, short param) {
  1540.         if (has_param && param==0)
  1541.                 attr_pop(ATTR_SUPER);
  1542.         else
  1543.                 attr_push(ATTR_SUPER,NULL);
  1544.         return FALSE;
  1545. }
  1546.  
  1547. /*========================================================================
  1548.  * Name:        cmd_sub
  1549.  * Purpose:     Executes the \sub command.
  1550.  * Args:        Word, paragraph align info, and numeric param if any.
  1551.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1552.  *=======================================================================*/
  1553.  
  1554. static int cmd_sub (Word *w, int align, char has_param, short param) {
  1555.         if (has_param && param==0)
  1556.                 attr_pop(ATTR_SUB);
  1557.         else
  1558.                 attr_push(ATTR_SUB,NULL);
  1559.         return FALSE;
  1560. }
  1561.  
  1562. /*========================================================================
  1563.  * Name:        cmd_shad
  1564.  * Purpose:     Executes the \shad command.
  1565.  * Args:        Word, paragraph align info, and numeric param if any.
  1566.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1567.  *=======================================================================*/
  1568.  
  1569. static int cmd_shad (Word *w, int align, char has_param, short param) {
  1570.         if (has_param && param==0)
  1571.                 attr_pop(ATTR_SHADOW);
  1572.         else
  1573.                 attr_push(ATTR_SHADOW,NULL);
  1574.         return FALSE;
  1575. }
  1576.  
  1577. /*========================================================================
  1578.  * Name:        cmd_b
  1579.  * Purpose:     Executes the \b command.
  1580.  * Args:        Word, paragraph align info, and numeric param if any.
  1581.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1582.  *=======================================================================*/
  1583.  
  1584. static int
  1585. cmd_b (Word *w, int align, char has_param, short param) {
  1586.         if (has_param && param==0) {
  1587.                 attr_pop(ATTR_BOLD);
  1588.         }
  1589.         else
  1590.                 attr_push(ATTR_BOLD,NULL);
  1591.         return FALSE;
  1592. }
  1593.  
  1594. /*========================================================================
  1595.  * Name:        cmd_i
  1596.  * Purpose:     Executes the \i command.
  1597.  * Args:        Word, paragraph align info, and numeric param if any.
  1598.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1599.  *=======================================================================*/
  1600.  
  1601. static int cmd_i (Word *w, int align, char has_param, short param) {
  1602.         if (has_param && param==0)
  1603.                 attr_pop(ATTR_ITALIC);
  1604.         else
  1605.                 attr_push(ATTR_ITALIC,NULL);
  1606.         return FALSE;
  1607. }
  1608.  
  1609. /*========================================================================
  1610.  * Name:        cmd_s
  1611.  * Purpose:     Executes the \s command.
  1612.  * Args:        Word, paragraph align info, and numeric param if any.
  1613.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1614.  *=======================================================================*/
  1615. static int cmd_s (Word *w, int align, char has_param, short param) {
  1616.         return FALSE;
  1617. }
  1618.  
  1619. /*========================================================================
  1620.  * Name:        cmd_sect
  1621.  * Purpose:     Executes the \sect command.
  1622.  * Args:        Word, paragraph align info, and numeric param if any.
  1623.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1624.  *=======================================================================*/
  1625.  
  1626. static int cmd_sect (Word *w, int align, char has_param, short param) {
  1627.         /* XX kludge */
  1628.         printf (op->paragraph_begin);
  1629.         return FALSE;
  1630. }
  1631.  
  1632. /*========================================================================
  1633.  * Name:        cmd_shp
  1634.  * Purpose:     Executes the \shp command.
  1635.  * Args:        Word, paragraph align info, and numeric param if any.
  1636.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1637.  *=======================================================================*/
  1638.  
  1639. static int cmd_shp (Word *w, int align, char has_param, short param) {
  1640.         printf (op->comment_begin);
  1641.         printf ("Drawn Shape (ignored--not implemented yet)");
  1642.         printf (op->comment_begin);
  1643.         return FALSE;
  1644. }
  1645.  
  1646. /*========================================================================
  1647.  * Name:        cmd_outl
  1648.  * Purpose:     Executes the \outl command.
  1649.  * Args:        Word, paragraph align info, and numeric param if any.
  1650.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1651.  *=======================================================================*/
  1652.  
  1653. static int cmd_outl (Word *w, int align, char has_param, short param) {
  1654.         if (has_param && param==0)
  1655.                 attr_pop(ATTR_OUTLINE);
  1656.         else
  1657.                 attr_push(ATTR_OUTLINE,NULL);
  1658.         return FALSE;
  1659. }
  1660.  
  1661. /*========================================================================
  1662.  * Name:        cmd_ansi
  1663.  * Purpose:     Executes the \ansi command.
  1664.  * Args:        Word, paragraph align info, and numeric param if any.
  1665.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1666.  *=======================================================================*/
  1667.  
  1668. static int cmd_ansi (Word *w, int align, char has_param, short param) {
  1669.         charset_type = CHARSET_ANSI;
  1670.         printf (op->comment_begin);
  1671.         printf ("document uses ANSI character set");
  1672.         printf (op->comment_end);
  1673.         return FALSE;
  1674. }
  1675.  
  1676. /*========================================================================
  1677.  * Name:        cmd_pc
  1678.  * Purpose:     Executes the \pc command.
  1679.  * Args:        Word, paragraph align info, and numeric param if any.
  1680.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1681.  *=======================================================================*/
  1682.  
  1683. static int cmd_pc (Word *w, int align, char has_param, short param) {
  1684.         charset_type = CHARSET_CP437 ;
  1685.         printf (op->comment_begin);
  1686.         printf ("document uses PC codepage 437 character set");
  1687.         printf (op->comment_end);
  1688.         return FALSE;
  1689. }
  1690.  
  1691. /*========================================================================
  1692.  * Name:        cmd_pca
  1693.  * Purpose:     Executes the \pca command.
  1694.  * Args:        Word, paragraph align info, and numeric param if any.
  1695.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1696.  *=======================================================================*/
  1697.  
  1698. static int cmd_pca (Word *w, int align, char has_param, short param) {
  1699.         charset_type = CHARSET_CP850;
  1700.         printf (op->comment_begin);
  1701.         printf ("document uses PC codepage 850 character set");
  1702.         printf (op->comment_end);
  1703.         return FALSE;
  1704. }
  1705.  
  1706. /*========================================================================
  1707.  * Name:        cmd_mac
  1708.  * Purpose:     Executes the \mac command.
  1709.  * Args:        Word, paragraph align info, and numeric param if any.
  1710.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1711.  *=======================================================================*/
  1712.  
  1713. static int cmd_mac (Word *w, int align, char has_param, short param) {
  1714.         charset_type = CHARSET_MAC;
  1715.         printf (op->comment_begin);
  1716.         printf ("document uses Macintosh character set");
  1717.         printf (op->comment_end);
  1718.         return FALSE;
  1719. }
  1720.  
  1721. /*========================================================================
  1722.  * Name:        cmd_colortbl
  1723.  * Purpose:     Executes the \colortbl command.
  1724.  * Args:        Word, paragraph align info, and numeric param if any.
  1725.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1726.  *=======================================================================*/
  1727.  
  1728. static int cmd_colortbl (Word *w, int align, char has_param, short param) {
  1729.         if (w->next) {
  1730.                 process_color_table(w->next);
  1731.         }
  1732.         return TRUE;
  1733. }
  1734.  
  1735. /*========================================================================
  1736.  * Name:        cmd_fonttbl
  1737.  * Purpose:     Executes the \fonttbl command.
  1738.  * Args:        Word, paragraph align info, and numeric param if any.
  1739.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1740.  *=======================================================================*/
  1741.  
  1742. static int cmd_fonttbl (Word *w, int align, char has_param, short param) {
  1743.         if (w->next) {
  1744.                 process_font_table(w->next);
  1745.         }
  1746.         return TRUE;
  1747. }
  1748.  
  1749. /*========================================================================
  1750.  * Name:        cmd_header
  1751.  * Purpose:     Executes the \header command.
  1752.  * Args:        Word, paragraph align info, and numeric param if any.
  1753.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1754.  *=======================================================================*/
  1755.  
  1756. static int cmd_header (Word *w, int align, char has_param, short param) {
  1757.         return TRUE;
  1758. }
  1759.  
  1760. /*========================================================================
  1761.  * Name:        cmd_headerl
  1762.  * Purpose:     Executes the \headerl command.
  1763.  * Args:        Word, paragraph align info, and numeric param if any.
  1764.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1765.  *=======================================================================*/
  1766.  
  1767. static int cmd_headerl (Word *w, int align, char has_param, short param) {
  1768.         return TRUE;
  1769. }
  1770.  
  1771. /*========================================================================
  1772.  * Name:        cmd_headerr
  1773.  * Purpose:     Executes the \headerr command.
  1774.  * Args:        Word, paragraph align info, and numeric param if any.
  1775.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1776.  *=======================================================================*/
  1777.  
  1778. static int cmd_headerr (Word *w, int align, char has_param, short param) {
  1779.         return TRUE;
  1780. }
  1781.  
  1782. /*========================================================================
  1783.  * Name:        cmd_headerf
  1784.  * Purpose:     Executes the \headerf command.
  1785.  * Args:        Word, paragraph align info, and numeric param if any.
  1786.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1787.  *=======================================================================*/
  1788.  
  1789. static int cmd_headerf (Word *w, int align, char has_param, short param) {
  1790.         return TRUE;
  1791. }
  1792.  
  1793. /*========================================================================
  1794.  * Name:        cmd_footer
  1795.  * Purpose:     Executes the \footer command.
  1796.  * Args:        Word, paragraph align info, and numeric param if any.
  1797.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1798.  *=======================================================================*/
  1799.  
  1800. static int cmd_footer (Word *w, int align, char has_param, short param) {
  1801.         return TRUE;
  1802. }
  1803.  
  1804. /*========================================================================
  1805.  * Name:        cmd_footerl
  1806.  * Purpose:     Executes the \footerl command.
  1807.  * Args:        Word, paragraph align info, and numeric param if any.
  1808.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1809.  *=======================================================================*/
  1810.  
  1811. static int cmd_footerl (Word *w, int align, char has_param, short param) {
  1812.         return TRUE;
  1813. }
  1814.  
  1815. /*========================================================================
  1816.  * Name:        cmd_footerr
  1817.  * Purpose:     Executes the \footerr command.
  1818.  * Args:        Word, paragraph align info, and numeric param if any.
  1819.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1820.  *=======================================================================*/
  1821.  
  1822. static int cmd_footerr (Word *w, int align, char has_param, short param) {
  1823.         return TRUE;
  1824. }
  1825.  
  1826. /*========================================================================
  1827.  * Name:        cmd_footerf
  1828.  * Purpose:     Executes the \footerf command.
  1829.  * Args:        Word, paragraph align info, and numeric param if any.
  1830.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1831.  *=======================================================================*/
  1832.  
  1833. static int cmd_footerf (Word *w, int align, char has_param, short param) {
  1834.         return TRUE;
  1835. }
  1836.  
  1837. /*========================================================================
  1838.  * Name:        cmd_ignore
  1839.  * Purpose:     Dummy function to get rid of subgroups
  1840.  * Args:        Word, paragraph align info, and numeric param if any.
  1841.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1842.  *=======================================================================*/
  1843.  
  1844. static int cmd_ignore (Word *w, int align, char has_param, short param) {
  1845.         return TRUE;
  1846. }
  1847.  
  1848. /*========================================================================
  1849.  * Name:        cmd_info
  1850.  * Purpose:     Executes the \info command.
  1851.  * Args:        Word, paragraph align info, and numeric param if any.
  1852.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1853.  *=======================================================================*/
  1854.  
  1855. static int cmd_info (Word *w, int align, char has_param, short param) {
  1856.         process_info_group (w->next);
  1857.         return TRUE;
  1858. }
  1859.  
  1860. /*========================================================================
  1861.  * Name:        cmd_pict
  1862.  * Purpose:     Executes the \pict command.
  1863.  * Args:        Word, paragraph align info, and numeric param if any.
  1864.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1865.  *=======================================================================*/
  1866.  
  1867. static int cmd_pict (Word *w, int align, char has_param, short param) {
  1868.         within_picture=TRUE;
  1869.         picture_width = picture_height = 0;
  1870.         picture_type = PICT_WB;
  1871.         return FALSE;          
  1872. }
  1873.  
  1874. /*========================================================================
  1875.  * Name:        cmd_bin
  1876.  * Purpose:     Executes the \bin command.
  1877.  * Args:        Word, paragraph align info, and numeric param if any.
  1878.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1879.  *=======================================================================*/
  1880.  
  1881. static int cmd_bin (Word *w, int align, char has_param, short param) {
  1882.         return FALSE;          
  1883. }
  1884.  
  1885.  
  1886. /*========================================================================
  1887.  * Name:        cmd_macpict
  1888.  * Purpose:     Executes the \macpict command.
  1889.  * Args:        Word, paragraph align info, and numeric param if any.
  1890.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1891.  *=======================================================================*/
  1892.  
  1893. static int cmd_macpict (Word *w, int align, char has_param, short param) {
  1894.         picture_type = PICT_MAC;
  1895.         return FALSE;          
  1896. }
  1897.  
  1898. /*========================================================================
  1899.  * Name:        cmd_jpegblip
  1900.  * Purpose:     Executes the \jpegblip command.
  1901.  * Args:        Word, paragraph align info, and numeric param if any.
  1902.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1903.  *=======================================================================*/
  1904.  
  1905. static int cmd_jpegblip (Word *w, int align, char has_param, short param) {
  1906.         picture_type = PICT_JPEG;
  1907.         return FALSE;          
  1908. }
  1909.  
  1910. /*========================================================================
  1911.  * Name:        cmd_pngblip
  1912.  * Purpose:     Executes the \pngblip command.
  1913.  * Args:        Word, paragraph align info, and numeric param if any.
  1914.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1915.  *=======================================================================*/
  1916.  
  1917. static int cmd_pngblip (Word *w, int align, char has_param, short param) {
  1918.         picture_type = PICT_PNG;
  1919.         return FALSE;          
  1920. }
  1921.  
  1922. /*========================================================================
  1923.  * Name:        cmd_pnmetafile
  1924.  * Purpose:     Executes the \pnmetafile command.
  1925.  * Args:        Word, paragraph align info, and numeric param if any.
  1926.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1927.  *=======================================================================*/
  1928.  
  1929. static int cmd_pnmetafile (Word *w, int align, char has_param, short param) {
  1930.         picture_type = PICT_PM;
  1931.         return FALSE;          
  1932. }
  1933.  
  1934. /*========================================================================
  1935.  * Name:        cmd_wmetafile
  1936.  * Purpose:     Executes the \wmetafile command.
  1937.  * Args:        Word, paragraph align info, and numeric param if any.
  1938.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1939.  *=======================================================================*/
  1940.  
  1941. static int cmd_wmetafile (Word *w, int align, char has_param, short param) {
  1942.         picture_type = PICT_WM;
  1943.         if (within_picture && has_param) {
  1944.                 picture_wmetafile_type=param;
  1945.                 switch(param) {
  1946.                 case 1: picture_wmetafile_type_str="MM_TEXT"; break;
  1947.                 case 2: picture_wmetafile_type_str="MM_LOMETRIC"; break;
  1948.                 case 3: picture_wmetafile_type_str="MM_HIMETRIC"; break;
  1949.                 case 4: picture_wmetafile_type_str="MM_LOENGLISH"; break;
  1950.                 case 5: picture_wmetafile_type_str="MM_HIENGLISH"; break;
  1951.                 case 6: picture_wmetafile_type_str="MM_TWIPS"; break;
  1952.                 case 7: picture_wmetafile_type_str="MM_ISOTROPIC"; break;
  1953.                 case 8: picture_wmetafile_type_str="MM_ANISOTROPIC"; break;
  1954.                 default: picture_wmetafile_type_str="default:MM_TEXT"; break;
  1955.                 }
  1956.         }
  1957.         return FALSE;          
  1958. }
  1959.  
  1960. /*========================================================================
  1961.  * Name:        cmd_wbmbitspixel
  1962.  * Purpose:     Executes the \wbmbitspixel command.
  1963.  * Args:        Word, paragraph align info, and numeric param if any.
  1964.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1965.  *=======================================================================*/
  1966.  
  1967. static int cmd_wbmbitspixel (Word *w, int align, char has_param, short param) {
  1968.         if (within_picture && has_param)
  1969.                 picture_bits_per_pixel = param;
  1970.         return FALSE;          
  1971. }
  1972.  
  1973. /*========================================================================
  1974.  * Name:        cmd_picw
  1975.  * Purpose:     Executes the \picw command.
  1976.  * Args:        Word, paragraph align info, and numeric param if any.
  1977.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1978.  *=======================================================================*/
  1979.  
  1980. static int cmd_picw (Word *w, int align, char has_param, short param) {
  1981.         if (within_picture && has_param)
  1982.                 picture_width = param;
  1983.         return FALSE;          
  1984. }
  1985.  
  1986. /*========================================================================
  1987.  * Name:        cmd_pich
  1988.  * Purpose:     Executes the \pich command.
  1989.  * Args:        Word, paragraph align info, and numeric param if any.
  1990.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  1991.  *=======================================================================*/
  1992.  
  1993. static int cmd_pich (Word *w, int align, char has_param, short param) {
  1994.         if (within_picture && has_param)
  1995.                 picture_height = param;
  1996.         return FALSE;          
  1997. }
  1998.  
  1999.  
  2000. /*========================================================================
  2001.  * Name:        cmd_xe
  2002.  * Purpose:     Executes the \xe (index entry) command.
  2003.  * Args:        Word, paragraph align info, and numeric param if any.
  2004.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  2005.  *=======================================================================*/
  2006.  
  2007. static int cmd_xe (Word *w, int align, char has_param, short param) {
  2008.         process_index_entry (w);
  2009.         return TRUE;           
  2010. }
  2011.  
  2012. /*========================================================================
  2013.  * Name:        cmd_tc
  2014.  * Purpose:     Executes the \tc (TOC entry) command.
  2015.  * Args:        Word, paragraph align info, and numeric param if any.
  2016.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  2017.  *=======================================================================*/
  2018.  
  2019. static int cmd_tc (Word *w, int align, char has_param, short param) {
  2020.         process_toc_entry (w, TRUE);
  2021.         return TRUE;           
  2022. }
  2023.  
  2024. /*========================================================================
  2025.  * Name:        cmd_tcn
  2026.  * Purpose:     Executes the \tcn (TOC entry, no page #) command.
  2027.  * Args:        Word, paragraph align info, and numeric param if any.
  2028.  * Returns:     Flag, true only if rest of Words on line should be ignored.
  2029.  *=======================================================================*/
  2030.  
  2031. static int cmd_tcn (Word *w, int align, char has_param, short param) {
  2032.         process_toc_entry (w, FALSE);
  2033.         return TRUE;           
  2034. }
  2035.  
  2036.  
  2037. typedef struct {
  2038.         char *name;
  2039.         int (*func)(Word*,int,char,short);
  2040.         char *debug_print;
  2041. }
  2042. HashItem;
  2043.  
  2044.  
  2045.  
  2046. static HashItem hashArray_other [] = {
  2047.         { "*", cmd_ignore, NULL },
  2048.         { "-", cmd_optional_hyphen, "optional hyphen" },
  2049.         { "_", cmd_nonbreaking_hyphen, "nonbreaking hyphen" },
  2050.         { "~", cmd_nonbreaking_space, NULL },
  2051.         { NULL, NULL, NULL}
  2052. };
  2053. static HashItem hashArray_a [] = {
  2054.         { "ansi", &cmd_ansi , NULL },
  2055.         { NULL, NULL, NULL}
  2056. };
  2057. static HashItem hashArray_b [] = {
  2058.         { "b", &cmd_b, NULL },
  2059.         { "bullet", &cmd_bullet, NULL },
  2060.         { "bin", &cmd_bin, "picture is binary" },
  2061. #if 0
  2062.         { "bgbdiag", NULL, NULL },
  2063.         { "bgcross", NULL, NULL },
  2064.         { "bgdcross", NULL, NULL },
  2065.         { "bgfdiag", NULL, NULL },
  2066.         { "bghoriz", NULL, NULL },
  2067.         { "bgkbdiag", NULL, NULL },
  2068.         { "bgkcross", NULL, NULL },
  2069.         { "bgkdcross", NULL, NULL },
  2070.         { "bgkfdiag", NULL, NULL },
  2071.         { "bgkhoriz", NULL, NULL },
  2072.         { "bgkvert", NULL, NULL },
  2073.         { "bgvert", NULL, NULL },
  2074.         { "brdrcf", NULL, NULL },
  2075.         { "brdrdb", NULL, NULL },
  2076.         { "brdrdot", NULL, NULL },
  2077.         { "brdrhair", NULL, NULL },
  2078.         { "brdrs", NULL, NULL },
  2079.         { "brdrsh", NULL, NULL },
  2080.         { "brdrth", NULL, NULL },
  2081.         { "brdrw", NULL, NULL },
  2082. #endif
  2083.         { NULL, NULL, NULL}
  2084. };
  2085. static HashItem hashArray_c [] = {
  2086.         { "caps", &cmd_caps, NULL },
  2087.         { "cb", cmd_cb, NULL },
  2088.         { "cf", cmd_cf, NULL },
  2089.         { "colortbl", &cmd_colortbl, "color table" },
  2090.         { "cols", NULL, "columns (not implemented)" },
  2091.         { "column", NULL, "column break (not implemented)" },
  2092. #if 0
  2093.         { "cbpat", NULL, NULL },
  2094.         { "cellx", NULL, NULL },
  2095.         { "cfpat", NULL, NULL },
  2096.         { "cgrid", NULL, NULL },
  2097.         { "clbgbcross", NULL, NULL },
  2098.         { "clbgbdiag", NULL, NULL },
  2099.         { "clbgbkbdiag", NULL, NULL },
  2100.         { "clbgbkcross", NULL, NULL },
  2101.         { "clbgbkdcross", NULL, NULL },
  2102.         { "clbgbkfdiag", NULL, NULL },
  2103.         { "clbgbkhor", NULL, NULL },
  2104.         { "clbgbkvert", NULL, NULL },
  2105.         { "clbgdcross", NULL, NULL },
  2106.         { "clbgfdiag", NULL, NULL },
  2107.         { "clbghoriz", NULL, NULL },
  2108.         { "clbgvert", NULL, NULL },
  2109.         { "clbrdrb", NULL, NULL },
  2110.         { "clbrdrl", NULL, NULL },
  2111.         { "clbrdrr", NULL, NULL },
  2112.         { "clbrdrt", NULL, NULL },
  2113.         { "clcbpat", NULL, NULL },
  2114.         { "clcfpat", NULL, NULL },
  2115.         { "clmgf", NULL, NULL },
  2116.         { "clmrg", NULL, NULL },
  2117.         { "clshdng", NULL, NULL },
  2118. #endif
  2119.         { NULL, NULL, NULL}
  2120. };
  2121. static HashItem hashArray_d [] = {
  2122.         { "dn", &cmd_dn, NULL },
  2123. #if 0
  2124.         { "dibitmap", NULL, NULL },
  2125. #endif
  2126.         { NULL, NULL, NULL}
  2127. };
  2128. static HashItem hashArray_e [] = {
  2129.         { "emdash", cmd_emdash, NULL },
  2130.         { "endash", cmd_endash, NULL },
  2131.         { "embo", &cmd_emboss, NULL },
  2132.         { "expand", &cmd_expand, NULL },
  2133.         { "expnd", &cmd_expand, NULL },
  2134.         { NULL, NULL, NULL}
  2135. };
  2136. static HashItem hashArray_f [] = {
  2137.         { "f", cmd_f, NULL },
  2138.         { "fdecor", cmd_fdecor, NULL },
  2139.         { "fmodern", cmd_fmodern, NULL },
  2140.         { "fnil", cmd_fnil, NULL },
  2141.         { "fonttbl", cmd_fonttbl, "font table" },
  2142.         { "froman", cmd_froman, NULL },
  2143.         { "fs", cmd_fs, NULL },
  2144.         { "fscript", cmd_fscript, NULL },
  2145.         { "fswiss", cmd_fswiss, NULL },
  2146.         { "ftech", cmd_ftech, NULL },
  2147.         { "field", cmd_field, NULL },
  2148.         { "footer", cmd_footer, NULL },
  2149.         { "footerf", cmd_footerf, NULL },
  2150.         { "footerl", cmd_footerl, NULL },
  2151.         { "footerr", cmd_footerr, NULL },
  2152.         { NULL, NULL, NULL}
  2153. };
  2154. static HashItem hashArray_h [] = {
  2155.         { "highlight", &cmd_highlight, NULL },
  2156.         { "header", cmd_header, NULL },
  2157.         { "headerf", cmd_headerf, NULL },
  2158.         { "headerl", cmd_headerl, NULL },
  2159.         { "headerr", cmd_headerr, NULL },
  2160.         { "hl", cmd_ignore, "hyperlink within object" },
  2161.         { NULL, NULL, NULL}
  2162. };
  2163. static HashItem hashArray_i [] = {
  2164.         { "i", &cmd_i, NULL },
  2165.         { "info", &cmd_info, NULL },
  2166.         { "intbl", &cmd_intbl, NULL },
  2167.         { "impr", &cmd_engrave, NULL },
  2168.         { NULL, NULL, NULL}
  2169. };
  2170. static HashItem hashArray_j [] = {
  2171.         { "jpegblip", &cmd_jpegblip, NULL },
  2172.         { NULL, NULL, NULL}
  2173. };
  2174. static HashItem hashArray_l [] = {
  2175.         { "ldblquote", &cmd_ldblquote, NULL },
  2176.         { "line", &cmd_line, NULL },
  2177.         { "lquote", &cmd_lquote, NULL },
  2178.         { NULL, NULL, NULL}
  2179. };
  2180. static HashItem hashArray_m [] = {
  2181.         { "mac", &cmd_mac , NULL },
  2182.         { "macpict", &cmd_macpict, NULL },
  2183.         { NULL, NULL, NULL}
  2184. };
  2185. static HashItem hashArray_n [] = {
  2186.         { "nosupersub", &cmd_nosupersub, NULL },
  2187.         { NULL, NULL, NULL}
  2188. };
  2189. static HashItem hashArray_o [] = {
  2190.         { "outl", &cmd_outl, NULL },
  2191.         { NULL, NULL, NULL}
  2192. };
  2193. static HashItem hashArray_p [] = {
  2194.         { "page", &cmd_page, NULL },
  2195.         { "par", &cmd_par, NULL },
  2196.         { "pc", &cmd_pc , NULL },
  2197.         { "pca", &cmd_pca , NULL },
  2198.         { "pich", &cmd_pich, NULL },
  2199.         { "pict", &cmd_pict, "picture" },
  2200.         { "picw", &cmd_picw, NULL },
  2201.         { "plain", &cmd_plain, NULL },
  2202.         { "pngblip", &cmd_pngblip, NULL },
  2203.         { "pnmetafile", &cmd_pnmetafile, NULL },
  2204. #if 0
  2205.         { "piccropb", NULL, NULL },
  2206.         { "piccropl", NULL, NULL },
  2207.         { "piccropr", NULL, NULL },
  2208.         { "piccropt", NULL, NULL },
  2209.         { "pichgoal", NULL, NULL },
  2210.         { "pichgoal", NULL, NULL },
  2211.         { "picscaled", NULL, NULL },
  2212.         { "picscalex", NULL, NULL },
  2213.         { "picwgoal", NULL, NULL },
  2214. #endif
  2215.         { NULL, NULL, NULL}
  2216. };
  2217. static HashItem hashArray_r [] = {
  2218.         { "rdblquote", &cmd_rdblquote, NULL },
  2219.         { "rquote", &cmd_rquote, NULL },
  2220.         { "rtf", &cmd_rtf, NULL },
  2221.         { NULL, NULL, NULL}
  2222. };
  2223. static HashItem hashArray_s [] = {
  2224.         { "s", cmd_s, "style" },
  2225.         { "sect", &cmd_sect, "section break"},
  2226.         { "scaps", &cmd_scaps, NULL },
  2227.         { "super", &cmd_super, NULL },
  2228.         { "sub", &cmd_sub, NULL },
  2229.         { "shad", &cmd_shad, NULL },
  2230.         { "strike", &cmd_strike, NULL },
  2231.         { "striked", &cmd_striked, NULL },
  2232.         { "strikedl", &cmd_strikedl, NULL },
  2233.         { "stylesheet", &cmd_ignore, "style sheet" },
  2234.         { "shp", cmd_shp, "drawn shape" },
  2235. #if 0
  2236.         { "shading", NULL, NULL },
  2237. #endif
  2238.         { NULL, NULL, NULL}
  2239. };
  2240. static HashItem hashArray_t [] = {
  2241.         { "tab", &cmd_tab, NULL },
  2242.         { "tc", cmd_tc, "TOC entry" },
  2243.         { "tcn", cmd_tcn, "TOC entry" },
  2244. #if 0
  2245.         { "tcf", NULL , NULL },
  2246.         { "tcl", NULL , NULL },
  2247.         { "trgaph", NULL , NULL },
  2248.         { "trleft", NULL , NULL },
  2249.         { "trowd", NULL , NULL },
  2250.         { "trqc", NULL , NULL },
  2251.         { "trql", NULL , NULL },
  2252.         { "trqr", NULL , NULL },
  2253.         { "trrh", NULL , NULL },
  2254. #endif
  2255.         { NULL, NULL, NULL}
  2256. };
  2257. static HashItem hashArray_u [] = {
  2258.         { "ul", &cmd_ul, NULL },
  2259.         { "up", &cmd_up, NULL },
  2260.         { "uld", &cmd_uld, NULL },
  2261.         { "uldash", &cmd_uldash, NULL },
  2262.         { "uldashd", &cmd_uldashd, NULL },
  2263.         { "uldashdd", &cmd_uldashdd, NULL },
  2264.         { "uldb", &cmd_uldb, NULL },
  2265.         { "ulnone", &cmd_ulnone, NULL },
  2266.         { "ulth", &cmd_ulth, NULL },
  2267.         { "ulw", &cmd_ulw, NULL },
  2268.         { "ulwave", &cmd_ulwave, NULL },
  2269.         { NULL, NULL, NULL}
  2270. };
  2271.  
  2272. static HashItem hashArray_w [] = {
  2273.         { "wbmbitspixel", &cmd_wbmbitspixel, NULL },
  2274.         { "wmetafile", &cmd_wmetafile, NULL },
  2275. #if 0
  2276.         { "wbitmap", NULL, NULL },
  2277.         { "wbmplanes", NULL, NULL },
  2278.         { "wbmwidthbytes", NULL, NULL },
  2279. #endif
  2280.         { NULL, NULL, NULL}
  2281. };
  2282.  
  2283. static HashItem hashArray_x [] = {
  2284.         { "xe", cmd_xe, "index entry" },
  2285.         { NULL, NULL, NULL}
  2286. };
  2287.  
  2288. static HashItem *hash [26] = {
  2289.         hashArray_a,
  2290.         hashArray_b,
  2291.         hashArray_c,
  2292.         hashArray_d,
  2293.         hashArray_e,
  2294.         hashArray_f,
  2295.         NULL,
  2296.         hashArray_h,
  2297.         hashArray_i,
  2298.         hashArray_j,
  2299.         NULL,
  2300.         hashArray_l,
  2301.         hashArray_m,
  2302.         hashArray_n,
  2303.         hashArray_o,
  2304.         hashArray_p,
  2305.         NULL,
  2306.         hashArray_r,
  2307.         hashArray_s,
  2308.         hashArray_t,
  2309.         hashArray_u,
  2310.         NULL,
  2311.         hashArray_w,
  2312.         hashArray_x,
  2313.         NULL, NULL
  2314. };
  2315.  
  2316.  
  2317. /*-------------------------------------------------------------------*/
  2318. /*-------------------------------------------------------------------*/
  2319.  
  2320.  
  2321.  
  2322. /*-------------------------------------------------------------------*/
  2323. /*-------------------------------------------------------------------*/
  2324.  
  2325.  
  2326. /*========================================================================
  2327.  * Name:       
  2328.  * Purpose:    
  2329.  * Args:        None.
  2330.  * Returns:     None.
  2331.  *=======================================================================*/
  2332.  
  2333. void
  2334. print_with_special_exprs (char *s) {
  2335.         int ch;
  2336.         int state;
  2337.  
  2338. enum { SMALL=0, BIG=1 };
  2339.  
  2340.         CHECK_PARAM_NOT_NULL(s);
  2341.  
  2342.         if (simulate_smallcaps) {
  2343.                 if (*s >= 'a' && *s <= 'z') {
  2344.                         state=SMALL;
  2345.                         printf (op->smaller_begin);
  2346.                 }
  2347.                 else
  2348.                         state=BIG;
  2349.         }
  2350.  
  2351.         while ((ch=*s)) {
  2352.                 char *post_trans = NULL;
  2353.  
  2354.                 if (simulate_allcaps || simulate_smallcaps)
  2355.                         ch = toupper (ch);
  2356.  
  2357.                 if (ch >= 0x20 && ch < 0x80) {
  2358.                         post_trans = op_translate_char (op, charset_type, ch);
  2359.                         printf ("%s",post_trans);
  2360.                 }
  2361.  
  2362.                 s++;
  2363.  
  2364.                 if (simulate_smallcaps) {
  2365.                         ch = *s;
  2366.                         if (ch >= 'a' && ch <= 'z') {
  2367.                                 if (state==BIG)
  2368.                                         printf (op->smaller_begin);
  2369.                                 state=SMALL;
  2370.                         }
  2371.                         else
  2372.                         {
  2373.                                 if (state==SMALL)
  2374.                                         printf (op->smaller_end);
  2375.                                 state=BIG;
  2376.                         }
  2377.                 }
  2378.         }
  2379. }
  2380.  
  2381.  
  2382.  
  2383. /*========================================================================
  2384.  * Name:       
  2385.  * Purpose:    
  2386.  * Args:        None.
  2387.  * Returns:     None.
  2388.  *=======================================================================*/
  2389.  
  2390. static void
  2391. begin_table()
  2392. {
  2393.         within_table=TRUE;
  2394.         have_printed_row_begin = FALSE;
  2395.         have_printed_cell_begin = FALSE;
  2396.         have_printed_row_end = FALSE;
  2397.         have_printed_cell_end = FALSE;
  2398.         attrstack_push();
  2399.         starting_body();
  2400.         printf (op->table_begin);
  2401. }
  2402.  
  2403.  
  2404.  
  2405. /*========================================================================
  2406.  * Name:       
  2407.  * Purpose:    
  2408.  * Args:        None.
  2409.  * Returns:     None.
  2410.  *=======================================================================*/
  2411.  
  2412. void
  2413. end_table ()
  2414. {
  2415.         if (within_table) {
  2416.                 if (!have_printed_cell_end) {
  2417.                         attr_pop_dump();
  2418.                         printf (op->table_cell_end);
  2419.                 }
  2420.                 if (!have_printed_row_end) {
  2421.                         printf (op->table_row_end);
  2422.                 }
  2423.                 printf (op->table_end);
  2424.                 within_table=FALSE;
  2425.                 have_printed_row_begin = FALSE;
  2426.                 have_printed_cell_begin = FALSE;
  2427.                 have_printed_row_end = FALSE;
  2428.                 have_printed_cell_end = FALSE;
  2429.         }
  2430. }
  2431.  
  2432.  
  2433.  
  2434. /*========================================================================
  2435.  * Name:       
  2436.  * Purpose:    
  2437.  * Args:        None.
  2438.  * Returns:     None.
  2439.  *=======================================================================*/
  2440.  
  2441. void
  2442. starting_text() {
  2443.         if (within_table) {
  2444.                 if (!have_printed_row_begin) {
  2445.                         printf (op->table_row_begin);
  2446.                         have_printed_row_begin=TRUE;
  2447.                         have_printed_row_end=FALSE;
  2448.                         have_printed_cell_begin=FALSE;
  2449.                 }
  2450.                 if (!have_printed_cell_begin) {
  2451.                         printf (op->table_cell_begin);
  2452.                         attrstack_express_all();
  2453.                         have_printed_cell_begin=TRUE;
  2454.                         have_printed_cell_end=FALSE;
  2455.                 }
  2456.         }
  2457. }
  2458.  
  2459.  
  2460.  
  2461.  
  2462. /*========================================================================
  2463.  * Name:       
  2464.  * Purpose:    
  2465.  * Args:        None.
  2466.  * Returns:     None.
  2467.  *=======================================================================*/
  2468.  
  2469. static void
  2470. starting_paragraph_align (int align)
  2471. {
  2472.         if (within_header && align != ALIGN_LEFT)
  2473.                 starting_body();
  2474.  
  2475.         switch (align)
  2476.         {
  2477.         case ALIGN_CENTER:
  2478.                 printf (op->center_begin);
  2479.                 break;
  2480.         case ALIGN_LEFT:
  2481.                 break;
  2482.         case ALIGN_RIGHT:
  2483.                 printf (op->align_right_begin);
  2484.                 break;
  2485.         case ALIGN_JUSTIFY:
  2486.                 printf (op->align_right_begin);
  2487.                 break;
  2488.         }
  2489. }
  2490.  
  2491.  
  2492.  
  2493. /*========================================================================
  2494.  * Name:       
  2495.  * Purpose:    
  2496.  * Args:        None.
  2497.  * Returns:     None.
  2498.  *=======================================================================*/
  2499.  
  2500. static void
  2501. ending_paragraph_align (int align)
  2502. {
  2503.         switch (align) {
  2504.         case ALIGN_CENTER:
  2505.                 printf (op->center_end);
  2506.                 break;
  2507.         case ALIGN_LEFT:
  2508.                 // printf (op->align_left_end);
  2509.                 break;
  2510.         case ALIGN_RIGHT:
  2511.                 printf (op->align_right_end);
  2512.                 break;
  2513.         case ALIGN_JUSTIFY:
  2514.                 printf (op->justify_end);
  2515.                 break;
  2516.         }
  2517. }
  2518.  
  2519.  
  2520. /*========================================================================
  2521.  * Name:       
  2522.  * Purpose:     Recursive routine to produce the output in the target
  2523.  *              format given on a tree of words.
  2524.  * Args:        Word* (the tree).
  2525.  * Returns:     None.
  2526.  *=======================================================================*/
  2527.  
  2528. static void
  2529. word_print_core (Word *w)
  2530. {
  2531.         char *s;
  2532.         FILE *f=NULL;
  2533.         int is_cell_group=FALSE;
  2534.         int paragraph_begined=FALSE;
  2535.         int paragraph_align=ALIGN_LEFT;
  2536.  
  2537.         CHECK_PARAM_NOT_NULL(w);
  2538.  
  2539.         if (!coming_pars_that_are_tabular && within_table) {
  2540.                 end_table();
  2541.         }
  2542.         else if (coming_pars_that_are_tabular && !within_table) {
  2543.                 begin_table();
  2544.         }
  2545.  
  2546.         /* Mark our place in the stack */
  2547.         attrstack_push();
  2548.  
  2549.         while (w) {
  2550.                 s = word_string (w);
  2551.  
  2552.                 if (s) {
  2553.                         /*--Ignore whitespace in header--------------------*/
  2554.                         if (*s==' ' && within_header) {
  2555.                                 /* no op */
  2556.                         }
  2557.                         else
  2558.                         /*--Handle word -----------------------------------*/
  2559.                         if (s[0] != '\\')
  2560.                         {
  2561.                                 starting_body();
  2562.                                 starting_text();
  2563.  
  2564.                                 if (!paragraph_begined) {
  2565.                                         starting_paragraph_align (paragraph_align);
  2566.                                         paragraph_begined=TRUE;
  2567.                                 }
  2568.  
  2569.                                 /*----------------------------------------*/
  2570.                                 if (within_picture) {
  2571.                                         starting_body();
  2572.                                         if (!f) {
  2573.                                                 char *ext=NULL;
  2574.                                                 switch (picture_type) {
  2575.                                                 case PICT_WB: ext="bmp"; break;
  2576.                                                 case PICT_WM: ext="wmf"; break;
  2577.                                                 case PICT_MAC: ext="pict"; break;
  2578.                                                 case PICT_JPEG: ext="jpg"; break;
  2579.                                                 case PICT_PNG: ext="png"; break;
  2580.                                                 case PICT_DI: ext="dib"; break; /* Device independent bitmap=??? */
  2581.                                                 case PICT_PM: ext="pmm"; break; /* OS/2 metafile=??? */
  2582.                                                 }
  2583.                                                 sprintf (picture_path, "pict%03d.%s",
  2584.                                                         picture_file_number++,ext);
  2585.                                                 f=fopen(picture_path,"w");
  2586.                                         }
  2587.  
  2588.                                         if (s[0]!=' ') {
  2589.                                                 char *s2;
  2590.                                                 printf (op->comment_begin);
  2591.                                                 printf ("picture data found, ");
  2592.                                                 if (picture_wmetafile_type_str) {
  2593.                                                         printf ("WMF type is %s, ",
  2594.                                                                 picture_wmetafile_type_str);
  2595.                                                 }
  2596.                                                 printf ("picture dimensions are %d by %d, depth %d",
  2597.                                                         picture_width, picture_height, picture_bits_per_pixel);
  2598.                                                 printf (op->comment_end);
  2599.                                                 if (picture_width && picture_height && picture_bits_per_pixel) {
  2600.                                                         s2=s;
  2601.                                                         while (*s2) {
  2602.                                                                 unsigned int tmp,value;
  2603.                                                                 tmp=tolower(*s2++);
  2604.                                                                 if (tmp>'9') tmp-=('a'-10);
  2605.                                                                 else tmp-='0';
  2606.                                                                 value=16*tmp;
  2607.                                                                 tmp=tolower(*s2++);
  2608.                                                                 if (tmp>'9') tmp-=('a'-10);
  2609.                                                                 else tmp-='0';
  2610.                                                                 value+=tmp;
  2611.                                                                 fprintf (f,"%c", value);
  2612.                                                         }
  2613.                                                 }
  2614.                                         }
  2615.                                 }
  2616.                                 /*----------------------------------------*/
  2617.                                 else {
  2618.                                         total_chars_this_line += strlen(s);
  2619.  
  2620.                                         if (op->word_begin)
  2621.                                                 printf (op->word_begin);
  2622.  
  2623.                                         print_with_special_exprs (s);
  2624.  
  2625.                                         if (op->word_end)
  2626.                                                 printf (op->word_end);
  2627.                                 }
  2628.  
  2629.                         /*---Handle RTF keywords---------------------------*/
  2630.  
  2631.                         } else {
  2632.                                 int done=FALSE;
  2633.  
  2634.                                 s++;
  2635.  
  2636. /*----Paragraph alignment----------------------------------------------------*/
  2637.                                 if (!strcmp ("ql", s))
  2638.                                         paragraph_align = ALIGN_LEFT;
  2639.                                 else if (!strcmp ("qr", s))
  2640.                                         paragraph_align = ALIGN_RIGHT;
  2641.                                 else if (!strcmp ("qj", s))
  2642.                                         paragraph_align = ALIGN_JUSTIFY;
  2643.                                 else if (!strcmp ("qc", s))
  2644.                                         paragraph_align = ALIGN_CENTER;
  2645.                                 else if (!strcmp ("pard", s))
  2646.                                 {
  2647.                                         /* Clear out all font attributes.
  2648.                                          */
  2649.                                         attr_pop_all();
  2650.                                         if(coming_pars_that_are_tabular) {
  2651.                                                 --coming_pars_that_are_tabular;
  2652.                                         }
  2653.  
  2654.                                         /* Clear out all paragraph attributes.
  2655.                                          */
  2656.                                         ending_paragraph_align(paragraph_align);
  2657.                                         paragraph_align = ALIGN_LEFT;
  2658.                                         paragraph_begined = FALSE;
  2659.                                 }
  2660. /*----Table keywords---------------------------------------------------------*/
  2661.                                 else
  2662.                                 if (!strcmp (s, "cell")) {
  2663.                                         is_cell_group=TRUE;
  2664.                                         if (!have_printed_cell_begin) {
  2665.                                                 /* Need this with empty cells */
  2666.                                                 printf (op->table_cell_begin);
  2667.                                                 attrstack_express_all();
  2668.                                         }
  2669.                                         attr_pop_dump();
  2670.                                         printf (op->table_cell_end);
  2671.                                         have_printed_cell_begin = FALSE;
  2672.                                         have_printed_cell_end=TRUE;
  2673.                                 }
  2674.                                 else if (!strcmp (s, "row")) {
  2675.                                         if (within_table) {
  2676.                                                 printf (op->table_row_end);
  2677.                                                 have_printed_row_begin = FALSE;
  2678.                                                 have_printed_row_end=TRUE;
  2679.                                         } else {
  2680.                                                 if (debug_mode) {
  2681.                                                         printf (op->comment_begin);
  2682.                                                         printf ("end of table row");
  2683.                                                         printf (op->comment_end);
  2684.                                                 }
  2685.                                         }
  2686.                                 }
  2687.  
  2688. /*----Special chars---------------------------------------------------------*/
  2689.                                 else if (*s == '\'') {
  2690.                                         /* \'XX is a hex char code expression */
  2691.                                         int ch = h2toi (&s[1]);
  2692.                                         char *s2;
  2693.  
  2694.                                         s2 = op_translate_char (op, charset_type, ch);
  2695.  
  2696.                                         if (!s2 || !*s2) {
  2697.                                                 printf (op->comment_begin);
  2698.                                                 printf("char 0x%02x",ch);
  2699.                                                 printf (op->comment_end);
  2700.                                         } else {
  2701.                                                 if (op->word_begin)
  2702.                                                         printf (op->word_begin);
  2703.                                                 printf ("%s", s2);
  2704.                                                 if (op->word_end)
  2705.                                                         printf (op->word_end);
  2706.                                         }
  2707.                                 }
  2708.                                 else
  2709. /*----Search the RTF command hash-------------------------------------------*/
  2710.                                 {
  2711.                                         int ch;
  2712.                                         int index=0;
  2713.                                         int have_param=FALSE, param=0;
  2714.                                         HashItem *hip;
  2715.                                         char *p;
  2716.                                         int match;
  2717.  
  2718.                                         /* Look for a parameter */
  2719.                                         p=s;
  2720.                                         while(*p && (!isdigit(*p) && *p!='-')) p++;
  2721.                                         if (*p && (isdigit(*p) || *p=='-')) {
  2722.                                                 have_param=TRUE;
  2723.                                                 param=atoi (p);
  2724.                                         }
  2725.  
  2726.                                         /* Generate a hash index
  2727.                                          */
  2728.                                         ch = tolower (*s);
  2729.                                         if (ch>='a' && ch<='z')
  2730.                                                 hip = hash [ch-'a'];
  2731.                                         else
  2732.                                                 hip = hashArray_other;
  2733.  
  2734.                                         if (!hip) {
  2735.                                                 if (debug_mode) {
  2736.                                                         printf (op->comment_begin);
  2737.                                                         printf ("unfamiliar rtf command: %s", s);
  2738.                                                         printf (op->comment_begin);
  2739.                                                 }
  2740.                                         }
  2741.                                         else
  2742.                                         {
  2743.                                                 while (!done) {
  2744.                                                         match=FALSE;
  2745.  
  2746.                                                         if (have_param) {
  2747.                                                                 int len=p-s;
  2748.                                                                 if (!hip[index].name[len] && !strncmp (s, hip[index].name, len))
  2749.                                                                         match=TRUE;
  2750.                                                         }
  2751.                                                         else
  2752.                                                                 match = !strcmp(s, hip[index].name);
  2753.  
  2754.                                                         if (match) {
  2755. #if 0
  2756.                                                                 char *always;
  2757. #endif
  2758.                                                                 char *debug;
  2759.                                                                 int terminate_group;
  2760.  
  2761.                                                                 if (hip[index].func) {
  2762.                                                                         terminate_group = hip[index].func (w,paragraph_align, have_param, param);
  2763.  
  2764.                                                                         if (terminate_group)
  2765.                                                                                 while(w) w=w->next;
  2766.                                                                 }
  2767.  
  2768.                                                                 debug=hip[index].debug_print;
  2769.  
  2770. #if 0
  2771.                                                                 always=hip[index].always_print;
  2772.                                                                 if (always)
  2773.                                                                         printf ("%s", always);
  2774. #endif
  2775.                                                                 if (debug && debug_mode) {
  2776.                                                                         printf (op->comment_begin);
  2777.                                                                         printf ("%s", debug);
  2778.                                                                         printf (op->comment_end);
  2779.                                                                 }
  2780.  
  2781.                                                                 done=TRUE;
  2782.                                                         }
  2783.                                                         else
  2784.                                                         {
  2785.                                                                 index++;
  2786.                                                                 if (!hip[index].name)
  2787.                                                                         done=TRUE;
  2788.                                                         }
  2789.                                                 }
  2790.                                         }
  2791.                                         if (!match) {
  2792.                                                 if (debug_mode) {
  2793.                                                         printf (op->comment_begin);
  2794.                                                         printf ("unfamiliar rtf command: %s", s);
  2795.                                                         printf (op->comment_end);
  2796.                                                 }
  2797.                                         }
  2798.                                 }
  2799.                         }
  2800. /*-------------------------------------------------------------------------*/
  2801.                 } else {
  2802.                         Word *child;
  2803.  
  2804.                         child = w->child;
  2805.  
  2806.                         if (!paragraph_begined) {
  2807.                                 starting_paragraph_align (paragraph_align);
  2808.                                 paragraph_begined=TRUE;
  2809.                         }
  2810.  
  2811.                         if (child)
  2812.                           word_print_core (child);
  2813.                 }
  2814.  
  2815.                 if (w)
  2816.                         w = w->next;
  2817.         }
  2818.  
  2819.         if (within_picture) {
  2820.                 if(f) {
  2821.                         fclose(f);
  2822.                         printf (op->imagelink_begin);
  2823.                         printf ("%s", picture_path);
  2824.                         printf (op->imagelink_end);
  2825.                         within_picture=FALSE;
  2826.                 }
  2827.         }
  2828.  
  2829.         /* Undo font attributes UNLESS we're doing table cells
  2830.          * since they would appear between </td> and </tr>.
  2831.          */
  2832.         if (!is_cell_group)
  2833.                 attr_pop_all();
  2834.         else
  2835.                 attr_drop_all();
  2836.  
  2837.         /* Undo paragraph alignment
  2838.          */
  2839.         if (paragraph_begined)
  2840.                 ending_paragraph_align (paragraph_align);
  2841.  
  2842.         attrstack_drop();
  2843. }
  2844.  
  2845.  
  2846.  
  2847.  
  2848. /*========================================================================
  2849.  * Name:       
  2850.  * Purpose:    
  2851.  * Args:        None.
  2852.  * Returns:     None.
  2853.  *=======================================================================*/
  2854.  
  2855. void
  2856. word_print (Word *w)
  2857. {
  2858.         CHECK_PARAM_NOT_NULL (w);
  2859.  
  2860.         if (!inline_mode) {
  2861.                 printf (op->document_begin);
  2862.                 printf (op->header_begin);
  2863.         }
  2864.  
  2865.         print_banner ();
  2866.  
  2867.         within_header=TRUE;
  2868.         have_printed_body=FALSE;
  2869.         within_table=FALSE;
  2870.         simulate_allcaps=FALSE;
  2871.         word_print_core (w);
  2872.         end_table();
  2873.  
  2874.         if (!inline_mode) {
  2875.                 printf (op->body_end);
  2876.                 printf (op->document_end);
  2877.         }
  2878. }
  2879.  
  2880.  
  2881.