home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / lout2.lzh / LOUT2 / z11.c < prev    next >
Text File  |  1994-01-23  |  9KB  |  183 lines

  1. /*@z11.c:Style Service:EchoStyle()@*******************************************/
  2. /*                                                                           */
  3. /*  LOUT: A HIGH-LEVEL LANGUAGE FOR DOCUMENT FORMATTING (VERSION 2.05)       */
  4. /*  COPYRIGHT (C) 1993 Jeffrey H. Kingston                                   */
  5. /*                                                                           */
  6. /*  Jeffrey H. Kingston (jeff@cs.su.oz.au)                                   */
  7. /*  Basser Department of Computer Science                                    */
  8. /*  The University of Sydney 2006                                            */
  9. /*  AUSTRALIA                                                                */
  10. /*                                                                           */
  11. /*  This program is free software; you can redistribute it and/or modify     */
  12. /*  it under the terms of the GNU General Public License as published by     */
  13. /*  the Free Software Foundation; either version 1, or (at your option)      */
  14. /*  any later version.                                                       */
  15. /*                                                                           */
  16. /*  This program is distributed in the hope that it will be useful,          */
  17. /*  but WITHOUT ANY WARRANTY; without even the implied warranty of           */
  18. /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            */
  19. /*  GNU General Public License for more details.                             */
  20. /*                                                                           */
  21. /*  You should have received a copy of the GNU General Public License        */
  22. /*  along with this program; if not, write to the Free Software              */
  23. /*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
  24. /*                                                                           */
  25. /*  FILE:         z11.c                                                      */
  26. /*  MODULE:       Style Service                                              */
  27. /*  EXTERNS:      EchoStyle(), SpaceChange(), BreakChange()                  */
  28. /*                                                                           */
  29. /*****************************************************************************/
  30. #include "externs"
  31.  
  32.  
  33. #if DEBUG_ON
  34. /*****************************************************************************/
  35. /*                                                                           */
  36. /*  FULL_CHAR *EchoStyle(style)                                              */
  37. /*                                                                           */
  38. /*  Returns a string showing the value of the style.                         */
  39. /*                                                                           */
  40. /*****************************************************************************/
  41.  
  42. FULL_CHAR *EchoStyle(style)
  43. STYLE *style;
  44. { FULL_CHAR buff1[100], buff2[100], buff3[100], buff4[100];
  45.   static FULL_CHAR res[100];
  46.   static char *hyphwords[] = { "hyph_undef", "hyph_off", "hyph_on" };
  47.   static char *fillwords[] = { "fill_undef", "fill_off", "fill_on" };
  48.   static char *displaywords[] = { "undef", "adjust", "outdent", "left",
  49.                  "centre", "right", "do" };
  50.  
  51.   StringCopy(res, AsciiToFull("["));
  52.   StringCat(res, EchoCatOp(VCAT,mark(line_gap(*style)),join(line_gap(*style))));
  53.   StringCat(res, EchoGap(&line_gap(*style)));
  54.   StringCat(res, AsciiToFull(", "));
  55.   StringCat(res, font(*style) == 0 ?
  56.            AsciiToFull("nofont") : FontFamilyAndFace(font(*style)));
  57.   StringCat(res, AsciiToFull(" ("));
  58.   StringCat(res, EchoGap(&space_gap(*style)));
  59.   StringCat(res, AsciiToFull("), "));
  60.   StringCat(res, AsciiToFull(hyph_style(*style) < 3 ?
  61.             hyphwords[hyph_style(*style)] : "?"));
  62.   StringCat(res, AsciiToFull(":"));
  63.   StringCat(res, AsciiToFull(fill_style(*style) < 3 ?
  64.             fillwords[fill_style(*style)] : "?"));
  65.   StringCat(res, AsciiToFull(":"));
  66.   StringCat(res, AsciiToFull(display_style(*style) < 7 ?
  67.             displaywords[display_style(*style)] : "?"));
  68.   StringCat(res, AsciiToFull("]"));
  69.   return res;
  70. } /* end EchoStyle */
  71. #endif
  72.  
  73.  
  74. /*@::SpaceChange()@***********************************************************/
  75. /*                                                                           */
  76. /*  SpaceChange(style, x)                                                    */
  77. /*                                                                           */
  78. /*  Change the current break style as indicated by object x.                 */
  79. /*                                                                           */
  80. /*****************************************************************************/
  81.  
  82. SpaceChange(style, x)
  83. STYLE *style;  OBJECT x;
  84. { GAP res_gap;  unsigned gap_inc;
  85.   debug2(DSS, D, "SpaceChange(%s, %s)", EchoStyle(style), EchoObject(x));
  86.   if( !is_word(type(x)) )
  87.   { Error(WARN, &fpos(x), "invalid left parameter to %s", KW_SPACE);
  88.   }
  89.   else
  90.   { GetGap(x, style, &res_gap, &gap_inc);
  91.     if( gap_inc != GAP_ABS && units(res_gap) != units(space_gap(*style)) )
  92.     { Error(WARN, &fpos(x), "space %s incompatible with enclosing", string(x));
  93.     }
  94.     else
  95.     { units(space_gap(*style)) = units(res_gap);
  96.       mode(space_gap(*style))  = mode(res_gap);
  97.       width(space_gap(*style)) = gap_inc == GAP_ABS ? width(res_gap) :
  98.          gap_inc == GAP_INC ? width(space_gap(*style)) + width(res_gap) :
  99.          max(width(space_gap(*style)) - width(res_gap), 0);
  100.     }
  101.   }
  102.   debug1(DSS, D, "SpaceChange returning %s", EchoStyle(style));
  103. } /* end SpaceChange */
  104.  
  105.  
  106. /*@::BreakChange()@***********************************************************/
  107. /*                                                                           */
  108. /*  BreakChange(style, x)                                                    */
  109. /*                                                                           */
  110. /*  Change the current break style as indicated by object x.                 */
  111. /*                                                                           */
  112. /*****************************************************************************/
  113.  
  114. static changebreak(style, x)
  115. STYLE *style;  OBJECT x;
  116. { GAP res_gap;  unsigned gap_inc;
  117.   if( beginsbreakstyle(string(x)[0]) )
  118.   {
  119.     /* should be a new break style option */
  120.     if( StringEqual(string(x), STR_BREAK_HYPHEN) )
  121.     hyph_style(*style) = HYPH_ON;
  122.     else if( StringEqual(string(x), STR_BREAK_NOHYPHEN) )
  123.     hyph_style(*style) = HYPH_OFF;
  124.     else if( StringEqual(string(x), STR_BREAK_ADJUST) )
  125.     fill_style(*style) = FILL_ON, display_style(*style) = DISPLAY_ADJUST;
  126.     else if( StringEqual(string(x), STR_BREAK_OUTDENT) )
  127.     fill_style(*style) = FILL_ON, display_style(*style) = DISPLAY_OUTDENT;
  128.     else if( StringEqual(string(x), STR_BREAK_RAGGED) )
  129.     fill_style(*style) = FILL_ON, display_style(*style) = DISPLAY_LEFT;
  130.     else if( StringEqual(string(x), STR_BREAK_CRAGGED) )
  131.     fill_style(*style) = FILL_ON, display_style(*style) = DISPLAY_CENTRE;
  132.     else if( StringEqual(string(x), STR_BREAK_RRAGGED) )
  133.     fill_style(*style) = FILL_ON, display_style(*style) = DISPLAY_RIGHT;
  134.     else if( StringEqual(string(x), STR_BREAK_LINES) )
  135.     fill_style(*style) = FILL_OFF, display_style(*style) = DISPLAY_LEFT;
  136.     else if( StringEqual(string(x), STR_BREAK_CLINES) )
  137.     fill_style(*style) = FILL_OFF, display_style(*style) = DISPLAY_CENTRE;
  138.     else if( StringEqual(string(x), STR_BREAK_RLINES) )
  139.     fill_style(*style) = FILL_OFF, display_style(*style) = DISPLAY_RIGHT;
  140.     else Error(WARN, &fpos(x), "invalid %s option %s", KW_BREAK, string(x));
  141.   }
  142.   else /* should be a new inter-line gap */
  143.   { GetGap(x, style, &res_gap, &gap_inc);
  144.     if( gap_inc != GAP_ABS && units(res_gap) != units(line_gap(*style)) )
  145.       Error(WARN, &fpos(x),
  146.             "line spacing %s incompatible with enclosing", string(x));
  147.     else
  148.     { units(line_gap(*style)) = units(res_gap);
  149.       mode(line_gap(*style))  = mode(res_gap);
  150.       width(line_gap(*style)) = gap_inc == GAP_ABS ? width(res_gap) :
  151.     gap_inc == GAP_INC ? width(line_gap(*style)) + width(res_gap) :
  152.     max(width(line_gap(*style)) - width(res_gap), 0);
  153.     }
  154.   }
  155. } /* end changebreak */
  156.  
  157. BreakChange(style, x)
  158. STYLE *style;  OBJECT x;
  159. { OBJECT link, y;
  160.   debug2(DSS, D, "BreakChange(%s, %s)", EchoStyle(style), EchoObject(x));
  161.   switch( type(x) )
  162.   {
  163.     case WORD:
  164.     case QWORD:    changebreak(style, x);
  165.         break;
  166.  
  167.  
  168.     case ACAT:    for( link = Down(x);  link != x;  link = NextDown(link) )
  169.         { Child(y, link);
  170.           if( type(y) == GAP_OBJ )  continue;
  171.           else if( is_word(type(y)) )  changebreak(style, y);
  172.           else Error(WARN, &fpos(x), "invalid left parameter of %s",
  173.              KW_BREAK);
  174.         }
  175.         break;
  176.  
  177.  
  178.     default:    Error(WARN, &fpos(x), "invalid left parameter of %s", KW_BREAK);
  179.         break;
  180.   }
  181.   debug1(DSS, D, "BreakChange returning %s", EchoStyle(style));
  182. } /* end BreakChange */
  183.