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

  1. /*@z21.c:Galley Maker:SizeGalley()@*******************************************/
  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:         z21.c                                                      */
  26. /*  MODULE:       Galley Maker                                               */
  27. /*  EXTERNS:      SizeGalley()                                               */
  28. /*                                                                           */
  29. /*****************************************************************************/
  30. #include "externs"
  31.  
  32.  
  33. /*****************************************************************************/
  34. /*                                                                           */
  35. /*  SizeGalley(hd, env, rows, joined, nonblock, trig, style, c, target,      */
  36. /*                                                dest_index, recs, inners)  */
  37. /*                                                                           */
  38. /*  Convert unsized galley hd into sized format.  The input parameters are:  */
  39. /*                                                                           */
  40. /*    hd          the galley to be converted                                 */
  41. /*    env         its environment                                            */
  42. /*    rows        TRUE if the resulting galley may have more than one row    */
  43. /*    joined      TRUE if the resulting galley must be simply joined         */
  44. /*    nonblock    Set the non_blocking() field of RECEPTIVEs to this value   */
  45. /*    trig        TRUE if indefinites of hd may trigger external galleys     */
  46. /*    *style      The initial style                                          */
  47. /*    *c          the width constraint hd should conform to                  */
  48. /*    target      if non-nil, expand indefinite objects to reveal a          */
  49. /*                @Galley within this symbol                                 */
  50. /*                                                                           */
  51. /*  The output parameters, in addition to the converted hd, are:             */
  52. /*                                                                           */
  53. /*    dest_index  the index of the @Galley found within target, if any       */
  54. /*    recs        list of all RECURSIVE indexes found (or nil if none)       */
  55. /*    inners      list of all UNATTACHED indexes found (or nil if none)      */
  56. /*                                                                           */
  57. /*****************************************************************************/
  58.  
  59. SizeGalley(hd, env, rows, joined, nonblock, trig, style, c, target,
  60.                         dest_index, recs, inners)
  61. OBJECT hd, env;  BOOLEAN rows, joined, nonblock, trig;  STYLE *style;
  62. CONSTRAINT *c;  OBJECT target, *dest_index, *recs, *inners;
  63. { OBJECT y, link, z, crs, t, tlink, zlink, tmp;
  64.   OBJECT extras, tmp1, tmp2, bt[2], ft[2];
  65.   
  66.   assert( type(hd) == HEAD && Down(hd) != hd, "SizeGalley: precondition!" );
  67.   assert( !sized(hd), "SizeGalley: already sized!" );
  68.   debug6(DGM, D, "SizeGalley(hd, -, %s, %s, %s, %s, %s, %s, -, -, -), hd =",
  69.     bool(joined), bool(nonblock), bool(trig), EchoStyle(style),
  70.     EchoConstraint(c), SymName(target));
  71.   ifdebug(DGM, DD, DebugObject(hd));
  72.  
  73.   /* manifest the child of hd, making sure it is simply joined if required */
  74.   tmp1 = target;
  75.   Child(y, Down(hd));
  76.   crs = nil;
  77.   bt[COL] = ft[COL] = bt[ROW] = ft[ROW] = nil;
  78.   if( joined )
  79.   { bt[COL] = New(THREAD);  ft[COL] = New(THREAD);
  80.     y = Manifest(y, env, style, bt, ft, &tmp1, &crs, TRUE, must_expand(hd));
  81.     assert( Down(bt[COL]) != bt[COL] && Down(ft[COL]) != ft[COL],
  82.     "SizeGalley: threads!" );
  83.     Child(tmp1, Down(bt[COL]));  Child(tmp2, Down(ft[COL]));
  84.     if( Down(bt[COL]) != LastDown(bt[COL]) ||
  85.       Down(ft[COL]) != LastDown(ft[COL]) || tmp1 != tmp2 )
  86.       Error(FATAL, &fpos(y), "galley %s must have just one column mark",
  87.                         SymName(actual(hd)) );
  88.     DisposeObject(bt[COL]);  DisposeObject(ft[COL]);
  89.   }
  90.   else y = Manifest(y, env, style, bt, ft, &tmp1, &crs, TRUE, must_expand(hd));
  91.  
  92.   /* horizontally size and break hd */
  93.   debug0(DGM, DD, "SizeGalley: after manifesting, hd =");
  94.   ifdebug(DGM, DD, DebugObject(hd));
  95.   debug0(DGM, DD, "SizeGalley horizontally sizing and breaking hd:");
  96.   CopyConstraint(constraint(hd), *c);
  97.   y = MinSize(y, COL, &extras);
  98.   debug0(DOB, DD, "  calling BreakObject from SizeGalley");
  99.   y = BreakObject(y, c);
  100.   back(hd, COL) = back(y, COL);
  101.   fwd(hd, COL)  = fwd(y, COL);
  102.   assert( FitsConstraint(back(hd, COL), fwd(hd, COL), *c),
  103.     "SizeGalley: BreakObject failed to fit!" );
  104.   debug2(DSF, D, "MinSize(hd, COL) = %s,%s",
  105.       EchoLength(back(hd, COL)), EchoLength(fwd(hd, COL)) );
  106.  
  107.   /* get the rows of hd to the top level, if required */
  108.   seen_nojoin(hd) = FALSE;
  109.   if( rows )
  110.   { /* OBJECT prev_gap = nil; */
  111.     debug0(DGM, DD, "SizeGalley cleaning up rows of hd:");
  112.     for( link = hd;  NextDown(link) != hd;  link = NextDown(link) )
  113.     { Child(y, NextDown(link));
  114.       debug2(DGM, DD, "  cleaning %s: %s", Image(type(y)), EchoObject(y));
  115.       switch( type(y) )
  116.       {
  117.     case GAP_OBJ:
  118.  
  119.       /* prev_gap = y; */
  120.       if( !join(gap(y)) )  seen_nojoin(hd) = TRUE;
  121.       break;
  122.  
  123.  
  124.     case VCAT:
  125.       
  126.       TransferLinks(Down(y), y, Up(y));
  127.       DisposeChild(Up(y));
  128.       link = PrevDown(link);
  129.       break;
  130.  
  131.  
  132.     case SPLIT:
  133.       
  134.       assert(Up(y)==LastUp(y), "SizeGalley COL_THR: Up(y)!=LastUp(y)!");
  135.       Child(z, DownDim(y, ROW));
  136.       if( is_indefinite(type(z)) )  external(z) = TRUE;
  137.       else if( type(z) == VCAT )
  138.       { OBJECT hor, thor, clink, dlink;
  139.         Child(hor, DownDim(y, COL));
  140.         assert( type(hor) == COL_THR, "SizeGalley: missing COL_THR!" );
  141.         Parent(thor, UpDim(z, COL));
  142.         assert( hor == thor, "SizeGalley/SPLIT: hor != thor!" );
  143.         clink = DownDim(y, COL);
  144.         dlink = UpDim(z, COL);
  145.         for( tlink = LastDown(z);  tlink != z;  tlink = PrevDown(tlink) )
  146.         { Child(t, tlink);
  147.           if( type(t) == GAP_OBJ )  Link(NextDown(link), t);
  148.           else
  149.           {    tmp = New(SPLIT);
  150.         back(tmp, COL) = back(hor, COL);
  151.         fwd(tmp, COL) = fwd(hor, COL);
  152.         Link(NextDown(link), tmp);
  153.         Link(tmp, NextUp(clink));
  154.         Link(NextDown(dlink), t);
  155.         Link(tmp, t);
  156.           }
  157.         }
  158.         DeleteLink(dlink);
  159.         assert(Up(y)==LastUp(y), "SizeGalley COL_THR: Up(y) != LastUp(y)!");
  160.         DisposeChild(Up(y));
  161.         link = PrevDown(link);
  162.       }
  163.       break;
  164.  
  165.  
  166.     case CLOSURE:
  167.     case HEAD:
  168.       
  169.       external(y) = TRUE;
  170.       break;
  171.  
  172.  
  173.     default:
  174.       
  175.       break;
  176.       }
  177.     }
  178.   }
  179.  
  180.   /* size the rows of hd and attach indices where needed */
  181.   debug0(DGM, DD, "SizeGalley sizing rows of hd =");
  182.   ifdebug(DGM, DD, DebugObject(hd));
  183.   *recs = *inners = *dest_index = nil;
  184.   for( link = Down(hd);  link != hd;  link = NextDown(link) )
  185.   { Child(y, link);
  186.     if( type(y) == GAP_OBJ || is_index(type(y)) )  continue;
  187.     debug0(DGM, DDD, "  ROW sizing:");
  188.     ifdebug(DGM, DDD, DebugObject(y));
  189.     extras = New(ACAT);
  190.     y = MinSize(y, ROW, &extras);
  191.     debug3(DSF, D, "MinSize( %s , ROW ) = %s,%s", EchoObject(y),
  192.       EchoLength(back(y, ROW)), EchoLength(fwd(y, ROW)) );
  193.     debug0(DGM, DDD, "  ROW result:");
  194.     ifdebug(DGM, DDD, DebugObject(y));
  195.  
  196.     /* now attach indexes in front of y */
  197.     for( zlink = Down(extras);  zlink != extras;  zlink = NextDown(zlink) )
  198.     { Child(z, zlink);
  199.       blocked(z) = FALSE;
  200.       /* debug1(DCR, D, "  extra: %s", EchoObject(z)); */
  201.       debug1(DGM, DD, "  extra: %s", EchoObject(z));
  202.       switch( type(z) )
  203.       {
  204.     case RECEPTIVE:
  205.  
  206.       /* debug2(DCR, D, "  ... uses_ext  = %s, trig = %s",
  207.         bool(uses_extern_target(actual(actual(z)))), bool(trig)); */
  208.       trigger_externs(z) = uses_extern_target(actual(actual(z))) && trig;
  209.       non_blocking(z)    = nonblock;
  210.       if( actual(actual(z)) == GalleySym )  *dest_index = z;
  211.       break;
  212.  
  213.  
  214.     case RECURSIVE:
  215.  
  216.       if( *recs == nil )  *recs = New(ACAT);
  217.       Link(*recs, z);
  218.       break;
  219.  
  220.  
  221.     case UNATTACHED:
  222.  
  223.       if( *inners == nil )  *inners = New(ACAT);
  224.       Link(*inners, z);
  225.       break;
  226.  
  227.         
  228.     case EXPAND_IND:
  229.     case GALL_PREC:
  230.     case GALL_FOLL:
  231.     case GALL_TARG:
  232.     case CROSS_PREC:
  233.     case CROSS_FOLL:
  234.     case CROSS_TARG:
  235.  
  236.       debug1(DCR, DD, "  SizeGalley: %s", EchoObject(z));
  237.       break;
  238.  
  239.  
  240.     default:
  241.       
  242.       Error(INTERN, no_fpos, "SizeGalley: %s", Image(type(z)) );
  243.       break;
  244.  
  245.       }
  246.     }
  247.     TransferLinks(Down(extras), extras, link);
  248.     assert( Down(extras) == extras && Up(extras) == extras, "SizeG: extras!");
  249.     Dispose(extras);
  250.   }
  251.   
  252.   /* insinuate cross references */
  253.   if( crs != nil )
  254.   { 
  255.     debug1(DCR, D, "SizeGalley insinuating %s", crs);
  256.     TransferLinks(Down(crs), crs, Down(hd));
  257.     DisposeObject(crs);
  258.   }
  259.  
  260.   /* check that *dest_index was found if it was required, and exit */
  261.   if( target != nil && *dest_index == nil )
  262.     Error(FATAL, &fpos(hd), "Unexpected absence of %s from the body of %s",
  263.       SymName(target), SymName(actual(hd)));
  264.   debug3(DGM, D, "SizeGalley returning %s,%s  %s;  hd =",
  265.     EchoLength(back(hd, COL)), EchoLength(fwd(hd, COL)),
  266.     EchoConstraint(&constraint(hd)));
  267.   ifdebug(DGM, DD, DebugObject(hd));
  268.   sized(hd) = TRUE;
  269.  
  270. } /* end SizeGalley */
  271.