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

  1. /*@z04.c:Token Service:NewToken(), CopyTokenList()@***************************/
  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:         z04.c                                                      */
  26. /*  MODULE:       Token Service                                              */
  27. /*  EXTERNS:      NewToken(), CopyTokenList(), EchoCatOp(), EchoToken()      */
  28. /*                                                                           */
  29. /*****************************************************************************/
  30. #include "externs"
  31.  
  32.  
  33. /*****************************************************************************/
  34. /*                                                                           */
  35. /*  OBJECT NewToken(xtype, xfpos, xvspace, xhspace, xprec, xactual)          */
  36. /*                                                                           */
  37. /*  Returns a new non-WORD token initialised as the parameters indicate.     */
  38. /*                                                                           */
  39. /*****************************************************************************/
  40.  
  41. OBJECT NewToken(xtype, xfpos, xvspace, xhspace, xprec, xactual)
  42. unsigned char xtype;  FILE_POS *xfpos;  unsigned char xvspace, xhspace;
  43. unsigned char xprec;  OBJECT xactual;
  44. { OBJECT res;
  45.   debug1(DTS, DDD, "NewToken(%s, ...)", Image(xtype));
  46.   res = New(xtype);  FposCopy(fpos(res), *xfpos);
  47.   vspace(res) = xvspace;  hspace(res) = xhspace;
  48.   precedence(res) = xprec;  actual(res) = xactual;
  49.   debug1(DTS, DDD, "NewToken returning %s", EchoToken(res));
  50.   return res;
  51. } /* end NewToken */
  52.  
  53.  
  54. /*****************************************************************************/
  55. /*                                                                           */
  56. /*  OBJECT CopyTokenList(x, pos)                                             */
  57. /*                                                                           */
  58. /*  Returns a copy of the list of tokens pointed to by x.                    */
  59. /*  All file positions in the copy are set to *pos.                          */
  60. /*                                                                           */
  61. /*****************************************************************************/
  62.  
  63. OBJECT CopyTokenList(x, pos)
  64. OBJECT x;  FILE_POS *pos;
  65. { OBJECT y, z, res;
  66.   res = nil;  y = x;
  67.   if( x != nil ) do
  68.   { if( is_word(type(y)) )
  69.     { z = MakeWord(type(y), string(y), pos);
  70.       vspace(z) = vspace(y);  hspace(z) = hspace(y);
  71.     }
  72.     else z = NewToken(type(y), pos,vspace(y),hspace(y),precedence(y),actual(y));
  73.     res = Append(res, z, PARENT);
  74.     y = succ(y, PARENT);
  75.   } while( y != x );
  76.   return res;
  77. } /* end CopyTokenList */
  78.  
  79. /*@::EchoCatOp(), EchoToken()@************************************************/
  80. /*                                                                           */
  81. /*  FULL_CHAR *EchoCatOp(xtype, xmark, xjoin)                                */
  82. /*                                                                           */
  83. /*  Return the catenation operator with this type, mark and join.            */
  84. /*                                                                           */
  85. /*****************************************************************************/
  86.  
  87. FULL_CHAR *EchoCatOp(xtype, xmark, xjoin)
  88. unsigned xtype;  BOOLEAN xmark, xjoin;
  89. { switch( xtype )
  90.   {
  91.     case VCAT:    return    (xmark ? xjoin ? KW_VCAT_MJ : KW_VCAT_MN
  92.                    : xjoin ? KW_VCAT_NJ : KW_VCAT_NN);
  93.  
  94.     case HCAT:    return    (xmark ? xjoin ? KW_HCAT_MJ : KW_HCAT_MN
  95.                    : xjoin ? KW_HCAT_NJ : KW_HCAT_NN);
  96.  
  97.     case ACAT:    return    (xmark ? xjoin ? KW_ACAT_MJ : AsciiToFull("??")
  98.                    : xjoin ? KW_ACAT_NJ : AsciiToFull("??") );
  99.  
  100.     default:    Error(INTERN, no_fpos, "EchoCatOp: xtype = %d", xtype);
  101.         return STR_EMPTY;
  102.  
  103.   } /* end switch */
  104. } /* end EchoCatOp */
  105.  
  106.  
  107. #if DEBUG_ON
  108. /*****************************************************************************/
  109. /*                                                                           */
  110. /*  FULL_CHAR *EchoToken(x)                                                  */
  111. /*                                                                           */
  112. /*  Return an image of token x.  Do not worry about preceding space.         */
  113. /*                                                                           */
  114. /*****************************************************************************/
  115.  
  116. FULL_CHAR *EchoToken(x)
  117. OBJECT x;
  118. { switch( type(x) )
  119.   {
  120.     case WORD:
  121.     
  122.       return string(x);
  123.       break;
  124.  
  125.  
  126.     case QWORD:
  127.     
  128.       return StringQuotedWord(x);
  129.       break;
  130.  
  131.  
  132.     case TSPACE:
  133.     case TJUXTA:
  134.     case USE:
  135.     case GSTUB_EXT:
  136.     case GSTUB_INT:
  137.     case GSTUB_NONE:
  138.     
  139.       return Image(type(x));
  140.       break;
  141.  
  142.  
  143.     case BEGIN:
  144.     case END:
  145.     case ENV:
  146.     case CLOS:
  147.     case LBR:
  148.     case RBR:
  149.     case NULL_CLOS:
  150.     case CROSS:
  151.     case ONE_COL:
  152.     case ONE_ROW:
  153.     case WIDE:
  154.     case HIGH:
  155.     case HSCALE:
  156.     case VSCALE:
  157.     case SCALE:
  158.     case HCONTRACT:
  159.     case VCONTRACT:
  160.     case HEXPAND:
  161.     case VEXPAND:
  162.     case PADJUST:
  163.     case HADJUST:
  164.     case VADJUST:
  165.     case ROTATE:
  166.     case CASE:
  167.     case YIELD:
  168.     case XCHAR:
  169.     case FONT:
  170.     case SPACE:
  171.     case BREAK:
  172.     case NEXT:
  173.     case OPEN:
  174.     case TAGGED:
  175.     case INCGRAPHIC:
  176.     case SINCGRAPHIC:
  177.     case GRAPHIC:
  178.     case ACAT:
  179.     case HCAT:
  180.     case VCAT:
  181.     case CLOSURE:
  182.     case PREPEND:
  183.     case SYS_PREPEND:
  184.     case DATABASE:
  185.     case SYS_DATABASE:
  186.     
  187.       return SymName(actual(x));
  188.       break;
  189.  
  190.  
  191.     default:
  192.     
  193.       Error(INTERN, &fpos(x), "EchoToken: %s", Image(type(x)));
  194.       return STR_EMPTY;
  195.       break;
  196.   }
  197. } /* end EchoToken */
  198. #endif
  199.