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

  1. /*@z07.c:Object Service:SplitIsDefinite(), DisposeObject()@*******************/
  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:         z07.c                                                      */
  26. /*  MODULE:       Object Service                                             */
  27. /*  EXTERNS:      MakeWord(), MakeWordTwo(), DisposeObject(), CopyObject(),  */
  28. /*                SplitIsDefinite()                                          */
  29. /*                                                                           */
  30. /*****************************************************************************/
  31. #include "externs"
  32.  
  33.  
  34. /*****************************************************************************/
  35. /*                                                                           */
  36. /*  BOOLEAN SplitIsDefinite(x)                                               */
  37. /*                                                                           */
  38. /*  Return TRUE if x is a definite SPLIT object (both children definite)     */
  39. /*                                                                           */
  40. /*****************************************************************************/
  41.  
  42. BOOLEAN SplitIsDefinite(x)
  43. OBJECT x;
  44. { OBJECT y1, y2;
  45.   assert( type(x) == SPLIT, "SplitIsDefinite: x not a SPLIT!" );
  46.   Child(y1, DownDim(x, COL));
  47.   Child(y2, DownDim(x, ROW));
  48.   return is_definite(type(y1)) && is_definite(type(y2));
  49. } /* end SplitIsDefinite */
  50.  
  51.  
  52. /*****************************************************************************/
  53. /*                                                                           */
  54. /*  DisposeObject(x)                                                         */
  55. /*                                                                           */
  56. /*  Dispose object x recrusively, leaving intact any shared descendants.     */
  57. /*                                                                           */
  58. /*****************************************************************************/
  59.  
  60. DisposeObject(x)
  61. OBJECT x;
  62. { debug2(DOS,D,"[DisposeObject( %d ), type = %s, x =", (int) x, Image(type(x)));
  63.   ifdebug(DOS, DD, DebugObject(x));
  64.   assert( Up(x) == x, "DisposeObject: x has a parent!" );
  65.   while( Down(x) != x )  DisposeChild(Down(x));   Dispose(x);
  66.   debug0(DOS, D, "]DisposeObject returning.");
  67. } /* end DisposeObject */
  68.  
  69.  
  70. /*@::MakeWord(), MakeWordTwo()@***********************************************/
  71. /*                                                                           */
  72. /*  OBJECT MakeWord(typ, str, pos)                                           */
  73. /*                                                                           */
  74. /*  Return an unsized WORD or QWORD made from the given string and fpos.     */
  75. /*                                                                           */
  76. /*****************************************************************************/
  77.  
  78. OBJECT MakeWord(typ, str, pos)
  79. unsigned typ;  FULL_CHAR *str;  FILE_POS *pos;
  80. { OBJECT res = NewWord(typ, StringLength(str), pos);
  81.   StringCopy(string(res), str);
  82.   FposCopy(fpos(res), *pos);
  83.   debug4(DOS, DD, "MakeWord(%s, %s, %s) returning %s",
  84.     Image(typ), str, EchoFilePos(pos), EchoObject(res));
  85.   return res;
  86. } /* end MakeWord */
  87.  
  88.  
  89. /*****************************************************************************/
  90. /*                                                                           */
  91. /*  OBJECT MakeWordTwo(typ, str1, str2, pos)                                 */
  92. /*                                                                           */
  93. /*  Return an unsized WORD or QWORD made from the two strings and fpos.      */
  94. /*                                                                           */
  95. /*****************************************************************************/
  96.  
  97. OBJECT MakeWordTwo(typ, str1, str2, pos)
  98. unsigned typ;  FULL_CHAR *str1, *str2;  FILE_POS *pos;
  99. { int len1 = StringLength(str1);
  100.   int len2 = StringLength(str2);
  101.   OBJECT res = NewWord(typ, len1 + len2, pos);
  102.   StringCopy(string(res), str1);
  103.   StringCopy(&string(res)[len1], str2);
  104.   FposCopy(fpos(res), *pos);
  105.   debug5(DOS, DD, "MakeWordTwo(%s, %s, %s, %s) returning %s",
  106.     Image(typ), str1, str2, EchoFilePos(pos), EchoObject(res));
  107.   return res;
  108. } /* end MakeWordTwo */
  109.  
  110.  
  111. /*@::CopyObject()@************************************************************/
  112. /*                                                                           */
  113. /*  OBJECT CopyObject(x, pos)                                                */
  114. /*                                                                           */
  115. /*  Make a copy of unsized object x, setting all file positions to *pos.     */
  116. /*                                                                           */
  117. /*****************************************************************************/
  118.  
  119. OBJECT CopyObject(x, pos)
  120. OBJECT x;  FILE_POS *pos;
  121. { OBJECT y, link, res, tmp;
  122.  
  123.   debug2(DOS, DD, "CopyObject(%s, %s)", EchoObject(x), EchoFilePos(pos));
  124.   switch( type(x) )
  125.   {
  126.  
  127.     case WORD:
  128.     case QWORD:
  129.     
  130.       res = NewWord(type(x), StringLength(string(x)), pos);
  131.       StringCopy(string(res), string(x));
  132.       break;
  133.  
  134.  
  135.     case GAP_OBJ:
  136.     
  137.       res = New(type(x));
  138.       mark(gap(res)) = mark(gap(x));
  139.       join(gap(res)) = join(gap(x));
  140.       if( Down(x) != x )
  141.       {    Child(y, Down(x));
  142.     tmp = CopyObject(y, pos);
  143.     Link(res, tmp);
  144.       }
  145.       else
  146.       {    hspace(res) = hspace(x);
  147.     vspace(res) = vspace(x);
  148.       }
  149.       break;
  150.  
  151.  
  152.     /* case HEAD: */
  153.     case NULL_CLOS:
  154.     case CROSS:
  155.     case ONE_COL:
  156.     case ONE_ROW:
  157.     case WIDE:
  158.     case HIGH:
  159.     case HSCALE:
  160.     case VSCALE:
  161.     case SCALE:
  162.     case HCONTRACT:
  163.     case VCONTRACT:
  164.     case HEXPAND:
  165.     case VEXPAND:
  166.     case PADJUST:
  167.     case HADJUST:
  168.     case VADJUST:
  169.     case ROTATE:
  170.     case CASE:
  171.     case YIELD:
  172.     case XCHAR:
  173.     case FONT:
  174.     case SPACE:
  175.     case BREAK:
  176.     case NEXT:
  177.     case OPEN:
  178.     case TAGGED:
  179.     case INCGRAPHIC:
  180.     case SINCGRAPHIC:
  181.     case GRAPHIC:
  182.     case VCAT:
  183.     case HCAT:
  184.     case ACAT:
  185.     
  186.       res = New(type(x));
  187.       for( link = Down(x);  link != x;  link = NextDown(link) )
  188.       {    Child(y, link);
  189.     tmp = CopyObject(y, pos);
  190.     Link(res, tmp);
  191.       }
  192.       break;
  193.  
  194.  
  195.     case ENV:
  196.     
  197.       res = x;  /* do not copy environments */
  198.       break;
  199.  
  200.  
  201.     case PAR:
  202.     
  203.       res = New(PAR);
  204.       actual(res) = actual(x);
  205.       assert( Down(x) != x, "CopyObject: PAR child!" );
  206.       Child(y, Down(x));
  207.       tmp = CopyObject(y, pos);
  208.       Link(res, tmp);
  209.       break;
  210.  
  211.  
  212.     case CLOSURE:
  213.     
  214.       res = New(type(x));
  215.       for( link = Down(x);  link != x;  link = NextDown(link) )
  216.       {    Child(y, link);
  217.     assert( type(y) != CLOSURE, "CopyObject: CLOSURE!" );
  218.     tmp = CopyObject(y, pos);
  219.     Link(res, tmp);
  220.       }
  221.       actual(res) = actual(x);
  222.       StyleCopy(save_style(res), save_style(x));
  223.       break;
  224.  
  225.  
  226.     default:
  227.     
  228.       Error(INTERN, pos, "CopyObject: %s found", Image(type(x)));
  229.       break;
  230.  
  231.   } /* end switch */
  232.   if( pos == no_fpos )  FposCopy(fpos(res), fpos(x));
  233.   else FposCopy(fpos(res), *pos);
  234.   debug1(DOS, DD, "CopyObject returning %s", EchoObject(res));
  235.   return res;
  236. } /* end CopyObject */
  237.